@seatlayer/core 0.71.3 → 0.71.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{categoryInventory-BiUDSvBt.d.ts → categoryInventory-B8CDQtH4.d.ts} +1 -1
- package/dist/{categoryInventory-DBqgM5in.d.cts → categoryInventory-r3OfIEQn.d.cts} +1 -1
- package/dist/{chunk-GK4ILJFB.js → chunk-7KS6TAYH.js} +1 -1
- package/dist/{chunk-A27USMF7.js → chunk-AM2LRFAY.js} +1 -1
- package/dist/chunk-KCFEFP6H.js +1 -0
- package/dist/{chunk-7OJ6SB6V.js → chunk-KPSJDH3N.js} +1 -1
- package/dist/{chunk-FBRBY6NE.js → chunk-LR7WIR5Z.js} +1 -1
- package/dist/chunk-NKYPEBW3.js +1 -0
- package/dist/{chunk-TQWKQGXF.js → chunk-NXFDYBZY.js} +1 -1
- package/dist/{chunk-AB4ALUEW.js → chunk-SKO3DCVB.js} +1 -1
- package/dist/{chunk-652LV66L.js → chunk-YSVXAUOH.js} +1 -1
- package/dist/core/chart-ops/index.cjs +1 -1
- package/dist/core/chart-ops/index.d.cts +4 -4
- package/dist/core/chart-ops/index.d.ts +4 -4
- package/dist/core/chart-ops/index.js +1 -1
- package/dist/core/inventory/index.cjs +1 -1
- package/dist/core/inventory/index.d.cts +4 -4
- package/dist/core/inventory/index.d.ts +4 -4
- package/dist/core/inventory/index.js +1 -1
- package/dist/core/layout/index.cjs +1 -1
- package/dist/core/layout/index.d.cts +5 -4
- package/dist/core/layout/index.d.ts +5 -4
- package/dist/core/layout/index.js +1 -1
- package/dist/core/quality/index.d.cts +3 -3
- package/dist/core/quality/index.d.ts +3 -3
- package/dist/core/render-assets/index.d.cts +1 -1
- package/dist/core/render-assets/index.d.ts +1 -1
- package/dist/core/seatConfidence.d.cts +1 -1
- package/dist/core/seatConfidence.d.ts +1 -1
- package/dist/core/sections/index.cjs +1 -1
- package/dist/core/sections/index.d.cts +5 -5
- package/dist/core/sections/index.d.ts +5 -5
- package/dist/core/sections/index.js +1 -1
- package/dist/{eventConfigurations-CA2XhDig.d.ts → eventConfigurations-0OC43JJY.d.ts} +1 -1
- package/dist/{eventConfigurations-Csdxe89O.d.cts → eventConfigurations-ByU_uPeS.d.cts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +21 -13
- package/dist/index.d.ts +21 -13
- package/dist/index.js +1 -1
- package/dist/{labeling-CxZWjZBN.d.ts → labeling-B05IJwd2.d.ts} +1 -1
- package/dist/{labeling-DG-Sc8VW.d.cts → labeling-DAGq3u0z.d.cts} +1 -1
- package/dist/{layout-BjTtYIy8.d.ts → layout-DkDRcXvu.d.ts} +102 -60
- package/dist/{layout-CUiLkR8o.d.cts → layout-e0Qe7jmM.d.cts} +102 -60
- package/dist/{renderedQuality-ZDPLvzcZ.d.cts → renderedQuality-BaejczsK.d.cts} +1 -1
- package/dist/{renderedQuality-DrOWtrO-.d.ts → renderedQuality-BwwrqYzX.d.ts} +1 -1
- package/dist/{renderer-DIebhcYo.d.cts → renderer-BNicx5sw.d.ts} +4 -1
- package/dist/{renderer-DtR3EaF4.d.ts → renderer-Duv1HhQg.d.cts} +4 -1
- package/dist/{sections-Bb0L9lDT.d.cts → sections-BjGjR21N.d.cts} +1 -1
- package/dist/{sections-87qiciyN.d.ts → sections-CrX4vq-m.d.ts} +1 -1
- package/dist/{segmentedRowModel-CEP6crcl.d.ts → segmentedRowModel-BOO8w9Ng.d.ts} +1 -1
- package/dist/{segmentedRowModel-BqiM0U65.d.cts → segmentedRowModel-UO_YIQRB.d.cts} +1 -1
- package/dist/{ticketRestrictions-NKWgOV-D.d.cts → ticketRestrictions-DUQrKTpS.d.cts} +2 -2
- package/dist/{ticketRestrictions-Ch3ZKeMR.d.ts → ticketRestrictions-dvlNTwem.d.ts} +2 -2
- package/dist/{types-DNztpn7q.d.cts → types-0yruRsAj.d.cts} +30 -1
- package/dist/{types-DNztpn7q.d.ts → types-0yruRsAj.d.ts} +30 -1
- package/dist/view3d/crossfade/panorama.d.cts +1 -1
- package/dist/view3d/crossfade/panorama.d.ts +1 -1
- package/dist/view3d/index.cjs +8 -8
- package/dist/view3d/index.d.cts +3 -3
- package/dist/view3d/index.d.ts +3 -3
- package/dist/view3d/index.js +1 -1
- package/dist/view3d/scene/scene.worker.cjs +1 -1
- package/dist/view3d/scene/scene.worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-WXWJZ5DO.js +0 -1
- package/dist/chunk-X3K36XZM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as we,b as ve,f as Pt,g as Rt}from"../../chunk-TQWKQGXF.js";import"../../chunk-GXMGOWKB.js";import{n as Ct,p as xt,q as _t,r as Ot,v as Ue}from"../../chunk-JBGLFOJO.js";import{a as ye,b as ee,d as vt,e as It,f as le,g as ze,i as St,k as ce}from"../../chunk-A27USMF7.js";import{a as jt,b as At}from"../../chunk-T2LWVOQ3.js";import{b as be,h as De,i as Ke,l as Uo,m as Jo,n as Y}from"../../chunk-GK4ILJFB.js";import{j as de}from"../../chunk-UL5OIGIF.js";import{A as Ge,B as bt,Ba as J,C as pt,D as wn,H as mt,Ja as wt,R as yt,a as it,b as at,c as st,d as lt,e as ct,f as dt,g as pe,h as ft,i as ut,la as $e,oa as z,p as gt,sa as se,t as me,va as E,xa as T,z as ht,za as M}from"../../chunk-X3K36XZM.js";import{m as Be}from"../../chunk-CXF32VPG.js";import"../../chunk-CRCGO52K.js";var d=class extends Error{constructor(r,o,i={}){super(o);this.code=r;this.details=i;this.name="ChartOperationError"}};function S(t,e){let r=M(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:o.id,objects:o.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 P(t,e,r,o){let i=new Set([...o,...t.categories.map(a=>a.key),...t.zones?.map(a=>a.id)??[],...t.floors?.map(a=>a.id)??[],...t.floors?.length?t.floors.flatMap(a=>a.objects.map(n=>n.id)):t.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let n=r(e);if(n&&!i.has(n))return o.add(n),n}throw new d("id_generation_failed",`Unable to allocate a unique ${e} id`)}function vn(t){let e=t.slice().sort((a,n)=>a.x-n.x||a.y-n.y);if(e.length<3)return e;let r=(a,n,s)=>(n.x-a.x)*(s.y-a.y)-(n.y-a.y)*(s.x-a.x),o=[];for(let a of e){for(;o.length>=2&&r(o[o.length-2],o[o.length-1],a)<=0;)o.pop();o.push(a)}let i=[];for(let a=e.length-1;a>=0;a--){let n=e[a];for(;i.length>=2&&r(i[i.length-2],i[i.length-1],n)<=0;)i.pop();i.push(n)}return o.pop(),i.pop(),o.concat(i)}function In(t,e){if(!t.length)return t;let r={x:t.reduce((o,i)=>o+i.x,0)/t.length,y:t.reduce((o,i)=>o+i.y,0)/t.length};return t.map(o=>{let i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a)||1;return{x:o.x+i/n*e,y:o.y+a/n*e}})}function Z(t){let e=[];for(let o of t)o.type==="row"?e.push(...z(o).map(i=>({x:i.x,y:i.y}))):o.type==="table"?e.push(...se(o).map(i=>({x:i.x,y:i.y}))):o.type==="gaArea"?e.push(...o.points):o.type==="booth"&&e.push(o.center);if(e.length<3)return null;let r=In(vn(e),22);return r.length>=3?r:null}function Ie(t,e){let r=S(t,e),o=M(t).find(i=>i.id===r.floorId);return{...t,objects:r.objects,floors:void 0,focalPoint:o.focalPoint,referenceImage:o.referenceImage,backgroundImage:o.backgroundImage}}var Ft=24,kt=80;function Je(t,e){let r=t.normalize("NFKC").trim();if(r.length>Ft)throw new d("invalid_operation",`${e} displayed type must be at most ${Ft} characters`);return r}function Se(t,e){if(t.displayType===void 0)return!1;let r=Je(t.displayType,e);return r?(t.displayType=r,!1):(delete t.displayType,!0)}function te(t,e){if(t.displayLabel===void 0)return!1;let r=t.displayLabel.normalize("NFKC").trim();if(r.length>kt)throw new d("invalid_operation",`${e} displayed label must be at most ${kt} 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 Mt(t,e){if(!Number.isFinite(t)||t<De||t>Ke)throw new d("invalid_operation",`${e} label size must be from ${De} to ${Ke}`)}function ne(t,e){t.size!==void 0&&t.size!==null&&Mt(t.size,e),t.color!==void 0&&t.color!==null&&N(t.color,`${e} label color`)}function Ce(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&&Mt(r.size,e),r.color!==void 0&&N(r.color,`${e} label color`))}function xe(t,e){let r=t?structuredClone(t):{},o=r.labelStyle?{...r.labelStyle}:{};return e.size===null?delete o.size:e.size!==void 0&&(o.size=e.size),e.color===null?delete o.color:e.color!==void 0&&(o.color=N(e.color,"Label color")),o.size===void 0&&o.color===void 0?delete r.labelStyle:r.labelStyle=o,e.visible!==void 0&&(r.visible=e.visible),Object.keys(r).length?r:void 0}function qe(t,e,r){let o=e.normalize("NFKC").trim();if(!o||o.length>80)throw new d("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(i=>i.id!==r&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new d("invalid_operation",`Zone label already exists: ${o}`);return o}function He(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 G(t,e,r){return(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x)}var q=Math.PI/180,B=Math.PI/180;function W(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 _e(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 Sn=0,Ve=120,Tt=4;function Cn(t){if(!Number.isFinite(t)||t<Sn||t>Ve)throw new d("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function Zo(t,e){let r=M(t);if(r.length>=5)throw new d("invalid_operation","A chart can contain at most five physical floors");let o=(e.name??String(r.length+1)).normalize("NFKC").trim();if(!o||o.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(l=>l.name.toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${o}`);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 a=t.floors[t.floors.length-1].baseHeightM??Math.min(Ve,(t.floors.length-1)*Tt),n=Math.min(Ve,a+Tt),s=P(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:o,baseHeightM:n,objects:[],focalPoint:{...t.focalPoint}}),_e(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:n}}function Wo(t,e){let r=M(t),o=r.find(n=>n.id===e.floorId);if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let i=e.name.normalize("NFKC").trim();if(!i||i.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(n=>n.id!==o.id&&n.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${i}`);let a=o.name!==i;return a&&(o.name=i),{changed:a,floorId:o.id,floorName:i}}function Qo(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(i=>i.id===e.floorId);if(!r)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});Cn(e.baseHeightM);let o=r.baseHeightM!==e.baseHeightM;return o&&(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:o,floorId:r.id,baseHeightM:e.baseHeightM}}function er(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(i=>i.id===e.floorId);if(r<0)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[o]=t.floors.splice(r,1);if(t.floors.length===1){let[i]=t.floors;t.objects=i.objects,t.focalPoint=i.focalPoint,t.referenceImage=i.referenceImage,t.backgroundImage=i.backgroundImage,t.floors=void 0}else _e(t);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:M(t).length}}function ir(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:P(t,"zone",e.idFactory,new Set),label:qe(t,e.label),color:N(e.color,"Zone color"),...e.focalPoint?{focalPoint:He(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function ar(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 o=new Map((t.zones??[]).map(l=>[l.id,l])),i=r.filter(l=>!o.has(l));if(i.length)throw new d("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),n=new Map((a.zones??[]).map(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=n.get(l.zoneId);l.patch.label!==void 0&&(f.label=qe(a,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=He(l.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:r,zones:r.map(l=>structuredClone(n.get(l)))}}function sr(t,e){let r=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let o=M(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(o.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${o.length} section(s)`,{zoneId:e.zoneId,sectionIds:o.map(a=>a.id),requiresClearSectionAssignments:!0});let i=o.map(a=>a.id);for(let a of o)delete a.zone;return t.zones.splice(r,1),t.zones.length||delete t.zones,_e(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var Q={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 fe(t,e,r,o,i,a,n=0){return{type:"row",id:t,label:e,origin:{x:-(o-1)*i/2,y:r},rotation:0,curve:n,seatCount:o,seatSpacing:i,categoryKey:a}}function xn(t,e,r,o,i,a){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function Nt(t,e,r,o,i,a){let n=r/2,s=o/2;return{type:"gaArea",id:t,label:e,points:[{x:-n,y:-s},{x:n,y:-s},{x:n,y:s},{x:-n,y:s}],capacity:i,categoryKey:a}}function _n(t,e,r,o,i){let a=r*2,n=[];for(let s=0;s<a;s++){let l=s%2===0,c=l?["wheelchair"]:["companion"];n.push(l?{index:s,accessibility:c,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:c})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:n}}var Et=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[Q.balcony],sectionLabel:"Balcony",build:()=>[fe("blk-b0","A",-45,18,24,"balcony",18),fe("blk-b1","B",-15,20,24,"balcony",18),fe("blk-b2","C",15,22,24,"balcony",18),fe("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[Q.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>fe(`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:[Q.standard],build:()=>[Nt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[Q.premium],build:()=>Array.from({length:6},(t,e)=>xn(`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:[Q.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:[Q.standard],build:()=>[Nt("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:[Q.standard],build:()=>[_n("blk-wc","A",4,40,"standard")]}];function L(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 Lt(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 Xe(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 Dt(t,e,r){let o=i=>({x:i.x+e,y:i.y+r});switch(t.type){case"row":t.origin=o(t.origin),t.path&&(t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)});break;case"table":case"booth":t.center=o(t.center);break;case"text":t.position=o(t.position);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=t.holes.map(i=>i.map(o)));break;case"section":t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=bt(t.outlinePath,e,r)),t.holes&&(t.holes=t.holes.map(i=>i.map(o)));break;case"shape":t.points&&(t.points=t.points.map(o)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}function Ir(t,e){let r=S(t,e.floorId),o=[...new Set(e.tableIds)];if(!o.length)throw new d("invalid_operation","At least one table id is required");let i=o.map(b=>r.objects.find(p=>p.type==="table"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one table change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey);let s=n.seatCount!==void 0,l=n.seatCountsBySide!==void 0;if(l){if(n.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(n.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let b=["top","bottom","left","right"],p=Object.keys(n.seatCountsBySide);if(p.length!==b.length||p.some(v=>!b.includes(v)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let v of b){let I=n.seatCountsBySide[v];if(!Number.isInteger(I)||I<0||I>40)throw new d("invalid_operation",`seatCountsBySide.${v} must be a whole number from 0 to 40`)}let x=b.reduce((v,I)=>v+n.seatCountsBySide[I],0);if(x<1||x>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&n.seatCount!==x)throw new d("invalid_operation",`seatCount must equal the ${x}-chair seatCountsBySide total`);n.seatCount=x,n.sides=b.filter(v=>n.seatCountsBySide[v]>0)}if(n.seatCount!==void 0&&(!Number.isInteger(n.seatCount)||n.seatCount<1||n.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(n.shape!==void 0&&n.shape!=="round"&&n.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(n.bookAsWhole===!0&&n.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(n.variableOccupancy===!1&&(n.minOccupancy!==void 0||n.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let c=(b,p,x,v)=>{if(p!==void 0&&(!Number.isFinite(p)||p<x||p>v))throw new d("invalid_operation",`${String(b)} must be from ${x} to ${v}`)};if(c("rotation",n.rotation,0,360),c("radius",n.radius,24,160),c("seatArc",n.seatArc,120,360),c("width",n.width,40,320),c("height",n.height,30,240),n.minOccupancy!==void 0&&(!Number.isInteger(n.minOccupancy)||n.minOccupancy<1||n.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(n.maxOccupancy!==void 0&&(!Number.isInteger(n.maxOccupancy)||n.maxOccupancy<1||n.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(n.sides!==void 0){let b=new Set(["top","bottom","left","right"]);if(!n.sides.length||n.sides.length>4||new Set(n.sides).size!==n.sides.length||n.sides.some(p=>!b.has(p)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=te(n,"Table"),g=Se(n,"Table"),h=i.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,n),p.shape==="round"&&delete p.seatCountsBySide,p.overrides&&n.seatCount!==void 0&&(p.overrides=p.overrides.filter(x=>x.index<p.seatCount),p.overrides.length||delete p.overrides),n.bookAsWhole===!1&&delete p.bookAsWhole,n.variableOccupancy===!1&&(delete p.variableOccupancy,delete p.minOccupancy,delete p.maxOccupancy),p.bookAsWhole||delete p.bookAsWhole,p.variableOccupancy||delete p.variableOccupancy,p.bookAsWhole&&p.variableOccupancy)throw new d("invalid_operation",`Table "${p.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:p.id});if((p.bookAsWhole||p.variableOccupancy)&&p.overrides?.length)throw new d("invalid_operation",`Table "${p.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:p.id,overriddenChairIndices:p.overrides.map(x=>x.index)});if(p.bookAsWhole)delete p.minOccupancy,delete p.maxOccupancy;else if(p.variableOccupancy){if(!Number.isInteger(p.minOccupancy)||!Number.isInteger(p.maxOccupancy)||p.minOccupancy<1||p.maxOccupancy<p.minOccupancy||p.maxOccupancy>p.seatCount)throw new d("invalid_operation",`Table "${p.label}" needs whole-number minimum and maximum guests from 1 to its ${p.seatCount}-chair capacity`,{tableId:p.id,seatCount:p.seatCount})}else{if(n.minOccupancy!==void 0||n.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:p.id});delete p.minOccupancy,delete p.maxOccupancy}if(g&&delete p.displayType,f&&delete p.displayLabel,p.shape==="rect"){if(p.width??=80,p.height??=50,p.seatCountsBySide){let x=["top","bottom","left","right"],v=x.reduce((I,A)=>I+p.seatCountsBySide[A],0);if(v!==p.seatCount)throw new d("invalid_operation",`Table "${p.label}" side counts total ${v}, but seatCount is ${p.seatCount}`,{tableId:p.id,seatCount:p.seatCount,seatCountsBySide:p.seatCountsBySide});p.sides=x.filter(I=>p.seatCountsBySide[I]>0)}}else p.radius??=40;if((p.bookAsWhole||p.variableOccupancy)&&St(p.label))throw new d("invalid_operation",`Grouped table label "${p.label}" uses SeatLayer's reserved GA namespace`,{tableId:p.id});return p}),u=new Map(h.map(b=>[b.id,b])),m=new Set(o),y=new Map;for(let b of M(t))for(let p of b.objects){let x=p.type==="table"?u.get(p.id)??p:p,v=[];x.type==="row"?v=z(x).map(I=>I.label):x.type==="table"?v=x.bookAsWhole||x.variableOccupancy?[x.label]:se(x).map(I=>I.label):x.type==="booth"?v=[x.label]:x.type==="gaArea"&&(v=le(x));for(let I of v){let A=y.get(I);if(A&&(m.has(A)||m.has(x.id)))throw new d("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:I,conflictingObjectIds:[A,x.id]});y.set(I,A??x.id)}}let w=!1,_=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[b,p]of i.entries()){let x=h[b],v=JSON.stringify(p);for(let I of _)I in x||delete p[I];Object.assign(p,x),JSON.stringify(p)!==v&&(w=!0)}return{floorId:r.floorId,changed:w,tableIds:o}}function Sr(t,e){let r=S(t,e.floorId),o=[...new Set(e.boothIds)];if(!o.length)throw new d("invalid_operation","At least one booth id is required");let i=o.map(u=>r.objects.find(m=>m.type==="booth"&&m.id===u)),a=o.filter((u,m)=>!i[m]);if(a.length)throw new d("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one booth change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey);let s=(u,m,y,w)=>{if(m!==void 0&&(!Number.isFinite(m)||m<y||m>w))throw new d("invalid_operation",`${u} must be from ${y} to ${w}`)};s("width",n.width,30,400),s("height",n.height,30,400),s("rotation",n.rotation,0,360);let l=n.points===null;if(n.points!=null){if(o.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let u=Pt(n.points);if(!u.ok)throw new d("invalid_operation",u.message??"The booth outline is not a valid simple polygon")}let c=n.points!=null?n.points.map(u=>({x:u.x,y:u.y})):void 0;delete n.points;let f=te(n,"Booth"),g=Se(n,"Booth"),h=!1;for(let u of i){let m=JSON.stringify(u);Object.assign(u,n),f&&delete u.displayLabel,g&&delete u.displayType,l?delete u.points:c&&(u.points=c),JSON.stringify(u)!==m&&(h=!0)}return{floorId:r.floorId,changed:h,boothIds:o}}function Cr(t,e){let r=S(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(!o.length)throw new d("invalid_operation","At least one GA area id is required");let i=o.map(f=>r.objects.find(g=>g.type==="gaArea"&&g.id===f)),a=o.filter((f,g)=>!i[g]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one GA area change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(n.categoryKey!==void 0&&F(t,n.categoryKey),n.capacity!==void 0&&(!Number.isInteger(n.capacity)||n.capacity<1||n.capacity>1e5))throw new d("invalid_operation","capacity must be an integer from 1 to 100000");if(n.cornerRadius!==void 0&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=te(n,"GA area"),l=Se(n,"GA area");if(n.capacity!==void 0)for(let f of i){if(f.inventorySegments!==void 0&&n.capacity<f.capacity)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot be reduced below ${f.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:f.id,currentCapacity:f.capacity,requestedCapacity:n.capacity});if(f.inventorySegments!==void 0&&n.capacity>f.capacity&&ze(f,n.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 i){let g=JSON.stringify(f),h=n.capacity===void 0?f.inventorySegments:ze(f,n.capacity);Object.assign(f,n),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:o}}function Ye(t,e){if(e.length<3)return 0;let r=i=>E(i,e,void 0),o=0;for(let i of t)r(T(i))&&(i.type==="row"?o+=z(i).length:i.type==="table"?o+=se(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=W(i)));return o}function xr(t,e){let r=S(t,e.floorId);if(!e.objectIds.length)throw new d("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new d("invalid_operation","Chart object ids must be unique");let o=e.objectIds.map(s=>r.objects.find(l=>l.id===s)),i=e.objectIds.filter((s,l)=>!o[l]);if(i.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=o,n=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)n.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,l)=>s+W(l),0),remainingObjectCount:r.objects.length}}function _r(t,e){let r=S(t,e.floorId),o=[...new Set(e.textIds)];if(!o.length)throw new d("invalid_operation","At least one text id is required");let i=o.map(c=>r.objects.find(f=>f.type==="text"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one text change is required");if(n.text!==void 0){if(n.text=n.text.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!n.text||n.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(n.fontSize!==void 0&&(!Number.isFinite(n.fontSize)||n.fontSize<8||n.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(n.fontFamily!==void 0&&n.fontFamily!==null&&(n.fontFamily=n.fontFamily.normalize("NFKC").trim(),!n.fontFamily||n.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(n.rotation!==void 0&&(!Number.isFinite(n.rotation)||n.rotation<0||n.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(n.color!==void 0&&n.color!==null&&(n.color=N(n.color,"Text color")),n.bold!==void 0&&typeof n.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(n.italic!==void 0&&typeof n.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(n.width!==void 0&&n.width!==null&&(!Number.isFinite(n.width)||n.width<40||n.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new d("invalid_operation","Text align must be left, center, or right");if(n.lineHeight!==void 0&&(!Number.isFinite(n.lineHeight)||n.lineHeight<.8||n.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(n.letterSpacing!==void 0&&(!Number.isFinite(n.letterSpacing)||n.letterSpacing<-2||n.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(n.underline!==void 0&&typeof n.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(n.opacity!==void 0&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(n.background!==void 0&&n.background!==null){n.background.color=N(n.background.color,"Text background color");let{padding:c=6,cornerRadius:f=4,opacity:g=.9}=n.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(n,c))&&i.some(c=>c.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(n.iconKey!==void 0){if(!Ct(n.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(i.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 i){let f=JSON.stringify(c);n.iconKey!==void 0&&(c.iconKey=n.iconKey),n.text!==void 0&&(c.text=n.text),n.fontSize!==void 0&&(c.fontSize=n.fontSize),n.fontFamily===null?delete c.fontFamily:n.fontFamily!==void 0&&(c.fontFamily=n.fontFamily),n.rotation!==void 0&&(c.rotation=n.rotation),n.color===null?delete c.color:n.color!==void 0&&(c.color=n.color),n.bold!==void 0&&(n.bold?c.bold=!0:delete c.bold),n.italic!==void 0&&(n.italic?c.italic=!0:delete c.italic),n.width===null?delete c.width:n.width!==void 0&&(c.width=n.width),n.align!==void 0&&(n.align==="left"?delete c.align:c.align=n.align),n.lineHeight!==void 0&&(n.lineHeight===1.2?delete c.lineHeight:c.lineHeight=n.lineHeight),n.letterSpacing!==void 0&&(n.letterSpacing===0?delete c.letterSpacing:c.letterSpacing=n.letterSpacing),n.underline!==void 0&&(n.underline?c.underline=!0:delete c.underline),n.opacity!==void 0&&(n.opacity===1?delete c.opacity:c.opacity=n.opacity),n.background===null?delete c.background:n.background!==void 0&&(c.background=n.background),JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,textIds:o}}function Or(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(c=>r.objects.find(f=>f.type==="row"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i.slice().sort((c,f)=>c.origin.y-f.origin.y||c.origin.x-f.origin.x),s=yt(n.map(c=>({label:c.label})),e.options),l=!1;return n.forEach((c,f)=>{c.label!==s[f].label&&(l=!0),c.label=s[f].label}),{floorId:r.floorId,changed:l,rows:n.map(c=>({id:c.id,label:c.label}))}}function jr(t,e){let r=Et.find(c=>c.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=S(t,e.floorId),i=new Set,a=r.build().map(c=>structuredClone(c));for(let c of a)c.id=P(t,c.type,e.idFactory,i),Dt(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 n=a.filter(c=>c.type==="row");if(n.length){let c=0;for(let f of o.objects){if(f.type!=="row")continue;let g=Lt(f.label);g!=null&&(c=Math.max(c,g+1))}for(let f of n)f.label=L(c++)}let s=new Set(o.objects.flatMap(c=>"label"in c&&c.label?[c.label]:[]));for(let c of a){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)}o.objects.push(...a);let l=null;if(r.sectionLabel&&e.wrapInSection!==!1){let c=Z(a);if(c){let f={type:"section",id:P(t,"sec",e.idFactory,i),label:r.sectionLabel,outline:c};o.objects.push(f),l=f.id}}return{floorId:o.floorId,blockKey:r.key,createdIds:[...a.map(c=>c.id),...l?[l]:[]],sectionId:l}}function On(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new d("invalid_operation","Exact row path points must be finite");let o=gt(e,97),i=o.slice(1).reduce((a,n,s)=>a+Math.hypot(n.x-o[s].x,n.y-o[s].y),0);if(!Number.isFinite(i)||i<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function jn(t,e){let r=S(t,e.floorId),o=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!o)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=On(e.path),a=z(o),n=structuredClone(o);n.path=i.path,n.origin={...i.path.start};let s=z(n),l=a.map((f,g)=>Math.hypot(f.x-s[g].x,f.y-s[g].y)),c=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:r.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:l.length?l.reduce((f,g)=>f+g,0)/l.length:0,maxSeatMovement:l.length?Math.max(...l):0,convertingFromParametric:!o.path,changed:c,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function Tr(t,e){let r=jn(t,e);if(!r.changed)return r;let i=S(t,r.floorId).objects.find(a=>a.type==="row"&&a.id===r.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,r}function An(t,e){let r=t.map((o,i)=>[...o,e[i]]);for(let o=0;o<3;o++){let i=o;for(let n=o+1;n<3;n++)Math.abs(r[n][o])>Math.abs(r[i][o])&&(i=n);if(Math.abs(r[i][o])<1e-9)return null;[r[o],r[i]]=[r[i],r[o]];let a=r[o][o];for(let n=o;n<4;n++)r[o][n]/=a;for(let n=0;n<3;n++){if(n===o)continue;let s=r[n][o];for(let l=o;l<4;l++)r[n][l]-=s*r[o][l]}}return[r[0][3],r[1][3],r[2][3]]}function Pn(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],n=i.x**2+i.y**2;for(let s=0;s<3;s++){r[s]+=a[s]*n;for(let l=0;l<3;l++)e[s][l]+=a[s]*a[l]}}let o=An(e,r);return o?{x:o[0],y:o[1]}:null}function Kt(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function Rn(t,e){let r=S(t,e.floorId),o=r.objects.find(u=>u.type==="section"&&u.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let a=M(t).find(u=>u.id===r.floorId),n=e.mode==="outline"?Pn(o.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(u=>u.type==="row"&&E(T(u),o.outline,o.holes)),l=s.filter(u=>!!u.path).map(u=>u.id),c=[],f=[],g=i/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-n.x,u.origin.y-n.y);if(m<=u.seatSpacing/2+1e-6){c.push(u.id);continue}let y=2*Math.asin(u.seatSpacing/(2*m))/q,w=z(u),_=Math.atan2(u.origin.x-n.x,u.origin.y-n.y)/q,p=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(Kt(Math.atan2(w[1].x-n.x,w[1].y-n.y)/q-_))||1)*y*(u.seatCount-1);if(Math.abs(p)>320){c.push(u.id);continue}let x=-_,v=u.curve+(p-u.curve)*g,I=u.rotation+Kt(x-u.rotation)*g,A={...u,curve:v,rotation:I},U=z(A).map((V,$)=>Math.hypot(V.x-w[$].x,V.y-w[$].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:p,resultCurve:v,fromRotation:u.rotation,resultRotation:I,rmsMovement:Math.sqrt(U.reduce((V,$)=>V+$**2,0)/U.length),maxMovement:Math.max(...U)})}let h=f.map(u=>u.rmsMovement);return{floorId:r.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...n},strength:i,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=Rn(t,e),o=S(t,r.floorId),i=o.objects.find(n=>n.type==="section"&&n.id===r.sectionId),a=!1;for(let n of r.rows){let s=o.objects.find(l=>l.type==="row"&&l.id===n.rowId);(s.curve!==n.resultCurve||s.rotation!==n.resultRotation)&&(s.curve=n.resultCurve,s.rotation=n.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==r.strength&&(i.smoothing=r.strength,a=!0),{...r,changed:a}}function $t(t,e,r,o){let i=G(t,e,r),a=G(t,e,o),n=G(r,o,t),s=G(r,o,e);return i*a<-1e-9&&n*s<-1e-9}function Gt(t,e){return t.some((r,o)=>{let i=t[(o+1)%t.length];return e.some((a,n)=>$t(r,i,a,e[(n+1)%e.length]))})}function Fn(t){if(t.length<3||t.length>256||Math.abs(me(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)&&$t(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Oe(t,e,r){let o=S(t,e),i=o.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===r);if(!i)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:o,object:i,outer:i.type==="section"?i.outline:i.points}}function Ze(t,e){let{target:r,object:o,outer:i}=Oe(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Fn(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(c=>!E(c,i,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(Gt(a,i))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let n=o.holes??[],s=e.holeIndex??n.length;if(!Number.isInteger(s)||s<0||s>n.length||e.holeIndex!=null&&s>=n.length)throw new d("invalid_operation","Opening not found");for(let c=0;c<n.length;c++){if(c===e.holeIndex)continue;let f=n[c];if(Gt(a,f)||E(a[0],f,void 0)||E(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let l=r.objects.filter(c=>c.id!==o.id&&c.type!=="section"&&E(T(c),a,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:l.map(c=>c.id),excludedInventoryUnits:Ye(r.objects.filter(c=>c.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Er(t,e){let r=Ze(t,e),{object:o}=Oe(t,r.floorId,r.objectId);return o.holes??=[],e.holeIndex==null?o.holes.push(structuredClone(e.points)):o.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function kn(t,e){let{target:r,object:o}=Oe(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(o.holes?.length??0))throw new d("invalid_operation","Opening not found");let i=o.holes[e.holeIndex],a=r.objects.filter(n=>n.id!==o.id&&n.type!=="section"&&E(T(n),i,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(n=>n.id),excludedInventoryUnits:Ye(r.objects.filter(n=>n.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Lr(t,e){let r=kn(t,e),{object:o}=Oe(t,r.floorId,r.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...r,changed:!0}}function Mn(t){let e=Y(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function zt(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let o=r.map(n=>t.find(s=>s.type==="section"&&s.id===n)),i=r.filter((n,s)=>!o[s]);if(i.length)throw new d("object_not_found",`Unknown section id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:i});let a=o;return{requested:r,sections:a,logicalSectionIds:[...new Set(a.map(n=>n.logicalSectionId??n.id))]}}function Tn(t,e){let r=S(t,e.floorId),o=zt(r.objects,e.sectionIds),i=ce(Ie(t,r.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),n=new Map(r.objects.map(g=>[g.id,g])),s=o.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),l=new Set;for(let g of s){let h=n.get(g);if(h)if(h.type==="row"||h.type==="table")for(let u of ve(h).keys())l.add(u);else(h.type==="booth"||h.type==="gaArea")&&l.add(h.categoryKey)}let c=o.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),f=o.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(h=>{let u=n.get(h);return u?.type==="row"||u?.type==="table"||u?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:c,...c&&l.size===1?{categoryKey:[...l][0]}:{},categoryMixed:c&&l.size!==1,viewApplicable:f}}function qr(t,e){F(t,e.categoryKey);let r=Tn(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 o=S(t,r.floorId),i=new Set(r.objectIds),a=!1,n=0;for(let s of o.objects){if(!i.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,a=!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,n++,a=!0,Object.keys(f).some(g=>g!=="index")?[f]:[]});l.length?s.overrides=l:delete s.overrides}return{...r,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:n}}function Hr(t,e){let r=S(t,e.floorId),o=zt(r.objects,e.sectionIds),{requested:i}=o,a=structuredClone(e.patch),n=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(u=>!n.has(u));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new d("invalid_operation","At least one section metadata change is required");if(a.label!==void 0){if(a.label=a.label.normalize("NFKC").trim(),i.length!==1)throw new d("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new d("invalid_operation","Section labels must contain 1 to 80 characters")}if(a.displayLabel!==void 0&&a.displayLabel!==null){if(a.displayLabel=a.displayLabel.normalize("NFKC").trim(),i.length!==1)throw new d("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new d("invalid_operation","Section display labels must contain 1 to 80 characters")}if(a.entrance!==void 0&&a.entrance!==null&&(a.entrance=a.entrance.normalize("NFKC").trim(),a.entrance.length>40))throw new d("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Mn(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&Ce(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ne(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(u=>u.id===a.zone))throw new d("object_not_found",`Unknown chart zone: ${a.zone}`,{zoneId:a.zone});if(a.elevation!==void 0&&(!Number.isInteger(a.elevation)||a.elevation<0||a.elevation>3))throw new d("invalid_operation","Section elevation must be an integer from 0 to 3");if(a.height!==void 0&&a.height!==null&&(!Number.isFinite(a.height)||a.height<0||a.height>120))throw new d("invalid_operation","Section height must be a number from 0 to 120 metres");if(a.rake!==void 0&&a.rake!==null&&(!Number.isFinite(a.rake)||a.rake<0||a.rake>45))throw new d("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(a.surfaceKind!==void 0&&a.surfaceKind!==null&&a.surfaceKind!=="flat"&&a.surfaceKind!=="rakedRows")throw new d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=N(a.color,"Section color"));let l=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,c=new Set(o.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 o.sections){let m=JSON.stringify(u);a.label!==void 0&&(u.label=a.label),a.labelPresentation===null?delete u.labelPresentation:a.labelPresentation!==void 0&&(u.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(u.elevation=a.elevation);let y=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};a.height===null?(delete u.height,y("height")):a.height!==void 0&&(u.height=a.height,u.physical3dProvenance={...u.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete u.rake,y("rake")):a.rake!==void 0&&(u.rake=a.rake,u.physical3dProvenance={...u.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete u.surfaceKind,y("surfaceKind")):a.surfaceKind!==void 0&&(u.surfaceKind=a.surfaceKind,u.physical3dProvenance={...u.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete u.color:a.color!==void 0&&(u.color=a.color),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}for(let u of f){let m=JSON.stringify(u),y=u.viewFromSeatUrl;if(a.displayLabel===null?delete u.displayLabel:a.displayLabel!==void 0&&(u.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete u.entrance:a.entrance!==void 0&&(u.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete u.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(u.viewFromSeatUrl=a.viewFromSeatUrl),!u.viewFromSeatUrl||a.viewFromSeatMeta===null?delete u.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?u.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==y&&delete u.viewFromSeatMeta,a.labelStyle!==void 0){let w=xe(u.labelPresentation,a.labelStyle);w?u.labelPresentation=w:delete u.labelPresentation}a.zone===null?delete u.zone:a.zone!==void 0&&(u.zone=a.zone),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}return{floorId:r.floorId,changed:h,sectionIds:i,affectedSectionIds:[...g]}}function Nn(t,e){let r=S(t,e.floorId),o=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(o.outlinePath)throw new d("invalid_operation",`Section ${o.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:o.id,representation:"exact-path"});if(!o.geometry)throw new d("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=r.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&E(T(a),o.outline,o.holes));return{floorId:r.floorId,sectionId:o.id,sectionLabel:o.label,source:{representation:"generated-polygon",generator:structuredClone(o.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:o.outline.length,holeCount:o.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,n)=>a+W(n),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function Vr(t,e){let r=Nn(t,e),i=S(t,r.floorId).objects.find(a=>a.type==="section"&&a.id===r.sectionId);return delete i.geometry,{...r,changed:!0}}function En(t,e){let r=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,n=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");n=e.dx!==0||e.dy!==0,o=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");n=e.factor!==1,i=e.factor;let s=T(t);o=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");n=(e.degrees%360+360)%360!==0;let l=e.degrees*Math.PI/180,c=Math.cos(l),f=Math.sin(l),g=T(t);o=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");a=!0,o=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return n&&(t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=pt(t.outlinePath,o,i,a)),t.holes&&(t.holes=t.holes.map(s=>s.map(o)))),{changed:n,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function Xr(t,e){let r=S(t,e.floorId),o=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...En(o,e.transform)}}function Yr(t,e){let r=S(t,e.floorId),o=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!ht(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ge(i),n=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return n&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:r.floorId,sectionId:o.id,changed:n,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function Ln(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function Zr(t,e){return Dn(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Dn(t,e){let r=S(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new d("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new d("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(e.sectionIds)],i=new Set,a=new Map,n=!1;try{for(let s of o){let l=r.objects.find(b=>b.type==="section"&&b.id===s);if(!l||!Ln(l))continue;let f=structuredClone(l);a.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?mt(h,{cornerSmoothing:u,...w?{edgeCurvature:y}:{}}):null;_?(l.sourceOutline=h,l.outlinePath=_,l.outline=Ge(_),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&&(n=!0,i.add(l.id))}}catch(s){for(let{section:l,snapshot:c}of a.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:n,sectionIds:o,affectedSectionIds:[...i]}}var Kn=new Set(["companion","child","senior","student","membership","custom"]);function ue(t){if(!t.length)throw new d("invalid_operation","A chart must have at least one category");let e=new Set,r=new Map,o=structuredClone(t);for(let i of o){let a=i.key.trim(),n=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!n||n.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=n.toLocaleLowerCase("en"),l=r.get(s);if(l)throw new d("duplicate_category_label",`Categories ${l} and ${a} share the same label`,{categoryKeys:[l,a],label:n});if(r.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new d("invalid_operation",`Category ${a} must use a six-digit hex color`,{categoryKey:a});if(i.price!=null&&(!Number.isFinite(i.price)||i.price<0||i.price>1e6))throw new d("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!de(i.seatGlyph))throw new d("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let c=new Set,f=new Set;for(let g of i.tiers){let h=g.id.trim(),u=g.name.normalize("NFKC").trim(),m=u.toLocaleLowerCase("en");if(!h||h.length>160||c.has(h))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!u||u.length>80||f.has(m))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:u});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new d("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(g.restriction!=null&&!Kn.has(g.restriction))throw new d("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new d("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(g.applicability!=null){let y=g.applicability.seatLabels?.map(_=>_.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(_=>!be.some(b=>b.key===_))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...y?{seatLabels:y}:{},...w?{accessibility:[...w]}:{}},!g.applicability.seatLabels&&!g.applicability.accessibility&&delete g.applicability}if(g.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(g.evidence.provenance)||typeof g.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}c.add(h),f.add(m)}}}return o}function Gn(t,e){let r=new Set,o=structuredClone(t.categories);for(let n of e.updates){if(r.has(n.categoryKey))throw new d("invalid_operation",`Category ${n.categoryKey} may be updated only once`);r.add(n.categoryKey);let s=o.find(g=>g.key===n.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${n.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:n.categoryKey});let l=structuredClone(n.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 i=ue(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...r],categories:t.categories}}function ii(t,e){let r=e.categoryKeys.map(l=>l.trim()),o=t.categories.map(l=>l.key);if(r.length!==o.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:o});let i=new Set(o),a=o.filter(l=>!r.includes(l)),n=r.filter(l=>!i.has(l));if(a.length||n.length)throw new d(n.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:a,unknownCategoryKeys:n});if(r.every((l,c)=>l===o[c]))return{changed:!1,categoryKeys:o,categories:t.categories};let s=new Map(t.categories.map(l=>[l.key,l]));return t.categories=ue(r.map(l=>structuredClone(s.get(l)))),{changed:!0,categoryKeys:r,categories:t.categories}}var Ut=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Bt(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(o=>o+o).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function $n(t,e){let r=Bt(t),o=Bt(e);return!r||!o?1/0:(r[0]-o[0])**2+(r[1]-o[1])**2+(r[2]-o[2])**2}var zn=3600;function Bn(t,e,r=Ut){return r.find(i=>t.every(a=>$n(i,a)>=zn))??r[e%r.length]}function ai(t,e){let r=e?.palette??Ut;if(!t.categories.length)return{changed:[],categories:t.categories};let o=new Map(t.categories.map(n=>[n.key,n.color.toLowerCase()])),i=t.categories.map((n,s)=>({categoryKey:n.key,patch:{color:r[s%r.length]}}));return Gn(t,{updates:i}),{changed:t.categories.map(n=>({key:n.key,from:o.get(n.key),to:n.color})).filter(n=>n.from!==n.to),categories:t.categories}}function si(t,e){let r=e.color.trim().toLowerCase(),o=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!o||o.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(l=>l.key===e.categoryKey);if(!a)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=r,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let n=ue(i),s=JSON.stringify(n)!==JSON.stringify(t.categories);return s&&(t.categories=n),{changed:s,category:t.categories.find(l=>l.key===e.categoryKey),categories:t.categories}}function Un(t,e){let r=new Set(t.categories.map(n=>n.key)),o="";for(let n=0;n<100;n++){let l=e.idFactory("cat").trim();if(l&&!r.has(l)){o=l;break}}if(!o)throw new d("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(n=>({...n,id:n.id.trim(),name:n.name.normalize("NFKC").trim()}))},a=ue([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(n=>n.key===o),categories:a}}var Jn=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],qn={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function Hn(t,e){let r=qn[t];return!r||!e.includes(r)?e:[r,...e.filter(o=>o!==r)]}var Vn=26;function Xn(t,e,r){let o=(1-Math.abs(2*r-1))*e,i=(t%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[n,s,l]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],c=r-o/2,f=g=>Math.round((g+c)*255).toString(16).padStart(2,"0");return`#${f(n)}${f(s)}${f(l)}`}function Yn(t,e,r){let o=n=>t.every(s=>{let l=Rt(n,s);return l==null||l>=Vn}),i=n=>{let s=Be(n,"#12151d"),l=Be(n,"#ffffff");return(s??0)>=3||(l??0)>=3},a=e.find(n=>o(n)&&i(n));if(a)return a;for(let n=0;n<360;n+=12)for(let s of[.52,.44,.6]){let l=Xn(n,.62,s);if(o(l)&&i(l))return l}return r}function Zn(t,e){let r=we.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function Wn(t){let e=new Map;for(let r of M(t))for(let o of r.objects){let i=we.find(n=>n.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let n of ve(o).keys())a.add(n);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let n of a){let s=e.get(n)??new Set;s.add(i.objectType),e.set(n,s)}}return e}function Qn(t,e){let r=new Set(t.categories.map(i=>i.label.toLowerCase())),o=e;for(let i=2;r.has(o.toLowerCase());i+=1)o=`${e} ${i}`;return o}function eo(t,e,r){let o=Wn(t),i=c=>{let f=o.get(c);return!f||f.size===0||f.size===1&&f.has(r)},a=t.categories.find(c=>c.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let c=t.categories.find(f=>{let g=o.get(f.key);return g?.size===1&&g.has(r)});if(c)return{kind:"existing",categoryKey:c.key,label:c.label}}let n=we.find(c=>c.objectType===r),s=a?Zn(a.label,r):r==="gaArea"?"General Admission":n.creationWord,l=t.categories.find(c=>c.label.toLowerCase()===s.toLowerCase()&&i(c.key));return l?{kind:"existing",categoryKey:l.key,label:l.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:Qn(t,s)}}function li(t,e,r,o){let i=eo(t,e,r);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?t.categories.find(n=>n.key===i.baseCategoryKey):void 0;return to(t,r,a,i.label,o)}function to(t,e,r,o,i){let a=i.palette??Jn,n=t.categories.map(f=>f.color),s=i.suggestColor?.(n.map(f=>f.toLowerCase()))??Bn(n,t.categories.length),l=Yn(n,Hn(e,a),s),c=Un(t,{label:o,color:l,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:i.idFactory});return t.categories=c.categories,c.category.key}function no(t,e){let r=new Set;for(let o of M(t))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===e&&r.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&r.add(i.id);return[...r]}function ci(t,e){let r=t.categories.find(a=>a.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let o=no(t,e.categoryKey);if(o.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:o});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=ue(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var oo=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Jt=.7,qt=1.6,ro=["seat","deck","shell","fascia"];function hi(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let o=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of oo){let n=r[a];n===null?delete i[a]:n!==void 0&&(i[a]=N(n,`Theme ${a}`))}if(r.fontFamily===null)delete i.fontFamily;else if(r.fontFamily!==void 0){let a=r.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(r.seatScale===null)delete i.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<Jt||r.seatScale>qt)throw new d("invalid_operation",`Theme seatScale must be from ${Jt} to ${qt}`);i.seatScale=r.seatScale}if(r.logoUrl===null)delete i.logoUrl;else if(r.logoUrl!==void 0){let a=Y(r.logoUrl);if(!a)throw new d("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster image reference");i.logoUrl=a}if(r.brandName===null)delete i.brandName;else if(r.brandName!==void 0){let a=r.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}if(r.hideBadge===null||r.hideBadge===!1?delete i.hideBadge:r.hideBadge===!0&&(i.hideBadge=!0),r.venue3d===null)delete i.venue3d;else if(r.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of ro){let l=r.venue3d[s];l===null?delete a[s]:l!==void 0&&(a[s]=N(l,`3D venue ${s}`))}let n=r.venue3d.roughness;if(n===null)delete a.roughness;else if(n!==void 0){if(!Number.isFinite(n)||n<0||n>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=n}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==o,theme:t.theme??null}}function bi(t,e){let r=e.url===null?null:Y(e.url);if(e.url!==null&&!r)throw new d("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let l=(s.viewFromSeatUrl??void 0)===o,c=o?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=o,s.viewFromSeatMeta=c,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,n=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=o,t.viewFromSeatMeta=a,{changed:n,scope:"venue",url:t.viewFromSeatUrl??null}}function pi(t,e){let r=Ie(t,e.floorId),o=wt(r),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-e.height/2}:i==="left"?{x:o.x-a-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+e.height/2}}function je(t,e){F(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=e.endAngle-e.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new d("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new d("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,n=e.skewDegrees??0;if(!r(a,n)||Math.abs(a)>120||Math.abs(n)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let c=S(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:n,aisleGaps:s,rowLabelStart:e.rowLabelStart??c,seatLabelStart:e.seatLabelStart??1}}function io(t,e,r){let o=r*q;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function ao(t,e,r,o){let i=Math.abs(o-r)*q,a=[["left",.25],["center",.5],["right",.75]].flatMap(([c,f])=>{let g=t.aisleGaps[c];if(!g)return[];let h=g/e/i/2;return[[Math.max(0,f-h),Math.min(1,f+h)]]}).sort((c,f)=>c[0]-f[0]),n=[];for(let c of a){let f=n[n.length-1];f&&c[0]<=f[1]?f[1]=Math.max(f[1],c[1]):n.push([...c])}let s=[],l=0;for(let c of n)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*i*(f-c)>=t.seatPitch*.75)}function so(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let o=e-r,i=t.reduce((l,c)=>l+c,0),a=t.map(l=>o*l/i),n=a.map(l=>2+Math.floor(l)),s=e-n.reduce((l,c)=>l+c,0);return a.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&&n[l]++}),n}function Ae(t,e,r){let o=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),n=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,l=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,c=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;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 ${i+1} below a 5\xB0 sweep`);let f=ao(t,n,l,c);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let g=f.map(([m,y])=>n*Math.abs(c-l)*q*(y-m)),h=t.fit==="fixed-count"?so(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 x=Math.abs(b-_)*q/(p-1),v=2*n*Math.sin(x/2),I={type:"row",id:r(i,w),label:L(t.rowLabelStart+i),origin:io(t.center,n,_),rotation:-_,curve:b-_,seatCount:p,seatSpacing:v,categoryKey:t.categoryKey,seatLabelStart:u,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:w}};o.push(I),u+=p})}return o}function Ht(t,e){let r=je(t,e),o=S(t,e.floorId),i=Ae(r,"preview-arc-fan",(l,c)=>`preview-fan-${l}-${c}`),a=i.map(l=>l.seatSpacing),n=Math.max(...a.map(l=>Math.abs(l-r.seatPitch))),s=[];return n>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${n.toFixed(1)} chart units`),i.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:r.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((l,c)=>l+c.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:n,aisleCount:Object.values(r.aisleGaps).filter(l=>l>0).length,warnings:s}}function vi(t,e){let r=je(t,e),o=S(t,e.floorId),i=new Set,a=P(t,"fan",e.idFactory,i),n=Ae(r,a,()=>P(t,"r",e.idFactory,i)),s=Ht(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=Z(n);g&&(l=P(t,"sec",e.idFactory,i),f={type:"section",id:l,label:c,outline:g,arcFanGroupId:a})}return o.objects.push(...n,...f?[f]:[]),{floorId:o.floorId,rowIds:n.map(g=>g.id),sectionId:l,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function lo(t,e){let r=S(t,e.floorId),o=r.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(o.some(g=>a(g)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let n=r.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:r.floorId,center:{...i.center},innerRadius:i.innerRadius,rowCount:i.rowCount,rowGap:i.rowGap,startAngle:i.startAngle,endAngle:i.endAngle,seatPitch:i.seatPitch,fit:i.fit,seatsPerRow:i.seatsPerRow,facing:i.facing,taperDegrees:i.taperDegrees,skewDegrees:i.skewDegrees,aisleGaps:{...i.aisleGaps},categoryKey:o[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:n?.label},l=je(t,s),c=new Set(Ae(l,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(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 Ii(t,e){lo(t,{floorId:e.floorId,groupId:e.groupId});let r=je(t,e),o=S(t,e.floorId),i=o.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),n=new Map(i.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,l=Ae(r,e.groupId,(y,w)=>n.get(`${y}:${w}`)??P(t,"r",e.idFactory,s)),c=Ht(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=Z(l);y&&(g={type:"section",id:a?.id??P(t,"sec",e.idFactory,s),label:f,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...i.map(y=>y.id),...a?[a.id]:[]]),u=Math.min(...o.objects.map((y,w)=>h.has(y.id)?w:1/0)),m=o.objects.filter(y=>!h.has(y.id));return m.splice(Number.isFinite(u)?u:m.length,0,...l,...g?[g]:[]),o.objects.splice(0,o.objects.length,...m),{floorId:o.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 co(t){let e=new Set(J(t).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),r=0;return()=>{for(;e.has(L(r));)r+=1;let o=L(r);return e.add(o),r+=1,o}}function Vt(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 ji(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,o=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(o)||o<=0)throw new d("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new d("invalid_operation","rotation must be a finite number of degrees");let i=S(t,e.floorId),a=new Set,n=co(t),s=Xe(e.rotation??0),l=e.curve??0,c=e.style,f=c?P(t,"rowblock",e.idFactory,a):void 0,g=c?Vt({style:c,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:o,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?o/2:0,x={type:"row",id:P(t,"r",e.idFactory,a),label:n(),origin:{x:e.origin.x+u.x*b*r+h.x*p,y:e.origin.y+u.y*b*r+h.y*p},rotation:s,curve:l,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return c&&f&&g&&(x.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:o,curve:l,signature:g}),x});i.objects.push(...m);let y=null,w=e.sectionLabel?.trim();if(w){let _=Z(m);if(_){let b={type:"section",id:P(t,"sec",e.idFactory,a),label:w,outline:_};i.objects.push(b),y=b.id}}return{floorId:i.floorId,rowIds:m.map(_=>_.id),sectionId:y,createdIds:[...m.map(_=>_.id),...y?[y]:[]]}}function Xt(t,e){let r=new Set(J(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;r.has(`${e}${o}`);)o+=1;let i=`${e}${o}`;return r.add(i),o+=1,i}}function fo(t,e){let r=new Set(J(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!r.has(e))return e;let o=2;for(;r.has(`${e} ${o}`);)o+=1;return`${e} ${o}`}var uo=456;function go(t){let e=Math.sqrt(Math.max(1,t)*uo);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function Ai(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=S(t,e.floorId),o=new Set,{width:i,height:a}=go(e.capacity),n=fo(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:P(t,"ga",e.idFactory,o),label:n,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:n,createdIds:[s.id]}}function Pi(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,o=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(o)||o<80)throw new d("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Table array center must be finite");let i=S(t,e.floorId),a=new Set,n=Xt(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:P(t,"t",e.idFactory,a),label:n(),center:{x:e.center.x+(c-(e.tableColumns-1)/2)*r,y:e.center.y+(l-(e.tableRows-1)/2)*o},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Ri(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,o=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(o)||o<52)throw new d("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Booth array center must be finite");let i=S(t,e.floorId),a=new Set,n=Xt(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:P(t,"booth",e.idFactory,a),label:n(),center:{x:e.center.x+(c-(e.boothColumns-1)/2)*r,y:e.center.y+(l-(e.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Fi(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2||o.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==o.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(h=>h.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let l=(e.displayLabel??n[0].displayLabel??n[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=n[0];return n.forEach((h,u)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:u,componentCount:n.length,boundaryBefore:u===0?"start":e.boundaries[u-1],displayLabel: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:o,changed:!0}}function ki(t,e){let r=S(t,e.floorId),o=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??o?.segmentedRow?.groupId;if(!i)throw new d("object_not_found","The segmented row does not exist on the selected floor");let a=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let n=a.sort((s,l)=>s.segmentedRow.componentIndex-l.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:r.floorId,groupId:i,rowIds:n,changed:!0}}function Mi(t,e){let r=S(t,e.floorId),o=r.objects.filter(n=>n.type==="row"&&n.segmentedRow?.groupId===e.groupId).sort((n,s)=>n.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(o.length<2)throw new d("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==o.length-1||e.boundaries.some(n=>n!=="continuous"&&n!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(o.map(n=>n.segmentedRow));return o.forEach((n,s)=>{let l=n.segmentedRow,c=l.viewFromSeatUrl;i!==void 0&&(l.displayLabel=i),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:o.map(n=>n.id),changed:JSON.stringify(o.map(n=>n.segmentedRow))!==a}}function Ti(t,e){let r=S(t,e.floorId),o=r.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,D)=>O.rowBlockGeneration.rowIndex-D.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((O,D)=>{let R=O.rowBlockGeneration;return R.kind!=="row-block-v1"||R.rowIndex!==D||R.signature!==i.signature||JSON.stringify(R)!==JSON.stringify({...i,rowIndex:D})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(o),n=e.style??i.style,s=e.rowCount??i.rowCount,l=e.seatsPerRow??i.seatsPerRow,c=e.rowGap??i.rowGap,f=e.seatSpacing??i.seatSpacing,g=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?Xe(e.rotation??i.rotation):e.rotation??i.rotation,u=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(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=Vt({style:n,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(o.map(O=>[O.rowBlockGeneration.rowIndex,O])),b=new Set,p=new Set(r.objects.filter(O=>O.type==="row").filter(O=>!o.includes(O)).map(O=>O.label)),x=r.objects.filter(O=>O.type==="row").length,v=()=>{for(;p.has(L(x));)x+=1;let O=L(x);return p.add(O),x+=1,O},I=[],A=[];for(let O=0;O<s;O+=1){let D=n==="intertwined"&&O%2===1?f/2:0,R=_.get(O);R||(R={type:"row",id:P(t,"r",e.idFactory,b),label:v(),origin:{...u},rotation:h,curve:g,seatCount:l,seatSpacing:f,categoryKey:o[0].categoryKey},A.push(R.id)),R.origin={x:u.x+w.x*O*c+y.x*D,y:u.y+w.y*O*c+y.y*D},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(Ee=>Ee.index<l),R.overrides.length||delete R.overrides),R.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:n,rowIndex:O,rowCount:s,seatsPerRow:l,origin:{...u},rotation:h,rowGap:c,seatSpacing:f,curve:g,signature:m},I.push(R)}let H=o.slice(s).map(O=>O.id),U=Math.min(...o.map(O=>r.objects.indexOf(O))),V=new Set(o.map(O=>O.id)),$=r.objects.filter(O=>!V.has(O.id));return $.splice(U,0,...I),r.objects.splice(0,r.objects.length,...$),{floorId:r.floorId,groupId:e.groupId,rowIds:I.map(O=>O.id),createdRowIds:A,removedRowIds:H,changed:a!==JSON.stringify(I)||A.length>0||H.length>0}}var ho=300,bo=40;function po(t){let e=new Set(J(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),r=0,o=()=>{for(;e.has(L(r));)r+=1;let i=L(r);return r+=1,i};return i=>{let a=i.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,bo).trim(),n=0;return()=>{for(;a&&n<4096;n+=1){let l=`${a}-${L(n)}`;if(!e.has(l))return e.add(l),n+=1,l}let s=o();return e.add(s),s}}}function mo(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 yo(t,e,r,o,i){let a=t.sectionId?e.find(l=>l.type==="section"&&l.id===t.sectionId):void 0;if(a){let l=mo(e,r).filter(c=>E(T(c),a.outline,a.holes));if(l.length)return{skip:{sectionId:a.id,name:t.name,reason:"section_not_empty",objectIds:l.map(c=>c.id)},rows:[],seats:0}}let n=[],s=0;for(let l of t.rows){let c=Math.min(ho,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):o>0?o:24;if(!Number.isFinite(u)||u<=0)continue;let m=h>0?Math.atan2(g,f)*180/Math.PI:0;n.push({label:i(),origin:{x:l.start.x,y:l.start.y},rotation:m,seatCount:c,seatSpacing:u}),s+=c}return{skip:null,rows:n,seats:s}}function Ki(t,e,r){F(t,r.categoryKey);let o=S(t,r.floorId),i=e.assetId,a=[],n=o.objects.filter(u=>u.type==="row"&&u.referenceScan?.assetId===i?(a.push(u.id),!1):!0);o.objects.splice(0,o.objects.length,...n);let s=[],l=[],c=[],f=new Set,g=0,h=po(t);for(let u of e.sections){let m=yo(u,o.objects,i,e.seatPitch,h(u.name));if(m.skip){l.push(m.skip);continue}let y=m.rows.map(w=>({type:"row",id:P(t,"r",r.idFactory,f),referenceScan:{assetId:i},label:w.label,origin:w.origin,rotation:w.rotation,curve:0,seatCount:w.seatCount,seatSpacing:w.seatSpacing,categoryKey:r.categoryKey}));o.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:o.floorId,assetId:i,createdRowIds:c,removedRowIds:a,totalSeats:g,perSection:s,skipped:l}}function Yt(t,e){let r=S(t,e.floorId),o=[...new Set(e.objectIds)];if(!o.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let i=o.map(u=>r.objects.find(m=>(m.type==="table"||m.type==="booth")&&m.id===u)),a=o.filter((u,m)=>!i[m]);if(a.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:a});let n=i[0].type;if(i.some(u=>u.type!==n))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=o.length*(s-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let c=i.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>ee)throw new d("invalid_operation",`Grid inventory would exceed the ${ee} unit event limit`);return{target:r,sources:i,preview:{floorId:r.floorId,kind:n,sourceIds:o,sourceCount:o.length,cells:s,createdCount:l,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:i.filter(u=>!!u.referenceInventorySource).length*(s-1)}}}function Bi(t,e){return Yt(t,e).preview}function Ui(t,e){let{target:r,sources:o,preview:i}=Yt(t,e),a=new Set,n=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(;n.has(m);)m=u(++h);return n.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 o){let u=structuredClone(h);u.id=P(t,u.type,e.idFactory,a),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),{...i,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 vo=new Set(be.map(t=>t.key));function Pe(t){return`${t.rowId}:${t.index}`}function Yi(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",o=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(o)||o<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:o}}function Io(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,de(t.glyph)||delete t.glyph,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 So(t){return Object.keys(t).every(e=>e==="index")}function Zt(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let o=S(t,e),i=[],a=new Set,n=new Map;for(let s of r){let l=Pe(s);if(a.has(l))continue;a.add(l);let c=o.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});i.push({rowId:s.rowId,index:s.index}),n.set(c.id,c)}return{floorId:o.floorId,refs:i,owners:n}}function Wt(t,e){let r=Zt(t,e.floorId,e.seats),o=Object.keys(e.patch);if(!o.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&F(t,e.patch.categoryKey),e.patch.glyph!=null&&!de(e.patch.glyph))throw new d("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(n=>!vo.has(n));if(a.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new d("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of r.refs){let n=r.owners.get(a.rowId)?.overrides?.find(c=>c.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??n?.wheelchairSpaceType,l=e.patch.skip===null?!1:e.patch.skip??n?.skip??!1;if(s&&l)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:Pe(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new d("invalid_operation","Commercial note supports at most 160 characters");if(e.patch.viewFromSeatUrl!=null){let a=Y(e.patch.viewFromSeatUrl);if(!a)throw new d("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");e.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let n=e.patch[a];if(n!=null&&!Number.isFinite(n))throw new d("invalid_operation",`${a} must be finite`,{[a]:n})}e.patch.labelStyle!=null&&ne(e.patch.labelStyle,"Seat");let i=!1;return r.refs.forEach((a,n)=>{let s=r.owners.get(a.rowId),l=JSON.stringify(s.overrides??[]),c=s.overrides??(s.overrides=[]),f=c.find(h=>h.index===a.index);f||(f={index:a.index},c.push(f));let g=f.viewFromSeatUrl;for(let h of o){let u=e.patch[h];if(h==="wheelchairSpaceType"&&u==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(m=>m!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(u==null)delete f[h];else if(h==="accessibility")f.accessibility=[...new Set(u)],delete f.accessible;else if(h==="commercial")f.commercial={...f.commercial,...u};else if(h==="labelStyle"){let m=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}${n+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${n+1}`),Io(f),So(f)&&(s.overrides=c.filter(h=>h!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==l&&(i=!0)}),{floorId:r.floorId,changed:i,seatIds:r.refs.map(Pe)}}function Zi(t,e){let r=Zt(t,e.floorId,e.seats),o=!1;for(let[i,a]of r.owners){if(!a.overrides?.length)continue;let n=new Set(r.refs.filter(l=>l.rowId===i).map(l=>l.index)),s=a.overrides.filter(l=>!n.has(l.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:r.floorId,changed:o,seatIds:r.refs.map(Pe)}}function ta(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(b=>r.objects.find(p=>p.type==="row"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&F(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let b=e.patch.seatNumbering,p=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(b.scheme!==void 0&&!p.includes(b.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${b.scheme}. Expected one of ${p.join(", ")}.`);if(b.prefix!==void 0&&(typeof b.prefix!="string"||b.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(b.endAt!==void 0&&b.endAt!==null&&(!Number.isInteger(b.endAt)||b.endAt<0||b.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:n,labelPosition:s,labelRotation:l,labelStyleShape:c,displayLabel:f,displayType:g,...h}=e.patch,u=f===void 0?{}:{displayLabel:f},m=te(u,"Row"),y=g===void 0?void 0:Je(g,"Row");if(n!==void 0&&ne(n,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new d("invalid_operation","Row labelPosition must be one of start, end, both, none");if(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&&Ce(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 i){let p=JSON.stringify(b),x=w(b),v=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?T(b):null;if(Object.assign(b,structuredClone(h)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(I=>I.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),v){let I=T(b);b.origin={x:b.origin.x+v.x-I.x,y:b.origin.y+v.y-I.y}}if(JSON.stringify(b)!==p&&(_=!0),w(b)!==x&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),n!==void 0){let I=JSON.stringify(b.labelPresentation??null),A=xe(b.labelPresentation,n);A?b.labelPresentation=A:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==I&&(_=!0)}if(s!==void 0){let I=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)!==I&&(_=!0)}if(l!==void 0||c!==void 0){let I=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)!==I&&(_=!0)}if(y!==void 0){let I=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==I&&(_=!0)}if(f!==void 0){let I=b.displayLabel;m?delete b.displayLabel:b.displayLabel=u.displayLabel,b.displayLabel!==I&&(_=!0)}}return{floorId:r.floorId,changed:_,rowIds:o}}var Co=3;function Re(t){return(t%360+360)%360}function xo(t){let e=t.rotation*B;return{x:Math.cos(e),y:Math.sin(e)}}function _o(t,e){let r=Math.abs(Re(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 Qt(t){let e=0,r=0;for(let i of t){let a=2*i.rotation*B;e+=Math.cos(a),r+=Math.sin(a)}let o=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(o),y:Math.sin(o)}}function Oo(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let o=i=>({x:i.x+e,y:i.y+r});t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)}}}function en(t,e){let r=Qt(t),o={x:-r.y,y:r.x},i=T(t[0]),a=t.map(l=>({row:l,coord:oe(T(l),i,o)})).sort((l,c)=>l.coord-c.coord),n=a[0].coord,s=!1;return a.forEach((l,c)=>{let f=n+c*e-l.coord;Math.abs(f)>1e-6&&(Oo(l.row,o.x*f,o.y*f),delete l.row.arcFanGeneration,delete l.row.rowBlockGeneration,s=!0)}),s}function jo(t,e){let r={x:-e.y,y:e.x},o=T(t[0]),i=t.map(n=>oe(T(n),o,r)).sort((n,s)=>n-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Ao(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=$e(t),r=e[0],o=e[e.length-1],i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,n/(t.seatCount-1))),n>1e-6&&(t.rotation=Re(Math.atan2(a,i)/B)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Po(t,e){let r=new Set(t.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${e}${o}`.slice(0,80);if(!r.has(i))return i}return`${e}-${Date.now().toString(36)}`}function na(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to merge");let i=o.map(v=>r.objects.find(I=>I.type==="row"&&I.id===v)),a=o.filter((v,I)=>!i[I]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(v=>v.path||v.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(v=>v.id)});let l=n[0],c=n.find(v=>_o(v.rotation,l.rotation)>Co);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=xo(l),g={x:-f.y,y:f.x},h=Math.max(8,l.seatSpacing*.6),u=n.find(v=>Math.abs(oe(v.origin,l.origin,g))>h);if(u){let v=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 ${v} units from the first.`,{rowIds:[l.id,u.id]})}let m=n.slice().sort((v,I)=>oe(v.origin,l.origin,f)-oe(I.origin,l.origin,f)),y=m.reduce((v,I)=>v+I.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 v of m){if(v.overrides)for(let I of v.overrides)_.push({...structuredClone(I),index:I.index+b});b+=v.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(v=>v.id),x=new Set(p);for(let v=r.objects.length-1;v>=0;v--)x.has(r.objects[v].id)&&r.objects.splice(v,1);return{floorId:r.floorId,changed:!0,rowId:w.id,removedRowIds:p,seatCount:y}}function oa(t,e){let r=S(t,e.floorId),o=r.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!o)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(o.path)throw new d("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let n=$e(o),s=i>1?o.curve/(i-1):0,l=i-a,c={type:"row",id:P(t,"r",e.idFactory,new Set),label:Po(r.objects,o.label),origin:{...n[a]},rotation:Re(o.rotation-s*a),curve:s*(l-1),seatCount:l,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(c.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(c.seatLabelStart=o.seatLabelStart),o.commercial&&(c.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(c.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(c.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(c.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let u=structuredClone(o.labelPresentation);delete u.position,c.labelPresentation=u}let f=[],g=[];if(o.overrides)for(let u of o.overrides)u.index<a?f.push(structuredClone(u)):g.push({...structuredClone(u),index:u.index-a});o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,g.length&&(c.overrides=g);let h=r.objects.indexOf(o);return r.objects.splice(h+1,0,c),{floorId:r.floorId,changed:!0,rowId:o.id,newRowId:c.id,firstSeatCount:a,secondSeatCount:l,newLabel:c.label}}function ra(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new d("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(s=>r.objects.find(l=>l.type==="row"&&l.id===s)),a=o.filter((s,l)=>!i[l]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=en(i,e.gap);return{floorId:r.floorId,changed:n,rowIds:o,gap:e.gap}}function ia(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=()=>JSON.stringify(n.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),l=s();for(let h of n)Ao(h);let c=Qt(n),f=Re(Math.atan2(c.y,c.x)/B);for(let h of n)h.rotation=f;let g=jo(n,c);return en(n,g),{floorId:r.floorId,changed:s()!==l,rowIds:o,gap:g}}import We from"polygon-clipping";var tn=100,nn=512,Qe=8192,fn=64,on=1e7,k=1e-7;function un(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function gn(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&un(e[0],e[e.length-1]);)e.pop();return e}function ge(t,e,r){let o=G(e,r,t);return Math.abs(o)>k?!1:t.x>=Math.min(e.x,r.x)-k&&t.x<=Math.max(e.x,r.x)+k&&t.y>=Math.min(e.y,r.y)-k&&t.y<=Math.max(e.y,r.y)+k}function hn(t,e,r,o){let i=G(t,e,r),a=G(t,e,o),n=G(r,o,t),s=G(r,o,e);return(i>k&&a<-k||i<-k&&a>k)&&(n>k&&s<-k||n<-k&&s>k)?!0:Math.abs(i)<=k&&ge(r,t,e)||Math.abs(a)<=k&&ge(o,t,e)||Math.abs(n)<=k&&ge(t,r,o)||Math.abs(s)<=k&&ge(e,r,o)}function Ro(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let o=e+1;o<t.length;o+=1){let i=(o+1)%t.length;if(!(e===o||r===o||i===e)&&hn(t[e],t[r],t[o],t[i]))return!0}}return!1}function rn(t,e){return t.some((r,o)=>e.some((i,a)=>hn(r,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function et(t,e){return!e.some((r,o)=>ge(t,r,e[(o+1)%e.length]))&&E(t,e,void 0)}function ke(t,e,r){let o=gn(t);if(o.length<3||o.length>nn||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>on||Math.abs(i.y)>on||un(i,o[(a+1)%o.length]))||Math.abs(me(o))<=k||Ro(o))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${nn} finite vertices per ring.`,{gaAreaId:r,ring:e});return o}function Fo(t){let e=ke(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>fn)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=r.map(i=>ke(i,"cutout",t.id));for(let i=0;i<o.length;i+=1){let a=o[i];if(!a.flatMap((s,l)=>{let c=a[(l+1)%a.length];return[s,{x:(s.x+c.x)/2,y:(s.y+c.y)/2}]}).every(s=>et(s,e))||rn(a,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<o.length;s+=1)if(rn(a,o[s])||et(a[0],o[s])||et(o[s][0],a))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:o}}function Fe(t){return t.map(e=>[e.x,e.y])}function an(t){return gn(t.map(([e,r])=>({x:e,y:r})))}function sn(t){return Math.abs(t.reduce((e,r,o)=>{let i=t[(o+1)%t.length];return e+r[0]*i[1]-i[0]*r[1]},0))/2}function ko(t){return t.reduce((e,r)=>e+(sn(r[0]??[])-r.slice(1).reduce((o,i)=>o+sn(i),0)),0)}function tt(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(tt).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${tt(e[r])}`).join(",")}}`}function ln(t,e,r){let o=t[e];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return i}function cn(t){return tt({categoryKey:t.categoryKey,displayLabel:ln(t,"displayLabel",80),displayType:ln(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function dn(t,e){let r=Math.min(...t.points.map(i=>i.y)),o=Math.min(...t.points.map(i=>i.x));return[r,o,e]}function Mo(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function bn(t,e){let r=S(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(o.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(o.length>tn)throw new d("invalid_operation",`Join Areas supports at most ${tn} areas at once`);let i=o.map(C=>r.objects.find(j=>j.type==="gaArea"&&j.id===C)),a=o.filter((C,j)=>!i[j]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=i;F(t,n[0].categoryKey);let s=cn(n[0]),l=n.find(C=>cn(C)!==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:[n[0].id,l.id]});let c=ce(t).objectToSection,f=c.get(n[0].id)??"__ungrouped__",g=n.find(C=>(c.get(C.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:[n[0].id,g.id],sectionIds:[f,c.get(g.id)??"__ungrouped__"]});let h=n.reduce((C,j)=>{if(!Number.isInteger(j.capacity)||j.capacity<1||j.capacity>ye)throw new d("invalid_operation",`GA area ${j.id} has invalid capacity`,{gaAreaId:j.id});return C+j.capacity},0);if(h>ye)throw new d("invalid_operation",`Joined GA capacity would be ${h}, over the ${ye}-unit area limit`,{capacity:h});let u=J(t).reduce((C,j)=>C+W(j),0);if(u>ee)throw new d("invalid_operation",`Chart inventory exceeds the ${ee}-unit publication limit`,{inventory:u});let m=n.map(Fo),y=m.reduce((C,j)=>C+j.outer.length+j.holes.reduce((K,X)=>K+X.length,0),0);if(y>Qe)throw new d("invalid_operation",`Join Areas supports at most ${Qe} source vertices`,{vertexCount:y});let w;try{let C=m.map(X=>[Fe(X.outer)]);if(w=We.union(C[0],...C.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 j=m.flatMap(X=>X.holes.map(Le=>[Fe(Le)]));j.length&&(w=We.difference(w,...j));let K=m.findIndex(X=>{let Le=[Fe(X.outer),...X.holes.map(Fe)];return ko(We.intersection(Le,w))<=k});if(K>=0)throw new d("invalid_operation",`GA area ${n[K].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:n[K].id})}catch(C){throw C instanceof d?C:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:C instanceof Error?C.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 _=an(w[0][0]),b=w[0].slice(1).map(an),p=_.length+b.reduce((C,j)=>C+j.length,0);if(b.length>fn||p>Qe)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:b.length,vertexCount:p});ke(_,"outline",n[0].id),b.forEach(C=>ke(C,"cutout",n[0].id));let x=new Map(r.objects.map((C,j)=>[C.id,j])),v=n.slice().sort((C,j)=>Mo(dn(C,x.get(C.id)??Number.MAX_SAFE_INTEGER),dn(j,x.get(j.id)??Number.MAX_SAFE_INTEGER))),I=v[0],A=structuredClone(t),H=S(A,r.floorId),U=H.objects.find(C=>C.type==="gaArea"&&C.id===I.id);U.points=structuredClone(_),b.length?U.holes=structuredClone(b):delete U.holes;let V=new Set(v.slice(1).map(C=>C.id));for(let C=H.objects.length-1;C>=0;C-=1)V.has(H.objects[C].id)&&H.objects.splice(C,1);let $=ce(A).objectToSection.get(I.id)??"__ungrouped__";if($!==f)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:f,afterSectionId:$});let O=[],D=new Set;for(let C of v){if(!vt(C))throw new d("invalid_operation",`GA area ${C.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:C.id});let j=le(C);if(j.length!==C.capacity||j.some(K=>D.has(K)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:C.id});j.forEach(K=>D.add(K)),O.push(...It(C))}if(O.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let R=new Set(n.map(C=>C.id));for(let C of J(t).filter(j=>j.type==="gaArea"&&!R.has(j.id))){let j=le(C).find(K=>D.has(K));if(j)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:j,gaAreaId:C.id})}let Ee=v.slice(1).map(C=>C.id);return{floorId:r.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:Ee,sourceAreaCount:v.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:_.length,holeCount:b.length,sectionId:f,points:_,...b.length?{holes:b}:{},segments:O}}function ga(t,e){let{segments:r,...o}=bn(t,e);return o}function ha(t,e){let r=bn(t,e),o=S(t,r.floorId),i=o.objects.find(l=>l.type==="gaArea"&&l.id===r.areaId);i.points=structuredClone(r.points),r.holes?.length?i.holes=structuredClone(r.holes):delete i.holes,i.capacity=r.capacity,i.inventorySegments=structuredClone(r.segments);let a=new Set(r.removedAreaIds);for(let l=o.objects.length-1;l>=0;l-=1)a.has(o.objects[l].id)&&o.objects.splice(l,1);let{segments:n,...s}=r;return{...s,changed:!0}}function wa(t,e){let r=S(t,e.floorId),o=[...new Set(e.shapeIds)];if(!o.length)throw new d("invalid_operation","At least one shape id is required");let i=o.map(c=>r.objects.find(f=>f.type==="shape"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one shape change is required");if(n.label!==void 0){if(o.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(n.label!==null){if(n.label=n.label.normalize("NFKC").trim(),!n.label)n.label=null;else if(n.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(n.fill!==void 0&&n.fill!==null&&(n.fill=N(n.fill,"Shape fill")),n.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(n.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(n.stroke!==void 0&&n.stroke!==null){if(!Number.isFinite(n.stroke.width)||n.stroke.width<.5||n.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");n.stroke={color:N(n.stroke.color,"Shape stroke"),width:n.stroke.width}}if(n.cornerRadius!==void 0&&n.cornerRadius!==null&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(n.opacity!==void 0&&n.opacity!==null&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(n.heightM!==void 0&&n.heightM!==null&&(!Number.isFinite(n.heightM)||n.heightM<.05||n.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(n.eventConfigurationIds!==void 0&&n.eventConfigurationIds!==null){let c=n.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");n.eventConfigurationIds=c}if(n.lineCap!==void 0&&n.lineCap!==null&&!xt.includes(n.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(n.lineJoin!==void 0&&n.lineJoin!==null&&!_t.includes(n.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[c,f]of[["startEnding",n.startEnding],["endEnding",n.endEnding]])if(f!=null&&!Ot.includes(f))throw new d("invalid_operation",`Shape ${c} must be none or arrow`);if(n.lineCap!=null||n.lineJoin!=null||n.startEnding!=null||n.endEnding!=null){let c=i.filter(f=>!Ue(n.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 i){let f=JSON.stringify(c);if(n.label===null?delete c.label:n.label!==void 0&&(c.label=n.label),n.fill===null?delete c.fill:n.fill!==void 0&&(c.fill=n.fill),n.kind!==void 0&&(c.kind=n.kind,Ue(c.kind)||(delete c.lineCap,delete c.lineJoin,delete c.startEnding,delete c.endEnding)),n.stroke===null?delete c.stroke:n.stroke!==void 0&&(c.stroke={...n.stroke}),n.opacity===null?delete c.opacity:n.opacity!==void 0&&(c.opacity=n.opacity),n.heightM===null?delete c.heightM:n.heightM!==void 0&&(c.heightM=n.heightM),n.eventConfigurationIds===null?delete c.eventConfigurationIds:n.eventConfigurationIds!==void 0&&(c.eventConfigurationIds=[...n.eventConfigurationIds]),n.lineCap===null?delete c.lineCap:n.lineCap!==void 0&&(c.lineCap=n.lineCap),n.lineJoin===null?delete c.lineJoin:n.lineJoin!==void 0&&(c.lineJoin=n.lineJoin),n.startEnding===null?delete c.startEnding:n.startEnding!==void 0&&(c.startEnding=n.startEnding),n.endEnding===null?delete c.endEnding:n.endEnding!==void 0&&(c.endEnding=n.endEnding),n.cornerRadius===null)delete c.cornerRadius;else if(n.cornerRadius!==void 0){let g=Math.min(c.width??1/0,c.height??1/0),h=Number.isFinite(g)?g/2:n.cornerRadius;c.cornerRadius=c.kind==="rect"?Math.max(0,Math.min(n.cornerRadius,h)):n.cornerRadius}JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,shapeIds:o}}function pn(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),o=e.map(f=>f.y),i=Math.min(...r),a=Math.max(...r),n=Math.min(...o),s=Math.max(...o),l=Math.max(1,a-i),c=Math.max(1,s-n);return{cx:i+l/2,cy:n+c/2,width:l,height:c}}function va(t,e){let r=S(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let o=e.updates.map(n=>n.shapeId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Shape ids must be unique");let i=e.updates.map(n=>{if(![n.width,n.height].every(Number.isFinite)||n.width<8||n.height<8||n.width>1e4||n.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:n.shapeId});let s=r.objects.find(c=>c.type==="shape"&&c.id===n.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${n.shapeId}`,{shapeId:n.shapeId});let l=s.role==="stage"?pn(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:n,box:l}}),a=!1;for(let{shape:n,update:s,box:l}of i)if(!(Math.abs(l.width-s.width)<1e-9&&Math.abs(l.height-s.height)<1e-9)){if(n.kind==="rect"||n.kind==="ellipse")n.x=l.cx-s.width/2,n.y=l.cy-s.height/2,n.width=s.width,n.height=s.height;else{let c=s.width/l.width,f=s.height/l.height;n.points=(n.points??[]).map(g=>({x:l.cx+(g.x-l.cx)*c,y:l.cy+(g.y-l.cy)*f})),(n.x!=null||n.y!=null||n.width!=null||n.height!=null||n.role==="stage")&&(n.x=l.cx-s.width/2,n.y=l.cy-s.height/2,n.width=s.width,n.height=s.height)}a=!0}return{floorId:r.floorId,changed:a,shapes:i.map(({shape:n,update:s})=>({id:n.id,width:s.width,height:s.height}))}}function Ia(t,e){let r=S(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let o=e.updates.map(s=>s.stageId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Stage ids must be unique");let i=new Set(jt.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let 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:pn(l)}}),n=!1;for(let s of a)s.box&&(s.shape.points=At({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,n=!0);return{floorId:r.floorId,changed:n,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function mn(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let r of M(t)){r.confidenceEvidence&&e.set(`floor:${r.id}`,{target:{scope:"floor",floorId:r.id},evidence:r.confidenceEvidence});for(let o of r.objects){let i=`floor:${r.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&e.set(i,{target:{scope:o.type,floorId:r.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&e.set(`${i}:segmented`,{target:{scope:"row",floorId:r.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&e.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:r.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return e}function Me(t){return Array.isArray(t)?t.map(Me):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[r])=>e.localeCompare(r)).map(([e,r])=>[e,Me(r)]))}function No(t,e){return JSON.stringify(Me(t))===JSON.stringify(Me(e))}function nt(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function Eo(t){return t?t.status==="retracted"?"retract":nt(t)?"approve":"set":"clear"}function Lo(t,e){let r=mn(t),o=mn(e),i=[...new Set([...r.keys(),...o.keys()])].sort(),a=[];for(let n of i){let s=r.get(n),l=o.get(n);if(s&&l&&No(s.evidence,l.evidence))continue;let c=l?.target??s?.target;c&&a.push({...c,operation:Eo(l?.evidence),...s?{before:s.evidence}:{},...l?{after:l.evidence}:{}})}return a}function Oa(t,e){return Lo(t,e).some(r=>nt(r.before)||nt(r.after))}var Do=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Ko=new Set(["generated","geometry-verified","configuration-verified"]),Go=new Set(["none","comparable-build-reference","actual-build-checked"]),$o=new Set(["clear","partial","obstructed"]);function ot(t){return t.toISOString().slice(0,10)}function rt(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function ie(t,e,r){if(!rt(t,e))throw new d("invalid_operation",`Confidence evidence ${r} is invalid`,{field:r});return t}function re(t,e,r){if(t!==void 0)return ie(t,e,r)}function Te(t,e,r){let o=r?[S(t,r)]:M(t).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(n=>n.id===e);if(a)return{floorId:i.floorId,object:a}}throw new d("object_not_found",`Unknown chart object: ${e}`,{objectId:e,floorId:r})}function yn(t,e){let r=M(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return o}function he(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return yn(t,e.floorId).confidenceEvidence;if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let o=Te(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new d("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:e.objectId});return o.object.overrides?.find(i=>i.index===e.seatIndex)?.confidenceEvidence}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let r=Te(t,e.objectId,e.floorId);if(e.scope==="row"&&r.object.type!=="row")throw new d("invalid_operation","Row evidence requires a row id",{objectId:e.objectId});if(e.scope==="section"&&r.object.type!=="section")throw new d("invalid_operation","Section evidence requires a section id",{objectId:e.objectId});if(r.object.type==="row"||r.object.type==="section")return r.object.confidenceEvidence;throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:r.object.type})}function Ne(t,e,r){if(e.scope==="venue")return r?t.confidenceEvidence=r:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=yn(t,e.floorId);return r?i.confidenceEvidence=r:delete i.confidenceEvidence,{floorId:i.id}}if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let i=Te(t,e.objectId,e.floorId);return Wt(t,{floorId:i.floorId,seats:[{rowId:e.objectId,index:e.seatIndex}],patch:{confidenceEvidence:r??null}}),{floorId:i.floorId,objectId:e.objectId}}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let o=Te(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:o.object.type});return r?o.object.confidenceEvidence=r:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function zo(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!rt(t.label,80)||!rt(t.methodLabel,100))throw new d("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(t.totalRayCount)||t.totalRayCount<1||t.totalRayCount>1e3||!Number.isInteger(t.clearRayCount)||t.clearRayCount<0||t.clearRayCount>t.totalRayCount)throw new d("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!$o.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(r=>ie(r,80,"occluder label"));return{label:t.label,methodLabel:t.methodLabel,totalRayCount:t.totalRayCount,clearRayCount:t.clearRayCount,classification:t.classification,...e?.length?{occluderLabels:e}:{}}}function Bo(t,e=new Date){if(t.schema!==void 0&&t.schema!=="seatlayer.seat-confidence/1")throw new d("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!Do.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!Ko.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let r=t.realityLevel??"none";if(!Go.has(r))throw new d("invalid_operation","Confidence evidence reality level is invalid");if(t.evidenceKind==="synthetic-model"&&(t.modelLevel!=="generated"||r!=="none"))throw new d("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=re(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(f=>ie(f,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=re(t.assessedAt,40,"assessedAt")??ot(e),n=Date.parse(a);if(!Number.isFinite(n))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=re(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:ot(new Date(n+365*24*60*60*1e3))),l=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(l)||l<n||l>n+366*24*60*60*1e3))throw new d("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let c=re(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!c)throw new d("invalid_operation","Verified model levels require approvedByRole");return{schema:"seatlayer.seat-confidence/1",evidenceId:ie(t.evidenceId,120,"evidenceId"),modelVersion:ie(t.modelVersion,120,"modelVersion"),evidenceKind:t.evidenceKind,modelLevel:t.modelLevel,realityLevel:r,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...t.eventConfigurationVersion!==void 0?{eventConfigurationVersion:t.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...c?{approvedByRole:c}:{},...re(t.sourceLabel,120,"sourceLabel")?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:zo(t.modeledTarget)}:{}}}function ae(t,e={}){return{changed:e.changed??!0,scope:t.scope,...t.objectId?{objectId:t.objectId}:{},...t.floorId?{floorId:t.floorId}:{},...t.seatIndex!==void 0?{seatIndex:t.seatIndex}:{},...e}}function ja(t,e){let r=Bo(e.evidence,e.now),o=JSON.stringify(he(t,e)??null),i=Ne(t,e,r),a=JSON.stringify(he(t,e)??null);return ae(e,{changed:o!==a,...i,evidenceId:r.evidenceId,status:"draft"})}function Aa(t,e){let r=he(t,e);if(!r)return ae(e,{changed:!1});let o=Ne(t,e,void 0);return ae(e,{changed:!0,...o,evidenceId:r.evidenceId})}function Pa(t,e){let r=he(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to approve",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")throw new d("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=ie(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=re(e.eventConfigurationId,100,"eventConfigurationId")??r.eventConfigurationId;if(r.modelLevel==="configuration-verified"&&!i)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=e.eventConfigurationVersion??r.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let n={...r,status:"approved",approvedByRole:o,assessedAt:ot(e.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete n.basisSha256;let s=e.basisSha256??t.confidenceBasisSha256;s&&(n.basisSha256=s);let l=JSON.stringify(r),c=Ne(t,e,n);return ae(e,{changed:l!==JSON.stringify(n),...c,evidenceId:n.evidenceId,status:"approved"})}function Ra(t,e){let r=he(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to retract",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")return ae(e,{changed:!1,evidenceId:r.evidenceId,status:"retracted"});let o={...r,status:"retracted"};delete o.basisSha256;let i=Ne(t,e,o);return ae(e,{changed:!0,...i,evidenceId:r.evidenceId,status:"retracted"})}export{Ut as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,Tt as DEFAULT_FLOOR_HEIGHT_STEP_M,wn as DEFAULT_SECTION_CORNER_SMOOTHING,Uo as MAX_BUYER_IMAGE_URL_LENGTH,Ve as MAX_FLOOR_BASE_HEIGHT_M,vi as addArcFanRows,Ui as addBookableGridArray,Ri as addBoothArray,Un as addChartCategory,Zo as addChartFloor,ir as addChartZone,Ai as addGAArea,ji as addRowBlock,Pi as addTableArray,Er as applyPolygonHole,Ki as applyReferenceScanRows,Zr as applySectionCornerSmoothing,Dn as applySectionOutlineShaping,Nr as applySectionRowFit,Pa as approveConfidenceEvidence,lo as arcFanInputForGroup,qr as assignSectionInventoryCategory,pi as automaticPlacementCenter,Aa as clearConfidenceEvidence,Oa as confidenceEvidenceChangeRequiresPublish,Lo as confidenceEvidenceChanges,si as confirmReferenceCategoryOutputColor,Vr as convertGeneratedSectionToPolygon,Ye as countCoveredInventory,Zn as familyCategoryLabel,go as gaAreaFootprint,Fi as groupRowsAsSegmented,jr as insertSeatingBlock,Jo as isSafeBuyerImageUrl,ha as joinGAAreas,na as mergeRows,_e as mirrorFirstFloor,Y as normalizeBuyerImageUrl,Bo as normalizeDraftEvidence,Yi as parseSeatRefId,Bn as pickColorblindSafeCategoryColor,eo as planCreationCategory,Ht as previewArcFanRows,Bi as previewBookableGridArray,Nn as previewGeneratedSectionPolygonConversion,ga as previewJoinGAAreas,Ze as previewPolygonHole,kn as previewRemovePolygonHole,jn as previewRowCubicPath,Rn as previewSectionRowFit,ai as reassignColorblindSafeCategoryColors,Or as relabelChartRows,ci as removeChartCategory,er as removeChartFloor,xr as removeChartObjects,sr as removeChartZone,Lr as removePolygonHole,Wo as renameChartFloor,ii as reorderChartCategories,Ii as replaceArcFanRows,Ti as replaceRowBlock,Zi as resetSeatOverrides,va as resizeShapes,li as resolveCreationCategory,Ra as retractConfidenceEvidence,Pe as seatRefId,Tn as sectionInventorySelectionSummary,ja as setConfidenceEvidence,ra as setRowBlockSpacing,oa as splitRow,ia as straightenAndSpaceRows,Xr as transformSectionBoundary,En as transformSectionBoundaryObject,ki as ungroupSegmentedRow,Sr as updateBooths,Gn as updateCategoryDefinitions,Qo as updateChartFloorBaseHeight,hi as updateChartTheme,ar as updateChartZones,Cr as updateGAAreas,Tr as updateRowCubicPath,ta as updateRows,Wt as updateSeatOverrides,Yr as updateSectionExactPath,Hr as updateSectionMetadata,Mi as updateSegmentedRow,wa as updateShapes,Ia as updateStageKinds,Ir as updateTables,_r as updateTextObjects,bi as updateViewFromSeatFallback};
|
|
1
|
+
import{a as we,b as ve,f as Pt,g as Rt}from"../../chunk-NXFDYBZY.js";import"../../chunk-GXMGOWKB.js";import{n as Ct,p as xt,q as _t,r as Ot,v as Ue}from"../../chunk-JBGLFOJO.js";import{a as ye,b as ee,d as vt,e as It,f as le,g as ze,i as St,k as ce}from"../../chunk-AM2LRFAY.js";import{a as jt,b as At}from"../../chunk-T2LWVOQ3.js";import{b as be,h as De,i as Ke,l as Uo,m as Jo,n as Y}from"../../chunk-7KS6TAYH.js";import{j as de}from"../../chunk-UL5OIGIF.js";import{A as Ge,B as bt,Ba as J,C as pt,D as wn,Fa as wt,H as mt,R as yt,a as it,b as at,c as st,d as lt,e as ct,f as dt,g as pe,h as ft,i as ut,la as $e,oa as z,p as gt,sa as se,t as me,va as E,xa as T,z as ht,za as M}from"../../chunk-KCFEFP6H.js";import{m as Be}from"../../chunk-CXF32VPG.js";import"../../chunk-CRCGO52K.js";var d=class extends Error{constructor(r,o,i={}){super(o);this.code=r;this.details=i;this.name="ChartOperationError"}};function S(t,e){let r=M(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:o.id,objects:o.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 P(t,e,r,o){let i=new Set([...o,...t.categories.map(a=>a.key),...t.zones?.map(a=>a.id)??[],...t.floors?.map(a=>a.id)??[],...t.floors?.length?t.floors.flatMap(a=>a.objects.map(n=>n.id)):t.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let n=r(e);if(n&&!i.has(n))return o.add(n),n}throw new d("id_generation_failed",`Unable to allocate a unique ${e} id`)}function vn(t){let e=t.slice().sort((a,n)=>a.x-n.x||a.y-n.y);if(e.length<3)return e;let r=(a,n,s)=>(n.x-a.x)*(s.y-a.y)-(n.y-a.y)*(s.x-a.x),o=[];for(let a of e){for(;o.length>=2&&r(o[o.length-2],o[o.length-1],a)<=0;)o.pop();o.push(a)}let i=[];for(let a=e.length-1;a>=0;a--){let n=e[a];for(;i.length>=2&&r(i[i.length-2],i[i.length-1],n)<=0;)i.pop();i.push(n)}return o.pop(),i.pop(),o.concat(i)}function In(t,e){if(!t.length)return t;let r={x:t.reduce((o,i)=>o+i.x,0)/t.length,y:t.reduce((o,i)=>o+i.y,0)/t.length};return t.map(o=>{let i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a)||1;return{x:o.x+i/n*e,y:o.y+a/n*e}})}function Z(t){let e=[];for(let o of t)o.type==="row"?e.push(...z(o).map(i=>({x:i.x,y:i.y}))):o.type==="table"?e.push(...se(o).map(i=>({x:i.x,y:i.y}))):o.type==="gaArea"?e.push(...o.points):o.type==="booth"&&e.push(o.center);if(e.length<3)return null;let r=In(vn(e),22);return r.length>=3?r:null}function Ie(t,e){let r=S(t,e),o=M(t).find(i=>i.id===r.floorId);return{...t,objects:r.objects,floors:void 0,focalPoint:o.focalPoint,referenceImage:o.referenceImage,backgroundImage:o.backgroundImage}}var Ft=24,kt=80;function Je(t,e){let r=t.normalize("NFKC").trim();if(r.length>Ft)throw new d("invalid_operation",`${e} displayed type must be at most ${Ft} characters`);return r}function Se(t,e){if(t.displayType===void 0)return!1;let r=Je(t.displayType,e);return r?(t.displayType=r,!1):(delete t.displayType,!0)}function te(t,e){if(t.displayLabel===void 0)return!1;let r=t.displayLabel.normalize("NFKC").trim();if(r.length>kt)throw new d("invalid_operation",`${e} displayed label must be at most ${kt} 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 Mt(t,e){if(!Number.isFinite(t)||t<De||t>Ke)throw new d("invalid_operation",`${e} label size must be from ${De} to ${Ke}`)}function ne(t,e){t.size!==void 0&&t.size!==null&&Mt(t.size,e),t.color!==void 0&&t.color!==null&&N(t.color,`${e} label color`)}function Ce(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&&Mt(r.size,e),r.color!==void 0&&N(r.color,`${e} label color`))}function xe(t,e){let r=t?structuredClone(t):{},o=r.labelStyle?{...r.labelStyle}:{};return e.size===null?delete o.size:e.size!==void 0&&(o.size=e.size),e.color===null?delete o.color:e.color!==void 0&&(o.color=N(e.color,"Label color")),o.size===void 0&&o.color===void 0?delete r.labelStyle:r.labelStyle=o,e.visible!==void 0&&(r.visible=e.visible),Object.keys(r).length?r:void 0}function qe(t,e,r){let o=e.normalize("NFKC").trim();if(!o||o.length>80)throw new d("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(i=>i.id!==r&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new d("invalid_operation",`Zone label already exists: ${o}`);return o}function He(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 G(t,e,r){return(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x)}var q=Math.PI/180,B=Math.PI/180;function W(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 _e(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 Sn=0,Ve=120,Tt=4;function Cn(t){if(!Number.isFinite(t)||t<Sn||t>Ve)throw new d("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function Zo(t,e){let r=M(t);if(r.length>=5)throw new d("invalid_operation","A chart can contain at most five physical floors");let o=(e.name??String(r.length+1)).normalize("NFKC").trim();if(!o||o.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(l=>l.name.toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${o}`);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 a=t.floors[t.floors.length-1].baseHeightM??Math.min(Ve,(t.floors.length-1)*Tt),n=Math.min(Ve,a+Tt),s=P(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:o,baseHeightM:n,objects:[],focalPoint:{...t.focalPoint}}),_e(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:n}}function Wo(t,e){let r=M(t),o=r.find(n=>n.id===e.floorId);if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let i=e.name.normalize("NFKC").trim();if(!i||i.length>80)throw new d("invalid_operation","Floor names must contain 1 to 80 characters");if(r.some(n=>n.id!==o.id&&n.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new d("invalid_operation",`Floor name already exists: ${i}`);let a=o.name!==i;return a&&(o.name=i),{changed:a,floorId:o.id,floorName:i}}function Qo(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(i=>i.id===e.floorId);if(!r)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});Cn(e.baseHeightM);let o=r.baseHeightM!==e.baseHeightM;return o&&(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:o,floorId:r.id,baseHeightM:e.baseHeightM}}function er(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(i=>i.id===e.floorId);if(r<0)throw new d("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[o]=t.floors.splice(r,1);if(t.floors.length===1){let[i]=t.floors;t.objects=i.objects,t.focalPoint=i.focalPoint,t.referenceImage=i.referenceImage,t.backgroundImage=i.backgroundImage,t.floors=void 0}else _e(t);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:M(t).length}}function ir(t,e){if((t.zones?.length??0)>=100)throw new d("invalid_operation","A chart supports at most 100 zones");let r={id:P(t,"zone",e.idFactory,new Set),label:qe(t,e.label),color:N(e.color,"Zone color"),...e.focalPoint?{focalPoint:He(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(r),{changed:!0,zone:structuredClone(r)}}function ar(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 o=new Map((t.zones??[]).map(l=>[l.id,l])),i=r.filter(l=>!o.has(l));if(i.length)throw new d("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),n=new Map((a.zones??[]).map(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=n.get(l.zoneId);l.patch.label!==void 0&&(f.label=qe(a,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=He(l.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:r,zones:r.map(l=>structuredClone(n.get(l)))}}function sr(t,e){let r=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(r<0)throw new d("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let o=M(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(o.length&&e.clearSectionAssignments!==!0)throw new d("invalid_operation",`Zone ${e.zoneId} is assigned to ${o.length} section(s)`,{zoneId:e.zoneId,sectionIds:o.map(a=>a.id),requiresClearSectionAssignments:!0});let i=o.map(a=>a.id);for(let a of o)delete a.zone;return t.zones.splice(r,1),t.zones.length||delete t.zones,_e(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var Q={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 fe(t,e,r,o,i,a,n=0){return{type:"row",id:t,label:e,origin:{x:-(o-1)*i/2,y:r},rotation:0,curve:n,seatCount:o,seatSpacing:i,categoryKey:a}}function xn(t,e,r,o,i,a){return{type:"table",id:t,label:e,center:r,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function Nt(t,e,r,o,i,a){let n=r/2,s=o/2;return{type:"gaArea",id:t,label:e,points:[{x:-n,y:-s},{x:n,y:-s},{x:n,y:s},{x:-n,y:s}],capacity:i,categoryKey:a}}function _n(t,e,r,o,i){let a=r*2,n=[];for(let s=0;s<a;s++){let l=s%2===0,c=l?["wheelchair"]:["companion"];n.push(l?{index:s,accessibility:c,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:c})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:n}}var Et=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[Q.balcony],sectionLabel:"Balcony",build:()=>[fe("blk-b0","A",-45,18,24,"balcony",18),fe("blk-b1","B",-15,20,24,"balcony",18),fe("blk-b2","C",15,22,24,"balcony",18),fe("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[Q.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>fe(`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:[Q.standard],build:()=>[Nt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[Q.premium],build:()=>Array.from({length:6},(t,e)=>xn(`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:[Q.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:[Q.standard],build:()=>[Nt("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:[Q.standard],build:()=>[_n("blk-wc","A",4,40,"standard")]}];function L(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 Lt(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 Xe(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 Dt(t,e,r){let o=i=>({x:i.x+e,y:i.y+r});switch(t.type){case"row":t.origin=o(t.origin),t.path&&(t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)});break;case"table":case"booth":t.center=o(t.center);break;case"text":t.position=o(t.position);break;case"gaArea":t.points=t.points.map(o),t.holes&&(t.holes=t.holes.map(i=>i.map(o)));break;case"section":t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=bt(t.outlinePath,e,r)),t.holes&&(t.holes=t.holes.map(i=>i.map(o)));break;case"shape":t.points&&(t.points=t.points.map(o)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=r);break;case"decorImage":t.x+=e,t.y+=r;break}}function Ir(t,e){let r=S(t,e.floorId),o=[...new Set(e.tableIds)];if(!o.length)throw new d("invalid_operation","At least one table id is required");let i=o.map(b=>r.objects.find(p=>p.type==="table"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one table change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one table at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Table labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey);let s=n.seatCount!==void 0,l=n.seatCountsBySide!==void 0;if(l){if(n.sides!==void 0)throw new d("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(n.shape==="round")throw new d("invalid_operation","seatCountsBySide can be used only with rectangular tables");let b=["top","bottom","left","right"],p=Object.keys(n.seatCountsBySide);if(p.length!==b.length||p.some(v=>!b.includes(v)))throw new d("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let v of b){let I=n.seatCountsBySide[v];if(!Number.isInteger(I)||I<0||I>40)throw new d("invalid_operation",`seatCountsBySide.${v} must be a whole number from 0 to 40`)}let x=b.reduce((v,I)=>v+n.seatCountsBySide[I],0);if(x<1||x>40)throw new d("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&n.seatCount!==x)throw new d("invalid_operation",`seatCount must equal the ${x}-chair seatCountsBySide total`);n.seatCount=x,n.sides=b.filter(v=>n.seatCountsBySide[v]>0)}if(n.seatCount!==void 0&&(!Number.isInteger(n.seatCount)||n.seatCount<1||n.seatCount>40))throw new d("invalid_operation","seatCount must be an integer from 1 to 40");if(n.shape!==void 0&&n.shape!=="round"&&n.shape!=="rect")throw new d("invalid_operation","Table shape must be round or rect");if(n.bookAsWhole===!0&&n.variableOccupancy===!0)throw new d("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(n.variableOccupancy===!1&&(n.minOccupancy!==void 0||n.maxOccupancy!==void 0))throw new d("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let c=(b,p,x,v)=>{if(p!==void 0&&(!Number.isFinite(p)||p<x||p>v))throw new d("invalid_operation",`${String(b)} must be from ${x} to ${v}`)};if(c("rotation",n.rotation,0,360),c("radius",n.radius,24,160),c("seatArc",n.seatArc,120,360),c("width",n.width,40,320),c("height",n.height,30,240),n.minOccupancy!==void 0&&(!Number.isInteger(n.minOccupancy)||n.minOccupancy<1||n.minOccupancy>40))throw new d("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(n.maxOccupancy!==void 0&&(!Number.isInteger(n.maxOccupancy)||n.maxOccupancy<1||n.maxOccupancy>40))throw new d("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(n.sides!==void 0){let b=new Set(["top","bottom","left","right"]);if(!n.sides.length||n.sides.length>4||new Set(n.sides).size!==n.sides.length||n.sides.some(p=>!b.has(p)))throw new d("invalid_operation","Table sides must contain one to four unique perimeter sides")}let f=te(n,"Table"),g=Se(n,"Table"),h=i.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,n),p.shape==="round"&&delete p.seatCountsBySide,p.overrides&&n.seatCount!==void 0&&(p.overrides=p.overrides.filter(x=>x.index<p.seatCount),p.overrides.length||delete p.overrides),n.bookAsWhole===!1&&delete p.bookAsWhole,n.variableOccupancy===!1&&(delete p.variableOccupancy,delete p.minOccupancy,delete p.maxOccupancy),p.bookAsWhole||delete p.bookAsWhole,p.variableOccupancy||delete p.variableOccupancy,p.bookAsWhole&&p.variableOccupancy)throw new d("invalid_operation",`Table "${p.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:p.id});if((p.bookAsWhole||p.variableOccupancy)&&p.overrides?.length)throw new d("invalid_operation",`Table "${p.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:p.id,overriddenChairIndices:p.overrides.map(x=>x.index)});if(p.bookAsWhole)delete p.minOccupancy,delete p.maxOccupancy;else if(p.variableOccupancy){if(!Number.isInteger(p.minOccupancy)||!Number.isInteger(p.maxOccupancy)||p.minOccupancy<1||p.maxOccupancy<p.minOccupancy||p.maxOccupancy>p.seatCount)throw new d("invalid_operation",`Table "${p.label}" needs whole-number minimum and maximum guests from 1 to its ${p.seatCount}-chair capacity`,{tableId:p.id,seatCount:p.seatCount})}else{if(n.minOccupancy!==void 0||n.maxOccupancy!==void 0)throw new d("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:p.id});delete p.minOccupancy,delete p.maxOccupancy}if(g&&delete p.displayType,f&&delete p.displayLabel,p.shape==="rect"){if(p.width??=80,p.height??=50,p.seatCountsBySide){let x=["top","bottom","left","right"],v=x.reduce((I,A)=>I+p.seatCountsBySide[A],0);if(v!==p.seatCount)throw new d("invalid_operation",`Table "${p.label}" side counts total ${v}, but seatCount is ${p.seatCount}`,{tableId:p.id,seatCount:p.seatCount,seatCountsBySide:p.seatCountsBySide});p.sides=x.filter(I=>p.seatCountsBySide[I]>0)}}else p.radius??=40;if((p.bookAsWhole||p.variableOccupancy)&&St(p.label))throw new d("invalid_operation",`Grouped table label "${p.label}" uses SeatLayer's reserved GA namespace`,{tableId:p.id});return p}),u=new Map(h.map(b=>[b.id,b])),m=new Set(o),y=new Map;for(let b of M(t))for(let p of b.objects){let x=p.type==="table"?u.get(p.id)??p:p,v=[];x.type==="row"?v=z(x).map(I=>I.label):x.type==="table"?v=x.bookAsWhole||x.variableOccupancy?[x.label]:se(x).map(I=>I.label):x.type==="booth"?v=[x.label]:x.type==="gaArea"&&(v=le(x));for(let I of v){let A=y.get(I);if(A&&(m.has(A)||m.has(x.id)))throw new d("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:I,conflictingObjectIds:[A,x.id]});y.set(I,A??x.id)}}let w=!1,_=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[b,p]of i.entries()){let x=h[b],v=JSON.stringify(p);for(let I of _)I in x||delete p[I];Object.assign(p,x),JSON.stringify(p)!==v&&(w=!0)}return{floorId:r.floorId,changed:w,tableIds:o}}function Sr(t,e){let r=S(t,e.floorId),o=[...new Set(e.boothIds)];if(!o.length)throw new d("invalid_operation","At least one booth id is required");let i=o.map(u=>r.objects.find(m=>m.type==="booth"&&m.id===u)),a=o.filter((u,m)=>!i[m]);if(a.length)throw new d("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one booth change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one booth at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","Booth labels must contain 1 to 80 characters")}n.categoryKey!==void 0&&F(t,n.categoryKey);let s=(u,m,y,w)=>{if(m!==void 0&&(!Number.isFinite(m)||m<y||m>w))throw new d("invalid_operation",`${u} must be from ${y} to ${w}`)};s("width",n.width,30,400),s("height",n.height,30,400),s("rotation",n.rotation,0,360);let l=n.points===null;if(n.points!=null){if(o.length!==1)throw new d("invalid_operation","points can be changed only for one booth at a time");let u=Pt(n.points);if(!u.ok)throw new d("invalid_operation",u.message??"The booth outline is not a valid simple polygon")}let c=n.points!=null?n.points.map(u=>({x:u.x,y:u.y})):void 0;delete n.points;let f=te(n,"Booth"),g=Se(n,"Booth"),h=!1;for(let u of i){let m=JSON.stringify(u);Object.assign(u,n),f&&delete u.displayLabel,g&&delete u.displayType,l?delete u.points:c&&(u.points=c),JSON.stringify(u)!==m&&(h=!0)}return{floorId:r.floorId,changed:h,boothIds:o}}function Cr(t,e){let r=S(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(!o.length)throw new d("invalid_operation","At least one GA area id is required");let i=o.map(f=>r.objects.find(g=>g.type==="gaArea"&&g.id===f)),a=o.filter((f,g)=>!i[g]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one GA area change is required");if(n.label!==void 0){if(n.label=n.label.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","label can be changed only for one GA area at a time");if(!n.label||n.label.length>80)throw new d("invalid_operation","GA area labels must contain 1 to 80 characters")}if(n.categoryKey!==void 0&&F(t,n.categoryKey),n.capacity!==void 0&&(!Number.isInteger(n.capacity)||n.capacity<1||n.capacity>1e5))throw new d("invalid_operation","capacity must be an integer from 1 to 100000");if(n.cornerRadius!==void 0&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>2e3))throw new d("invalid_operation","cornerRadius must be from 0 to 2000");let s=te(n,"GA area"),l=Se(n,"GA area");if(n.capacity!==void 0)for(let f of i){if(f.inventorySegments!==void 0&&n.capacity<f.capacity)throw new d("invalid_operation",`Joined GA area "${f.label}" cannot be reduced below ${f.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:f.id,currentCapacity:f.capacity,requestedCapacity:n.capacity});if(f.inventorySegments!==void 0&&n.capacity>f.capacity&&ze(f,n.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 i){let g=JSON.stringify(f),h=n.capacity===void 0?f.inventorySegments:ze(f,n.capacity);Object.assign(f,n),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:o}}function Ye(t,e){if(e.length<3)return 0;let r=i=>E(i,e,void 0),o=0;for(let i of t)r(T(i))&&(i.type==="row"?o+=z(i).length:i.type==="table"?o+=se(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=W(i)));return o}function xr(t,e){let r=S(t,e.floorId);if(!e.objectIds.length)throw new d("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new d("invalid_operation","Chart object ids must be unique");let o=e.objectIds.map(s=>r.objects.find(l=>l.id===s)),i=e.objectIds.filter((s,l)=>!o[l]);if(i.length)throw new d("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=o,n=new Set(e.objectIds);for(let s=r.objects.length-1;s>=0;s--)n.has(r.objects[s].id)&&r.objects.splice(s,1);return{floorId:r.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,l)=>s+W(l),0),remainingObjectCount:r.objects.length}}function _r(t,e){let r=S(t,e.floorId),o=[...new Set(e.textIds)];if(!o.length)throw new d("invalid_operation","At least one text id is required");let i=o.map(c=>r.objects.find(f=>f.type==="text"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one text change is required");if(n.text!==void 0){if(n.text=n.text.normalize("NFKC").trim(),o.length!==1)throw new d("invalid_operation","content can be changed only for one text object at a time");if(!n.text||n.text.length>240)throw new d("invalid_operation","Text content must contain 1 to 240 characters")}if(n.fontSize!==void 0&&(!Number.isFinite(n.fontSize)||n.fontSize<8||n.fontSize>72))throw new d("invalid_operation","Text fontSize must be from 8 to 72");if(n.fontFamily!==void 0&&n.fontFamily!==null&&(n.fontFamily=n.fontFamily.normalize("NFKC").trim(),!n.fontFamily||n.fontFamily.length>120))throw new d("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(n.rotation!==void 0&&(!Number.isFinite(n.rotation)||n.rotation<0||n.rotation>360))throw new d("invalid_operation","Text rotation must be from 0 to 360");if(n.color!==void 0&&n.color!==null&&(n.color=N(n.color,"Text color")),n.bold!==void 0&&typeof n.bold!="boolean")throw new d("invalid_operation","Text bold must be a boolean");if(n.italic!==void 0&&typeof n.italic!="boolean")throw new d("invalid_operation","Text italic must be a boolean");if(n.width!==void 0&&n.width!==null&&(!Number.isFinite(n.width)||n.width<40||n.width>1200))throw new d("invalid_operation",`Text width must be from ${40} to ${1200}`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new d("invalid_operation","Text align must be left, center, or right");if(n.lineHeight!==void 0&&(!Number.isFinite(n.lineHeight)||n.lineHeight<.8||n.lineHeight>3))throw new d("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(n.letterSpacing!==void 0&&(!Number.isFinite(n.letterSpacing)||n.letterSpacing<-2||n.letterSpacing>20))throw new d("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(n.underline!==void 0&&typeof n.underline!="boolean")throw new d("invalid_operation","Text underline must be a boolean");if(n.opacity!==void 0&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation",`Text opacity must be from ${.1} to 1`);if(n.background!==void 0&&n.background!==null){n.background.color=N(n.background.color,"Text background color");let{padding:c=6,cornerRadius:f=4,opacity:g=.9}=n.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(n,c))&&i.some(c=>c.semanticKind==="icon"))throw new d("invalid_operation","Text layout fields cannot be applied to venue icons");if(n.iconKey!==void 0){if(!Ct(n.iconKey))throw new d("invalid_operation","iconKey must be a known venue-icon registry key");if(i.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 i){let f=JSON.stringify(c);n.iconKey!==void 0&&(c.iconKey=n.iconKey),n.text!==void 0&&(c.text=n.text),n.fontSize!==void 0&&(c.fontSize=n.fontSize),n.fontFamily===null?delete c.fontFamily:n.fontFamily!==void 0&&(c.fontFamily=n.fontFamily),n.rotation!==void 0&&(c.rotation=n.rotation),n.color===null?delete c.color:n.color!==void 0&&(c.color=n.color),n.bold!==void 0&&(n.bold?c.bold=!0:delete c.bold),n.italic!==void 0&&(n.italic?c.italic=!0:delete c.italic),n.width===null?delete c.width:n.width!==void 0&&(c.width=n.width),n.align!==void 0&&(n.align==="left"?delete c.align:c.align=n.align),n.lineHeight!==void 0&&(n.lineHeight===1.2?delete c.lineHeight:c.lineHeight=n.lineHeight),n.letterSpacing!==void 0&&(n.letterSpacing===0?delete c.letterSpacing:c.letterSpacing=n.letterSpacing),n.underline!==void 0&&(n.underline?c.underline=!0:delete c.underline),n.opacity!==void 0&&(n.opacity===1?delete c.opacity:c.opacity=n.opacity),n.background===null?delete c.background:n.background!==void 0&&(c.background=n.background),JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,textIds:o}}function Or(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(c=>r.objects.find(f=>f.type==="row"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i.slice().sort((c,f)=>c.origin.y-f.origin.y||c.origin.x-f.origin.x),s=yt(n.map(c=>({label:c.label})),e.options),l=!1;return n.forEach((c,f)=>{c.label!==s[f].label&&(l=!0),c.label=s[f].label}),{floorId:r.floorId,changed:l,rows:n.map(c=>({id:c.id,label:c.label}))}}function jr(t,e){let r=Et.find(c=>c.key===e.blockKey);if(!r)throw new d("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let o=S(t,e.floorId),i=new Set,a=r.build().map(c=>structuredClone(c));for(let c of a)c.id=P(t,c.type,e.idFactory,i),Dt(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 n=a.filter(c=>c.type==="row");if(n.length){let c=0;for(let f of o.objects){if(f.type!=="row")continue;let g=Lt(f.label);g!=null&&(c=Math.max(c,g+1))}for(let f of n)f.label=L(c++)}let s=new Set(o.objects.flatMap(c=>"label"in c&&c.label?[c.label]:[]));for(let c of a){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)}o.objects.push(...a);let l=null;if(r.sectionLabel&&e.wrapInSection!==!1){let c=Z(a);if(c){let f={type:"section",id:P(t,"sec",e.idFactory,i),label:r.sectionLabel,outline:c};o.objects.push(f),l=f.id}}return{floorId:o.floorId,blockKey:r.key,createdIds:[...a.map(c=>c.id),...l?[l]:[]],sectionId:l}}function On(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new d("invalid_operation","Exact row path points must be finite");let o=gt(e,97),i=o.slice(1).reduce((a,n,s)=>a+Math.hypot(n.x-o[s].x,n.y-o[s].y),0);if(!Number.isFinite(i)||i<1)throw new d("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function jn(t,e){let r=S(t,e.floorId),o=r.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!o)throw new d("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=On(e.path),a=z(o),n=structuredClone(o);n.path=i.path,n.origin={...i.path.start};let s=z(n),l=a.map((f,g)=>Math.hypot(f.x-s[g].x,f.y-s[g].y)),c=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:r.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:l.length?l.reduce((f,g)=>f+g,0)/l.length:0,maxSeatMovement:l.length?Math.max(...l):0,convertingFromParametric:!o.path,changed:c,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function Tr(t,e){let r=jn(t,e);if(!r.changed)return r;let i=S(t,r.floorId).objects.find(a=>a.type==="row"&&a.id===r.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,r}function An(t,e){let r=t.map((o,i)=>[...o,e[i]]);for(let o=0;o<3;o++){let i=o;for(let n=o+1;n<3;n++)Math.abs(r[n][o])>Math.abs(r[i][o])&&(i=n);if(Math.abs(r[i][o])<1e-9)return null;[r[o],r[i]]=[r[i],r[o]];let a=r[o][o];for(let n=o;n<4;n++)r[o][n]/=a;for(let n=0;n<3;n++){if(n===o)continue;let s=r[n][o];for(let l=o;l<4;l++)r[n][l]-=s*r[o][l]}}return[r[0][3],r[1][3],r[2][3]]}function Pn(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],r=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],n=i.x**2+i.y**2;for(let s=0;s<3;s++){r[s]+=a[s]*n;for(let l=0;l<3;l++)e[s][l]+=a[s]*a[l]}}let o=An(e,r);return o?{x:o[0],y:o[1]}:null}function Kt(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function Rn(t,e){let r=S(t,e.floorId),o=r.objects.find(u=>u.type==="section"&&u.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new d("invalid_operation","Section row-fit strength must be from 0 to 100");let a=M(t).find(u=>u.id===r.floorId),n=e.mode==="outline"?Pn(o.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new d("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=r.objects.filter(u=>u.type==="row"&&E(T(u),o.outline,o.holes)),l=s.filter(u=>!!u.path).map(u=>u.id),c=[],f=[],g=i/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-n.x,u.origin.y-n.y);if(m<=u.seatSpacing/2+1e-6){c.push(u.id);continue}let y=2*Math.asin(u.seatSpacing/(2*m))/q,w=z(u),_=Math.atan2(u.origin.x-n.x,u.origin.y-n.y)/q,p=(u.curve!==0?Math.sign(u.curve):w.length>1&&Math.sign(Kt(Math.atan2(w[1].x-n.x,w[1].y-n.y)/q-_))||1)*y*(u.seatCount-1);if(Math.abs(p)>320){c.push(u.id);continue}let x=-_,v=u.curve+(p-u.curve)*g,I=u.rotation+Kt(x-u.rotation)*g,A={...u,curve:v,rotation:I},U=z(A).map((V,$)=>Math.hypot(V.x-w[$].x,V.y-w[$].y));f.push({rowId:u.id,fromCurve:u.curve,targetCurve:p,resultCurve:v,fromRotation:u.rotation,resultRotation:I,rmsMovement:Math.sqrt(U.reduce((V,$)=>V+$**2,0)/U.length),maxMovement:Math.max(...U)})}let h=f.map(u=>u.rmsMovement);return{floorId:r.floorId,sectionId:o.id,mode:e.mode,fitCenter:{...n},strength:i,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=Rn(t,e),o=S(t,r.floorId),i=o.objects.find(n=>n.type==="section"&&n.id===r.sectionId),a=!1;for(let n of r.rows){let s=o.objects.find(l=>l.type==="row"&&l.id===n.rowId);(s.curve!==n.resultCurve||s.rotation!==n.resultRotation)&&(s.curve=n.resultCurve,s.rotation=n.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==r.strength&&(i.smoothing=r.strength,a=!0),{...r,changed:a}}function $t(t,e,r,o){let i=G(t,e,r),a=G(t,e,o),n=G(r,o,t),s=G(r,o,e);return i*a<-1e-9&&n*s<-1e-9}function Gt(t,e){return t.some((r,o)=>{let i=t[(o+1)%t.length];return e.some((a,n)=>$t(r,i,a,e[(n+1)%e.length]))})}function Fn(t){if(t.length<3||t.length>256||Math.abs(me(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)&&$t(t[e],t[(e+1)%t.length],t[r],t[(r+1)%t.length]))return!1;return!0}function Oe(t,e,r){let o=S(t,e),i=o.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===r);if(!i)throw new d("object_not_found",`Unknown polygon object id: ${r}`,{objectId:r});return{target:o,object:i,outer:i.type==="section"?i.outline:i.points}}function Ze(t,e){let{target:r,object:o,outer:i}=Oe(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Fn(a))throw new d("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(c=>!E(c,i,void 0)))throw new d("invalid_operation","Every opening corner must stay inside the outer boundary");if(Gt(a,i))throw new d("invalid_operation","Opening edges cannot cross the outer boundary");let n=o.holes??[],s=e.holeIndex??n.length;if(!Number.isInteger(s)||s<0||s>n.length||e.holeIndex!=null&&s>=n.length)throw new d("invalid_operation","Opening not found");for(let c=0;c<n.length;c++){if(c===e.holeIndex)continue;let f=n[c];if(Gt(a,f)||E(a[0],f,void 0)||E(f[0],a,void 0))throw new d("invalid_operation","Openings cannot overlap or contain one another")}let l=r.objects.filter(c=>c.id!==o.id&&c.type!=="section"&&E(T(c),a,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:l.map(c=>c.id),excludedInventoryUnits:Ye(r.objects.filter(c=>c.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Er(t,e){let r=Ze(t,e),{object:o}=Oe(t,r.floorId,r.objectId);return o.holes??=[],e.holeIndex==null?o.holes.push(structuredClone(e.points)):o.holes[e.holeIndex]=structuredClone(e.points),{...r,changed:!0}}function kn(t,e){let{target:r,object:o}=Oe(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(o.holes?.length??0))throw new d("invalid_operation","Opening not found");let i=o.holes[e.holeIndex],a=r.objects.filter(n=>n.id!==o.id&&n.type!=="section"&&E(T(n),i,void 0));return{floorId:r.floorId,objectId:o.id,objectType:o.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(n=>n.id),excludedInventoryUnits:Ye(r.objects.filter(n=>n.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Lr(t,e){let r=kn(t,e),{object:o}=Oe(t,r.floorId,r.objectId);return o.holes.splice(e.holeIndex,1),o.holes.length||delete o.holes,{...r,changed:!0}}function Mn(t){let e=Y(t);if(!e)throw new d("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return e}function zt(t,e){let r=[...new Set(e)];if(!r.length)throw new d("invalid_operation","At least one section id is required");let o=r.map(n=>t.find(s=>s.type==="section"&&s.id===n)),i=r.filter((n,s)=>!o[s]);if(i.length)throw new d("object_not_found",`Unknown section id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:i});let a=o;return{requested:r,sections:a,logicalSectionIds:[...new Set(a.map(n=>n.logicalSectionId??n.id))]}}function Tn(t,e){let r=S(t,e.floorId),o=zt(r.objects,e.sectionIds),i=ce(Ie(t,r.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),n=new Map(r.objects.map(g=>[g.id,g])),s=o.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),l=new Set;for(let g of s){let h=n.get(g);if(h)if(h.type==="row"||h.type==="table")for(let u of ve(h).keys())l.add(u);else(h.type==="booth"||h.type==="gaArea")&&l.add(h.categoryKey)}let c=o.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),f=o.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(h=>{let u=n.get(h);return u?.type==="row"||u?.type==="table"||u?.type==="booth"})===!0);return{floorId:r.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:c,...c&&l.size===1?{categoryKey:[...l][0]}:{},categoryMixed:c&&l.size!==1,viewApplicable:f}}function qr(t,e){F(t,e.categoryKey);let r=Tn(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 o=S(t,r.floorId),i=new Set(r.objectIds),a=!1,n=0;for(let s of o.objects){if(!i.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,a=!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,n++,a=!0,Object.keys(f).some(g=>g!=="index")?[f]:[]});l.length?s.overrides=l:delete s.overrides}return{...r,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:n}}function Hr(t,e){let r=S(t,e.floorId),o=zt(r.objects,e.sectionIds),{requested:i}=o,a=structuredClone(e.patch),n=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(u=>!n.has(u));if(s.length)throw new d("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new d("invalid_operation","At least one section metadata change is required");if(a.label!==void 0){if(a.label=a.label.normalize("NFKC").trim(),i.length!==1)throw new d("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new d("invalid_operation","Section labels must contain 1 to 80 characters")}if(a.displayLabel!==void 0&&a.displayLabel!==null){if(a.displayLabel=a.displayLabel.normalize("NFKC").trim(),i.length!==1)throw new d("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new d("invalid_operation","Section display labels must contain 1 to 80 characters")}if(a.entrance!==void 0&&a.entrance!==null&&(a.entrance=a.entrance.normalize("NFKC").trim(),a.entrance.length>40))throw new d("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Mn(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new d("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new d("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&Ce(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ne(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(u=>u.id===a.zone))throw new d("object_not_found",`Unknown chart zone: ${a.zone}`,{zoneId:a.zone});if(a.elevation!==void 0&&(!Number.isInteger(a.elevation)||a.elevation<0||a.elevation>3))throw new d("invalid_operation","Section elevation must be an integer from 0 to 3");if(a.height!==void 0&&a.height!==null&&(!Number.isFinite(a.height)||a.height<0||a.height>120))throw new d("invalid_operation","Section height must be a number from 0 to 120 metres");if(a.rake!==void 0&&a.rake!==null&&(!Number.isFinite(a.rake)||a.rake<0||a.rake>45))throw new d("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(a.surfaceKind!==void 0&&a.surfaceKind!==null&&a.surfaceKind!=="flat"&&a.surfaceKind!=="rakedRows")throw new d("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=N(a.color,"Section color"));let l=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,c=new Set(o.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 o.sections){let m=JSON.stringify(u);a.label!==void 0&&(u.label=a.label),a.labelPresentation===null?delete u.labelPresentation:a.labelPresentation!==void 0&&(u.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(u.elevation=a.elevation);let y=w=>{u.physical3dProvenance&&(delete u.physical3dProvenance[w],Object.keys(u.physical3dProvenance).length===0&&delete u.physical3dProvenance)};a.height===null?(delete u.height,y("height")):a.height!==void 0&&(u.height=a.height,u.physical3dProvenance={...u.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete u.rake,y("rake")):a.rake!==void 0&&(u.rake=a.rake,u.physical3dProvenance={...u.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete u.surfaceKind,y("surfaceKind")):a.surfaceKind!==void 0&&(u.surfaceKind=a.surfaceKind,u.physical3dProvenance={...u.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete u.color:a.color!==void 0&&(u.color=a.color),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}for(let u of f){let m=JSON.stringify(u),y=u.viewFromSeatUrl;if(a.displayLabel===null?delete u.displayLabel:a.displayLabel!==void 0&&(u.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete u.entrance:a.entrance!==void 0&&(u.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete u.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(u.viewFromSeatUrl=a.viewFromSeatUrl),!u.viewFromSeatUrl||a.viewFromSeatMeta===null?delete u.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?u.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&u.viewFromSeatUrl!==y&&delete u.viewFromSeatMeta,a.labelStyle!==void 0){let w=xe(u.labelPresentation,a.labelStyle);w?u.labelPresentation=w:delete u.labelPresentation}a.zone===null?delete u.zone:a.zone!==void 0&&(u.zone=a.zone),JSON.stringify(u)!==m&&(h=!0,g.add(u.id))}return{floorId:r.floorId,changed:h,sectionIds:i,affectedSectionIds:[...g]}}function Nn(t,e){let r=S(t,e.floorId),o=r.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(o.outlinePath)throw new d("invalid_operation",`Section ${o.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:o.id,representation:"exact-path"});if(!o.geometry)throw new d("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=r.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&E(T(a),o.outline,o.holes));return{floorId:r.floorId,sectionId:o.id,sectionLabel:o.label,source:{representation:"generated-polygon",generator:structuredClone(o.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:o.outline.length,holeCount:o.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,n)=>a+W(n),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function Vr(t,e){let r=Nn(t,e),i=S(t,r.floorId).objects.find(a=>a.type==="section"&&a.id===r.sectionId);return delete i.geometry,{...r,changed:!0}}function En(t,e){let r=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,n=!0;if(e.kind==="translate"){if(!r(e.dx,e.dy))throw new d("invalid_operation","Section translation must be finite");n=e.dx!==0||e.dy!==0,o=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!r(e.factor)||e.factor<=0||e.factor>100)throw new d("invalid_operation","Section scale factor must be finite and greater than 0");n=e.factor!==1,i=e.factor;let s=T(t);o=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");n=(e.degrees%360+360)%360!==0;let l=e.degrees*Math.PI/180,c=Math.cos(l),f=Math.sin(l),g=T(t);o=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");a=!0,o=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return n&&(t.outline=t.outline.map(o),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(o)),t.outlinePath&&(t.outlinePath=pt(t.outlinePath,o,i,a)),t.holes&&(t.holes=t.holes.map(s=>s.map(o)))),{changed:n,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function Xr(t,e){let r=S(t,e.floorId),o=r.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:r.floorId,...En(o,e.transform)}}function Yr(t,e){let r=S(t,e.floorId),o=r.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!o)throw new d("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!ht(i))throw new d("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ge(i),n=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return n&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:r.floorId,sectionId:o.id,changed:n,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function Ln(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function Zr(t,e){return Dn(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function Dn(t,e){let r=S(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new d("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new d("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(e.sectionIds)],i=new Set,a=new Map,n=!1;try{for(let s of o){let l=r.objects.find(b=>b.type==="section"&&b.id===s);if(!l||!Ln(l))continue;let f=structuredClone(l);a.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?mt(h,{cornerSmoothing:u,...w?{edgeCurvature:y}:{}}):null;_?(l.sourceOutline=h,l.outlinePath=_,l.outline=Ge(_),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&&(n=!0,i.add(l.id))}}catch(s){for(let{section:l,snapshot:c}of a.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:n,sectionIds:o,affectedSectionIds:[...i]}}var Kn=new Set(["companion","child","senior","student","membership","custom"]);function ue(t){if(!t.length)throw new d("invalid_operation","A chart must have at least one category");let e=new Set,r=new Map,o=structuredClone(t);for(let i of o){let a=i.key.trim(),n=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new d("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!n||n.length>80)throw new d("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=n.toLocaleLowerCase("en"),l=r.get(s);if(l)throw new d("duplicate_category_label",`Categories ${l} and ${a} share the same label`,{categoryKeys:[l,a],label:n});if(r.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new d("invalid_operation",`Category ${a} must use a six-digit hex color`,{categoryKey:a});if(i.price!=null&&(!Number.isFinite(i.price)||i.price<0||i.price>1e6))throw new d("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!de(i.seatGlyph))throw new d("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new d("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let c=new Set,f=new Set;for(let g of i.tiers){let h=g.id.trim(),u=g.name.normalize("NFKC").trim(),m=u.toLocaleLowerCase("en");if(!h||h.length>160||c.has(h))throw new d("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!u||u.length>80||f.has(m))throw new d("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:u});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new d("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(g.restriction!=null&&!Kn.has(g.restriction))throw new d("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new d("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new d("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(g.applicability!=null){let y=g.applicability.seatLabels?.map(_=>_.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(_=>!be.some(b=>b.key===_))||new Set(w).size!==w.length))throw new d("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...y?{seatLabels:y}:{},...w?{accessibility:[...w]}:{}},!g.applicability.seatLabels&&!g.applicability.accessibility&&delete g.applicability}if(g.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(g.evidence.provenance)||typeof g.evidence.sourceDescription!="string")throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new d("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}c.add(h),f.add(m)}}}return o}function Gn(t,e){let r=new Set,o=structuredClone(t.categories);for(let n of e.updates){if(r.has(n.categoryKey))throw new d("invalid_operation",`Category ${n.categoryKey} may be updated only once`);r.add(n.categoryKey);let s=o.find(g=>g.key===n.categoryKey);if(!s)throw new d("category_not_found",`Unknown chart category: ${n.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:n.categoryKey});let l=structuredClone(n.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 i=ue(o),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...r],categories:t.categories}}function ii(t,e){let r=e.categoryKeys.map(l=>l.trim()),o=t.categories.map(l=>l.key);if(r.length!==o.length||new Set(r).size!==r.length)throw new d("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:r,expectedCategoryKeys:o});let i=new Set(o),a=o.filter(l=>!r.includes(l)),n=r.filter(l=>!i.has(l));if(a.length||n.length)throw new d(n.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:r,missingCategoryKeys:a,unknownCategoryKeys:n});if(r.every((l,c)=>l===o[c]))return{changed:!1,categoryKeys:o,categories:t.categories};let s=new Map(t.categories.map(l=>[l.key,l]));return t.categories=ue(r.map(l=>structuredClone(s.get(l)))),{changed:!0,categoryKeys:r,categories:t.categories}}var Ut=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Bt(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let r=e[1];return r.length===3&&(r=r.split("").map(o=>o+o).join("")),[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]}function $n(t,e){let r=Bt(t),o=Bt(e);return!r||!o?1/0:(r[0]-o[0])**2+(r[1]-o[1])**2+(r[2]-o[2])**2}var zn=3600;function Bn(t,e,r=Ut){return r.find(i=>t.every(a=>$n(i,a)>=zn))??r[e%r.length]}function ai(t,e){let r=e?.palette??Ut;if(!t.categories.length)return{changed:[],categories:t.categories};let o=new Map(t.categories.map(n=>[n.key,n.color.toLowerCase()])),i=t.categories.map((n,s)=>({categoryKey:n.key,patch:{color:r[s%r.length]}}));return Gn(t,{updates:i}),{changed:t.categories.map(n=>({key:n.key,from:o.get(n.key),to:n.color})).filter(n=>n.from!==n.to),categories:t.categories}}function si(t,e){let r=e.color.trim().toLowerCase(),o=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(r))throw new d("invalid_operation","Sampled category color must be a six-digit hex color");if(!o||o.length>240)throw new d("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(l=>l.key===e.categoryKey);if(!a)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=r,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let n=ue(i),s=JSON.stringify(n)!==JSON.stringify(t.categories);return s&&(t.categories=n),{changed:s,category:t.categories.find(l=>l.key===e.categoryKey),categories:t.categories}}function Un(t,e){let r=new Set(t.categories.map(n=>n.key)),o="";for(let n=0;n<100;n++){let l=e.idFactory("cat").trim();if(l&&!r.has(l)){o=l;break}}if(!o)throw new d("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(n=>({...n,id:n.id.trim(),name:n.name.normalize("NFKC").trim()}))},a=ue([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(n=>n.key===o),categories:a}}var Jn=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],qn={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function Hn(t,e){let r=qn[t];return!r||!e.includes(r)?e:[r,...e.filter(o=>o!==r)]}var Vn=26;function Xn(t,e,r){let o=(1-Math.abs(2*r-1))*e,i=(t%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[n,s,l]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],c=r-o/2,f=g=>Math.round((g+c)*255).toString(16).padStart(2,"0");return`#${f(n)}${f(s)}${f(l)}`}function Yn(t,e,r){let o=n=>t.every(s=>{let l=Rt(n,s);return l==null||l>=Vn}),i=n=>{let s=Be(n,"#12151d"),l=Be(n,"#ffffff");return(s??0)>=3||(l??0)>=3},a=e.find(n=>o(n)&&i(n));if(a)return a;for(let n=0;n<360;n+=12)for(let s of[.52,.44,.6]){let l=Xn(n,.62,s);if(o(l)&&i(l))return l}return r}function Zn(t,e){let r=we.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${r}`}function Wn(t){let e=new Map;for(let r of M(t))for(let o of r.objects){let i=we.find(n=>n.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let n of ve(o).keys())a.add(n);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let n of a){let s=e.get(n)??new Set;s.add(i.objectType),e.set(n,s)}}return e}function Qn(t,e){let r=new Set(t.categories.map(i=>i.label.toLowerCase())),o=e;for(let i=2;r.has(o.toLowerCase());i+=1)o=`${e} ${i}`;return o}function eo(t,e,r){let o=Wn(t),i=c=>{let f=o.get(c);return!f||f.size===0||f.size===1&&f.has(r)},a=t.categories.find(c=>c.key===e);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let c=t.categories.find(f=>{let g=o.get(f.key);return g?.size===1&&g.has(r)});if(c)return{kind:"existing",categoryKey:c.key,label:c.label}}let n=we.find(c=>c.objectType===r),s=a?Zn(a.label,r):r==="gaArea"?"General Admission":n.creationWord,l=t.categories.find(c=>c.label.toLowerCase()===s.toLowerCase()&&i(c.key));return l?{kind:"existing",categoryKey:l.key,label:l.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:Qn(t,s)}}function li(t,e,r,o){let i=eo(t,e,r);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?t.categories.find(n=>n.key===i.baseCategoryKey):void 0;return to(t,r,a,i.label,o)}function to(t,e,r,o,i){let a=i.palette??Jn,n=t.categories.map(f=>f.color),s=i.suggestColor?.(n.map(f=>f.toLowerCase()))??Bn(n,t.categories.length),l=Yn(n,Hn(e,a),s),c=Un(t,{label:o,color:l,...r?.price!==void 0?{price:r.price}:{},...r?.tiers?.length?{tiers:r.tiers}:{},idFactory:i.idFactory});return t.categories=c.categories,c.category.key}function no(t,e){let r=new Set;for(let o of M(t))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===e&&r.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&r.add(i.id);return[...r]}function ci(t,e){let r=t.categories.find(a=>a.key===e.categoryKey);if(!r)throw new d("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new d("invalid_operation","A chart must retain at least one category");let o=no(t,e.categoryKey);if(o.length)throw new d("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:o});if(r.referenceCategorySource)throw new d("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=ue(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var oo=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Jt=.7,qt=1.6,ro=["seat","deck","shell","fascia"];function hi(t,e){let r=e.patch;if(!Object.keys(r).length)throw new d("invalid_operation","At least one theme field is required");let o=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of oo){let n=r[a];n===null?delete i[a]:n!==void 0&&(i[a]=N(n,`Theme ${a}`))}if(r.fontFamily===null)delete i.fontFamily;else if(r.fontFamily!==void 0){let a=r.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new d("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(r.seatScale===null)delete i.seatScale;else if(r.seatScale!==void 0){if(!Number.isFinite(r.seatScale)||r.seatScale<Jt||r.seatScale>qt)throw new d("invalid_operation",`Theme seatScale must be from ${Jt} to ${qt}`);i.seatScale=r.seatScale}if(r.logoUrl===null)delete i.logoUrl;else if(r.logoUrl!==void 0){let a=Y(r.logoUrl);if(!a)throw new d("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster image reference");i.logoUrl=a}if(r.brandName===null)delete i.brandName;else if(r.brandName!==void 0){let a=r.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new d("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}if(r.hideBadge===null||r.hideBadge===!1?delete i.hideBadge:r.hideBadge===!0&&(i.hideBadge=!0),r.venue3d===null)delete i.venue3d;else if(r.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of ro){let l=r.venue3d[s];l===null?delete a[s]:l!==void 0&&(a[s]=N(l,`3D venue ${s}`))}let n=r.venue3d.roughness;if(n===null)delete a.roughness;else if(n!==void 0){if(!Number.isFinite(n)||n<0||n>1)throw new d("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=n}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==o,theme:t.theme??null}}function bi(t,e){let r=e.url===null?null:Y(e.url);if(e.url!==null&&!r)throw new d("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=r??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new d("invalid_operation",`Unknown floor: ${e.floorId}`);let l=(s.viewFromSeatUrl??void 0)===o,c=o?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=o,s.viewFromSeatMeta=c,{changed:f,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===o,a=o?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,n=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=o,t.viewFromSeatMeta=a,{changed:n,scope:"venue",url:t.viewFromSeatUrl??null}}function pi(t,e){let r=Ie(t,e.floorId),o=wt(r),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-e.height/2}:i==="left"?{x:o.x-a-e.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+e.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+e.height/2}}function je(t,e){F(t,e.categoryKey);let r=(...f)=>f.every(Number.isFinite);if(!r(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new d("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new d("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=e.endAngle-e.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new d("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new d("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new d("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,n=e.skewDegrees??0;if(!r(a,n)||Math.abs(a)>120||Math.abs(n)>180)throw new d("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!r(s.left,s.center,s.right)||Object.values(s).some(f=>f<0||f>200))throw new d("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let c=S(t,e.floorId).objects.filter(f=>f.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:n,aisleGaps:s,rowLabelStart:e.rowLabelStart??c,seatLabelStart:e.seatLabelStart??1}}function io(t,e,r){let o=r*q;return{x:t.x+e*Math.sin(o),y:t.y+e*Math.cos(o)}}function ao(t,e,r,o){let i=Math.abs(o-r)*q,a=[["left",.25],["center",.5],["right",.75]].flatMap(([c,f])=>{let g=t.aisleGaps[c];if(!g)return[];let h=g/e/i/2;return[[Math.max(0,f-h),Math.min(1,f+h)]]}).sort((c,f)=>c[0]-f[0]),n=[];for(let c of a){let f=n[n.length-1];f&&c[0]<=f[1]?f[1]=Math.max(f[1],c[1]):n.push([...c])}let s=[],l=0;for(let c of n)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*i*(f-c)>=t.seatPitch*.75)}function so(t,e){let r=t.length*2;if(e<r)throw new d("invalid_operation",`Fixed seat count must be at least ${r} for ${t.length} aisle-separated row segments`);let o=e-r,i=t.reduce((l,c)=>l+c,0),a=t.map(l=>o*l/i),n=a.map(l=>2+Math.floor(l)),s=e-n.reduce((l,c)=>l+c,0);return a.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&&n[l]++}),n}function Ae(t,e,r){let o=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),n=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,l=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,c=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;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 ${i+1} below a 5\xB0 sweep`);let f=ao(t,n,l,c);if(!f.length)throw new d("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(f=f.slice().reverse());let g=f.map(([m,y])=>n*Math.abs(c-l)*q*(y-m)),h=t.fit==="fixed-count"?so(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 x=Math.abs(b-_)*q/(p-1),v=2*n*Math.sin(x/2),I={type:"row",id:r(i,w),label:L(t.rowLabelStart+i),origin:io(t.center,n,_),rotation:-_,curve:b-_,seatCount:p,seatSpacing:v,categoryKey:t.categoryKey,seatLabelStart:u,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:w}};o.push(I),u+=p})}return o}function Ht(t,e){let r=je(t,e),o=S(t,e.floorId),i=Ae(r,"preview-arc-fan",(l,c)=>`preview-fan-${l}-${c}`),a=i.map(l=>l.seatSpacing),n=Math.max(...a.map(l=>Math.abs(l-r.seatPitch))),s=[];return n>r.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${n.toFixed(1)} chart units`),i.length>r.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:r.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((l,c)=>l+c.seatCount,0),innerRadius:r.innerRadius,outerRadius:r.innerRadius+(r.rowCount-1)*r.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:n,aisleCount:Object.values(r.aisleGaps).filter(l=>l>0).length,warnings:s}}function vi(t,e){let r=je(t,e),o=S(t,e.floorId),i=new Set,a=P(t,"fan",e.idFactory,i),n=Ae(r,a,()=>P(t,"r",e.idFactory,i)),s=Ht(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=Z(n);g&&(l=P(t,"sec",e.idFactory,i),f={type:"section",id:l,label:c,outline:g,arcFanGroupId:a})}return o.objects.push(...n,...f?[f]:[]),{floorId:o.floorId,rowIds:n.map(g=>g.id),sectionId:l,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function lo(t,e){let r=S(t,e.floorId),o=r.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!o.length)throw new d("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=o[0].arcFanGeneration,a=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(o.some(g=>a(g)!==a(o[0])))throw new d("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let n=r.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:r.floorId,center:{...i.center},innerRadius:i.innerRadius,rowCount:i.rowCount,rowGap:i.rowGap,startAngle:i.startAngle,endAngle:i.endAngle,seatPitch:i.seatPitch,fit:i.fit,seatsPerRow:i.seatsPerRow,facing:i.facing,taperDegrees:i.taperDegrees,skewDegrees:i.skewDegrees,aisleGaps:{...i.aisleGaps},categoryKey:o[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:n?.label},l=je(t,s),c=new Set(Ae(l,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),f=new Set(o.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(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 Ii(t,e){lo(t,{floorId:e.floorId,groupId:e.groupId});let r=je(t,e),o=S(t,e.floorId),i=o.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),a=o.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),n=new Map(i.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,l=Ae(r,e.groupId,(y,w)=>n.get(`${y}:${w}`)??P(t,"r",e.idFactory,s)),c=Ht(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=Z(l);y&&(g={type:"section",id:a?.id??P(t,"sec",e.idFactory,s),label:f,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...i.map(y=>y.id),...a?[a.id]:[]]),u=Math.min(...o.objects.map((y,w)=>h.has(y.id)?w:1/0)),m=o.objects.filter(y=>!h.has(y.id));return m.splice(Number.isFinite(u)?u:m.length,0,...l,...g?[g]:[]),o.objects.splice(0,o.objects.length,...m),{floorId:o.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 co(t){let e=new Set(J(t).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),r=0;return()=>{for(;e.has(L(r));)r+=1;let o=L(r);return e.add(o),r+=1,o}}function Vt(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 ji(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new d("invalid_operation","seatsPerRow must be an integer from 1 to 300");let r=e.rowGap??28,o=e.seatSpacing??24;if(!Number.isFinite(r)||r<=0||!Number.isFinite(o)||o<=0)throw new d("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new d("invalid_operation","rotation must be a finite number of degrees");let i=S(t,e.floorId),a=new Set,n=co(t),s=Xe(e.rotation??0),l=e.curve??0,c=e.style,f=c?P(t,"rowblock",e.idFactory,a):void 0,g=c?Vt({style:c,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:r,seatSpacing:o,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?o/2:0,x={type:"row",id:P(t,"r",e.idFactory,a),label:n(),origin:{x:e.origin.x+u.x*b*r+h.x*p,y:e.origin.y+u.y*b*r+h.y*p},rotation:s,curve:l,seatCount:e.seatsPerRow,seatSpacing:o,categoryKey:e.categoryKey};return c&&f&&g&&(x.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:o,curve:l,signature:g}),x});i.objects.push(...m);let y=null,w=e.sectionLabel?.trim();if(w){let _=Z(m);if(_){let b={type:"section",id:P(t,"sec",e.idFactory,a),label:w,outline:_};i.objects.push(b),y=b.id}}return{floorId:i.floorId,rowIds:m.map(_=>_.id),sectionId:y,createdIds:[...m.map(_=>_.id),...y?[y]:[]]}}function Xt(t,e){let r=new Set(J(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;r.has(`${e}${o}`);)o+=1;let i=`${e}${o}`;return r.add(i),o+=1,i}}function fo(t,e){let r=new Set(J(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!r.has(e))return e;let o=2;for(;r.has(`${e} ${o}`);)o+=1;return`${e} ${o}`}var uo=456;function go(t){let e=Math.sqrt(Math.max(1,t)*uo);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function Ai(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=S(t,e.floorId),o=new Set,{width:i,height:a}=go(e.capacity),n=fo(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:P(t,"ga",e.idFactory,o),label:n,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return r.objects.push(s),{floorId:r.floorId,gaAreaId:s.id,label:n,createdIds:[s.id]}}function Pi(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new d("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new d("invalid_operation","seatsPerTable must be an integer from 1 to 20");let r=e.gapX??155,o=e.gapY??150;if(!Number.isFinite(r)||r<80||!Number.isFinite(o)||o<80)throw new d("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Table array center must be finite");let i=S(t,e.floorId),a=new Set,n=Xt(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:P(t,"t",e.idFactory,a),label:n(),center:{x:e.center.x+(c-(e.tableColumns-1)/2)*r,y:e.center.y+(l-(e.tableRows-1)/2)*o},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Ri(t,e){if(F(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new d("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let r=e.gapX??88,o=e.gapY??82;if(!Number.isFinite(r)||r<62||!Number.isFinite(o)||o<52)throw new d("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new d("invalid_operation","Booth array center must be finite");let i=S(t,e.floorId),a=new Set,n=Xt(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:P(t,"booth",e.idFactory,a),label:n(),center:{x:e.center.x+(c-(e.boothColumns-1)/2)*r,y:e.center.y+(l-(e.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(l=>l.id),createdIds:s.map(l=>l.id)}}function Fi(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2||o.length>64)throw new d("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==o.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(h=>h.segmentedRow);if(s.length)throw new d("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let l=(e.displayLabel??n[0].displayLabel??n[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=n[0];return n.forEach((h,u)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:f,componentIndex:u,componentCount:n.length,boundaryBefore:u===0?"start":e.boundaries[u-1],displayLabel: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:o,changed:!0}}function ki(t,e){let r=S(t,e.floorId),o=e.groupId?r.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):r.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??o?.segmentedRow?.groupId;if(!i)throw new d("object_not_found","The segmented row does not exist on the selected floor");let a=r.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new d("object_not_found","The segmented row does not exist on the selected floor");let n=a.sort((s,l)=>s.segmentedRow.componentIndex-l.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:r.floorId,groupId:i,rowIds:n,changed:!0}}function Mi(t,e){let r=S(t,e.floorId),o=r.objects.filter(n=>n.type==="row"&&n.segmentedRow?.groupId===e.groupId).sort((n,s)=>n.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(o.length<2)throw new d("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==o.length-1||e.boundaries.some(n=>n!=="continuous"&&n!=="break")))throw new d("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new d("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(o.map(n=>n.segmentedRow));return o.forEach((n,s)=>{let l=n.segmentedRow,c=l.viewFromSeatUrl;i!==void 0&&(l.displayLabel=i),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:o.map(n=>n.id),changed:JSON.stringify(o.map(n=>n.segmentedRow))!==a}}function Ti(t,e){let r=S(t,e.floorId),o=r.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,D)=>O.rowBlockGeneration.rowIndex-D.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((O,D)=>{let R=O.rowBlockGeneration;return R.kind!=="row-block-v1"||R.rowIndex!==D||R.signature!==i.signature||JSON.stringify(R)!==JSON.stringify({...i,rowIndex:D})}))throw new d("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(o),n=e.style??i.style,s=e.rowCount??i.rowCount,l=e.seatsPerRow??i.seatsPerRow,c=e.rowGap??i.rowGap,f=e.seatSpacing??i.seatSpacing,g=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?Xe(e.rotation??i.rotation):e.rotation??i.rotation,u=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new d("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(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=Vt({style:n,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(o.map(O=>[O.rowBlockGeneration.rowIndex,O])),b=new Set,p=new Set(r.objects.filter(O=>O.type==="row").filter(O=>!o.includes(O)).map(O=>O.label)),x=r.objects.filter(O=>O.type==="row").length,v=()=>{for(;p.has(L(x));)x+=1;let O=L(x);return p.add(O),x+=1,O},I=[],A=[];for(let O=0;O<s;O+=1){let D=n==="intertwined"&&O%2===1?f/2:0,R=_.get(O);R||(R={type:"row",id:P(t,"r",e.idFactory,b),label:v(),origin:{...u},rotation:h,curve:g,seatCount:l,seatSpacing:f,categoryKey:o[0].categoryKey},A.push(R.id)),R.origin={x:u.x+w.x*O*c+y.x*D,y:u.y+w.y*O*c+y.y*D},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(Ee=>Ee.index<l),R.overrides.length||delete R.overrides),R.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:n,rowIndex:O,rowCount:s,seatsPerRow:l,origin:{...u},rotation:h,rowGap:c,seatSpacing:f,curve:g,signature:m},I.push(R)}let H=o.slice(s).map(O=>O.id),U=Math.min(...o.map(O=>r.objects.indexOf(O))),V=new Set(o.map(O=>O.id)),$=r.objects.filter(O=>!V.has(O.id));return $.splice(U,0,...I),r.objects.splice(0,r.objects.length,...$),{floorId:r.floorId,groupId:e.groupId,rowIds:I.map(O=>O.id),createdRowIds:A,removedRowIds:H,changed:a!==JSON.stringify(I)||A.length>0||H.length>0}}var ho=300,bo=40;function po(t){let e=new Set(J(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),r=0,o=()=>{for(;e.has(L(r));)r+=1;let i=L(r);return r+=1,i};return i=>{let a=i.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,bo).trim(),n=0;return()=>{for(;a&&n<4096;n+=1){let l=`${a}-${L(n)}`;if(!e.has(l))return e.add(l),n+=1,l}let s=o();return e.add(s),s}}}function mo(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 yo(t,e,r,o,i){let a=t.sectionId?e.find(l=>l.type==="section"&&l.id===t.sectionId):void 0;if(a){let l=mo(e,r).filter(c=>E(T(c),a.outline,a.holes));if(l.length)return{skip:{sectionId:a.id,name:t.name,reason:"section_not_empty",objectIds:l.map(c=>c.id)},rows:[],seats:0}}let n=[],s=0;for(let l of t.rows){let c=Math.min(ho,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):o>0?o:24;if(!Number.isFinite(u)||u<=0)continue;let m=h>0?Math.atan2(g,f)*180/Math.PI:0;n.push({label:i(),origin:{x:l.start.x,y:l.start.y},rotation:m,seatCount:c,seatSpacing:u}),s+=c}return{skip:null,rows:n,seats:s}}function Ki(t,e,r){F(t,r.categoryKey);let o=S(t,r.floorId),i=e.assetId,a=[],n=o.objects.filter(u=>u.type==="row"&&u.referenceScan?.assetId===i?(a.push(u.id),!1):!0);o.objects.splice(0,o.objects.length,...n);let s=[],l=[],c=[],f=new Set,g=0,h=po(t);for(let u of e.sections){let m=yo(u,o.objects,i,e.seatPitch,h(u.name));if(m.skip){l.push(m.skip);continue}let y=m.rows.map(w=>({type:"row",id:P(t,"r",r.idFactory,f),referenceScan:{assetId:i},label:w.label,origin:w.origin,rotation:w.rotation,curve:0,seatCount:w.seatCount,seatSpacing:w.seatSpacing,categoryKey:r.categoryKey}));o.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:o.floorId,assetId:i,createdRowIds:c,removedRowIds:a,totalSeats:g,perSection:s,skipped:l}}function Yt(t,e){let r=S(t,e.floorId),o=[...new Set(e.objectIds)];if(!o.length)throw new d("invalid_operation","Select at least one table or booth to repeat");let i=o.map(u=>r.objects.find(m=>(m.type==="table"||m.type==="booth")&&m.id===u)),a=o.filter((u,m)=>!i[m]);if(a.length)throw new d("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:a});let n=i[0].type;if(i.some(u=>u.type!==n))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=o.length*(s-1);if(l>5e3)throw new d("invalid_operation","A grid array can add at most 5000 objects");let c=i.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>ee)throw new d("invalid_operation",`Grid inventory would exceed the ${ee} unit event limit`);return{target:r,sources:i,preview:{floorId:r.floorId,kind:n,sourceIds:o,sourceCount:o.length,cells:s,createdCount:l,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:i.filter(u=>!!u.referenceInventorySource).length*(s-1)}}}function Bi(t,e){return Yt(t,e).preview}function Ui(t,e){let{target:r,sources:o,preview:i}=Yt(t,e),a=new Set,n=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(;n.has(m);)m=u(++h);return n.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 o){let u=structuredClone(h);u.id=P(t,u.type,e.idFactory,a),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),{...i,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 vo=new Set(be.map(t=>t.key));function Pe(t){return`${t.rowId}:${t.index}`}function Yi(t){let e=t.lastIndexOf(":"),r=e>0?t.slice(0,e):"",o=e>0?Number(t.slice(e+1)):Number.NaN;if(!r||!Number.isInteger(o)||o<0)throw new d("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:r,index:o}}function Io(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,de(t.glyph)||delete t.glyph,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 So(t){return Object.keys(t).every(e=>e==="index")}function Zt(t,e,r){if(!r.length)throw new d("invalid_operation","At least one seat is required");let o=S(t,e),i=[],a=new Set,n=new Map;for(let s of r){let l=Pe(s);if(a.has(l))continue;a.add(l);let c=o.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});i.push({rowId:s.rowId,index:s.index}),n.set(c.id,c)}return{floorId:o.floorId,refs:i,owners:n}}function Wt(t,e){let r=Zt(t,e.floorId,e.seats),o=Object.keys(e.patch);if(!o.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new d("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new d("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new d("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(r.refs.length>1&&e.patch.label!=null)throw new d("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(r.refs.length>1&&e.patch.displayLabel!=null)throw new d("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&F(t,e.patch.categoryKey),e.patch.glyph!=null&&!de(e.patch.glyph))throw new d("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(n=>!vo.has(n));if(a.length)throw new d("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new d("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of r.refs){let n=r.owners.get(a.rowId)?.overrides?.find(c=>c.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??n?.wheelchairSpaceType,l=e.patch.skip===null?!1:e.patch.skip??n?.skip??!1;if(s&&l)throw new d("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:Pe(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new d("invalid_operation","Commercial note supports at most 160 characters");if(e.patch.viewFromSeatUrl!=null){let a=Y(e.patch.viewFromSeatUrl);if(!a)throw new d("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");e.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let n=e.patch[a];if(n!=null&&!Number.isFinite(n))throw new d("invalid_operation",`${a} must be finite`,{[a]:n})}e.patch.labelStyle!=null&&ne(e.patch.labelStyle,"Seat");let i=!1;return r.refs.forEach((a,n)=>{let s=r.owners.get(a.rowId),l=JSON.stringify(s.overrides??[]),c=s.overrides??(s.overrides=[]),f=c.find(h=>h.index===a.index);f||(f={index:a.index},c.push(f));let g=f.viewFromSeatUrl;for(let h of o){let u=e.patch[h];if(h==="wheelchairSpaceType"&&u==null)delete f.wheelchairSpaceType,f.accessibility&&(f.accessibility=f.accessibility.filter(m=>m!=="wheelchair"),f.accessibility.length||delete f.accessibility),delete f.accessible;else if(u==null)delete f[h];else if(h==="accessibility")f.accessibility=[...new Set(u)],delete f.accessible;else if(h==="commercial")f.commercial={...f.commercial,...u};else if(h==="labelStyle"){let m=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}${n+1}`),e.displayLabelPrefix!==void 0&&(f.displayLabel=`${e.displayLabelPrefix}${n+1}`),Io(f),So(f)&&(s.overrides=c.filter(h=>h!==f)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==l&&(i=!0)}),{floorId:r.floorId,changed:i,seatIds:r.refs.map(Pe)}}function Zi(t,e){let r=Zt(t,e.floorId,e.seats),o=!1;for(let[i,a]of r.owners){if(!a.overrides?.length)continue;let n=new Set(r.refs.filter(l=>l.rowId===i).map(l=>l.index)),s=a.overrides.filter(l=>!n.has(l.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:r.floorId,changed:o,seatIds:r.refs.map(Pe)}}function ta(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)],i=o.map(b=>r.objects.find(p=>p.type==="row"&&p.id===b)),a=o.filter((b,p)=>!i[p]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&F(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new d("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let b=e.patch.seatNumbering,p=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(b.scheme!==void 0&&!p.includes(b.scheme))throw new d("invalid_operation",`Unknown seat numbering scheme: ${b.scheme}. Expected one of ${p.join(", ")}.`);if(b.prefix!==void 0&&(typeof b.prefix!="string"||b.prefix.length>8))throw new d("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(b.endAt!==void 0&&b.endAt!==null&&(!Number.isInteger(b.endAt)||b.endAt<0||b.endAt>9999))throw new d("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:n,labelPosition:s,labelRotation:l,labelStyleShape:c,displayLabel:f,displayType:g,...h}=e.patch,u=f===void 0?{}:{displayLabel:f},m=te(u,"Row"),y=g===void 0?void 0:Je(g,"Row");if(n!==void 0&&ne(n,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new d("invalid_operation","Row labelPosition must be one of start, end, both, none");if(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&&Ce(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 i){let p=JSON.stringify(b),x=w(b),v=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?T(b):null;if(Object.assign(b,structuredClone(h)),b.overrides&&e.patch.seatCount!==void 0&&(b.overrides=b.overrides.filter(I=>I.index<b.seatCount),b.overrides.length||(b.overrides=void 0)),v){let I=T(b);b.origin={x:b.origin.x+v.x-I.x,y:b.origin.y+v.y-I.y}}if(JSON.stringify(b)!==p&&(_=!0),w(b)!==x&&(delete b.arcFanGeneration,delete b.rowBlockGeneration),n!==void 0){let I=JSON.stringify(b.labelPresentation??null),A=xe(b.labelPresentation,n);A?b.labelPresentation=A:delete b.labelPresentation,JSON.stringify(b.labelPresentation??null)!==I&&(_=!0)}if(s!==void 0){let I=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)!==I&&(_=!0)}if(l!==void 0||c!==void 0){let I=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)!==I&&(_=!0)}if(y!==void 0){let I=b.displayType;y?b.displayType=y:delete b.displayType,b.displayType!==I&&(_=!0)}if(f!==void 0){let I=b.displayLabel;m?delete b.displayLabel:b.displayLabel=u.displayLabel,b.displayLabel!==I&&(_=!0)}}return{floorId:r.floorId,changed:_,rowIds:o}}var Co=3;function Re(t){return(t%360+360)%360}function xo(t){let e=t.rotation*B;return{x:Math.cos(e),y:Math.sin(e)}}function _o(t,e){let r=Math.abs(Re(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 Qt(t){let e=0,r=0;for(let i of t){let a=2*i.rotation*B;e+=Math.cos(a),r+=Math.sin(a)}let o=(e===0&&r===0?0:Math.atan2(r,e))/2;return{x:Math.cos(o),y:Math.sin(o)}}function Oo(t,e,r){if(t.origin={x:t.origin.x+e,y:t.origin.y+r},t.path){let o=i=>({x:i.x+e,y:i.y+r});t.path={start:o(t.path.start),control1:o(t.path.control1),control2:o(t.path.control2),end:o(t.path.end)}}}function en(t,e){let r=Qt(t),o={x:-r.y,y:r.x},i=T(t[0]),a=t.map(l=>({row:l,coord:oe(T(l),i,o)})).sort((l,c)=>l.coord-c.coord),n=a[0].coord,s=!1;return a.forEach((l,c)=>{let f=n+c*e-l.coord;Math.abs(f)>1e-6&&(Oo(l.row,o.x*f,o.y*f),delete l.row.arcFanGeneration,delete l.row.rowBlockGeneration,s=!0)}),s}function jo(t,e){let r={x:-e.y,y:e.x},o=T(t[0]),i=t.map(n=>oe(T(n),o,r)).sort((n,s)=>n-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Ao(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=$e(t),r=e[0],o=e[e.length-1],i=o.x-r.x,a=o.y-r.y,n=Math.hypot(i,a);t.path&&(t.origin={...r},t.seatSpacing=Math.max(1,n/(t.seatCount-1))),n>1e-6&&(t.rotation=Re(Math.atan2(a,i)/B)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Po(t,e){let r=new Set(t.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${e}${o}`.slice(0,80);if(!r.has(i))return i}return`${e}-${Date.now().toString(36)}`}function na(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to merge");let i=o.map(v=>r.objects.find(I=>I.type==="row"&&I.id===v)),a=o.filter((v,I)=>!i[I]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=n.filter(v=>v.path||v.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(v=>v.id)});let l=n[0],c=n.find(v=>_o(v.rotation,l.rotation)>Co);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=xo(l),g={x:-f.y,y:f.x},h=Math.max(8,l.seatSpacing*.6),u=n.find(v=>Math.abs(oe(v.origin,l.origin,g))>h);if(u){let v=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 ${v} units from the first.`,{rowIds:[l.id,u.id]})}let m=n.slice().sort((v,I)=>oe(v.origin,l.origin,f)-oe(I.origin,l.origin,f)),y=m.reduce((v,I)=>v+I.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 v of m){if(v.overrides)for(let I of v.overrides)_.push({...structuredClone(I),index:I.index+b});b+=v.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(v=>v.id),x=new Set(p);for(let v=r.objects.length-1;v>=0;v--)x.has(r.objects[v].id)&&r.objects.splice(v,1);return{floorId:r.floorId,changed:!0,rowId:w.id,removedRowIds:p,seatCount:y}}function oa(t,e){let r=S(t,e.floorId),o=r.objects.find(u=>u.type==="row"&&u.id===e.rowId);if(!o)throw new d("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(o.path)throw new d("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new d("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let n=$e(o),s=i>1?o.curve/(i-1):0,l=i-a,c={type:"row",id:P(t,"r",e.idFactory,new Set),label:Po(r.objects,o.label),origin:{...n[a]},rotation:Re(o.rotation-s*a),curve:s*(l-1),seatCount:l,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(c.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(c.seatLabelStart=o.seatLabelStart),o.commercial&&(c.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(c.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(c.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(c.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let u=structuredClone(o.labelPresentation);delete u.position,c.labelPresentation=u}let f=[],g=[];if(o.overrides)for(let u of o.overrides)u.index<a?f.push(structuredClone(u)):g.push({...structuredClone(u),index:u.index-a});o.seatCount=a,o.curve=s*(a-1),f.length?o.overrides=f:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,g.length&&(c.overrides=g);let h=r.objects.indexOf(o);return r.objects.splice(h+1,0,c),{floorId:r.floorId,changed:!0,rowId:o.id,newRowId:c.id,firstSeatCount:a,secondSeatCount:l,newLabel:c.label}}function ra(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new d("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(s=>r.objects.find(l=>l.type==="row"&&l.id===s)),a=o.filter((s,l)=>!i[l]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=en(i,e.gap);return{floorId:r.floorId,changed:n,rowIds:o,gap:e.gap}}function ia(t,e){let r=S(t,e.floorId),o=[...new Set(e.rowIds)];if(o.length<2)throw new d("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(h=>r.objects.find(u=>u.type==="row"&&u.id===h)),a=o.filter((h,u)=>!i[u]);if(a.length)throw new d("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let n=i,s=()=>JSON.stringify(n.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),l=s();for(let h of n)Ao(h);let c=Qt(n),f=Re(Math.atan2(c.y,c.x)/B);for(let h of n)h.rotation=f;let g=jo(n,c);return en(n,g),{floorId:r.floorId,changed:s()!==l,rowIds:o,gap:g}}import We from"polygon-clipping";var tn=100,nn=512,Qe=8192,fn=64,on=1e7,k=1e-7;function un(t,e){return Math.abs(t.x-e.x)<=k&&Math.abs(t.y-e.y)<=k}function gn(t){let e=t.map(r=>({x:r.x,y:r.y}));for(;e.length>1&&un(e[0],e[e.length-1]);)e.pop();return e}function ge(t,e,r){let o=G(e,r,t);return Math.abs(o)>k?!1:t.x>=Math.min(e.x,r.x)-k&&t.x<=Math.max(e.x,r.x)+k&&t.y>=Math.min(e.y,r.y)-k&&t.y<=Math.max(e.y,r.y)+k}function hn(t,e,r,o){let i=G(t,e,r),a=G(t,e,o),n=G(r,o,t),s=G(r,o,e);return(i>k&&a<-k||i<-k&&a>k)&&(n>k&&s<-k||n<-k&&s>k)?!0:Math.abs(i)<=k&&ge(r,t,e)||Math.abs(a)<=k&&ge(o,t,e)||Math.abs(n)<=k&&ge(t,r,o)||Math.abs(s)<=k&&ge(e,r,o)}function Ro(t){for(let e=0;e<t.length;e+=1){let r=(e+1)%t.length;for(let o=e+1;o<t.length;o+=1){let i=(o+1)%t.length;if(!(e===o||r===o||i===e)&&hn(t[e],t[r],t[o],t[i]))return!0}}return!1}function rn(t,e){return t.some((r,o)=>e.some((i,a)=>hn(r,t[(o+1)%t.length],i,e[(a+1)%e.length])))}function et(t,e){return!e.some((r,o)=>ge(t,r,e[(o+1)%e.length]))&&E(t,e,void 0)}function ke(t,e,r){let o=gn(t);if(o.length<3||o.length>nn||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>on||Math.abs(i.y)>on||un(i,o[(a+1)%o.length]))||Math.abs(me(o))<=k||Ro(o))throw new d("invalid_operation",`GA area ${r} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${nn} finite vertices per ring.`,{gaAreaId:r,ring:e});return o}function Fo(t){let e=ke(t.points,"outline",t.id),r=t.holes??[];if(!Array.isArray(r)||r.length>fn)throw new d("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let o=r.map(i=>ke(i,"cutout",t.id));for(let i=0;i<o.length;i+=1){let a=o[i];if(!a.flatMap((s,l)=>{let c=a[(l+1)%a.length];return[s,{x:(s.x+c.x)/2,y:(s.y+c.y)/2}]}).every(s=>et(s,e))||rn(a,e))throw new d("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<o.length;s+=1)if(rn(a,o[s])||et(a[0],o[s])||et(o[s][0],a))throw new d("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:o}}function Fe(t){return t.map(e=>[e.x,e.y])}function an(t){return gn(t.map(([e,r])=>({x:e,y:r})))}function sn(t){return Math.abs(t.reduce((e,r,o)=>{let i=t[(o+1)%t.length];return e+r[0]*i[1]-i[0]*r[1]},0))/2}function ko(t){return t.reduce((e,r)=>e+(sn(r[0]??[])-r.slice(1).reduce((o,i)=>o+sn(i),0)),0)}function tt(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(tt).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${tt(e[r])}`).join(",")}}`}function ln(t,e,r){let o=t[e];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>r)throw new d("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${r} characters before joining.`,{gaAreaId:t.id,field:e});return i}function cn(t){return tt({categoryKey:t.categoryKey,displayLabel:ln(t,"displayLabel",80),displayType:ln(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function dn(t,e){let r=Math.min(...t.points.map(i=>i.y)),o=Math.min(...t.points.map(i=>i.x));return[r,o,e]}function Mo(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function bn(t,e){let r=S(t,e.floorId),o=[...new Set(e.gaAreaIds)];if(o.length<2)throw new d("invalid_operation","Select at least two GA areas to join");if(o.length>tn)throw new d("invalid_operation",`Join Areas supports at most ${tn} areas at once`);let i=o.map(C=>r.objects.find(j=>j.type==="gaArea"&&j.id===C)),a=o.filter((C,j)=>!i[j]);if(a.length)throw new d("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let n=i;F(t,n[0].categoryKey);let s=cn(n[0]),l=n.find(C=>cn(C)!==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:[n[0].id,l.id]});let c=ce(t).objectToSection,f=c.get(n[0].id)??"__ungrouped__",g=n.find(C=>(c.get(C.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:[n[0].id,g.id],sectionIds:[f,c.get(g.id)??"__ungrouped__"]});let h=n.reduce((C,j)=>{if(!Number.isInteger(j.capacity)||j.capacity<1||j.capacity>ye)throw new d("invalid_operation",`GA area ${j.id} has invalid capacity`,{gaAreaId:j.id});return C+j.capacity},0);if(h>ye)throw new d("invalid_operation",`Joined GA capacity would be ${h}, over the ${ye}-unit area limit`,{capacity:h});let u=J(t).reduce((C,j)=>C+W(j),0);if(u>ee)throw new d("invalid_operation",`Chart inventory exceeds the ${ee}-unit publication limit`,{inventory:u});let m=n.map(Fo),y=m.reduce((C,j)=>C+j.outer.length+j.holes.reduce((K,X)=>K+X.length,0),0);if(y>Qe)throw new d("invalid_operation",`Join Areas supports at most ${Qe} source vertices`,{vertexCount:y});let w;try{let C=m.map(X=>[Fe(X.outer)]);if(w=We.union(C[0],...C.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 j=m.flatMap(X=>X.holes.map(Le=>[Fe(Le)]));j.length&&(w=We.difference(w,...j));let K=m.findIndex(X=>{let Le=[Fe(X.outer),...X.holes.map(Fe)];return ko(We.intersection(Le,w))<=k});if(K>=0)throw new d("invalid_operation",`GA area ${n[K].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:n[K].id})}catch(C){throw C instanceof d?C:new d("invalid_operation","The selected GA boundaries could not be joined safely",{reason:C instanceof Error?C.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 _=an(w[0][0]),b=w[0].slice(1).map(an),p=_.length+b.reduce((C,j)=>C+j.length,0);if(b.length>fn||p>Qe)throw new d("invalid_operation","The joined boundary is too complex to store safely",{holeCount:b.length,vertexCount:p});ke(_,"outline",n[0].id),b.forEach(C=>ke(C,"cutout",n[0].id));let x=new Map(r.objects.map((C,j)=>[C.id,j])),v=n.slice().sort((C,j)=>Mo(dn(C,x.get(C.id)??Number.MAX_SAFE_INTEGER),dn(j,x.get(j.id)??Number.MAX_SAFE_INTEGER))),I=v[0],A=structuredClone(t),H=S(A,r.floorId),U=H.objects.find(C=>C.type==="gaArea"&&C.id===I.id);U.points=structuredClone(_),b.length?U.holes=structuredClone(b):delete U.holes;let V=new Set(v.slice(1).map(C=>C.id));for(let C=H.objects.length-1;C>=0;C-=1)V.has(H.objects[C].id)&&H.objects.splice(C,1);let $=ce(A).objectToSection.get(I.id)??"__ungrouped__";if($!==f)throw new d("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:f,afterSectionId:$});let O=[],D=new Set;for(let C of v){if(!vt(C))throw new d("invalid_operation",`GA area ${C.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:C.id});let j=le(C);if(j.length!==C.capacity||j.some(K=>D.has(K)))throw new d("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:C.id});j.forEach(K=>D.add(K)),O.push(...It(C))}if(O.length>256)throw new d("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let R=new Set(n.map(C=>C.id));for(let C of J(t).filter(j=>j.type==="gaArea"&&!R.has(j.id))){let j=le(C).find(K=>D.has(K));if(j)throw new d("invalid_operation","A stable GA inventory identity is already owned by another area",{label:j,gaAreaId:C.id})}let Ee=v.slice(1).map(C=>C.id);return{floorId:r.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:Ee,sourceAreaCount:v.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:_.length,holeCount:b.length,sectionId:f,points:_,...b.length?{holes:b}:{},segments:O}}function ga(t,e){let{segments:r,...o}=bn(t,e);return o}function ha(t,e){let r=bn(t,e),o=S(t,r.floorId),i=o.objects.find(l=>l.type==="gaArea"&&l.id===r.areaId);i.points=structuredClone(r.points),r.holes?.length?i.holes=structuredClone(r.holes):delete i.holes,i.capacity=r.capacity,i.inventorySegments=structuredClone(r.segments);let a=new Set(r.removedAreaIds);for(let l=o.objects.length-1;l>=0;l-=1)a.has(o.objects[l].id)&&o.objects.splice(l,1);let{segments:n,...s}=r;return{...s,changed:!0}}function wa(t,e){let r=S(t,e.floorId),o=[...new Set(e.shapeIds)];if(!o.length)throw new d("invalid_operation","At least one shape id is required");let i=o.map(c=>r.objects.find(f=>f.type==="shape"&&f.id===c)),a=o.filter((c,f)=>!i[f]);if(a.length)throw new d("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let n=structuredClone(e.patch);if(!Object.keys(n).length)throw new d("invalid_operation","At least one shape change is required");if(n.label!==void 0){if(o.length!==1)throw new d("invalid_operation","label can be changed only for one shape at a time");if(n.label!==null){if(n.label=n.label.normalize("NFKC").trim(),!n.label)n.label=null;else if(n.label.length>80)throw new d("invalid_operation","Shape labels support at most 80 characters")}}if(n.fill!==void 0&&n.fill!==null&&(n.fill=N(n.fill,"Shape fill")),n.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(n.kind))throw new d("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(n.stroke!==void 0&&n.stroke!==null){if(!Number.isFinite(n.stroke.width)||n.stroke.width<.5||n.stroke.width>40)throw new d("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");n.stroke={color:N(n.stroke.color,"Shape stroke"),width:n.stroke.width}}if(n.cornerRadius!==void 0&&n.cornerRadius!==null&&(!Number.isFinite(n.cornerRadius)||n.cornerRadius<0||n.cornerRadius>5e3))throw new d("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(n.opacity!==void 0&&n.opacity!==null&&(!Number.isFinite(n.opacity)||n.opacity<.1||n.opacity>1))throw new d("invalid_operation","Shape opacity must be from 0.1 to 1");if(n.heightM!==void 0&&n.heightM!==null&&(!Number.isFinite(n.heightM)||n.heightM<.05||n.heightM>50))throw new d("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(n.eventConfigurationIds!==void 0&&n.eventConfigurationIds!==null){let c=n.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");n.eventConfigurationIds=c}if(n.lineCap!==void 0&&n.lineCap!==null&&!xt.includes(n.lineCap))throw new d("invalid_operation","Shape lineCap must be butt, round, or square");if(n.lineJoin!==void 0&&n.lineJoin!==null&&!_t.includes(n.lineJoin))throw new d("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[c,f]of[["startEnding",n.startEnding],["endEnding",n.endEnding]])if(f!=null&&!Ot.includes(f))throw new d("invalid_operation",`Shape ${c} must be none or arrow`);if(n.lineCap!=null||n.lineJoin!=null||n.startEnding!=null||n.endEnding!=null){let c=i.filter(f=>!Ue(n.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 i){let f=JSON.stringify(c);if(n.label===null?delete c.label:n.label!==void 0&&(c.label=n.label),n.fill===null?delete c.fill:n.fill!==void 0&&(c.fill=n.fill),n.kind!==void 0&&(c.kind=n.kind,Ue(c.kind)||(delete c.lineCap,delete c.lineJoin,delete c.startEnding,delete c.endEnding)),n.stroke===null?delete c.stroke:n.stroke!==void 0&&(c.stroke={...n.stroke}),n.opacity===null?delete c.opacity:n.opacity!==void 0&&(c.opacity=n.opacity),n.heightM===null?delete c.heightM:n.heightM!==void 0&&(c.heightM=n.heightM),n.eventConfigurationIds===null?delete c.eventConfigurationIds:n.eventConfigurationIds!==void 0&&(c.eventConfigurationIds=[...n.eventConfigurationIds]),n.lineCap===null?delete c.lineCap:n.lineCap!==void 0&&(c.lineCap=n.lineCap),n.lineJoin===null?delete c.lineJoin:n.lineJoin!==void 0&&(c.lineJoin=n.lineJoin),n.startEnding===null?delete c.startEnding:n.startEnding!==void 0&&(c.startEnding=n.startEnding),n.endEnding===null?delete c.endEnding:n.endEnding!==void 0&&(c.endEnding=n.endEnding),n.cornerRadius===null)delete c.cornerRadius;else if(n.cornerRadius!==void 0){let g=Math.min(c.width??1/0,c.height??1/0),h=Number.isFinite(g)?g/2:n.cornerRadius;c.cornerRadius=c.kind==="rect"?Math.max(0,Math.min(n.cornerRadius,h)):n.cornerRadius}JSON.stringify(c)!==f&&(l=!0)}return{floorId:r.floorId,changed:l,shapeIds:o}}function pn(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new d("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(f=>!Number.isFinite(f.x)||!Number.isFinite(f.y)))throw new d("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let r=e.map(f=>f.x),o=e.map(f=>f.y),i=Math.min(...r),a=Math.max(...r),n=Math.min(...o),s=Math.max(...o),l=Math.max(1,a-i),c=Math.max(1,s-n);return{cx:i+l/2,cy:n+c/2,width:l,height:c}}function va(t,e){let r=S(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one shape resize is required");let o=e.updates.map(n=>n.shapeId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Shape ids must be unique");let i=e.updates.map(n=>{if(![n.width,n.height].every(Number.isFinite)||n.width<8||n.height<8||n.width>1e4||n.height>1e4)throw new d("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:n.shapeId});let s=r.objects.find(c=>c.type==="shape"&&c.id===n.shapeId);if(!s)throw new d("object_not_found",`Unknown shape id: ${n.shapeId}`,{shapeId:n.shapeId});let l=s.role==="stage"?pn(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:n,box:l}}),a=!1;for(let{shape:n,update:s,box:l}of i)if(!(Math.abs(l.width-s.width)<1e-9&&Math.abs(l.height-s.height)<1e-9)){if(n.kind==="rect"||n.kind==="ellipse")n.x=l.cx-s.width/2,n.y=l.cy-s.height/2,n.width=s.width,n.height=s.height;else{let c=s.width/l.width,f=s.height/l.height;n.points=(n.points??[]).map(g=>({x:l.cx+(g.x-l.cx)*c,y:l.cy+(g.y-l.cy)*f})),(n.x!=null||n.y!=null||n.width!=null||n.height!=null||n.role==="stage")&&(n.x=l.cx-s.width/2,n.y=l.cy-s.height/2,n.width=s.width,n.height=s.height)}a=!0}return{floorId:r.floorId,changed:a,shapes:i.map(({shape:n,update:s})=>({id:n.id,width:s.width,height:s.height}))}}function Ia(t,e){let r=S(t,e.floorId);if(!e.updates.length)throw new d("invalid_operation","At least one stage update is required");let o=e.updates.map(s=>s.stageId);if(new Set(o).size!==o.length)throw new d("invalid_operation","Stage ids must be unique");let i=new Set(jt.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new d("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let 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:pn(l)}}),n=!1;for(let s of a)s.box&&(s.shape.points=At({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,n=!0);return{floorId:r.floorId,changed:n,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function mn(t){let e=new Map;t.confidenceEvidence&&e.set("venue",{target:{scope:"venue"},evidence:t.confidenceEvidence});for(let r of M(t)){r.confidenceEvidence&&e.set(`floor:${r.id}`,{target:{scope:"floor",floorId:r.id},evidence:r.confidenceEvidence});for(let o of r.objects){let i=`floor:${r.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&e.set(i,{target:{scope:o.type,floorId:r.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&e.set(`${i}:segmented`,{target:{scope:"row",floorId:r.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&e.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:r.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return e}function Me(t){return Array.isArray(t)?t.map(Me):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).sort(([e],[r])=>e.localeCompare(r)).map(([e,r])=>[e,Me(r)]))}function No(t,e){return JSON.stringify(Me(t))===JSON.stringify(Me(e))}function nt(t){return!!t&&t.status!=="draft"&&t.status!=="retracted"}function Eo(t){return t?t.status==="retracted"?"retract":nt(t)?"approve":"set":"clear"}function Lo(t,e){let r=mn(t),o=mn(e),i=[...new Set([...r.keys(),...o.keys()])].sort(),a=[];for(let n of i){let s=r.get(n),l=o.get(n);if(s&&l&&No(s.evidence,l.evidence))continue;let c=l?.target??s?.target;c&&a.push({...c,operation:Eo(l?.evidence),...s?{before:s.evidence}:{},...l?{after:l.evidence}:{}})}return a}function Oa(t,e){return Lo(t,e).some(r=>nt(r.before)||nt(r.after))}var Do=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Ko=new Set(["generated","geometry-verified","configuration-verified"]),Go=new Set(["none","comparable-build-reference","actual-build-checked"]),$o=new Set(["clear","partial","obstructed"]);function ot(t){return t.toISOString().slice(0,10)}function rt(t,e){return typeof t=="string"&&t.normalize("NFKC").trim()===t&&t.length>0&&t.length<=e}function ie(t,e,r){if(!rt(t,e))throw new d("invalid_operation",`Confidence evidence ${r} is invalid`,{field:r});return t}function re(t,e,r){if(t!==void 0)return ie(t,e,r)}function Te(t,e,r){let o=r?[S(t,r)]:M(t).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(n=>n.id===e);if(a)return{floorId:i.floorId,object:a}}throw new d("object_not_found",`Unknown chart object: ${e}`,{objectId:e,floorId:r})}function yn(t,e){let r=M(t),o=e?r.find(i=>i.id===e):r[0];if(!o)throw new d("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return o}function he(t,e){if(e.scope==="venue")return t.confidenceEvidence;if(e.scope==="floor")return yn(t,e.floorId).confidenceEvidence;if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let o=Te(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new d("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:e.objectId});return o.object.overrides?.find(i=>i.index===e.seatIndex)?.confidenceEvidence}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let r=Te(t,e.objectId,e.floorId);if(e.scope==="row"&&r.object.type!=="row")throw new d("invalid_operation","Row evidence requires a row id",{objectId:e.objectId});if(e.scope==="section"&&r.object.type!=="section")throw new d("invalid_operation","Section evidence requires a section id",{objectId:e.objectId});if(r.object.type==="row"||r.object.type==="section")return r.object.confidenceEvidence;throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:r.object.type})}function Ne(t,e,r){if(e.scope==="venue")return r?t.confidenceEvidence=r:delete t.confidenceEvidence,{};if(e.scope==="floor"){let i=yn(t,e.floorId);return r?i.confidenceEvidence=r:delete i.confidenceEvidence,{floorId:i.id}}if(e.scope==="seat"){if(!e.objectId||e.seatIndex===void 0)throw new d("invalid_operation","Seat evidence requires objectId and seatIndex");let i=Te(t,e.objectId,e.floorId);return Wt(t,{floorId:i.floorId,seats:[{rowId:e.objectId,index:e.seatIndex}],patch:{confidenceEvidence:r??null}}),{floorId:i.floorId,objectId:e.objectId}}if(!e.objectId)throw new d("invalid_operation",`${e.scope} evidence requires objectId`);let o=Te(t,e.objectId,e.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new d("invalid_operation",`${e.scope} evidence is not supported on this object`,{objectId:e.objectId,type:o.object.type});return r?o.object.confidenceEvidence=r:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function zo(t){if(t===void 0)return;if(!t||typeof t!="object")throw new d("invalid_operation","Confidence evidence modeledTarget is invalid");if(!rt(t.label,80)||!rt(t.methodLabel,100))throw new d("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(t.totalRayCount)||t.totalRayCount<1||t.totalRayCount>1e3||!Number.isInteger(t.clearRayCount)||t.clearRayCount<0||t.clearRayCount>t.totalRayCount)throw new d("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!$o.has(t.classification))throw new d("invalid_operation","Confidence evidence modeledTarget classification is invalid");let e=t.occluderLabels?.map(r=>ie(r,80,"occluder label"));return{label:t.label,methodLabel:t.methodLabel,totalRayCount:t.totalRayCount,clearRayCount:t.clearRayCount,classification:t.classification,...e?.length?{occluderLabels:e}:{}}}function Bo(t,e=new Date){if(t.schema!==void 0&&t.schema!=="seatlayer.seat-confidence/1")throw new d("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!Do.has(t.evidenceKind))throw new d("invalid_operation","Confidence evidence kind is invalid");if(!Ko.has(t.modelLevel))throw new d("invalid_operation","Confidence evidence model level is invalid");let r=t.realityLevel??"none";if(!Go.has(r))throw new d("invalid_operation","Confidence evidence reality level is invalid");if(t.evidenceKind==="synthetic-model"&&(t.modelLevel!=="generated"||r!=="none"))throw new d("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=re(t.eventConfigurationId,100,"eventConfigurationId");if(t.eventConfigurationVersion!==void 0&&(!Number.isInteger(t.eventConfigurationVersion)||t.eventConfigurationVersion<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(t.modelLevel==="configuration-verified"&&!o)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=t.limitations?.map(f=>ie(f,160,"limitation"));if(i&&i.length>6)throw new d("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=re(t.assessedAt,40,"assessedAt")??ot(e),n=Date.parse(a);if(!Number.isFinite(n))throw new d("invalid_operation","Confidence evidence assessedAt is invalid");let s=re(t.validUntil,40,"validUntil")??(t.modelLevel==="generated"?void 0:ot(new Date(n+365*24*60*60*1e3))),l=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(l)||l<n||l>n+366*24*60*60*1e3))throw new d("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let c=re(t.approvedByRole,100,"approvedByRole");if(t.modelLevel!=="generated"&&!c)throw new d("invalid_operation","Verified model levels require approvedByRole");return{schema:"seatlayer.seat-confidence/1",evidenceId:ie(t.evidenceId,120,"evidenceId"),modelVersion:ie(t.modelVersion,120,"modelVersion"),evidenceKind:t.evidenceKind,modelLevel:t.modelLevel,realityLevel:r,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...t.eventConfigurationVersion!==void 0?{eventConfigurationVersion:t.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...c?{approvedByRole:c}:{},...re(t.sourceLabel,120,"sourceLabel")?{sourceLabel:t.sourceLabel}:{},...i?.length?{limitations:i}:{},...t.modeledTarget?{modeledTarget:zo(t.modeledTarget)}:{}}}function ae(t,e={}){return{changed:e.changed??!0,scope:t.scope,...t.objectId?{objectId:t.objectId}:{},...t.floorId?{floorId:t.floorId}:{},...t.seatIndex!==void 0?{seatIndex:t.seatIndex}:{},...e}}function ja(t,e){let r=Bo(e.evidence,e.now),o=JSON.stringify(he(t,e)??null),i=Ne(t,e,r),a=JSON.stringify(he(t,e)??null);return ae(e,{changed:o!==a,...i,evidenceId:r.evidenceId,status:"draft"})}function Aa(t,e){let r=he(t,e);if(!r)return ae(e,{changed:!1});let o=Ne(t,e,void 0);return ae(e,{changed:!0,...o,evidenceId:r.evidenceId})}function Pa(t,e){let r=he(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to approve",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")throw new d("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=ie(e.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=re(e.eventConfigurationId,100,"eventConfigurationId")??r.eventConfigurationId;if(r.modelLevel==="configuration-verified"&&!i)throw new d("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=e.eventConfigurationVersion??r.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new d("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let n={...r,status:"approved",approvedByRole:o,assessedAt:ot(e.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete n.basisSha256;let s=e.basisSha256??t.confidenceBasisSha256;s&&(n.basisSha256=s);let l=JSON.stringify(r),c=Ne(t,e,n);return ae(e,{changed:l!==JSON.stringify(n),...c,evidenceId:n.evidenceId,status:"approved"})}function Ra(t,e){let r=he(t,e);if(!r)throw new d("invalid_operation","There is no confidence evidence at this scope to retract",{scope:e.scope,objectId:e.objectId});if(r.status==="retracted")return ae(e,{changed:!1,evidenceId:r.evidenceId,status:"retracted"});let o={...r,status:"retracted"};delete o.basisSha256;let i=Ne(t,e,o);return ae(e,{changed:!0,...i,evidenceId:r.evidenceId,status:"retracted"})}export{Ut as COLORBLIND_SAFE_PALETTE,d as ChartOperationError,Tt as DEFAULT_FLOOR_HEIGHT_STEP_M,wn as DEFAULT_SECTION_CORNER_SMOOTHING,Uo as MAX_BUYER_IMAGE_URL_LENGTH,Ve as MAX_FLOOR_BASE_HEIGHT_M,vi as addArcFanRows,Ui as addBookableGridArray,Ri as addBoothArray,Un as addChartCategory,Zo as addChartFloor,ir as addChartZone,Ai as addGAArea,ji as addRowBlock,Pi as addTableArray,Er as applyPolygonHole,Ki as applyReferenceScanRows,Zr as applySectionCornerSmoothing,Dn as applySectionOutlineShaping,Nr as applySectionRowFit,Pa as approveConfidenceEvidence,lo as arcFanInputForGroup,qr as assignSectionInventoryCategory,pi as automaticPlacementCenter,Aa as clearConfidenceEvidence,Oa as confidenceEvidenceChangeRequiresPublish,Lo as confidenceEvidenceChanges,si as confirmReferenceCategoryOutputColor,Vr as convertGeneratedSectionToPolygon,Ye as countCoveredInventory,Zn as familyCategoryLabel,go as gaAreaFootprint,Fi as groupRowsAsSegmented,jr as insertSeatingBlock,Jo as isSafeBuyerImageUrl,ha as joinGAAreas,na as mergeRows,_e as mirrorFirstFloor,Y as normalizeBuyerImageUrl,Bo as normalizeDraftEvidence,Yi as parseSeatRefId,Bn as pickColorblindSafeCategoryColor,eo as planCreationCategory,Ht as previewArcFanRows,Bi as previewBookableGridArray,Nn as previewGeneratedSectionPolygonConversion,ga as previewJoinGAAreas,Ze as previewPolygonHole,kn as previewRemovePolygonHole,jn as previewRowCubicPath,Rn as previewSectionRowFit,ai as reassignColorblindSafeCategoryColors,Or as relabelChartRows,ci as removeChartCategory,er as removeChartFloor,xr as removeChartObjects,sr as removeChartZone,Lr as removePolygonHole,Wo as renameChartFloor,ii as reorderChartCategories,Ii as replaceArcFanRows,Ti as replaceRowBlock,Zi as resetSeatOverrides,va as resizeShapes,li as resolveCreationCategory,Ra as retractConfidenceEvidence,Pe as seatRefId,Tn as sectionInventorySelectionSummary,ja as setConfidenceEvidence,ra as setRowBlockSpacing,oa as splitRow,ia as straightenAndSpaceRows,Xr as transformSectionBoundary,En as transformSectionBoundaryObject,ki as ungroupSegmentedRow,Sr as updateBooths,Gn as updateCategoryDefinitions,Qo as updateChartFloorBaseHeight,hi as updateChartTheme,ar as updateChartZones,Cr as updateGAAreas,Tr as updateRowCubicPath,ta as updateRows,Wt as updateSeatOverrides,Yr as updateSectionExactPath,Hr as updateSectionMetadata,Mi as updateSegmentedRow,wa as updateShapes,Ia as updateStageKinds,Ir as updateTables,_r as updateTextObjects,bi as updateViewFromSeatFallback};
|