@seatlayer/core 0.100.0 → 0.102.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/ar-TGXEBJUB.js +1 -0
- package/dist/be-JIDOHWF6.js +1 -0
- package/dist/bg-ODVJNCC2.js +1 -0
- package/dist/ca-3I7TMWYU.js +1 -0
- package/dist/{categoryInventory-DuOez0-4.d.cts → categoryInventory-7gSFTu0l.d.cts} +1 -1
- package/dist/{categoryInventory-DdJdJ4Og.d.ts → categoryInventory-hJxuFF9L.d.ts} +1 -1
- package/dist/chunk-254ABRJF.js +1 -0
- package/dist/{chunk-VWT44HBR.js → chunk-4DYJCT62.js} +1 -1
- package/dist/chunk-4R6TXHY2.js +1 -0
- package/dist/{chunk-D723OZEY.js → chunk-66T4EAUA.js} +1 -1
- package/dist/{chunk-GLGXP5I7.js → chunk-AFJWTB7L.js} +1 -1
- package/dist/chunk-COECA63Q.js +1 -0
- package/dist/chunk-EIV3CAGV.js +1 -0
- package/dist/chunk-FOIYJ5NT.js +1 -0
- package/dist/chunk-FUFRWRPM.js +1 -0
- package/dist/{chunk-KFVUBZMK.js → chunk-GPZFVQXV.js} +1 -1
- package/dist/{chunk-L34T3APU.js → chunk-GTRYL7YV.js} +1 -1
- package/dist/chunk-JRZHC75P.js +1 -0
- package/dist/chunk-KTMZ3QAO.js +1 -0
- package/dist/chunk-PHV2U54Y.js +1 -0
- package/dist/chunk-TAMY7HTV.js +1 -0
- package/dist/chunk-UEDS3HJ3.js +1 -0
- package/dist/{chunk-P4J57TK6.js → chunk-YPVYZYMH.js} +1 -1
- package/dist/chunk-ZS5YFXSE.js +1 -0
- package/dist/core/chart-ops/index.cjs +1 -1
- package/dist/core/chart-ops/index.d.cts +30 -9
- package/dist/core/chart-ops/index.d.ts +30 -9
- package/dist/core/chart-ops/index.js +1 -1
- package/dist/core/inventory/index.cjs +1 -1
- package/dist/core/inventory/index.d.cts +72 -5
- package/dist/core/inventory/index.d.ts +72 -5
- package/dist/core/inventory/index.js +1 -1
- package/dist/core/layout/index.cjs +1 -1
- package/dist/core/layout/index.d.cts +63 -6
- package/dist/core/layout/index.d.ts +63 -6
- package/dist/core/layout/index.js +1 -1
- package/dist/core/quality/index.cjs +1 -1
- package/dist/core/quality/index.d.cts +18 -4
- package/dist/core/quality/index.d.ts +18 -4
- package/dist/core/quality/index.js +1 -1
- package/dist/core/render-assets/index.cjs +1 -1
- package/dist/core/render-assets/index.d.cts +2 -2
- package/dist/core/render-assets/index.d.ts +2 -2
- package/dist/core/render-assets/index.js +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/cs-XXB624Z3.js +1 -0
- package/dist/cy-W2QNU2GO.js +1 -0
- package/dist/da-Q47YPK2E.js +1 -0
- package/dist/de-TS3DPLM5.js +1 -0
- package/dist/{el-ZPFVDCWA.js → el-3JQUH6DB.js} +1 -1
- package/dist/es-GP7VOX7S.js +1 -0
- package/dist/et-A22OMZ6V.js +1 -0
- package/dist/{eventConfigurations-DYn5XP3J.d.cts → eventConfigurations-BHIfPJJJ.d.cts} +1 -1
- package/dist/{eventConfigurations-BISNREZL.d.ts → eventConfigurations-I5UBS6r9.d.ts} +1 -1
- package/dist/fa-5MS3C6YX.js +1 -0
- package/dist/fi-OJLAOJO2.js +1 -0
- package/dist/fr-7ATOYJCF.js +1 -0
- package/dist/he-37LKRY5W.js +1 -0
- package/dist/hi-YXZ5EWK7.js +1 -0
- package/dist/hr-QFOPGLMR.js +1 -0
- package/dist/hu-RHRBK46E.js +1 -0
- package/dist/id-A5Q3MLSX.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +58 -17
- package/dist/index.d.ts +58 -17
- package/dist/index.js +1 -1
- package/dist/it-KG53QPQF.js +1 -0
- package/dist/ja-CC6EPUSN.js +1 -0
- package/dist/ko-7H4RGYFK.js +1 -0
- package/dist/ku-HFYWPSS4.js +1 -0
- package/dist/{labeling-CzuSxAkr.d.ts → labeling-2A31f781.d.cts} +11 -3
- package/dist/{labeling-owTTG6e0.d.cts → labeling-CDKZ9TO1.d.ts} +11 -3
- package/dist/localeLoaders-4YMC7FIZ.js +1 -0
- package/dist/lt-HQXE7W47.js +1 -0
- package/dist/lv-AN25XXPB.js +1 -0
- package/dist/ms-CWAYSF6E.js +1 -0
- package/dist/nl-63QBRZSZ.js +1 -0
- package/dist/no-RAPQMKWU.js +1 -0
- package/dist/pl-ILSTD4ZV.js +1 -0
- package/dist/pt-WF3US5D7.js +1 -0
- package/dist/{renderedQuality-BZycehrC.d.cts → renderedQuality-CwZ8hY-5.d.cts} +1 -1
- package/dist/{renderedQuality-DPElQ3-x.d.ts → renderedQuality-wDIiUId3.d.ts} +1 -1
- package/dist/{renderer-DnsIDiWN.d.cts → renderer-CdJx5l3B.d.ts} +12 -3
- package/dist/{renderer-DPKIlnuF.d.ts → renderer-D6ggv3bV.d.cts} +12 -3
- package/dist/ro-XR3HT6DE.js +1 -0
- package/dist/ru-TLJEWDPA.js +1 -0
- package/dist/{seatTypeIcons-dy3XQVWN.d.ts → seatTypeIcons-DMJX4rVN.d.cts} +2 -2
- package/dist/{seatTypeIcons-QwEebl3k.d.cts → seatTypeIcons-UpUTD8Xf.d.ts} +2 -2
- package/dist/{sections-DSIfnBJY.d.cts → sections-CempT5a0.d.cts} +5 -2
- package/dist/{sections-C8VTe6BN.d.ts → sections-lpdfwSdO.d.ts} +5 -2
- package/dist/{segmentedRowModel-CDvvJJ4-.d.cts → segmentedRowModel-Ddx5ol8T.d.cts} +1 -1
- package/dist/{segmentedRowModel-I8eYUQft.d.ts → segmentedRowModel-HwY4XuYa.d.ts} +1 -1
- package/dist/sk-OJC2EL3Z.js +1 -0
- package/dist/sl-7RGTVXCV.js +1 -0
- package/dist/sr-NHDJ54BS.js +1 -0
- package/dist/sv-ZODCCBCU.js +1 -0
- package/dist/{tableSizing-x8ADFtKS.d.cts → tableSizing-BJqAuJDg.d.cts} +3 -3
- package/dist/{tableSizing-0PwrOWi5.d.ts → tableSizing-C0zx97eg.d.ts} +3 -3
- package/dist/th-VCZA4MP5.js +1 -0
- package/dist/{ticketRestrictions-C8H-XJha.d.ts → ticketRestrictions-AU8UUmdL.d.ts} +39 -3
- package/dist/{ticketRestrictions-O-fv0Os6.d.cts → ticketRestrictions-DDQHiKF-.d.cts} +39 -3
- package/dist/tr-ROKZO3HC.js +1 -0
- package/dist/{types-DWx32xXH.d.cts → types-DL7qIUrD.d.cts} +85 -2
- package/dist/{types-DWx32xXH.d.ts → types-DL7qIUrD.d.ts} +85 -2
- package/dist/uk-LP2DPUHC.js +1 -0
- package/dist/vi-JDK3JRJR.js +1 -0
- package/dist/view3d/crossfade/panorama.d.cts +1 -1
- package/dist/view3d/crossfade/panorama.d.ts +1 -1
- package/dist/view3d/index.cjs +102 -60
- package/dist/view3d/index.d.cts +26 -5
- package/dist/view3d/index.d.ts +26 -5
- package/dist/view3d/index.js +100 -58
- package/dist/view3d/scene/scene.worker.cjs +1 -1
- package/dist/view3d/scene/scene.worker.js +1 -1
- package/dist/zh-Hans-P3GB3FAZ.js +1 -0
- package/dist/zh-Hant-YU4OKSFZ.js +1 -0
- package/package.json +1 -1
- package/dist/ar-Q44JP5JY.js +0 -1
- package/dist/be-CGFFSIQL.js +0 -1
- package/dist/bg-WOYK6OLH.js +0 -1
- package/dist/ca-77ZVI3X5.js +0 -1
- package/dist/chunk-23OTKCJU.js +0 -1
- package/dist/chunk-5BMXWOE7.js +0 -1
- package/dist/chunk-5ITK5236.js +0 -1
- package/dist/chunk-COOPHSHM.js +0 -1
- package/dist/chunk-CTIGUXXK.js +0 -1
- package/dist/chunk-HO4MFTVX.js +0 -1
- package/dist/chunk-HYEZPOZU.js +0 -1
- package/dist/chunk-N4J4CT6P.js +0 -1
- package/dist/chunk-QJXSZT3H.js +0 -1
- package/dist/chunk-UIMDB6GZ.js +0 -1
- package/dist/chunk-UISTXRO5.js +0 -1
- package/dist/cs-OSBZYCSR.js +0 -1
- package/dist/cy-ZCOJW2WH.js +0 -1
- package/dist/da-2PDK6JTR.js +0 -1
- package/dist/de-R5LLVFUU.js +0 -1
- package/dist/es-7YASJP32.js +0 -1
- package/dist/et-J4TV6KQL.js +0 -1
- package/dist/fa-4TEO7UGM.js +0 -1
- package/dist/fi-GIUDDKMH.js +0 -1
- package/dist/fr-J5J2XJLA.js +0 -1
- package/dist/he-OCEHSVUJ.js +0 -1
- package/dist/hi-EK5CTBW5.js +0 -1
- package/dist/hr-SLDTQOYC.js +0 -1
- package/dist/hu-2QNE77NO.js +0 -1
- package/dist/id-LGDAFQJK.js +0 -1
- package/dist/it-DT4Y3IYB.js +0 -1
- package/dist/ja-D5EY2XCQ.js +0 -1
- package/dist/ko-DD2NV45Q.js +0 -1
- package/dist/ku-KZCMVLBE.js +0 -1
- package/dist/localeLoaders-GGAKX22E.js +0 -1
- package/dist/lt-QWGTJ47Y.js +0 -1
- package/dist/lv-LYAIG3VK.js +0 -1
- package/dist/ms-XTF4KNGD.js +0 -1
- package/dist/nl-QEXY6XHS.js +0 -1
- package/dist/no-HCOXN2CN.js +0 -1
- package/dist/pl-BWY53TSD.js +0 -1
- package/dist/pt-2UJUBCPL.js +0 -1
- package/dist/ro-GGXOLTED.js +0 -1
- package/dist/ru-ZTFK3WCU.js +0 -1
- package/dist/sk-KU543Y2U.js +0 -1
- package/dist/sl-FT576R7A.js +0 -1
- package/dist/sr-WE3J46JE.js +0 -1
- package/dist/sv-YEAOPSEB.js +0 -1
- package/dist/th-BEBRDHJA.js +0 -1
- package/dist/tr-LOAHUPSH.js +0 -1
- package/dist/uk-2GMICSHN.js +0 -1
- package/dist/vi-TC5B6AUR.js +0 -1
- package/dist/zh-Hans-TSZWTZQY.js +0 -1
- package/dist/zh-Hant-TLB4FZYM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as tt}from"../../chunk-5N4H3KMR.js";import{a as d,b as C,c as F,d as P,e as Q,f as _e,g as qt,h as Oe,i as ne,j as L,k as oe,l as je,m as Ae,n as et,o as be,p as $,q,r as U,s as ee,t as Pe,u as Rr,v as _r,w as Or,x as jr,y as Ar,z as Pr}from"../../chunk-VWT44HBR.js";import{a as xe,b as Re,f as Jt}from"../../chunk-23OTKCJU.js";import{g as We,h as Ze}from"../../chunk-D723OZEY.js";import{c as Nt}from"../../chunk-N4J4CT6P.js";import{a as yt,b as ze,e as we,k as Be}from"../../chunk-HYEZPOZU.js";import{k as he}from"../../chunk-4N5CHKHD.js";import{i as $t,k as zt,l as Bt,m as Ut,q as Qe}from"../../chunk-TQN2VWQO.js";import{a as Se,d as wr,e as Ir,f as Tt,g as vr,h as Sr,i as Cr,j as xr}from"../../chunk-5BMXWOE7.js";import{b as Ce,c as W,e as Dt,f as Kt,g as Z,h as Xe,n as ge}from"../../chunk-HO4MFTVX.js";import{Ba as Ve,Ea as X,F as _t,Ia as He,J as ve,La as ue,Ma as M,Oa as E,P as Ot,Q as Je,Qa as T,R as jt,S as At,Sa as B,T as Gn,Wa as Mt,X as Pt,a as yr,b as mr,c as Y,e as Ue,q as mt,r as wt,ra as kt,s as It,t as vt,u as St,v as Ct,va as Et,w as Ie,x as xt,y as Rt,za as Lt}from"../../chunk-UISTXRO5.js";import{e as Ft,h as qe}from"../../chunk-5ITK5236.js";import{i as Gt,n as Ye}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function Lr(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:P(t,"zone",e.idFactory,new Set),label:et(t,e.label),color:L(e.color,"Zone color"),...e.focalPoint?{focalPoint:be(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function Mr(t,e){if(!e.updates.length)throw new d("invalid_operation","At least one zone update is required");let r=e.updates.map(c=>c.zoneId);if(new Set(r).size!==r.length)throw new d("invalid_operation","Zone ids must be unique");let o=new Map((t.zones??[]).map(c=>[c.id,c])),i=r.filter(c=>!o.has(c));if(i.length)throw new d("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),n=new Map((a.zones??[]).map(c=>[c.id,c]));for(let c of e.updates){if(!Object.keys(c.patch).length)throw new d("invalid_operation",`Zone ${c.zoneId} has no changes`);let f=n.get(c.zoneId);c.patch.label!==void 0&&(f.label=et(a,c.patch.label,f.id)),c.patch.color!==void 0&&(f.color=L(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(f.focalPoint=be(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:r,zones:r.map(c=>structuredClone(n.get(c)))}}function Tr(t,e){let r=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let o=T(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(o.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${o.length} section(s)`,{zoneId:e.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 t.zones.splice(r,1),t.zones.length||delete t.zones,Pe(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var te={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 pe(t,e,r,o,i,a,n=0){return{type:"row",id:t,label:e,origin:{x:-(o-1)*i/2,y:r},rotation:0,curve:n,seatCount:o,seatSpacing:i,categoryKey:a}}function $n(t,e,r,o,i,a){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function Vt(t,e,r,o,i,a){let n=r/2,s=o/2;return{type:"gaArea",id:t,label:e,points:[{x:-n,y:-s},{x:n,y:-s},{x:n,y:s},{x:-n,y:s}],capacity:i,categoryKey:a}}function zn(t,e,r,o,i){let a=r*2,n=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];n.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:n}}var Ht=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[te.balcony],sectionLabel:"Balcony",build:()=>[pe("blk-b0","A",-45,18,24,"balcony",18),pe("blk-b1","B",-15,20,24,"balcony",18),pe("blk-b2","C",15,22,24,"balcony",18),pe("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[te.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>pe(`blk-r${e}`,"ABCDEF"[e],-80+e*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[te.standard],build:()=>[Vt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[te.premium],build:()=>Array.from({length:6},(t,e)=>$n(`blk-t${e}`,`T${e+1}`,{x:-150+e%3*150,y:e<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[te.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:[te.standard],build:()=>[Vt("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:[te.standard],build:()=>[zn("blk-wc","A",4,40,"standard")]}];function N(t){let e="",r=t;do e=String.fromCharCode(65+r%26)+e,r=Math.floor(r/26)-1;while(r>=0);return e}function Xt(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let r of t)e=e*26+(r.charCodeAt(0)-64);return e-1}function Yt(t,e,r){let o=i=>({x:i.x+e,y:i.y+r});switch(t.type){case"row":t.origin=o(t.origin),t.path&&(t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)});break;case"table":case"booth":t.center=o(t.center);break;case"text":t.position=o(t.position);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=ue(t.holes).map(i=>i.map(o)));break;case"section":t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=jt(t.outlinePath,e,r)),t.holes&&(t.holes=ue(t.holes).map(i=>i.map(o))),t.labelPresentation?.position&&(t.labelPresentation.position=o(t.labelPresentation.position));break;case"shape":t.points&&(t.points=t.points.map(o)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}function Zr(t,e){let r=C(t,e.floorId),o=[...new Set(e.tableIds)];if(!o.length)throw new d("invalid_operation","At least one table id is required");let i=o.map(b=>r.objects.find(p=>p.type==="table"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one table change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey),n.fill!==void 0&&n.fill!==null&&(n.fill=L(n.fill,"Table surface color"));let s=n.seatCount!==void 0,c=n.seatCountsBySide!==void 0;if(c){if(n.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(n.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let b=["top","bottom","left","right"],p=Object.keys(n.seatCountsBySide);if(p.length!==b.length||p.some(I=>!b.includes(I)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let I of b){let S=n.seatCountsBySide[I];if(!Number.isInteger(S)||S<0||S>40)throw new d("invalid_operation",`seatCountsBySide.${I} must be a whole number from 0 to 40`)}let v=b.reduce((I,S)=>I+n.seatCountsBySide[S],0);if(v<1||v>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&n.seatCount!==v)throw new d("invalid_operation",`seatCount must equal the ${v}-chair seatCountsBySide total`);n.seatCount=v,n.sides=b.filter(I=>n.seatCountsBySide[I]>0)}if(n.seatCount!==void 0&&(!Number.isInteger(n.seatCount)||n.seatCount<1||n.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(n.shape!==void 0&&n.shape!=="round"&&n.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(n.automaticRadius!==void 0&&typeof n.automaticRadius!="boolean")throw new d("invalid_operation","automaticRadius must be true or false");if(n.shape==="rect"&&n.automaticRadius===!0)throw new d("invalid_operation","Automatic radius can be used only with round tables");if(n.bookAsWhole===!0&&n.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(n.variableOccupancy===!1&&(n.minOccupancy!==void 0||n.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(b,p,v,I)=>{if(p!==void 0&&(!Number.isFinite(p)||p<v||p>I))throw new d("invalid_operation",`${String(b)} must be from ${v} to ${I}`)};if(l("rotation",n.rotation,0,360),l("radius",n.radius,24,160),l("seatArc",n.seatArc,120,360),l("width",n.width,40,320),l("height",n.height,30,240),n.minOccupancy!==void 0&&(!Number.isInteger(n.minOccupancy)||n.minOccupancy<1||n.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(n.maxOccupancy!==void 0&&(!Number.isInteger(n.maxOccupancy)||n.maxOccupancy<1||n.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(n.sides!==void 0){let b=new Set(["top","bottom","left","right"]);if(!n.sides.length||n.sides.length>4||new Set(n.sides).size!==n.sides.length||n.sides.some(p=>!b.has(p)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=ne(n,"Table"),u=Oe(n,"Table"),h=i.map(b=>{if(b.seatCountsBySide&&!c&&(s||e.patch.sides!==void 0))throw new d("invalid_operation",`Table "${b.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:b.id});let p=structuredClone(b);if(Object.assign(p,n),n.fill===null&&delete p.fill,p.shape==="round")delete p.seatCountsBySide,p.automaticRadius===!0?p.radius=Nt(p.seatCount,p.seatArc):delete p.automaticRadius;else{if(n.automaticRadius===!0)throw new d("invalid_operation",`Table "${p.label}" is rectangular and cannot use automatic radius`,{tableId:p.id});delete p.automaticRadius}if(p.overrides&&n.seatCount!==void 0&&(p.overrides=p.overrides.filter(v=>v.index<p.seatCount),p.overrides.length||delete p.overrides),n.bookAsWhole===!1&&delete p.bookAsWhole,n.variableOccupancy===!1&&(delete p.variableOccupancy,delete p.minOccupancy,delete p.maxOccupancy),p.bookAsWhole||delete p.bookAsWhole,p.variableOccupancy||delete p.variableOccupancy,p.bookAsWhole&&p.variableOccupancy)throw new d("invalid_operation",`Table "${p.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:p.id});if((p.bookAsWhole||p.variableOccupancy)&&p.overrides?.length)throw new d("invalid_operation",`Table "${p.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:p.id,overriddenChairIndices:p.overrides.map(v=>v.index)});if(p.bookAsWhole)delete p.minOccupancy,delete p.maxOccupancy;else if(p.variableOccupancy){if(!Number.isInteger(p.minOccupancy)||!Number.isInteger(p.maxOccupancy)||p.minOccupancy<1||p.maxOccupancy<p.minOccupancy||p.maxOccupancy>p.seatCount)throw new d("invalid_operation",`Table "${p.label}" needs whole-number minimum and maximum guests from 1 to its ${p.seatCount}-chair capacity`,{tableId:p.id,seatCount:p.seatCount})}else{if(n.minOccupancy!==void 0||n.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:p.id});delete p.minOccupancy,delete p.maxOccupancy}if(u&&delete p.displayType,f&&delete p.displayLabel,p.shape==="rect"){if(p.width??=80,p.height??=50,p.seatCountsBySide){let v=["top","bottom","left","right"],I=v.reduce((S,j)=>S+p.seatCountsBySide[j],0);if(I!==p.seatCount)throw new d("invalid_operation",`Table "${p.label}" side counts total ${I}, but seatCount is ${p.seatCount}`,{tableId:p.id,seatCount:p.seatCount,seatCountsBySide:p.seatCountsBySide});p.sides=v.filter(S=>p.seatCountsBySide[S]>0)}}else p.radius??=40;if((p.bookAsWhole||p.variableOccupancy)&&Ce(p.label))throw new d("invalid_operation",`Grouped table label "${p.label}" uses SeatLayer's reserved GA namespace`,{tableId:p.id});return p}),g=new Map(h.map(b=>[b.id,b])),w=new Set(o),y=new Map;for(let b of T(t))for(let p of b.objects){let v=p.type==="table"?g.get(p.id)??p:p,I=[];v.type==="row"?I=X(v).map(S=>S.label):v.type==="table"?I=v.bookAsWhole||v.variableOccupancy?[v.label]:He(v).map(S=>S.label):v.type==="booth"?I=[v.label]:v.type==="gaArea"&&(I=Z(v));for(let S of I){let j=y.get(S);if(j&&(w.has(j)||w.has(v.id)))throw new d("invalid_operation",`Inventory label "${S}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:S,conflictingObjectIds:[j,v.id]});y.set(S,j??v.id)}}let m=!1,x=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","fill","seatCountsBySide","overrides","automaticRadius"];for(let[b,p]of i.entries()){let v=h[b],I=JSON.stringify(p);for(let S of x)S in v||delete p[S];Object.assign(p,v),JSON.stringify(p)!==I&&(m=!0)}return{floorId:r.floorId,changed:m,tableIds:o}}function Qr(t,e){let r=C(t,e.floorId),o=[...new Set(e.boothIds)];if(!o.length)throw new d("invalid_operation","At least one booth id is required");let i=o.map(g=>r.objects.find(w=>w.type==="booth"&&w.id===g)),a=o.filter((g,w)=>!i[w]);if(a.length)throw new d("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one booth change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey);let s=(g,w,y,m)=>{if(w!==void 0&&(!Number.isFinite(w)||w<y||w>m))throw new d("invalid_operation",`${g} must be from ${y} to ${m}`)};s("width",n.width,30,400),s("height",n.height,30,400),s("rotation",n.rotation,0,360);let c=n.points===null;if(n.points!=null){if(o.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let g=Jt(n.points);if(!g.ok)throw new d("invalid_operation",g.message??"The booth outline is not a valid simple polygon")}let l=n.points!=null?n.points.map(g=>({x:g.x,y:g.y})):void 0;delete n.points;let f=ne(n,"Booth"),u=Oe(n,"Booth"),h=!1;for(let g of i){let w=JSON.stringify(g);Object.assign(g,n),f&&delete g.displayLabel,u&&delete g.displayType,c?delete g.points:l&&(g.points=l),JSON.stringify(g)!==w&&(h=!0)}return{floorId:r.floorId,changed:h,boothIds:o}}function ei(t,e){let r=C(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(!o.length)throw new d("invalid_operation","At least one GA area id is required");let i=o.map(f=>r.objects.find(u=>u.type==="gaArea"&&u.id===f)),a=o.filter((f,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one GA area change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(n.categoryKey!==void 0&&F(t,n.categoryKey),n.capacity!==void 0&&(!Number.isInteger(n.capacity)||n.capacity<1||n.capacity>W))throw new d("invalid_operation",`capacity must be an integer from 1 to ${W}`);if(n.cornerRadius!==void 0&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=ne(n,"GA area"),c=Oe(n,"GA area");if(n.capacity!==void 0)for(let f of i){if(f.inventorySegments!==void 0&&n.capacity<f.capacity)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot be reduced below ${f.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:f.id,currentCapacity:f.capacity,requestedCapacity:n.capacity});if(f.inventorySegments!==void 0&&n.capacity>f.capacity&&Xe(f,n.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot append that capacity safely`,{gaAreaId:f.id})}let l=!1;for(let f of i){let u=JSON.stringify(f),h=n.capacity===void 0?f.inventorySegments:Xe(f,n.capacity);Object.assign(f,n),h!==void 0&&(f.inventorySegments=h),s&&delete f.displayLabel,c&&delete f.displayType,JSON.stringify(f)!==u&&(l=!0)}return{floorId:r.floorId,changed:l,gaAreaIds:o}}function nt(t,e){if(e.length<3)return 0;let r=i=>M(i,e,void 0),o=0;for(let i of t)r(E(i))&&(i.type==="row"?o+=X(i).length:i.type==="table"?o+=He(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=ee(i)));return o}function ti(t,e){let r=C(t,e.floorId);if(!e.objectIds.length)throw new d("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new d("invalid_operation","Chart object ids must be unique");let o=e.objectIds.map(s=>r.objects.find(c=>c.id===s)),i=e.objectIds.filter((s,c)=>!o[c]);if(i.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=o,n=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)n.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+ee(c),0),remainingObjectCount:r.objects.length}}function ni(t,e){let r=C(t,e.floorId),o=[...new Set(e.textIds)];if(!o.length)throw new d("invalid_operation","At least one text id is required");let i=o.map(l=>r.objects.find(f=>f.type==="text"&&f.id===l)),a=o.filter((l,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one text change is required");if(n.text!==void 0){if(n.text=n.text.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!n.text||n.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(n.fontSize!==void 0&&(!Number.isFinite(n.fontSize)||n.fontSize<8||n.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(n.fontFamily!==void 0&&n.fontFamily!==null&&(n.fontFamily=n.fontFamily.normalize("NFKC").trim(),!n.fontFamily||n.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(n.rotation!==void 0&&(!Number.isFinite(n.rotation)||n.rotation<0||n.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(n.color!==void 0&&n.color!==null&&(n.color=L(n.color,"Text color")),n.bold!==void 0&&typeof n.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(n.italic!==void 0&&typeof n.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(n.width!==void 0&&n.width!==null&&(!Number.isFinite(n.width)||n.width<40||n.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new d("invalid_operation","Text align must be left, center, or right");if(n.lineHeight!==void 0&&(!Number.isFinite(n.lineHeight)||n.lineHeight<.8||n.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(n.letterSpacing!==void 0&&(!Number.isFinite(n.letterSpacing)||n.letterSpacing<-2||n.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(n.underline!==void 0&&typeof n.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(n.opacity!==void 0&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(n.background!==void 0&&n.background!==null){n.background.color=L(n.background.color,"Text background color");let{padding:l=6,cornerRadius:f=4,opacity:u=.9}=n.background;if(!Number.isFinite(l)||l<0||l>40)throw new d("invalid_operation",`Text background padding must be from 0 to ${40}`);if(!Number.isFinite(f)||f<0||f>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(u)||u<.1||u>1)throw new d("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(n,l))&&i.some(l=>l.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(n.labelImportance!==void 0&&n.labelImportance!==null&&n.labelImportance!=="orientation"&&n.labelImportance!=="detail")throw new d("invalid_operation","Text labelImportance must be 'orientation', 'detail' or null");if(n.iconKey!==void 0){if(!$t(n.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(i.some(l=>l.semanticKind!=="icon"))throw new d("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let c=!1;for(let l of i){let f=JSON.stringify(l);n.iconKey!==void 0&&(l.iconKey=n.iconKey),n.text!==void 0&&(l.text=n.text),n.fontSize!==void 0&&(l.fontSize=n.fontSize),n.fontFamily===null?delete l.fontFamily:n.fontFamily!==void 0&&(l.fontFamily=n.fontFamily),n.rotation!==void 0&&(l.rotation=n.rotation),n.color===null?delete l.color:n.color!==void 0&&(l.color=n.color),n.bold!==void 0&&(n.bold?l.bold=!0:delete l.bold),n.italic!==void 0&&(n.italic?l.italic=!0:delete l.italic),n.width===null?delete l.width:n.width!==void 0&&(l.width=n.width),n.align!==void 0&&(n.align==="left"?delete l.align:l.align=n.align),n.lineHeight!==void 0&&(n.lineHeight===1.2?delete l.lineHeight:l.lineHeight=n.lineHeight),n.letterSpacing!==void 0&&(n.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=n.letterSpacing),n.underline!==void 0&&(n.underline?l.underline=!0:delete l.underline),n.opacity!==void 0&&(n.opacity===1?delete l.opacity:l.opacity=n.opacity),n.background===null?delete l.background:n.background!==void 0&&(l.background=n.background),n.labelImportance===null?delete l.labelImportance:n.labelImportance!==void 0&&(l.labelImportance=n.labelImportance),JSON.stringify(l)!==f&&(Se(l),c=!0)}return{floorId:r.floorId,changed:c,textIds:o}}function oi(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(h=>r.objects.find(g=>g.type==="row"&&g.id===h)),a=o.filter((h,g)=>!i[g]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i.slice().sort((h,g)=>h.origin.y-g.origin.y||h.origin.x-g.origin.x),s=h=>h.segmentedRow?.displayLabel??h.displayLabel??h.label,c=Ft(n.map(h=>({label:s(h)})),e.options),l=e.displayType==null?void 0:e.displayType.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,24),f=l===void 0||l===""||l==="Row"?e.displayType===void 0?void 0:null:l,u=!1;return n.forEach((h,g)=>{let w=c[g].label.normalize("NFKC").replace(/\s+/g," ").trim();if(s(h)!==w&&(u=!0,h.segmentedRow?h.segmentedRow.displayLabel=w:h.displayLabel=w),f!==void 0){if(f===null){h.displayType!==void 0&&(u=!0,delete h.displayType);return}h.displayType!==f&&(u=!0,h.displayType=f)}}),{floorId:r.floorId,changed:u,rows:n.map(h=>({id:h.id,displayLabel:s(h),...h.displayType?{displayType:h.displayType}:{}}))}}function ri(t,e){let r=Ht.find(l=>l.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=C(t,e.floorId),i=new Set,a=r.build().map(l=>structuredClone(l));for(let l of a)l.id=P(t,l.type,e.idFactory,i),Yt(l,e.center.x,e.center.y);for(let l of r.categories)t.categories.some(f=>f.key===l.key)||t.categories.push({...l});let n=a.filter(l=>l.type==="row");if(n.length){let l=0;for(let f of o.objects){if(f.type!=="row")continue;let u=Xt(f.label);u!=null&&(l=Math.max(l,u+1))}for(let f of n)f.label=N(l++)}let s=new Set(o.objects.flatMap(l=>"label"in l&&l.label?[l.label]:[]));for(let l of a){if((l.type==="table"||l.type==="booth")&&s.has(l.label)){let f=/^(.*?)(\d+)$/.exec(l.label),u=f?f[1]:`${l.label} `,h=f?Number.parseInt(f[2],10):1;do h++;while(s.has(`${u}${h}`));l.label=`${u}${h}`}"label"in l&&l.label&&s.add(l.label)}o.objects.push(...a);let c=null;if(r.sectionLabel&&e.wrapInSection!==!1){let l=Q(a);if(l){let f={type:"section",id:P(t,"sec",e.idFactory,i),label:r.sectionLabel,outline:l};o.objects.push(f),c=f.id}}return{floorId:o.floorId,blockKey:r.key,createdIds:[...a.map(l=>l.id),...c?[c]:[]],sectionId:c}}function Bn(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new d("invalid_operation","Exact row path points must be finite");let o=_t(e,97),i=o.slice(1).reduce((a,n,s)=>a+Math.hypot(n.x-o[s].x,n.y-o[s].y),0);if(!Number.isFinite(i)||i<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function Un(t,e){let r=C(t,e.floorId),o=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!o)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=Bn(e.path),a=X(o),n=structuredClone(o);n.path=i.path,n.origin={...i.path.start};let s=X(n),c=a.map((f,u)=>Math.hypot(f.x-s[u].x,f.y-s[u].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:r.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((f,u)=>f+u,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function fi(t,e){let r=Un(t,e);if(!r.changed)return r;let i=C(t,r.floorId).objects.find(a=>a.type==="row"&&a.id===r.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,r}function Jn(t,e){let r=t.map((o,i)=>[...o,e[i]]);for(let o=0;o<3;o++){let i=o;for(let n=o+1;n<3;n++)Math.abs(r[n][o])>Math.abs(r[i][o])&&(i=n);if(Math.abs(r[i][o])<1e-9)return null;[r[o],r[i]]=[r[i],r[o]];let a=r[o][o];for(let n=o;n<4;n++)r[o][n]/=a;for(let n=0;n<3;n++){if(n===o)continue;let s=r[n][o];for(let c=o;c<4;c++)r[n][c]-=s*r[o][c]}}return[r[0][3],r[1][3],r[2][3]]}function qn(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],n=i.x**2+i.y**2;for(let s=0;s<3;s++){r[s]+=a[s]*n;for(let c=0;c<3;c++)e[s][c]+=a[s]*a[c]}}let o=Jn(e,r);return o?{x:o[0],y:o[1]}:null}function Wt(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function Vn(t,e){let r=C(t,e.floorId),o=r.objects.find(g=>g.type==="section"&&g.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let a=T(t).find(g=>g.id===r.floorId),n=e.mode==="outline"?qn(o.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(g=>g.type==="row"&&M(E(g),o.outline,o.holes)),c=s.filter(g=>!!g.path).map(g=>g.id),l=[],f=[],u=i/100;for(let g of s){if(g.path)continue;if(g.seatCount<2){l.push(g.id);continue}let w=Math.hypot(g.origin.x-n.x,g.origin.y-n.y);if(w<=g.seatSpacing/2+1e-6){l.push(g.id);continue}let y=2*Math.asin(g.seatSpacing/(2*w))/q,m=X(g),x=Math.atan2(g.origin.x-n.x,g.origin.y-n.y)/q,p=(g.curve!==0?Math.sign(g.curve):m.length>1&&Math.sign(Wt(Math.atan2(m[1].x-n.x,m[1].y-n.y)/q-x))||1)*y*(g.seatCount-1);if(Math.abs(p)>320){l.push(g.id);continue}let v=-x,I=g.curve+(p-g.curve)*u,S=g.rotation+Wt(v-g.rotation)*u,j={...g,curve:I,rotation:S},V=X(j).map((D,K)=>Math.hypot(D.x-m[K].x,D.y-m[K].y));f.push({rowId:g.id,fromCurve:g.curve,targetCurve:p,resultCurve:I,fromRotation:g.rotation,resultRotation:S,rmsMovement:Math.sqrt(V.reduce((D,K)=>D+K**2,0)/V.length),maxMovement:Math.max(...V)})}let h=f.map(g=>g.rmsMovement);return{floorId:r.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...n},strength:i,rows:f,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:h.length?h.reduce((g,w)=>g+w,0)/h.length:0,maxMovement:f.length?Math.max(...f.map(g=>g.maxMovement)):0}}function ui(t,e){let r=Vn(t,e),o=C(t,r.floorId),i=o.objects.find(n=>n.type==="section"&&n.id===r.sectionId),a=!1;for(let n of r.rows){let s=o.objects.find(c=>c.type==="row"&&c.id===n.rowId);(s.curve!==n.resultCurve||s.rotation!==n.resultRotation)&&(s.curve=n.resultCurve,s.rotation=n.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==r.strength&&(i.smoothing=r.strength,a=!0),{...r,changed:a}}function Qt(t,e,r,o){let i=$(t,e,r),a=$(t,e,o),n=$(r,o,t),s=$(r,o,e);return i*a<-1e-9&&n*s<-1e-9}function Zt(t,e){return t.some((r,o)=>{let i=t[(o+1)%t.length];return e.some((a,n)=>Qt(r,i,a,e[(n+1)%e.length]))})}function Hn(t){if(t.length<3||t.length>256||Math.abs(ve(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)if(!(r===e+1||e===0&&r===t.length-1)&&Qt(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Fe(t,e,r){let o=C(t,e),i=o.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===r);if(!i)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:o,object:i,outer:i.type==="section"?i.outline:i.points}}function ot(t,e){let{target:r,object:o,outer:i}=Fe(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Hn(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!M(l,i,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(Zt(a,i))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let n=o.holes??[],s=e.holeIndex??n.length;if(!Number.isInteger(s)||s<0||s>n.length||e.holeIndex!=null&&s>=n.length)throw new d("invalid_operation","Opening not found");for(let l=0;l<n.length;l++){if(l===e.holeIndex)continue;let f=n[l];if(Zt(a,f)||M(a[0],f,void 0)||M(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let c=r.objects.filter(l=>l.id!==o.id&&l.type!=="section"&&M(E(l),a,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.map(l=>l.id),excludedInventoryUnits:nt(r.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function gi(t,e){let r=ot(t,e),{object:o}=Fe(t,r.floorId,r.objectId);return o.holes??=[],e.holeIndex==null?o.holes.push(structuredClone(e.points)):o.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function Xn(t,e){let{target:r,object:o}=Fe(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(o.holes?.length??0))throw new d("invalid_operation","Opening not found");let i=o.holes[e.holeIndex],a=r.objects.filter(n=>n.id!==o.id&&n.type!=="section"&&M(E(n),i,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(n=>n.id),excludedInventoryUnits:nt(r.objects.filter(n=>n.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function hi(t,e){let r=Xn(t,e),{object:o}=Fe(t,r.floorId,r.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...r,changed:!0}}function Yn(t){let e=Y(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function en(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let o=r.map(n=>t.find(s=>s.type==="section"&&s.id===n)),i=r.filter((n,s)=>!o[s]);if(i.length)throw new d("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:r,sections:a,logicalSectionIds:[...new Set(a.map(n=>n.logicalSectionId??n.id))]}}function Wn(t,e){let r=C(t,e.floorId),o=en(r.objects,e.sectionIds),i=ge(_e(t,r.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),n=new Map(r.objects.map(g=>[g.id,g])),s=o.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),c=new Set,l=new Set(o.logicalSectionIds),f=new Set(r.objects.filter(g=>g.type==="section"&&l.has(g.logicalSectionId??g.id)).flatMap(g=>g.editor?.defaultCategoryKey?[g.editor.defaultCategoryKey]:[]));for(let g of s){let w=n.get(g);if(w)if(w.type==="row"||w.type==="table")for(let y of Re(w).keys())c.add(y);else(w.type==="booth"||w.type==="gaArea")&&c.add(w.categoryKey)}let u=o.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),h=o.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(w=>{let y=n.get(w);return y?.type==="row"||y?.type==="table"||y?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:u,...u&&c.size===1?{categoryKey:[...c][0]}:!u&&!s.length&&f.size===1?{categoryKey:[...f][0]}:{},categoryMixed:u?c.size!==1:!s.length&&f.size>1,viewApplicable:h}}function xi(t,e){F(t,e.categoryKey);let r=Wn(t,e);if(!r.categoryApplicable&&r.objectIds.length)throw new d("invalid_operation","A mixed selection of empty and occupied logical sections cannot be assigned together",{logicalSectionIds:r.logicalSectionIds});let o=C(t,r.floorId),i=new Set(r.objectIds),a=!1,n=0,s=new Set(r.logicalSectionIds);for(let c of o.objects)c.type!=="section"||!s.has(c.logicalSectionId??c.id)||c.editor?.defaultCategoryKey!==e.categoryKey&&(c.editor={...c.editor,defaultCategoryKey:e.categoryKey},a=!0);for(let c of o.objects){if(!i.has(c.id)||c.type!=="row"&&c.type!=="table"&&c.type!=="booth"&&c.type!=="gaArea"||(c.categoryKey!==e.categoryKey&&(c.categoryKey=e.categoryKey,a=!0),c.type!=="row"&&c.type!=="table"||!c.overrides?.length))continue;let l=c.overrides.flatMap(f=>{if(f.categoryKey===void 0)return[f];let u={...f};return delete u.categoryKey,n++,a=!0,Object.keys(u).some(h=>h!=="index")?[u]:[]});l.length?c.overrides=l:delete c.overrides}return{...r,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:n}}function tn(t,e){let r=C(t,e.floorId),o=en(r.objects,e.sectionIds),{requested:i}=o,a=structuredClone(e.patch),n=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(g=>!n.has(g));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new d("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 d("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new d("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 d("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new d("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 d("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Yn(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&je(a.labelPresentation,"Section"),a.labelStyle!==void 0&&oe(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(g=>g.id===a.zone))throw new d("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 d("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 d("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 d("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 d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=L(a.color,"Section color"));let c=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,l=new Set(o.logicalSectionIds),f=c?r.objects.filter(g=>g.type==="section"&&l.has(g.logicalSectionId??g.id)):[],u=new Set,h=!1;for(let g of o.sections){let w=JSON.stringify(g);a.label!==void 0&&(g.label=a.label),a.labelPresentation===null?delete g.labelPresentation:a.labelPresentation!==void 0&&(g.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(g.elevation=a.elevation);let y=m=>{g.physical3dProvenance&&(delete g.physical3dProvenance[m],Object.keys(g.physical3dProvenance).length===0&&delete g.physical3dProvenance)};a.height===null?(delete g.height,y("height")):a.height!==void 0&&(g.height=a.height,g.physical3dProvenance={...g.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete g.rake,y("rake")):a.rake!==void 0&&(g.rake=a.rake,g.physical3dProvenance={...g.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete g.surfaceKind,y("surfaceKind")):a.surfaceKind!==void 0&&(g.surfaceKind=a.surfaceKind,g.physical3dProvenance={...g.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete g.color:a.color!==void 0&&(g.color=a.color),JSON.stringify(g)!==w&&(h=!0,u.add(g.id))}for(let g of f){let w=JSON.stringify(g),y=g.viewFromSeatUrl;if(a.displayLabel===null?delete g.displayLabel:a.displayLabel!==void 0&&(g.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete g.entrance:a.entrance!==void 0&&(g.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete g.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(g.viewFromSeatUrl=a.viewFromSeatUrl),!g.viewFromSeatUrl||a.viewFromSeatMeta===null?delete g.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?g.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&g.viewFromSeatUrl!==y&&delete g.viewFromSeatMeta,a.labelStyle!==void 0){let m=Ae(g.labelPresentation,a.labelStyle);m?g.labelPresentation=m:delete g.labelPresentation}a.zone===null?delete g.zone:a.zone!==void 0&&(g.zone=a.zone),JSON.stringify(g)!==w&&(h=!0,u.add(g.id))}return{floorId:r.floorId,changed:h,sectionIds:i,affectedSectionIds:[...u]}}function Zn(t,e){let r=C(t,e.floorId),o=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(o.outlinePath)throw new d("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 d("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=r.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&M(E(a),o.outline,o.holes));return{floorId:r.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,n)=>a+ee(n),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function Ri(t,e){let r=Zn(t,e),i=C(t,r.floorId).objects.find(a=>a.type==="section"&&a.id===r.sectionId);return delete i.geometry,{...r,changed:!0}}function Qn(t,e){let r=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,n=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");n=e.dx!==0||e.dy!==0,o=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");n=e.factor!==1,i=e.factor;let s=E(t);o=c=>({x:s.x+(c.x-s.x)*e.factor,y:s.y+(c.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!r(e.degrees))throw new d("invalid_operation","Section rotation must be finite");n=(e.degrees%360+360)%360!==0;let c=e.degrees*Math.PI/180,l=Math.cos(c),f=Math.sin(c),u=E(t);o=h=>{let g=h.x-u.x,w=h.y-u.y;return{x:u.x+g*l-w*f,y:u.y+g*f+w*l}}}else{if(!r(e.coordinate))throw new d("invalid_operation","Section reflection coordinate must be finite");a=!0,o=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return n&&(t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=At(t.outlinePath,o,i,a)),t.holes&&(t.holes=ue(t.holes).map(s=>s.map(o)))),{changed:n,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function _i(t,e){let r=C(t,e.floorId),o=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...Qn(o,e.transform)}}function Oi(t,e){let r=C(t,e.floorId),o=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!Ot(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Je(i),n=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return n&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:r.floorId,sectionId:o.id,changed:n,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function eo(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function ji(t,e){return to(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function to(t,e){let r=C(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new d("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new d("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(e.sectionIds)],i=new Set,a=new Map,n=!1;try{for(let s of o){let c=r.objects.find(b=>b.type==="section"&&b.id===s);if(!c||!eo(c))continue;let f=structuredClone(c);a.set(c.id,{section:c,snapshot:f});let u=JSON.stringify(c),h=(c.sourceOutline??c.outline).map(b=>({...b})),g=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),y=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(b=>Math.min(100,Math.max(-100,b))),m=y?.some(b=>Math.abs(b)>.5)===!0,x=g>.5||m?Pt(h,{cornerSmoothing:g,...m?{edgeCurvature:y}:{}}):null;x?(c.sourceOutline=h,c.outlinePath=x,c.outline=Je(x),g>.5?c.cornerSmoothing=g:delete c.cornerSmoothing,m?c.edgeCurvature=[...y]:delete c.edgeCurvature):(c.outline=h,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let b=0;b<(c.holes?.length??0);b+=1)ot(t,{floorId:r.floorId,objectId:c.id,points:c.holes[b],holeIndex:b});JSON.stringify(c)!==u&&(n=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let f=c;for(let u of Object.keys(f))delete f[u];Object.assign(c,structuredClone(l))}throw s}return{floorId:r.floorId,changed:n,sectionIds:o,affectedSectionIds:[...i]}}function Ei(t,e,r={}){let o=!1;for(let i of e){let a=tn(t,{floorId:i.floorId,sectionIds:[i.sectionId],patch:{height:i.height,rake:i.rake,surfaceKind:i.surfaceKind}});o||=a.changed}if(r.stage){let i=C(t,r.stage.floorId).objects.find(a=>a.type==="shape"&&a.id===r.stage.shapeId);i&&i.role!=="stage"&&(i.role="stage",o=!0),i&&r.stage.stageKind&&!i.stageKind&&(i.stageKind=r.stage.stageKind,o=!0)}for(let{shapeId:i,floorId:a,role:n}of r.roles??[]){let s=C(t,a).objects.find(c=>c.type==="shape"&&c.id===i);s&&!s.role&&(s.role=n,o=!0)}for(let{floorId:i,point:a}of r.focal??[]){let n=be(a,"focalPoint"),s=i?t.floors?.find(l=>l.id===i):void 0,c=s?s.focalPoint:t.focalPoint;c?.x===n.x&&c?.y===n.y||(s?s.focalPoint=n:t.focalPoint=n,o=!0)}return t.floors?.length&&Pe(t),{changed:o}}var no=new Set(["companion","child","senior","student","membership","custom"]);function re(t){if(!t.length)throw new d("invalid_operation","A chart must have at least one category");let e=new Set,r=new Map,o=structuredClone(t);for(let i of o){let a=i.key.trim(),n=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!n||n.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=n.toLocaleLowerCase("en"),c=r.get(s);if(c)throw new d("duplicate_category_label",`Categories ${c} and ${a} share the same label`,{categoryKeys:[c,a],label:n});if(r.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new d("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 d("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 d("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!he(i.seatGlyph))throw new d("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 d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,f=new Set;for(let u of i.tiers){let h=u.id.trim(),g=u.name.normalize("NFKC").trim(),w=g.toLocaleLowerCase("en");if(!h||h.length>160||l.has(h))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!g||g.length>80||f.has(w))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:g});if(!Number.isFinite(u.price)||u.price<0||u.price>1e6)throw new d("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(u.restriction!=null&&!no.has(u.restriction))throw new d("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(u.buyerMessage!=null){if(u.buyerMessage=u.buyerMessage.normalize("NFKC").trim(),!u.buyerMessage)delete u.buyerMessage;else if(u.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(u.currency!=null&&(u.currency=u.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(u.currency)))throw new d("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(u.applicability!=null){let y=u.applicability.seatLabels?.map(x=>x.normalize("NFKC").trim()),m=u.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(x=>!x||x.length>160)||new Set(y).size!==y.length)||m&&(!m.length||m.some(x=>!we.some(b=>b.key===x))||new Set(m).size!==m.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});u.applicability={...y?{seatLabels:y}:{},...m?{accessibility:[...m]}:{}},!u.applicability.seatLabels&&!u.applicability.accessibility&&delete u.applicability}if(u.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(u.evidence.provenance)||typeof u.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(u.evidence.sourceDescription=u.evidence.sourceDescription.normalize("NFKC").trim(),!u.evidence.sourceDescription||u.evidence.sourceDescription.length>240||u.evidence.capturedAt!==void 0&&(u.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(u.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}l.add(h),f.add(w)}}}return o}function oo(t,e){let r=new Set,o=structuredClone(t.categories);for(let n of e.updates){if(r.has(n.categoryKey))throw new d("invalid_operation",`Category ${n.categoryKey} may be updated only once`);r.add(n.categoryKey);let s=o.find(u=>u.key===n.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${n.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:n.categoryKey});let c=structuredClone(n.patch),{tiers:l,...f}=c;typeof f.label=="string"&&(f.label=f.label.normalize("NFKC").trim()),typeof f.color=="string"&&(f.color=f.color.toLowerCase()),Object.assign(s,f),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(u=>{let h={...u,id:u.id.trim(),name:u.name.normalize("NFKC").trim()};return u.buyerMessage?.trim()?h.buyerMessage=u.buyerMessage.normalize("NFKC").trim():delete h.buyerMessage,h})),delete s.referenceDirectSeatImport}let i=re(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...r],categories:t.categories}}function $i(t,e){let r=structuredClone(t.categories),o=r.find(n=>n.key===e.categoryKey);if(!o||o.referenceDirectSeatImport?.assetId!==e.source.assetId||o.referenceDirectSeatImport.familyId!==e.source.familyId)throw new d("invalid_operation","The prior direct-seat import category is no longer available for this reference");o.label=e.label.normalize("NFKC").trim();let i=re(r),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,category:t.categories.find(n=>n.key===e.categoryKey),categories:t.categories}}function zi(t,e){let r=e.categoryKeys.map(c=>c.trim()),o=t.categories.map(c=>c.key);if(r.length!==o.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:o});let i=new Set(o),a=o.filter(c=>!r.includes(c)),n=r.filter(c=>!i.has(c));if(a.length||n.length)throw new d(n.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:a,unknownCategoryKeys:n});if(r.every((c,l)=>c===o[l]))return{changed:!1,categoryKeys:o,categories:t.categories};let s=new Map(t.categories.map(c=>[c.key,c]));return t.categories=re(r.map((c,l)=>{let f=structuredClone(s.get(c));return c!==o[l]&&delete f.referenceDirectSeatImport,f})),{changed:!0,categoryKeys:r,categories:t.categories}}var on=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function nn(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(o=>o+o).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function ro(t,e){let r=nn(t),o=nn(e);return!r||!o?1/0:(r[0]-o[0])**2+(r[1]-o[1])**2+(r[2]-o[2])**2}var io=3600;function ao(t,e,r=on){return r.find(i=>t.every(a=>ro(i,a)>=io))??r[e%r.length]}function Bi(t,e){let r=e?.palette??on;if(!t.categories.length)return{changed:[],categories:t.categories};let o=new Map(t.categories.map(n=>[n.key,n.color.toLowerCase()])),i=t.categories.map((n,s)=>({categoryKey:n.key,patch:{color:r[s%r.length]}}));return oo(t,{updates:i}),{changed:t.categories.map(n=>({key:n.key,from:o.get(n.key),to:n.color})).filter(n=>n.from!==n.to),categories:t.categories}}function Ui(t,e){let r=e.color.trim().toLowerCase(),o=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!o||o.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(c=>c.key===e.categoryKey);if(!a)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=r,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let n=re(i),s=JSON.stringify(n)!==JSON.stringify(t.categories);return s&&(t.categories=n),{changed:s,category:t.categories.find(c=>c.key===e.categoryKey),categories:t.categories}}function so(t,e){let r=new Set(t.categories.map(n=>n.key)),o="";for(let n=0;n<100;n++){let c=e.idFactory("cat").trim();if(c&&!r.has(c)){o=c;break}}if(!o)throw new d("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(n=>({...n,id:n.id.trim(),name:n.name.normalize("NFKC").trim()})),...e.referenceDirectSeatImport?{referenceDirectSeatImport:structuredClone(e.referenceDirectSeatImport)}:{}},a=re([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(n=>n.key===o),categories:a}}var co=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],lo={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function fo(t,e){let r=lo[t];return!r||!e.includes(r)?e:[r,...e.filter(o=>o!==r)]}var uo=26;function go(t,e,r){let o=(1-Math.abs(2*r-1))*e,i=(t%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[n,s,c]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],l=r-o/2,f=u=>Math.round((u+l)*255).toString(16).padStart(2,"0");return`#${f(n)}${f(s)}${f(c)}`}function ho(t,e,r){let o=n=>t.every(s=>{let c=Gt(n,s);return c==null||c>=uo}),i=n=>{let s=Ye(n,"#12151d"),c=Ye(n,"#ffffff");return(s??0)>=3||(c??0)>=3},a=e.find(n=>o(n)&&i(n));if(a)return a;for(let n=0;n<360;n+=12)for(let s of[.52,.44,.6]){let c=go(n,.62,s);if(o(c)&&i(c))return c}return r}function bo(t,e){let r=xe.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function po(t){let e=new Map;for(let r of T(t))for(let o of r.objects){let i=xe.find(n=>n.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let n of Re(o).keys())a.add(n);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let n of a){let s=e.get(n)??new Set;s.add(i.objectType),e.set(n,s)}}return e}function yo(t,e){let r=new Set(t.categories.map(i=>i.label.toLowerCase())),o=e;for(let i=2;r.has(o.toLowerCase());i+=1)o=`${e} ${i}`;return o}function mo(t,e,r){let o=po(t),i=l=>{let f=o.get(l);return!f||f.size===0||f.size===1&&f.has(r)},a=t.categories.find(l=>l.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let l=t.categories.find(f=>{let u=o.get(f.key);return u?.size===1&&u.has(r)});if(l)return{kind:"existing",categoryKey:l.key,label:l.label}}let n=xe.find(l=>l.objectType===r),s=a?bo(a.label,r):r==="gaArea"?"General Admission":n.creationWord,c=t.categories.find(l=>l.label.toLowerCase()===s.toLowerCase()&&i(l.key));return c?{kind:"existing",categoryKey:c.key,label:c.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:yo(t,s)}}function Ji(t,e,r,o){let i=mo(t,e,r);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?t.categories.find(n=>n.key===i.baseCategoryKey):void 0;return wo(t,r,a,i.label,o)}function wo(t,e,r,o,i){let a=i.palette??co,n=t.categories.map(f=>f.color),s=i.suggestColor?.(n.map(f=>f.toLowerCase()))??ao(n,t.categories.length),c=ho(n,fo(e,a),s),l=so(t,{label:o,color:c,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:i.idFactory});return t.categories=l.categories,l.category.key}function Io(t,e){let r=new Set;for(let o of T(t))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===e&&r.add(i.id),i.type==="section"&&i.editor?.defaultCategoryKey===e&&r.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&r.add(i.id);return[...r]}function qi(t,e){let r=t.categories.find(a=>a.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let o=Io(t,e.categoryKey);if(o.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:o});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=re(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var vo=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],So=["seat","deck","shell","fascia"];function Zi(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let o=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of vo){let n=r[a];n===null?delete i[a]:n!==void 0&&(i[a]=L(n,`Theme ${a}`))}if(r.fontFamily===null)delete i.fontFamily;else if(r.fontFamily!==void 0){let a=r.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(r.seatScale===null)delete i.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<We||r.seatScale>Ze)throw new d("invalid_operation",`Theme seatScale must be from ${We} to ${Ze}`);i.seatScale=r.seatScale}if(r.logoUrl===null)delete i.logoUrl;else if(r.logoUrl!==void 0){let a=Y(r.logoUrl);if(!a)throw new d("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster image reference");i.logoUrl=a}if(r.brandName===null)delete i.brandName;else if(r.brandName!==void 0){let a=r.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}if(r.hideBadge===null||r.hideBadge===!1?delete i.hideBadge:r.hideBadge===!0&&(i.hideBadge=!0),r.venue3d===null)delete i.venue3d;else if(r.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of So){let c=r.venue3d[s];c===null?delete a[s]:c!==void 0&&(a[s]=L(c,`3D venue ${s}`))}let n=r.venue3d.roughness;if(n===null)delete a.roughness;else if(n!==void 0){if(!Number.isFinite(n)||n<0||n>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=n}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==o,theme:t.theme??null}}function Qi(t,e){let r=e.url===null?null:Y(e.url);if(e.url!==null&&!r)throw new d("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(u=>u.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===o,l=o?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,f=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,n=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=o,t.viewFromSeatMeta=a,{changed:n,scope:"venue",url:t.viewFromSeatUrl??null}}function ea(t,e){let r=_e(t,e.floorId),o=Mt(r),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-e.height/2}:i==="left"?{x:o.x-a-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+e.height/2}}function ke(t,e){F(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=e.endAngle-e.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new d("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new d("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,n=e.skewDegrees??0;if(!r(a,n)||Math.abs(a)>120||Math.abs(n)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let l=C(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:n,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function Co(t,e,r){let o=r*q;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function xo(t,e,r,o){let i=Math.abs(o-r)*q,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,f])=>{let u=t.aisleGaps[l];if(!u)return[];let h=u/e/i/2;return[[Math.max(0,f-h),Math.min(1,f+h)]]}).sort((l,f)=>l[0]-f[0]),n=[];for(let l of a){let f=n[n.length-1];f&&l[0]<=f[1]?f[1]=Math.max(f[1],l[1]):n.push([...l])}let s=[],c=0;for(let l of n)l[0]-c>1e-6&&s.push([c,l[0]]),c=Math.max(c,l[1]);return 1-c>1e-6&&s.push([c,1]),s.filter(([l,f])=>e*i*(f-l)>=t.seatPitch*.75)}function Ro(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let o=e-r,i=t.reduce((c,l)=>c+l,0),a=t.map(c=>o*c/i),n=a.map(c=>2+Math.floor(c)),s=e-n.reduce((c,l)=>c+l,0);return a.map((c,l)=>({index:l,fraction:c-Math.floor(c)})).sort((c,l)=>l.fraction-c.fraction||c.index-l.index).forEach(({index:c})=>{s-- >0&&n[c]++}),n}function Ee(t,e,r){let o=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),n=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,c=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,l=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;if(Math.sign(l-c)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(l-c)<5)throw new d("invalid_operation",`Arc/Fan taper collapses row ${i+1} below a 5\xB0 sweep`);let f=xo(t,n,c,l);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let u=f.map(([w,y])=>n*Math.abs(l-c)*q*(y-w)),h=t.fit==="fixed-count"?Ro(u,t.seatsPerRow):u.map(w=>Math.max(2,Math.round(w/t.seatPitch)+1)),g=t.seatLabelStart;f.forEach(([w,y],m)=>{let x=c+(l-c)*w,b=c+(l-c)*y;t.facing==="outward"&&([x,b]=[b,x]);let p=h[m];if(p>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let v=Math.abs(b-x)*q/(p-1),I=2*n*Math.sin(v/2),S={type:"row",id:r(i,m),label:N(t.rowLabelStart+i),origin:Co(t.center,n,x),rotation:-x,curve:b-x,seatCount:p,seatSpacing:I,categoryKey:t.categoryKey,seatLabelStart:g,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:m}};o.push(S),g+=p})}return o}function rn(t,e){let r=ke(t,e),o=C(t,e.floorId),i=Ee(r,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),n=Math.max(...a.map(c=>Math.abs(c-r.seatPitch))),s=[];return n>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${n.toFixed(1)} chart units`),i.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:r.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((c,l)=>c+l.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:n,aisleCount:Object.values(r.aisleGaps).filter(c=>c>0).length,warnings:s}}function ra(t,e){let r=ke(t,e),o=C(t,e.floorId),i=new Set,a=P(t,"fan",e.idFactory,i),n=Ee(r,a,()=>P(t,"r",e.idFactory,i)),s=rn(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(l){if(l.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let u=Q(n);u&&(c=P(t,"sec",e.idFactory,i),f={type:"section",id:c,label:l,outline:u,arcFanGroupId:a})}return o.objects.push(...n,...f?[f]:[]),{floorId:o.floorId,rowIds:n.map(u=>u.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function _o(t,e){let r=C(t,e.floorId),o=r.objects.filter(u=>u.type==="row"&&u.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=u=>{let h=u.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(o.some(u=>a(u)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let n=r.objects.find(u=>u.type==="section"&&u.arcFanGroupId===e.groupId),s={floorId:r.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:n?.label},c=ke(t,s),l=new Set(Ee(c,e.groupId,(u,h)=>`${u}:${h}`).map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`));if(l.size!==f.size||[...l].some(u=>!f.has(u)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function ia(t,e){_o(t,{floorId:e.floorId,groupId:e.groupId});let r=ke(t,e),o=C(t,e.floorId),i=o.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),n=new Map(i.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,c=Ee(r,e.groupId,(y,m)=>n.get(`${y}:${m}`)??P(t,"r",e.idFactory,s)),l=rn(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),u=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let y=Q(c);y&&(u={type:"section",id:a?.id??P(t,"sec",e.idFactory,s),label:f,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...i.map(y=>y.id),...a?[a.id]:[]]),g=Math.min(...o.objects.map((y,m)=>h.has(y.id)?m:1/0)),w=o.objects.filter(y=>!h.has(y.id));return w.splice(Number.isFinite(g)?g:w.length,0,...c,...u?[u]:[]),o.objects.splice(0,o.objects.length,...w),{floorId:o.floorId,rowIds:c.map(y=>y.id),sectionId:u?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function Oo(t){let e=new Set(B(t).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),r=0;return()=>{for(;e.has(N(r));)r+=1;let o=N(r);return e.add(o),r+=1,o}}function an(t){return JSON.stringify(["row-block-v1",t.style,t.origin.x,t.origin.y,t.rotation,t.rowCount,t.seatsPerRow,t.rowGap,t.seatSpacing,t.curve])}function fa(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,o=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(o)||o<=0)throw new d("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new d("invalid_operation","rotation must be a finite number of degrees");let i=C(t,e.floorId),a=new Set,n=Oo(t),s=tt(e.rotation??0),c=e.curve??0,l=e.style,f=l?P(t,"rowblock",e.idFactory,a):void 0,u=l?an({style:l,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:o,curve:c}):void 0,h={x:Math.cos(s*U),y:Math.sin(s*U)},g={x:-h.y,y:h.x},w=Array.from({length:e.rowCount},(x,b)=>{let p=l==="intertwined"&&b%2===1?o/2:0,v={type:"row",id:P(t,"r",e.idFactory,a),label:n(),origin:{x:e.origin.x+g.x*b*r+h.x*p,y:e.origin.y+g.y*b*r+h.y*p},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&f&&u&&(v.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:l,rowIndex:b,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:r,seatSpacing:o,curve:c,signature:u}),v});i.objects.push(...w);let y=null,m=e.sectionLabel?.trim();if(m){let x=Q(w);if(x){let b={type:"section",id:P(t,"sec",e.idFactory,a),label:m,outline:x};i.objects.push(b),y=b.id}}return{floorId:i.floorId,rowIds:w.map(x=>x.id),sectionId:y,createdIds:[...w.map(x=>x.id),...y?[y]:[]]}}function sn(t,e){let r=new Set(B(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;r.has(`${e}${o}`);)o+=1;let i=`${e}${o}`;return r.add(i),o+=1,i}}function jo(t,e){let r=new Set(B(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!r.has(e))return e;let o=2;for(;r.has(`${e} ${o}`);)o+=1;return`${e} ${o}`}var Ao=456;function Po(t){let e=Math.sqrt(Math.max(1,t)*Ao);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function ua(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new d("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","GA area center must be finite");let r=C(t,e.floorId),o=new Set,{width:i,height:a}=Po(e.capacity),n=jo(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:P(t,"ga",e.idFactory,o),label:n,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:n,createdIds:[s.id]}}function ga(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,o=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(o)||o<80)throw new d("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Table array center must be finite");let i=C(t,e.floorId),a=new Set,n=sn(t,"T"),s=[];for(let c=0;c<e.tableRows;c+=1)for(let l=0;l<e.tableColumns;l+=1)s.push({type:"table",id:P(t,"t",e.idFactory,a),label:n(),center:{x:e.center.x+(l-(e.tableColumns-1)/2)*r,y:e.center.y+(c-(e.tableRows-1)/2)*o},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function ha(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,o=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(o)||o<52)throw new d("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Booth array center must be finite");let i=C(t,e.floorId),a=new Set,n=sn(t,"B"),s=[];for(let c=0;c<e.boothRows;c+=1)for(let l=0;l<e.boothColumns;l+=1)s.push({type:"booth",id:P(t,"booth",e.idFactory,a),label:n(),center:{x:e.center.x+(l-(e.boothColumns-1)/2)*r,y:e.center.y+(c-(e.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function ba(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2||o.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==o.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(h=>r.objects.find(g=>g.type==="row"&&g.id===h)),a=o.filter((h,g)=>!i[g]);if(a.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(h=>h.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let c=(e.displayLabel??n[0].displayLabel??n[0].label).normalize("NFKC").trim();if(!c||c.length>80)throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let l=new Set(r.objects.flatMap(h=>h.type==="row"?[h.segmentedRow?.groupId,h.rowBlockGeneration?.groupId].filter(g=>!!g):[])),f="";for(let h=0;h<100;h+=1){let g=e.idFactory("rowgroup");if(g&&!l.has(g)){f=g;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let u=n[0];return n.forEach((h,g)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:g,componentCount:n.length,boundaryBefore:g===0?"start":e.boundaries[g-1],displayLabel:c,...u.displayType?{displayType:u.displayType}:{},...u.labelPresentation?{labelPresentation:structuredClone(u.labelPresentation)}:{},...u.viewFromSeatUrl?{viewFromSeatUrl:u.viewFromSeatUrl}:{},...u.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(u.viewFromSeatMeta)}:{},...u.confidenceEvidence?{confidenceEvidence:structuredClone(u.confidenceEvidence)}:{}}}),{floorId:r.floorId,groupId:f,rowIds:o,changed:!0}}function pa(t,e){let r=C(t,e.floorId),o=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??o?.segmentedRow?.groupId;if(!i)throw new d("object_not_found","The segmented row does not exist on the selected floor");let a=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let n=a.sort((s,c)=>s.segmentedRow.componentIndex-c.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:r.floorId,groupId:i,rowIds:n,changed:!0}}function ya(t,e){let r=C(t,e.floorId),o=r.objects.filter(n=>n.type==="row"&&n.segmentedRow?.groupId===e.groupId).sort((n,s)=>n.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(o.length<2)throw new d("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==o.length-1||e.boundaries.some(n=>n!=="continuous"&&n!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(o.map(n=>n.segmentedRow));return o.forEach((n,s)=>{let c=n.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),e.boundaries&&s>0&&(c.boundaryBefore=e.boundaries[s-1]),e.smoothing!==void 0&&(c.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete c.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=e.viewFromSeatUrl),!c.viewFromSeatUrl||e.viewFromSeatMeta===null?delete c.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:r.floorId,groupId:e.groupId,rowIds:o.map(n=>n.id),changed:JSON.stringify(o.map(n=>n.segmentedRow))!==a}}function ma(t,e){if(typeof e.groupId!="string"||!e.groupId)throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let r=C(t,e.floorId),o=r.objects.filter(_=>_.type==="row"&&_.rowBlockGeneration?.groupId===e.groupId).sort((_,z)=>_.rowBlockGeneration.rowIndex-z.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((_,z)=>{let A=_.rowBlockGeneration;return A.kind!=="row-block-v1"||A.rowIndex!==z||A.signature!==i.signature||JSON.stringify(A)!==JSON.stringify({...i,rowIndex:z})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(o),n=e.style??i.style,s=e.rowCount??i.rowCount,c=e.seatsPerRow??i.seatsPerRow,l=e.rowGap??i.rowGap,f=e.seatSpacing??i.seatSpacing,u=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?tt(e.rotation??i.rotation):e.rotation??i.rotation,g=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(c)||c<1||c>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![l,f].every(_=>Number.isFinite(_)&&_>0)||!Number.isFinite(u)||!Number.isFinite(h)||!Number.isFinite(g.x)||!Number.isFinite(g.y))throw new d("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let w=an({style:n,origin:g,rotation:h,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:f,curve:u}),y={x:Math.cos(h*U),y:Math.sin(h*U)},m={x:-y.y,y:y.x},x=new Map(o.map(_=>[_.rowBlockGeneration.rowIndex,_])),b=new Set,p=new Set(r.objects.filter(_=>_.type==="row").filter(_=>!o.includes(_)).map(_=>_.label)),v=r.objects.filter(_=>_.type==="row").length,I=()=>{for(;p.has(N(v));)v+=1;let _=N(v);return p.add(_),v+=1,_},S=[],j=[];for(let _=0;_<s;_+=1){let z=n==="intertwined"&&_%2===1?f/2:0,A=x.get(_);A||(A={type:"row",id:P(t,"r",e.idFactory,b),label:I(),origin:{...g},rotation:h,curve:u,seatCount:c,seatSpacing:f,categoryKey:o[0].categoryKey},j.push(A.id)),A.origin={x:g.x+m.x*_*l+y.x*z,y:g.y+m.y*_*l+y.y*z},A.rotation=h,A.curve=u,A.seatCount=c,A.seatSpacing=f,delete A.path,delete A.arcFanGeneration,A.overrides&&(A.overrides=A.overrides.filter(fe=>fe.index<c),A.overrides.length||delete A.overrides),A.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:n,rowIndex:_,rowCount:s,seatsPerRow:c,origin:{...g},rotation:h,rowGap:l,seatSpacing:f,curve:u,signature:w},S.push(A)}let J=o.slice(s).map(_=>_.id),V=Math.min(...o.map(_=>r.objects.indexOf(_))),D=new Set(o.map(_=>_.id)),K=r.objects.filter(_=>!D.has(_.id));return K.splice(V,0,...S),r.objects.splice(0,r.objects.length,...K),{floorId:r.floorId,groupId:e.groupId,rowIds:S.map(_=>_.id),createdRowIds:j,removedRowIds:J,changed:a!==JSON.stringify(S)||j.length>0||J.length>0}}function rt(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function it(t,e){let r="";for(let o of t){if(r.length+o.length>e)break;r+=o}return r.trim()}function at(t){return it(rt(t),40)}function cn(t,e=39){return it(rt(t),Math.max(1,e))}function ie(t,e=80){return it(rt(t),Math.max(1,e))}function ln(t){return ie(t).toLocaleLowerCase("en")}function st(t){return ln(t)}function dn(t){return new Map((t??[]).map(e=>[e.index,e]))}function Fo(t){let e=dn(t.overrides),r=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||r.push(qe(t,o,i))}return r}function ko(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=dn(t.overrides),r=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||r.push(i?.label??`${t.label}-${o+1}`)}return r}function Eo(t){return t.type==="row"?[t.label,...Fo(t)]:t.type==="table"?[t.label,...ko(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...Z(t)]:[]}function fn(t,e){let r=new Set;for(let o of t)if(!e?.has(o.id))for(let i of Eo(o)){let a=st(i);a&&r.add(a)}return r}function Lo(t,e){if(!Number.isInteger(e)||e<1)return[];let r={label:t,seatCount:e},o=[st(t)];for(let i=0;i<e;i+=1)o.push(st(qe(r,i)));return o.filter(Boolean)}function un(t,e,r){let o=Lo(e,r);if(!o.length||o.some(i=>t.has(i)||Ce(i)))return!1;for(let i of o)t.add(i);return!0}var Mo=1e-6,To=160,No=.001,Do=1e-5;function ae(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>To)return;for(let a of e){let n=a.codePointAt(0)??0;if(n<32||n===127)return}let r=e.lastIndexOf(":"),o=e.slice(0,r),i=e.slice(r+1);if(!(!o||!/^(0|[1-9]\d*)$/.test(i)||!Number.isSafeInteger(Number(i))))return e}function gn(t){return typeof t=="string"&&cn(t)||void 0}function hn(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(ct(t.origin)&&ct(e.start)&&ct(e.end)&&Number.isFinite(t.rotation)&&Number.isFinite(t.seatSpacing)&&t.seatSpacing>0)||t.curve!==0||t.path)return!1;let r=t.rotation*Math.PI/180,o={x:t.origin.x+Math.cos(r)*t.seatSpacing*(t.seatCount-1),y:t.origin.y+Math.sin(r)*t.seatSpacing*(t.seatCount-1)},i=Math.hypot(e.end.x-e.start.x,e.end.y-e.start.y),a=No+Math.max(1,i)*Do;if(Math.hypot(t.origin.x-e.start.x,t.origin.y-e.start.y)>a||Math.hypot(o.x-e.end.x,o.y-e.end.y)>a)return!1;if(t.seatCount<2||i<=Mo)return!0;let n=i/(t.seatCount-1);if(Math.abs(t.seatSpacing-n)>a)return!1;let s=Math.atan2(e.end.y-e.start.y,e.end.x-e.start.x)*180/Math.PI,c=Math.abs(((t.rotation-s)%360+540)%360-180),l=Math.max(.001,Math.atan2(a,Math.max(1,i))*180/Math.PI);return c<=l}function ct(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var Ko=300;function Go(t){let e=new Set(B(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(Boolean)),r=0,o=()=>{for(;e.has(N(r));)r+=1;let i=N(r);return r+=1,e.add(i),i};return i=>{let a=at(i),n=0;return()=>{for(;a&&n<4096;n+=1){let s=`${a}-${N(n)}`;if(!e.has(s))return e.add(s),n+=1,s}return o()}}}function $o(t){let e=fn(B(t));return(r,o)=>{let i=ie(r);for(let a=1;a<4096;a+=1){let n=a===1?"":` ${a}`,s=n?`${ie(i,80-n.length)}${n}`:i;if(s&&un(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function zo(t){return{ordinaryFor:Go(t),direct:$o(t)}}function bn(t,e,r){return t.type==="row"&&t.referenceScan?.assetId===e&&(!r||t.referenceScan.sectionId===r)}function Bo(t,e,r){let o=new Map;for(let n of e.sections)if(!(r&&n.sectionId!==r)&&n.sourceGroupId)for(let[s,c]of n.rows.entries()){let l=ae(`${n.sourceGroupId}:${s}`),f=l&&ae(c.directSourceRowId)===l?l:void 0;f&&o.set(f,o.has(f)?null:c)}let i=new Map;for(let n of t){let s=ae(n.referenceScan?.directSourceRowId);if(!s){if(!n.overrides?.length)continue;throw new d("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:n.id})}let c=i.get(s)??[];c.push(n),i.set(s,c)}let a=new Map;for(let[n,s]of i){let c=s.filter(h=>h.overrides?.length);if(!c.length)continue;let l=o.get(n),f=c[0],u=f.overrides;if(s.length!==1||c.length!==1||!u||!l||!hn(f,l))throw new d("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:n,rowIds:s.map(h=>h.id)});a.set(n,structuredClone(u))}return a}function pn(t,e,r){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!(o.type==="row"&&o.referenceScan?.assetId===e&&(!r||o.referenceScan.sectionId===r)))}function Uo(t,e,r,o,i,a,n){let s=t.sectionId?e.find(f=>f.type==="section"&&f.id===t.sectionId):void 0;if(s){let f=pn(e,r,n).filter(u=>M(E(u),s.outline,s.holes));if(f.length)return{skip:{sectionId:s.id,name:t.name,reason:"section_not_empty",objectIds:f.map(u=>u.id)},rows:[],seats:0}}let c=[],l=0;for(let[f,u]of t.rows.entries()){let h=Math.min(Ko,Math.max(1,Math.round(u.seatCount)));if(!Number.isFinite(h)||h<1)continue;let g=u.end.x-u.start.x,w=u.end.y-u.start.y,y=Math.hypot(g,w),m=h>1&&y>0?y/(h-1):o>0?o:24;if(!Number.isFinite(m)||m<=0)continue;let x=y>0?Math.atan2(w,g)*180/Math.PI:0,b=t.sourceGroupId?ae(`${t.sourceGroupId}:${f}`):void 0,p=b&&ae(u.directSourceRowId)===b?b:void 0,v=p?gn(u.directReviewedSuffix):void 0,I=t.sourceGroupId&&u.rowLabel?ie(u.rowLabel):"",S=t.sourceGroupId&&u.rowDisplayLabel?ie(u.rowDisplayLabel):"",j=!!t.sourceGroupId&&u.rowDisplayLabel==="";c.push({label:I?a(I,h):i(),displayLabel:S||(j?"":String(f+1)),origin:{x:u.start.x,y:u.start.y},rotation:x,seatCount:h,seatSpacing:m,...p?{directSourceRowId:p}:{},...v?{directReviewedSuffix:v}:{}}),l+=h}return{skip:null,rows:c,seats:l}}function La(t,e,r){F(t,r.categoryKey);let o=C(t,r.floorId),i=e.assetId,a=r.sectionId?o.objects.find(b=>b.type==="section"&&b.id===r.sectionId):void 0;if(r.sectionId&&!a)throw new Error("The opened section no longer exists on this floor");let n=new Map;for(let b of e.sections){if(a&&b.sectionId!==a.id)continue;let p=r.categoryKeyForSection?.(b)??r.categoryKey;F(t,p),n.set(b,p)}if(a&&!e.sections.some(b=>b.sectionId===a.id&&b.seatCount>0))return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[]};let s=a?e.sections.find(b=>b.sectionId===a.id&&b.seatCount>0):void 0;if(a&&s){let b=pn(o.objects,i,a.id).filter(p=>M(E(p),a.outline,a.holes));if(b.length)return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[{sectionId:a.id,name:s.name,reason:"section_not_empty",objectIds:b.map(p=>p.id)}]}}let c=o.objects.filter(b=>bn(b,i,a?.id)),l=Bo(c,e,a?.id),f=[],u=o.objects.filter(b=>bn(b,i,a?.id)?(f.push(b.id),!1):!0);o.objects.splice(0,o.objects.length,...u);let h=[],g=[],w=[],y=new Set,m=0,x=zo(t);for(let b of e.sections){if(a&&b.sectionId!==a.id)continue;let p=Uo(b,o.objects,i,e.seatPitch,x.ordinaryFor(b.name),x.direct,a?.id);if(p.skip){g.push(p.skip);continue}let v=p.rows.map(I=>({type:"row",id:P(t,"r",r.idFactory,y),referenceScan:{assetId:i,...b.sectionId?{sectionId:b.sectionId}:{},...I.directSourceRowId?{directSourceRowId:I.directSourceRowId}:{},...I.directReviewedSuffix?{directReviewedSuffix:I.directReviewedSuffix}:{}},label:I.label,...I.displayLabel!==void 0?{displayLabel:I.displayLabel}:{},origin:I.origin,rotation:I.rotation,curve:0,seatCount:I.seatCount,seatSpacing:I.seatSpacing,categoryKey:n.get(b)??r.categoryKey,...I.directSourceRowId&&l.has(I.directSourceRowId)?{overrides:structuredClone(l.get(I.directSourceRowId))}:{}}));o.objects.push(...v);for(let I of v)w.push(I.id);h.push({sectionId:b.sectionId,name:b.name,seats:p.seats,rows:v.length}),m+=p.seats}return{floorId:o.floorId,assetId:i,createdRowIds:w,removedRowIds:f,totalSeats:m,perSection:h,skipped:g}}function yn(t,e,r={}){let o=C(t,e.floorId),i=[...new Set(e.objectIds)];if(!i.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let a=i.map(y=>o.objects.find(m=>(m.type==="table"||m.type==="booth")&&m.id===y)),n=i.filter((y,m)=>!a[m]);if(n.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:n});let s=a[0].type;if(a.some(y=>y.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[y,m,x]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(m)||m<1||m>x)throw new d("invalid_operation",`${y} must be a whole number from 1 to ${x}`);for(let[y,m]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(m)||m<30||m>2e3)throw new d("invalid_operation",`${y} must be from 30 to 2000 chart units`);let c=e.rows*e.columns;if(c<2)throw new d("invalid_operation","Choose at least two grid cells");let l=i.length*(c-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let f=a.reduce((y,m)=>y+(m.type==="table"?m.seatCount:1),0),h=(t.floors?.length?t.floors.flatMap(y=>y.objects):t.objects).reduce((y,m)=>y+(m.type==="row"||m.type==="table"?m.seatCount:m.type==="gaArea"?Math.max(0,Math.floor(m.capacity)):m.type==="booth"?1:0),0),g=f*(c-1),w=r.maxInventory??1e5;if(h+g>w)throw new d("invalid_operation",`Grid inventory would exceed the ${w} unit event limit`);return{target:o,sources:a,preview:{floorId:o.floorId,kind:s,sourceIds:i,sourceCount:i.length,cells:c,createdCount:l,addedInventory:g,resultingInventory:h+g,provenanceRemovedCount:a.filter(y=>!!y.referenceInventorySource).length*(c-1)}}}function Na(t,e,r={}){return yn(t,e,r).preview}function Da(t,e,r={}){let{target:o,sources:i,preview:a}=yn(t,e,r),n=new Set,s=new Set((t.floors?.length?t.floors.flatMap(u=>u.objects):t.objects).flatMap(u=>"label"in u&&u.label?[u.label]:[])),c=[],l=(u,h)=>{let g=Math.max(2,h),w=m=>{let x=`-${m}`;return`${u.slice(0,Math.max(1,80-x.length))}${x}`},y=w(g);for(;s.has(y);)y=w(++g);return s.add(y),y},f=1;for(let u=0;u<e.rows;u++)for(let h=0;h<e.columns;h++)if(!(u===0&&h===0)){f+=1;for(let g of i){let w=structuredClone(g);w.id=P(t,w.type,e.idFactory,n),w.label=l(g.label,f),w.center={x:g.center.x+h*e.stepX,y:g.center.y+u*e.stepY},delete w.referenceInventorySource,c.push(w)}}return o.objects.push(...c),{...a,createdIds:c.map(u=>u.id)}}function Jo(t,e){let r=t?{...t}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=L(e.color,"Seat label color")),r.size===void 0&&r.color===void 0?void 0:r}var qo=new Set(we.map(t=>t.key));function Le(t){return`${t.rowId}:${t.index}`}function qa(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",o=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(o)||o<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:o}}function Vo(t,e){t.label||delete t.label,t.displayLabel||delete t.displayLabel,t.dx||delete t.dx,t.dy||delete t.dy,t.skip||delete t.skip,t.categoryKey||delete t.categoryKey,he(t.glyph)||delete t.glyph;let r=Lt(t);if(r.length?t.accessibility=r:delete t.accessibility,delete t.accessible,t.commercial){let o=t.commercial.note?.normalize("NFKC").trim(),i={};typeof t.commercial.restrictedView=="boolean"&&(i.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(i.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(i.premium=t.commercial.premium),o&&(i.note=o),Object.keys(i).length?t.commercial=i:delete t.commercial}t.viewFromSeatUrl||(delete t.viewFromSeatUrl,delete t.viewFromSeatMeta),t.labelStyle&&t.labelStyle.size===void 0&&t.labelStyle.color===void 0&&delete t.labelStyle,e?.type==="row"&&Tt(e,t)}function Ho(t){return Object.keys(t).every(e=>e==="index")}function mn(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let o=C(t,e),i=[],a=new Set,n=new Map;for(let s of r){let c=Le(s);if(a.has(c))continue;a.add(c);let l=o.objects.find(f=>(f.type==="row"||f.type==="table")&&f.id===s.rowId);if(!l)throw new d("object_not_found",`Unknown row or table for seat: ${c}`,{seatId:c,objectId:s.rowId});if(l.type==="table"&&(l.bookAsWhole||l.variableOccupancy))throw new d("invalid_operation",`Table "${l.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:c,tableId:l.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=l.seatCount)throw new d("invalid_operation",l.type==="row"?`Seat index is outside row bounds: ${c}`:`Chair index is outside table bounds: ${c}`,{seatId:c,objectId:s.rowId,index:s.index,seatCount:l.seatCount});i.push({rowId:s.rowId,index:s.index}),n.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:n}}function wn(t,e){let r=mn(t,e.floorId,e.seats),o=Object.keys(e.patch);if(!o.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&F(t,e.patch.categoryKey),e.patch.glyph!=null&&!he(e.patch.glyph))throw new d("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(n=>!qo.has(n));if(a.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new d("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of r.refs){let n=r.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??n?.wheelchairSpaceType,c=e.patch.skip===null?!1:e.patch.skip??n?.skip??!1;if(s&&c)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:Le(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new d("invalid_operation","Commercial note supports at most 160 characters");if(e.patch.viewFromSeatUrl!=null){let a=Y(e.patch.viewFromSeatUrl);if(!a)throw new d("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");e.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let n=e.patch[a];if(n!=null&&!Number.isFinite(n))throw new d("invalid_operation",`${a} must be finite`,{[a]:n})}e.patch.labelStyle!=null&&oe(e.patch.labelStyle,"Seat");let i=!1;return r.refs.forEach((a,n)=>{let s=r.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),f=l.find(h=>h.index===a.index);f||(f={index:a.index},l.push(f));let u=f.viewFromSeatUrl;for(let h of o){let g=e.patch[h];if(h==="wheelchairSpaceType"&&g==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(w=>w!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(g==null)delete f[h];else if(h==="accessibility")f.accessibility=[...new Set(g)],delete f.accessible;else if(h==="commercial")f.commercial={...f.commercial,...g};else if(h==="labelStyle"){let w=Jo(f.labelStyle,g);w?f.labelStyle=w:delete f.labelStyle}else Object.assign(f,{[h]:g})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==u&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${n+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${n+1}`),Vo(f,s),Ho(f)&&(s.overrides=l.filter(h=>h!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:r.floorId,changed:i,seatIds:r.refs.map(Le)}}function Va(t,e){let r=mn(t,e.floorId,e.seats),o=!1;for(let[i,a]of r.owners){if(!a.overrides?.length)continue;let n=new Set(r.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!n.has(c.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:r.floorId,changed:o,seatIds:r.refs.map(Le)}}function Wa(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(b=>r.objects.find(p=>p.type==="row"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&F(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let b=e.patch.seatNumbering,p=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(b.scheme!==void 0&&!p.includes(b.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${b.scheme}. Expected one of ${p.join(", ")}.`);if(b.prefix!==void 0&&(typeof b.prefix!="string"||b.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(b.endAt!==void 0&&b.endAt!==null&&(!Number.isInteger(b.endAt)||b.endAt<0||b.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:n,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:f,displayType:u,...h}=e.patch,g=f===void 0?{}:{displayLabel:f},w=ne(g,"Row"),y=u===void 0?void 0:qt(u,"Row");if(n!==void 0&&oe(n,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new d("invalid_operation","Row labelPosition must be one of start, end, both, none");if(c!=null&&(!Number.isFinite(c)||c<-180||c>180))throw new d("invalid_operation","Row labelRotation must be a number from -180 to 180");if(l!==void 0&&l!=="plain"&&l!=="pill")throw new d("invalid_operation","Row labelStyleShape must be plain or pill");h.labelPresentation!==void 0&&je(h.labelPresentation,"Row");let m=b=>JSON.stringify({origin:b.origin,rotation:b.rotation,curve:b.curve,seatCount:b.seatCount,seatSpacing:b.seatSpacing,path:b.path??null}),x=!1;for(let b of i){let p=JSON.stringify(b),v=m(b),I=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?E(b):null;if(Object.assign(b,structuredClone(h)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(S=>S.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),I){let S=E(b);b.origin={x:b.origin.x+I.x-S.x,y:b.origin.y+I.y-S.y}}if(JSON.stringify(b)!==p&&(x=!0),m(b)!==v&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),n!==void 0){let S=JSON.stringify(b.labelPresentation??null),j=Ae(b.labelPresentation,n);j?b.labelPresentation=j:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(s!==void 0){let S=JSON.stringify(b.labelPresentation??null),j=b.labelPresentation?structuredClone(b.labelPresentation):{};j.positionPreset=s,j.visible=s!=="none",delete j.position,b.labelPresentation=j,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(c!==void 0||l!==void 0){let S=JSON.stringify(b.labelPresentation??null),j=b.labelPresentation?structuredClone(b.labelPresentation):{};c===null?delete j.rotation:c!==void 0&&(j.rotation=c),l!==void 0&&(j.style=l),b.labelPresentation=j,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(y!==void 0){let S=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==S&&(x=!0)}if(f!==void 0){let S=b.displayLabel;w?delete b.displayLabel:b.displayLabel=g.displayLabel,b.displayLabel!==S&&(x=!0)}}return{floorId:r.floorId,changed:x,rowIds:o}}var Xo=3;function Me(t){return(t%360+360)%360}function Yo(t){let e=t.rotation*U;return{x:Math.cos(e),y:Math.sin(e)}}function Wo(t,e){let r=Math.abs(Me(t-e));return r>180&&(r=360-r),r}function se(t,e,r){return(t.x-e.x)*r.x+(t.y-e.y)*r.y}function In(t){let e=0,r=0;for(let i of t){let a=2*i.rotation*U;e+=Math.cos(a),r+=Math.sin(a)}let o=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(o),y:Math.sin(o)}}function Zo(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let o=i=>({x:i.x+e,y:i.y+r});t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)}}}function vn(t,e){let r=In(t),o={x:-r.y,y:r.x},i=E(t[0]),a=t.map(c=>({row:c,coord:se(E(c),i,o)})).sort((c,l)=>c.coord-l.coord),n=a[0].coord,s=!1;return a.forEach((c,l)=>{let f=n+l*e-c.coord;Math.abs(f)>1e-6&&(Zo(c.row,o.x*f,o.y*f),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Qo(t,e){let r={x:-e.y,y:e.x},o=E(t[0]),i=t.map(n=>se(E(n),o,r)).sort((n,s)=>n-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function er(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=Ve(t),r=e[0],o=e[e.length-1],i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,n/(t.seatCount-1))),n>1e-6&&(t.rotation=Me(Math.atan2(a,i)/U)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function tr(t,e){let r=new Set(t.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${e}${o}`.slice(0,80);if(!r.has(i))return i}return`${e}-${Date.now().toString(36)}`}function Za(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to merge");let i=o.map(I=>r.objects.find(S=>S.type==="row"&&S.id===I)),a=o.filter((I,S)=>!i[S]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(I=>I.path||I.curve!==0);if(s.length)throw new d("invalid_operation","Only straight rows can be merged. Straighten the rows first, then merge.",{rowIds:s.map(I=>I.id)});let c=n[0],l=n.find(I=>Wo(I.rotation,c.rotation)>Xo);if(l)throw new d("invalid_operation","Rows must be parallel to merge. They point in different directions.",{rowIds:[c.id,l.id]});let f=Yo(c),u={x:-f.y,y:f.x},h=Math.max(8,c.seatSpacing*.6),g=n.find(I=>Math.abs(se(I.origin,c.origin,u))>h);if(g){let I=Math.round(Math.abs(se(g.origin,c.origin,u)));throw new d("invalid_operation",`Rows must lie on the same line to merge: a selected row is offset ${I} units from the first.`,{rowIds:[c.id,g.id]})}let w=n.slice().sort((I,S)=>se(I.origin,c.origin,f)-se(S.origin,c.origin,f)),y=w.reduce((I,S)=>I+S.seatCount,0);if(y>300)throw new d("invalid_operation",`A merged row would have ${y} seats, over the 300-seat row limit. Merge fewer rows.`);let m=w[0],x=[],b=0;for(let I of w){if(I.overrides)for(let S of I.overrides)x.push({...structuredClone(S),index:S.index+b});b+=I.seatCount}m.seatCount=y,m.curve=0,delete m.path,x.length?m.overrides=x:delete m.overrides,delete m.arcFanGeneration,delete m.rowBlockGeneration;let p=w.slice(1).map(I=>I.id),v=new Set(p);for(let I=r.objects.length-1;I>=0;I--)v.has(r.objects[I].id)&&r.objects.splice(I,1);return{floorId:r.floorId,changed:!0,rowId:m.id,removedRowIds:p,seatCount:y}}function Qa(t,e){let r=C(t,e.floorId),o=r.objects.find(g=>g.type==="row"&&g.id===e.rowId);if(!o)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(o.path)throw new d("invalid_operation","Cannot split a free-form curved row. Straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let n=Ve(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:P(t,"r",e.idFactory,new Set),label:tr(r.objects,o.label),origin:{...n[a]},rotation:Me(o.rotation-s*a),curve:s*(c-1),seatCount:c,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(l.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(l.seatLabelStart=o.seatLabelStart),o.commercial&&(l.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(l.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(l.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let g=structuredClone(o.labelPresentation);delete g.position,l.labelPresentation=g}let f=[],u=[];if(o.overrides)for(let g of o.overrides)g.index<a?f.push(structuredClone(g)):u.push({...structuredClone(g),index:g.index-a});o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,u.length&&(l.overrides=u);let h=r.objects.indexOf(o);return r.objects.splice(h+1,0,l),{floorId:r.floorId,changed:!0,rowId:o.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function es(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new d("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(s=>r.objects.find(c=>c.type==="row"&&c.id===s)),a=o.filter((s,c)=>!i[c]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=vn(i,e.gap);return{floorId:r.floorId,changed:n,rowIds:o,gap:e.gap}}function ts(t,e){let r=C(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(h=>r.objects.find(g=>g.type==="row"&&g.id===h)),a=o.filter((h,g)=>!i[g]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=()=>JSON.stringify(n.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),c=s();for(let h of n)er(h);let l=In(n),f=Me(Math.atan2(l.y,l.x)/U);for(let h of n)h.rotation=f;let u=Qo(n,l);return vn(n,u),{floorId:r.floorId,changed:s()!==c,rowIds:o,gap:u}}import lt from"polygon-clipping";var Sn=100,Cn=512,dt=8192,Fn=64,xn=1e7,k=1e-7;function kn(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function En(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&kn(e[0],e[e.length-1]);)e.pop();return e}function ye(t,e,r){let o=$(e,r,t);return Math.abs(o)>k?!1:t.x>=Math.min(e.x,r.x)-k&&t.x<=Math.max(e.x,r.x)+k&&t.y>=Math.min(e.y,r.y)-k&&t.y<=Math.max(e.y,r.y)+k}function Ln(t,e,r,o){let i=$(t,e,r),a=$(t,e,o),n=$(r,o,t),s=$(r,o,e);return(i>k&&a<-k||i<-k&&a>k)&&(n>k&&s<-k||n<-k&&s>k)?!0:Math.abs(i)<=k&&ye(r,t,e)||Math.abs(a)<=k&&ye(o,t,e)||Math.abs(n)<=k&&ye(t,r,o)||Math.abs(s)<=k&&ye(e,r,o)}function nr(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let o=e+1;o<t.length;o+=1){let i=(o+1)%t.length;if(!(e===o||r===o||i===e)&&Ln(t[e],t[r],t[o],t[i]))return!0}}return!1}function Rn(t,e){return t.some((r,o)=>e.some((i,a)=>Ln(r,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function ft(t,e){return!e.some((r,o)=>ye(t,r,e[(o+1)%e.length]))&&M(t,e,void 0)}function Ne(t,e,r){let o=En(t);if(o.length<3||o.length>Cn||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>xn||Math.abs(i.y)>xn||kn(i,o[(a+1)%o.length]))||Math.abs(ve(o))<=k||nr(o))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${Cn} finite vertices per ring.`,{gaAreaId:r,ring:e});return o}function or(t){let e=Ne(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>Fn)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=r.map(i=>Ne(i,"cutout",t.id));for(let i=0;i<o.length;i+=1){let a=o[i];if(!a.flatMap((s,c)=>{let l=a[(c+1)%a.length];return[s,{x:(s.x+l.x)/2,y:(s.y+l.y)/2}]}).every(s=>ft(s,e))||Rn(a,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<o.length;s+=1)if(Rn(a,o[s])||ft(a[0],o[s])||ft(o[s][0],a))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:o}}function Te(t){return t.map(e=>[e.x,e.y])}function _n(t){return En(t.map(([e,r])=>({x:e,y:r})))}function On(t){return Math.abs(t.reduce((e,r,o)=>{let i=t[(o+1)%t.length];return e+r[0]*i[1]-i[0]*r[1]},0))/2}function rr(t){return t.reduce((e,r)=>e+(On(r[0]??[])-r.slice(1).reduce((o,i)=>o+On(i),0)),0)}function ut(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(ut).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${ut(e[r])}`).join(",")}}`}function jn(t,e,r){let o=t[e];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return i}function An(t){return ut({categoryKey:t.categoryKey,displayLabel:jn(t,"displayLabel",80),displayType:jn(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Pn(t,e){let r=Math.min(...t.points.map(i=>i.y)),o=Math.min(...t.points.map(i=>i.x));return[r,o,e]}function ir(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function Mn(t,e,r={}){let o=C(t,e.floorId),i=[...new Set(e.gaAreaIds)];if(i.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(i.length>Sn)throw new d("invalid_operation",`Join Areas supports at most ${Sn} areas at once`);let a=i.map(R=>o.objects.find(O=>O.type==="gaArea"&&O.id===R)),n=i.filter((R,O)=>!a[O]);if(n.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:n});let s=a;F(t,s[0].categoryKey);let c=An(s[0]),l=s.find(R=>An(R)!==c);if(l)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[s[0].id,l.id]});let f=ge(t).objectToSection,u=f.get(s[0].id)??"__ungrouped__",h=s.find(R=>(f.get(R.id)??"__ungrouped__")!==u);if(h)throw new d("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[s[0].id,h.id],sectionIds:[u,f.get(h.id)??"__ungrouped__"]});let g=s.reduce((R,O)=>{if(!Number.isInteger(O.capacity)||O.capacity<1||O.capacity>W)throw new d("invalid_operation",`GA area ${O.id} has invalid capacity`,{gaAreaId:O.id});return R+O.capacity},0);if(g>W)throw new d("invalid_operation",`Joined GA capacity would be ${g}, over the ${W}-unit area limit`,{capacity:g});let w=B(t).reduce((R,O)=>R+ee(O),0),y=r.maxInventory??1e5;if(w>y)throw new d("invalid_operation",`Chart inventory exceeds the ${y}-unit publication limit`,{inventory:w});let m=s.map(or),x=m.reduce((R,O)=>R+O.outer.length+O.holes.reduce((G,H)=>G+H.length,0),0);if(x>dt)throw new d("invalid_operation",`Join Areas supports at most ${dt} source vertices`,{vertexCount:x});let b;try{let R=m.map(H=>[Te(H.outer)]);if(b=lt.union(R[0],...R.slice(1)),b.length!==1)throw new d("invalid_operation","Selected GA areas must overlap or share an edge. Disconnected or point-only contact cannot produce one sellable surface.",{surfaceCount:b.length});let O=m.flatMap(H=>H.holes.map($e=>[Te($e)]));O.length&&(b=lt.difference(b,...O));let G=m.findIndex(H=>{let $e=[Te(H.outer),...H.holes.map(Te)];return rr(lt.intersection($e,b))<=k});if(G>=0)throw new d("invalid_operation",`GA area ${s[G].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:s[G].id})}catch(R){throw R instanceof d?R:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:R instanceof Error?R.message:"polygon_union_failed"})}if(b.length!==1||!b[0]?.length)throw new d("invalid_operation","Joining these boundaries would create disconnected sellable surfaces; adjust the outlines or cutouts first.",{surfaceCount:b.length});let p=_n(b[0][0]),v=b[0].slice(1).map(_n),I=p.length+v.reduce((R,O)=>R+O.length,0);if(v.length>Fn||I>dt)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:v.length,vertexCount:I});Ne(p,"outline",s[0].id),v.forEach(R=>Ne(R,"cutout",s[0].id));let S=new Map(o.objects.map((R,O)=>[R.id,O])),j=s.slice().sort((R,O)=>ir(Pn(R,S.get(R.id)??Number.MAX_SAFE_INTEGER),Pn(O,S.get(O.id)??Number.MAX_SAFE_INTEGER))),J=j[0],V=structuredClone(t),D=C(V,o.floorId),K=D.objects.find(R=>R.type==="gaArea"&&R.id===J.id);K.points=structuredClone(p),v.length?K.holes=structuredClone(v):delete K.holes;let _=new Set(j.slice(1).map(R=>R.id));for(let R=D.objects.length-1;R>=0;R-=1)_.has(D.objects[R].id)&&D.objects.splice(R,1);let z=ge(V).objectToSection.get(J.id)??"__ungrouped__";if(z!==u)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:J.id,beforeSectionId:u,afterSectionId:z});let A=[],fe=new Set;for(let R of j){if(!Dt(R))throw new d("invalid_operation",`GA area ${R.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:R.id});let O=Z(R);if(O.length!==R.capacity||O.some(G=>fe.has(G)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:R.id});O.forEach(G=>fe.add(G)),A.push(...Kt(R))}if(A.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let Dn=new Set(s.map(R=>R.id));for(let R of B(t).filter(O=>O.type==="gaArea"&&!Dn.has(O.id))){let O=Z(R).find(G=>fe.has(G));if(O)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:O,gaAreaId:R.id})}let Kn=j.slice(1).map(R=>R.id);return{floorId:o.floorId,areaId:J.id,survivorLabel:J.label,removedAreaIds:Kn,sourceAreaCount:j.length,capacity:g,inventorySegmentCount:A.length,outerVertexCount:p.length,holeCount:v.length,sectionId:u,points:p,...v.length?{holes:v}:{},segments:A}}function ls(t,e,r={}){let{segments:o,...i}=Mn(t,e,r);return i}function ds(t,e,r={}){let o=Mn(t,e,r),i=C(t,o.floorId),a=i.objects.find(l=>l.type==="gaArea"&&l.id===o.areaId);a.points=structuredClone(o.points),o.holes?.length?a.holes=structuredClone(o.holes):delete a.holes,a.capacity=o.capacity,a.inventorySegments=structuredClone(o.segments);let n=new Set(o.removedAreaIds);for(let l=i.objects.length-1;l>=0;l-=1)n.has(i.objects[l].id)&&i.objects.splice(l,1);let{segments:s,...c}=o;return{...c,changed:!0}}function ms(t,e){let r=C(t,e.floorId),o=[...new Set(e.shapeIds)];if(!o.length)throw new d("invalid_operation","At least one shape id is required");let i=o.map(l=>r.objects.find(f=>f.type==="shape"&&f.id===l)),a=o.filter((l,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one shape change is required");if(n.label!==void 0){if(o.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(n.label!==null){if(n.label=n.label.normalize("NFKC").trim(),!n.label)n.label=null;else if(n.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(n.labelStyle!==void 0){let l=i.filter(f=>f.role!=="stage");if(l.length)throw new d("invalid_operation","Shape label styling applies only to stages",{shapeIds:l.map(f=>f.id)});if(n.labelStyle.size!==void 0&&n.labelStyle.size!==null&&(!Number.isFinite(n.labelStyle.size)||n.labelStyle.size<Be||n.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${Be} to ${72}`);if(n.labelStyle.color!==void 0&&n.labelStyle.color!==null&&(n.labelStyle.color=L(n.labelStyle.color,"Shape label color")),n.labelStyle.fontFamily!==void 0&&n.labelStyle.fontFamily!==null&&(n.labelStyle.fontFamily=n.labelStyle.fontFamily.normalize("NFKC").trim(),!n.labelStyle.fontFamily||n.labelStyle.fontFamily.length>120))throw new d("invalid_operation","Stage label fontFamily must contain 1 to 120 characters");if(n.labelStyle.direction!==void 0&&n.labelStyle.direction!==null&&!yt.includes(n.labelStyle.direction))throw new d("invalid_operation","Stage label direction must be horizontal, vertical, or auto");for(let f of["bold","italic","underline"]){let u=n.labelStyle[f];if(u!=null&&typeof u!="boolean")throw new d("invalid_operation",`Stage label ${f} must be a boolean`)}}if(n.fill!==void 0&&n.fill!==null&&(n.fill=L(n.fill,"Shape fill")),n.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(n.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(n.stroke!==void 0&&n.stroke!==null){if(!Number.isFinite(n.stroke.width)||n.stroke.width<.5||n.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");n.stroke={color:L(n.stroke.color,"Shape stroke"),width:n.stroke.width}}if(n.cornerRadius!==void 0&&n.cornerRadius!==null&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(n.opacity!==void 0&&n.opacity!==null&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(n.heightM!==void 0&&n.heightM!==null&&(!Number.isFinite(n.heightM)||n.heightM<.05||n.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(n.eventConfigurationIds!==void 0&&n.eventConfigurationIds!==null){let l=n.eventConfigurationIds.map(f=>f.normalize("NFKC").trim());if(!l.length||l.length>20||l.some(f=>!f||f.length>100)||new Set(l).size!==l.length)throw new d("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");n.eventConfigurationIds=l}if(n.lineCap!==void 0&&n.lineCap!==null&&!zt.includes(n.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(n.lineJoin!==void 0&&n.lineJoin!==null&&!Bt.includes(n.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,f]of[["startEnding",n.startEnding],["endEnding",n.endEnding]])if(f!=null&&!Ut.includes(f))throw new d("invalid_operation",`Shape ${l} must be none or arrow`);if(n.lineCap!=null||n.lineJoin!=null||n.startEnding!=null||n.endEnding!=null){let l=i.filter(f=>!Qe(n.kind??f.kind));if(l.length)throw new d("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:l.map(f=>f.id)})}let c=!1;for(let l of i){let f=JSON.stringify(l);if(n.label===null?delete l.label:n.label!==void 0&&(l.label=n.label),n.labelStyle!==void 0){let u={...l.labelStyle};n.labelStyle.size===null?delete u.size:n.labelStyle.size!==void 0&&(u.size=n.labelStyle.size),n.labelStyle.color===null?delete u.color:n.labelStyle.color!==void 0&&(u.color=n.labelStyle.color),n.labelStyle.fontFamily===null?delete u.fontFamily:n.labelStyle.fontFamily!==void 0&&(u.fontFamily=n.labelStyle.fontFamily),n.labelStyle.bold===null?delete u.bold:n.labelStyle.bold!==void 0&&(u.bold=n.labelStyle.bold),n.labelStyle.italic===null||n.labelStyle.italic===!1?delete u.italic:n.labelStyle.italic===!0&&(u.italic=!0),n.labelStyle.underline===null||n.labelStyle.underline===!1?delete u.underline:n.labelStyle.underline===!0&&(u.underline=!0),n.labelStyle.direction===null||n.labelStyle.direction==="horizontal"?delete u.direction:n.labelStyle.direction!==void 0&&(u.direction=n.labelStyle.direction),Object.keys(u).length?l.labelStyle=u:delete l.labelStyle}if(n.fill===null?delete l.fill:n.fill!==void 0&&(l.fill=n.fill),n.kind!==void 0&&(l.kind=n.kind,Qe(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),n.stroke===null?delete l.stroke:n.stroke!==void 0&&(l.stroke={...n.stroke}),n.opacity===null?delete l.opacity:n.opacity!==void 0&&(l.opacity=n.opacity),n.heightM===null?delete l.heightM:n.heightM!==void 0&&(l.heightM=n.heightM),n.eventConfigurationIds===null?delete l.eventConfigurationIds:n.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...n.eventConfigurationIds]),n.lineCap===null?delete l.lineCap:n.lineCap!==void 0&&(l.lineCap=n.lineCap),n.lineJoin===null?delete l.lineJoin:n.lineJoin!==void 0&&(l.lineJoin=n.lineJoin),n.startEnding===null?delete l.startEnding:n.startEnding!==void 0&&(l.startEnding=n.startEnding),n.endEnding===null?delete l.endEnding:n.endEnding!==void 0&&(l.endEnding=n.endEnding),n.cornerRadius===null)delete l.cornerRadius;else if(n.cornerRadius!==void 0){let u=Math.min(l.width??1/0,l.height??1/0),h=Number.isFinite(u)?u/2:n.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(n.cornerRadius,h)):n.cornerRadius}JSON.stringify(l)!==f&&(Se(l),c=!0)}return{floorId:r.floorId,changed:c,shapeIds:o}}function Tn(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),o=e.map(f=>f.y),i=Math.min(...r),a=Math.max(...r),n=Math.min(...o),s=Math.max(...o),c=Math.max(1,a-i),l=Math.max(1,s-n);return{cx:i+c/2,cy:n+l/2,width:c,height:l}}function ws(t,e){let r=C(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let o=e.updates.map(n=>n.shapeId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Shape ids must be unique");let i=e.updates.map(n=>{if(![n.width,n.height].every(Number.isFinite)||n.width<8||n.height<8||n.width>1e4||n.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:n.shapeId});let s=r.objects.find(l=>l.type==="shape"&&l.id===n.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${n.shapeId}`,{shapeId:n.shapeId});let c=s.role==="stage"?Tn(s):(s.kind==="rect"||s.kind==="ellipse")&&s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null?{cx:s.x+s.width/2,cy:s.y+s.height/2,width:s.width,height:s.height}:(()=>{let l=s.points??[];if(l.length<3||l.some(m=>!Number.isFinite(m.x)||!Number.isFinite(m.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=l.map(m=>m.x),u=l.map(m=>m.y),h=Math.min(...f),g=Math.max(...f),w=Math.min(...u),y=Math.max(...u);return{cx:(h+g)/2,cy:(w+y)/2,width:Math.max(1,g-h),height:Math.max(1,y-w)}})();return{shape:s,update:n,box:c}}),a=!1;for(let{shape:n,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(n.kind==="rect"||n.kind==="ellipse")n.x=c.cx-s.width/2,n.y=c.cy-s.height/2,n.width=s.width,n.height=s.height;else{let l=s.width/c.width,f=s.height/c.height;n.points=(n.points??[]).map(u=>({x:c.cx+(u.x-c.cx)*l,y:c.cy+(u.y-c.cy)*f})),(n.x!=null||n.y!=null||n.width!=null||n.height!=null||n.role==="stage")&&(n.x=c.cx-s.width/2,n.y=c.cy-s.height/2,n.width=s.width,n.height=s.height)}a=!0}return{floorId:r.floorId,changed:a,shapes:i.map(({shape:n,update:s})=>({id:n.id,width:s.width,height:s.height}))}}function Is(t,e){let r=C(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let o=e.updates.map(s=>s.stageId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Stage ids must be unique");let i=new Set(kt.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let c=r.objects.find(l=>l.type==="shape"&&l.id===s.stageId);if(!c)throw new d("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(c.role!=="stage")throw new d("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:c,stageKind:s.stageKind,box:c.stageKind===s.stageKind?null:Tn(c)}}),n=!1;for(let s of a)s.box&&(s.shape.points=Et({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,n=!0);return{floorId:r.floorId,changed:n,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function Rs(t){return[...pt(t)].map(([e,r])=>({key:e,...r}))}function sr(t){if(!Array.isArray(t))return pt(t);let e=new Map;for(let{key:r,target:o,evidence:i}of t)e.set(r,{target:o,evidence:i});return e}function pt(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let r of T(t)){r.confidenceEvidence&&e.set(`floor:${r.id}`,{target:{scope:"floor",floorId:r.id},evidence:r.confidenceEvidence});for(let o of r.objects){let i=`floor:${r.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&e.set(i,{target:{scope:o.type,floorId:r.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&e.set(`${i}:segmented`,{target:{scope:"row",floorId:r.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&e.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:r.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return e}function De(t){return Array.isArray(t)?t.map(De):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[r])=>e.localeCompare(r)).map(([e,r])=>[e,De(r)]))}function cr(t,e){return JSON.stringify(De(t))===JSON.stringify(De(e))}function gt(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function lr(t){return t?t.status==="retracted"?"retract":gt(t)?"approve":"set":"clear"}function dr(t,e){let r=sr(t),o=pt(e),i=[...new Set([...r.keys(),...o.keys()])].sort(),a=[];for(let n of i){let s=r.get(n),c=o.get(n);if(s&&c&&cr(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:lr(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function _s(t,e){return dr(t,e).some(r=>gt(r.before)||gt(r.after))}var fr=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),ur=new Set(["generated","geometry-verified","configuration-verified"]),gr=new Set(["none","comparable-build-reference","actual-build-checked"]),hr=new Set(["clear","partial","obstructed"]);function ht(t){return t.toISOString().slice(0,10)}function bt(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function le(t,e,r){if(!bt(t,e))throw new d("invalid_operation",`Confidence evidence ${r} is invalid`,{field:r});return t}function ce(t,e,r){if(t!==void 0)return le(t,e,r)}function Ke(t,e,r){let o=r?[C(t,r)]:T(t).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(n=>n.id===e);if(a)return{floorId:i.floorId,object:a}}throw new d("object_not_found",`Unknown chart object: ${e}`,{objectId:e,floorId:r})}function Nn(t,e){let r=T(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return o}function me(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return Nn(t,e.floorId).confidenceEvidence;if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let o=Ke(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new d("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:e.objectId});return o.object.overrides?.find(i=>i.index===e.seatIndex)?.confidenceEvidence}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let r=Ke(t,e.objectId,e.floorId);if(e.scope==="row"&&r.object.type!=="row")throw new d("invalid_operation","Row evidence requires a row id",{objectId:e.objectId});if(e.scope==="section"&&r.object.type!=="section")throw new d("invalid_operation","Section evidence requires a section id",{objectId:e.objectId});if(r.object.type==="row"||r.object.type==="section")return r.object.confidenceEvidence;throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:r.object.type})}function Ge(t,e,r){if(e.scope==="venue")return r?t.confidenceEvidence=r:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=Nn(t,e.floorId);return r?i.confidenceEvidence=r:delete i.confidenceEvidence,{floorId:i.id}}if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let i=Ke(t,e.objectId,e.floorId);return wn(t,{floorId:i.floorId,seats:[{rowId:e.objectId,index:e.seatIndex}],patch:{confidenceEvidence:r??null}}),{floorId:i.floorId,objectId:e.objectId}}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let o=Ke(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:o.object.type});return r?o.object.confidenceEvidence=r:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function br(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!bt(t.label,80)||!bt(t.methodLabel,100))throw new d("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(t.totalRayCount)||t.totalRayCount<1||t.totalRayCount>1e3||!Number.isInteger(t.clearRayCount)||t.clearRayCount<0||t.clearRayCount>t.totalRayCount)throw new d("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!hr.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(r=>le(r,80,"occluder label"));return{label:t.label,methodLabel:t.methodLabel,totalRayCount:t.totalRayCount,clearRayCount:t.clearRayCount,classification:t.classification,...e?.length?{occluderLabels:e}:{}}}function pr(t,e=new Date){if(t.schema!==void 0&&t.schema!=="seatlayer.seat-confidence/1")throw new d("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!fr.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!ur.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let r=t.realityLevel??"none";if(!gr.has(r))throw new d("invalid_operation","Confidence evidence reality level is invalid");if(t.evidenceKind==="synthetic-model"&&(t.modelLevel!=="generated"||r!=="none"))throw new d("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=ce(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(u=>le(u,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=ce(t.assessedAt,40,"assessedAt")??ht(e),n=Date.parse(a);if(!Number.isFinite(n))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=ce(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:ht(new Date(n+365*24*60*60*1e3))),c=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(c)||c<n||c>n+366*24*60*60*1e3))throw new d("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let l=ce(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let f=ce(t.sourceLabel,120,"sourceLabel");if(r!=="none"&&!f)throw new d("invalid_operation","Real-world evidence requires a buyer-safe source describing what was checked");if(r==="actual-build-checked"&&(t.modelLevel!=="configuration-verified"||!o))throw new d("invalid_operation","An actual-build check requires a configuration-verified model and an event configuration");return{schema:"seatlayer.seat-confidence/1",evidenceId:le(t.evidenceId,120,"evidenceId"),modelVersion:le(t.modelVersion,120,"modelVersion"),evidenceKind:t.evidenceKind,modelLevel:t.modelLevel,realityLevel:r,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...t.eventConfigurationVersion!==void 0?{eventConfigurationVersion:t.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...l?{approvedByRole:l}:{},...f?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:br(t.modeledTarget)}:{}}}function de(t,e={}){return{changed:e.changed??!0,scope:t.scope,...t.objectId?{objectId:t.objectId}:{},...t.floorId?{floorId:t.floorId}:{},...t.seatIndex!==void 0?{seatIndex:t.seatIndex}:{},...e}}function Os(t,e){let r=pr(e.evidence,e.now),o=JSON.stringify(me(t,e)??null),i=Ge(t,e,r),a=JSON.stringify(me(t,e)??null);return de(e,{changed:o!==a,...i,evidenceId:r.evidenceId,status:"draft"})}function js(t,e){let r=me(t,e);if(!r)return de(e,{changed:!1});let o=Ge(t,e,void 0);return de(e,{changed:!0,...o,evidenceId:r.evidenceId})}function As(t,e){let r=me(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to approve",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")throw new d("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=le(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=ce(e.eventConfigurationId,100,"eventConfigurationId")??r.eventConfigurationId;if(r.modelLevel==="configuration-verified"&&!i)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=e.eventConfigurationVersion??r.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let n={...r,status:"approved",approvedByRole:o,assessedAt:ht(e.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete n.basisSha256;let s=e.basisSha256??t.confidenceBasisSha256;s&&(n.basisSha256=s);let c=JSON.stringify(r),l=Ge(t,e,n);return de(e,{changed:c!==JSON.stringify(n),...l,evidenceId:n.evidenceId,status:"approved"})}function Ps(t,e){let r=me(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to retract",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")return de(e,{changed:!1,evidenceId:r.evidenceId,status:"retracted"});let o={...r,status:"retracted"};delete o.basisSha256;let i=Ge(t,e,o);return de(e,{changed:!0,...i,evidenceId:r.evidenceId,status:"retracted"})}export{on as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,_r as DEFAULT_FLOOR_HEIGHT_STEP_M,Gn as DEFAULT_SECTION_CORNER_SMOOTHING,yr as MAX_BUYER_IMAGE_URL_LENGTH,Rr as MAX_FLOOR_BASE_HEIGHT_M,ra as addArcFanRows,Da as addBookableGridArray,ha as addBoothArray,so as addChartCategory,Or as addChartFloor,Lr as addChartZone,ua as addGAArea,fa as addRowBlock,ga as addTableArray,gi as applyPolygonHole,La as applyReferenceScanRows,ji as applySectionCornerSmoothing,Ei as applySectionEstimates,to as applySectionOutlineShaping,ui as applySectionRowFit,As as approveConfidenceEvidence,_o as arcFanInputForGroup,xi as assignSectionInventoryCategory,ea as automaticPlacementCenter,js as clearConfidenceEvidence,Cr as compactChartDoc,vr as compactRowOverrides,Sr as compactTableOverrides,_s as confidenceEvidenceChangeRequiresPublish,dr as confidenceEvidenceChanges,Rs as confidenceEvidenceIndex,Ui as confirmReferenceCategoryOutputColor,Ri as convertGeneratedSectionToPolygon,nt as countCoveredInventory,Ir as detectSeatLabelRun,Tt as dropRedundantSeatOverrideFields,bo as familyCategoryLabel,Po as gaAreaFootprint,ba as groupRowsAsSegmented,ri as insertSeatingBlock,mr as isSafeBuyerImageUrl,ds as joinGAAreas,Za as mergeRows,Pe as mirrorFirstFloor,Y as normalizeBuyerImageUrl,pr as normalizeDraftEvidence,qa as parseSeatRefId,ao as pickColorblindSafeCategoryColor,mo as planCreationCategory,rn as previewArcFanRows,Na as previewBookableGridArray,Zn as previewGeneratedSectionPolygonConversion,ls as previewJoinGAAreas,ot as previewPolygonHole,Xn as previewRemovePolygonHole,Un as previewRowCubicPath,Vn as previewSectionRowFit,Bi as reassignColorblindSafeCategoryColors,oi as relabelChartRows,qi as removeChartCategory,Pr as removeChartFloor,ti as removeChartObjects,Tr as removeChartZone,hi as removePolygonHole,jr as renameChartFloor,$i as renameDirectSeatImportCategory,zi as reorderChartCategories,ia as replaceArcFanRows,ma as replaceRowBlock,Va as resetSeatOverrides,ws as resizeShapes,Ji as resolveCreationCategory,Ps as retractConfidenceEvidence,xr as roundBuyerCoordinates,Le as seatRefId,wr as seatSemanticsSignature,Wn as sectionInventorySelectionSummary,Os as setConfidenceEvidence,es as setRowBlockSpacing,Qa as splitRow,ts as straightenAndSpaceRows,_i as transformSectionBoundary,Qn as transformSectionBoundaryObject,pa as ungroupSegmentedRow,Qr as updateBooths,oo as updateCategoryDefinitions,Ar as updateChartFloorBaseHeight,Zi as updateChartTheme,Mr as updateChartZones,ei as updateGAAreas,fi as updateRowCubicPath,Wa as updateRows,wn as updateSeatOverrides,Oi as updateSectionExactPath,tn as updateSectionMetadata,ya as updateSegmentedRow,ms as updateShapes,Is as updateStageKinds,Zr as updateTables,ni as updateTextObjects,Qi as updateViewFromSeatFallback};
|
|
1
|
+
import{a as dt}from"../../chunk-5N4H3KMR.js";import{a as d,b as O,c as M,d as k,e as re,f as Te,g as un,h as Ne,i as le,j as L,k as te,l as Le,m as de,n as lt,o as Ce,p as H,q as Q,r as W,s as ie,t as De,u as ii,v as ai,w as si,x as ci,y as li,z as di}from"../../chunk-4DYJCT62.js";import{a as Me,b as Ee,f as fn}from"../../chunk-4R6TXHY2.js";import{g as at,h as st}from"../../chunk-66T4EAUA.js";import{c as Zt,d as on,h as rn,i as an}from"../../chunk-PHV2U54Y.js";import"../../chunk-JRZHC75P.js";import{a as _t,b as Ze,e as je,k as Qe,n as At}from"../../chunk-UEDS3HJ3.js";import{k as Se}from"../../chunk-4N5CHKHD.js";import{i as sn,k as cn,l as ln,m as dn,q as ct}from"../../chunk-TQN2VWQO.js";import{a as Fe,d as Qr,e as ei,f as Wt,g as ti,h as ni,i as oi,j as ri}from"../../chunk-FOIYJ5NT.js";import{b as ce,c as J,e as Qt,f as en,g as ot,h as tn,i as Ie,k as Z,o as rt,v as ve}from"../../chunk-COECA63Q.js";import{Aa as Ht,Ba as Xt,Ca as ee,F as Lt,Fa as X,J as ke,Ja as me,Ma as we,Na as K,P as Dt,Pa as N,Q as tt,R as Gt,Ra as G,S as Kt,T as $t,Ta as Y,U as po,Xa as Yt,Y as Bt,a as Wr,b as Zr,c as oe,e as et,q as jt,r as Pt,s as kt,sa as qt,t as Ft,u as Mt,v as Et,w as Pe,wa as Vt,x as Tt,y as Nt}from"../../chunk-EIV3CAGV.js";import{e as zt,h as nt,p as Ut,q as Jt}from"../../chunk-KTMZ3QAO.js";import{i as nn,n as it}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function hi(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:k(t,"zone",e.idFactory,new Set),label:lt(t,e.label),color:L(e.color,"Zone color"),...e.focalPoint?{focalPoint:Ce(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function bi(t,e){if(!e.updates.length)throw new d("invalid_operation","At least one zone update is required");let r=e.updates.map(c=>c.zoneId);if(new Set(r).size!==r.length)throw new d("invalid_operation","Zone ids must be unique");let o=new Map((t.zones??[]).map(c=>[c.id,c])),i=r.filter(c=>!o.has(c));if(i.length)throw new d("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),n=new Map((a.zones??[]).map(c=>[c.id,c]));for(let c of e.updates){if(!Object.keys(c.patch).length)throw new d("invalid_operation",`Zone ${c.zoneId} has no changes`);let f=n.get(c.zoneId);c.patch.label!==void 0&&(f.label=lt(a,c.patch.label,f.id)),c.patch.color!==void 0&&(f.color=L(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(f.focalPoint=Ce(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:r,zones:r.map(c=>structuredClone(n.get(c)))}}function pi(t,e){let r=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let o=G(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(o.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${o.length} section(s)`,{zoneId:e.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 t.zones.splice(r,1),t.zones.length||delete t.zones,De(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var ae={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 xe(t,e,r,o,i,a,n=0){return{type:"row",id:t,label:e,origin:{x:-(o-1)*i/2,y:r},rotation:0,curve:n,seatCount:o,seatSpacing:i,categoryKey:a}}function yo(t,e,r,o,i,a){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function gn(t,e,r,o,i,a){let n=r/2,s=o/2;return{type:"gaArea",id:t,label:e,points:[{x:-n,y:-s},{x:n,y:-s},{x:n,y:s},{x:-n,y:s}],capacity:i,categoryKey:a}}function mo(t,e,r,o,i){let a=r*2,n=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];n.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:n}}var hn=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[ae.balcony],sectionLabel:"Balcony",build:()=>[xe("blk-b0","A",-45,18,24,"balcony",18),xe("blk-b1","B",-15,20,24,"balcony",18),xe("blk-b2","C",15,22,24,"balcony",18),xe("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[ae.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>xe(`blk-r${e}`,"ABCDEF"[e],-80+e*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[ae.standard],build:()=>[gn("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[ae.premium],build:()=>Array.from({length:6},(t,e)=>yo(`blk-t${e}`,`T${e+1}`,{x:-150+e%3*150,y:e<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[ae.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:[ae.standard],build:()=>[gn("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:[ae.standard],build:()=>[mo("blk-wc","A",4,40,"standard")]}];function U(t){let e="",r=t;do e=String.fromCharCode(65+r%26)+e,r=Math.floor(r/26)-1;while(r>=0);return e}function bn(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let r of t)e=e*26+(r.charCodeAt(0)-64);return e-1}function pn(t,e,r){let o=i=>({x:i.x+e,y:i.y+r});switch(t.type){case"row":t.origin=o(t.origin),t.path&&(t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)});break;case"table":case"booth":t.center=o(t.center);break;case"text":t.position=o(t.position);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=we(t.holes).map(i=>i.map(o)));break;case"section":t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=Gt(t.outlinePath,e,r)),t.holes&&(t.holes=we(t.holes).map(i=>i.map(o))),t.labelPresentation?.position&&(t.labelPresentation.position=o(t.labelPresentation.position));break;case"shape":t.points&&(t.points=t.points.map(o)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}var wo=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","wheelchairPlaces"],yn=(t,e,r)=>Number.isInteger(t)&&t>=e&&t<=r;function mn(t){let e={};for(let r of wo){if(!(r in t))continue;let o=t[r];delete t[r],o!==void 0&&(e[r]=o)}for(let r of["bookAsWhole","variableOccupancy"])if(e[r]!==void 0&&typeof e[r]!="boolean")throw new d("invalid_operation",`${r} must be true or false`);if(e.bookAsWhole===!0&&e.variableOccupancy===!0)throw new d("invalid_operation","A standing area cannot be sold whole and by party size at the same time");if(e.variableOccupancy===!1&&(e.minOccupancy!==void 0||e.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with party-size selling");for(let r of["minOccupancy","maxOccupancy"])if(e[r]!==void 0&&!yn(e[r],1,J))throw new d("invalid_operation",`${r} must be a whole number from 1 to ${J}`);if(e.wheelchairPlaces!==void 0&&!yn(e.wheelchairPlaces,0,J))throw new d("invalid_operation",`wheelchairPlaces must be a whole number from 0 to ${J}`);return e}function wn(t,e){if(Object.assign(t,e),e.bookAsWhole===!0&&delete t.variableOccupancy,e.variableOccupancy===!0&&delete t.bookAsWhole,t.bookAsWhole||delete t.bookAsWhole,!t.variableOccupancy){if(e.minOccupancy!==void 0||e.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on an area sold by party size",{gaAreaId:t.id});delete t.variableOccupancy,delete t.minOccupancy,delete t.maxOccupancy}t.wheelchairPlaces||delete t.wheelchairPlaces;let r=Ie(t);if(r&&t.inventorySegments!==void 0)throw new d("invalid_operation",`Joined area "${t.label}" is sold per person: its places keep the identities of the areas it was joined from, so it cannot become one box`,{gaAreaId:t.id});if(r&&t.capacity>ot)throw new d("invalid_operation",tn,{gaAreaId:t.id,capacity:t.capacity,max:ot});if(r&&ce(t.label))throw new d("invalid_operation",`Area label "${t.label}" uses SeatLayer's reserved GA namespace`,{gaAreaId:t.id});if(r==="variable"&&(!Number.isInteger(t.minOccupancy)||!Number.isInteger(t.maxOccupancy)||t.minOccupancy<1||t.maxOccupancy<t.minOccupancy||t.maxOccupancy>t.capacity))throw new d("invalid_operation",`Area "${t.label}" needs whole-number fewest and most guests from 1 to its ${t.capacity}-person capacity`,{gaAreaId:t.id,capacity:t.capacity});if(t.wheelchairPlaces!==void 0&&t.wheelchairPlaces>t.capacity)throw new d("invalid_operation",`Area "${t.label}" has ${t.capacity} places, so at most ${t.capacity} can be wheelchair places`,{gaAreaId:t.id,capacity:t.capacity})}function In(t,e){let r=e.filter(a=>Ie(a));if(!r.length)return;let o=new Map(e.map(a=>[a.id,a])),i=new Map(r.map(a=>[a.label,a.id]));for(let a of G(t))for(let n of a.objects){let s=n.type==="gaArea"?o.get(n.id)??n:n,c=[];s.type==="row"?c=X(s).map(l=>l.label):s.type==="table"?c=s.bookAsWhole||s.variableOccupancy?[s.label]:me(s).map(l=>l.label):s.type==="booth"?c=[s.label]:s.type==="gaArea"&&(c=Z(s));for(let l of c){let f=i.get(l);if(f&&f!==s.id)throw new d("invalid_operation",`Inventory label "${l}" is already in use; an area sold as one box needs a unique label`,{gaAreaId:f,inventoryLabel:l,conflictingObjectId:s.id})}}}var vn=40,Sn=160;function Io(t,e){let r=t.normalize("NFKC").trim();if(r.length>vn)throw new d("invalid_operation",`${e} entrance must be at most ${vn} characters`);return r}function Ge(t,e){let r={};if("labelStyle"in t){let o=t.labelStyle;if(delete t.labelStyle,o!==void 0){if(o.color!==void 0)throw new d("invalid_operation",`${e} names use the chart's label colour; only visible and size can change`);if(te(o,e),o.visible!==void 0&&typeof o.visible!="boolean")throw new d("invalid_operation",`${e} name visibility must be true or false`);r.labelStyle=o}}if("entrance"in t){let o=t.entrance;if(delete t.entrance,o===null)r.entrance=null;else if(o!==void 0){if(typeof o!="string")throw new d("invalid_operation",`${e} entrance must be text`);r.entrance=Io(o,e)||null}}return r}function Ke(t,e){if(e.labelStyle){let r=de(t.labelPresentation,e.labelStyle);r?.visible===!0&&delete r.visible,r&&Object.keys(r).length?t.labelPresentation=r:delete t.labelPresentation}e.entrance===null?delete t.entrance:e.entrance!==void 0&&(t.entrance=e.entrance)}function Cn(t){if(!("chairNumbering"in t))return;let e=t.chairNumbering;if(delete t.chairNumbering,e===null)return null;let r=Ut(e);if(r)throw new d("invalid_operation",r);return e}function xn(t,e){if(e===void 0)return;let r=e===null?void 0:Jt({...t.chairNumbering,...e});r?t.chairNumbering=r:delete t.chairNumbering}function On(t){let e={};if("boothType"in t){let r=t.boothType;if(delete t.boothType,r===null)e.boothType=null;else if(r!==void 0){if(!At.includes(r))throw new d("invalid_operation","boothType must be inline, corner, peninsula or island");e.boothType=r}}if("commercial"in t){let r=t.commercial;if(delete t.commercial,r===null)e.note=null;else if(r!==void 0){let o=Object.keys(r).filter(i=>i!=="note");if(o.length)throw new d("invalid_operation",`Booth commercial supports only a note (got ${o.join(", ")})`);if(r.note===null)e.note=null;else if(r.note!==void 0){if(typeof r.note!="string")throw new d("invalid_operation","Booth note must be text");let i=r.note.normalize("NFKC").trim();if(i.length>Sn)throw new d("invalid_operation",`Booth note supports at most ${Sn} characters`);e.note=i||null}}}return e}function Rn(t,e){e.boothType===null?delete t.boothType:e.boothType!==void 0&&(t.boothType=e.boothType),e.note===null?delete t.commercial:e.note!==void 0&&(t.commercial={note:e.note})}function Bi(t,e){let r=O(t,e.floorId),o=[...new Set(e.tableIds)];if(!o.length)throw new d("invalid_operation","At least one table id is required");let i=o.map(C=>r.objects.find(b=>b.type==="table"&&b.id===C)),a=o.filter((C,b)=>!i[b]);if(a.length)throw new d("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one table change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&M(t,n.categoryKey),n.fill!==void 0&&n.fill!==null&&(n.fill=L(n.fill,"Table surface color"));let s=n.seatCount!==void 0,c=n.seatCountsBySide!==void 0;if(c){if(n.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(n.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let C=["top","bottom","left","right"],b=Object.keys(n.seatCountsBySide);if(b.length!==C.length||b.some(S=>!C.includes(S)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let S of C){let _=n.seatCountsBySide[S];if(!Number.isInteger(_)||_<0||_>40)throw new d("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let x=C.reduce((S,_)=>S+n.seatCountsBySide[_],0);if(x<1||x>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&n.seatCount!==x)throw new d("invalid_operation",`seatCount must equal the ${x}-chair seatCountsBySide total`);n.seatCount=x,n.sides=C.filter(S=>n.seatCountsBySide[S]>0)}if(n.seatCount!==void 0&&(!Number.isInteger(n.seatCount)||n.seatCount<1||n.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(n.shape!==void 0&&n.shape!=="round"&&n.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(n.automaticRadius!==void 0&&typeof n.automaticRadius!="boolean")throw new d("invalid_operation","automaticRadius must be true or false");if(n.shape==="rect"&&n.automaticRadius===!0)throw new d("invalid_operation","Automatic radius can be used only with round tables");if(n.bookAsWhole===!0&&n.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(n.variableOccupancy===!1&&(n.minOccupancy!==void 0||n.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(C,b,x,S)=>{if(b!==void 0&&(!Number.isFinite(b)||b<x||b>S))throw new d("invalid_operation",`${String(C)} must be from ${x} to ${S}`)};if(l("rotation",n.rotation,0,360),l("radius",n.radius,24,160),l("seatArc",n.seatArc,120,360),l("width",n.width,40,320),l("height",n.height,30,240),n.minOccupancy!==void 0&&(!Number.isInteger(n.minOccupancy)||n.minOccupancy<1||n.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(n.maxOccupancy!==void 0&&(!Number.isInteger(n.maxOccupancy)||n.maxOccupancy<1||n.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(n.sides!==void 0){let C=new Set(["top","bottom","left","right"]);if(!n.sides.length||n.sides.length>4||new Set(n.sides).size!==n.sides.length||n.sides.some(b=>!C.has(b)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=le(n,"Table"),g=Ne(n,"Table"),h=Ge(n,"Table"),u=Cn(n),m=i.map(C=>{if(C.seatCountsBySide&&!c&&(s||e.patch.sides!==void 0))throw new d("invalid_operation",`Table "${C.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:C.id});let b=structuredClone(C);if(Object.assign(b,n),Ke(b,h),xn(b,u),n.fill===null&&delete b.fill,b.shape==="round")delete b.seatCountsBySide,b.automaticRadius===!0?b.radius=Zt(b.seatCount,b.seatArc):delete b.automaticRadius;else{if(n.automaticRadius===!0)throw new d("invalid_operation",`Table "${b.label}" is rectangular and cannot use automatic radius`,{tableId:b.id});delete b.automaticRadius}if(b.overrides&&n.seatCount!==void 0&&(b.overrides=b.overrides.filter(x=>x.index<b.seatCount),b.overrides.length||delete b.overrides),n.bookAsWhole===!1&&delete b.bookAsWhole,n.variableOccupancy===!1&&(delete b.variableOccupancy,delete b.minOccupancy,delete b.maxOccupancy),b.bookAsWhole||delete b.bookAsWhole,b.variableOccupancy||delete b.variableOccupancy,b.bookAsWhole&&b.variableOccupancy)throw new d("invalid_operation",`Table "${b.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:b.id});if((b.bookAsWhole||b.variableOccupancy)&&b.overrides?.length)throw new d("invalid_operation",`Table "${b.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:b.id,overriddenChairIndices:b.overrides.map(x=>x.index)});if(b.bookAsWhole)delete b.minOccupancy,delete b.maxOccupancy;else if(b.variableOccupancy){if(!Number.isInteger(b.minOccupancy)||!Number.isInteger(b.maxOccupancy)||b.minOccupancy<1||b.maxOccupancy<b.minOccupancy||b.maxOccupancy>b.seatCount)throw new d("invalid_operation",`Table "${b.label}" needs whole-number minimum and maximum guests from 1 to its ${b.seatCount}-chair capacity`,{tableId:b.id,seatCount:b.seatCount})}else{if(n.minOccupancy!==void 0||n.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:b.id});delete b.minOccupancy,delete b.maxOccupancy}if(g&&delete b.displayType,f&&delete b.displayLabel,b.shape==="rect"){if(b.width??=80,b.height??=50,b.seatCountsBySide){let x=["top","bottom","left","right"],S=x.reduce((_,F)=>_+b.seatCountsBySide[F],0);if(S!==b.seatCount)throw new d("invalid_operation",`Table "${b.label}" side counts total ${S}, but seatCount is ${b.seatCount}`,{tableId:b.id,seatCount:b.seatCount,seatCountsBySide:b.seatCountsBySide});b.sides=x.filter(_=>b.seatCountsBySide[_]>0)}}else b.radius??=40;if((b.bookAsWhole||b.variableOccupancy)&&ce(b.label))throw new d("invalid_operation",`Grouped table label "${b.label}" uses SeatLayer's reserved GA namespace`,{tableId:b.id});return b}),p=new Map(m.map(C=>[C.id,C])),w=new Set(o),v=new Map;for(let C of G(t))for(let b of C.objects){let x=b.type==="table"?p.get(b.id)??b:b,S=[];x.type==="row"?S=X(x).map(_=>_.label):x.type==="table"?S=x.bookAsWhole||x.variableOccupancy?[x.label]:me(x).map(_=>_.label):x.type==="booth"?S=[x.label]:x.type==="gaArea"&&(S=Z(x));for(let _ of S){let F=v.get(_);if(F&&(w.has(F)||w.has(x.id)))throw new d("invalid_operation",`Inventory label "${_}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:_,conflictingObjectIds:[F,x.id]});v.set(_,F??x.id)}}let I=!1,y=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","fill","seatCountsBySide","overrides","automaticRadius","chairNumbering","labelPresentation","entrance"];for(let[C,b]of i.entries()){let x=m[C],S=JSON.stringify(b);for(let _ of y)_ in x||delete b[_];Object.assign(b,x),JSON.stringify(b)!==S&&(I=!0)}return{floorId:r.floorId,changed:I,tableIds:o}}function zi(t,e){let r=O(t,e.floorId),o=[...new Set(e.boothIds)];if(!o.length)throw new d("invalid_operation","At least one booth id is required");let i=o.map(p=>r.objects.find(w=>w.type==="booth"&&w.id===p)),a=o.filter((p,w)=>!i[w]);if(a.length)throw new d("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one booth change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&M(t,n.categoryKey);let s=(p,w,v,I)=>{if(w!==void 0&&(!Number.isFinite(w)||w<v||w>I))throw new d("invalid_operation",`${p} must be from ${v} to ${I}`)};s("width",n.width,30,400),s("height",n.height,30,400),s("rotation",n.rotation,0,360);let c=n.points===null;if(n.points!=null){if(o.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let p=fn(n.points);if(!p.ok)throw new d("invalid_operation",p.message??"The booth outline is not a valid simple polygon")}let l=n.points!=null?n.points.map(p=>({x:p.x,y:p.y})):void 0;delete n.points;let f=le(n,"Booth"),g=Ne(n,"Booth"),h=Ge(n,"Booth"),u=On(n),m=!1;for(let p of i){let w=JSON.stringify(p);Object.assign(p,n),Ke(p,h),Rn(p,u),f&&delete p.displayLabel,g&&delete p.displayType,c?delete p.points:l&&(p.points=l),JSON.stringify(p)!==w&&(m=!0)}return{floorId:r.floorId,changed:m,boothIds:o}}function Ui(t,e){let r=O(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(!o.length)throw new d("invalid_operation","At least one GA area id is required");let i=o.map(u=>r.objects.find(m=>m.type==="gaArea"&&m.id===u)),a=o.filter((u,m)=>!i[m]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one GA area change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(n.categoryKey!==void 0&&M(t,n.categoryKey),n.capacity!==void 0&&(!Number.isInteger(n.capacity)||n.capacity<1||n.capacity>J))throw new d("invalid_operation",`capacity must be an integer from 1 to ${J}`);if(n.cornerRadius!==void 0&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=le(n,"GA area"),c=Ne(n,"GA area"),l=Ge(n,"GA area"),f=mn(n);if(n.capacity!==void 0)for(let u of i){if(u.inventorySegments!==void 0&&n.capacity<u.capacity)throw new d("invalid_operation",`Joined GA area "${u.label}" cannot be reduced below ${u.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:u.id,currentCapacity:u.capacity,requestedCapacity:n.capacity});if(u.inventorySegments!==void 0&&n.capacity>u.capacity&&rt(u,n.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${u.label}" cannot append that capacity safely`,{gaAreaId:u.id})}let g=i.map(u=>{let m=structuredClone(u),p=n.capacity===void 0?u.inventorySegments:rt(u,n.capacity);return Object.assign(m,n),Ke(m,l),wn(m,f),p!==void 0&&(m.inventorySegments=p),s&&delete m.displayLabel,c&&delete m.displayType,m});In(t,g);let h=!1;for(let[u,m]of i.entries()){let p=g[u],w=JSON.stringify(m);for(let v of Object.keys(m))v in p||delete m[v];Object.assign(m,p),JSON.stringify(m)!==w&&(h=!0)}return{floorId:r.floorId,changed:h,gaAreaIds:o}}function ft(t,e){if(e.length<3)return 0;let r=i=>K(i,e,void 0),o=0;for(let i of t)r(N(i))&&(i.type==="row"?o+=X(i).length:i.type==="table"?o+=me(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=ie(i)));return o}function Ji(t,e){let r=O(t,e.floorId);if(!e.objectIds.length)throw new d("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new d("invalid_operation","Chart object ids must be unique");let o=e.objectIds.map(s=>r.objects.find(c=>c.id===s)),i=e.objectIds.filter((s,c)=>!o[c]);if(i.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=o,n=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)n.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+ie(c),0),remainingObjectCount:r.objects.length}}function qi(t,e){let r=O(t,e.floorId),o=[...new Set(e.textIds)];if(!o.length)throw new d("invalid_operation","At least one text id is required");let i=o.map(l=>r.objects.find(f=>f.type==="text"&&f.id===l)),a=o.filter((l,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one text change is required");if(n.text!==void 0){if(n.text=n.text.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!n.text||n.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(n.fontSize!==void 0&&(!Number.isFinite(n.fontSize)||n.fontSize<8||n.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(n.fontFamily!==void 0&&n.fontFamily!==null&&(n.fontFamily=n.fontFamily.normalize("NFKC").trim(),!n.fontFamily||n.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(n.rotation!==void 0&&(!Number.isFinite(n.rotation)||n.rotation<0||n.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(n.color!==void 0&&n.color!==null&&(n.color=L(n.color,"Text color")),n.bold!==void 0&&typeof n.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(n.italic!==void 0&&typeof n.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(n.width!==void 0&&n.width!==null&&(!Number.isFinite(n.width)||n.width<40||n.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new d("invalid_operation","Text align must be left, center, or right");if(n.lineHeight!==void 0&&(!Number.isFinite(n.lineHeight)||n.lineHeight<.8||n.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(n.letterSpacing!==void 0&&(!Number.isFinite(n.letterSpacing)||n.letterSpacing<-2||n.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(n.underline!==void 0&&typeof n.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(n.opacity!==void 0&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(n.background!==void 0&&n.background!==null){n.background.color=L(n.background.color,"Text background color");let{padding:l=6,cornerRadius:f=4,opacity:g=.9}=n.background;if(!Number.isFinite(l)||l<0||l>40)throw new d("invalid_operation",`Text background padding must be from 0 to ${40}`);if(!Number.isFinite(f)||f<0||f>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(g)||g<.1||g>1)throw new d("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(n,l))&&i.some(l=>l.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(n.labelImportance!==void 0&&n.labelImportance!==null&&n.labelImportance!=="orientation"&&n.labelImportance!=="detail")throw new d("invalid_operation","Text labelImportance must be 'orientation', 'detail' or null");if(n.iconKey!==void 0){if(!sn(n.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(i.some(l=>l.semanticKind!=="icon"))throw new d("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let c=!1;for(let l of i){let f=JSON.stringify(l);n.iconKey!==void 0&&(l.iconKey=n.iconKey),n.text!==void 0&&(l.text=n.text),n.fontSize!==void 0&&(l.fontSize=n.fontSize),n.fontFamily===null?delete l.fontFamily:n.fontFamily!==void 0&&(l.fontFamily=n.fontFamily),n.rotation!==void 0&&(l.rotation=n.rotation),n.color===null?delete l.color:n.color!==void 0&&(l.color=n.color),n.bold!==void 0&&(n.bold?l.bold=!0:delete l.bold),n.italic!==void 0&&(n.italic?l.italic=!0:delete l.italic),n.width===null?delete l.width:n.width!==void 0&&(l.width=n.width),n.align!==void 0&&(n.align==="left"?delete l.align:l.align=n.align),n.lineHeight!==void 0&&(n.lineHeight===1.2?delete l.lineHeight:l.lineHeight=n.lineHeight),n.letterSpacing!==void 0&&(n.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=n.letterSpacing),n.underline!==void 0&&(n.underline?l.underline=!0:delete l.underline),n.opacity!==void 0&&(n.opacity===1?delete l.opacity:l.opacity=n.opacity),n.background===null?delete l.background:n.background!==void 0&&(l.background=n.background),n.labelImportance===null?delete l.labelImportance:n.labelImportance!==void 0&&(l.labelImportance=n.labelImportance),JSON.stringify(l)!==f&&(Fe(l),c=!0)}return{floorId:r.floorId,changed:c,textIds:o}}function Vi(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i.slice().sort((h,u)=>h.origin.y-u.origin.y||h.origin.x-u.origin.x),s=h=>h.segmentedRow?.displayLabel??h.displayLabel??h.label,c=zt(n.map(h=>({label:s(h)})),e.options),l=e.displayType==null?void 0:e.displayType.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,24),f=l===void 0||l===""||l==="Row"?e.displayType===void 0?void 0:null:l,g=!1;return n.forEach((h,u)=>{let m=c[u].label.normalize("NFKC").replace(/\s+/g," ").trim();if(s(h)!==m&&(g=!0,h.segmentedRow?h.segmentedRow.displayLabel=m:h.displayLabel=m),f!==void 0){if(f===null){h.displayType!==void 0&&(g=!0,delete h.displayType);return}h.displayType!==f&&(g=!0,h.displayType=f)}}),{floorId:r.floorId,changed:g,rows:n.map(h=>({id:h.id,displayLabel:s(h),...h.displayType?{displayType:h.displayType}:{}}))}}function Hi(t,e){let r=hn.find(l=>l.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=O(t,e.floorId),i=new Set,a=r.build().map(l=>structuredClone(l));for(let l of a)l.id=k(t,l.type,e.idFactory,i),pn(l,e.center.x,e.center.y);for(let l of r.categories)t.categories.some(f=>f.key===l.key)||t.categories.push({...l});let n=a.filter(l=>l.type==="row");if(n.length){let l=0;for(let f of o.objects){if(f.type!=="row")continue;let g=bn(f.label);g!=null&&(l=Math.max(l,g+1))}for(let f of n)f.label=U(l++)}let s=new Set(o.objects.flatMap(l=>"label"in l&&l.label?[l.label]:[]));for(let l of a){if((l.type==="table"||l.type==="booth")&&s.has(l.label)){let f=/^(.*?)(\d+)$/.exec(l.label),g=f?f[1]:`${l.label} `,h=f?Number.parseInt(f[2],10):1;do h++;while(s.has(`${g}${h}`));l.label=`${g}${h}`}"label"in l&&l.label&&s.add(l.label)}o.objects.push(...a);let c=null;if(r.sectionLabel&&e.wrapInSection!==!1){let l=re(a);if(l){let f={type:"section",id:k(t,"sec",e.idFactory,i),label:r.sectionLabel,outline:l};o.objects.push(f),c=f.id}}return{floorId:o.floorId,blockKey:r.key,createdIds:[...a.map(l=>l.id),...c?[c]:[]],sectionId:c}}function vo(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new d("invalid_operation","Exact row path points must be finite");let o=Lt(e,97),i=o.slice(1).reduce((a,n,s)=>a+Math.hypot(n.x-o[s].x,n.y-o[s].y),0);if(!Number.isFinite(i)||i<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function So(t,e){let r=O(t,e.floorId),o=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!o)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=vo(e.path),a=X(o),n=structuredClone(o);n.path=i.path,n.origin={...i.path.start};let s=X(n),c=a.map((f,g)=>Math.hypot(f.x-s[g].x,f.y-s[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:r.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((f,g)=>f+g,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function ta(t,e){let r=So(t,e);if(!r.changed)return r;let i=O(t,r.floorId).objects.find(a=>a.type==="row"&&a.id===r.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,r}function Co(t,e){let r=t.map((o,i)=>[...o,e[i]]);for(let o=0;o<3;o++){let i=o;for(let n=o+1;n<3;n++)Math.abs(r[n][o])>Math.abs(r[i][o])&&(i=n);if(Math.abs(r[i][o])<1e-9)return null;[r[o],r[i]]=[r[i],r[o]];let a=r[o][o];for(let n=o;n<4;n++)r[o][n]/=a;for(let n=0;n<3;n++){if(n===o)continue;let s=r[n][o];for(let c=o;c<4;c++)r[n][c]-=s*r[o][c]}}return[r[0][3],r[1][3],r[2][3]]}function xo(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],n=i.x**2+i.y**2;for(let s=0;s<3;s++){r[s]+=a[s]*n;for(let c=0;c<3;c++)e[s][c]+=a[s]*a[c]}}let o=Co(e,r);return o?{x:o[0],y:o[1]}:null}function _n(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function Oo(t,e){let r=O(t,e.floorId),o=r.objects.find(u=>u.type==="section"&&u.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let a=G(t).find(u=>u.id===r.floorId),n=e.mode==="outline"?xo(o.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(u=>u.type==="row"&&K(N(u),o.outline,o.holes)),c=s.filter(u=>!!u.path).map(u=>u.id),l=[],f=[],g=i/100;for(let u of s){if(u.path)continue;if(u.seatCount<2){l.push(u.id);continue}let m=Math.hypot(u.origin.x-n.x,u.origin.y-n.y);if(m<=u.seatSpacing/2+1e-6){l.push(u.id);continue}let p=2*Math.asin(u.seatSpacing/(2*m))/Q,w=X(u),v=Math.atan2(u.origin.x-n.x,u.origin.y-n.y)/Q,y=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(_n(Math.atan2(w[1].x-n.x,w[1].y-n.y)/Q-v))||1)*p*(u.seatCount-1);if(Math.abs(y)>320){l.push(u.id);continue}let C=-v,b=u.curve+(y-u.curve)*g,x=u.rotation+_n(C-u.rotation)*g,S={...u,curve:b,rotation:x},F=X(S).map(($,B)=>Math.hypot($.x-w[B].x,$.y-w[B].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:y,resultCurve:b,fromRotation:u.rotation,resultRotation:x,rmsMovement:Math.sqrt(F.reduce(($,B)=>$+B**2,0)/F.length),maxMovement:Math.max(...F)})}let h=f.map(u=>u.rmsMovement);return{floorId:r.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...n},strength:i,rows:f,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:h.length?h.reduce((u,m)=>u+m,0)/h.length:0,maxMovement:f.length?Math.max(...f.map(u=>u.maxMovement)):0}}function na(t,e){let r=Oo(t,e),o=O(t,r.floorId),i=o.objects.find(n=>n.type==="section"&&n.id===r.sectionId),a=!1;for(let n of r.rows){let s=o.objects.find(c=>c.type==="row"&&c.id===n.rowId);(s.curve!==n.resultCurve||s.rotation!==n.resultRotation)&&(s.curve=n.resultCurve,s.rotation=n.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==r.strength&&(i.smoothing=r.strength,a=!0),{...r,changed:a}}function jn(t,e,r,o){let i=H(t,e,r),a=H(t,e,o),n=H(r,o,t),s=H(r,o,e);return i*a<-1e-9&&n*s<-1e-9}function An(t,e){return t.some((r,o)=>{let i=t[(o+1)%t.length];return e.some((a,n)=>jn(r,i,a,e[(n+1)%e.length]))})}function Ro(t){if(t.length<3||t.length>256||Math.abs(ke(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)if(!(r===e+1||e===0&&r===t.length-1)&&jn(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function $e(t,e,r){let o=O(t,e),i=o.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===r);if(!i)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:o,object:i,outer:i.type==="section"?i.outline:i.points}}function ut(t,e){let{target:r,object:o,outer:i}=$e(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Ro(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!K(l,i,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(An(a,i))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let n=o.holes??[],s=e.holeIndex??n.length;if(!Number.isInteger(s)||s<0||s>n.length||e.holeIndex!=null&&s>=n.length)throw new d("invalid_operation","Opening not found");for(let l=0;l<n.length;l++){if(l===e.holeIndex)continue;let f=n[l];if(An(a,f)||K(a[0],f,void 0)||K(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let c=r.objects.filter(l=>l.id!==o.id&&l.type!=="section"&&K(N(l),a,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.map(l=>l.id),excludedInventoryUnits:ft(r.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function oa(t,e){let r=ut(t,e),{object:o}=$e(t,r.floorId,r.objectId);return o.holes??=[],e.holeIndex==null?o.holes.push(structuredClone(e.points)):o.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function _o(t,e){let{target:r,object:o}=$e(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(o.holes?.length??0))throw new d("invalid_operation","Opening not found");let i=o.holes[e.holeIndex],a=r.objects.filter(n=>n.id!==o.id&&n.type!=="section"&&K(N(n),i,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(n=>n.id),excludedInventoryUnits:ft(r.objects.filter(n=>n.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function ra(t,e){let r=_o(t,e),{object:o}=$e(t,r.floorId,r.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...r,changed:!0}}function Ao(t){let e=oe(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function Pn(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let o=r.map(n=>t.find(s=>s.type==="section"&&s.id===n)),i=r.filter((n,s)=>!o[s]);if(i.length)throw new d("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:r,sections:a,logicalSectionIds:[...new Set(a.map(n=>n.logicalSectionId??n.id))]}}function jo(t,e){let r=O(t,e.floorId),o=Pn(r.objects,e.sectionIds),i=ve(Te(t,r.floorId)),a=new Map(i.sections.map(u=>[u.id,u])),n=new Map(r.objects.map(u=>[u.id,u])),s=o.logicalSectionIds.flatMap(u=>a.get(u)?.objectIds??[]),c=new Set,l=new Set(o.logicalSectionIds),f=new Set(r.objects.filter(u=>u.type==="section"&&l.has(u.logicalSectionId??u.id)).flatMap(u=>u.editor?.defaultCategoryKey?[u.editor.defaultCategoryKey]:[]));for(let u of s){let m=n.get(u);if(m)if(m.type==="row"||m.type==="table")for(let p of Ee(m).keys())c.add(p);else(m.type==="booth"||m.type==="gaArea")&&c.add(m.categoryKey)}let g=o.logicalSectionIds.every(u=>(a.get(u)?.seatCount??0)>0),h=o.logicalSectionIds.every(u=>a.get(u)?.objectIds.some(m=>{let p=n.get(m);return p?.type==="row"||p?.type==="table"||p?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:g,...g&&c.size===1?{categoryKey:[...c][0]}:!g&&!s.length&&f.size===1?{categoryKey:[...f][0]}:{},categoryMixed:g?c.size!==1:!s.length&&f.size>1,viewApplicable:h}}function ha(t,e){M(t,e.categoryKey);let r=jo(t,e);if(!r.categoryApplicable&&r.objectIds.length)throw new d("invalid_operation","A mixed selection of empty and occupied logical sections cannot be assigned together",{logicalSectionIds:r.logicalSectionIds});let o=O(t,r.floorId),i=new Set(r.objectIds),a=!1,n=0,s=new Set(r.logicalSectionIds);for(let c of o.objects)c.type!=="section"||!s.has(c.logicalSectionId??c.id)||c.editor?.defaultCategoryKey!==e.categoryKey&&(c.editor={...c.editor,defaultCategoryKey:e.categoryKey},a=!0);for(let c of o.objects){if(!i.has(c.id)||c.type!=="row"&&c.type!=="table"&&c.type!=="booth"&&c.type!=="gaArea"||(c.categoryKey!==e.categoryKey&&(c.categoryKey=e.categoryKey,a=!0),c.type!=="row"&&c.type!=="table"||!c.overrides?.length))continue;let l=c.overrides.flatMap(f=>{if(f.categoryKey===void 0)return[f];let g={...f};return delete g.categoryKey,n++,a=!0,Object.keys(g).some(h=>h!=="index")?[g]:[]});l.length?c.overrides=l:delete c.overrides}return{...r,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:n}}function kn(t,e){let r=O(t,e.floorId),o=Pn(r.objects,e.sectionIds),{requested:i}=o,a=structuredClone(e.patch),n=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(u=>!n.has(u));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new d("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 d("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new d("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 d("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new d("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 d("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Ao(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&Le(a.labelPresentation,"Section"),a.labelStyle!==void 0&&te(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(u=>u.id===a.zone))throw new d("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 d("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 d("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 d("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 d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=L(a.color,"Section color"));let c=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,l=new Set(o.logicalSectionIds),f=c?r.objects.filter(u=>u.type==="section"&&l.has(u.logicalSectionId??u.id)):[],g=new Set,h=!1;for(let u of o.sections){let m=JSON.stringify(u);a.label!==void 0&&(u.label=a.label),a.labelPresentation===null?delete u.labelPresentation:a.labelPresentation!==void 0&&(u.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(u.elevation=a.elevation);let p=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};a.height===null?(delete u.height,p("height")):a.height!==void 0&&(u.height=a.height,u.physical3dProvenance={...u.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete u.rake,p("rake")):a.rake!==void 0&&(u.rake=a.rake,u.physical3dProvenance={...u.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete u.surfaceKind,p("surfaceKind")):a.surfaceKind!==void 0&&(u.surfaceKind=a.surfaceKind,u.physical3dProvenance={...u.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete u.color:a.color!==void 0&&(u.color=a.color),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}for(let u of f){let m=JSON.stringify(u),p=u.viewFromSeatUrl;if(a.displayLabel===null?delete u.displayLabel:a.displayLabel!==void 0&&(u.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete u.entrance:a.entrance!==void 0&&(u.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete u.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(u.viewFromSeatUrl=a.viewFromSeatUrl),!u.viewFromSeatUrl||a.viewFromSeatMeta===null?delete u.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?u.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==p&&delete u.viewFromSeatMeta,a.labelStyle!==void 0){let w=de(u.labelPresentation,a.labelStyle);w?u.labelPresentation=w:delete u.labelPresentation}a.zone===null?delete u.zone:a.zone!==void 0&&(u.zone=a.zone),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}return{floorId:r.floorId,changed:h,sectionIds:i,affectedSectionIds:[...g]}}function Po(t,e){let r=O(t,e.floorId),o=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(o.outlinePath)throw new d("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 d("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=r.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&K(N(a),o.outline,o.holes));return{floorId:r.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,n)=>a+ie(n),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function ba(t,e){let r=Po(t,e),i=O(t,r.floorId).objects.find(a=>a.type==="section"&&a.id===r.sectionId);return delete i.geometry,{...r,changed:!0}}function ko(t,e){let r=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,n=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");n=e.dx!==0||e.dy!==0,o=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");n=e.factor!==1,i=e.factor;let s=N(t);o=c=>({x:s.x+(c.x-s.x)*e.factor,y:s.y+(c.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!r(e.degrees))throw new d("invalid_operation","Section rotation must be finite");n=(e.degrees%360+360)%360!==0;let c=e.degrees*Math.PI/180,l=Math.cos(c),f=Math.sin(c),g=N(t);o=h=>{let u=h.x-g.x,m=h.y-g.y;return{x:g.x+u*l-m*f,y:g.y+u*f+m*l}}}else{if(!r(e.coordinate))throw new d("invalid_operation","Section reflection coordinate must be finite");a=!0,o=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return n&&(t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=Kt(t.outlinePath,o,i,a)),a&&t.edgeCurvature&&(t.edgeCurvature=$t(t.edgeCurvature)),t.holes&&(t.holes=we(t.holes).map(s=>s.map(o)))),{changed:n,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function pa(t,e){let r=O(t,e.floorId),o=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...ko(o,e.transform)}}function ya(t,e){let r=O(t,e.floorId),o=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!Dt(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=tt(i),n=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return n&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:r.floorId,sectionId:o.id,changed:n,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function Fo(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function ma(t,e){return Mo(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Mo(t,e){let r=O(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new d("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new d("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(e.sectionIds)],i=new Set,a=new Map,n=!1;try{for(let s of o){let c=r.objects.find(I=>I.type==="section"&&I.id===s);if(!c||!Fo(c))continue;let f=structuredClone(c);a.set(c.id,{section:c,snapshot:f});let g=JSON.stringify(c),h=(c.sourceOutline??c.outline).map(I=>({...I})),u=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),p=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(I=>Math.min(100,Math.max(-100,I))),w=p?.some(I=>Math.abs(I)>.5)===!0,v=u>.5||w?Bt(h,{cornerSmoothing:u,...w?{edgeCurvature:p}:{}}):null;v?(c.sourceOutline=h,c.outlinePath=v,c.outline=tt(v),u>.5?c.cornerSmoothing=u:delete c.cornerSmoothing,w?c.edgeCurvature=[...p]:delete c.edgeCurvature):(c.outline=h,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let I=0;I<(c.holes?.length??0);I+=1)ut(t,{floorId:r.floorId,objectId:c.id,points:c.holes[I],holeIndex:I});JSON.stringify(c)!==g&&(n=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let f=c;for(let g of Object.keys(f))delete f[g];Object.assign(c,structuredClone(l))}throw s}return{floorId:r.floorId,changed:n,sectionIds:o,affectedSectionIds:[...i]}}function Ca(t,e,r={}){let o=!1;for(let i of e){let a=kn(t,{floorId:i.floorId,sectionIds:[i.sectionId],patch:{height:i.height,rake:i.rake,surfaceKind:i.surfaceKind}});o||=a.changed}if(r.stage){let i=O(t,r.stage.floorId).objects.find(a=>a.type==="shape"&&a.id===r.stage.shapeId);i&&i.role!=="stage"&&(i.role="stage",o=!0),i&&r.stage.stageKind&&!i.stageKind&&(i.stageKind=r.stage.stageKind,o=!0)}for(let{shapeId:i,floorId:a,role:n}of r.roles??[]){let s=O(t,a).objects.find(c=>c.type==="shape"&&c.id===i);s&&!s.role&&(s.role=n,o=!0)}for(let{floorId:i,point:a}of r.focal??[]){let n=Ce(a,"focalPoint"),s=i?t.floors?.find(l=>l.id===i):void 0,c=s?s.focalPoint:t.focalPoint;c?.x===n.x&&c?.y===n.y||(s?s.focalPoint=n:t.focalPoint=n,o=!0)}return t.floors?.length&&De(t),{changed:o}}var Eo=new Set(["companion","child","senior","student","membership","custom"]);function fe(t){if(!t.length)throw new d("invalid_operation","A chart must have at least one category");let e=new Set,r=new Map,o=structuredClone(t);for(let i of o){let a=i.key.trim(),n=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!n||n.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=n.toLocaleLowerCase("en"),c=r.get(s);if(c)throw new d("duplicate_category_label",`Categories ${c} and ${a} share the same label`,{categoryKeys:[c,a],label:n});if(r.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new d("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 d("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 d("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!Se(i.seatGlyph))throw new d("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 d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,f=new Set;for(let g of i.tiers){let h=g.id.trim(),u=g.name.normalize("NFKC").trim(),m=u.toLocaleLowerCase("en");if(!h||h.length>160||l.has(h))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!u||u.length>80||f.has(m))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:u});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new d("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(g.restriction!=null&&!Eo.has(g.restriction))throw new d("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new d("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(g.applicability!=null){let p=g.applicability.seatLabels?.map(v=>v.normalize("NFKC").trim()),w=g.applicability.accessibility;if(p&&(!p.length||p.length>1e4||p.some(v=>!v||v.length>160)||new Set(p).size!==p.length)||w&&(!w.length||w.some(v=>!je.some(I=>I.key===v))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...p?{seatLabels:p}:{},...w?{accessibility:[...w]}:{}},!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 d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}l.add(h),f.add(m)}}}return o}function To(t,e){let r=new Set,o=structuredClone(t.categories);for(let n of e.updates){if(r.has(n.categoryKey))throw new d("invalid_operation",`Category ${n.categoryKey} may be updated only once`);r.add(n.categoryKey);let s=o.find(g=>g.key===n.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${n.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:n.categoryKey});let c=structuredClone(n.patch),{tiers:l,...f}=c;typeof f.label=="string"&&(f.label=f.label.normalize("NFKC").trim()),typeof f.color=="string"&&(f.color=f.color.toLowerCase()),Object.assign(s,f),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(g=>{let h={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?h.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete h.buyerMessage,h})),delete s.referenceDirectSeatImport}let i=fe(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...r],categories:t.categories}}function ka(t,e){let r=structuredClone(t.categories),o=r.find(n=>n.key===e.categoryKey);if(!o||o.referenceDirectSeatImport?.assetId!==e.source.assetId||o.referenceDirectSeatImport.familyId!==e.source.familyId)throw new d("invalid_operation","The prior direct-seat import category is no longer available for this reference");o.label=e.label.normalize("NFKC").trim();let i=fe(r),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,category:t.categories.find(n=>n.key===e.categoryKey),categories:t.categories}}function Fa(t,e){let r=e.categoryKeys.map(c=>c.trim()),o=t.categories.map(c=>c.key);if(r.length!==o.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:o});let i=new Set(o),a=o.filter(c=>!r.includes(c)),n=r.filter(c=>!i.has(c));if(a.length||n.length)throw new d(n.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:a,unknownCategoryKeys:n});if(r.every((c,l)=>c===o[l]))return{changed:!1,categoryKeys:o,categories:t.categories};let s=new Map(t.categories.map(c=>[c.key,c]));return t.categories=fe(r.map((c,l)=>{let f=structuredClone(s.get(c));return c!==o[l]&&delete f.referenceDirectSeatImport,f})),{changed:!0,categoryKeys:r,categories:t.categories}}var Mn=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Fn(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(o=>o+o).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function No(t,e){let r=Fn(t),o=Fn(e);return!r||!o?1/0:(r[0]-o[0])**2+(r[1]-o[1])**2+(r[2]-o[2])**2}var Lo=3600;function Do(t,e,r=Mn){return r.find(i=>t.every(a=>No(i,a)>=Lo))??r[e%r.length]}function Ma(t,e){let r=e?.palette??Mn;if(!t.categories.length)return{changed:[],categories:t.categories};let o=new Map(t.categories.map(n=>[n.key,n.color.toLowerCase()])),i=t.categories.map((n,s)=>({categoryKey:n.key,patch:{color:r[s%r.length]}}));return To(t,{updates:i}),{changed:t.categories.map(n=>({key:n.key,from:o.get(n.key),to:n.color})).filter(n=>n.from!==n.to),categories:t.categories}}function Ea(t,e){let r=e.color.trim().toLowerCase(),o=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!o||o.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(c=>c.key===e.categoryKey);if(!a)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=r,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let n=fe(i),s=JSON.stringify(n)!==JSON.stringify(t.categories);return s&&(t.categories=n),{changed:s,category:t.categories.find(c=>c.key===e.categoryKey),categories:t.categories}}function Go(t,e){let r=new Set(t.categories.map(n=>n.key)),o="";for(let n=0;n<100;n++){let c=e.idFactory("cat").trim();if(c&&!r.has(c)){o=c;break}}if(!o)throw new d("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(n=>({...n,id:n.id.trim(),name:n.name.normalize("NFKC").trim()})),...e.referenceDirectSeatImport?{referenceDirectSeatImport:structuredClone(e.referenceDirectSeatImport)}:{}},a=fe([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(n=>n.key===o),categories:a}}var Ko=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],$o={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function Bo(t,e){let r=$o[t];return!r||!e.includes(r)?e:[r,...e.filter(o=>o!==r)]}var zo=26;function Uo(t,e,r){let o=(1-Math.abs(2*r-1))*e,i=(t%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[n,s,c]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],l=r-o/2,f=g=>Math.round((g+l)*255).toString(16).padStart(2,"0");return`#${f(n)}${f(s)}${f(c)}`}function Jo(t,e,r){let o=n=>t.every(s=>{let c=nn(n,s);return c==null||c>=zo}),i=n=>{let s=it(n,"#12151d"),c=it(n,"#ffffff");return(s??0)>=3||(c??0)>=3},a=e.find(n=>o(n)&&i(n));if(a)return a;for(let n=0;n<360;n+=12)for(let s of[.52,.44,.6]){let c=Uo(n,.62,s);if(o(c)&&i(c))return c}return r}function qo(t,e){let r=Me.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function Vo(t){let e=new Map;for(let r of G(t))for(let o of r.objects){let i=Me.find(n=>n.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let n of Ee(o).keys())a.add(n);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let n of a){let s=e.get(n)??new Set;s.add(i.objectType),e.set(n,s)}}return e}function Ho(t,e){let r=new Set(t.categories.map(i=>i.label.toLowerCase())),o=e;for(let i=2;r.has(o.toLowerCase());i+=1)o=`${e} ${i}`;return o}function Xo(t,e,r){let o=Vo(t),i=l=>{let f=o.get(l);return!f||f.size===0||f.size===1&&f.has(r)},a=t.categories.find(l=>l.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let l=t.categories.find(f=>{let g=o.get(f.key);return g?.size===1&&g.has(r)});if(l)return{kind:"existing",categoryKey:l.key,label:l.label}}let n=Me.find(l=>l.objectType===r),s=a?qo(a.label,r):r==="gaArea"?"General Admission":n.creationWord,c=t.categories.find(l=>l.label.toLowerCase()===s.toLowerCase()&&i(l.key));return c?{kind:"existing",categoryKey:c.key,label:c.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:Ho(t,s)}}function Ta(t,e,r,o){let i=Xo(t,e,r);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?t.categories.find(n=>n.key===i.baseCategoryKey):void 0;return Yo(t,r,a,i.label,o)}function Yo(t,e,r,o,i){let a=i.palette??Ko,n=t.categories.map(f=>f.color),s=i.suggestColor?.(n.map(f=>f.toLowerCase()))??Do(n,t.categories.length),c=Jo(n,Bo(e,a),s),l=Go(t,{label:o,color:c,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:i.idFactory});return t.categories=l.categories,l.category.key}function Wo(t,e){let r=new Set;for(let o of G(t))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===e&&r.add(i.id),i.type==="section"&&i.editor?.defaultCategoryKey===e&&r.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&r.add(i.id);return[...r]}function Na(t,e){let r=t.categories.find(a=>a.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let o=Wo(t,e.categoryKey);if(o.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:o});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=fe(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var Zo=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Qo=["seat","deck","shell","fascia"];function Ba(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let o=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of Zo){let n=r[a];n===null?delete i[a]:n!==void 0&&(i[a]=L(n,`Theme ${a}`))}if(r.fontFamily===null)delete i.fontFamily;else if(r.fontFamily!==void 0){let a=r.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(r.seatScale===null)delete i.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<at||r.seatScale>st)throw new d("invalid_operation",`Theme seatScale must be from ${at} to ${st}`);i.seatScale=r.seatScale}if(r.logoUrl===null)delete i.logoUrl;else if(r.logoUrl!==void 0){let a=oe(r.logoUrl);if(!a)throw new d("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster image reference");i.logoUrl=a}if(r.brandName===null)delete i.brandName;else if(r.brandName!==void 0){let a=r.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}if(r.hideBadge===null||r.hideBadge===!1?delete i.hideBadge:r.hideBadge===!0&&(i.hideBadge=!0),r.venue3d===null)delete i.venue3d;else if(r.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of Qo){let c=r.venue3d[s];c===null?delete a[s]:c!==void 0&&(a[s]=L(c,`3D venue ${s}`))}let n=r.venue3d.roughness;if(n===null)delete a.roughness;else if(n!==void 0){if(!Number.isFinite(n)||n<0||n>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=n}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==o,theme:t.theme??null}}function za(t,e){let r=e.url===null?null:oe(e.url);if(e.url!==null&&!r)throw new d("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===o,l=o?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,f=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,n=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=o,t.viewFromSeatMeta=a,{changed:n,scope:"venue",url:t.viewFromSeatUrl??null}}function Ua(t,e){let r=Te(t,e.floorId),o=Yt(r),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-e.height/2}:i==="left"?{x:o.x-a-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+e.height/2}}function Be(t,e){M(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=e.endAngle-e.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new d("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new d("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,n=e.skewDegrees??0;if(!r(a,n)||Math.abs(a)>120||Math.abs(n)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let l=O(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:n,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function er(t,e,r){let o=r*Q;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function tr(t,e,r,o){let i=Math.abs(o-r)*Q,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,f])=>{let g=t.aisleGaps[l];if(!g)return[];let h=g/e/i/2;return[[Math.max(0,f-h),Math.min(1,f+h)]]}).sort((l,f)=>l[0]-f[0]),n=[];for(let l of a){let f=n[n.length-1];f&&l[0]<=f[1]?f[1]=Math.max(f[1],l[1]):n.push([...l])}let s=[],c=0;for(let l of n)l[0]-c>1e-6&&s.push([c,l[0]]),c=Math.max(c,l[1]);return 1-c>1e-6&&s.push([c,1]),s.filter(([l,f])=>e*i*(f-l)>=t.seatPitch*.75)}function nr(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let o=e-r,i=t.reduce((c,l)=>c+l,0),a=t.map(c=>o*c/i),n=a.map(c=>2+Math.floor(c)),s=e-n.reduce((c,l)=>c+l,0);return a.map((c,l)=>({index:l,fraction:c-Math.floor(c)})).sort((c,l)=>l.fraction-c.fraction||c.index-l.index).forEach(({index:c})=>{s-- >0&&n[c]++}),n}function ze(t,e,r){let o=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),n=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,c=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,l=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;if(Math.sign(l-c)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(l-c)<5)throw new d("invalid_operation",`Arc/Fan taper collapses row ${i+1} below a 5\xB0 sweep`);let f=tr(t,n,c,l);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let g=f.map(([m,p])=>n*Math.abs(l-c)*Q*(p-m)),h=t.fit==="fixed-count"?nr(g,t.seatsPerRow):g.map(m=>Math.max(2,Math.round(m/t.seatPitch)+1)),u=t.seatLabelStart;f.forEach(([m,p],w)=>{let v=c+(l-c)*m,I=c+(l-c)*p;t.facing==="outward"&&([v,I]=[I,v]);let y=h[w];if(y>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let C=Math.abs(I-v)*Q/(y-1),b=2*n*Math.sin(C/2),x={type:"row",id:r(i,w),label:U(t.rowLabelStart+i),origin:er(t.center,n,v),rotation:-v,curve:I-v,seatCount:y,seatSpacing:b,categoryKey:t.categoryKey,seatLabelStart:u,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:w}};o.push(x),u+=y})}return o}function En(t,e){let r=Be(t,e),o=O(t,e.floorId),i=ze(r,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),n=Math.max(...a.map(c=>Math.abs(c-r.seatPitch))),s=[];return n>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${n.toFixed(1)} chart units`),i.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:r.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((c,l)=>c+l.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:n,aisleCount:Object.values(r.aisleGaps).filter(c=>c>0).length,warnings:s}}function Ha(t,e){let r=Be(t,e),o=O(t,e.floorId),i=new Set,a=k(t,"fan",e.idFactory,i),n=ze(r,a,()=>k(t,"r",e.idFactory,i)),s=En(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(l){if(l.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let g=re(n);g&&(c=k(t,"sec",e.idFactory,i),f={type:"section",id:c,label:l,outline:g,arcFanGroupId:a})}return o.objects.push(...n,...f?[f]:[]),{floorId:o.floorId,rowIds:n.map(g=>g.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function or(t,e){let r=O(t,e.floorId),o=r.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(o.some(g=>a(g)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let n=r.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:r.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:n?.label},c=Be(t,s),l=new Set(ze(c,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(l.size!==f.size||[...l].some(g=>!f.has(g)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function Xa(t,e){or(t,{floorId:e.floorId,groupId:e.groupId});let r=Be(t,e),o=O(t,e.floorId),i=o.objects.filter(p=>p.type==="row"&&p.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(p=>p.type==="section"&&p.arcFanGroupId===e.groupId),n=new Map(i.map(p=>[`${p.arcFanGeneration.rowIndex}:${p.arcFanGeneration.segmentIndex}`,p.id])),s=new Set,c=ze(r,e.groupId,(p,w)=>n.get(`${p}:${w}`)??k(t,"r",e.idFactory,s)),l=En(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),g=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let p=re(c);p&&(g={type:"section",id:a?.id??k(t,"sec",e.idFactory,s),label:f,outline:p,arcFanGroupId:e.groupId})}let h=new Set([...i.map(p=>p.id),...a?[a.id]:[]]),u=Math.min(...o.objects.map((p,w)=>h.has(p.id)?w:1/0)),m=o.objects.filter(p=>!h.has(p.id));return m.splice(Number.isFinite(u)?u:m.length,0,...c,...g?[g]:[]),o.objects.splice(0,o.objects.length,...m),{floorId:o.floorId,rowIds:c.map(p=>p.id),sectionId:g?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function rr(t){let e=new Set(Y(t).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),r=0;return()=>{for(;e.has(U(r));)r+=1;let o=U(r);return e.add(o),r+=1,o}}function Tn(t){return JSON.stringify(["row-block-v1",t.style,t.origin.x,t.origin.y,t.rotation,t.rowCount,t.seatsPerRow,t.rowGap,t.seatSpacing,t.curve])}function ts(t,e){if(M(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,o=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(o)||o<=0)throw new d("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new d("invalid_operation","rotation must be a finite number of degrees");let i=O(t,e.floorId),a=new Set,n=rr(t),s=dt(e.rotation??0),c=e.curve??0,l=e.style,f=l?k(t,"rowblock",e.idFactory,a):void 0,g=l?Tn({style:l,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:o,curve:c}):void 0,h={x:Math.cos(s*W),y:Math.sin(s*W)},u={x:-h.y,y:h.x},m=Array.from({length:e.rowCount},(v,I)=>{let y=l==="intertwined"&&I%2===1?o/2:0,C={type:"row",id:k(t,"r",e.idFactory,a),label:n(),origin:{x:e.origin.x+u.x*I*r+h.x*y,y:e.origin.y+u.y*I*r+h.y*y},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&f&&g&&(C.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:l,rowIndex:I,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:r,seatSpacing:o,curve:c,signature:g}),C});i.objects.push(...m);let p=null,w=e.sectionLabel?.trim();if(w){let v=re(m);if(v){let I={type:"section",id:k(t,"sec",e.idFactory,a),label:w,outline:v};i.objects.push(I),p=I.id}}return{floorId:i.floorId,rowIds:m.map(v=>v.id),sectionId:p,createdIds:[...m.map(v=>v.id),...p?[p]:[]]}}function Nn(t,e){let r=new Set(Y(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;r.has(`${e}${o}`);)o+=1;let i=`${e}${o}`;return r.add(i),o+=1,i}}function ir(t,e){let r=new Set(Y(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!r.has(e))return e;let o=2;for(;r.has(`${e} ${o}`);)o+=1;return`${e} ${o}`}var ar=456;function sr(t){let e=Math.sqrt(Math.max(1,t)*ar);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function ns(t,e){if(M(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new d("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","GA area center must be finite");let r=O(t,e.floorId),o=new Set,{width:i,height:a}=sr(e.capacity),n=ir(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:k(t,"ga",e.idFactory,o),label:n,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:n,createdIds:[s.id]}}function os(t,e){if(M(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,o=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(o)||o<80)throw new d("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Table array center must be finite");let i=O(t,e.floorId),a=new Set,n=Nn(t,"T"),s=[];for(let c=0;c<e.tableRows;c+=1)for(let l=0;l<e.tableColumns;l+=1)s.push({type:"table",id:k(t,"t",e.idFactory,a),label:n(),center:{x:e.center.x+(l-(e.tableColumns-1)/2)*r,y:e.center.y+(c-(e.tableRows-1)/2)*o},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function rs(t,e){if(M(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,o=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(o)||o<52)throw new d("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Booth array center must be finite");let i=O(t,e.floorId),a=new Set,n=Nn(t,"B"),s=[];for(let c=0;c<e.boothRows;c+=1)for(let l=0;l<e.boothColumns;l+=1)s.push({type:"booth",id:k(t,"booth",e.idFactory,a),label:n(),center:{x:e.center.x+(l-(e.boothColumns-1)/2)*r,y:e.center.y+(c-(e.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function Ln(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2||o.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==o.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(h=>h.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let c=(e.displayLabel??n[0].displayLabel??n[0].label).normalize("NFKC").trim();if(!c||c.length>80)throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let l=new Set(r.objects.flatMap(h=>h.type==="row"?[h.segmentedRow?.groupId,h.rowBlockGeneration?.groupId].filter(u=>!!u):[])),f="";for(let h=0;h<100;h+=1){let u=e.idFactory("rowgroup");if(u&&!l.has(u)){f=u;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let g=n[0];return n.forEach((h,u)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:u,componentCount:n.length,boundaryBefore:u===0?"start":e.boundaries[u-1],displayLabel:c,...g.displayType?{displayType:g.displayType}:{},...g.labelPresentation?{labelPresentation:structuredClone(g.labelPresentation)}:{},...g.viewFromSeatUrl?{viewFromSeatUrl:g.viewFromSeatUrl}:{},...g.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(g.viewFromSeatMeta)}:{},...g.confidenceEvidence?{confidenceEvidence:structuredClone(g.confidenceEvidence)}:{}}}),{floorId:r.floorId,groupId:f,rowIds:o,changed:!0}}function is(t,e){let r=O(t,e.floorId),o=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??o?.segmentedRow?.groupId;if(!i)throw new d("object_not_found","The segmented row does not exist on the selected floor");let a=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let n=a.sort((s,c)=>s.segmentedRow.componentIndex-c.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:r.floorId,groupId:i,rowIds:n,changed:!0}}function as(t,e){let r=O(t,e.floorId),o=r.objects.filter(n=>n.type==="row"&&n.segmentedRow?.groupId===e.groupId).sort((n,s)=>n.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(o.length<2)throw new d("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==o.length-1||e.boundaries.some(n=>n!=="continuous"&&n!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(o.map(n=>n.segmentedRow));return o.forEach((n,s)=>{let c=n.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),e.boundaries&&s>0&&(c.boundaryBefore=e.boundaries[s-1]),e.smoothing!==void 0&&(c.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete c.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=e.viewFromSeatUrl),!c.viewFromSeatUrl||e.viewFromSeatMeta===null?delete c.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:r.floorId,groupId:e.groupId,rowIds:o.map(n=>n.id),changed:JSON.stringify(o.map(n=>n.segmentedRow))!==a}}function ss(t,e){if(typeof e.groupId!="string"||!e.groupId)throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let r=O(t,e.floorId),o=r.objects.filter(A=>A.type==="row"&&A.rowBlockGeneration?.groupId===e.groupId).sort((A,q)=>A.rowBlockGeneration.rowIndex-q.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((A,q)=>{let j=A.rowBlockGeneration;return j.kind!=="row-block-v1"||j.rowIndex!==q||j.signature!==i.signature||JSON.stringify(j)!==JSON.stringify({...i,rowIndex:q})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(o),n=e.style??i.style,s=e.rowCount??i.rowCount,c=e.seatsPerRow??i.seatsPerRow,l=e.rowGap??i.rowGap,f=e.seatSpacing??i.seatSpacing,g=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?dt(e.rotation??i.rotation):e.rotation??i.rotation,u=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(c)||c<1||c>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![l,f].every(A=>Number.isFinite(A)&&A>0)||!Number.isFinite(g)||!Number.isFinite(h)||!Number.isFinite(u.x)||!Number.isFinite(u.y))throw new d("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let m=Tn({style:n,origin:u,rotation:h,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:f,curve:g}),p={x:Math.cos(h*W),y:Math.sin(h*W)},w={x:-p.y,y:p.x},v=new Map(o.map(A=>[A.rowBlockGeneration.rowIndex,A])),I=new Set,y=new Set(r.objects.filter(A=>A.type==="row").filter(A=>!o.includes(A)).map(A=>A.label)),C=r.objects.filter(A=>A.type==="row").length,b=()=>{for(;y.has(U(C));)C+=1;let A=U(C);return y.add(A),C+=1,A},x=[],S=[];for(let A=0;A<s;A+=1){let q=n==="intertwined"&&A%2===1?f/2:0,j=v.get(A);j||(j={type:"row",id:k(t,"r",e.idFactory,I),label:b(),origin:{...u},rotation:h,curve:g,seatCount:c,seatSpacing:f,categoryKey:o[0].categoryKey},S.push(j.id)),j.origin={x:u.x+w.x*A*l+p.x*q,y:u.y+w.y*A*l+p.y*q},j.rotation=h,j.curve=g,j.seatCount=c,j.seatSpacing=f,delete j.path,delete j.arcFanGeneration,j.overrides&&(j.overrides=j.overrides.filter(z=>z.index<c),j.overrides.length||delete j.overrides),j.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:n,rowIndex:A,rowCount:s,seatsPerRow:c,origin:{...u},rotation:h,rowGap:l,seatSpacing:f,curve:g,signature:m},x.push(j)}let _=o.slice(s).map(A=>A.id),F=Math.min(...o.map(A=>r.objects.indexOf(A))),$=new Set(o.map(A=>A.id)),B=r.objects.filter(A=>!$.has(A.id));return B.splice(F,0,...x),r.objects.splice(0,r.objects.length,...B),{floorId:r.floorId,groupId:e.groupId,rowIds:x.map(A=>A.id),createdRowIds:S,removedRowIds:_,changed:a!==JSON.stringify(x)||S.length>0||_.length>0}}function Dn(t){let e=0;for(let r=1;r<t.length;r+=1)e+=Math.hypot(t[r].x-t[r-1].x,t[r].y-t[r-1].y);return e/Math.max(1,t.length-1)}function cr(t){let e=t.length,r=t.reduce((v,I)=>v+I.x,0)/e,o=t.reduce((v,I)=>v+I.y,0)/e,i=0,a=0,n=0,s=0,c=0,l=0,f=0;for(let v of t){let I=v.x-r,y=v.y-o;i+=I*I,a+=y*y,n+=I*y,s+=I*I*I,c+=y*y*y,l+=I*y*y,f+=y*I*I}let g=i*a-n*n;if(Math.abs(g)<1e-9)return null;let h=(s+l)/2,u=(c+f)/2,m=(h*a-u*n)/g,p=(u*i-h*n)/g,w=Math.sqrt(m*m+p*p+(i+a)/e);return Number.isFinite(w)?{center:{x:m+r,y:p+o},radius:w}:null}function Oe(t){let e=t[0],r=t[t.length-1],o=Math.hypot(r.x-e.x,r.y-e.y),i=t.length;return{origin:{...e},rotation:o>0?Math.atan2(r.y-e.y,r.x-e.x)*180/Math.PI:0,curve:0,seatSpacing:i>1&&o>0?o/(i-1):Dn(t),seatCount:i,ordered:t}}function lr(t){if(t.length<3)return Oe(t);let e=t[0],r=t[t.length-1],o=Math.hypot(r.x-e.x,r.y-e.y),i=Dn(t);if(o<=0||i<=0)return Oe(t);let a=0;for(let h of t){let u=Math.abs((r.x-e.x)*(e.y-h.y)-(e.x-h.x)*(r.y-e.y))/o;a=Math.max(a,u)}if(a<i*.2)return Oe(t);let n=cr(t);if(!n||n.radius<=i/2)return Oe(t);let s=h=>{let u=h[0],m=h[1],p=u.x-n.center.x,v=-(u.y-n.center.y),I=p;v*(m.x-u.x)+I*(m.y-u.y)<0&&(v=-v,I=-I);let y=Math.hypot(v,I)||1;v/=y,I/=y;let C=(n.center.x-u.x)*I+(n.center.y-u.y)*-v;return{tx:v,ty:I,centreSide:C}},c=t,l=s(c);l.centreSide<0&&(c=[...t].reverse(),l=s(c));let g=2*Math.asin(Math.min(1,i/(2*n.radius)))*(c.length-1)*180/Math.PI;return!Number.isFinite(g)||g>=359?Oe(t):{origin:{...c[0]},rotation:Math.atan2(l.ty,l.tx)*180/Math.PI,curve:g,seatSpacing:i,seatCount:c.length,ordered:c}}function Ue(t,e){let r=lr(t);if(t.length<6)return[r];let o=e(r),i=-1,a=0;if(r.ordered.forEach((s,c)=>{let l=o[c]?Math.hypot(s.x-o[c].x,s.y-o[c].y):1/0;l>a&&(a=l,i=c)}),a<=r.seatSpacing/3)return[r];let n=Math.min(r.ordered.length-3,Math.max(3,i));return[...Ue(r.ordered.slice(0,n),e),...Ue(r.ordered.slice(n),e)]}function gt(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function ht(t,e){let r="";for(let o of t){if(r.length+o.length>e)break;r+=o}return r.trim()}function bt(t){return ht(gt(t),40)}function Gn(t,e=39){return ht(gt(t),Math.max(1,e))}function ue(t,e=80){return ht(gt(t),Math.max(1,e))}function Kn(t){return ue(t).toLocaleLowerCase("en")}function pt(t){return Kn(t)}function $n(t){return new Map((t??[]).map(e=>[e.index,e]))}function dr(t){let e=$n(t.overrides),r=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||r.push(nt(t,o,i))}return r}function fr(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=$n(t.overrides),r=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||r.push(i?.label??`${t.label}-${o+1}`)}return r}function ur(t){return t.type==="row"?[t.label,...dr(t)]:t.type==="table"?[t.label,...fr(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...Z(t)]:[]}function Bn(t,e){let r=new Set;for(let o of t)if(!e?.has(o.id))for(let i of ur(o)){let a=pt(i);a&&r.add(a)}return r}function gr(t,e){if(!Number.isInteger(e)||e<1)return[];let r={label:t,seatCount:e},o=[pt(t)];for(let i=0;i<e;i+=1)o.push(pt(nt(r,i)));return o.filter(Boolean)}function zn(t,e,r){let o=gr(e,r);if(!o.length||o.some(i=>t.has(i)||ce(i)))return!1;for(let i of o)t.add(i);return!0}var hr=1e-6,br=160,pr=.001,yr=1e-5;function ge(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>br)return;for(let a of e){let n=a.codePointAt(0)??0;if(n<32||n===127)return}let r=e.lastIndexOf(":"),o=e.slice(0,r),i=e.slice(r+1);if(!(!o||!/^(0|[1-9]\d*)$/.test(i)||!Number.isSafeInteger(Number(i))))return e}function Un(t){return typeof t=="string"&&Gn(t)||void 0}function Jn(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(yt(t.origin)&&yt(e.start)&&yt(e.end)&&Number.isFinite(t.rotation)&&Number.isFinite(t.seatSpacing)&&t.seatSpacing>0)||t.curve!==0||t.path)return!1;let r=t.rotation*Math.PI/180,o={x:t.origin.x+Math.cos(r)*t.seatSpacing*(t.seatCount-1),y:t.origin.y+Math.sin(r)*t.seatSpacing*(t.seatCount-1)},i=Math.hypot(e.end.x-e.start.x,e.end.y-e.start.y),a=pr+Math.max(1,i)*yr;if(Math.hypot(t.origin.x-e.start.x,t.origin.y-e.start.y)>a||Math.hypot(o.x-e.end.x,o.y-e.end.y)>a)return!1;if(t.seatCount<2||i<=hr)return!0;let n=i/(t.seatCount-1);if(Math.abs(t.seatSpacing-n)>a)return!1;let s=Math.atan2(e.end.y-e.start.y,e.end.x-e.start.x)*180/Math.PI,c=Math.abs(((t.rotation-s)%360+540)%360-180),l=Math.max(.001,Math.atan2(a,Math.max(1,i))*180/Math.PI);return c<=l}function yt(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var mr=300;function wr(t){let e=new Set(Y(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(Boolean)),r=0,o=()=>{for(;e.has(U(r));)r+=1;let i=U(r);return r+=1,e.add(i),i};return i=>{let a=bt(i),n=0;return()=>{for(;a&&n<4096;n+=1){let s=`${a}-${U(n)}`;if(!e.has(s))return e.add(s),n+=1,s}return o()}}}function Ir(t){let e=Bn(Y(t));return(r,o)=>{let i=ue(r);for(let a=1;a<4096;a+=1){let n=a===1?"":` ${a}`,s=n?`${ue(i,80-n.length)}${n}`:i;if(s&&zn(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function vr(t){return{ordinaryFor:wr(t),direct:Ir(t)}}function mt(t,e,r){return t.type==="row"&&t.referenceScan?.assetId===e&&(!r||t.referenceScan.sectionId===r)}function qn(t,e,r){return t.type==="table"&&t.referenceScan?.assetId===e&&(!r||t.referenceScan.sectionId===r)}function Sr(t,e,r){let o=new Map;for(let n of e.sections)if(!(r&&n.sectionId!==r)&&n.sourceGroupId)for(let[s,c]of n.rows.entries()){let l=ge(`${n.sourceGroupId}:${s}`),f=l&&ge(c.directSourceRowId)===l?l:void 0;f&&o.set(f,o.has(f)?null:c)}let i=new Map;for(let n of t){let s=ge(n.referenceScan?.directSourceRowId);if(!s){if(!n.overrides?.length)continue;throw new d("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:n.id})}let c=i.get(s)??[];c.push(n),i.set(s,c)}let a=new Map;for(let[n,s]of i){let c=s.filter(h=>h.overrides?.length);if(!c.length)continue;let l=o.get(n),f=c[0],g=f.overrides;if(s.length!==1||c.length!==1||!g||!l||!Jn(f,l))throw new d("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:n,rowIds:s.map(h=>h.id)});a.set(n,structuredClone(g))}return a}function Vn(t,e,r){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!mt(o,e,r)&&!qn(o,e,r))}function Cr(t,e,r,o,i,a,n){let s=t.sectionId?e.find(f=>f.type==="section"&&f.id===t.sectionId):void 0;if(s){let f=Vn(e,r,n).filter(g=>K(N(g),s.outline,s.holes));if(f.length)return{skip:{sectionId:s.id,name:t.name,reason:"section_not_empty",objectIds:f.map(g=>g.id)},rows:[],seats:0}}let c=[],l=0;for(let[f,g]of t.rows.entries()){let h=Math.min(mr,Math.max(1,Math.round(g.seatCount)));if(!Number.isFinite(h)||h<1)continue;let u=g.end.x-g.start.x,m=g.end.y-g.start.y,p=Math.hypot(u,m),w=h>1&&p>0?p/(h-1):o>0?o:24;if(!Number.isFinite(w)||w<=0)continue;let v=p>0?Math.atan2(m,u)*180/Math.PI:0,I={x:g.start.x,y:g.start.y},y=0,C=w,b,x=g.seats?.length===h&&g.seats.every(j=>Number.isFinite(j.x)&&Number.isFinite(j.y))?g.seats:null;if(x&&g.table&&h>=3){let j=g.table.center,z=x.reduce((E,D)=>E+Math.hypot(D.x-j.x,D.y-j.y),0)/h,V=x.map(E=>Math.atan2(E.y-j.y,E.x-j.x)).sort((E,D)=>E-D),ne=0,Ae=0;V.forEach((E,D)=>{let se=D+1<V.length?V[D+1]:V[0]+Math.PI*2;se-E>ne&&(ne=se-E,Ae=(D+1)%V.length)});let R=ne>1.6*(Math.PI*2/h),P=R?(Math.PI*2-ne)*180/Math.PI:void 0;b={center:{...j},radius:Math.max(1,z-Xt),...P!==void 0?{seatArc:P}:{}},v=R?(V[Ae]-ne/2)*180/Math.PI:V[0]*180/Math.PI,I={...j}}let S=[];if(x&&!b&&h>=3){S=Ue(x,z=>ee({origin:z.origin,rotation:z.rotation,curve:z.curve,seatCount:z.seatCount,seatSpacing:z.seatSpacing}));let j=S[0];I=j.origin,v=j.rotation,y=j.curve,C=j.seatSpacing}if(!Number.isFinite(C)||C<=0)continue;let _=t.sourceGroupId?ge(`${t.sourceGroupId}:${f}`):void 0,F=_&&ge(g.directSourceRowId)===_?_:void 0,$=F?Un(g.directReviewedSuffix):void 0,B=t.sourceGroupId&&g.rowLabel?ue(g.rowLabel):"",A=t.sourceGroupId&&g.rowDisplayLabel?ue(g.rowDisplayLabel):"",q=!!t.sourceGroupId&&g.rowDisplayLabel==="";c.push({label:B?a(B,h):i(),displayLabel:A||(q?"":String(f+1)),origin:I,rotation:v,curve:y,seatCount:S[0]?.seatCount??h,seatSpacing:C,...b?{table:b}:{},...x&&!b?{measured:!0}:{},...F?{directSourceRowId:F}:{},...$?{directReviewedSuffix:$}:{}});for(let j of S.slice(1))c.push({label:i(),displayLabel:String(f+1),origin:j.origin,rotation:j.rotation,curve:j.curve,seatCount:j.seatCount,seatSpacing:j.seatSpacing,measured:!0});l+=h}return{skip:null,rows:c,seats:l}}function Rs(t,e,r){M(t,r.categoryKey);let o=O(t,r.floorId),i=e.assetId,a=r.sectionId?o.objects.find(I=>I.type==="section"&&I.id===r.sectionId):void 0;if(r.sectionId&&!a)throw new Error("The opened section no longer exists on this floor");let n=new Map;for(let I of e.sections){if(a&&I.sectionId!==a.id)continue;let y=r.categoryKeyForSection?.(I)??r.categoryKey;M(t,y),n.set(I,y)}if(a&&!e.sections.some(I=>I.sectionId===a.id&&I.seatCount>0))return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[]};let s=a?e.sections.find(I=>I.sectionId===a.id&&I.seatCount>0):void 0;if(a&&s){let I=Vn(o.objects,i,a.id).filter(y=>K(N(y),a.outline,a.holes));if(I.length)return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[{sectionId:a.id,name:s.name,reason:"section_not_empty",objectIds:I.map(y=>y.id)}]}}let c=o.objects.filter(I=>mt(I,i,a?.id)),l=Sr(c,e,a?.id),f=[],g=o.objects.filter(I=>mt(I,i,a?.id)||qn(I,i,a?.id)?(f.push(I.id),!1):!0);o.objects.splice(0,o.objects.length,...g);let h=[],u=[],m=[],p=new Set,w=0,v=vr(t);for(let I of e.sections){if(a&&I.sectionId!==a.id)continue;let y=Cr(I,o.objects,i,e.seatPitch,v.ordinaryFor(I.name),v.direct,a?.id);if(y.skip){u.push(y.skip);continue}let C=[],b=[],x=0;for(let S of y.rows){let _={assetId:i,...I.sectionId?{sectionId:I.sectionId}:{}},F=n.get(I)??r.categoryKey;if(S.table){x+=1,C.push({type:"table",id:k(t,"t",r.idFactory,p),referenceScan:_,label:S.label,displayLabel:String(x),center:S.table.center,shape:"round",radius:S.table.radius,...S.table.seatArc!==void 0?{seatArc:S.table.seatArc}:{},rotation:S.rotation,seatCount:S.seatCount,categoryKey:F});continue}let $={type:"row",id:k(t,"r",r.idFactory,p),referenceScan:{..._,...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:S.curve,seatCount:S.seatCount,seatSpacing:S.seatSpacing,categoryKey:F,...S.directSourceRowId&&l.has(S.directSourceRowId)?{overrides:structuredClone(l.get(S.directSourceRowId))}:{}};C.push($),S.measured&&b.push($)}if(o.objects.push(...C),b.length&&!I.sourceGroupId){let S=G(t).find(_=>_.id===o.floorId);xr(t,b,S?.focalPoint??t.focalPoint,o.floorId,r.idFactory)}for(let S of C)m.push(S.id);h.push({sectionId:I.sectionId,name:I.name,seats:y.seats,rows:C.length}),w+=y.seats}return{floorId:o.floorId,assetId:i,createdRowIds:m,removedRowIds:f,totalSeats:w,perSection:h,skipped:u}}function xr(t,e,r,o,i){let a=e.map(u=>ee(u)),n=a.flat(),s=r??{x:n.reduce((u,m)=>u+m.x,0)/n.length,y:Math.min(...n.map(u=>u.y))-1},c=e.map((u,m)=>{let p=a[m],w=p.map((I,y)=>{let C=p[Math.max(0,y-1)],b=p[Math.min(p.length-1,y+1)],x=Math.hypot(b.x-C.x,b.y-C.y);return x<=0?Math.hypot(I.x-s.x,I.y-s.y):Math.abs((I.x-s.x)*(-(b.y-C.y)/x)+(I.y-s.y)*((b.x-C.x)/x))}).sort((I,y)=>I-y),v=p.reduce((I,y)=>I+y.x,0)/p.length;return{row:u,depth:w[Math.floor(w.length/2)],along:v}}).sort((u,m)=>u.depth-m.depth||u.along-m.along),l=c.slice(1).map((u,m)=>u.depth-c[m].depth).filter(u=>u>1e-6).sort((u,m)=>u-m),f=l.length?l[Math.floor(l.length*.75)]:1/0,g=[],h=-1/0;for(let u of c)(!g.length||u.depth-h>f*.45)&&(g.push([]),h=u.depth),g[g.length-1].push(u.row);g.forEach((u,m)=>{let p=U(m);u.sort((w,v)=>{let I=ee(w),y=ee(v);return I.reduce((C,b)=>C+b.x,0)/I.length-y.reduce((C,b)=>C+b.x,0)/y.length});for(let w of u)w.displayLabel=p;u.length>=2&&u.length<=64&&Ln(t,{floorId:o,rowIds:u.map(w=>w.id),boundaries:u.slice(1).map(()=>"break"),displayLabel:p,idFactory:i})})}function Hn(t,e,r={}){let o=O(t,e.floorId),i=[...new Set(e.objectIds)];if(!i.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let a=i.map(p=>o.objects.find(w=>(w.type==="table"||w.type==="booth")&&w.id===p)),n=i.filter((p,w)=>!a[w]);if(n.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:n});let s=a[0].type;if(a.some(p=>p.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[p,w,v]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(w)||w<1||w>v)throw new d("invalid_operation",`${p} must be a whole number from 1 to ${v}`);for(let[p,w]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(w)||w<30||w>2e3)throw new d("invalid_operation",`${p} must be from 30 to 2000 chart units`);let c=e.rows*e.columns;if(c<2)throw new d("invalid_operation","Choose at least two grid cells");let l=i.length*(c-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let f=a.reduce((p,w)=>p+(w.type==="table"?w.seatCount:1),0),h=(t.floors?.length?t.floors.flatMap(p=>p.objects):t.objects).reduce((p,w)=>p+(w.type==="row"||w.type==="table"?w.seatCount:w.type==="gaArea"?Math.max(0,Math.floor(w.capacity)):w.type==="booth"?1:0),0),u=f*(c-1),m=r.maxInventory??1e5;if(h+u>m)throw new d("invalid_operation",`Grid inventory would exceed the ${m} unit event limit`);return{target:o,sources:a,preview:{floorId:o.floorId,kind:s,sourceIds:i,sourceCount:i.length,cells:c,createdCount:l,addedInventory:u,resultingInventory:h+u,provenanceRemovedCount:a.filter(p=>!!p.referenceInventorySource).length*(c-1)}}}function js(t,e,r={}){return Hn(t,e,r).preview}function Ps(t,e,r={}){let{target:o,sources:i,preview:a}=Hn(t,e,r),n=new Set,s=new Set((t.floors?.length?t.floors.flatMap(g=>g.objects):t.objects).flatMap(g=>"label"in g&&g.label?[g.label]:[])),c=[],l=(g,h)=>{let u=Math.max(2,h),m=w=>{let v=`-${w}`;return`${g.slice(0,Math.max(1,80-v.length))}${v}`},p=m(u);for(;s.has(p);)p=m(++u);return s.add(p),p},f=1;for(let g=0;g<e.rows;g++)for(let h=0;h<e.columns;h++)if(!(g===0&&h===0)){f+=1;for(let u of i){let m=structuredClone(u);m.id=k(t,m.type,e.idFactory,n),m.label=l(u.label,f),m.center={x:u.center.x+h*e.stepX,y:u.center.y+g*e.stepY},delete m.referenceInventorySource,c.push(m)}}return o.objects.push(...c),{...a,createdIds:c.map(g=>g.id)}}function Or(t,e){let r=t?{...t}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=L(e.color,"Seat label color")),r.size===void 0&&r.color===void 0?void 0:r}var Rr=new Set(je.map(t=>t.key));function Je(t){return`${t.rowId}:${t.index}`}function Ds(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",o=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(o)||o<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:o}}function _r(t,e){t.label||delete t.label,t.displayLabel||delete t.displayLabel,t.dx||delete t.dx,t.dy||delete t.dy,t.skip||delete t.skip,t.categoryKey||delete t.categoryKey,Se(t.glyph)||delete t.glyph;let r=Ht(t);if(r.length?t.accessibility=r:delete t.accessibility,delete t.accessible,t.commercial){let o=t.commercial.note?.normalize("NFKC").trim(),i={};typeof t.commercial.restrictedView=="boolean"&&(i.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(i.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(i.premium=t.commercial.premium),o&&(i.note=o),Object.keys(i).length?t.commercial=i:delete t.commercial}t.viewFromSeatUrl||(delete t.viewFromSeatUrl,delete t.viewFromSeatMeta),t.labelStyle&&t.labelStyle.size===void 0&&t.labelStyle.color===void 0&&delete t.labelStyle,e?.type==="row"&&Wt(e,t)}function Ar(t){return Object.keys(t).every(e=>e==="index")}function Xn(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let o=O(t,e),i=[],a=new Set,n=new Map;for(let s of r){let c=Je(s);if(a.has(c))continue;a.add(c);let l=o.objects.find(f=>(f.type==="row"||f.type==="table")&&f.id===s.rowId);if(!l)throw new d("object_not_found",`Unknown row or table for seat: ${c}`,{seatId:c,objectId:s.rowId});if(l.type==="table"&&(l.bookAsWhole||l.variableOccupancy))throw new d("invalid_operation",`Table "${l.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:c,tableId:l.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=l.seatCount)throw new d("invalid_operation",l.type==="row"?`Seat index is outside row bounds: ${c}`:`Chair index is outside table bounds: ${c}`,{seatId:c,objectId:s.rowId,index:s.index,seatCount:l.seatCount});i.push({rowId:s.rowId,index:s.index}),n.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:n}}function Yn(t,e){let r=Xn(t,e.floorId,e.seats),o=Object.keys(e.patch);if(!o.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&M(t,e.patch.categoryKey),e.patch.glyph!=null&&!Se(e.patch.glyph))throw new d("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(n=>!Rr.has(n));if(a.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new d("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of r.refs){let n=r.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??n?.wheelchairSpaceType,c=e.patch.skip===null?!1:e.patch.skip??n?.skip??!1;if(s&&c)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:Je(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new d("invalid_operation","Commercial note supports at most 160 characters");if(e.patch.viewFromSeatUrl!=null){let a=oe(e.patch.viewFromSeatUrl);if(!a)throw new d("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");e.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let n=e.patch[a];if(n!=null&&!Number.isFinite(n))throw new d("invalid_operation",`${a} must be finite`,{[a]:n})}e.patch.labelStyle!=null&&te(e.patch.labelStyle,"Seat");let i=!1;return r.refs.forEach((a,n)=>{let s=r.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),f=l.find(h=>h.index===a.index);f||(f={index:a.index},l.push(f));let g=f.viewFromSeatUrl;for(let h of o){let u=e.patch[h];if(h==="wheelchairSpaceType"&&u==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(m=>m!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(u==null)delete f[h];else if(h==="accessibility")f.accessibility=[...new Set(u)],delete f.accessible;else if(h==="commercial")f.commercial={...f.commercial,...u};else if(h==="labelStyle"){let m=Or(f.labelStyle,u);m?f.labelStyle=m:delete f.labelStyle}else Object.assign(f,{[h]:u})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==g&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${n+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${n+1}`),_r(f,s),Ar(f)&&(s.overrides=l.filter(h=>h!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:r.floorId,changed:i,seatIds:r.refs.map(Je)}}function Gs(t,e){let r=Xn(t,e.floorId,e.seats),o=!1;for(let[i,a]of r.owners){if(!a.overrides?.length)continue;let n=new Set(r.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!n.has(c.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:r.floorId,changed:o,seatIds:r.refs.map(Je)}}function Us(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(y=>r.objects.find(C=>C.type==="row"&&C.id===y)),a=o.filter((y,C)=>!i[C]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&M(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let y=e.patch.seatNumbering,C=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(y.scheme!==void 0&&!C.includes(y.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${y.scheme}. Expected one of ${C.join(", ")}.`);if(y.prefix!==void 0&&(typeof y.prefix!="string"||y.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(y.endAt!==void 0&&y.endAt!==null&&(!Number.isInteger(y.endAt)||y.endAt<0||y.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:n,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:f,displayType:g,aisleSeats:h,...u}=e.patch,m=f===void 0?{}:{displayLabel:f},p=le(m,"Row"),w=g===void 0?void 0:un(g,"Row");if(n!==void 0&&te(n,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new d("invalid_operation","Row labelPosition must be one of start, end, both, none");if(c!=null&&(!Number.isFinite(c)||c<-180||c>180))throw new d("invalid_operation","Row labelRotation must be a number from -180 to 180");if(l!==void 0&&l!=="plain"&&l!=="pill")throw new d("invalid_operation","Row labelStyleShape must be plain or pill");if(u.labelPresentation!==void 0&&Le(u.labelPresentation,"Row"),h!=null&&!on(h))throw new d("invalid_operation","Row aisleSeats must be one of start, end, both, none (or null for automatic)");let v=y=>JSON.stringify({origin:y.origin,rotation:y.rotation,curve:y.curve,seatCount:y.seatCount,seatSpacing:y.seatSpacing,path:y.path??null}),I=!1;for(let y of i){let C=JSON.stringify(y),b=v(y),x=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?N(y):null;if(Object.assign(y,structuredClone(u)),y.overrides&&e.patch.seatCount!==void 0&&(y.overrides=y.overrides.filter(S=>S.index<y.seatCount),y.overrides.length||(y.overrides=void 0)),x){let S=N(y);y.origin={x:y.origin.x+x.x-S.x,y:y.origin.y+x.y-S.y}}if(JSON.stringify(y)!==C&&(I=!0),v(y)!==b&&(delete y.arcFanGeneration,delete y.rowBlockGeneration),n!==void 0){let S=JSON.stringify(y.labelPresentation??null),_=de(y.labelPresentation,n);_?y.labelPresentation=_:delete y.labelPresentation,JSON.stringify(y.labelPresentation??null)!==S&&(I=!0)}if(s!==void 0){let S=JSON.stringify(y.labelPresentation??null),_=y.labelPresentation?structuredClone(y.labelPresentation):{};_.positionPreset=s,_.visible=s!=="none",delete _.position,y.labelPresentation=_,JSON.stringify(y.labelPresentation??null)!==S&&(I=!0)}if(c!==void 0||l!==void 0){let S=JSON.stringify(y.labelPresentation??null),_=y.labelPresentation?structuredClone(y.labelPresentation):{};c===null?delete _.rotation:c!==void 0&&(_.rotation=c),l!==void 0&&(_.style=l),y.labelPresentation=_,JSON.stringify(y.labelPresentation??null)!==S&&(I=!0)}if(w!==void 0){let S=y.displayType;w?y.displayType=w:delete y.displayType,y.displayType!==S&&(I=!0)}if(h!==void 0){let S=y.aisleSeats;h===null?delete y.aisleSeats:y.aisleSeats=h,y.aisleSeats!==S&&(I=!0)}if(f!==void 0){let S=y.displayLabel;p?delete y.displayLabel:y.displayLabel=m.displayLabel,y.displayLabel!==S&&(I=!0)}}return{floorId:r.floorId,changed:I,rowIds:o}}var jr=3;function qe(t){return(t%360+360)%360}function Pr(t){let e=t.rotation*W;return{x:Math.cos(e),y:Math.sin(e)}}function kr(t,e){let r=Math.abs(qe(t-e));return r>180&&(r=360-r),r}function he(t,e,r){return(t.x-e.x)*r.x+(t.y-e.y)*r.y}function Wn(t){let e=0,r=0;for(let i of t){let a=2*i.rotation*W;e+=Math.cos(a),r+=Math.sin(a)}let o=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(o),y:Math.sin(o)}}function Fr(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let o=i=>({x:i.x+e,y:i.y+r});t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)}}}function Zn(t,e){let r=Wn(t),o={x:-r.y,y:r.x},i=N(t[0]),a=t.map(c=>({row:c,coord:he(N(c),i,o)})).sort((c,l)=>c.coord-l.coord),n=a[0].coord,s=!1;return a.forEach((c,l)=>{let f=n+l*e-c.coord;Math.abs(f)>1e-6&&(Fr(c.row,o.x*f,o.y*f),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Mr(t,e){let r={x:-e.y,y:e.x},o=N(t[0]),i=t.map(n=>he(N(n),o,r)).sort((n,s)=>n-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Er(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=ee(t),r=e[0],o=e[e.length-1],i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,n/(t.seatCount-1))),n>1e-6&&(t.rotation=qe(Math.atan2(a,i)/W)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Tr(t,e){let r=new Set(t.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${e}${o}`.slice(0,80);if(!r.has(i))return i}return`${e}-${Date.now().toString(36)}`}function Js(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to merge");let i=o.map(b=>r.objects.find(x=>x.type==="row"&&x.id===b)),a=o.filter((b,x)=>!i[x]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(b=>b.path||b.curve!==0);if(s.length)throw new d("invalid_operation","Only straight rows can be merged. Straighten the rows first, then merge.",{rowIds:s.map(b=>b.id)});let c=n[0],l=n.find(b=>kr(b.rotation,c.rotation)>jr);if(l)throw new d("invalid_operation","Rows must be parallel to merge. They point in different directions.",{rowIds:[c.id,l.id]});let f=Pr(c),g={x:-f.y,y:f.x},h=Math.max(8,c.seatSpacing*.6),u=n.find(b=>Math.abs(he(b.origin,c.origin,g))>h);if(u){let b=Math.round(Math.abs(he(u.origin,c.origin,g)));throw new d("invalid_operation",`Rows must lie on the same line to merge: a selected row is offset ${b} units from the first.`,{rowIds:[c.id,u.id]})}let m=n.slice().sort((b,x)=>he(b.origin,c.origin,f)-he(x.origin,c.origin,f)),p=m.reduce((b,x)=>b+x.seatCount,0);if(p>300)throw new d("invalid_operation",`A merged row would have ${p} seats, over the 300-seat row limit. Merge fewer rows.`);let w=m[0];an(m,w);let v=[],I=0;for(let b of m){if(b.overrides)for(let x of b.overrides)v.push({...structuredClone(x),index:x.index+I});I+=b.seatCount}w.seatCount=p,w.curve=0,delete w.path,v.length?w.overrides=v:delete w.overrides,delete w.arcFanGeneration,delete w.rowBlockGeneration;let y=m.slice(1).map(b=>b.id),C=new Set(y);for(let b=r.objects.length-1;b>=0;b--)C.has(r.objects[b].id)&&r.objects.splice(b,1);return{floorId:r.floorId,changed:!0,rowId:w.id,removedRowIds:y,seatCount:p}}function qs(t,e){let r=O(t,e.floorId),o=r.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!o)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(o.path)throw new d("invalid_operation","Cannot split a free-form curved row. Straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let n=ee(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:k(t,"r",e.idFactory,new Set),label:Tr(r.objects,o.label),origin:{...n[a]},rotation:qe(o.rotation-s*a),curve:s*(c-1),seatCount:c,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(l.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(l.seatLabelStart=o.seatLabelStart),o.commercial&&(l.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(l.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(l.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let u=structuredClone(o.labelPresentation);delete u.position,l.labelPresentation=u}let f=[],g=[];if(o.overrides)for(let u of o.overrides)u.index<a?f.push(structuredClone(u)):g.push({...structuredClone(u),index:u.index-a});rn(o,o,l),o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,g.length&&(l.overrides=g);let h=r.objects.indexOf(o);return r.objects.splice(h+1,0,l),{floorId:r.floorId,changed:!0,rowId:o.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function Vs(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new d("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(s=>r.objects.find(c=>c.type==="row"&&c.id===s)),a=o.filter((s,c)=>!i[c]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=Zn(i,e.gap);return{floorId:r.floorId,changed:n,rowIds:o,gap:e.gap}}function Hs(t,e){let r=O(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=()=>JSON.stringify(n.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),c=s();for(let h of n)Er(h);let l=Wn(n),f=qe(Math.atan2(l.y,l.x)/W);for(let h of n)h.rotation=f;let g=Mr(n,l);return Zn(n,g),{floorId:r.floorId,changed:s()!==c,rowIds:o,gap:g}}import wt from"polygon-clipping";var Qn=100,eo=512,It=8192,co=64,to=1e7,T=1e-7;function lo(t,e){return Math.abs(t.x-e.x)<=T&&Math.abs(t.y-e.y)<=T}function fo(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&lo(e[0],e[e.length-1]);)e.pop();return e}function Re(t,e,r){let o=H(e,r,t);return Math.abs(o)>T?!1:t.x>=Math.min(e.x,r.x)-T&&t.x<=Math.max(e.x,r.x)+T&&t.y>=Math.min(e.y,r.y)-T&&t.y<=Math.max(e.y,r.y)+T}function uo(t,e,r,o){let i=H(t,e,r),a=H(t,e,o),n=H(r,o,t),s=H(r,o,e);return(i>T&&a<-T||i<-T&&a>T)&&(n>T&&s<-T||n<-T&&s>T)?!0:Math.abs(i)<=T&&Re(r,t,e)||Math.abs(a)<=T&&Re(o,t,e)||Math.abs(n)<=T&&Re(t,r,o)||Math.abs(s)<=T&&Re(e,r,o)}function Nr(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let o=e+1;o<t.length;o+=1){let i=(o+1)%t.length;if(!(e===o||r===o||i===e)&&uo(t[e],t[r],t[o],t[i]))return!0}}return!1}function no(t,e){return t.some((r,o)=>e.some((i,a)=>uo(r,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function vt(t,e){return!e.some((r,o)=>Re(t,r,e[(o+1)%e.length]))&&K(t,e,void 0)}function He(t,e,r){let o=fo(t);if(o.length<3||o.length>eo||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>to||Math.abs(i.y)>to||lo(i,o[(a+1)%o.length]))||Math.abs(ke(o))<=T||Nr(o))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${eo} finite vertices per ring.`,{gaAreaId:r,ring:e});return o}function Lr(t){let e=He(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>co)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=r.map(i=>He(i,"cutout",t.id));for(let i=0;i<o.length;i+=1){let a=o[i];if(!a.flatMap((s,c)=>{let l=a[(c+1)%a.length];return[s,{x:(s.x+l.x)/2,y:(s.y+l.y)/2}]}).every(s=>vt(s,e))||no(a,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<o.length;s+=1)if(no(a,o[s])||vt(a[0],o[s])||vt(o[s][0],a))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:o}}function Ve(t){return t.map(e=>[e.x,e.y])}function oo(t){return fo(t.map(([e,r])=>({x:e,y:r})))}function ro(t){return Math.abs(t.reduce((e,r,o)=>{let i=t[(o+1)%t.length];return e+r[0]*i[1]-i[0]*r[1]},0))/2}function Dr(t){return t.reduce((e,r)=>e+(ro(r[0]??[])-r.slice(1).reduce((o,i)=>o+ro(i),0)),0)}function St(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(St).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${St(e[r])}`).join(",")}}`}function io(t,e,r){let o=t[e];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return i}function ao(t){return St({categoryKey:t.categoryKey,displayLabel:io(t,"displayLabel",80),displayType:io(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function so(t,e){let r=Math.min(...t.points.map(i=>i.y)),o=Math.min(...t.points.map(i=>i.x));return[r,o,e]}function Gr(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function go(t,e,r={}){let o=O(t,e.floorId),i=[...new Set(e.gaAreaIds)];if(i.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(i.length>Qn)throw new d("invalid_operation",`Join Areas supports at most ${Qn} areas at once`);let a=i.map(R=>o.objects.find(P=>P.type==="gaArea"&&P.id===R)),n=i.filter((R,P)=>!a[P]);if(n.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:n});let s=a,c=s.find(R=>Ie(R));if(c)throw new d("invalid_operation",`"${c.displayLabel??c.label}" is sold as one box. Only areas sold per person can be joined; switch it back to Standing first.`,{gaAreaId:c.id});M(t,s[0].categoryKey);let l=ao(s[0]),f=s.find(R=>ao(R)!==l);if(f)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[s[0].id,f.id]});let g=ve(t).objectToSection,h=g.get(s[0].id)??"__ungrouped__",u=s.find(R=>(g.get(R.id)??"__ungrouped__")!==h);if(u)throw new d("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[s[0].id,u.id],sectionIds:[h,g.get(u.id)??"__ungrouped__"]});let m=s.reduce((R,P)=>{if(!Number.isInteger(P.capacity)||P.capacity<1||P.capacity>J)throw new d("invalid_operation",`GA area ${P.id} has invalid capacity`,{gaAreaId:P.id});return R+P.capacity},0);if(m>J)throw new d("invalid_operation",`Joined GA capacity would be ${m}, over the ${J}-unit area limit`,{capacity:m});let p=Y(t).reduce((R,P)=>R+ie(P),0),w=r.maxInventory??1e5;if(p>w)throw new d("invalid_operation",`Chart inventory exceeds the ${w}-unit publication limit`,{inventory:p});let v=s.map(Lr),I=v.reduce((R,P)=>R+P.outer.length+P.holes.reduce((E,D)=>E+D.length,0),0);if(I>It)throw new d("invalid_operation",`Join Areas supports at most ${It} source vertices`,{vertexCount:I});let y;try{let R=v.map(D=>[Ve(D.outer)]);if(y=wt.union(R[0],...R.slice(1)),y.length!==1)throw new d("invalid_operation","Selected GA areas must overlap or share an edge. Disconnected or point-only contact cannot produce one sellable surface.",{surfaceCount:y.length});let P=v.flatMap(D=>D.holes.map(se=>[Ve(se)]));P.length&&(y=wt.difference(y,...P));let E=v.findIndex(D=>{let se=[Ve(D.outer),...D.holes.map(Ve)];return Dr(wt.intersection(se,y))<=T});if(E>=0)throw new d("invalid_operation",`GA area ${s[E].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:s[E].id})}catch(R){throw R instanceof d?R:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:R instanceof Error?R.message:"polygon_union_failed"})}if(y.length!==1||!y[0]?.length)throw new d("invalid_operation","Joining these boundaries would create disconnected sellable surfaces; adjust the outlines or cutouts first.",{surfaceCount:y.length});let C=oo(y[0][0]),b=y[0].slice(1).map(oo),x=C.length+b.reduce((R,P)=>R+P.length,0);if(b.length>co||x>It)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:b.length,vertexCount:x});He(C,"outline",s[0].id),b.forEach(R=>He(R,"cutout",s[0].id));let S=new Map(o.objects.map((R,P)=>[R.id,P])),_=s.slice().sort((R,P)=>Gr(so(R,S.get(R.id)??Number.MAX_SAFE_INTEGER),so(P,S.get(P.id)??Number.MAX_SAFE_INTEGER))),F=_[0],$=structuredClone(t),B=O($,o.floorId),A=B.objects.find(R=>R.type==="gaArea"&&R.id===F.id);A.points=structuredClone(C),b.length?A.holes=structuredClone(b):delete A.holes;let q=new Set(_.slice(1).map(R=>R.id));for(let R=B.objects.length-1;R>=0;R-=1)q.has(B.objects[R].id)&&B.objects.splice(R,1);let j=ve($).objectToSection.get(F.id)??"__ungrouped__";if(j!==h)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:F.id,beforeSectionId:h,afterSectionId:j});let z=[],V=new Set;for(let R of _){if(!Qt(R))throw new d("invalid_operation",`GA area ${R.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:R.id});let P=Z(R);if(P.length!==R.capacity||P.some(E=>V.has(E)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:R.id});P.forEach(E=>V.add(E)),z.push(...en(R))}if(z.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let ne=new Set(s.map(R=>R.id));for(let R of Y(t).filter(P=>P.type==="gaArea"&&!ne.has(P.id))){let P=Z(R).find(E=>V.has(E));if(P)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:P,gaAreaId:R.id})}let Ae=_.slice(1).map(R=>R.id);return{floorId:o.floorId,areaId:F.id,survivorLabel:F.label,removedAreaIds:Ae,sourceAreaCount:_.length,capacity:m,inventorySegmentCount:z.length,outerVertexCount:C.length,holeCount:b.length,sectionId:h,points:C,...b.length?{holes:b}:{},segments:z}}function nc(t,e,r={}){let{segments:o,...i}=go(t,e,r);return i}function oc(t,e,r={}){let o=go(t,e,r),i=O(t,o.floorId),a=i.objects.find(f=>f.type==="gaArea"&&f.id===o.areaId);a.points=structuredClone(o.points),o.holes?.length?a.holes=structuredClone(o.holes):delete a.holes;let n=i.objects.filter(f=>f.type==="gaArea"&&(f.id===o.areaId||o.removedAreaIds.includes(f.id))).reduce((f,g)=>f+(g.wheelchairPlaces??0),0);a.capacity=o.capacity,a.inventorySegments=structuredClone(o.segments),n>0&&(a.wheelchairPlaces=Math.min(n,o.capacity));let s=new Set(o.removedAreaIds);for(let f=i.objects.length-1;f>=0;f-=1)s.has(i.objects[f].id)&&i.objects.splice(f,1);let{segments:c,...l}=o;return{...l,changed:!0}}function fc(t,e){let r=O(t,e.floorId),o=[...new Set(e.shapeIds)];if(!o.length)throw new d("invalid_operation","At least one shape id is required");let i=o.map(l=>r.objects.find(f=>f.type==="shape"&&f.id===l)),a=o.filter((l,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one shape change is required");if(n.label!==void 0){if(o.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(n.label!==null){if(n.label=n.label.normalize("NFKC").trim(),!n.label)n.label=null;else if(n.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(n.labelStyle!==void 0){let l=i.filter(f=>f.role!=="stage");if(l.length)throw new d("invalid_operation","Shape label styling applies only to stages",{shapeIds:l.map(f=>f.id)});if(n.labelStyle.size!==void 0&&n.labelStyle.size!==null&&(!Number.isFinite(n.labelStyle.size)||n.labelStyle.size<Qe||n.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${Qe} to ${72}`);if(n.labelStyle.color!==void 0&&n.labelStyle.color!==null&&(n.labelStyle.color=L(n.labelStyle.color,"Shape label color")),n.labelStyle.fontFamily!==void 0&&n.labelStyle.fontFamily!==null&&(n.labelStyle.fontFamily=n.labelStyle.fontFamily.normalize("NFKC").trim(),!n.labelStyle.fontFamily||n.labelStyle.fontFamily.length>120))throw new d("invalid_operation","Stage label fontFamily must contain 1 to 120 characters");if(n.labelStyle.direction!==void 0&&n.labelStyle.direction!==null&&!_t.includes(n.labelStyle.direction))throw new d("invalid_operation","Stage label direction must be horizontal, vertical, or auto");for(let f of["bold","italic","underline"]){let g=n.labelStyle[f];if(g!=null&&typeof g!="boolean")throw new d("invalid_operation",`Stage label ${f} must be a boolean`)}}if(n.fill!==void 0&&n.fill!==null&&(n.fill=L(n.fill,"Shape fill")),n.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(n.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(n.stroke!==void 0&&n.stroke!==null){if(!Number.isFinite(n.stroke.width)||n.stroke.width<.5||n.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");n.stroke={color:L(n.stroke.color,"Shape stroke"),width:n.stroke.width}}if(n.cornerRadius!==void 0&&n.cornerRadius!==null&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(n.opacity!==void 0&&n.opacity!==null&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(n.heightM!==void 0&&n.heightM!==null&&(!Number.isFinite(n.heightM)||n.heightM<.05||n.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(n.eventConfigurationIds!==void 0&&n.eventConfigurationIds!==null){let l=n.eventConfigurationIds.map(f=>f.normalize("NFKC").trim());if(!l.length||l.length>20||l.some(f=>!f||f.length>100)||new Set(l).size!==l.length)throw new d("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");n.eventConfigurationIds=l}if(n.lineCap!==void 0&&n.lineCap!==null&&!cn.includes(n.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(n.lineJoin!==void 0&&n.lineJoin!==null&&!ln.includes(n.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,f]of[["startEnding",n.startEnding],["endEnding",n.endEnding]])if(f!=null&&!dn.includes(f))throw new d("invalid_operation",`Shape ${l} must be none or arrow`);if(n.lineCap!=null||n.lineJoin!=null||n.startEnding!=null||n.endEnding!=null){let l=i.filter(f=>!ct(n.kind??f.kind));if(l.length)throw new d("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:l.map(f=>f.id)})}let c=!1;for(let l of i){let f=JSON.stringify(l);if(n.label===null?delete l.label:n.label!==void 0&&(l.label=n.label),n.labelStyle!==void 0){let g={...l.labelStyle};n.labelStyle.size===null?delete g.size:n.labelStyle.size!==void 0&&(g.size=n.labelStyle.size),n.labelStyle.color===null?delete g.color:n.labelStyle.color!==void 0&&(g.color=n.labelStyle.color),n.labelStyle.fontFamily===null?delete g.fontFamily:n.labelStyle.fontFamily!==void 0&&(g.fontFamily=n.labelStyle.fontFamily),n.labelStyle.bold===null?delete g.bold:n.labelStyle.bold!==void 0&&(g.bold=n.labelStyle.bold),n.labelStyle.italic===null||n.labelStyle.italic===!1?delete g.italic:n.labelStyle.italic===!0&&(g.italic=!0),n.labelStyle.underline===null||n.labelStyle.underline===!1?delete g.underline:n.labelStyle.underline===!0&&(g.underline=!0),n.labelStyle.direction===null||n.labelStyle.direction==="horizontal"?delete g.direction:n.labelStyle.direction!==void 0&&(g.direction=n.labelStyle.direction),Object.keys(g).length?l.labelStyle=g:delete l.labelStyle}if(n.fill===null?delete l.fill:n.fill!==void 0&&(l.fill=n.fill),n.kind!==void 0&&(l.kind=n.kind,ct(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),n.stroke===null?delete l.stroke:n.stroke!==void 0&&(l.stroke={...n.stroke}),n.opacity===null?delete l.opacity:n.opacity!==void 0&&(l.opacity=n.opacity),n.heightM===null?delete l.heightM:n.heightM!==void 0&&(l.heightM=n.heightM),n.eventConfigurationIds===null?delete l.eventConfigurationIds:n.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...n.eventConfigurationIds]),n.lineCap===null?delete l.lineCap:n.lineCap!==void 0&&(l.lineCap=n.lineCap),n.lineJoin===null?delete l.lineJoin:n.lineJoin!==void 0&&(l.lineJoin=n.lineJoin),n.startEnding===null?delete l.startEnding:n.startEnding!==void 0&&(l.startEnding=n.startEnding),n.endEnding===null?delete l.endEnding:n.endEnding!==void 0&&(l.endEnding=n.endEnding),n.cornerRadius===null)delete l.cornerRadius;else if(n.cornerRadius!==void 0){let g=Math.min(l.width??1/0,l.height??1/0),h=Number.isFinite(g)?g/2:n.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(n.cornerRadius,h)):n.cornerRadius}JSON.stringify(l)!==f&&(Fe(l),c=!0)}return{floorId:r.floorId,changed:c,shapeIds:o}}function ho(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),o=e.map(f=>f.y),i=Math.min(...r),a=Math.max(...r),n=Math.min(...o),s=Math.max(...o),c=Math.max(1,a-i),l=Math.max(1,s-n);return{cx:i+c/2,cy:n+l/2,width:c,height:l}}function uc(t,e){let r=O(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let o=e.updates.map(n=>n.shapeId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Shape ids must be unique");let i=e.updates.map(n=>{if(![n.width,n.height].every(Number.isFinite)||n.width<8||n.height<8||n.width>1e4||n.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:n.shapeId});let s=r.objects.find(l=>l.type==="shape"&&l.id===n.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${n.shapeId}`,{shapeId:n.shapeId});let c=s.role==="stage"?ho(s):(s.kind==="rect"||s.kind==="ellipse")&&s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null?{cx:s.x+s.width/2,cy:s.y+s.height/2,width:s.width,height:s.height}:(()=>{let l=s.points??[];if(l.length<3||l.some(w=>!Number.isFinite(w.x)||!Number.isFinite(w.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=l.map(w=>w.x),g=l.map(w=>w.y),h=Math.min(...f),u=Math.max(...f),m=Math.min(...g),p=Math.max(...g);return{cx:(h+u)/2,cy:(m+p)/2,width:Math.max(1,u-h),height:Math.max(1,p-m)}})();return{shape:s,update:n,box:c}}),a=!1;for(let{shape:n,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(n.kind==="rect"||n.kind==="ellipse")n.x=c.cx-s.width/2,n.y=c.cy-s.height/2,n.width=s.width,n.height=s.height;else{let l=s.width/c.width,f=s.height/c.height;n.points=(n.points??[]).map(g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*f})),(n.x!=null||n.y!=null||n.width!=null||n.height!=null||n.role==="stage")&&(n.x=c.cx-s.width/2,n.y=c.cy-s.height/2,n.width=s.width,n.height=s.height)}a=!0}return{floorId:r.floorId,changed:a,shapes:i.map(({shape:n,update:s})=>({id:n.id,width:s.width,height:s.height}))}}function gc(t,e){let r=O(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let o=e.updates.map(s=>s.stageId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Stage ids must be unique");let i=new Set(qt.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let c=r.objects.find(l=>l.type==="shape"&&l.id===s.stageId);if(!c)throw new d("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(c.role!=="stage")throw new d("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:c,stageKind:s.stageKind,box:c.stageKind===s.stageKind?null:ho(c)}}),n=!1;for(let s of a)s.box&&(s.shape.points=Vt({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,n=!0);return{floorId:r.floorId,changed:n,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function mc(t){return[...Rt(t)].map(([e,r])=>({key:e,...r}))}function $r(t){if(!Array.isArray(t))return Rt(t);let e=new Map;for(let{key:r,target:o,evidence:i}of t)e.set(r,{target:o,evidence:i});return e}function Rt(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let r of G(t)){r.confidenceEvidence&&e.set(`floor:${r.id}`,{target:{scope:"floor",floorId:r.id},evidence:r.confidenceEvidence});for(let o of r.objects){let i=`floor:${r.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&e.set(i,{target:{scope:o.type,floorId:r.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&e.set(`${i}:segmented`,{target:{scope:"row",floorId:r.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&e.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:r.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return e}function Xe(t){return Array.isArray(t)?t.map(Xe):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[r])=>e.localeCompare(r)).map(([e,r])=>[e,Xe(r)]))}function Br(t,e){return JSON.stringify(Xe(t))===JSON.stringify(Xe(e))}function Ct(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function zr(t){return t?t.status==="retracted"?"retract":Ct(t)?"approve":"set":"clear"}function Ur(t,e){let r=$r(t),o=Rt(e),i=[...new Set([...r.keys(),...o.keys()])].sort(),a=[];for(let n of i){let s=r.get(n),c=o.get(n);if(s&&c&&Br(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:zr(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function wc(t,e){return Ur(t,e).some(r=>Ct(r.before)||Ct(r.after))}var Jr=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),qr=new Set(["generated","geometry-verified","configuration-verified"]),Vr=new Set(["none","comparable-build-reference","actual-build-checked"]),Hr=new Set(["clear","partial","obstructed"]);function xt(t){return t.toISOString().slice(0,10)}function Ot(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function pe(t,e,r){if(!Ot(t,e))throw new d("invalid_operation",`Confidence evidence ${r} is invalid`,{field:r});return t}function be(t,e,r){if(t!==void 0)return pe(t,e,r)}function Ye(t,e,r){let o=r?[O(t,r)]:G(t).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(n=>n.id===e);if(a)return{floorId:i.floorId,object:a}}throw new d("object_not_found",`Unknown chart object: ${e}`,{objectId:e,floorId:r})}function bo(t,e){let r=G(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return o}function _e(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return bo(t,e.floorId).confidenceEvidence;if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let o=Ye(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new d("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:e.objectId});return o.object.overrides?.find(i=>i.index===e.seatIndex)?.confidenceEvidence}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let r=Ye(t,e.objectId,e.floorId);if(e.scope==="row"&&r.object.type!=="row")throw new d("invalid_operation","Row evidence requires a row id",{objectId:e.objectId});if(e.scope==="section"&&r.object.type!=="section")throw new d("invalid_operation","Section evidence requires a section id",{objectId:e.objectId});if(r.object.type==="row"||r.object.type==="section")return r.object.confidenceEvidence;throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:r.object.type})}function We(t,e,r){if(e.scope==="venue")return r?t.confidenceEvidence=r:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=bo(t,e.floorId);return r?i.confidenceEvidence=r:delete i.confidenceEvidence,{floorId:i.id}}if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let i=Ye(t,e.objectId,e.floorId);return Yn(t,{floorId:i.floorId,seats:[{rowId:e.objectId,index:e.seatIndex}],patch:{confidenceEvidence:r??null}}),{floorId:i.floorId,objectId:e.objectId}}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let o=Ye(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:o.object.type});return r?o.object.confidenceEvidence=r:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function Xr(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!Ot(t.label,80)||!Ot(t.methodLabel,100))throw new d("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(t.totalRayCount)||t.totalRayCount<1||t.totalRayCount>1e3||!Number.isInteger(t.clearRayCount)||t.clearRayCount<0||t.clearRayCount>t.totalRayCount)throw new d("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!Hr.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(r=>pe(r,80,"occluder label"));return{label:t.label,methodLabel:t.methodLabel,totalRayCount:t.totalRayCount,clearRayCount:t.clearRayCount,classification:t.classification,...e?.length?{occluderLabels:e}:{}}}function Yr(t,e=new Date){if(t.schema!==void 0&&t.schema!=="seatlayer.seat-confidence/1")throw new d("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!Jr.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!qr.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let r=t.realityLevel??"none";if(!Vr.has(r))throw new d("invalid_operation","Confidence evidence reality level is invalid");if(t.evidenceKind==="synthetic-model"&&(t.modelLevel!=="generated"||r!=="none"))throw new d("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=be(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(g=>pe(g,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=be(t.assessedAt,40,"assessedAt")??xt(e),n=Date.parse(a);if(!Number.isFinite(n))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=be(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:xt(new Date(n+365*24*60*60*1e3))),c=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(c)||c<n||c>n+366*24*60*60*1e3))throw new d("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let l=be(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let f=be(t.sourceLabel,120,"sourceLabel");if(r!=="none"&&!f)throw new d("invalid_operation","Real-world evidence requires a buyer-safe source describing what was checked");if(r==="actual-build-checked"&&(t.modelLevel!=="configuration-verified"||!o))throw new d("invalid_operation","An actual-build check requires a configuration-verified model and an event configuration");return{schema:"seatlayer.seat-confidence/1",evidenceId:pe(t.evidenceId,120,"evidenceId"),modelVersion:pe(t.modelVersion,120,"modelVersion"),evidenceKind:t.evidenceKind,modelLevel:t.modelLevel,realityLevel:r,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...t.eventConfigurationVersion!==void 0?{eventConfigurationVersion:t.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...l?{approvedByRole:l}:{},...f?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:Xr(t.modeledTarget)}:{}}}function ye(t,e={}){return{changed:e.changed??!0,scope:t.scope,...t.objectId?{objectId:t.objectId}:{},...t.floorId?{floorId:t.floorId}:{},...t.seatIndex!==void 0?{seatIndex:t.seatIndex}:{},...e}}function Ic(t,e){let r=Yr(e.evidence,e.now),o=JSON.stringify(_e(t,e)??null),i=We(t,e,r),a=JSON.stringify(_e(t,e)??null);return ye(e,{changed:o!==a,...i,evidenceId:r.evidenceId,status:"draft"})}function vc(t,e){let r=_e(t,e);if(!r)return ye(e,{changed:!1});let o=We(t,e,void 0);return ye(e,{changed:!0,...o,evidenceId:r.evidenceId})}function Sc(t,e){let r=_e(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to approve",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")throw new d("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=pe(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=be(e.eventConfigurationId,100,"eventConfigurationId")??r.eventConfigurationId;if(r.modelLevel==="configuration-verified"&&!i)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=e.eventConfigurationVersion??r.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let n={...r,status:"approved",approvedByRole:o,assessedAt:xt(e.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete n.basisSha256;let s=e.basisSha256??t.confidenceBasisSha256;s&&(n.basisSha256=s);let c=JSON.stringify(r),l=We(t,e,n);return ye(e,{changed:c!==JSON.stringify(n),...l,evidenceId:n.evidenceId,status:"approved"})}function Cc(t,e){let r=_e(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to retract",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")return ye(e,{changed:!1,evidenceId:r.evidenceId,status:"retracted"});let o={...r,status:"retracted"};delete o.basisSha256;let i=We(t,e,o);return ye(e,{changed:!0,...i,evidenceId:r.evidenceId,status:"retracted"})}export{Mn as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,ai as DEFAULT_FLOOR_HEIGHT_STEP_M,po as DEFAULT_SECTION_CORNER_SMOOTHING,Wr as MAX_BUYER_IMAGE_URL_LENGTH,ii as MAX_FLOOR_BASE_HEIGHT_M,Ha as addArcFanRows,Ps as addBookableGridArray,rs as addBoothArray,Go as addChartCategory,si as addChartFloor,hi as addChartZone,ns as addGAArea,ts as addRowBlock,os as addTableArray,oa as applyPolygonHole,Rs as applyReferenceScanRows,ma as applySectionCornerSmoothing,Ca as applySectionEstimates,Mo as applySectionOutlineShaping,na as applySectionRowFit,Sc as approveConfidenceEvidence,or as arcFanInputForGroup,ha as assignSectionInventoryCategory,Ua as automaticPlacementCenter,vc as clearConfidenceEvidence,oi as compactChartDoc,ti as compactRowOverrides,ni as compactTableOverrides,wc as confidenceEvidenceChangeRequiresPublish,Ur as confidenceEvidenceChanges,mc as confidenceEvidenceIndex,Ea as confirmReferenceCategoryOutputColor,ba as convertGeneratedSectionToPolygon,ft as countCoveredInventory,ei as detectSeatLabelRun,Wt as dropRedundantSeatOverrideFields,qo as familyCategoryLabel,sr as gaAreaFootprint,Ln as groupRowsAsSegmented,Hi as insertSeatingBlock,Zr as isSafeBuyerImageUrl,oc as joinGAAreas,Js as mergeRows,De as mirrorFirstFloor,oe as normalizeBuyerImageUrl,Yr as normalizeDraftEvidence,Ds as parseSeatRefId,Do as pickColorblindSafeCategoryColor,Xo as planCreationCategory,En as previewArcFanRows,js as previewBookableGridArray,Po as previewGeneratedSectionPolygonConversion,nc as previewJoinGAAreas,ut as previewPolygonHole,_o as previewRemovePolygonHole,So as previewRowCubicPath,Oo as previewSectionRowFit,Ma as reassignColorblindSafeCategoryColors,Vi as relabelChartRows,Na as removeChartCategory,di as removeChartFloor,Ji as removeChartObjects,pi as removeChartZone,ra as removePolygonHole,ci as renameChartFloor,ka as renameDirectSeatImportCategory,Fa as reorderChartCategories,Xa as replaceArcFanRows,ss as replaceRowBlock,Gs as resetSeatOverrides,uc as resizeShapes,Ta as resolveCreationCategory,Cc as retractConfidenceEvidence,ri as roundBuyerCoordinates,Je as seatRefId,Qr as seatSemanticsSignature,jo as sectionInventorySelectionSummary,Ic as setConfidenceEvidence,Vs as setRowBlockSpacing,qs as splitRow,Hs as straightenAndSpaceRows,pa as transformSectionBoundary,ko as transformSectionBoundaryObject,is as ungroupSegmentedRow,zi as updateBooths,To as updateCategoryDefinitions,li as updateChartFloorBaseHeight,Ba as updateChartTheme,bi as updateChartZones,Ui as updateGAAreas,ta as updateRowCubicPath,Us as updateRows,Yn as updateSeatOverrides,ya as updateSectionExactPath,kn as updateSectionMetadata,as as updateSegmentedRow,fc as updateShapes,gc as updateStageKinds,Bi as updateTables,qi as updateTextObjects,za as updateViewFromSeatFallback};
|