@seatlayer/core 0.101.0 → 0.103.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.
Files changed (183) hide show
  1. package/dist/ar-D6ASWQBI.js +1 -0
  2. package/dist/be-T23MSCFC.js +1 -0
  3. package/dist/bg-2MMSY43I.js +1 -0
  4. package/dist/ca-EXRTYE33.js +1 -0
  5. package/dist/{categoryInventory-H77A_8pF.d.cts → categoryInventory-D_gpkfsq.d.cts} +1 -1
  6. package/dist/{categoryInventory-DZ5IcDOy.d.ts → categoryInventory-i-mGCBD3.d.ts} +1 -1
  7. package/dist/chunk-2STEWCI2.js +1 -0
  8. package/dist/chunk-33SRM2CP.js +1 -0
  9. package/dist/chunk-3W4ZMU4G.js +1 -0
  10. package/dist/chunk-76AUT55N.js +1 -0
  11. package/dist/chunk-B75VUM6L.js +1 -0
  12. package/dist/{chunk-L34T3APU.js → chunk-FAY7ARLB.js} +1 -1
  13. package/dist/{chunk-2RNZOV5I.js → chunk-GPZFVQXV.js} +1 -1
  14. package/dist/chunk-JRZHC75P.js +1 -0
  15. package/dist/chunk-KTMZ3QAO.js +1 -0
  16. package/dist/chunk-NWRHKTMV.js +1 -0
  17. package/dist/{chunk-5HXTEMRE.js → chunk-QG7ZFUNX.js} +1 -1
  18. package/dist/{chunk-GLGXP5I7.js → chunk-R2TRYVOY.js} +1 -1
  19. package/dist/chunk-RF4QU72N.js +1 -0
  20. package/dist/chunk-TFYAMLCK.js +1 -0
  21. package/dist/chunk-TZBJCAXH.js +1 -0
  22. package/dist/chunk-UEDS3HJ3.js +1 -0
  23. package/dist/chunk-UEYHH7Y5.js +1 -0
  24. package/dist/chunk-WH2EVBIG.js +1 -0
  25. package/dist/chunk-WKWXU5QM.js +1 -0
  26. package/dist/{chunk-P4J57TK6.js → chunk-YPVYZYMH.js} +1 -1
  27. package/dist/core/chart-ops/index.cjs +1 -1
  28. package/dist/core/chart-ops/index.d.cts +491 -18
  29. package/dist/core/chart-ops/index.d.ts +491 -18
  30. package/dist/core/chart-ops/index.js +1 -1
  31. package/dist/core/color.d.cts +1 -1
  32. package/dist/core/color.d.ts +1 -1
  33. package/dist/core/inventory/index.cjs +1 -1
  34. package/dist/core/inventory/index.d.cts +72 -5
  35. package/dist/core/inventory/index.d.ts +72 -5
  36. package/dist/core/inventory/index.js +1 -1
  37. package/dist/core/layout/index.cjs +1 -1
  38. package/dist/core/layout/index.d.cts +63 -6
  39. package/dist/core/layout/index.d.ts +63 -6
  40. package/dist/core/layout/index.js +1 -1
  41. package/dist/core/quality/index.cjs +1 -1
  42. package/dist/core/quality/index.d.cts +18 -4
  43. package/dist/core/quality/index.d.ts +18 -4
  44. package/dist/core/quality/index.js +1 -1
  45. package/dist/core/render-assets/index.cjs +1 -1
  46. package/dist/core/render-assets/index.d.cts +45 -5
  47. package/dist/core/render-assets/index.d.ts +45 -5
  48. package/dist/core/render-assets/index.js +1 -1
  49. package/dist/core/seatConfidence.d.cts +1 -1
  50. package/dist/core/seatConfidence.d.ts +1 -1
  51. package/dist/core/sections/index.cjs +1 -1
  52. package/dist/core/sections/index.d.cts +5 -5
  53. package/dist/core/sections/index.d.ts +5 -5
  54. package/dist/core/sections/index.js +1 -1
  55. package/dist/cs-L5EG7LLR.js +1 -0
  56. package/dist/cy-AB2Q6XHI.js +1 -0
  57. package/dist/da-EGJO7W4Q.js +1 -0
  58. package/dist/de-Q56NNVPD.js +1 -0
  59. package/dist/el-JW2YADAL.js +1 -0
  60. package/dist/es-N35HVHMD.js +1 -0
  61. package/dist/et-53UYPQR7.js +1 -0
  62. package/dist/{eventConfigurations-ClFqXQi9.d.cts → eventConfigurations-C0x_OtjQ.d.cts} +1 -1
  63. package/dist/{eventConfigurations-B6aS6c-_.d.ts → eventConfigurations-CDPqKz_8.d.ts} +1 -1
  64. package/dist/fa-JL3HW42Q.js +1 -0
  65. package/dist/fi-ZFWROLPU.js +1 -0
  66. package/dist/fr-6EKBGKIT.js +1 -0
  67. package/dist/he-KSOTIRJW.js +1 -0
  68. package/dist/hi-RWHSYCVV.js +1 -0
  69. package/dist/hr-ECH5LYKR.js +1 -0
  70. package/dist/hu-BAXHRRWC.js +1 -0
  71. package/dist/id-ECFNLK3G.js +1 -0
  72. package/dist/index.cjs +1 -1
  73. package/dist/index.d.cts +65 -17
  74. package/dist/index.d.ts +65 -17
  75. package/dist/index.js +1 -1
  76. package/dist/it-HT57FDFI.js +1 -0
  77. package/dist/ja-LHVHSM5J.js +1 -0
  78. package/dist/ko-G2HVHBKT.js +1 -0
  79. package/dist/ku-MNPV6BJJ.js +1 -0
  80. package/dist/{labeling-ByEZkLee.d.cts → labeling-20iLar-Q.d.ts} +11 -3
  81. package/dist/{labeling-CP3GhUrf.d.ts → labeling-DW_pEMgl.d.cts} +11 -3
  82. package/dist/localeLoaders-L36RHPNS.js +1 -0
  83. package/dist/lt-GB2GJDNS.js +1 -0
  84. package/dist/lv-3ZE6IM47.js +1 -0
  85. package/dist/ms-YH2PYOHG.js +1 -0
  86. package/dist/nl-D4FX7T7U.js +1 -0
  87. package/dist/no-5YNLYHN4.js +1 -0
  88. package/dist/pl-RUXCR6JV.js +1 -0
  89. package/dist/pt-TKFGIUL6.js +1 -0
  90. package/dist/{renderedQuality--H0toc-2.d.cts → renderedQuality-BIWwSRMS.d.cts} +1 -1
  91. package/dist/{renderedQuality-Bo4k99GE.d.ts → renderedQuality-CdpKQidA.d.ts} +1 -1
  92. package/dist/{renderer-BPhSZUGh.d.cts → renderer-BSjyHBDK.d.cts} +8 -1
  93. package/dist/{renderer-CWbam_zr.d.ts → renderer-BurPZ2Io.d.ts} +8 -1
  94. package/dist/ro-UFIOIOVH.js +1 -0
  95. package/dist/ru-VMRD53B7.js +1 -0
  96. package/dist/{seatTypeIcons-CSt1isBY.d.ts → seatTypeIcons-BlEzPXFf.d.cts} +2 -2
  97. package/dist/{seatTypeIcons-B2tvcQ0H.d.cts → seatTypeIcons-D_T5HfJs.d.ts} +2 -2
  98. package/dist/{sections-C_AKwOIh.d.cts → sections-BySKMsFE.d.ts} +5 -2
  99. package/dist/{sections-JHox6Lsw.d.ts → sections-DXUcW0ZT.d.cts} +5 -2
  100. package/dist/{segmentedRowModel-DQO0vHR1.d.ts → segmentedRowModel-C5qFY6jJ.d.ts} +1 -1
  101. package/dist/{segmentedRowModel-CZ0Ciea-.d.cts → segmentedRowModel-CyW-LFuI.d.cts} +1 -1
  102. package/dist/sk-XIK2KO3F.js +1 -0
  103. package/dist/sl-CDZGH6C6.js +1 -0
  104. package/dist/sr-A3TESNV3.js +1 -0
  105. package/dist/sv-HKGKDGSG.js +1 -0
  106. package/dist/{tableSizing-ClgbhNks.d.ts → tableSizing-Bos5ueqg.d.cts} +5 -4
  107. package/dist/{tableSizing-Cp5T_6Lw.d.cts → tableSizing-CAiE_oii.d.ts} +5 -4
  108. package/dist/th-ZPGRIY7D.js +1 -0
  109. package/dist/{ticketRestrictions-DUdzkp4F.d.ts → ticketRestrictions-DKdJWh9u.d.cts} +39 -3
  110. package/dist/{ticketRestrictions-BHNbxzFT.d.cts → ticketRestrictions-DRDtAVKw.d.ts} +39 -3
  111. package/dist/tr-IUB54G3R.js +1 -0
  112. package/dist/{types-5AlKCD4j.d.ts → types-ZviQR7ch.d.cts} +194 -9
  113. package/dist/{types-5AlKCD4j.d.cts → types-ZviQR7ch.d.ts} +194 -9
  114. package/dist/uk-JQKEV42K.js +1 -0
  115. package/dist/vi-KRM5S2Q7.js +1 -0
  116. package/dist/view3d/crossfade/panorama.d.cts +1 -1
  117. package/dist/view3d/crossfade/panorama.d.ts +1 -1
  118. package/dist/view3d/index.cjs +54 -54
  119. package/dist/view3d/index.d.cts +13 -3
  120. package/dist/view3d/index.d.ts +13 -3
  121. package/dist/view3d/index.js +44 -44
  122. package/dist/view3d/scene/scene.worker.cjs +1 -1
  123. package/dist/view3d/scene/scene.worker.js +1 -1
  124. package/dist/zh-Hans-FEUYIOYS.js +1 -0
  125. package/dist/zh-Hant-PK2XOE2G.js +1 -0
  126. package/package.json +1 -1
  127. package/dist/ar-Q44JP5JY.js +0 -1
  128. package/dist/be-CGFFSIQL.js +0 -1
  129. package/dist/bg-WOYK6OLH.js +0 -1
  130. package/dist/ca-77ZVI3X5.js +0 -1
  131. package/dist/chunk-52XO3LA7.js +0 -1
  132. package/dist/chunk-5BMXWOE7.js +0 -1
  133. package/dist/chunk-5ITK5236.js +0 -1
  134. package/dist/chunk-5N4H3KMR.js +0 -1
  135. package/dist/chunk-5PFYIYM5.js +0 -1
  136. package/dist/chunk-CTIGUXXK.js +0 -1
  137. package/dist/chunk-D723OZEY.js +0 -1
  138. package/dist/chunk-FLZKBXHA.js +0 -1
  139. package/dist/chunk-HO4MFTVX.js +0 -1
  140. package/dist/chunk-JK3DUFRX.js +0 -1
  141. package/dist/chunk-N4J4CT6P.js +0 -1
  142. package/dist/chunk-NO6OLVTT.js +0 -1
  143. package/dist/chunk-TQN2VWQO.js +0 -1
  144. package/dist/chunk-UISTXRO5.js +0 -1
  145. package/dist/cs-OSBZYCSR.js +0 -1
  146. package/dist/cy-ZCOJW2WH.js +0 -1
  147. package/dist/da-2PDK6JTR.js +0 -1
  148. package/dist/de-R5LLVFUU.js +0 -1
  149. package/dist/el-ZPFVDCWA.js +0 -1
  150. package/dist/es-7YASJP32.js +0 -1
  151. package/dist/et-J4TV6KQL.js +0 -1
  152. package/dist/fa-4TEO7UGM.js +0 -1
  153. package/dist/fi-GIUDDKMH.js +0 -1
  154. package/dist/fr-J5J2XJLA.js +0 -1
  155. package/dist/he-OCEHSVUJ.js +0 -1
  156. package/dist/hi-EK5CTBW5.js +0 -1
  157. package/dist/hr-SLDTQOYC.js +0 -1
  158. package/dist/hu-2QNE77NO.js +0 -1
  159. package/dist/id-LGDAFQJK.js +0 -1
  160. package/dist/it-DT4Y3IYB.js +0 -1
  161. package/dist/ja-D5EY2XCQ.js +0 -1
  162. package/dist/ko-DD2NV45Q.js +0 -1
  163. package/dist/ku-KZCMVLBE.js +0 -1
  164. package/dist/localeLoaders-GGAKX22E.js +0 -1
  165. package/dist/lt-QWGTJ47Y.js +0 -1
  166. package/dist/lv-LYAIG3VK.js +0 -1
  167. package/dist/ms-XTF4KNGD.js +0 -1
  168. package/dist/nl-QEXY6XHS.js +0 -1
  169. package/dist/no-HCOXN2CN.js +0 -1
  170. package/dist/pl-BWY53TSD.js +0 -1
  171. package/dist/pt-2UJUBCPL.js +0 -1
  172. package/dist/ro-GGXOLTED.js +0 -1
  173. package/dist/ru-ZTFK3WCU.js +0 -1
  174. package/dist/sk-KU543Y2U.js +0 -1
  175. package/dist/sl-FT576R7A.js +0 -1
  176. package/dist/sr-WE3J46JE.js +0 -1
  177. package/dist/sv-YEAOPSEB.js +0 -1
  178. package/dist/th-BEBRDHJA.js +0 -1
  179. package/dist/tr-LOAHUPSH.js +0 -1
  180. package/dist/uk-2GMICSHN.js +0 -1
  181. package/dist/vi-TC5B6AUR.js +0 -1
  182. package/dist/zh-Hans-TSZWTZQY.js +0 -1
  183. package/dist/zh-Hant-TLB4FZYM.js +0 -1
@@ -1 +1 @@
1
- import{a as it}from"../../chunk-5N4H3KMR.js";import{a as d,b as R,c as F,d as P,e as re,f as Fe,g as Qt,h as ke,i as se,j as T,k as ce,l as Me,m as Ee,n as rt,o as we,p as V,q as W,r as X,s as ie,t as Le,u as Lr,v as Tr,w as Nr,x as Dr,y as Kr,z as Gr}from"../../chunk-5HXTEMRE.js";import{a as je,b as Pe,f as Zt}from"../../chunk-JK3DUFRX.js";import{g as tt,h as nt}from"../../chunk-D723OZEY.js";import{a as xt,b as Ve,e as Ce,k as He}from"../../chunk-52XO3LA7.js";import{c as Ut}from"../../chunk-N4J4CT6P.js";import{k as me}from"../../chunk-4N5CHKHD.js";import{i as Ht,k as Xt,l as Yt,m as Wt,q as ot}from"../../chunk-TQN2VWQO.js";import{a as Oe,d as jr,e as Pr,f as Bt,g as Fr,h as kr,i as Mr,j as Er}from"../../chunk-5BMXWOE7.js";import{b as Ae,c as ne,e as Jt,f as qt,g as oe,h as Qe,n as ye}from"../../chunk-HO4MFTVX.js";import{Aa as $t,Ba as Z,Ea as Q,F as kt,Ia as Ze,J as _e,La as pe,Ma as D,Oa as M,P as Mt,Q as Ye,Qa as G,R as Et,S as Lt,Sa as H,T as Vn,Wa as zt,X as Tt,a as Or,b as Ar,c as te,e as Xe,q as Ct,r as Rt,ra as Dt,s as _t,t as Ot,u as At,v as jt,va as Kt,w as Re,x as Pt,y as Ft,za as Gt}from"../../chunk-UISTXRO5.js";import{e as Nt,h as We}from"../../chunk-5ITK5236.js";import{i as Vt,n as et}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function Ur(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:rt(t,e.label),color:T(e.color,"Zone color"),...e.focalPoint?{focalPoint:we(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function Jr(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=rt(a,c.patch.label,f.id)),c.patch.color!==void 0&&(f.color=T(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(f.focalPoint=we(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 qr(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,Le(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 Ie(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 Hn(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 en(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 Xn(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 tn=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[ae.balcony],sectionLabel:"Balcony",build:()=>[Ie("blk-b0","A",-45,18,24,"balcony",18),Ie("blk-b1","B",-15,20,24,"balcony",18),Ie("blk-b2","C",15,22,24,"balcony",18),Ie("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)=>Ie(`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:()=>[en("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)=>Hn(`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:()=>[en("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:()=>[Xn("blk-wc","A",4,40,"standard")]}];function B(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 nn(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 on(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=pe(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=Et(t.outlinePath,e,r)),t.holes&&(t.holes=pe(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 ci(t,e){let r=R(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=T(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 x=n.seatCountsBySide[I];if(!Number.isInteger(x)||x<0||x>40)throw new d("invalid_operation",`seatCountsBySide.${I} must be a whole number from 0 to 40`)}let v=b.reduce((I,x)=>I+n.seatCountsBySide[x],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=se(n,"Table"),g=ke(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=Ut(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(g&&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((x,C)=>x+p.seatCountsBySide[C],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(x=>p.seatCountsBySide[x]>0)}}else p.radius??=40;if((p.bookAsWhole||p.variableOccupancy)&&Ae(p.label))throw new d("invalid_operation",`Grouped table label "${p.label}" uses SeatLayer's reserved GA namespace`,{tableId:p.id});return p}),u=new Map(h.map(b=>[b.id,b])),m=new Set(o),y=new Map;for(let b of G(t))for(let p of b.objects){let v=p.type==="table"?u.get(p.id)??p:p,I=[];v.type==="row"?I=Q(v).map(x=>x.label):v.type==="table"?I=v.bookAsWhole||v.variableOccupancy?[v.label]:Ze(v).map(x=>x.label):v.type==="booth"?I=[v.label]:v.type==="gaArea"&&(I=oe(v));for(let x of I){let C=y.get(x);if(C&&(m.has(C)||m.has(v.id)))throw new d("invalid_operation",`Inventory label "${x}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:x,conflictingObjectIds:[C,v.id]});y.set(x,C??v.id)}}let w=!1,S=["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 x of S)x in v||delete p[x];Object.assign(p,v),JSON.stringify(p)!==I&&(w=!0)}return{floorId:r.floorId,changed:w,tableIds:o}}function li(t,e){let r=R(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(u=>r.objects.find(m=>m.type==="booth"&&m.id===u)),a=o.filter((u,m)=>!i[m]);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=(u,m,y,w)=>{if(m!==void 0&&(!Number.isFinite(m)||m<y||m>w))throw new d("invalid_operation",`${u} must be from ${y} to ${w}`)};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 u=Zt(n.points);if(!u.ok)throw new d("invalid_operation",u.message??"The booth outline is not a valid simple polygon")}let l=n.points!=null?n.points.map(u=>({x:u.x,y:u.y})):void 0;delete n.points;let f=se(n,"Booth"),g=ke(n,"Booth"),h=!1;for(let u of i){let m=JSON.stringify(u);Object.assign(u,n),f&&delete u.displayLabel,g&&delete u.displayType,c?delete u.points:l&&(u.points=l),JSON.stringify(u)!==m&&(h=!0)}return{floorId:r.floorId,changed:h,boothIds:o}}function di(t,e){let r=R(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(g=>g.type==="gaArea"&&g.id===f)),a=o.filter((f,g)=>!i[g]);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>ne))throw new d("invalid_operation",`capacity must be an integer from 1 to ${ne}`);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=se(n,"GA area"),c=ke(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&&Qe(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 g=JSON.stringify(f),h=n.capacity===void 0?f.inventorySegments:Qe(f,n.capacity);Object.assign(f,n),h!==void 0&&(f.inventorySegments=h),s&&delete f.displayLabel,c&&delete f.displayType,JSON.stringify(f)!==g&&(l=!0)}return{floorId:r.floorId,changed:l,gaAreaIds:o}}function at(t,e){if(e.length<3)return 0;let r=i=>D(i,e,void 0),o=0;for(let i of t)r(M(i))&&(i.type==="row"?o+=Q(i).length:i.type==="table"?o+=Ze(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=ie(i)));return o}function fi(t,e){let r=R(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 ui(t,e){let r=R(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=T(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=T(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(!Ht(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&&(Oe(l),c=!0)}return{floorId:r.floorId,changed:c,textIds:o}}function gi(t,e){let r=R(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=Nt(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=tn.find(l=>l.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=R(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),on(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=nn(f.label);g!=null&&(l=Math.max(l,g+1))}for(let f of n)f.label=B(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: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 Yn(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=kt(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 Wn(t,e){let r=R(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=Yn(e.path),a=Q(o),n=structuredClone(o);n.path=i.path,n.origin={...i.path.start};let s=Q(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 vi(t,e){let r=Wn(t,e);if(!r.changed)return r;let i=R(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 Zn(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=Zn(e,r);return o?{x:o[0],y:o[1]}:null}function rn(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function eo(t,e){let r=R(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"?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(u=>u.type==="row"&&D(M(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 y=2*Math.asin(u.seatSpacing/(2*m))/W,w=Q(u),S=Math.atan2(u.origin.x-n.x,u.origin.y-n.y)/W,p=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(rn(Math.atan2(w[1].x-n.x,w[1].y-n.y)/W-S))||1)*y*(u.seatCount-1);if(Math.abs(p)>320){l.push(u.id);continue}let v=-S,I=u.curve+(p-u.curve)*g,x=u.rotation+rn(v-u.rotation)*g,C={...u,curve:I,rotation:x},K=Q(C).map((N,$)=>Math.hypot(N.x-w[$].x,N.y-w[$].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:p,resultCurve:I,fromRotation:u.rotation,resultRotation:x,rmsMovement:Math.sqrt(K.reduce((N,$)=>N+$**2,0)/K.length),maxMovement:Math.max(...K)})}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 Si(t,e){let r=eo(t,e),o=R(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 sn(t,e,r,o){let i=V(t,e,r),a=V(t,e,o),n=V(r,o,t),s=V(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)=>sn(r,i,a,e[(n+1)%e.length]))})}function to(t){if(t.length<3||t.length>256||Math.abs(_e(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)&&sn(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Te(t,e,r){let o=R(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 st(t,e){let{target:r,object:o,outer:i}=Te(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!to(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!D(l,i,void 0)))throw new 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)||D(a[0],f,void 0)||D(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"&&D(M(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:at(r.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function xi(t,e){let r=st(t,e),{object:o}=Te(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 no(t,e){let{target:r,object:o}=Te(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"&&D(M(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:at(r.objects.filter(n=>n.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Ci(t,e){let r=no(t,e),{object:o}=Te(t,r.floorId,r.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...r,changed:!0}}function oo(t){let e=te(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function cn(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 ro(t,e){let r=R(t,e.floorId),o=cn(r.objects,e.sectionIds),i=ye(Fe(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 y of Pe(m).keys())c.add(y);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 y=n.get(m);return y?.type==="row"||y?.type==="table"||y?.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 Ei(t,e){F(t,e.categoryKey);let r=ro(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=R(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 ln(t,e){let r=R(t,e.floorId),o=cn(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=oo(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&&Me(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ce(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=T(a.color,"Section color"));let c=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,l=new Set(o.logicalSectionIds),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 y=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};a.height===null?(delete u.height,y("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,y("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,y("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),y=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!==y&&delete u.viewFromSeatMeta,a.labelStyle!==void 0){let w=Ee(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 io(t,e){let r=R(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"&&D(M(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 Li(t,e){let r=io(t,e),i=R(t,r.floorId).objects.find(a=>a.type==="section"&&a.id===r.sectionId);return delete i.geometry,{...r,changed:!0}}function ao(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=M(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=M(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=Lt(t.outlinePath,o,i,a)),t.holes&&(t.holes=pe(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 Ti(t,e){let r=R(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,...ao(o,e.transform)}}function Ni(t,e){let r=R(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(!Mt(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ye(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 so(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function Di(t,e){return co(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function co(t,e){let r=R(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||!so(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(b=>({...b})),u=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))),w=y?.some(b=>Math.abs(b)>.5)===!0,S=u>.5||w?Tt(h,{cornerSmoothing:u,...w?{edgeCurvature:y}:{}}):null;S?(c.sourceOutline=h,c.outlinePath=S,c.outline=Ye(S),u>.5?c.cornerSmoothing=u:delete c.cornerSmoothing,w?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)st(t,{floorId:r.floorId,objectId:c.id,points:c.holes[b],holeIndex:b});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 Bi(t,e,r={}){let o=!1;for(let i of e){let a=ln(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=R(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=R(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=we(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&&Le(t),{changed:o}}var lo=new Set(["companion","child","senior","student","membership","custom"]);function le(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&&!me(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&&!lo.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 y=g.applicability.seatLabels?.map(S=>S.normalize("NFKC").trim()),w=g.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(S=>!S||S.length>160)||new Set(y).size!==y.length)||w&&(!w.length||w.some(S=>!Ce.some(b=>b.key===S))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...y?{seatLabels:y}:{},...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 fo(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=le(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...r],categories:t.categories}}function Wi(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=le(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=le(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 fn=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function dn(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 uo(t,e){let r=dn(t),o=dn(e);return!r||!o?1/0:(r[0]-o[0])**2+(r[1]-o[1])**2+(r[2]-o[2])**2}var go=3600;function ho(t,e,r=fn){return r.find(i=>t.every(a=>uo(i,a)>=go))??r[e%r.length]}function Qi(t,e){let r=e?.palette??fn;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 fo(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=le(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 bo(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=le([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(n=>n.key===o),categories:a}}var po=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],yo={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function mo(t,e){let r=yo[t];return!r||!e.includes(r)?e:[r,...e.filter(o=>o!==r)]}var wo=26;function Io(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 vo(t,e,r){let o=n=>t.every(s=>{let c=Vt(n,s);return c==null||c>=wo}),i=n=>{let s=et(n,"#12151d"),c=et(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=Io(n,.62,s);if(o(c)&&i(c))return c}return r}function So(t,e){let r=je.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function xo(t){let e=new Map;for(let r of G(t))for(let o of r.objects){let i=je.find(n=>n.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let n of Pe(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 Co(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 Ro(t,e,r){let o=xo(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=je.find(l=>l.objectType===r),s=a?So(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:Co(t,s)}}function ta(t,e,r,o){let i=Ro(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 _o(t,r,a,i.label,o)}function _o(t,e,r,o,i){let a=i.palette??po,n=t.categories.map(f=>f.color),s=i.suggestColor?.(n.map(f=>f.toLowerCase()))??ho(n,t.categories.length),c=vo(n,mo(e,a),s),l=bo(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 Oo(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=Oo(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=le(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var Ao=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],jo=["seat","deck","shell","fascia"];function ca(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 Ao){let n=r[a];n===null?delete i[a]:n!==void 0&&(i[a]=T(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<tt||r.seatScale>nt)throw new d("invalid_operation",`Theme seatScale must be from ${tt} to ${nt}`);i.seatScale=r.seatScale}if(r.logoUrl===null)delete i.logoUrl;else if(r.logoUrl!==void 0){let a=te(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 jo){let c=r.venue3d[s];c===null?delete a[s]:c!==void 0&&(a[s]=T(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 la(t,e){let r=e.url===null?null:te(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 da(t,e){let r=Fe(t,e.floorId),o=zt(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 Ne(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=R(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 Po(t,e,r){let o=r*W;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function Fo(t,e,r,o){let i=Math.abs(o-r)*W,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 ko(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 De(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=Fo(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,y])=>n*Math.abs(l-c)*W*(y-m)),h=t.fit==="fixed-count"?ko(g,t.seatsPerRow):g.map(m=>Math.max(2,Math.round(m/t.seatPitch)+1)),u=t.seatLabelStart;f.forEach(([m,y],w)=>{let S=c+(l-c)*m,b=c+(l-c)*y;t.facing==="outward"&&([S,b]=[b,S]);let p=h[w];if(p>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let v=Math.abs(b-S)*W/(p-1),I=2*n*Math.sin(v/2),x={type:"row",id:r(i,w),label:B(t.rowLabelStart+i),origin:Po(t.center,n,S),rotation:-S,curve:b-S,seatCount:p,seatSpacing:I,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+=p})}return o}function un(t,e){let r=Ne(t,e),o=R(t,e.floorId),i=De(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=Ne(t,e),o=R(t,e.floorId),i=new Set,a=P(t,"fan",e.idFactory,i),n=De(r,a,()=>P(t,"r",e.idFactory,i)),s=un(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=P(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 Mo(t,e){let r=R(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=Ne(t,s),l=new Set(De(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 ba(t,e){Mo(t,{floorId:e.floorId,groupId:e.groupId});let r=Ne(t,e),o=R(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=De(r,e.groupId,(y,w)=>n.get(`${y}:${w}`)??P(t,"r",e.idFactory,s)),l=un(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 y=re(c);y&&(g={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]:[]]),u=Math.min(...o.objects.map((y,w)=>h.has(y.id)?w:1/0)),m=o.objects.filter(y=>!h.has(y.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(y=>y.id),sectionId:g?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function Eo(t){let e=new Set(H(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(B(r));)r+=1;let o=B(r);return e.add(o),r+=1,o}}function gn(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 va(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=R(t,e.floorId),a=new Set,n=Eo(t),s=it(e.rotation??0),c=e.curve??0,l=e.style,f=l?P(t,"rowblock",e.idFactory,a):void 0,g=l?gn({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*X),y:Math.sin(s*X)},u={x:-h.y,y:h.x},m=Array.from({length:e.rowCount},(S,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+u.x*b*r+h.x*p,y:e.origin.y+u.y*b*r+h.y*p},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&f&&g&&(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:g}),v});i.objects.push(...m);let y=null,w=e.sectionLabel?.trim();if(w){let S=re(m);if(S){let b={type:"section",id:P(t,"sec",e.idFactory,a),label:w,outline:S};i.objects.push(b),y=b.id}}return{floorId:i.floorId,rowIds:m.map(S=>S.id),sectionId:y,createdIds:[...m.map(S=>S.id),...y?[y]:[]]}}function hn(t,e){let r=new Set(H(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 Lo(t,e){let r=new Set(H(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 To=456;function No(t){let e=Math.sqrt(Math.max(1,t)*To);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function Sa(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=R(t,e.floorId),o=new Set,{width:i,height:a}=No(e.capacity),n=Lo(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 xa(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=R(t,e.floorId),a=new Set,n=hn(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 Ca(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=R(t,e.floorId),a=new Set,n=hn(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 bn(t,e){let r=R(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 Ra(t,e){let r=R(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 _a(t,e){let r=R(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 Oa(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=R(t,e.floorId),o=r.objects.filter(A=>A.type==="row"&&A.rowBlockGeneration?.groupId===e.groupId).sort((A,J)=>A.rowBlockGeneration.rowIndex-J.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((A,J)=>{let O=A.rowBlockGeneration;return O.kind!=="row-block-v1"||O.rowIndex!==J||O.signature!==i.signature||JSON.stringify(O)!==JSON.stringify({...i,rowIndex:J})}))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)?it(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=gn({style:n,origin:u,rotation:h,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:f,curve:g}),y={x:Math.cos(h*X),y:Math.sin(h*X)},w={x:-y.y,y:y.x},S=new Map(o.map(A=>[A.rowBlockGeneration.rowIndex,A])),b=new Set,p=new Set(r.objects.filter(A=>A.type==="row").filter(A=>!o.includes(A)).map(A=>A.label)),v=r.objects.filter(A=>A.type==="row").length,I=()=>{for(;p.has(B(v));)v+=1;let A=B(v);return p.add(A),v+=1,A},x=[],C=[];for(let A=0;A<s;A+=1){let J=n==="intertwined"&&A%2===1?f/2:0,O=S.get(A);O||(O={type:"row",id:P(t,"r",e.idFactory,b),label:I(),origin:{...u},rotation:h,curve:g,seatCount:c,seatSpacing:f,categoryKey:o[0].categoryKey},C.push(O.id)),O.origin={x:u.x+w.x*A*l+y.x*J,y:u.y+w.y*A*l+y.y*J},O.rotation=h,O.curve=g,O.seatCount=c,O.seatSpacing=f,delete O.path,delete O.arcFanGeneration,O.overrides&&(O.overrides=O.overrides.filter(U=>U.index<c),O.overrides.length||delete O.overrides),O.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(O)}let E=o.slice(s).map(A=>A.id),K=Math.min(...o.map(A=>r.objects.indexOf(A))),N=new Set(o.map(A=>A.id)),$=r.objects.filter(A=>!N.has(A.id));return $.splice(K,0,...x),r.objects.splice(0,r.objects.length,...$),{floorId:r.floorId,groupId:e.groupId,rowIds:x.map(A=>A.id),createdRowIds:C,removedRowIds:E,changed:a!==JSON.stringify(x)||C.length>0||E.length>0}}function pn(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 Do(t){let e=t.length,r=t.reduce((S,b)=>S+b.x,0)/e,o=t.reduce((S,b)=>S+b.y,0)/e,i=0,a=0,n=0,s=0,c=0,l=0,f=0;for(let S of t){let b=S.x-r,p=S.y-o;i+=b*b,a+=p*p,n+=b*p,s+=b*b*b,c+=p*p*p,l+=b*p*p,f+=p*b*b}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,y=(u*i-h*n)/g,w=Math.sqrt(m*m+y*y+(i+a)/e);return Number.isFinite(w)?{center:{x:m+r,y:y+o},radius:w}:null}function ve(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):pn(t),seatCount:i,ordered:t}}function Ko(t){if(t.length<3)return ve(t);let e=t[0],r=t[t.length-1],o=Math.hypot(r.x-e.x,r.y-e.y),i=pn(t);if(o<=0||i<=0)return ve(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 ve(t);let n=Do(t);if(!n||n.radius<=i/2)return ve(t);let s=h=>{let u=h[0],m=h[1],y=u.x-n.center.x,S=-(u.y-n.center.y),b=y;S*(m.x-u.x)+b*(m.y-u.y)<0&&(S=-S,b=-b);let p=Math.hypot(S,b)||1;S/=p,b/=p;let v=(n.center.x-u.x)*b+(n.center.y-u.y)*-S;return{tx:S,ty:b,centreSide:v}},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?ve(t):{origin:{...c[0]},rotation:Math.atan2(l.ty,l.tx)*180/Math.PI,curve:g,seatSpacing:i,seatCount:c.length,ordered:c}}function Ke(t,e){let r=Ko(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[...Ke(r.ordered.slice(0,n),e),...Ke(r.ordered.slice(n),e)]}function ct(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function lt(t,e){let r="";for(let o of t){if(r.length+o.length>e)break;r+=o}return r.trim()}function dt(t){return lt(ct(t),40)}function yn(t,e=39){return lt(ct(t),Math.max(1,e))}function de(t,e=80){return lt(ct(t),Math.max(1,e))}function mn(t){return de(t).toLocaleLowerCase("en")}function ft(t){return mn(t)}function wn(t){return new Map((t??[]).map(e=>[e.index,e]))}function Go(t){let e=wn(t.overrides),r=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||r.push(We(t,o,i))}return r}function $o(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=wn(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 zo(t){return t.type==="row"?[t.label,...Go(t)]:t.type==="table"?[t.label,...$o(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...oe(t)]:[]}function In(t,e){let r=new Set;for(let o of t)if(!e?.has(o.id))for(let i of zo(o)){let a=ft(i);a&&r.add(a)}return r}function Bo(t,e){if(!Number.isInteger(e)||e<1)return[];let r={label:t,seatCount:e},o=[ft(t)];for(let i=0;i<e;i+=1)o.push(ft(We(r,i)));return o.filter(Boolean)}function vn(t,e,r){let o=Bo(e,r);if(!o.length||o.some(i=>t.has(i)||Ae(i)))return!1;for(let i of o)t.add(i);return!0}var Uo=1e-6,Jo=160,qo=.001,Vo=1e-5;function fe(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>Jo)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 Sn(t){return typeof t=="string"&&yn(t)||void 0}function xn(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(ut(t.origin)&&ut(e.start)&&ut(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=qo+Math.max(1,i)*Vo;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<=Uo)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 ut(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var Ho=300;function Xo(t){let e=new Set(H(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(Boolean)),r=0,o=()=>{for(;e.has(B(r));)r+=1;let i=B(r);return r+=1,e.add(i),i};return i=>{let a=dt(i),n=0;return()=>{for(;a&&n<4096;n+=1){let s=`${a}-${B(n)}`;if(!e.has(s))return e.add(s),n+=1,s}return o()}}}function Yo(t){let e=In(H(t));return(r,o)=>{let i=de(r);for(let a=1;a<4096;a+=1){let n=a===1?"":` ${a}`,s=n?`${de(i,80-n.length)}${n}`:i;if(s&&vn(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function Wo(t){return{ordinaryFor:Xo(t),direct:Yo(t)}}function gt(t,e,r){return t.type==="row"&&t.referenceScan?.assetId===e&&(!r||t.referenceScan.sectionId===r)}function Cn(t,e,r){return t.type==="table"&&t.referenceScan?.assetId===e&&(!r||t.referenceScan.sectionId===r)}function Zo(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=fe(`${n.sourceGroupId}:${s}`),f=l&&fe(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=fe(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||!xn(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 Rn(t,e,r){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!gt(o,e,r)&&!Cn(o,e,r))}function Qo(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=Rn(e,r,n).filter(g=>D(M(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(Ho,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,y=Math.hypot(u,m),w=h>1&&y>0?y/(h-1):o>0?o:24;if(!Number.isFinite(w)||w<=0)continue;let S=y>0?Math.atan2(m,u)*180/Math.PI:0,b={x:g.start.x,y:g.start.y},p=0,v=w,I,x=g.seats?.length===h&&g.seats.every(O=>Number.isFinite(O.x)&&Number.isFinite(O.y))?g.seats:null;if(x&&g.table&&h>=3){let O=g.table.center,U=x.reduce((L,q)=>L+Math.hypot(q.x-O.x,q.y-O.y),0)/h,Y=x.map(L=>Math.atan2(L.y-O.y,L.x-O.x)).sort((L,q)=>L-q),ee=0,_=0;Y.forEach((L,q)=>{let St=q+1<Y.length?Y[q+1]:Y[0]+Math.PI*2;St-L>ee&&(ee=St-L,_=(q+1)%Y.length)});let j=ee>1.6*(Math.PI*2/h),z=j?(Math.PI*2-ee)*180/Math.PI:void 0;I={center:{...O},radius:Math.max(1,U-$t),...z!==void 0?{seatArc:z}:{}},S=j?(Y[_]-ee/2)*180/Math.PI:Y[0]*180/Math.PI,b={...O}}let C=[];if(x&&!I&&h>=3){C=Ke(x,U=>Z({origin:U.origin,rotation:U.rotation,curve:U.curve,seatCount:U.seatCount,seatSpacing:U.seatSpacing}));let O=C[0];b=O.origin,S=O.rotation,p=O.curve,v=O.seatSpacing}if(!Number.isFinite(v)||v<=0)continue;let E=t.sourceGroupId?fe(`${t.sourceGroupId}:${f}`):void 0,K=E&&fe(g.directSourceRowId)===E?E:void 0,N=K?Sn(g.directReviewedSuffix):void 0,$=t.sourceGroupId&&g.rowLabel?de(g.rowLabel):"",A=t.sourceGroupId&&g.rowDisplayLabel?de(g.rowDisplayLabel):"",J=!!t.sourceGroupId&&g.rowDisplayLabel==="";c.push({label:$?a($,h):i(),displayLabel:A||(J?"":String(f+1)),origin:b,rotation:S,curve:p,seatCount:C[0]?.seatCount??h,seatSpacing:v,...I?{table:I}:{},...x&&!I?{measured:!0}:{},...K?{directSourceRowId:K}:{},...N?{directReviewedSuffix:N}:{}});for(let O of C.slice(1))c.push({label:i(),displayLabel:String(f+1),origin:O.origin,rotation:O.rotation,curve:O.curve,seatCount:O.seatCount,seatSpacing:O.seatSpacing,measured:!0});l+=h}return{skip:null,rows:c,seats:l}}function qa(t,e,r){F(t,r.categoryKey);let o=R(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=Rn(o.objects,i,a.id).filter(p=>D(M(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=>gt(b,i,a?.id)),l=Zo(c,e,a?.id),f=[],g=o.objects.filter(b=>gt(b,i,a?.id)||Cn(b,i,a?.id)?(f.push(b.id),!1):!0);o.objects.splice(0,o.objects.length,...g);let h=[],u=[],m=[],y=new Set,w=0,S=Wo(t);for(let b of e.sections){if(a&&b.sectionId!==a.id)continue;let p=Qo(b,o.objects,i,e.seatPitch,S.ordinaryFor(b.name),S.direct,a?.id);if(p.skip){u.push(p.skip);continue}let v=[],I=[],x=0;for(let C of p.rows){let E={assetId:i,...b.sectionId?{sectionId:b.sectionId}:{}},K=n.get(b)??r.categoryKey;if(C.table){x+=1,v.push({type:"table",id:P(t,"t",r.idFactory,y),referenceScan:E,label:C.label,displayLabel:String(x),center:C.table.center,shape:"round",radius:C.table.radius,...C.table.seatArc!==void 0?{seatArc:C.table.seatArc}:{},rotation:C.rotation,seatCount:C.seatCount,categoryKey:K});continue}let N={type:"row",id:P(t,"r",r.idFactory,y),referenceScan:{...E,...C.directSourceRowId?{directSourceRowId:C.directSourceRowId}:{},...C.directReviewedSuffix?{directReviewedSuffix:C.directReviewedSuffix}:{}},label:C.label,...C.displayLabel!==void 0?{displayLabel:C.displayLabel}:{},origin:C.origin,rotation:C.rotation,curve:C.curve,seatCount:C.seatCount,seatSpacing:C.seatSpacing,categoryKey:K,...C.directSourceRowId&&l.has(C.directSourceRowId)?{overrides:structuredClone(l.get(C.directSourceRowId))}:{}};v.push(N),C.measured&&I.push(N)}if(o.objects.push(...v),I.length&&!b.sourceGroupId){let C=G(t).find(E=>E.id===o.floorId);er(t,I,C?.focalPoint??t.focalPoint,o.floorId,r.idFactory)}for(let C of v)m.push(C.id);h.push({sectionId:b.sectionId,name:b.name,seats:p.seats,rows:v.length}),w+=p.seats}return{floorId:o.floorId,assetId:i,createdRowIds:m,removedRowIds:f,totalSeats:w,perSection:h,skipped:u}}function er(t,e,r,o,i){let a=e.map(u=>Z(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 y=a[m],w=y.map((b,p)=>{let v=y[Math.max(0,p-1)],I=y[Math.min(y.length-1,p+1)],x=Math.hypot(I.x-v.x,I.y-v.y);return x<=0?Math.hypot(b.x-s.x,b.y-s.y):Math.abs((b.x-s.x)*(-(I.y-v.y)/x)+(b.y-s.y)*((I.x-v.x)/x))}).sort((b,p)=>b-p),S=y.reduce((b,p)=>b+p.x,0)/y.length;return{row:u,depth:w[Math.floor(w.length/2)],along:S}}).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 y=B(m);u.sort((w,S)=>{let b=Z(w),p=Z(S);return b.reduce((v,I)=>v+I.x,0)/b.length-p.reduce((v,I)=>v+I.x,0)/p.length});for(let w of u)w.displayLabel=y;u.length>=2&&u.length<=64&&bn(t,{floorId:o,rowIds:u.map(w=>w.id),boundaries:u.slice(1).map(()=>"break"),displayLabel:y,idFactory:i})})}function _n(t,e,r={}){let o=R(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(w=>(w.type==="table"||w.type==="booth")&&w.id===y)),n=i.filter((y,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(y=>y.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[y,w,S]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(w)||w<1||w>S)throw new d("invalid_operation",`${y} must be a whole number from 1 to ${S}`);for(let[y,w]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(w)||w<30||w>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,w)=>y+(w.type==="table"?w.seatCount:1),0),h=(t.floors?.length?t.floors.flatMap(y=>y.objects):t.objects).reduce((y,w)=>y+(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(y=>!!y.referenceInventorySource).length*(c-1)}}}function Xa(t,e,r={}){return _n(t,e,r).preview}function Ya(t,e,r={}){let{target:o,sources:i,preview:a}=_n(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 S=`-${w}`;return`${g.slice(0,Math.max(1,80-S.length))}${S}`},y=m(u);for(;s.has(y);)y=m(++u);return s.add(y),y},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=P(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 tr(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=T(e.color,"Seat label color")),r.size===void 0&&r.color===void 0?void 0:r}var nr=new Set(Ce.map(t=>t.key));function Ge(t){return`${t.rowId}:${t.index}`}function rs(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 or(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,me(t.glyph)||delete t.glyph;let r=Gt(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"&&Bt(e,t)}function rr(t){return Object.keys(t).every(e=>e==="index")}function On(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let o=R(t,e),i=[],a=new Set,n=new Map;for(let s of r){let c=Ge(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 An(t,e){let r=On(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&&!me(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=>!nr.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:Ge(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=te(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&&ce(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=tr(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}`),or(f,s),rr(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(Ge)}}function is(t,e){let r=On(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(Ge)}}function ls(t,e){let r=R(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:g,...h}=e.patch,u=f===void 0?{}:{displayLabel:f},m=se(u,"Row"),y=g===void 0?void 0:Qt(g,"Row");if(n!==void 0&&ce(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&&Me(h.labelPresentation,"Row");let w=b=>JSON.stringify({origin:b.origin,rotation:b.rotation,curve:b.curve,seatCount:b.seatCount,seatSpacing:b.seatSpacing,path:b.path??null}),S=!1;for(let b of i){let p=JSON.stringify(b),v=w(b),I=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?M(b):null;if(Object.assign(b,structuredClone(h)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(x=>x.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),I){let x=M(b);b.origin={x:b.origin.x+I.x-x.x,y:b.origin.y+I.y-x.y}}if(JSON.stringify(b)!==p&&(S=!0),w(b)!==v&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),n!==void 0){let x=JSON.stringify(b.labelPresentation??null),C=Ee(b.labelPresentation,n);C?b.labelPresentation=C:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==x&&(S=!0)}if(s!==void 0){let x=JSON.stringify(b.labelPresentation??null),C=b.labelPresentation?structuredClone(b.labelPresentation):{};C.positionPreset=s,C.visible=s!=="none",delete C.position,b.labelPresentation=C,JSON.stringify(b.labelPresentation??null)!==x&&(S=!0)}if(c!==void 0||l!==void 0){let x=JSON.stringify(b.labelPresentation??null),C=b.labelPresentation?structuredClone(b.labelPresentation):{};c===null?delete C.rotation:c!==void 0&&(C.rotation=c),l!==void 0&&(C.style=l),b.labelPresentation=C,JSON.stringify(b.labelPresentation??null)!==x&&(S=!0)}if(y!==void 0){let x=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==x&&(S=!0)}if(f!==void 0){let x=b.displayLabel;m?delete b.displayLabel:b.displayLabel=u.displayLabel,b.displayLabel!==x&&(S=!0)}}return{floorId:r.floorId,changed:S,rowIds:o}}var ir=3;function $e(t){return(t%360+360)%360}function ar(t){let e=t.rotation*X;return{x:Math.cos(e),y:Math.sin(e)}}function sr(t,e){let r=Math.abs($e(t-e));return r>180&&(r=360-r),r}function ue(t,e,r){return(t.x-e.x)*r.x+(t.y-e.y)*r.y}function jn(t){let e=0,r=0;for(let i of t){let a=2*i.rotation*X;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 cr(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 Pn(t,e){let r=jn(t),o={x:-r.y,y:r.x},i=M(t[0]),a=t.map(c=>({row:c,coord:ue(M(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&&(cr(c.row,o.x*f,o.y*f),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function lr(t,e){let r={x:-e.y,y:e.x},o=M(t[0]),i=t.map(n=>ue(M(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 dr(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=Z(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=$e(Math.atan2(a,i)/X)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function fr(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 ds(t,e){let r=R(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(x=>x.type==="row"&&x.id===I)),a=o.filter((I,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(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=>sr(I.rotation,c.rotation)>ir);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=ar(c),g={x:-f.y,y:f.x},h=Math.max(8,c.seatSpacing*.6),u=n.find(I=>Math.abs(ue(I.origin,c.origin,g))>h);if(u){let I=Math.round(Math.abs(ue(u.origin,c.origin,g)));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,u.id]})}let m=n.slice().sort((I,x)=>ue(I.origin,c.origin,f)-ue(x.origin,c.origin,f)),y=m.reduce((I,x)=>I+x.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 w=m[0],S=[],b=0;for(let I of m){if(I.overrides)for(let x of I.overrides)S.push({...structuredClone(x),index:x.index+b});b+=I.seatCount}w.seatCount=y,w.curve=0,delete w.path,S.length?w.overrides=S:delete w.overrides,delete w.arcFanGeneration,delete w.rowBlockGeneration;let p=m.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:w.id,removedRowIds:p,seatCount:y}}function fs(t,e){let r=R(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=Z(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:P(t,"r",e.idFactory,new Set),label:fr(r.objects,o.label),origin:{...n[a]},rotation:$e(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});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 us(t,e){let r=R(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=Pn(i,e.gap);return{floorId:r.floorId,changed:n,rowIds:o,gap:e.gap}}function gs(t,e){let r=R(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)dr(h);let l=jn(n),f=$e(Math.atan2(l.y,l.x)/X);for(let h of n)h.rotation=f;let g=lr(n,l);return Pn(n,g),{floorId:r.floorId,changed:s()!==c,rowIds:o,gap:g}}import ht from"polygon-clipping";var Fn=100,kn=512,bt=8192,Gn=64,Mn=1e7,k=1e-7;function $n(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function zn(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&$n(e[0],e[e.length-1]);)e.pop();return e}function Se(t,e,r){let o=V(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 Bn(t,e,r,o){let i=V(t,e,r),a=V(t,e,o),n=V(r,o,t),s=V(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&&Se(r,t,e)||Math.abs(a)<=k&&Se(o,t,e)||Math.abs(n)<=k&&Se(t,r,o)||Math.abs(s)<=k&&Se(e,r,o)}function ur(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)&&Bn(t[e],t[r],t[o],t[i]))return!0}}return!1}function En(t,e){return t.some((r,o)=>e.some((i,a)=>Bn(r,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function pt(t,e){return!e.some((r,o)=>Se(t,r,e[(o+1)%e.length]))&&D(t,e,void 0)}function Be(t,e,r){let o=zn(t);if(o.length<3||o.length>kn||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Mn||Math.abs(i.y)>Mn||$n(i,o[(a+1)%o.length]))||Math.abs(_e(o))<=k||ur(o))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${kn} finite vertices per ring.`,{gaAreaId:r,ring:e});return o}function gr(t){let e=Be(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>Gn)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=r.map(i=>Be(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=>pt(s,e))||En(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(En(a,o[s])||pt(a[0],o[s])||pt(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 ze(t){return t.map(e=>[e.x,e.y])}function Ln(t){return zn(t.map(([e,r])=>({x:e,y:r})))}function Tn(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 hr(t){return t.reduce((e,r)=>e+(Tn(r[0]??[])-r.slice(1).reduce((o,i)=>o+Tn(i),0)),0)}function yt(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(yt).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${yt(e[r])}`).join(",")}}`}function Nn(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 Dn(t){return yt({categoryKey:t.categoryKey,displayLabel:Nn(t,"displayLabel",80),displayType:Nn(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Kn(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 br(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function Un(t,e,r={}){let o=R(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>Fn)throw new d("invalid_operation",`Join Areas supports at most ${Fn} areas at once`);let a=i.map(_=>o.objects.find(j=>j.type==="gaArea"&&j.id===_)),n=i.filter((_,j)=>!a[j]);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=Dn(s[0]),l=s.find(_=>Dn(_)!==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=ye(t).objectToSection,g=f.get(s[0].id)??"__ungrouped__",h=s.find(_=>(f.get(_.id)??"__ungrouped__")!==g);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:[g,f.get(h.id)??"__ungrouped__"]});let u=s.reduce((_,j)=>{if(!Number.isInteger(j.capacity)||j.capacity<1||j.capacity>ne)throw new d("invalid_operation",`GA area ${j.id} has invalid capacity`,{gaAreaId:j.id});return _+j.capacity},0);if(u>ne)throw new d("invalid_operation",`Joined GA capacity would be ${u}, over the ${ne}-unit area limit`,{capacity:u});let m=H(t).reduce((_,j)=>_+ie(j),0),y=r.maxInventory??1e5;if(m>y)throw new d("invalid_operation",`Chart inventory exceeds the ${y}-unit publication limit`,{inventory:m});let w=s.map(gr),S=w.reduce((_,j)=>_+j.outer.length+j.holes.reduce((z,L)=>z+L.length,0),0);if(S>bt)throw new d("invalid_operation",`Join Areas supports at most ${bt} source vertices`,{vertexCount:S});let b;try{let _=w.map(L=>[ze(L.outer)]);if(b=ht.union(_[0],..._.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 j=w.flatMap(L=>L.holes.map(q=>[ze(q)]));j.length&&(b=ht.difference(b,...j));let z=w.findIndex(L=>{let q=[ze(L.outer),...L.holes.map(ze)];return hr(ht.intersection(q,b))<=k});if(z>=0)throw new d("invalid_operation",`GA area ${s[z].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:s[z].id})}catch(_){throw _ instanceof d?_:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:_ instanceof Error?_.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=Ln(b[0][0]),v=b[0].slice(1).map(Ln),I=p.length+v.reduce((_,j)=>_+j.length,0);if(v.length>Gn||I>bt)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:v.length,vertexCount:I});Be(p,"outline",s[0].id),v.forEach(_=>Be(_,"cutout",s[0].id));let x=new Map(o.objects.map((_,j)=>[_.id,j])),C=s.slice().sort((_,j)=>br(Kn(_,x.get(_.id)??Number.MAX_SAFE_INTEGER),Kn(j,x.get(j.id)??Number.MAX_SAFE_INTEGER))),E=C[0],K=structuredClone(t),N=R(K,o.floorId),$=N.objects.find(_=>_.type==="gaArea"&&_.id===E.id);$.points=structuredClone(p),v.length?$.holes=structuredClone(v):delete $.holes;let A=new Set(C.slice(1).map(_=>_.id));for(let _=N.objects.length-1;_>=0;_-=1)A.has(N.objects[_].id)&&N.objects.splice(_,1);let J=ye(K).objectToSection.get(E.id)??"__ungrouped__";if(J!==g)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:E.id,beforeSectionId:g,afterSectionId:J});let O=[],U=new Set;for(let _ of C){if(!Jt(_))throw new d("invalid_operation",`GA area ${_.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:_.id});let j=oe(_);if(j.length!==_.capacity||j.some(z=>U.has(z)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:_.id});j.forEach(z=>U.add(z)),O.push(...qt(_))}if(O.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let Y=new Set(s.map(_=>_.id));for(let _ of H(t).filter(j=>j.type==="gaArea"&&!Y.has(j.id))){let j=oe(_).find(z=>U.has(z));if(j)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:j,gaAreaId:_.id})}let ee=C.slice(1).map(_=>_.id);return{floorId:o.floorId,areaId:E.id,survivorLabel:E.label,removedAreaIds:ee,sourceAreaCount:C.length,capacity:u,inventorySegmentCount:O.length,outerVertexCount:p.length,holeCount:v.length,sectionId:g,points:p,...v.length?{holes:v}:{},segments:O}}function vs(t,e,r={}){let{segments:o,...i}=Un(t,e,r);return i}function Ss(t,e,r={}){let o=Un(t,e,r),i=R(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 Ps(t,e){let r=R(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<He||n.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${He} to ${72}`);if(n.labelStyle.color!==void 0&&n.labelStyle.color!==null&&(n.labelStyle.color=T(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&&!xt.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=T(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:T(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&&!Xt.includes(n.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(n.lineJoin!==void 0&&n.lineJoin!==null&&!Yt.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&&!Wt.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=>!ot(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,ot(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&&(Oe(l),c=!0)}return{floorId:r.floorId,changed:c,shapeIds:o}}function Jn(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 Fs(t,e){let r=R(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"?Jn(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),y=Math.max(...g);return{cx:(h+u)/2,cy:(m+y)/2,width:Math.max(1,u-h),height:Math.max(1,y-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 ks(t,e){let r=R(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(Dt.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:Jn(c)}}),n=!1;for(let s of a)s.box&&(s.shape.points=Kt({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 Ns(t){return[...vt(t)].map(([e,r])=>({key:e,...r}))}function yr(t){if(!Array.isArray(t))return vt(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 vt(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 Ue(t){return Array.isArray(t)?t.map(Ue):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[r])=>e.localeCompare(r)).map(([e,r])=>[e,Ue(r)]))}function mr(t,e){return JSON.stringify(Ue(t))===JSON.stringify(Ue(e))}function mt(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function wr(t){return t?t.status==="retracted"?"retract":mt(t)?"approve":"set":"clear"}function Ir(t,e){let r=yr(t),o=vt(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&&mr(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:wr(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function Ds(t,e){return Ir(t,e).some(r=>mt(r.before)||mt(r.after))}var vr=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Sr=new Set(["generated","geometry-verified","configuration-verified"]),xr=new Set(["none","comparable-build-reference","actual-build-checked"]),Cr=new Set(["clear","partial","obstructed"]);function wt(t){return t.toISOString().slice(0,10)}function It(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function he(t,e,r){if(!It(t,e))throw new d("invalid_operation",`Confidence evidence ${r} is invalid`,{field:r});return t}function ge(t,e,r){if(t!==void 0)return he(t,e,r)}function Je(t,e,r){let o=r?[R(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 qn(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 xe(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return qn(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=Je(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=Je(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 qe(t,e,r){if(e.scope==="venue")return r?t.confidenceEvidence=r:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=qn(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=Je(t,e.objectId,e.floorId);return An(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=Je(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 Rr(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!It(t.label,80)||!It(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(!Cr.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(r=>he(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 _r(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(!vr.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!Sr.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let r=t.realityLevel??"none";if(!xr.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=ge(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=>he(g,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=ge(t.assessedAt,40,"assessedAt")??wt(e),n=Date.parse(a);if(!Number.isFinite(n))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=ge(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:wt(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=ge(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let f=ge(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:he(t.evidenceId,120,"evidenceId"),modelVersion:he(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:Rr(t.modeledTarget)}:{}}}function be(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 Ks(t,e){let r=_r(e.evidence,e.now),o=JSON.stringify(xe(t,e)??null),i=qe(t,e,r),a=JSON.stringify(xe(t,e)??null);return be(e,{changed:o!==a,...i,evidenceId:r.evidenceId,status:"draft"})}function Gs(t,e){let r=xe(t,e);if(!r)return be(e,{changed:!1});let o=qe(t,e,void 0);return be(e,{changed:!0,...o,evidenceId:r.evidenceId})}function $s(t,e){let r=xe(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=he(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=ge(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:wt(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=qe(t,e,n);return be(e,{changed:c!==JSON.stringify(n),...l,evidenceId:n.evidenceId,status:"approved"})}function zs(t,e){let r=xe(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 be(e,{changed:!1,evidenceId:r.evidenceId,status:"retracted"});let o={...r,status:"retracted"};delete o.basisSha256;let i=qe(t,e,o);return be(e,{changed:!0,...i,evidenceId:r.evidenceId,status:"retracted"})}export{fn as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,Tr as DEFAULT_FLOOR_HEIGHT_STEP_M,Vn as DEFAULT_SECTION_CORNER_SMOOTHING,Or as MAX_BUYER_IMAGE_URL_LENGTH,Lr as MAX_FLOOR_BASE_HEIGHT_M,ha as addArcFanRows,Ya as addBookableGridArray,Ca as addBoothArray,bo as addChartCategory,Nr as addChartFloor,Ur as addChartZone,Sa as addGAArea,va as addRowBlock,xa as addTableArray,xi as applyPolygonHole,qa as applyReferenceScanRows,Di as applySectionCornerSmoothing,Bi as applySectionEstimates,co as applySectionOutlineShaping,Si as applySectionRowFit,$s as approveConfidenceEvidence,Mo as arcFanInputForGroup,Ei as assignSectionInventoryCategory,da as automaticPlacementCenter,Gs as clearConfidenceEvidence,Mr as compactChartDoc,Fr as compactRowOverrides,kr as compactTableOverrides,Ds as confidenceEvidenceChangeRequiresPublish,Ir as confidenceEvidenceChanges,Ns as confidenceEvidenceIndex,ea as confirmReferenceCategoryOutputColor,Li as convertGeneratedSectionToPolygon,at as countCoveredInventory,Pr as detectSeatLabelRun,Bt as dropRedundantSeatOverrideFields,So as familyCategoryLabel,No as gaAreaFootprint,bn as groupRowsAsSegmented,hi as insertSeatingBlock,Ar as isSafeBuyerImageUrl,Ss as joinGAAreas,ds as mergeRows,Le as mirrorFirstFloor,te as normalizeBuyerImageUrl,_r as normalizeDraftEvidence,rs as parseSeatRefId,ho as pickColorblindSafeCategoryColor,Ro as planCreationCategory,un as previewArcFanRows,Xa as previewBookableGridArray,io as previewGeneratedSectionPolygonConversion,vs as previewJoinGAAreas,st as previewPolygonHole,no as previewRemovePolygonHole,Wn as previewRowCubicPath,eo as previewSectionRowFit,Qi as reassignColorblindSafeCategoryColors,gi as relabelChartRows,na as removeChartCategory,Gr as removeChartFloor,fi as removeChartObjects,qr as removeChartZone,Ci as removePolygonHole,Dr as renameChartFloor,Wi as renameDirectSeatImportCategory,Zi as reorderChartCategories,ba as replaceArcFanRows,Oa as replaceRowBlock,is as resetSeatOverrides,Fs as resizeShapes,ta as resolveCreationCategory,zs as retractConfidenceEvidence,Er as roundBuyerCoordinates,Ge as seatRefId,jr as seatSemanticsSignature,ro as sectionInventorySelectionSummary,Ks as setConfidenceEvidence,us as setRowBlockSpacing,fs as splitRow,gs as straightenAndSpaceRows,Ti as transformSectionBoundary,ao as transformSectionBoundaryObject,Ra as ungroupSegmentedRow,li as updateBooths,fo as updateCategoryDefinitions,Kr as updateChartFloorBaseHeight,ca as updateChartTheme,Jr as updateChartZones,di as updateGAAreas,vi as updateRowCubicPath,ls as updateRows,An as updateSeatOverrides,Ni as updateSectionExactPath,ln as updateSectionMetadata,_a as updateSegmentedRow,Ps as updateShapes,ks as updateStageKinds,ci as updateTables,ui as updateTextObjects,la as updateViewFromSeatFallback};
1
+ import{a as Lt,b as ie}from"../../chunk-TZBJCAXH.js";import{a as d,b as O,c as T,d as M,e as ce,f as ne,g as po,h as Ye,i as me,j as D,k as re,l as Ze,m as be,n as Dt,o as Fe,p as X,q as oe,r as ee,s as le,t as Qe,u as _s,v as As,w as Ps,x as ks,y as Ms,z as Fs}from"../../chunk-QG7ZFUNX.js";import{a as Me,b as We}from"../../chunk-76AUT55N.js";import{g as Pt,h as kt,j as uo,k as fo,l as ho,m as ge,n as go,o as mo,p as Tt,q as Et,r as bo}from"../../chunk-B75VUM6L.js";import{c as qn,d as no,h as oo,i as ro}from"../../chunk-RF4QU72N.js";import{k as ke}from"../../chunk-4N5CHKHD.js";import{a as Mt,b as Ft,n as io,p as ao,r as so,s as co,t as lo,x as jt}from"../../chunk-33SRM2CP.js";import{a as _e,c as zn,d as Ss,e as vs,f as Un,g as xs,h as Cs,i as Os,j as Rs,l as Jn}from"../../chunk-TFYAMLCK.js";import{A as to,k as Qn,s as eo}from"../../chunk-JRZHC75P.js";import{a as un,b as It,e as qe,k as St,n as fn}from"../../chunk-UEDS3HJ3.js";import{b as he,c as J,e as Hn,f as Vn,g as Rt,h as Xn,i as Ae,k as te,o as _t,v as Pe}from"../../chunk-WH2EVBIG.js";import{$ as _n,$a as Bn,A as Sn,Aa as En,Ea as Dn,Fa as Ln,G as vn,Ga as Nn,Ia as Gn,K as Ve,Ka as Kn,La as $n,Ma as W,Pa as Y,Q as xn,R as xt,S as Cn,T as Xe,Ta as Re,U as On,V as Xr,Xa as Z,Ya as $,Z as Rn,_a as G,a as ws,aa as Ct,ab as F,b as Is,c as se,ca as An,cb as V,da as Pn,e as vt,ea as kn,gb as Q,ka as Tn,q as hn,r as gn,s as mn,t as bn,u as pn,v as yn,w as He,x as wn,y as In}from"../../chunk-3W4ZMU4G.js";import{e as Mn,h as Ot,p as Fn,q as jn}from"../../chunk-KTMZ3QAO.js";import{G as Zn,i as Wn,m as Yn,n as At}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function Ds(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let n={id:M(t,"zone",e.idFactory,new Set),label:Dt(t,e.label),color:D(e.color,"Zone color"),...e.focalPoint?{focalPoint:Fe(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function Ls(t,e){if(!e.updates.length)throw new d("invalid_operation","At least one zone update is required");let n=e.updates.map(c=>c.zoneId);if(new Set(n).size!==n.length)throw new d("invalid_operation","Zone ids must be unique");let o=new Map((t.zones??[]).map(c=>[c.id,c])),i=n.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),r=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 u=r.get(c.zoneId);c.patch.label!==void 0&&(u.label=Dt(a,c.patch.label,u.id)),c.patch.color!==void 0&&(u.color=D(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(u.focalPoint=Fe(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:n,zones:n.map(c=>structuredClone(r.get(c)))}}function Ns(t,e){let n=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(n<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let o=F(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(n,1),t.zones.length||delete t.zones,Qe(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var de={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 je(t,e,n,o,i,a,r=0){return{type:"row",id:t,label:e,origin:{x:-(o-1)*i/2,y:n},rotation:0,curve:r,seatCount:o,seatSpacing:i,categoryKey:a}}function Wr(t,e,n,o,i,a){return{type:"table",id:t,label:e,center:n,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function yo(t,e,n,o,i,a){let r=n/2,s=o/2;return{type:"gaArea",id:t,label:e,points:[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}],capacity:i,categoryKey:a}}function Yr(t,e,n,o,i){let a=n*2,r=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];r.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:r}}var wo=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[de.balcony],sectionLabel:"Balcony",build:()=>[je("blk-b0","A",-45,18,24,"balcony",18),je("blk-b1","B",-15,20,24,"balcony",18),je("blk-b2","C",15,22,24,"balcony",18),je("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[de.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>je(`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:[de.standard],build:()=>[yo("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[de.premium],build:()=>Array.from({length:6},(t,e)=>Wr(`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:[de.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:[de.standard],build:()=>[yo("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:[de.standard],build:()=>[Yr("blk-wc","A",4,40,"standard")]}];function L(t){let e="",n=t;do e=String.fromCharCode(65+n%26)+e,n=Math.floor(n/26)-1;while(n>=0);return e}function et(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let n of t)e=e*26+(n.charCodeAt(0)-64);return e-1}function pe(t,e,n){let o=i=>({x:i.x+e,y:i.y+n});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=Z(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=Cn(t.outlinePath,e,n)),t.holes&&(t.holes=Z(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.holes&&(t.holes=Z(t.holes).map(i=>i.map(o))),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=n);break;case"decorImage":t.x+=e,t.y+=n;break}}function tt(t,e,n){return n?Sn(t,e,n):{x:t.x,y:t.y}}function Zr(t,e,n){let o=i=>tt(i,e,n);t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=Xe(t.outlinePath,o,1,!1)),t.holes&&(t.holes=Z(t.holes).map(i=>i.map(o)))}function Qr(t,e,n){let o=t.rotation??0;if(t.points?.length){let i={x:t.points.reduce((s,c)=>s+c.x,0)/t.points.length,y:t.points.reduce((s,c)=>s+c.y,0)/t.points.length},a=tt(i,e,n),r=s=>({x:s.x+a.x-i.x,y:s.y+a.y-i.y});t.points=t.points.map(r),t.holes&&(t.holes=Z(t.holes).map(s=>s.map(r)))}else if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){let i={x:t.x+t.width/2,y:t.y+t.height/2},a=tt(i,e,n);t.x+=a.x-i.x,t.y+=a.y-i.y}t.rotation=ie("shape",o+n)}function Io(t,e,n){if(!Number.isFinite(n)||!Number.isFinite(e.x)||!Number.isFinite(e.y))throw new RangeError("group_rotation_must_be_finite");if(n===0)return;let o=i=>tt(i,e,n);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)}),t.rotation=ie("row",t.rotation+n);break;case"table":case"booth":t.center=o(t.center),t.rotation=ie(t.type,t.rotation+n);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=Z(t.holes).map(i=>i.map(o)));break;case"section":Zr(t,e,n);break;case"shape":Qr(t,e,n);break;case"text":t.position=o(t.position),t.rotation=ie("text",t.rotation+n);break;case"decorImage":{let i={x:t.x+t.width/2,y:t.y+t.height/2},a=o(i);t.x+=a.x-i.x,t.y+=a.y-i.y,t.rotation=ie("decorImage",(t.rotation??0)+n);break}}}var ei=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","wheelchairPlaces"],So=(t,e,n)=>Number.isInteger(t)&&t>=e&&t<=n;function vo(t){let e={};for(let n of ei){if(!(n in t))continue;let o=t[n];delete t[n],o!==void 0&&(e[n]=o)}for(let n of["bookAsWhole","variableOccupancy"])if(e[n]!==void 0&&typeof e[n]!="boolean")throw new d("invalid_operation",`${n} 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 n of["minOccupancy","maxOccupancy"])if(e[n]!==void 0&&!So(e[n],1,J))throw new d("invalid_operation",`${n} must be a whole number from 1 to ${J}`);if(e.wheelchairPlaces!==void 0&&!So(e.wheelchairPlaces,0,J))throw new d("invalid_operation",`wheelchairPlaces must be a whole number from 0 to ${J}`);return e}function xo(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 n=Ae(t);if(n&&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(n&&t.capacity>Rt)throw new d("invalid_operation",Xn,{gaAreaId:t.id,capacity:t.capacity,max:Rt});if(n&&he(t.label))throw new d("invalid_operation",`Area label "${t.label}" uses SeatLayer's reserved GA namespace`,{gaAreaId:t.id});if(n==="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 Co(t,e){let n=e.filter(a=>Ae(a));if(!n.length)return;let o=new Map(e.map(a=>[a.id,a])),i=new Map(n.map(a=>[a.label,a.id]));for(let a of F(t))for(let r of a.objects){let s=r.type==="gaArea"?o.get(r.id)??r:r,c=[];s.type==="row"?c=Y(s).map(l=>l.label):s.type==="table"?c=s.bookAsWhole||s.variableOccupancy?[s.label]:Re(s).map(l=>l.label):s.type==="booth"?c=[s.label]:s.type==="gaArea"&&(c=te(s));for(let l of c){let u=i.get(l);if(u&&u!==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:u,inventoryLabel:l,conflictingObjectId:s.id})}}}var Oo=40,Ro=160;function ti(t,e){let n=t.normalize("NFKC").trim();if(n.length>Oo)throw new d("invalid_operation",`${e} entrance must be at most ${Oo} characters`);return n}function nt(t,e){let n={};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(re(o,e),o.visible!==void 0&&typeof o.visible!="boolean")throw new d("invalid_operation",`${e} name visibility must be true or false`);n.labelStyle=o}}if("entrance"in t){let o=t.entrance;if(delete t.entrance,o===null)n.entrance=null;else if(o!==void 0){if(typeof o!="string")throw new d("invalid_operation",`${e} entrance must be text`);n.entrance=ti(o,e)||null}}return n}function ot(t,e){if(e.labelStyle){let o=be(t.labelPresentation,e.labelStyle);o?.visible===!0&&delete o.visible,o&&Object.keys(o).length?t.labelPresentation=o:delete t.labelPresentation}let n=t.entrance;e.entrance===null?delete t.entrance:e.entrance!==void 0&&(t.entrance=e.entrance),t.entrance!==n&&delete t.entranceGateId}function _o(t){if(!("chairNumbering"in t))return;let e=t.chairNumbering;if(delete t.chairNumbering,e===null)return null;let n=Fn(e);if(n)throw new d("invalid_operation",n);return e}function Ao(t,e){if(e===void 0)return;let n=e===null?void 0:jn({...t.chairNumbering,...e});n?t.chairNumbering=n:delete t.chairNumbering}function Po(t){let e={};if("boothType"in t){let n=t.boothType;if(delete t.boothType,n===null)e.boothType=null;else if(n!==void 0){if(!fn.includes(n))throw new d("invalid_operation","boothType must be inline, corner, peninsula or island");e.boothType=n}}if("commercial"in t){let n=t.commercial;if(delete t.commercial,n===null)e.note=null;else if(n!==void 0){let o=Object.keys(n).filter(i=>i!=="note");if(o.length)throw new d("invalid_operation",`Booth commercial supports only a note (got ${o.join(", ")})`);if(n.note===null)e.note=null;else if(n.note!==void 0){if(typeof n.note!="string")throw new d("invalid_operation","Booth note must be text");let i=n.note.normalize("NFKC").trim();if(i.length>Ro)throw new d("invalid_operation",`Booth note supports at most ${Ro} characters`);e.note=i||null}}}return e}function ko(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})}var ni=[{role:"bar",label:"Bar",icon:"\u{1F378}",kind:"rect",width:160,height:44,fill:"#3a2f4a",blurb:"Drinks counter.",heightM:1.1},{role:"entrance",label:"Entrance",icon:"\u21E5",kind:"rect",width:90,height:30,fill:"#26433a",blurb:"Way in.",heightM:2.7},{role:"exit",label:"Exit",icon:"\u21E4",kind:"rect",width:90,height:30,fill:"#4a2f2f",blurb:"Emergency / way out.",heightM:2.7},{role:"restroom",label:"Restrooms",icon:"\u{1F6BB}",kind:"rect",width:90,height:60,fill:"#2b3550",blurb:"Toilets.",heightM:2.4},{role:"screen",label:"Screen",icon:"\u{1F4FD}\uFE0F",kind:"rect",width:320,height:18,fill:"#203454",blurb:"Projection surface.",heightM:6},{role:"sound",label:"Sound booth",icon:"\u{1F39B}\uFE0F",kind:"rect",width:70,height:50,fill:"#2b2b3a",blurb:"FOH / mixing desk.",heightM:1.45},{role:"concession",label:"Concession",icon:"\u{1F37F}",kind:"rect",width:120,height:44,fill:"#4a3f26",blurb:"Food stand.",heightM:1.1},{role:"coat",label:"Coat check",icon:"\u{1F9E5}",kind:"rect",width:90,height:40,fill:"#2f3a4a",blurb:"Cloakroom.",heightM:1.1},{role:"wall",label:"Wall",icon:"",kind:"rect",width:220,height:14,fill:"#1b2233",blurb:"Structural divider.",heightM:2.8},{role:"rail",label:"Safety rail",icon:"",kind:"rect",width:220,height:7,fill:"#5b6472",blurb:"Guardrail along a tier or balcony edge.",heightM:1.1},{role:"suite",label:"Suite",icon:"\u25C7",kind:"rect",width:180,height:90,fill:"#31394a",blurb:"Open-front hospitality suite.",heightM:3},{role:"obstruction",label:"Obstruction",icon:"\u25CF",kind:"ellipse",width:28,height:28,fill:"#343943",blurb:"Pillar or sightline obstruction.",heightM:4.5}],Mo=new Map(ni.map(t=>[t.role,t]));function Te(t){return Mo.get(t)}function Fo(t,e,n){let o=Mo.get(t);if(!o)throw new Error(`unknown d\xE9cor role: ${t}`);let i=o.icon?`${o.icon} ${o.label}`:o.label;return{type:"shape",id:n,kind:o.kind,x:e.x-o.width/2,y:e.y-o.height/2,width:o.width,height:o.height,fill:o.fill,label:o.role==="wall"?void 0:i,role:t,...o.heightM!==void 0?{heightM:o.heightM}:{}}}var Do={color:Ft.accessibility,width:4},Lo="Step-free route";function rt(t,e,n){if(typeof t!="string")throw new d("invalid_operation",`${n} must be text`);let o=t.normalize("NFKC").trim();if(!o)throw new d("invalid_operation",`${n} cannot be empty`);if(o.length>e)throw new d("invalid_operation",`${n} must be at most ${e} characters`);return o}function ri(t){if(!uo.includes(t))throw new d("invalid_operation","Gate use must be in, out or both")}function Gt(t,e){if(typeof t!="boolean")throw new d("invalid_operation",`${e} must be true or false`)}function Ee(t){return F(t).flatMap(e=>e.objects)}function No(t,e){let n=mo(t).get(e);if(!n)throw new d("object_not_found",`Unknown gate id: ${e}. Call get_chart to list gate ids.`,{gateId:e});return n}function Go(t){let e=t.height??40,n=bo(t.label??"",e,t.gate?.stepFree===!0),o=(t.x??0)+(t.width??n)/2;t.x=o-n/2,t.width=n,t.kind==="rect"&&(t.cornerRadius=e/2)}function Ko(t,e){t.type!=="row"&&(e?t.entrance=e:delete t.entrance)}var jo=t=>t.type==="row"?void 0:t.entrance;function ii(t,e){let n=Tt(e),o=[];for(let i of Ee(t))!ge(i)||i.entranceGateId!==e.id||(Ko(i,n),o.push(i.id));return o}function Kt(t,e,n){n.name!==void 0&&(t.label=rt(n.name,40,"Gate name")),n.use!==void 0&&(ri(n.use),e.use=n.use),n.stepFree!==void 0&&(Gt(n.stepFree,"Step-free"),n.stepFree?e.stepFree=!0:delete e.stepFree),n.opens!==void 0&&(n.opens===null||typeof n.opens=="string"&&!n.opens.trim()?delete e.opens:e.opens=rt(n.opens,40,"Opening time")),n.hideFromBuyers!==void 0&&(Gt(n.hideFromBuyers,"Hide from buyers"),n.hideFromBuyers?e.hideFromBuyers=!0:delete e.hideFromBuyers),t.gate=e,t.role=go(e.use)}function ai(t,e,n,o=0){let i={type:"shape",id:t,kind:"rect",x:e.x,y:e.y-40/2,width:0,height:40,fill:Ft.navigation,...o?{rotation:o}:{},heightM:Te("entrance")?.heightM??2.7};return Kt(i,{use:"in"},n),Go(i),i}function lc(t,e){let n=O(t,e.floorId);if(!Number.isFinite(e.center?.x)||!Number.isFinite(e.center?.y))throw new d("invalid_operation","A gate needs a finite centre point");if(e.rotation!==void 0&&(!Number.isFinite(e.rotation)||e.rotation<0||e.rotation>360))throw new d("invalid_operation","Gate rotation must be from 0 to 360");let o=M(t,"gate",e.idFactory,new Set),i=ai(o,e.center,{...e,name:e.name??Et(t)},e.rotation??0);return n.objects.push(i),{changed:!0,floorId:n.floorId,gate:structuredClone(i)}}function dc(t,e){let n=No(t,e.gateId);if(!Object.keys(e.patch).length)throw new d("invalid_operation","At least one gate change is required");let o=JSON.stringify(n),i=structuredClone(n);Kt(i,i.gate,e.patch),(e.patch.name!==void 0||e.patch.stepFree!==void 0)&&Go(i);let a=JSON.stringify(i)!==o;a&&Object.assign(n,i);let r=ii(t,n);return{changed:a,gate:structuredClone(n),servedObjectIds:r}}function uc(t,e){let n=Ee(t).find(a=>a.id===e.shapeId);if(!n)throw new d("object_not_found",`Unknown shape id: ${e.shapeId}`,{shapeId:e.shapeId});if(n.type!=="shape"||!ho(n))throw new d("invalid_operation","Only an Entrance or Exit landmark can become a gate");let o=n.label?.replace(/^[^\p{L}\p{N}]+/u,"").trim(),i=!o||/^(entrance|exit)$/i.test(o);return Kt(n,{use:n.role==="exit"?"out":"in"},{...e,name:e.name??(i?Et(t):o.slice(0,40))}),{changed:!0,gate:structuredClone(n)}}function fc(t,e){if(!e.objectIds.length)throw new d("invalid_operation","At least one object id is required");let n=Ee(t),o=new Map(n.map(f=>[f.id,f])),i=e.objectIds.filter(f=>!o.has(f));if(i.length)throw new d("object_not_found",`Unknown object id(s): ${i.join(", ")}`,{objectIds:i});let a=e.objectIds.filter(f=>!ge(o.get(f)));if(a.length)throw new d("invalid_operation","Only sections, rows, tables, booths and standing areas have an entrance",{objectIds:a});let r=e.gateId===null?null:No(t,e.gateId),s=new Set(e.objectIds.flatMap(f=>{let g=o.get(f);return g.type==="section"?[g.logicalSectionId??g.id]:[]})),c=n.filter(f=>ge(f)&&(e.objectIds.includes(f.id)||f.type==="section"&&s.has(f.logicalSectionId??f.id))),l=r?Tt(r):void 0,u=!1;for(let f of c){let g=`${f.entranceGateId??""}|${jo(f)??""}`;r?f.entranceGateId=r.id:delete f.entranceGateId,Ko(f,l),`${f.entranceGateId??""}|${jo(f)??""}`!==g&&(u=!0)}return{changed:u,objectIds:c.map(f=>f.id)}}function $o(t,e){let n=new Map(e.filter(fo).map(i=>[i.id,i.label?.trim()??""]));if(!n.size)return[];let o=[];for(let i of Ee(t))!ge(i)||!i.entranceGateId||!n.has(i.entranceGateId)||(i.type!=="row"&&i.entrance?.trim()===n.get(i.entranceGateId)&&delete i.entrance,delete i.entranceGateId,o.push(i.id));return o}function hc(t,e){for(let n of t){if(!ge(n)||!n.entranceGateId)continue;let o=e.get(n.entranceGateId);o&&(n.entranceGateId=o)}}function si(t,e,n=Lo,o=!0){return{type:"shape",id:t,kind:e.length===2?"line":"polyline",label:rt(n,40,"Route name"),points:e.map(i=>({x:i.x,y:i.y})),stroke:{...Do},lineCap:"round",lineJoin:"round",endEnding:"arrow",route:o?{stepFree:!0}:{}}}function gc(t,e){let n=O(t,e.floorId);if(!Array.isArray(e.points)||e.points.length<2||e.points.length>200||e.points.some(i=>!Number.isFinite(i?.x)||!Number.isFinite(i?.y)))throw new d("invalid_operation","A route needs 2 to 200 finite points");let o=si(M(t,"route",e.idFactory,new Set),e.points,e.name,e.stepFree??!0);return n.objects.push(o),{changed:!0,floorId:n.floorId,route:structuredClone(o)}}function mc(t,e){let n=Ee(t).find(i=>i.type==="shape"&&i.id===e.shapeId);if(!n)throw new d("object_not_found",`Unknown shape id: ${e.shapeId}`,{shapeId:e.shapeId});if(n.kind!=="line"&&n.kind!=="polyline")throw new d("invalid_operation","Only a line or path can be a route");let o=JSON.stringify(n);if(e.route===null)delete n.route;else{let i={...n.route??{}};e.route.stepFree!==void 0?(Gt(e.route.stepFree,"Step-free"),e.route.stepFree?i.stepFree=!0:delete i.stepFree):n.route||(i.stepFree=!0),e.route.name!==void 0?n.label=rt(e.route.name,40,"Route name"):n.label?.trim()||(n.label=Lo),n.route||(n.stroke={...Do}),n.route=i}return{changed:JSON.stringify(n)!==o,shape:structuredClone(n)}}function Mc(t,e){let n=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(v=>n.objects.find(m=>m.type==="table"&&m.id===v)),a=o.filter((v,m)=>!i[m]);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 r=structuredClone(e.patch);if(!Object.keys(r).length)throw new d("invalid_operation","At least one table change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!r.label||r.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&T(t,r.categoryKey),r.fill!==void 0&&r.fill!==null&&(r.fill=D(r.fill,"Table surface color"));let s=r.seatCount!==void 0,c=r.seatCountsBySide!==void 0;if(c){if(r.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(r.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let v=["top","bottom","left","right"],m=Object.keys(r.seatCountsBySide);if(m.length!==v.length||m.some(C=>!v.includes(C)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let C of v){let _=r.seatCountsBySide[C];if(!Number.isInteger(_)||_<0||_>40)throw new d("invalid_operation",`seatCountsBySide.${C} must be a whole number from 0 to 40`)}let x=v.reduce((C,_)=>C+r.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&&r.seatCount!==x)throw new d("invalid_operation",`seatCount must equal the ${x}-chair seatCountsBySide total`);r.seatCount=x,r.sides=v.filter(C=>r.seatCountsBySide[C]>0)}if(r.seatCount!==void 0&&(!Number.isInteger(r.seatCount)||r.seatCount<1||r.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(r.shape!==void 0&&r.shape!=="round"&&r.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(r.automaticRadius!==void 0&&typeof r.automaticRadius!="boolean")throw new d("invalid_operation","automaticRadius must be true or false");if(r.shape==="rect"&&r.automaticRadius===!0)throw new d("invalid_operation","Automatic radius can be used only with round tables");if(r.bookAsWhole===!0&&r.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(r.variableOccupancy===!1&&(r.minOccupancy!==void 0||r.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(v,m,x,C)=>{if(m!==void 0&&(!Number.isFinite(m)||m<x||m>C))throw new d("invalid_operation",`${String(v)} must be from ${x} to ${C}`)};if(l("rotation",r.rotation,0,360),l("radius",r.radius,24,160),l("seatArc",r.seatArc,120,360),l("width",r.width,40,320),l("height",r.height,30,240),r.minOccupancy!==void 0&&(!Number.isInteger(r.minOccupancy)||r.minOccupancy<1||r.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(r.maxOccupancy!==void 0&&(!Number.isInteger(r.maxOccupancy)||r.maxOccupancy<1||r.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(r.sides!==void 0){let v=new Set(["top","bottom","left","right"]);if(!r.sides.length||r.sides.length>4||new Set(r.sides).size!==r.sides.length||r.sides.some(m=>!v.has(m)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let u=me(r,"Table"),f=Ye(r,"Table"),g=nt(r,"Table"),h=_o(r),y=i.map(v=>{if(v.seatCountsBySide&&!c&&(s||e.patch.sides!==void 0))throw new d("invalid_operation",`Table "${v.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:v.id});let m=structuredClone(v);if(Object.assign(m,r),ot(m,g),Ao(m,h),r.fill===null&&delete m.fill,m.shape==="round")delete m.seatCountsBySide,m.automaticRadius===!0?m.radius=qn(m.seatCount,m.seatArc):delete m.automaticRadius;else{if(r.automaticRadius===!0)throw new d("invalid_operation",`Table "${m.label}" is rectangular and cannot use automatic radius`,{tableId:m.id});delete m.automaticRadius}if(m.overrides&&r.seatCount!==void 0&&(m.overrides=m.overrides.filter(x=>x.index<m.seatCount),m.overrides.length||delete m.overrides),r.bookAsWhole===!1&&delete m.bookAsWhole,r.variableOccupancy===!1&&(delete m.variableOccupancy,delete m.minOccupancy,delete m.maxOccupancy),m.bookAsWhole||delete m.bookAsWhole,m.variableOccupancy||delete m.variableOccupancy,m.bookAsWhole&&m.variableOccupancy)throw new d("invalid_operation",`Table "${m.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:m.id});if((m.bookAsWhole||m.variableOccupancy)&&m.overrides?.length)throw new d("invalid_operation",`Table "${m.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:m.id,overriddenChairIndices:m.overrides.map(x=>x.index)});if(m.bookAsWhole)delete m.minOccupancy,delete m.maxOccupancy;else if(m.variableOccupancy){if(!Number.isInteger(m.minOccupancy)||!Number.isInteger(m.maxOccupancy)||m.minOccupancy<1||m.maxOccupancy<m.minOccupancy||m.maxOccupancy>m.seatCount)throw new d("invalid_operation",`Table "${m.label}" needs whole-number minimum and maximum guests from 1 to its ${m.seatCount}-chair capacity`,{tableId:m.id,seatCount:m.seatCount})}else{if(r.minOccupancy!==void 0||r.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:m.id});delete m.minOccupancy,delete m.maxOccupancy}if(f&&delete m.displayType,u&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let x=["top","bottom","left","right"],C=x.reduce((_,j)=>_+m.seatCountsBySide[j],0);if(C!==m.seatCount)throw new d("invalid_operation",`Table "${m.label}" side counts total ${C}, but seatCount is ${m.seatCount}`,{tableId:m.id,seatCount:m.seatCount,seatCountsBySide:m.seatCountsBySide});m.sides=x.filter(_=>m.seatCountsBySide[_]>0)}}else m.radius??=40;if((m.bookAsWhole||m.variableOccupancy)&&he(m.label))throw new d("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),b=new Map(y.map(v=>[v.id,v])),I=new Set(o),S=new Map;for(let v of F(t))for(let m of v.objects){let x=m.type==="table"?b.get(m.id)??m:m,C=[];x.type==="row"?C=Y(x).map(_=>_.label):x.type==="table"?C=x.bookAsWhole||x.variableOccupancy?[x.label]:Re(x).map(_=>_.label):x.type==="booth"?C=[x.label]:x.type==="gaArea"&&(C=te(x));for(let _ of C){let j=S.get(_);if(j&&(I.has(j)||I.has(x.id)))throw new d("invalid_operation",`Inventory label "${_}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:_,conflictingObjectIds:[j,x.id]});S.set(_,j??x.id)}}let p=!1,w=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","fill","seatCountsBySide","overrides","automaticRadius","chairNumbering","labelPresentation","entrance"];for(let[v,m]of i.entries()){let x=y[v],C=JSON.stringify(m);for(let _ of w)_ in x||delete m[_];Object.assign(m,x),JSON.stringify(m)!==C&&(p=!0)}return{floorId:n.floorId,changed:p,tableIds:o}}function Fc(t,e){let n=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(b=>n.objects.find(I=>I.type==="booth"&&I.id===b)),a=o.filter((b,I)=>!i[I]);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 r=structuredClone(e.patch);if(!Object.keys(r).length)throw new d("invalid_operation","At least one booth change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!r.label||r.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&T(t,r.categoryKey);let s=(b,I,S,p)=>{if(I!==void 0&&(!Number.isFinite(I)||I<S||I>p))throw new d("invalid_operation",`${b} must be from ${S} to ${p}`)};s("width",r.width,30,400),s("height",r.height,30,400),s("rotation",r.rotation,0,360);let c=r.points===null;if(r.points!=null){if(o.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let b=_n(r.points);if(!b.ok)throw new d("invalid_operation",b.message??"The booth outline is not a valid simple polygon")}let l=r.points!=null?r.points.map(b=>({x:b.x,y:b.y})):void 0;delete r.points;let u=me(r,"Booth"),f=Ye(r,"Booth"),g=nt(r,"Booth"),h=Po(r),y=!1;for(let b of i){let I=JSON.stringify(b);Object.assign(b,r),ot(b,g),ko(b,h),u&&delete b.displayLabel,f&&delete b.displayType,c?delete b.points:l&&(b.points=l),JSON.stringify(b)!==I&&(y=!0)}return{floorId:n.floorId,changed:y,boothIds:o}}function jc(t,e){let n=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(h=>n.objects.find(y=>y.type==="gaArea"&&y.id===h)),a=o.filter((h,y)=>!i[y]);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 r=structuredClone(e.patch);if(!Object.keys(r).length)throw new d("invalid_operation","At least one GA area change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!r.label||r.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(r.categoryKey!==void 0&&T(t,r.categoryKey),r.capacity!==void 0&&(!Number.isInteger(r.capacity)||r.capacity<1||r.capacity>J))throw new d("invalid_operation",`capacity must be an integer from 1 to ${J}`);if(r.cornerRadius!==void 0&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=me(r,"GA area"),c=Ye(r,"GA area"),l=nt(r,"GA area"),u=vo(r);if(r.capacity!==void 0)for(let h of i){if(h.inventorySegments!==void 0&&r.capacity<h.capacity)throw new d("invalid_operation",`Joined GA area "${h.label}" cannot be reduced below ${h.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:h.id,currentCapacity:h.capacity,requestedCapacity:r.capacity});if(h.inventorySegments!==void 0&&r.capacity>h.capacity&&_t(h,r.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${h.label}" cannot append that capacity safely`,{gaAreaId:h.id})}let f=i.map(h=>{let y=structuredClone(h),b=r.capacity===void 0?h.inventorySegments:_t(h,r.capacity);return Object.assign(y,r),ot(y,l),xo(y,u),b!==void 0&&(y.inventorySegments=b),s&&delete y.displayLabel,c&&delete y.displayType,y});Co(t,f);let g=!1;for(let[h,y]of i.entries()){let b=f[h],I=JSON.stringify(y);for(let S of Object.keys(y))S in b||delete y[S];Object.assign(y,b),JSON.stringify(y)!==I&&(g=!0)}return{floorId:n.floorId,changed:g,gaAreaIds:o}}function Bo(t,e){if(e.length<3)return 0;let n=i=>$(i,e,void 0),o=0;for(let i of t)n(G(i))&&(i.type==="row"?o+=Y(i).length:i.type==="table"?o+=Re(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=le(i)));return o}function Tc(t,e){let n=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=>n.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,r=new Set(e.objectIds);for(let s=n.objects.length-1;s>=0;s--)r.has(n.objects[s].id)&&n.objects.splice(s,1);return $o(t,a),{floorId:n.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+le(c),0),remainingObjectCount:n.objects.length}}function Ec(t,e){let n=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=>n.objects.find(u=>u.type==="text"&&u.id===l)),a=o.filter((l,u)=>!i[u]);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 r=structuredClone(e.patch);if(!Object.keys(r).length)throw new d("invalid_operation","At least one text change is required");if(r.text!==void 0){if(r.text=r.text.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!r.text||r.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(r.fontSize!==void 0&&(!Number.isFinite(r.fontSize)||r.fontSize<8||r.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(r.fontFamily!==void 0&&r.fontFamily!==null&&(r.fontFamily=r.fontFamily.normalize("NFKC").trim(),!r.fontFamily||r.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(r.rotation!==void 0&&(!Number.isFinite(r.rotation)||r.rotation<0||r.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(r.color!==void 0&&r.color!==null&&(r.color=D(r.color,"Text color")),r.bold!==void 0&&typeof r.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(r.italic!==void 0&&typeof r.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(r.width!==void 0&&r.width!==null&&(!Number.isFinite(r.width)||r.width<40||r.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(r.align!==void 0&&!["left","center","right"].includes(r.align))throw new d("invalid_operation","Text align must be left, center, or right");if(r.lineHeight!==void 0&&(!Number.isFinite(r.lineHeight)||r.lineHeight<.8||r.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(r.letterSpacing!==void 0&&(!Number.isFinite(r.letterSpacing)||r.letterSpacing<-2||r.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(r.underline!==void 0&&typeof r.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(r.opacity!==void 0&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(r.background!==void 0&&r.background!==null){r.background.color=D(r.background.color,"Text background color");let{padding:l=6,cornerRadius:u=4,opacity:f=.9}=r.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(u)||u<0||u>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(f)||f<.1||f>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(r,l))&&i.some(l=>l.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(r.labelImportance!==void 0&&r.labelImportance!==null&&r.labelImportance!=="orientation"&&r.labelImportance!=="detail")throw new d("invalid_operation","Text labelImportance must be 'orientation', 'detail' or null");if(r.iconKey!==void 0){if(!ao(r.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 u=JSON.stringify(l);r.iconKey!==void 0&&(l.iconKey=r.iconKey),r.text!==void 0&&(l.text=r.text),r.fontSize!==void 0&&(l.fontSize=r.fontSize),r.fontFamily===null?delete l.fontFamily:r.fontFamily!==void 0&&(l.fontFamily=r.fontFamily),r.rotation!==void 0&&(l.rotation=r.rotation),r.color===null?delete l.color:r.color!==void 0&&(l.color=r.color),r.bold!==void 0&&(r.bold?l.bold=!0:delete l.bold),r.italic!==void 0&&(r.italic?l.italic=!0:delete l.italic),r.width===null?delete l.width:r.width!==void 0&&(l.width=r.width),r.align!==void 0&&(r.align==="left"?delete l.align:l.align=r.align),r.lineHeight!==void 0&&(r.lineHeight===1.2?delete l.lineHeight:l.lineHeight=r.lineHeight),r.letterSpacing!==void 0&&(r.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=r.letterSpacing),r.underline!==void 0&&(r.underline?l.underline=!0:delete l.underline),r.opacity!==void 0&&(r.opacity===1?delete l.opacity:l.opacity=r.opacity),r.background===null?delete l.background:r.background!==void 0&&(l.background=r.background),r.labelImportance===null?delete l.labelImportance:r.labelImportance!==void 0&&(l.labelImportance=r.labelImportance),JSON.stringify(l)!==u&&(_e(l),c=!0)}return{floorId:n.floorId,changed:c,textIds:o}}function Dc(t,e){let n=O(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(g=>n.objects.find(h=>h.type==="row"&&h.id===g)),a=o.filter((g,h)=>!i[h]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i.slice().sort((g,h)=>g.origin.y-h.origin.y||g.origin.x-h.origin.x),s=g=>g.segmentedRow?.displayLabel??g.displayLabel??g.label,c=Mn(r.map(g=>({label:s(g)})),e.options),l=e.displayType==null?void 0:e.displayType.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,24),u=l===void 0||l===""||l==="Row"?e.displayType===void 0?void 0:null:l,f=!1;return r.forEach((g,h)=>{let y=c[h].label.normalize("NFKC").replace(/\s+/g," ").trim();if(s(g)!==y&&(f=!0,g.segmentedRow?g.segmentedRow.displayLabel=y:g.displayLabel=y),u!==void 0){if(u===null){g.displayType!==void 0&&(f=!0,delete g.displayType);return}g.displayType!==u&&(f=!0,g.displayType=u)}}),{floorId:n.floorId,changed:f,rows:r.map(g=>({id:g.id,displayLabel:s(g),...g.displayType?{displayType:g.displayType}:{}}))}}function Lc(t,e){let n=wo.find(u=>u.key===e.blockKey);if(!n)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=e.rotation??0;if(!Number.isFinite(o))throw new d("invalid_operation","Block rotation must be a finite number of degrees");let i=O(t,e.floorId),a=new Set,r=n.build().map(u=>structuredClone(u));for(let u of r)u.id=M(t,u.type,e.idFactory,a),pe(u,e.center.x,e.center.y),o%360&&Io(u,e.center,o);for(let u of n.categories)t.categories.some(f=>f.key===u.key)||t.categories.push({...u});let s=r.filter(u=>u.type==="row");if(s.length){let u=0;for(let f of i.objects){if(f.type!=="row")continue;let g=et(f.label);g!=null&&(u=Math.max(u,g+1))}for(let f of s)f.label=L(u++)}let c=new Set(i.objects.flatMap(u=>"label"in u&&u.label?[u.label]:[]));for(let u of r){if((u.type==="table"||u.type==="booth")&&c.has(u.label)){let f=/^(.*?)(\d+)$/.exec(u.label),g=f?f[1]:`${u.label} `,h=f?Number.parseInt(f[2],10):1;do h++;while(c.has(`${g}${h}`));u.label=`${g}${h}`}"label"in u&&u.label&&c.add(u.label)}i.objects.push(...r);let l=null;if(n.sectionLabel&&e.wrapInSection!==!1){let u=ce(r);if(u){let f={type:"section",id:M(t,"sec",e.idFactory,a),label:n.sectionLabel,outline:u};i.objects.push(f),l=f.id}}return{floorId:i.floorId,blockKey:n.key,createdIds:[...r.map(u=>u.id),...l?[l]:[]],sectionId:l}}function ci(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=vn(e,97),i=o.slice(1).reduce((a,r,s)=>a+Math.hypot(r.x-o[s].x,r.y-o[s].y),0);if(!Number.isFinite(i)||i<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function li(t,e){let n=O(t,e.floorId),o=n.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!o)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=ci(e.path),a=Y(o),r=structuredClone(o);r.path=i.path,r.origin={...i.path.start};let s=Y(r),c=a.map((u,f)=>Math.hypot(u.x-s[f].x,u.y-s[f].y)),l=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((u,f)=>u+f,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function Jc(t,e){let n=li(t,e);if(!n.changed)return n;let i=O(t,n.floorId).objects.find(a=>a.type==="row"&&a.id===n.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,n}function di(t,e){let n=t.map((o,i)=>[...o,e[i]]);for(let o=0;o<3;o++){let i=o;for(let r=o+1;r<3;r++)Math.abs(n[r][o])>Math.abs(n[i][o])&&(i=r);if(Math.abs(n[i][o])<1e-9)return null;[n[o],n[i]]=[n[i],n[o]];let a=n[o][o];for(let r=o;r<4;r++)n[o][r]/=a;for(let r=0;r<3;r++){if(r===o)continue;let s=n[r][o];for(let c=o;c<4;c++)n[r][c]-=s*n[o][c]}}return[n[0][3],n[1][3],n[2][3]]}function ui(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],n=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],r=i.x**2+i.y**2;for(let s=0;s<3;s++){n[s]+=a[s]*r;for(let c=0;c<3;c++)e[s][c]+=a[s]*a[c]}}let o=di(e,n);return o?{x:o[0],y:o[1]}:null}function zo(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function fi(t,e){let n=O(t,e.floorId),o=n.objects.find(h=>h.type==="section"&&h.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=F(t).find(h=>h.id===n.floorId),r=e.mode==="outline"?ui(o.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=n.objects.filter(h=>h.type==="row"&&$(G(h),o.outline,o.holes)),c=s.filter(h=>!!h.path).map(h=>h.id),l=[],u=[],f=i/100;for(let h of s){if(h.path)continue;if(h.seatCount<2){l.push(h.id);continue}let y=Math.hypot(h.origin.x-r.x,h.origin.y-r.y);if(y<=h.seatSpacing/2+1e-6){l.push(h.id);continue}let b=2*Math.asin(h.seatSpacing/(2*y))/oe,I=Y(h),S=Math.atan2(h.origin.x-r.x,h.origin.y-r.y)/oe,w=(h.curve!==0?Math.sign(h.curve):I.length>1&&Math.sign(zo(Math.atan2(I[1].x-r.x,I[1].y-r.y)/oe-S))||1)*b*(h.seatCount-1);if(Math.abs(w)>320){l.push(h.id);continue}let v=-S,m=h.curve+(w-h.curve)*f,x=h.rotation+zo(v-h.rotation)*f,C={...h,curve:m,rotation:x},j=Y(C).map((B,z)=>Math.hypot(B.x-I[z].x,B.y-I[z].y));u.push({rowId:h.id,fromCurve:h.curve,targetCurve:w,resultCurve:m,fromRotation:h.rotation,resultRotation:x,rmsMovement:Math.sqrt(j.reduce((B,z)=>B+z**2,0)/j.length),maxMovement:Math.max(...j)})}let g=u.map(h=>h.rmsMovement);return{floorId:n.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...r},strength:i,rows:u,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:g.length?g.reduce((h,y)=>h+y,0)/g.length:0,maxMovement:u.length?Math.max(...u.map(h=>h.maxMovement)):0}}function qc(t,e){let n=fi(t,e),o=O(t,n.floorId),i=o.objects.find(r=>r.type==="section"&&r.id===n.sectionId),a=!1;for(let r of n.rows){let s=o.objects.find(c=>c.type==="row"&&c.id===r.rowId);(s.curve!==r.resultCurve||s.rotation!==r.resultRotation)&&(s.curve=r.resultCurve,s.rotation=r.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==n.strength&&(i.smoothing=n.strength,a=!0),{...n,changed:a}}function Jo(t,e,n,o){let i=X(t,e,n),a=X(t,e,o),r=X(n,o,t),s=X(n,o,e);return i*a<-1e-9&&r*s<-1e-9}function Uo(t,e){return t.some((n,o)=>{let i=t[(o+1)%t.length];return e.some((a,r)=>Jo(n,i,a,e[(r+1)%e.length]))})}function hi(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 n=e+1;n<t.length;n++)if(!(n===e+1||e===0&&n===t.length-1)&&Jo(t[e],t[(e+1)%t.length],t[n],t[(n+1)%t.length]))return!1;return!0}function it(t,e,n){let o=O(t,e),i=o.objects.find(r=>(r.type==="section"||r.type==="gaArea"||r.type==="shape"&&r.kind==="polygon")&&r.id===n);if(!i)throw new d("object_not_found",`Unknown polygon object id: ${n}`,{objectId:n});let a=i.type==="section"?i.outline:i.type==="shape"?An(i):i.points;return{target:o,object:i,outer:a}}function qo(t,e,n){return e.type==="shape"?{ids:[],units:0}:{ids:t.objects.filter(i=>i.id!==e.id&&i.type!=="section"&&$(G(i),n,void 0)).map(i=>i.id),units:Bo(t.objects.filter(i=>i.id!==e.id),n)}}function $t(t,e){let{target:n,object:o,outer:i}=it(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!hi(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!$(l,i,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(Uo(a,i))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let r=o.holes??[],s=e.holeIndex??r.length;if(o.type==="shape"&&e.holeIndex==null&&r.length>=Ct)throw new d("invalid_operation",`A shape holds at most ${Ct} cut-outs`);if(!Number.isInteger(s)||s<0||s>r.length||e.holeIndex!=null&&s>=r.length)throw new d("invalid_operation","Opening not found");for(let l=0;l<r.length;l++){if(l===e.holeIndex)continue;let u=r[l];if(Uo(a,u)||$(a[0],u,void 0)||$(u[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let c=qo(n,o,a);return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.ids,excludedInventoryUnits:c.units,preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Hc(t,e){let n=$t(t,e),{object:o}=it(t,n.floorId,n.objectId);return o.holes??=[],e.holeIndex==null?o.holes.push(structuredClone(e.points)):o.holes[e.holeIndex]=structuredClone(e.points),{...n,changed:!0}}function gi(t,e){let{target:n,object:o}=it(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=qo(n,o,i);return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.ids,excludedInventoryUnits:a.units,preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Vc(t,e){let n=gi(t,e),{object:o}=it(t,n.floorId,n.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function mi(t){let e=se(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function Ho(t,e){let n=[...new Set(e)];if(!n.length)throw new d("invalid_operation","At least one section id is required");let o=n.map(r=>t.find(s=>s.type==="section"&&s.id===r)),i=n.filter((r,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:n,sections:a,logicalSectionIds:[...new Set(a.map(r=>r.logicalSectionId??r.id))]}}function bi(t,e){let n=O(t,e.floorId),o=Ho(n.objects,e.sectionIds),i=Pe(ne(t,n.floorId)),a=new Map(i.sections.map(h=>[h.id,h])),r=new Map(n.objects.map(h=>[h.id,h])),s=o.logicalSectionIds.flatMap(h=>a.get(h)?.objectIds??[]),c=new Set,l=new Set(o.logicalSectionIds),u=new Set(n.objects.filter(h=>h.type==="section"&&l.has(h.logicalSectionId??h.id)).flatMap(h=>h.editor?.defaultCategoryKey?[h.editor.defaultCategoryKey]:[]));for(let h of s){let y=r.get(h);if(y)if(y.type==="row"||y.type==="table")for(let b of We(y).keys())c.add(b);else(y.type==="booth"||y.type==="gaArea")&&c.add(y.categoryKey)}let f=o.logicalSectionIds.every(h=>(a.get(h)?.seatCount??0)>0),g=o.logicalSectionIds.every(h=>a.get(h)?.objectIds.some(y=>{let b=r.get(y);return b?.type==="row"||b?.type==="table"||b?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:f,...f&&c.size===1?{categoryKey:[...c][0]}:!f&&!s.length&&u.size===1?{categoryKey:[...u][0]}:{},categoryMixed:f?c.size!==1:!s.length&&u.size>1,viewApplicable:g}}function rl(t,e){T(t,e.categoryKey);let n=bi(t,e);if(!n.categoryApplicable&&n.objectIds.length)throw new d("invalid_operation","A mixed selection of empty and occupied logical sections cannot be assigned together",{logicalSectionIds:n.logicalSectionIds});let o=O(t,n.floorId),i=new Set(n.objectIds),a=!1,r=0,s=new Set(n.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(u=>{if(u.categoryKey===void 0)return[u];let f={...u};return delete f.categoryKey,r++,a=!0,Object.keys(f).some(g=>g!=="index")?[f]:[]});l.length?c.overrides=l:delete c.overrides}return{...n,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function Vo(t,e){let n=O(t,e.floorId),o=Ho(n.objects,e.sectionIds),{requested:i}=o,a=structuredClone(e.patch),r=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(h=>!r.has(h));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=mi(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&&Ze(a.labelPresentation,"Section"),a.labelStyle!==void 0&&re(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(h=>h.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=D(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),u=c?n.objects.filter(h=>h.type==="section"&&l.has(h.logicalSectionId??h.id)):[],f=new Set,g=!1;for(let h of o.sections){let y=JSON.stringify(h);a.label!==void 0&&(h.label=a.label),a.labelPresentation===null?delete h.labelPresentation:a.labelPresentation!==void 0&&(h.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(h.elevation=a.elevation);let b=I=>{h.physical3dProvenance&&(delete h.physical3dProvenance[I],Object.keys(h.physical3dProvenance).length===0&&delete h.physical3dProvenance)};a.height===null?(delete h.height,b("height")):a.height!==void 0&&(h.height=a.height,h.physical3dProvenance={...h.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete h.rake,b("rake")):a.rake!==void 0&&(h.rake=a.rake,h.physical3dProvenance={...h.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete h.surfaceKind,b("surfaceKind")):a.surfaceKind!==void 0&&(h.surfaceKind=a.surfaceKind,h.physical3dProvenance={...h.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete h.color:a.color!==void 0&&(h.color=a.color),JSON.stringify(h)!==y&&(g=!0,f.add(h.id))}for(let h of u){let y=JSON.stringify(h),b=h.viewFromSeatUrl;a.displayLabel===null?delete h.displayLabel:a.displayLabel!==void 0&&(h.displayLabel=a.displayLabel);let I=h.entrance;if(a.entrance===null||a.entrance===""?delete h.entrance:a.entrance!==void 0&&(h.entrance=a.entrance),h.entrance!==I&&delete h.entranceGateId,a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete h.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(h.viewFromSeatUrl=a.viewFromSeatUrl),!h.viewFromSeatUrl||a.viewFromSeatMeta===null?delete h.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?h.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&h.viewFromSeatUrl!==b&&delete h.viewFromSeatMeta,a.labelStyle!==void 0){let S=be(h.labelPresentation,a.labelStyle);S?h.labelPresentation=S:delete h.labelPresentation}a.zone===null?delete h.zone:a.zone!==void 0&&(h.zone=a.zone),JSON.stringify(h)!==y&&(g=!0,f.add(h.id))}return{floorId:n.floorId,changed:g,sectionIds:i,affectedSectionIds:[...f]}}function pi(t,e){let n=O(t,e.floorId),o=n.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=n.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&$(G(a),o.outline,o.holes));return{floorId:n.floorId,sectionId:o.id,sectionLabel:o.label,source:{representation:"generated-polygon",generator:structuredClone(o.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:o.outline.length,holeCount:o.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,r)=>a+le(r),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function il(t,e){let n=pi(t,e),i=O(t,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function yi(t,e){let n=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,r=!0;if(e.kind==="translate"){if(!n(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");r=e.dx!==0||e.dy!==0,o=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!n(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");r=e.factor!==1,i=e.factor;let s=G(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(!n(e.degrees))throw new d("invalid_operation","Section rotation must be finite");r=(e.degrees%360+360)%360!==0;let c=e.degrees*Math.PI/180,l=Math.cos(c),u=Math.sin(c),f=G(t);o=g=>{let h=g.x-f.x,y=g.y-f.y;return{x:f.x+h*l-y*u,y:f.y+h*u+y*l}}}else{if(!n(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 r&&(t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=Xe(t.outlinePath,o,i,a)),a&&t.edgeCurvature&&(t.edgeCurvature=On(t.edgeCurvature)),t.holes&&(t.holes=Z(t.holes).map(s=>s.map(o)))),{changed:r,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 al(t,e){let n=O(t,e.floorId),o=n.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:n.floorId,...yi(o,e.transform)}}function sl(t,e){let n=O(t,e.floorId),o=n.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(!xn(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=xt(i),r=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return r&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:n.floorId,sectionId:o.id,changed:r,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function wi(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function cl(t,e){return Ii(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Ii(t,e){let n=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,r=!1;try{for(let s of o){let c=n.objects.find(p=>p.type==="section"&&p.id===s);if(!c||!wi(c))continue;let u=structuredClone(c);a.set(c.id,{section:c,snapshot:u});let f=JSON.stringify(c),g=(c.sourceOutline??c.outline).map(p=>({...p})),h=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),b=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(p=>Math.min(100,Math.max(-100,p))),I=b?.some(p=>Math.abs(p)>.5)===!0,S=h>.5||I?Rn(g,{cornerSmoothing:h,...I?{edgeCurvature:b}:{}}):null;S?(c.sourceOutline=g,c.outlinePath=S,c.outline=xt(S),h>.5?c.cornerSmoothing=h:delete c.cornerSmoothing,I?c.edgeCurvature=[...b]:delete c.edgeCurvature):(c.outline=g,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let p=0;p<(c.holes?.length??0);p+=1)$t(t,{floorId:n.floorId,objectId:c.id,points:c.holes[p],holeIndex:p});JSON.stringify(c)!==f&&(r=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let u=c;for(let f of Object.keys(u))delete u[f];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:r,sectionIds:o,affectedSectionIds:[...i]}}function hl(t,e,n={}){let o=!1;for(let i of e){let a=Vo(t,{floorId:i.floorId,sectionIds:[i.sectionId],patch:{height:i.height,rake:i.rake,surfaceKind:i.surfaceKind}});o||=a.changed}if(n.stage){let i=O(t,n.stage.floorId).objects.find(a=>a.type==="shape"&&a.id===n.stage.shapeId);i&&i.role!=="stage"&&(i.role="stage",o=!0),i&&n.stage.stageKind&&!i.stageKind&&(i.stageKind=n.stage.stageKind,o=!0)}for(let{shapeId:i,floorId:a,role:r}of n.roles??[]){let s=O(t,a).objects.find(c=>c.type==="shape"&&c.id===i);s&&!s.role&&(s.role=r,o=!0)}for(let{floorId:i,point:a}of n.focal??[]){let r=Fe(a,"focalPoint"),s=i?t.floors?.find(l=>l.id===i):void 0,c=s?s.focalPoint:t.focalPoint;c?.x===r.x&&c?.y===r.y||(s?s.focalPoint=r:t.focalPoint=r,o=!0)}return t.floors?.length&&Qe(t),{changed:o}}var Si=new Set(["companion","child","senior","student","membership","custom"]);function ye(t){if(!t.length)throw new d("invalid_operation","A chart must have at least one category");let e=new Set,n=new Map,o=structuredClone(t);for(let i of o){let a=i.key.trim(),r=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),!r||r.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=r.toLocaleLowerCase("en"),c=n.get(s);if(c)throw new d("duplicate_category_label",`Categories ${c} and ${a} share the same label`,{categoryKeys:[c,a],label:r});if(n.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new 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&&!ke(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,u=new Set;for(let f of i.tiers){let g=f.id.trim(),h=f.name.normalize("NFKC").trim(),y=h.toLocaleLowerCase("en");if(!g||g.length>160||l.has(g))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:g});if(!h||h.length>80||u.has(y))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:h});if(!Number.isFinite(f.price)||f.price<0||f.price>1e6)throw new d("invalid_operation",`Ticket tier ${g} price must be from 0 to 1000000`,{categoryKey:a,tierId:g});if(f.restriction!=null&&!Si.has(f.restriction))throw new d("invalid_operation",`Ticket tier ${g} has an unknown restriction`,{categoryKey:a,tierId:g});if(f.buyerMessage!=null){if(f.buyerMessage=f.buyerMessage.normalize("NFKC").trim(),!f.buyerMessage)delete f.buyerMessage;else if(f.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${g} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:g})}if(f.currency!=null&&(f.currency=f.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(f.currency)))throw new d("invalid_operation",`Ticket tier ${g} must use a three-letter ISO currency`,{categoryKey:a,tierId:g});if(f.applicability!=null){let b=f.applicability.seatLabels?.map(S=>S.normalize("NFKC").trim()),I=f.applicability.accessibility;if(b&&(!b.length||b.length>1e4||b.some(S=>!S||S.length>160)||new Set(b).size!==b.length)||I&&(!I.length||I.some(S=>!qe.some(p=>p.key===S))||new Set(I).size!==I.length))throw new d("invalid_operation",`Ticket tier ${g} has invalid seat applicability`,{categoryKey:a,tierId:g});f.applicability={...b?{seatLabels:b}:{},...I?{accessibility:[...I]}:{}},!f.applicability.seatLabels&&!f.applicability.accessibility&&delete f.applicability}if(f.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(f.evidence.provenance)||typeof f.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g});if(f.evidence.sourceDescription=f.evidence.sourceDescription.normalize("NFKC").trim(),!f.evidence.sourceDescription||f.evidence.sourceDescription.length>240||f.evidence.capturedAt!==void 0&&(f.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(f.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g})}l.add(g),u.add(y)}}}return o}function Bt(t,e){let n=new Set,o=structuredClone(t.categories);for(let r of e.updates){if(n.has(r.categoryKey))throw new d("invalid_operation",`Category ${r.categoryKey} may be updated only once`);n.add(r.categoryKey);let s=o.find(f=>f.key===r.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${r.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:r.categoryKey});let c=structuredClone(r.patch),{tiers:l,...u}=c;typeof u.label=="string"&&(u.label=u.label.normalize("NFKC").trim()),typeof u.color=="string"&&(u.color=u.color.toLowerCase()),Object.assign(s,u),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(f=>{let g={...f,id:f.id.trim(),name:f.name.normalize("NFKC").trim()};return f.buyerMessage?.trim()?g.buyerMessage=f.buyerMessage.normalize("NFKC").trim():delete g.buyerMessage,g})),delete s.referenceDirectSeatImport}let i=ye(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...n],categories:t.categories}}function xl(t,e){let n=structuredClone(t.categories),o=n.find(r=>r.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=ye(n),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,category:t.categories.find(r=>r.key===e.categoryKey),categories:t.categories}}function Cl(t,e){let n=e.categoryKeys.map(c=>c.trim()),o=t.categories.map(c=>c.key);if(n.length!==o.length||new Set(n).size!==n.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:n,expectedCategoryKeys:o});let i=new Set(o),a=o.filter(c=>!n.includes(c)),r=n.filter(c=>!i.has(c));if(a.length||r.length)throw new d(r.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:n,missingCategoryKeys:a,unknownCategoryKeys:r});if(n.every((c,l)=>c===o[l]))return{changed:!1,categoryKeys:o,categories:t.categories};let s=new Map(t.categories.map(c=>[c.key,c]));return t.categories=ye(n.map((c,l)=>{let u=structuredClone(s.get(c));return c!==o[l]&&delete u.referenceDirectSeatImport,u})),{changed:!0,categoryKeys:n,categories:t.categories}}function Xo(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let n=e[1];return n.length===3&&(n=n.split("").map(o=>o+o).join("")),[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function vi(t,e){let n=Xo(t),o=Xo(e);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var xi=3600;function Ci(t,e,n=Mt){return n.find(i=>t.every(a=>vi(i,a)>=xi))??n[e%n.length]}function Ol(t,e){let n=e?.palette??Mt;if(!t.categories.length)return{changed:[],categories:t.categories};let o=new Map(t.categories.map(r=>[r.key,r.color.toLowerCase()])),i=t.categories.map((r,s)=>({categoryKey:r.key,patch:{color:n[s%n.length]}}));return Bt(t,{updates:i}),{changed:t.categories.map(r=>({key:r.key,from:o.get(r.key),to:r.color})).filter(r=>r.from!==r.to),categories:t.categories}}function Rl(t,e){let n=e.color.trim().toLowerCase(),o=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(n))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=n,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let r=ye(i),s=JSON.stringify(r)!==JSON.stringify(t.categories);return s&&(t.categories=r),{changed:s,category:t.categories.find(c=>c.key===e.categoryKey),categories:t.categories}}function zt(t,e){let n=new Set(t.categories.map(r=>r.key)),o="";for(let r=0;r<100;r++){let c=e.idFactory("cat").trim();if(c&&!n.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(r=>({...r,id:r.id.trim(),name:r.name.normalize("NFKC").trim()})),...e.referenceDirectSeatImport?{referenceDirectSeatImport:structuredClone(e.referenceDirectSeatImport)}:{}},a=ye([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(r=>r.key===o),categories:a}}var Oi=["#3e8e7e","#6e7ff0","#b0700f","#b05fc4"],Ri=[...Oi,"#4d7c0f","#c026d3","#a86b00","#d6336c","#e5484d","#dc2626"],_i={row:"#6e7ff0",table:"#3e8e7e",booth:"#b05fc4",gaArea:"#b0700f"};function Ai(t,e){let n=_i[t];return!n||!e.includes(n)?e:[n,...e.filter(o=>o!==n)]}var Pi="#f5f6f8",ki="#f7f8fb",Mi=26;function Fi(t,e,n){let o=(1-Math.abs(2*n-1))*e,i=(t%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[r,s,c]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],l=n-o/2,u=f=>Math.round((f+l)*255).toString(16).padStart(2,"0");return`#${u(r)}${u(s)}${u(c)}`}function ji(t,e,n,o,i){let a=u=>t.every(f=>{let g=Wn(u,f);return g==null||g>=Mi}),r=[Pi,i??ki],s=(u,f)=>At(to(u,f,Qn),f)??0,c=u=>o==="gaArea"?[...r,"#12151d"].every(f=>s(u,f)>=3):r.every(f=>(At(u,f)??0)>=3),l=e.find(u=>a(u)&&c(u));if(l)return l;for(let u=0;u<360;u+=12)for(let f of[.52,.44,.6]){let g=Fi(u,.62,f);if(a(g)&&c(g))return g}return n}function Ti(t,e){let n=Me.find(a=>a.objectType===e).creationWord,o=t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim();return Me.some(a=>a.creationWord.toLowerCase()===o.toLowerCase())?n:`${o} \u2013 ${n}`}function Ei(t){let e=new Map;for(let n of F(t))for(let o of n.objects){let i=Me.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of We(o).keys())a.add(r);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let r of a){let s=e.get(r)??new Set;s.add(i.objectType),e.set(r,s)}}return e}function Di(t,e){let n=new Set(t.categories.map(i=>i.label.toLowerCase())),o=e;for(let i=2;n.has(o.toLowerCase());i+=1)o=`${e} ${i}`;return o}function Li(t,e,n){let o=Ei(t),i=u=>{let f=o.get(u);return!f||f.size===0||f.size===1&&f.has(n)},a=t.categories.find(u=>u.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};let r=t.categories.find(u=>{let f=o.get(u.key);return f?.size===1&&f.has(n)});if(!a&&r)return{kind:"existing",categoryKey:r.key,label:r.label};let s=Me.find(u=>u.objectType===n),c=a?Ti(a.label,n):s.creationWord,l=t.categories.find(u=>u.label.toLowerCase()===c.toLowerCase()&&i(u.key));return l?{kind:"existing",categoryKey:l.key,label:l.label}:r?{kind:"existing",categoryKey:r.key,label:r.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:Di(t,c)}}function _l(t,e,n,o){let i=Li(t,e,n);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?t.categories.find(r=>r.key===i.baseCategoryKey):void 0;return Ni(t,n,a,i.label,o)}function Ni(t,e,n,o,i){let a=i.palette??Ri,r=t.categories.map(u=>u.color),s=i.suggestColor?.(r.map(u=>u.toLowerCase()))??Ci(r,t.categories.length),c=ji(r,Ai(e,a),s,e,t.theme?.background),l=zt(t,{label:o,color:c,...n?.price!==void 0?{price:n.price}:{},...n?.tiers?.length?{tiers:n.tiers}:{},idFactory:i.idFactory});return t.categories=l.categories,l.category.key}function Gi(t,e){let n=new Set;for(let o of F(t))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===e&&n.add(i.id),i.type==="section"&&i.editor?.defaultCategoryKey===e&&n.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&n.add(i.id);return[...n]}function Wo(t,e){let n=t.categories.find(a=>a.key===e.categoryKey);if(!n)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=Gi(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(n.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=ye(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}function Fl(t,e){if(!e.drafts.length)throw new d("invalid_operation","Add at least one category");let n=[];for(let o of e.drafts){let i=Ki(t.categories,o.label),a=zt(t,{label:i,color:o.color,...o.price!==void 0?{price:o.price}:{},...o.tiers?.length?{tiers:o.tiers}:{},idFactory:e.idFactory});n.push(a.category.key),(o.notForSale||o.seatGlyph)&&Bt(t,{updates:[{categoryKey:a.category.key,patch:{...o.notForSale?{notForSale:!0}:{},...o.seatGlyph?{seatGlyph:o.seatGlyph}:{}}}]})}return{categoryKeys:n,categories:t.categories}}function Ki(t,e){let n=e.normalize("NFKC").trim().slice(0,76)||"Category",o=new Set(t.map(i=>i.label.toLocaleLowerCase("en")));if(!o.has(n.toLocaleLowerCase("en")))return n;for(let i=2;i<1e4;i+=1){let a=`${n} ${i}`;if(!o.has(a.toLocaleLowerCase("en")))return a}return`${n} ${Date.now()}`}function jl(t,e){let{categoryKey:n,toCategoryKey:o}=e;if(!t.categories.some(r=>r.key===n))throw new d("category_not_found",`Unknown chart category: ${n}`,{categoryKey:n});if(o!==void 0){if(o===n)throw new d("invalid_operation","Move the seats to a different category");if(!t.categories.some(r=>r.key===o))throw new d("category_not_found",`Unknown chart category: ${o}`,{categoryKey:o})}let i=new Set;if(o!==void 0)for(let r of F(t))for(let s of r.objects){if((s.type==="row"||s.type==="table"||s.type==="booth"||s.type==="gaArea")&&s.categoryKey===n&&(s.categoryKey=o,i.add(s.id)),(s.type==="row"||s.type==="table")&&s.overrides?.length){for(let l of s.overrides)l.categoryKey===n&&(l.categoryKey=o,i.add(s.id));let c=s.overrides.flatMap(l=>{if(l.categoryKey!==s.categoryKey)return[l];let u={...l};return delete u.categoryKey,Object.keys(u).some(f=>f!=="index")?[u]:[]});c.length?s.overrides=c:delete s.overrides}s.type==="section"&&s.editor?.defaultCategoryKey===n&&(s.editor.defaultCategoryKey=o,i.add(s.id))}let a=Wo(t,{categoryKey:n});return{movedObjectIds:[...i],categories:a.categories}}var $i=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Bi=["seat","deck","shell","fascia"];function Gl(t,e){let n=e.patch;if(!Object.keys(n).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 $i){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=D(r,`Theme ${a}`))}if(n.fontFamily===null)delete i.fontFamily;else if(n.fontFamily!==void 0){let a=n.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(n.seatScale===null)delete i.seatScale;else if(n.seatScale!==void 0){if(!Number.isFinite(n.seatScale)||n.seatScale<Pt||n.seatScale>kt)throw new d("invalid_operation",`Theme seatScale must be from ${Pt} to ${kt}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=se(n.logoUrl);if(!a)throw new d("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster image reference");i.logoUrl=a}if(n.brandName===null)delete i.brandName;else if(n.brandName!==void 0){let a=n.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}if(n.hideBadge===null||n.hideBadge===!1?delete i.hideBadge:n.hideBadge===!0&&(i.hideBadge=!0),n.venue3d===null)delete i.venue3d;else if(n.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of Bi){let c=n.venue3d[s];c===null?delete a[s]:c!==void 0&&(a[s]=D(c,`3D venue ${s}`))}let r=n.venue3d.roughness;if(r===null)delete a.roughness;else if(r!==void 0){if(!Number.isFinite(r)||r<0||r>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=r}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==o,theme:t.theme??null}}function Kl(t,e){let n=e.url===null?null:se(e.url);if(e.url!==null&&!n)throw new d("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=n??void 0;if(e.floorId!==void 0){let s=t.floors?.find(f=>f.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,u=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:u,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,r=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=o,t.viewFromSeatMeta=a,{changed:r,scope:"venue",url:t.viewFromSeatUrl??null}}function we(t,e){let n=ne(t,e.floorId),o=Q(n),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 at(t,e){T(t,e.categoryKey);let n=(...u)=>u.every(Number.isFinite);if(!n(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,r=e.skewDegrees??0;if(!n(a,r)||Math.abs(a)>120||Math.abs(r)>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(!n(s.left,s.center,s.right)||Object.values(s).some(u=>u<0||u>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(u=>u.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:r,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function zi(t,e,n){let o=n*oe;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function Ui(t,e,n,o){let i=Math.abs(o-n)*oe,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,u])=>{let f=t.aisleGaps[l];if(!f)return[];let g=f/e/i/2;return[[Math.max(0,u-g),Math.min(1,u+g)]]}).sort((l,u)=>l[0]-u[0]),r=[];for(let l of a){let u=r[r.length-1];u&&l[0]<=u[1]?u[1]=Math.max(u[1],l[1]):r.push([...l])}let s=[],c=0;for(let l of r)l[0]-c>1e-6&&s.push([c,l[0]]),c=Math.max(c,l[1]);return 1-c>1e-6&&s.push([c,1]),s.filter(([l,u])=>e*i*(u-l)>=t.seatPitch*.75)}function Ji(t,e){let n=t.length*2;if(e<n)throw new d("invalid_operation",`Fixed seat count must be at least ${n} for ${t.length} aisle-separated row segments`);let o=e-n,i=t.reduce((c,l)=>c+l,0),a=t.map(c=>o*c/i),r=a.map(c=>2+Math.floor(c)),s=e-r.reduce((c,l)=>c+l,0);return a.map((c,l)=>({index:l,fraction:c-Math.floor(c)})).sort((c,l)=>l.fraction-c.fraction||c.index-l.index).forEach(({index:c})=>{s-- >0&&r[c]++}),r}function st(t,e,n){let o=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),r=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 u=Ui(t,r,c,l);if(!u.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(u=u.slice().reverse());let f=u.map(([y,b])=>r*Math.abs(l-c)*oe*(b-y)),g=t.fit==="fixed-count"?Ji(f,t.seatsPerRow):f.map(y=>Math.max(2,Math.round(y/t.seatPitch)+1)),h=t.seatLabelStart;u.forEach(([y,b],I)=>{let S=c+(l-c)*y,p=c+(l-c)*b;t.facing==="outward"&&([S,p]=[p,S]);let w=g[I];if(w>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let v=Math.abs(p-S)*oe/(w-1),m=2*r*Math.sin(v/2),x={type:"row",id:n(i,I),label:L(t.rowLabelStart+i),origin:zi(t.center,r,S),rotation:-S,curve:p-S,seatCount:w,seatSpacing:m,categoryKey:t.categoryKey,seatLabelStart:h,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:I}};o.push(x),h+=w})}return o}function Yo(t,e){let n=at(t,e),o=O(t,e.floorId),i=st(n,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),r=Math.max(...a.map(c=>Math.abs(c-n.seatPitch))),s=[];return r>n.seatPitch*.12&&s.push(`Seat spacing differs from the setting by up to ${Math.round(r*Tn*100)} cm, so each row keeps its seat count`),i.length>n.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:n.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((c,l)=>c+l.seatCount,0),innerRadius:n.innerRadius,outerRadius:n.innerRadius+(n.rowCount-1)*n.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:r,aisleCount:Object.values(n.aisleGaps).filter(c=>c>0).length,warnings:s}}function Zo(t,e){let n=at(t,e),o=O(t,e.floorId),i=new Set,a=M(t,"fan",e.idFactory,i),r=st(n,a,()=>M(t,"r",e.idFactory,i)),s=Yo(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),u=null;if(l){if(l.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let f=ce(r);f&&(c=M(t,"sec",e.idFactory,i),u={type:"section",id:c,label:l,outline:f,arcFanGroupId:a})}return o.objects.push(...r,...u?[u]:[]),{floorId:o.floorId,rowIds:r.map(f=>f.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function qi(t,e){let n=O(t,e.floorId),o=n.objects.filter(f=>f.type==="row"&&f.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=f=>{let g=f.arcFanGeneration;return JSON.stringify({center:g.center,innerRadius:g.innerRadius,rowCount:g.rowCount,rowGap:g.rowGap,startAngle:g.startAngle,endAngle:g.endAngle,seatPitch:g.seatPitch,fit:g.fit,seatsPerRow:g.seatsPerRow,facing:g.facing,taperDegrees:g.taperDegrees,skewDegrees:g.skewDegrees,aisleGaps:g.aisleGaps,rowLabelStart:g.rowLabelStart,seatLabelStart:g.seatLabelStart})};if(o.some(f=>a(f)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let r=n.objects.find(f=>f.type==="section"&&f.arcFanGroupId===e.groupId),s={floorId:n.floorId,center:{...i.center},innerRadius:i.innerRadius,rowCount:i.rowCount,rowGap:i.rowGap,startAngle:i.startAngle,endAngle:i.endAngle,seatPitch:i.seatPitch,fit:i.fit,seatsPerRow:i.seatsPerRow,facing:i.facing,taperDegrees:i.taperDegrees,skewDegrees:i.skewDegrees,aisleGaps:{...i.aisleGaps},categoryKey:o[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:r?.label},c=at(t,s),l=new Set(st(c,e.groupId,(f,g)=>`${f}:${g}`).map(f=>`${f.arcFanGeneration.rowIndex}:${f.arcFanGeneration.segmentIndex}`)),u=new Set(o.map(f=>`${f.arcFanGeneration.rowIndex}:${f.arcFanGeneration.segmentIndex}`));if(l.size!==u.size||[...l].some(f=>!u.has(f)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function Jl(t,e){qi(t,{floorId:e.floorId,groupId:e.groupId});let n=at(t,e),o=O(t,e.floorId),i=o.objects.filter(b=>b.type==="row"&&b.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(b=>b.type==="section"&&b.arcFanGroupId===e.groupId),r=new Map(i.map(b=>[`${b.arcFanGeneration.rowIndex}:${b.arcFanGeneration.segmentIndex}`,b.id])),s=new Set,c=st(n,e.groupId,(b,I)=>r.get(`${b}:${I}`)??M(t,"r",e.idFactory,s)),l=Yo(t,e),u=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(u){if(u.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let b=ce(c);b&&(f={type:"section",id:a?.id??M(t,"sec",e.idFactory,s),label:u,outline:b,arcFanGroupId:e.groupId})}let g=new Set([...i.map(b=>b.id),...a?[a.id]:[]]),h=Math.min(...o.objects.map((b,I)=>g.has(b.id)?I:1/0)),y=o.objects.filter(b=>!g.has(b.id));return y.splice(Number.isFinite(h)?h:y.length,0,...c,...f?[f]:[]),o.objects.splice(0,o.objects.length,...y),{floorId:o.floorId,rowIds:c.map(b=>b.id),sectionId:f?.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 Qo(t,e){let n=Hi(t?.trim()??"");if(n){let i=n(1);for(let a=2;e.has(i)&&a<1e3;a+=1)i=n(a);if(!e.has(i))return i}let o=0;for(;e.has(L(o));)o+=1;return L(o)}function Hi(t){if(!t)return null;let e=/^([A-Za-z])\1+$/.exec(t);if(e){let r=t===t.toLowerCase(),s=e[1].toUpperCase().charCodeAt(0)-65;return c=>{let l=s+c,f=String.fromCharCode(65+l%26).repeat(t.length+Math.floor(l/26));return r?f.toLowerCase():f}}let n=/^(.*?)(\d+)$/.exec(t);if(n){let[,r,s]=n,c=s.startsWith("0")?s.length:0;return l=>`${r}${String(Number(s)+l).padStart(c,"0")}`}let o=t.toUpperCase(),i=et(o);if(i==null)return null;let a=t===t.toLowerCase();return r=>{let s=L(i+r);return a?s.toLowerCase():s}}function Ut(t){return t.segmentedRow?.displayLabel??t.displayLabel??t.label}function Vi(t,e=[]){let n=new Set([...V(t),...e].filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=0;return()=>{for(;n.has(L(o));)o+=1;let i=L(o);return n.add(i),o+=1,i}}function Xi(t){let e=new Set(t.flatMap(o=>o.type==="row"?[Ut(o)]:o.type==="table"||o.type==="booth"?[o.label]:[])),n=0;return()=>{for(;e.has(L(n));)n+=1;let o=L(n);return e.add(o),o}}function Wi(t,e){let n=t.filter(c=>c.type==="section"),o=n.find(c=>$(e,c.outline,c.holes));if(!o)return Xi(t);let i=t.filter(c=>c.type==="row"&&Bn(t,c,n)===o),a=new Set(i.map(Ut)),r=i[i.length-1],s=r?Ut(r):void 0;return()=>{let c=Qo(s,a);return a.add(c),s=c,c}}function er(t,e){let n=e.pending??[],o=Vi(t,n),i=Wi([...O(t,e.floorId).objects,...n],e.origin);return Array.from({length:Math.max(0,e.count)},()=>{let a=o(),r=i?.();return r&&r!==a?{label:a,displayLabel:r}:{label:a}})}function tr(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 nr(t,e){if(T(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 n=e.rowGap??28,o=e.seatSpacing??24;if(!Number.isFinite(n)||n<=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,r=er(t,{floorId:e.floorId,origin:e.origin,count:e.rowCount}),s=Lt(e.rotation??0),c=e.curve??0,l=e.style,u=l?M(t,"rowblock",e.idFactory,a):void 0,f=l?tr({style:l,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:n,seatSpacing:o,curve:c}):void 0,g={x:Math.cos(s*ee),y:Math.sin(s*ee)},h={x:-g.y,y:g.x},y=Array.from({length:e.rowCount},(S,p)=>{let w=l==="intertwined"&&p%2===1?o/2:0,v={type:"row",id:M(t,"r",e.idFactory,a),...r[p],origin:{x:e.origin.x+h.x*p*n+g.x*w,y:e.origin.y+h.y*p*n+g.y*w},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&u&&f&&(v.rowBlockGeneration={kind:"row-block-v1",groupId:u,style:l,rowIndex:p,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:n,seatSpacing:o,curve:c,signature:f}),v});i.objects.push(...y);let b=null,I=e.sectionLabel?.trim();if(I){let S=ce(y);if(S){let p={type:"section",id:M(t,"sec",e.idFactory,a),label:I,outline:S};i.objects.push(p),b=p.id}}return{floorId:i.floorId,rowIds:y.map(S=>S.id),sectionId:b,createdIds:[...y.map(S=>S.id),...b?[b]:[]]}}function or(t,e){let n=new Set(V(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(;n.has(`${e}${o}`);)o+=1;let i=`${e}${o}`;return n.add(i),o+=1,i}}function Yi(t,e){let n=new Set(V(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!n.has(e))return e;let o=2;for(;n.has(`${e} ${o}`);)o+=1;return`${e} ${o}`}var Zi=456;function Jt(t){let e=Math.sqrt(Math.max(1,t)*Zi);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function rr(t,e){if(T(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 n=O(t,e.floorId),o=new Set,{width:i,height:a}=Jt(e.capacity),r=Yi(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:M(t,"ga",e.idFactory,o),label:r,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return n.objects.push(s),{floorId:n.floorId,gaAreaId:s.id,label:r,createdIds:[s.id]}}function ir(t,e){if(T(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 n=e.gapX??155,o=e.gapY??150;if(!Number.isFinite(n)||n<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,r=or(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:M(t,"t",e.idFactory,a),label:r(),center:{x:e.center.x+(l-(e.tableColumns-1)/2)*n,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 ar(t,e){if(T(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 n=e.gapX??88,o=e.gapY??82;if(!Number.isFinite(n)||n<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,r=or(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:M(t,"booth",e.idFactory,a),label:r(),center:{x:e.center.x+(l-(e.boothColumns-1)/2)*n,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 sr(t,e){let n=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(g=>g!=="continuous"&&g!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(g=>n.objects.find(h=>h.type==="row"&&h.id===g)),a=o.filter((g,h)=>!i[h]);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 r=i,s=r.filter(g=>g.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(g=>g.id)});let c=(e.displayLabel??r[0].displayLabel??r[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(n.objects.flatMap(g=>g.type==="row"?[g.segmentedRow?.groupId,g.rowBlockGeneration?.groupId].filter(h=>!!h):[])),u="";for(let g=0;g<100;g+=1){let h=e.idFactory("rowgroup");if(h&&!l.has(h)){u=h;break}}if(!u)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let f=r[0];return r.forEach((g,h)=>{g.segmentedRow={kind:"segmented-row-v1",groupId:u,componentIndex:h,componentCount:r.length,boundaryBefore:h===0?"start":e.boundaries[h-1],displayLabel:c,...f.displayType?{displayType:f.displayType}:{},...f.labelPresentation?{labelPresentation:structuredClone(f.labelPresentation)}:{},...f.viewFromSeatUrl?{viewFromSeatUrl:f.viewFromSeatUrl}:{},...f.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(f.viewFromSeatMeta)}:{},...f.confidenceEvidence?{confidenceEvidence:structuredClone(f.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:u,rowIds:o,changed:!0}}function id(t,e){let n=O(t,e.floorId),o=e.groupId?n.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):n.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??o?.segmentedRow?.groupId;if(!i)throw new d("object_not_found","The segmented row does not exist on the selected floor");let a=n.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let r=a.sort((s,c)=>s.segmentedRow.componentIndex-c.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:n.floorId,groupId:i,rowIds:r,changed:!0}}function ad(t,e){let n=O(t,e.floorId),o=n.objects.filter(r=>r.type==="row"&&r.segmentedRow?.groupId===e.groupId).sort((r,s)=>r.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(r=>r!=="continuous"&&r!=="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(r=>r.segmentedRow));return o.forEach((r,s)=>{let c=r.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),e.boundaries&&s>0&&(c.boundaryBefore=e.boundaries[s-1]),e.smoothing!==void 0&&(c.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete c.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=e.viewFromSeatUrl),!c.viewFromSeatUrl||e.viewFromSeatMeta===null?delete c.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:n.floorId,groupId:e.groupId,rowIds:o.map(r=>r.id),changed:JSON.stringify(o.map(r=>r.segmentedRow))!==a}}function sd(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 n=O(t,e.floorId),o=n.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 P=A.rowBlockGeneration;return P.kind!=="row-block-v1"||P.rowIndex!==q||P.signature!==i.signature||JSON.stringify(P)!==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),r=e.style??i.style,s=e.rowCount??i.rowCount,c=e.seatsPerRow??i.seatsPerRow,l=e.rowGap??i.rowGap,u=e.seatSpacing??i.seatSpacing,f=e.curve??i.curve,g=Number.isFinite(e.rotation??i.rotation)?Lt(e.rotation??i.rotation):e.rotation??i.rotation,h=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,u].every(A=>Number.isFinite(A)&&A>0)||!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(h.x)||!Number.isFinite(h.y))throw new d("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let y=tr({style:r,origin:h,rotation:g,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:u,curve:f}),b={x:Math.cos(g*ee),y:Math.sin(g*ee)},I={x:-b.y,y:b.x},S=new Map(o.map(A=>[A.rowBlockGeneration.rowIndex,A])),p=new Set,w=new Set(n.objects.filter(A=>A.type==="row").filter(A=>!o.includes(A)).map(A=>A.label)),v=n.objects.filter(A=>A.type==="row").length,m=()=>{for(;w.has(L(v));)v+=1;let A=L(v);return w.add(A),v+=1,A},x=[],C=[];for(let A=0;A<s;A+=1){let q=r==="intertwined"&&A%2===1?u/2:0,P=S.get(A);P||(P={type:"row",id:M(t,"r",e.idFactory,p),label:m(),origin:{...h},rotation:g,curve:f,seatCount:c,seatSpacing:u,categoryKey:o[0].categoryKey},C.push(P.id)),P.origin={x:h.x+I.x*A*l+b.x*q,y:h.y+I.y*A*l+b.y*q},P.rotation=g,P.curve=f,P.seatCount=c,P.seatSpacing=u,delete P.path,delete P.arcFanGeneration,P.overrides&&(P.overrides=P.overrides.filter(U=>U.index<c),P.overrides.length||delete P.overrides),P.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:r,rowIndex:A,rowCount:s,seatsPerRow:c,origin:{...h},rotation:g,rowGap:l,seatSpacing:u,curve:f,signature:y},x.push(P)}let _=o.slice(s).map(A=>A.id),j=Math.min(...o.map(A=>n.objects.indexOf(A))),B=new Set(o.map(A=>A.id)),z=n.objects.filter(A=>!B.has(A.id));return z.splice(j,0,...x),n.objects.splice(0,n.objects.length,...z),{floorId:n.floorId,groupId:e.groupId,rowIds:x.map(A=>A.id),createdRowIds:C,removedRowIds:_,changed:a!==JSON.stringify(x)||C.length>0||_.length>0}}function cr(t){let e=0;for(let n=1;n<t.length;n+=1)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e/Math.max(1,t.length-1)}function Qi(t){let e=t.length,n=t.reduce((S,p)=>S+p.x,0)/e,o=t.reduce((S,p)=>S+p.y,0)/e,i=0,a=0,r=0,s=0,c=0,l=0,u=0;for(let S of t){let p=S.x-n,w=S.y-o;i+=p*p,a+=w*w,r+=p*w,s+=p*p*p,c+=w*w*w,l+=p*w*w,u+=w*p*p}let f=i*a-r*r;if(Math.abs(f)<1e-9)return null;let g=(s+l)/2,h=(c+u)/2,y=(g*a-h*r)/f,b=(h*i-g*r)/f,I=Math.sqrt(y*y+b*b+(i+a)/e);return Number.isFinite(I)?{center:{x:y+n,y:b+o},radius:I}:null}function De(t){let e=t[0],n=t[t.length-1],o=Math.hypot(n.x-e.x,n.y-e.y),i=t.length;return{origin:{...e},rotation:o>0?Math.atan2(n.y-e.y,n.x-e.x)*180/Math.PI:0,curve:0,seatSpacing:i>1&&o>0?o/(i-1):cr(t),seatCount:i,ordered:t}}function ea(t){if(t.length<3)return De(t);let e=t[0],n=t[t.length-1],o=Math.hypot(n.x-e.x,n.y-e.y),i=cr(t);if(o<=0||i<=0)return De(t);let a=0;for(let g of t){let h=Math.abs((n.x-e.x)*(e.y-g.y)-(e.x-g.x)*(n.y-e.y))/o;a=Math.max(a,h)}if(a<i*.2)return De(t);let r=Qi(t);if(!r||r.radius<=i/2)return De(t);let s=g=>{let h=g[0],y=g[1],b=h.x-r.center.x,S=-(h.y-r.center.y),p=b;S*(y.x-h.x)+p*(y.y-h.y)<0&&(S=-S,p=-p);let w=Math.hypot(S,p)||1;S/=w,p/=w;let v=(r.center.x-h.x)*p+(r.center.y-h.y)*-S;return{tx:S,ty:p,centreSide:v}},c=t,l=s(c);l.centreSide<0&&(c=[...t].reverse(),l=s(c));let f=2*Math.asin(Math.min(1,i/(2*r.radius)))*(c.length-1)*180/Math.PI;return!Number.isFinite(f)||f>=359?De(t):{origin:{...c[0]},rotation:Math.atan2(l.ty,l.tx)*180/Math.PI,curve:f,seatSpacing:i,seatCount:c.length,ordered:c}}function ct(t,e){let n=ea(t);if(t.length<6)return[n];let o=e(n),i=-1,a=0;if(n.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<=n.seatSpacing/3)return[n];let r=Math.min(n.ordered.length-3,Math.max(3,i));return[...ct(n.ordered.slice(0,r),e),...ct(n.ordered.slice(r),e)]}function qt(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function Ht(t,e){let n="";for(let o of t){if(n.length+o.length>e)break;n+=o}return n.trim()}function Vt(t){return Ht(qt(t),40)}function lr(t,e=39){return Ht(qt(t),Math.max(1,e))}function Ie(t,e=80){return Ht(qt(t),Math.max(1,e))}function dr(t){return Ie(t).toLocaleLowerCase("en")}function Xt(t){return dr(t)}function ur(t){return new Map((t??[]).map(e=>[e.index,e]))}function ta(t){let e=ur(t.overrides),n=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||n.push(Ot(t,o,i))}return n}function na(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=ur(t.overrides),n=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||n.push(i?.label??`${t.label}-${o+1}`)}return n}function oa(t){return t.type==="row"?[t.label,...ta(t)]:t.type==="table"?[t.label,...na(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...te(t)]:[]}function fr(t,e){let n=new Set;for(let o of t)if(!e?.has(o.id))for(let i of oa(o)){let a=Xt(i);a&&n.add(a)}return n}function ra(t,e){if(!Number.isInteger(e)||e<1)return[];let n={label:t,seatCount:e},o=[Xt(t)];for(let i=0;i<e;i+=1)o.push(Xt(Ot(n,i)));return o.filter(Boolean)}function hr(t,e,n){let o=ra(e,n);if(!o.length||o.some(i=>t.has(i)||he(i)))return!1;for(let i of o)t.add(i);return!0}var ia=1e-6,aa=160,sa=.001,ca=1e-5;function Se(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>aa)return;for(let a of e){let r=a.codePointAt(0)??0;if(r<32||r===127)return}let n=e.lastIndexOf(":"),o=e.slice(0,n),i=e.slice(n+1);if(!(!o||!/^(0|[1-9]\d*)$/.test(i)||!Number.isSafeInteger(Number(i))))return e}function gr(t){return typeof t=="string"&&lr(t)||void 0}function mr(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(Wt(t.origin)&&Wt(e.start)&&Wt(e.end)&&Number.isFinite(t.rotation)&&Number.isFinite(t.seatSpacing)&&t.seatSpacing>0)||t.curve!==0||t.path)return!1;let n=t.rotation*Math.PI/180,o={x:t.origin.x+Math.cos(n)*t.seatSpacing*(t.seatCount-1),y:t.origin.y+Math.sin(n)*t.seatSpacing*(t.seatCount-1)},i=Math.hypot(e.end.x-e.start.x,e.end.y-e.start.y),a=sa+Math.max(1,i)*ca;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<=ia)return!0;let r=i/(t.seatCount-1);if(Math.abs(t.seatSpacing-r)>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 Wt(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var la=300;function da(t){let e=new Set(V(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(Boolean)),n=0,o=()=>{for(;e.has(L(n));)n+=1;let i=L(n);return n+=1,e.add(i),i};return i=>{let a=Vt(i),r=0;return()=>{for(;a&&r<4096;r+=1){let s=`${a}-${L(r)}`;if(!e.has(s))return e.add(s),r+=1,s}return o()}}}function ua(t){let e=fr(V(t));return(n,o)=>{let i=Ie(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,s=r?`${Ie(i,80-r.length)}${r}`:i;if(s&&hr(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function fa(t){return{ordinaryFor:da(t),direct:ua(t)}}function Yt(t,e,n){return t.type==="row"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function br(t,e,n){return t.type==="table"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function ha(t,e,n){let o=new Map;for(let r of e.sections)if(!(n&&r.sectionId!==n)&&r.sourceGroupId)for(let[s,c]of r.rows.entries()){let l=Se(`${r.sourceGroupId}:${s}`),u=l&&Se(c.directSourceRowId)===l?l:void 0;u&&o.set(u,o.has(u)?null:c)}let i=new Map;for(let r of t){let s=Se(r.referenceScan?.directSourceRowId);if(!s){if(!r.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:r.id})}let c=i.get(s)??[];c.push(r),i.set(s,c)}let a=new Map;for(let[r,s]of i){let c=s.filter(g=>g.overrides?.length);if(!c.length)continue;let l=o.get(r),u=c[0],f=u.overrides;if(s.length!==1||c.length!==1||!f||!l||!mr(u,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:r,rowIds:s.map(g=>g.id)});a.set(r,structuredClone(f))}return a}function pr(t,e,n){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!Yt(o,e,n)&&!br(o,e,n))}function ga(t,e,n,o,i,a,r){let s=t.sectionId?e.find(u=>u.type==="section"&&u.id===t.sectionId):void 0;if(s){let u=pr(e,n,r).filter(f=>$(G(f),s.outline,s.holes));if(u.length)return{skip:{sectionId:s.id,name:t.name,reason:"section_not_empty",objectIds:u.map(f=>f.id)},rows:[],seats:0}}let c=[],l=0;for(let[u,f]of t.rows.entries()){let g=Math.min(la,Math.max(1,Math.round(f.seatCount)));if(!Number.isFinite(g)||g<1)continue;let h=f.end.x-f.start.x,y=f.end.y-f.start.y,b=Math.hypot(h,y),I=g>1&&b>0?b/(g-1):o>0?o:24;if(!Number.isFinite(I)||I<=0)continue;let S=b>0?Math.atan2(y,h)*180/Math.PI:0,p={x:f.start.x,y:f.start.y},w=0,v=I,m,x=f.seats?.length===g&&f.seats.every(P=>Number.isFinite(P.x)&&Number.isFinite(P.y))?f.seats:null;if(x&&f.table&&g>=3){let P=f.table.center,U=x.reduce((E,K)=>E+Math.hypot(K.x-P.x,K.y-P.y),0)/g,H=x.map(E=>Math.atan2(E.y-P.y,E.x-P.x)).sort((E,K)=>E-K),ae=0,Je=0;H.forEach((E,K)=>{let fe=K+1<H.length?H[K+1]:H[0]+Math.PI*2;fe-E>ae&&(ae=fe-E,Je=(K+1)%H.length)});let R=ae>1.6*(Math.PI*2/g),k=R?(Math.PI*2-ae)*180/Math.PI:void 0;m={center:{...P},radius:Math.max(1,U-$n),...k!==void 0?{seatArc:k}:{}},S=R?(H[Je]-ae/2)*180/Math.PI:H[0]*180/Math.PI,p={...P}}let C=[];if(x&&!m&&g>=3){C=ct(x,U=>W({origin:U.origin,rotation:U.rotation,curve:U.curve,seatCount:U.seatCount,seatSpacing:U.seatSpacing}));let P=C[0];p=P.origin,S=P.rotation,w=P.curve,v=P.seatSpacing}if(!Number.isFinite(v)||v<=0)continue;let _=t.sourceGroupId?Se(`${t.sourceGroupId}:${u}`):void 0,j=_&&Se(f.directSourceRowId)===_?_:void 0,B=j?gr(f.directReviewedSuffix):void 0,z=t.sourceGroupId&&f.rowLabel?Ie(f.rowLabel):"",A=t.sourceGroupId&&f.rowDisplayLabel?Ie(f.rowDisplayLabel):"",q=!!t.sourceGroupId&&f.rowDisplayLabel==="";c.push({label:z?a(z,g):i(),displayLabel:A||(q?"":String(u+1)),origin:p,rotation:S,curve:w,seatCount:C[0]?.seatCount??g,seatSpacing:v,...m?{table:m}:{},...x&&!m?{measured:!0}:{},...j?{directSourceRowId:j}:{},...B?{directReviewedSuffix:B}:{}});for(let P of C.slice(1))c.push({label:i(),displayLabel:String(u+1),origin:P.origin,rotation:P.rotation,curve:P.curve,seatCount:P.seatCount,seatSpacing:P.seatSpacing,measured:!0});l+=g}return{skip:null,rows:c,seats:l}}function Rd(t,e,n){T(t,n.categoryKey);let o=O(t,n.floorId),i=e.assetId,a=n.sectionId?o.objects.find(p=>p.type==="section"&&p.id===n.sectionId):void 0;if(n.sectionId&&!a)throw new Error("The opened section no longer exists on this floor");let r=new Map;for(let p of e.sections){if(a&&p.sectionId!==a.id)continue;let w=n.categoryKeyForSection?.(p)??n.categoryKey;T(t,w),r.set(p,w)}if(a&&!e.sections.some(p=>p.sectionId===a.id&&p.seatCount>0))return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[]};let s=a?e.sections.find(p=>p.sectionId===a.id&&p.seatCount>0):void 0;if(a&&s){let p=pr(o.objects,i,a.id).filter(w=>$(G(w),a.outline,a.holes));if(p.length)return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[{sectionId:a.id,name:s.name,reason:"section_not_empty",objectIds:p.map(w=>w.id)}]}}let c=o.objects.filter(p=>Yt(p,i,a?.id)),l=ha(c,e,a?.id),u=[],f=o.objects.filter(p=>Yt(p,i,a?.id)||br(p,i,a?.id)?(u.push(p.id),!1):!0);o.objects.splice(0,o.objects.length,...f);let g=[],h=[],y=[],b=new Set,I=0,S=fa(t);for(let p of e.sections){if(a&&p.sectionId!==a.id)continue;let w=ga(p,o.objects,i,e.seatPitch,S.ordinaryFor(p.name),S.direct,a?.id);if(w.skip){h.push(w.skip);continue}let v=[],m=[],x=0;for(let C of w.rows){let _={assetId:i,...p.sectionId?{sectionId:p.sectionId}:{}},j=r.get(p)??n.categoryKey;if(C.table){x+=1,v.push({type:"table",id:M(t,"t",n.idFactory,b),referenceScan:_,label:C.label,displayLabel:String(x),center:C.table.center,shape:"round",radius:C.table.radius,...C.table.seatArc!==void 0?{seatArc:C.table.seatArc}:{},rotation:C.rotation,seatCount:C.seatCount,categoryKey:j});continue}let B={type:"row",id:M(t,"r",n.idFactory,b),referenceScan:{..._,...C.directSourceRowId?{directSourceRowId:C.directSourceRowId}:{},...C.directReviewedSuffix?{directReviewedSuffix:C.directReviewedSuffix}:{}},label:C.label,...C.displayLabel!==void 0?{displayLabel:C.displayLabel}:{},origin:C.origin,rotation:C.rotation,curve:C.curve,seatCount:C.seatCount,seatSpacing:C.seatSpacing,categoryKey:j,...C.directSourceRowId&&l.has(C.directSourceRowId)?{overrides:structuredClone(l.get(C.directSourceRowId))}:{}};v.push(B),C.measured&&m.push(B)}if(o.objects.push(...v),m.length&&!p.sourceGroupId){let C=F(t).find(_=>_.id===o.floorId);ma(t,m,C?.focalPoint??t.focalPoint,o.floorId,n.idFactory)}for(let C of v)y.push(C.id);g.push({sectionId:p.sectionId,name:p.name,seats:w.seats,rows:v.length}),I+=w.seats}return{floorId:o.floorId,assetId:i,createdRowIds:y,removedRowIds:u,totalSeats:I,perSection:g,skipped:h}}function ma(t,e,n,o,i){let a=e.map(h=>W(h)),r=a.flat(),s=n??{x:r.reduce((h,y)=>h+y.x,0)/r.length,y:Math.min(...r.map(h=>h.y))-1},c=e.map((h,y)=>{let b=a[y],I=b.map((p,w)=>{let v=b[Math.max(0,w-1)],m=b[Math.min(b.length-1,w+1)],x=Math.hypot(m.x-v.x,m.y-v.y);return x<=0?Math.hypot(p.x-s.x,p.y-s.y):Math.abs((p.x-s.x)*(-(m.y-v.y)/x)+(p.y-s.y)*((m.x-v.x)/x))}).sort((p,w)=>p-w),S=b.reduce((p,w)=>p+w.x,0)/b.length;return{row:h,depth:I[Math.floor(I.length/2)],along:S}}).sort((h,y)=>h.depth-y.depth||h.along-y.along),l=c.slice(1).map((h,y)=>h.depth-c[y].depth).filter(h=>h>1e-6).sort((h,y)=>h-y),u=l.length?l[Math.floor(l.length*.75)]:1/0,f=[],g=-1/0;for(let h of c)(!f.length||h.depth-g>u*.45)&&(f.push([]),g=h.depth),f[f.length-1].push(h.row);f.forEach((h,y)=>{let b=L(y);h.sort((I,S)=>{let p=W(I),w=W(S);return p.reduce((v,m)=>v+m.x,0)/p.length-w.reduce((v,m)=>v+m.x,0)/w.length});for(let I of h)I.displayLabel=b;h.length>=2&&h.length<=64&&sr(t,{floorId:o,rowIds:h.map(I=>I.id),boundaries:h.slice(1).map(()=>"break"),displayLabel:b,idFactory:i})})}function yr(t,e,n={}){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(b=>o.objects.find(I=>(I.type==="table"||I.type==="booth")&&I.id===b)),r=i.filter((b,I)=>!a[I]);if(r.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:r});let s=a[0].type;if(a.some(b=>b.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[b,I,S]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(I)||I<1||I>S)throw new d("invalid_operation",`${b} must be a whole number from 1 to ${S}`);for(let[b,I]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(I)||I<30||I>2e3)throw new d("invalid_operation",`${b} 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 u=a.reduce((b,I)=>b+(I.type==="table"?I.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(b=>b.objects):t.objects).reduce((b,I)=>b+(I.type==="row"||I.type==="table"?I.seatCount:I.type==="gaArea"?Math.max(0,Math.floor(I.capacity)):I.type==="booth"?1:0),0),h=u*(c-1),y=n.maxInventory??1e5;if(g+h>y)throw new d("invalid_operation",`Grid inventory would exceed the ${y} unit event limit`);return{target:o,sources:a,preview:{floorId:o.floorId,kind:s,sourceIds:i,sourceCount:i.length,cells:c,createdCount:l,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:a.filter(b=>!!b.referenceInventorySource).length*(c-1)}}}function Pd(t,e,n={}){return yr(t,e,n).preview}function kd(t,e,n={}){let{target:o,sources:i,preview:a}=yr(t,e,n),r=new Set,s=new Set((t.floors?.length?t.floors.flatMap(f=>f.objects):t.objects).flatMap(f=>"label"in f&&f.label?[f.label]:[])),c=[],l=(f,g)=>{let h=Math.max(2,g),y=I=>{let S=`-${I}`;return`${f.slice(0,Math.max(1,80-S.length))}${S}`},b=y(h);for(;s.has(b);)b=y(++h);return s.add(b),b},u=1;for(let f=0;f<e.rows;f++)for(let g=0;g<e.columns;g++)if(!(f===0&&g===0)){u+=1;for(let h of i){let y=structuredClone(h);y.id=M(t,y.type,e.idFactory,r),y.label=l(h.label,u),y.center={x:h.center.x+g*e.stepX,y:h.center.y+f*e.stepY},delete y.referenceInventorySource,c.push(y)}}return o.objects.push(...c),{...a,createdIds:c.map(f=>f.id)}}function ba(t,e){let n=t?{...t}:{};return e.size===null?delete n.size:e.size!==void 0&&(n.size=e.size),e.color===null?delete n.color:e.color!==void 0&&(n.color=D(e.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var pa=new Set(qe.map(t=>t.key));function lt(t){return`${t.rowId}:${t.index}`}function Nd(t){let e=t.lastIndexOf(":"),n=e>0?t.slice(0,e):"",o=e>0?Number(t.slice(e+1)):Number.NaN;if(!n||!Number.isInteger(o)||o<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:n,index:o}}function ya(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,ke(t.glyph)||delete t.glyph;let n=Kn(t);if(n.length?t.accessibility=n: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"&&Un(e,t)}function wa(t){return Object.keys(t).every(e=>e==="index")}function wr(t,e,n){if(!n.length)throw new d("invalid_operation","At least one seat is required");let o=O(t,e),i=[],a=new Set,r=new Map;for(let s of n){let c=lt(s);if(a.has(c))continue;a.add(c);let l=o.objects.find(u=>(u.type==="row"||u.type==="table")&&u.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}),r.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:r}}function Ir(t,e){let n=wr(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(n.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(n.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&&T(t,e.patch.categoryKey),e.patch.glyph!=null&&!ke(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(r=>!pa.has(r));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 n.refs){let r=n.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??r?.wheelchairSpaceType,c=e.patch.skip===null?!1:e.patch.skip??r?.skip??!1;if(s&&c)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:lt(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=se(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 r=e.patch[a];if(r!=null&&!Number.isFinite(r))throw new d("invalid_operation",`${a} must be finite`,{[a]:r})}e.patch.labelStyle!=null&&re(e.patch.labelStyle,"Seat");let i=!1;return n.refs.forEach((a,r)=>{let s=n.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),u=l.find(g=>g.index===a.index);u||(u={index:a.index},l.push(u));let f=u.viewFromSeatUrl;for(let g of o){let h=e.patch[g];if(g==="wheelchairSpaceType"&&h==null)delete u.wheelchairSpaceType,u.accessibility&&(u.accessibility=u.accessibility.filter(y=>y!=="wheelchair"),u.accessibility.length||delete u.accessibility),delete u.accessible;else if(h==null)delete u[g];else if(g==="accessibility")u.accessibility=[...new Set(h)],delete u.accessible;else if(g==="commercial")u.commercial={...u.commercial,...h};else if(g==="labelStyle"){let y=ba(u.labelStyle,h);y?u.labelStyle=y:delete u.labelStyle}else Object.assign(u,{[g]:h})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==f&&delete u.viewFromSeatMeta,e.labelPrefix!==void 0&&(u.label=`${e.labelPrefix}${r+1}`),e.displayLabelPrefix!==void 0&&(u.displayLabel=`${e.displayLabelPrefix}${r+1}`),ya(u,s),wa(u)&&(s.overrides=l.filter(g=>g!==u)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(lt)}}function Gd(t,e){let n=wr(t,e.floorId,e.seats),o=!1;for(let[i,a]of n.owners){if(!a.overrides?.length)continue;let r=new Set(n.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!r.has(c.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:n.floorId,changed:o,seatIds:n.refs.map(lt)}}function Ud(t,e){let n=O(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(w=>n.objects.find(v=>v.type==="row"&&v.id===w)),a=o.filter((w,v)=>!i[v]);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&&T(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 w=e.patch.seatNumbering,v=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(w.scheme!==void 0&&!v.includes(w.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${w.scheme}. Expected one of ${v.join(", ")}.`);if(w.prefix!==void 0&&(typeof w.prefix!="string"||w.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(w.endAt!==void 0&&w.endAt!==null&&(!Number.isInteger(w.endAt)||w.endAt<0||w.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:r,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:u,displayType:f,aisleSeats:g,...h}=e.patch,y=u===void 0?{}:{displayLabel:u},b=me(y,"Row"),I=f===void 0?void 0:po(f,"Row");if(r!==void 0&&re(r,"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(h.labelPresentation!==void 0&&Ze(h.labelPresentation,"Row"),g!=null&&!no(g))throw new d("invalid_operation","Row aisleSeats must be one of start, end, both, none (or null for automatic)");let S=w=>JSON.stringify({origin:w.origin,rotation:w.rotation,curve:w.curve,seatCount:w.seatCount,seatSpacing:w.seatSpacing,path:w.path??null}),p=!1;for(let w of i){let v=JSON.stringify(w),m=S(w),x=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?G(w):null;if(Object.assign(w,structuredClone(h)),w.overrides&&e.patch.seatCount!==void 0&&(w.overrides=w.overrides.filter(C=>C.index<w.seatCount),w.overrides.length||(w.overrides=void 0)),x){let C=G(w);w.origin={x:w.origin.x+x.x-C.x,y:w.origin.y+x.y-C.y}}if(JSON.stringify(w)!==v&&(p=!0),S(w)!==m&&(delete w.arcFanGeneration,delete w.rowBlockGeneration),r!==void 0){let C=JSON.stringify(w.labelPresentation??null),_=be(w.labelPresentation,r);_?w.labelPresentation=_:delete w.labelPresentation,JSON.stringify(w.labelPresentation??null)!==C&&(p=!0)}if(s!==void 0){let C=JSON.stringify(w.labelPresentation??null),_=w.labelPresentation?structuredClone(w.labelPresentation):{};_.positionPreset=s,_.visible=s!=="none",delete _.position,w.labelPresentation=_,JSON.stringify(w.labelPresentation??null)!==C&&(p=!0)}if(c!==void 0||l!==void 0){let C=JSON.stringify(w.labelPresentation??null),_=w.labelPresentation?structuredClone(w.labelPresentation):{};c===null?delete _.rotation:c!==void 0&&(_.rotation=c),l!==void 0&&(_.style=l),w.labelPresentation=_,JSON.stringify(w.labelPresentation??null)!==C&&(p=!0)}if(I!==void 0){let C=w.displayType;I?w.displayType=I:delete w.displayType,w.displayType!==C&&(p=!0)}if(g!==void 0){let C=w.aisleSeats;g===null?delete w.aisleSeats:w.aisleSeats=g,w.aisleSeats!==C&&(p=!0)}if(u!==void 0){let C=w.displayLabel;b?delete w.displayLabel:w.displayLabel=y.displayLabel,w.displayLabel!==C&&(p=!0)}}return{floorId:n.floorId,changed:p,rowIds:o}}var Ia=3;function dt(t){return(t%360+360)%360}function Sa(t){let e=t.rotation*ee;return{x:Math.cos(e),y:Math.sin(e)}}function va(t,e){let n=Math.abs(dt(t-e));return n>180&&(n=360-n),n}function ve(t,e,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y}function Sr(t){let e=0,n=0;for(let i of t){let a=2*i.rotation*ee;e+=Math.cos(a),n+=Math.sin(a)}let o=(e===0&&n===0?0:Math.atan2(n,e))/2;return{x:Math.cos(o),y:Math.sin(o)}}function xa(t,e,n){if(t.origin={x:t.origin.x+e,y:t.origin.y+n},t.path){let o=i=>({x:i.x+e,y:i.y+n});t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)}}}function vr(t,e){let n=Sr(t),o={x:-n.y,y:n.x},i=G(t[0]),a=t.map(c=>({row:c,coord:ve(G(c),i,o)})).sort((c,l)=>c.coord-l.coord),r=a[0].coord,s=!1;return a.forEach((c,l)=>{let u=r+l*e-c.coord;Math.abs(u)>1e-6&&(xa(c.row,o.x*u,o.y*u),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Ca(t,e){let n={x:-e.y,y:e.x},o=G(t[0]),i=t.map(r=>ve(G(r),o,n)).sort((r,s)=>r-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Oa(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=W(t),n=e[0],o=e[e.length-1],i=o.x-n.x,a=o.y-n.y,r=Math.hypot(i,a);t.path&&(t.origin={...n},t.seatSpacing=Math.max(1,r/(t.seatCount-1))),r>1e-6&&(t.rotation=dt(Math.atan2(a,i)/ee)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Ra(t,e){let n=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(!n.has(i))return i}return`${e}-${Date.now().toString(36)}`}function Jd(t,e){let n=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(m=>n.objects.find(x=>x.type==="row"&&x.id===m)),a=o.filter((m,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 r=i,s=r.filter(m=>m.path||m.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(m=>m.id)});let c=r[0],l=r.find(m=>va(m.rotation,c.rotation)>Ia);if(l)throw new d("invalid_operation","Rows must be parallel to merge. They point in different directions.",{rowIds:[c.id,l.id]});let u=Sa(c),f={x:-u.y,y:u.x},g=Math.max(8,c.seatSpacing*.6),h=r.find(m=>Math.abs(ve(m.origin,c.origin,f))>g);if(h){let m=Math.round(Math.abs(ve(h.origin,c.origin,f)));throw new d("invalid_operation",`Rows must lie on the same line to merge: a selected row is offset ${m} units from the first.`,{rowIds:[c.id,h.id]})}let y=r.slice().sort((m,x)=>ve(m.origin,c.origin,u)-ve(x.origin,c.origin,u)),b=y.reduce((m,x)=>m+x.seatCount,0);if(b>300)throw new d("invalid_operation",`A merged row would have ${b} seats, over the 300-seat row limit. Merge fewer rows.`);let I=y[0];ro(y,I);let S=[],p=0;for(let m of y){if(m.overrides)for(let x of m.overrides)S.push({...structuredClone(x),index:x.index+p});p+=m.seatCount}I.seatCount=b,I.curve=0,delete I.path,S.length?I.overrides=S:delete I.overrides,delete I.arcFanGeneration,delete I.rowBlockGeneration;let w=y.slice(1).map(m=>m.id),v=new Set(w);for(let m=n.objects.length-1;m>=0;m--)v.has(n.objects[m].id)&&n.objects.splice(m,1);return{floorId:n.floorId,changed:!0,rowId:I.id,removedRowIds:w,seatCount:b}}function qd(t,e){let n=O(t,e.floorId),o=n.objects.find(h=>h.type==="row"&&h.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 r=W(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:M(t,"r",e.idFactory,new Set),label:Ra(n.objects,o.label),origin:{...r[a]},rotation:dt(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 h=structuredClone(o.labelPresentation);delete h.position,l.labelPresentation=h}let u=[],f=[];if(o.overrides)for(let h of o.overrides)h.index<a?u.push(structuredClone(h)):f.push({...structuredClone(h),index:h.index-a});oo(o,o,l),o.seatCount=a,o.curve=s*(a-1),u.length?o.overrides=u:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,f.length&&(l.overrides=f);let g=n.objects.indexOf(o);return n.objects.splice(g+1,0,l),{floorId:n.floorId,changed:!0,rowId:o.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function Hd(t,e){let n=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=>n.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 r=vr(i,e.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:e.gap}}function Vd(t,e){let n=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(g=>n.objects.find(h=>h.type==="row"&&h.id===g)),a=o.filter((g,h)=>!i[h]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,s=()=>JSON.stringify(r.map(g=>[g.origin,g.rotation,g.curve,g.path??null,g.seatSpacing])),c=s();for(let g of r)Oa(g);let l=Sr(r),u=dt(Math.atan2(l.y,l.x)/ee);for(let g of r)g.rotation=u;let f=Ca(r,l);return vr(r,f),{floorId:n.floorId,changed:s()!==c,rowIds:o,gap:f}}import Zt from"polygon-clipping";var xr=100,Cr=512,Qt=8192,Fr=64,Or=1e7,N=1e-7;function jr(t,e){return Math.abs(t.x-e.x)<=N&&Math.abs(t.y-e.y)<=N}function Tr(t){let e=t.map(n=>({x:n.x,y:n.y}));for(;e.length>1&&jr(e[0],e[e.length-1]);)e.pop();return e}function Le(t,e,n){let o=X(e,n,t);return Math.abs(o)>N?!1:t.x>=Math.min(e.x,n.x)-N&&t.x<=Math.max(e.x,n.x)+N&&t.y>=Math.min(e.y,n.y)-N&&t.y<=Math.max(e.y,n.y)+N}function Er(t,e,n,o){let i=X(t,e,n),a=X(t,e,o),r=X(n,o,t),s=X(n,o,e);return(i>N&&a<-N||i<-N&&a>N)&&(r>N&&s<-N||r<-N&&s>N)?!0:Math.abs(i)<=N&&Le(n,t,e)||Math.abs(a)<=N&&Le(o,t,e)||Math.abs(r)<=N&&Le(t,n,o)||Math.abs(s)<=N&&Le(e,n,o)}function _a(t){for(let e=0;e<t.length;e+=1){let n=(e+1)%t.length;for(let o=e+1;o<t.length;o+=1){let i=(o+1)%t.length;if(!(e===o||n===o||i===e)&&Er(t[e],t[n],t[o],t[i]))return!0}}return!1}function Rr(t,e){return t.some((n,o)=>e.some((i,a)=>Er(n,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function en(t,e){return!e.some((n,o)=>Le(t,n,e[(o+1)%e.length]))&&$(t,e,void 0)}function ft(t,e,n){let o=Tr(t);if(o.length<3||o.length>Cr||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Or||Math.abs(i.y)>Or||jr(i,o[(a+1)%o.length]))||Math.abs(Ve(o))<=N||_a(o))throw new d("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${Cr} finite vertices per ring.`,{gaAreaId:n,ring:e});return o}function Aa(t){let e=ft(t.points,"outline",t.id),n=t.holes??[];if(!Array.isArray(n)||n.length>Fr)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=n.map(i=>ft(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=>en(s,e))||Rr(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(Rr(a,o[s])||en(a[0],o[s])||en(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 ut(t){return t.map(e=>[e.x,e.y])}function _r(t){return Tr(t.map(([e,n])=>({x:e,y:n})))}function Ar(t){return Math.abs(t.reduce((e,n,o)=>{let i=t[(o+1)%t.length];return e+n[0]*i[1]-i[0]*n[1]},0))/2}function Pa(t){return t.reduce((e,n)=>e+(Ar(n[0]??[])-n.slice(1).reduce((o,i)=>o+Ar(i),0)),0)}function tn(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(tn).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${tn(e[n])}`).join(",")}}`}function Pr(t,e,n){let o=t[e];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>n)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${n} characters before joining.`,{gaAreaId:t.id,field:e});return i}function kr(t){return tn({categoryKey:t.categoryKey,displayLabel:Pr(t,"displayLabel",80),displayType:Pr(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Mr(t,e){let n=Math.min(...t.points.map(i=>i.y)),o=Math.min(...t.points.map(i=>i.x));return[n,o,e]}function ka(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function Dr(t,e,n={}){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>xr)throw new d("invalid_operation",`Join Areas supports at most ${xr} areas at once`);let a=i.map(R=>o.objects.find(k=>k.type==="gaArea"&&k.id===R)),r=i.filter((R,k)=>!a[k]);if(r.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:r});let s=a,c=s.find(R=>Ae(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});T(t,s[0].categoryKey);let l=kr(s[0]),u=s.find(R=>kr(R)!==l);if(u)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,u.id]});let f=Pe(t).objectToSection,g=f.get(s[0].id)??"__ungrouped__",h=s.find(R=>(f.get(R.id)??"__ungrouped__")!==g);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:[g,f.get(h.id)??"__ungrouped__"]});let y=s.reduce((R,k)=>{if(!Number.isInteger(k.capacity)||k.capacity<1||k.capacity>J)throw new d("invalid_operation",`GA area ${k.id} has invalid capacity`,{gaAreaId:k.id});return R+k.capacity},0);if(y>J)throw new d("invalid_operation",`Joined GA capacity would be ${y}, over the ${J}-unit area limit`,{capacity:y});let b=V(t).reduce((R,k)=>R+le(k),0),I=n.maxInventory??1e5;if(b>I)throw new d("invalid_operation",`Chart inventory exceeds the ${I}-unit publication limit`,{inventory:b});let S=s.map(Aa),p=S.reduce((R,k)=>R+k.outer.length+k.holes.reduce((E,K)=>E+K.length,0),0);if(p>Qt)throw new d("invalid_operation",`Join Areas supports at most ${Qt} source vertices`,{vertexCount:p});let w;try{let R=S.map(K=>[ut(K.outer)]);if(w=Zt.union(R[0],...R.slice(1)),w.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:w.length});let k=S.flatMap(K=>K.holes.map(fe=>[ut(fe)]));k.length&&(w=Zt.difference(w,...k));let E=S.findIndex(K=>{let fe=[ut(K.outer),...K.holes.map(ut)];return Pa(Zt.intersection(fe,w))<=N});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(w.length!==1||!w[0]?.length)throw new d("invalid_operation","Joining these boundaries would create disconnected sellable surfaces; adjust the outlines or cutouts first.",{surfaceCount:w.length});let v=_r(w[0][0]),m=w[0].slice(1).map(_r),x=v.length+m.reduce((R,k)=>R+k.length,0);if(m.length>Fr||x>Qt)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:m.length,vertexCount:x});ft(v,"outline",s[0].id),m.forEach(R=>ft(R,"cutout",s[0].id));let C=new Map(o.objects.map((R,k)=>[R.id,k])),_=s.slice().sort((R,k)=>ka(Mr(R,C.get(R.id)??Number.MAX_SAFE_INTEGER),Mr(k,C.get(k.id)??Number.MAX_SAFE_INTEGER))),j=_[0],B=structuredClone(t),z=O(B,o.floorId),A=z.objects.find(R=>R.type==="gaArea"&&R.id===j.id);A.points=structuredClone(v),m.length?A.holes=structuredClone(m):delete A.holes;let q=new Set(_.slice(1).map(R=>R.id));for(let R=z.objects.length-1;R>=0;R-=1)q.has(z.objects[R].id)&&z.objects.splice(R,1);let P=Pe(B).objectToSection.get(j.id)??"__ungrouped__";if(P!==g)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:j.id,beforeSectionId:g,afterSectionId:P});let U=[],H=new Set;for(let R of _){if(!Hn(R))throw new d("invalid_operation",`GA area ${R.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:R.id});let k=te(R);if(k.length!==R.capacity||k.some(E=>H.has(E)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:R.id});k.forEach(E=>H.add(E)),U.push(...Vn(R))}if(U.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let ae=new Set(s.map(R=>R.id));for(let R of V(t).filter(k=>k.type==="gaArea"&&!ae.has(k.id))){let k=te(R).find(E=>H.has(E));if(k)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:k,gaAreaId:R.id})}let Je=_.slice(1).map(R=>R.id);return{floorId:o.floorId,areaId:j.id,survivorLabel:j.label,removedAreaIds:Je,sourceAreaCount:_.length,capacity:y,inventorySegmentCount:U.length,outerVertexCount:v.length,holeCount:m.length,sectionId:g,points:v,...m.length?{holes:m}:{},segments:U}}function nu(t,e,n={}){let{segments:o,...i}=Dr(t,e,n);return i}function ou(t,e,n={}){let o=Dr(t,e,n),i=O(t,o.floorId),a=i.objects.find(u=>u.type==="gaArea"&&u.id===o.areaId);a.points=structuredClone(o.points),o.holes?.length?a.holes=structuredClone(o.holes):delete a.holes;let r=i.objects.filter(u=>u.type==="gaArea"&&(u.id===o.areaId||o.removedAreaIds.includes(u.id))).reduce((u,f)=>u+(f.wheelchairPlaces??0),0);a.capacity=o.capacity,a.inventorySegments=structuredClone(o.segments),r>0&&(a.wheelchairPlaces=Math.min(r,o.capacity));let s=new Set(o.removedAreaIds);for(let u=i.objects.length-1;u>=0;u-=1)s.has(i.objects[u].id)&&i.objects.splice(u,1);let{segments:c,...l}=o;return{...l,changed:!0}}function hu(t,e){let n=O(t,e.floorId),o=n.objects.find(c=>c.type==="shape"&&c.id===e.shapeId);if(!o)throw new d("object_not_found",`Unknown shape id: ${e.shapeId}`,{shapeId:e.shapeId});if(o.role==="stage")throw new d("invalid_operation","A stage keeps its generated outline; turn it back into a shape first");if(o.kind==="polygon")return{floorId:n.floorId,changed:!1,shapeId:o.id};if(o.kind!=="rect"||o.x==null||o.y==null||o.width==null||o.height==null||![o.x,o.y,o.width,o.height].every(Number.isFinite)||o.width<=0||o.height<=0)throw new d("invalid_operation","Only a rectangle can become a custom outline");let{x:i,y:a,width:r,height:s}=o;return o.points=[{x:i,y:a},{x:i+r,y:a},{x:i+r,y:a+s},{x:i,y:a+s}],o.kind="polygon",delete o.x,delete o.y,delete o.width,delete o.height,delete o.cornerRadius,_e(o),{floorId:n.floorId,changed:!0,shapeId:o.id}}function gu(t,e){let n=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=>n.objects.find(u=>u.type==="shape"&&u.id===l)),a=o.filter((l,u)=>!i[u]);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 r=structuredClone(e.patch);if(!Object.keys(r).length)throw new d("invalid_operation","At least one shape change is required");if(r.label!==void 0){if(o.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(r.label!==null){if(r.label=r.label.normalize("NFKC").trim(),!r.label)r.label=null;else if(r.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(r.labelStyle!==void 0){let l=i.filter(u=>u.role!=="stage");if(l.length)throw new d("invalid_operation","Shape label styling applies only to stages",{shapeIds:l.map(u=>u.id)});if(r.labelStyle.size!==void 0&&r.labelStyle.size!==null&&(!Number.isFinite(r.labelStyle.size)||r.labelStyle.size<St||r.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${St} to ${72}`);if(r.labelStyle.color!==void 0&&r.labelStyle.color!==null&&(r.labelStyle.color=D(r.labelStyle.color,"Shape label color")),r.labelStyle.fontFamily!==void 0&&r.labelStyle.fontFamily!==null&&(r.labelStyle.fontFamily=r.labelStyle.fontFamily.normalize("NFKC").trim(),!r.labelStyle.fontFamily||r.labelStyle.fontFamily.length>120))throw new d("invalid_operation","Stage label fontFamily must contain 1 to 120 characters");if(r.labelStyle.direction!==void 0&&r.labelStyle.direction!==null&&!un.includes(r.labelStyle.direction))throw new d("invalid_operation","Stage label direction must be horizontal, vertical, or auto");for(let u of["bold","italic","underline"]){let f=r.labelStyle[u];if(f!=null&&typeof f!="boolean")throw new d("invalid_operation",`Stage label ${u} must be a boolean`)}}if(r.fill!==void 0&&r.fill!==null&&(r.fill=D(r.fill,"Shape fill")),r.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(r.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(r.stroke!==void 0&&r.stroke!==null){if(!Number.isFinite(r.stroke.width)||r.stroke.width<.5||r.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");r.stroke={color:D(r.stroke.color,"Shape stroke"),width:r.stroke.width}}if(r.cornerRadius!==void 0&&r.cornerRadius!==null&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(r.opacity!==void 0&&r.opacity!==null&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(r.heightM!==void 0&&r.heightM!==null&&(!Number.isFinite(r.heightM)||r.heightM<.05||r.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(r.rotation!==void 0&&r.rotation!==null){if(!Number.isFinite(r.rotation))throw new d("invalid_operation","Shape rotation must be a finite number of degrees");r.rotation=ie("shape",r.rotation)}if(r.edgeCurvature!==void 0){if(o.length!==1)throw new d("invalid_operation","edgeCurvature can be changed only for one shape at a time");let l=i[0];if((r.kind??l.kind)!=="polygon"||(l.points?.length??0)<3)throw new d("invalid_operation","Curved sides apply only to custom outline (polygon) shapes",{shapeIds:[l.id]});if(r.edgeCurvature!==null){if(!Array.isArray(r.edgeCurvature)||r.edgeCurvature.some(f=>!Number.isFinite(f)||f<-100||f>100))throw new d("invalid_operation","Edge curvature values must be numbers from -100 to 100");if(r.edgeCurvature.length&&r.edgeCurvature.length!==l.points.length)throw new d("invalid_operation",`edgeCurvature needs one value per side: this shape has ${l.points.length} sides`,{shapeIds:[l.id]});r.edgeCurvature.some(f=>Math.abs(f)>.5)||(r.edgeCurvature=null)}let u={kind:"polygon",points:l.points,edgeCurvature:r.edgeCurvature??void 0,holes:l.holes};Pn(u).forEach((f,g)=>{if(!kn(u,f))throw new d("invalid_operation",`That curve would cross cut-out ${g+1}. Move the cut-out or use less curve.`,{shapeIds:[l.id]})})}if(r.eventConfigurationIds!==void 0&&r.eventConfigurationIds!==null){let l=r.eventConfigurationIds.map(u=>u.normalize("NFKC").trim());if(!l.length||l.length>20||l.some(u=>!u||u.length>100)||new Set(l).size!==l.length)throw new d("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");r.eventConfigurationIds=l}if(r.lineCap!==void 0&&r.lineCap!==null&&!so.includes(r.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!co.includes(r.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,u]of[["startEnding",r.startEnding],["endEnding",r.endEnding]])if(u!=null&&!lo.includes(u))throw new d("invalid_operation",`Shape ${l} must be none or arrow`);if(r.lineCap!=null||r.lineJoin!=null||r.startEnding!=null||r.endEnding!=null){let l=i.filter(u=>!jt(r.kind??u.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(u=>u.id)})}let c=!1;for(let l of i){let u=JSON.stringify(l);if(r.label===null?delete l.label:r.label!==void 0&&(l.label=r.label),r.labelStyle!==void 0){let f={...l.labelStyle};r.labelStyle.size===null?delete f.size:r.labelStyle.size!==void 0&&(f.size=r.labelStyle.size),r.labelStyle.color===null?delete f.color:r.labelStyle.color!==void 0&&(f.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete f.fontFamily:r.labelStyle.fontFamily!==void 0&&(f.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete f.bold:r.labelStyle.bold!==void 0&&(f.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete f.italic:r.labelStyle.italic===!0&&(f.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete f.underline:r.labelStyle.underline===!0&&(f.underline=!0),r.labelStyle.direction===null||r.labelStyle.direction==="horizontal"?delete f.direction:r.labelStyle.direction!==void 0&&(f.direction=r.labelStyle.direction),Object.keys(f).length?l.labelStyle=f:delete l.labelStyle}if(r.fill===null?delete l.fill:r.fill!==void 0&&(l.fill=r.fill),r.kind!==void 0&&(l.kind=r.kind,jt(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),r.stroke===null?delete l.stroke:r.stroke!==void 0&&(l.stroke={...r.stroke}),r.opacity===null?delete l.opacity:r.opacity!==void 0&&(l.opacity=r.opacity),r.heightM===null?delete l.heightM:r.heightM!==void 0&&(l.heightM=r.heightM),r.rotation===null||r.rotation===0?delete l.rotation:r.rotation!==void 0&&(l.rotation=r.rotation),r.edgeCurvature===null?delete l.edgeCurvature:r.edgeCurvature!==void 0&&(l.edgeCurvature=[...r.edgeCurvature]),r.kind!==void 0&&r.kind!=="polygon"&&(delete l.edgeCurvature,delete l.holes),r.eventConfigurationIds===null?delete l.eventConfigurationIds:r.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...r.eventConfigurationIds]),r.lineCap===null?delete l.lineCap:r.lineCap!==void 0&&(l.lineCap=r.lineCap),r.lineJoin===null?delete l.lineJoin:r.lineJoin!==void 0&&(l.lineJoin=r.lineJoin),r.startEnding===null?delete l.startEnding:r.startEnding!==void 0&&(l.startEnding=r.startEnding),r.endEnding===null?delete l.endEnding:r.endEnding!==void 0&&(l.endEnding=r.endEnding),r.cornerRadius===null)delete l.cornerRadius;else if(r.cornerRadius!==void 0){let f=Math.min(l.width??1/0,l.height??1/0),g=Number.isFinite(f)?f/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,g)):r.cornerRadius}JSON.stringify(l)!==u&&(_e(l),c=!0)}return{floorId:n.floorId,changed:c,shapeIds:o}}function Lr(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(u=>!Number.isFinite(u.x)||!Number.isFinite(u.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let n=e.map(u=>u.x),o=e.map(u=>u.y),i=Math.min(...n),a=Math.max(...n),r=Math.min(...o),s=Math.max(...o),c=Math.max(1,a-i),l=Math.max(1,s-r);return{cx:i+c/2,cy:r+l/2,width:c,height:l}}function mu(t,e){let n=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(r=>r.shapeId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Shape ids must be unique");let i=e.updates.map(r=>{if(![r.width,r.height].every(Number.isFinite)||r.width<8||r.height<8||r.width>1e4||r.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:r.shapeId});let s=n.objects.find(l=>l.type==="shape"&&l.id===r.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${r.shapeId}`,{shapeId:r.shapeId});let c=s.role==="stage"?Lr(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(I=>!Number.isFinite(I.x)||!Number.isFinite(I.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let u=l.map(I=>I.x),f=l.map(I=>I.y),g=Math.min(...u),h=Math.max(...u),y=Math.min(...f),b=Math.max(...f);return{cx:(g+h)/2,cy:(y+b)/2,width:Math.max(1,h-g),height:Math.max(1,b-y)}})();return{shape:s,update:r,box:c}}),a=!1;for(let{shape:r,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(r.kind==="rect"||r.kind==="ellipse")r.x=c.cx-s.width/2,r.y=c.cy-s.height/2,r.width=s.width,r.height=s.height;else{let l=s.width/c.width,u=s.height/c.height,f=g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*u});r.points=(r.points??[]).map(f),r.holes&&(r.holes=r.holes.map(g=>g.map(f))),(r.x!=null||r.y!=null||r.width!=null||r.height!=null||r.role==="stage")&&(r.x=c.cx-s.width/2,r.y=c.cy-s.height/2,r.width=s.width,r.height=s.height)}a=!0}return{floorId:n.floorId,changed:a,shapes:i.map(({shape:r,update:s})=>({id:r.id,width:s.width,height:s.height}))}}function bu(t,e){let n=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(En.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=n.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:Lr(c)}}),r=!1;for(let s of a)s.box&&(s.shape.points=Ln({kind:s.stageKind,...s.box}),s.shape.kind="polygon",delete s.shape.edgeCurvature,delete s.shape.holes,s.shape.stageKind=s.stageKind,r=!0);return{floorId:n.floorId,changed:r,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function Su(t){return[...an(t)].map(([e,n])=>({key:e,...n}))}function Fa(t){if(!Array.isArray(t))return an(t);let e=new Map;for(let{key:n,target:o,evidence:i}of t)e.set(n,{target:o,evidence:i});return e}function an(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let n of F(t)){n.confidenceEvidence&&e.set(`floor:${n.id}`,{target:{scope:"floor",floorId:n.id},evidence:n.confidenceEvidence});for(let o of n.objects){let i=`floor:${n.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&e.set(i,{target:{scope:o.type,floorId:n.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&e.set(`${i}:segmented`,{target:{scope:"row",floorId:n.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&e.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:n.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return e}function ht(t){return Array.isArray(t)?t.map(ht):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[n])=>e.localeCompare(n)).map(([e,n])=>[e,ht(n)]))}function ja(t,e){return JSON.stringify(ht(t))===JSON.stringify(ht(e))}function nn(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function Ta(t){return t?t.status==="retracted"?"retract":nn(t)?"approve":"set":"clear"}function Ea(t,e){let n=Fa(t),o=an(e),i=[...new Set([...n.keys(),...o.keys()])].sort(),a=[];for(let r of i){let s=n.get(r),c=o.get(r);if(s&&c&&ja(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:Ta(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function vu(t,e){return Ea(t,e).some(n=>nn(n.before)||nn(n.after))}var Da=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),La=new Set(["generated","geometry-verified","configuration-verified"]),Na=new Set(["none","comparable-build-reference","actual-build-checked"]),Ga=new Set(["clear","partial","obstructed"]);function on(t){return t.toISOString().slice(0,10)}function rn(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function Ce(t,e,n){if(!rn(t,e))throw new d("invalid_operation",`Confidence evidence ${n} is invalid`,{field:n});return t}function xe(t,e,n){if(t!==void 0)return Ce(t,e,n)}function gt(t,e,n){let o=n?[O(t,n)]:F(t).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(r=>r.id===e);if(a)return{floorId:i.floorId,object:a}}throw new d("object_not_found",`Unknown chart object: ${e}`,{objectId:e,floorId:n})}function Nr(t,e){let n=F(t),o=e?n.find(i=>i.id===e):n[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return o}function Ne(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return Nr(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=gt(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 n=gt(t,e.objectId,e.floorId);if(e.scope==="row"&&n.object.type!=="row")throw new d("invalid_operation","Row evidence requires a row id",{objectId:e.objectId});if(e.scope==="section"&&n.object.type!=="section")throw new d("invalid_operation","Section evidence requires a section id",{objectId:e.objectId});if(n.object.type==="row"||n.object.type==="section")return n.object.confidenceEvidence;throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:n.object.type})}function mt(t,e,n){if(e.scope==="venue")return n?t.confidenceEvidence=n:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=Nr(t,e.floorId);return n?i.confidenceEvidence=n: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=gt(t,e.objectId,e.floorId);return Ir(t,{floorId:i.floorId,seats:[{rowId:e.objectId,index:e.seatIndex}],patch:{confidenceEvidence:n??null}}),{floorId:i.floorId,objectId:e.objectId}}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let o=gt(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 n?o.object.confidenceEvidence=n:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function Ka(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!rn(t.label,80)||!rn(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(!Ga.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(n=>Ce(n,80,"occluder label"));return{label:t.label,methodLabel:t.methodLabel,totalRayCount:t.totalRayCount,clearRayCount:t.clearRayCount,classification:t.classification,...e?.length?{occluderLabels:e}:{}}}function $a(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(!Da.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!La.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let n=t.realityLevel??"none";if(!Na.has(n))throw new d("invalid_operation","Confidence evidence reality level is invalid");if(t.evidenceKind==="synthetic-model"&&(t.modelLevel!=="generated"||n!=="none"))throw new d("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=xe(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(f=>Ce(f,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=xe(t.assessedAt,40,"assessedAt")??on(e),r=Date.parse(a);if(!Number.isFinite(r))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=xe(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:on(new Date(r+365*24*60*60*1e3))),c=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(c)||c<r||c>r+366*24*60*60*1e3))throw new d("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let l=xe(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let u=xe(t.sourceLabel,120,"sourceLabel");if(n!=="none"&&!u)throw new d("invalid_operation","Real-world evidence requires a buyer-safe source describing what was checked");if(n==="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:Ce(t.evidenceId,120,"evidenceId"),modelVersion:Ce(t.modelVersion,120,"modelVersion"),evidenceKind:t.evidenceKind,modelLevel:t.modelLevel,realityLevel:n,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...t.eventConfigurationVersion!==void 0?{eventConfigurationVersion:t.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...l?{approvedByRole:l}:{},...u?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:Ka(t.modeledTarget)}:{}}}function Oe(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 xu(t,e){let n=$a(e.evidence,e.now),o=JSON.stringify(Ne(t,e)??null),i=mt(t,e,n),a=JSON.stringify(Ne(t,e)??null);return Oe(e,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function Cu(t,e){let n=Ne(t,e);if(!n)return Oe(e,{changed:!1});let o=mt(t,e,void 0);return Oe(e,{changed:!0,...o,evidenceId:n.evidenceId})}function Ou(t,e){let n=Ne(t,e);if(!n)throw new d("invalid_operation","There is no confidence evidence at this scope to approve",{scope:e.scope,objectId:e.objectId});if(n.status==="retracted")throw new d("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=Ce(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=xe(e.eventConfigurationId,100,"eventConfigurationId")??n.eventConfigurationId;if(n.modelLevel==="configuration-verified"&&!i)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=e.eventConfigurationVersion??n.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let r={...n,status:"approved",approvedByRole:o,assessedAt:on(e.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete r.basisSha256;let s=e.basisSha256??t.confidenceBasisSha256;s&&(r.basisSha256=s);let c=JSON.stringify(n),l=mt(t,e,r);return Oe(e,{changed:c!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function Ru(t,e){let n=Ne(t,e);if(!n)throw new d("invalid_operation","There is no confidence evidence at this scope to retract",{scope:e.scope,objectId:e.objectId});if(n.status==="retracted")return Oe(e,{changed:!1,evidenceId:n.evidenceId,status:"retracted"});let o={...n,status:"retracted"};delete o.basisSha256;let i=mt(t,e,o);return Oe(e,{changed:!0,...i,evidenceId:n.evidenceId,status:"retracted"})}var Ba={width:960,height:600};function za(t,e,n=t){let o={...t,objects:e,floors:void 0,referenceImage:void 0,backgroundImage:Jn(n)},i=Q(o,{freeText:"exclude"}),{width:a,height:r}=Ba;return Math.min(a/Math.max(i.width,1e-6),r/Math.max(i.height,1e-6))}function Ua(t,e){return!t.text.trim()||t.semanticKind==="icon"||t.labelImportance==="detail"||zn(t)?!1:!eo(t.fontSize,e)}function Gr(t){let e=[],n=!!t.floors?.length;for(let o of F(t)){let i=o.objects.filter(r=>r.type==="text");if(!i.length)continue;let a=za(t,o.objects,n?o:t);for(let r of i)Ua(r,a)&&e.push({floorId:o.id,text:r,renderedPx:r.fontSize*a})}return e}var bt=40,Kr=96,Ja=48,ue=24;function Ge(t,e){let n=Q({...t,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"});return{x:n.x+bt,y:n.y+bt,width:Math.max(0,n.width-2*bt),height:Math.max(0,n.height-2*bt)}}function qa(t){if(!t.length)return null;let e=Math.min(...t.map(a=>a.x)),n=Math.min(...t.map(a=>a.y)),o=Math.max(...t.map(a=>a.x+a.width)),i=Math.max(...t.map(a=>a.y+a.height));return{x:e,y:n,width:o-e,height:i-n}}function Ha(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}var sn=t=>t.type==="shape"&&t.role==="stage";function Va(t,e){let n=e.x-(t.x+t.width/2),o=e.y-(t.y+t.height/2);return Math.abs(n)>Math.abs(o)?{dx:n>=0?1:-1,dy:0}:{dx:0,dy:o>=0?1:-1}}function Xa(t,e){return e.dy===1?t.y+t.height:e.dy===-1?-t.y:e.dx===1?t.x+t.width:-t.x}function cn(t,e){return e.dy===1?t.y:e.dy===-1?-(t.y+t.height):e.dx===1?t.x:-(t.x+t.width)}function pt(t,e){let n=ne(t,e.floorId),o=qa(n.objects.filter(sn).map(p=>Ge(n,p)));if(!o)return null;let i=Va(o,n.focalPoint),a=i.dy!==0?e.height:e.width,r=Xa(o,i),s=n.objects.filter(p=>!sn(p)&&Ha(p)).map(p=>Ge(n,p)).filter(p=>cn(p,i)>=r-1),c=s.length?Math.min(...s.map(p=>cn(p,i))):1/0,l=Kr+a+Ja,u=c-r,f=()=>{let p=r+Kr+a/2;return i.dy!==0?{x:o.x+o.width/2,y:i.dy*p}:{x:i.dx*p,y:o.y+o.height/2}};if(!s.length)return{center:f(),movedBack:0};if(u>=a+2*ue){let p=r+u/2;return{center:i.dy!==0?{x:o.x+o.width/2,y:i.dy*p}:{x:i.dx*p,y:o.y+o.height/2},movedBack:0}}if(e.makeRoom){let p=l-u,w=O(t,e.floorId);for(let v of w.objects)sn(v)||cn(Ge(n,v),i)<r-1||pe(v,i.dx*p,i.dy*p);return{center:f(),movedBack:p}}let g="No room between the stage and the seats, so it went beside the stage. Tell the user; moving seats to make room is done in the Designer.",h=e.width,y=e.height,b=o.x+o.width/2,I=o.y+o.height/2;if(i.dy!==0){let p=i.dy===1?Math.min(I,c-ue-y/2):Math.max(I,-c+ue+y/2);return{center:{x:o.x-ue-h/2,y:p},note:g,movedBack:0}}return{center:{x:i.dx===1?Math.min(b,c-ue-h/2):Math.max(b,-c+ue+h/2),y:o.y-ue-y/2},note:g,movedBack:0}}var Wa=40,Ke=24;function Ya(t,e,n){let{objects:o}=O(t,e),i=o.find(a=>a.id===n);if(!i)throw new d("object_not_found",`No object ${n} on this floor. Call get_chart for ids.`,{objectId:n});return i}function $e(t,e){if(!e.nearObjectId&&e.placement==="front"){let n=pt(t,{floorId:e.floorId,width:e.width,height:e.height,makeRoom:e.makeRoom});if(n)return n.note?{center:n.center,note:n.note}:{center:n.center}}return{center:$r(t,e)}}function qu(t,e){return $e(t,e).center}function $r(t,e){if(e.nearObjectId){let n=Ya(t,e.floorId,e.nearObjectId),o=Ge(ne(t,e.floorId),n),i=e.side??"rear";return i==="front"?{x:o.x+o.width/2,y:o.y-Ke-e.height/2}:i==="left"?{x:o.x-Ke-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+Ke+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+Ke+e.height/2}}if(e.placement==="center"){let n=Q(ne(t,e.floorId),{freeText:"exclude"});return{x:n.x+n.width/2,y:n.y+n.height/2}}return we(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}function yt(t,e,n){if(t===void 0)return n;if(!Number.isFinite(t)||t<=0||t>400)throw new d("invalid_operation",`${e} must be between 0 and 400 metres`);return t*Wa}function ln(t,e){if(t===void 0)return;let n=t.trim();if(!n||n.length>80)throw new d("invalid_operation",`${e} must be 1 to 80 characters`);return n}function Za(t){return t.some(e=>e.type==="shape"&&e.role==="stage")}function Hu(t,e){let n=O(t,e.floorId),o=Dn(e.kind),i=yt(e.widthM,"widthM",o.width),a=yt(e.depthM,"depthM",o.height),r=$r(t,{...e,placement:e.placement??"front",width:i,height:a}),s=ln(e.label,"label")??Gn(e.kind),c=M(t,"stage",e.idFactory,new Set),l={...Nn({kind:e.kind,cx:r.x,cy:r.y,width:i,height:a,label:s},c),x:r.x-i/2,y:r.y-a/2,width:i,height:a},u=Za(n.objects);if(n.objects.push(l),!u){let f={x:r.x,y:r.y+a/2+Ke},g=F(t).find(h=>h.id===n.floorId);t.floors?.length&&g&&(g.focalPoint=f),(!t.floors?.length||t.floors[0]?.id===n.floorId)&&(t.focalPoint=f)}return{floorId:n.floorId,stageId:c,label:s,focalPointMoved:!u,createdIds:[c]}}function Vu(t,e){let n=Te(e.role);if(!n)throw new d("invalid_operation",`Unknown landmark: ${e.role}`);let o=O(t,e.floorId),{center:i,note:a}=$e(t,{...e,width:n.width,height:n.height}),r=M(t,"decor",e.idFactory,new Set),s=Fo(e.role,i,r),c=ln(e.label,"label");return c&&s.label!==void 0&&(s.label=n.icon?`${n.icon} ${c}`:c),o.objects.push(s),{floorId:o.floorId,landmarkId:r,label:s.label??null,createdIds:[r],...a?{note:a}:{}}}var Qa={small:16,medium:24,large:36};function wt(t){if(t==="always")return"orientation";if(t==="close-up")return"detail"}var es="#f7f8fb";function ts(t){let e=t.theme?.background??es,n=t.theme?.textColor;return n&&Yn(n,e)>=4.5?n:Zn(e,"#0b1220","#e8ecf4")}function Xu(t,e){let n=e.text.trim();if(!n||n.length>120)throw new d("invalid_operation","text must be 1 to 120 characters");let o=O(t,e.floorId),i=Qa[e.size??"medium"],a=Math.max(i,n.length*i*.56),r=i*1.2,{center:s,note:c}=$e(t,{...e,width:a,height:r}),l=M(t,"txt",e.idFactory,new Set),u={type:"text",id:l,text:n,position:{x:s.x-a/2,y:s.y-r/2},fontSize:i,rotation:0,color:e.color?D(e.color,"color"):ts(t),...e.bold?{bold:!0}:{},...wt(e.showAt)?{labelImportance:wt(e.showAt)}:{}};o.objects.push(u);let f=e.showAt===void 0&&Gr(t).some(h=>h.text.id===l)?'Buyers see this text only after zooming in. For a gate, entrance or anything they must see at once, set showAt "always" or size "large".':void 0,g=[c,f].filter(Boolean).join(" ");return{floorId:o.floorId,textId:l,createdIds:[l],...g?{note:g}:{}}}function Wu(t,e){let n=io(e.iconKey);if(!n)throw new d("invalid_operation",`Unknown icon: ${e.iconKey}`);let o=O(t,e.floorId),i=28,{center:a,note:r}=$e(t,{...e,width:i,height:i}),s=M(t,"icon",e.idFactory,new Set),c={type:"text",id:s,semanticKind:"icon",iconKey:n.key,text:n.label,position:a,fontSize:i,rotation:0,...wt(e.showAt)?{labelImportance:wt(e.showAt)}:{}};return o.objects.push(c),{floorId:o.floorId,iconId:s,createdIds:[s],...r?{note:r}:{}}}var ns="#4b5568";function Yu(t,e){let n=ln(e.label,"label"),o=O(t,e.floorId),i=yt(e.widthM,"widthM",0),a=yt(e.depthM,"depthM",0),{center:r,note:s}=$e(t,{...e,width:i,height:a}),c=M(t,"shape",e.idFactory,new Set),l={type:"shape",id:c,kind:e.shape??"rect",x:r.x-i/2,y:r.y-a/2,width:i,height:a,fill:e.fill?D(e.fill,"fill"):ns,...n?{label:n}:{},...e.shape!=="ellipse"?{cornerRadius:8}:{}};return o.objects.push(l),{floorId:o.floorId,areaId:c,createdIds:[c],...s?{note:s}:{}}}function Zu(){return["bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"].map(t=>({role:t,label:Te(t)?.label??t}))}var os=100,rs=300,ef=os*rs;function Br(t,e,n){if(n==="horizontal"||!e||![t.x,t.y,e.x,e.y].every(Number.isFinite))return 0;let o=t.x-e.x,i=t.y-e.y,a=Math.hypot(o,i);if(a<=1e-6)return 0;let r={x:i/a,y:-o/a},s=Math.atan2(r.y,r.x)*180/Math.PI;return Object.is(s,-0)?0:s}function Ue(t,e){if(e.placement==="front"){let n=pt(t,e);if(n)return n.note?{center:n.center,note:n.note}:{center:n.center}}return{center:we(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}}var is={straight:0,gentle:15,medium:30,strong:45},as=24,ss=28,cs=48;function uf(t,e){let n=e.blocks??1;if(!Number.isInteger(n)||n<1||n>8)throw new d("invalid_operation","blocks must be a whole number from 1 to 8");if(e.sectionLabels&&e.sectionLabels.length!==n)throw new d("invalid_operation",`Give one section name per block (${n})`);if(e.blockSeats&&e.blockSeats.length!==n)throw new d("invalid_operation",`Give one seat count per block (${n})`);let o=S=>e.blockSeats?.[S]??e.seatsPerRow,i=S=>Math.max(24,(S-1)*as),a=i(e.seatsPerRow),r=Math.max(28,(e.rowCount-1)*ss),s=e.aisleWidth??cs,c=e.placement??"auto",l=is[e.curveStyle??"straight"],u={floorId:"",rowIds:[],sectionIds:[],createdIds:[]},f=(S,p,w)=>{let v=nr(t,{floorId:e.floorId,origin:S,rowCount:e.rowCount,seatsPerRow:o(w),categoryKey:e.categoryKey,curve:l,...e.blockStyle?{style:e.blockStyle}:{},rotation:p,sectionLabel:e.sectionLabels?.[w],idFactory:e.idFactory});u.floorId=v.floorId,u.rowIds.push(...v.rowIds),v.sectionId&&u.sectionIds.push(v.sectionId),u.createdIds.push(...v.createdIds)};if(n===1&&c==="front"){let S=Ue(t,{floorId:e.floorId,width:a,height:r,placement:c,makeRoom:e.makeRoom});return S.note&&(u.note=S.note),f({x:S.center.x-a/2,y:S.center.y-r/2},0,0),u}if(n===1){let S=we(t,{floorId:e.floorId,width:a,height:r,placement:c}),p=Br(S,t.focalPoint,e.orientation??"horizontal"),w=p*Math.PI/180,v=Math.abs(a*Math.cos(w))+Math.abs(r*Math.sin(w)),m=Math.abs(a*Math.sin(w))+Math.abs(r*Math.cos(w)),x=p===0?S:we(t,{floorId:e.floorId,width:v,height:m,placement:c});return f({x:x.x-a/2,y:x.y-r/2},p,0),u}let g=Array.from({length:n},(S,p)=>i(o(p))),h=g.reduce((S,p)=>S+p,0)+(n-1)*s,y=Ue(t,{floorId:e.floorId,width:h,height:r,placement:c,makeRoom:e.makeRoom});y.note&&(u.note=y.note);let b=y.center,I=b.x-h/2;for(let S=0;S<n;S+=1)f({x:I,y:b.y-r/2},0,S),I+=g[S]+s;return u}function ff(t,e){return e===1?[t]:e===2?[`${t} Left`,`${t} Right`]:e===3?[`${t} Left`,`${t} Centre`,`${t} Right`]:Array.from({length:e},(n,o)=>`${t} ${o+1}`)}var ls=155,ds=150,zr=110;function hf(t,e){let n=(e.tableColumns-1)*ls+zr,o=(e.tableRows-1)*ds+zr,{center:i,note:a}=Ue(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=ir(t,{floorId:e.floorId,center:i,tableRows:e.tableRows,tableColumns:e.tableColumns,seatsPerTable:e.seatsPerTable??8,shape:e.shape??"round",categoryKey:e.categoryKey,idFactory:e.idFactory});return a?{...r,note:a}:r}function gf(t,e){let n=Jt(e.capacity),{center:o,note:i}=Ue(t,{floorId:e.floorId,...n,placement:e.placement,makeRoom:e.makeRoom}),a=rr(t,{floorId:e.floorId,center:o,capacity:e.capacity,categoryKey:e.categoryKey,...e.label===void 0?{}:{label:e.label},...e.displayLabel===void 0?{}:{displayLabel:e.displayLabel},idFactory:e.idFactory});return i?{...a,note:i}:a}var us=88,fs=82,hs=62,gs=52;function mf(t,e){let n=(e.boothColumns-1)*us+hs,o=(e.boothRows-1)*fs+gs,{center:i,note:a}=Ue(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=ar(t,{floorId:e.floorId,center:i,boothRows:e.boothRows,boothColumns:e.boothColumns,categoryKey:e.categoryKey,idFactory:e.idFactory});return a?{...r,note:a}:r}var ms=40,Jr=30,ze=42,Be=48;function qr(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}function dn(t,e){return Q({...t,floors:void 0,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"})}function bs(t){return[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x,y:t.y+t.height},{x:t.x+t.width,y:t.y+t.height}]}function ps(t,e,n){let o=F(t),i=e?o.find(y=>y.id===e):o[0];if(!i)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});let a=i.focalPoint??t.focalPoint,r=i.objects.filter(qr),s=0;if(r.length){let y=0,b=0;for(let I of r){let S=dn(t,I);y+=S.x+S.width/2-a.x,b+=S.y+S.height/2-a.y}Math.hypot(y,b)>1&&(s=Math.atan2(y,b)*180/Math.PI)}let c=n/2,l={x:Math.sin(s*Math.PI/180),y:Math.cos(s*Math.PI/180)},u=0,f=[],g=r.some(y=>y.type==="row");for(let y of r){if(y.type==="section"&&g)continue;let b=y.type==="row"?W(y):bs(dn(t,y)),I=y.type==="row"?y.seatSpacing/2:0;for(let S of b){let p=S.x-a.x,w=S.y-a.y,v=Math.atan2(p,w)*180/Math.PI;if(Math.abs((v-s+540)%360-180)>c+10)continue;let x=Math.hypot(p,w)+I;u=Math.max(u,x),f.push({radius:x,depth:p*l.x+w*l.y+I})}}let h=y=>{let b=Math.cos(y/2*Math.PI/180);return b<.2||!f.length?0:(Math.max(...f.map(I=>I.depth))+ze)/b};return{center:a,bearing:s,occupiedRadius:u,floorId:i.id,clearRadius:h}}var Hr=100;function Ur(t,e,n){return t===void 0||n<=0?Hr:Math.min(180,Math.max(20,Math.round(Vr(t,e)/n*(180/Math.PI))))}function Vr(t,e){let n=e==="two"?2:e==="center"?1:0;return t*Jr+n*Be}function ys(t,e,n,o){let i=[],a=o+ze-e.occupiedRadius;if(e.occupiedRadius<=0||a<=0)return i;let r=n/2+10;for(let s of O(t,e.floorId).objects){if(qr(s)||s.type==="shape"&&s.role==="stage")continue;let c=dn(t,s),l=c.x+c.width/2-e.center.x,u=c.y+c.height/2-e.center.y,f=Math.hypot(l,u);if(f<=e.occupiedRadius)continue;let g=Math.atan2(l,u)*180/Math.PI;Math.abs((g-e.bearing+540)%360-180)>r||(pe(s,l/f*a,u/f*a),i.push(s.id))}return i}function bf(t,e){let n=ps(t,e.floorId,e.spreadDegrees??Hr),o=Math.max((e.firstRowDistanceM??4)*ms,n.occupiedRadius>0?n.occupiedRadius+ze+Be:0),i=e.spreadDegrees??Ur(e.seatsPerRow,e.aisles,o),a=e.spreadDegrees!==void 0&&e.seatsPerRow!==void 0?Vr(e.seatsPerRow,e.aisles)/(e.spreadDegrees*Math.PI/180):0,r=Math.max(o,a,n.clearRadius(i)),s=e.spreadDegrees??Ur(e.seatsPerRow,e.aisles,r),c=r+(e.rowCount-1)*ze,l=ys(t,n,s,c);return{...Zo(t,{floorId:n.floorId,center:n.center,innerRadius:r,rowCount:e.rowCount,rowGap:ze,startAngle:n.bearing-s/2,endAngle:n.bearing+s/2,seatPitch:Jr,fit:e.seatsPerRow===void 0?"seat-pitch":"fixed-count",...e.seatsPerRow===void 0?{}:{seatsPerRow:e.seatsPerRow},facing:"inward",...e.aisles==="center"?{aisleGaps:{center:Be}}:e.aisles==="two"?{aisleGaps:{left:Be,right:Be}}:{},categoryKey:e.categoryKey,...e.sectionLabel===void 0?{}:{sectionLabel:e.sectionLabel},idFactory:e.idFactory}),spreadDegrees:s,movedBackIds:l}}export{Mt as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,Wa as DECOR_UNITS_PER_METRE,As as DEFAULT_FLOOR_HEIGHT_STEP_M,Lo as DEFAULT_ROUTE_NAME,Xr as DEFAULT_SECTION_CORNER_SMOOTHING,Oi as FIRST_CATEGORY_COLOURS,ws as MAX_BUYER_IMAGE_URL_LENGTH,_s as MAX_FLOOR_BASE_HEIGHT_M,ns as NAMED_AREA_FILL,Do as ROUTE_STROKE,is as ROW_CURVE_DEGREES,Zo as addArcFanRows,Yu as addArea,kd as addBookableGridArray,ar as addBoothArray,Fl as addChartCategories,zt as addChartCategory,Ps as addChartFloor,Ds as addChartZone,bf as addCurvedRows,rr as addGAArea,lc as addGate,Wu as addIcon,Vu as addLandmark,mf as addPlacedBoothArray,gf as addPlacedGAArea,uf as addPlacedRowBlocks,hf as addPlacedTableArray,gc as addRoute,nr as addRowBlock,Hu as addStage,ir as addTableArray,Xu as addText,Hc as applyPolygonHole,Rd as applyReferenceScanRows,cl as applySectionCornerSmoothing,hl as applySectionEstimates,Ii as applySectionOutlineShaping,qc as applySectionRowFit,Ou as approveConfidenceEvidence,qi as arcFanInputForGroup,rl as assignSectionInventoryCategory,we as automaticPlacementCenter,ff as blockSectionLabels,Cu as clearConfidenceEvidence,Os as compactChartDoc,xs as compactRowOverrides,Cs as compactTableOverrides,vu as confidenceEvidenceChangeRequiresPublish,Ea as confidenceEvidenceChanges,Su as confidenceEvidenceIndex,Rl as confirmReferenceCategoryOutputColor,il as convertGeneratedSectionToPolygon,hu as convertShapeToOutline,Bo as countCoveredInventory,ps as curvedRowsPlacement,$e as decorPlacement,qu as decorPlacementCenter,vs as detectSeatLabelRun,Un as dropRedundantSeatOverrideFields,Ti as familyCategoryLabel,Jt as gaAreaFootprint,ai as gateShape,sr as groupRowsAsSegmented,Lc as insertSeatingBlock,Is as isSafeBuyerImageUrl,ou as joinGAAreas,Zu as landmarkRoles,uc as makeGate,Jd as mergeRows,Qe as mirrorFirstFloor,se as normalizeBuyerImageUrl,$a as normalizeDraftEvidence,Nd as parseSeatRefId,Ci as pickColorblindSafeCategoryColor,Li as planCreationCategory,Yo as previewArcFanRows,Pd as previewBookableGridArray,pi as previewGeneratedSectionPolygonConversion,nu as previewJoinGAAreas,$t as previewPolygonHole,gi as previewRemovePolygonHole,li as previewRowCubicPath,fi as previewSectionRowFit,Ol as reassignColorblindSafeCategoryColors,Dc as relabelChartRows,$o as releaseGateReferences,hc as remapGateReferences,jl as removeCategoryMovingInventory,Wo as removeChartCategory,Fs as removeChartFloor,Tc as removeChartObjects,Ns as removeChartZone,Vc as removePolygonHole,ks as renameChartFloor,xl as renameDirectSeatImportCategory,Cl as reorderChartCategories,Jl as replaceArcFanRows,sd as replaceRowBlock,Gd as resetSeatOverrides,mu as resizeShapes,_l as resolveCreationCategory,Ru as retractConfidenceEvidence,Rs as roundBuyerCoordinates,si as routeShape,lt as seatRefId,Ss as seatSemanticsSignature,bi as sectionInventorySelectionSummary,xu as setConfidenceEvidence,fc as setObjectEntrance,mc as setRoute,Hd as setRowBlockSpacing,qd as splitRow,Vd as straightenAndSpaceRows,al as transformSectionBoundary,yi as transformSectionBoundaryObject,id as ungroupSegmentedRow,Ki as uniqueCategoryLabel,Fc as updateBooths,Bt as updateCategoryDefinitions,Ms as updateChartFloorBaseHeight,Gl as updateChartTheme,Ls as updateChartZones,jc as updateGAAreas,dc as updateGate,Jc as updateRowCubicPath,Ud as updateRows,Ir as updateSeatOverrides,sl as updateSectionExactPath,Vo as updateSectionMetadata,ad as updateSegmentedRow,gu as updateShapes,bu as updateStageKinds,Mc as updateTables,Ec as updateTextObjects,Kl as updateViewFromSeatFallback};