@seatlayer/core 0.58.0 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/ar-H46G25IW.js +1 -0
  2. package/dist/be-X2N4CNF6.js +1 -0
  3. package/dist/bg-WAFRHN4U.js +1 -0
  4. package/dist/ca-KJY6UBX2.js +1 -0
  5. package/dist/{categoryInventory-BwarniiK.d.ts → categoryInventory-B-0p5PBr.d.ts} +1 -1
  6. package/dist/{categoryInventory-D3qPwfKz.d.cts → categoryInventory-DjFHXtp6.d.cts} +1 -1
  7. package/dist/{chunk-4BVXDBFE.js → chunk-ATFAQDPR.js} +1 -1
  8. package/dist/chunk-CNCFI5RT.js +1 -0
  9. package/dist/chunk-FOYQOIWG.js +1 -0
  10. package/dist/{chunk-66HGMU7D.js → chunk-IZTHA3X2.js} +1 -1
  11. package/dist/{chunk-N4CBOQFB.js → chunk-P2NJ6UO6.js} +1 -1
  12. package/dist/chunk-T2LWVOQ3.js +1 -0
  13. package/dist/{chunk-6XJN4REG.js → chunk-VI3IZS2B.js} +1 -1
  14. package/dist/{chunk-IRFG5DVH.js → chunk-VOJMGPDK.js} +1 -1
  15. package/dist/{chunk-PMU3VPNK.js → chunk-XU73MULJ.js} +1 -1
  16. package/dist/core/cdnAsset.cjs +1 -0
  17. package/dist/core/cdnAsset.d.cts +35 -0
  18. package/dist/core/cdnAsset.d.ts +35 -0
  19. package/dist/core/cdnAsset.js +1 -0
  20. package/dist/core/chart-ops/index.cjs +1 -1
  21. package/dist/core/chart-ops/index.d.cts +5 -5
  22. package/dist/core/chart-ops/index.d.ts +5 -5
  23. package/dist/core/chart-ops/index.js +1 -1
  24. package/dist/core/inventory/index.cjs +1 -1
  25. package/dist/core/inventory/index.d.cts +4 -4
  26. package/dist/core/inventory/index.d.ts +4 -4
  27. package/dist/core/inventory/index.js +1 -1
  28. package/dist/core/layout/index.cjs +1 -1
  29. package/dist/core/layout/index.d.cts +4 -4
  30. package/dist/core/layout/index.d.ts +4 -4
  31. package/dist/core/layout/index.js +1 -1
  32. package/dist/core/quality/index.d.cts +3 -3
  33. package/dist/core/quality/index.d.ts +3 -3
  34. package/dist/core/render-assets/index.d.cts +1 -1
  35. package/dist/core/render-assets/index.d.ts +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.cjs +1 -1
  39. package/dist/core/sections/index.d.cts +5 -5
  40. package/dist/core/sections/index.d.ts +5 -5
  41. package/dist/core/sections/index.js +1 -1
  42. package/dist/cs-6DGE2CXL.js +1 -0
  43. package/dist/cy-IN3H2JGF.js +1 -0
  44. package/dist/da-CW77LCG4.js +1 -0
  45. package/dist/{de-JS2HQ675.js → de-BTL7PM4X.js} +1 -1
  46. package/dist/el-TWE62U4P.js +1 -0
  47. package/dist/es-EJCQGGF7.js +1 -0
  48. package/dist/et-UQ6VFRG2.js +1 -0
  49. package/dist/fa-A5636YDV.js +1 -0
  50. package/dist/fi-6YNSAFLB.js +1 -0
  51. package/dist/fr-TGUAIAOM.js +1 -0
  52. package/dist/he-PAFZSFIR.js +1 -0
  53. package/dist/hr-SIQR4W7D.js +1 -0
  54. package/dist/hu-YBOAMZ2D.js +1 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.d.cts +125 -41
  57. package/dist/index.d.ts +125 -41
  58. package/dist/index.js +1 -1
  59. package/dist/it-KCSKVAKE.js +1 -0
  60. package/dist/ja-4454OUK5.js +1 -0
  61. package/dist/ku-JPB5LQ72.js +1 -0
  62. package/dist/{labeling-BmCzW50y.d.ts → labeling-BPCTQfDG.d.ts} +1 -1
  63. package/dist/{labeling-VfJBEOn0.d.cts → labeling-iVwhgoip.d.cts} +1 -1
  64. package/dist/{layout-ClQkmixY.d.ts → layout-D-R46h1m.d.ts} +40 -4
  65. package/dist/{layout-Dlv5bIf2.d.cts → layout-Vk2ZGdMS.d.cts} +40 -4
  66. package/dist/localeLoaders-KUIWB7O3.js +1 -0
  67. package/dist/lt-54TNW6YF.js +1 -0
  68. package/dist/lv-TJ75JL4U.js +1 -0
  69. package/dist/nl-B67UFSMM.js +1 -0
  70. package/dist/no-6JQSRSCX.js +1 -0
  71. package/dist/pl-MKZX6GFZ.js +1 -0
  72. package/dist/pt-F2GLS7QA.js +1 -0
  73. package/dist/{renderedQuality-B3jgdgPO.d.ts → renderedQuality-CsXNQCCH.d.ts} +1 -1
  74. package/dist/{renderedQuality-bDkUOyBL.d.cts → renderedQuality-h9RvUWMo.d.cts} +1 -1
  75. package/dist/{renderer-B_g-W_QB.d.ts → renderer-Bo9JzqMA.d.ts} +46 -8
  76. package/dist/{renderer-DySMcKAR.d.cts → renderer-QnB3a1yh.d.cts} +46 -8
  77. package/dist/ro-2WKWAK7S.js +1 -0
  78. package/dist/ru-I7I76LMP.js +1 -0
  79. package/dist/{sections-DIzgtDjF.d.ts → sections-9_Ka3i-z.d.ts} +1 -1
  80. package/dist/{sections-Dna1nZgR.d.cts → sections-Dmjtj1BQ.d.cts} +1 -1
  81. package/dist/{segmentedRowModel-COXw4GCh.d.ts → segmentedRowModel-CO6Jogaa.d.ts} +1 -1
  82. package/dist/{segmentedRowModel-BNXEUeHp.d.cts → segmentedRowModel-s157HmRp.d.cts} +1 -1
  83. package/dist/sk-6ERFVKXJ.js +1 -0
  84. package/dist/sl-AVE6GE3D.js +1 -0
  85. package/dist/sr-D5KFFJNW.js +1 -0
  86. package/dist/sv-JJ7HXVOK.js +1 -0
  87. package/dist/{ticketRestrictions-CzchbX_o.d.cts → ticketRestrictions-DetdPbsL.d.cts} +2 -2
  88. package/dist/{ticketRestrictions-DaYOCpEw.d.ts → ticketRestrictions-EJTEWPGN.d.ts} +2 -2
  89. package/dist/tr-KKJMU4QY.js +1 -0
  90. package/dist/{types-DTSG6_Hq.d.cts → types-Db9rXT14.d.cts} +155 -1
  91. package/dist/{types-DTSG6_Hq.d.ts → types-Db9rXT14.d.ts} +155 -1
  92. package/dist/uk-KX5ZFXAR.js +1 -0
  93. package/dist/view3d/crossfade/panorama.d.cts +1 -1
  94. package/dist/view3d/crossfade/panorama.d.ts +1 -1
  95. package/dist/view3d/index.cjs +21 -21
  96. package/dist/view3d/index.d.cts +2 -2
  97. package/dist/view3d/index.d.ts +2 -2
  98. package/dist/view3d/index.js +23 -23
  99. package/dist/zh-Hans-TTCOG4UW.js +1 -0
  100. package/dist/zh-Hant-37V5VMCE.js +1 -0
  101. package/package.json +19 -2
  102. package/dist/chunk-GHJUDU3U.js +0 -1
  103. package/dist/es-XJUREIJL.js +0 -1
  104. package/dist/fr-CAT46QLZ.js +0 -1
@@ -1 +1 @@
1
- import{a as ge,b as he,f as bt,g as pt}from"../../chunk-N4CBOQFB.js";import"../../chunk-VI2CLV3Y.js";import{n as ft,p as ut,q as gt,r as ht,v as Te}from"../../chunk-DNGP2HDT.js";import{a as ue,b as W,d as lt,e as ct,f as ne,g as Me,i as dt,k as re}from"../../chunk-4BVXDBFE.js";import{b as ce,h as je,i as Re}from"../../chunk-6XJN4REG.js";import{A as Fe,B as nt,C as rt,D as ro,Fa as st,G as it,Q as at,a as qe,b as Xe,c as Ve,d as Ye,e as Ze,f as We,g as de,h as Qe,i as et,ja as ke,ma as z,p as tt,qa as oe,t as fe,ta as L,va as M,xa as T,z as ot,za as V}from"../../chunk-GHJUDU3U.js";import{m as Ne}from"../../chunk-CXF32VPG.js";var d=class extends Error{constructor(r,n,a={}){super(n);this.code=r;this.details=a;this.name="ChartOperationError"}};function v(t,e){let r=T(t),n=e?r.find(a=>a.id===e):r[0];if(!n)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:n.id,objects:n.objects}}function F(t,e){if(!t.categories.some(r=>r.key===e))throw new d("category_not_found",`Unknown chart category: ${e}. Call get_chart to list valid category keys.`,{categoryKey:e})}function j(t,e,r,n){let a=new Set([...n,...t.categories.map(i=>i.key),...t.zones?.map(i=>i.id)??[],...t.floors?.map(i=>i.id)??[],...t.floors?.length?t.floors.flatMap(i=>i.objects.map(o=>o.id)):t.objects.map(i=>i.id)]);for(let i=0;i<100;i++){let o=r(e);if(o&&!a.has(o))return n.add(o),o}throw new d("id_generation_failed",`Unable to allocate a unique ${e} id`)}function io(t){let e=t.slice().sort((i,o)=>i.x-o.x||i.y-o.y);if(e.length<3)return e;let r=(i,o,s)=>(o.x-i.x)*(s.y-i.y)-(o.y-i.y)*(s.x-i.x),n=[];for(let i of e){for(;n.length>=2&&r(n[n.length-2],n[n.length-1],i)<=0;)n.pop();n.push(i)}let a=[];for(let i=e.length-1;i>=0;i--){let o=e[i];for(;a.length>=2&&r(a[a.length-2],a[a.length-1],o)<=0;)a.pop();a.push(o)}return n.pop(),a.pop(),n.concat(a)}function ao(t,e){if(!t.length)return t;let r={x:t.reduce((n,a)=>n+a.x,0)/t.length,y:t.reduce((n,a)=>n+a.y,0)/t.length};return t.map(n=>{let a=n.x-r.x,i=n.y-r.y,o=Math.hypot(a,i)||1;return{x:n.x+a/o*e,y:n.y+i/o*e}})}function Y(t){let e=[];for(let n of t)n.type==="row"?e.push(...z(n).map(a=>({x:a.x,y:a.y}))):n.type==="table"?e.push(...oe(n).map(a=>({x:a.x,y:a.y}))):n.type==="gaArea"?e.push(...n.points):n.type==="booth"&&e.push(n.center);if(e.length<3)return null;let r=ao(io(e),22);return r.length>=3?r:null}function be(t,e){let r=v(t,e),n=T(t).find(a=>a.id===r.floorId);return{...t,objects:r.objects,floors:void 0,focalPoint:n.focalPoint,referenceImage:n.referenceImage,backgroundImage:n.backgroundImage}}var mt=24,yt=80;function Le(t,e){let r=t.normalize("NFKC").trim();if(r.length>mt)throw new d("invalid_operation",`${e} displayed type must be at most ${mt} characters`);return r}function pe(t,e){if(t.displayType===void 0)return!1;let r=Le(t.displayType,e);return r?(t.displayType=r,!1):(delete t.displayType,!0)}function Q(t,e){if(t.displayLabel===void 0)return!1;let r=t.displayLabel.normalize("NFKC").trim();if(r.length>yt)throw new d("invalid_operation",`${e} displayed label must be at most ${yt} characters`);return r?(t.displayLabel=r,!1):(delete t.displayLabel,!0)}function N(t,e){let r=t.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation",`${e} must use a six-digit hex color`);return r}function wt(t,e){if(!Number.isFinite(t)||t<je||t>Re)throw new d("invalid_operation",`${e} label size must be from ${je} to ${Re}`)}function ee(t,e){t.size!==void 0&&t.size!==null&&wt(t.size,e),t.color!==void 0&&t.color!==null&&N(t.color,`${e} label color`)}function me(t,e){if(t?.positionPreset!==void 0&&!["start","end","both","none"].includes(t.positionPreset))throw new d("invalid_operation",`${e} label positionPreset must be one of start, end, both, none`);let r=t?.labelStyle;r&&(r.size!==void 0&&wt(r.size,e),r.color!==void 0&&N(r.color,`${e} label color`))}function ye(t,e){let r=t?structuredClone(t):{},n=r.labelStyle?{...r.labelStyle}:{};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=N(e.color,"Label color")),n.size===void 0&&n.color===void 0?delete r.labelStyle:r.labelStyle=n,e.visible!==void 0&&(r.visible=e.visible),Object.keys(r).length?r:void 0}function Ke(t,e,r){let n=e.normalize("NFKC").trim();if(!n||n.length>80)throw new d("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(a=>a.id!==r&&a.label.normalize("NFKC").trim().toLocaleLowerCase("en")===n.toLocaleLowerCase("en")))throw new d("invalid_operation",`Zone label already exists: ${n}`);return n}function Ge(t,e){if(!Number.isFinite(t?.x)||!Number.isFinite(t?.y))throw new d("invalid_operation",`${e} must contain finite x and y values`);return{x:t.x,y:t.y}}function D(t,e,r){return(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x)}var J=Math.PI/180,B=Math.PI/180;function Z(t){return t.type==="row"||t.type==="table"?t.seatCount:t.type==="gaArea"?Math.max(0,Math.floor(t.capacity)):t.type==="booth"?1:0}function we(t){if(t.floors?.length){let e=t.floors[0];t.objects=e.objects,t.focalPoint=e.focalPoint,t.referenceImage=e.referenceImage,t.backgroundImage=e.backgroundImage}return t}var so=0,De=120,It=4;function lo(t){if(!Number.isFinite(t)||t<so||t>De)throw new d("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function yn(t,e){let r=T(t);if(r.length>=5)throw new d("invalid_operation","A chart can contain at most five physical floors");let n=(e.name??String(r.length+1)).normalize("NFKC").trim();if(!n||n.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(l=>l.name.toLocaleLowerCase("en")===n.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${n}`);t.floors?.length||(t.floors=[{id:"floor-0",name:"1",objects:t.objects,baseHeightM:0,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]);let i=t.floors[t.floors.length-1].baseHeightM??Math.min(De,(t.floors.length-1)*It),o=Math.min(De,i+It),s=j(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:n,baseHeightM:o,objects:[],focalPoint:{...t.focalPoint}}),we(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:o}}function wn(t,e){let r=T(t),n=r.find(o=>o.id===e.floorId);if(!n)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let a=e.name.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(o=>o.id!==n.id&&o.name.toLocaleLowerCase("en")===a.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${a}`);let i=n.name!==a;return i&&(n.name=a),{changed:i,floorId:n.id,floorName:a}}function In(t,e){if(!t.floors?.length)throw new d("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let r=t.floors.find(a=>a.id===e.floorId);if(!r)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});lo(e.baseHeightM);let n=r.baseHeightM!==e.baseHeightM;return n&&(r.baseHeightM=e.baseHeightM,r.physical3dProvenance={...r.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:n,floorId:r.id,baseHeightM:e.baseHeightM}}function Sn(t,e){if(!t.floors?.length)throw new d("invalid_operation","A single-floor chart cannot remove its only floor");let r=t.floors.findIndex(a=>a.id===e.floorId);if(r<0)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[n]=t.floors.splice(r,1);if(t.floors.length===1){let[a]=t.floors;t.objects=a.objects,t.focalPoint=a.focalPoint,t.referenceImage=a.referenceImage,t.backgroundImage=a.backgroundImage,t.floors=void 0}else we(t);return{changed:!0,floorId:n.id,removedObjects:n.objects.length,floorCount:T(t).length}}function On(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:j(t,"zone",e.idFactory,new Set),label:Ke(t,e.label),color:N(e.color,"Zone color"),...e.focalPoint?{focalPoint:Ge(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function Pn(t,e){if(!e.updates.length)throw new d("invalid_operation","At least one zone update is required");let r=e.updates.map(l=>l.zoneId);if(new Set(r).size!==r.length)throw new d("invalid_operation","Zone ids must be unique");let n=new Map((t.zones??[]).map(l=>[l.id,l])),a=r.filter(l=>!n.has(l));if(a.length)throw new d("object_not_found",`Unknown zone id(s): ${a.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:a});let i=structuredClone(t),o=new Map((i.zones??[]).map(l=>[l.id,l]));for(let l of e.updates){if(!Object.keys(l.patch).length)throw new d("invalid_operation",`Zone ${l.zoneId} has no changes`);let f=o.get(l.zoneId);l.patch.label!==void 0&&(f.label=Ke(i,l.patch.label,f.id)),l.patch.color!==void 0&&(f.color=N(l.patch.color,"Zone color")),l.patch.focalPoint!==void 0&&(f.focalPoint=Ge(l.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(i.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=i.zones),{changed:s,zoneIds:r,zones:r.map(l=>structuredClone(o.get(l)))}}function An(t,e){let r=(t.zones??[]).findIndex(i=>i.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let n=T(t).flatMap(i=>i.objects).filter(i=>i.type==="section"&&i.zone===e.zoneId);if(n.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${n.length} section(s)`,{zoneId:e.zoneId,sectionIds:n.map(i=>i.id),requiresClearSectionAssignments:!0});let a=n.map(i=>i.id);for(let i of n)delete i.zone;return t.zones.splice(r,1),t.zones.length||delete t.zones,we(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:a,zoneCount:t.zones?.length??0}}var ie={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 ae(t,e,r,n,a,i,o=0){return{type:"row",id:t,label:e,origin:{x:-(n-1)*a/2,y:r},rotation:0,curve:o,seatCount:n,seatSpacing:a,categoryKey:i}}function co(t,e,r,n,a,i){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:n,rotation:0,radius:a,categoryKey:i}}function fo(t,e,r,n,a,i){let o=r/2,s=n/2;return{type:"gaArea",id:t,label:e,points:[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}],capacity:a,categoryKey:i}}var St=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[ie.balcony],sectionLabel:"Balcony",build:()=>[ae("blk-b0","A",-45,18,24,"balcony",18),ae("blk-b1","B",-15,20,24,"balcony",18),ae("blk-b2","C",15,22,24,"balcony",18),ae("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[ie.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>ae(`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:[ie.standard],build:()=>[fo("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[ie.premium],build:()=>Array.from({length:6},(t,e)=>co(`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:[ie.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"}]}];function $(t){let e="",r=t;do e=String.fromCharCode(65+r%26)+e,r=Math.floor(r/26)-1;while(r>=0);return e}function vt(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let r of t)e=e*26+(r.charCodeAt(0)-64);return e-1}function $e(t){let e=(t%360+360)%360,r=e>=180?e-360:e;return Object.is(r,-0)||Math.abs(r)<1e-9?0:r}function xt(t,e,r){let n=a=>({x:a.x+e,y:a.y+r});switch(t.type){case"row":t.origin=n(t.origin),t.path&&(t.path={start:n(t.path.start),control1:n(t.path.control1),control2:n(t.path.control2),end:n(t.path.end)});break;case"table":case"booth":t.center=n(t.center);break;case"text":t.position=n(t.position);break;case"gaArea":t.points=t.points.map(n),t.holes&&(t.holes=t.holes.map(a=>a.map(n)));break;case"section":t.outline=t.outline.map(n),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(n)),t.outlinePath&&(t.outlinePath=nt(t.outlinePath,e,r)),t.holes&&(t.holes=t.holes.map(a=>a.map(n)));break;case"shape":t.points&&(t.points=t.points.map(n)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}function zn(t,e){let r=v(t,e.floorId),n=[...new Set(e.tableIds)];if(!n.length)throw new d("invalid_operation","At least one table id is required");let a=n.map(b=>r.objects.find(m=>m.type==="table"&&m.id===b)),i=n.filter((b,m)=>!a[m]);if(i.length)throw new d("object_not_found",`Unknown table id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one table change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&F(t,o.categoryKey);let s=o.seatCount!==void 0,l=o.seatCountsBySide!==void 0;if(l){if(o.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(o.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let b=["top","bottom","left","right"],m=Object.keys(o.seatCountsBySide);if(m.length!==b.length||m.some(I=>!b.includes(I)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let I of b){let S=o.seatCountsBySide[I];if(!Number.isInteger(S)||S<0||S>40)throw new d("invalid_operation",`seatCountsBySide.${I} must be a whole number from 0 to 40`)}let C=b.reduce((I,S)=>I+o.seatCountsBySide[S],0);if(C<1||C>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&o.seatCount!==C)throw new d("invalid_operation",`seatCount must equal the ${C}-chair seatCountsBySide total`);o.seatCount=C,o.sides=b.filter(I=>o.seatCountsBySide[I]>0)}if(o.seatCount!==void 0&&(!Number.isInteger(o.seatCount)||o.seatCount<1||o.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(o.shape!==void 0&&o.shape!=="round"&&o.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(o.bookAsWhole===!0&&o.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(o.variableOccupancy===!1&&(o.minOccupancy!==void 0||o.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let c=(b,m,C,I)=>{if(m!==void 0&&(!Number.isFinite(m)||m<C||m>I))throw new d("invalid_operation",`${String(b)} must be from ${C} to ${I}`)};if(c("rotation",o.rotation,0,360),c("radius",o.radius,24,160),c("seatArc",o.seatArc,120,360),c("width",o.width,40,320),c("height",o.height,30,240),o.minOccupancy!==void 0&&(!Number.isInteger(o.minOccupancy)||o.minOccupancy<1||o.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(o.maxOccupancy!==void 0&&(!Number.isInteger(o.maxOccupancy)||o.maxOccupancy<1||o.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(o.sides!==void 0){let b=new Set(["top","bottom","left","right"]);if(!o.sides.length||o.sides.length>4||new Set(o.sides).size!==o.sides.length||o.sides.some(m=>!b.has(m)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=Q(o,"Table"),h=pe(o,"Table"),g=a.map(b=>{if(b.seatCountsBySide&&!l&&(s||e.patch.sides!==void 0))throw new d("invalid_operation",`Table "${b.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:b.id});let m=structuredClone(b);if(Object.assign(m,o),m.shape==="round"&&delete m.seatCountsBySide,m.overrides&&o.seatCount!==void 0&&(m.overrides=m.overrides.filter(C=>C.index<m.seatCount),m.overrides.length||delete m.overrides),o.bookAsWhole===!1&&delete m.bookAsWhole,o.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(C=>C.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(o.minOccupancy!==void 0||o.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(h&&delete m.displayType,f&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let C=["top","bottom","left","right"],I=C.reduce((S,A)=>S+m.seatCountsBySide[A],0);if(I!==m.seatCount)throw new d("invalid_operation",`Table "${m.label}" side counts total ${I}, but seatCount is ${m.seatCount}`,{tableId:m.id,seatCount:m.seatCount,seatCountsBySide:m.seatCountsBySide});m.sides=C.filter(S=>m.seatCountsBySide[S]>0)}}else m.radius??=40;if((m.bookAsWhole||m.variableOccupancy)&&dt(m.label))throw new d("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),u=new Map(g.map(b=>[b.id,b])),p=new Set(n),y=new Map;for(let b of T(t))for(let m of b.objects){let C=m.type==="table"?u.get(m.id)??m:m,I=[];C.type==="row"?I=z(C).map(S=>S.label):C.type==="table"?I=C.bookAsWhole||C.variableOccupancy?[C.label]:oe(C).map(S=>S.label):C.type==="booth"?I=[C.label]:C.type==="gaArea"&&(I=ne(C));for(let S of I){let A=y.get(S);if(A&&(p.has(A)||p.has(C.id)))throw new d("invalid_operation",`Inventory label "${S}" is already in use; grouped table labels must be unique`,{tableIds:n,inventoryLabel:S,conflictingObjectIds:[A,C.id]});y.set(S,A??C.id)}}let w=!1,x=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[b,m]of a.entries()){let C=g[b],I=JSON.stringify(m);for(let S of x)S in C||delete m[S];Object.assign(m,C),JSON.stringify(m)!==I&&(w=!0)}return{floorId:r.floorId,changed:w,tableIds:n}}function Bn(t,e){let r=v(t,e.floorId),n=[...new Set(e.boothIds)];if(!n.length)throw new d("invalid_operation","At least one booth id is required");let a=n.map(u=>r.objects.find(p=>p.type==="booth"&&p.id===u)),i=n.filter((u,p)=>!a[p]);if(i.length)throw new d("object_not_found",`Unknown booth id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one booth change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&F(t,o.categoryKey);let s=(u,p,y,w)=>{if(p!==void 0&&(!Number.isFinite(p)||p<y||p>w))throw new d("invalid_operation",`${u} must be from ${y} to ${w}`)};s("width",o.width,30,400),s("height",o.height,30,400),s("rotation",o.rotation,0,360);let l=o.points===null;if(o.points!=null){if(n.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let u=bt(o.points);if(!u.ok)throw new d("invalid_operation",u.message??"The booth outline is not a valid simple polygon")}let c=o.points!=null?o.points.map(u=>({x:u.x,y:u.y})):void 0;delete o.points;let f=Q(o,"Booth"),h=pe(o,"Booth"),g=!1;for(let u of a){let p=JSON.stringify(u);Object.assign(u,o),f&&delete u.displayLabel,h&&delete u.displayType,l?delete u.points:c&&(u.points=c),JSON.stringify(u)!==p&&(g=!0)}return{floorId:r.floorId,changed:g,boothIds:n}}function Un(t,e){let r=v(t,e.floorId),n=[...new Set(e.gaAreaIds)];if(!n.length)throw new d("invalid_operation","At least one GA area id is required");let a=n.map(f=>r.objects.find(h=>h.type==="gaArea"&&h.id===f)),i=n.filter((f,h)=>!a[h]);if(i.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one GA area change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(o.categoryKey!==void 0&&F(t,o.categoryKey),o.capacity!==void 0&&(!Number.isInteger(o.capacity)||o.capacity<1||o.capacity>1e5))throw new d("invalid_operation","capacity must be an integer from 1 to 100000");if(o.cornerRadius!==void 0&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=Q(o,"GA area"),l=pe(o,"GA area");if(o.capacity!==void 0)for(let f of a){if(f.inventorySegments!==void 0&&o.capacity<f.capacity)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot be reduced below ${f.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:f.id,currentCapacity:f.capacity,requestedCapacity:o.capacity});if(f.inventorySegments!==void 0&&o.capacity>f.capacity&&Me(f,o.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot append that capacity safely`,{gaAreaId:f.id})}let c=!1;for(let f of a){let h=JSON.stringify(f),g=o.capacity===void 0?f.inventorySegments:Me(f,o.capacity);Object.assign(f,o),g!==void 0&&(f.inventorySegments=g),s&&delete f.displayLabel,l&&delete f.displayType,JSON.stringify(f)!==h&&(c=!0)}return{floorId:r.floorId,changed:c,gaAreaIds:n}}function Ee(t,e){if(e.length<3)return 0;let r=a=>L(a,e,void 0),n=0;for(let a of t)r(M(a))&&(a.type==="row"?n+=z(a).length:a.type==="table"?n+=oe(a).length:(a.type==="gaArea"||a.type==="booth")&&(n+=Z(a)));return n}function Jn(t,e){let r=v(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 n=e.objectIds.map(s=>r.objects.find(l=>l.id===s)),a=e.objectIds.filter((s,l)=>!n[l]);if(a.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:a});let i=n,o=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)o.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:i.map(s=>({id:s.id,type:s.type})),removedInventory:i.reduce((s,l)=>s+Z(l),0),remainingObjectCount:r.objects.length}}function Hn(t,e){let r=v(t,e.floorId),n=[...new Set(e.textIds)];if(!n.length)throw new d("invalid_operation","At least one text id is required");let a=n.map(c=>r.objects.find(f=>f.type==="text"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found",`Unknown text id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one text change is required");if(o.text!==void 0){if(o.text=o.text.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!o.text||o.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(o.fontSize!==void 0&&(!Number.isFinite(o.fontSize)||o.fontSize<8||o.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(o.fontFamily!==void 0&&o.fontFamily!==null&&(o.fontFamily=o.fontFamily.normalize("NFKC").trim(),!o.fontFamily||o.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(o.rotation!==void 0&&(!Number.isFinite(o.rotation)||o.rotation<0||o.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(o.color!==void 0&&o.color!==null&&(o.color=N(o.color,"Text color")),o.bold!==void 0&&typeof o.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(o.italic!==void 0&&typeof o.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(o.width!==void 0&&o.width!==null&&(!Number.isFinite(o.width)||o.width<40||o.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(o.align!==void 0&&!["left","center","right"].includes(o.align))throw new d("invalid_operation","Text align must be left, center, or right");if(o.lineHeight!==void 0&&(!Number.isFinite(o.lineHeight)||o.lineHeight<.8||o.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(o.letterSpacing!==void 0&&(!Number.isFinite(o.letterSpacing)||o.letterSpacing<-2||o.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(o.underline!==void 0&&typeof o.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(o.opacity!==void 0&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(o.background!==void 0&&o.background!==null){o.background.color=N(o.background.color,"Text background color");let{padding:c=6,cornerRadius:f=4,opacity:h=.9}=o.background;if(!Number.isFinite(c)||c<0||c>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(h)||h<.1||h>1)throw new d("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(c=>Object.prototype.hasOwnProperty.call(o,c))&&a.some(c=>c.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(o.iconKey!==void 0){if(!ft(o.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(a.some(c=>c.semanticKind!=="icon"))throw new d("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let l=!1;for(let c of a){let f=JSON.stringify(c);o.iconKey!==void 0&&(c.iconKey=o.iconKey),o.text!==void 0&&(c.text=o.text),o.fontSize!==void 0&&(c.fontSize=o.fontSize),o.fontFamily===null?delete c.fontFamily:o.fontFamily!==void 0&&(c.fontFamily=o.fontFamily),o.rotation!==void 0&&(c.rotation=o.rotation),o.color===null?delete c.color:o.color!==void 0&&(c.color=o.color),o.bold!==void 0&&(o.bold?c.bold=!0:delete c.bold),o.italic!==void 0&&(o.italic?c.italic=!0:delete c.italic),o.width===null?delete c.width:o.width!==void 0&&(c.width=o.width),o.align!==void 0&&(o.align==="left"?delete c.align:c.align=o.align),o.lineHeight!==void 0&&(o.lineHeight===1.2?delete c.lineHeight:c.lineHeight=o.lineHeight),o.letterSpacing!==void 0&&(o.letterSpacing===0?delete c.letterSpacing:c.letterSpacing=o.letterSpacing),o.underline!==void 0&&(o.underline?c.underline=!0:delete c.underline),o.opacity!==void 0&&(o.opacity===1?delete c.opacity:c.opacity=o.opacity),o.background===null?delete c.background:o.background!==void 0&&(c.background=o.background),JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,textIds:n}}function qn(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)],a=n.map(c=>r.objects.find(f=>f.type==="row"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a.slice().sort((c,f)=>c.origin.y-f.origin.y||c.origin.x-f.origin.x),s=at(o.map(c=>({label:c.label})),e.options),l=!1;return o.forEach((c,f)=>{c.label!==s[f].label&&(l=!0),c.label=s[f].label}),{floorId:r.floorId,changed:l,rows:o.map(c=>({id:c.id,label:c.label}))}}function Xn(t,e){let r=St.find(c=>c.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let n=v(t,e.floorId),a=new Set,i=r.build().map(c=>structuredClone(c));for(let c of i)c.id=j(t,c.type,e.idFactory,a),xt(c,e.center.x,e.center.y);for(let c of r.categories)t.categories.some(f=>f.key===c.key)||t.categories.push({...c});let o=i.filter(c=>c.type==="row");if(o.length){let c=0;for(let f of n.objects){if(f.type!=="row")continue;let h=vt(f.label);h!=null&&(c=Math.max(c,h+1))}for(let f of o)f.label=$(c++)}let s=new Set(n.objects.flatMap(c=>"label"in c&&c.label?[c.label]:[]));for(let c of i){if((c.type==="table"||c.type==="booth")&&s.has(c.label)){let f=/^(.*?)(\d+)$/.exec(c.label),h=f?f[1]:`${c.label} `,g=f?Number.parseInt(f[2],10):1;do g++;while(s.has(`${h}${g}`));c.label=`${h}${g}`}"label"in c&&c.label&&s.add(c.label)}n.objects.push(...i);let l=null;if(r.sectionLabel){let c=Y(i);if(c){let f={type:"section",id:j(t,"sec",e.idFactory,a),label:r.sectionLabel,outline:c};n.objects.push(f),l=f.id}}return{floorId:n.floorId,blockKey:r.key,createdIds:[...i.map(c=>c.id),...l?[l]:[]],sectionId:l}}function uo(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(i=>!Number.isFinite(i.x)||!Number.isFinite(i.y)))throw new d("invalid_operation","Exact row path points must be finite");let n=tt(e,97),a=n.slice(1).reduce((i,o,s)=>i+Math.hypot(o.x-n[s].x,o.y-n[s].y),0);if(!Number.isFinite(a)||a<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:a}}function go(t,e){let r=v(t,e.floorId),n=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!n)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let a=uo(e.path),i=z(n),o=structuredClone(n);o.path=a.path,o.origin={...a.path.start};let s=z(o),l=i.map((f,h)=>Math.hypot(f.x-s[h].x,f.y-s[h].y)),c=JSON.stringify(n.path)!==JSON.stringify(a.path)||n.origin.x!==a.path.start.x||n.origin.y!==a.path.start.y;return{floorId:r.floorId,rowId:n.id,seatCount:n.seatCount,pathLength:a.length,averageSeatMovement:l.length?l.reduce((f,h)=>f+h,0)/l.length:0,maxSeatMovement:l.length?Math.max(...l):0,convertingFromParametric:!n.path,changed:c,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:n.seatCount}}function tr(t,e){let r=go(t,e);if(!r.changed)return r;let a=v(t,r.floorId).objects.find(i=>i.type==="row"&&i.id===r.rowId);return a.path=structuredClone(e.path),a.origin={...e.path.start},delete a.arcFanGeneration,delete a.rowBlockGeneration,r}function ho(t,e){let r=t.map((n,a)=>[...n,e[a]]);for(let n=0;n<3;n++){let a=n;for(let o=n+1;o<3;o++)Math.abs(r[o][n])>Math.abs(r[a][n])&&(a=o);if(Math.abs(r[a][n])<1e-9)return null;[r[n],r[a]]=[r[a],r[n]];let i=r[n][n];for(let o=n;o<4;o++)r[n][o]/=i;for(let o=0;o<3;o++){if(o===n)continue;let s=r[o][n];for(let l=n;l<4;l++)r[o][l]-=s*r[n][l]}}return[r[0][3],r[1][3],r[2][3]]}function bo(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let a of t){if(!Number.isFinite(a.x)||!Number.isFinite(a.y))return null;let i=[2*a.x,2*a.y,1],o=a.x**2+a.y**2;for(let s=0;s<3;s++){r[s]+=i[s]*o;for(let l=0;l<3;l++)e[s][l]+=i[s]*i[l]}}let n=ho(e,r);return n?{x:n[0],y:n[1]}:null}function Ct(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function po(t,e){let r=v(t,e.floorId),n=r.objects.find(u=>u.type==="section"&&u.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let a=e.strength??100;if(!Number.isFinite(a)||a<0||a>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let i=T(t).find(u=>u.id===r.floorId),o=e.mode==="outline"?bo(n.outline):e.focalPoint??i.focalPoint??t.focalPoint;if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(u=>u.type==="row"&&L(M(u),n.outline,n.holes)),l=s.filter(u=>!!u.path).map(u=>u.id),c=[],f=[],h=a/100;for(let u of s){if(u.path)continue;if(u.seatCount<2){c.push(u.id);continue}let p=Math.hypot(u.origin.x-o.x,u.origin.y-o.y);if(p<=u.seatSpacing/2+1e-6){c.push(u.id);continue}let y=2*Math.asin(u.seatSpacing/(2*p))/J,w=z(u),x=Math.atan2(u.origin.x-o.x,u.origin.y-o.y)/J,m=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(Ct(Math.atan2(w[1].x-o.x,w[1].y-o.y)/J-x))||1)*y*(u.seatCount-1);if(Math.abs(m)>320){c.push(u.id);continue}let C=-x,I=u.curve+(m-u.curve)*h,S=u.rotation+Ct(C-u.rotation)*h,A={...u,curve:I,rotation:S},U=z(A).map((q,E)=>Math.hypot(q.x-w[E].x,q.y-w[E].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:m,resultCurve:I,fromRotation:u.rotation,resultRotation:S,rmsMovement:Math.sqrt(U.reduce((q,E)=>q+E**2,0)/U.length),maxMovement:Math.max(...U)})}let g=f.map(u=>u.rmsMovement);return{floorId:r.floorId,sectionId:n.id,mode:e.mode,fitCenter:{...o},strength:a,rows:f,skippedPathRowIds:l,skippedInvalidRowIds:c,averageMovement:g.length?g.reduce((u,p)=>u+p,0)/g.length:0,maxMovement:f.length?Math.max(...f.map(u=>u.maxMovement)):0}}function or(t,e){let r=po(t,e),n=v(t,r.floorId),a=n.objects.find(o=>o.type==="section"&&o.id===r.sectionId),i=!1;for(let o of r.rows){let s=n.objects.find(l=>l.type==="row"&&l.id===o.rowId);(s.curve!==o.resultCurve||s.rotation!==o.resultRotation)&&(s.curve=o.resultCurve,s.rotation=o.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,i=!0)}return(a.smoothing??0)!==r.strength&&(a.smoothing=r.strength,i=!0),{...r,changed:i}}function Ot(t,e,r,n){let a=D(t,e,r),i=D(t,e,n),o=D(r,n,t),s=D(r,n,e);return a*i<-1e-9&&o*s<-1e-9}function _t(t,e){return t.some((r,n)=>{let a=t[(n+1)%t.length];return e.some((i,o)=>Ot(r,a,i,e[(o+1)%e.length]))})}function mo(t){if(t.length<3||t.length>256||Math.abs(fe(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)if(!(r===e+1||e===0&&r===t.length-1)&&Ot(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Ie(t,e,r){let n=v(t,e),a=n.objects.find(i=>(i.type==="section"||i.type==="gaArea")&&i.id===r);if(!a)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:n,object:a,outer:a.type==="section"?a.outline:a.points}}function ze(t,e){let{target:r,object:n,outer:a}=Ie(t,e.floorId,e.objectId),i=structuredClone(e.points);if(!mo(i))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(i.some(c=>!L(c,a,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(_t(i,a))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let o=n.holes??[],s=e.holeIndex??o.length;if(!Number.isInteger(s)||s<0||s>o.length||e.holeIndex!=null&&s>=o.length)throw new d("invalid_operation","Opening not found");for(let c=0;c<o.length;c++){if(c===e.holeIndex)continue;let f=o[c];if(_t(i,f)||L(i[0],f,void 0)||L(f[0],i,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let l=r.objects.filter(c=>c.id!==n.id&&c.type!=="section"&&L(M(c),i,void 0));return{floorId:r.floorId,objectId:n.id,objectType:n.type,holeIndex:s,vertexCount:i.length,excludedObjectIds:l.map(c=>c.id),excludedInventoryUnits:Ee(r.objects.filter(c=>c.id!==n.id),i),preservesExactOuterPath:n.type==="section"&&!!n.outlinePath}}function nr(t,e){let r=ze(t,e),{object:n}=Ie(t,r.floorId,r.objectId);return n.holes??=[],e.holeIndex==null?n.holes.push(structuredClone(e.points)):n.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function yo(t,e){let{target:r,object:n}=Ie(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(n.holes?.length??0))throw new d("invalid_operation","Opening not found");let a=n.holes[e.holeIndex],i=r.objects.filter(o=>o.id!==n.id&&o.type!=="section"&&L(M(o),a,void 0));return{floorId:r.floorId,objectId:n.id,objectType:n.type,holeIndex:e.holeIndex,vertexCount:a.length,excludedObjectIds:i.map(o=>o.id),excludedInventoryUnits:Ee(r.objects.filter(o=>o.id!==n.id),a),preservesExactOuterPath:n.type==="section"&&!!n.outlinePath}}function rr(t,e){let r=yo(t,e),{object:n}=Ie(t,r.floorId,r.objectId);return n.holes.splice(e.holeIndex,1),n.holes.length||delete n.holes,{...r,changed:!0}}function wo(t){let e=t.trim();if(!e||e.length>2e6||!/^(https:\/\/|data:image\/)/.test(e))throw new d("invalid_operation","Section view photo must be an HTTPS or data:image URL no larger than 2 MB");return e}function Pt(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let n=r.map(o=>t.find(s=>s.type==="section"&&s.id===o)),a=r.filter((o,s)=>!n[s]);if(a.length)throw new d("object_not_found",`Unknown section id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:a});let i=n;return{requested:r,sections:i,logicalSectionIds:[...new Set(i.map(o=>o.logicalSectionId??o.id))]}}function Io(t,e){let r=v(t,e.floorId),n=Pt(r.objects,e.sectionIds),a=re(be(t,r.floorId)),i=new Map(a.sections.map(h=>[h.id,h])),o=new Map(r.objects.map(h=>[h.id,h])),s=n.logicalSectionIds.flatMap(h=>i.get(h)?.objectIds??[]),l=new Set;for(let h of s){let g=o.get(h);if(g)if(g.type==="row"||g.type==="table")for(let u of he(g).keys())l.add(u);else(g.type==="booth"||g.type==="gaArea")&&l.add(g.categoryKey)}let c=n.logicalSectionIds.every(h=>(i.get(h)?.seatCount??0)>0),f=n.logicalSectionIds.every(h=>i.get(h)?.objectIds.some(g=>{let u=o.get(g);return u?.type==="row"||u?.type==="table"||u?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:n.requested,logicalSectionIds:n.logicalSectionIds,objectIds:s,categoryApplicable:c,...c&&l.size===1?{categoryKey:[...l][0]}:{},categoryMixed:c&&l.size!==1,viewApplicable:f}}function ur(t,e){F(t,e.categoryKey);let r=Io(t,e);if(!r.categoryApplicable)throw new d("invalid_operation","Every selected logical section must contain buyer inventory before a section category can be assigned",{logicalSectionIds:r.logicalSectionIds});let n=v(t,r.floorId),a=new Set(r.objectIds),i=!1,o=0;for(let s of n.objects){if(!a.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,i=!0),s.type!=="row"&&s.type!=="table"||!s.overrides?.length))continue;let l=s.overrides.flatMap(c=>{if(c.categoryKey===void 0)return[c];let f={...c};return delete f.categoryKey,o++,i=!0,Object.keys(f).some(h=>h!=="index")?[f]:[]});l.length?s.overrides=l:delete s.overrides}return{...r,changed:i,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:o}}function gr(t,e){let r=v(t,e.floorId),n=Pt(r.objects,e.sectionIds),{requested:a}=n,i=structuredClone(e.patch),o=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(i).filter(u=>!o.has(u));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(i).length)throw new d("invalid_operation","At least one section metadata change is required");if(i.label!==void 0){if(i.label=i.label.normalize("NFKC").trim(),a.length!==1)throw new d("invalid_operation","label can be changed only for one section at a time");if(!i.label||i.label.length>80)throw new d("invalid_operation","Section labels must contain 1 to 80 characters")}if(i.displayLabel!==void 0&&i.displayLabel!==null){if(i.displayLabel=i.displayLabel.normalize("NFKC").trim(),a.length!==1)throw new d("invalid_operation","displayLabel can be changed only for one section at a time");if(!i.displayLabel||i.displayLabel.length>80)throw new d("invalid_operation","Section display labels must contain 1 to 80 characters")}if(i.entrance!==void 0&&i.entrance!==null&&(i.entrance=i.entrance.normalize("NFKC").trim(),i.entrance.length>40))throw new d("invalid_operation","Section entrance must be at most 40 characters");if(i.viewFromSeatUrl!==void 0&&i.viewFromSeatUrl!==null&&(i.viewFromSeatUrl=wo(i.viewFromSeatUrl)),i.labelPresentation?.position&&(!Number.isFinite(i.labelPresentation.position.x)||!Number.isFinite(i.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(i.labelPresentation?.rotation!=null&&!Number.isFinite(i.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(i.labelPresentation!==void 0&&me(i.labelPresentation,"Section"),i.labelStyle!==void 0&&ee(i.labelStyle,"Section"),i.zone!==void 0&&i.zone!==null&&!(t.zones??[]).some(u=>u.id===i.zone))throw new d("object_not_found",`Unknown chart zone: ${i.zone}`,{zoneId:i.zone});if(i.elevation!==void 0&&(!Number.isInteger(i.elevation)||i.elevation<0||i.elevation>3))throw new d("invalid_operation","Section elevation must be an integer from 0 to 3");if(i.height!==void 0&&i.height!==null&&(!Number.isFinite(i.height)||i.height<0||i.height>120))throw new d("invalid_operation","Section height must be a number from 0 to 120 metres");if(i.rake!==void 0&&i.rake!==null&&(!Number.isFinite(i.rake)||i.rake<0||i.rake>45))throw new d("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(i.surfaceKind!==void 0&&i.surfaceKind!==null&&i.surfaceKind!=="flat"&&i.surfaceKind!=="rakedRows")throw new d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");i.color!==void 0&&i.color!==null&&(i.color=N(i.color,"Section color"));let l=i.displayLabel!==void 0||i.entrance!==void 0||i.viewFromSeatUrl!==void 0||i.viewFromSeatMeta!==void 0||i.labelStyle!==void 0||i.zone!==void 0,c=new Set(n.logicalSectionIds),f=l?r.objects.filter(u=>u.type==="section"&&c.has(u.logicalSectionId??u.id)):[],h=new Set,g=!1;for(let u of n.sections){let p=JSON.stringify(u);i.label!==void 0&&(u.label=i.label),i.labelPresentation===null?delete u.labelPresentation:i.labelPresentation!==void 0&&(u.labelPresentation=i.labelPresentation),i.elevation!==void 0&&(u.elevation=i.elevation);let y=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};i.height===null?(delete u.height,y("height")):i.height!==void 0&&(u.height=i.height,u.physical3dProvenance={...u.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),i.rake===null?(delete u.rake,y("rake")):i.rake!==void 0&&(u.rake=i.rake,u.physical3dProvenance={...u.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),i.surfaceKind===null?(delete u.surfaceKind,y("surfaceKind")):i.surfaceKind!==void 0&&(u.surfaceKind=i.surfaceKind,u.physical3dProvenance={...u.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),i.color===null?delete u.color:i.color!==void 0&&(u.color=i.color),JSON.stringify(u)!==p&&(g=!0,h.add(u.id))}for(let u of f){let p=JSON.stringify(u),y=u.viewFromSeatUrl;if(i.displayLabel===null?delete u.displayLabel:i.displayLabel!==void 0&&(u.displayLabel=i.displayLabel),i.entrance===null||i.entrance===""?delete u.entrance:i.entrance!==void 0&&(u.entrance=i.entrance),i.viewFromSeatUrl===null||i.viewFromSeatUrl===""?delete u.viewFromSeatUrl:i.viewFromSeatUrl!==void 0&&(u.viewFromSeatUrl=i.viewFromSeatUrl),!u.viewFromSeatUrl||i.viewFromSeatMeta===null?delete u.viewFromSeatMeta:i.viewFromSeatMeta!==void 0?u.viewFromSeatMeta=structuredClone(i.viewFromSeatMeta):i.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==y&&delete u.viewFromSeatMeta,i.labelStyle!==void 0){let w=ye(u.labelPresentation,i.labelStyle);w?u.labelPresentation=w:delete u.labelPresentation}i.zone===null?delete u.zone:i.zone!==void 0&&(u.zone=i.zone),JSON.stringify(u)!==p&&(g=!0,h.add(u.id))}return{floorId:r.floorId,changed:g,sectionIds:a,affectedSectionIds:[...h]}}function So(t,e){let r=v(t,e.floorId),n=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(n.outlinePath)throw new d("invalid_operation",`Section ${n.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:n.id,representation:"exact-path"});if(!n.geometry)throw new d("invalid_operation",`Section ${n.id} is already a manual polygon`,{sectionId:n.id,representation:"manual-polygon"});let a=r.objects.filter(i=>i.id!==n.id&&i.type!=="section"&&L(M(i),n.outline,n.holes));return{floorId:r.floorId,sectionId:n.id,sectionLabel:n.label,source:{representation:"generated-polygon",generator:structuredClone(n.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:n.outline.length,holeCount:n.holes?.length??0,memberObjectIds:a.map(i=>i.id),inventoryUnits:a.reduce((i,o)=>i+Z(o),0),durableReferenceSource:!!n.referenceSource,inventoryExclusionEvidence:!!n.referenceInventoryExclusion},removedFields:["geometry"]}}function hr(t,e){let r=So(t,e),a=v(t,r.floorId).objects.find(i=>i.type==="section"&&i.id===r.sectionId);return delete a.geometry,{...r,changed:!0}}function vo(t,e){let r=(...s)=>s.every(Number.isFinite),n,a=1,i=!1,o=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");o=e.dx!==0||e.dy!==0,n=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");o=e.factor!==1,a=e.factor;let s=M(t);n=l=>({x:s.x+(l.x-s.x)*e.factor,y:s.y+(l.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!r(e.degrees))throw new d("invalid_operation","Section rotation must be finite");o=(e.degrees%360+360)%360!==0;let l=e.degrees*Math.PI/180,c=Math.cos(l),f=Math.sin(l),h=M(t);n=g=>{let u=g.x-h.x,p=g.y-h.y;return{x:h.x+u*c-p*f,y:h.y+u*f+p*c}}}else{if(!r(e.coordinate))throw new d("invalid_operation","Section reflection coordinate must be finite");i=!0,n=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return o&&(t.outline=t.outline.map(n),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(n)),t.outlinePath&&(t.outlinePath=rt(t.outlinePath,n,a,i)),t.holes&&(t.holes=t.holes.map(s=>s.map(n)))),{changed:o,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 br(t,e){let r=v(t,e.floorId),n=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...vo(n,e.transform)}}function pr(t,e){let r=v(t,e.floorId),n=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let a=structuredClone(e.path);if(!ot(a))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let i=Fe(a),o=JSON.stringify(n.outlinePath)!==JSON.stringify(a)||JSON.stringify(n.outline)!==JSON.stringify(i)||n.sourceOutline!==void 0||n.cornerSmoothing!==void 0;return o&&(n.outlinePath=a,n.outline=i,delete n.geometry,delete n.sourceOutline,delete n.cornerSmoothing),{floorId:r.floorId,sectionId:n.id,changed:o,segmentKinds:a.segments.map(s=>s.kind),sampledVertexCount:i.length,holeCount:n.holes?.length??0}}function xo(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function mr(t,e){return Co(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Co(t,e){let r=v(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 n=[...new Set(e.sectionIds)],a=new Set,i=new Map,o=!1;try{for(let s of n){let l=r.objects.find(b=>b.type==="section"&&b.id===s);if(!l||!xo(l))continue;let f=structuredClone(l);i.set(l.id,{section:l,snapshot:f});let h=JSON.stringify(l),g=(l.sourceOutline??l.outline).map(b=>({...b})),u=Math.min(100,Math.max(0,e.cornerSmoothing??l.cornerSmoothing??0)),y=(e.edgeCurvature===void 0?l.edgeCurvature:e.edgeCurvature??void 0)?.map(b=>Math.min(100,Math.max(-100,b))),w=y?.some(b=>Math.abs(b)>.5)===!0,x=u>.5||w?it(g,{cornerSmoothing:u,...w?{edgeCurvature:y}:{}}):null;x?(l.sourceOutline=g,l.outlinePath=x,l.outline=Fe(x),u>.5?l.cornerSmoothing=u:delete l.cornerSmoothing,w?l.edgeCurvature=[...y]:delete l.edgeCurvature):(l.outline=g,delete l.outlinePath,delete l.sourceOutline,delete l.cornerSmoothing,delete l.edgeCurvature);for(let b=0;b<(l.holes?.length??0);b+=1)ze(t,{floorId:r.floorId,objectId:l.id,points:l.holes[b],holeIndex:b});JSON.stringify(l)!==h&&(o=!0,a.add(l.id))}}catch(s){for(let{section:l,snapshot:c}of i.values()){let f=l;for(let h of Object.keys(f))delete f[h];Object.assign(l,structuredClone(c))}throw s}return{floorId:r.floorId,changed:o,sectionIds:n,affectedSectionIds:[...a]}}var _o=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,r=new Map,n=structuredClone(t);for(let a of n){let i=a.key.trim(),o=a.label.normalize("NFKC").trim();if(!i||i.length>160||e.has(i))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${i}`,{categoryKey:i});if(e.add(i),!o||o.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${i}`,{categoryKey:i});let s=o.toLocaleLowerCase("en"),l=r.get(s);if(l)throw new d("duplicate_category_label",`Categories ${l} and ${i} share the same label`,{categoryKeys:[l,i],label:o});if(r.set(s,i),!/^#[0-9a-fA-F]{6}$/.test(a.color))throw new d("invalid_operation",`Category ${i} must use a six-digit hex color`,{categoryKey:i});if(a.price!=null&&(!Number.isFinite(a.price)||a.price<0||a.price>1e6))throw new d("invalid_operation",`Category ${i} price must be from 0 to 1000000`,{categoryKey:i});if(a.tiers!=null)if(!a.tiers.length)delete a.tiers;else{if(a.tiers.length>20)throw new d("invalid_operation",`Category ${i} supports at most 20 ticket tiers`);let c=new Set,f=new Set;for(let h of a.tiers){let g=h.id.trim(),u=h.name.normalize("NFKC").trim(),p=u.toLocaleLowerCase("en");if(!g||g.length>160||c.has(g))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${i}`,{categoryKey:i,tierId:g});if(!u||u.length>80||f.has(p))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${i}`,{categoryKey:i,tierName:u});if(!Number.isFinite(h.price)||h.price<0||h.price>1e6)throw new d("invalid_operation",`Ticket tier ${g} price must be from 0 to 1000000`,{categoryKey:i,tierId:g});if(h.restriction!=null&&!_o.has(h.restriction))throw new d("invalid_operation",`Ticket tier ${g} has an unknown restriction`,{categoryKey:i,tierId:g});if(h.buyerMessage!=null){if(h.buyerMessage=h.buyerMessage.normalize("NFKC").trim(),!h.buyerMessage)delete h.buyerMessage;else if(h.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${g} buyer guidance must be at most 240 characters`,{categoryKey:i,tierId:g})}if(h.currency!=null&&(h.currency=h.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(h.currency)))throw new d("invalid_operation",`Ticket tier ${g} must use a three-letter ISO currency`,{categoryKey:i,tierId:g});if(h.applicability!=null){let y=h.applicability.seatLabels?.map(x=>x.normalize("NFKC").trim()),w=h.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(x=>!x||x.length>160)||new Set(y).size!==y.length)||w&&(!w.length||w.some(x=>!ce.some(b=>b.key===x))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${g} has invalid seat applicability`,{categoryKey:i,tierId:g});h.applicability={...y?{seatLabels:y}:{},...w?{accessibility:[...w]}:{}},!h.applicability.seatLabels&&!h.applicability.accessibility&&delete h.applicability}if(h.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(h.evidence.provenance)||typeof h.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:i,tierId:g});if(h.evidence.sourceDescription=h.evidence.sourceDescription.normalize("NFKC").trim(),!h.evidence.sourceDescription||h.evidence.sourceDescription.length>240||h.evidence.capturedAt!==void 0&&(h.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(h.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${g} has invalid evidence provenance`,{categoryKey:i,tierId:g})}c.add(g),f.add(p)}}}return n}function Oo(t,e){let r=new Set,n=structuredClone(t.categories);for(let o of e.updates){if(r.has(o.categoryKey))throw new d("invalid_operation",`Category ${o.categoryKey} may be updated only once`);r.add(o.categoryKey);let s=n.find(h=>h.key===o.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${o.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:o.categoryKey});let l=structuredClone(o.patch),{tiers:c,...f}=l;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(l,"tiers")&&(c==null?delete s.tiers:s.tiers=c?.map(h=>{let g={...h,id:h.id.trim(),name:h.name.normalize("NFKC").trim()};return h.buyerMessage?.trim()?g.buyerMessage=h.buyerMessage.normalize("NFKC").trim():delete g.buyerMessage,g}))}let a=se(n),i=JSON.stringify(a)!==JSON.stringify(t.categories);return i&&(t.categories=a),{changed:i,categoryKeys:[...r],categories:t.categories}}function Cr(t,e){let r=e.categoryKeys.map(l=>l.trim()),n=t.categories.map(l=>l.key);if(r.length!==n.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:n});let a=new Set(n),i=n.filter(l=>!r.includes(l)),o=r.filter(l=>!a.has(l));if(i.length||o.length)throw new d(o.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:i,unknownCategoryKeys:o});if(r.every((l,c)=>l===n[c]))return{changed:!1,categoryKeys:n,categories:t.categories};let s=new Map(t.categories.map(l=>[l.key,l]));return t.categories=se(r.map(l=>structuredClone(s.get(l)))),{changed:!0,categoryKeys:r,categories:t.categories}}var Rt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function At(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(n=>n+n).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function Po(t,e){let r=At(t),n=At(e);return!r||!n?1/0:(r[0]-n[0])**2+(r[1]-n[1])**2+(r[2]-n[2])**2}var Ao=3600;function jo(t,e,r=Rt){return r.find(a=>t.every(i=>Po(a,i)>=Ao))??r[e%r.length]}function _r(t,e){let r=e?.palette??Rt;if(!t.categories.length)return{changed:[],categories:t.categories};let n=new Map(t.categories.map(o=>[o.key,o.color.toLowerCase()])),a=t.categories.map((o,s)=>({categoryKey:o.key,patch:{color:r[s%r.length]}}));return Oo(t,{updates:a}),{changed:t.categories.map(o=>({key:o.key,from:n.get(o.key),to:o.color})).filter(o=>o.from!==o.to),categories:t.categories}}function Or(t,e){let r=e.color.trim().toLowerCase(),n=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!n||n.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let a=structuredClone(t.categories),i=a.find(l=>l.key===e.categoryKey);if(!i)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});i.color=r,i.referenceCategorySource&&(i.referenceCategorySource.outputColorEvidence="user-confirmed",i.referenceCategorySource.outputColorSourceDescription=n);let o=se(a),s=JSON.stringify(o)!==JSON.stringify(t.categories);return s&&(t.categories=o),{changed:s,category:t.categories.find(l=>l.key===e.categoryKey),categories:t.categories}}function Ro(t,e){let r=new Set(t.categories.map(o=>o.key)),n="";for(let o=0;o<100;o++){let l=e.idFactory("cat").trim();if(l&&!r.has(l)){n=l;break}}if(!n)throw new d("id_generation_failed","Unable to allocate a unique category id");let a={key:n,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(o=>({...o,id:o.id.trim(),name:o.name.normalize("NFKC").trim()}))},i=se([...t.categories,a]);return t.categories=i,{changed:!0,category:i.find(o=>o.key===n),categories:i}}var Fo=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],ko=26;function Mo(t,e,r){let n=(1-Math.abs(2*r-1))*e,a=(t%360+360)%360/60,i=n*(1-Math.abs(a%2-1)),[o,s,l]=a<1?[n,i,0]:a<2?[i,n,0]:a<3?[0,n,i]:a<4?[0,i,n]:a<5?[i,0,n]:[n,0,i],c=r-n/2,f=h=>Math.round((h+c)*255).toString(16).padStart(2,"0");return`#${f(o)}${f(s)}${f(l)}`}function No(t,e,r){let n=o=>t.every(s=>{let l=pt(o,s);return l==null||l>=ko}),a=o=>{let s=Ne(o,"#12151d"),l=Ne(o,"#ffffff");return(s??0)>=3||(l??0)>=3},i=e.find(o=>n(o)&&a(o));if(i)return i;for(let o=0;o<360;o+=12)for(let s of[.52,.44,.6]){let l=Mo(o,.62,s);if(n(l)&&a(l))return l}return r}function Ft(t,e){let r=ge.find(a=>a.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function To(t){let e=new Map;for(let r of T(t))for(let n of r.objects){let a=ge.find(o=>o.objectType===n.type);if(!a)continue;let i=new Set;if(n.type==="row"||n.type==="table")for(let o of he(n).keys())i.add(o);else"categoryKey"in n&&n.categoryKey&&i.add(n.categoryKey);for(let o of i){let s=e.get(o)??new Set;s.add(a.objectType),e.set(o,s)}}return e}function Pr(t,e,r,n){let a=r,i=To(t),o=h=>{let g=i.get(h);return!g||g.size===0||g.size===1&&g.has(a)},s=t.categories.find(h=>h.key===e);if(s&&o(s.key))return s.key;if(!s){let h=t.categories.find(g=>{let u=i.get(g.key);return u?.size===1&&u.has(a)});if(h)return h.key}let l=s;if(!l)return jt(t,r,void 0,n);let c=Ft(l.label,r),f=t.categories.find(h=>h.label.toLowerCase()===c.toLowerCase()&&o(h.key));return f?f.key:jt(t,r,l,n)}function jt(t,e,r,n){let a=ge.find(p=>p.objectType===e),i=e==="gaArea"?"General Admission":a.creationWord,o=r?Ft(r.label,e):i,s=n.palette??Fo,l=t.categories.map(p=>p.color),c=n.suggestColor?.(l.map(p=>p.toLowerCase()))??jo(l,t.categories.length),f=No(l,s,c),h=new Set(t.categories.map(p=>p.label.toLowerCase())),g=o;for(let p=2;h.has(g.toLowerCase());p+=1)g=`${o} ${p}`;let u=Ro(t,{label:g,color:f,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:n.idFactory});return t.categories=u.categories,u.category.key}function Lo(t,e){let r=new Set;for(let n of T(t))for(let a of n.objects)"categoryKey"in a&&a.categoryKey===e&&r.add(a.id),(a.type==="row"||a.type==="table")&&a.overrides?.some(i=>i.categoryKey===e)&&r.add(a.id);return[...r]}function Ar(t,e){let r=t.categories.find(i=>i.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let n=Lo(t,e.categoryKey);if(n.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:n});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let a=se(t.categories.filter(i=>i.key!==e.categoryKey));return t.categories=a,{changed:!0,categoryKey:e.categoryKey,categories:a}}var Ko=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],kt=.7,Mt=1.6;function kr(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let n=JSON.stringify(t.theme??null),a={...t.theme??{}};for(let i of Ko){let o=r[i];o===null?delete a[i]:o!==void 0&&(a[i]=N(o,`Theme ${i}`))}if(r.fontFamily===null)delete a.fontFamily;else if(r.fontFamily!==void 0){let i=r.fontFamily.normalize("NFKC").trim();if(!i||i.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");a.fontFamily=i}if(r.seatScale===null)delete a.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<kt||r.seatScale>Mt)throw new d("invalid_operation",`Theme seatScale must be from ${kt} to ${Mt}`);a.seatScale=r.seatScale}if(r.logoUrl===null)delete a.logoUrl;else if(r.logoUrl!==void 0){let i=r.logoUrl.trim();if(!/^(https:\/\/|data:image\/)/.test(i)||i.length>2e6)throw new d("invalid_operation","Theme logoUrl must be an https or data:image reference");a.logoUrl=i}if(r.brandName===null)delete a.brandName;else if(r.brandName!==void 0){let i=r.brandName.normalize("NFKC").trim();if(!i||i.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");a.brandName=i}return r.hideBadge===null||r.hideBadge===!1?delete a.hideBadge:r.hideBadge===!0&&(a.hideBadge=!0),t.theme=Object.keys(a).length?a:void 0,{changed:JSON.stringify(t.theme??null)!==n,theme:t.theme??null}}function Mr(t,e){let r=e.url===null?null:e.url.trim();if(r!==null&&(!/^(https:\/\/|data:image\/)/.test(r)||r.length>2e6))throw new d("invalid_operation","View-from-seat photo must be an https or data:image reference");let n=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(h=>h.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let l=(s.viewFromSeatUrl??void 0)===n,c=n?e.metadata===null?void 0:e.metadata??(l?s.viewFromSeatMeta:void 0):void 0,f=!l||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(c??null);return s.viewFromSeatUrl=n,s.viewFromSeatMeta=c,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let a=(t.viewFromSeatUrl??void 0)===n,i=n?e.metadata===null?void 0:e.metadata??(a?t.viewFromSeatMeta:void 0):void 0,o=!a||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(i??null);return t.viewFromSeatUrl=n,t.viewFromSeatMeta=i,{changed:o,scope:"venue",url:t.viewFromSeatUrl??null}}function Nr(t,e){let r=be(t,e.floorId),n=st(r),a=e.placement==="auto"||e.placement==null?"rear":e.placement,i=96;return a==="front"?{x:n.x+n.width/2,y:n.y-i-e.height/2}:a==="left"?{x:n.x-i-e.width/2,y:n.y+n.height/2}:a==="right"?{x:n.x+n.width+i+e.width/2,y:n.y+n.height/2}:{x:n.x+n.width/2,y:n.y+n.height+i+e.height/2}}function Se(t,e){F(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let n=e.endAngle-e.startAngle;if(Math.abs(n)<5||Math.abs(n)>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 a=e.fit??"seat-pitch";if(a==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let i=e.taperDegrees??0,o=e.skewDegrees??0;if(!r(i,o)||Math.abs(i)>120||Math.abs(o)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let c=v(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:a,facing:e.facing??"inward",taperDegrees:i,skewDegrees:o,aisleGaps:s,rowLabelStart:e.rowLabelStart??c,seatLabelStart:e.seatLabelStart??1}}function Go(t,e,r){let n=r*J;return{x:t.x+e*Math.sin(n),y:t.y+e*Math.cos(n)}}function Do(t,e,r,n){let a=Math.abs(n-r)*J,i=[["left",.25],["center",.5],["right",.75]].flatMap(([c,f])=>{let h=t.aisleGaps[c];if(!h)return[];let g=h/e/a/2;return[[Math.max(0,f-g),Math.min(1,f+g)]]}).sort((c,f)=>c[0]-f[0]),o=[];for(let c of i){let f=o[o.length-1];f&&c[0]<=f[1]?f[1]=Math.max(f[1],c[1]):o.push([...c])}let s=[],l=0;for(let c of o)c[0]-l>1e-6&&s.push([l,c[0]]),l=Math.max(l,c[1]);return 1-l>1e-6&&s.push([l,1]),s.filter(([c,f])=>e*a*(f-c)>=t.seatPitch*.75)}function $o(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let n=e-r,a=t.reduce((l,c)=>l+c,0),i=t.map(l=>n*l/a),o=i.map(l=>2+Math.floor(l)),s=e-o.reduce((l,c)=>l+c,0);return i.map((l,c)=>({index:c,fraction:l-Math.floor(l)})).sort((l,c)=>c.fraction-l.fraction||l.index-c.index).forEach(({index:l})=>{s-- >0&&o[l]++}),o}function ve(t,e,r){let n=[];for(let a=0;a<t.rowCount;a++){let i=t.rowCount===1?0:a/(t.rowCount-1),o=t.innerRadius+a*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,l=t.startAngle+s*t.taperDegrees*i+t.skewDegrees*i,c=t.endAngle-s*t.taperDegrees*i+t.skewDegrees*i;if(Math.sign(c-l)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(c-l)<5)throw new d("invalid_operation",`Arc/Fan taper collapses row ${a+1} below a 5\xB0 sweep`);let f=Do(t,o,l,c);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${a+1}`);t.facing==="outward"&&(f=f.slice().reverse());let h=f.map(([p,y])=>o*Math.abs(c-l)*J*(y-p)),g=t.fit==="fixed-count"?$o(h,t.seatsPerRow):h.map(p=>Math.max(2,Math.round(p/t.seatPitch)+1)),u=t.seatLabelStart;f.forEach(([p,y],w)=>{let x=l+(c-l)*p,b=l+(c-l)*y;t.facing==="outward"&&([x,b]=[b,x]);let m=g[w];if(m>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let C=Math.abs(b-x)*J/(m-1),I=2*o*Math.sin(C/2),S={type:"row",id:r(a,w),label:$(t.rowLabelStart+a),origin:Go(t.center,o,x),rotation:-x,curve:b-x,seatCount:m,seatSpacing:I,categoryKey:t.categoryKey,seatLabelStart:u,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:a,segmentIndex:w}};n.push(S),u+=m})}return n}function Nt(t,e){let r=Se(t,e),n=v(t,e.floorId),a=ve(r,"preview-arc-fan",(l,c)=>`preview-fan-${l}-${c}`),i=a.map(l=>l.seatSpacing),o=Math.max(...i.map(l=>Math.abs(l-r.seatPitch))),s=[];return o>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${o.toFixed(1)} chart units`),a.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:n.floorId,rows:a,logicalRowCount:r.rowCount,rowSegmentCount:a.length,totalSeats:a.reduce((l,c)=>l+c.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...i),maxSeatSpacing:Math.max(...i),maxPitchDeviation:o,aisleCount:Object.values(r.aisleGaps).filter(l=>l>0).length,warnings:s}}function Gr(t,e){let r=Se(t,e),n=v(t,e.floorId),a=new Set,i=j(t,"fan",e.idFactory,a),o=ve(r,i,()=>j(t,"r",e.idFactory,a)),s=Nt(t,e),l=null,c=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(c){if(c.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let h=Y(o);h&&(l=j(t,"sec",e.idFactory,a),f={type:"section",id:l,label:c,outline:h,arcFanGroupId:i})}return n.objects.push(...o,...f?[f]:[]),{floorId:n.floorId,rowIds:o.map(h=>h.id),sectionId:l,groupId:i,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 Eo(t,e){let r=v(t,e.floorId),n=r.objects.filter(h=>h.type==="row"&&h.arcFanGeneration?.groupId===e.groupId);if(!n.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let a=n[0].arcFanGeneration,i=h=>{let g=h.arcFanGeneration;return JSON.stringify({center:g.center,innerRadius:g.innerRadius,rowCount:g.rowCount,rowGap:g.rowGap,startAngle:g.startAngle,endAngle:g.endAngle,seatPitch:g.seatPitch,fit:g.fit,seatsPerRow:g.seatsPerRow,facing:g.facing,taperDegrees:g.taperDegrees,skewDegrees:g.skewDegrees,aisleGaps:g.aisleGaps,rowLabelStart:g.rowLabelStart,seatLabelStart:g.seatLabelStart})};if(n.some(h=>i(h)!==i(n[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let o=r.objects.find(h=>h.type==="section"&&h.arcFanGroupId===e.groupId),s={floorId:r.floorId,center:{...a.center},innerRadius:a.innerRadius,rowCount:a.rowCount,rowGap:a.rowGap,startAngle:a.startAngle,endAngle:a.endAngle,seatPitch:a.seatPitch,fit:a.fit,seatsPerRow:a.seatsPerRow,facing:a.facing,taperDegrees:a.taperDegrees,skewDegrees:a.skewDegrees,aisleGaps:{...a.aisleGaps},categoryKey:n[0].categoryKey,rowLabelStart:a.rowLabelStart,seatLabelStart:a.seatLabelStart,sectionLabel:o?.label},l=Se(t,s),c=new Set(ve(l,e.groupId,(h,g)=>`${h}:${g}`).map(h=>`${h.arcFanGeneration.rowIndex}:${h.arcFanGeneration.segmentIndex}`)),f=new Set(n.map(h=>`${h.arcFanGeneration.rowIndex}:${h.arcFanGeneration.segmentIndex}`));if(c.size!==f.size||[...c].some(h=>!f.has(h)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function Dr(t,e){Eo(t,{floorId:e.floorId,groupId:e.groupId});let r=Se(t,e),n=v(t,e.floorId),a=n.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),i=n.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),o=new Map(a.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,l=ve(r,e.groupId,(y,w)=>o.get(`${y}:${w}`)??j(t,"r",e.idFactory,s)),c=Nt(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),h=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let y=Y(l);y&&(h={type:"section",id:i?.id??j(t,"sec",e.idFactory,s),label:f,outline:y,arcFanGroupId:e.groupId})}let g=new Set([...a.map(y=>y.id),...i?[i.id]:[]]),u=Math.min(...n.objects.map((y,w)=>g.has(y.id)?w:1/0)),p=n.objects.filter(y=>!g.has(y.id));return p.splice(Number.isFinite(u)?u:p.length,0,...l,...h?[h]:[]),n.objects.splice(0,n.objects.length,...p),{floorId:n.floorId,rowIds:l.map(y=>y.id),sectionId:h?.id??null,groupId:e.groupId,logicalRowCount:c.logicalRowCount,rowSegmentCount:c.rowSegmentCount,totalSeats:c.totalSeats,innerRadius:c.innerRadius,outerRadius:c.outerRadius,minSeatSpacing:c.minSeatSpacing,maxSeatSpacing:c.maxSeatSpacing,maxPitchDeviation:c.maxPitchDeviation,aisleCount:c.aisleCount,warnings:c.warnings}}function zo(t){let e=new Set(V(t).filter(n=>n.type==="row"||n.type==="table"||n.type==="booth").map(n=>n.label).filter(n=>typeof n=="string")),r=0;return()=>{for(;e.has($(r));)r+=1;let n=$(r);return e.add(n),r+=1,n}}function Tt(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 Jr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,n=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(n)||n<=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 a=v(t,e.floorId),i=new Set,o=zo(t),s=$e(e.rotation??0),l=e.curve??0,c=e.style,f=c?j(t,"rowblock",e.idFactory,i):void 0,h=c?Tt({style:c,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:n,curve:l}):void 0,g={x:Math.cos(s*B),y:Math.sin(s*B)},u={x:-g.y,y:g.x},p=Array.from({length:e.rowCount},(x,b)=>{let m=c==="intertwined"&&b%2===1?n/2:0,C={type:"row",id:j(t,"r",e.idFactory,i),label:o(),origin:{x:e.origin.x+u.x*b*r+g.x*m,y:e.origin.y+u.y*b*r+g.y*m},rotation:s,curve:l,seatCount:e.seatsPerRow,seatSpacing:n,categoryKey:e.categoryKey};return c&&f&&h&&(C.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:c,rowIndex:b,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:r,seatSpacing:n,curve:l,signature:h}),C});a.objects.push(...p);let y=null,w=e.sectionLabel?.trim();if(w){let x=Y(p);if(x){let b={type:"section",id:j(t,"sec",e.idFactory,i),label:w,outline:x};a.objects.push(b),y=b.id}}return{floorId:a.floorId,rowIds:p.map(x=>x.id),sectionId:y,createdIds:[...p.map(x=>x.id),...y?[y]:[]]}}function Lt(t,e){let r=new Set(V(t).filter(a=>a.type==="row"||a.type==="table"||a.type==="booth").map(a=>a.label).filter(a=>typeof a=="string")),n=1;return()=>{for(;r.has(`${e}${n}`);)n+=1;let a=`${e}${n}`;return r.add(a),n+=1,a}}function Bo(t,e){let r=new Set(V(t).filter(a=>a.type==="gaArea").map(a=>a.label));if(!r.has(e))return e;let n=2;for(;r.has(`${e} ${n}`);)n+=1;return`${e} ${n}`}var Uo=456;function Jo(t){let e=Math.sqrt(Math.max(1,t)*Uo);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function Hr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new d("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","GA area center must be finite");let r=v(t,e.floorId),n=new Set,{width:a,height:i}=Jo(e.capacity),o=Bo(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:j(t,"ga",e.idFactory,n),label:o,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-a/2,y:e.center.y-i/2},{x:e.center.x+a/2,y:e.center.y-i/2},{x:e.center.x+a/2,y:e.center.y+i/2},{x:e.center.x-a/2,y:e.center.y+i/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:o,createdIds:[s.id]}}function qr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,n=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(n)||n<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 a=v(t,e.floorId),i=new Set,o=Lt(t,"T"),s=[];for(let l=0;l<e.tableRows;l+=1)for(let c=0;c<e.tableColumns;c+=1)s.push({type:"table",id:j(t,"t",e.idFactory,i),label:o(),center:{x:e.center.x+(c-(e.tableColumns-1)/2)*r,y:e.center.y+(l-(e.tableRows-1)/2)*n},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 a.objects.push(...s),{floorId:a.floorId,tableIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Xr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,n=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(n)||n<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 a=v(t,e.floorId),i=new Set,o=Lt(t,"B"),s=[];for(let l=0;l<e.boothRows;l+=1)for(let c=0;c<e.boothColumns;c+=1)s.push({type:"booth",id:j(t,"booth",e.idFactory,i),label:o(),center:{x:e.center.x+(c-(e.boothColumns-1)/2)*r,y:e.center.y+(l-(e.boothRows-1)/2)*n},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return a.objects.push(...s),{floorId:a.floorId,boothIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Vr(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2||n.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==n.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 a=n.map(g=>r.objects.find(u=>u.type==="row"&&u.id===g)),i=n.filter((g,u)=>!a[u]);if(i.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:i});let o=a,s=o.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 l=(e.displayLabel??o[0].displayLabel??o[0].label).normalize("NFKC").trim();if(!l||l.length>80)throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let c=new Set(r.objects.flatMap(g=>g.type==="row"?[g.segmentedRow?.groupId,g.rowBlockGeneration?.groupId].filter(u=>!!u):[])),f="";for(let g=0;g<100;g+=1){let u=e.idFactory("rowgroup");if(u&&!c.has(u)){f=u;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let h=o[0];return o.forEach((g,u)=>{g.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:u,componentCount:o.length,boundaryBefore:u===0?"start":e.boundaries[u-1],displayLabel:l,...h.displayType?{displayType:h.displayType}:{},...h.labelPresentation?{labelPresentation:structuredClone(h.labelPresentation)}:{},...h.viewFromSeatUrl?{viewFromSeatUrl:h.viewFromSeatUrl}:{},...h.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(h.viewFromSeatMeta)}:{},...h.confidenceEvidence?{confidenceEvidence:structuredClone(h.confidenceEvidence)}:{}}}),{floorId:r.floorId,groupId:f,rowIds:n,changed:!0}}function Yr(t,e){let r=v(t,e.floorId),n=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),a=e.groupId??n?.segmentedRow?.groupId;if(!a)throw new d("object_not_found","The segmented row does not exist on the selected floor");let i=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===a);if(!i.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let o=i.sort((s,l)=>s.segmentedRow.componentIndex-l.segmentedRow.componentIndex).map(s=>s.id);for(let s of i)delete s.segmentedRow;return{floorId:r.floorId,groupId:a,rowIds:o,changed:!0}}function Zr(t,e){let r=v(t,e.floorId),n=r.objects.filter(o=>o.type==="row"&&o.segmentedRow?.groupId===e.groupId).sort((o,s)=>o.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(n.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!==n.length-1||e.boundaries.some(o=>o!=="continuous"&&o!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let a=e.displayLabel?.normalize("NFKC").trim();if(a!==void 0&&(!a||a.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let i=JSON.stringify(n.map(o=>o.segmentedRow));return n.forEach((o,s)=>{let l=o.segmentedRow,c=l.viewFromSeatUrl;a!==void 0&&(l.displayLabel=a),e.boundaries&&s>0&&(l.boundaryBefore=e.boundaries[s-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!==c&&delete l.viewFromSeatMeta}),{floorId:r.floorId,groupId:e.groupId,rowIds:n.map(o=>o.id),changed:JSON.stringify(n.map(o=>o.segmentedRow))!==i}}function Wr(t,e){let r=v(t,e.floorId),n=r.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,K)=>O.rowBlockGeneration.rowIndex-K.rowBlockGeneration.rowIndex),a=n[0]?.rowBlockGeneration;if(!a||n.length!==a.rowCount||n.some((O,K)=>{let R=O.rowBlockGeneration;return R.kind!=="row-block-v1"||R.rowIndex!==K||R.signature!==a.signature||JSON.stringify(R)!==JSON.stringify({...a,rowIndex:K})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let i=JSON.stringify(n),o=e.style??a.style,s=e.rowCount??a.rowCount,l=e.seatsPerRow??a.seatsPerRow,c=e.rowGap??a.rowGap,f=e.seatSpacing??a.seatSpacing,h=e.curve??a.curve,g=Number.isFinite(e.rotation??a.rotation)?$e(e.rotation??a.rotation):e.rotation??a.rotation,u=e.origin?{...e.origin}:{...a.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(l)||l<1||l>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![c,f].every(O=>Number.isFinite(O)&&O>0)||!Number.isFinite(h)||!Number.isFinite(g)||!Number.isFinite(u.x)||!Number.isFinite(u.y))throw new d("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let p=Tt({style:o,origin:u,rotation:g,rowCount:s,seatsPerRow:l,rowGap:c,seatSpacing:f,curve:h}),y={x:Math.cos(g*B),y:Math.sin(g*B)},w={x:-y.y,y:y.x},x=new Map(n.map(O=>[O.rowBlockGeneration.rowIndex,O])),b=new Set,m=new Set(r.objects.filter(O=>O.type==="row").filter(O=>!n.includes(O)).map(O=>O.label)),C=r.objects.filter(O=>O.type==="row").length,I=()=>{for(;m.has($(C));)C+=1;let O=$(C);return m.add(O),C+=1,O},S=[],A=[];for(let O=0;O<s;O+=1){let K=o==="intertwined"&&O%2===1?f/2:0,R=x.get(O);R||(R={type:"row",id:j(t,"r",e.idFactory,b),label:I(),origin:{...u},rotation:g,curve:h,seatCount:l,seatSpacing:f,categoryKey:n[0].categoryKey},A.push(R.id)),R.origin={x:u.x+w.x*O*c+y.x*K,y:u.y+w.y*O*c+y.y*K},R.rotation=g,R.curve=h,R.seatCount=l,R.seatSpacing=f,delete R.path,delete R.arcFanGeneration,R.overrides&&(R.overrides=R.overrides.filter(Pe=>Pe.index<l),R.overrides.length||delete R.overrides),R.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:o,rowIndex:O,rowCount:s,seatsPerRow:l,origin:{...u},rotation:g,rowGap:c,seatSpacing:f,curve:h,signature:p},S.push(R)}let H=n.slice(s).map(O=>O.id),U=Math.min(...n.map(O=>r.objects.indexOf(O))),q=new Set(n.map(O=>O.id)),E=r.objects.filter(O=>!q.has(O.id));return E.splice(U,0,...S),r.objects.splice(0,r.objects.length,...E),{floorId:r.floorId,groupId:e.groupId,rowIds:S.map(O=>O.id),createdRowIds:A,removedRowIds:H,changed:i!==JSON.stringify(S)||A.length>0||H.length>0}}var Ho=300;function qo(t,e){return t.filter(r=>(r.type==="row"||r.type==="table"||r.type==="booth"||r.type==="gaArea")&&!(r.type==="row"&&r.referenceScan?.assetId===e))}function Xo(t,e,r,n){let a=t.sectionId?e.find(s=>s.type==="section"&&s.id===t.sectionId):void 0;if(a){let s=qo(e,r).filter(l=>L(M(l),a.outline,a.holes));if(s.length)return{skip:{sectionId:a.id,name:t.name,reason:"section_not_empty",objectIds:s.map(l=>l.id)},rows:[],seats:0}}let i=[],o=0;for(let s of t.rows){let l=Math.min(Ho,Math.max(1,Math.round(s.seatCount)));if(!Number.isFinite(l)||l<1)continue;let c=s.end.x-s.start.x,f=s.end.y-s.start.y,h=Math.hypot(c,f),g=l>1&&h>0?h/(l-1):n>0?n:24;if(!Number.isFinite(g)||g<=0)continue;let u=h>0?Math.atan2(f,c)*180/Math.PI:0;i.push({label:$(i.length),origin:{x:s.start.x,y:s.start.y},rotation:u,seatCount:l,seatSpacing:g}),o+=l}return{skip:null,rows:i,seats:o}}function ni(t,e,r){F(t,r.categoryKey);let n=v(t,r.floorId),a=e.assetId,i=[],o=n.objects.filter(g=>g.type==="row"&&g.referenceScan?.assetId===a?(i.push(g.id),!1):!0);n.objects.splice(0,n.objects.length,...o);let s=[],l=[],c=[],f=new Set,h=0;for(let g of e.sections){let u=Xo(g,n.objects,a,e.seatPitch);if(u.skip){l.push(u.skip);continue}let p=u.rows.map(y=>({type:"row",id:j(t,"r",r.idFactory,f),referenceScan:{assetId:a},label:y.label,origin:y.origin,rotation:y.rotation,curve:0,seatCount:y.seatCount,seatSpacing:y.seatSpacing,categoryKey:r.categoryKey}));n.objects.push(...p);for(let y of p)c.push(y.id);s.push({sectionId:g.sectionId,name:g.name,seats:u.seats,rows:p.length}),h+=u.seats}return{floorId:n.floorId,assetId:a,createdRowIds:c,removedRowIds:i,totalSeats:h,perSection:s,skipped:l}}function Kt(t,e){let r=v(t,e.floorId),n=[...new Set(e.objectIds)];if(!n.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let a=n.map(u=>r.objects.find(p=>(p.type==="table"||p.type==="booth")&&p.id===u)),i=n.filter((u,p)=>!a[p]);if(i.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:i});let o=a[0].type;if(a.some(u=>u.type!==o))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[u,p,y]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(p)||p<1||p>y)throw new d("invalid_operation",`${u} must be a whole number from 1 to ${y}`);for(let[u,p]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(p)||p<30||p>2e3)throw new d("invalid_operation",`${u} must be from 30 to 2000 chart units`);let s=e.rows*e.columns;if(s<2)throw new d("invalid_operation","Choose at least two grid cells");let l=n.length*(s-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let c=a.reduce((u,p)=>u+(p.type==="table"?p.seatCount:1),0),h=(t.floors?.length?t.floors.flatMap(u=>u.objects):t.objects).reduce((u,p)=>u+(p.type==="row"||p.type==="table"?p.seatCount:p.type==="gaArea"?Math.max(0,Math.floor(p.capacity)):p.type==="booth"?1:0),0),g=c*(s-1);if(h+g>W)throw new d("invalid_operation",`Grid inventory would exceed the ${W} unit event limit`);return{target:r,sources:a,preview:{floorId:r.floorId,kind:o,sourceIds:n,sourceCount:n.length,cells:s,createdCount:l,addedInventory:g,resultingInventory:h+g,provenanceRemovedCount:a.filter(u=>!!u.referenceInventorySource).length*(s-1)}}}function si(t,e){return Kt(t,e).preview}function li(t,e){let{target:r,sources:n,preview:a}=Kt(t,e),i=new Set,o=new Set((t.floors?.length?t.floors.flatMap(f=>f.objects):t.objects).flatMap(f=>"label"in f&&f.label?[f.label]:[])),s=[],l=(f,h)=>{let g=Math.max(2,h),u=y=>{let w=`-${y}`;return`${f.slice(0,Math.max(1,80-w.length))}${w}`},p=u(g);for(;o.has(p);)p=u(++g);return o.add(p),p},c=1;for(let f=0;f<e.rows;f++)for(let h=0;h<e.columns;h++)if(!(f===0&&h===0)){c+=1;for(let g of n){let u=structuredClone(g);u.id=j(t,u.type,e.idFactory,i),u.label=l(g.label,c),u.center={x:g.center.x+h*e.stepX,y:g.center.y+f*e.stepY},delete u.referenceInventorySource,s.push(u)}}return r.objects.push(...s),{...a,createdIds:s.map(f=>f.id)}}function Vo(t,e){let r=t?{...t}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=N(e.color,"Seat label color")),r.size===void 0&&r.color===void 0?void 0:r}var Yo=new Set(ce.map(t=>t.key));function xe(t){return`${t.rowId}:${t.index}`}function ui(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",n=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(n)||n<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:n}}function Zo(t){if(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,t.accessible&&!t.accessibility?.length&&(t.accessibility=["wheelchair"]),delete t.accessible,t.wheelchairSpaceType&&!t.accessibility?.includes("wheelchair")&&(t.accessibility=["wheelchair",...t.accessibility??[]]),t.accessibility?.length||delete t.accessibility,t.commercial){let e=t.commercial.note?.normalize("NFKC").trim(),r={};typeof t.commercial.restrictedView=="boolean"&&(r.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(r.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(r.premium=t.commercial.premium),e&&(r.note=e),Object.keys(r).length?t.commercial=r: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}function Wo(t){return Object.keys(t).every(e=>e==="index")}function Gt(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let n=v(t,e),a=[],i=new Set,o=new Map;for(let s of r){let l=xe(s);if(i.has(l))continue;i.add(l);let c=n.objects.find(f=>(f.type==="row"||f.type==="table")&&f.id===s.rowId);if(!c)throw new d("object_not_found",`Unknown row or table for seat: ${l}`,{seatId:l,objectId:s.rowId});if(c.type==="table"&&(c.bookAsWhole||c.variableOccupancy))throw new d("invalid_operation",`Table "${c.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:l,tableId:c.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=c.seatCount)throw new d("invalid_operation",c.type==="row"?`Seat index is outside row bounds: ${l}`:`Chair index is outside table bounds: ${l}`,{seatId:l,objectId:s.rowId,index:s.index,seatCount:c.seatCount});a.push({rowId:s.rowId,index:s.index}),o.set(c.id,c)}return{floorId:n.floorId,refs:a,owners:o}}function gi(t,e){let r=Gt(t,e.floorId,e.seats),n=Object.keys(e.patch);if(!n.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&F(t,e.patch.categoryKey),e.patch.accessibility){let i=e.patch.accessibility.filter(o=>!Yo.has(o));if(i.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:i})}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 i of r.refs){let o=r.owners.get(i.rowId)?.overrides?.find(c=>c.index===i.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??o?.wheelchairSpaceType,l=e.patch.skip===null?!1:e.patch.skip??o?.skip??!1;if(s&&l)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:xe(i)})}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");for(let i of["dx","dy"]){let o=e.patch[i];if(o!=null&&!Number.isFinite(o))throw new d("invalid_operation",`${i} must be finite`,{[i]:o})}e.patch.labelStyle!=null&&ee(e.patch.labelStyle,"Seat");let a=!1;return r.refs.forEach((i,o)=>{let s=r.owners.get(i.rowId),l=JSON.stringify(s.overrides??[]),c=s.overrides??(s.overrides=[]),f=c.find(g=>g.index===i.index);f||(f={index:i.index},c.push(f));let h=f.viewFromSeatUrl;for(let g of n){let u=e.patch[g];if(g==="wheelchairSpaceType"&&u==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(p=>p!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(u==null)delete f[g];else if(g==="accessibility")f.accessibility=[...new Set(u)],delete f.accessible;else if(g==="commercial")f.commercial={...f.commercial,...u};else if(g==="labelStyle"){let p=Vo(f.labelStyle,u);p?f.labelStyle=p:delete f.labelStyle}else Object.assign(f,{[g]:u})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==h&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${o+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${o+1}`),Zo(f),Wo(f)&&(s.overrides=c.filter(g=>g!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==l&&(a=!0)}),{floorId:r.floorId,changed:a,seatIds:r.refs.map(xe)}}function hi(t,e){let r=Gt(t,e.floorId,e.seats),n=!1;for(let[a,i]of r.owners){if(!i.overrides?.length)continue;let o=new Set(r.refs.filter(l=>l.rowId===a).map(l=>l.index)),s=i.overrides.filter(l=>!o.has(l.index));s.length!==i.overrides.length&&(n=!0),i.overrides=s,i.overrides.length||delete i.overrides}return{floorId:r.floorId,changed:n,seatIds:r.refs.map(xe)}}function yi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)],a=n.map(b=>r.objects.find(m=>m.type==="row"&&m.id===b)),i=n.filter((b,m)=>!a[m]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});if(e.patch.categoryKey!==void 0&&F(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let b=e.patch.seatNumbering,m=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(b.scheme!==void 0&&!m.includes(b.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${b.scheme}. Expected one of ${m.join(", ")}.`);if(b.prefix!==void 0&&(typeof b.prefix!="string"||b.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(b.endAt!==void 0&&b.endAt!==null&&(!Number.isInteger(b.endAt)||b.endAt<0||b.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:o,labelPosition:s,labelRotation:l,labelStyleShape:c,displayLabel:f,displayType:h,...g}=e.patch,u=f===void 0?{}:{displayLabel:f},p=Q(u,"Row"),y=h===void 0?void 0:Le(h,"Row");if(o!==void 0&&ee(o,"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(l!=null&&(!Number.isFinite(l)||l<-180||l>180))throw new d("invalid_operation","Row labelRotation must be a number from -180 to 180");if(c!==void 0&&c!=="plain"&&c!=="pill")throw new d("invalid_operation","Row labelStyleShape must be plain or pill");g.labelPresentation!==void 0&&me(g.labelPresentation,"Row");let w=b=>JSON.stringify({origin:b.origin,rotation:b.rotation,curve:b.curve,seatCount:b.seatCount,seatSpacing:b.seatSpacing,path:b.path??null}),x=!1;for(let b of a){let m=JSON.stringify(b),C=w(b),I=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?M(b):null;if(Object.assign(b,structuredClone(g)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(S=>S.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),I){let S=M(b);b.origin={x:b.origin.x+I.x-S.x,y:b.origin.y+I.y-S.y}}if(JSON.stringify(b)!==m&&(x=!0),w(b)!==C&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),o!==void 0){let S=JSON.stringify(b.labelPresentation??null),A=ye(b.labelPresentation,o);A?b.labelPresentation=A:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(s!==void 0){let S=JSON.stringify(b.labelPresentation??null),A=b.labelPresentation?structuredClone(b.labelPresentation):{};A.positionPreset=s,A.visible=s!=="none",delete A.position,b.labelPresentation=A,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(l!==void 0||c!==void 0){let S=JSON.stringify(b.labelPresentation??null),A=b.labelPresentation?structuredClone(b.labelPresentation):{};l===null?delete A.rotation:l!==void 0&&(A.rotation=l),c!==void 0&&(A.style=c),b.labelPresentation=A,JSON.stringify(b.labelPresentation??null)!==S&&(x=!0)}if(y!==void 0){let S=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==S&&(x=!0)}if(f!==void 0){let S=b.displayLabel;p?delete b.displayLabel:b.displayLabel=u.displayLabel,b.displayLabel!==S&&(x=!0)}}return{floorId:r.floorId,changed:x,rowIds:n}}var Qo=3;function Ce(t){return(t%360+360)%360}function en(t){let e=t.rotation*B;return{x:Math.cos(e),y:Math.sin(e)}}function tn(t,e){let r=Math.abs(Ce(t-e));return r>180&&(r=360-r),r}function te(t,e,r){return(t.x-e.x)*r.x+(t.y-e.y)*r.y}function Dt(t){let e=0,r=0;for(let a of t){let i=2*a.rotation*B;e+=Math.cos(i),r+=Math.sin(i)}let n=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(n),y:Math.sin(n)}}function on(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let n=a=>({x:a.x+e,y:a.y+r});t.path={start:n(t.path.start),control1:n(t.path.control1),control2:n(t.path.control2),end:n(t.path.end)}}}function $t(t,e){let r=Dt(t),n={x:-r.y,y:r.x},a=M(t[0]),i=t.map(l=>({row:l,coord:te(M(l),a,n)})).sort((l,c)=>l.coord-c.coord),o=i[0].coord,s=!1;return i.forEach((l,c)=>{let f=o+c*e-l.coord;Math.abs(f)>1e-6&&(on(l.row,n.x*f,n.y*f),delete l.row.arcFanGeneration,delete l.row.rowBlockGeneration,s=!0)}),s}function nn(t,e){let r={x:-e.y,y:e.x},n=M(t[0]),a=t.map(o=>te(M(o),n,r)).sort((o,s)=>o-s);if(a.length<2)return 28;let i=(a[a.length-1]-a[0])/(a.length-1);return i>.5?i:28}function rn(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=ke(t),r=e[0],n=e[e.length-1],a=n.x-r.x,i=n.y-r.y,o=Math.hypot(a,i);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,o/(t.seatCount-1))),o>1e-6&&(t.rotation=Ce(Math.atan2(i,a)/B)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function an(t,e){let r=new Set(t.filter(n=>n.type==="row").map(n=>n.label));for(let n=2;n<1e4;n++){let a=`${e}${n}`.slice(0,80);if(!r.has(a))return a}return`${e}-${Date.now().toString(36)}`}function wi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2)throw new d("invalid_operation","Select at least two rows to merge");let a=n.map(I=>r.objects.find(S=>S.type==="row"&&S.id===I)),i=n.filter((I,S)=>!a[S]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a,s=o.filter(I=>I.path||I.curve!==0);if(s.length)throw new d("invalid_operation","Only straight rows can be merged \u2014 straighten the rows first, then merge.",{rowIds:s.map(I=>I.id)});let l=o[0],c=o.find(I=>tn(I.rotation,l.rotation)>Qo);if(c)throw new d("invalid_operation","Rows must be parallel to merge \u2014 they point in different directions.",{rowIds:[l.id,c.id]});let f=en(l),h={x:-f.y,y:f.x},g=Math.max(8,l.seatSpacing*.6),u=o.find(I=>Math.abs(te(I.origin,l.origin,h))>g);if(u){let I=Math.round(Math.abs(te(u.origin,l.origin,h)));throw new d("invalid_operation",`Rows must lie on the same line to merge \u2014 a selected row is offset ${I} units from the first.`,{rowIds:[l.id,u.id]})}let p=o.slice().sort((I,S)=>te(I.origin,l.origin,f)-te(S.origin,l.origin,f)),y=p.reduce((I,S)=>I+S.seatCount,0);if(y>300)throw new d("invalid_operation",`A merged row would have ${y} seats, over the 300-seat row limit. Merge fewer rows.`);let w=p[0],x=[],b=0;for(let I of p){if(I.overrides)for(let S of I.overrides)x.push({...structuredClone(S),index:S.index+b});b+=I.seatCount}w.seatCount=y,w.curve=0,delete w.path,x.length?w.overrides=x:delete w.overrides,delete w.arcFanGeneration,delete w.rowBlockGeneration;let m=p.slice(1).map(I=>I.id),C=new Set(m);for(let I=r.objects.length-1;I>=0;I--)C.has(r.objects[I].id)&&r.objects.splice(I,1);return{floorId:r.floorId,changed:!0,rowId:w.id,removedRowIds:m,seatCount:y}}function Ii(t,e){let r=v(t,e.floorId),n=r.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!n)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(n.path)throw new d("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[n.id]});let a=n.seatCount,i=e.index;if(!Number.isInteger(i)||i<1||i>a-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${a-1} (the seat where the second row begins)`);let o=ke(n),s=a>1?n.curve/(a-1):0,l=a-i,c={type:"row",id:j(t,"r",e.idFactory,new Set),label:an(r.objects,n.label),origin:{...o[i]},rotation:Ce(n.rotation-s*i),curve:s*(l-1),seatCount:l,seatSpacing:n.seatSpacing,categoryKey:n.categoryKey};if(n.seatNumbering&&(c.seatNumbering=structuredClone(n.seatNumbering)),n.seatLabelStart!=null&&(c.seatLabelStart=n.seatLabelStart),n.commercial&&(c.commercial=structuredClone(n.commercial)),n.viewFromSeatUrl&&(c.viewFromSeatUrl=n.viewFromSeatUrl),n.viewFromSeatMeta&&(c.viewFromSeatMeta=structuredClone(n.viewFromSeatMeta)),n.confidenceEvidence&&(c.confidenceEvidence=structuredClone(n.confidenceEvidence)),n.labelPresentation){let u=structuredClone(n.labelPresentation);delete u.position,c.labelPresentation=u}let f=[],h=[];if(n.overrides)for(let u of n.overrides)u.index<i?f.push(structuredClone(u)):h.push({...structuredClone(u),index:u.index-i});n.seatCount=i,n.curve=s*(i-1),f.length?n.overrides=f:delete n.overrides,delete n.arcFanGeneration,delete n.rowBlockGeneration,h.length&&(c.overrides=h);let g=r.objects.indexOf(n);return r.objects.splice(g+1,0,c),{floorId:r.floorId,changed:!0,rowId:n.id,newRowId:c.id,firstSeatCount:i,secondSeatCount:l,newLabel:c.label}}function Si(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.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 a=n.map(s=>r.objects.find(l=>l.type==="row"&&l.id===s)),i=n.filter((s,l)=>!a[l]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=$t(a,e.gap);return{floorId:r.floorId,changed:o,rowIds:n,gap:e.gap}}function vi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let a=n.map(g=>r.objects.find(u=>u.type==="row"&&u.id===g)),i=n.filter((g,u)=>!a[u]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a,s=()=>JSON.stringify(o.map(g=>[g.origin,g.rotation,g.curve,g.path??null,g.seatSpacing])),l=s();for(let g of o)rn(g);let c=Dt(o),f=Ce(Math.atan2(c.y,c.x)/B);for(let g of o)g.rotation=f;let h=nn(o,c);return $t(o,h),{floorId:r.floorId,changed:s()!==l,rowIds:n,gap:h}}import Be from"polygon-clipping";var Et=100,zt=512,Ue=8192,Yt=64,Bt=1e7,k=1e-7;function Zt(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function Wt(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&Zt(e[0],e[e.length-1]);)e.pop();return e}function le(t,e,r){let n=D(e,r,t);return Math.abs(n)>k?!1:t.x>=Math.min(e.x,r.x)-k&&t.x<=Math.max(e.x,r.x)+k&&t.y>=Math.min(e.y,r.y)-k&&t.y<=Math.max(e.y,r.y)+k}function Qt(t,e,r,n){let a=D(t,e,r),i=D(t,e,n),o=D(r,n,t),s=D(r,n,e);return(a>k&&i<-k||a<-k&&i>k)&&(o>k&&s<-k||o<-k&&s>k)?!0:Math.abs(a)<=k&&le(r,t,e)||Math.abs(i)<=k&&le(n,t,e)||Math.abs(o)<=k&&le(t,r,n)||Math.abs(s)<=k&&le(e,r,n)}function sn(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let n=e+1;n<t.length;n+=1){let a=(n+1)%t.length;if(!(e===n||r===n||a===e)&&Qt(t[e],t[r],t[n],t[a]))return!0}}return!1}function Ut(t,e){return t.some((r,n)=>e.some((a,i)=>Qt(r,t[(n+1)%t.length],a,e[(i+1)%e.length])))}function Je(t,e){return!e.some((r,n)=>le(t,r,e[(n+1)%e.length]))&&L(t,e,void 0)}function Oe(t,e,r){let n=Wt(t);if(n.length<3||n.length>zt||n.some((a,i)=>!Number.isFinite(a.x)||!Number.isFinite(a.y)||Math.abs(a.x)>Bt||Math.abs(a.y)>Bt||Zt(a,n[(i+1)%n.length]))||Math.abs(fe(n))<=k||sn(n))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${zt} finite vertices per ring.`,{gaAreaId:r,ring:e});return n}function ln(t){let e=Oe(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>Yt)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let n=r.map(a=>Oe(a,"cutout",t.id));for(let a=0;a<n.length;a+=1){let i=n[a];if(!i.flatMap((s,l)=>{let c=i[(l+1)%i.length];return[s,{x:(s.x+c.x)/2,y:(s.y+c.y)/2}]}).every(s=>Je(s,e))||Ut(i,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:a});for(let s=a+1;s<n.length;s+=1)if(Ut(i,n[s])||Je(i[0],n[s])||Je(n[s][0],i))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:a})}return{outer:e,holes:n}}function _e(t){return t.map(e=>[e.x,e.y])}function Jt(t){return Wt(t.map(([e,r])=>({x:e,y:r})))}function Ht(t){return Math.abs(t.reduce((e,r,n)=>{let a=t[(n+1)%t.length];return e+r[0]*a[1]-a[0]*r[1]},0))/2}function cn(t){return t.reduce((e,r)=>e+(Ht(r[0]??[])-r.slice(1).reduce((n,a)=>n+Ht(a),0)),0)}function He(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(He).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${He(e[r])}`).join(",")}}`}function qt(t,e,r){let n=t[e];if(n===void 0)return null;let a=n.normalize("NFKC").trim();if(!a||a!==n||a.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return a}function Xt(t){return He({categoryKey:t.categoryKey,displayLabel:qt(t,"displayLabel",80),displayType:qt(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Vt(t,e){let r=Math.min(...t.points.map(a=>a.y)),n=Math.min(...t.points.map(a=>a.x));return[r,n,e]}function dn(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function eo(t,e){let r=v(t,e.floorId),n=[...new Set(e.gaAreaIds)];if(n.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(n.length>Et)throw new d("invalid_operation",`Join Areas supports at most ${Et} areas at once`);let a=n.map(_=>r.objects.find(P=>P.type==="gaArea"&&P.id===_)),i=n.filter((_,P)=>!a[P]);if(i.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:i});let o=a;F(t,o[0].categoryKey);let s=Xt(o[0]),l=o.find(_=>Xt(_)!==s);if(l)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[o[0].id,l.id]});let c=re(t).objectToSection,f=c.get(o[0].id)??"__ungrouped__",h=o.find(_=>(c.get(_.id)??"__ungrouped__")!==f);if(h)throw new d("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[o[0].id,h.id],sectionIds:[f,c.get(h.id)??"__ungrouped__"]});let g=o.reduce((_,P)=>{if(!Number.isInteger(P.capacity)||P.capacity<1||P.capacity>ue)throw new d("invalid_operation",`GA area ${P.id} has invalid capacity`,{gaAreaId:P.id});return _+P.capacity},0);if(g>ue)throw new d("invalid_operation",`Joined GA capacity would be ${g}, over the ${ue}-unit area limit`,{capacity:g});let u=V(t).reduce((_,P)=>_+Z(P),0);if(u>W)throw new d("invalid_operation",`Chart inventory exceeds the ${W}-unit publication limit`,{inventory:u});let p=o.map(ln),y=p.reduce((_,P)=>_+P.outer.length+P.holes.reduce((G,X)=>G+X.length,0),0);if(y>Ue)throw new d("invalid_operation",`Join Areas supports at most ${Ue} source vertices`,{vertexCount:y});let w;try{let _=p.map(X=>[_e(X.outer)]);if(w=Be.union(_[0],..._.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 P=p.flatMap(X=>X.holes.map(Ae=>[_e(Ae)]));P.length&&(w=Be.difference(w,...P));let G=p.findIndex(X=>{let Ae=[_e(X.outer),...X.holes.map(_e)];return cn(Be.intersection(Ae,w))<=k});if(G>=0)throw new d("invalid_operation",`GA area ${o[G].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:o[G].id})}catch(_){throw _ instanceof d?_:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:_ instanceof Error?_.message:"polygon_union_failed"})}if(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 x=Jt(w[0][0]),b=w[0].slice(1).map(Jt),m=x.length+b.reduce((_,P)=>_+P.length,0);if(b.length>Yt||m>Ue)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:b.length,vertexCount:m});Oe(x,"outline",o[0].id),b.forEach(_=>Oe(_,"cutout",o[0].id));let C=new Map(r.objects.map((_,P)=>[_.id,P])),I=o.slice().sort((_,P)=>dn(Vt(_,C.get(_.id)??Number.MAX_SAFE_INTEGER),Vt(P,C.get(P.id)??Number.MAX_SAFE_INTEGER))),S=I[0],A=structuredClone(t),H=v(A,r.floorId),U=H.objects.find(_=>_.type==="gaArea"&&_.id===S.id);U.points=structuredClone(x),b.length?U.holes=structuredClone(b):delete U.holes;let q=new Set(I.slice(1).map(_=>_.id));for(let _=H.objects.length-1;_>=0;_-=1)q.has(H.objects[_].id)&&H.objects.splice(_,1);let E=re(A).objectToSection.get(S.id)??"__ungrouped__";if(E!==f)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:S.id,beforeSectionId:f,afterSectionId:E});let O=[],K=new Set;for(let _ of I){if(!lt(_))throw new d("invalid_operation",`GA area ${_.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:_.id});let P=ne(_);if(P.length!==_.capacity||P.some(G=>K.has(G)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:_.id});P.forEach(G=>K.add(G)),O.push(...ct(_))}if(O.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let R=new Set(o.map(_=>_.id));for(let _ of V(t).filter(P=>P.type==="gaArea"&&!R.has(P.id))){let P=ne(_).find(G=>K.has(G));if(P)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:P,gaAreaId:_.id})}let Pe=I.slice(1).map(_=>_.id);return{floorId:r.floorId,areaId:S.id,survivorLabel:S.label,removedAreaIds:Pe,sourceAreaCount:I.length,capacity:g,inventorySegmentCount:O.length,outerVertexCount:x.length,holeCount:b.length,sectionId:f,points:x,...b.length?{holes:b}:{},segments:O}}function Ri(t,e){let{segments:r,...n}=eo(t,e);return n}function Fi(t,e){let r=eo(t,e),n=v(t,r.floorId),a=n.objects.find(l=>l.type==="gaArea"&&l.id===r.areaId);a.points=structuredClone(r.points),r.holes?.length?a.holes=structuredClone(r.holes):delete a.holes,a.capacity=r.capacity,a.inventorySegments=structuredClone(r.segments);let i=new Set(r.removedAreaIds);for(let l=n.objects.length-1;l>=0;l-=1)i.has(n.objects[l].id)&&n.objects.splice(l,1);let{segments:o,...s}=r;return{...s,changed:!0}}var to=[{key:"rect",label:"Flat stage",icon:"\u25AD",blurb:"Classic proscenium box."},{key:"rounded",label:"Rounded",icon:"\u25A2",blurb:"Softened corners."},{key:"arc",label:"Curved front",icon:"\u25D7",blurb:"Front edge bows toward the audience."},{key:"thrust",label:"Thrust (T)",icon:"\u22A4",blurb:"Central tongue projects into the crowd."},{key:"runway",label:"Runway",icon:"\u2337",blurb:"Long catwalk into the audience."},{key:"round",label:"In the round",icon:"\u25EF",blurb:"Central platform, audience all around."}];var fn=Math.PI*2;function un(t,e,r,n,a,i){return{x:a+t*r-e*n,y:i+t*n+e*r}}function oo(t){let{kind:e,cx:r,cy:n,width:a,height:i}=t,o=(t.rotation??0)*Math.PI/180,s=Math.cos(o),l=Math.sin(o),c=a/2,f=i/2,h=[],g=(u,p)=>{h.push({x:u,y:p})};switch(e){case"rect":{g(-c,-f),g(c,-f),g(c,f),g(-c,f);break}case"rounded":{let u=Math.min(a,i)*.18,p=5,y=(w,x,b)=>{for(let m=0;m<=p;m++){let C=b+m/p*(Math.PI/2);g(w+u*Math.cos(C),x+u*Math.sin(C))}};y(c-u,-f+u,-Math.PI/2),y(c-u,f-u,0),y(-c+u,f-u,Math.PI/2),y(-c+u,-f+u,Math.PI);break}case"arc":{let u=i*.45;g(-c,-f),g(c,-f);let p=24;for(let y=0;y<=p;y++){let w=y/p,x=c-w*a,b=f+u*(1-Math.pow(2*x/a,2));g(x,b)}break}case"thrust":{let u=a*.18,p=i*1.1;g(-c,-f),g(c,-f),g(c,f),g(u,f),g(u,f+p),g(-u,f+p),g(-u,f),g(-c,f);break}case"runway":{let u=a*.1,p=i*3;g(-c,-f),g(c,-f),g(c,f),g(u,f),g(u,f+p),g(-u,f+p),g(-u,f),g(-c,f);break}case"round":{for(let p=0;p<40;p++){let y=p/40*fn;g(c*Math.cos(y),f*Math.sin(y))}break}}return h.map(u=>un(u.x,u.y,s,l,r,n))}function Ki(t,e){let r=v(t,e.floorId),n=[...new Set(e.shapeIds)];if(!n.length)throw new d("invalid_operation","At least one shape id is required");let a=n.map(c=>r.objects.find(f=>f.type==="shape"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found",`Unknown shape id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one shape change is required");if(o.label!==void 0){if(n.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(o.label!==null){if(o.label=o.label.normalize("NFKC").trim(),!o.label)o.label=null;else if(o.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(o.fill!==void 0&&o.fill!==null&&(o.fill=N(o.fill,"Shape fill")),o.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(o.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(o.stroke!==void 0&&o.stroke!==null){if(!Number.isFinite(o.stroke.width)||o.stroke.width<.5||o.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");o.stroke={color:N(o.stroke.color,"Shape stroke"),width:o.stroke.width}}if(o.cornerRadius!==void 0&&o.cornerRadius!==null&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(o.opacity!==void 0&&o.opacity!==null&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(o.heightM!==void 0&&o.heightM!==null&&(!Number.isFinite(o.heightM)||o.heightM<.05||o.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(o.eventConfigurationIds!==void 0&&o.eventConfigurationIds!==null){let c=o.eventConfigurationIds.map(f=>f.normalize("NFKC").trim());if(!c.length||c.length>20||c.some(f=>!f||f.length>100)||new Set(c).size!==c.length)throw new d("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");o.eventConfigurationIds=c}if(o.lineCap!==void 0&&o.lineCap!==null&&!ut.includes(o.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(o.lineJoin!==void 0&&o.lineJoin!==null&&!gt.includes(o.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[c,f]of[["startEnding",o.startEnding],["endEnding",o.endEnding]])if(f!=null&&!ht.includes(f))throw new d("invalid_operation",`Shape ${c} must be none or arrow`);if(o.lineCap!=null||o.lineJoin!=null||o.startEnding!=null||o.endEnding!=null){let c=a.filter(f=>!Te(o.kind??f.kind));if(c.length)throw new d("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:c.map(f=>f.id)})}let l=!1;for(let c of a){let f=JSON.stringify(c);if(o.label===null?delete c.label:o.label!==void 0&&(c.label=o.label),o.fill===null?delete c.fill:o.fill!==void 0&&(c.fill=o.fill),o.kind!==void 0&&(c.kind=o.kind,Te(c.kind)||(delete c.lineCap,delete c.lineJoin,delete c.startEnding,delete c.endEnding)),o.stroke===null?delete c.stroke:o.stroke!==void 0&&(c.stroke={...o.stroke}),o.opacity===null?delete c.opacity:o.opacity!==void 0&&(c.opacity=o.opacity),o.heightM===null?delete c.heightM:o.heightM!==void 0&&(c.heightM=o.heightM),o.eventConfigurationIds===null?delete c.eventConfigurationIds:o.eventConfigurationIds!==void 0&&(c.eventConfigurationIds=[...o.eventConfigurationIds]),o.lineCap===null?delete c.lineCap:o.lineCap!==void 0&&(c.lineCap=o.lineCap),o.lineJoin===null?delete c.lineJoin:o.lineJoin!==void 0&&(c.lineJoin=o.lineJoin),o.startEnding===null?delete c.startEnding:o.startEnding!==void 0&&(c.startEnding=o.startEnding),o.endEnding===null?delete c.endEnding:o.endEnding!==void 0&&(c.endEnding=o.endEnding),o.cornerRadius===null)delete c.cornerRadius;else if(o.cornerRadius!==void 0){let h=Math.min(c.width??1/0,c.height??1/0),g=Number.isFinite(h)?h/2:o.cornerRadius;c.cornerRadius=c.kind==="rect"?Math.max(0,Math.min(o.cornerRadius,g)):o.cornerRadius}JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,shapeIds:n}}function no(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),n=e.map(f=>f.y),a=Math.min(...r),i=Math.max(...r),o=Math.min(...n),s=Math.max(...n),l=Math.max(1,i-a),c=Math.max(1,s-o);return{cx:a+l/2,cy:o+c/2,width:l,height:c}}function Gi(t,e){let r=v(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let n=e.updates.map(o=>o.shapeId);if(new Set(n).size!==n.length)throw new d("invalid_operation","Shape ids must be unique");let a=e.updates.map(o=>{if(![o.width,o.height].every(Number.isFinite)||o.width<8||o.height<8||o.width>1e4||o.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:o.shapeId});let s=r.objects.find(c=>c.type==="shape"&&c.id===o.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${o.shapeId}`,{shapeId:o.shapeId});let l=s.role==="stage"?no(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 c=s.points??[];if(c.length<3||c.some(w=>!Number.isFinite(w.x)||!Number.isFinite(w.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=c.map(w=>w.x),h=c.map(w=>w.y),g=Math.min(...f),u=Math.max(...f),p=Math.min(...h),y=Math.max(...h);return{cx:(g+u)/2,cy:(p+y)/2,width:Math.max(1,u-g),height:Math.max(1,y-p)}})();return{shape:s,update:o,box:l}}),i=!1;for(let{shape:o,update:s,box:l}of a)if(!(Math.abs(l.width-s.width)<1e-9&&Math.abs(l.height-s.height)<1e-9)){if(o.kind==="rect"||o.kind==="ellipse")o.x=l.cx-s.width/2,o.y=l.cy-s.height/2,o.width=s.width,o.height=s.height;else{let c=s.width/l.width,f=s.height/l.height;o.points=(o.points??[]).map(h=>({x:l.cx+(h.x-l.cx)*c,y:l.cy+(h.y-l.cy)*f})),(o.x!=null||o.y!=null||o.width!=null||o.height!=null||o.role==="stage")&&(o.x=l.cx-s.width/2,o.y=l.cy-s.height/2,o.width=s.width,o.height=s.height)}i=!0}return{floorId:r.floorId,changed:i,shapes:a.map(({shape:o,update:s})=>({id:o.id,width:s.width,height:s.height}))}}function Di(t,e){let r=v(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let n=e.updates.map(s=>s.stageId);if(new Set(n).size!==n.length)throw new d("invalid_operation","Stage ids must be unique");let a=new Set(to.map(s=>s.key)),i=e.updates.map(s=>{if(!a.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let l=r.objects.find(c=>c.type==="shape"&&c.id===s.stageId);if(!l)throw new d("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(l.role!=="stage")throw new d("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:l,stageKind:s.stageKind,box:l.stageKind===s.stageKind?null:no(l)}}),o=!1;for(let s of i)s.box&&(s.shape.points=oo({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,o=!0);return{floorId:r.floorId,changed:o,stages:i.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}export{Rt as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,It as DEFAULT_FLOOR_HEIGHT_STEP_M,ro as DEFAULT_SECTION_CORNER_SMOOTHING,De as MAX_FLOOR_BASE_HEIGHT_M,Gr as addArcFanRows,li as addBookableGridArray,Xr as addBoothArray,Ro as addChartCategory,yn as addChartFloor,On as addChartZone,Hr as addGAArea,Jr as addRowBlock,qr as addTableArray,nr as applyPolygonHole,ni as applyReferenceScanRows,mr as applySectionCornerSmoothing,Co as applySectionOutlineShaping,or as applySectionRowFit,Eo as arcFanInputForGroup,ur as assignSectionInventoryCategory,Nr as automaticPlacementCenter,Or as confirmReferenceCategoryOutputColor,hr as convertGeneratedSectionToPolygon,Ee as countCoveredInventory,Ft as familyCategoryLabel,Jo as gaAreaFootprint,Vr as groupRowsAsSegmented,Xn as insertSeatingBlock,Fi as joinGAAreas,wi as mergeRows,we as mirrorFirstFloor,ui as parseSeatRefId,jo as pickColorblindSafeCategoryColor,Nt as previewArcFanRows,si as previewBookableGridArray,So as previewGeneratedSectionPolygonConversion,Ri as previewJoinGAAreas,ze as previewPolygonHole,yo as previewRemovePolygonHole,go as previewRowCubicPath,po as previewSectionRowFit,_r as reassignColorblindSafeCategoryColors,qn as relabelChartRows,Ar as removeChartCategory,Sn as removeChartFloor,Jn as removeChartObjects,An as removeChartZone,rr as removePolygonHole,wn as renameChartFloor,Cr as reorderChartCategories,Dr as replaceArcFanRows,Wr as replaceRowBlock,hi as resetSeatOverrides,Gi as resizeShapes,Pr as resolveCreationCategory,xe as seatRefId,Io as sectionInventorySelectionSummary,Si as setRowBlockSpacing,Ii as splitRow,vi as straightenAndSpaceRows,br as transformSectionBoundary,vo as transformSectionBoundaryObject,Yr as ungroupSegmentedRow,Bn as updateBooths,Oo as updateCategoryDefinitions,In as updateChartFloorBaseHeight,kr as updateChartTheme,Pn as updateChartZones,Un as updateGAAreas,tr as updateRowCubicPath,yi as updateRows,gi as updateSeatOverrides,pr as updateSectionExactPath,gr as updateSectionMetadata,Zr as updateSegmentedRow,Ki as updateShapes,Di as updateStageKinds,zn as updateTables,Hn as updateTextObjects,Mr as updateViewFromSeatFallback};
1
+ import{a as ge,b as he,f as mt,g as yt}from"../../chunk-P2NJ6UO6.js";import"../../chunk-VI2CLV3Y.js";import{n as ft,p as ut,q as gt,r as ht,v as Te}from"../../chunk-DNGP2HDT.js";import{a as ue,b as Q,d as lt,e as ct,f as re,g as Me,i as dt,k as ie}from"../../chunk-ATFAQDPR.js";import{a as bt,b as pt}from"../../chunk-T2LWVOQ3.js";import{b as ce,h as je,i as Re}from"../../chunk-VI3IZS2B.js";import{A as Fe,B as nt,C as rt,D as io,G as it,Ha as st,Q as at,a as qe,b as Xe,c as Ve,d as Ye,e as Ze,f as We,g as de,h as Qe,i as et,ja as ke,ma as z,p as tt,qa as ne,t as fe,ta as L,va as M,xa as T,z as ot,za as J}from"../../chunk-CNCFI5RT.js";import{m as Ne}from"../../chunk-CXF32VPG.js";var d=class extends Error{constructor(r,n,a={}){super(n);this.code=r;this.details=a;this.name="ChartOperationError"}};function v(t,e){let r=T(t),n=e?r.find(a=>a.id===e):r[0];if(!n)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:n.id,objects:n.objects}}function F(t,e){if(!t.categories.some(r=>r.key===e))throw new d("category_not_found",`Unknown chart category: ${e}. Call get_chart to list valid category keys.`,{categoryKey:e})}function j(t,e,r,n){let a=new Set([...n,...t.categories.map(i=>i.key),...t.zones?.map(i=>i.id)??[],...t.floors?.map(i=>i.id)??[],...t.floors?.length?t.floors.flatMap(i=>i.objects.map(o=>o.id)):t.objects.map(i=>i.id)]);for(let i=0;i<100;i++){let o=r(e);if(o&&!a.has(o))return n.add(o),o}throw new d("id_generation_failed",`Unable to allocate a unique ${e} id`)}function ao(t){let e=t.slice().sort((i,o)=>i.x-o.x||i.y-o.y);if(e.length<3)return e;let r=(i,o,s)=>(o.x-i.x)*(s.y-i.y)-(o.y-i.y)*(s.x-i.x),n=[];for(let i of e){for(;n.length>=2&&r(n[n.length-2],n[n.length-1],i)<=0;)n.pop();n.push(i)}let a=[];for(let i=e.length-1;i>=0;i--){let o=e[i];for(;a.length>=2&&r(a[a.length-2],a[a.length-1],o)<=0;)a.pop();a.push(o)}return n.pop(),a.pop(),n.concat(a)}function so(t,e){if(!t.length)return t;let r={x:t.reduce((n,a)=>n+a.x,0)/t.length,y:t.reduce((n,a)=>n+a.y,0)/t.length};return t.map(n=>{let a=n.x-r.x,i=n.y-r.y,o=Math.hypot(a,i)||1;return{x:n.x+a/o*e,y:n.y+i/o*e}})}function Y(t){let e=[];for(let n of t)n.type==="row"?e.push(...z(n).map(a=>({x:a.x,y:a.y}))):n.type==="table"?e.push(...ne(n).map(a=>({x:a.x,y:a.y}))):n.type==="gaArea"?e.push(...n.points):n.type==="booth"&&e.push(n.center);if(e.length<3)return null;let r=so(ao(e),22);return r.length>=3?r:null}function be(t,e){let r=v(t,e),n=T(t).find(a=>a.id===r.floorId);return{...t,objects:r.objects,floors:void 0,focalPoint:n.focalPoint,referenceImage:n.referenceImage,backgroundImage:n.backgroundImage}}var wt=24,It=80;function Le(t,e){let r=t.normalize("NFKC").trim();if(r.length>wt)throw new d("invalid_operation",`${e} displayed type must be at most ${wt} characters`);return r}function pe(t,e){if(t.displayType===void 0)return!1;let r=Le(t.displayType,e);return r?(t.displayType=r,!1):(delete t.displayType,!0)}function ee(t,e){if(t.displayLabel===void 0)return!1;let r=t.displayLabel.normalize("NFKC").trim();if(r.length>It)throw new d("invalid_operation",`${e} displayed label must be at most ${It} characters`);return r?(t.displayLabel=r,!1):(delete t.displayLabel,!0)}function N(t,e){let r=t.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation",`${e} must use a six-digit hex color`);return r}function St(t,e){if(!Number.isFinite(t)||t<je||t>Re)throw new d("invalid_operation",`${e} label size must be from ${je} to ${Re}`)}function te(t,e){t.size!==void 0&&t.size!==null&&St(t.size,e),t.color!==void 0&&t.color!==null&&N(t.color,`${e} label color`)}function me(t,e){if(t?.positionPreset!==void 0&&!["start","end","both","none"].includes(t.positionPreset))throw new d("invalid_operation",`${e} label positionPreset must be one of start, end, both, none`);let r=t?.labelStyle;r&&(r.size!==void 0&&St(r.size,e),r.color!==void 0&&N(r.color,`${e} label color`))}function ye(t,e){let r=t?structuredClone(t):{},n=r.labelStyle?{...r.labelStyle}:{};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=N(e.color,"Label color")),n.size===void 0&&n.color===void 0?delete r.labelStyle:r.labelStyle=n,e.visible!==void 0&&(r.visible=e.visible),Object.keys(r).length?r:void 0}function Ke(t,e,r){let n=e.normalize("NFKC").trim();if(!n||n.length>80)throw new d("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(a=>a.id!==r&&a.label.normalize("NFKC").trim().toLocaleLowerCase("en")===n.toLocaleLowerCase("en")))throw new d("invalid_operation",`Zone label already exists: ${n}`);return n}function Ge(t,e){if(!Number.isFinite(t?.x)||!Number.isFinite(t?.y))throw new d("invalid_operation",`${e} must contain finite x and y values`);return{x:t.x,y:t.y}}function $(t,e,r){return(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x)}var H=Math.PI/180,B=Math.PI/180;function Z(t){return t.type==="row"||t.type==="table"?t.seatCount:t.type==="gaArea"?Math.max(0,Math.floor(t.capacity)):t.type==="booth"?1:0}function we(t){if(t.floors?.length){let e=t.floors[0];t.objects=e.objects,t.focalPoint=e.focalPoint,t.referenceImage=e.referenceImage,t.backgroundImage=e.backgroundImage}return t}var lo=0,De=120,vt=4;function co(t){if(!Number.isFinite(t)||t<lo||t>De)throw new d("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function wn(t,e){let r=T(t);if(r.length>=5)throw new d("invalid_operation","A chart can contain at most five physical floors");let n=(e.name??String(r.length+1)).normalize("NFKC").trim();if(!n||n.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(l=>l.name.toLocaleLowerCase("en")===n.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${n}`);t.floors?.length||(t.floors=[{id:"floor-0",name:"1",objects:t.objects,baseHeightM:0,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]);let i=t.floors[t.floors.length-1].baseHeightM??Math.min(De,(t.floors.length-1)*vt),o=Math.min(De,i+vt),s=j(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:n,baseHeightM:o,objects:[],focalPoint:{...t.focalPoint}}),we(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:o}}function In(t,e){let r=T(t),n=r.find(o=>o.id===e.floorId);if(!n)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let a=e.name.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(o=>o.id!==n.id&&o.name.toLocaleLowerCase("en")===a.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${a}`);let i=n.name!==a;return i&&(n.name=a),{changed:i,floorId:n.id,floorName:a}}function Sn(t,e){if(!t.floors?.length)throw new d("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let r=t.floors.find(a=>a.id===e.floorId);if(!r)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});co(e.baseHeightM);let n=r.baseHeightM!==e.baseHeightM;return n&&(r.baseHeightM=e.baseHeightM,r.physical3dProvenance={...r.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:n,floorId:r.id,baseHeightM:e.baseHeightM}}function vn(t,e){if(!t.floors?.length)throw new d("invalid_operation","A single-floor chart cannot remove its only floor");let r=t.floors.findIndex(a=>a.id===e.floorId);if(r<0)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[n]=t.floors.splice(r,1);if(t.floors.length===1){let[a]=t.floors;t.objects=a.objects,t.focalPoint=a.focalPoint,t.referenceImage=a.referenceImage,t.backgroundImage=a.backgroundImage,t.floors=void 0}else we(t);return{changed:!0,floorId:n.id,removedObjects:n.objects.length,floorCount:T(t).length}}function An(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:j(t,"zone",e.idFactory,new Set),label:Ke(t,e.label),color:N(e.color,"Zone color"),...e.focalPoint?{focalPoint:Ge(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function Pn(t,e){if(!e.updates.length)throw new d("invalid_operation","At least one zone update is required");let r=e.updates.map(l=>l.zoneId);if(new Set(r).size!==r.length)throw new d("invalid_operation","Zone ids must be unique");let n=new Map((t.zones??[]).map(l=>[l.id,l])),a=r.filter(l=>!n.has(l));if(a.length)throw new d("object_not_found",`Unknown zone id(s): ${a.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:a});let i=structuredClone(t),o=new Map((i.zones??[]).map(l=>[l.id,l]));for(let l of e.updates){if(!Object.keys(l.patch).length)throw new d("invalid_operation",`Zone ${l.zoneId} has no changes`);let f=o.get(l.zoneId);l.patch.label!==void 0&&(f.label=Ke(i,l.patch.label,f.id)),l.patch.color!==void 0&&(f.color=N(l.patch.color,"Zone color")),l.patch.focalPoint!==void 0&&(f.focalPoint=Ge(l.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(i.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=i.zones),{changed:s,zoneIds:r,zones:r.map(l=>structuredClone(o.get(l)))}}function jn(t,e){let r=(t.zones??[]).findIndex(i=>i.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let n=T(t).flatMap(i=>i.objects).filter(i=>i.type==="section"&&i.zone===e.zoneId);if(n.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${n.length} section(s)`,{zoneId:e.zoneId,sectionIds:n.map(i=>i.id),requiresClearSectionAssignments:!0});let a=n.map(i=>i.id);for(let i of n)delete i.zone;return t.zones.splice(r,1),t.zones.length||delete t.zones,we(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:a,zoneCount:t.zones?.length??0}}var W={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 ae(t,e,r,n,a,i,o=0){return{type:"row",id:t,label:e,origin:{x:-(n-1)*a/2,y:r},rotation:0,curve:o,seatCount:n,seatSpacing:a,categoryKey:i}}function fo(t,e,r,n,a,i){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:n,rotation:0,radius:a,categoryKey:i}}function xt(t,e,r,n,a,i){let o=r/2,s=n/2;return{type:"gaArea",id:t,label:e,points:[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}],capacity:a,categoryKey:i}}function uo(t,e,r,n,a){let i=r*2,o=[];for(let s=0;s<i;s++){let l=s%2===0,c=l?["wheelchair"]:["companion"];o.push(l?{index:s,accessibility:c,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:c})}return{type:"row",id:t,label:e,origin:{x:-(i-1)*n/2,y:0},rotation:0,curve:0,seatCount:i,seatSpacing:n,categoryKey:a,overrides:o}}var Ct=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[W.balcony],sectionLabel:"Balcony",build:()=>[ae("blk-b0","A",-45,18,24,"balcony",18),ae("blk-b1","B",-15,20,24,"balcony",18),ae("blk-b2","C",15,22,24,"balcony",18),ae("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[W.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>ae(`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:[W.standard],build:()=>[xt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[W.premium],build:()=>Array.from({length:6},(t,e)=>fo(`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:[W.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:[W.standard],build:()=>[xt("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:[W.standard],build:()=>[uo("blk-wc","A",4,40,"standard")]}];function K(t){let e="",r=t;do e=String.fromCharCode(65+r%26)+e,r=Math.floor(r/26)-1;while(r>=0);return e}function _t(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let r of t)e=e*26+(r.charCodeAt(0)-64);return e-1}function $e(t){let e=(t%360+360)%360,r=e>=180?e-360:e;return Object.is(r,-0)||Math.abs(r)<1e-9?0:r}function Ot(t,e,r){let n=a=>({x:a.x+e,y:a.y+r});switch(t.type){case"row":t.origin=n(t.origin),t.path&&(t.path={start:n(t.path.start),control1:n(t.path.control1),control2:n(t.path.control2),end:n(t.path.end)});break;case"table":case"booth":t.center=n(t.center);break;case"text":t.position=n(t.position);break;case"gaArea":t.points=t.points.map(n),t.holes&&(t.holes=t.holes.map(a=>a.map(n)));break;case"section":t.outline=t.outline.map(n),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(n)),t.outlinePath&&(t.outlinePath=nt(t.outlinePath,e,r)),t.holes&&(t.holes=t.holes.map(a=>a.map(n)));break;case"shape":t.points&&(t.points=t.points.map(n)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}function Bn(t,e){let r=v(t,e.floorId),n=[...new Set(e.tableIds)];if(!n.length)throw new d("invalid_operation","At least one table id is required");let a=n.map(b=>r.objects.find(p=>p.type==="table"&&p.id===b)),i=n.filter((b,p)=>!a[p]);if(i.length)throw new d("object_not_found",`Unknown table id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one table change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&F(t,o.categoryKey);let s=o.seatCount!==void 0,l=o.seatCountsBySide!==void 0;if(l){if(o.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(o.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let b=["top","bottom","left","right"],p=Object.keys(o.seatCountsBySide);if(p.length!==b.length||p.some(I=>!b.includes(I)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let I of b){let S=o.seatCountsBySide[I];if(!Number.isInteger(S)||S<0||S>40)throw new d("invalid_operation",`seatCountsBySide.${I} must be a whole number from 0 to 40`)}let C=b.reduce((I,S)=>I+o.seatCountsBySide[S],0);if(C<1||C>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&o.seatCount!==C)throw new d("invalid_operation",`seatCount must equal the ${C}-chair seatCountsBySide total`);o.seatCount=C,o.sides=b.filter(I=>o.seatCountsBySide[I]>0)}if(o.seatCount!==void 0&&(!Number.isInteger(o.seatCount)||o.seatCount<1||o.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(o.shape!==void 0&&o.shape!=="round"&&o.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(o.bookAsWhole===!0&&o.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(o.variableOccupancy===!1&&(o.minOccupancy!==void 0||o.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let c=(b,p,C,I)=>{if(p!==void 0&&(!Number.isFinite(p)||p<C||p>I))throw new d("invalid_operation",`${String(b)} must be from ${C} to ${I}`)};if(c("rotation",o.rotation,0,360),c("radius",o.radius,24,160),c("seatArc",o.seatArc,120,360),c("width",o.width,40,320),c("height",o.height,30,240),o.minOccupancy!==void 0&&(!Number.isInteger(o.minOccupancy)||o.minOccupancy<1||o.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(o.maxOccupancy!==void 0&&(!Number.isInteger(o.maxOccupancy)||o.maxOccupancy<1||o.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(o.sides!==void 0){let b=new Set(["top","bottom","left","right"]);if(!o.sides.length||o.sides.length>4||new Set(o.sides).size!==o.sides.length||o.sides.some(p=>!b.has(p)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=ee(o,"Table"),g=pe(o,"Table"),h=a.map(b=>{if(b.seatCountsBySide&&!l&&(s||e.patch.sides!==void 0))throw new d("invalid_operation",`Table "${b.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:b.id});let p=structuredClone(b);if(Object.assign(p,o),p.shape==="round"&&delete p.seatCountsBySide,p.overrides&&o.seatCount!==void 0&&(p.overrides=p.overrides.filter(C=>C.index<p.seatCount),p.overrides.length||delete p.overrides),o.bookAsWhole===!1&&delete p.bookAsWhole,o.variableOccupancy===!1&&(delete p.variableOccupancy,delete p.minOccupancy,delete p.maxOccupancy),p.bookAsWhole||delete p.bookAsWhole,p.variableOccupancy||delete p.variableOccupancy,p.bookAsWhole&&p.variableOccupancy)throw new d("invalid_operation",`Table "${p.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:p.id});if((p.bookAsWhole||p.variableOccupancy)&&p.overrides?.length)throw new d("invalid_operation",`Table "${p.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:p.id,overriddenChairIndices:p.overrides.map(C=>C.index)});if(p.bookAsWhole)delete p.minOccupancy,delete p.maxOccupancy;else if(p.variableOccupancy){if(!Number.isInteger(p.minOccupancy)||!Number.isInteger(p.maxOccupancy)||p.minOccupancy<1||p.maxOccupancy<p.minOccupancy||p.maxOccupancy>p.seatCount)throw new d("invalid_operation",`Table "${p.label}" needs whole-number minimum and maximum guests from 1 to its ${p.seatCount}-chair capacity`,{tableId:p.id,seatCount:p.seatCount})}else{if(o.minOccupancy!==void 0||o.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:p.id});delete p.minOccupancy,delete p.maxOccupancy}if(g&&delete p.displayType,f&&delete p.displayLabel,p.shape==="rect"){if(p.width??=80,p.height??=50,p.seatCountsBySide){let C=["top","bottom","left","right"],I=C.reduce((S,P)=>S+p.seatCountsBySide[P],0);if(I!==p.seatCount)throw new d("invalid_operation",`Table "${p.label}" side counts total ${I}, but seatCount is ${p.seatCount}`,{tableId:p.id,seatCount:p.seatCount,seatCountsBySide:p.seatCountsBySide});p.sides=C.filter(S=>p.seatCountsBySide[S]>0)}}else p.radius??=40;if((p.bookAsWhole||p.variableOccupancy)&&dt(p.label))throw new d("invalid_operation",`Grouped table label "${p.label}" uses SeatLayer's reserved GA namespace`,{tableId:p.id});return p}),u=new Map(h.map(b=>[b.id,b])),m=new Set(n),y=new Map;for(let b of T(t))for(let p of b.objects){let C=p.type==="table"?u.get(p.id)??p:p,I=[];C.type==="row"?I=z(C).map(S=>S.label):C.type==="table"?I=C.bookAsWhole||C.variableOccupancy?[C.label]:ne(C).map(S=>S.label):C.type==="booth"?I=[C.label]:C.type==="gaArea"&&(I=re(C));for(let S of I){let P=y.get(S);if(P&&(m.has(P)||m.has(C.id)))throw new d("invalid_operation",`Inventory label "${S}" is already in use; grouped table labels must be unique`,{tableIds:n,inventoryLabel:S,conflictingObjectIds:[P,C.id]});y.set(S,P??C.id)}}let w=!1,_=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[b,p]of a.entries()){let C=h[b],I=JSON.stringify(p);for(let S of _)S in C||delete p[S];Object.assign(p,C),JSON.stringify(p)!==I&&(w=!0)}return{floorId:r.floorId,changed:w,tableIds:n}}function Un(t,e){let r=v(t,e.floorId),n=[...new Set(e.boothIds)];if(!n.length)throw new d("invalid_operation","At least one booth id is required");let a=n.map(u=>r.objects.find(m=>m.type==="booth"&&m.id===u)),i=n.filter((u,m)=>!a[m]);if(i.length)throw new d("object_not_found",`Unknown booth id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one booth change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&F(t,o.categoryKey);let s=(u,m,y,w)=>{if(m!==void 0&&(!Number.isFinite(m)||m<y||m>w))throw new d("invalid_operation",`${u} must be from ${y} to ${w}`)};s("width",o.width,30,400),s("height",o.height,30,400),s("rotation",o.rotation,0,360);let l=o.points===null;if(o.points!=null){if(n.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let u=mt(o.points);if(!u.ok)throw new d("invalid_operation",u.message??"The booth outline is not a valid simple polygon")}let c=o.points!=null?o.points.map(u=>({x:u.x,y:u.y})):void 0;delete o.points;let f=ee(o,"Booth"),g=pe(o,"Booth"),h=!1;for(let u of a){let m=JSON.stringify(u);Object.assign(u,o),f&&delete u.displayLabel,g&&delete u.displayType,l?delete u.points:c&&(u.points=c),JSON.stringify(u)!==m&&(h=!0)}return{floorId:r.floorId,changed:h,boothIds:n}}function Jn(t,e){let r=v(t,e.floorId),n=[...new Set(e.gaAreaIds)];if(!n.length)throw new d("invalid_operation","At least one GA area id is required");let a=n.map(f=>r.objects.find(g=>g.type==="gaArea"&&g.id===f)),i=n.filter((f,g)=>!a[g]);if(i.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one GA area change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!o.label||o.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(o.categoryKey!==void 0&&F(t,o.categoryKey),o.capacity!==void 0&&(!Number.isInteger(o.capacity)||o.capacity<1||o.capacity>1e5))throw new d("invalid_operation","capacity must be an integer from 1 to 100000");if(o.cornerRadius!==void 0&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=ee(o,"GA area"),l=pe(o,"GA area");if(o.capacity!==void 0)for(let f of a){if(f.inventorySegments!==void 0&&o.capacity<f.capacity)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot be reduced below ${f.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:f.id,currentCapacity:f.capacity,requestedCapacity:o.capacity});if(f.inventorySegments!==void 0&&o.capacity>f.capacity&&Me(f,o.capacity)===void 0)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot append that capacity safely`,{gaAreaId:f.id})}let c=!1;for(let f of a){let g=JSON.stringify(f),h=o.capacity===void 0?f.inventorySegments:Me(f,o.capacity);Object.assign(f,o),h!==void 0&&(f.inventorySegments=h),s&&delete f.displayLabel,l&&delete f.displayType,JSON.stringify(f)!==g&&(c=!0)}return{floorId:r.floorId,changed:c,gaAreaIds:n}}function Ee(t,e){if(e.length<3)return 0;let r=a=>L(a,e,void 0),n=0;for(let a of t)r(M(a))&&(a.type==="row"?n+=z(a).length:a.type==="table"?n+=ne(a).length:(a.type==="gaArea"||a.type==="booth")&&(n+=Z(a)));return n}function Hn(t,e){let r=v(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 n=e.objectIds.map(s=>r.objects.find(l=>l.id===s)),a=e.objectIds.filter((s,l)=>!n[l]);if(a.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:a});let i=n,o=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)o.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:i.map(s=>({id:s.id,type:s.type})),removedInventory:i.reduce((s,l)=>s+Z(l),0),remainingObjectCount:r.objects.length}}function qn(t,e){let r=v(t,e.floorId),n=[...new Set(e.textIds)];if(!n.length)throw new d("invalid_operation","At least one text id is required");let a=n.map(c=>r.objects.find(f=>f.type==="text"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found",`Unknown text id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one text change is required");if(o.text!==void 0){if(o.text=o.text.normalize("NFKC").trim(),n.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!o.text||o.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(o.fontSize!==void 0&&(!Number.isFinite(o.fontSize)||o.fontSize<8||o.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(o.fontFamily!==void 0&&o.fontFamily!==null&&(o.fontFamily=o.fontFamily.normalize("NFKC").trim(),!o.fontFamily||o.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(o.rotation!==void 0&&(!Number.isFinite(o.rotation)||o.rotation<0||o.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(o.color!==void 0&&o.color!==null&&(o.color=N(o.color,"Text color")),o.bold!==void 0&&typeof o.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(o.italic!==void 0&&typeof o.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(o.width!==void 0&&o.width!==null&&(!Number.isFinite(o.width)||o.width<40||o.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(o.align!==void 0&&!["left","center","right"].includes(o.align))throw new d("invalid_operation","Text align must be left, center, or right");if(o.lineHeight!==void 0&&(!Number.isFinite(o.lineHeight)||o.lineHeight<.8||o.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(o.letterSpacing!==void 0&&(!Number.isFinite(o.letterSpacing)||o.letterSpacing<-2||o.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(o.underline!==void 0&&typeof o.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(o.opacity!==void 0&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(o.background!==void 0&&o.background!==null){o.background.color=N(o.background.color,"Text background color");let{padding:c=6,cornerRadius:f=4,opacity:g=.9}=o.background;if(!Number.isFinite(c)||c<0||c>40)throw new d("invalid_operation",`Text background padding must be from 0 to ${40}`);if(!Number.isFinite(f)||f<0||f>40)throw new d("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(g)||g<.1||g>1)throw new d("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(c=>Object.prototype.hasOwnProperty.call(o,c))&&a.some(c=>c.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(o.iconKey!==void 0){if(!ft(o.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(a.some(c=>c.semanticKind!=="icon"))throw new d("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let l=!1;for(let c of a){let f=JSON.stringify(c);o.iconKey!==void 0&&(c.iconKey=o.iconKey),o.text!==void 0&&(c.text=o.text),o.fontSize!==void 0&&(c.fontSize=o.fontSize),o.fontFamily===null?delete c.fontFamily:o.fontFamily!==void 0&&(c.fontFamily=o.fontFamily),o.rotation!==void 0&&(c.rotation=o.rotation),o.color===null?delete c.color:o.color!==void 0&&(c.color=o.color),o.bold!==void 0&&(o.bold?c.bold=!0:delete c.bold),o.italic!==void 0&&(o.italic?c.italic=!0:delete c.italic),o.width===null?delete c.width:o.width!==void 0&&(c.width=o.width),o.align!==void 0&&(o.align==="left"?delete c.align:c.align=o.align),o.lineHeight!==void 0&&(o.lineHeight===1.2?delete c.lineHeight:c.lineHeight=o.lineHeight),o.letterSpacing!==void 0&&(o.letterSpacing===0?delete c.letterSpacing:c.letterSpacing=o.letterSpacing),o.underline!==void 0&&(o.underline?c.underline=!0:delete c.underline),o.opacity!==void 0&&(o.opacity===1?delete c.opacity:c.opacity=o.opacity),o.background===null?delete c.background:o.background!==void 0&&(c.background=o.background),JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,textIds:n}}function Xn(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)],a=n.map(c=>r.objects.find(f=>f.type==="row"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a.slice().sort((c,f)=>c.origin.y-f.origin.y||c.origin.x-f.origin.x),s=at(o.map(c=>({label:c.label})),e.options),l=!1;return o.forEach((c,f)=>{c.label!==s[f].label&&(l=!0),c.label=s[f].label}),{floorId:r.floorId,changed:l,rows:o.map(c=>({id:c.id,label:c.label}))}}function Vn(t,e){let r=Ct.find(c=>c.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let n=v(t,e.floorId),a=new Set,i=r.build().map(c=>structuredClone(c));for(let c of i)c.id=j(t,c.type,e.idFactory,a),Ot(c,e.center.x,e.center.y);for(let c of r.categories)t.categories.some(f=>f.key===c.key)||t.categories.push({...c});let o=i.filter(c=>c.type==="row");if(o.length){let c=0;for(let f of n.objects){if(f.type!=="row")continue;let g=_t(f.label);g!=null&&(c=Math.max(c,g+1))}for(let f of o)f.label=K(c++)}let s=new Set(n.objects.flatMap(c=>"label"in c&&c.label?[c.label]:[]));for(let c of i){if((c.type==="table"||c.type==="booth")&&s.has(c.label)){let f=/^(.*?)(\d+)$/.exec(c.label),g=f?f[1]:`${c.label} `,h=f?Number.parseInt(f[2],10):1;do h++;while(s.has(`${g}${h}`));c.label=`${g}${h}`}"label"in c&&c.label&&s.add(c.label)}n.objects.push(...i);let l=null;if(r.sectionLabel){let c=Y(i);if(c){let f={type:"section",id:j(t,"sec",e.idFactory,a),label:r.sectionLabel,outline:c};n.objects.push(f),l=f.id}}return{floorId:n.floorId,blockKey:r.key,createdIds:[...i.map(c=>c.id),...l?[l]:[]],sectionId:l}}function go(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(i=>!Number.isFinite(i.x)||!Number.isFinite(i.y)))throw new d("invalid_operation","Exact row path points must be finite");let n=tt(e,97),a=n.slice(1).reduce((i,o,s)=>i+Math.hypot(o.x-n[s].x,o.y-n[s].y),0);if(!Number.isFinite(a)||a<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:a}}function ho(t,e){let r=v(t,e.floorId),n=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!n)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let a=go(e.path),i=z(n),o=structuredClone(n);o.path=a.path,o.origin={...a.path.start};let s=z(o),l=i.map((f,g)=>Math.hypot(f.x-s[g].x,f.y-s[g].y)),c=JSON.stringify(n.path)!==JSON.stringify(a.path)||n.origin.x!==a.path.start.x||n.origin.y!==a.path.start.y;return{floorId:r.floorId,rowId:n.id,seatCount:n.seatCount,pathLength:a.length,averageSeatMovement:l.length?l.reduce((f,g)=>f+g,0)/l.length:0,maxSeatMovement:l.length?Math.max(...l):0,convertingFromParametric:!n.path,changed:c,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:n.seatCount}}function or(t,e){let r=ho(t,e);if(!r.changed)return r;let a=v(t,r.floorId).objects.find(i=>i.type==="row"&&i.id===r.rowId);return a.path=structuredClone(e.path),a.origin={...e.path.start},delete a.arcFanGeneration,delete a.rowBlockGeneration,r}function bo(t,e){let r=t.map((n,a)=>[...n,e[a]]);for(let n=0;n<3;n++){let a=n;for(let o=n+1;o<3;o++)Math.abs(r[o][n])>Math.abs(r[a][n])&&(a=o);if(Math.abs(r[a][n])<1e-9)return null;[r[n],r[a]]=[r[a],r[n]];let i=r[n][n];for(let o=n;o<4;o++)r[n][o]/=i;for(let o=0;o<3;o++){if(o===n)continue;let s=r[o][n];for(let l=n;l<4;l++)r[o][l]-=s*r[n][l]}}return[r[0][3],r[1][3],r[2][3]]}function po(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let a of t){if(!Number.isFinite(a.x)||!Number.isFinite(a.y))return null;let i=[2*a.x,2*a.y,1],o=a.x**2+a.y**2;for(let s=0;s<3;s++){r[s]+=i[s]*o;for(let l=0;l<3;l++)e[s][l]+=i[s]*i[l]}}let n=bo(e,r);return n?{x:n[0],y:n[1]}:null}function At(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function mo(t,e){let r=v(t,e.floorId),n=r.objects.find(u=>u.type==="section"&&u.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let a=e.strength??100;if(!Number.isFinite(a)||a<0||a>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let i=T(t).find(u=>u.id===r.floorId),o=e.mode==="outline"?po(n.outline):e.focalPoint??i.focalPoint??t.focalPoint;if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(u=>u.type==="row"&&L(M(u),n.outline,n.holes)),l=s.filter(u=>!!u.path).map(u=>u.id),c=[],f=[],g=a/100;for(let u of s){if(u.path)continue;if(u.seatCount<2){c.push(u.id);continue}let m=Math.hypot(u.origin.x-o.x,u.origin.y-o.y);if(m<=u.seatSpacing/2+1e-6){c.push(u.id);continue}let y=2*Math.asin(u.seatSpacing/(2*m))/H,w=z(u),_=Math.atan2(u.origin.x-o.x,u.origin.y-o.y)/H,p=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(At(Math.atan2(w[1].x-o.x,w[1].y-o.y)/H-_))||1)*y*(u.seatCount-1);if(Math.abs(p)>320){c.push(u.id);continue}let C=-_,I=u.curve+(p-u.curve)*g,S=u.rotation+At(C-u.rotation)*g,P={...u,curve:I,rotation:S},U=z(P).map((X,E)=>Math.hypot(X.x-w[E].x,X.y-w[E].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:p,resultCurve:I,fromRotation:u.rotation,resultRotation:S,rmsMovement:Math.sqrt(U.reduce((X,E)=>X+E**2,0)/U.length),maxMovement:Math.max(...U)})}let h=f.map(u=>u.rmsMovement);return{floorId:r.floorId,sectionId:n.id,mode:e.mode,fitCenter:{...o},strength:a,rows:f,skippedPathRowIds:l,skippedInvalidRowIds:c,averageMovement:h.length?h.reduce((u,m)=>u+m,0)/h.length:0,maxMovement:f.length?Math.max(...f.map(u=>u.maxMovement)):0}}function nr(t,e){let r=mo(t,e),n=v(t,r.floorId),a=n.objects.find(o=>o.type==="section"&&o.id===r.sectionId),i=!1;for(let o of r.rows){let s=n.objects.find(l=>l.type==="row"&&l.id===o.rowId);(s.curve!==o.resultCurve||s.rotation!==o.resultRotation)&&(s.curve=o.resultCurve,s.rotation=o.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,i=!0)}return(a.smoothing??0)!==r.strength&&(a.smoothing=r.strength,i=!0),{...r,changed:i}}function jt(t,e,r,n){let a=$(t,e,r),i=$(t,e,n),o=$(r,n,t),s=$(r,n,e);return a*i<-1e-9&&o*s<-1e-9}function Pt(t,e){return t.some((r,n)=>{let a=t[(n+1)%t.length];return e.some((i,o)=>jt(r,a,i,e[(o+1)%e.length]))})}function yo(t){if(t.length<3||t.length>256||Math.abs(fe(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)if(!(r===e+1||e===0&&r===t.length-1)&&jt(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Ie(t,e,r){let n=v(t,e),a=n.objects.find(i=>(i.type==="section"||i.type==="gaArea")&&i.id===r);if(!a)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:n,object:a,outer:a.type==="section"?a.outline:a.points}}function ze(t,e){let{target:r,object:n,outer:a}=Ie(t,e.floorId,e.objectId),i=structuredClone(e.points);if(!yo(i))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(i.some(c=>!L(c,a,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(Pt(i,a))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let o=n.holes??[],s=e.holeIndex??o.length;if(!Number.isInteger(s)||s<0||s>o.length||e.holeIndex!=null&&s>=o.length)throw new d("invalid_operation","Opening not found");for(let c=0;c<o.length;c++){if(c===e.holeIndex)continue;let f=o[c];if(Pt(i,f)||L(i[0],f,void 0)||L(f[0],i,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let l=r.objects.filter(c=>c.id!==n.id&&c.type!=="section"&&L(M(c),i,void 0));return{floorId:r.floorId,objectId:n.id,objectType:n.type,holeIndex:s,vertexCount:i.length,excludedObjectIds:l.map(c=>c.id),excludedInventoryUnits:Ee(r.objects.filter(c=>c.id!==n.id),i),preservesExactOuterPath:n.type==="section"&&!!n.outlinePath}}function rr(t,e){let r=ze(t,e),{object:n}=Ie(t,r.floorId,r.objectId);return n.holes??=[],e.holeIndex==null?n.holes.push(structuredClone(e.points)):n.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function wo(t,e){let{target:r,object:n}=Ie(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(n.holes?.length??0))throw new d("invalid_operation","Opening not found");let a=n.holes[e.holeIndex],i=r.objects.filter(o=>o.id!==n.id&&o.type!=="section"&&L(M(o),a,void 0));return{floorId:r.floorId,objectId:n.id,objectType:n.type,holeIndex:e.holeIndex,vertexCount:a.length,excludedObjectIds:i.map(o=>o.id),excludedInventoryUnits:Ee(r.objects.filter(o=>o.id!==n.id),a),preservesExactOuterPath:n.type==="section"&&!!n.outlinePath}}function ir(t,e){let r=wo(t,e),{object:n}=Ie(t,r.floorId,r.objectId);return n.holes.splice(e.holeIndex,1),n.holes.length||delete n.holes,{...r,changed:!0}}function Io(t){let e=t.trim();if(!e||e.length>2e6||!/^(https:\/\/|data:image\/)/.test(e))throw new d("invalid_operation","Section view photo must be an HTTPS or data:image URL no larger than 2 MB");return e}function Rt(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let n=r.map(o=>t.find(s=>s.type==="section"&&s.id===o)),a=r.filter((o,s)=>!n[s]);if(a.length)throw new d("object_not_found",`Unknown section id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:a});let i=n;return{requested:r,sections:i,logicalSectionIds:[...new Set(i.map(o=>o.logicalSectionId??o.id))]}}function So(t,e){let r=v(t,e.floorId),n=Rt(r.objects,e.sectionIds),a=ie(be(t,r.floorId)),i=new Map(a.sections.map(g=>[g.id,g])),o=new Map(r.objects.map(g=>[g.id,g])),s=n.logicalSectionIds.flatMap(g=>i.get(g)?.objectIds??[]),l=new Set;for(let g of s){let h=o.get(g);if(h)if(h.type==="row"||h.type==="table")for(let u of he(h).keys())l.add(u);else(h.type==="booth"||h.type==="gaArea")&&l.add(h.categoryKey)}let c=n.logicalSectionIds.every(g=>(i.get(g)?.seatCount??0)>0),f=n.logicalSectionIds.every(g=>i.get(g)?.objectIds.some(h=>{let u=o.get(h);return u?.type==="row"||u?.type==="table"||u?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:n.requested,logicalSectionIds:n.logicalSectionIds,objectIds:s,categoryApplicable:c,...c&&l.size===1?{categoryKey:[...l][0]}:{},categoryMixed:c&&l.size!==1,viewApplicable:f}}function gr(t,e){F(t,e.categoryKey);let r=So(t,e);if(!r.categoryApplicable)throw new d("invalid_operation","Every selected logical section must contain buyer inventory before a section category can be assigned",{logicalSectionIds:r.logicalSectionIds});let n=v(t,r.floorId),a=new Set(r.objectIds),i=!1,o=0;for(let s of n.objects){if(!a.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,i=!0),s.type!=="row"&&s.type!=="table"||!s.overrides?.length))continue;let l=s.overrides.flatMap(c=>{if(c.categoryKey===void 0)return[c];let f={...c};return delete f.categoryKey,o++,i=!0,Object.keys(f).some(g=>g!=="index")?[f]:[]});l.length?s.overrides=l:delete s.overrides}return{...r,changed:i,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:o}}function hr(t,e){let r=v(t,e.floorId),n=Rt(r.objects,e.sectionIds),{requested:a}=n,i=structuredClone(e.patch),o=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(i).filter(u=>!o.has(u));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(i).length)throw new d("invalid_operation","At least one section metadata change is required");if(i.label!==void 0){if(i.label=i.label.normalize("NFKC").trim(),a.length!==1)throw new d("invalid_operation","label can be changed only for one section at a time");if(!i.label||i.label.length>80)throw new d("invalid_operation","Section labels must contain 1 to 80 characters")}if(i.displayLabel!==void 0&&i.displayLabel!==null){if(i.displayLabel=i.displayLabel.normalize("NFKC").trim(),a.length!==1)throw new d("invalid_operation","displayLabel can be changed only for one section at a time");if(!i.displayLabel||i.displayLabel.length>80)throw new d("invalid_operation","Section display labels must contain 1 to 80 characters")}if(i.entrance!==void 0&&i.entrance!==null&&(i.entrance=i.entrance.normalize("NFKC").trim(),i.entrance.length>40))throw new d("invalid_operation","Section entrance must be at most 40 characters");if(i.viewFromSeatUrl!==void 0&&i.viewFromSeatUrl!==null&&(i.viewFromSeatUrl=Io(i.viewFromSeatUrl)),i.labelPresentation?.position&&(!Number.isFinite(i.labelPresentation.position.x)||!Number.isFinite(i.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(i.labelPresentation?.rotation!=null&&!Number.isFinite(i.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(i.labelPresentation!==void 0&&me(i.labelPresentation,"Section"),i.labelStyle!==void 0&&te(i.labelStyle,"Section"),i.zone!==void 0&&i.zone!==null&&!(t.zones??[]).some(u=>u.id===i.zone))throw new d("object_not_found",`Unknown chart zone: ${i.zone}`,{zoneId:i.zone});if(i.elevation!==void 0&&(!Number.isInteger(i.elevation)||i.elevation<0||i.elevation>3))throw new d("invalid_operation","Section elevation must be an integer from 0 to 3");if(i.height!==void 0&&i.height!==null&&(!Number.isFinite(i.height)||i.height<0||i.height>120))throw new d("invalid_operation","Section height must be a number from 0 to 120 metres");if(i.rake!==void 0&&i.rake!==null&&(!Number.isFinite(i.rake)||i.rake<0||i.rake>45))throw new d("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(i.surfaceKind!==void 0&&i.surfaceKind!==null&&i.surfaceKind!=="flat"&&i.surfaceKind!=="rakedRows")throw new d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");i.color!==void 0&&i.color!==null&&(i.color=N(i.color,"Section color"));let l=i.displayLabel!==void 0||i.entrance!==void 0||i.viewFromSeatUrl!==void 0||i.viewFromSeatMeta!==void 0||i.labelStyle!==void 0||i.zone!==void 0,c=new Set(n.logicalSectionIds),f=l?r.objects.filter(u=>u.type==="section"&&c.has(u.logicalSectionId??u.id)):[],g=new Set,h=!1;for(let u of n.sections){let m=JSON.stringify(u);i.label!==void 0&&(u.label=i.label),i.labelPresentation===null?delete u.labelPresentation:i.labelPresentation!==void 0&&(u.labelPresentation=i.labelPresentation),i.elevation!==void 0&&(u.elevation=i.elevation);let y=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};i.height===null?(delete u.height,y("height")):i.height!==void 0&&(u.height=i.height,u.physical3dProvenance={...u.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),i.rake===null?(delete u.rake,y("rake")):i.rake!==void 0&&(u.rake=i.rake,u.physical3dProvenance={...u.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),i.surfaceKind===null?(delete u.surfaceKind,y("surfaceKind")):i.surfaceKind!==void 0&&(u.surfaceKind=i.surfaceKind,u.physical3dProvenance={...u.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),i.color===null?delete u.color:i.color!==void 0&&(u.color=i.color),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}for(let u of f){let m=JSON.stringify(u),y=u.viewFromSeatUrl;if(i.displayLabel===null?delete u.displayLabel:i.displayLabel!==void 0&&(u.displayLabel=i.displayLabel),i.entrance===null||i.entrance===""?delete u.entrance:i.entrance!==void 0&&(u.entrance=i.entrance),i.viewFromSeatUrl===null||i.viewFromSeatUrl===""?delete u.viewFromSeatUrl:i.viewFromSeatUrl!==void 0&&(u.viewFromSeatUrl=i.viewFromSeatUrl),!u.viewFromSeatUrl||i.viewFromSeatMeta===null?delete u.viewFromSeatMeta:i.viewFromSeatMeta!==void 0?u.viewFromSeatMeta=structuredClone(i.viewFromSeatMeta):i.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==y&&delete u.viewFromSeatMeta,i.labelStyle!==void 0){let w=ye(u.labelPresentation,i.labelStyle);w?u.labelPresentation=w:delete u.labelPresentation}i.zone===null?delete u.zone:i.zone!==void 0&&(u.zone=i.zone),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}return{floorId:r.floorId,changed:h,sectionIds:a,affectedSectionIds:[...g]}}function vo(t,e){let r=v(t,e.floorId),n=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(n.outlinePath)throw new d("invalid_operation",`Section ${n.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:n.id,representation:"exact-path"});if(!n.geometry)throw new d("invalid_operation",`Section ${n.id} is already a manual polygon`,{sectionId:n.id,representation:"manual-polygon"});let a=r.objects.filter(i=>i.id!==n.id&&i.type!=="section"&&L(M(i),n.outline,n.holes));return{floorId:r.floorId,sectionId:n.id,sectionLabel:n.label,source:{representation:"generated-polygon",generator:structuredClone(n.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:n.outline.length,holeCount:n.holes?.length??0,memberObjectIds:a.map(i=>i.id),inventoryUnits:a.reduce((i,o)=>i+Z(o),0),durableReferenceSource:!!n.referenceSource,inventoryExclusionEvidence:!!n.referenceInventoryExclusion},removedFields:["geometry"]}}function br(t,e){let r=vo(t,e),a=v(t,r.floorId).objects.find(i=>i.type==="section"&&i.id===r.sectionId);return delete a.geometry,{...r,changed:!0}}function xo(t,e){let r=(...s)=>s.every(Number.isFinite),n,a=1,i=!1,o=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");o=e.dx!==0||e.dy!==0,n=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");o=e.factor!==1,a=e.factor;let s=M(t);n=l=>({x:s.x+(l.x-s.x)*e.factor,y:s.y+(l.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!r(e.degrees))throw new d("invalid_operation","Section rotation must be finite");o=(e.degrees%360+360)%360!==0;let l=e.degrees*Math.PI/180,c=Math.cos(l),f=Math.sin(l),g=M(t);n=h=>{let u=h.x-g.x,m=h.y-g.y;return{x:g.x+u*c-m*f,y:g.y+u*f+m*c}}}else{if(!r(e.coordinate))throw new d("invalid_operation","Section reflection coordinate must be finite");i=!0,n=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return o&&(t.outline=t.outline.map(n),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(n)),t.outlinePath&&(t.outlinePath=rt(t.outlinePath,n,a,i)),t.holes&&(t.holes=t.holes.map(s=>s.map(n)))),{changed:o,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 pr(t,e){let r=v(t,e.floorId),n=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...xo(n,e.transform)}}function mr(t,e){let r=v(t,e.floorId),n=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!n)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let a=structuredClone(e.path);if(!ot(a))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let i=Fe(a),o=JSON.stringify(n.outlinePath)!==JSON.stringify(a)||JSON.stringify(n.outline)!==JSON.stringify(i)||n.sourceOutline!==void 0||n.cornerSmoothing!==void 0;return o&&(n.outlinePath=a,n.outline=i,delete n.geometry,delete n.sourceOutline,delete n.cornerSmoothing),{floorId:r.floorId,sectionId:n.id,changed:o,segmentKinds:a.segments.map(s=>s.kind),sampledVertexCount:i.length,holeCount:n.holes?.length??0}}function Co(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function yr(t,e){return _o(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function _o(t,e){let r=v(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 n=[...new Set(e.sectionIds)],a=new Set,i=new Map,o=!1;try{for(let s of n){let l=r.objects.find(b=>b.type==="section"&&b.id===s);if(!l||!Co(l))continue;let f=structuredClone(l);i.set(l.id,{section:l,snapshot:f});let g=JSON.stringify(l),h=(l.sourceOutline??l.outline).map(b=>({...b})),u=Math.min(100,Math.max(0,e.cornerSmoothing??l.cornerSmoothing??0)),y=(e.edgeCurvature===void 0?l.edgeCurvature:e.edgeCurvature??void 0)?.map(b=>Math.min(100,Math.max(-100,b))),w=y?.some(b=>Math.abs(b)>.5)===!0,_=u>.5||w?it(h,{cornerSmoothing:u,...w?{edgeCurvature:y}:{}}):null;_?(l.sourceOutline=h,l.outlinePath=_,l.outline=Fe(_),u>.5?l.cornerSmoothing=u:delete l.cornerSmoothing,w?l.edgeCurvature=[...y]:delete l.edgeCurvature):(l.outline=h,delete l.outlinePath,delete l.sourceOutline,delete l.cornerSmoothing,delete l.edgeCurvature);for(let b=0;b<(l.holes?.length??0);b+=1)ze(t,{floorId:r.floorId,objectId:l.id,points:l.holes[b],holeIndex:b});JSON.stringify(l)!==g&&(o=!0,a.add(l.id))}}catch(s){for(let{section:l,snapshot:c}of i.values()){let f=l;for(let g of Object.keys(f))delete f[g];Object.assign(l,structuredClone(c))}throw s}return{floorId:r.floorId,changed:o,sectionIds:n,affectedSectionIds:[...a]}}var Oo=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,r=new Map,n=structuredClone(t);for(let a of n){let i=a.key.trim(),o=a.label.normalize("NFKC").trim();if(!i||i.length>160||e.has(i))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${i}`,{categoryKey:i});if(e.add(i),!o||o.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${i}`,{categoryKey:i});let s=o.toLocaleLowerCase("en"),l=r.get(s);if(l)throw new d("duplicate_category_label",`Categories ${l} and ${i} share the same label`,{categoryKeys:[l,i],label:o});if(r.set(s,i),!/^#[0-9a-fA-F]{6}$/.test(a.color))throw new d("invalid_operation",`Category ${i} must use a six-digit hex color`,{categoryKey:i});if(a.price!=null&&(!Number.isFinite(a.price)||a.price<0||a.price>1e6))throw new d("invalid_operation",`Category ${i} price must be from 0 to 1000000`,{categoryKey:i});if(a.tiers!=null)if(!a.tiers.length)delete a.tiers;else{if(a.tiers.length>20)throw new d("invalid_operation",`Category ${i} supports at most 20 ticket tiers`);let c=new Set,f=new Set;for(let g of a.tiers){let h=g.id.trim(),u=g.name.normalize("NFKC").trim(),m=u.toLocaleLowerCase("en");if(!h||h.length>160||c.has(h))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${i}`,{categoryKey:i,tierId:h});if(!u||u.length>80||f.has(m))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${i}`,{categoryKey:i,tierName:u});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new d("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:i,tierId:h});if(g.restriction!=null&&!Oo.has(g.restriction))throw new d("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:i,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:i,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new d("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:i,tierId:h});if(g.applicability!=null){let y=g.applicability.seatLabels?.map(_=>_.normalize("NFKC").trim()),w=g.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(_=>!_||_.length>160)||new Set(y).size!==y.length)||w&&(!w.length||w.some(_=>!ce.some(b=>b.key===_))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:i,tierId:h});g.applicability={...y?{seatLabels:y}:{},...w?{accessibility:[...w]}:{}},!g.applicability.seatLabels&&!g.applicability.accessibility&&delete g.applicability}if(g.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(g.evidence.provenance)||typeof g.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:i,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:i,tierId:h})}c.add(h),f.add(m)}}}return n}function Ao(t,e){let r=new Set,n=structuredClone(t.categories);for(let o of e.updates){if(r.has(o.categoryKey))throw new d("invalid_operation",`Category ${o.categoryKey} may be updated only once`);r.add(o.categoryKey);let s=n.find(g=>g.key===o.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${o.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:o.categoryKey});let l=structuredClone(o.patch),{tiers:c,...f}=l;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(l,"tiers")&&(c==null?delete s.tiers:s.tiers=c?.map(g=>{let h={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?h.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete h.buyerMessage,h}))}let a=se(n),i=JSON.stringify(a)!==JSON.stringify(t.categories);return i&&(t.categories=a),{changed:i,categoryKeys:[...r],categories:t.categories}}function _r(t,e){let r=e.categoryKeys.map(l=>l.trim()),n=t.categories.map(l=>l.key);if(r.length!==n.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:n});let a=new Set(n),i=n.filter(l=>!r.includes(l)),o=r.filter(l=>!a.has(l));if(i.length||o.length)throw new d(o.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:i,unknownCategoryKeys:o});if(r.every((l,c)=>l===n[c]))return{changed:!1,categoryKeys:n,categories:t.categories};let s=new Map(t.categories.map(l=>[l.key,l]));return t.categories=se(r.map(l=>structuredClone(s.get(l)))),{changed:!0,categoryKeys:r,categories:t.categories}}var Mt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Ft(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(n=>n+n).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function Po(t,e){let r=Ft(t),n=Ft(e);return!r||!n?1/0:(r[0]-n[0])**2+(r[1]-n[1])**2+(r[2]-n[2])**2}var jo=3600;function Ro(t,e,r=Mt){return r.find(a=>t.every(i=>Po(a,i)>=jo))??r[e%r.length]}function Or(t,e){let r=e?.palette??Mt;if(!t.categories.length)return{changed:[],categories:t.categories};let n=new Map(t.categories.map(o=>[o.key,o.color.toLowerCase()])),a=t.categories.map((o,s)=>({categoryKey:o.key,patch:{color:r[s%r.length]}}));return Ao(t,{updates:a}),{changed:t.categories.map(o=>({key:o.key,from:n.get(o.key),to:o.color})).filter(o=>o.from!==o.to),categories:t.categories}}function Ar(t,e){let r=e.color.trim().toLowerCase(),n=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!n||n.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let a=structuredClone(t.categories),i=a.find(l=>l.key===e.categoryKey);if(!i)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});i.color=r,i.referenceCategorySource&&(i.referenceCategorySource.outputColorEvidence="user-confirmed",i.referenceCategorySource.outputColorSourceDescription=n);let o=se(a),s=JSON.stringify(o)!==JSON.stringify(t.categories);return s&&(t.categories=o),{changed:s,category:t.categories.find(l=>l.key===e.categoryKey),categories:t.categories}}function Fo(t,e){let r=new Set(t.categories.map(o=>o.key)),n="";for(let o=0;o<100;o++){let l=e.idFactory("cat").trim();if(l&&!r.has(l)){n=l;break}}if(!n)throw new d("id_generation_failed","Unable to allocate a unique category id");let a={key:n,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(o=>({...o,id:o.id.trim(),name:o.name.normalize("NFKC").trim()}))},i=se([...t.categories,a]);return t.categories=i,{changed:!0,category:i.find(o=>o.key===n),categories:i}}var ko=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],Mo=26;function No(t,e,r){let n=(1-Math.abs(2*r-1))*e,a=(t%360+360)%360/60,i=n*(1-Math.abs(a%2-1)),[o,s,l]=a<1?[n,i,0]:a<2?[i,n,0]:a<3?[0,n,i]:a<4?[0,i,n]:a<5?[i,0,n]:[n,0,i],c=r-n/2,f=g=>Math.round((g+c)*255).toString(16).padStart(2,"0");return`#${f(o)}${f(s)}${f(l)}`}function To(t,e,r){let n=o=>t.every(s=>{let l=yt(o,s);return l==null||l>=Mo}),a=o=>{let s=Ne(o,"#12151d"),l=Ne(o,"#ffffff");return(s??0)>=3||(l??0)>=3},i=e.find(o=>n(o)&&a(o));if(i)return i;for(let o=0;o<360;o+=12)for(let s of[.52,.44,.6]){let l=No(o,.62,s);if(n(l)&&a(l))return l}return r}function Nt(t,e){let r=ge.find(a=>a.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function Lo(t){let e=new Map;for(let r of T(t))for(let n of r.objects){let a=ge.find(o=>o.objectType===n.type);if(!a)continue;let i=new Set;if(n.type==="row"||n.type==="table")for(let o of he(n).keys())i.add(o);else"categoryKey"in n&&n.categoryKey&&i.add(n.categoryKey);for(let o of i){let s=e.get(o)??new Set;s.add(a.objectType),e.set(o,s)}}return e}function Pr(t,e,r,n){let a=r,i=Lo(t),o=g=>{let h=i.get(g);return!h||h.size===0||h.size===1&&h.has(a)},s=t.categories.find(g=>g.key===e);if(s&&o(s.key))return s.key;if(!s){let g=t.categories.find(h=>{let u=i.get(h.key);return u?.size===1&&u.has(a)});if(g)return g.key}let l=s;if(!l)return kt(t,r,void 0,n);let c=Nt(l.label,r),f=t.categories.find(g=>g.label.toLowerCase()===c.toLowerCase()&&o(g.key));return f?f.key:kt(t,r,l,n)}function kt(t,e,r,n){let a=ge.find(m=>m.objectType===e),i=e==="gaArea"?"General Admission":a.creationWord,o=r?Nt(r.label,e):i,s=n.palette??ko,l=t.categories.map(m=>m.color),c=n.suggestColor?.(l.map(m=>m.toLowerCase()))??Ro(l,t.categories.length),f=To(l,s,c),g=new Set(t.categories.map(m=>m.label.toLowerCase())),h=o;for(let m=2;g.has(h.toLowerCase());m+=1)h=`${o} ${m}`;let u=Fo(t,{label:h,color:f,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:n.idFactory});return t.categories=u.categories,u.category.key}function Ko(t,e){let r=new Set;for(let n of T(t))for(let a of n.objects)"categoryKey"in a&&a.categoryKey===e&&r.add(a.id),(a.type==="row"||a.type==="table")&&a.overrides?.some(i=>i.categoryKey===e)&&r.add(a.id);return[...r]}function jr(t,e){let r=t.categories.find(i=>i.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let n=Ko(t,e.categoryKey);if(n.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:n});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let a=se(t.categories.filter(i=>i.key!==e.categoryKey));return t.categories=a,{changed:!0,categoryKey:e.categoryKey,categories:a}}var Go=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Tt=.7,Lt=1.6;function Mr(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let n=JSON.stringify(t.theme??null),a={...t.theme??{}};for(let i of Go){let o=r[i];o===null?delete a[i]:o!==void 0&&(a[i]=N(o,`Theme ${i}`))}if(r.fontFamily===null)delete a.fontFamily;else if(r.fontFamily!==void 0){let i=r.fontFamily.normalize("NFKC").trim();if(!i||i.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");a.fontFamily=i}if(r.seatScale===null)delete a.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<Tt||r.seatScale>Lt)throw new d("invalid_operation",`Theme seatScale must be from ${Tt} to ${Lt}`);a.seatScale=r.seatScale}if(r.logoUrl===null)delete a.logoUrl;else if(r.logoUrl!==void 0){let i=r.logoUrl.trim();if(!/^(https:\/\/|data:image\/)/.test(i)||i.length>2e6)throw new d("invalid_operation","Theme logoUrl must be an https or data:image reference");a.logoUrl=i}if(r.brandName===null)delete a.brandName;else if(r.brandName!==void 0){let i=r.brandName.normalize("NFKC").trim();if(!i||i.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");a.brandName=i}return r.hideBadge===null||r.hideBadge===!1?delete a.hideBadge:r.hideBadge===!0&&(a.hideBadge=!0),t.theme=Object.keys(a).length?a:void 0,{changed:JSON.stringify(t.theme??null)!==n,theme:t.theme??null}}function Nr(t,e){let r=e.url===null?null:e.url.trim();if(r!==null&&(!/^(https:\/\/|data:image\/)/.test(r)||r.length>2e6))throw new d("invalid_operation","View-from-seat photo must be an https or data:image reference");let n=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let l=(s.viewFromSeatUrl??void 0)===n,c=n?e.metadata===null?void 0:e.metadata??(l?s.viewFromSeatMeta:void 0):void 0,f=!l||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(c??null);return s.viewFromSeatUrl=n,s.viewFromSeatMeta=c,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let a=(t.viewFromSeatUrl??void 0)===n,i=n?e.metadata===null?void 0:e.metadata??(a?t.viewFromSeatMeta:void 0):void 0,o=!a||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(i??null);return t.viewFromSeatUrl=n,t.viewFromSeatMeta=i,{changed:o,scope:"venue",url:t.viewFromSeatUrl??null}}function Tr(t,e){let r=be(t,e.floorId),n=st(r),a=e.placement==="auto"||e.placement==null?"rear":e.placement,i=96;return a==="front"?{x:n.x+n.width/2,y:n.y-i-e.height/2}:a==="left"?{x:n.x-i-e.width/2,y:n.y+n.height/2}:a==="right"?{x:n.x+n.width+i+e.width/2,y:n.y+n.height/2}:{x:n.x+n.width/2,y:n.y+n.height+i+e.height/2}}function Se(t,e){F(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let n=e.endAngle-e.startAngle;if(Math.abs(n)<5||Math.abs(n)>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 a=e.fit??"seat-pitch";if(a==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let i=e.taperDegrees??0,o=e.skewDegrees??0;if(!r(i,o)||Math.abs(i)>120||Math.abs(o)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let c=v(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:a,facing:e.facing??"inward",taperDegrees:i,skewDegrees:o,aisleGaps:s,rowLabelStart:e.rowLabelStart??c,seatLabelStart:e.seatLabelStart??1}}function Do(t,e,r){let n=r*H;return{x:t.x+e*Math.sin(n),y:t.y+e*Math.cos(n)}}function $o(t,e,r,n){let a=Math.abs(n-r)*H,i=[["left",.25],["center",.5],["right",.75]].flatMap(([c,f])=>{let g=t.aisleGaps[c];if(!g)return[];let h=g/e/a/2;return[[Math.max(0,f-h),Math.min(1,f+h)]]}).sort((c,f)=>c[0]-f[0]),o=[];for(let c of i){let f=o[o.length-1];f&&c[0]<=f[1]?f[1]=Math.max(f[1],c[1]):o.push([...c])}let s=[],l=0;for(let c of o)c[0]-l>1e-6&&s.push([l,c[0]]),l=Math.max(l,c[1]);return 1-l>1e-6&&s.push([l,1]),s.filter(([c,f])=>e*a*(f-c)>=t.seatPitch*.75)}function Eo(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let n=e-r,a=t.reduce((l,c)=>l+c,0),i=t.map(l=>n*l/a),o=i.map(l=>2+Math.floor(l)),s=e-o.reduce((l,c)=>l+c,0);return i.map((l,c)=>({index:c,fraction:l-Math.floor(l)})).sort((l,c)=>c.fraction-l.fraction||l.index-c.index).forEach(({index:l})=>{s-- >0&&o[l]++}),o}function ve(t,e,r){let n=[];for(let a=0;a<t.rowCount;a++){let i=t.rowCount===1?0:a/(t.rowCount-1),o=t.innerRadius+a*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,l=t.startAngle+s*t.taperDegrees*i+t.skewDegrees*i,c=t.endAngle-s*t.taperDegrees*i+t.skewDegrees*i;if(Math.sign(c-l)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(c-l)<5)throw new d("invalid_operation",`Arc/Fan taper collapses row ${a+1} below a 5\xB0 sweep`);let f=$o(t,o,l,c);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${a+1}`);t.facing==="outward"&&(f=f.slice().reverse());let g=f.map(([m,y])=>o*Math.abs(c-l)*H*(y-m)),h=t.fit==="fixed-count"?Eo(g,t.seatsPerRow):g.map(m=>Math.max(2,Math.round(m/t.seatPitch)+1)),u=t.seatLabelStart;f.forEach(([m,y],w)=>{let _=l+(c-l)*m,b=l+(c-l)*y;t.facing==="outward"&&([_,b]=[b,_]);let p=h[w];if(p>300)throw new d("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let C=Math.abs(b-_)*H/(p-1),I=2*o*Math.sin(C/2),S={type:"row",id:r(a,w),label:K(t.rowLabelStart+a),origin:Do(t.center,o,_),rotation:-_,curve:b-_,seatCount:p,seatSpacing:I,categoryKey:t.categoryKey,seatLabelStart:u,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:a,segmentIndex:w}};n.push(S),u+=p})}return n}function Kt(t,e){let r=Se(t,e),n=v(t,e.floorId),a=ve(r,"preview-arc-fan",(l,c)=>`preview-fan-${l}-${c}`),i=a.map(l=>l.seatSpacing),o=Math.max(...i.map(l=>Math.abs(l-r.seatPitch))),s=[];return o>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${o.toFixed(1)} chart units`),a.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:n.floorId,rows:a,logicalRowCount:r.rowCount,rowSegmentCount:a.length,totalSeats:a.reduce((l,c)=>l+c.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...i),maxSeatSpacing:Math.max(...i),maxPitchDeviation:o,aisleCount:Object.values(r.aisleGaps).filter(l=>l>0).length,warnings:s}}function Dr(t,e){let r=Se(t,e),n=v(t,e.floorId),a=new Set,i=j(t,"fan",e.idFactory,a),o=ve(r,i,()=>j(t,"r",e.idFactory,a)),s=Kt(t,e),l=null,c=e.sectionLabel?.normalize("NFKC").trim(),f=null;if(c){if(c.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let g=Y(o);g&&(l=j(t,"sec",e.idFactory,a),f={type:"section",id:l,label:c,outline:g,arcFanGroupId:i})}return n.objects.push(...o,...f?[f]:[]),{floorId:n.floorId,rowIds:o.map(g=>g.id),sectionId:l,groupId:i,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 zo(t,e){let r=v(t,e.floorId),n=r.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!n.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let a=n[0].arcFanGeneration,i=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(n.some(g=>i(g)!==i(n[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let o=r.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:r.floorId,center:{...a.center},innerRadius:a.innerRadius,rowCount:a.rowCount,rowGap:a.rowGap,startAngle:a.startAngle,endAngle:a.endAngle,seatPitch:a.seatPitch,fit:a.fit,seatsPerRow:a.seatsPerRow,facing:a.facing,taperDegrees:a.taperDegrees,skewDegrees:a.skewDegrees,aisleGaps:{...a.aisleGaps},categoryKey:n[0].categoryKey,rowLabelStart:a.rowLabelStart,seatLabelStart:a.seatLabelStart,sectionLabel:o?.label},l=Se(t,s),c=new Set(ve(l,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),f=new Set(n.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(c.size!==f.size||[...c].some(g=>!f.has(g)))throw new d("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function $r(t,e){zo(t,{floorId:e.floorId,groupId:e.groupId});let r=Se(t,e),n=v(t,e.floorId),a=n.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),i=n.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),o=new Map(a.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,l=ve(r,e.groupId,(y,w)=>o.get(`${y}:${w}`)??j(t,"r",e.idFactory,s)),c=Kt(t,e),f=e.sectionLabel?.normalize("NFKC").trim(),g=null;if(f){if(f.length>80)throw new d("invalid_operation","Arc/Fan section label must contain at most 80 characters");let y=Y(l);y&&(g={type:"section",id:i?.id??j(t,"sec",e.idFactory,s),label:f,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...a.map(y=>y.id),...i?[i.id]:[]]),u=Math.min(...n.objects.map((y,w)=>h.has(y.id)?w:1/0)),m=n.objects.filter(y=>!h.has(y.id));return m.splice(Number.isFinite(u)?u:m.length,0,...l,...g?[g]:[]),n.objects.splice(0,n.objects.length,...m),{floorId:n.floorId,rowIds:l.map(y=>y.id),sectionId:g?.id??null,groupId:e.groupId,logicalRowCount:c.logicalRowCount,rowSegmentCount:c.rowSegmentCount,totalSeats:c.totalSeats,innerRadius:c.innerRadius,outerRadius:c.outerRadius,minSeatSpacing:c.minSeatSpacing,maxSeatSpacing:c.maxSeatSpacing,maxPitchDeviation:c.maxPitchDeviation,aisleCount:c.aisleCount,warnings:c.warnings}}function Bo(t){let e=new Set(J(t).filter(n=>n.type==="row"||n.type==="table"||n.type==="booth").map(n=>n.label).filter(n=>typeof n=="string")),r=0;return()=>{for(;e.has(K(r));)r+=1;let n=K(r);return e.add(n),r+=1,n}}function Gt(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(F(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,n=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(n)||n<=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 a=v(t,e.floorId),i=new Set,o=Bo(t),s=$e(e.rotation??0),l=e.curve??0,c=e.style,f=c?j(t,"rowblock",e.idFactory,i):void 0,g=c?Gt({style:c,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:n,curve:l}):void 0,h={x:Math.cos(s*B),y:Math.sin(s*B)},u={x:-h.y,y:h.x},m=Array.from({length:e.rowCount},(_,b)=>{let p=c==="intertwined"&&b%2===1?n/2:0,C={type:"row",id:j(t,"r",e.idFactory,i),label:o(),origin:{x:e.origin.x+u.x*b*r+h.x*p,y:e.origin.y+u.y*b*r+h.y*p},rotation:s,curve:l,seatCount:e.seatsPerRow,seatSpacing:n,categoryKey:e.categoryKey};return c&&f&&g&&(C.rowBlockGeneration={kind:"row-block-v1",groupId:f,style:c,rowIndex:b,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:r,seatSpacing:n,curve:l,signature:g}),C});a.objects.push(...m);let y=null,w=e.sectionLabel?.trim();if(w){let _=Y(m);if(_){let b={type:"section",id:j(t,"sec",e.idFactory,i),label:w,outline:_};a.objects.push(b),y=b.id}}return{floorId:a.floorId,rowIds:m.map(_=>_.id),sectionId:y,createdIds:[...m.map(_=>_.id),...y?[y]:[]]}}function Dt(t,e){let r=new Set(J(t).filter(a=>a.type==="row"||a.type==="table"||a.type==="booth").map(a=>a.label).filter(a=>typeof a=="string")),n=1;return()=>{for(;r.has(`${e}${n}`);)n+=1;let a=`${e}${n}`;return r.add(a),n+=1,a}}function Uo(t,e){let r=new Set(J(t).filter(a=>a.type==="gaArea").map(a=>a.label));if(!r.has(e))return e;let n=2;for(;r.has(`${e} ${n}`);)n+=1;return`${e} ${n}`}var Jo=456;function Ho(t){let e=Math.sqrt(Math.max(1,t)*Jo);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function qr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new d("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","GA area center must be finite");let r=v(t,e.floorId),n=new Set,{width:a,height:i}=Ho(e.capacity),o=Uo(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:j(t,"ga",e.idFactory,n),label:o,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-a/2,y:e.center.y-i/2},{x:e.center.x+a/2,y:e.center.y-i/2},{x:e.center.x+a/2,y:e.center.y+i/2},{x:e.center.x-a/2,y:e.center.y+i/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:o,createdIds:[s.id]}}function Xr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,n=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(n)||n<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 a=v(t,e.floorId),i=new Set,o=Dt(t,"T"),s=[];for(let l=0;l<e.tableRows;l+=1)for(let c=0;c<e.tableColumns;c+=1)s.push({type:"table",id:j(t,"t",e.idFactory,i),label:o(),center:{x:e.center.x+(c-(e.tableColumns-1)/2)*r,y:e.center.y+(l-(e.tableRows-1)/2)*n},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 a.objects.push(...s),{floorId:a.floorId,tableIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Vr(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,n=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(n)||n<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 a=v(t,e.floorId),i=new Set,o=Dt(t,"B"),s=[];for(let l=0;l<e.boothRows;l+=1)for(let c=0;c<e.boothColumns;c+=1)s.push({type:"booth",id:j(t,"booth",e.idFactory,i),label:o(),center:{x:e.center.x+(c-(e.boothColumns-1)/2)*r,y:e.center.y+(l-(e.boothRows-1)/2)*n},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return a.objects.push(...s),{floorId:a.floorId,boothIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Yr(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2||n.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==n.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let a=n.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),i=n.filter((h,u)=>!a[u]);if(i.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:i});let o=a,s=o.filter(h=>h.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let l=(e.displayLabel??o[0].displayLabel??o[0].label).normalize("NFKC").trim();if(!l||l.length>80)throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let c=new Set(r.objects.flatMap(h=>h.type==="row"?[h.segmentedRow?.groupId,h.rowBlockGeneration?.groupId].filter(u=>!!u):[])),f="";for(let h=0;h<100;h+=1){let u=e.idFactory("rowgroup");if(u&&!c.has(u)){f=u;break}}if(!f)throw new d("id_generation_failed","Unable to allocate a segmented-row group id");let g=o[0];return o.forEach((h,u)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:u,componentCount:o.length,boundaryBefore:u===0?"start":e.boundaries[u-1],displayLabel:l,...g.displayType?{displayType:g.displayType}:{},...g.labelPresentation?{labelPresentation:structuredClone(g.labelPresentation)}:{},...g.viewFromSeatUrl?{viewFromSeatUrl:g.viewFromSeatUrl}:{},...g.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(g.viewFromSeatMeta)}:{},...g.confidenceEvidence?{confidenceEvidence:structuredClone(g.confidenceEvidence)}:{}}}),{floorId:r.floorId,groupId:f,rowIds:n,changed:!0}}function Zr(t,e){let r=v(t,e.floorId),n=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),a=e.groupId??n?.segmentedRow?.groupId;if(!a)throw new d("object_not_found","The segmented row does not exist on the selected floor");let i=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===a);if(!i.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let o=i.sort((s,l)=>s.segmentedRow.componentIndex-l.segmentedRow.componentIndex).map(s=>s.id);for(let s of i)delete s.segmentedRow;return{floorId:r.floorId,groupId:a,rowIds:o,changed:!0}}function Wr(t,e){let r=v(t,e.floorId),n=r.objects.filter(o=>o.type==="row"&&o.segmentedRow?.groupId===e.groupId).sort((o,s)=>o.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(n.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!==n.length-1||e.boundaries.some(o=>o!=="continuous"&&o!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let a=e.displayLabel?.normalize("NFKC").trim();if(a!==void 0&&(!a||a.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let i=JSON.stringify(n.map(o=>o.segmentedRow));return n.forEach((o,s)=>{let l=o.segmentedRow,c=l.viewFromSeatUrl;a!==void 0&&(l.displayLabel=a),e.boundaries&&s>0&&(l.boundaryBefore=e.boundaries[s-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!==c&&delete l.viewFromSeatMeta}),{floorId:r.floorId,groupId:e.groupId,rowIds:n.map(o=>o.id),changed:JSON.stringify(n.map(o=>o.segmentedRow))!==i}}function Qr(t,e){let r=v(t,e.floorId),n=r.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,G)=>O.rowBlockGeneration.rowIndex-G.rowBlockGeneration.rowIndex),a=n[0]?.rowBlockGeneration;if(!a||n.length!==a.rowCount||n.some((O,G)=>{let R=O.rowBlockGeneration;return R.kind!=="row-block-v1"||R.rowIndex!==G||R.signature!==a.signature||JSON.stringify(R)!==JSON.stringify({...a,rowIndex:G})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let i=JSON.stringify(n),o=e.style??a.style,s=e.rowCount??a.rowCount,l=e.seatsPerRow??a.seatsPerRow,c=e.rowGap??a.rowGap,f=e.seatSpacing??a.seatSpacing,g=e.curve??a.curve,h=Number.isFinite(e.rotation??a.rotation)?$e(e.rotation??a.rotation):e.rotation??a.rotation,u=e.origin?{...e.origin}:{...a.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(l)||l<1||l>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![c,f].every(O=>Number.isFinite(O)&&O>0)||!Number.isFinite(g)||!Number.isFinite(h)||!Number.isFinite(u.x)||!Number.isFinite(u.y))throw new d("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let m=Gt({style:o,origin:u,rotation:h,rowCount:s,seatsPerRow:l,rowGap:c,seatSpacing:f,curve:g}),y={x:Math.cos(h*B),y:Math.sin(h*B)},w={x:-y.y,y:y.x},_=new Map(n.map(O=>[O.rowBlockGeneration.rowIndex,O])),b=new Set,p=new Set(r.objects.filter(O=>O.type==="row").filter(O=>!n.includes(O)).map(O=>O.label)),C=r.objects.filter(O=>O.type==="row").length,I=()=>{for(;p.has(K(C));)C+=1;let O=K(C);return p.add(O),C+=1,O},S=[],P=[];for(let O=0;O<s;O+=1){let G=o==="intertwined"&&O%2===1?f/2:0,R=_.get(O);R||(R={type:"row",id:j(t,"r",e.idFactory,b),label:I(),origin:{...u},rotation:h,curve:g,seatCount:l,seatSpacing:f,categoryKey:n[0].categoryKey},P.push(R.id)),R.origin={x:u.x+w.x*O*c+y.x*G,y:u.y+w.y*O*c+y.y*G},R.rotation=h,R.curve=g,R.seatCount=l,R.seatSpacing=f,delete R.path,delete R.arcFanGeneration,R.overrides&&(R.overrides=R.overrides.filter(Ae=>Ae.index<l),R.overrides.length||delete R.overrides),R.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:o,rowIndex:O,rowCount:s,seatsPerRow:l,origin:{...u},rotation:h,rowGap:c,seatSpacing:f,curve:g,signature:m},S.push(R)}let q=n.slice(s).map(O=>O.id),U=Math.min(...n.map(O=>r.objects.indexOf(O))),X=new Set(n.map(O=>O.id)),E=r.objects.filter(O=>!X.has(O.id));return E.splice(U,0,...S),r.objects.splice(0,r.objects.length,...E),{floorId:r.floorId,groupId:e.groupId,rowIds:S.map(O=>O.id),createdRowIds:P,removedRowIds:q,changed:i!==JSON.stringify(S)||P.length>0||q.length>0}}var qo=300,Xo=40;function Vo(t){let e=new Set(J(t).filter(a=>a.type==="row"||a.type==="table"||a.type==="booth").map(a=>a.label).filter(a=>typeof a=="string")),r=0,n=()=>{for(;e.has(K(r));)r+=1;let a=K(r);return r+=1,a};return a=>{let i=a.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,Xo).trim(),o=0;return()=>{for(;i&&o<4096;o+=1){let l=`${i}-${K(o)}`;if(!e.has(l))return e.add(l),o+=1,l}let s=n();return e.add(s),s}}}function Yo(t,e){return t.filter(r=>(r.type==="row"||r.type==="table"||r.type==="booth"||r.type==="gaArea")&&!(r.type==="row"&&r.referenceScan?.assetId===e))}function Zo(t,e,r,n,a){let i=t.sectionId?e.find(l=>l.type==="section"&&l.id===t.sectionId):void 0;if(i){let l=Yo(e,r).filter(c=>L(M(c),i.outline,i.holes));if(l.length)return{skip:{sectionId:i.id,name:t.name,reason:"section_not_empty",objectIds:l.map(c=>c.id)},rows:[],seats:0}}let o=[],s=0;for(let l of t.rows){let c=Math.min(qo,Math.max(1,Math.round(l.seatCount)));if(!Number.isFinite(c)||c<1)continue;let f=l.end.x-l.start.x,g=l.end.y-l.start.y,h=Math.hypot(f,g),u=c>1&&h>0?h/(c-1):n>0?n:24;if(!Number.isFinite(u)||u<=0)continue;let m=h>0?Math.atan2(g,f)*180/Math.PI:0;o.push({label:a(),origin:{x:l.start.x,y:l.start.y},rotation:m,seatCount:c,seatSpacing:u}),s+=c}return{skip:null,rows:o,seats:s}}function ri(t,e,r){F(t,r.categoryKey);let n=v(t,r.floorId),a=e.assetId,i=[],o=n.objects.filter(u=>u.type==="row"&&u.referenceScan?.assetId===a?(i.push(u.id),!1):!0);n.objects.splice(0,n.objects.length,...o);let s=[],l=[],c=[],f=new Set,g=0,h=Vo(t);for(let u of e.sections){let m=Zo(u,n.objects,a,e.seatPitch,h(u.name));if(m.skip){l.push(m.skip);continue}let y=m.rows.map(w=>({type:"row",id:j(t,"r",r.idFactory,f),referenceScan:{assetId:a},label:w.label,origin:w.origin,rotation:w.rotation,curve:0,seatCount:w.seatCount,seatSpacing:w.seatSpacing,categoryKey:r.categoryKey}));n.objects.push(...y);for(let w of y)c.push(w.id);s.push({sectionId:u.sectionId,name:u.name,seats:m.seats,rows:y.length}),g+=m.seats}return{floorId:n.floorId,assetId:a,createdRowIds:c,removedRowIds:i,totalSeats:g,perSection:s,skipped:l}}function $t(t,e){let r=v(t,e.floorId),n=[...new Set(e.objectIds)];if(!n.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let a=n.map(u=>r.objects.find(m=>(m.type==="table"||m.type==="booth")&&m.id===u)),i=n.filter((u,m)=>!a[m]);if(i.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:i});let o=a[0].type;if(a.some(u=>u.type!==o))throw new d("invalid_operation","A grid array must contain only tables or only booths");for(let[u,m,y]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(m)||m<1||m>y)throw new d("invalid_operation",`${u} must be a whole number from 1 to ${y}`);for(let[u,m]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(m)||m<30||m>2e3)throw new d("invalid_operation",`${u} must be from 30 to 2000 chart units`);let s=e.rows*e.columns;if(s<2)throw new d("invalid_operation","Choose at least two grid cells");let l=n.length*(s-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let c=a.reduce((u,m)=>u+(m.type==="table"?m.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(u=>u.objects):t.objects).reduce((u,m)=>u+(m.type==="row"||m.type==="table"?m.seatCount:m.type==="gaArea"?Math.max(0,Math.floor(m.capacity)):m.type==="booth"?1:0),0),h=c*(s-1);if(g+h>Q)throw new d("invalid_operation",`Grid inventory would exceed the ${Q} unit event limit`);return{target:r,sources:a,preview:{floorId:r.floorId,kind:o,sourceIds:n,sourceCount:n.length,cells:s,createdCount:l,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:a.filter(u=>!!u.referenceInventorySource).length*(s-1)}}}function li(t,e){return $t(t,e).preview}function ci(t,e){let{target:r,sources:n,preview:a}=$t(t,e),i=new Set,o=new Set((t.floors?.length?t.floors.flatMap(f=>f.objects):t.objects).flatMap(f=>"label"in f&&f.label?[f.label]:[])),s=[],l=(f,g)=>{let h=Math.max(2,g),u=y=>{let w=`-${y}`;return`${f.slice(0,Math.max(1,80-w.length))}${w}`},m=u(h);for(;o.has(m);)m=u(++h);return o.add(m),m},c=1;for(let f=0;f<e.rows;f++)for(let g=0;g<e.columns;g++)if(!(f===0&&g===0)){c+=1;for(let h of n){let u=structuredClone(h);u.id=j(t,u.type,e.idFactory,i),u.label=l(h.label,c),u.center={x:h.center.x+g*e.stepX,y:h.center.y+f*e.stepY},delete u.referenceInventorySource,s.push(u)}}return r.objects.push(...s),{...a,createdIds:s.map(f=>f.id)}}function Wo(t,e){let r=t?{...t}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=N(e.color,"Seat label color")),r.size===void 0&&r.color===void 0?void 0:r}var Qo=new Set(ce.map(t=>t.key));function xe(t){return`${t.rowId}:${t.index}`}function gi(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",n=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(n)||n<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:n}}function en(t){if(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,t.accessible&&!t.accessibility?.length&&(t.accessibility=["wheelchair"]),delete t.accessible,t.wheelchairSpaceType&&!t.accessibility?.includes("wheelchair")&&(t.accessibility=["wheelchair",...t.accessibility??[]]),t.accessibility?.length||delete t.accessibility,t.commercial){let e=t.commercial.note?.normalize("NFKC").trim(),r={};typeof t.commercial.restrictedView=="boolean"&&(r.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(r.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(r.premium=t.commercial.premium),e&&(r.note=e),Object.keys(r).length?t.commercial=r: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}function tn(t){return Object.keys(t).every(e=>e==="index")}function Et(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let n=v(t,e),a=[],i=new Set,o=new Map;for(let s of r){let l=xe(s);if(i.has(l))continue;i.add(l);let c=n.objects.find(f=>(f.type==="row"||f.type==="table")&&f.id===s.rowId);if(!c)throw new d("object_not_found",`Unknown row or table for seat: ${l}`,{seatId:l,objectId:s.rowId});if(c.type==="table"&&(c.bookAsWhole||c.variableOccupancy))throw new d("invalid_operation",`Table "${c.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:l,tableId:c.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=c.seatCount)throw new d("invalid_operation",c.type==="row"?`Seat index is outside row bounds: ${l}`:`Chair index is outside table bounds: ${l}`,{seatId:l,objectId:s.rowId,index:s.index,seatCount:c.seatCount});a.push({rowId:s.rowId,index:s.index}),o.set(c.id,c)}return{floorId:n.floorId,refs:a,owners:o}}function hi(t,e){let r=Et(t,e.floorId,e.seats),n=Object.keys(e.patch);if(!n.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&F(t,e.patch.categoryKey),e.patch.accessibility){let i=e.patch.accessibility.filter(o=>!Qo.has(o));if(i.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:i})}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 i of r.refs){let o=r.owners.get(i.rowId)?.overrides?.find(c=>c.index===i.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??o?.wheelchairSpaceType,l=e.patch.skip===null?!1:e.patch.skip??o?.skip??!1;if(s&&l)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:xe(i)})}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");for(let i of["dx","dy"]){let o=e.patch[i];if(o!=null&&!Number.isFinite(o))throw new d("invalid_operation",`${i} must be finite`,{[i]:o})}e.patch.labelStyle!=null&&te(e.patch.labelStyle,"Seat");let a=!1;return r.refs.forEach((i,o)=>{let s=r.owners.get(i.rowId),l=JSON.stringify(s.overrides??[]),c=s.overrides??(s.overrides=[]),f=c.find(h=>h.index===i.index);f||(f={index:i.index},c.push(f));let g=f.viewFromSeatUrl;for(let h of n){let u=e.patch[h];if(h==="wheelchairSpaceType"&&u==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(m=>m!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(u==null)delete f[h];else if(h==="accessibility")f.accessibility=[...new Set(u)],delete f.accessible;else if(h==="commercial")f.commercial={...f.commercial,...u};else if(h==="labelStyle"){let m=Wo(f.labelStyle,u);m?f.labelStyle=m:delete f.labelStyle}else Object.assign(f,{[h]:u})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==g&&delete f.viewFromSeatMeta,e.labelPrefix!==void 0&&(f.label=`${e.labelPrefix}${o+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${o+1}`),en(f),tn(f)&&(s.overrides=c.filter(h=>h!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==l&&(a=!0)}),{floorId:r.floorId,changed:a,seatIds:r.refs.map(xe)}}function bi(t,e){let r=Et(t,e.floorId,e.seats),n=!1;for(let[a,i]of r.owners){if(!i.overrides?.length)continue;let o=new Set(r.refs.filter(l=>l.rowId===a).map(l=>l.index)),s=i.overrides.filter(l=>!o.has(l.index));s.length!==i.overrides.length&&(n=!0),i.overrides=s,i.overrides.length||delete i.overrides}return{floorId:r.floorId,changed:n,seatIds:r.refs.map(xe)}}function wi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)],a=n.map(b=>r.objects.find(p=>p.type==="row"&&p.id===b)),i=n.filter((b,p)=>!a[p]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});if(e.patch.categoryKey!==void 0&&F(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let b=e.patch.seatNumbering,p=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(b.scheme!==void 0&&!p.includes(b.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${b.scheme}. Expected one of ${p.join(", ")}.`);if(b.prefix!==void 0&&(typeof b.prefix!="string"||b.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(b.endAt!==void 0&&b.endAt!==null&&(!Number.isInteger(b.endAt)||b.endAt<0||b.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:o,labelPosition:s,labelRotation:l,labelStyleShape:c,displayLabel:f,displayType:g,...h}=e.patch,u=f===void 0?{}:{displayLabel:f},m=ee(u,"Row"),y=g===void 0?void 0:Le(g,"Row");if(o!==void 0&&te(o,"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(l!=null&&(!Number.isFinite(l)||l<-180||l>180))throw new d("invalid_operation","Row labelRotation must be a number from -180 to 180");if(c!==void 0&&c!=="plain"&&c!=="pill")throw new d("invalid_operation","Row labelStyleShape must be plain or pill");h.labelPresentation!==void 0&&me(h.labelPresentation,"Row");let w=b=>JSON.stringify({origin:b.origin,rotation:b.rotation,curve:b.curve,seatCount:b.seatCount,seatSpacing:b.seatSpacing,path:b.path??null}),_=!1;for(let b of a){let p=JSON.stringify(b),C=w(b),I=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?M(b):null;if(Object.assign(b,structuredClone(h)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(S=>S.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),I){let S=M(b);b.origin={x:b.origin.x+I.x-S.x,y:b.origin.y+I.y-S.y}}if(JSON.stringify(b)!==p&&(_=!0),w(b)!==C&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),o!==void 0){let S=JSON.stringify(b.labelPresentation??null),P=ye(b.labelPresentation,o);P?b.labelPresentation=P:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==S&&(_=!0)}if(s!==void 0){let S=JSON.stringify(b.labelPresentation??null),P=b.labelPresentation?structuredClone(b.labelPresentation):{};P.positionPreset=s,P.visible=s!=="none",delete P.position,b.labelPresentation=P,JSON.stringify(b.labelPresentation??null)!==S&&(_=!0)}if(l!==void 0||c!==void 0){let S=JSON.stringify(b.labelPresentation??null),P=b.labelPresentation?structuredClone(b.labelPresentation):{};l===null?delete P.rotation:l!==void 0&&(P.rotation=l),c!==void 0&&(P.style=c),b.labelPresentation=P,JSON.stringify(b.labelPresentation??null)!==S&&(_=!0)}if(y!==void 0){let S=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==S&&(_=!0)}if(f!==void 0){let S=b.displayLabel;m?delete b.displayLabel:b.displayLabel=u.displayLabel,b.displayLabel!==S&&(_=!0)}}return{floorId:r.floorId,changed:_,rowIds:n}}var on=3;function Ce(t){return(t%360+360)%360}function nn(t){let e=t.rotation*B;return{x:Math.cos(e),y:Math.sin(e)}}function rn(t,e){let r=Math.abs(Ce(t-e));return r>180&&(r=360-r),r}function oe(t,e,r){return(t.x-e.x)*r.x+(t.y-e.y)*r.y}function zt(t){let e=0,r=0;for(let a of t){let i=2*a.rotation*B;e+=Math.cos(i),r+=Math.sin(i)}let n=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(n),y:Math.sin(n)}}function an(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let n=a=>({x:a.x+e,y:a.y+r});t.path={start:n(t.path.start),control1:n(t.path.control1),control2:n(t.path.control2),end:n(t.path.end)}}}function Bt(t,e){let r=zt(t),n={x:-r.y,y:r.x},a=M(t[0]),i=t.map(l=>({row:l,coord:oe(M(l),a,n)})).sort((l,c)=>l.coord-c.coord),o=i[0].coord,s=!1;return i.forEach((l,c)=>{let f=o+c*e-l.coord;Math.abs(f)>1e-6&&(an(l.row,n.x*f,n.y*f),delete l.row.arcFanGeneration,delete l.row.rowBlockGeneration,s=!0)}),s}function sn(t,e){let r={x:-e.y,y:e.x},n=M(t[0]),a=t.map(o=>oe(M(o),n,r)).sort((o,s)=>o-s);if(a.length<2)return 28;let i=(a[a.length-1]-a[0])/(a.length-1);return i>.5?i:28}function ln(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=ke(t),r=e[0],n=e[e.length-1],a=n.x-r.x,i=n.y-r.y,o=Math.hypot(a,i);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,o/(t.seatCount-1))),o>1e-6&&(t.rotation=Ce(Math.atan2(i,a)/B)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function cn(t,e){let r=new Set(t.filter(n=>n.type==="row").map(n=>n.label));for(let n=2;n<1e4;n++){let a=`${e}${n}`.slice(0,80);if(!r.has(a))return a}return`${e}-${Date.now().toString(36)}`}function Ii(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2)throw new d("invalid_operation","Select at least two rows to merge");let a=n.map(I=>r.objects.find(S=>S.type==="row"&&S.id===I)),i=n.filter((I,S)=>!a[S]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a,s=o.filter(I=>I.path||I.curve!==0);if(s.length)throw new d("invalid_operation","Only straight rows can be merged \u2014 straighten the rows first, then merge.",{rowIds:s.map(I=>I.id)});let l=o[0],c=o.find(I=>rn(I.rotation,l.rotation)>on);if(c)throw new d("invalid_operation","Rows must be parallel to merge \u2014 they point in different directions.",{rowIds:[l.id,c.id]});let f=nn(l),g={x:-f.y,y:f.x},h=Math.max(8,l.seatSpacing*.6),u=o.find(I=>Math.abs(oe(I.origin,l.origin,g))>h);if(u){let I=Math.round(Math.abs(oe(u.origin,l.origin,g)));throw new d("invalid_operation",`Rows must lie on the same line to merge \u2014 a selected row is offset ${I} units from the first.`,{rowIds:[l.id,u.id]})}let m=o.slice().sort((I,S)=>oe(I.origin,l.origin,f)-oe(S.origin,l.origin,f)),y=m.reduce((I,S)=>I+S.seatCount,0);if(y>300)throw new d("invalid_operation",`A merged row would have ${y} seats, over the 300-seat row limit. Merge fewer rows.`);let w=m[0],_=[],b=0;for(let I of m){if(I.overrides)for(let S of I.overrides)_.push({...structuredClone(S),index:S.index+b});b+=I.seatCount}w.seatCount=y,w.curve=0,delete w.path,_.length?w.overrides=_:delete w.overrides,delete w.arcFanGeneration,delete w.rowBlockGeneration;let p=m.slice(1).map(I=>I.id),C=new Set(p);for(let I=r.objects.length-1;I>=0;I--)C.has(r.objects[I].id)&&r.objects.splice(I,1);return{floorId:r.floorId,changed:!0,rowId:w.id,removedRowIds:p,seatCount:y}}function Si(t,e){let r=v(t,e.floorId),n=r.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!n)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(n.path)throw new d("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[n.id]});let a=n.seatCount,i=e.index;if(!Number.isInteger(i)||i<1||i>a-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${a-1} (the seat where the second row begins)`);let o=ke(n),s=a>1?n.curve/(a-1):0,l=a-i,c={type:"row",id:j(t,"r",e.idFactory,new Set),label:cn(r.objects,n.label),origin:{...o[i]},rotation:Ce(n.rotation-s*i),curve:s*(l-1),seatCount:l,seatSpacing:n.seatSpacing,categoryKey:n.categoryKey};if(n.seatNumbering&&(c.seatNumbering=structuredClone(n.seatNumbering)),n.seatLabelStart!=null&&(c.seatLabelStart=n.seatLabelStart),n.commercial&&(c.commercial=structuredClone(n.commercial)),n.viewFromSeatUrl&&(c.viewFromSeatUrl=n.viewFromSeatUrl),n.viewFromSeatMeta&&(c.viewFromSeatMeta=structuredClone(n.viewFromSeatMeta)),n.confidenceEvidence&&(c.confidenceEvidence=structuredClone(n.confidenceEvidence)),n.labelPresentation){let u=structuredClone(n.labelPresentation);delete u.position,c.labelPresentation=u}let f=[],g=[];if(n.overrides)for(let u of n.overrides)u.index<i?f.push(structuredClone(u)):g.push({...structuredClone(u),index:u.index-i});n.seatCount=i,n.curve=s*(i-1),f.length?n.overrides=f:delete n.overrides,delete n.arcFanGeneration,delete n.rowBlockGeneration,g.length&&(c.overrides=g);let h=r.objects.indexOf(n);return r.objects.splice(h+1,0,c),{floorId:r.floorId,changed:!0,rowId:n.id,newRowId:c.id,firstSeatCount:i,secondSeatCount:l,newLabel:c.label}}function vi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.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 a=n.map(s=>r.objects.find(l=>l.type==="row"&&l.id===s)),i=n.filter((s,l)=>!a[l]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=Bt(a,e.gap);return{floorId:r.floorId,changed:o,rowIds:n,gap:e.gap}}function xi(t,e){let r=v(t,e.floorId),n=[...new Set(e.rowIds)];if(n.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let a=n.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),i=n.filter((h,u)=>!a[u]);if(i.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:i});let o=a,s=()=>JSON.stringify(o.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),l=s();for(let h of o)ln(h);let c=zt(o),f=Ce(Math.atan2(c.y,c.x)/B);for(let h of o)h.rotation=f;let g=sn(o,c);return Bt(o,g),{floorId:r.floorId,changed:s()!==l,rowIds:n,gap:g}}import Be from"polygon-clipping";var Ut=100,Jt=512,Ue=8192,Qt=64,Ht=1e7,k=1e-7;function eo(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function to(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&eo(e[0],e[e.length-1]);)e.pop();return e}function le(t,e,r){let n=$(e,r,t);return Math.abs(n)>k?!1:t.x>=Math.min(e.x,r.x)-k&&t.x<=Math.max(e.x,r.x)+k&&t.y>=Math.min(e.y,r.y)-k&&t.y<=Math.max(e.y,r.y)+k}function oo(t,e,r,n){let a=$(t,e,r),i=$(t,e,n),o=$(r,n,t),s=$(r,n,e);return(a>k&&i<-k||a<-k&&i>k)&&(o>k&&s<-k||o<-k&&s>k)?!0:Math.abs(a)<=k&&le(r,t,e)||Math.abs(i)<=k&&le(n,t,e)||Math.abs(o)<=k&&le(t,r,n)||Math.abs(s)<=k&&le(e,r,n)}function dn(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let n=e+1;n<t.length;n+=1){let a=(n+1)%t.length;if(!(e===n||r===n||a===e)&&oo(t[e],t[r],t[n],t[a]))return!0}}return!1}function qt(t,e){return t.some((r,n)=>e.some((a,i)=>oo(r,t[(n+1)%t.length],a,e[(i+1)%e.length])))}function Je(t,e){return!e.some((r,n)=>le(t,r,e[(n+1)%e.length]))&&L(t,e,void 0)}function Oe(t,e,r){let n=to(t);if(n.length<3||n.length>Jt||n.some((a,i)=>!Number.isFinite(a.x)||!Number.isFinite(a.y)||Math.abs(a.x)>Ht||Math.abs(a.y)>Ht||eo(a,n[(i+1)%n.length]))||Math.abs(fe(n))<=k||dn(n))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${Jt} finite vertices per ring.`,{gaAreaId:r,ring:e});return n}function fn(t){let e=Oe(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>Qt)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let n=r.map(a=>Oe(a,"cutout",t.id));for(let a=0;a<n.length;a+=1){let i=n[a];if(!i.flatMap((s,l)=>{let c=i[(l+1)%i.length];return[s,{x:(s.x+c.x)/2,y:(s.y+c.y)/2}]}).every(s=>Je(s,e))||qt(i,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:a});for(let s=a+1;s<n.length;s+=1)if(qt(i,n[s])||Je(i[0],n[s])||Je(n[s][0],i))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:a})}return{outer:e,holes:n}}function _e(t){return t.map(e=>[e.x,e.y])}function Xt(t){return to(t.map(([e,r])=>({x:e,y:r})))}function Vt(t){return Math.abs(t.reduce((e,r,n)=>{let a=t[(n+1)%t.length];return e+r[0]*a[1]-a[0]*r[1]},0))/2}function un(t){return t.reduce((e,r)=>e+(Vt(r[0]??[])-r.slice(1).reduce((n,a)=>n+Vt(a),0)),0)}function He(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(He).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${He(e[r])}`).join(",")}}`}function Yt(t,e,r){let n=t[e];if(n===void 0)return null;let a=n.normalize("NFKC").trim();if(!a||a!==n||a.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return a}function Zt(t){return He({categoryKey:t.categoryKey,displayLabel:Yt(t,"displayLabel",80),displayType:Yt(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Wt(t,e){let r=Math.min(...t.points.map(a=>a.y)),n=Math.min(...t.points.map(a=>a.x));return[r,n,e]}function gn(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function no(t,e){let r=v(t,e.floorId),n=[...new Set(e.gaAreaIds)];if(n.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(n.length>Ut)throw new d("invalid_operation",`Join Areas supports at most ${Ut} areas at once`);let a=n.map(x=>r.objects.find(A=>A.type==="gaArea"&&A.id===x)),i=n.filter((x,A)=>!a[A]);if(i.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:i});let o=a;F(t,o[0].categoryKey);let s=Zt(o[0]),l=o.find(x=>Zt(x)!==s);if(l)throw new d("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[o[0].id,l.id]});let c=ie(t).objectToSection,f=c.get(o[0].id)??"__ungrouped__",g=o.find(x=>(c.get(x.id)??"__ungrouped__")!==f);if(g)throw new d("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[o[0].id,g.id],sectionIds:[f,c.get(g.id)??"__ungrouped__"]});let h=o.reduce((x,A)=>{if(!Number.isInteger(A.capacity)||A.capacity<1||A.capacity>ue)throw new d("invalid_operation",`GA area ${A.id} has invalid capacity`,{gaAreaId:A.id});return x+A.capacity},0);if(h>ue)throw new d("invalid_operation",`Joined GA capacity would be ${h}, over the ${ue}-unit area limit`,{capacity:h});let u=J(t).reduce((x,A)=>x+Z(A),0);if(u>Q)throw new d("invalid_operation",`Chart inventory exceeds the ${Q}-unit publication limit`,{inventory:u});let m=o.map(fn),y=m.reduce((x,A)=>x+A.outer.length+A.holes.reduce((D,V)=>D+V.length,0),0);if(y>Ue)throw new d("invalid_operation",`Join Areas supports at most ${Ue} source vertices`,{vertexCount:y});let w;try{let x=m.map(V=>[_e(V.outer)]);if(w=Be.union(x[0],...x.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 A=m.flatMap(V=>V.holes.map(Pe=>[_e(Pe)]));A.length&&(w=Be.difference(w,...A));let D=m.findIndex(V=>{let Pe=[_e(V.outer),...V.holes.map(_e)];return un(Be.intersection(Pe,w))<=k});if(D>=0)throw new d("invalid_operation",`GA area ${o[D].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:o[D].id})}catch(x){throw x instanceof d?x:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:x instanceof Error?x.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 _=Xt(w[0][0]),b=w[0].slice(1).map(Xt),p=_.length+b.reduce((x,A)=>x+A.length,0);if(b.length>Qt||p>Ue)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:b.length,vertexCount:p});Oe(_,"outline",o[0].id),b.forEach(x=>Oe(x,"cutout",o[0].id));let C=new Map(r.objects.map((x,A)=>[x.id,A])),I=o.slice().sort((x,A)=>gn(Wt(x,C.get(x.id)??Number.MAX_SAFE_INTEGER),Wt(A,C.get(A.id)??Number.MAX_SAFE_INTEGER))),S=I[0],P=structuredClone(t),q=v(P,r.floorId),U=q.objects.find(x=>x.type==="gaArea"&&x.id===S.id);U.points=structuredClone(_),b.length?U.holes=structuredClone(b):delete U.holes;let X=new Set(I.slice(1).map(x=>x.id));for(let x=q.objects.length-1;x>=0;x-=1)X.has(q.objects[x].id)&&q.objects.splice(x,1);let E=ie(P).objectToSection.get(S.id)??"__ungrouped__";if(E!==f)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:S.id,beforeSectionId:f,afterSectionId:E});let O=[],G=new Set;for(let x of I){if(!lt(x))throw new d("invalid_operation",`GA area ${x.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:x.id});let A=re(x);if(A.length!==x.capacity||A.some(D=>G.has(D)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:x.id});A.forEach(D=>G.add(D)),O.push(...ct(x))}if(O.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let R=new Set(o.map(x=>x.id));for(let x of J(t).filter(A=>A.type==="gaArea"&&!R.has(A.id))){let A=re(x).find(D=>G.has(D));if(A)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:A,gaAreaId:x.id})}let Ae=I.slice(1).map(x=>x.id);return{floorId:r.floorId,areaId:S.id,survivorLabel:S.label,removedAreaIds:Ae,sourceAreaCount:I.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:_.length,holeCount:b.length,sectionId:f,points:_,...b.length?{holes:b}:{},segments:O}}function Fi(t,e){let{segments:r,...n}=no(t,e);return n}function ki(t,e){let r=no(t,e),n=v(t,r.floorId),a=n.objects.find(l=>l.type==="gaArea"&&l.id===r.areaId);a.points=structuredClone(r.points),r.holes?.length?a.holes=structuredClone(r.holes):delete a.holes,a.capacity=r.capacity,a.inventorySegments=structuredClone(r.segments);let i=new Set(r.removedAreaIds);for(let l=n.objects.length-1;l>=0;l-=1)i.has(n.objects[l].id)&&n.objects.splice(l,1);let{segments:o,...s}=r;return{...s,changed:!0}}function Ki(t,e){let r=v(t,e.floorId),n=[...new Set(e.shapeIds)];if(!n.length)throw new d("invalid_operation","At least one shape id is required");let a=n.map(c=>r.objects.find(f=>f.type==="shape"&&f.id===c)),i=n.filter((c,f)=>!a[f]);if(i.length)throw new d("object_not_found",`Unknown shape id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:i});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new d("invalid_operation","At least one shape change is required");if(o.label!==void 0){if(n.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(o.label!==null){if(o.label=o.label.normalize("NFKC").trim(),!o.label)o.label=null;else if(o.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(o.fill!==void 0&&o.fill!==null&&(o.fill=N(o.fill,"Shape fill")),o.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(o.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(o.stroke!==void 0&&o.stroke!==null){if(!Number.isFinite(o.stroke.width)||o.stroke.width<.5||o.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");o.stroke={color:N(o.stroke.color,"Shape stroke"),width:o.stroke.width}}if(o.cornerRadius!==void 0&&o.cornerRadius!==null&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(o.opacity!==void 0&&o.opacity!==null&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(o.heightM!==void 0&&o.heightM!==null&&(!Number.isFinite(o.heightM)||o.heightM<.05||o.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(o.eventConfigurationIds!==void 0&&o.eventConfigurationIds!==null){let c=o.eventConfigurationIds.map(f=>f.normalize("NFKC").trim());if(!c.length||c.length>20||c.some(f=>!f||f.length>100)||new Set(c).size!==c.length)throw new d("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");o.eventConfigurationIds=c}if(o.lineCap!==void 0&&o.lineCap!==null&&!ut.includes(o.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(o.lineJoin!==void 0&&o.lineJoin!==null&&!gt.includes(o.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[c,f]of[["startEnding",o.startEnding],["endEnding",o.endEnding]])if(f!=null&&!ht.includes(f))throw new d("invalid_operation",`Shape ${c} must be none or arrow`);if(o.lineCap!=null||o.lineJoin!=null||o.startEnding!=null||o.endEnding!=null){let c=a.filter(f=>!Te(o.kind??f.kind));if(c.length)throw new d("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:c.map(f=>f.id)})}let l=!1;for(let c of a){let f=JSON.stringify(c);if(o.label===null?delete c.label:o.label!==void 0&&(c.label=o.label),o.fill===null?delete c.fill:o.fill!==void 0&&(c.fill=o.fill),o.kind!==void 0&&(c.kind=o.kind,Te(c.kind)||(delete c.lineCap,delete c.lineJoin,delete c.startEnding,delete c.endEnding)),o.stroke===null?delete c.stroke:o.stroke!==void 0&&(c.stroke={...o.stroke}),o.opacity===null?delete c.opacity:o.opacity!==void 0&&(c.opacity=o.opacity),o.heightM===null?delete c.heightM:o.heightM!==void 0&&(c.heightM=o.heightM),o.eventConfigurationIds===null?delete c.eventConfigurationIds:o.eventConfigurationIds!==void 0&&(c.eventConfigurationIds=[...o.eventConfigurationIds]),o.lineCap===null?delete c.lineCap:o.lineCap!==void 0&&(c.lineCap=o.lineCap),o.lineJoin===null?delete c.lineJoin:o.lineJoin!==void 0&&(c.lineJoin=o.lineJoin),o.startEnding===null?delete c.startEnding:o.startEnding!==void 0&&(c.startEnding=o.startEnding),o.endEnding===null?delete c.endEnding:o.endEnding!==void 0&&(c.endEnding=o.endEnding),o.cornerRadius===null)delete c.cornerRadius;else if(o.cornerRadius!==void 0){let g=Math.min(c.width??1/0,c.height??1/0),h=Number.isFinite(g)?g/2:o.cornerRadius;c.cornerRadius=c.kind==="rect"?Math.max(0,Math.min(o.cornerRadius,h)):o.cornerRadius}JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,shapeIds:n}}function ro(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),n=e.map(f=>f.y),a=Math.min(...r),i=Math.max(...r),o=Math.min(...n),s=Math.max(...n),l=Math.max(1,i-a),c=Math.max(1,s-o);return{cx:a+l/2,cy:o+c/2,width:l,height:c}}function Gi(t,e){let r=v(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let n=e.updates.map(o=>o.shapeId);if(new Set(n).size!==n.length)throw new d("invalid_operation","Shape ids must be unique");let a=e.updates.map(o=>{if(![o.width,o.height].every(Number.isFinite)||o.width<8||o.height<8||o.width>1e4||o.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:o.shapeId});let s=r.objects.find(c=>c.type==="shape"&&c.id===o.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${o.shapeId}`,{shapeId:o.shapeId});let l=s.role==="stage"?ro(s):(s.kind==="rect"||s.kind==="ellipse")&&s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null?{cx:s.x+s.width/2,cy:s.y+s.height/2,width:s.width,height:s.height}:(()=>{let c=s.points??[];if(c.length<3||c.some(w=>!Number.isFinite(w.x)||!Number.isFinite(w.y)))throw new d("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let f=c.map(w=>w.x),g=c.map(w=>w.y),h=Math.min(...f),u=Math.max(...f),m=Math.min(...g),y=Math.max(...g);return{cx:(h+u)/2,cy:(m+y)/2,width:Math.max(1,u-h),height:Math.max(1,y-m)}})();return{shape:s,update:o,box:l}}),i=!1;for(let{shape:o,update:s,box:l}of a)if(!(Math.abs(l.width-s.width)<1e-9&&Math.abs(l.height-s.height)<1e-9)){if(o.kind==="rect"||o.kind==="ellipse")o.x=l.cx-s.width/2,o.y=l.cy-s.height/2,o.width=s.width,o.height=s.height;else{let c=s.width/l.width,f=s.height/l.height;o.points=(o.points??[]).map(g=>({x:l.cx+(g.x-l.cx)*c,y:l.cy+(g.y-l.cy)*f})),(o.x!=null||o.y!=null||o.width!=null||o.height!=null||o.role==="stage")&&(o.x=l.cx-s.width/2,o.y=l.cy-s.height/2,o.width=s.width,o.height=s.height)}i=!0}return{floorId:r.floorId,changed:i,shapes:a.map(({shape:o,update:s})=>({id:o.id,width:s.width,height:s.height}))}}function Di(t,e){let r=v(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let n=e.updates.map(s=>s.stageId);if(new Set(n).size!==n.length)throw new d("invalid_operation","Stage ids must be unique");let a=new Set(bt.map(s=>s.key)),i=e.updates.map(s=>{if(!a.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let l=r.objects.find(c=>c.type==="shape"&&c.id===s.stageId);if(!l)throw new d("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(l.role!=="stage")throw new d("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:l,stageKind:s.stageKind,box:l.stageKind===s.stageKind?null:ro(l)}}),o=!1;for(let s of i)s.box&&(s.shape.points=pt({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,o=!0);return{floorId:r.floorId,changed:o,stages:i.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}export{Mt as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,vt as DEFAULT_FLOOR_HEIGHT_STEP_M,io as DEFAULT_SECTION_CORNER_SMOOTHING,De as MAX_FLOOR_BASE_HEIGHT_M,Dr as addArcFanRows,ci as addBookableGridArray,Vr as addBoothArray,Fo as addChartCategory,wn as addChartFloor,An as addChartZone,qr as addGAArea,Hr as addRowBlock,Xr as addTableArray,rr as applyPolygonHole,ri as applyReferenceScanRows,yr as applySectionCornerSmoothing,_o as applySectionOutlineShaping,nr as applySectionRowFit,zo as arcFanInputForGroup,gr as assignSectionInventoryCategory,Tr as automaticPlacementCenter,Ar as confirmReferenceCategoryOutputColor,br as convertGeneratedSectionToPolygon,Ee as countCoveredInventory,Nt as familyCategoryLabel,Ho as gaAreaFootprint,Yr as groupRowsAsSegmented,Vn as insertSeatingBlock,ki as joinGAAreas,Ii as mergeRows,we as mirrorFirstFloor,gi as parseSeatRefId,Ro as pickColorblindSafeCategoryColor,Kt as previewArcFanRows,li as previewBookableGridArray,vo as previewGeneratedSectionPolygonConversion,Fi as previewJoinGAAreas,ze as previewPolygonHole,wo as previewRemovePolygonHole,ho as previewRowCubicPath,mo as previewSectionRowFit,Or as reassignColorblindSafeCategoryColors,Xn as relabelChartRows,jr as removeChartCategory,vn as removeChartFloor,Hn as removeChartObjects,jn as removeChartZone,ir as removePolygonHole,In as renameChartFloor,_r as reorderChartCategories,$r as replaceArcFanRows,Qr as replaceRowBlock,bi as resetSeatOverrides,Gi as resizeShapes,Pr as resolveCreationCategory,xe as seatRefId,So as sectionInventorySelectionSummary,vi as setRowBlockSpacing,Si as splitRow,xi as straightenAndSpaceRows,pr as transformSectionBoundary,xo as transformSectionBoundaryObject,Zr as ungroupSegmentedRow,Un as updateBooths,Ao as updateCategoryDefinitions,Sn as updateChartFloorBaseHeight,Mr as updateChartTheme,Pn as updateChartZones,Jn as updateGAAreas,or as updateRowCubicPath,wi as updateRows,hi as updateSeatOverrides,mr as updateSectionExactPath,hr as updateSectionMetadata,Wr as updateSegmentedRow,Ki as updateShapes,Di as updateStageKinds,Bn as updateTables,qn as updateTextObjects,Nr as updateViewFromSeatFallback};