@seatlayer/core 0.110.0 → 0.110.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/ar-C5PA2DVE.js +1 -0
  2. package/dist/be-TMKSMYPN.js +1 -0
  3. package/dist/bg-V6HTEDUB.js +1 -0
  4. package/dist/ca-CTZMHWW4.js +1 -0
  5. package/dist/{categoryInventory-BfvwE3nC.d.cts → categoryInventory-BE1AThTx.d.cts} +1 -1
  6. package/dist/{categoryInventory-ClZ-68jI.d.ts → categoryInventory-DxciZQK_.d.ts} +1 -1
  7. package/dist/{chunk-6VOUTNRV.js → chunk-2VYFNNYC.js} +1 -1
  8. package/dist/{chunk-YE4NP3XB.js → chunk-3V32MDJI.js} +1 -1
  9. package/dist/chunk-4AGC7B64.js +1 -0
  10. package/dist/{chunk-ZYQXT5JP.js → chunk-5IADCFUU.js} +1 -1
  11. package/dist/{chunk-2JFCDE27.js → chunk-6CBJBESS.js} +1 -1
  12. package/dist/{chunk-WUNZCUE6.js → chunk-DLHW3UDD.js} +1 -1
  13. package/dist/{chunk-UUIZHJYL.js → chunk-GVVZR3YS.js} +1 -1
  14. package/dist/{chunk-MRLWH6RC.js → chunk-GWGWNBGU.js} +1 -1
  15. package/dist/chunk-JQBJZMLG.js +1 -0
  16. package/dist/{chunk-OJSGMXJS.js → chunk-NVAF2E7Q.js} +1 -1
  17. package/dist/{chunk-FBXZWNND.js → chunk-YRDOE3N7.js} +1 -1
  18. package/dist/{chunk-BNLANXXZ.js → chunk-ZY6WTPTI.js} +1 -1
  19. package/dist/core/chart-ops/index.cjs +1 -1
  20. package/dist/core/chart-ops/index.d.cts +6 -4
  21. package/dist/core/chart-ops/index.d.ts +6 -4
  22. package/dist/core/chart-ops/index.js +1 -1
  23. package/dist/core/inventory/index.d.cts +4 -4
  24. package/dist/core/inventory/index.d.ts +4 -4
  25. package/dist/core/inventory/index.js +1 -1
  26. package/dist/core/layout/index.d.cts +5 -5
  27. package/dist/core/layout/index.d.ts +5 -5
  28. package/dist/core/layout/index.js +1 -1
  29. package/dist/core/quality/index.cjs +1 -1
  30. package/dist/core/quality/index.d.cts +3 -3
  31. package/dist/core/quality/index.d.ts +3 -3
  32. package/dist/core/render-assets/index.cjs +1 -1
  33. package/dist/core/render-assets/index.d.cts +2 -2
  34. package/dist/core/render-assets/index.d.ts +2 -2
  35. package/dist/core/render-assets/index.js +1 -1
  36. package/dist/core/seatConfidence.d.cts +1 -1
  37. package/dist/core/seatConfidence.d.ts +1 -1
  38. package/dist/core/sections/index.d.cts +5 -5
  39. package/dist/core/sections/index.d.ts +5 -5
  40. package/dist/core/sections/index.js +1 -1
  41. package/dist/cs-FUDGOUFL.js +1 -0
  42. package/dist/cy-5RRARIAP.js +1 -0
  43. package/dist/da-PONPPWKY.js +1 -0
  44. package/dist/de-PKG7AAB5.js +1 -0
  45. package/dist/el-H7OFU4QQ.js +1 -0
  46. package/dist/es-QSW5IZ6U.js +1 -0
  47. package/dist/et-GTMPSS72.js +1 -0
  48. package/dist/{eventConfigurations-DsW5Mj2e.d.ts → eventConfigurations-Cdt-e0uD.d.ts} +1 -1
  49. package/dist/{eventConfigurations-dmn9FClw.d.cts → eventConfigurations-D0us5j0K.d.cts} +1 -1
  50. package/dist/fa-SGLTFGJF.js +1 -0
  51. package/dist/fi-7YTEAVDM.js +1 -0
  52. package/dist/fr-ECCQ24MZ.js +1 -0
  53. package/dist/he-YHMMDOX7.js +1 -0
  54. package/dist/hi-GRAQX2E6.js +1 -0
  55. package/dist/hr-MN33LRIJ.js +1 -0
  56. package/dist/hu-NW3SMQVM.js +1 -0
  57. package/dist/id-3OPRAUF7.js +1 -0
  58. package/dist/index.cjs +1 -1
  59. package/dist/index.d.cts +13 -13
  60. package/dist/index.d.ts +13 -13
  61. package/dist/index.js +1 -1
  62. package/dist/it-RYM74YWO.js +1 -0
  63. package/dist/ja-4NI6DG5D.js +1 -0
  64. package/dist/{ko-6YCWWHFQ.js → ko-C4F6UEMK.js} +1 -1
  65. package/dist/ku-DMSBMWTC.js +1 -0
  66. package/dist/{labeling-Bn41ByDd.d.ts → labeling-DXgkxMoi.d.ts} +1 -1
  67. package/dist/{labeling-BmEjVxFt.d.cts → labeling-eYKVPLMb.d.cts} +1 -1
  68. package/dist/localeLoaders-G3GCGLPW.js +1 -0
  69. package/dist/lt-3EXKKZFG.js +1 -0
  70. package/dist/lv-4EWNRDCG.js +1 -0
  71. package/dist/ms-7LJBSAEJ.js +1 -0
  72. package/dist/nl-GWTIWXRW.js +1 -0
  73. package/dist/no-T3FW2WLX.js +1 -0
  74. package/dist/pl-OG5OBRHR.js +1 -0
  75. package/dist/pt-YQ6VES5R.js +1 -0
  76. package/dist/{renderedQuality-MDkNe8GA.d.ts → renderedQuality-Dzo2_8f4.d.ts} +1 -1
  77. package/dist/{renderedQuality-Bt2d0uq1.d.cts → renderedQuality-Frgw6jdx.d.cts} +1 -1
  78. package/dist/{renderer-DH0yI32q.d.cts → renderer-DM2sv1un.d.cts} +1 -1
  79. package/dist/{renderer-BJrpMV6U.d.ts → renderer-DuieD7jP.d.ts} +1 -1
  80. package/dist/ro-VK5MASYF.js +1 -0
  81. package/dist/ru-YU5CYR6T.js +1 -0
  82. package/dist/{seatTypeIcons-CG_Uzpaw.d.ts → seatTypeIcons-Bz0OJtEi.d.ts} +1 -1
  83. package/dist/{seatTypeIcons-Ck7oEFei.d.cts → seatTypeIcons-Cm8tjLYl.d.cts} +1 -1
  84. package/dist/{sections-C-UAqr1x.d.ts → sections-Bf_DV0oG.d.ts} +1 -1
  85. package/dist/{sections-C8HApYxd.d.cts → sections-PbQiqN0i.d.cts} +1 -1
  86. package/dist/{segmentedRowModel-DR1w9M13.d.ts → segmentedRowModel-CO7DD803.d.ts} +1 -1
  87. package/dist/{segmentedRowModel-CeoMsBnt.d.cts → segmentedRowModel-Co9LqS4i.d.cts} +1 -1
  88. package/dist/sk-CE7PXAYL.js +1 -0
  89. package/dist/sl-EYUPV4BG.js +1 -0
  90. package/dist/sr-PPXCN4IK.js +1 -0
  91. package/dist/sv-WR2BJBCJ.js +1 -0
  92. package/dist/{tableSizing-RRmpxOXl.d.ts → tableSizing-BDePQyPD.d.ts} +3 -3
  93. package/dist/{tableSizing-Bz-hxLza.d.cts → tableSizing-C6EjKNnk.d.cts} +3 -3
  94. package/dist/th-JUB2DODR.js +1 -0
  95. package/dist/{ticketRestrictions-lq4dH4k6.d.cts → ticketRestrictions-CgYwHQOf.d.cts} +2 -2
  96. package/dist/{ticketRestrictions-C7KUrulv.d.ts → ticketRestrictions-D5wgOq4P.d.ts} +2 -2
  97. package/dist/tr-GFHA7FT6.js +1 -0
  98. package/dist/{types-DM-OneoD.d.ts → types-CGOr0BpE.d.cts} +40 -16
  99. package/dist/{types-DM-OneoD.d.cts → types-CGOr0BpE.d.ts} +40 -16
  100. package/dist/uk-3FTS2SRK.js +1 -0
  101. package/dist/vi-7OTXPOQV.js +1 -0
  102. package/dist/view3d/crossfade/panorama.d.cts +1 -1
  103. package/dist/view3d/crossfade/panorama.d.ts +1 -1
  104. package/dist/view3d/index.cjs +410 -169
  105. package/dist/view3d/index.d.cts +100 -4
  106. package/dist/view3d/index.d.ts +100 -4
  107. package/dist/view3d/index.js +408 -167
  108. package/dist/view3d/scene/scene.worker.cjs +1 -1
  109. package/dist/view3d/scene/scene.worker.js +1 -1
  110. package/dist/zh-Hans-FD4XNYUA.js +1 -0
  111. package/dist/zh-Hant-7TXVJKJQ.js +1 -0
  112. package/package.json +1 -1
  113. package/dist/ar-O3RHQRH3.js +0 -1
  114. package/dist/be-SXFCG3F5.js +0 -1
  115. package/dist/bg-W7YBNYB2.js +0 -1
  116. package/dist/ca-FA7WHACR.js +0 -1
  117. package/dist/chunk-4N5CHKHD.js +0 -1
  118. package/dist/chunk-4QQG5EEP.js +0 -1
  119. package/dist/cs-RR3VIKRC.js +0 -1
  120. package/dist/cy-U4JJ5C47.js +0 -1
  121. package/dist/da-ATULGB2M.js +0 -1
  122. package/dist/de-VB543CPC.js +0 -1
  123. package/dist/el-7Y2KXU6N.js +0 -1
  124. package/dist/es-GUV5XIYC.js +0 -1
  125. package/dist/et-SZ6I4Z44.js +0 -1
  126. package/dist/fa-FM6ELEN7.js +0 -1
  127. package/dist/fi-6QQ2M5JI.js +0 -1
  128. package/dist/fr-2SEQSVLR.js +0 -1
  129. package/dist/he-V3EVB7IW.js +0 -1
  130. package/dist/hi-I4QIBK5Q.js +0 -1
  131. package/dist/hr-I5DNEVUU.js +0 -1
  132. package/dist/hu-KTFWBQMF.js +0 -1
  133. package/dist/id-RZWUH426.js +0 -1
  134. package/dist/it-CNQP36V4.js +0 -1
  135. package/dist/ja-JQZOYIHI.js +0 -1
  136. package/dist/ku-33PM4OWG.js +0 -1
  137. package/dist/localeLoaders-VFQOZMUH.js +0 -1
  138. package/dist/lt-24JO2B7V.js +0 -1
  139. package/dist/lv-HTSDEEAB.js +0 -1
  140. package/dist/ms-PUEZJJ3R.js +0 -1
  141. package/dist/nl-NQPDRSCW.js +0 -1
  142. package/dist/no-3N3MUMSA.js +0 -1
  143. package/dist/pl-YHBEO6ZF.js +0 -1
  144. package/dist/pt-5RPESNZB.js +0 -1
  145. package/dist/ro-XDFXIMHX.js +0 -1
  146. package/dist/ru-BIIALOM5.js +0 -1
  147. package/dist/sk-LHSFRUFT.js +0 -1
  148. package/dist/sl-MPE5TPI3.js +0 -1
  149. package/dist/sr-T3N67KTP.js +0 -1
  150. package/dist/sv-LJWWYUIY.js +0 -1
  151. package/dist/th-E5POGG37.js +0 -1
  152. package/dist/tr-2DCWQ2CY.js +0 -1
  153. package/dist/uk-C3VJP6EA.js +0 -1
  154. package/dist/vi-XVMTKCOL.js +0 -1
  155. package/dist/zh-Hans-RG4CQGBY.js +0 -1
  156. package/dist/zh-Hant-YHNTYPFS.js +0 -1
@@ -1 +1 @@
1
- import{a as Kt,b as ae}from"../../chunk-TZBJCAXH.js";import{A as qs,b as d,c as R,d as E,e as M,f as ye,g as oe,h as Ro,i as Ze,j as we,k as D,l as ie,m as Qe,n as Ie,o as Gt,p as Te,q as Y,r as Z,s as te,t as de,u as et,v as $s,w as Bs,x as zs,y as Us,z as Js}from"../../chunk-6VOUTNRV.js";import{a as Ee,b as Ye}from"../../chunk-OJSGMXJS.js";import{g as Ft,h as jt,j as wo,k as Io,l as So,m as pe,n as vo,o as xo,p as Lt,q as Nt,r as Co}from"../../chunk-FBXZWNND.js";import{c as eo,d as fo,h as uo,i as ho}from"../../chunk-BNLANXXZ.js";import{k as je}from"../../chunk-4N5CHKHD.js";import{a as Et,b as Tt,n as go,p as mo,r as bo,s as po,t as yo,x as Dt}from"../../chunk-GUNNA5LB.js";import{a as ke,c as Yn,d as Ts,e as Ds,f as Zn,g as Ls,h as Ns,i as Gs,j as Ks,l as Qn}from"../../chunk-M4NGX5NM.js";import{A as lo,k as so,s as co}from"../../chunk-EE2CVYFJ.js";import{a as wn,b as xt,e as He,k as Ct,n as In}from"../../chunk-URW7MSCJ.js";import{b as be,c as H,e as to,f as no,g as At,h as oo,i as Me,k as ne,o as kt,v as Fe}from"../../chunk-UUIZHJYL.js";import{$ as Tn,$a as j,A as An,Da as Un,Ea as Jn,Fa as qn,G as kn,Ha as Hn,Ja as Vn,K as Xe,Ka as Xn,La as J,Oa as q,Q as Mn,R as Ot,S as Fn,Sa as Ae,T as We,U as jn,V as ri,Wa as Q,Xa as $,Z as En,Za as G,_a as Wn,a as js,aa as _t,b as Es,bb as W,c as le,ca as Dn,da as Ln,e as Rt,ea as Nn,fb as ee,ka as Bn,q as Sn,r as vn,s as xn,t as Cn,u as Rn,v as On,w as Ve,x as _n,y as Pn,za as zn}from"../../chunk-YE4NP3XB.js";import{e as Gn,h as Pt,q as Kn,r as $n}from"../../chunk-S3VH7IDA.js";import{G as ao,i as ro,m as io,n as Mt}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function Ws(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:Gt(t,e.label),color:D(e.color,"Zone color"),...e.focalPoint?{focalPoint:Te(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function Ys(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 f=r.get(c.zoneId);c.patch.label!==void 0&&(f.label=Gt(a,c.patch.label,f.id)),c.patch.color!==void 0&&(f.color=D(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(f.focalPoint=Te(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 Zs(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=j(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,et(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var fe={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 De(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 ii(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 Oo(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 ai(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 _o=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[fe.balcony],sectionLabel:"Balcony",build:()=>[De("blk-b0","A",-45,18,24,"balcony",18),De("blk-b1","B",-15,20,24,"balcony",18),De("blk-b2","C",15,22,24,"balcony",18),De("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[fe.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>De(`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:[fe.standard],build:()=>[Oo("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[fe.premium],build:()=>Array.from({length:6},(t,e)=>ii(`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:[fe.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:[fe.standard],build:()=>[Oo("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:[fe.standard],build:()=>[ai("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 tt(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 se(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=Q(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=Fn(t.outlinePath,e,n)),t.holes&&(t.holes=Q(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=Q(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 nt(t,e,n){return n?An(t,e,n):{x:t.x,y:t.y}}function si(t,e,n){let o=i=>nt(i,e,n);t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=We(t.outlinePath,o,1,!1)),t.holes&&(t.holes=Q(t.holes).map(i=>i.map(o)))}function ci(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=nt(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=Q(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=nt(i,e,n);t.x+=a.x-i.x,t.y+=a.y-i.y}t.rotation=ae("shape",o+n)}function Po(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=>nt(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=ae("row",t.rotation+n);break;case"table":case"booth":t.center=o(t.center),t.rotation=ae(t.type,t.rotation+n);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=Q(t.holes).map(i=>i.map(o)));break;case"section":si(t,e,n);break;case"shape":ci(t,e,n);break;case"text":t.position=o(t.position),t.rotation=ae("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=ae("decorImage",(t.rotation??0)+n);break}}}var li=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","wheelchairPlaces"],Ao=(t,e,n)=>Number.isInteger(t)&&t>=e&&t<=n;function ko(t){let e={};for(let n of li){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&&!Ao(e[n],1,H))throw new d("invalid_operation",`${n} must be a whole number from 1 to ${H}`);if(e.wheelchairPlaces!==void 0&&!Ao(e.wheelchairPlaces,0,H))throw new d("invalid_operation",`wheelchairPlaces must be a whole number from 0 to ${H}`);return e}function Mo(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=Me(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>At)throw new d("invalid_operation",oo,{gaAreaId:t.id,capacity:t.capacity,max:At});if(n&&be(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 Fo(t,e){let n=e.filter(a=>Me(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 j(t))for(let r of a.objects){let s=r.type==="gaArea"?o.get(r.id)??r:r,c=[];s.type==="row"?c=q(s).map(l=>l.label):s.type==="table"?c=s.bookAsWhole||s.variableOccupancy?[s.label]:Ae(s).map(l=>l.label):s.type==="booth"?c=[s.label]:s.type==="gaArea"&&(c=ne(s));for(let l of c){let f=i.get(l);if(f&&f!==s.id)throw new d("invalid_operation",`Inventory label "${l}" is already in use; an area sold as one box needs a unique label`,{gaAreaId:f,inventoryLabel:l,conflictingObjectId:s.id})}}}var jo=40,Eo=160;function di(t,e){let n=t.normalize("NFKC").trim();if(n.length>jo)throw new d("invalid_operation",`${e} entrance must be at most ${jo} characters`);return n}function ot(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(ie(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=di(o,e)||null}}return n}function rt(t,e){if(e.labelStyle){let o=Ie(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 To(t){if(!("chairNumbering"in t))return;let e=t.chairNumbering;if(delete t.chairNumbering,e===null)return null;let n=Kn(e);if(n)throw new d("invalid_operation",n);return e}function Do(t,e){if(e===void 0)return;let n=e===null?void 0:$n({...t.chairNumbering,...e});n?t.chairNumbering=n:delete t.chairNumbering}function Lo(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(!In.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>Eo)throw new d("invalid_operation",`Booth note supports at most ${Eo} characters`);e.note=i||null}}}return e}function No(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 fi=[{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}],Go=new Map(fi.map(t=>[t.role,t]));function Le(t){return Go.get(t)}function Ko(t,e,n){let o=Go.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 Uo={color:Tt.accessibility,width:4},Jo="Step-free route";function it(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 hi(t){if(!wo.includes(t))throw new d("invalid_operation","Gate use must be in, out or both")}function Bt(t,e){if(typeof t!="boolean")throw new d("invalid_operation",`${e} must be true or false`)}function Ne(t){return j(t).flatMap(e=>e.objects)}function qo(t,e){let n=xo(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 Ho(t){let e=t.height??40,n=Co(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 Vo(t,e){t.type!=="row"&&(e?t.entrance=e:delete t.entrance)}var $o=t=>t.type==="row"?void 0:t.entrance;function gi(t,e){let n=Lt(e),o=[];for(let i of Ne(t))!pe(i)||i.entranceGateId!==e.id||(Vo(i,n),o.push(i.id));return o}function zt(t,e,n){n.name!==void 0&&(t.label=it(n.name,40,"Gate name")),n.use!==void 0&&(hi(n.use),e.use=n.use),n.stepFree!==void 0&&(Bt(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=it(n.opens,40,"Opening time")),n.hideFromBuyers!==void 0&&(Bt(n.hideFromBuyers,"Hide from buyers"),n.hideFromBuyers?e.hideFromBuyers=!0:delete e.hideFromBuyers),t.gate=e,t.role=vo(e.use)}function mi(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:Tt.navigation,...o?{rotation:o}:{},heightM:Le("entrance")?.heightM??2.7};return zt(i,{use:"in"},n),Ho(i),i}function xc(t,e){let n=R(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=mi(o,e.center,{...e,name:e.name??Nt(t)},e.rotation??0);return n.objects.push(i),{changed:!0,floorId:n.floorId,gate:structuredClone(i)}}function Cc(t,e){let n=qo(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);zt(i,i.gate,e.patch),(e.patch.name!==void 0||e.patch.stepFree!==void 0)&&Ho(i);let a=JSON.stringify(i)!==o;a&&Object.assign(n,i);let r=gi(t,n);return{changed:a,gate:structuredClone(n),servedObjectIds:r}}function Rc(t,e){let n=Ne(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"||!So(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 zt(n,{use:n.role==="exit"?"out":"in"},{...e,name:e.name??(i?Nt(t):o.slice(0,40))}),{changed:!0,gate:structuredClone(n)}}function Oc(t,e){if(!e.objectIds.length)throw new d("invalid_operation","At least one object id is required");let n=Ne(t),o=new Map(n.map(u=>[u.id,u])),i=e.objectIds.filter(u=>!o.has(u));if(i.length)throw new d("object_not_found",`Unknown object id(s): ${i.join(", ")}`,{objectIds:i});let a=e.objectIds.filter(u=>!pe(o.get(u)));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:qo(t,e.gateId),s=new Set(e.objectIds.flatMap(u=>{let g=o.get(u);return g.type==="section"?[g.logicalSectionId??g.id]:[]})),c=n.filter(u=>pe(u)&&(e.objectIds.includes(u.id)||u.type==="section"&&s.has(u.logicalSectionId??u.id))),l=r?Lt(r):void 0,f=!1;for(let u of c){let g=`${u.entranceGateId??""}|${$o(u)??""}`;r?u.entranceGateId=r.id:delete u.entranceGateId,Vo(u,l),`${u.entranceGateId??""}|${$o(u)??""}`!==g&&(f=!0)}return{changed:f,objectIds:c.map(u=>u.id)}}function Xo(t,e){let n=new Map(e.filter(Io).map(i=>[i.id,i.label?.trim()??""]));if(!n.size)return[];let o=[];for(let i of Ne(t))!pe(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 _c(t,e){for(let n of t){if(!pe(n)||!n.entranceGateId)continue;let o=e.get(n.entranceGateId);o&&(n.entranceGateId=o)}}function bi(t,e,n=Jo,o=!0){return{type:"shape",id:t,kind:e.length===2?"line":"polyline",label:it(n,40,"Route name"),points:e.map(i=>({x:i.x,y:i.y})),stroke:{...Uo},lineCap:"round",lineJoin:"round",endEnding:"arrow",route:o?{stepFree:!0}:{}}}function Pc(t,e){let n=R(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=bi(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 Ac(t,e){let n=Ne(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?(Bt(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=it(e.route.name,40,"Route name"):n.label?.trim()||(n.label=Jo),n.route||(n.stroke={...Uo}),n.route=i}return{changed:JSON.stringify(n)!==o,shape:structuredClone(n)}}function Jc(t,e){let n=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(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&&E(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 f=we(r,"Table"),u=Ze(r,"Table"),g=ot(r,"Table"),h=To(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),rt(m,g),Do(m,h),r.fill===null&&delete m.fill,m.shape==="round")delete m.seatCountsBySide,m.automaticRadius===!0?m.radius=eo(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(u&&delete m.displayType,f&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let x=["top","bottom","left","right"],C=x.reduce((_,F)=>_+m.seatCountsBySide[F],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)&&be(m.label))throw new d("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),p=new Map(y.map(v=>[v.id,v])),S=new Set(o),I=new Map;for(let v of j(t))for(let m of v.objects){let x=m.type==="table"?p.get(m.id)??m:m,C=[];x.type==="row"?C=q(x).map(_=>_.label):x.type==="table"?C=x.bookAsWhole||x.variableOccupancy?[x.label]:Ae(x).map(_=>_.label):x.type==="booth"?C=[x.label]:x.type==="gaArea"&&(C=ne(x));for(let _ of C){let F=I.get(_);if(F&&(S.has(F)||S.has(x.id)))throw new d("invalid_operation",`Inventory label "${_}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:_,conflictingObjectIds:[F,x.id]});I.set(_,F??x.id)}}let b=!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&&(b=!0)}return{floorId:n.floorId,changed:b,tableIds:o}}function qc(t,e){let n=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(p=>n.objects.find(S=>S.type==="booth"&&S.id===p)),a=o.filter((p,S)=>!i[S]);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&&E(t,r.categoryKey);let s=(p,S,I,b)=>{if(S!==void 0&&(!Number.isFinite(S)||S<I||S>b))throw new d("invalid_operation",`${p} must be from ${I} to ${b}`)};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 p=Tn(r.points);if(!p.ok)throw new d("invalid_operation",p.message??"The booth outline is not a valid simple polygon")}let l=r.points!=null?r.points.map(p=>({x:p.x,y:p.y})):void 0;delete r.points;let f=we(r,"Booth"),u=Ze(r,"Booth"),g=ot(r,"Booth"),h=Lo(r),y=!1;for(let p of i){let S=JSON.stringify(p);Object.assign(p,r),rt(p,g),No(p,h),f&&delete p.displayLabel,u&&delete p.displayType,c?delete p.points:l&&(p.points=l),JSON.stringify(p)!==S&&(y=!0)}return{floorId:n.floorId,changed:y,boothIds:o}}function Hc(t,e){let n=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(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&&E(t,r.categoryKey),r.capacity!==void 0&&(!Number.isInteger(r.capacity)||r.capacity<1||r.capacity>H))throw new d("invalid_operation",`capacity must be an integer from 1 to ${H}`);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=we(r,"GA area"),c=Ze(r,"GA area"),l=ot(r,"GA area"),f=ko(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&&kt(h,r.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${h.label}" cannot append that capacity safely`,{gaAreaId:h.id})}let u=i.map(h=>{let y=structuredClone(h),p=r.capacity===void 0?h.inventorySegments:kt(h,r.capacity);return Object.assign(y,r),rt(y,l),Mo(y,f),p!==void 0&&(y.inventorySegments=p),s&&delete y.displayLabel,c&&delete y.displayType,y});Fo(t,u);let g=!1;for(let[h,y]of i.entries()){let p=u[h],S=JSON.stringify(y);for(let I of Object.keys(y))I in p||delete y[I];Object.assign(y,p),JSON.stringify(y)!==S&&(g=!0)}return{floorId:n.floorId,changed:g,gaAreaIds:o}}function Wo(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+=q(i).length:i.type==="table"?o+=Ae(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=de(i)));return o}function Vc(t,e){let n=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=>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 Xo(t,a),{floorId:n.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+de(c),0),remainingObjectCount:n.objects.length}}function Xc(t,e){let n=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=>n.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 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:f=4,opacity:u=.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(f)||f<0||f>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(u)||u<.1||u>1)throw new d("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(l=>Object.prototype.hasOwnProperty.call(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(!mo(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 f=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)!==f&&(ke(l),c=!0)}return{floorId:n.floorId,changed:c,textIds:o}}function Wc(t,e){let n=R(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=Gn(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),f=l===void 0||l===""||l==="Row"?e.displayType===void 0?void 0:null:l,u=!1;return r.forEach((g,h)=>{let y=c[h].label.normalize("NFKC").replace(/\s+/g," ").trim();if(s(g)!==y&&(u=!0,g.segmentedRow?g.segmentedRow.displayLabel=y:g.displayLabel=y),f!==void 0){if(f===null){g.displayType!==void 0&&(u=!0,delete g.displayType);return}g.displayType!==f&&(u=!0,g.displayType=f)}}),{floorId:n.floorId,changed:u,rows:r.map(g=>({id:g.id,displayLabel:s(g),...g.displayType?{displayType:g.displayType}:{}}))}}function Yc(t,e){let n=_o.find(f=>f.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=R(t,e.floorId),a=new Set,r=n.build().map(f=>structuredClone(f));for(let f of r)f.id=M(t,f.type,e.idFactory,a),se(f,e.center.x,e.center.y),o%360&&Po(f,e.center,o);for(let f of n.categories)t.categories.some(u=>u.key===f.key)||t.categories.push({...f});let s=r.filter(f=>f.type==="row");if(s.length){let f=0;for(let u of i.objects){if(u.type!=="row")continue;let g=tt(u.label);g!=null&&(f=Math.max(f,g+1))}for(let u of s)u.label=L(f++)}let c=new Set(i.objects.flatMap(f=>"label"in f&&f.label?[f.label]:[]));for(let f of r){if((f.type==="table"||f.type==="booth")&&c.has(f.label)){let u=/^(.*?)(\d+)$/.exec(f.label),g=u?u[1]:`${f.label} `,h=u?Number.parseInt(u[2],10):1;do h++;while(c.has(`${g}${h}`));f.label=`${g}${h}`}"label"in f&&f.label&&c.add(f.label)}i.objects.push(...r);let l=null;if(n.sectionLabel&&e.wrapInSection!==!1){let f=ye(r);if(f){let u={type:"section",id:M(t,"sec",e.idFactory,a),label:n.sectionLabel,outline:f};i.objects.push(u),l=u.id}}return{floorId:i.floorId,blockKey:n.key,createdIds:[...r.map(f=>f.id),...l?[l]:[]],sectionId:l}}function pi(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=kn(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 yi(t,e){let n=R(t,e.floorId),o=n.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=pi(e.path),a=q(o),r=structuredClone(o);r.path=i.path,r.origin={...i.path.start};let s=q(r),c=a.map((f,u)=>Math.hypot(f.x-s[u].x,f.y-s[u].y)),l=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((f,u)=>f+u,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function il(t,e){let n=yi(t,e);if(!n.changed)return n;let i=R(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 wi(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 Ii(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=wi(e,n);return o?{x:o[0],y:o[1]}:null}function Yo(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function Si(t,e){let n=R(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=j(t).find(h=>h.id===n.floorId),r=e.mode==="outline"?Ii(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=[],f=[],u=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 p=2*Math.asin(h.seatSpacing/(2*y))/Z,S=q(h),I=Math.atan2(h.origin.x-r.x,h.origin.y-r.y)/Z,w=(h.curve!==0?Math.sign(h.curve):S.length>1&&Math.sign(Yo(Math.atan2(S[1].x-r.x,S[1].y-r.y)/Z-I))||1)*p*(h.seatCount-1);if(Math.abs(w)>320){l.push(h.id);continue}let v=-I,m=h.curve+(w-h.curve)*u,x=h.rotation+Yo(v-h.rotation)*u,C={...h,curve:m,rotation:x},F=q(C).map((B,z)=>Math.hypot(B.x-S[z].x,B.y-S[z].y));f.push({rowId:h.id,fromCurve:h.curve,targetCurve:w,resultCurve:m,fromRotation:h.rotation,resultRotation:x,rmsMovement:Math.sqrt(F.reduce((B,z)=>B+z**2,0)/F.length),maxMovement:Math.max(...F)})}let g=f.map(h=>h.rmsMovement);return{floorId:n.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...r},strength:i,rows:f,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:g.length?g.reduce((h,y)=>h+y,0)/g.length:0,maxMovement:f.length?Math.max(...f.map(h=>h.maxMovement)):0}}function al(t,e){let n=Si(t,e),o=R(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 Qo(t,e,n,o){let i=Y(t,e,n),a=Y(t,e,o),r=Y(n,o,t),s=Y(n,o,e);return i*a<-1e-9&&r*s<-1e-9}function Zo(t,e){return t.some((n,o)=>{let i=t[(o+1)%t.length];return e.some((a,r)=>Qo(n,i,a,e[(r+1)%e.length]))})}function vi(t){if(t.length<3||t.length>256||Math.abs(Xe(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)&&Qo(t[e],t[(e+1)%t.length],t[n],t[(n+1)%t.length]))return!1;return!0}function at(t,e,n){let o=R(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"?Dn(i):i.points;return{target:o,object:i,outer:a}}function er(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:Wo(t.objects.filter(i=>i.id!==e.id),n)}}function Ut(t,e){let{target:n,object:o,outer:i}=at(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!vi(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(Zo(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>=_t)throw new d("invalid_operation",`A shape holds at most ${_t} 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 f=r[l];if(Zo(a,f)||$(a[0],f,void 0)||$(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let c=er(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 sl(t,e){let n=Ut(t,e),{object:o}=at(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 xi(t,e){let{target:n,object:o}=at(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=er(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 cl(t,e){let n=xi(t,e),{object:o}=at(t,n.floorId,n.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function Ci(t){let e=le(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function tr(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 Ri(t,e){let n=R(t,e.floorId),o=tr(n.objects,e.sectionIds),i=Fe(oe(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),f=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 p of Ye(y).keys())c.add(p);else(y.type==="booth"||y.type==="gaArea")&&c.add(y.categoryKey)}let u=o.logicalSectionIds.every(h=>(a.get(h)?.seatCount??0)>0),g=o.logicalSectionIds.every(h=>a.get(h)?.objectIds.some(y=>{let p=r.get(y);return p?.type==="row"||p?.type==="table"||p?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:u,...u&&c.size===1?{categoryKey:[...c][0]}:!u&&!s.length&&f.size===1?{categoryKey:[...f][0]}:{},categoryMixed:u?c.size!==1:!s.length&&f.size>1,viewApplicable:g}}function yl(t,e){E(t,e.categoryKey);let n=Ri(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=R(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(f=>{if(f.categoryKey===void 0)return[f];let u={...f};return delete u.categoryKey,r++,a=!0,Object.keys(u).some(g=>g!=="index")?[u]:[]});l.length?c.overrides=l:delete c.overrides}return{...n,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function nr(t,e){let n=R(t,e.floorId),o=tr(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=Ci(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&&Qe(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ie(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),f=c?n.objects.filter(h=>h.type==="section"&&l.has(h.logicalSectionId??h.id)):[],u=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 p=S=>{h.physical3dProvenance&&(delete h.physical3dProvenance[S],Object.keys(h.physical3dProvenance).length===0&&delete h.physical3dProvenance)};a.height===null?(delete h.height,p("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,p("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,p("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,u.add(h.id))}for(let h of f){let y=JSON.stringify(h),p=h.viewFromSeatUrl;a.displayLabel===null?delete h.displayLabel:a.displayLabel!==void 0&&(h.displayLabel=a.displayLabel);let S=h.entrance;if(a.entrance===null||a.entrance===""?delete h.entrance:a.entrance!==void 0&&(h.entrance=a.entrance),h.entrance!==S&&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!==p&&delete h.viewFromSeatMeta,a.labelStyle!==void 0){let I=Ie(h.labelPresentation,a.labelStyle);I?h.labelPresentation=I:delete h.labelPresentation}a.zone===null?delete h.zone:a.zone!==void 0&&(h.zone=a.zone),JSON.stringify(h)!==y&&(g=!0,u.add(h.id))}return{floorId:n.floorId,changed:g,sectionIds:i,affectedSectionIds:[...u]}}function Oi(t,e){let n=R(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+de(r),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function wl(t,e){let n=Oi(t,e),i=R(t,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function _i(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),f=Math.sin(c),u=G(t);o=g=>{let h=g.x-u.x,y=g.y-u.y;return{x:u.x+h*l-y*f,y:u.y+h*f+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=We(t.outlinePath,o,i,a)),a&&t.edgeCurvature&&(t.edgeCurvature=jn(t.edgeCurvature)),t.holes&&(t.holes=Q(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 Il(t,e){let n=R(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,..._i(o,e.transform)}}function Sl(t,e){let n=R(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(!Mn(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ot(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 Pi(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function vl(t,e){return Ai(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Ai(t,e){let n=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,r=!1;try{for(let s of o){let c=n.objects.find(b=>b.type==="section"&&b.id===s);if(!c||!Pi(c))continue;let f=structuredClone(c);a.set(c.id,{section:c,snapshot:f});let u=JSON.stringify(c),g=(c.sourceOutline??c.outline).map(b=>({...b})),h=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),p=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(b=>Math.min(100,Math.max(-100,b))),S=p?.some(b=>Math.abs(b)>.5)===!0,I=h>.5||S?En(g,{cornerSmoothing:h,...S?{edgeCurvature:p}:{}}):null;I?(c.sourceOutline=g,c.outlinePath=I,c.outline=Ot(I),h>.5?c.cornerSmoothing=h:delete c.cornerSmoothing,S?c.edgeCurvature=[...p]:delete c.edgeCurvature):(c.outline=g,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let b=0;b<(c.holes?.length??0);b+=1)Ut(t,{floorId:n.floorId,objectId:c.id,points:c.holes[b],holeIndex:b});JSON.stringify(c)!==u&&(r=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let f=c;for(let u of Object.keys(f))delete f[u];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:r,sectionIds:o,affectedSectionIds:[...i]}}function _l(t,e,n={}){let o=!1;for(let i of e){let a=nr(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=R(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=R(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=Te(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&&et(t),{changed:o}}var ki=new Set(["companion","child","senior","student","membership","custom"]);function Se(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&&!je(i.seatGlyph))throw new d("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,f=new Set;for(let u of i.tiers){let g=u.id.trim(),h=u.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||f.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(u.price)||u.price<0||u.price>1e6)throw new d("invalid_operation",`Ticket tier ${g} price must be from 0 to 1000000`,{categoryKey:a,tierId:g});if(u.restriction!=null&&!ki.has(u.restriction))throw new d("invalid_operation",`Ticket tier ${g} has an unknown restriction`,{categoryKey:a,tierId:g});if(u.buyerMessage!=null){if(u.buyerMessage=u.buyerMessage.normalize("NFKC").trim(),!u.buyerMessage)delete u.buyerMessage;else if(u.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${g} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:g})}if(u.currency!=null&&(u.currency=u.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(u.currency)))throw new d("invalid_operation",`Ticket tier ${g} must use a three-letter ISO currency`,{categoryKey:a,tierId:g});if(u.applicability!=null){let p=u.applicability.seatLabels?.map(I=>I.normalize("NFKC").trim()),S=u.applicability.accessibility;if(p&&(!p.length||p.length>1e4||p.some(I=>!I||I.length>160)||new Set(p).size!==p.length)||S&&(!S.length||S.some(I=>!He.some(b=>b.key===I))||new Set(S).size!==S.length))throw new d("invalid_operation",`Ticket tier ${g} has invalid seat applicability`,{categoryKey:a,tierId:g});u.applicability={...p?{seatLabels:p}:{},...S?{accessibility:[...S]}:{}},!u.applicability.seatLabels&&!u.applicability.accessibility&&delete u.applicability}if(u.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(u.evidence.provenance)||typeof u.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g});if(u.evidence.sourceDescription=u.evidence.sourceDescription.normalize("NFKC").trim(),!u.evidence.sourceDescription||u.evidence.sourceDescription.length>240||u.evidence.capturedAt!==void 0&&(u.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(u.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g})}l.add(g),f.add(y)}}}return o}function Jt(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(u=>u.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,...f}=c;typeof f.label=="string"&&(f.label=f.label.normalize("NFKC").trim()),typeof f.color=="string"&&(f.color=f.color.toLowerCase()),Object.assign(s,f),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(u=>{let g={...u,id:u.id.trim(),name:u.name.normalize("NFKC").trim()};return u.buyerMessage?.trim()?g.buyerMessage=u.buyerMessage.normalize("NFKC").trim():delete g.buyerMessage,g})),delete s.referenceDirectSeatImport}let i=Se(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...n],categories:t.categories}}function Ll(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=Se(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 Nl(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=Se(n.map((c,l)=>{let f=structuredClone(s.get(c));return c!==o[l]&&delete f.referenceDirectSeatImport,f})),{changed:!0,categoryKeys:n,categories:t.categories}}function or(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 Mi(t,e){let n=or(t),o=or(e);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var Fi=3600;function ji(t,e,n=Et){return n.find(i=>t.every(a=>Mi(i,a)>=Fi))??n[e%n.length]}function Gl(t,e){let n=e?.palette??Et;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 Jt(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 Kl(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=Se(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 qt(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=Se([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(r=>r.key===o),categories:a}}var Ei=["#3e8e7e","#6e7ff0","#b0700f","#b05fc4"],Ti=[...Ei,"#4d7c0f","#c026d3","#a86b00","#d6336c","#e5484d","#dc2626"],Di={row:"#6e7ff0",table:"#3e8e7e",booth:"#b05fc4",gaArea:"#b0700f"};function Li(t,e){let n=Di[t];return!n||!e.includes(n)?e:[n,...e.filter(o=>o!==n)]}var Ni="#f5f6f8",Gi="#f7f8fb",Ki=26;function $i(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,f=u=>Math.round((u+l)*255).toString(16).padStart(2,"0");return`#${f(r)}${f(s)}${f(c)}`}function Bi(t,e,n,o,i){let a=f=>t.every(u=>{let g=ro(f,u);return g==null||g>=Ki}),r=[Ni,i??Gi],s=(f,u)=>Mt(lo(f,u,so),u)??0,c=f=>o==="gaArea"?[...r,"#12151d"].every(u=>s(f,u)>=3):r.every(u=>(Mt(f,u)??0)>=3),l=e.find(f=>a(f)&&c(f));if(l)return l;for(let f=0;f<360;f+=12)for(let u of[.52,.44,.6]){let g=$i(f,.62,u);if(a(g)&&c(g))return g}return n}function zi(t,e){let n=Ee.find(a=>a.objectType===e).creationWord,o=t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim();return Ee.some(a=>a.creationWord.toLowerCase()===o.toLowerCase())?n:`${o} \u2013 ${n}`}function Ui(t){let e=new Map;for(let n of j(t))for(let o of n.objects){let i=Ee.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of Ye(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 Ji(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 qi(t,e,n){let o=Ui(t),i=f=>{let u=o.get(f);return!u||u.size===0||u.size===1&&u.has(n)},a=t.categories.find(f=>f.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};let r=t.categories.find(f=>{let u=o.get(f.key);return u?.size===1&&u.has(n)});if(!a&&r)return{kind:"existing",categoryKey:r.key,label:r.label};let s=Ee.find(f=>f.objectType===n),c=a?zi(a.label,n):s.creationWord,l=t.categories.find(f=>f.label.toLowerCase()===c.toLowerCase()&&i(f.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:Ji(t,c)}}function $l(t,e,n,o){let i=qi(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 Hi(t,n,a,i.label,o)}function Hi(t,e,n,o,i){let a=i.palette??Ti,r=t.categories.map(f=>f.color),s=i.suggestColor?.(r.map(f=>f.toLowerCase()))??ji(r,t.categories.length),c=Bi(r,Li(e,a),s,e,t.theme?.background),l=qt(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 Vi(t,e){let n=new Set;for(let o of j(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 rr(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=Vi(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=Se(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}function ql(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=Xi(t.categories,o.label),a=qt(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)&&Jt(t,{updates:[{categoryKey:a.category.key,patch:{...o.notForSale?{notForSale:!0}:{},...o.seatGlyph?{seatGlyph:o.seatGlyph}:{}}}]})}return{categoryKeys:n,categories:t.categories}}function Xi(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 Hl(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 j(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 f={...l};return delete f.categoryKey,Object.keys(f).some(u=>u!=="index")?[f]:[]});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=rr(t,{categoryKey:n});return{movedObjectIds:[...i],categories:a.categories}}var Wi=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Yi=["seat","deck","shell","fascia"];function Ql(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 Wi){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=D(r,`Theme ${a}`))}if(n.sectionDetail===null)delete i.sectionDetail;else if(n.sectionDetail!==void 0){if(n.sectionDetail!=="rows"&&n.sectionDetail!=="seats")throw new d("invalid_operation","Theme sectionDetail must be rows or seats");i.sectionDetail=n.sectionDetail}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<Ft||n.seatScale>jt)throw new d("invalid_operation",`Theme seatScale must be from ${Ft} to ${jt}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=le(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 Yi){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 ed(t,e){let n=e.url===null?null:le(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(u=>u.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===o,l=o?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,f=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,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 ve(t,e){let n=oe(t,e.floorId),o=ee(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 st(t,e){E(t,e.categoryKey);let n=(...f)=>f.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");if(e.seatsPerRowByRow!==void 0&&(i!=="fixed-count"||e.seatsPerRowByRow.length!==e.rowCount||e.seatsPerRowByRow.some(f=>!Number.isInteger(f)||f<2||f>300)))throw new d("invalid_operation","Fixed Arc/Fan seats per row need one count from 2 to 300 for every row");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(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:r,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function ir(t,e,n){let o=n*Z;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function Zi(t,e,n,o){let i=Math.abs(o-n)*Z,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,f])=>{let u=t.aisleGaps[l];if(!u)return[];let g=u/e/i/2;return[[Math.max(0,f-g),Math.min(1,f+g)]]}).sort((l,f)=>l[0]-f[0]),r=[];for(let l of a){let f=r[r.length-1];f&&l[0]<=f[1]?f[1]=Math.max(f[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,f])=>e*i*(f-l)>=t.seatPitch*.75)}function Vt(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 ct(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 f=Zi(t,r,c,l);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let u=f.map(([y,p])=>r*Math.abs(l-c)*Z*(p-y)),g=t.fit==="fixed-count"?Vt(u,t.seatsPerRowByRow?.[i]??t.seatsPerRow):u.map(y=>Math.max(2,Math.round(y/t.seatPitch)+1)),h=t.seatLabelStart;f.forEach(([y,p],S)=>{let I=c+(l-c)*y,b=c+(l-c)*p;t.facing==="outward"&&([I,b]=[b,I]);let w=g[S];if(w>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let v=Math.abs(b-I)*Z/(w-1),m=2*r*Math.sin(v/2),x={type:"row",id:n(i,S),label:L(t.rowLabelStart+i),origin:ir(t.center,r,I),rotation:-I,curve:b-I,seatCount:w,seatSpacing:m,categoryKey:t.categoryKey,seatLabelStart:h,...f.length>1?{aisleSeats:S===0?"end":S===f.length-1?"start":"both"}:{},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}:{},...t.seatsPerRowByRow?{seatsPerRowByRow:[...t.seatsPerRowByRow]}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:S}};o.push(x),h+=w})}return o}var Qi=150,Ht=22,ea=3;function ar(t,e){if(Math.abs(t.endAngle-t.startAngle)<=Qi)return ye(e);let n=(t.startAngle+t.endAngle)/2,o=1/0,i=0,a=1/0,r=-1/0;for(let y of e)for(let p of q(y)){let S=p.x-t.center.x,I=p.y-t.center.y,b=Math.hypot(S,I),w=(Math.atan2(S,I)/Z-n+540)%360-180;o=Math.min(o,b),i=Math.max(i,b),a=Math.min(a,w),r=Math.max(r,w)}if(!Number.isFinite(o))return null;let s=Math.max(0,o-Ht),c=i+Ht,l=Ht/Math.max(o,1)/Z,f=Math.max(a-l,-179.5),u=Math.min(r+l,179.5),g=Math.max(2,Math.ceil((u-f)/ea)),h=(y,p)=>Array.from({length:g+1},(S,I)=>{let b=p?g-I:I;return ir(t.center,y,n+f+(u-f)*b/g)});return[...h(c,!1),...s>0?h(s,!0):[{...t.center}]]}function sr(t,e){let n=st(t,e),o=R(t,e.floorId),i=ct(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*Bn*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 Xt(t,e){let n=st(t,e),o=R(t,e.floorId),i=new Set,a=M(t,"fan",e.idFactory,i),r=ct(n,a,()=>M(t,"r",e.idFactory,i)),s=sr(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(l){if(l.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let u=ar(n,r);u&&(c=M(t,"sec",e.idFactory,i),f={type:"section",id:c,label:l,outline:u,arcFanGroupId:a})}return o.objects.push(...r,...f?[f]:[]),{floorId:o.floorId,rowIds:r.map(u=>u.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function ta(t,e){let n=R(t,e.floorId),o=n.objects.filter(u=>u.type==="row"&&u.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=u=>{let g=u.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,seatsPerRowByRow:g.seatsPerRowByRow,facing:g.facing,taperDegrees:g.taperDegrees,skewDegrees:g.skewDegrees,aisleGaps:g.aisleGaps,rowLabelStart:g.rowLabelStart,seatLabelStart:g.seatLabelStart})};if(o.some(u=>a(u)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let r=n.objects.find(u=>u.type==="section"&&u.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,...i.seatsPerRowByRow?{seatsPerRowByRow:[...i.seatsPerRowByRow]}:{},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=st(t,s),l=new Set(ct(c,e.groupId,(u,g)=>`${u}:${g}`).map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`));if(l.size!==f.size||[...l].some(u=>!f.has(u)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function ad(t,e){ta(t,{floorId:e.floorId,groupId:e.groupId});let n=st(t,e),o=R(t,e.floorId),i=o.objects.filter(p=>p.type==="row"&&p.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(p=>p.type==="section"&&p.arcFanGroupId===e.groupId),r=new Map(i.map(p=>[`${p.arcFanGeneration.rowIndex}:${p.arcFanGeneration.segmentIndex}`,p.id])),s=new Set,c=ct(n,e.groupId,(p,S)=>r.get(`${p}:${S}`)??M(t,"r",e.idFactory,s)),l=sr(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),u=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let p=ar(n,c);p&&(u={type:"section",id:a?.id??M(t,"sec",e.idFactory,s),label:f,outline:p,arcFanGroupId:e.groupId})}let g=new Set([...i.map(p=>p.id),...a?[a.id]:[]]),h=Math.min(...o.objects.map((p,S)=>g.has(p.id)?S:1/0)),y=o.objects.filter(p=>!g.has(p.id));return y.splice(Number.isFinite(h)?h:y.length,0,...c,...u?[u]:[]),o.objects.splice(0,o.objects.length,...y),{floorId:o.floorId,rowIds:c.map(p=>p.id),sectionId:u?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function cr(t,e){let n=na(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 na(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,u=String.fromCharCode(65+l%26).repeat(t.length+Math.floor(l/26));return r?u.toLowerCase():u}}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=tt(o);if(i==null)return null;let a=t===t.toLowerCase();return r=>{let s=L(i+r);return a?s.toLowerCase():s}}function Wt(t){return t.segmentedRow?.displayLabel??t.displayLabel??t.label}function oa(t,e=[]){let n=new Set([...W(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 ra(t){let e=new Set(t.flatMap(o=>o.type==="row"?[Wt(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 ia(t,e){let n=t.filter(c=>c.type==="section"),o=n.find(c=>$(e,c.outline,c.holes));if(!o)return ra(t);let i=t.filter(c=>c.type==="row"&&Wn(t,c,n)===o),a=new Set(i.map(Wt)),r=i[i.length-1],s=r?Wt(r):void 0;return()=>{let c=cr(s,a);return a.add(c),s=c,c}}function lr(t,e){let n=e.pending??[],o=oa(t,n),i=ia([...R(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}})}var aa=1,Yt=.01;function dr(t,e){let n=J(t),o=n[n.length-1],i=J(e)[0];if(!o||!i)return null;let a=Math.hypot(i.x-o.x,i.y-o.y),r=a>Yt?{x:(i.x-o.x)/a,y:(i.y-o.y)/a}:{x:Math.cos(e.rotation*Math.PI/180),y:Math.sin(e.rotation*Math.PI/180)};return{distance:a,direction:r,pitch:(t.seatSpacing+e.seatSpacing)/2}}function fr(t,e){return e==="break"?t*(1+aa):t}function pd(t,e){let n=t[e-1],o=t[e];if(!n||!o||o.segmentedRow?.boundaryBefore!=="break")return!1;let i=dr(n,o);return!!i&&fr(i.pitch,"break")-i.distance>=Yt}function lt(t,e,n){let o=t[e-1],i=t[e];if(!o||!i)return!1;let a=dr(o,i);if(!a)return!1;let r=fr(a.pitch,n),s=n==="break"?Math.max(0,r-a.distance):Math.min(0,r-a.distance);if(Math.abs(s)<Yt)return!1;for(let c of t.slice(e))se(c,a.direction.x*s,a.direction.y*s);return!0}function ur(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 hr(t,e){if(E(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=R(t,e.floorId),a=new Set,r=lr(t,{floorId:e.floorId,origin:e.origin,count:e.rowCount}),s=Kt(e.rotation??0),c=e.curve??0,l=e.style,f=l?M(t,"rowblock",e.idFactory,a):void 0,u=l?ur({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*te),y:Math.sin(s*te)},h={x:-g.y,y:g.x},y=Array.from({length:e.rowCount},(I,b)=>{let w=l==="intertwined"&&b%2===1?o/2:0,v={type:"row",id:M(t,"r",e.idFactory,a),...r[b],origin:{x:e.origin.x+h.x*b*n+g.x*w,y:e.origin.y+h.y*b*n+g.y*w},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&f&&u&&(v.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:l,rowIndex:b,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:n,seatSpacing:o,curve:c,signature:u}),v});i.objects.push(...y);let p=null,S=e.sectionLabel?.trim();if(S){let I=ye(y);if(I){let b={type:"section",id:M(t,"sec",e.idFactory,a),label:S,outline:I};i.objects.push(b),p=b.id}}return{floorId:i.floorId,rowIds:y.map(I=>I.id),sectionId:p,createdIds:[...y.map(I=>I.id),...p?[p]:[]]}}function gr(t,e){let n=new Set(W(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 sa(t,e){let n=new Set(W(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 ca=456;function Zt(t){let e=Math.sqrt(Math.max(1,t)*ca);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function mr(t,e){if(E(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=R(t,e.floorId),o=new Set,{width:i,height:a}=Zt(e.capacity),r=sa(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 br(t,e){if(E(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=R(t,e.floorId),a=new Set,r=gr(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 pr(t,e){if(E(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=R(t,e.floorId),a=new Set,r=gr(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 dt(t,e){let n=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(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):[])),f="";for(let g=0;g<100;g+=1){let h=e.idFactory("rowgroup");if(h&&!l.has(h)){f=h;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let u=r[0];return r.forEach((g,h)=>{g.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:h,componentCount:r.length,boundaryBefore:h===0?"start":e.boundaries[h-1],displayLabel:c,...u.displayType?{displayType:u.displayType}:{},...u.labelPresentation?{labelPresentation:structuredClone(u.labelPresentation)}:{},...u.viewFromSeatUrl?{viewFromSeatUrl:u.viewFromSeatUrl}:{},...u.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(u.viewFromSeatMeta)}:{},...u.confidenceEvidence?{confidenceEvidence:structuredClone(u.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:f,rowIds:o,changed:!0}}function Rd(t,e){let n=R(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 Od(t,e){let n=R(t,e.floorId),o=n.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId).sort((s,c)=>s.segmentedRow.componentIndex-c.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(s=>s!=="continuous"&&s!=="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(s=>s.segmentedRow)),r=!1;return e.boundaries?.forEach((s,c)=>{s==="break"&&(r=lt(o,c+1,"break")||r)}),o.forEach((s,c)=>{let l=s.segmentedRow,f=l.viewFromSeatUrl;i!==void 0&&(l.displayLabel=i),e.boundaries&&c>0&&(l.boundaryBefore=e.boundaries[c-1]),e.smoothing!==void 0&&(l.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete l.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(l.viewFromSeatUrl=e.viewFromSeatUrl),!l.viewFromSeatUrl||e.viewFromSeatMeta===null?delete l.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?l.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&l.viewFromSeatUrl!==f&&delete l.viewFromSeatMeta}),{floorId:n.floorId,groupId:e.groupId,rowIds:o.map(s=>s.id),changed:r||JSON.stringify(o.map(s=>s.segmentedRow))!==a,...r?{seatsMoved:!0}:{}}}function _d(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=R(t,e.floorId),o=n.objects.filter(P=>P.type==="row"&&P.rowBlockGeneration?.groupId===e.groupId).sort((P,V)=>P.rowBlockGeneration.rowIndex-V.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((P,V)=>{let A=P.rowBlockGeneration;return A.kind!=="row-block-v1"||A.rowIndex!==V||A.signature!==i.signature||JSON.stringify(A)!==JSON.stringify({...i,rowIndex:V})}))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,f=e.seatSpacing??i.seatSpacing,u=e.curve??i.curve,g=Number.isFinite(e.rotation??i.rotation)?Kt(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,f].every(P=>Number.isFinite(P)&&P>0)||!Number.isFinite(u)||!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=ur({style:r,origin:h,rotation:g,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:f,curve:u}),p={x:Math.cos(g*te),y:Math.sin(g*te)},S={x:-p.y,y:p.x},I=new Map(o.map(P=>[P.rowBlockGeneration.rowIndex,P])),b=new Set,w=new Set(n.objects.filter(P=>P.type==="row").filter(P=>!o.includes(P)).map(P=>P.label)),v=n.objects.filter(P=>P.type==="row").length,m=()=>{for(;w.has(L(v));)v+=1;let P=L(v);return w.add(P),v+=1,P},x=[],C=[];for(let P=0;P<s;P+=1){let V=r==="intertwined"&&P%2===1?f/2:0,A=I.get(P);A||(A={type:"row",id:M(t,"r",e.idFactory,b),label:m(),origin:{...h},rotation:g,curve:u,seatCount:c,seatSpacing:f,categoryKey:o[0].categoryKey},C.push(A.id)),A.origin={x:h.x+S.x*P*l+p.x*V,y:h.y+S.y*P*l+p.y*V},A.rotation=g,A.curve=u,A.seatCount=c,A.seatSpacing=f,delete A.path,delete A.arcFanGeneration,A.overrides&&(A.overrides=A.overrides.filter(U=>U.index<c),A.overrides.length||delete A.overrides),A.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:r,rowIndex:P,rowCount:s,seatsPerRow:c,origin:{...h},rotation:g,rowGap:l,seatSpacing:f,curve:u,signature:y},x.push(A)}let _=o.slice(s).map(P=>P.id),F=Math.min(...o.map(P=>n.objects.indexOf(P))),B=new Set(o.map(P=>P.id)),z=n.objects.filter(P=>!B.has(P.id));return z.splice(F,0,...x),n.objects.splice(0,n.objects.length,...z),{floorId:n.floorId,groupId:e.groupId,rowIds:x.map(P=>P.id),createdRowIds:C,removedRowIds:_,changed:a!==JSON.stringify(x)||C.length>0||_.length>0}}function yr(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 la(t){let e=t.length,n=t.reduce((I,b)=>I+b.x,0)/e,o=t.reduce((I,b)=>I+b.y,0)/e,i=0,a=0,r=0,s=0,c=0,l=0,f=0;for(let I of t){let b=I.x-n,w=I.y-o;i+=b*b,a+=w*w,r+=b*w,s+=b*b*b,c+=w*w*w,l+=b*w*w,f+=w*b*b}let u=i*a-r*r;if(Math.abs(u)<1e-9)return null;let g=(s+l)/2,h=(c+f)/2,y=(g*a-h*r)/u,p=(h*i-g*r)/u,S=Math.sqrt(y*y+p*p+(i+a)/e);return Number.isFinite(S)?{center:{x:y+n,y:p+o},radius:S}:null}function Ge(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):yr(t),seatCount:i,ordered:t}}function da(t){if(t.length<3)return Ge(t);let e=t[0],n=t[t.length-1],o=Math.hypot(n.x-e.x,n.y-e.y),i=yr(t);if(o<=0||i<=0)return Ge(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 Ge(t);let r=la(t);if(!r||r.radius<=i/2)return Ge(t);let s=g=>{let h=g[0],y=g[1],p=h.x-r.center.x,I=-(h.y-r.center.y),b=p;I*(y.x-h.x)+b*(y.y-h.y)<0&&(I=-I,b=-b);let w=Math.hypot(I,b)||1;I/=w,b/=w;let v=(r.center.x-h.x)*b+(r.center.y-h.y)*-I;return{tx:I,ty:b,centreSide:v}},c=t,l=s(c);l.centreSide<0&&(c=[...t].reverse(),l=s(c));let u=2*Math.asin(Math.min(1,i/(2*r.radius)))*(c.length-1)*180/Math.PI;return!Number.isFinite(u)||u>=359?Ge(t):{origin:{...c[0]},rotation:Math.atan2(l.ty,l.tx)*180/Math.PI,curve:u,seatSpacing:i,seatCount:c.length,ordered:c}}function ft(t,e){let n=da(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[...ft(n.ordered.slice(0,r),e),...ft(n.ordered.slice(r),e)]}function Qt(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function en(t,e){let n="";for(let o of t){if(n.length+o.length>e)break;n+=o}return n.trim()}function tn(t){return en(Qt(t),40)}function wr(t,e=39){return en(Qt(t),Math.max(1,e))}function xe(t,e=80){return en(Qt(t),Math.max(1,e))}function Ir(t){return xe(t).toLocaleLowerCase("en")}function nn(t){return Ir(t)}function Sr(t){return new Map((t??[]).map(e=>[e.index,e]))}function fa(t){let e=Sr(t.overrides),n=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||n.push(Pt(t,o,i))}return n}function ua(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=Sr(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 ha(t){return t.type==="row"?[t.label,...fa(t)]:t.type==="table"?[t.label,...ua(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...ne(t)]:[]}function vr(t,e){let n=new Set;for(let o of t)if(!e?.has(o.id))for(let i of ha(o)){let a=nn(i);a&&n.add(a)}return n}function ga(t,e){if(!Number.isInteger(e)||e<1)return[];let n={label:t,seatCount:e},o=[nn(t)];for(let i=0;i<e;i+=1)o.push(nn(Pt(n,i)));return o.filter(Boolean)}function xr(t,e,n){let o=ga(e,n);if(!o.length||o.some(i=>t.has(i)||be(i)))return!1;for(let i of o)t.add(i);return!0}var ma=1e-6,ba=160,pa=.001,ya=1e-5;function Ce(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>ba)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 Cr(t){return typeof t=="string"&&wr(t)||void 0}function Rr(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(on(t.origin)&&on(e.start)&&on(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=pa+Math.max(1,i)*ya;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<=ma)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 on(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var wa=300;function Ia(t){let e=new Set(W(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=tn(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 Sa(t){let e=vr(W(t));return(n,o)=>{let i=xe(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,s=r?`${xe(i,80-r.length)}${r}`:i;if(s&&xr(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function va(t){return{ordinaryFor:Ia(t),direct:Sa(t)}}function rn(t,e,n){return t.type==="row"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function Or(t,e,n){return t.type==="table"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function xa(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=Ce(`${r.sourceGroupId}:${s}`),f=l&&Ce(c.directSourceRowId)===l?l:void 0;f&&o.set(f,o.has(f)?null:c)}let i=new Map;for(let r of t){let s=Ce(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),f=c[0],u=f.overrides;if(s.length!==1||c.length!==1||!u||!l||!Rr(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:r,rowIds:s.map(g=>g.id)});a.set(r,structuredClone(u))}return a}function _r(t,e,n){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!rn(o,e,n)&&!Or(o,e,n))}function Ca(t,e,n,o,i,a,r){let s=t.sectionId?e.find(f=>f.type==="section"&&f.id===t.sectionId):void 0;if(s){let f=_r(e,n,r).filter(u=>$(G(u),s.outline,s.holes));if(f.length)return{skip:{sectionId:s.id,name:t.name,reason:"section_not_empty",objectIds:f.map(u=>u.id)},rows:[],seats:0}}let c=[],l=0;for(let[f,u]of t.rows.entries()){let g=Math.min(wa,Math.max(1,Math.round(u.seatCount)));if(!Number.isFinite(g)||g<1)continue;let h=u.end.x-u.start.x,y=u.end.y-u.start.y,p=Math.hypot(h,y),S=g>1&&p>0?p/(g-1):o>0?o:24;if(!Number.isFinite(S)||S<=0)continue;let I=p>0?Math.atan2(y,h)*180/Math.PI:0,b={x:u.start.x,y:u.start.y},w=0,v=S,m,x=u.seats?.length===g&&u.seats.every(A=>Number.isFinite(A.x)&&Number.isFinite(A.y))?u.seats:null;if(x&&u.table&&g>=3){let A=u.table.center,U=x.reduce((T,K)=>T+Math.hypot(K.x-A.x,K.y-A.y),0)/g,X=x.map(T=>Math.atan2(T.y-A.y,T.x-A.x)).sort((T,K)=>T-K),ce=0,qe=0;X.forEach((T,K)=>{let me=K+1<X.length?X[K+1]:X[0]+Math.PI*2;me-T>ce&&(ce=me-T,qe=(K+1)%X.length)});let O=ce>1.6*(Math.PI*2/g),k=O?(Math.PI*2-ce)*180/Math.PI:void 0;m={center:{...A},radius:Math.max(1,U-Xn),...k!==void 0?{seatArc:k}:{}},I=O?(X[qe]-ce/2)*180/Math.PI:X[0]*180/Math.PI,b={...A}}let C=[];if(x&&!m&&g>=3){C=ft(x,U=>J({origin:U.origin,rotation:U.rotation,curve:U.curve,seatCount:U.seatCount,seatSpacing:U.seatSpacing}));let A=C[0];b=A.origin,I=A.rotation,w=A.curve,v=A.seatSpacing}if(!Number.isFinite(v)||v<=0)continue;let _=t.sourceGroupId?Ce(`${t.sourceGroupId}:${f}`):void 0,F=_&&Ce(u.directSourceRowId)===_?_:void 0,B=F?Cr(u.directReviewedSuffix):void 0,z=t.sourceGroupId&&u.rowLabel?xe(u.rowLabel):"",P=t.sourceGroupId&&u.rowDisplayLabel?xe(u.rowDisplayLabel):"",V=!!t.sourceGroupId&&u.rowDisplayLabel==="";c.push({label:z?a(z,g):i(),displayLabel:P||(V?"":String(f+1)),origin:b,rotation:I,curve:w,seatCount:C[0]?.seatCount??g,seatSpacing:v,...m?{table:m}:{},...x&&!m?{measured:!0}:{},...F?{directSourceRowId:F}:{},...B?{directReviewedSuffix:B}:{}});for(let A of C.slice(1))c.push({label:i(),displayLabel:String(f+1),origin:A.origin,rotation:A.rotation,curve:A.curve,seatCount:A.seatCount,seatSpacing:A.seatSpacing,measured:!0});l+=g}return{skip:null,rows:c,seats:l}}function qd(t,e,n){E(t,n.categoryKey);let o=R(t,n.floorId),i=e.assetId,a=n.sectionId?o.objects.find(b=>b.type==="section"&&b.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 b of e.sections){if(a&&b.sectionId!==a.id)continue;let w=n.categoryKeyForSection?.(b)??n.categoryKey;E(t,w),r.set(b,w)}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=_r(o.objects,i,a.id).filter(w=>$(G(w),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(w=>w.id)}]}}let c=o.objects.filter(b=>rn(b,i,a?.id)),l=xa(c,e,a?.id),f=[],u=o.objects.filter(b=>rn(b,i,a?.id)||Or(b,i,a?.id)?(f.push(b.id),!1):!0);o.objects.splice(0,o.objects.length,...u);let g=[],h=[],y=[],p=new Set,S=0,I=va(t);for(let b of e.sections){if(a&&b.sectionId!==a.id)continue;let w=Ca(b,o.objects,i,e.seatPitch,I.ordinaryFor(b.name),I.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,...b.sectionId?{sectionId:b.sectionId}:{}},F=r.get(b)??n.categoryKey;if(C.table){x+=1,v.push({type:"table",id:M(t,"t",n.idFactory,p),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:F});continue}let B={type:"row",id:M(t,"r",n.idFactory,p),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:F,...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&&!b.sourceGroupId){let C=j(t).find(_=>_.id===o.floorId);Ra(t,m,C?.focalPoint??t.focalPoint,o.floorId,n.idFactory)}for(let C of v)y.push(C.id);g.push({sectionId:b.sectionId,name:b.name,seats:w.seats,rows:v.length}),S+=w.seats}return{floorId:o.floorId,assetId:i,createdRowIds:y,removedRowIds:f,totalSeats:S,perSection:g,skipped:h}}function Ra(t,e,n,o,i){let a=e.map(h=>J(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 p=a[y],S=p.map((b,w)=>{let v=p[Math.max(0,w-1)],m=p[Math.min(p.length-1,w+1)],x=Math.hypot(m.x-v.x,m.y-v.y);return x<=0?Math.hypot(b.x-s.x,b.y-s.y):Math.abs((b.x-s.x)*(-(m.y-v.y)/x)+(b.y-s.y)*((m.x-v.x)/x))}).sort((b,w)=>b-w),I=p.reduce((b,w)=>b+w.x,0)/p.length;return{row:h,depth:S[Math.floor(S.length/2)],along:I}}).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),f=l.length?l[Math.floor(l.length*.75)]:1/0,u=[],g=-1/0;for(let h of c)(!u.length||h.depth-g>f*.45)&&(u.push([]),g=h.depth),u[u.length-1].push(h.row);u.forEach((h,y)=>{let p=L(y);h.sort((S,I)=>{let b=J(S),w=J(I);return b.reduce((v,m)=>v+m.x,0)/b.length-w.reduce((v,m)=>v+m.x,0)/w.length});for(let S of h)S.displayLabel=p;h.length>=2&&h.length<=64&&dt(t,{floorId:o,rowIds:h.map(S=>S.id),boundaries:h.slice(1).map(()=>"break"),displayLabel:p,idFactory:i})})}function Pr(t,e,n={}){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(p=>o.objects.find(S=>(S.type==="table"||S.type==="booth")&&S.id===p)),r=i.filter((p,S)=>!a[S]);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(p=>p.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[p,S,I]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(S)||S<1||S>I)throw new d("invalid_operation",`${p} must be a whole number from 1 to ${I}`);for(let[p,S]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(S)||S<30||S>2e3)throw new d("invalid_operation",`${p} must be from 30 to 2000 chart units`);let c=e.rows*e.columns;if(c<2)throw new d("invalid_operation","Choose at least two grid cells");let l=i.length*(c-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let f=a.reduce((p,S)=>p+(S.type==="table"?S.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(p=>p.objects):t.objects).reduce((p,S)=>p+(S.type==="row"||S.type==="table"?S.seatCount:S.type==="gaArea"?Math.max(0,Math.floor(S.capacity)):S.type==="booth"?1:0),0),h=f*(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(p=>!!p.referenceInventorySource).length*(c-1)}}}function Xd(t,e,n={}){return Pr(t,e,n).preview}function Wd(t,e,n={}){let{target:o,sources:i,preview:a}=Pr(t,e,n),r=new Set,s=new Set((t.floors?.length?t.floors.flatMap(u=>u.objects):t.objects).flatMap(u=>"label"in u&&u.label?[u.label]:[])),c=[],l=(u,g)=>{let h=Math.max(2,g),y=S=>{let I=`-${S}`;return`${u.slice(0,Math.max(1,80-I.length))}${I}`},p=y(h);for(;s.has(p);)p=y(++h);return s.add(p),p},f=1;for(let u=0;u<e.rows;u++)for(let g=0;g<e.columns;g++)if(!(u===0&&g===0)){f+=1;for(let h of i){let y=structuredClone(h);y.id=M(t,y.type,e.idFactory,r),y.label=l(h.label,f),y.center={x:h.center.x+g*e.stepX,y:h.center.y+u*e.stepY},delete y.referenceInventorySource,c.push(y)}}return o.objects.push(...c),{...a,createdIds:c.map(u=>u.id)}}function Oa(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 _a=new Set(He.map(t=>t.key));function ut(t){return`${t.rowId}:${t.index}`}function rf(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 Pa(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,je(t.glyph)||delete t.glyph;let n=Vn(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"&&Zn(e,t)}function Aa(t){return Object.keys(t).every(e=>e==="index")}function Ar(t,e,n){if(!n.length)throw new d("invalid_operation","At least one seat is required");let o=R(t,e),i=[],a=new Set,r=new Map;for(let s of n){let c=ut(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}),r.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:r}}function kr(t,e){let n=Ar(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&&E(t,e.patch.categoryKey),e.patch.glyph!=null&&!je(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=>!_a.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:ut(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=le(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&&ie(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=[]),f=l.find(g=>g.index===a.index);f||(f={index:a.index},l.push(f));let u=f.viewFromSeatUrl;for(let g of o){let h=e.patch[g];if(g==="wheelchairSpaceType"&&h==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(y=>y!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(h==null)delete f[g];else if(g==="accessibility")f.accessibility=[...new Set(h)],delete f.accessible;else if(g==="commercial")f.commercial={...f.commercial,...h};else if(g==="labelStyle"){let y=Oa(f.labelStyle,h);y?f.labelStyle=y:delete f.labelStyle}else Object.assign(f,{[g]:h})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==u&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${r+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${r+1}`),Pa(f,s),Aa(f)&&(s.overrides=l.filter(g=>g!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(ut)}}function af(t,e){let n=Ar(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(ut)}}function ff(t,e){let n=R(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&&E(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:f,displayType:u,aisleSeats:g,...h}=e.patch,y=f===void 0?{}:{displayLabel:f},p=we(y,"Row"),S=u===void 0?void 0:Ro(u,"Row");if(r!==void 0&&ie(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&&Qe(h.labelPresentation,"Row"),g!=null&&!fo(g))throw new d("invalid_operation","Row aisleSeats must be one of start, end, both, none (or null to unmark)");let I=w=>JSON.stringify({origin:w.origin,rotation:w.rotation,curve:w.curve,seatCount:w.seatCount,seatSpacing:w.seatSpacing,path:w.path??null}),b=!1;for(let w of i){let v=JSON.stringify(w),m=I(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&&(b=!0),I(w)!==m&&(delete w.arcFanGeneration,delete w.rowBlockGeneration),r!==void 0){let C=JSON.stringify(w.labelPresentation??null),_=Ie(w.labelPresentation,r);_?w.labelPresentation=_:delete w.labelPresentation,JSON.stringify(w.labelPresentation??null)!==C&&(b=!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&&(b=!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&&(b=!0)}if(S!==void 0){let C=w.displayType;S?w.displayType=S:delete w.displayType,w.displayType!==C&&(b=!0)}if(g!==void 0){let C=w.aisleSeats;g===null?delete w.aisleSeats:w.aisleSeats=g,w.aisleSeats!==C&&(b=!0)}if(f!==void 0){let C=w.displayLabel;p?delete w.displayLabel:w.displayLabel=y.displayLabel,w.displayLabel!==C&&(b=!0)}}return{floorId:n.floorId,changed:b,rowIds:o}}var ka=3;function ht(t){return(t%360+360)%360}function Ma(t){let e=t.rotation*te;return{x:Math.cos(e),y:Math.sin(e)}}function Fa(t,e){let n=Math.abs(ht(t-e));return n>180&&(n=360-n),n}function Re(t,e,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y}function Mr(t){let e=0,n=0;for(let i of t){let a=2*i.rotation*te;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 ja(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 Fr(t,e){let n=Mr(t),o={x:-n.y,y:n.x},i=G(t[0]),a=t.map(c=>({row:c,coord:Re(G(c),i,o)})).sort((c,l)=>c.coord-l.coord),r=a[0].coord,s=!1;return a.forEach((c,l)=>{let f=r+l*e-c.coord;Math.abs(f)>1e-6&&(ja(c.row,o.x*f,o.y*f),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Ea(t,e){let n={x:-e.y,y:e.x},o=G(t[0]),i=t.map(r=>Re(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 Ta(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=J(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=ht(Math.atan2(a,i)/te)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Da(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 uf(t,e){let n=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(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=>Fa(m.rotation,c.rotation)>ka);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=Ma(c),u={x:-f.y,y:f.x},g=Math.max(8,c.seatSpacing*.6),h=r.find(m=>Math.abs(Re(m.origin,c.origin,u))>g);if(h){let m=Math.round(Math.abs(Re(h.origin,c.origin,u)));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)=>Re(m.origin,c.origin,f)-Re(x.origin,c.origin,f)),p=y.reduce((m,x)=>m+x.seatCount,0);if(p>300)throw new d("invalid_operation",`A merged row would have ${p} seats, over the 300-seat row limit. Merge fewer rows.`);let S=y[0];ho(y,S);let I=[],b=0;for(let m of y){if(m.overrides)for(let x of m.overrides)I.push({...structuredClone(x),index:x.index+b});b+=m.seatCount}S.seatCount=p,S.curve=0,delete S.path,I.length?S.overrides=I:delete S.overrides,delete S.arcFanGeneration,delete S.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:S.id,removedRowIds:w,seatCount:p}}function jr(t,e){let n=R(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=J(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:M(t,"r",e.idFactory,new Set),label:Da(n.objects,o.label),origin:{...r[a]},rotation:ht(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 f=[],u=[];if(o.overrides)for(let h of o.overrides)h.index<a?f.push(structuredClone(h)):u.push({...structuredClone(h),index:h.index-a});uo(o,o,l),o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,u.length&&(l.overrides=u);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 hf(t,e){let n=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=>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=Fr(i,e.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:e.gap}}function gf(t,e){let n=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(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)Ta(g);let l=Mr(r),f=ht(Math.atan2(l.y,l.x)/te);for(let g of r)g.rotation=f;let u=Ea(r,l);return Fr(r,u),{floorId:n.floorId,changed:s()!==c,rowIds:o,gap:u}}function If(t,e){let n=R(t,e.floorId).objects.find(c=>c.type==="row"&&c.id===e.rowId);if(n?.segmentedRow)throw new d("invalid_operation","This row already has parts: choose Aisle on the join between them.",{rowIds:[e.rowId]});let o=n?.displayLabel??n?.label,i=jr(t,e),a=dt(t,{floorId:i.floorId,rowIds:[i.rowId,i.newRowId],boundaries:["break"],...o?{displayLabel:o}:{},idFactory:e.idFactory}),{objects:r}=R(t,i.floorId),s=[i.rowId,i.newRowId].map(c=>r.find(l=>l.type==="row"&&l.id===c));return lt(s,1,"break"),{floorId:i.floorId,rowId:i.rowId,newRowId:i.newRowId,groupId:a.groupId}}import an from"polygon-clipping";var Er=100,Tr=512,sn=8192,zr=64,Dr=1e7,N=1e-7;function Ur(t,e){return Math.abs(t.x-e.x)<=N&&Math.abs(t.y-e.y)<=N}function Jr(t){let e=t.map(n=>({x:n.x,y:n.y}));for(;e.length>1&&Ur(e[0],e[e.length-1]);)e.pop();return e}function Ke(t,e,n){let o=Y(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 qr(t,e,n,o){let i=Y(t,e,n),a=Y(t,e,o),r=Y(n,o,t),s=Y(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&&Ke(n,t,e)||Math.abs(a)<=N&&Ke(o,t,e)||Math.abs(r)<=N&&Ke(t,n,o)||Math.abs(s)<=N&&Ke(e,n,o)}function La(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)&&qr(t[e],t[n],t[o],t[i]))return!0}}return!1}function Lr(t,e){return t.some((n,o)=>e.some((i,a)=>qr(n,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function cn(t,e){return!e.some((n,o)=>Ke(t,n,e[(o+1)%e.length]))&&$(t,e,void 0)}function mt(t,e,n){let o=Jr(t);if(o.length<3||o.length>Tr||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Dr||Math.abs(i.y)>Dr||Ur(i,o[(a+1)%o.length]))||Math.abs(Xe(o))<=N||La(o))throw new d("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${Tr} finite vertices per ring.`,{gaAreaId:n,ring:e});return o}function Na(t){let e=mt(t.points,"outline",t.id),n=t.holes??[];if(!Array.isArray(n)||n.length>zr)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=n.map(i=>mt(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=>cn(s,e))||Lr(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(Lr(a,o[s])||cn(a[0],o[s])||cn(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 gt(t){return t.map(e=>[e.x,e.y])}function Nr(t){return Jr(t.map(([e,n])=>({x:e,y:n})))}function Gr(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 Ga(t){return t.reduce((e,n)=>e+(Gr(n[0]??[])-n.slice(1).reduce((o,i)=>o+Gr(i),0)),0)}function ln(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(ln).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${ln(e[n])}`).join(",")}}`}function Kr(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 $r(t){return ln({categoryKey:t.categoryKey,displayLabel:Kr(t,"displayLabel",80),displayType:Kr(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Br(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 Hr(t,e,n={}){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>Er)throw new d("invalid_operation",`Join Areas supports at most ${Er} areas at once`);let a=i.map(O=>o.objects.find(k=>k.type==="gaArea"&&k.id===O)),r=i.filter((O,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(O=>Me(O));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});E(t,s[0].categoryKey);let l=$r(s[0]),f=s.find(O=>$r(O)!==l);if(f)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[s[0].id,f.id]});let u=Fe(t).objectToSection,g=u.get(s[0].id)??"__ungrouped__",h=s.find(O=>(u.get(O.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,u.get(h.id)??"__ungrouped__"]});let y=s.reduce((O,k)=>{if(!Number.isInteger(k.capacity)||k.capacity<1||k.capacity>H)throw new d("invalid_operation",`GA area ${k.id} has invalid capacity`,{gaAreaId:k.id});return O+k.capacity},0);if(y>H)throw new d("invalid_operation",`Joined GA capacity would be ${y}, over the ${H}-unit area limit`,{capacity:y});let p=W(t).reduce((O,k)=>O+de(k),0),S=n.maxInventory??1e5;if(p>S)throw new d("invalid_operation",`Chart inventory exceeds the ${S}-unit publication limit`,{inventory:p});let I=s.map(Na),b=I.reduce((O,k)=>O+k.outer.length+k.holes.reduce((T,K)=>T+K.length,0),0);if(b>sn)throw new d("invalid_operation",`Join Areas supports at most ${sn} source vertices`,{vertexCount:b});let w;try{let O=I.map(K=>[gt(K.outer)]);if(w=an.union(O[0],...O.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=I.flatMap(K=>K.holes.map(me=>[gt(me)]));k.length&&(w=an.difference(w,...k));let T=I.findIndex(K=>{let me=[gt(K.outer),...K.holes.map(gt)];return Ga(an.intersection(me,w))<=N});if(T>=0)throw new d("invalid_operation",`GA area ${s[T].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:s[T].id})}catch(O){throw O instanceof d?O:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:O instanceof Error?O.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=Nr(w[0][0]),m=w[0].slice(1).map(Nr),x=v.length+m.reduce((O,k)=>O+k.length,0);if(m.length>zr||x>sn)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:m.length,vertexCount:x});mt(v,"outline",s[0].id),m.forEach(O=>mt(O,"cutout",s[0].id));let C=new Map(o.objects.map((O,k)=>[O.id,k])),_=s.slice().sort((O,k)=>Ka(Br(O,C.get(O.id)??Number.MAX_SAFE_INTEGER),Br(k,C.get(k.id)??Number.MAX_SAFE_INTEGER))),F=_[0],B=structuredClone(t),z=R(B,o.floorId),P=z.objects.find(O=>O.type==="gaArea"&&O.id===F.id);P.points=structuredClone(v),m.length?P.holes=structuredClone(m):delete P.holes;let V=new Set(_.slice(1).map(O=>O.id));for(let O=z.objects.length-1;O>=0;O-=1)V.has(z.objects[O].id)&&z.objects.splice(O,1);let A=Fe(B).objectToSection.get(F.id)??"__ungrouped__";if(A!==g)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:F.id,beforeSectionId:g,afterSectionId:A});let U=[],X=new Set;for(let O of _){if(!to(O))throw new d("invalid_operation",`GA area ${O.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:O.id});let k=ne(O);if(k.length!==O.capacity||k.some(T=>X.has(T)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:O.id});k.forEach(T=>X.add(T)),U.push(...no(O))}if(U.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let ce=new Set(s.map(O=>O.id));for(let O of W(t).filter(k=>k.type==="gaArea"&&!ce.has(k.id))){let k=ne(O).find(T=>X.has(T));if(k)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:k,gaAreaId:O.id})}let qe=_.slice(1).map(O=>O.id);return{floorId:o.floorId,areaId:F.id,survivorLabel:F.label,removedAreaIds:qe,sourceAreaCount:_.length,capacity:y,inventorySegmentCount:U.length,outerVertexCount:v.length,holeCount:m.length,sectionId:g,points:v,...m.length?{holes:m}:{},segments:U}}function Pf(t,e,n={}){let{segments:o,...i}=Hr(t,e,n);return i}function Af(t,e,n={}){let o=Hr(t,e,n),i=R(t,o.floorId),a=i.objects.find(f=>f.type==="gaArea"&&f.id===o.areaId);a.points=structuredClone(o.points),o.holes?.length?a.holes=structuredClone(o.holes):delete a.holes;let r=i.objects.filter(f=>f.type==="gaArea"&&(f.id===o.areaId||o.removedAreaIds.includes(f.id))).reduce((f,u)=>f+(u.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 f=i.objects.length-1;f>=0;f-=1)s.has(i.objects[f].id)&&i.objects.splice(f,1);let{segments:c,...l}=o;return{...l,changed:!0}}function Gf(t,e){let n=R(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,ke(o),{floorId:n.floorId,changed:!0,shapeId:o.id}}function Kf(t,e){let n=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=>n.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 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(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(r.labelStyle.size!==void 0&&r.labelStyle.size!==null&&(!Number.isFinite(r.labelStyle.size)||r.labelStyle.size<Ct||r.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${Ct} 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&&!wn.includes(r.labelStyle.direction))throw new d("invalid_operation","Stage label direction must be horizontal, vertical, or auto");for(let f of["bold","italic","underline"]){let u=r.labelStyle[f];if(u!=null&&typeof u!="boolean")throw new d("invalid_operation",`Stage label ${f} 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=ae("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(u=>!Number.isFinite(u)||u<-100||u>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(u=>Math.abs(u)>.5)||(r.edgeCurvature=null)}let f={kind:"polygon",points:l.points,edgeCurvature:r.edgeCurvature??void 0,holes:l.holes};Ln(f).forEach((u,g)=>{if(!Nn(f,u))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(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");r.eventConfigurationIds=l}if(r.lineCap!==void 0&&r.lineCap!==null&&!bo.includes(r.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!po.includes(r.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,f]of[["startEnding",r.startEnding],["endEnding",r.endEnding]])if(f!=null&&!yo.includes(f))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(f=>!Dt(r.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(r.label===null?delete l.label:r.label!==void 0&&(l.label=r.label),r.labelStyle!==void 0){let u={...l.labelStyle};r.labelStyle.size===null?delete u.size:r.labelStyle.size!==void 0&&(u.size=r.labelStyle.size),r.labelStyle.color===null?delete u.color:r.labelStyle.color!==void 0&&(u.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete u.fontFamily:r.labelStyle.fontFamily!==void 0&&(u.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete u.bold:r.labelStyle.bold!==void 0&&(u.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete u.italic:r.labelStyle.italic===!0&&(u.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete u.underline:r.labelStyle.underline===!0&&(u.underline=!0),r.labelStyle.direction===null||r.labelStyle.direction==="horizontal"?delete u.direction:r.labelStyle.direction!==void 0&&(u.direction=r.labelStyle.direction),Object.keys(u).length?l.labelStyle=u: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,Dt(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 u=Math.min(l.width??1/0,l.height??1/0),g=Number.isFinite(u)?u/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,g)):r.cornerRadius}JSON.stringify(l)!==f&&(ke(l),c=!0)}return{floorId:n.floorId,changed:c,shapeIds:o}}function Vr(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 n=e.map(f=>f.x),o=e.map(f=>f.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 $f(t,e){let n=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(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"?Vr(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(S=>!Number.isFinite(S.x)||!Number.isFinite(S.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=l.map(S=>S.x),u=l.map(S=>S.y),g=Math.min(...f),h=Math.max(...f),y=Math.min(...u),p=Math.max(...u);return{cx:(g+h)/2,cy:(y+p)/2,width:Math.max(1,h-g),height:Math.max(1,p-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,f=s.height/c.height,u=g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*f});r.points=(r.points??[]).map(u),r.holes&&(r.holes=r.holes.map(g=>g.map(u))),(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 Bf(t,e){let n=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(zn.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:Vr(c)}}),r=!1;for(let s of a)s.box&&(s.shape.points=Jn({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 Hf(t){return[...hn(t)].map(([e,n])=>({key:e,...n}))}function Ba(t){if(!Array.isArray(t))return hn(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 hn(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let n of j(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 bt(t){return Array.isArray(t)?t.map(bt):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[n])=>e.localeCompare(n)).map(([e,n])=>[e,bt(n)]))}function za(t,e){return JSON.stringify(bt(t))===JSON.stringify(bt(e))}function dn(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function Ua(t){return t?t.status==="retracted"?"retract":dn(t)?"approve":"set":"clear"}function Ja(t,e){let n=Ba(t),o=hn(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&&za(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:Ua(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function Vf(t,e){return Ja(t,e).some(n=>dn(n.before)||dn(n.after))}var qa=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Ha=new Set(["generated","geometry-verified","configuration-verified"]),Va=new Set(["none","comparable-build-reference","actual-build-checked"]),Xa=new Set(["clear","partial","obstructed"]);function fn(t){return t.toISOString().slice(0,10)}function un(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function _e(t,e,n){if(!un(t,e))throw new d("invalid_operation",`Confidence evidence ${n} is invalid`,{field:n});return t}function Oe(t,e,n){if(t!==void 0)return _e(t,e,n)}function pt(t,e,n){let o=n?[R(t,n)]:j(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 Xr(t,e){let n=j(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 $e(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return Xr(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=pt(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=pt(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 yt(t,e,n){if(e.scope==="venue")return n?t.confidenceEvidence=n:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=Xr(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=pt(t,e.objectId,e.floorId);return kr(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=pt(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 Wa(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!un(t.label,80)||!un(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(!Xa.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(n=>_e(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 Ya(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(!qa.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!Ha.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let n=t.realityLevel??"none";if(!Va.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=Oe(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(u=>_e(u,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=Oe(t.assessedAt,40,"assessedAt")??fn(e),r=Date.parse(a);if(!Number.isFinite(r))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=Oe(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:fn(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=Oe(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let f=Oe(t.sourceLabel,120,"sourceLabel");if(n!=="none"&&!f)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:_e(t.evidenceId,120,"evidenceId"),modelVersion:_e(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}:{},...f?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:Wa(t.modeledTarget)}:{}}}function Pe(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 Xf(t,e){let n=Ya(e.evidence,e.now),o=JSON.stringify($e(t,e)??null),i=yt(t,e,n),a=JSON.stringify($e(t,e)??null);return Pe(e,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function Wf(t,e){let n=$e(t,e);if(!n)return Pe(e,{changed:!1});let o=yt(t,e,void 0);return Pe(e,{changed:!0,...o,evidenceId:n.evidenceId})}function Yf(t,e){let n=$e(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=_e(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=Oe(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:fn(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=yt(t,e,r);return Pe(e,{changed:c!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function Zf(t,e){let n=$e(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 Pe(e,{changed:!1,evidenceId:n.evidenceId,status:"retracted"});let o={...n,status:"retracted"};delete o.basisSha256;let i=yt(t,e,o);return Pe(e,{changed:!0,...i,evidenceId:n.evidenceId,status:"retracted"})}var Za={width:960,height:600};function Qa(t,e,n=t){let o={...t,objects:e,floors:void 0,referenceImage:void 0,backgroundImage:Qn(n)},i=ee(o,{freeText:"exclude"}),{width:a,height:r}=Za;return Math.min(a/Math.max(i.width,1e-6),r/Math.max(i.height,1e-6))}function es(t,e){return!t.text.trim()||t.semanticKind==="icon"||t.labelImportance==="detail"||Yn(t)?!1:!co(t.fontSize,e)}function Wr(t){let e=[],n=!!t.floors?.length;for(let o of j(t)){let i=o.objects.filter(r=>r.type==="text");if(!i.length)continue;let a=Qa(t,o.objects,n?o:t);for(let r of i)es(r,a)&&e.push({floorId:o.id,text:r,renderedPx:r.fontSize*a})}return e}var wt=40,Yr=96,ts=48,ue=24;function Be(t,e){let n=ee({...t,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"});return{x:n.x+wt,y:n.y+wt,width:Math.max(0,n.width-2*wt),height:Math.max(0,n.height-2*wt)}}function ns(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 os(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}var gn=t=>t.type==="shape"&&t.role==="stage";function rs(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 is(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 mn(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 It(t,e){let n=oe(t,e.floorId),o=ns(n.objects.filter(gn).map(b=>Be(n,b)));if(!o)return null;let i=rs(o,n.focalPoint),a=i.dy!==0?e.height:e.width,r=is(o,i),s=n.objects.filter(b=>!gn(b)&&os(b)).map(b=>Be(n,b)).filter(b=>mn(b,i)>=r-1),c=s.length?Math.min(...s.map(b=>mn(b,i))):1/0,l=Yr+a+ts,f=c-r,u=()=>{let b=r+Yr+a/2;return i.dy!==0?{x:o.x+o.width/2,y:i.dy*b}:{x:i.dx*b,y:o.y+o.height/2}};if(!s.length)return{center:u(),movedBack:0};if(f>=a+2*ue){let b=r+f/2;return{center:i.dy!==0?{x:o.x+o.width/2,y:i.dy*b}:{x:i.dx*b,y:o.y+o.height/2},movedBack:0}}if(e.makeRoom){let b=l-f,w=R(t,e.floorId);for(let v of w.objects)gn(v)||mn(Be(n,v),i)<r-1||se(v,i.dx*b,i.dy*b);return{center:u(),movedBack:b}}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,p=o.x+o.width/2,S=o.y+o.height/2;if(i.dy!==0){let b=i.dy===1?Math.min(S,c-ue-y/2):Math.max(S,-c+ue+y/2);return{center:{x:o.x-ue-h/2,y:b},note:g,movedBack:0}}return{center:{x:i.dx===1?Math.min(p,c-ue-h/2):Math.max(p,-c+ue+h/2),y:o.y-ue-y/2},note:g,movedBack:0}}var as=40,ze=24;function ss(t,e,n){let{objects:o}=R(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 Ue(t,e){if(!e.nearObjectId&&e.placement==="front"){let n=It(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:Zr(t,e)}}function yu(t,e){return Ue(t,e).center}function Zr(t,e){if(e.nearObjectId){let n=ss(t,e.floorId,e.nearObjectId),o=Be(oe(t,e.floorId),n),i=e.side??"rear";return i==="front"?{x:o.x+o.width/2,y:o.y-ze-e.height/2}:i==="left"?{x:o.x-ze-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+ze+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+ze+e.height/2}}if(e.placement==="center"){let n=ee(oe(t,e.floorId),{freeText:"exclude"});return{x:n.x+n.width/2,y:n.y+n.height/2}}return ve(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}function St(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*as}function bn(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 cs(t){return t.some(e=>e.type==="shape"&&e.role==="stage")}function wu(t,e){let n=R(t,e.floorId),o=Un(e.kind),i=St(e.widthM,"widthM",o.width),a=St(e.depthM,"depthM",o.height),r=Zr(t,{...e,placement:e.placement??"front",width:i,height:a}),s=bn(e.label,"label")??Hn(e.kind),c=M(t,"stage",e.idFactory,new Set),l={...qn({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},f=cs(n.objects);if(n.objects.push(l),!f){let u={x:r.x,y:r.y+a/2+ze},g=j(t).find(h=>h.id===n.floorId);t.floors?.length&&g&&(g.focalPoint=u),(!t.floors?.length||t.floors[0]?.id===n.floorId)&&(t.focalPoint=u)}return{floorId:n.floorId,stageId:c,label:s,focalPointMoved:!f,createdIds:[c]}}function Iu(t,e){let n=Le(e.role);if(!n)throw new d("invalid_operation",`Unknown landmark: ${e.role}`);let o=R(t,e.floorId),{center:i,note:a}=Ue(t,{...e,width:n.width,height:n.height}),r=M(t,"decor",e.idFactory,new Set),s=Ko(e.role,i,r),c=bn(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 ls={small:16,medium:24,large:36};function vt(t){if(t==="always")return"orientation";if(t==="close-up")return"detail"}var ds="#f7f8fb";function fs(t){let e=t.theme?.background??ds,n=t.theme?.textColor;return n&&io(n,e)>=4.5?n:ao(e,"#0b1220","#e8ecf4")}function Su(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=R(t,e.floorId),i=ls[e.size??"medium"],a=Math.max(i,n.length*i*.56),r=i*1.2,{center:s,note:c}=Ue(t,{...e,width:a,height:r}),l=M(t,"txt",e.idFactory,new Set),f={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"):fs(t),...e.bold?{bold:!0}:{},...vt(e.showAt)?{labelImportance:vt(e.showAt)}:{}};o.objects.push(f);let u=e.showAt===void 0&&Wr(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,u].filter(Boolean).join(" ");return{floorId:o.floorId,textId:l,createdIds:[l],...g?{note:g}:{}}}function vu(t,e){let n=go(e.iconKey);if(!n)throw new d("invalid_operation",`Unknown icon: ${e.iconKey}`);let o=R(t,e.floorId),i=28,{center:a,note:r}=Ue(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,...vt(e.showAt)?{labelImportance:vt(e.showAt)}:{}};return o.objects.push(c),{floorId:o.floorId,iconId:s,createdIds:[s],...r?{note:r}:{}}}var us="#4b5568";function xu(t,e){let n=bn(e.label,"label"),o=R(t,e.floorId),i=St(e.widthM,"widthM",0),a=St(e.depthM,"depthM",0),{center:r,note:s}=Ue(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"):us,...n?{label:n}:{},...e.shape!=="ellipse"?{cornerRadius:8}:{}};return o.objects.push(l),{floorId:o.floorId,areaId:c,createdIds:[c],...s?{note:s}:{}}}function Cu(){return["bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"].map(t=>({role:t,label:Le(t)?.label??t}))}var hs=100,gs=300,Ou=hs*gs;function Qr(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 Je(t,e){if(e.placement==="front"){let n=It(t,e);if(n)return n.note?{center:n.center,note:n.note}:{center:n.center}}return{center:ve(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}}var ms={straight:0,gentle:15,medium:30,strong:45},bs=24,ps=28,ys=48;function Du(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=I=>e.blockSeats?.[I]??e.seatsPerRow,i=I=>Math.max(24,(I-1)*bs),a=i(e.seatsPerRow),r=Math.max(28,(e.rowCount-1)*ps),s=e.aisleWidth??ys,c=e.placement??"auto",l=ms[e.curveStyle??"straight"],f={floorId:"",rowIds:[],sectionIds:[],createdIds:[]},u=(I,b,w)=>{let v=hr(t,{floorId:e.floorId,origin:I,rowCount:e.rowCount,seatsPerRow:o(w),categoryKey:e.categoryKey,curve:l,...e.blockStyle?{style:e.blockStyle}:{},rotation:b,sectionLabel:e.sectionLabels?.[w],idFactory:e.idFactory});f.floorId=v.floorId,f.rowIds.push(...v.rowIds),v.sectionId&&f.sectionIds.push(v.sectionId),f.createdIds.push(...v.createdIds)};if(n===1&&c==="front"){let I=Je(t,{floorId:e.floorId,width:a,height:r,placement:c,makeRoom:e.makeRoom});return I.note&&(f.note=I.note),u({x:I.center.x-a/2,y:I.center.y-r/2},0,0),f}if(n===1){let I=ve(t,{floorId:e.floorId,width:a,height:r,placement:c}),b=Qr(I,t.focalPoint,e.orientation??"horizontal"),w=b*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=b===0?I:ve(t,{floorId:e.floorId,width:v,height:m,placement:c});return u({x:x.x-a/2,y:x.y-r/2},b,0),f}let g=Array.from({length:n},(I,b)=>i(o(b))),h=g.reduce((I,b)=>I+b,0)+(n-1)*s,y=Je(t,{floorId:e.floorId,width:h,height:r,placement:c,makeRoom:e.makeRoom});y.note&&(f.note=y.note);let p=y.center,S=p.x-h/2;for(let I=0;I<n;I+=1)u({x:S,y:p.y-r/2},0,I),S+=g[I]+s;return f}function Lu(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 ws=155,Is=150,ei=110;function Nu(t,e){let n=(e.tableColumns-1)*ws+ei,o=(e.tableRows-1)*Is+ei,{center:i,note:a}=Je(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=br(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 Gu(t,e){let n=Zt(e.capacity),{center:o,note:i}=Je(t,{floorId:e.floorId,...n,placement:e.placement,makeRoom:e.makeRoom}),a=mr(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 Ss=88,vs=82,xs=62,Cs=52;function Ku(t,e){let n=(e.boothColumns-1)*Ss+xs,o=(e.boothRows-1)*vs+Cs,{center:i,note:a}=Je(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=pr(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 Rs=40,he=30,ge=42,re=48,Os={none:[1],center:[1,1],two:[1,2,1]},_s=6;function ni(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}function pn(t,e){return ee({...t,floors:void 0,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"})}function Ps(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 As(t,e,n,o="front"){let i=j(t),a=e?i.find(I=>I.id===e):i[0];if(!a)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});let r=a.focalPoint??t.focalPoint,s=a.objects.filter(ni),c=0;if(s.length){let I=0,b=0;for(let w of s){let v=pn(t,w);I+=v.x+v.width/2-r.x,b+=v.y+v.height/2-r.y}Math.hypot(I,b)>1&&(c=Math.atan2(I,b)*180/Math.PI)}let l=o==="behind";l&&(c=(c+360)%360-180);let f=n/2,u={x:Math.sin(c*Math.PI/180),y:Math.cos(c*Math.PI/180)},g=0,h=[],y=s.some(I=>I.type==="row"),p=l?a.objects.filter(I=>I.type==="shape"&&I.role==="stage"):[];for(let I of[...s,...p]){if(I.type==="section"&&y)continue;let b=I.type==="row"?J(I):Ps(pn(t,I)),w=I.type==="row"?I.seatSpacing/2:0;for(let v of b){let m=v.x-r.x,x=v.y-r.y,C=Math.atan2(m,x)*180/Math.PI;if(Math.abs((C-c+540)%360-180)>f+10)continue;let F=Math.hypot(m,x)+w;g=Math.max(g,F),h.push({radius:F,depth:m*u.x+x*u.y+w})}}let S=I=>{let b=Math.cos(I/2*Math.PI/180);return b<.2||!h.length?0:(Math.max(...h.map(w=>w.depth))+ge)/b};return{center:r,bearing:c,occupiedRadius:g,floorId:a.id,clearRadius:S}}var oi=100,yn=180;function ti(t,e){return t===void 0||e<=0?oi:Math.min(yn,Math.max(20,Math.round(t/e*(180/Math.PI))))}function ks(t,e){let n=e==="two"?2:e==="center"?1:0;return t*he+n*re}function Ms(t,e,n,o){let i=[],a=o+ge-e.occupiedRadius;if(e.occupiedRadius<=0||a<=0)return i;let r=n/2+10;for(let s of R(t,e.floorId).objects){if(ni(s)||s.type==="shape"&&s.role==="stage")continue;let c=pn(t,s),l=c.x+c.width/2-e.center.x,f=c.y+c.height/2-e.center.y,u=Math.hypot(l,f);if(u<=e.occupiedRadius)continue;let g=Math.atan2(l,f)*180/Math.PI;Math.abs((g-e.bearing+540)%360-180)>r||(se(s,l/u*a,f/u*a),i.push(s.id))}return i}function $u(t,e){let n=e.sectionLabels&&e.sectionLabels.length>1?e.sectionLabels:void 0;if(e.seatsPerRowByRow&&e.seatsPerRowByRow.length!==e.rowCount)throw new d("invalid_operation","Give one seat count per curved row");let o=v=>e.seatsPerRowByRow?.[v]??e.seatsPerRow,i=v=>n?n.length*v*he+(n.length-1)*re:ks(v,e.aisles),a=v=>{if(n)return n.length*(v-1)*he+(n.length-1)*re;let m=Os[e.aisles??"none"],x=m.reduce((_,F)=>_+F,0),C=Vt(m,v);return Math.max(...C.map((_,F)=>(_-1)*he*x/m[F]))+(m.length-1)*re},r=e.spreadDegrees===void 0?a:i,s=o(0),c=As(t,e.floorId,e.spreadDegrees??oi,e.stageSide),l=Math.max((e.firstRowDistanceM??4)*Rs,c.occupiedRadius>0?c.occupiedRadius+ge+re:0),f=e.spreadDegrees??ti(s===void 0?void 0:r(s),l),u=e.spreadDegrees??(s!==void 0&&f>=yn?yn:void 0),g=u!==void 0&&s!==void 0?Math.max(...Array.from({length:e.seatsPerRowByRow?e.rowCount:1},(v,m)=>r(o(m))/(u*Math.PI/180)-m*ge)):0,h=Math.max(l,g,c.clearRadius(f)),y=e.spreadDegrees??ti(s===void 0?void 0:r(s),h),p=h+(e.rowCount-1)*ge,S=Ms(t,c,y,p),I=e.spreadDegrees===void 0&&e.rowCount>1?o(e.rowCount-1):void 0,b=(v,m)=>{let x=m/p*(180/Math.PI);return Math.max(-120,Math.min(120,(v-Math.max(x,_s))/2))};if(n){let v=I===void 0?void 0:(I-1)*he;return{...Fs(t,e,n,c,h,y,s,m=>v===void 0?0:b(m,v)),spreadDegrees:y,movedBackIds:S}}return{...Xt(t,{floorId:c.floorId,center:c.center,innerRadius:h,rowCount:e.rowCount,rowGap:ge,startAngle:c.bearing-y/2,endAngle:c.bearing+y/2,seatPitch:he,fit:s===void 0?"seat-pitch":"fixed-count",...s===void 0?{}:{seatsPerRow:s},...e.seatsPerRowByRow?{seatsPerRowByRow:e.seatsPerRowByRow}:{},...I===void 0?{}:{taperDegrees:b(y,a(I))},facing:"inward",...e.aisles==="center"?{aisleGaps:{center:re}}:e.aisles==="two"?{aisleGaps:{left:re,right:re}}:{},categoryKey:e.categoryKey,...e.sectionLabel===void 0?{}:{sectionLabel:e.sectionLabel},idFactory:e.idFactory}),spreadDegrees:y,movedBackIds:S}}function Fs(t,e,n,o,i,a,r,s){let c=re/i*(180/Math.PI),l=a>=359,f=(a-(l?n.length:n.length-1)*c)/n.length;if(f<5)throw new d("invalid_operation",`${n.length} sections do not fit in ${Math.round(a)}\xB0; widen the fan or use fewer sections`);let u=o.bearing-a/2+(l?c/2:0),g=n.map((h,y)=>Xt(t,{floorId:o.floorId,center:o.center,innerRadius:i,rowCount:e.rowCount,rowGap:ge,startAngle:u+y*(f+c),endAngle:u+y*(f+c)+f,seatPitch:he,fit:r===void 0?"seat-pitch":"fixed-count",...r===void 0?{}:{seatsPerRow:r},...e.seatsPerRowByRow?{seatsPerRowByRow:e.seatsPerRowByRow}:{},...s(f)===0?{}:{taperDegrees:s(f)},facing:"inward",categoryKey:e.categoryKey,sectionLabel:h,idFactory:e.idFactory}));return{floorId:o.floorId,rowIds:g.flatMap(h=>h.rowIds),sectionId:g[0].sectionId,sectionIds:g.map(h=>h.sectionId).filter(h=>h!==null),groupId:g[0].groupId,logicalRowCount:e.rowCount,rowSegmentCount:g.reduce((h,y)=>h+y.rowSegmentCount,0),totalSeats:g.reduce((h,y)=>h+y.totalSeats,0),innerRadius:i,outerRadius:g[0].outerRadius,minSeatSpacing:Math.min(...g.map(h=>h.minSeatSpacing)),maxSeatSpacing:Math.max(...g.map(h=>h.maxSeatSpacing)),maxPitchDeviation:Math.max(...g.map(h=>h.maxPitchDeviation)),aisleCount:n.length-(l?0:1),warnings:[...new Set(g.flatMap(h=>h.warnings))]}}export{aa as AISLE_EMPTY_SEATS,Et as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,as as DECOR_UNITS_PER_METRE,Bs as DEFAULT_FLOOR_HEIGHT_STEP_M,Jo as DEFAULT_ROUTE_NAME,ri as DEFAULT_SECTION_CORNER_SMOOTHING,Ei as FIRST_CATEGORY_COLOURS,js as MAX_BUYER_IMAGE_URL_LENGTH,$s as MAX_FLOOR_BASE_HEIGHT_M,us as NAMED_AREA_FILL,Uo as ROUTE_STROKE,ms as ROW_CURVE_DEGREES,Xt as addArcFanRows,xu as addArea,Wd as addBookableGridArray,pr as addBoothArray,ql as addChartCategories,qt as addChartCategory,zs as addChartFloor,Ws as addChartZone,$u as addCurvedRows,mr as addGAArea,xc as addGate,vu as addIcon,Iu as addLandmark,Ku as addPlacedBoothArray,Gu as addPlacedGAArea,Du as addPlacedRowBlocks,Nu as addPlacedTableArray,Pc as addRoute,If as addRowAisle,hr as addRowBlock,wu as addStage,br as addTableArray,Su as addText,Vt as allocateFixedArcFanSeats,sl as applyPolygonHole,qd as applyReferenceScanRows,vl as applySectionCornerSmoothing,_l as applySectionEstimates,Ai as applySectionOutlineShaping,al as applySectionRowFit,Yf as approveConfidenceEvidence,ta as arcFanInputForGroup,yl as assignSectionInventoryCategory,ve as automaticPlacementCenter,Lu as blockSectionLabels,Wf as clearConfidenceEvidence,Gs as compactChartDoc,Ls as compactRowOverrides,Ns as compactTableOverrides,Vf as confidenceEvidenceChangeRequiresPublish,Ja as confidenceEvidenceChanges,Hf as confidenceEvidenceIndex,Kl as confirmReferenceCategoryOutputColor,wl as convertGeneratedSectionToPolygon,Gf as convertShapeToOutline,Wo as countCoveredInventory,As as curvedRowsPlacement,Ue as decorPlacement,yu as decorPlacementCenter,Ds as detectSeatLabelRun,Zn as dropRedundantSeatOverrideFields,zi as familyCategoryLabel,lt as fitSegmentedRowJoin,Zt as gaAreaFootprint,mi as gateShape,dt as groupRowsAsSegmented,Yc as insertSeatingBlock,Es as isSafeBuyerImageUrl,Af as joinGAAreas,Cu as landmarkRoles,Rc as makeGate,uf as mergeRows,et as mirrorFirstFloor,le as normalizeBuyerImageUrl,Ya as normalizeDraftEvidence,rf as parseSeatRefId,ji as pickColorblindSafeCategoryColor,qi as planCreationCategory,sr as previewArcFanRows,Xd as previewBookableGridArray,Oi as previewGeneratedSectionPolygonConversion,Pf as previewJoinGAAreas,Ut as previewPolygonHole,xi as previewRemovePolygonHole,yi as previewRowCubicPath,Si as previewSectionRowFit,Gl as reassignColorblindSafeCategoryColors,Wc as relabelChartRows,Xo as releaseGateReferences,_c as remapGateReferences,Hl as removeCategoryMovingInventory,rr as removeChartCategory,qs as removeChartFloor,Vc as removeChartObjects,Zs as removeChartZone,cl as removePolygonHole,Us as renameChartFloor,Ll as renameDirectSeatImportCategory,Nl as reorderChartCategories,ad as replaceArcFanRows,_d as replaceRowBlock,af as resetSeatOverrides,$f as resizeShapes,$l as resolveCreationCategory,Zf as retractConfidenceEvidence,Ks as roundBuyerCoordinates,bi as routeShape,ut as seatRefId,Ts as seatSemanticsSignature,Ri as sectionInventorySelectionSummary,pd as segmentedRowAisleTooNarrow,Xf as setConfidenceEvidence,Oc as setObjectEntrance,Ac as setRoute,hf as setRowBlockSpacing,jr as splitRow,gf as straightenAndSpaceRows,Il as transformSectionBoundary,_i as transformSectionBoundaryObject,Rd as ungroupSegmentedRow,Xi as uniqueCategoryLabel,qc as updateBooths,Jt as updateCategoryDefinitions,Js as updateChartFloorBaseHeight,Ql as updateChartTheme,Ys as updateChartZones,Hc as updateGAAreas,Cc as updateGate,il as updateRowCubicPath,ff as updateRows,kr as updateSeatOverrides,Sl as updateSectionExactPath,nr as updateSectionMetadata,Od as updateSegmentedRow,Kf as updateShapes,Bf as updateStageKinds,Jc as updateTables,Xc as updateTextObjects,ed as updateViewFromSeatFallback};
1
+ import{a as Kt,b as ae}from"../../chunk-TZBJCAXH.js";import{A as Hs,b as d,c as R,d as E,e as M,f as ye,g as oe,h as Oo,i as Ze,j as we,k as D,l as ie,m as Qe,n as Ie,o as Gt,p as Te,q as Y,r as Z,s as te,t as de,u as et,v as Bs,w as zs,x as Us,y as Js,z as qs}from"../../chunk-2VYFNNYC.js";import{a as Ee,b as Ye}from"../../chunk-NVAF2E7Q.js";import{g as Ft,h as jt,j as Io,k as So,l as vo,m as pe,n as xo,o as Co,p as Lt,q as Nt,r as Ro}from"../../chunk-YRDOE3N7.js";import{c as to,d as uo,h as ho,i as go}from"../../chunk-ZY6WTPTI.js";import{k as je}from"../../chunk-JQBJZMLG.js";import{a as Et,b as Tt,n as mo,p as bo,r as po,s as yo,t as wo,x as Dt}from"../../chunk-GUNNA5LB.js";import{a as ke,c as Zn,d as Ds,e as Ls,f as Qn,g as Ns,h as Gs,i as Ks,j as $s,l as eo}from"../../chunk-M4NGX5NM.js";import{A as fo,k as co,s as lo}from"../../chunk-EE2CVYFJ.js";import{a as In,b as xt,e as He,k as Ct,n as Sn}from"../../chunk-URW7MSCJ.js";import{b as be,c as H,e as no,f as oo,g as At,h as ro,i as Me,k as ne,o as kt,v as Fe}from"../../chunk-GVVZR3YS.js";import{$ as Dn,$a as Yn,A as kn,Ea as Jn,Fa as qn,G as Mn,Ga as Hn,Ia as Vn,K as Xe,Ka as Xn,La as Wn,Ma as J,Pa as q,Q as Fn,R as Ot,S as jn,T as We,Ta as Ae,U as En,V as ii,Xa as Q,Ya as $,Z as Tn,_a as G,a as Es,aa as _t,ab as j,b as Ts,c as le,ca as Ln,cb as W,da as Nn,e as Rt,ea as Gn,gb as ee,ka as zn,q as vn,r as xn,s as Cn,t as Rn,u as On,v as _n,w as Ve,x as Pn,y as An,za as Un}from"../../chunk-3V32MDJI.js";import{e as Kn,h as Pt,q as $n,r as Bn}from"../../chunk-S3VH7IDA.js";import{G as so,i as io,m as ao,n as Mt}from"../../chunk-JBOTRSMY.js";import"../../chunk-CRCGO52K.js";function Ys(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:Gt(t,e.label),color:D(e.color,"Zone color"),...e.focalPoint?{focalPoint:Te(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function Zs(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 f=r.get(c.zoneId);c.patch.label!==void 0&&(f.label=Gt(a,c.patch.label,f.id)),c.patch.color!==void 0&&(f.color=D(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(f.focalPoint=Te(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 Qs(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=j(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,et(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var fe={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 De(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 ai(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 _o(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 si(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 Po=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[fe.balcony],sectionLabel:"Balcony",build:()=>[De("blk-b0","A",-45,18,24,"balcony",18),De("blk-b1","B",-15,20,24,"balcony",18),De("blk-b2","C",15,22,24,"balcony",18),De("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[fe.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>De(`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:[fe.standard],build:()=>[_o("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[fe.premium],build:()=>Array.from({length:6},(t,e)=>ai(`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:[fe.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:[fe.standard],build:()=>[_o("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:[fe.standard],build:()=>[si("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 tt(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 se(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=Q(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=jn(t.outlinePath,e,n)),t.holes&&(t.holes=Q(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=Q(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 nt(t,e,n){return n?kn(t,e,n):{x:t.x,y:t.y}}function ci(t,e,n){let o=i=>nt(i,e,n);t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=We(t.outlinePath,o,1,!1)),t.holes&&(t.holes=Q(t.holes).map(i=>i.map(o)))}function li(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=nt(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=Q(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=nt(i,e,n);t.x+=a.x-i.x,t.y+=a.y-i.y}t.rotation=ae("shape",o+n)}function Ao(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=>nt(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=ae("row",t.rotation+n);break;case"table":case"booth":t.center=o(t.center),t.rotation=ae(t.type,t.rotation+n);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=Q(t.holes).map(i=>i.map(o)));break;case"section":ci(t,e,n);break;case"shape":li(t,e,n);break;case"text":t.position=o(t.position),t.rotation=ae("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=ae("decorImage",(t.rotation??0)+n);break}}}var di=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","wheelchairPlaces"],ko=(t,e,n)=>Number.isInteger(t)&&t>=e&&t<=n;function Mo(t){let e={};for(let n of di){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&&!ko(e[n],1,H))throw new d("invalid_operation",`${n} must be a whole number from 1 to ${H}`);if(e.wheelchairPlaces!==void 0&&!ko(e.wheelchairPlaces,0,H))throw new d("invalid_operation",`wheelchairPlaces must be a whole number from 0 to ${H}`);return e}function Fo(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=Me(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>At)throw new d("invalid_operation",ro,{gaAreaId:t.id,capacity:t.capacity,max:At});if(n&&be(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 jo(t,e){let n=e.filter(a=>Me(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 j(t))for(let r of a.objects){let s=r.type==="gaArea"?o.get(r.id)??r:r,c=[];s.type==="row"?c=q(s).map(l=>l.label):s.type==="table"?c=s.bookAsWhole||s.variableOccupancy?[s.label]:Ae(s).map(l=>l.label):s.type==="booth"?c=[s.label]:s.type==="gaArea"&&(c=ne(s));for(let l of c){let f=i.get(l);if(f&&f!==s.id)throw new d("invalid_operation",`Inventory label "${l}" is already in use; an area sold as one box needs a unique label`,{gaAreaId:f,inventoryLabel:l,conflictingObjectId:s.id})}}}var Eo=40,To=160;function fi(t,e){let n=t.normalize("NFKC").trim();if(n.length>Eo)throw new d("invalid_operation",`${e} entrance must be at most ${Eo} characters`);return n}function ot(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(ie(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=fi(o,e)||null}}return n}function rt(t,e){if(e.labelStyle){let o=Ie(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 Do(t){if(!("chairNumbering"in t))return;let e=t.chairNumbering;if(delete t.chairNumbering,e===null)return null;let n=$n(e);if(n)throw new d("invalid_operation",n);return e}function Lo(t,e){if(e===void 0)return;let n=e===null?void 0:Bn({...t.chairNumbering,...e});n?t.chairNumbering=n:delete t.chairNumbering}function No(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(!Sn.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>To)throw new d("invalid_operation",`Booth note supports at most ${To} characters`);e.note=i||null}}}return e}function Go(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 ui=[{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}],Ko=new Map(ui.map(t=>[t.role,t]));function Le(t){return Ko.get(t)}function $o(t,e,n){let o=Ko.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 Jo={color:Tt.accessibility,width:4},qo="Step-free route";function it(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 gi(t){if(!Io.includes(t))throw new d("invalid_operation","Gate use must be in, out or both")}function Bt(t,e){if(typeof t!="boolean")throw new d("invalid_operation",`${e} must be true or false`)}function Ne(t){return j(t).flatMap(e=>e.objects)}function Ho(t,e){let n=Co(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 Vo(t){let e=t.height??40,n=Ro(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 Xo(t,e){t.type!=="row"&&(e?t.entrance=e:delete t.entrance)}var Bo=t=>t.type==="row"?void 0:t.entrance;function mi(t,e){let n=Lt(e),o=[];for(let i of Ne(t))!pe(i)||i.entranceGateId!==e.id||(Xo(i,n),o.push(i.id));return o}function zt(t,e,n){n.name!==void 0&&(t.label=it(n.name,40,"Gate name")),n.use!==void 0&&(gi(n.use),e.use=n.use),n.stepFree!==void 0&&(Bt(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=it(n.opens,40,"Opening time")),n.hideFromBuyers!==void 0&&(Bt(n.hideFromBuyers,"Hide from buyers"),n.hideFromBuyers?e.hideFromBuyers=!0:delete e.hideFromBuyers),t.gate=e,t.role=xo(e.use)}function bi(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:Tt.navigation,...o?{rotation:o}:{},heightM:Le("entrance")?.heightM??2.7};return zt(i,{use:"in"},n),Vo(i),i}function Cc(t,e){let n=R(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=bi(o,e.center,{...e,name:e.name??Nt(t)},e.rotation??0);return n.objects.push(i),{changed:!0,floorId:n.floorId,gate:structuredClone(i)}}function Rc(t,e){let n=Ho(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);zt(i,i.gate,e.patch),(e.patch.name!==void 0||e.patch.stepFree!==void 0)&&Vo(i);let a=JSON.stringify(i)!==o;a&&Object.assign(n,i);let r=mi(t,n);return{changed:a,gate:structuredClone(n),servedObjectIds:r}}function Oc(t,e){let n=Ne(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"||!vo(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 zt(n,{use:n.role==="exit"?"out":"in"},{...e,name:e.name??(i?Nt(t):o.slice(0,40))}),{changed:!0,gate:structuredClone(n)}}function _c(t,e){if(!e.objectIds.length)throw new d("invalid_operation","At least one object id is required");let n=Ne(t),o=new Map(n.map(u=>[u.id,u])),i=e.objectIds.filter(u=>!o.has(u));if(i.length)throw new d("object_not_found",`Unknown object id(s): ${i.join(", ")}`,{objectIds:i});let a=e.objectIds.filter(u=>!pe(o.get(u)));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:Ho(t,e.gateId),s=new Set(e.objectIds.flatMap(u=>{let g=o.get(u);return g.type==="section"?[g.logicalSectionId??g.id]:[]})),c=n.filter(u=>pe(u)&&(e.objectIds.includes(u.id)||u.type==="section"&&s.has(u.logicalSectionId??u.id))),l=r?Lt(r):void 0,f=!1;for(let u of c){let g=`${u.entranceGateId??""}|${Bo(u)??""}`;r?u.entranceGateId=r.id:delete u.entranceGateId,Xo(u,l),`${u.entranceGateId??""}|${Bo(u)??""}`!==g&&(f=!0)}return{changed:f,objectIds:c.map(u=>u.id)}}function Wo(t,e){let n=new Map(e.filter(So).map(i=>[i.id,i.label?.trim()??""]));if(!n.size)return[];let o=[];for(let i of Ne(t))!pe(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 Pc(t,e){for(let n of t){if(!pe(n)||!n.entranceGateId)continue;let o=e.get(n.entranceGateId);o&&(n.entranceGateId=o)}}function pi(t,e,n=qo,o=!0){return{type:"shape",id:t,kind:e.length===2?"line":"polyline",label:it(n,40,"Route name"),points:e.map(i=>({x:i.x,y:i.y})),stroke:{...Jo},lineCap:"round",lineJoin:"round",endEnding:"arrow",route:o?{stepFree:!0}:{}}}function Ac(t,e){let n=R(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=pi(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 kc(t,e){let n=Ne(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?(Bt(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=it(e.route.name,40,"Route name"):n.label?.trim()||(n.label=qo),n.route||(n.stroke={...Jo}),n.route=i}return{changed:JSON.stringify(n)!==o,shape:structuredClone(n)}}function qc(t,e){let n=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(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&&E(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 f=we(r,"Table"),u=Ze(r,"Table"),g=ot(r,"Table"),h=Do(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),rt(m,g),Lo(m,h),r.fill===null&&delete m.fill,m.shape==="round")delete m.seatCountsBySide,m.automaticRadius===!0?m.radius=to(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(u&&delete m.displayType,f&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let x=["top","bottom","left","right"],C=x.reduce((_,F)=>_+m.seatCountsBySide[F],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)&&be(m.label))throw new d("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),p=new Map(y.map(v=>[v.id,v])),S=new Set(o),I=new Map;for(let v of j(t))for(let m of v.objects){let x=m.type==="table"?p.get(m.id)??m:m,C=[];x.type==="row"?C=q(x).map(_=>_.label):x.type==="table"?C=x.bookAsWhole||x.variableOccupancy?[x.label]:Ae(x).map(_=>_.label):x.type==="booth"?C=[x.label]:x.type==="gaArea"&&(C=ne(x));for(let _ of C){let F=I.get(_);if(F&&(S.has(F)||S.has(x.id)))throw new d("invalid_operation",`Inventory label "${_}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:_,conflictingObjectIds:[F,x.id]});I.set(_,F??x.id)}}let b=!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&&(b=!0)}return{floorId:n.floorId,changed:b,tableIds:o}}function Hc(t,e){let n=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(p=>n.objects.find(S=>S.type==="booth"&&S.id===p)),a=o.filter((p,S)=>!i[S]);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&&E(t,r.categoryKey);let s=(p,S,I,b)=>{if(S!==void 0&&(!Number.isFinite(S)||S<I||S>b))throw new d("invalid_operation",`${p} must be from ${I} to ${b}`)};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 p=Dn(r.points);if(!p.ok)throw new d("invalid_operation",p.message??"The booth outline is not a valid simple polygon")}let l=r.points!=null?r.points.map(p=>({x:p.x,y:p.y})):void 0;delete r.points;let f=we(r,"Booth"),u=Ze(r,"Booth"),g=ot(r,"Booth"),h=No(r),y=!1;for(let p of i){let S=JSON.stringify(p);Object.assign(p,r),rt(p,g),Go(p,h),f&&delete p.displayLabel,u&&delete p.displayType,c?delete p.points:l&&(p.points=l),JSON.stringify(p)!==S&&(y=!0)}return{floorId:n.floorId,changed:y,boothIds:o}}function Vc(t,e){let n=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(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&&E(t,r.categoryKey),r.capacity!==void 0&&(!Number.isInteger(r.capacity)||r.capacity<1||r.capacity>H))throw new d("invalid_operation",`capacity must be an integer from 1 to ${H}`);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=we(r,"GA area"),c=Ze(r,"GA area"),l=ot(r,"GA area"),f=Mo(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&&kt(h,r.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${h.label}" cannot append that capacity safely`,{gaAreaId:h.id})}let u=i.map(h=>{let y=structuredClone(h),p=r.capacity===void 0?h.inventorySegments:kt(h,r.capacity);return Object.assign(y,r),rt(y,l),Fo(y,f),p!==void 0&&(y.inventorySegments=p),s&&delete y.displayLabel,c&&delete y.displayType,y});jo(t,u);let g=!1;for(let[h,y]of i.entries()){let p=u[h],S=JSON.stringify(y);for(let I of Object.keys(y))I in p||delete y[I];Object.assign(y,p),JSON.stringify(y)!==S&&(g=!0)}return{floorId:n.floorId,changed:g,gaAreaIds:o}}function Yo(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+=q(i).length:i.type==="table"?o+=Ae(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=de(i)));return o}function Xc(t,e){let n=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=>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 Wo(t,a),{floorId:n.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+de(c),0),remainingObjectCount:n.objects.length}}function Wc(t,e){let n=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=>n.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 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:f=4,opacity:u=.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(f)||f<0||f>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(u)||u<.1||u>1)throw new d("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(l=>Object.prototype.hasOwnProperty.call(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(!bo(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 f=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)!==f&&(ke(l),c=!0)}return{floorId:n.floorId,changed:c,textIds:o}}function Yc(t,e){let n=R(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=Kn(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),f=l===void 0||l===""||l==="Row"?e.displayType===void 0?void 0:null:l,u=!1;return r.forEach((g,h)=>{let y=c[h].label.normalize("NFKC").replace(/\s+/g," ").trim();if(s(g)!==y&&(u=!0,g.segmentedRow?g.segmentedRow.displayLabel=y:g.displayLabel=y),f!==void 0){if(f===null){g.displayType!==void 0&&(u=!0,delete g.displayType);return}g.displayType!==f&&(u=!0,g.displayType=f)}}),{floorId:n.floorId,changed:u,rows:r.map(g=>({id:g.id,displayLabel:s(g),...g.displayType?{displayType:g.displayType}:{}}))}}function Zc(t,e){let n=Po.find(f=>f.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=R(t,e.floorId),a=new Set,r=n.build().map(f=>structuredClone(f));for(let f of r)f.id=M(t,f.type,e.idFactory,a),se(f,e.center.x,e.center.y),o%360&&Ao(f,e.center,o);for(let f of n.categories)t.categories.some(u=>u.key===f.key)||t.categories.push({...f});let s=r.filter(f=>f.type==="row");if(s.length){let f=0;for(let u of i.objects){if(u.type!=="row")continue;let g=tt(u.label);g!=null&&(f=Math.max(f,g+1))}for(let u of s)u.label=L(f++)}let c=new Set(i.objects.flatMap(f=>"label"in f&&f.label?[f.label]:[]));for(let f of r){if((f.type==="table"||f.type==="booth")&&c.has(f.label)){let u=/^(.*?)(\d+)$/.exec(f.label),g=u?u[1]:`${f.label} `,h=u?Number.parseInt(u[2],10):1;do h++;while(c.has(`${g}${h}`));f.label=`${g}${h}`}"label"in f&&f.label&&c.add(f.label)}i.objects.push(...r);let l=null;if(n.sectionLabel&&e.wrapInSection!==!1){let f=ye(r);if(f){let u={type:"section",id:M(t,"sec",e.idFactory,a),label:n.sectionLabel,outline:f};i.objects.push(u),l=u.id}}return{floorId:i.floorId,blockKey:n.key,createdIds:[...r.map(f=>f.id),...l?[l]:[]],sectionId:l}}function yi(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=Mn(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 wi(t,e){let n=R(t,e.floorId),o=n.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=yi(e.path),a=q(o),r=structuredClone(o);r.path=i.path,r.origin={...i.path.start};let s=q(r),c=a.map((f,u)=>Math.hypot(f.x-s[u].x,f.y-s[u].y)),l=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((f,u)=>f+u,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function al(t,e){let n=wi(t,e);if(!n.changed)return n;let i=R(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 Ii(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 Si(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=Ii(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 vi(t,e){let n=R(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=j(t).find(h=>h.id===n.floorId),r=e.mode==="outline"?Si(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=[],f=[],u=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 p=2*Math.asin(h.seatSpacing/(2*y))/Z,S=q(h),I=Math.atan2(h.origin.x-r.x,h.origin.y-r.y)/Z,w=(h.curve!==0?Math.sign(h.curve):S.length>1&&Math.sign(Zo(Math.atan2(S[1].x-r.x,S[1].y-r.y)/Z-I))||1)*p*(h.seatCount-1);if(Math.abs(w)>320){l.push(h.id);continue}let v=-I,m=h.curve+(w-h.curve)*u,x=h.rotation+Zo(v-h.rotation)*u,C={...h,curve:m,rotation:x},F=q(C).map((B,z)=>Math.hypot(B.x-S[z].x,B.y-S[z].y));f.push({rowId:h.id,fromCurve:h.curve,targetCurve:w,resultCurve:m,fromRotation:h.rotation,resultRotation:x,rmsMovement:Math.sqrt(F.reduce((B,z)=>B+z**2,0)/F.length),maxMovement:Math.max(...F)})}let g=f.map(h=>h.rmsMovement);return{floorId:n.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...r},strength:i,rows:f,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:g.length?g.reduce((h,y)=>h+y,0)/g.length:0,maxMovement:f.length?Math.max(...f.map(h=>h.maxMovement)):0}}function sl(t,e){let n=vi(t,e),o=R(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 er(t,e,n,o){let i=Y(t,e,n),a=Y(t,e,o),r=Y(n,o,t),s=Y(n,o,e);return i*a<-1e-9&&r*s<-1e-9}function Qo(t,e){return t.some((n,o)=>{let i=t[(o+1)%t.length];return e.some((a,r)=>er(n,i,a,e[(r+1)%e.length]))})}function xi(t){if(t.length<3||t.length>256||Math.abs(Xe(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)&&er(t[e],t[(e+1)%t.length],t[n],t[(n+1)%t.length]))return!1;return!0}function at(t,e,n){let o=R(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"?Ln(i):i.points;return{target:o,object:i,outer:a}}function tr(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:Yo(t.objects.filter(i=>i.id!==e.id),n)}}function Ut(t,e){let{target:n,object:o,outer:i}=at(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!xi(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(Qo(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>=_t)throw new d("invalid_operation",`A shape holds at most ${_t} 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 f=r[l];if(Qo(a,f)||$(a[0],f,void 0)||$(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let c=tr(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 cl(t,e){let n=Ut(t,e),{object:o}=at(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 Ci(t,e){let{target:n,object:o}=at(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=tr(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 ll(t,e){let n=Ci(t,e),{object:o}=at(t,n.floorId,n.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function Ri(t){let e=le(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function nr(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 Oi(t,e){let n=R(t,e.floorId),o=nr(n.objects,e.sectionIds),i=Fe(oe(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),f=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 p of Ye(y).keys())c.add(p);else(y.type==="booth"||y.type==="gaArea")&&c.add(y.categoryKey)}let u=o.logicalSectionIds.every(h=>(a.get(h)?.seatCount??0)>0),g=o.logicalSectionIds.every(h=>a.get(h)?.objectIds.some(y=>{let p=r.get(y);return p?.type==="row"||p?.type==="table"||p?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:u,...u&&c.size===1?{categoryKey:[...c][0]}:!u&&!s.length&&f.size===1?{categoryKey:[...f][0]}:{},categoryMixed:u?c.size!==1:!s.length&&f.size>1,viewApplicable:g}}function wl(t,e){E(t,e.categoryKey);let n=Oi(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=R(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(f=>{if(f.categoryKey===void 0)return[f];let u={...f};return delete u.categoryKey,r++,a=!0,Object.keys(u).some(g=>g!=="index")?[u]:[]});l.length?c.overrides=l:delete c.overrides}return{...n,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function or(t,e){let n=R(t,e.floorId),o=nr(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=Ri(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&&Qe(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ie(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),f=c?n.objects.filter(h=>h.type==="section"&&l.has(h.logicalSectionId??h.id)):[],u=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 p=S=>{h.physical3dProvenance&&(delete h.physical3dProvenance[S],Object.keys(h.physical3dProvenance).length===0&&delete h.physical3dProvenance)};a.height===null?(delete h.height,p("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,p("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,p("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,u.add(h.id))}for(let h of f){let y=JSON.stringify(h),p=h.viewFromSeatUrl;a.displayLabel===null?delete h.displayLabel:a.displayLabel!==void 0&&(h.displayLabel=a.displayLabel);let S=h.entrance;if(a.entrance===null||a.entrance===""?delete h.entrance:a.entrance!==void 0&&(h.entrance=a.entrance),h.entrance!==S&&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!==p&&delete h.viewFromSeatMeta,a.labelStyle!==void 0){let I=Ie(h.labelPresentation,a.labelStyle);I?h.labelPresentation=I:delete h.labelPresentation}a.zone===null?delete h.zone:a.zone!==void 0&&(h.zone=a.zone),JSON.stringify(h)!==y&&(g=!0,u.add(h.id))}return{floorId:n.floorId,changed:g,sectionIds:i,affectedSectionIds:[...u]}}function _i(t,e){let n=R(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+de(r),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function Il(t,e){let n=_i(t,e),i=R(t,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function Pi(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),f=Math.sin(c),u=G(t);o=g=>{let h=g.x-u.x,y=g.y-u.y;return{x:u.x+h*l-y*f,y:u.y+h*f+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=We(t.outlinePath,o,i,a)),a&&t.edgeCurvature&&(t.edgeCurvature=En(t.edgeCurvature)),t.holes&&(t.holes=Q(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 Sl(t,e){let n=R(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,...Pi(o,e.transform)}}function vl(t,e){let n=R(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(!Fn(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ot(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 Ai(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function xl(t,e){return ki(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function ki(t,e){let n=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,r=!1;try{for(let s of o){let c=n.objects.find(b=>b.type==="section"&&b.id===s);if(!c||!Ai(c))continue;let f=structuredClone(c);a.set(c.id,{section:c,snapshot:f});let u=JSON.stringify(c),g=(c.sourceOutline??c.outline).map(b=>({...b})),h=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),p=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(b=>Math.min(100,Math.max(-100,b))),S=p?.some(b=>Math.abs(b)>.5)===!0,I=h>.5||S?Tn(g,{cornerSmoothing:h,...S?{edgeCurvature:p}:{}}):null;I?(c.sourceOutline=g,c.outlinePath=I,c.outline=Ot(I),h>.5?c.cornerSmoothing=h:delete c.cornerSmoothing,S?c.edgeCurvature=[...p]:delete c.edgeCurvature):(c.outline=g,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let b=0;b<(c.holes?.length??0);b+=1)Ut(t,{floorId:n.floorId,objectId:c.id,points:c.holes[b],holeIndex:b});JSON.stringify(c)!==u&&(r=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let f=c;for(let u of Object.keys(f))delete f[u];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:r,sectionIds:o,affectedSectionIds:[...i]}}function Pl(t,e,n={}){let o=!1;for(let i of e){let a=or(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=R(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=R(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=Te(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&&et(t),{changed:o}}var Mi=new Set(["companion","child","senior","student","membership","custom"]);function Se(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&&!je(i.seatGlyph))throw new d("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,f=new Set;for(let u of i.tiers){let g=u.id.trim(),h=u.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||f.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(u.price)||u.price<0||u.price>1e6)throw new d("invalid_operation",`Ticket tier ${g} price must be from 0 to 1000000`,{categoryKey:a,tierId:g});if(u.restriction!=null&&!Mi.has(u.restriction))throw new d("invalid_operation",`Ticket tier ${g} has an unknown restriction`,{categoryKey:a,tierId:g});if(u.buyerMessage!=null){if(u.buyerMessage=u.buyerMessage.normalize("NFKC").trim(),!u.buyerMessage)delete u.buyerMessage;else if(u.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${g} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:g})}if(u.currency!=null&&(u.currency=u.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(u.currency)))throw new d("invalid_operation",`Ticket tier ${g} must use a three-letter ISO currency`,{categoryKey:a,tierId:g});if(u.applicability!=null){let p=u.applicability.seatLabels?.map(I=>I.normalize("NFKC").trim()),S=u.applicability.accessibility;if(p&&(!p.length||p.length>1e4||p.some(I=>!I||I.length>160)||new Set(p).size!==p.length)||S&&(!S.length||S.some(I=>!He.some(b=>b.key===I))||new Set(S).size!==S.length))throw new d("invalid_operation",`Ticket tier ${g} has invalid seat applicability`,{categoryKey:a,tierId:g});u.applicability={...p?{seatLabels:p}:{},...S?{accessibility:[...S]}:{}},!u.applicability.seatLabels&&!u.applicability.accessibility&&delete u.applicability}if(u.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(u.evidence.provenance)||typeof u.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g});if(u.evidence.sourceDescription=u.evidence.sourceDescription.normalize("NFKC").trim(),!u.evidence.sourceDescription||u.evidence.sourceDescription.length>240||u.evidence.capturedAt!==void 0&&(u.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(u.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:a,tierId:g})}l.add(g),f.add(y)}}}return o}function Jt(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(u=>u.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,...f}=c;typeof f.label=="string"&&(f.label=f.label.normalize("NFKC").trim()),typeof f.color=="string"&&(f.color=f.color.toLowerCase()),Object.assign(s,f),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(u=>{let g={...u,id:u.id.trim(),name:u.name.normalize("NFKC").trim()};return u.buyerMessage?.trim()?g.buyerMessage=u.buyerMessage.normalize("NFKC").trim():delete g.buyerMessage,g})),delete s.referenceDirectSeatImport}let i=Se(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...n],categories:t.categories}}function Nl(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=Se(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 Gl(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=Se(n.map((c,l)=>{let f=structuredClone(s.get(c));return c!==o[l]&&delete f.referenceDirectSeatImport,f})),{changed:!0,categoryKeys:n,categories:t.categories}}function rr(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 Fi(t,e){let n=rr(t),o=rr(e);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var ji=3600;function Ei(t,e,n=Et){return n.find(i=>t.every(a=>Fi(i,a)>=ji))??n[e%n.length]}function Kl(t,e){let n=e?.palette??Et;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 Jt(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 $l(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=Se(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 qt(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=Se([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(r=>r.key===o),categories:a}}var Ti=["#3e8e7e","#6e7ff0","#b0700f","#b05fc4"],Di=[...Ti,"#4d7c0f","#c026d3","#a86b00","#d6336c","#e5484d","#dc2626"],Li={row:"#6e7ff0",table:"#3e8e7e",booth:"#b05fc4",gaArea:"#b0700f"};function Ni(t,e){let n=Li[t];return!n||!e.includes(n)?e:[n,...e.filter(o=>o!==n)]}var Gi="#f5f6f8",Ki="#f7f8fb",$i=26;function Bi(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,f=u=>Math.round((u+l)*255).toString(16).padStart(2,"0");return`#${f(r)}${f(s)}${f(c)}`}function zi(t,e,n,o,i){let a=f=>t.every(u=>{let g=io(f,u);return g==null||g>=$i}),r=[Gi,i??Ki],s=(f,u)=>Mt(fo(f,u,co),u)??0,c=f=>o==="gaArea"?[...r,"#12151d"].every(u=>s(f,u)>=3):r.every(u=>(Mt(f,u)??0)>=3),l=e.find(f=>a(f)&&c(f));if(l)return l;for(let f=0;f<360;f+=12)for(let u of[.52,.44,.6]){let g=Bi(f,.62,u);if(a(g)&&c(g))return g}return n}function Ui(t,e){let n=Ee.find(a=>a.objectType===e).creationWord,o=t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim();return Ee.some(a=>a.creationWord.toLowerCase()===o.toLowerCase())?n:`${o} \u2013 ${n}`}function Ji(t){let e=new Map;for(let n of j(t))for(let o of n.objects){let i=Ee.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of Ye(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 qi(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 Hi(t,e,n){let o=Ji(t),i=f=>{let u=o.get(f);return!u||u.size===0||u.size===1&&u.has(n)},a=t.categories.find(f=>f.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};let r=t.categories.find(f=>{let u=o.get(f.key);return u?.size===1&&u.has(n)});if(!a&&r)return{kind:"existing",categoryKey:r.key,label:r.label};let s=Ee.find(f=>f.objectType===n),c=a?Ui(a.label,n):s.creationWord,l=t.categories.find(f=>f.label.toLowerCase()===c.toLowerCase()&&i(f.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:qi(t,c)}}function Bl(t,e,n,o){let i=Hi(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 Vi(t,n,a,i.label,o)}function Vi(t,e,n,o,i){let a=i.palette??Di,r=t.categories.map(f=>f.color),s=i.suggestColor?.(r.map(f=>f.toLowerCase()))??Ei(r,t.categories.length),c=zi(r,Ni(e,a),s,e,t.theme?.background),l=qt(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 Xi(t,e){let n=new Set;for(let o of j(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 ir(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=Xi(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=Se(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}function Hl(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=Wi(t.categories,o.label),a=qt(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)&&Jt(t,{updates:[{categoryKey:a.category.key,patch:{...o.notForSale?{notForSale:!0}:{},...o.seatGlyph?{seatGlyph:o.seatGlyph}:{}}}]})}return{categoryKeys:n,categories:t.categories}}function Wi(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 Vl(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 j(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 f={...l};return delete f.categoryKey,Object.keys(f).some(u=>u!=="index")?[f]:[]});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=ir(t,{categoryKey:n});return{movedObjectIds:[...i],categories:a.categories}}var Ht=["daylight","floodlit","evening","arena-show","theatre","concert-hall","plain"];var Yi=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Zi=["seat","deck","shell","fascia"];function nd(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 Yi){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=D(r,`Theme ${a}`))}if(n.sectionDetail===null)delete i.sectionDetail;else if(n.sectionDetail!==void 0){if(n.sectionDetail!=="rows"&&n.sectionDetail!=="seats")throw new d("invalid_operation","Theme sectionDetail must be rows or seats");i.sectionDetail=n.sectionDetail}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<Ft||n.seatScale>jt)throw new d("invalid_operation",`Theme seatScale must be from ${Ft} to ${jt}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=le(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??{}},r=n.venue3d.look;if(r===null)delete a.look;else if(r!==void 0){if(!Ht.includes(r))throw new d("invalid_operation",`3D venue look must be one of: ${Ht.join(", ")}`);a.look=r}for(let c of Zi){let l=n.venue3d[c];l===null?delete a[c]:l!==void 0&&(a[c]=D(l,`3D venue ${c}`))}let s=n.venue3d.roughness;if(s===null)delete a.roughness;else if(s!==void 0){if(!Number.isFinite(s)||s<0||s>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=s}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 od(t,e){let n=e.url===null?null:le(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(u=>u.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===o,l=o?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,f=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,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 ve(t,e){let n=oe(t,e.floorId),o=ee(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 st(t,e){E(t,e.categoryKey);let n=(...f)=>f.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");if(e.seatsPerRowByRow!==void 0&&(i!=="fixed-count"||e.seatsPerRowByRow.length!==e.rowCount||e.seatsPerRowByRow.some(f=>!Number.isInteger(f)||f<2||f>300)))throw new d("invalid_operation","Fixed Arc/Fan seats per row need one count from 2 to 300 for every row");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(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:r,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function ar(t,e,n){let o=n*Z;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function Qi(t,e,n,o){let i=Math.abs(o-n)*Z,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,f])=>{let u=t.aisleGaps[l];if(!u)return[];let g=u/e/i/2;return[[Math.max(0,f-g),Math.min(1,f+g)]]}).sort((l,f)=>l[0]-f[0]),r=[];for(let l of a){let f=r[r.length-1];f&&l[0]<=f[1]?f[1]=Math.max(f[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,f])=>e*i*(f-l)>=t.seatPitch*.75)}function Xt(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 ct(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 f=Qi(t,r,c,l);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let u=f.map(([y,p])=>r*Math.abs(l-c)*Z*(p-y)),g=t.fit==="fixed-count"?Xt(u,t.seatsPerRowByRow?.[i]??t.seatsPerRow):u.map(y=>Math.max(2,Math.round(y/t.seatPitch)+1)),h=t.seatLabelStart;f.forEach(([y,p],S)=>{let I=c+(l-c)*y,b=c+(l-c)*p;t.facing==="outward"&&([I,b]=[b,I]);let w=g[S];if(w>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let v=Math.abs(b-I)*Z/(w-1),m=2*r*Math.sin(v/2),x={type:"row",id:n(i,S),label:L(t.rowLabelStart+i),origin:ar(t.center,r,I),rotation:-I,curve:b-I,seatCount:w,seatSpacing:m,categoryKey:t.categoryKey,seatLabelStart:h,...f.length>1?{aisleSeats:S===0?"end":S===f.length-1?"start":"both"}:{},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}:{},...t.seatsPerRowByRow?{seatsPerRowByRow:[...t.seatsPerRowByRow]}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:S}};o.push(x),h+=w})}return o}var ea=150,Vt=22,ta=3;function sr(t,e){if(Math.abs(t.endAngle-t.startAngle)<=ea)return ye(e);let n=(t.startAngle+t.endAngle)/2,o=1/0,i=0,a=1/0,r=-1/0;for(let y of e)for(let p of q(y)){let S=p.x-t.center.x,I=p.y-t.center.y,b=Math.hypot(S,I),w=(Math.atan2(S,I)/Z-n+540)%360-180;o=Math.min(o,b),i=Math.max(i,b),a=Math.min(a,w),r=Math.max(r,w)}if(!Number.isFinite(o))return null;let s=Math.max(0,o-Vt),c=i+Vt,l=Vt/Math.max(o,1)/Z,f=Math.max(a-l,-179.5),u=Math.min(r+l,179.5),g=Math.max(2,Math.ceil((u-f)/ta)),h=(y,p)=>Array.from({length:g+1},(S,I)=>{let b=p?g-I:I;return ar(t.center,y,n+f+(u-f)*b/g)});return[...h(c,!1),...s>0?h(s,!0):[{...t.center}]]}function cr(t,e){let n=st(t,e),o=R(t,e.floorId),i=ct(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*zn*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 Wt(t,e){let n=st(t,e),o=R(t,e.floorId),i=new Set,a=M(t,"fan",e.idFactory,i),r=ct(n,a,()=>M(t,"r",e.idFactory,i)),s=cr(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(l){if(l.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let u=sr(n,r);u&&(c=M(t,"sec",e.idFactory,i),f={type:"section",id:c,label:l,outline:u,arcFanGroupId:a})}return o.objects.push(...r,...f?[f]:[]),{floorId:o.floorId,rowIds:r.map(u=>u.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function na(t,e){let n=R(t,e.floorId),o=n.objects.filter(u=>u.type==="row"&&u.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=u=>{let g=u.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,seatsPerRowByRow:g.seatsPerRowByRow,facing:g.facing,taperDegrees:g.taperDegrees,skewDegrees:g.skewDegrees,aisleGaps:g.aisleGaps,rowLabelStart:g.rowLabelStart,seatLabelStart:g.seatLabelStart})};if(o.some(u=>a(u)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let r=n.objects.find(u=>u.type==="section"&&u.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,...i.seatsPerRowByRow?{seatsPerRowByRow:[...i.seatsPerRowByRow]}:{},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=st(t,s),l=new Set(ct(c,e.groupId,(u,g)=>`${u}:${g}`).map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(u=>`${u.arcFanGeneration.rowIndex}:${u.arcFanGeneration.segmentIndex}`));if(l.size!==f.size||[...l].some(u=>!f.has(u)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function ld(t,e){na(t,{floorId:e.floorId,groupId:e.groupId});let n=st(t,e),o=R(t,e.floorId),i=o.objects.filter(p=>p.type==="row"&&p.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(p=>p.type==="section"&&p.arcFanGroupId===e.groupId),r=new Map(i.map(p=>[`${p.arcFanGeneration.rowIndex}:${p.arcFanGeneration.segmentIndex}`,p.id])),s=new Set,c=ct(n,e.groupId,(p,S)=>r.get(`${p}:${S}`)??M(t,"r",e.idFactory,s)),l=cr(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),u=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let p=sr(n,c);p&&(u={type:"section",id:a?.id??M(t,"sec",e.idFactory,s),label:f,outline:p,arcFanGroupId:e.groupId})}let g=new Set([...i.map(p=>p.id),...a?[a.id]:[]]),h=Math.min(...o.objects.map((p,S)=>g.has(p.id)?S:1/0)),y=o.objects.filter(p=>!g.has(p.id));return y.splice(Number.isFinite(h)?h:y.length,0,...c,...u?[u]:[]),o.objects.splice(0,o.objects.length,...y),{floorId:o.floorId,rowIds:c.map(p=>p.id),sectionId:u?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function lr(t,e){let n=oa(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 oa(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,u=String.fromCharCode(65+l%26).repeat(t.length+Math.floor(l/26));return r?u.toLowerCase():u}}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=tt(o);if(i==null)return null;let a=t===t.toLowerCase();return r=>{let s=L(i+r);return a?s.toLowerCase():s}}function Yt(t){return t.segmentedRow?.displayLabel??t.displayLabel??t.label}function ra(t,e=[]){let n=new Set([...W(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 ia(t){let e=new Set(t.flatMap(o=>o.type==="row"?[Yt(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 aa(t,e){let n=t.filter(c=>c.type==="section"),o=n.find(c=>$(e,c.outline,c.holes));if(!o)return ia(t);let i=t.filter(c=>c.type==="row"&&Yn(t,c,n)===o),a=new Set(i.map(Yt)),r=i[i.length-1],s=r?Yt(r):void 0;return()=>{let c=lr(s,a);return a.add(c),s=c,c}}function dr(t,e){let n=e.pending??[],o=ra(t,n),i=aa([...R(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}})}var sa=1,Zt=.01;function fr(t,e){let n=J(t),o=n[n.length-1],i=J(e)[0];if(!o||!i)return null;let a=Math.hypot(i.x-o.x,i.y-o.y),r=a>Zt?{x:(i.x-o.x)/a,y:(i.y-o.y)/a}:{x:Math.cos(e.rotation*Math.PI/180),y:Math.sin(e.rotation*Math.PI/180)};return{distance:a,direction:r,pitch:(t.seatSpacing+e.seatSpacing)/2}}function ur(t,e){return e==="break"?t*(1+sa):t}function Id(t,e){let n=t[e-1],o=t[e];if(!n||!o||o.segmentedRow?.boundaryBefore!=="break")return!1;let i=fr(n,o);return!!i&&ur(i.pitch,"break")-i.distance>=Zt}function lt(t,e,n){let o=t[e-1],i=t[e];if(!o||!i)return!1;let a=fr(o,i);if(!a)return!1;let r=ur(a.pitch,n),s=n==="break"?Math.max(0,r-a.distance):Math.min(0,r-a.distance);if(Math.abs(s)<Zt)return!1;for(let c of t.slice(e))se(c,a.direction.x*s,a.direction.y*s);return!0}function hr(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 gr(t,e){if(E(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=R(t,e.floorId),a=new Set,r=dr(t,{floorId:e.floorId,origin:e.origin,count:e.rowCount}),s=Kt(e.rotation??0),c=e.curve??0,l=e.style,f=l?M(t,"rowblock",e.idFactory,a):void 0,u=l?hr({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*te),y:Math.sin(s*te)},h={x:-g.y,y:g.x},y=Array.from({length:e.rowCount},(I,b)=>{let w=l==="intertwined"&&b%2===1?o/2:0,v={type:"row",id:M(t,"r",e.idFactory,a),...r[b],origin:{x:e.origin.x+h.x*b*n+g.x*w,y:e.origin.y+h.y*b*n+g.y*w},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return l&&f&&u&&(v.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:l,rowIndex:b,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:n,seatSpacing:o,curve:c,signature:u}),v});i.objects.push(...y);let p=null,S=e.sectionLabel?.trim();if(S){let I=ye(y);if(I){let b={type:"section",id:M(t,"sec",e.idFactory,a),label:S,outline:I};i.objects.push(b),p=b.id}}return{floorId:i.floorId,rowIds:y.map(I=>I.id),sectionId:p,createdIds:[...y.map(I=>I.id),...p?[p]:[]]}}function mr(t,e){let n=new Set(W(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 ca(t,e){let n=new Set(W(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 la=456;function Qt(t){let e=Math.sqrt(Math.max(1,t)*la);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function br(t,e){if(E(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=R(t,e.floorId),o=new Set,{width:i,height:a}=Qt(e.capacity),r=ca(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 pr(t,e){if(E(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=R(t,e.floorId),a=new Set,r=mr(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 yr(t,e){if(E(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=R(t,e.floorId),a=new Set,r=mr(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 dt(t,e){let n=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(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):[])),f="";for(let g=0;g<100;g+=1){let h=e.idFactory("rowgroup");if(h&&!l.has(h)){f=h;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let u=r[0];return r.forEach((g,h)=>{g.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:h,componentCount:r.length,boundaryBefore:h===0?"start":e.boundaries[h-1],displayLabel:c,...u.displayType?{displayType:u.displayType}:{},...u.labelPresentation?{labelPresentation:structuredClone(u.labelPresentation)}:{},...u.viewFromSeatUrl?{viewFromSeatUrl:u.viewFromSeatUrl}:{},...u.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(u.viewFromSeatMeta)}:{},...u.confidenceEvidence?{confidenceEvidence:structuredClone(u.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:f,rowIds:o,changed:!0}}function Pd(t,e){let n=R(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=R(t,e.floorId),o=n.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId).sort((s,c)=>s.segmentedRow.componentIndex-c.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(s=>s!=="continuous"&&s!=="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(s=>s.segmentedRow)),r=!1;return e.boundaries?.forEach((s,c)=>{s==="break"&&(r=lt(o,c+1,"break")||r)}),o.forEach((s,c)=>{let l=s.segmentedRow,f=l.viewFromSeatUrl;i!==void 0&&(l.displayLabel=i),e.boundaries&&c>0&&(l.boundaryBefore=e.boundaries[c-1]),e.smoothing!==void 0&&(l.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete l.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(l.viewFromSeatUrl=e.viewFromSeatUrl),!l.viewFromSeatUrl||e.viewFromSeatMeta===null?delete l.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?l.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&l.viewFromSeatUrl!==f&&delete l.viewFromSeatMeta}),{floorId:n.floorId,groupId:e.groupId,rowIds:o.map(s=>s.id),changed:r||JSON.stringify(o.map(s=>s.segmentedRow))!==a,...r?{seatsMoved:!0}:{}}}function kd(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=R(t,e.floorId),o=n.objects.filter(P=>P.type==="row"&&P.rowBlockGeneration?.groupId===e.groupId).sort((P,V)=>P.rowBlockGeneration.rowIndex-V.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((P,V)=>{let A=P.rowBlockGeneration;return A.kind!=="row-block-v1"||A.rowIndex!==V||A.signature!==i.signature||JSON.stringify(A)!==JSON.stringify({...i,rowIndex:V})}))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,f=e.seatSpacing??i.seatSpacing,u=e.curve??i.curve,g=Number.isFinite(e.rotation??i.rotation)?Kt(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,f].every(P=>Number.isFinite(P)&&P>0)||!Number.isFinite(u)||!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=hr({style:r,origin:h,rotation:g,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:f,curve:u}),p={x:Math.cos(g*te),y:Math.sin(g*te)},S={x:-p.y,y:p.x},I=new Map(o.map(P=>[P.rowBlockGeneration.rowIndex,P])),b=new Set,w=new Set(n.objects.filter(P=>P.type==="row").filter(P=>!o.includes(P)).map(P=>P.label)),v=n.objects.filter(P=>P.type==="row").length,m=()=>{for(;w.has(L(v));)v+=1;let P=L(v);return w.add(P),v+=1,P},x=[],C=[];for(let P=0;P<s;P+=1){let V=r==="intertwined"&&P%2===1?f/2:0,A=I.get(P);A||(A={type:"row",id:M(t,"r",e.idFactory,b),label:m(),origin:{...h},rotation:g,curve:u,seatCount:c,seatSpacing:f,categoryKey:o[0].categoryKey},C.push(A.id)),A.origin={x:h.x+S.x*P*l+p.x*V,y:h.y+S.y*P*l+p.y*V},A.rotation=g,A.curve=u,A.seatCount=c,A.seatSpacing=f,delete A.path,delete A.arcFanGeneration,A.overrides&&(A.overrides=A.overrides.filter(U=>U.index<c),A.overrides.length||delete A.overrides),A.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:r,rowIndex:P,rowCount:s,seatsPerRow:c,origin:{...h},rotation:g,rowGap:l,seatSpacing:f,curve:u,signature:y},x.push(A)}let _=o.slice(s).map(P=>P.id),F=Math.min(...o.map(P=>n.objects.indexOf(P))),B=new Set(o.map(P=>P.id)),z=n.objects.filter(P=>!B.has(P.id));return z.splice(F,0,...x),n.objects.splice(0,n.objects.length,...z),{floorId:n.floorId,groupId:e.groupId,rowIds:x.map(P=>P.id),createdRowIds:C,removedRowIds:_,changed:a!==JSON.stringify(x)||C.length>0||_.length>0}}function wr(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 da(t){let e=t.length,n=t.reduce((I,b)=>I+b.x,0)/e,o=t.reduce((I,b)=>I+b.y,0)/e,i=0,a=0,r=0,s=0,c=0,l=0,f=0;for(let I of t){let b=I.x-n,w=I.y-o;i+=b*b,a+=w*w,r+=b*w,s+=b*b*b,c+=w*w*w,l+=b*w*w,f+=w*b*b}let u=i*a-r*r;if(Math.abs(u)<1e-9)return null;let g=(s+l)/2,h=(c+f)/2,y=(g*a-h*r)/u,p=(h*i-g*r)/u,S=Math.sqrt(y*y+p*p+(i+a)/e);return Number.isFinite(S)?{center:{x:y+n,y:p+o},radius:S}:null}function Ge(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):wr(t),seatCount:i,ordered:t}}function fa(t){if(t.length<3)return Ge(t);let e=t[0],n=t[t.length-1],o=Math.hypot(n.x-e.x,n.y-e.y),i=wr(t);if(o<=0||i<=0)return Ge(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 Ge(t);let r=da(t);if(!r||r.radius<=i/2)return Ge(t);let s=g=>{let h=g[0],y=g[1],p=h.x-r.center.x,I=-(h.y-r.center.y),b=p;I*(y.x-h.x)+b*(y.y-h.y)<0&&(I=-I,b=-b);let w=Math.hypot(I,b)||1;I/=w,b/=w;let v=(r.center.x-h.x)*b+(r.center.y-h.y)*-I;return{tx:I,ty:b,centreSide:v}},c=t,l=s(c);l.centreSide<0&&(c=[...t].reverse(),l=s(c));let u=2*Math.asin(Math.min(1,i/(2*r.radius)))*(c.length-1)*180/Math.PI;return!Number.isFinite(u)||u>=359?Ge(t):{origin:{...c[0]},rotation:Math.atan2(l.ty,l.tx)*180/Math.PI,curve:u,seatSpacing:i,seatCount:c.length,ordered:c}}function ft(t,e){let n=fa(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[...ft(n.ordered.slice(0,r),e),...ft(n.ordered.slice(r),e)]}function en(t){return t.normalize("NFKC").replace(/\s+/g," ").trim()}function tn(t,e){let n="";for(let o of t){if(n.length+o.length>e)break;n+=o}return n.trim()}function nn(t){return tn(en(t),40)}function Ir(t,e=39){return tn(en(t),Math.max(1,e))}function xe(t,e=80){return tn(en(t),Math.max(1,e))}function Sr(t){return xe(t).toLocaleLowerCase("en")}function on(t){return Sr(t)}function vr(t){return new Map((t??[]).map(e=>[e.index,e]))}function ua(t){let e=vr(t.overrides),n=[];for(let o=0;o<t.seatCount;o+=1){let i=e.get(o);i?.skip||n.push(Pt(t,o,i))}return n}function ha(t){if(t.bookAsWhole||t.variableOccupancy)return[t.label];let e=vr(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 ga(t){return t.type==="row"?[t.label,...ua(t)]:t.type==="table"?[t.label,...ha(t)]:t.type==="booth"?[t.label]:t.type==="gaArea"?[t.label,...ne(t)]:[]}function xr(t,e){let n=new Set;for(let o of t)if(!e?.has(o.id))for(let i of ga(o)){let a=on(i);a&&n.add(a)}return n}function ma(t,e){if(!Number.isInteger(e)||e<1)return[];let n={label:t,seatCount:e},o=[on(t)];for(let i=0;i<e;i+=1)o.push(on(Pt(n,i)));return o.filter(Boolean)}function Cr(t,e,n){let o=ma(e,n);if(!o.length||o.some(i=>t.has(i)||be(i)))return!1;for(let i of o)t.add(i);return!0}var ba=1e-6,pa=160,ya=.001,wa=1e-5;function Ce(t){if(typeof t!="string")return;let e=t.normalize("NFKC").replace(/\s+/g," ").trim();if(!e||e.length>pa)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 Rr(t){return typeof t=="string"&&Ir(t)||void 0}function Or(t,e){if(t.seatCount!==e.seatCount||t.seatCount<1||!(rn(t.origin)&&rn(e.start)&&rn(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=ya+Math.max(1,i)*wa;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<=ba)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 rn(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}var Ia=300;function Sa(t){let e=new Set(W(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=nn(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 va(t){let e=xr(W(t));return(n,o)=>{let i=xe(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,s=r?`${xe(i,80-r.length)}${r}`:i;if(s&&Cr(e,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function xa(t){return{ordinaryFor:Sa(t),direct:va(t)}}function an(t,e,n){return t.type==="row"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function _r(t,e,n){return t.type==="table"&&t.referenceScan?.assetId===e&&(!n||t.referenceScan.sectionId===n)}function Ca(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=Ce(`${r.sourceGroupId}:${s}`),f=l&&Ce(c.directSourceRowId)===l?l:void 0;f&&o.set(f,o.has(f)?null:c)}let i=new Map;for(let r of t){let s=Ce(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),f=c[0],u=f.overrides;if(s.length!==1||c.length!==1||!u||!l||!Or(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:r,rowIds:s.map(g=>g.id)});a.set(r,structuredClone(u))}return a}function Pr(t,e,n){return t.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!an(o,e,n)&&!_r(o,e,n))}function Ra(t,e,n,o,i,a,r){let s=t.sectionId?e.find(f=>f.type==="section"&&f.id===t.sectionId):void 0;if(s){let f=Pr(e,n,r).filter(u=>$(G(u),s.outline,s.holes));if(f.length)return{skip:{sectionId:s.id,name:t.name,reason:"section_not_empty",objectIds:f.map(u=>u.id)},rows:[],seats:0}}let c=[],l=0;for(let[f,u]of t.rows.entries()){let g=Math.min(Ia,Math.max(1,Math.round(u.seatCount)));if(!Number.isFinite(g)||g<1)continue;let h=u.end.x-u.start.x,y=u.end.y-u.start.y,p=Math.hypot(h,y),S=g>1&&p>0?p/(g-1):o>0?o:24;if(!Number.isFinite(S)||S<=0)continue;let I=p>0?Math.atan2(y,h)*180/Math.PI:0,b={x:u.start.x,y:u.start.y},w=0,v=S,m,x=u.seats?.length===g&&u.seats.every(A=>Number.isFinite(A.x)&&Number.isFinite(A.y))?u.seats:null;if(x&&u.table&&g>=3){let A=u.table.center,U=x.reduce((T,K)=>T+Math.hypot(K.x-A.x,K.y-A.y),0)/g,X=x.map(T=>Math.atan2(T.y-A.y,T.x-A.x)).sort((T,K)=>T-K),ce=0,qe=0;X.forEach((T,K)=>{let me=K+1<X.length?X[K+1]:X[0]+Math.PI*2;me-T>ce&&(ce=me-T,qe=(K+1)%X.length)});let O=ce>1.6*(Math.PI*2/g),k=O?(Math.PI*2-ce)*180/Math.PI:void 0;m={center:{...A},radius:Math.max(1,U-Wn),...k!==void 0?{seatArc:k}:{}},I=O?(X[qe]-ce/2)*180/Math.PI:X[0]*180/Math.PI,b={...A}}let C=[];if(x&&!m&&g>=3){C=ft(x,U=>J({origin:U.origin,rotation:U.rotation,curve:U.curve,seatCount:U.seatCount,seatSpacing:U.seatSpacing}));let A=C[0];b=A.origin,I=A.rotation,w=A.curve,v=A.seatSpacing}if(!Number.isFinite(v)||v<=0)continue;let _=t.sourceGroupId?Ce(`${t.sourceGroupId}:${f}`):void 0,F=_&&Ce(u.directSourceRowId)===_?_:void 0,B=F?Rr(u.directReviewedSuffix):void 0,z=t.sourceGroupId&&u.rowLabel?xe(u.rowLabel):"",P=t.sourceGroupId&&u.rowDisplayLabel?xe(u.rowDisplayLabel):"",V=!!t.sourceGroupId&&u.rowDisplayLabel==="";c.push({label:z?a(z,g):i(),displayLabel:P||(V?"":String(f+1)),origin:b,rotation:I,curve:w,seatCount:C[0]?.seatCount??g,seatSpacing:v,...m?{table:m}:{},...x&&!m?{measured:!0}:{},...F?{directSourceRowId:F}:{},...B?{directReviewedSuffix:B}:{}});for(let A of C.slice(1))c.push({label:i(),displayLabel:String(f+1),origin:A.origin,rotation:A.rotation,curve:A.curve,seatCount:A.seatCount,seatSpacing:A.seatSpacing,measured:!0});l+=g}return{skip:null,rows:c,seats:l}}function Xd(t,e,n){E(t,n.categoryKey);let o=R(t,n.floorId),i=e.assetId,a=n.sectionId?o.objects.find(b=>b.type==="section"&&b.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 b of e.sections){if(a&&b.sectionId!==a.id)continue;let w=n.categoryKeyForSection?.(b)??n.categoryKey;E(t,w),r.set(b,w)}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=Pr(o.objects,i,a.id).filter(w=>$(G(w),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(w=>w.id)}]}}let c=o.objects.filter(b=>an(b,i,a?.id)),l=Ca(c,e,a?.id),f=[],u=o.objects.filter(b=>an(b,i,a?.id)||_r(b,i,a?.id)?(f.push(b.id),!1):!0);o.objects.splice(0,o.objects.length,...u);let g=[],h=[],y=[],p=new Set,S=0,I=xa(t);for(let b of e.sections){if(a&&b.sectionId!==a.id)continue;let w=Ra(b,o.objects,i,e.seatPitch,I.ordinaryFor(b.name),I.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,...b.sectionId?{sectionId:b.sectionId}:{}},F=r.get(b)??n.categoryKey;if(C.table){x+=1,v.push({type:"table",id:M(t,"t",n.idFactory,p),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:F});continue}let B={type:"row",id:M(t,"r",n.idFactory,p),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:F,...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&&!b.sourceGroupId){let C=j(t).find(_=>_.id===o.floorId);Oa(t,m,C?.focalPoint??t.focalPoint,o.floorId,n.idFactory)}for(let C of v)y.push(C.id);g.push({sectionId:b.sectionId,name:b.name,seats:w.seats,rows:v.length}),S+=w.seats}return{floorId:o.floorId,assetId:i,createdRowIds:y,removedRowIds:f,totalSeats:S,perSection:g,skipped:h}}function Oa(t,e,n,o,i){let a=e.map(h=>J(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 p=a[y],S=p.map((b,w)=>{let v=p[Math.max(0,w-1)],m=p[Math.min(p.length-1,w+1)],x=Math.hypot(m.x-v.x,m.y-v.y);return x<=0?Math.hypot(b.x-s.x,b.y-s.y):Math.abs((b.x-s.x)*(-(m.y-v.y)/x)+(b.y-s.y)*((m.x-v.x)/x))}).sort((b,w)=>b-w),I=p.reduce((b,w)=>b+w.x,0)/p.length;return{row:h,depth:S[Math.floor(S.length/2)],along:I}}).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),f=l.length?l[Math.floor(l.length*.75)]:1/0,u=[],g=-1/0;for(let h of c)(!u.length||h.depth-g>f*.45)&&(u.push([]),g=h.depth),u[u.length-1].push(h.row);u.forEach((h,y)=>{let p=L(y);h.sort((S,I)=>{let b=J(S),w=J(I);return b.reduce((v,m)=>v+m.x,0)/b.length-w.reduce((v,m)=>v+m.x,0)/w.length});for(let S of h)S.displayLabel=p;h.length>=2&&h.length<=64&&dt(t,{floorId:o,rowIds:h.map(S=>S.id),boundaries:h.slice(1).map(()=>"break"),displayLabel:p,idFactory:i})})}function Ar(t,e,n={}){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(p=>o.objects.find(S=>(S.type==="table"||S.type==="booth")&&S.id===p)),r=i.filter((p,S)=>!a[S]);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(p=>p.type!==s))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[p,S,I]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(S)||S<1||S>I)throw new d("invalid_operation",`${p} must be a whole number from 1 to ${I}`);for(let[p,S]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(S)||S<30||S>2e3)throw new d("invalid_operation",`${p} must be from 30 to 2000 chart units`);let c=e.rows*e.columns;if(c<2)throw new d("invalid_operation","Choose at least two grid cells");let l=i.length*(c-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let f=a.reduce((p,S)=>p+(S.type==="table"?S.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(p=>p.objects):t.objects).reduce((p,S)=>p+(S.type==="row"||S.type==="table"?S.seatCount:S.type==="gaArea"?Math.max(0,Math.floor(S.capacity)):S.type==="booth"?1:0),0),h=f*(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(p=>!!p.referenceInventorySource).length*(c-1)}}}function Zd(t,e,n={}){return Ar(t,e,n).preview}function Qd(t,e,n={}){let{target:o,sources:i,preview:a}=Ar(t,e,n),r=new Set,s=new Set((t.floors?.length?t.floors.flatMap(u=>u.objects):t.objects).flatMap(u=>"label"in u&&u.label?[u.label]:[])),c=[],l=(u,g)=>{let h=Math.max(2,g),y=S=>{let I=`-${S}`;return`${u.slice(0,Math.max(1,80-I.length))}${I}`},p=y(h);for(;s.has(p);)p=y(++h);return s.add(p),p},f=1;for(let u=0;u<e.rows;u++)for(let g=0;g<e.columns;g++)if(!(u===0&&g===0)){f+=1;for(let h of i){let y=structuredClone(h);y.id=M(t,y.type,e.idFactory,r),y.label=l(h.label,f),y.center={x:h.center.x+g*e.stepX,y:h.center.y+u*e.stepY},delete y.referenceInventorySource,c.push(y)}}return o.objects.push(...c),{...a,createdIds:c.map(u=>u.id)}}function _a(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(He.map(t=>t.key));function ut(t){return`${t.rowId}:${t.index}`}function cf(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 Aa(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,je(t.glyph)||delete t.glyph;let n=Xn(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"&&Qn(e,t)}function ka(t){return Object.keys(t).every(e=>e==="index")}function kr(t,e,n){if(!n.length)throw new d("invalid_operation","At least one seat is required");let o=R(t,e),i=[],a=new Set,r=new Map;for(let s of n){let c=ut(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}),r.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:r}}function Mr(t,e){let n=kr(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&&E(t,e.patch.categoryKey),e.patch.glyph!=null&&!je(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:ut(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=le(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&&ie(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=[]),f=l.find(g=>g.index===a.index);f||(f={index:a.index},l.push(f));let u=f.viewFromSeatUrl;for(let g of o){let h=e.patch[g];if(g==="wheelchairSpaceType"&&h==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(y=>y!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(h==null)delete f[g];else if(g==="accessibility")f.accessibility=[...new Set(h)],delete f.accessible;else if(g==="commercial")f.commercial={...f.commercial,...h};else if(g==="labelStyle"){let y=_a(f.labelStyle,h);y?f.labelStyle=y:delete f.labelStyle}else Object.assign(f,{[g]:h})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==u&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${r+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${r+1}`),Aa(f,s),ka(f)&&(s.overrides=l.filter(g=>g!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(ut)}}function lf(t,e){let n=kr(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(ut)}}function gf(t,e){let n=R(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&&E(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:f,displayType:u,aisleSeats:g,...h}=e.patch,y=f===void 0?{}:{displayLabel:f},p=we(y,"Row"),S=u===void 0?void 0:Oo(u,"Row");if(r!==void 0&&ie(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&&Qe(h.labelPresentation,"Row"),g!=null&&!uo(g))throw new d("invalid_operation","Row aisleSeats must be one of start, end, both, none (or null to unmark)");let I=w=>JSON.stringify({origin:w.origin,rotation:w.rotation,curve:w.curve,seatCount:w.seatCount,seatSpacing:w.seatSpacing,path:w.path??null}),b=!1;for(let w of i){let v=JSON.stringify(w),m=I(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&&(b=!0),I(w)!==m&&(delete w.arcFanGeneration,delete w.rowBlockGeneration),r!==void 0){let C=JSON.stringify(w.labelPresentation??null),_=Ie(w.labelPresentation,r);_?w.labelPresentation=_:delete w.labelPresentation,JSON.stringify(w.labelPresentation??null)!==C&&(b=!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&&(b=!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&&(b=!0)}if(S!==void 0){let C=w.displayType;S?w.displayType=S:delete w.displayType,w.displayType!==C&&(b=!0)}if(g!==void 0){let C=w.aisleSeats;g===null?delete w.aisleSeats:w.aisleSeats=g,w.aisleSeats!==C&&(b=!0)}if(f!==void 0){let C=w.displayLabel;p?delete w.displayLabel:w.displayLabel=y.displayLabel,w.displayLabel!==C&&(b=!0)}}return{floorId:n.floorId,changed:b,rowIds:o}}var Ma=3;function ht(t){return(t%360+360)%360}function Fa(t){let e=t.rotation*te;return{x:Math.cos(e),y:Math.sin(e)}}function ja(t,e){let n=Math.abs(ht(t-e));return n>180&&(n=360-n),n}function Re(t,e,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y}function Fr(t){let e=0,n=0;for(let i of t){let a=2*i.rotation*te;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 Ea(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 jr(t,e){let n=Fr(t),o={x:-n.y,y:n.x},i=G(t[0]),a=t.map(c=>({row:c,coord:Re(G(c),i,o)})).sort((c,l)=>c.coord-l.coord),r=a[0].coord,s=!1;return a.forEach((c,l)=>{let f=r+l*e-c.coord;Math.abs(f)>1e-6&&(Ea(c.row,o.x*f,o.y*f),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Ta(t,e){let n={x:-e.y,y:e.x},o=G(t[0]),i=t.map(r=>Re(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 Da(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=J(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=ht(Math.atan2(a,i)/te)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function La(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 mf(t,e){let n=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(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=>ja(m.rotation,c.rotation)>Ma);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=Fa(c),u={x:-f.y,y:f.x},g=Math.max(8,c.seatSpacing*.6),h=r.find(m=>Math.abs(Re(m.origin,c.origin,u))>g);if(h){let m=Math.round(Math.abs(Re(h.origin,c.origin,u)));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)=>Re(m.origin,c.origin,f)-Re(x.origin,c.origin,f)),p=y.reduce((m,x)=>m+x.seatCount,0);if(p>300)throw new d("invalid_operation",`A merged row would have ${p} seats, over the 300-seat row limit. Merge fewer rows.`);let S=y[0];go(y,S);let I=[],b=0;for(let m of y){if(m.overrides)for(let x of m.overrides)I.push({...structuredClone(x),index:x.index+b});b+=m.seatCount}S.seatCount=p,S.curve=0,delete S.path,I.length?S.overrides=I:delete S.overrides,delete S.arcFanGeneration,delete S.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:S.id,removedRowIds:w,seatCount:p}}function Er(t,e){let n=R(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=J(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:M(t,"r",e.idFactory,new Set),label:La(n.objects,o.label),origin:{...r[a]},rotation:ht(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 f=[],u=[];if(o.overrides)for(let h of o.overrides)h.index<a?f.push(structuredClone(h)):u.push({...structuredClone(h),index:h.index-a});ho(o,o,l),o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,u.length&&(l.overrides=u);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 bf(t,e){let n=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=>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=jr(i,e.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:e.gap}}function pf(t,e){let n=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(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)Da(g);let l=Fr(r),f=ht(Math.atan2(l.y,l.x)/te);for(let g of r)g.rotation=f;let u=Ta(r,l);return jr(r,u),{floorId:n.floorId,changed:s()!==c,rowIds:o,gap:u}}function xf(t,e){let n=R(t,e.floorId).objects.find(c=>c.type==="row"&&c.id===e.rowId);if(n?.segmentedRow)throw new d("invalid_operation","This row already has parts: choose Aisle on the join between them.",{rowIds:[e.rowId]});let o=n?.displayLabel??n?.label,i=Er(t,e),a=dt(t,{floorId:i.floorId,rowIds:[i.rowId,i.newRowId],boundaries:["break"],...o?{displayLabel:o}:{},idFactory:e.idFactory}),{objects:r}=R(t,i.floorId),s=[i.rowId,i.newRowId].map(c=>r.find(l=>l.type==="row"&&l.id===c));return lt(s,1,"break"),{floorId:i.floorId,rowId:i.rowId,newRowId:i.newRowId,groupId:a.groupId}}import sn from"polygon-clipping";var Tr=100,Dr=512,cn=8192,Ur=64,Lr=1e7,N=1e-7;function Jr(t,e){return Math.abs(t.x-e.x)<=N&&Math.abs(t.y-e.y)<=N}function qr(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 Ke(t,e,n){let o=Y(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 Hr(t,e,n,o){let i=Y(t,e,n),a=Y(t,e,o),r=Y(n,o,t),s=Y(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&&Ke(n,t,e)||Math.abs(a)<=N&&Ke(o,t,e)||Math.abs(r)<=N&&Ke(t,n,o)||Math.abs(s)<=N&&Ke(e,n,o)}function Na(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)&&Hr(t[e],t[n],t[o],t[i]))return!0}}return!1}function Nr(t,e){return t.some((n,o)=>e.some((i,a)=>Hr(n,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function ln(t,e){return!e.some((n,o)=>Ke(t,n,e[(o+1)%e.length]))&&$(t,e,void 0)}function mt(t,e,n){let o=qr(t);if(o.length<3||o.length>Dr||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Lr||Math.abs(i.y)>Lr||Jr(i,o[(a+1)%o.length]))||Math.abs(Xe(o))<=N||Na(o))throw new d("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${Dr} finite vertices per ring.`,{gaAreaId:n,ring:e});return o}function Ga(t){let e=mt(t.points,"outline",t.id),n=t.holes??[];if(!Array.isArray(n)||n.length>Ur)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=n.map(i=>mt(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=>ln(s,e))||Nr(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(Nr(a,o[s])||ln(a[0],o[s])||ln(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 gt(t){return t.map(e=>[e.x,e.y])}function Gr(t){return qr(t.map(([e,n])=>({x:e,y:n})))}function Kr(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 Ka(t){return t.reduce((e,n)=>e+(Kr(n[0]??[])-n.slice(1).reduce((o,i)=>o+Kr(i),0)),0)}function dn(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(dn).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${dn(e[n])}`).join(",")}}`}function $r(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 Br(t){return dn({categoryKey:t.categoryKey,displayLabel:$r(t,"displayLabel",80),displayType:$r(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function zr(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 $a(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function Vr(t,e,n={}){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>Tr)throw new d("invalid_operation",`Join Areas supports at most ${Tr} areas at once`);let a=i.map(O=>o.objects.find(k=>k.type==="gaArea"&&k.id===O)),r=i.filter((O,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(O=>Me(O));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});E(t,s[0].categoryKey);let l=Br(s[0]),f=s.find(O=>Br(O)!==l);if(f)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[s[0].id,f.id]});let u=Fe(t).objectToSection,g=u.get(s[0].id)??"__ungrouped__",h=s.find(O=>(u.get(O.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,u.get(h.id)??"__ungrouped__"]});let y=s.reduce((O,k)=>{if(!Number.isInteger(k.capacity)||k.capacity<1||k.capacity>H)throw new d("invalid_operation",`GA area ${k.id} has invalid capacity`,{gaAreaId:k.id});return O+k.capacity},0);if(y>H)throw new d("invalid_operation",`Joined GA capacity would be ${y}, over the ${H}-unit area limit`,{capacity:y});let p=W(t).reduce((O,k)=>O+de(k),0),S=n.maxInventory??1e5;if(p>S)throw new d("invalid_operation",`Chart inventory exceeds the ${S}-unit publication limit`,{inventory:p});let I=s.map(Ga),b=I.reduce((O,k)=>O+k.outer.length+k.holes.reduce((T,K)=>T+K.length,0),0);if(b>cn)throw new d("invalid_operation",`Join Areas supports at most ${cn} source vertices`,{vertexCount:b});let w;try{let O=I.map(K=>[gt(K.outer)]);if(w=sn.union(O[0],...O.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=I.flatMap(K=>K.holes.map(me=>[gt(me)]));k.length&&(w=sn.difference(w,...k));let T=I.findIndex(K=>{let me=[gt(K.outer),...K.holes.map(gt)];return Ka(sn.intersection(me,w))<=N});if(T>=0)throw new d("invalid_operation",`GA area ${s[T].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:s[T].id})}catch(O){throw O instanceof d?O:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:O instanceof Error?O.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=Gr(w[0][0]),m=w[0].slice(1).map(Gr),x=v.length+m.reduce((O,k)=>O+k.length,0);if(m.length>Ur||x>cn)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:m.length,vertexCount:x});mt(v,"outline",s[0].id),m.forEach(O=>mt(O,"cutout",s[0].id));let C=new Map(o.objects.map((O,k)=>[O.id,k])),_=s.slice().sort((O,k)=>$a(zr(O,C.get(O.id)??Number.MAX_SAFE_INTEGER),zr(k,C.get(k.id)??Number.MAX_SAFE_INTEGER))),F=_[0],B=structuredClone(t),z=R(B,o.floorId),P=z.objects.find(O=>O.type==="gaArea"&&O.id===F.id);P.points=structuredClone(v),m.length?P.holes=structuredClone(m):delete P.holes;let V=new Set(_.slice(1).map(O=>O.id));for(let O=z.objects.length-1;O>=0;O-=1)V.has(z.objects[O].id)&&z.objects.splice(O,1);let A=Fe(B).objectToSection.get(F.id)??"__ungrouped__";if(A!==g)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:F.id,beforeSectionId:g,afterSectionId:A});let U=[],X=new Set;for(let O of _){if(!no(O))throw new d("invalid_operation",`GA area ${O.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:O.id});let k=ne(O);if(k.length!==O.capacity||k.some(T=>X.has(T)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:O.id});k.forEach(T=>X.add(T)),U.push(...oo(O))}if(U.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let ce=new Set(s.map(O=>O.id));for(let O of W(t).filter(k=>k.type==="gaArea"&&!ce.has(k.id))){let k=ne(O).find(T=>X.has(T));if(k)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:k,gaAreaId:O.id})}let qe=_.slice(1).map(O=>O.id);return{floorId:o.floorId,areaId:F.id,survivorLabel:F.label,removedAreaIds:qe,sourceAreaCount:_.length,capacity:y,inventorySegmentCount:U.length,outerVertexCount:v.length,holeCount:m.length,sectionId:g,points:v,...m.length?{holes:m}:{},segments:U}}function Mf(t,e,n={}){let{segments:o,...i}=Vr(t,e,n);return i}function Ff(t,e,n={}){let o=Vr(t,e,n),i=R(t,o.floorId),a=i.objects.find(f=>f.type==="gaArea"&&f.id===o.areaId);a.points=structuredClone(o.points),o.holes?.length?a.holes=structuredClone(o.holes):delete a.holes;let r=i.objects.filter(f=>f.type==="gaArea"&&(f.id===o.areaId||o.removedAreaIds.includes(f.id))).reduce((f,u)=>f+(u.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 f=i.objects.length-1;f>=0;f-=1)s.has(i.objects[f].id)&&i.objects.splice(f,1);let{segments:c,...l}=o;return{...l,changed:!0}}function Bf(t,e){let n=R(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,ke(o),{floorId:n.floorId,changed:!0,shapeId:o.id}}function zf(t,e){let n=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=>n.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 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(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(r.labelStyle.size!==void 0&&r.labelStyle.size!==null&&(!Number.isFinite(r.labelStyle.size)||r.labelStyle.size<Ct||r.labelStyle.size>72))throw new d("invalid_operation",`Stage label size must be from ${Ct} 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&&!In.includes(r.labelStyle.direction))throw new d("invalid_operation","Stage label direction must be horizontal, vertical, or auto");for(let f of["bold","italic","underline"]){let u=r.labelStyle[f];if(u!=null&&typeof u!="boolean")throw new d("invalid_operation",`Stage label ${f} 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=ae("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(u=>!Number.isFinite(u)||u<-100||u>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(u=>Math.abs(u)>.5)||(r.edgeCurvature=null)}let f={kind:"polygon",points:l.points,edgeCurvature:r.edgeCurvature??void 0,holes:l.holes};Nn(f).forEach((u,g)=>{if(!Gn(f,u))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(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");r.eventConfigurationIds=l}if(r.lineCap!==void 0&&r.lineCap!==null&&!po.includes(r.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!yo.includes(r.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,f]of[["startEnding",r.startEnding],["endEnding",r.endEnding]])if(f!=null&&!wo.includes(f))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(f=>!Dt(r.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(r.label===null?delete l.label:r.label!==void 0&&(l.label=r.label),r.labelStyle!==void 0){let u={...l.labelStyle};r.labelStyle.size===null?delete u.size:r.labelStyle.size!==void 0&&(u.size=r.labelStyle.size),r.labelStyle.color===null?delete u.color:r.labelStyle.color!==void 0&&(u.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete u.fontFamily:r.labelStyle.fontFamily!==void 0&&(u.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete u.bold:r.labelStyle.bold!==void 0&&(u.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete u.italic:r.labelStyle.italic===!0&&(u.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete u.underline:r.labelStyle.underline===!0&&(u.underline=!0),r.labelStyle.direction===null||r.labelStyle.direction==="horizontal"?delete u.direction:r.labelStyle.direction!==void 0&&(u.direction=r.labelStyle.direction),Object.keys(u).length?l.labelStyle=u: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,Dt(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 u=Math.min(l.width??1/0,l.height??1/0),g=Number.isFinite(u)?u/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,g)):r.cornerRadius}JSON.stringify(l)!==f&&(ke(l),c=!0)}return{floorId:n.floorId,changed:c,shapeIds:o}}function Xr(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 n=e.map(f=>f.x),o=e.map(f=>f.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 Uf(t,e){let n=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(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"?Xr(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(S=>!Number.isFinite(S.x)||!Number.isFinite(S.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=l.map(S=>S.x),u=l.map(S=>S.y),g=Math.min(...f),h=Math.max(...f),y=Math.min(...u),p=Math.max(...u);return{cx:(g+h)/2,cy:(y+p)/2,width:Math.max(1,h-g),height:Math.max(1,p-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,f=s.height/c.height,u=g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*f});r.points=(r.points??[]).map(u),r.holes&&(r.holes=r.holes.map(g=>g.map(u))),(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 Jf(t,e){let n=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(Un.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:Xr(c)}}),r=!1;for(let s of a)s.box&&(s.shape.points=qn({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 Wf(t){return[...gn(t)].map(([e,n])=>({key:e,...n}))}function za(t){if(!Array.isArray(t))return gn(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 gn(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let n of j(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 bt(t){return Array.isArray(t)?t.map(bt):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[n])=>e.localeCompare(n)).map(([e,n])=>[e,bt(n)]))}function Ua(t,e){return JSON.stringify(bt(t))===JSON.stringify(bt(e))}function fn(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function Ja(t){return t?t.status==="retracted"?"retract":fn(t)?"approve":"set":"clear"}function qa(t,e){let n=za(t),o=gn(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&&Ua(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:Ja(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function Yf(t,e){return qa(t,e).some(n=>fn(n.before)||fn(n.after))}var Ha=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Va=new Set(["generated","geometry-verified","configuration-verified"]),Xa=new Set(["none","comparable-build-reference","actual-build-checked"]),Wa=new Set(["clear","partial","obstructed"]);function un(t){return t.toISOString().slice(0,10)}function hn(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function _e(t,e,n){if(!hn(t,e))throw new d("invalid_operation",`Confidence evidence ${n} is invalid`,{field:n});return t}function Oe(t,e,n){if(t!==void 0)return _e(t,e,n)}function pt(t,e,n){let o=n?[R(t,n)]:j(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 Wr(t,e){let n=j(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 $e(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return Wr(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=pt(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=pt(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 yt(t,e,n){if(e.scope==="venue")return n?t.confidenceEvidence=n:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=Wr(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=pt(t,e.objectId,e.floorId);return Mr(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=pt(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 Ya(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!hn(t.label,80)||!hn(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(!Wa.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(n=>_e(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 Za(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(!Ha.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!Va.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let n=t.realityLevel??"none";if(!Xa.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=Oe(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(u=>_e(u,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=Oe(t.assessedAt,40,"assessedAt")??un(e),r=Date.parse(a);if(!Number.isFinite(r))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=Oe(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:un(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=Oe(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!l)throw new d("invalid_operation","Verified model levels require approvedByRole");let f=Oe(t.sourceLabel,120,"sourceLabel");if(n!=="none"&&!f)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:_e(t.evidenceId,120,"evidenceId"),modelVersion:_e(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}:{},...f?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:Ya(t.modeledTarget)}:{}}}function Pe(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 Zf(t,e){let n=Za(e.evidence,e.now),o=JSON.stringify($e(t,e)??null),i=yt(t,e,n),a=JSON.stringify($e(t,e)??null);return Pe(e,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function Qf(t,e){let n=$e(t,e);if(!n)return Pe(e,{changed:!1});let o=yt(t,e,void 0);return Pe(e,{changed:!0,...o,evidenceId:n.evidenceId})}function eu(t,e){let n=$e(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=_e(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=Oe(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:un(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=yt(t,e,r);return Pe(e,{changed:c!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function tu(t,e){let n=$e(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 Pe(e,{changed:!1,evidenceId:n.evidenceId,status:"retracted"});let o={...n,status:"retracted"};delete o.basisSha256;let i=yt(t,e,o);return Pe(e,{changed:!0,...i,evidenceId:n.evidenceId,status:"retracted"})}var Qa={width:960,height:600};function es(t,e,n=t){let o={...t,objects:e,floors:void 0,referenceImage:void 0,backgroundImage:eo(n)},i=ee(o,{freeText:"exclude"}),{width:a,height:r}=Qa;return Math.min(a/Math.max(i.width,1e-6),r/Math.max(i.height,1e-6))}function ts(t,e){return!t.text.trim()||t.semanticKind==="icon"||t.labelImportance==="detail"||Zn(t)?!1:!lo(t.fontSize,e)}function Yr(t){let e=[],n=!!t.floors?.length;for(let o of j(t)){let i=o.objects.filter(r=>r.type==="text");if(!i.length)continue;let a=es(t,o.objects,n?o:t);for(let r of i)ts(r,a)&&e.push({floorId:o.id,text:r,renderedPx:r.fontSize*a})}return e}var wt=40,Zr=96,ns=48,ue=24;function Be(t,e){let n=ee({...t,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"});return{x:n.x+wt,y:n.y+wt,width:Math.max(0,n.width-2*wt),height:Math.max(0,n.height-2*wt)}}function os(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 rs(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}var mn=t=>t.type==="shape"&&t.role==="stage";function is(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 as(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 bn(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 It(t,e){let n=oe(t,e.floorId),o=os(n.objects.filter(mn).map(b=>Be(n,b)));if(!o)return null;let i=is(o,n.focalPoint),a=i.dy!==0?e.height:e.width,r=as(o,i),s=n.objects.filter(b=>!mn(b)&&rs(b)).map(b=>Be(n,b)).filter(b=>bn(b,i)>=r-1),c=s.length?Math.min(...s.map(b=>bn(b,i))):1/0,l=Zr+a+ns,f=c-r,u=()=>{let b=r+Zr+a/2;return i.dy!==0?{x:o.x+o.width/2,y:i.dy*b}:{x:i.dx*b,y:o.y+o.height/2}};if(!s.length)return{center:u(),movedBack:0};if(f>=a+2*ue){let b=r+f/2;return{center:i.dy!==0?{x:o.x+o.width/2,y:i.dy*b}:{x:i.dx*b,y:o.y+o.height/2},movedBack:0}}if(e.makeRoom){let b=l-f,w=R(t,e.floorId);for(let v of w.objects)mn(v)||bn(Be(n,v),i)<r-1||se(v,i.dx*b,i.dy*b);return{center:u(),movedBack:b}}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,p=o.x+o.width/2,S=o.y+o.height/2;if(i.dy!==0){let b=i.dy===1?Math.min(S,c-ue-y/2):Math.max(S,-c+ue+y/2);return{center:{x:o.x-ue-h/2,y:b},note:g,movedBack:0}}return{center:{x:i.dx===1?Math.min(p,c-ue-h/2):Math.max(p,-c+ue+h/2),y:o.y-ue-y/2},note:g,movedBack:0}}var ss=40,ze=24;function cs(t,e,n){let{objects:o}=R(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 Ue(t,e){if(!e.nearObjectId&&e.placement==="front"){let n=It(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:Qr(t,e)}}function Su(t,e){return Ue(t,e).center}function Qr(t,e){if(e.nearObjectId){let n=cs(t,e.floorId,e.nearObjectId),o=Be(oe(t,e.floorId),n),i=e.side??"rear";return i==="front"?{x:o.x+o.width/2,y:o.y-ze-e.height/2}:i==="left"?{x:o.x-ze-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+ze+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+ze+e.height/2}}if(e.placement==="center"){let n=ee(oe(t,e.floorId),{freeText:"exclude"});return{x:n.x+n.width/2,y:n.y+n.height/2}}return ve(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}function St(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*ss}function pn(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 ls(t){return t.some(e=>e.type==="shape"&&e.role==="stage")}function vu(t,e){let n=R(t,e.floorId),o=Jn(e.kind),i=St(e.widthM,"widthM",o.width),a=St(e.depthM,"depthM",o.height),r=Qr(t,{...e,placement:e.placement??"front",width:i,height:a}),s=pn(e.label,"label")??Vn(e.kind),c=M(t,"stage",e.idFactory,new Set),l={...Hn({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},f=ls(n.objects);if(n.objects.push(l),!f){let u={x:r.x,y:r.y+a/2+ze},g=j(t).find(h=>h.id===n.floorId);t.floors?.length&&g&&(g.focalPoint=u),(!t.floors?.length||t.floors[0]?.id===n.floorId)&&(t.focalPoint=u)}return{floorId:n.floorId,stageId:c,label:s,focalPointMoved:!f,createdIds:[c]}}function xu(t,e){let n=Le(e.role);if(!n)throw new d("invalid_operation",`Unknown landmark: ${e.role}`);let o=R(t,e.floorId),{center:i,note:a}=Ue(t,{...e,width:n.width,height:n.height}),r=M(t,"decor",e.idFactory,new Set),s=$o(e.role,i,r),c=pn(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 ds={small:16,medium:24,large:36};function vt(t){if(t==="always")return"orientation";if(t==="close-up")return"detail"}var fs="#f7f8fb";function us(t){let e=t.theme?.background??fs,n=t.theme?.textColor;return n&&ao(n,e)>=4.5?n:so(e,"#0b1220","#e8ecf4")}function Cu(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=R(t,e.floorId),i=ds[e.size??"medium"],a=Math.max(i,n.length*i*.56),r=i*1.2,{center:s,note:c}=Ue(t,{...e,width:a,height:r}),l=M(t,"txt",e.idFactory,new Set),f={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"):us(t),...e.bold?{bold:!0}:{},...vt(e.showAt)?{labelImportance:vt(e.showAt)}:{}};o.objects.push(f);let u=e.showAt===void 0&&Yr(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,u].filter(Boolean).join(" ");return{floorId:o.floorId,textId:l,createdIds:[l],...g?{note:g}:{}}}function Ru(t,e){let n=mo(e.iconKey);if(!n)throw new d("invalid_operation",`Unknown icon: ${e.iconKey}`);let o=R(t,e.floorId),i=28,{center:a,note:r}=Ue(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,...vt(e.showAt)?{labelImportance:vt(e.showAt)}:{}};return o.objects.push(c),{floorId:o.floorId,iconId:s,createdIds:[s],...r?{note:r}:{}}}var hs="#4b5568";function Ou(t,e){let n=pn(e.label,"label"),o=R(t,e.floorId),i=St(e.widthM,"widthM",0),a=St(e.depthM,"depthM",0),{center:r,note:s}=Ue(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"):hs,...n?{label:n}:{},...e.shape!=="ellipse"?{cornerRadius:8}:{}};return o.objects.push(l),{floorId:o.floorId,areaId:c,createdIds:[c],...s?{note:s}:{}}}function _u(){return["bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"].map(t=>({role:t,label:Le(t)?.label??t}))}var gs=100,ms=300,Au=gs*ms;function ei(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 Je(t,e){if(e.placement==="front"){let n=It(t,e);if(n)return n.note?{center:n.center,note:n.note}:{center:n.center}}return{center:ve(t,{floorId:e.floorId,width:e.width,height:e.height,placement:e.placement??"auto"})}}var bs={straight:0,gentle:15,medium:30,strong:45},ps=24,ys=28,ws=48;function Gu(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=I=>e.blockSeats?.[I]??e.seatsPerRow,i=I=>Math.max(24,(I-1)*ps),a=i(e.seatsPerRow),r=Math.max(28,(e.rowCount-1)*ys),s=e.aisleWidth??ws,c=e.placement??"auto",l=bs[e.curveStyle??"straight"],f={floorId:"",rowIds:[],sectionIds:[],createdIds:[]},u=(I,b,w)=>{let v=gr(t,{floorId:e.floorId,origin:I,rowCount:e.rowCount,seatsPerRow:o(w),categoryKey:e.categoryKey,curve:l,...e.blockStyle?{style:e.blockStyle}:{},rotation:b,sectionLabel:e.sectionLabels?.[w],idFactory:e.idFactory});f.floorId=v.floorId,f.rowIds.push(...v.rowIds),v.sectionId&&f.sectionIds.push(v.sectionId),f.createdIds.push(...v.createdIds)};if(n===1&&c==="front"){let I=Je(t,{floorId:e.floorId,width:a,height:r,placement:c,makeRoom:e.makeRoom});return I.note&&(f.note=I.note),u({x:I.center.x-a/2,y:I.center.y-r/2},0,0),f}if(n===1){let I=ve(t,{floorId:e.floorId,width:a,height:r,placement:c}),b=ei(I,t.focalPoint,e.orientation??"horizontal"),w=b*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=b===0?I:ve(t,{floorId:e.floorId,width:v,height:m,placement:c});return u({x:x.x-a/2,y:x.y-r/2},b,0),f}let g=Array.from({length:n},(I,b)=>i(o(b))),h=g.reduce((I,b)=>I+b,0)+(n-1)*s,y=Je(t,{floorId:e.floorId,width:h,height:r,placement:c,makeRoom:e.makeRoom});y.note&&(f.note=y.note);let p=y.center,S=p.x-h/2;for(let I=0;I<n;I+=1)u({x:S,y:p.y-r/2},0,I),S+=g[I]+s;return f}function Ku(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 Is=155,Ss=150,ti=110;function $u(t,e){let n=(e.tableColumns-1)*Is+ti,o=(e.tableRows-1)*Ss+ti,{center:i,note:a}=Je(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=pr(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 Bu(t,e){let n=Qt(e.capacity),{center:o,note:i}=Je(t,{floorId:e.floorId,...n,placement:e.placement,makeRoom:e.makeRoom}),a=br(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 vs=88,xs=82,Cs=62,Rs=52;function zu(t,e){let n=(e.boothColumns-1)*vs+Cs,o=(e.boothRows-1)*xs+Rs,{center:i,note:a}=Je(t,{floorId:e.floorId,width:n,height:o,placement:e.placement,makeRoom:e.makeRoom}),r=yr(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 Os=40,he=30,ge=42,re=48,_s={none:[1],center:[1,1],two:[1,2,1]},Ps=6;function oi(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"||t.type==="section"}function yn(t,e){return ee({...t,floors:void 0,objects:[e],backgroundImage:void 0,referenceImage:void 0},{freeText:"include"})}function As(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 ks(t,e,n,o="front"){let i=j(t),a=e?i.find(I=>I.id===e):i[0];if(!a)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});let r=a.focalPoint??t.focalPoint,s=a.objects.filter(oi),c=0;if(s.length){let I=0,b=0;for(let w of s){let v=yn(t,w);I+=v.x+v.width/2-r.x,b+=v.y+v.height/2-r.y}Math.hypot(I,b)>1&&(c=Math.atan2(I,b)*180/Math.PI)}let l=o==="behind";l&&(c=(c+360)%360-180);let f=n/2,u={x:Math.sin(c*Math.PI/180),y:Math.cos(c*Math.PI/180)},g=0,h=[],y=s.some(I=>I.type==="row"),p=l?a.objects.filter(I=>I.type==="shape"&&I.role==="stage"):[];for(let I of[...s,...p]){if(I.type==="section"&&y)continue;let b=I.type==="row"?J(I):As(yn(t,I)),w=I.type==="row"?I.seatSpacing/2:0;for(let v of b){let m=v.x-r.x,x=v.y-r.y,C=Math.atan2(m,x)*180/Math.PI;if(Math.abs((C-c+540)%360-180)>f+10)continue;let F=Math.hypot(m,x)+w;g=Math.max(g,F),h.push({radius:F,depth:m*u.x+x*u.y+w})}}let S=I=>{let b=Math.cos(I/2*Math.PI/180);return b<.2||!h.length?0:(Math.max(...h.map(w=>w.depth))+ge)/b};return{center:r,bearing:c,occupiedRadius:g,floorId:a.id,clearRadius:S}}var ri=100,wn=180;function ni(t,e){return t===void 0||e<=0?ri:Math.min(wn,Math.max(20,Math.round(t/e*(180/Math.PI))))}function Ms(t,e){let n=e==="two"?2:e==="center"?1:0;return t*he+n*re}function Fs(t,e,n,o){let i=[],a=o+ge-e.occupiedRadius;if(e.occupiedRadius<=0||a<=0)return i;let r=n/2+10;for(let s of R(t,e.floorId).objects){if(oi(s)||s.type==="shape"&&s.role==="stage")continue;let c=yn(t,s),l=c.x+c.width/2-e.center.x,f=c.y+c.height/2-e.center.y,u=Math.hypot(l,f);if(u<=e.occupiedRadius)continue;let g=Math.atan2(l,f)*180/Math.PI;Math.abs((g-e.bearing+540)%360-180)>r||(se(s,l/u*a,f/u*a),i.push(s.id))}return i}function Uu(t,e){let n=e.sectionLabels&&e.sectionLabels.length>1?e.sectionLabels:void 0;if(e.seatsPerRowByRow&&e.seatsPerRowByRow.length!==e.rowCount)throw new d("invalid_operation","Give one seat count per curved row");let o=v=>e.seatsPerRowByRow?.[v]??e.seatsPerRow,i=v=>n?n.length*v*he+(n.length-1)*re:Ms(v,e.aisles),a=v=>{if(n)return n.length*(v-1)*he+(n.length-1)*re;let m=_s[e.aisles??"none"],x=m.reduce((_,F)=>_+F,0),C=Xt(m,v);return Math.max(...C.map((_,F)=>(_-1)*he*x/m[F]))+(m.length-1)*re},r=e.spreadDegrees===void 0?a:i,s=o(0),c=ks(t,e.floorId,e.spreadDegrees??ri,e.stageSide),l=Math.max((e.firstRowDistanceM??4)*Os,c.occupiedRadius>0?c.occupiedRadius+ge+re:0),f=e.spreadDegrees??ni(s===void 0?void 0:r(s),l),u=e.spreadDegrees??(s!==void 0&&f>=wn?wn:void 0),g=u!==void 0&&s!==void 0?Math.max(...Array.from({length:e.seatsPerRowByRow?e.rowCount:1},(v,m)=>r(o(m))/(u*Math.PI/180)-m*ge)):0,h=Math.max(l,g,c.clearRadius(f)),y=e.spreadDegrees??ni(s===void 0?void 0:r(s),h),p=h+(e.rowCount-1)*ge,S=Fs(t,c,y,p),I=e.spreadDegrees===void 0&&e.rowCount>1?o(e.rowCount-1):void 0,b=(v,m)=>{let x=m/p*(180/Math.PI);return Math.max(-120,Math.min(120,(v-Math.max(x,Ps))/2))};if(n){let v=I===void 0?void 0:(I-1)*he;return{...js(t,e,n,c,h,y,s,m=>v===void 0?0:b(m,v)),spreadDegrees:y,movedBackIds:S}}return{...Wt(t,{floorId:c.floorId,center:c.center,innerRadius:h,rowCount:e.rowCount,rowGap:ge,startAngle:c.bearing-y/2,endAngle:c.bearing+y/2,seatPitch:he,fit:s===void 0?"seat-pitch":"fixed-count",...s===void 0?{}:{seatsPerRow:s},...e.seatsPerRowByRow?{seatsPerRowByRow:e.seatsPerRowByRow}:{},...I===void 0?{}:{taperDegrees:b(y,a(I))},facing:"inward",...e.aisles==="center"?{aisleGaps:{center:re}}:e.aisles==="two"?{aisleGaps:{left:re,right:re}}:{},categoryKey:e.categoryKey,...e.sectionLabel===void 0?{}:{sectionLabel:e.sectionLabel},idFactory:e.idFactory}),spreadDegrees:y,movedBackIds:S}}function js(t,e,n,o,i,a,r,s){let c=re/i*(180/Math.PI),l=a>=359,f=(a-(l?n.length:n.length-1)*c)/n.length;if(f<5)throw new d("invalid_operation",`${n.length} sections do not fit in ${Math.round(a)}\xB0; widen the fan or use fewer sections`);let u=o.bearing-a/2+(l?c/2:0),g=n.map((h,y)=>Wt(t,{floorId:o.floorId,center:o.center,innerRadius:i,rowCount:e.rowCount,rowGap:ge,startAngle:u+y*(f+c),endAngle:u+y*(f+c)+f,seatPitch:he,fit:r===void 0?"seat-pitch":"fixed-count",...r===void 0?{}:{seatsPerRow:r},...e.seatsPerRowByRow?{seatsPerRowByRow:e.seatsPerRowByRow}:{},...s(f)===0?{}:{taperDegrees:s(f)},facing:"inward",categoryKey:e.categoryKey,sectionLabel:h,idFactory:e.idFactory}));return{floorId:o.floorId,rowIds:g.flatMap(h=>h.rowIds),sectionId:g[0].sectionId,sectionIds:g.map(h=>h.sectionId).filter(h=>h!==null),groupId:g[0].groupId,logicalRowCount:e.rowCount,rowSegmentCount:g.reduce((h,y)=>h+y.rowSegmentCount,0),totalSeats:g.reduce((h,y)=>h+y.totalSeats,0),innerRadius:i,outerRadius:g[0].outerRadius,minSeatSpacing:Math.min(...g.map(h=>h.minSeatSpacing)),maxSeatSpacing:Math.max(...g.map(h=>h.maxSeatSpacing)),maxPitchDeviation:Math.max(...g.map(h=>h.maxPitchDeviation)),aisleCount:n.length-(l?0:1),warnings:[...new Set(g.flatMap(h=>h.warnings))]}}export{sa as AISLE_EMPTY_SEATS,Et as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,ss as DECOR_UNITS_PER_METRE,zs as DEFAULT_FLOOR_HEIGHT_STEP_M,qo as DEFAULT_ROUTE_NAME,ii as DEFAULT_SECTION_CORNER_SMOOTHING,Ti as FIRST_CATEGORY_COLOURS,Es as MAX_BUYER_IMAGE_URL_LENGTH,Bs as MAX_FLOOR_BASE_HEIGHT_M,hs as NAMED_AREA_FILL,Jo as ROUTE_STROKE,bs as ROW_CURVE_DEGREES,Wt as addArcFanRows,Ou as addArea,Qd as addBookableGridArray,yr as addBoothArray,Hl as addChartCategories,qt as addChartCategory,Us as addChartFloor,Ys as addChartZone,Uu as addCurvedRows,br as addGAArea,Cc as addGate,Ru as addIcon,xu as addLandmark,zu as addPlacedBoothArray,Bu as addPlacedGAArea,Gu as addPlacedRowBlocks,$u as addPlacedTableArray,Ac as addRoute,xf as addRowAisle,gr as addRowBlock,vu as addStage,pr as addTableArray,Cu as addText,Xt as allocateFixedArcFanSeats,cl as applyPolygonHole,Xd as applyReferenceScanRows,xl as applySectionCornerSmoothing,Pl as applySectionEstimates,ki as applySectionOutlineShaping,sl as applySectionRowFit,eu as approveConfidenceEvidence,na as arcFanInputForGroup,wl as assignSectionInventoryCategory,ve as automaticPlacementCenter,Ku as blockSectionLabels,Qf as clearConfidenceEvidence,Ks as compactChartDoc,Ns as compactRowOverrides,Gs as compactTableOverrides,Yf as confidenceEvidenceChangeRequiresPublish,qa as confidenceEvidenceChanges,Wf as confidenceEvidenceIndex,$l as confirmReferenceCategoryOutputColor,Il as convertGeneratedSectionToPolygon,Bf as convertShapeToOutline,Yo as countCoveredInventory,ks as curvedRowsPlacement,Ue as decorPlacement,Su as decorPlacementCenter,Ls as detectSeatLabelRun,Qn as dropRedundantSeatOverrideFields,Ui as familyCategoryLabel,lt as fitSegmentedRowJoin,Qt as gaAreaFootprint,bi as gateShape,dt as groupRowsAsSegmented,Zc as insertSeatingBlock,Ts as isSafeBuyerImageUrl,Ff as joinGAAreas,_u as landmarkRoles,Oc as makeGate,mf as mergeRows,et as mirrorFirstFloor,le as normalizeBuyerImageUrl,Za as normalizeDraftEvidence,cf as parseSeatRefId,Ei as pickColorblindSafeCategoryColor,Hi as planCreationCategory,cr as previewArcFanRows,Zd as previewBookableGridArray,_i as previewGeneratedSectionPolygonConversion,Mf as previewJoinGAAreas,Ut as previewPolygonHole,Ci as previewRemovePolygonHole,wi as previewRowCubicPath,vi as previewSectionRowFit,Kl as reassignColorblindSafeCategoryColors,Yc as relabelChartRows,Wo as releaseGateReferences,Pc as remapGateReferences,Vl as removeCategoryMovingInventory,ir as removeChartCategory,Hs as removeChartFloor,Xc as removeChartObjects,Qs as removeChartZone,ll as removePolygonHole,Js as renameChartFloor,Nl as renameDirectSeatImportCategory,Gl as reorderChartCategories,ld as replaceArcFanRows,kd as replaceRowBlock,lf as resetSeatOverrides,Uf as resizeShapes,Bl as resolveCreationCategory,tu as retractConfidenceEvidence,$s as roundBuyerCoordinates,pi as routeShape,ut as seatRefId,Ds as seatSemanticsSignature,Oi as sectionInventorySelectionSummary,Id as segmentedRowAisleTooNarrow,Zf as setConfidenceEvidence,_c as setObjectEntrance,kc as setRoute,bf as setRowBlockSpacing,Er as splitRow,pf as straightenAndSpaceRows,Sl as transformSectionBoundary,Pi as transformSectionBoundaryObject,Pd as ungroupSegmentedRow,Wi as uniqueCategoryLabel,Hc as updateBooths,Jt as updateCategoryDefinitions,qs as updateChartFloorBaseHeight,nd as updateChartTheme,Zs as updateChartZones,Vc as updateGAAreas,Rc as updateGate,al as updateRowCubicPath,gf as updateRows,Mr as updateSeatOverrides,vl as updateSectionExactPath,or as updateSectionMetadata,Ad as updateSegmentedRow,zf as updateShapes,Jf as updateStageKinds,qc as updateTables,Wc as updateTextObjects,od as updateViewFromSeatFallback};