@seatlayer/core 0.75.1 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{categoryInventory-DFp26meo.d.cts → categoryInventory-CBuJy9KM.d.cts} +1 -1
- package/dist/{categoryInventory-C5I2U-EM.d.ts → categoryInventory-Cy5pQ0KW.d.ts} +1 -1
- package/dist/chunk-24O23MNB.js +1 -0
- package/dist/chunk-BT2KJXQC.js +1 -0
- package/dist/{chunk-3L4M7L5I.js → chunk-BXU5D2Q5.js} +1 -1
- package/dist/chunk-FGMGDTMR.js +1 -0
- package/dist/{chunk-KHFCTR3V.js → chunk-JQL77POQ.js} +1 -1
- package/dist/{chunk-UVAV3E7K.js → chunk-NQZAZFAC.js} +1 -1
- package/dist/{chunk-OGIAQX62.js → chunk-O5UH442K.js} +1 -1
- package/dist/{chunk-TN6DFYEV.js → chunk-PRED5KHO.js} +1 -1
- package/dist/{chunk-N3DPHRJ3.js → chunk-Q3U3F4YJ.js} +1 -1
- package/dist/{chunk-YACNGDTE.js → chunk-WXGW2SYC.js} +1 -1
- package/dist/{chunk-FMZ6HLDH.js → chunk-XD2P4ZS4.js} +1 -1
- package/dist/core/chart-ops/index.cjs +1 -1
- package/dist/core/chart-ops/index.d.cts +7 -5
- package/dist/core/chart-ops/index.d.ts +7 -5
- package/dist/core/chart-ops/index.js +1 -1
- package/dist/core/inventory/index.cjs +1 -1
- package/dist/core/inventory/index.d.cts +4 -4
- package/dist/core/inventory/index.d.ts +4 -4
- package/dist/core/inventory/index.js +1 -1
- package/dist/core/layout/index.cjs +1 -1
- package/dist/core/layout/index.d.cts +5 -5
- package/dist/core/layout/index.d.ts +5 -5
- package/dist/core/layout/index.js +1 -1
- package/dist/core/quality/index.cjs +1 -1
- package/dist/core/quality/index.d.cts +18 -14
- package/dist/core/quality/index.d.ts +18 -14
- package/dist/core/quality/index.js +1 -1
- package/dist/core/render-assets/index.d.cts +1 -1
- package/dist/core/render-assets/index.d.ts +1 -1
- package/dist/core/seatConfidence.d.cts +1 -1
- package/dist/core/seatConfidence.d.ts +1 -1
- package/dist/core/sections/index.cjs +1 -1
- package/dist/core/sections/index.d.cts +5 -5
- package/dist/core/sections/index.d.ts +5 -5
- package/dist/core/sections/index.js +1 -1
- package/dist/{eventConfigurations-DAaOaKJK.d.cts → eventConfigurations-CqfrYWAb.d.cts} +1 -1
- package/dist/{eventConfigurations-BQGuLLv0.d.ts → eventConfigurations-Dhauc9V3.d.ts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +61 -18
- package/dist/index.d.ts +61 -18
- package/dist/index.js +1 -1
- package/dist/{labeling-BZp91HiS.d.cts → labeling-B1xsmowB.d.cts} +1 -1
- package/dist/{labeling-Duul2sao.d.ts → labeling-BwPEI5JN.d.ts} +1 -1
- package/dist/{renderedQuality-CEPse8ir.d.cts → renderedQuality-1E9KuJvY.d.cts} +1 -1
- package/dist/{renderedQuality-BYhJ3Cer.d.ts → renderedQuality-ChAZNV2N.d.ts} +1 -1
- package/dist/{renderer-Cv_gzYvT.d.cts → renderer-BRmVrITG.d.cts} +1 -1
- package/dist/{renderer-BlLKrW-U.d.ts → renderer-q7viZLGZ.d.ts} +1 -1
- package/dist/{sections-DIVvr8QN.d.ts → sections-ByTMouG8.d.ts} +1 -1
- package/dist/{sections-CRSGPI3T.d.cts → sections-CA-bBex5.d.cts} +1 -1
- package/dist/{segmentedRowModel-CvyOS6Bx.d.cts → segmentedRowModel-C7XOEjHk.d.cts} +1 -1
- package/dist/{segmentedRowModel-CD-YT9bT.d.ts → segmentedRowModel-DcvJVKLD.d.ts} +1 -1
- package/dist/{layout-Gkx3fo5_.d.cts → tableSizing-BdCyNeqX.d.cts} +14 -4
- package/dist/{layout-DGbWo5fV.d.ts → tableSizing-D8e8QAJ-.d.ts} +14 -4
- package/dist/{ticketRestrictions-C31mrE97.d.cts → ticketRestrictions-CPZglNvw.d.cts} +2 -2
- package/dist/{ticketRestrictions-DXO2eckD.d.ts → ticketRestrictions-CorjMY49.d.ts} +2 -2
- package/dist/{types-BVRza86Q.d.ts → types-CqaNLbU6.d.cts} +10 -4
- package/dist/{types-BVRza86Q.d.cts → types-CqaNLbU6.d.ts} +10 -4
- package/dist/view3d/crossfade/panorama.d.cts +1 -1
- package/dist/view3d/crossfade/panorama.d.ts +1 -1
- package/dist/view3d/index.cjs +6 -6
- package/dist/view3d/index.d.cts +3 -3
- package/dist/view3d/index.d.ts +3 -3
- package/dist/view3d/index.js +1 -1
- package/dist/view3d/scene/scene.worker.cjs +1 -1
- package/dist/view3d/scene/scene.worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-QUOAQQMP.js +0 -1
- package/dist/chunk-X2GZ5O7C.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ko=Object.create;var Ae=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)Ae(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&&Ae(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?Ae(n,"default",{value:e,enumerable:!0}):n,e)),Ko=e=>Ht(Ae({},"__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:()=>cr,MAX_FLOOR_BASE_HEIGHT_M:()=>Ge,addArcFanRows:()=>Xi,addBookableGridArray:()=>va,addBoothArray:()=>na,addChartCategory:()=>Vn,addChartFloor:()=>Cr,addChartZone:()=>_r,addGAArea:()=>ea,addRowBlock:()=>Qi,addTableArray:()=>ta,applyPolygonHole:()=>li,applyReferenceScanRows:()=>xa,applySectionCornerSmoothing:()=>mi,applySectionOutlineShaping:()=>Nn,applySectionRowFit:()=>si,approveConfidenceEvidence:()=>cs,arcFanInputForGroup:()=>Jn,assignSectionInventoryCategory:()=>fi,automaticPlacementCenter:()=>Ui,clearConfidenceEvidence:()=>ss,confidenceEvidenceChangeRequiresPublish:()=>es,confidenceEvidenceChanges:()=>Ao,confirmReferenceCategoryOutputColor:()=>Ri,convertGeneratedSectionToPolygon:()=>bi,countCoveredInventory:()=>Ve,familyCategoryLabel:()=>qn,gaAreaFootprint:()=>Zn,groupRowsAsSegmented:()=>oa,insertSeatingBlock:()=>ni,isSafeBuyerImageUrl:()=>cn,joinGAAreas:()=>qa,mergeRows:()=>Da,mirrorFirstFloor:()=>Ie,normalizeBuyerImageUrl:()=>Z,normalizeDraftEvidence:()=>Lo,parseSeatRefId:()=>Pa,pickColorblindSafeCategoryColor:()=>Hn,planCreationCategory:()=>Xn,previewArcFanRows:()=>Lt,previewBookableGridArray:()=>Ia,previewGeneratedSectionPolygonConversion:()=>Tn,previewJoinGAAreas:()=>Va,previewPolygonHole:()=>Xe,previewRemovePolygonHole:()=>Ln,previewRowCubicPath:()=>Mn,previewSectionRowFit:()=>An,reassignColorblindSafeCategoryColors:()=>Pi,relabelChartRows:()=>ti,removeChartCategory:()=>Gi,removeChartFloor:()=>Rr,removeChartObjects:()=>Wr,removeChartZone:()=>Ar,removePolygonHole:()=>di,renameChartFloor:()=>Or,renameDirectSeatImportCategory:()=>Ii,reorderChartCategories:()=>vi,replaceArcFanRows:()=>Ji,replaceRowBlock:()=>aa,resetSeatOverrides:()=>Ma,resizeShapes:()=>Ja,resolveCreationCategory:()=>Fi,retractConfidenceEvidence:()=>ls,seatRefId:()=>Re,sectionInventorySelectionSummary:()=>En,setConfidenceEvidence:()=>as,setRowBlockSpacing:()=>Ka,splitRow:()=>Ga,straightenAndSpaceRows:()=>$a,transformSectionBoundary:()=>hi,transformSectionBoundaryObject:()=>Fn,ungroupSegmentedRow:()=>ra,updateBooths:()=>Qr,updateCategoryDefinitions:()=>Un,updateChartFloorBaseHeight:()=>Pr,updateChartTheme:()=>zi,updateChartZones:()=>Mr,updateGAAreas:()=>Zr,updateRowCubicPath:()=>ri,updateRows:()=>Aa,updateSeatOverrides:()=>Dt,updateSectionExactPath:()=>pi,updateSectionMetadata:()=>gi,updateSegmentedRow:()=>ia,updateShapes:()=>Xa,updateStageKinds:()=>Ya,updateTables:()=>Yr,updateTextObjects:()=>ei,updateViewFromSeatFallback:()=>Bi});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 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 qt(e){let t=e.background?.padding??0,n=e.text.split(/\r?\n/),o=Math.max(1,...n.map(c=>c.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 Xt(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[Xt(e,.5)];let o=Array.from({length:n+1},(s,l)=>Xt(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],b=g===d?0:(l-d)/(g-d);r.push({x:o[c-1].x+(o[c].x-o[c-1].x)*b,y:o[c-1].y+(o[c].y-o[c-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 Jt(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),c=Math.atan2(a.end.y-a.center.y,a.end.x-a.center.x),s=Uo(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=D(i,a.control1)+D(a.control1,a.control2)+D(a.control2,a.end),c=Math.max(2,Math.ceil(r/n));for(let s=1;s<=c;s+=1)o.push(Ho(i,a,s/c))}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 Xo(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 Jo=.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,c=o/a,s=n*Yo;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 Wt(e,t){let{points:n,sourceIndex:o}=Xo(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 S=r[o[w]];c[w]=Number.isFinite(S)?Math.min(100,Math.max(-100,S))/100:0}let s=c.some(w=>Math.abs(w)>1e-6);if(a<=0&&!s)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 g=new Array(i).fill(0);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],R=n[(w+1)%i],G={x:S.x-I.x,y:S.y-I.y},N={x:R.x-I.x,y:R.y-I.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 A=Jt(($-l)/(180-l));g[w]=a*A*.5*Math.min(H,K)}for(let w=0;w<i;w+=1){let S=(w+1)%i,I=g[w]+g[S];if(I>d[w]&&I>1e-9){let R=d[w]/I;g[w]*=R,g[S]*=R}}let b=new Array(i),f=new Array(i);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],R=n[(w+1)%i];if(g[w]<=1e-6){b[w]={...I},f[w]={...I};continue}let G=D(I,S)||1,N=D(I,R)||1;b[w]={x:I.x+(S.x-I.x)/G*g[w],y:I.y+(S.y-I.y)/G*g[w]},f[w]={x:I.x+(R.x-I.x)/N*g[w],y:I.y+(R.y-I.y)/N*g[w]}}if(g.every(w=>w<=1e-6)&&!s)return null;let p=[],m={...f[0]},x=m,v=(w,S)=>{if(D(x,w)<=1e-9)return;let I=c[S];Math.abs(I)>1e-6?p.push(Qo(x,w,I*Jo*d[S])):p.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let S=w%i,I=n[S];v(b[S],(w-1)%i),g[S]>1e-6&&D(b[S],f[S])>1e-9&&(p.push({kind:"bezier",control1:st(b[S],I,Yt),control2:st(f[S],I,Yt),end:{...f[S]}}),x=f[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??"",c=e.seatNumbering?.endAt,s=e.seatCount;if(a==="updown"||a==="updown-descending"){let f=Math.ceil(s/2),p=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}${p}`}let l=a==="odd"||a==="even"?2:i,d=c!=null&&Number.isFinite(c)?c-(s-1)*l:n,g=o==="center"?nr(s)[t]:o==="rtl"?s-1-t:t,b;switch(a){case"odd":{let f=d%2===1?d:d+1;b=String(f+g*2);break}case"even":{let f=d%2===0?d:d+1;b=String(f+g*2);break}case"roman":b=nn(d+g*i);break;case"letters-upper":b=ft(d+g*i,!1);break;case"letters-lower":b=ft(d+g*i,!0);break;default:b=String(d+g*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)}`}var an=[{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 rr=Math.PI*2;function ir(e,t,n,o,i,a){return{x:i+e*n-t*o,y:a+e*o+t*n}}function sn(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=[],b=(f,p)=>{g.push({x:f,y:p})};switch(t){case"rect":{b(-l,-d),b(l,-d),b(l,d),b(-l,d);break}case"rounded":{let f=Math.min(i,a)*.18,p=5,m=(x,v,h)=>{for(let y=0;y<=p;y++){let w=h+y/p*(Math.PI/2);b(x+f*Math.cos(w),v+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;b(-l,-d),b(l,-d);let p=24;for(let m=0;m<=p;m++){let x=m/p,v=l-x*i,h=d+f*(1-Math.pow(2*v/i,2));b(v,h)}break}case"thrust":{let f=i*.18,p=a*1.1;b(-l,-d),b(l,-d),b(l,d),b(f,d),b(f,d+p),b(-f,d+p),b(-f,d),b(-l,d);break}case"runway":{let f=i*.1,p=a*3;b(-l,-d),b(l,-d),b(l,d),b(f,d),b(f,d+p),b(-f,d+p),b(-f,d),b(-l,d);break}case"round":case"oval-cricket":{for(let p=0;p<40;p++){let m=p/40*rr;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 f of ar(l,d,l*(8.5/60),d*(8.5/30)))b(f.x,f.y);break}case"track-athletics":{for(let f of sr(l,d))b(f.x,f.y);break}}return g.map(f=>ir(f.x,f.y,c,s,n,o))}function ar(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 sr(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}var cr=2e6,lr=/^data:image\/(?:png|jpe?g|webp|gif|avif);base64,[a-z0-9+/]+={0,2}$/i,dr=/[\s"'<>`\\]/;function cn(e){if(typeof e!="string"||!e||e.length>2e6||e!==e.trim())return!1;if(e.startsWith("data:"))return lr.test(e);if(dr.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 cn(t)?t:null}function un(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,ur=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 c=o/(t-1)*Ee,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),b=-s+s*Math.cos(d);r.push(ht(g,b,i,a))}return r}function fr(e){let t=new Map;if(e.overrides)for(let n of e.overrides)t.set(n.index,n);return t}function gr(e,t){let n=fr(e);return Se(e).map((o,i)=>{let a=n.get(i),r=un(a),c=we(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: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(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 gr(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 br(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 hr(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,b,f)=>{let p=o.get(d),m=un(p),x=p?.label??`${e.label}-${d+1}`,v=e.displayLabel??e.label;return{index:d,label:x,displayLabel:p?.displayLabel??`${v}-${d+1}`,x:g+(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,...f?{side:f}:{}}};if(e.shape==="round"){let d=(e.radius??40)+ae,g=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 v=g+x/n*2*Math.PI;t.push(i(x,e.center.x+d*Math.cos(v),e.center.y+d*Math.sin(v)))}return t}let f=b*Ee,p=(2*Math.PI-f)/2,m=g+p;for(let x=0;x<n;x++){let v=m+x/(n-1)*f;t.push(i(x,e.center.x+d*Math.cos(v),e.center.y+d*Math.sin(v)))}return t}let a=e.width??80,r=e.height??50,c=br(e),s=["top","bottom","left","right"],l=0;for(let d of s){let g=c[d];for(let b=0;b<g;b++){let f,p;d==="top"?(f=-a/2+(b+.5)*a/g,p=-r/2-ae):d==="bottom"?(f=-a/2+(b+.5)*a/g,p=r/2+ae):d==="left"?(f=-a/2-ae,p=-r/2+(b+.5)*r/g):(f=a/2+ae,p=-r/2+(b+.5)*r/g);let m=ht(f,p,e.rotation,e.center);t.push(i(l++,m.x,m.y,d))}}return t}function W(e){return hr(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 fn(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 ln(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 pr(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 F(e,t,n){return ln(e,t)&&!(n??[]).some(o=>ln(e,o)||pr(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 dn(e,t){return e.length===t.length&&e.every((n,o)=>n.x===t[o].x&&n.y===t[o].y)}function yr(e,t){if(e.type!=="gaArea"||!dn(e.points,t.outline))return!1;let n=e.holes??[],o=t.holes??[];return n.length===o.length&&n.every((i,a)=>dn(i,o[a]))}function gn(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&&(yr(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 bn(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 B(e))if(s.type==="row"){let l=new Map((s.overrides??[]).map(d=>[d.index,d]));Se(s).forEach((d,g)=>{let b=l.get(g);b?.skip||c(d.x+(b?.dx??0),d.y+(b?.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+ur,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=qt(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-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"}],As=new Map(xe.map(e=>[e.key,e]));var mr=[{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"}],js=new Map(mr.map(e=>[e.key,e]));var se=8,pt=24,wr=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],Ls=new Set(wr);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 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 Sr(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 xr(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=xr(Sr(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 hn=24,pn=80;function yt(e,t){let n=e.normalize("NFKC").trim();if(n.length>hn)throw new u("invalid_operation",`${t} displayed type must be at most ${hn} 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>pn)throw new u("invalid_operation",`${t} displayed label must be at most ${pn} 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 yn(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&&yn(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&&yn(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 J=Math.PI/180,X=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}function Ie(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 Ir=0,Ge=120,St=4;function vr(e){if(!Number.isFinite(e)||e<Ir||e>Ge)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function Cr(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(Ge,(e.floors.length-1)*St),r=Math.min(Ge,a+St),c=M(e,"floor",t.idFactory,new Set);return e.floors.push({id:c,name:o,baseHeightM:r,objects:[],focalPoint:{...e.focalPoint}}),Ie(e),{changed:!0,floorId:c,floorCount:e.floors.length,baseHeightM:r}}function Or(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 Pr(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});vr(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 Rr(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 Ie(e);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:E(e).length}}function _r(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: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 Mr(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=mt(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=wt(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 Ar(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,Ie(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 mn="__sl_ga__",ne=1e5,de=1e5;function jr(e,t){return`${mn}${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(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 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)=>jr(t.sourceAreaId,t.startIndex+o)))}function It(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(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 Be(e){return e.startsWith(mn)}var Lr="__ungrouped__";function kr(e){return e.type==="row"?z(e).map(t=>t.label):e.type==="table"?W(e).map(t=>t.label):e.type==="booth"?fn(e).map(t=>t.label):e.type==="gaArea"?Y(e):[]}function Er(e){return e.type==="row"||e.type==="table"||e.type==="booth"||e.type==="gaArea"}function ve(e){let t=B(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:Lr,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let r of t){if(!Er(r))continue;let c=kr(r);if(c.length===0)continue;let s=gn(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 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 Tr(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 wn(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 Fr(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:()=>[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:()=>[wn("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)=>Tr(`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:()=>[wn("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:()=>[Fr("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 xn(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 In="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",vn=[{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:In},{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:In},{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 Nr=new Map(vn.map(e=>[e.key,e]));function Cn(e){return typeof e=="string"&&Nr.has(e)}var tc=vn.map(e=>e.key);function vt(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 On(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 Dr(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 Gr(e,t,n,o){let i=Oe(e,t,n),a=Oe(e,t,o),r=Oe(n,o,e),c=Oe(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&&Ue(n,e,t)||Math.abs(a)<=1e-7&&Ue(o,e,t)||Math.abs(r)<=1e-7&&Ue(e,n,o)||Math.abs(c)<=1e-7&&Ue(t,n,o)}function Kr(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 $r(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)&&Gr(e[t],e[n],e[o],e[i]))return!0}}return!1}function Pn(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)=>Dr(t,e[(n+1)%e.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(Kr(e))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:$r(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?.kind==="direct-stage-v1")&&(e.referenceAnnotationSource.ownership="organizer"),e}function Yr(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 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 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 I=r.seatCountsBySide[S];if(!Number.isInteger(I)||I<0||I>40)throw new u("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let w=h.reduce((S,I)=>S+r.seatCountsBySide[I],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(c&&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"),g=Fe(r,"Table"),b=i.map(h=>{if(h.seatCountsBySide&&!s&&(c||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(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"],S=w.reduce((I,R)=>I+y.seatCountsBySide[R],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(I=>y.seatCountsBySide[I]>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}),f=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"?f.get(y.id)??y:y,S=[];w.type==="row"?S=z(w).map(I=>I.label):w.type==="table"?S=w.bookAsWhole||w.variableOccupancy?[w.label]:W(w).map(I=>I.label):w.type==="booth"?S=[w.label]:w.type==="gaArea"&&(S=Y(w));for(let I of S){let R=m.get(I);if(R&&(p.has(R)||p.has(w.id)))throw new u("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:I,conflictingObjectIds:[R,w.id]});m.set(I,R??w.id)}}let x=!1,v=["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 I of v)I in w||delete y[I];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(f=>n.objects.find(p=>p.type==="booth"&&p.id===f)),a=o.filter((f,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 c=(f,p,m,x)=>{if(p!==void 0&&(!Number.isFinite(p)||p<m||p>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=Pn(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=ce(r,"Booth"),g=Fe(r,"Booth"),b=!1;for(let f of i){let p=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)!==p&&(b=!0)}return{floorId:n.floorId,changed:b,boothIds:o}}function Zr(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&&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 c=ce(r,"GA area"),s=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&&It(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),b=r.capacity===void 0?d.inventorySegments:It(d,r.capacity);Object.assign(d,r),b!==void 0&&(d.inventorySegments=b),c&&delete d.displayLabel,s&&delete d.displayType,JSON.stringify(d)!==g&&(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 Wr(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+te(s),0),remainingObjectCount:n.objects.length}}function ei(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(!Cn(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&&(He(l),s=!0)}return{floorId:n.floorId,changed:s,textIds:o}}function ti(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(b=>n.objects.find(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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((b,f)=>b.origin.y-f.origin.y||b.origin.x-f.origin.x),c=b=>b.segmentedRow?.displayLabel??b.displayLabel??b.label,s=on(r.map(b=>({label:c(b)})),t.options),l=t.displayType==null?void 0:t.displayType.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,24),d=l===void 0||l===""||l==="Row"?t.displayType===void 0?void 0:null:l,g=!1;return r.forEach((b,f)=>{let p=s[f].label.normalize("NFKC").replace(/\s+/g," ").trim();if(c(b)!==p&&(g=!0,b.segmentedRow?b.segmentedRow.displayLabel=p:b.displayLabel=p),d!==void 0){if(d===null){b.displayType!==void 0&&(g=!0,delete b.displayType);return}b.displayType!==d&&(g=!0,b.displayType=d)}}),{floorId:n.floorId,changed:g,rows:r.map(b=>({id:b.id,displayLabel:c(b),...b.displayType?{displayType:b.displayType}:{}}))}}function ni(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),On(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=xn(d.label);g!=null&&(l=Math.max(l,g+1))}for(let d of r)d.label=U(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} `,b=d?Number.parseInt(d[2],10):1;do b++;while(c.has(`${g}${b}`));l.label=`${g}${b}`}"label"in l&&l.label&&c.add(l.label)}o.objects.push(...a);let s=null;if(n.sectionLabel&&t.wrapInSection!==!1){let l=ee(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 oi(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,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 Mn(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=oi(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 ri(e,t){let n=Mn(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 ii(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 ai(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=ii(t,n);return o?{x:o[0],y:o[1]}:null}function Rn(e){let t=((e+180)%360+360)%360-180;return t===-180&&(t=180),t}function An(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"?ai(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"&&F(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 p=Math.hypot(f.origin.x-r.x,f.origin.y-r.y);if(p<=f.seatSpacing/2+1e-6){l.push(f.id);continue}let m=2*Math.asin(f.seatSpacing/(2*p))/J,x=z(f),v=Math.atan2(f.origin.x-r.x,f.origin.y-r.y)/J,y=(f.curve!==0?Math.sign(f.curve):x.length>1&&Math.sign(Rn(Math.atan2(x[1].x-r.x,x[1].y-r.y)/J-v))||1)*m*(f.seatCount-1);if(Math.abs(y)>320){l.push(f.id);continue}let w=-v,S=f.curve+(y-f.curve)*g,I=f.rotation+Rn(w-f.rotation)*g,R={...f,curve:S,rotation:I},N=z(R).map((H,K)=>Math.hypot(H.x-x[K].x,H.y-x[K].y));d.push({rowId:f.id,fromCurve:f.curve,targetCurve:y,resultCurve:S,fromRotation:f.rotation,resultRotation:I,rmsMovement:Math.sqrt(N.reduce((H,K)=>H+K**2,0)/N.length),maxMovement:Math.max(...N)})}let b=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:b.length?b.reduce((f,p)=>f+p,0)/b.length:0,maxMovement:d.length?Math.max(...d.map(f=>f.maxMovement)):0}}function si(e,t){let n=An(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 jn(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),c=q(n,o,t);return i*a<-1e-9&&r*c<-1e-9}function _n(e,t){return e.some((n,o)=>{let i=e[(o+1)%e.length];return t.some((a,r)=>jn(n,i,a,t[(r+1)%t.length]))})}function ci(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)&&jn(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 Xe(e,t){let{target:n,object:o,outer:i}=qe(e,t.floorId,t.objectId),a=structuredClone(t.points);if(!ci(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(_n(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(_n(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 s=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:c,vertexCount:a.length,excludedObjectIds:s.map(l=>l.id),excludedInventoryUnits:Ve(n.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function li(e,t){let n=Xe(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 Ln(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 di(e,t){let n=Ln(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 ui(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 kn(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 En(e,t){let n=C(e,t.floorId),o=kn(n.objects,t.sectionIds),i=ve(Te(e,n.floorId)),a=new Map(i.sections.map(f=>[f.id,f])),r=new Map(n.objects.map(f=>[f.id,f])),c=o.logicalSectionIds.flatMap(f=>a.get(f)?.objectIds??[]),s=new Set,l=new Set(o.logicalSectionIds),d=new Set(n.objects.filter(f=>f.type==="section"&&l.has(f.logicalSectionId??f.id)).flatMap(f=>f.editor?.defaultCategoryKey?[f.editor.defaultCategoryKey]:[]));for(let f of c){let p=r.get(f);if(p)if(p.type==="row"||p.type==="table")for(let m of $e(p).keys())s.add(m);else(p.type==="booth"||p.type==="gaArea")&&s.add(p.categoryKey)}let g=o.logicalSectionIds.every(f=>(a.get(f)?.seatCount??0)>0),b=o.logicalSectionIds.every(f=>a.get(f)?.objectIds.some(p=>{let m=r.get(p);return m?.type==="row"||m?.type==="table"||m?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:c,categoryApplicable:g,...g&&s.size===1?{categoryKey:[...s][0]}:!g&&!c.length&&d.size===1?{categoryKey:[...d][0]}:{},categoryMixed:g?s.size!==1:!c.length&&d.size>1,viewApplicable:b}}function fi(e,t){j(e,t.categoryKey);let n=En(e,t);if(!n.categoryApplicable&&n.objectIds.length)throw new u("invalid_operation","A mixed selection of empty and occupied logical sections cannot be assigned together",{logicalSectionIds:n.logicalSectionIds});let o=C(e,n.floorId),i=new Set(n.objectIds),a=!1,r=0,c=new Set(n.logicalSectionIds);for(let s of o.objects)s.type!=="section"||!c.has(s.logicalSectionId??s.id)||s.editor?.defaultCategoryKey!==t.categoryKey&&(s.editor={...s.editor,defaultCategoryKey:t.categoryKey},a=!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 l=s.overrides.flatMap(d=>{if(d.categoryKey===void 0)return[d];let g={...d};return delete g.categoryKey,r++,a=!0,Object.keys(g).some(b=>b!=="index")?[g]:[]});l.length?s.overrides=l:delete s.overrides}return{...n,changed:a,categoryKey:t.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function gi(e,t){let n=C(e,t.floorId),o=kn(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=ui(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(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,b=!1;for(let f of o.sections){let p=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)!==p&&(b=!0,g.add(f.id))}for(let f of d){let p=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=De(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)!==p&&(b=!0,g.add(f.id))}return{floorId:n.floorId,changed:b,sectionIds:i,affectedSectionIds:[...g]}}function Tn(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 bi(e,t){let n=Tn(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 Fn(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=b=>{let f=b.x-g.x,p=b.y-g.y;return{x:g.x+f*l-p*d,y:g.y+f*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"?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=dt(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 hi(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,...Fn(o,t.transform)}}function pi(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(!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(c=>c.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function yi(e){return e.geometry?null:e.sourceOutline?.length?e.sourceOutline:e.outlinePath?null:e.outline?.length?e.outline:null}function mi(e,t){return Nn(e,{floorId:t.floorId,sectionIds:t.sectionIds,cornerSmoothing:t.strength})}function Nn(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(h=>h.type==="section"&&h.id===c);if(!s||!yi(s))continue;let d=structuredClone(s);a.set(s.id,{section:s,snapshot:d});let g=JSON.stringify(s),b=(s.sourceOutline??s.outline).map(h=>({...h})),f=Math.min(100,Math.max(0,t.cornerSmoothing??s.cornerSmoothing??0)),m=(t.edgeCurvature===void 0?s.edgeCurvature:t.edgeCurvature??void 0)?.map(h=>Math.min(100,Math.max(-100,h))),x=m?.some(h=>Math.abs(h)>.5)===!0,v=f>.5||x?Wt(b,{cornerSmoothing:f,...x?{edgeCurvature:m}:{}}):null;v?(s.sourceOutline=b,s.outlinePath=v,s.outline=lt(v),f>.5?s.cornerSmoothing=f:delete s.cornerSmoothing,x?s.edgeCurvature=[...m]:delete s.edgeCurvature):(s.outline=b,delete s.outlinePath,delete s.sourceOutline,delete s.cornerSmoothing,delete s.edgeCurvature);for(let h=0;h<(s.holes?.length??0);h+=1)Xe(e,{floorId:n.floorId,objectId:s.id,points:s.holes[h],holeIndex:h});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 Ot=.15,Pt=1.6;var wi=/^#?([\da-f]{3}|[\da-f]{6})$/i;function _t(e){let t=wi.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 Mt(e,t){let n=a=>{let r=_t(a);if(!r)return null;let c=h=>{let y=h/255;return y<=.04045?y/12.92:((y+.055)/1.055)**2.4},s=c(r[0]),l=c(r[1]),d=c(r[2]),g=(.4124*s+.3576*l+.1805*d)/.95047,b=.2126*s+.7152*l+.0722*d,f=(.0193*s+.1192*l+.9505*d)/1.08883,p=h=>h>.008856?Math.cbrt(h):7.787*h+16/116,m=p(g),x=p(b),v=p(f);return[116*x-16,500*(m-x),200*(x-v)]},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 Rt(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Dn(e){return .2126*Rt(e[0])+.7152*Rt(e[1])+.0722*Rt(e[2])}function Je(e,t){let n=_t(e),o=_t(t);if(!n||!o)return null;let i=Dn(n),a=Dn(o);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var Gn=["butt","round","square"],Kn=["miter","round","bevel"],$n=["none","arrow"];function At(e){return e==="line"||e==="polyline"}var zn=[{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}}],Nc=zn.map(e=>e.key),Si=new Map(zn.map(e=>[e.key,e]));function Pe(e){return typeof e=="string"&&Si.has(e)}var xi=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 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.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 g of i.tiers){let b=g.id.trim(),f=g.name.normalize("NFKC").trim(),p=f.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(!f||f.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:f});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new u("invalid_operation",`Ticket tier ${b} price must be from 0 to 1000000`,{categoryKey:a,tierId:b});if(g.restriction!=null&&!xi.has(g.restriction))throw new u("invalid_operation",`Ticket tier ${b} has an unknown restriction`,{categoryKey:a,tierId:b});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 ${b} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:b})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new u("invalid_operation",`Ticket tier ${b} must use a three-letter ISO currency`,{categoryKey:a,tierId:b});if(g.applicability!=null){let m=g.applicability.seatLabels?.map(v=>v.normalize("NFKC").trim()),x=g.applicability.accessibility;if(m&&(!m.length||m.length>1e4||m.some(v=>!v||v.length>160)||new Set(m).size!==m.length)||x&&(!x.length||x.some(v=>!xe.some(h=>h.key===v))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${b} has invalid seat applicability`,{categoryKey:a,tierId:b});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 ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b});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 ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b})}l.add(b),d.add(p)}}}return o}function Un(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 b={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?b.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete b.buyerMessage,b})),delete c.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 Ii(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 vi(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=ue(n.map((s,l)=>{let d=structuredClone(c.get(s));return s!==o[l]&&delete d.referenceDirectSeatImport,d})),{changed:!0,categoryKeys:n,categories:e.categories}}var jt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Bn(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 Ci(e,t){let n=Bn(e),o=Bn(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 Hn(e,t,n=jt){return n.find(i=>e.every(a=>Ci(i,a)>=Oi))??n[t%n.length]}function Pi(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,c)=>({categoryKey:r.key,patch:{color:n[c%n.length]}}));return Un(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 Ri(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,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let r=ue(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 Vn(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()})),...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 _i=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],Mi={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function Ai(e,t){let n=Mi[e];return!n||!t.includes(n)?t:[n,...t.filter(o=>o!==n)]}var ji=26;function Li(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 ki(e,t,n){let o=r=>e.every(c=>{let s=Mt(r,c);return s==null||s>=ji}),i=r=>{let c=Je(r,"#12151d"),s=Je(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=Li(r,.62,c);if(o(s)&&i(s))return s}return n}function qn(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 Ei(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 c=t.get(r)??new Set;c.add(i.objectType),t.set(r,c)}}return t}function Ti(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 Xn(e,t,n){let o=Ei(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=Ke.find(l=>l.objectType===n),c=a?qn(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:Ti(e,c)}}function Fi(e,t,n,o){let i=Xn(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 Ni(e,n,a,i.label,o)}function Ni(e,t,n,o,i){let a=i.palette??_i,r=e.categories.map(d=>d.color),c=i.suggestColor?.(r.map(d=>d.toLowerCase()))??Hn(r,e.categories.length),s=ki(r,Ai(t,a),c),l=Vn(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 Di(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==="section"&&i.editor?.defaultCategoryKey===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 Gi(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=Di(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 Ki=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],$i=["seat","deck","shell","fascia"];function zi(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 Ki){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 c of $i){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 Bi(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 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 Ui(e,t){let n=Te(e,t.floorId),o=bn(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 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 Hi(e,t,n){let o=n*J;return{x:e.x+t*Math.sin(o),y:e.y+t*Math.cos(o)}}function Vi(e,t,n,o){let i=Math.abs(o-n)*J,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let g=e.aisleGaps[l];if(!g)return[];let b=g/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 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 qi(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 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,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=Vi(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(([p,m])=>r*Math.abs(l-s)*J*(m-p)),b=e.fit==="fixed-count"?qi(g,e.seatsPerRow):g.map(p=>Math.max(2,Math.round(p/e.seatPitch)+1)),f=e.seatLabelStart;d.forEach(([p,m],x)=>{let v=s+(l-s)*p,h=s+(l-s)*m;e.facing==="outward"&&([v,h]=[h,v]);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-v)*J/(y-1),S=2*r*Math.sin(w/2),I={type:"row",id:n(i,x),label:U(e.rowLabelStart+i),origin:Hi(e.center,r,v),rotation:-v,curve:h-v,seatCount:y,seatSpacing:S,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(I),f+=y})}return o}function Lt(e,t){let n=Ye(e,t),o=C(e,t.floorId),i=Qe(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 Xi(e,t){let n=Ye(e,t),o=C(e,t.floorId),i=new Set,a=M(e,"fan",t.idFactory,i),r=Qe(n,a,()=>M(e,"r",t.idFactory,i)),c=Lt(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=ee(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 Jn(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 b=g.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(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=Ye(e,c),l=new Set(Qe(s,t.groupId,(g,b)=>`${g}:${b}`).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 Ji(e,t){Jn(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])),c=new Set,s=Qe(n,t.groupId,(m,x)=>r.get(`${m}:${x}`)??M(e,"r",t.idFactory,c)),l=Lt(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=ee(s);m&&(g={type:"section",id:a?.id??M(e,"sec",t.idFactory,c),label:d,outline:m,arcFanGroupId:t.groupId})}let b=new Set([...i.map(m=>m.id),...a?[a.id]:[]]),f=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(f)?f:p.length,0,...s,...g?[g]:[]),o.objects.splice(0,o.objects.length,...p),{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 Yi(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 Yn(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=Yi(e),c=vt(t.rotation??0),s=t.curve??0,l=t.style,d=l?M(e,"rowblock",t.idFactory,a):void 0,g=l?Yn({style:l,origin:t.origin,rotation:c,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,rowGap:n,seatSpacing:o,curve:s}):void 0,b={x:Math.cos(c*X),y:Math.sin(c*X)},f={x:-b.y,y:b.x},p=Array.from({length:t.rowCount},(v,h)=>{let y=l==="intertwined"&&h%2===1?o/2:0,w={type:"row",id:M(e,"r",t.idFactory,a),label:r(),origin:{x:t.origin.x+f.x*h*n+b.x*y,y:t.origin.y+f.y*h*n+b.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:h,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,origin:{...t.origin},rotation:c,rowGap:n,seatSpacing:o,curve:s,signature:g}),w});i.objects.push(...p);let m=null,x=t.sectionLabel?.trim();if(x){let v=ee(p);if(v){let h={type:"section",id:M(e,"sec",t.idFactory,a),label:x,outline:v};i.objects.push(h),m=h.id}}return{floorId:i.floorId,rowIds:p.map(v=>v.id),sectionId:m,createdIds:[...p.map(v=>v.id),...m?[m]:[]]}}function Qn(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 Zi(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 Wi=456;function Zn(e){let t=Math.sqrt(Math.max(1,e)*Wi);return{width:Math.round(t*1.027),height:Math.round(t/1.027)}}function ea(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}=Zn(t.capacity),r=Zi(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 ta(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=Qn(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 na(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=Qn(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 oa(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(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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(b=>b.segmentedRow);if(c.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:c.map(b=>b.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(b=>b.type==="row"?[b.segmentedRow?.groupId,b.rowBlockGeneration?.groupId].filter(f=>!!f):[])),d="";for(let b=0;b<100;b+=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((b,f)=>{b.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 ra(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 ia(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 aa(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 A=P.rowBlockGeneration;return A.kind!=="row-block-v1"||A.rowIndex!==$||A.signature!==i.signature||JSON.stringify(A)!==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,b=Number.isFinite(t.rotation??i.rotation)?vt(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(P=>Number.isFinite(P)&&P>0)||!Number.isFinite(g)||!Number.isFinite(b)||!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 p=Yn({style:r,origin:f,rotation:b,rowCount:c,seatsPerRow:s,rowGap:l,seatSpacing:d,curve:g}),m={x:Math.cos(b*X),y:Math.sin(b*X)},x={x:-m.y,y:m.x},v=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},I=[],R=[];for(let P=0;P<c;P+=1){let $=r==="intertwined"&&P%2===1?d/2:0,A=v.get(P);A||(A={type:"row",id:M(e,"r",t.idFactory,h),label:S(),origin:{...f},rotation:b,curve:g,seatCount:s,seatSpacing:d,categoryKey:o[0].categoryKey},R.push(A.id)),A.origin={x:f.x+x.x*P*l+m.x*$,y:f.y+x.y*P*l+m.y*$},A.rotation=b,A.curve=g,A.seatCount=s,A.seatSpacing=d,delete A.path,delete A.arcFanGeneration,A.overrides&&(A.overrides=A.overrides.filter(it=>it.index<s),A.overrides.length||delete A.overrides),A.rowBlockGeneration={kind:"row-block-v1",groupId:t.groupId,style:r,rowIndex:P,rowCount:c,seatsPerRow:s,origin:{...f},rotation:b,rowGap:l,seatSpacing:d,curve:g,signature:p},I.push(A)}let G=o.slice(c).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,...I),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:t.groupId,rowIds:I.map(P=>P.id),createdRowIds:R,removedRowIds:G,changed:a!==JSON.stringify(I)||R.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 Wn(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 eo(e){return fe(e).toLocaleLowerCase("en")}function Ft(e){return eo(e)}function to(e){return new Map((e??[]).map(t=>[t.index,t]))}function sa(e){let t=to(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 ca(e){if(e.bookAsWhole||e.variableOccupancy)return[e.label];let t=to(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 la(e){return e.type==="row"?[e.label,...sa(e)]:e.type==="table"?[e.label,...ca(e)]:e.type==="booth"?[e.label]:e.type==="gaArea"?[e.label,...Y(e)]:[]}function no(e,t){let n=new Set;for(let o of e)if(!t?.has(o.id))for(let i of la(o)){let a=Ft(i);a&&n.add(a)}return n}function da(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 oo(e,t,n){let o=da(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 ua=1e-6,fa=160,ga=.001,ba=1e-5;function ge(e){if(typeof e!="string")return;let t=e.normalize("NFKC").replace(/\s+/g," ").trim();if(!t||t.length>fa)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 ro(e){return typeof e=="string"&&Wn(e)||void 0}function io(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=ga+Math.max(1,i)*ba;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<=ua)return!0;let r=i/(e.seatCount-1);if(Math.abs(e.seatSpacing-r)>a)return!1;let c=Math.atan2(t.end.y-t.start.y,t.end.x-t.start.x)*180/Math.PI,s=Math.abs(((e.rotation-c)%360+540)%360-180),l=Math.max(.001,Math.atan2(a,Math.max(1,i))*180/Math.PI);return s<=l}function Nt(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}var ha=300;function pa(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 c=`${a}-${U(r)}`;if(!t.has(c))return t.add(c),r+=1,c}return o()}}}function ya(e){let t=no(B(e));return(n,o)=>{let i=fe(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,c=r?`${fe(i,80-r.length)}${r}`:i;if(c&&oo(t,c,o))return c}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function ma(e){return{ordinaryFor:pa(e),direct:ya(e)}}function ao(e,t,n){return e.type==="row"&&e.referenceScan?.assetId===t&&(!n||e.referenceScan.sectionId===n)}function wa(e,t,n){let o=new Map;for(let r of t.sections)if(!(n&&r.sectionId!==n)&&r.sourceGroupId)for(let[c,s]of r.rows.entries()){let l=ge(`${r.sourceGroupId}:${c}`),d=l&&ge(s.directSourceRowId)===l?l:void 0;d&&o.set(d,o.has(d)?null:s)}let i=new Map;for(let r of e){let c=ge(r.referenceScan?.directSourceRowId);if(!c){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 s=i.get(c)??[];s.push(r),i.set(c,s)}let a=new Map;for(let[r,c]of i){let s=c.filter(b=>b.overrides?.length);if(!s.length)continue;let l=o.get(r),d=s[0],g=d.overrides;if(c.length!==1||s.length!==1||!g||!l||!io(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:c.map(b=>b.id)});a.set(r,structuredClone(g))}return a}function so(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 Sa(e,t,n,o,i,a,r){let c=e.sectionId?t.find(d=>d.type==="section"&&d.id===e.sectionId):void 0;if(c){let d=so(t,n,r).filter(g=>F(L(g),c.outline,c.holes));if(d.length)return{skip:{sectionId:c.id,name:e.name,reason:"section_not_empty",objectIds:d.map(g=>g.id)},rows:[],seats:0}}let s=[],l=0;for(let[d,g]of e.rows.entries()){let b=Math.min(ha,Math.max(1,Math.round(g.seatCount)));if(!Number.isFinite(b)||b<1)continue;let f=g.end.x-g.start.x,p=g.end.y-g.start.y,m=Math.hypot(f,p),x=b>1&&m>0?m/(b-1):o>0?o:24;if(!Number.isFinite(x)||x<=0)continue;let v=m>0?Math.atan2(p,f)*180/Math.PI:0,h=e.sourceGroupId?ge(`${e.sourceGroupId}:${d}`):void 0,y=h&&ge(g.directSourceRowId)===h?h:void 0,w=y?ro(g.directReviewedSuffix):void 0,S=e.sourceGroupId&&g.rowLabel?fe(g.rowLabel):"",I=e.sourceGroupId&&g.rowDisplayLabel?fe(g.rowDisplayLabel):"",R=!!e.sourceGroupId&&g.rowDisplayLabel==="";s.push({label:S?a(S,b):i(),displayLabel:I||(R?"":String(d+1)),origin:{x:g.start.x,y:g.start.y},rotation:v,seatCount:b,seatSpacing:x,...y?{directSourceRowId:y}:{},...w?{directReviewedSuffix:w}:{}}),l+=b}return{skip:null,rows:s,seats:l}}function xa(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 c=a?t.sections.find(h=>h.sectionId===a.id&&h.seatCount>0):void 0;if(a&&c){let h=so(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:c.name,reason:"section_not_empty",objectIds:h.map(y=>y.id)}]}}let s=o.objects.filter(h=>ao(h,i,a?.id)),l=wa(s,t,a?.id),d=[],g=o.objects.filter(h=>ao(h,i,a?.id)?(d.push(h.id),!1):!0);o.objects.splice(0,o.objects.length,...g);let b=[],f=[],p=[],m=new Set,x=0,v=ma(e);for(let h of t.sections){if(a&&h.sectionId!==a.id)continue;let y=Sa(h,o.objects,i,t.seatPitch,v.ordinaryFor(h.name),v.direct,a?.id);if(y.skip){f.push(y.skip);continue}let w=y.rows.map(S=>({type:"row",id:M(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!==void 0?{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:f}}function co(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(p=>(p.type==="table"||p.type==="booth")&&p.id===f)),a=o.filter((f,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(f=>f.type!==r))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[f,p,m]of[["rows",t.rows,30],["columns",t.columns,30]])if(!Number.isInteger(p)||p<1||p>m)throw new u("invalid_operation",`${f} must be a whole number from 1 to ${m}`);for(let[f,p]of[["stepX",t.stepX],["stepY",t.stepY]])if(!Number.isFinite(p)||p<30||p>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,p)=>f+(p.type==="table"?p.seatCount:1),0),g=(e.floors?.length?e.floors.flatMap(f=>f.objects):e.objects).reduce((f,p)=>f+(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*(c-1);if(g+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:c,createdCount:s,addedInventory:b,resultingInventory:g+b,provenanceRemovedCount:i.filter(f=>!!f.referenceInventorySource).length*(c-1)}}}function Ia(e,t){return co(e,t).preview}function va(e,t){let{target:n,sources:o,preview:i}=co(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 b=Math.max(2,g),f=m=>{let x=`-${m}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},p=f(b);for(;r.has(p);)p=f(++b);return r.add(p),p},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 b of o){let f=structuredClone(b);f.id=M(e,f.type,t.idFactory,a),f.label=s(b.label,l),f.center={x:b.center.x+g*t.stepX,y:b.center.y+d*t.stepY},delete f.referenceInventorySource,c.push(f)}}return n.objects.push(...c),{...i,createdIds:c.map(d=>d.id)}}function Ca(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 Oa=new Set(xe.map(e=>e.key));function Re(e){return`${e.rowId}:${e.index}`}function Pa(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 Ra(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 _a(e){return Object.keys(e).every(t=>t==="index")}function lo(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=Re(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 Dt(e,t){let n=lo(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=>!Oa.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:Re(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 c=n.owners.get(a.rowId),s=JSON.stringify(c.overrides??[]),l=c.overrides??(c.overrides=[]),d=l.find(b=>b.index===a.index);d||(d={index:a.index},l.push(d));let g=d.viewFromSeatUrl;for(let b of o){let f=t.patch[b];if(b==="wheelchairSpaceType"&&f==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(f==null)delete d[b];else if(b==="accessibility")d.accessibility=[...new Set(f)],delete d.accessible;else if(b==="commercial")d.commercial={...d.commercial,...f};else if(b==="labelStyle"){let p=Ca(d.labelStyle,f);p?d.labelStyle=p:delete d.labelStyle}else Object.assign(d,{[b]: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}`),Ra(d),_a(d)&&(c.overrides=l.filter(b=>b!==d)),c.overrides?.length||delete c.overrides,JSON.stringify(c.overrides??[])!==s&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(Re)}}function Ma(e,t){let n=lo(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(Re)}}function Aa(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:c,labelRotation:s,labelStyleShape:l,displayLabel:d,displayType:g,...b}=t.patch,f=d===void 0?{}:{displayLabel:d},p=ce(f,"Row"),m=g===void 0?void 0:yt(g,"Row");if(r!==void 0&&le(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");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}),v=!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(I=>I.index<h.seatCount),h.overrides.length||(h.overrides=void 0)),S){let I=L(h);h.origin={x:h.origin.x+S.x-I.x,y:h.origin.y+S.y-I.y}}if(JSON.stringify(h)!==y&&(v=!0),x(h)!==w&&(delete h.arcFanGeneration,delete h.rowBlockGeneration),r!==void 0){let I=JSON.stringify(h.labelPresentation??null),R=De(h.labelPresentation,r);R?h.labelPresentation=R:delete h.labelPresentation,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(c!==void 0){let I=JSON.stringify(h.labelPresentation??null),R=h.labelPresentation?structuredClone(h.labelPresentation):{};R.positionPreset=c,R.visible=c!=="none",delete R.position,h.labelPresentation=R,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(s!==void 0||l!==void 0){let I=JSON.stringify(h.labelPresentation??null),R=h.labelPresentation?structuredClone(h.labelPresentation):{};s===null?delete R.rotation:s!==void 0&&(R.rotation=s),l!==void 0&&(R.style=l),h.labelPresentation=R,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(m!==void 0){let I=h.displayType;m?h.displayType=m:delete h.displayType,h.displayType!==I&&(v=!0)}if(d!==void 0){let I=h.displayLabel;p?delete h.displayLabel:h.displayLabel=f.displayLabel,h.displayLabel!==I&&(v=!0)}}return{floorId:n.floorId,changed:v,rowIds:o}}var ja=3;function Ze(e){return(e%360+360)%360}function La(e){let t=e.rotation*X;return{x:Math.cos(t),y:Math.sin(t)}}function ka(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 uo(e){let t=0,n=0;for(let i of e){let a=2*i.rotation*X;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 Ea(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 fo(e,t){let n=uo(e),o={x:-n.y,y:n.x},i=L(e[0]),a=e.map(s=>({row:s,coord:be(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&&(Ea(s.row,o.x*d,o.y*d),delete s.row.arcFanGeneration,delete s.row.rowBlockGeneration,c=!0)}),c}function Ta(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,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 Fa(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)/X)),e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration}function Na(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 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 merge");let i=o.map(S=>n.objects.find(I=>I.type==="row"&&I.id===S)),a=o.filter((S,I)=>!i[I]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,c=r.filter(S=>S.path||S.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(S=>S.id)});let s=r[0],l=r.find(S=>ka(S.rotation,s.rotation)>ja);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=La(s),g={x:-d.y,y:d.x},b=Math.max(8,s.seatSpacing*.6),f=r.find(S=>Math.abs(be(S.origin,s.origin,g))>b);if(f){let S=Math.round(Math.abs(be(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 ${S} units from the first.`,{rowIds:[s.id,f.id]})}let p=r.slice().sort((S,I)=>be(S.origin,s.origin,d)-be(I.origin,s.origin,d)),m=p.reduce((S,I)=>S+I.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],v=[],h=0;for(let S of p){if(S.overrides)for(let I of S.overrides)v.push({...structuredClone(I),index:I.index+h});h+=S.seatCount}x.seatCount=m,x.curve=0,delete x.path,v.length?x.overrides=v: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 Ga(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=Se(o),c=i>1?o.curve/(i-1):0,s=i-a,l={type:"row",id:M(e,"r",t.idFactory,new Set),label:Na(n.objects,o.label),origin:{...r[a]},rotation:Ze(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 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:s,newLabel:l.label}}function Ka(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=fo(i,t.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:t.gap}}function $a(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(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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(b=>[b.origin,b.rotation,b.curve,b.path??null,b.seatSpacing])),s=c();for(let b of r)Fa(b);let l=uo(r),d=Ze(Math.atan2(l.y,l.x)/X);for(let b of r)b.rotation=d;let g=Ta(r,l);return fo(r,g),{floorId:n.floorId,changed:c()!==s,rowIds:o,gap:g}}var et=Go(require("polygon-clipping"),1),go=100,bo=512,Gt=8192,Io=64,ho=1e7,k=1e-7;function vo(e,t){return Math.abs(e.x-t.x)<=k&&Math.abs(e.y-t.y)<=k}function Co(e){let t=e.map(n=>({x:n.x,y:n.y}));for(;t.length>1&&vo(t[0],t[t.length-1]);)t.pop();return t}function _e(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 Oo(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),c=q(n,o,t);return(i>k&&a<-k||i<-k&&a>k)&&(r>k&&c<-k||r<-k&&c>k)?!0:Math.abs(i)<=k&&_e(n,e,t)||Math.abs(a)<=k&&_e(o,e,t)||Math.abs(r)<=k&&_e(e,n,o)||Math.abs(c)<=k&&_e(t,n,o)}function za(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)&&Oo(e[t],e[n],e[o],e[i]))return!0}}return!1}function po(e,t){return e.some((n,o)=>t.some((i,a)=>Oo(n,e[(o+1)%e.length],i,t[(a+1)%t.length])))}function Kt(e,t){return!t.some((n,o)=>_e(e,n,t[(o+1)%t.length]))&&F(e,t,void 0)}function tt(e,t,n){let o=Co(e);if(o.length<3||o.length>bo||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>ho||Math.abs(i.y)>ho||vo(i,o[(a+1)%o.length]))||Math.abs(me(o))<=k||za(o))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${t}; Join Areas accepts 3\u2013${bo} finite vertices per ring.`,{gaAreaId:n,ring:t});return o}function Ba(e){let t=tt(e.points,"outline",e.id),n=e.holes??[];if(!Array.isArray(n)||n.length>Io)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((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=>Kt(c,t))||po(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(po(a,o[c])||Kt(a[0],o[c])||Kt(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 We(e){return e.map(t=>[t.x,t.y])}function yo(e){return Co(e.map(([t,n])=>({x:t,y:n})))}function mo(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 Ua(e){return e.reduce((t,n)=>t+(mo(n[0]??[])-n.slice(1).reduce((o,i)=>o+mo(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 wo(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 So(e){return $t({categoryKey:e.categoryKey,displayLabel:wo(e,"displayLabel",80),displayType:wo(e,"displayType",24),referenceInventorySource:e.referenceInventorySource??null})}function xo(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 Po(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>go)throw new u("invalid_operation",`Join Areas supports at most ${go} areas at once`);let i=o.map(O=>n.objects.find(_=>_.type==="gaArea"&&_.id===O)),a=o.filter((O,_)=>!i[_]);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 c=So(r[0]),s=r.find(O=>So(O)!==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=ve(e).objectToSection,d=l.get(r[0].id)??"__ungrouped__",g=r.find(O=>(l.get(O.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 b=r.reduce((O,_)=>{if(!Number.isInteger(_.capacity)||_.capacity<1||_.capacity>ne)throw new u("invalid_operation",`GA area ${_.id} has invalid capacity`,{gaAreaId:_.id});return O+_.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 f=B(e).reduce((O,_)=>O+te(_),0);if(f>de)throw new u("invalid_operation",`Chart inventory exceeds the ${de}-unit publication limit`,{inventory:f});let p=r.map(Ba),m=p.reduce((O,_)=>O+_.outer.length+_.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 _=p.flatMap(Q=>Q.holes.map(at=>[We(at)]));_.length&&(x=et.default.difference(x,..._));let V=p.findIndex(Q=>{let at=[We(Q.outer),...Q.holes.map(We)];return Ua(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 v=yo(x[0][0]),h=x[0].slice(1).map(yo),y=v.length+h.reduce((O,_)=>O+_.length,0);if(h.length>Io||y>Gt)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:h.length,vertexCount:y});tt(v,"outline",r[0].id),h.forEach(O=>tt(O,"cutout",r[0].id));let w=new Map(n.objects.map((O,_)=>[O.id,_])),S=r.slice().sort((O,_)=>Ha(xo(O,w.get(O.id)??Number.MAX_SAFE_INTEGER),xo(_,w.get(_.id)??Number.MAX_SAFE_INTEGER))),I=S[0],R=structuredClone(e),G=C(R,n.floorId),N=G.objects.find(O=>O.type==="gaArea"&&O.id===I.id);N.points=structuredClone(v),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=ve(R).objectToSection.get(I.id)??"__ungrouped__";if(K!==d)throw new u("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:d,afterSectionId:K});let 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 _=Y(O);if(_.length!==O.capacity||_.some(V=>$.has(V)))throw new u("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:O.id});_.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 A=new Set(r.map(O=>O.id));for(let O of B(e).filter(_=>_.type==="gaArea"&&!A.has(_.id))){let _=Y(O).find(V=>$.has(V));if(_)throw new u("invalid_operation","A stable GA inventory identity is already owned by another area",{label:_,gaAreaId:O.id})}let it=S.slice(1).map(O=>O.id);return{floorId:n.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:it,sourceAreaCount:S.length,capacity:b,inventorySegmentCount:P.length,outerVertexCount:v.length,holeCount:h.length,sectionId:d,points:v,...h.length?{holes:h}:{},segments:P}}function Va(e,t){let{segments:n,...o}=Po(e,t);return o}function qa(e,t){let n=Po(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}}function Xa(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 g=r.labelStyle[d];if(g!=null&&typeof g!="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&&!Gn.includes(r.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!Kn.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&&!$n.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=>!At(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.labelStyle!==void 0){let g={...l.labelStyle};r.labelStyle.size===null?delete g.size:r.labelStyle.size!==void 0&&(g.size=r.labelStyle.size),r.labelStyle.color===null?delete g.color:r.labelStyle.color!==void 0&&(g.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete g.fontFamily:r.labelStyle.fontFamily!==void 0&&(g.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete g.bold:r.labelStyle.bold!==void 0&&(g.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete g.italic:r.labelStyle.italic===!0&&(g.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete g.underline:r.labelStyle.underline===!0&&(g.underline=!0),Object.keys(g).length?l.labelStyle=g: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,At(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),b=Number.isFinite(g)?g/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,b)):r.cornerRadius}JSON.stringify(l)!==d&&(He(l),s=!0)}return{floorId:n.floorId,changed:s,shapeIds:o}}function _o(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 Ja(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"?_o(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),b=Math.min(...d),f=Math.max(...d),p=Math.min(...g),m=Math.max(...g);return{cx:(b+f)/2,cy:(p+m)/2,width:Math.max(1,f-b),height:Math.max(1,m-p)}})();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 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(c=>c.stageId);if(new Set(o).size!==o.length)throw new u("invalid_operation","Stage ids must be unique");let i=new Set(an.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:_o(s)}}),r=!1;for(let c of a)c.box&&(c.shape.points=sn({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 Mo(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 Ao(e,t){let n=Mo(e),o=Mo(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&&Za(c.evidence,s.evidence))continue;let l=s?.target??c?.target;l&&a.push({...l,operation:Wa(s?.evidence),...c?{before:c.evidence}:{},...s?{after:s.evidence}:{}})}return a}function es(e,t){return Ao(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 Me(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 c=he(e.validUntil,40,"validUntil")??(e.modelLevel==="generated"?void 0:Bt(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=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}:{},...c?{validUntil:c}:{},...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(Me(e,t)??null),i=rt(e,t,n),a=JSON.stringify(Me(e,t)??null);return ye(t,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function ss(e,t){let n=Me(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=Me(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 c=t.basisSha256??e.confidenceBasisSha256;c&&(r.basisSha256=c);let s=JSON.stringify(n),l=rt(e,t,r);return ye(t,{changed:s!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function ls(e,t){let n=Me(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});
|
|
1
|
+
"use strict";var To=Object.create;var Le=Object.defineProperty;var Fo=Object.getOwnPropertyDescriptor;var No=Object.getOwnPropertyNames;var Do=Object.getPrototypeOf,Go=Object.prototype.hasOwnProperty;var Ko=(e,t)=>{for(var n in t)Le(e,n,{get:t[n],enumerable:!0})},qt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of No(t))!Go.call(e,i)&&i!==n&&Le(e,i,{get:()=>t[i],enumerable:!(o=Fo(t,i))||o.enumerable});return e};var $o=(e,t,n)=>(n=e!=null?To(Do(e)):{},qt(t||!e||!e.__esModule?Le(n,"default",{value:e,enumerable:!0}):n,e)),zo=e=>qt(Le({},"__esModule",{value:!0}),e);var gs={};Ko(gs,{COLORBLIND_SAFE_PALETTE:()=>kt,ChartOperationError:()=>u,DEFAULT_FLOOR_HEIGHT_STEP_M:()=>It,DEFAULT_SECTION_CORNER_SMOOTHING:()=>gt,MAX_BUYER_IMAGE_URL_LENGTH:()=>lr,MAX_FLOOR_BASE_HEIGHT_M:()=>$e,addArcFanRows:()=>Qi,addBookableGridArray:()=>Ra,addBoothArray:()=>ia,addChartCategory:()=>Xn,addChartFloor:()=>Pr,addChartZone:()=>jr,addGAArea:()=>oa,addRowBlock:()=>ea,addTableArray:()=>ra,applyPolygonHole:()=>fi,applyReferenceScanRows:()=>Ca,applySectionCornerSmoothing:()=>xi,applySectionOutlineShaping:()=>Gn,applySectionRowFit:()=>di,approveConfidenceEvidence:()=>us,arcFanInputForGroup:()=>Qn,assignSectionInventoryCategory:()=>hi,automaticPlacementCenter:()=>qi,clearConfidenceEvidence:()=>ds,confidenceEvidenceChangeRequiresPublish:()=>os,confidenceEvidenceChanges:()=>Lo,confirmReferenceCategoryOutputColor:()=>Mi,convertGeneratedSectionToPolygon:()=>yi,countCoveredInventory:()=>Xe,familyCategoryLabel:()=>Jn,gaAreaFootprint:()=>eo,groupRowsAsSegmented:()=>aa,insertSeatingBlock:()=>ii,isSafeBuyerImageUrl:()=>dn,joinGAAreas:()=>Ya,mergeRows:()=>$a,mirrorFirstFloor:()=>Ce,normalizeBuyerImageUrl:()=>Z,normalizeDraftEvidence:()=>Eo,parseSeatRefId:()=>Aa,pickColorblindSafeCategoryColor:()=>qn,planCreationCategory:()=>Yn,previewArcFanRows:()=>Et,previewBookableGridArray:()=>Oa,previewGeneratedSectionPolygonConversion:()=>Nn,previewJoinGAAreas:()=>Ja,previewPolygonHole:()=>Ye,previewRemovePolygonHole:()=>En,previewRowCubicPath:()=>jn,previewSectionRowFit:()=>Ln,reassignColorblindSafeCategoryColors:()=>Ai,relabelChartRows:()=>ri,removeChartCategory:()=>zi,removeChartFloor:()=>Mr,removeChartObjects:()=>ni,removeChartZone:()=>kr,removePolygonHole:()=>gi,renameChartFloor:()=>_r,renameDirectSeatImportCategory:()=>Oi,reorderChartCategories:()=>Ri,replaceArcFanRows:()=>Zi,replaceRowBlock:()=>la,resetSeatOverrides:()=>La,resizeShapes:()=>Za,resolveCreationCategory:()=>Gi,retractConfidenceEvidence:()=>fs,seatRefId:()=>Ae,sectionInventorySelectionSummary:()=>Fn,setConfidenceEvidence:()=>ls,setRowBlockSpacing:()=>Ba,splitRow:()=>za,straightenAndSpaceRows:()=>Ua,transformSectionBoundary:()=>mi,transformSectionBoundaryObject:()=>Dn,ungroupSegmentedRow:()=>sa,updateBooths:()=>ei,updateCategoryDefinitions:()=>Vn,updateChartFloorBaseHeight:()=>Ar,updateChartTheme:()=>Hi,updateChartZones:()=>Lr,updateGAAreas:()=>ti,updateRowCubicPath:()=>si,updateRows:()=>ka,updateSeatOverrides:()=>Kt,updateSectionExactPath:()=>wi,updateSectionMetadata:()=>pi,updateSegmentedRow:()=>ca,updateShapes:()=>Qa,updateStageKinds:()=>Wa,updateTables:()=>Wr,updateTextObjects:()=>oi,updateViewFromSeatFallback:()=>Vi});module.exports=zo(gs);var Xt=e=>Math.max(1,e.fontSize*.6+(e.letterSpacing??0));function Bo(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/Xt(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 Jt(e){let t=e.background?.padding??0,n=e.text.split(/\r?\n/),o=Math.max(1,...n.map(c=>c.length))*Xt(e),i=e.width??o+t*2,a=Math.max(1,i-t*2),r=Bo(e,a);return{width:i,height:r*e.fontSize*(e.lineHeight??1.2)+t*2,lineCount:r,padding:t}}var ps=Math.PI/180;function D(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function lt(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function Yt(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 ke(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[Yt(e,.5)];let o=Array.from({length:n+1},(s,l)=>Yt(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],b=g===d?0:(l-d)/(g-d);r.push({x:o[c-1].x+(o[c].x-o[c-1].x)*b,y:o[c-1].y+(o[c].y-o[c-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 we(e,t,n){return Math.max(t,Math.min(n,e))}function Uo(e){return we(e,0,1)}function Qt(e){let t=Uo(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 Ho(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 Ee(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 Vo(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 ut(e,t=2){if(!Ee(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=Ho(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=D(i,a.control1)+D(a.control1,a.control2)+D(a.control2,a.end),c=Math.max(2,Math.ceil(r/n));for(let s=1;s<=c;s+=1)o.push(Vo(i,a,s/c))}i=a.end}return D(o[o.length-1],o[0])<=1e-4&&o.pop(),o}function en(e,t,n){return ft(e,i=>({x:i.x+t,y:i.y+n}))}function ft(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 gt=45,dt=150,qo=60;function Xo(e){let t=gt/100;if(e<=t)return dt;let n=Math.min(1,(e-t)/(1-t));return dt-n*(dt-qo)}var Zt=.5523;function Wt(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&&Wt(t[t.length-1],o)||(t.push({x:o.x,y:o.y}),n.push(i)))});t.length>1&&Wt(t[0],t[t.length-1]);)t.pop(),n.pop();return{points:t,sourceIndex:n}}var Yo=.5,Qo=4/3;function Zo(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*Qo;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 tn(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,c=new Array(i).fill(0);if(r?.length)for(let w=0;w<i;w+=1){let S=r[o[w]];c[w]=Number.isFinite(S)?Math.min(100,Math.max(-100,S))/100:0}let s=c.some(w=>Math.abs(w)>1e-6);if(a<=0&&!s)return null;let l=t.wideAngleThresholdDeg??Xo(a),d=[];for(let w=0;w<i;w+=1)d[w]=D(n[w],n[(w+1)%i]);let g=new Array(i).fill(0);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],P=n[(w+1)%i],G={x:S.x-I.x,y:S.y-I.y},N={x:P.x-I.x,y:P.y-I.y},H=Math.hypot(G.x,G.y),K=Math.hypot(N.x,N.y);if(H<=1e-9||K<=1e-9)continue;let R=Math.min(1,Math.max(-1,(G.x*N.x+G.y*N.y)/(H*K))),$=Math.acos(R)*180/Math.PI;if($<l)continue;let M=Qt(($-l)/(180-l));g[w]=a*M*.5*Math.min(H,K)}for(let w=0;w<i;w+=1){let S=(w+1)%i,I=g[w]+g[S];if(I>d[w]&&I>1e-9){let P=d[w]/I;g[w]*=P,g[S]*=P}}let b=new Array(i),f=new Array(i);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],P=n[(w+1)%i];if(g[w]<=1e-6){b[w]={...I},f[w]={...I};continue}let G=D(I,S)||1,N=D(I,P)||1;b[w]={x:I.x+(S.x-I.x)/G*g[w],y:I.y+(S.y-I.y)/G*g[w]},f[w]={x:I.x+(P.x-I.x)/N*g[w],y:I.y+(P.y-I.y)/N*g[w]}}if(g.every(w=>w<=1e-6)&&!s)return null;let p=[],m={...f[0]},x=m,v=(w,S)=>{if(D(x,w)<=1e-9)return;let I=c[S];Math.abs(I)>1e-6?p.push(Zo(x,w,I*Yo*d[S])):p.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let S=w%i,I=n[S];v(b[S],(w-1)%i),g[S]>1e-6&&D(b[S],f[S])>1e-9&&(p.push({kind:"bezier",control1:lt(b[S],I,Zt),control2:lt(f[S],I,Zt),end:{...f[S]}}),x=f[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 Ee(y)?y:null}var nn="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Wo="ABCDEFGHJKLMNPQRSTUVWXYZ",er="abcdefghijklmnopqrstuvwxyz";function on(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 tr(e,t){let n=t.startAt-1,o=e+n;if(t.scheme==="numbers")return String(o+1);let i=t.skipAmbiguous?Wo:nn;return on(o,i)}function bt(e,t=!1){let n=t?er:nn;return on(Math.max(0,Math.floor(e)-1),n)}var nr=[[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 rn(e){if(!Number.isFinite(e)||e<=0)return String(e);let t=Math.floor(e),n="";for(let[o,i]of nr)for(;t>=o;)n+=i,t-=o;return n}function an(e,t){let n=e.length;return e.map((o,i)=>{let a=t.reverse?n-1-i:i;return{...o,label:tr(a,t)}})}function or(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 ht(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),p=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}${p}`}let l=a==="odd"||a==="even"?2:i,d=c!=null&&Number.isFinite(c)?c-(s-1)*l:n,g=o==="center"?or(s)[t]:o==="rtl"?s-1-t:t,b;switch(a){case"odd":{let f=d%2===1?d:d+1;b=String(f+g*2);break}case"even":{let f=d%2===0?d:d+1;b=String(f+g*2);break}case"roman":b=rn(d+g*i);break;case"letters-upper":b=bt(d+g*i,!1);break;case"letters-lower":b=bt(d+g*i,!0);break;default:b=String(d+g*i);break}return`${r}${b}`}function rr(e){return{...e.canonical,seatCount:e.totalSeats,label:e.displayLabel,displayLabel:e.displayLabel}}function Se(e,t,n){return n?.label??`${e.label}-${ht(e,t)}`}function sn(e,t,n,o){if(o?.displayLabel)return o.displayLabel;if(!n)return`${e.displayLabel||e.label}-${ht(e,t)}`;let i=rr(n),a=n.displayOffset+t;return`${n.displayLabel}-${ht(i,a)}`}var cn=[{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 ir=Math.PI*2;function ar(e,t,n,o,i,a){return{x:i+e*n-t*o,y:a+e*o+t*n}}function ln(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=[],b=(f,p)=>{g.push({x:f,y:p})};switch(t){case"rect":{b(-l,-d),b(l,-d),b(l,d),b(-l,d);break}case"rounded":{let f=Math.min(i,a)*.18,p=5,m=(x,v,h)=>{for(let y=0;y<=p;y++){let w=h+y/p*(Math.PI/2);b(x+f*Math.cos(w),v+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;b(-l,-d),b(l,-d);let p=24;for(let m=0;m<=p;m++){let x=m/p,v=l-x*i,h=d+f*(1-Math.pow(2*v/i,2));b(v,h)}break}case"thrust":{let f=i*.18,p=a*1.1;b(-l,-d),b(l,-d),b(l,d),b(f,d),b(f,d+p),b(-f,d+p),b(-f,d),b(-l,d);break}case"runway":{let f=i*.1,p=a*3;b(-l,-d),b(l,-d),b(l,d),b(f,d),b(f,d+p),b(-f,d+p),b(-f,d),b(-l,d);break}case"round":case"oval-cricket":{for(let p=0;p<40;p++){let m=p/40*ir;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 f of sr(l,d,l*(8.5/60),d*(8.5/30)))b(f.x,f.y);break}case"track-athletics":{for(let f of cr(l,d))b(f.x,f.y);break}}return g.map(f=>ar(f.x,f.y,c,s,n,o))}function sr(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 cr(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}var lr=2e6,dr=/^data:image\/(?:png|jpe?g|webp|gif|avif);base64,[a-z0-9+/]+={0,2}$/i,ur=/[\s"'<>`\\]/;function dn(e){if(typeof e!="string"||!e||e.length>2e6||e!==e.trim())return!1;if(e.startsWith("data:"))return dr.test(e);if(ur.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 dn(t)?t:null}function xe(e){return e?e.accessibility?.length?e.wheelchairSpaceType&&!e.accessibility.includes("wheelchair")?["wheelchair",...e.accessibility]:e.accessibility:e.wheelchairSpaceType?["wheelchair"]:e.accessible?["wheelchair"]:[]:[]}var Fe=Math.PI/180,fr=9,ae=16;function yt(e,t,n,o){let i=n*Fe,a=Math.cos(i),r=Math.sin(i);return{x:o.x+e*a-t*r,y:o.y+e*r+t*a}}function Ie(e){let{seatCount:t,seatSpacing:n,curve:o,rotation:i,origin:a}=e,r=[];if(e.path)return ke(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(yt(l*n,0,i,a));return r}let c=o/(t-1)*Fe,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),b=-s+s*Math.cos(d);r.push(yt(g,b,i,a))}return r}function gr(e){let t=new Map;if(e.overrides)for(let n of e.overrides)t.set(n.index,n);return t}function br(e,t){let n=gr(e);return Ie(e).map((o,i)=>{let a=n.get(i),r=xe(a),c=Se(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:sn(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 br(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 hr(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 pr(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,b,f)=>{let p=o.get(d),m=xe(p),x=p?.label??`${e.label}-${d+1}`,v=e.displayLabel??e.label;return{index:d,label:x,displayLabel:p?.displayLabel??`${v}-${d+1}`,x:g+(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,...f?{side:f}:{}}};if(e.shape==="round"){let d=(e.radius??40)+ae,g=e.rotation*Fe,b=Math.max(0,Math.min(360,e.seatArc??360));if(b>=360||n===1){for(let x=0;x<n;x++){let v=g+x/n*2*Math.PI;t.push(i(x,e.center.x+d*Math.cos(v),e.center.y+d*Math.sin(v)))}return t}let f=b*Fe,p=(2*Math.PI-f)/2,m=g+p;for(let x=0;x<n;x++){let v=m+x/(n-1)*f;t.push(i(x,e.center.x+d*Math.cos(v),e.center.y+d*Math.sin(v)))}return t}let a=e.width??80,r=e.height??50,c=hr(e),s=["top","bottom","left","right"],l=0;for(let d of s){let g=c[d];for(let b=0;b<g;b++){let f,p;d==="top"?(f=-a/2+(b+.5)*a/g,p=-r/2-ae):d==="bottom"?(f=-a/2+(b+.5)*a/g,p=r/2+ae):d==="left"?(f=-a/2-ae,p=-r/2+(b+.5)*r/g):(f=a/2+ae,p=-r/2+(b+.5)*r/g);let m=yt(f,p,e.rotation,e.center);t.push(i(l++,m.x,m.y,d))}}return t}function W(e){return pr(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 gn(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 un(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 yr(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 F(e,t,n){return un(e,t)&&!(n??[]).some(o=>un(e,o)||yr(e,o))}function pt(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 pt(e.points);case"section":return pt(e.outline);case"text":return{x:e.position.x,y:e.position.y};case"shape":return e.points&&e.points.length?pt(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 fn(e,t){return e.length===t.length&&e.every((n,o)=>n.x===t[o].x&&n.y===t[o].y)}function mr(e,t){if(e.type!=="gaArea"||!fn(e.points,t.outline))return!1;let n=e.holes??[],o=t.holes??[];return n.length===o.length&&n.every((i,a)=>fn(i,o[a]))}function bn(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&&(mr(t,r)||F(i,r.outline,r.holes))):void 0)??n.find(r=>F(i,r.outline,r.holes))}function T(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 Te=40;function hn(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 B(e))if(s.type==="row"){let l=new Map((s.overrides??[]).map(d=>[d.index,d]));Ie(s).forEach((d,g)=>{let b=l.get(g);b?.skip||c(d.x+(b?.dx??0),d.y+(b?.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+fr,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=Jt(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-Te,y:i-Te,width:a-o+Te*2,height:r-i+Te*2}}var wr=36,Sr=160;function pn(e,t=360){let n=we(Math.round(Number.isFinite(e)?e:1),1,40),o=we(Number.isFinite(t)?t:360,120,360);return Math.round(we(n*4*(360/o),wr,Sr))}var ve=[{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"}],Ns=new Map(ve.map(e=>[e.key,e]));var xr=[{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"}],Ds=new Map(xr.map(e=>[e.key,e]));var se=8,mt=24,Ir=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],Gs=new Set(Ir);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=T(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 vr(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 Cr(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=Cr(vr(t),22);return n.length>=3?n:null}function Ne(e,t){let n=C(e,t),o=T(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 yn=24,mn=80;function wt(e,t){let n=e.normalize("NFKC").trim();if(n.length>yn)throw new u("invalid_operation",`${t} displayed type must be at most ${yn} characters`);return n}function De(e,t){if(e.displayType===void 0)return!1;let n=wt(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>mn)throw new u("invalid_operation",`${t} displayed label must be at most ${mn} characters`);return n?(e.displayLabel=n,!1):(delete e.displayLabel,!0)}function k(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 wn(e,t){if(!Number.isFinite(e)||e<se||e>mt)throw new u("invalid_operation",`${t} label size must be from ${se} to ${mt}`)}function le(e,t){e.size!==void 0&&e.size!==null&&wn(e.size,t),e.color!==void 0&&e.color!==null&&k(e.color,`${t} label color`)}function Ge(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&&wn(n.size,t),n.color!==void 0&&k(n.color,`${t} label color`))}function Ke(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=k(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 St(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 xt(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 J=Math.PI/180,X=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}function Ce(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 Or=0,$e=120,It=4;function Rr(e){if(!Number.isFinite(e)||e<Or||e>$e)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function Pr(e,t){let n=T(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($e,(e.floors.length-1)*It),r=Math.min($e,a+It),c=A(e,"floor",t.idFactory,new Set);return e.floors.push({id:c,name:o,baseHeightM:r,objects:[],focalPoint:{...e.focalPoint}}),Ce(e),{changed:!0,floorId:c,floorCount:e.floors.length,baseHeightM:r}}function _r(e,t){let n=T(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 Ar(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});Rr(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 Mr(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 Ce(e);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:T(e).length}}function jr(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:St(e,t.label),color:k(t.color,"Zone color"),...t.focalPoint?{focalPoint:xt(t.focalPoint,"Zone focal point")}:{}};return(e.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function Lr(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=St(a,s.patch.label,d.id)),s.patch.color!==void 0&&(d.color=k(s.patch.color,"Zone color")),s.patch.focalPoint!==void 0&&(d.focalPoint=xt(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 kr(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=T(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,Ce(e),{changed:!0,zoneId:t.zoneId,clearedSectionIds:i,zoneCount:e.zones?.length??0}}var ze=[{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 Be(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 Sn="__sl_ga__",ne=1e5,de=1e5;function Er(e,t){return`${Sn}${encodeURIComponent(e)}__${t+1}`}function vt(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(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 Ue(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}]:[]:vt(e)?e.inventorySegments.map(n=>({...n})):[]}function Y(e){return Ue(e).flatMap(t=>Array.from({length:t.count},(n,o)=>Er(t.sourceAreaId,t.startIndex+o)))}function Ct(e,t){if(e.inventorySegments===void 0||t===e.capacity)return e.inventorySegments;if(t<e.capacity)return;let n=Ue(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 He(e){return e.startsWith(Sn)}var Tr="__ungrouped__";function Fr(e){return e.type==="row"?z(e).map(t=>t.label):e.type==="table"?W(e).map(t=>t.label):e.type==="booth"?gn(e).map(t=>t.label):e.type==="gaArea"?Y(e):[]}function Nr(e){return e.type==="row"||e.type==="table"||e.type==="booth"||e.type==="gaArea"}function Oe(e){let t=B(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:Tr,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let r of t){if(!Nr(r))continue;let c=Fr(r);if(c.length===0)continue;let s=bn(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 Re(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 Dr(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 xn(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 Gr(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 In=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[oe.balcony],sectionLabel:"Balcony",build:()=>[Re("blk-b0","A",-45,18,24,"balcony",18),Re("blk-b1","B",-15,20,24,"balcony",18),Re("blk-b2","C",15,22,24,"balcony",18),Re("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)=>Re(`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:()=>[xn("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)=>Dr(`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:()=>[xn("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:()=>[Gr("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 vn(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 Cn="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",On=[{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:Cn},{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:Cn},{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(On.map(e=>[e.key,e]));function Rn(e){return typeof e=="string"&&Kr.has(e)}var cc=On.map(e=>e.key);function Ot(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 Pn(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=en(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 $r(e,t){return Math.abs(e.x-t.x)<=1e-7&&Math.abs(e.y-t.y)<=1e-7}function Pe(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function Ve(e,t,n){let o=Pe(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 zr(e,t,n,o){let i=Pe(e,t,n),a=Pe(e,t,o),r=Pe(n,o,e),c=Pe(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&&Ve(n,e,t)||Math.abs(a)<=1e-7&&Ve(o,e,t)||Math.abs(r)<=1e-7&&Ve(e,n,o)||Math.abs(c)<=1e-7&&Ve(t,n,o)}function Br(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 Ur(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)&&zr(e[t],e[n],e[o],e[i]))return!0}}return!1}function _n(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)=>$r(t,e[(n+1)%e.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(Br(e))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:Ur(e)?{ok:!1,code:"self_intersection",message:"Polygon edges cannot cross or touch each other."}:{ok:!0}}function qe(e){return(e.type==="shape"||e.type==="text")&&(e.referenceAnnotationSource?.kind==="direct-landmark-v1"||e.referenceAnnotationSource?.kind==="direct-stage-v1")&&(e.referenceAnnotationSource.ownership="organizer"),e}function Wr(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),r.fill!==void 0&&r.fill!==null&&(r.fill=k(r.fill,"Table surface color"));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 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 I=r.seatCountsBySide[S];if(!Number.isInteger(I)||I<0||I>40)throw new u("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let w=h.reduce((S,I)=>S+r.seatCountsBySide[I],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(c&&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.automaticRadius!==void 0&&typeof r.automaticRadius!="boolean")throw new u("invalid_operation","automaticRadius must be true or false");if(r.shape==="rect"&&r.automaticRadius===!0)throw new u("invalid_operation","Automatic radius can be used only with round tables");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"),g=De(r,"Table"),b=i.map(h=>{if(h.seatCountsBySide&&!s&&(c||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),r.fill===null&&delete y.fill,y.shape==="round")delete y.seatCountsBySide,y.automaticRadius===!0?y.radius=pn(y.seatCount,y.seatArc):delete y.automaticRadius;else{if(r.automaticRadius===!0)throw new u("invalid_operation",`Table "${y.label}" is rectangular and cannot use automatic radius`,{tableId:y.id});delete y.automaticRadius}if(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"],S=w.reduce((I,P)=>I+y.seatCountsBySide[P],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(I=>y.seatCountsBySide[I]>0)}}else y.radius??=40;if((y.bookAsWhole||y.variableOccupancy)&&He(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(b.map(h=>[h.id,h])),p=new Set(o),m=new Map;for(let h of T(e))for(let y of h.objects){let w=y.type==="table"?f.get(y.id)??y:y,S=[];w.type==="row"?S=z(w).map(I=>I.label):w.type==="table"?S=w.bookAsWhole||w.variableOccupancy?[w.label]:W(w).map(I=>I.label):w.type==="booth"?S=[w.label]:w.type==="gaArea"&&(S=Y(w));for(let I of S){let P=m.get(I);if(P&&(p.has(P)||p.has(w.id)))throw new u("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:I,conflictingObjectIds:[P,w.id]});m.set(I,P??w.id)}}let x=!1,v=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","fill","seatCountsBySide","overrides","automaticRadius"];for(let[h,y]of i.entries()){let w=b[h],S=JSON.stringify(y);for(let I of v)I in w||delete y[I];Object.assign(y,w),JSON.stringify(y)!==S&&(x=!0)}return{floorId:n.floorId,changed:x,tableIds:o}}function ei(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(p=>p.type==="booth"&&p.id===f)),a=o.filter((f,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 c=(f,p,m,x)=>{if(p!==void 0&&(!Number.isFinite(p)||p<m||p>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=_n(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=ce(r,"Booth"),g=De(r,"Booth"),b=!1;for(let f of i){let p=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)!==p&&(b=!0)}return{floorId:n.floorId,changed:b,boothIds:o}}function ti(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&&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 c=ce(r,"GA area"),s=De(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&&Ct(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),b=r.capacity===void 0?d.inventorySegments:Ct(d,r.capacity);Object.assign(d,r),b!==void 0&&(d.inventorySegments=b),c&&delete d.displayLabel,s&&delete d.displayType,JSON.stringify(d)!==g&&(l=!0)}return{floorId:n.floorId,changed:l,gaAreaIds:o}}function Xe(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 ni(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+te(s),0),remainingObjectCount:n.objects.length}}function oi(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=k(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=k(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(!Rn(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&&(qe(l),s=!0)}return{floorId:n.floorId,changed:s,textIds:o}}function ri(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(b=>n.objects.find(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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((b,f)=>b.origin.y-f.origin.y||b.origin.x-f.origin.x),c=b=>b.segmentedRow?.displayLabel??b.displayLabel??b.label,s=an(r.map(b=>({label:c(b)})),t.options),l=t.displayType==null?void 0:t.displayType.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,24),d=l===void 0||l===""||l==="Row"?t.displayType===void 0?void 0:null:l,g=!1;return r.forEach((b,f)=>{let p=s[f].label.normalize("NFKC").replace(/\s+/g," ").trim();if(c(b)!==p&&(g=!0,b.segmentedRow?b.segmentedRow.displayLabel=p:b.displayLabel=p),d!==void 0){if(d===null){b.displayType!==void 0&&(g=!0,delete b.displayType);return}b.displayType!==d&&(g=!0,b.displayType=d)}}),{floorId:n.floorId,changed:g,rows:r.map(b=>({id:b.id,displayLabel:c(b),...b.displayType?{displayType:b.displayType}:{}}))}}function ii(e,t){let n=In.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),Pn(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=vn(d.label);g!=null&&(l=Math.max(l,g+1))}for(let d of r)d.label=U(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} `,b=d?Number.parseInt(d[2],10):1;do b++;while(c.has(`${g}${b}`));l.label=`${g}${b}`}"label"in l&&l.label&&c.add(l.label)}o.objects.push(...a);let s=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),s=d.id}}return{floorId:o.floorId,blockKey:n.key,createdIds:[...a.map(l=>l.id),...s?[s]:[]],sectionId:s}}function ai(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=ke(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 jn(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=ai(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 si(e,t){let n=jn(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 ci(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 li(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=ci(t,n);return o?{x:o[0],y:o[1]}:null}function An(e){let t=((e+180)%360+360)%360-180;return t===-180&&(t=180),t}function Ln(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=T(e).find(f=>f.id===n.floorId),r=t.mode==="outline"?li(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"&&F(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 p=Math.hypot(f.origin.x-r.x,f.origin.y-r.y);if(p<=f.seatSpacing/2+1e-6){l.push(f.id);continue}let m=2*Math.asin(f.seatSpacing/(2*p))/J,x=z(f),v=Math.atan2(f.origin.x-r.x,f.origin.y-r.y)/J,y=(f.curve!==0?Math.sign(f.curve):x.length>1&&Math.sign(An(Math.atan2(x[1].x-r.x,x[1].y-r.y)/J-v))||1)*m*(f.seatCount-1);if(Math.abs(y)>320){l.push(f.id);continue}let w=-v,S=f.curve+(y-f.curve)*g,I=f.rotation+An(w-f.rotation)*g,P={...f,curve:S,rotation:I},N=z(P).map((H,K)=>Math.hypot(H.x-x[K].x,H.y-x[K].y));d.push({rowId:f.id,fromCurve:f.curve,targetCurve:y,resultCurve:S,fromRotation:f.rotation,resultRotation:I,rmsMovement:Math.sqrt(N.reduce((H,K)=>H+K**2,0)/N.length),maxMovement:Math.max(...N)})}let b=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:b.length?b.reduce((f,p)=>f+p,0)/b.length:0,maxMovement:d.length?Math.max(...d.map(f=>f.maxMovement)):0}}function di(e,t){let n=Ln(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 kn(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),c=q(n,o,t);return i*a<-1e-9&&r*c<-1e-9}function Mn(e,t){return e.some((n,o)=>{let i=e[(o+1)%e.length];return t.some((a,r)=>kn(n,i,a,t[(r+1)%t.length]))})}function ui(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)&&kn(e[t],e[(t+1)%e.length],e[n],e[(n+1)%e.length]))return!1;return!0}function Je(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 Ye(e,t){let{target:n,object:o,outer:i}=Je(e,t.floorId,t.objectId),a=structuredClone(t.points);if(!ui(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(Mn(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(Mn(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 s=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:c,vertexCount:a.length,excludedObjectIds:s.map(l=>l.id),excludedInventoryUnits:Xe(n.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function fi(e,t){let n=Ye(e,t),{object:o}=Je(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 En(e,t){let{target:n,object:o}=Je(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:Xe(n.objects.filter(r=>r.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function gi(e,t){let n=En(e,t),{object:o}=Je(e,n.floorId,n.objectId);return o.holes.splice(t.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function bi(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 Tn(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 Fn(e,t){let n=C(e,t.floorId),o=Tn(n.objects,t.sectionIds),i=Oe(Ne(e,n.floorId)),a=new Map(i.sections.map(f=>[f.id,f])),r=new Map(n.objects.map(f=>[f.id,f])),c=o.logicalSectionIds.flatMap(f=>a.get(f)?.objectIds??[]),s=new Set,l=new Set(o.logicalSectionIds),d=new Set(n.objects.filter(f=>f.type==="section"&&l.has(f.logicalSectionId??f.id)).flatMap(f=>f.editor?.defaultCategoryKey?[f.editor.defaultCategoryKey]:[]));for(let f of c){let p=r.get(f);if(p)if(p.type==="row"||p.type==="table")for(let m of Be(p).keys())s.add(m);else(p.type==="booth"||p.type==="gaArea")&&s.add(p.categoryKey)}let g=o.logicalSectionIds.every(f=>(a.get(f)?.seatCount??0)>0),b=o.logicalSectionIds.every(f=>a.get(f)?.objectIds.some(p=>{let m=r.get(p);return m?.type==="row"||m?.type==="table"||m?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:c,categoryApplicable:g,...g&&s.size===1?{categoryKey:[...s][0]}:!g&&!c.length&&d.size===1?{categoryKey:[...d][0]}:{},categoryMixed:g?s.size!==1:!c.length&&d.size>1,viewApplicable:b}}function hi(e,t){j(e,t.categoryKey);let n=Fn(e,t);if(!n.categoryApplicable&&n.objectIds.length)throw new u("invalid_operation","A mixed selection of empty and occupied logical sections cannot be assigned together",{logicalSectionIds:n.logicalSectionIds});let o=C(e,n.floorId),i=new Set(n.objectIds),a=!1,r=0,c=new Set(n.logicalSectionIds);for(let s of o.objects)s.type!=="section"||!c.has(s.logicalSectionId??s.id)||s.editor?.defaultCategoryKey!==t.categoryKey&&(s.editor={...s.editor,defaultCategoryKey:t.categoryKey},a=!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 l=s.overrides.flatMap(d=>{if(d.categoryKey===void 0)return[d];let g={...d};return delete g.categoryKey,r++,a=!0,Object.keys(g).some(b=>b!=="index")?[g]:[]});l.length?s.overrides=l:delete s.overrides}return{...n,changed:a,categoryKey:t.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function pi(e,t){let n=C(e,t.floorId),o=Tn(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=bi(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&&Ge(a.labelPresentation,"Section"),a.labelStyle!==void 0&&le(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=k(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,b=!1;for(let f of o.sections){let p=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)!==p&&(b=!0,g.add(f.id))}for(let f of d){let p=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=Ke(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)!==p&&(b=!0,g.add(f.id))}return{floorId:n.floorId,changed:b,sectionIds:i,affectedSectionIds:[...g]}}function Nn(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 yi(e,t){let n=Nn(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 Dn(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=b=>{let f=b.x-g.x,p=b.y-g.y;return{x:g.x+f*l-p*d,y:g.y+f*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"?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=ft(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 mi(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,...Dn(o,t.transform)}}function wi(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(!Ee(i))throw new u("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=ut(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 Si(e){return e.geometry?null:e.sourceOutline?.length?e.sourceOutline:e.outlinePath?null:e.outline?.length?e.outline:null}function xi(e,t){return Gn(e,{floorId:t.floorId,sectionIds:t.sectionIds,cornerSmoothing:t.strength})}function Gn(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(h=>h.type==="section"&&h.id===c);if(!s||!Si(s))continue;let d=structuredClone(s);a.set(s.id,{section:s,snapshot:d});let g=JSON.stringify(s),b=(s.sourceOutline??s.outline).map(h=>({...h})),f=Math.min(100,Math.max(0,t.cornerSmoothing??s.cornerSmoothing??0)),m=(t.edgeCurvature===void 0?s.edgeCurvature:t.edgeCurvature??void 0)?.map(h=>Math.min(100,Math.max(-100,h))),x=m?.some(h=>Math.abs(h)>.5)===!0,v=f>.5||x?tn(b,{cornerSmoothing:f,...x?{edgeCurvature:m}:{}}):null;v?(s.sourceOutline=b,s.outlinePath=v,s.outline=ut(v),f>.5?s.cornerSmoothing=f:delete s.cornerSmoothing,x?s.edgeCurvature=[...m]:delete s.edgeCurvature):(s.outline=b,delete s.outlinePath,delete s.sourceOutline,delete s.cornerSmoothing,delete s.edgeCurvature);for(let h=0;h<(s.holes?.length??0);h+=1)Ye(e,{floorId:n.floorId,objectId:s.id,points:s.holes[h],holeIndex:h});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 Pt=.15,_t=1.6;var Ii=/^#?([\da-f]{3}|[\da-f]{6})$/i;function Mt(e){let t=Ii.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 jt(e,t){let n=a=>{let r=Mt(a);if(!r)return null;let c=h=>{let y=h/255;return y<=.04045?y/12.92:((y+.055)/1.055)**2.4},s=c(r[0]),l=c(r[1]),d=c(r[2]),g=(.4124*s+.3576*l+.1805*d)/.95047,b=.2126*s+.7152*l+.0722*d,f=(.0193*s+.1192*l+.9505*d)/1.08883,p=h=>h>.008856?Math.cbrt(h):7.787*h+16/116,m=p(g),x=p(b),v=p(f);return[116*x-16,500*(m-x),200*(x-v)]},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 At(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Kn(e){return .2126*At(e[0])+.7152*At(e[1])+.0722*At(e[2])}function Qe(e,t){let n=Mt(e),o=Mt(t);if(!n||!o)return null;let i=Kn(n),a=Kn(o);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var $n=["butt","round","square"],zn=["miter","round","bevel"],Bn=["none","arrow"];function Lt(e){return e==="line"||e==="polyline"}var Un=[{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}}],Hc=Un.map(e=>e.key),vi=new Map(Un.map(e=>[e.key,e]));function _e(e){return typeof e=="string"&&vi.has(e)}var Ci=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 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.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&&!_e(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 b=g.id.trim(),f=g.name.normalize("NFKC").trim(),p=f.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(!f||f.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:f});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new u("invalid_operation",`Ticket tier ${b} price must be from 0 to 1000000`,{categoryKey:a,tierId:b});if(g.restriction!=null&&!Ci.has(g.restriction))throw new u("invalid_operation",`Ticket tier ${b} has an unknown restriction`,{categoryKey:a,tierId:b});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 ${b} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:b})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new u("invalid_operation",`Ticket tier ${b} must use a three-letter ISO currency`,{categoryKey:a,tierId:b});if(g.applicability!=null){let m=g.applicability.seatLabels?.map(v=>v.normalize("NFKC").trim()),x=g.applicability.accessibility;if(m&&(!m.length||m.length>1e4||m.some(v=>!v||v.length>160)||new Set(m).size!==m.length)||x&&(!x.length||x.some(v=>!ve.some(h=>h.key===v))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${b} has invalid seat applicability`,{categoryKey:a,tierId:b});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 ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b});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 ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b})}l.add(b),d.add(p)}}}return o}function Vn(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 b={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?b.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete b.buyerMessage,b})),delete c.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 Oi(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 Ri(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=ue(n.map((s,l)=>{let d=structuredClone(c.get(s));return s!==o[l]&&delete d.referenceDirectSeatImport,d})),{changed:!0,categoryKeys:n,categories:e.categories}}var kt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Hn(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 Pi(e,t){let n=Hn(e),o=Hn(t);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var _i=3600;function qn(e,t,n=kt){return n.find(i=>e.every(a=>Pi(i,a)>=_i))??n[t%n.length]}function Ai(e,t){let n=t?.palette??kt;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 Vn(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 Mi(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,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let r=ue(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 Xn(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()})),...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 ji=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],Li={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function ki(e,t){let n=Li[e];return!n||!t.includes(n)?t:[n,...t.filter(o=>o!==n)]}var Ei=26;function Ti(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 Fi(e,t,n){let o=r=>e.every(c=>{let s=jt(r,c);return s==null||s>=Ei}),i=r=>{let c=Qe(r,"#12151d"),s=Qe(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=Ti(r,.62,c);if(o(s)&&i(s))return s}return n}function Jn(e,t){let n=ze.find(i=>i.objectType===t).creationWord;return`${e.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||e.trim()} \u2013 ${n}`}function Ni(e){let t=new Map;for(let n of T(e))for(let o of n.objects){let i=ze.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of Be(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 Di(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 Yn(e,t,n){let o=Ni(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=ze.find(l=>l.objectType===n),c=a?Jn(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:Di(e,c)}}function Gi(e,t,n,o){let i=Yn(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??ji,r=e.categories.map(d=>d.color),c=i.suggestColor?.(r.map(d=>d.toLowerCase()))??qn(r,e.categories.length),s=Fi(r,ki(t,a),c),l=Xn(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 $i(e,t){let n=new Set;for(let o of T(e))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===t&&n.add(i.id),i.type==="section"&&i.editor?.defaultCategoryKey===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 zi(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=$i(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 Bi=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Ui=["seat","deck","shell","fascia"];function Hi(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 Bi){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=k(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<Pt||n.seatScale>_t)throw new u("invalid_operation",`Theme seatScale must be from ${Pt} to ${_t}`);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 c of Ui){let s=n.venue3d[c];s===null?delete a[c]:s!==void 0&&(a[c]=k(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: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 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 qi(e,t){let n=Ne(e,t.floorId),o=hn(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 Ze(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 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 Xi(e,t,n){let o=n*J;return{x:e.x+t*Math.sin(o),y:e.y+t*Math.cos(o)}}function Ji(e,t,n,o){let i=Math.abs(o-n)*J,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let g=e.aisleGaps[l];if(!g)return[];let b=g/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 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 Yi(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 We(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=Ji(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(([p,m])=>r*Math.abs(l-s)*J*(m-p)),b=e.fit==="fixed-count"?Yi(g,e.seatsPerRow):g.map(p=>Math.max(2,Math.round(p/e.seatPitch)+1)),f=e.seatLabelStart;d.forEach(([p,m],x)=>{let v=s+(l-s)*p,h=s+(l-s)*m;e.facing==="outward"&&([v,h]=[h,v]);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-v)*J/(y-1),S=2*r*Math.sin(w/2),I={type:"row",id:n(i,x),label:U(e.rowLabelStart+i),origin:Xi(e.center,r,v),rotation:-v,curve:h-v,seatCount:y,seatSpacing:S,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(I),f+=y})}return o}function Et(e,t){let n=Ze(e,t),o=C(e,t.floorId),i=We(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 Qi(e,t){let n=Ze(e,t),o=C(e,t.floorId),i=new Set,a=A(e,"fan",t.idFactory,i),r=We(n,a,()=>A(e,"r",t.idFactory,i)),c=Et(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=ee(r);g&&(s=A(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 Qn(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 b=g.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(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=Ze(e,c),l=new Set(We(s,t.groupId,(g,b)=>`${g}:${b}`).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 Zi(e,t){Qn(e,{floorId:t.floorId,groupId:t.groupId});let n=Ze(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=We(n,t.groupId,(m,x)=>r.get(`${m}:${x}`)??A(e,"r",t.idFactory,c)),l=Et(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=ee(s);m&&(g={type:"section",id:a?.id??A(e,"sec",t.idFactory,c),label:d,outline:m,arcFanGroupId:t.groupId})}let b=new Set([...i.map(m=>m.id),...a?[a.id]:[]]),f=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(f)?f:p.length,0,...s,...g?[g]:[]),o.objects.splice(0,o.objects.length,...p),{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 Wi(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 Zn(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 ea(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=Wi(e),c=Ot(t.rotation??0),s=t.curve??0,l=t.style,d=l?A(e,"rowblock",t.idFactory,a):void 0,g=l?Zn({style:l,origin:t.origin,rotation:c,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,rowGap:n,seatSpacing:o,curve:s}):void 0,b={x:Math.cos(c*X),y:Math.sin(c*X)},f={x:-b.y,y:b.x},p=Array.from({length:t.rowCount},(v,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+f.x*h*n+b.x*y,y:t.origin.y+f.y*h*n+b.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:h,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,origin:{...t.origin},rotation:c,rowGap:n,seatSpacing:o,curve:s,signature:g}),w});i.objects.push(...p);let m=null,x=t.sectionLabel?.trim();if(x){let v=ee(p);if(v){let h={type:"section",id:A(e,"sec",t.idFactory,a),label:x,outline:v};i.objects.push(h),m=h.id}}return{floorId:i.floorId,rowIds:p.map(v=>v.id),sectionId:m,createdIds:[...p.map(v=>v.id),...m?[m]:[]]}}function Wn(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 ta(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 na=456;function eo(e){let t=Math.sqrt(Math.max(1,e)*na);return{width:Math.round(t*1.027),height:Math.round(t/1.027)}}function oa(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}=eo(t.capacity),r=ta(e,(t.label??"General Admission").trim()||"General Admission"),c={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(c),{floorId:n.floorId,gaAreaId:c.id,label:r,createdIds:[c.id]}}function ra(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=Wn(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:A(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 ia(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=Wn(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:A(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 aa(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(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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(b=>b.segmentedRow);if(c.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:c.map(b=>b.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(b=>b.type==="row"?[b.segmentedRow?.groupId,b.rowBlockGeneration?.groupId].filter(f=>!!f):[])),d="";for(let b=0;b<100;b+=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((b,f)=>{b.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 sa(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 ca(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 la(e,t){let n=C(e,t.floorId),o=n.objects.filter(R=>R.type==="row"&&R.rowBlockGeneration?.groupId===t.groupId).sort((R,$)=>R.rowBlockGeneration.rowIndex-$.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((R,$)=>{let M=R.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,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,b=Number.isFinite(t.rotation??i.rotation)?Ot(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(R=>Number.isFinite(R)&&R>0)||!Number.isFinite(g)||!Number.isFinite(b)||!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 p=Zn({style:r,origin:f,rotation:b,rowCount:c,seatsPerRow:s,rowGap:l,seatSpacing:d,curve:g}),m={x:Math.cos(b*X),y:Math.sin(b*X)},x={x:-m.y,y:m.x},v=new Map(o.map(R=>[R.rowBlockGeneration.rowIndex,R])),h=new Set,y=new Set(n.objects.filter(R=>R.type==="row").filter(R=>!o.includes(R)).map(R=>R.label)),w=n.objects.filter(R=>R.type==="row").length,S=()=>{for(;y.has(U(w));)w+=1;let R=U(w);return y.add(R),w+=1,R},I=[],P=[];for(let R=0;R<c;R+=1){let $=r==="intertwined"&&R%2===1?d/2:0,M=v.get(R);M||(M={type:"row",id:A(e,"r",t.idFactory,h),label:S(),origin:{...f},rotation:b,curve:g,seatCount:s,seatSpacing:d,categoryKey:o[0].categoryKey},P.push(M.id)),M.origin={x:f.x+x.x*R*l+m.x*$,y:f.y+x.y*R*l+m.y*$},M.rotation=b,M.curve=g,M.seatCount=s,M.seatSpacing=d,delete M.path,delete M.arcFanGeneration,M.overrides&&(M.overrides=M.overrides.filter(st=>st.index<s),M.overrides.length||delete M.overrides),M.rowBlockGeneration={kind:"row-block-v1",groupId:t.groupId,style:r,rowIndex:R,rowCount:c,seatsPerRow:s,origin:{...f},rotation:b,rowGap:l,seatSpacing:d,curve:g,signature:p},I.push(M)}let G=o.slice(c).map(R=>R.id),N=Math.min(...o.map(R=>n.objects.indexOf(R))),H=new Set(o.map(R=>R.id)),K=n.objects.filter(R=>!H.has(R.id));return K.splice(N,0,...I),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:t.groupId,rowIds:I.map(R=>R.id),createdRowIds:P,removedRowIds:G,changed:a!==JSON.stringify(I)||P.length>0||G.length>0}}function Tt(e){return e.normalize("NFKC").replace(/\s+/g," ").trim()}function Ft(e,t){let n="";for(let o of e){if(n.length+o.length>t)break;n+=o}return n.trim()}function Nt(e){return Ft(Tt(e),40)}function to(e,t=39){return Ft(Tt(e),Math.max(1,t))}function fe(e,t=80){return Ft(Tt(e),Math.max(1,t))}function no(e){return fe(e).toLocaleLowerCase("en")}function Dt(e){return no(e)}function oo(e){return new Map((e??[]).map(t=>[t.index,t]))}function da(e){let t=oo(e.overrides),n=[];for(let o=0;o<e.seatCount;o+=1){let i=t.get(o);i?.skip||n.push(Se(e,o,i))}return n}function ua(e){if(e.bookAsWhole||e.variableOccupancy)return[e.label];let t=oo(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 fa(e){return e.type==="row"?[e.label,...da(e)]:e.type==="table"?[e.label,...ua(e)]:e.type==="booth"?[e.label]:e.type==="gaArea"?[e.label,...Y(e)]:[]}function ro(e,t){let n=new Set;for(let o of e)if(!t?.has(o.id))for(let i of fa(o)){let a=Dt(i);a&&n.add(a)}return n}function ga(e,t){if(!Number.isInteger(t)||t<1)return[];let n={label:e,seatCount:t},o=[Dt(e)];for(let i=0;i<t;i+=1)o.push(Dt(Se(n,i)));return o.filter(Boolean)}function io(e,t,n){let o=ga(t,n);if(!o.length||o.some(i=>e.has(i)||He(i)))return!1;for(let i of o)e.add(i);return!0}var ba=1e-6,ha=160,pa=.001,ya=1e-5;function ge(e){if(typeof e!="string")return;let t=e.normalize("NFKC").replace(/\s+/g," ").trim();if(!t||t.length>ha)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 ao(e){return typeof e=="string"&&to(e)||void 0}function so(e,t){if(e.seatCount!==t.seatCount||e.seatCount<1||!(Gt(e.origin)&&Gt(t.start)&&Gt(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=pa+Math.max(1,i)*ya;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<=ba)return!0;let r=i/(e.seatCount-1);if(Math.abs(e.seatSpacing-r)>a)return!1;let c=Math.atan2(t.end.y-t.start.y,t.end.x-t.start.x)*180/Math.PI,s=Math.abs(((e.rotation-c)%360+540)%360-180),l=Math.max(.001,Math.atan2(a,Math.max(1,i))*180/Math.PI);return s<=l}function Gt(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}var ma=300;function wa(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=Nt(i),r=0;return()=>{for(;a&&r<4096;r+=1){let c=`${a}-${U(r)}`;if(!t.has(c))return t.add(c),r+=1,c}return o()}}}function Sa(e){let t=ro(B(e));return(n,o)=>{let i=fe(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,c=r?`${fe(i,80-r.length)}${r}`:i;if(c&&io(t,c,o))return c}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function xa(e){return{ordinaryFor:wa(e),direct:Sa(e)}}function co(e,t,n){return e.type==="row"&&e.referenceScan?.assetId===t&&(!n||e.referenceScan.sectionId===n)}function Ia(e,t,n){let o=new Map;for(let r of t.sections)if(!(n&&r.sectionId!==n)&&r.sourceGroupId)for(let[c,s]of r.rows.entries()){let l=ge(`${r.sourceGroupId}:${c}`),d=l&&ge(s.directSourceRowId)===l?l:void 0;d&&o.set(d,o.has(d)?null:s)}let i=new Map;for(let r of e){let c=ge(r.referenceScan?.directSourceRowId);if(!c){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 s=i.get(c)??[];s.push(r),i.set(c,s)}let a=new Map;for(let[r,c]of i){let s=c.filter(b=>b.overrides?.length);if(!s.length)continue;let l=o.get(r),d=s[0],g=d.overrides;if(c.length!==1||s.length!==1||!g||!l||!so(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:c.map(b=>b.id)});a.set(r,structuredClone(g))}return a}function lo(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 va(e,t,n,o,i,a,r){let c=e.sectionId?t.find(d=>d.type==="section"&&d.id===e.sectionId):void 0;if(c){let d=lo(t,n,r).filter(g=>F(L(g),c.outline,c.holes));if(d.length)return{skip:{sectionId:c.id,name:e.name,reason:"section_not_empty",objectIds:d.map(g=>g.id)},rows:[],seats:0}}let s=[],l=0;for(let[d,g]of e.rows.entries()){let b=Math.min(ma,Math.max(1,Math.round(g.seatCount)));if(!Number.isFinite(b)||b<1)continue;let f=g.end.x-g.start.x,p=g.end.y-g.start.y,m=Math.hypot(f,p),x=b>1&&m>0?m/(b-1):o>0?o:24;if(!Number.isFinite(x)||x<=0)continue;let v=m>0?Math.atan2(p,f)*180/Math.PI:0,h=e.sourceGroupId?ge(`${e.sourceGroupId}:${d}`):void 0,y=h&&ge(g.directSourceRowId)===h?h:void 0,w=y?ao(g.directReviewedSuffix):void 0,S=e.sourceGroupId&&g.rowLabel?fe(g.rowLabel):"",I=e.sourceGroupId&&g.rowDisplayLabel?fe(g.rowDisplayLabel):"",P=!!e.sourceGroupId&&g.rowDisplayLabel==="";s.push({label:S?a(S,b):i(),displayLabel:I||(P?"":String(d+1)),origin:{x:g.start.x,y:g.start.y},rotation:v,seatCount:b,seatSpacing:x,...y?{directSourceRowId:y}:{},...w?{directReviewedSuffix:w}:{}}),l+=b}return{skip:null,rows:s,seats:l}}function Ca(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 c=a?t.sections.find(h=>h.sectionId===a.id&&h.seatCount>0):void 0;if(a&&c){let h=lo(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:c.name,reason:"section_not_empty",objectIds:h.map(y=>y.id)}]}}let s=o.objects.filter(h=>co(h,i,a?.id)),l=Ia(s,t,a?.id),d=[],g=o.objects.filter(h=>co(h,i,a?.id)?(d.push(h.id),!1):!0);o.objects.splice(0,o.objects.length,...g);let b=[],f=[],p=[],m=new Set,x=0,v=xa(e);for(let h of t.sections){if(a&&h.sectionId!==a.id)continue;let y=va(h,o.objects,i,t.seatPitch,v.ordinaryFor(h.name),v.direct,a?.id);if(y.skip){f.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!==void 0?{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:f}}function uo(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(p=>(p.type==="table"||p.type==="booth")&&p.id===f)),a=o.filter((f,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(f=>f.type!==r))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[f,p,m]of[["rows",t.rows,30],["columns",t.columns,30]])if(!Number.isInteger(p)||p<1||p>m)throw new u("invalid_operation",`${f} must be a whole number from 1 to ${m}`);for(let[f,p]of[["stepX",t.stepX],["stepY",t.stepY]])if(!Number.isFinite(p)||p<30||p>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,p)=>f+(p.type==="table"?p.seatCount:1),0),g=(e.floors?.length?e.floors.flatMap(f=>f.objects):e.objects).reduce((f,p)=>f+(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*(c-1);if(g+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:c,createdCount:s,addedInventory:b,resultingInventory:g+b,provenanceRemovedCount:i.filter(f=>!!f.referenceInventorySource).length*(c-1)}}}function Oa(e,t){return uo(e,t).preview}function Ra(e,t){let{target:n,sources:o,preview:i}=uo(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 b=Math.max(2,g),f=m=>{let x=`-${m}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},p=f(b);for(;r.has(p);)p=f(++b);return r.add(p),p},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 b of o){let f=structuredClone(b);f.id=A(e,f.type,t.idFactory,a),f.label=s(b.label,l),f.center={x:b.center.x+g*t.stepX,y:b.center.y+d*t.stepY},delete f.referenceInventorySource,c.push(f)}}return n.objects.push(...c),{...i,createdIds:c.map(d=>d.id)}}function Pa(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=k(t.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var _a=new Set(ve.map(e=>e.key));function Ae(e){return`${e.rowId}:${e.index}`}function Aa(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 Ma(e){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,_e(e.glyph)||delete e.glyph;let t=xe(e);if(t.length?e.accessibility=t:delete e.accessibility,delete e.accessible,e.commercial){let n=e.commercial.note?.normalize("NFKC").trim(),o={};typeof e.commercial.restrictedView=="boolean"&&(o.restrictedView=e.commercial.restrictedView),typeof e.commercial.obstructedView=="boolean"&&(o.obstructedView=e.commercial.obstructedView),typeof e.commercial.premium=="boolean"&&(o.premium=e.commercial.premium),n&&(o.note=n),Object.keys(o).length?e.commercial=o: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 ja(e){return Object.keys(e).every(t=>t==="index")}function fo(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=Ae(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 Kt(e,t){let n=fo(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&&!_e(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=>!_a.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:Ae(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 c=n.owners.get(a.rowId),s=JSON.stringify(c.overrides??[]),l=c.overrides??(c.overrides=[]),d=l.find(b=>b.index===a.index);d||(d={index:a.index},l.push(d));let g=d.viewFromSeatUrl;for(let b of o){let f=t.patch[b];if(b==="wheelchairSpaceType"&&f==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(f==null)delete d[b];else if(b==="accessibility")d.accessibility=[...new Set(f)],delete d.accessible;else if(b==="commercial")d.commercial={...d.commercial,...f};else if(b==="labelStyle"){let p=Pa(d.labelStyle,f);p?d.labelStyle=p:delete d.labelStyle}else Object.assign(d,{[b]: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}`),Ma(d),ja(d)&&(c.overrides=l.filter(b=>b!==d)),c.overrides?.length||delete c.overrides,JSON.stringify(c.overrides??[])!==s&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(Ae)}}function La(e,t){let n=fo(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(Ae)}}function ka(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:c,labelRotation:s,labelStyleShape:l,displayLabel:d,displayType:g,...b}=t.patch,f=d===void 0?{}:{displayLabel:d},p=ce(f,"Row"),m=g===void 0?void 0:wt(g,"Row");if(r!==void 0&&le(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");b.labelPresentation!==void 0&&Ge(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}),v=!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(I=>I.index<h.seatCount),h.overrides.length||(h.overrides=void 0)),S){let I=L(h);h.origin={x:h.origin.x+S.x-I.x,y:h.origin.y+S.y-I.y}}if(JSON.stringify(h)!==y&&(v=!0),x(h)!==w&&(delete h.arcFanGeneration,delete h.rowBlockGeneration),r!==void 0){let I=JSON.stringify(h.labelPresentation??null),P=Ke(h.labelPresentation,r);P?h.labelPresentation=P:delete h.labelPresentation,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(c!==void 0){let I=JSON.stringify(h.labelPresentation??null),P=h.labelPresentation?structuredClone(h.labelPresentation):{};P.positionPreset=c,P.visible=c!=="none",delete P.position,h.labelPresentation=P,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(s!==void 0||l!==void 0){let I=JSON.stringify(h.labelPresentation??null),P=h.labelPresentation?structuredClone(h.labelPresentation):{};s===null?delete P.rotation:s!==void 0&&(P.rotation=s),l!==void 0&&(P.style=l),h.labelPresentation=P,JSON.stringify(h.labelPresentation??null)!==I&&(v=!0)}if(m!==void 0){let I=h.displayType;m?h.displayType=m:delete h.displayType,h.displayType!==I&&(v=!0)}if(d!==void 0){let I=h.displayLabel;p?delete h.displayLabel:h.displayLabel=f.displayLabel,h.displayLabel!==I&&(v=!0)}}return{floorId:n.floorId,changed:v,rowIds:o}}var Ea=3;function et(e){return(e%360+360)%360}function Ta(e){let t=e.rotation*X;return{x:Math.cos(t),y:Math.sin(t)}}function Fa(e,t){let n=Math.abs(et(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 go(e){let t=0,n=0;for(let i of e){let a=2*i.rotation*X;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 Na(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 bo(e,t){let n=go(e),o={x:-n.y,y:n.x},i=L(e[0]),a=e.map(s=>({row:s,coord:be(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&&(Na(s.row,o.x*d,o.y*d),delete s.row.arcFanGeneration,delete s.row.rowBlockGeneration,c=!0)}),c}function Da(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,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 Ga(e){if(e.seatCount<2){e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration;return}let t=Ie(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=et(Math.atan2(a,i)/X)),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 $a(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(I=>I.type==="row"&&I.id===S)),a=o.filter((S,I)=>!i[I]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,c=r.filter(S=>S.path||S.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(S=>S.id)});let s=r[0],l=r.find(S=>Fa(S.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},b=Math.max(8,s.seatSpacing*.6),f=r.find(S=>Math.abs(be(S.origin,s.origin,g))>b);if(f){let S=Math.round(Math.abs(be(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 ${S} units from the first.`,{rowIds:[s.id,f.id]})}let p=r.slice().sort((S,I)=>be(S.origin,s.origin,d)-be(I.origin,s.origin,d)),m=p.reduce((S,I)=>S+I.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],v=[],h=0;for(let S of p){if(S.overrides)for(let I of S.overrides)v.push({...structuredClone(I),index:I.index+h});h+=S.seatCount}x.seatCount=m,x.curve=0,delete x.path,v.length?x.overrides=v: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 za(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=Ie(o),c=i>1?o.curve/(i-1):0,s=i-a,l={type:"row",id:A(e,"r",t.idFactory,new Set),label:Ka(n.objects,o.label),origin:{...r[a]},rotation:et(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 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:s,newLabel:l.label}}function Ba(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=bo(i,t.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:t.gap}}function Ua(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(f=>f.type==="row"&&f.id===b)),a=o.filter((b,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(b=>[b.origin,b.rotation,b.curve,b.path??null,b.seatSpacing])),s=c();for(let b of r)Ga(b);let l=go(r),d=et(Math.atan2(l.y,l.x)/X);for(let b of r)b.rotation=d;let g=Da(r,l);return bo(r,g),{floorId:n.floorId,changed:c()!==s,rowIds:o,gap:g}}var nt=$o(require("polygon-clipping"),1),ho=100,po=512,$t=8192,Co=64,yo=1e7,E=1e-7;function Oo(e,t){return Math.abs(e.x-t.x)<=E&&Math.abs(e.y-t.y)<=E}function Ro(e){let t=e.map(n=>({x:n.x,y:n.y}));for(;t.length>1&&Oo(t[0],t[t.length-1]);)t.pop();return t}function Me(e,t,n){let o=q(t,n,e);return Math.abs(o)>E?!1:e.x>=Math.min(t.x,n.x)-E&&e.x<=Math.max(t.x,n.x)+E&&e.y>=Math.min(t.y,n.y)-E&&e.y<=Math.max(t.y,n.y)+E}function Po(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),c=q(n,o,t);return(i>E&&a<-E||i<-E&&a>E)&&(r>E&&c<-E||r<-E&&c>E)?!0:Math.abs(i)<=E&&Me(n,e,t)||Math.abs(a)<=E&&Me(o,e,t)||Math.abs(r)<=E&&Me(e,n,o)||Math.abs(c)<=E&&Me(t,n,o)}function Ha(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)&&Po(e[t],e[n],e[o],e[i]))return!0}}return!1}function mo(e,t){return e.some((n,o)=>t.some((i,a)=>Po(n,e[(o+1)%e.length],i,t[(a+1)%t.length])))}function zt(e,t){return!t.some((n,o)=>Me(e,n,t[(o+1)%t.length]))&&F(e,t,void 0)}function ot(e,t,n){let o=Ro(e);if(o.length<3||o.length>po||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>yo||Math.abs(i.y)>yo||Oo(i,o[(a+1)%o.length]))||Math.abs(me(o))<=E||Ha(o))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${t}; Join Areas accepts 3\u2013${po} finite vertices per ring.`,{gaAreaId:n,ring:t});return o}function Va(e){let t=ot(e.points,"outline",e.id),n=e.holes??[];if(!Array.isArray(n)||n.length>Co)throw new u("invalid_operation",`GA area ${e.id} has too many cutouts to join`,{gaAreaId:e.id});let o=n.map(i=>ot(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=>zt(c,t))||mo(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(mo(a,o[c])||zt(a[0],o[c])||zt(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 tt(e){return e.map(t=>[t.x,t.y])}function wo(e){return Ro(e.map(([t,n])=>({x:t,y:n})))}function So(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 qa(e){return e.reduce((t,n)=>t+(So(n[0]??[])-n.slice(1).reduce((o,i)=>o+So(i),0)),0)}function Bt(e){if(e===void 0)return"undefined";if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(Bt).join(",")}]`;let t=e;return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${Bt(t[n])}`).join(",")}}`}function xo(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 Io(e){return Bt({categoryKey:e.categoryKey,displayLabel:xo(e,"displayLabel",80),displayType:xo(e,"displayType",24),referenceInventorySource:e.referenceInventorySource??null})}function vo(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 Xa(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}function _o(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>ho)throw new u("invalid_operation",`Join Areas supports at most ${ho} areas at once`);let i=o.map(O=>n.objects.find(_=>_.type==="gaArea"&&_.id===O)),a=o.filter((O,_)=>!i[_]);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 c=Io(r[0]),s=r.find(O=>Io(O)!==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=Oe(e).objectToSection,d=l.get(r[0].id)??"__ungrouped__",g=r.find(O=>(l.get(O.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 b=r.reduce((O,_)=>{if(!Number.isInteger(_.capacity)||_.capacity<1||_.capacity>ne)throw new u("invalid_operation",`GA area ${_.id} has invalid capacity`,{gaAreaId:_.id});return O+_.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 f=B(e).reduce((O,_)=>O+te(_),0);if(f>de)throw new u("invalid_operation",`Chart inventory exceeds the ${de}-unit publication limit`,{inventory:f});let p=r.map(Va),m=p.reduce((O,_)=>O+_.outer.length+_.holes.reduce((V,Q)=>V+Q.length,0),0);if(m>$t)throw new u("invalid_operation",`Join Areas supports at most ${$t} source vertices`,{vertexCount:m});let x;try{let O=p.map(Q=>[tt(Q.outer)]);if(x=nt.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 _=p.flatMap(Q=>Q.holes.map(ct=>[tt(ct)]));_.length&&(x=nt.default.difference(x,..._));let V=p.findIndex(Q=>{let ct=[tt(Q.outer),...Q.holes.map(tt)];return qa(nt.default.intersection(ct,x))<=E});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 v=wo(x[0][0]),h=x[0].slice(1).map(wo),y=v.length+h.reduce((O,_)=>O+_.length,0);if(h.length>Co||y>$t)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:h.length,vertexCount:y});ot(v,"outline",r[0].id),h.forEach(O=>ot(O,"cutout",r[0].id));let w=new Map(n.objects.map((O,_)=>[O.id,_])),S=r.slice().sort((O,_)=>Xa(vo(O,w.get(O.id)??Number.MAX_SAFE_INTEGER),vo(_,w.get(_.id)??Number.MAX_SAFE_INTEGER))),I=S[0],P=structuredClone(e),G=C(P,n.floorId),N=G.objects.find(O=>O.type==="gaArea"&&O.id===I.id);N.points=structuredClone(v),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=Oe(P).objectToSection.get(I.id)??"__ungrouped__";if(K!==d)throw new u("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:d,afterSectionId:K});let R=[],$=new Set;for(let O of S){if(!vt(O))throw new u("invalid_operation",`GA area ${O.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:O.id});let _=Y(O);if(_.length!==O.capacity||_.some(V=>$.has(V)))throw new u("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:O.id});_.forEach(V=>$.add(V)),R.push(...Ue(O))}if(R.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(_=>_.type==="gaArea"&&!M.has(_.id))){let _=Y(O).find(V=>$.has(V));if(_)throw new u("invalid_operation","A stable GA inventory identity is already owned by another area",{label:_,gaAreaId:O.id})}let st=S.slice(1).map(O=>O.id);return{floorId:n.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:st,sourceAreaCount:S.length,capacity:b,inventorySegmentCount:R.length,outerVertexCount:v.length,holeCount:h.length,sectionId:d,points:v,...h.length?{holes:h}:{},segments:R}}function Ja(e,t){let{segments:n,...o}=_o(e,t);return o}function Ya(e,t){let n=_o(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}}function Qa(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=k(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 g=r.labelStyle[d];if(g!=null&&typeof g!="boolean")throw new u("invalid_operation",`Stage label ${d} must be a boolean`)}}if(r.fill!==void 0&&r.fill!==null&&(r.fill=k(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:k(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&&!$n.includes(r.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!zn.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&&!Bn.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=>!Lt(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.labelStyle!==void 0){let g={...l.labelStyle};r.labelStyle.size===null?delete g.size:r.labelStyle.size!==void 0&&(g.size=r.labelStyle.size),r.labelStyle.color===null?delete g.color:r.labelStyle.color!==void 0&&(g.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete g.fontFamily:r.labelStyle.fontFamily!==void 0&&(g.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete g.bold:r.labelStyle.bold!==void 0&&(g.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete g.italic:r.labelStyle.italic===!0&&(g.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete g.underline:r.labelStyle.underline===!0&&(g.underline=!0),Object.keys(g).length?l.labelStyle=g: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,Lt(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),b=Number.isFinite(g)?g/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,b)):r.cornerRadius}JSON.stringify(l)!==d&&(qe(l),s=!0)}return{floorId:n.floorId,changed:s,shapeIds:o}}function Mo(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 Za(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"?Mo(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),b=Math.min(...d),f=Math.max(...d),p=Math.min(...g),m=Math.max(...g);return{cx:(b+f)/2,cy:(p+m)/2,width:Math.max(1,f-b),height:Math.max(1,m-p)}})();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 Wa(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(cn.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:Mo(s)}}),r=!1;for(let c of a)c.box&&(c.shape.points=ln({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 jo(e){let t=new Map;e.confidenceEvidence&&t.set("venue",{target:{scope:"venue"},evidence:e.confidenceEvidence});for(let n of T(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 rt(e){return Array.isArray(e)?e.map(rt):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,rt(n)]))}function ts(e,t){return JSON.stringify(rt(e))===JSON.stringify(rt(t))}function Ut(e){return!!e&&e.status!=="draft"&&e.status!=="retracted"}function ns(e){return e?e.status==="retracted"?"retract":Ut(e)?"approve":"set":"clear"}function Lo(e,t){let n=jo(e),o=jo(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&&ts(c.evidence,s.evidence))continue;let l=s?.target??c?.target;l&&a.push({...l,operation:ns(s?.evidence),...c?{before:c.evidence}:{},...s?{after:s.evidence}:{}})}return a}function os(e,t){return Lo(e,t).some(n=>Ut(n.before)||Ut(n.after))}var rs=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),is=new Set(["generated","geometry-verified","configuration-verified"]),as=new Set(["none","comparable-build-reference","actual-build-checked"]),ss=new Set(["clear","partial","obstructed"]);function Ht(e){return e.toISOString().slice(0,10)}function Vt(e,t){return typeof e=="string"&&e.normalize("NFKC").trim()===e&&e.length>0&&e.length<=t}function pe(e,t,n){if(!Vt(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 it(e,t,n){let o=n?[C(e,n)]:T(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 ko(e,t){let n=T(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 je(e,t){if(t.scope==="venue")return e.confidenceEvidence;if(t.scope==="floor")return ko(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=it(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=it(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 at(e,t,n){if(t.scope==="venue")return n?e.confidenceEvidence=n:delete e.confidenceEvidence,{};if(t.scope==="floor"){let i=ko(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=it(e,t.objectId,t.floorId);return Kt(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=it(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 cs(e){if(e===void 0)return;if(!e||typeof e!="object")throw new u("invalid_operation","Confidence evidence modeledTarget is invalid");if(!Vt(e.label,80)||!Vt(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(!ss.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 Eo(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(!rs.has(e.evidenceKind))throw new u("invalid_operation","Confidence evidence kind is invalid");if(!is.has(e.modelLevel))throw new u("invalid_operation","Confidence evidence model level is invalid");let n=e.realityLevel??"none";if(!as.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")??Ht(t),r=Date.parse(a);if(!Number.isFinite(r))throw new u("invalid_operation","Confidence evidence assessedAt is invalid");let c=he(e.validUntil,40,"validUntil")??(e.modelLevel==="generated"?void 0:Ht(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=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}:{},...c?{validUntil:c}:{},...l?{approvedByRole:l}:{},...he(e.sourceLabel,120,"sourceLabel")?{sourceLabel:e.sourceLabel}:{},...i?.length?{limitations:i}:{},...e.modeledTarget?{modeledTarget:cs(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 ls(e,t){let n=Eo(t.evidence,t.now),o=JSON.stringify(je(e,t)??null),i=at(e,t,n),a=JSON.stringify(je(e,t)??null);return ye(t,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function ds(e,t){let n=je(e,t);if(!n)return ye(t,{changed:!1});let o=at(e,t,void 0);return ye(t,{changed:!0,...o,evidenceId:n.evidenceId})}function us(e,t){let n=je(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:Ht(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=at(e,t,r);return ye(t,{changed:s!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function fs(e,t){let n=je(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=at(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});
|