@g1cloud/entity-modeler-next 5.2.7 → 5.2.8

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.
@@ -3336,7 +3336,7 @@ function Yg(e, t, n) {
3336
3336
  o++;
3337
3337
  }
3338
3338
  }
3339
- const M8 = "5.2.7";
3339
+ const M8 = "5.2.8";
3340
3340
  function gn(e) {
3341
3341
  return e.reduce((t, n) => Math.max(t, n.order), -1) + 1;
3342
3342
  }
@@ -6024,6 +6024,12 @@ function Ec(e, t, n) {
6024
6024
  ...e.defaultValue != null ? { defaultValue: e.defaultValue } : {},
6025
6025
  ...e.attributeGroup ? { attributeGroup: e.attributeGroup } : {},
6026
6026
  ...e.description ? { description: e.description } : {},
6027
+ // 직렬화 타입 자기 필드의 컨테이너(`Set<String>`). ⚠️**이 줄이 빠져 있었다** — 키 목록·스키마·타입은
6028
+ // 열어 놓고 «조립»만 안 해서 `ok:true` 로 통과한 뒤 값이 **사라졌다**(2026-08-31 프로덕션 실측).
6029
+ // A-3 가 `entity.add` 에서 잡은 *「spec 은 명명 필드만 조립돼 사라진다」* 와 **같은 형상**이고,
6030
+ // 그때 세운 배리어 2층(`specKeys` 컴파일 결박 · schema 대조)은 **키↔조립**을 보지 않아 못 잡았다
6031
+ // ⇒ 그 세 번째 층을 `resolver.test.ts` 에 신설했다(전 키 조립 왕복).
6032
+ ...e.collectionType ? { collectionType: e.collectionType } : {},
6027
6033
  dbAttrs: o ? [
6028
6034
  {
6029
6035
  modelId: n(),
@@ -24,7 +24,7 @@ ${u}
24
24
  `)+`
25
25
  `}}function Zg(e,n,o,i){const a=[`${n}.${e}`,...i?[i]:[],ot.jpaRepository,ot.querydslExecutor].sort(),r=[`package ${n};`,""];for(const l of a)r.push(`import ${l};`);return r.push(""),r.push(`public interface ${e}Repository extends JpaRepository<${e}, ${o}>, QuerydslPredicateExecutor<${e}> {`),r.push("}"),{fileName:`${e}Repository.java`,source:r.join(`
26
26
  `)+`
27
- `}}const ao="com.example",Qg="command.domain";function kn(e,n,o={}){const i=To(e,n);if(i.kind==="explicit")return i.value;const a=o.packageConfig;if(a!=null&&a.basePackage){const r=i.value?`.${i.value}`:"",l=a.layerSuffix??Qg,s=l?`.${l}`:"";return`${a.basePackage}${r}${s}`}return n.packageName||""}const eb="CustomMoneyType",tb="Money";function nb(e){return!(e.type!==eb||e.attrType!=="NORMAL"||e.identifier||e.dbAttrs.length>1)}function ob(e){const n=e.dbAttrs[0]??{modelId:Pe(),physicalName:"",dataType:""},o={modelId:Pe(),physicalName:"",dataType:""},{customType:i,...a}=e;return{...a,type:tb,attrType:"EMBED_PREDEF",dbAttrs:[n,o]}}function ib(e){let n=!1;const o=e.entities.map(i=>{let a=!1;const r=i.attributes.map(l=>nb(l)?(a=!0,n=!0,ob(l)):l);return a?{...i,attributes:r}:i});return n?{...e,entities:o}:e}function ab(e,n){const o=new Map,i=[],a=new Map;for(const h of e.entities){const g=new Map,b=new Map,_=new Map,E=(N,y,k)=>{if(!N)return;o.get(N)||o.set(N,[{entityId:y,assignedId:N}]),i.push({id:N,entityId:y,sink:k}),k(N)};for(const N of h.attributes){E(N.modelId,h.modelId,y=>g.set(N,y));for(const y of N.dbAttrs)E(y.modelId,h.modelId,k=>b.set(y,k))}for(const N of h.indexes??[])E(N.modelId,h.modelId,y=>_.set(N,y));a.set(h,{attrs:g,cols:b,idx:_})}const r=new Set(o.keys()),l=new Map;for(const h of i){const g=(l.get(h.id)??0)+1;if(l.set(h.id,g),g===1)continue;const b=rb(h.id,g-1,r);r.add(b),o.get(h.id).push({entityId:h.entityId,assignedId:b}),h.sink(b)}const s=[...o.values()].reduce((h,g)=>h+Math.max(0,g.length-1),0);if(s===0)return{logical:e,layout:n,reissued:0};const c=(h,g)=>{var _;if(!g||!h)return g;const b=o.get(g);return!b||b.length<2?g:((_=b.find(E=>E.entityId===h))==null?void 0:_.assignedId)??g},d=new Map(e.associations.map(h=>[h.modelId,h])),u=(h,g)=>{const b=d.get(h);if(b)return b.end1.entityRef===g?b.end2.entityRef:b.end1.entityRef},m=e.entities.map(h=>{var N;const g=a.get(h),b=h.attributes.map(y=>{const k=g.attrs.get(y),S=y.dbAttrs.map(A=>{const V=g.cols.get(A);return V===A.modelId?A:{...A,modelId:V}});let T=y.derivedFrom;if(T){const A=u(T.associationRef,h.modelId),V=c(A,T.sourceAttributeRef);V!==T.sourceAttributeRef&&(T={...T,sourceAttributeRef:V})}return k!==y.modelId||T!==y.derivedFrom||S.some((A,V)=>A!==y.dbAttrs[V])?{...y,modelId:k,dbAttrs:S,derivedFrom:T}:y}),_=(N=h.indexes)==null?void 0:N.map(y=>{const k=g.idx.get(y),S=y.columns.map(O=>{const A=c(h.modelId,O.columnRef);return A===O.columnRef?O:{...O,columnRef:A}});return k!==y.modelId||S.some((O,A)=>O!==y.columns[A])?{...y,modelId:k,columns:S}:y});return b.some((y,k)=>y!==h.attributes[k])||_&&h.indexes&&_.some((y,k)=>y!==h.indexes[k])?{...h,attributes:b,..._?{indexes:_}:{}}:h}),p=e.associations.map(h=>{const g=c(h.end1.entityRef,h.end1.attributeRef),b=c(h.end2.entityRef,h.end2.attributeRef);return g===h.end1.attributeRef&&b===h.end2.attributeRef?h:{...h,end1:g===h.end1.attributeRef?h.end1:{...h.end1,attributeRef:g},end2:b===h.end2.attributeRef?h.end2:{...h.end2,attributeRef:b}}}),f=n.associationLayouts.map(h=>{const g=d.get(h.associationRef);if(!g)return h;const b=c(g.end1.entityRef,h.sourceColumnRef),_=c(g.end2.entityRef,h.targetColumnRef);return b===h.sourceColumnRef&&_===h.targetColumnRef?h:{...h,sourceColumnRef:b,targetColumnRef:_}});return{logical:{...e,entities:m,associations:p},layout:f.some((h,g)=>h!==n.associationLayouts[g])?{...n,associationLayouts:f}:n,reissued:s}}function rb(e,n,o){let i=n;for(;;){const a=`dup${i}:${e}`;if(!o.has(a))return a;i++}}const lb="5.2.7";function Ht(e){return e.reduce((n,o)=>Math.max(n,o.order),-1)+1}function wl(e,n,o){const i=new Set(n),a=e.filter(s=>i.has(s.modelId)),r=e.filter(s=>!i.has(s.modelId)),l=Math.max(0,Math.min(o,r.length));return[...r.slice(0,l),...a,...r.slice(l)]}function wd(e){return!!e.derivedFrom&&e.dbAttrs.length>0}function Id(e){for(const n of e){const o=[...n.attributes].sort((s,c)=>s.order-c.order),i=o.filter(wd);if(!i.length)continue;const a=o.filter(s=>!wd(s));let r=0;a.forEach((s,c)=>{s.identifier&&!s.derivedFrom&&(r=c+1)});const l=[...a.slice(0,r),...i,...a.slice(r)];l.forEach((s,c)=>s.order=c),n.attributes=l}}function zo(e){return JSON.parse(JSON.stringify(e))}function vd(e,n,o){var O;const i=o.idFactory??Pe,a=o.offset??{x:0,y:0},{logical:r,layout:l}=e,s=new Set(n);if(o.includeRelated){const A=new Set(n);for(const V of r.associations){const C=A.has(V.end1.entityRef),R=A.has(V.end2.entityRef);C!==R&&s.add(C?V.end2.entityRef:V.end1.entityRef)}}const c=r.entities.filter(A=>s.has(A.modelId)),d=new Set(c.map(A=>A.modelId)),u=r.associations.filter(A=>d.has(A.end1.entityRef)&&d.has(A.end2.entityRef)),m=new Set(u.map(A=>A.modelId)),p=new Map,f=A=>{let V=p.get(A);return V||(V=i(),p.set(A,V)),V};for(const A of c){f(A.modelId);for(const V of A.attributes){f(V.modelId);for(const C of V.dbAttrs)f(C.modelId)}for(const V of A.indexes??[])f(V.modelId);for(const V of A.operations??[])f(V.modelId)}for(const A of u)f(A.modelId);const h=A=>p.get(A),g=c.map(A=>{const V=zo(A);V.modelId=h(A.modelId),V.attributes=V.attributes.map(C=>sb(C,h,m,d));for(const C of V.indexes??[])C.modelId=h(C.modelId),C.columns=C.columns.map(R=>Xn(R.columnRef)?R:{...R,columnRef:h(R.columnRef)}).filter(R=>R.columnRef!==void 0);for(const C of V.operations??[])C.modelId=h(C.modelId);return V});Id(g);const b=u.map(A=>{const V=zo(A);return V.modelId=h(A.modelId),V.end1=Cd(V.end1,h),V.end2=Cd(V.end2,h),V}),_=[];for(const A of r.groups){const V=A.memberEntityRefs.filter(R=>d.has(R));if(V.length===0)continue;const C=zo(A);C.modelId=f(A.modelId),C.memberEntityRefs=V.map(R=>h(R)),_.push(C)}const E=o.collisionSuffix??"_imported",N=new Set(o.existing.entities.map(A=>A.name)),y=new Set(o.existing.entities.map(A=>{var V;return(V=A.table)==null?void 0:V.physicalName}).filter(A=>!!A));for(const A of g)N.has(A.name)&&(A.name=`${A.name}${E}`),(O=A.table)!=null&&O.physicalName&&y.has(A.table.physicalName)&&(A.table.physicalName=`${A.table.physicalName}${E}`);const k=[];for(const A of l.entityLayouts){const V=h(A.entityRef);if(!V)continue;const C=zo(A);C.entityRef=V,C.geo={...C.geo,location:Il(C.geo.location,a)},C.attributeStyles&&(C.attributeStyles=Na(C.attributeStyles,h)),C.operationStyles&&(C.operationStyles=Na(C.operationStyles,h)),k.push(C)}const S=[];for(const A of l.associationLayouts){const V=h(A.associationRef);if(!V)continue;const C=zo(A);C.associationRef=V,C.sourceColumnRef=A.sourceColumnRef?h(A.sourceColumnRef):void 0,C.targetColumnRef=A.targetColumnRef?h(A.targetColumnRef):void 0,C.waypoints=C.waypoints.map(R=>Il(R,a)),S.push(C)}const T=[];for(const A of l.groupLayouts){const V=h(A.groupRef);if(!V)continue;const C=zo(A);C.groupRef=V,C.geo={...C.geo,location:Il(C.geo.location,a)},delete C.memberNoteRefs,T.push(C)}return{logical:{entities:g,associations:b,groups:_},layout:{entityLayouts:k,associationLayouts:S,groupLayouts:T},idMap:p}}function Il(e,n){return{x:e.x+n.x,y:e.y+n.y}}function sb(e,n,o,i){e.modelId=n(e.modelId);for(const a of e.dbAttrs)if(a.modelId=n(a.modelId),a.sharedColumnRef!==void 0){const r=n(a.sharedColumnRef);r?a.sharedColumnRef=r:delete a.sharedColumnRef}return e.derivedFrom&&(o.has(e.derivedFrom.associationRef)?e.derivedFrom={associationRef:n(e.derivedFrom.associationRef),sourceAttributeRef:n(e.derivedFrom.sourceAttributeRef)??e.derivedFrom.sourceAttributeRef}:(delete e.derivedFrom,(e.attrType==="RELATION_OWN"||e.attrType==="RELATION_REF")&&(e.attrType="NORMAL"))),e.embedded&&(i.has(e.embedded.embeddableRef)?e.embedded={associationRef:n(e.embedded.associationRef)??e.embedded.associationRef,embeddableRef:n(e.embedded.embeddableRef)}:(delete e.embedded,e.attrType.startsWith("EMBED")&&(e.attrType="NORMAL"))),e}function Cd(e,n){return{...e,entityRef:n(e.entityRef),attributeRef:e.attributeRef?n(e.attributeRef):void 0}}function Na(e,n){const o={};for(const[i,a]of Object.entries(e)){const r=n(i);r&&(o[r]=a)}return o}function vl(e){if(!("rev"in e))return e;const{rev:n,...o}=e;return o}function ro(e,n){if(e===n||e==null&&n==null)return!0;if(e==null||n==null)return!1;if(Array.isArray(e)||Array.isArray(n))return!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length?!1:e.every((o,i)=>ro(o,n[i]));if(typeof e=="object"&&typeof n=="object"){const o=new Set([...Object.keys(e),...Object.keys(n)]);for(const i of o)if(!ro(e[i],n[i]))return!1;return!0}return!1}function lo(e,n,o){const i={},a=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of a)o.has(r)||ro(e[r],n[r])||(i[r]=n[r]===void 0?null:n[r]);return Object.keys(i).length?i:null}function so(e,n,o){const i=new Map(e.map(d=>[o(d),d])),a=new Map(n.map(d=>[o(d),d])),r=[],l=[],s=[];for(const[d,u]of a){const m=i.get(d);m?s.push({cur:m,tgt:u}):r.push(u)}for(const[d,u]of i)a.has(d)||l.push(u);const c=(d,u)=>o(d)<o(u)?-1:o(d)>o(u)?1:0;return r.sort(c),l.sort(c),s.sort((d,u)=>c(d.tgt,u.tgt)),{added:r,removed:l,common:s}}function cb(e,n){const o=new Set(e),i=new Set(n),a=n.filter(l=>!o.has(l)).sort(),r=e.filter(l=>!i.has(l)).sort();return{added:a,removed:r}}const db=new Set(["attributes","operations","indexes","rev"]),ub=new Set(["end1","end2","rev"]),mb=new Set(["memberEntityRefs","rev"]),Sd=new Set(["modelId"]),fb=new Set(["modelId","columns"]),pb=new Set([]);function hb(e,n,o,i){const a=so(n.attributes??[],o.attributes??[],s=>s.modelId);for(const s of a.removed)i.push({kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId});for(const s of a.added)i.push({kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of a.common){const d=lo(s,c,Sd);d&&i.push({kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId,patch:d})}const r=so(n.operations??[],o.operations??[],s=>s.modelId);for(const s of r.removed)i.push({kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId});for(const s of r.added)i.push({kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of r.common){const d=lo(s,c,Sd);d&&i.push({kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId,patch:d})}const l=so(n.indexes??[],o.indexes??[],s=>s.modelId);for(const s of l.removed)i.push({kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId});for(const s of l.added)i.push({kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of l.common){if(!ro(s.columns,c.columns)){i.push({kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId}),i.push({kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:c});continue}const d=lo(s,c,fb);d&&i.push({kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId,patch:d})}}function yb(e,n,o){const i=so(e.entities??[],n.entities??[],l=>l.modelId);for(const l of i.removed)o.push({kind:"entity.remove",casUnit:"logical",entityRef:l.modelId});for(const l of i.added)o.push({kind:"entity.add",casUnit:"logical",entityRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of i.common){const c=lo(l,s,db);c&&o.push({kind:"entity.update",casUnit:"logical",containerRef:l.modelId,entityRef:l.modelId,patch:c}),hb(l.modelId,l,s,o)}const a=so(e.associations??[],n.associations??[],l=>l.modelId);for(const l of a.removed)o.push({kind:"association.remove",casUnit:"logical",associationRef:l.modelId});for(const l of a.added)o.push({kind:"association.add",casUnit:"logical",associationRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of a.common){const c=lo(l,s,ub);c&&o.push({kind:"association.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,patch:c});for(const d of["end1","end2"]){const u=lo(l[d]??{},s[d]??{},pb);u&&o.push({kind:"associationEnd.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,end:d,patch:u})}}const r=so(e.groups??[],n.groups??[],l=>l.modelId);for(const l of r.removed)o.push({kind:"group.remove",casUnit:"logical",groupRef:l.modelId});for(const l of r.added)o.push({kind:"group.add",casUnit:"logical",groupRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of r.common){const c=lo(l,s,mb);c&&o.push({kind:"group.update",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,patch:c});const d=cb(l.memberEntityRefs??[],s.memberEntityRefs??[]);for(const u of d.removed)o.push({kind:"group.removeMember",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,entityRef:u});for(const u of d.added)o.push({kind:"group.addMember",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,entityRef:u})}}function wa(e,n,o,i,a,r,l){const s=so(e,n,o);for(const c of s.removed)l.push({kind:a,casUnit:"layout",[r]:o(c),value:void 0});for(const c of s.added)l.push({kind:i,casUnit:"layout",[r]:o(c),value:c});for(const{cur:c,tgt:d}of s.common)ro(c,d)||(l.push({kind:a,casUnit:"layout",[r]:o(c),value:void 0}),l.push({kind:i,casUnit:"layout",[r]:o(d),value:d}))}function gb(e,n,o){wa(e.entityLayouts??[],n.entityLayouts??[],i=>i.entityRef,"entityLayout.add","entityLayout.remove","entityRef",o),wa(e.associationLayouts??[],n.associationLayouts??[],i=>i.associationRef,"associationLayout.add","associationLayout.remove","associationRef",o),wa(e.groupLayouts??[],n.groupLayouts??[],i=>i.groupRef,"groupLayout.add","groupLayout.remove","groupRef",o),wa(e.notes??[],n.notes??[],i=>i.modelId,"note.add","note.remove","noteRef",o)}function bb(e,n){const o=[];return yb(e.logical,n.logical,o),gb(e.layout,n.layout,o),o}function _b(e){if(e.groupRef!=null)return"group";if(e.associationRef!=null)return e.end!=null?"associationEnd":"association";if(e.entityRef!=null&&e.attributeRef!=null)return"attribute";if(e.entityRef!=null&&e.operationRef!=null)return"operation";if(e.entityRef!=null&&e.indexRef!=null)return"index";if(e.entityRef!=null)return"entity";throw new Error("projectFieldAudit: 대상 로케이터가 비었습니다(entityRef/associationRef/groupRef 중 하나 필요).")}const kb={entity:new Set(["attributes","operations","indexes","rev","modelId"]),association:new Set(["end1","end2","rev","modelId"]),group:new Set(["memberEntityRefs","rev","modelId"]),attribute:new Set(["modelId"]),operation:new Set(["modelId"]),index:new Set(["modelId"]),associationEnd:new Set([])};class Eb{constructor(n){st(this,"out",[]);st(this,"last",new Map);this.fieldFilter=n}set(n,o,i){if(this.fieldFilter!=null&&o!==this.fieldFilter)return;const a=this.last.get(o);this.out.push({...bi(n),field:o,value:i,...this.last.has(o)?{oldValue:a}:{}}),this.last.set(o,i)}remove(n,o){if(o!=null){if(this.fieldFilter!=null&&o!==this.fieldFilter)return;this.out.push({...bi(n),field:o,value:void 0,removed:!0,...this.last.has(o)?{oldValue:this.last.get(o)}:{}}),this.last.delete(o);return}const i=this.fieldFilter!=null?[this.fieldFilter]:[...this.last.keys()];for(const a of i){if(!this.last.has(a)){this.out.push({...bi(n),field:a,value:void 0,removed:!0});continue}this.out.push({...bi(n),field:a,value:void 0,removed:!0,oldValue:this.last.get(a)}),this.last.delete(a)}}member(n,o,i){const a="memberEntityRefs";this.fieldFilter!=null&&a!==this.fieldFilter||this.out.push({...bi(n),field:a,value:o,...i?{removed:!0}:{}})}result(){return this.out}}function bi(e){const n={seq:e.seq};return e.ts!==void 0&&(n.ts=e.ts),e.origin!==void 0&&(n.origin=e.origin),e.author!==void 0&&(n.author=e.author),e.kind!==void 0&&(n.kind=e.kind),e.restoredFromSeq!==void 0&&(n.restoredFromSeq=e.restoredFromSeq),n}function rn(e,n,o,i){if(o==null||typeof o!="object")return;const a=kb[i];for(const[r,l]of Object.entries(o))a.has(r)||e.set(n,r,l)}function co(e,n,o){if(!(o==null||typeof o!="object"))for(const[i,a]of Object.entries(o))e.set(n,i,a)}function Cl(e,n){if(Array.isArray(e))return e.find(o=>o.modelId===n)}function Ln(e,n){var r,l,s,c,d,u,m,p;const o=_b(n),i=new Eb(n.field),a=[...e].sort((f,h)=>f.seq-h.seq);for(const f of a)for(const h of f.ops)switch(o){case"entity":if(h.entityRef!==n.entityRef)break;h.kind==="entity.add"?rn(i,f,h.value,"entity"):h.kind==="entity.update"?co(i,f,h.patch):h.kind==="entity.remove"&&i.remove(f);break;case"attribute":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((r=h.value)==null?void 0:r.attributes,n.attributeRef);g&&rn(i,f,g,"attribute")}else h.kind==="attribute.add"&&((l=h.value)==null?void 0:l.modelId)===n.attributeRef?rn(i,f,h.value,"attribute"):h.kind==="attribute.update"&&h.attributeRef===n.attributeRef?co(i,f,h.patch):(h.kind==="attribute.remove"&&h.attributeRef===n.attributeRef||h.kind==="entity.remove")&&i.remove(f);break;case"operation":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((s=h.value)==null?void 0:s.operations,n.operationRef);g&&rn(i,f,g,"operation")}else h.kind==="operation.add"&&((c=h.value)==null?void 0:c.modelId)===n.operationRef?rn(i,f,h.value,"operation"):h.kind==="operation.update"&&h.operationRef===n.operationRef?co(i,f,h.patch):(h.kind==="operation.remove"&&h.operationRef===n.operationRef||h.kind==="entity.remove")&&i.remove(f);break;case"index":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((d=h.value)==null?void 0:d.indexes,n.indexRef);g&&rn(i,f,g,"index")}else h.kind==="index.add"&&((u=h.value)==null?void 0:u.modelId)===n.indexRef?rn(i,f,h.value,"index"):h.kind==="index.update"&&h.indexRef===n.indexRef?co(i,f,h.patch):(h.kind==="index.remove"&&h.indexRef===n.indexRef||h.kind==="entity.remove")&&i.remove(f);break;case"association":if(h.associationRef!==n.associationRef)break;h.kind==="association.add"?rn(i,f,h.value,"association"):h.kind==="association.update"?co(i,f,h.patch):h.kind==="association.remove"&&i.remove(f);break;case"associationEnd":if(h.associationRef!==n.associationRef)break;if(h.kind==="association.add"){const g=(m=h.value)==null?void 0:m[n.end];rn(i,f,g,"associationEnd")}else h.kind==="associationEnd.update"&&h.end===n.end?co(i,f,h.patch):h.kind==="association.remove"&&i.remove(f);break;case"group":if(h.groupRef!==n.groupRef)break;if(h.kind==="group.add"){rn(i,f,h.value,"group");const g=(p=h.value)==null?void 0:p.memberEntityRefs;if(Array.isArray(g))for(const b of g)i.member(f,b,!1)}else h.kind==="group.update"?co(i,f,h.patch):h.kind==="group.remove"?i.remove(f):h.kind==="group.addMember"&&h.entityRef!=null?i.member(f,h.entityRef,!1):h.kind==="group.removeMember"&&h.entityRef!=null&&i.member(f,h.entityRef,!0);break}return i.result()}const rt={subject:null,existence:null,fieldAudit:!1,note:"레이아웃 축(LWW) — 감사·복원 diff는 논리 축 전용(AA-5: layout/note는 의도적 범위 밖)"},Nb={"entity.add":{subject:"entity",existence:"add",fieldAudit:!0},"entity.update":{subject:"entity",existence:null,fieldAudit:!0},"entity.remove":{subject:"entity",existence:"remove",fieldAudit:!0},"attribute.add":{subject:"attribute",existence:"add",fieldAudit:!0},"attribute.update":{subject:"attribute",existence:null,fieldAudit:!0},"attribute.remove":{subject:"attribute",existence:"remove",fieldAudit:!0},"operation.add":{subject:"operation",existence:"add",fieldAudit:!0},"operation.update":{subject:"operation",existence:null,fieldAudit:!0},"operation.remove":{subject:"operation",existence:"remove",fieldAudit:!0},"index.add":{subject:"index",existence:"add",fieldAudit:!0},"index.update":{subject:"index",existence:null,fieldAudit:!0},"index.remove":{subject:"index",existence:"remove",fieldAudit:!0},"attribute.reorder":{subject:null,existence:null,fieldAudit:!1,note:"과거 어휘(호스트 지원·lib 미방출). 컬렉션 순서 축이라 subject 단위 필드 변경으로 표현 안 됨"},"operation.reorder":{subject:null,existence:null,fieldAudit:!1,note:"과거 어휘(호스트 지원·lib 미방출). attribute.reorder와 동형"},"association.add":{subject:"association",existence:"add",fieldAudit:!0},"association.update":{subject:"association",existence:null,fieldAudit:!0},"association.remove":{subject:"association",existence:"remove",fieldAudit:!0},"associationEnd.update":{subject:"associationEnd",existence:null,fieldAudit:!0},"group.add":{subject:"group",existence:"add",fieldAudit:!0},"group.update":{subject:"group",existence:null,fieldAudit:!0},"group.remove":{subject:"group",existence:"remove",fieldAudit:!0},"group.addMember":{subject:"group",existence:null,fieldAudit:!0},"group.removeMember":{subject:"group",existence:null,fieldAudit:!0},"entityLayout.add":rt,"entityLayout.remove":rt,"entityLayout.move":rt,"entityLayout.resize":rt,"entityLayout.setCollapsed":rt,"entityLayout.setLocked":rt,"entityLayout.setStyle":rt,"entityLayout.setAttrStyle":rt,"entityLayout.setOpStyle":rt,"groupLayout.add":rt,"groupLayout.remove":rt,"groupLayout.move":rt,"groupLayout.resize":rt,"groupLayout.setLocked":rt,"groupLayout.setStyle":rt,"groupLayout.addNoteMember":rt,"groupLayout.removeNoteMember":rt,"associationLayout.add":rt,"associationLayout.remove":rt,"associationLayout.setWaypoints":rt,"note.add":rt,"note.remove":rt,"note.move":rt,"note.resize":rt,"note.setMemo":rt,"note.setStyle":rt,"noteConnection.add":rt,"noteConnection.remove":rt,"noteConnection.setWaypoints":rt},jt=e=>typeof e=="string"?e:void 0,wb=e=>{var n;return jt((n=e.value)==null?void 0:n.modelId)};function xd(e){return jt(e.containerRef)??jt(e.entityRef)}function Sl(e,n,o,i){var l;const a=(l=e.value)==null?void 0:l[n];if(!Array.isArray(a))return[];const r=[];for(const s of a){const c=jt(s.modelId);c&&r.push({subject:{kind:o,ref:c,...i?{entityRef:i}:{}},existence:"add",inline:!0})}return r}function xl(e){const n=Nb[e.kind];if(!n||!n.subject)return[];const o=e,i=n.existence??void 0;switch(n.subject){case"entity":{const a=jt(o.entityRef);if(!a)return[];const r={subject:{kind:"entity",ref:a},...i?{existence:i}:{}};return e.kind!=="entity.add"?[r]:[r,...Sl(o,"attributes","attribute",a),...Sl(o,"operations","operation",a),...Sl(o,"indexes","index",a)]}case"attribute":case"operation":case"index":{const a=n.subject,r=xd(o),l={attribute:"attributeRef",operation:"operationRef",index:"indexRef"}[a],s=i==="add"?wb(o):jt(o[l]);return s?[{subject:{kind:a,ref:s,...r?{entityRef:r}:{}},...i?{existence:i}:{}}]:[]}case"association":case"associationEnd":{const a=jt(o.associationRef);if(!a)return[];const r=o.end==="end1"||o.end==="end2"?o.end:void 0;return[{subject:{kind:n.subject,ref:a,...r?{end:r}:{}},...i?{existence:i}:{}}]}case"group":{const a=jt(o.groupRef);return a?[{subject:{kind:"group",ref:a},...i?{existence:i}:{}}]:[]}}}function Ib(e){const n=e,o=e.kind;if(o.startsWith("entity.")){const i=jt(n.entityRef);return i?{kind:"entity",ref:i}:null}if(o.startsWith("attribute.")||o.startsWith("operation.")||o.startsWith("index.")){const i=xd(n);return i?{kind:"entity",ref:i}:null}if(o.startsWith("associationEnd.")||o.startsWith("association.")){const i=jt(n.associationRef);return i?{kind:"association",ref:i}:null}if(o.startsWith("group.")){const i=jt(n.groupRef);return i?{kind:"group",ref:i}:null}return null}function vb(e,n){const o=e;return o.entityRef===n||o.containerRef===n}function Cb(e,n){const o=new Set,i=new Set,a=new Set,r={attribute:o,operation:i,index:a};for(const l of e)for(const s of l.ops)for(const{subject:c}of xl(s))c.kind==="entity"||c.entityRef!==n||c.kind in r&&r[c.kind].add(c.ref);return{attributes:o,operations:i,indexes:a}}function Ia(e,n){return e.map(o=>({...o,subject:n}))}function Rd(e,n){const o=e.filter(s=>s.ops.some(c=>vb(c,n))),{attributes:i,operations:a,indexes:r}=Cb(o,n),l=[...Ia(Ln(o,{entityRef:n}),{kind:"entity",ref:n})];for(const s of i)l.push(...Ia(Ln(o,{entityRef:n,attributeRef:s}),{kind:"attribute",ref:s}));for(const s of a)l.push(...Ia(Ln(o,{entityRef:n,operationRef:s}),{kind:"operation",ref:s}));for(const s of r)l.push(...Ia(Ln(o,{entityRef:n,indexRef:s}),{kind:"index",ref:s}));return l.map((s,c)=>({e:s,i:c})).sort((s,c)=>s.e.seq-c.e.seq||s.i-c.i).map(({e:s})=>s)}function Rl(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Sb(e){const n=new Set;for(const o of e)for(const i of o.ops)for(const a of xl(i))a.existence==="add"&&n.add(Rl(a.subject));return n}function xb(e){const n=new Set,o=new Set,i=new Set,a={entity:n,association:o,group:i};for(const r of e)for(const l of r.ops){const s=Ib(l);s&&a[s.kind].add(s.ref)}return{entities:n,associations:o,groups:i}}function Rb(e){const{entities:n,associations:o,groups:i}=xb(e),a=[];for(const r of n)for(const l of Rd(e,r))a.push({...l,subject:{...l.subject,entityRef:r}});for(const r of o){for(const l of Ln(e,{associationRef:r}))a.push({...l,subject:{kind:"association",ref:r}});for(const l of["end1","end2"])for(const s of Ln(e,{associationRef:r,end:l}))a.push({...s,subject:{kind:"associationEnd",ref:r,end:l}})}for(const r of i)for(const l of Ln(e,{groupRef:r}))a.push({...l,subject:{kind:"group",ref:r}});return a}function Al(e){const n=Rb(e),o=Sb(e),i=new Map;for(const l of n){const s=Rl(l.subject),c=i.get(s);(c===void 0||l.seq<c)&&i.set(s,l.seq)}const a=new Map;for(const l of n){let s=a.get(l.seq);s||(s={meta:l,subjects:new Map},a.set(l.seq,s));const c=Rl(l.subject);let d=s.subjects.get(c);if(!d){const u=l.removed?"remove":i.get(c)===l.seq&&o.has(c)?"add":"update";d={subject:l.subject,verb:u,fields:[]},s.subjects.set(c,d)}l.removed?d.verb="remove":d.fields.push({field:l.field,value:l.value,...l.oldValue!==void 0?{oldValue:l.oldValue}:{}})}const r=[];for(const[l,s]of a){const c=s.meta;r.push({seq:l,...c.ts!==void 0?{ts:c.ts}:{},...c.origin!==void 0?{origin:c.origin}:{},...c.author!==void 0?{author:c.author}:{},...c.kind!==void 0?{kind:c.kind}:{},...c.restoredFromSeq!==void 0?{restoredFromSeq:c.restoredFromSeq}:{},actions:[...s.subjects.values()]})}return r.sort((l,s)=>s.seq-l.seq)}function Ad(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Ab(e,n,o){const i=[];for(const a of e)if(!(a.seq<=n||a.seq>o))for(const r of a.ops)for(const l of xl(r)){if(!l.existence||l.inline)continue;const s=l.subject;$b.has(s.kind)&&!s.entityRef||i.push({seq:a.seq,subject:s,verb:l.existence,fields:[]})}return i}const $b=new Set(["attribute","operation","index"]);function $l(e,n){const{fromSeq:o}=n,i=Al(e);let a=o;for(const m of e)m.seq>a&&(a=m.seq);const r=n.toSeq??a,l=i.filter(m=>m.seq>o&&m.seq<=r).reverse(),s=new Map,c=m=>{const p=Ad(m.subject);let f=s.get(p);f||(f={subject:m.subject,evs:[]},s.set(p,f)),f.evs.push(m)};for(const m of l)for(const p of m.actions)c({seq:m.seq,subject:p.subject,verb:p.verb,fields:p.fields});for(const m of Ab(e,o,r)){const p=s.get(Ad(m.subject));p!=null&&p.evs.some(f=>f.seq===m.seq)||c(m)}const d=[],u=new Set;for(const m of s.values()){m.evs.sort((f,h)=>f.seq-h.seq);const p=m.evs[m.evs.length-1];m.subject.kind==="entity"&&p.verb==="remove"&&u.add(m.subject.ref)}for(const m of s.values()){const p=m.evs[0].verb==="add",f=m.evs[m.evs.length-1].verb==="remove";if(m.subject.kind!=="entity"&&m.subject.entityRef&&u.has(m.subject.entityRef)||p&&f)continue;const h=new Map;let g=null;for(const _ of m.evs){_.verb==="add"&&g!==null&&g!=="add"&&h.clear(),g=_.verb;for(const E of _.fields){const N=h.get(E.field);N?N.lastValue=E.value:h.set(E.field,{firstOld:E.oldValue,hasOld:E.oldValue!==void 0,lastValue:E.value})}}if(f){d.push({subject:m.subject,verb:"removed",fields:[]});continue}if(p){const _=[];for(const[E,N]of h)_.push({field:E,value:N.lastValue});d.push({subject:m.subject,verb:"added",fields:_});continue}const b=[];for(const[_,E]of h)E.hasOld&&ro(E.firstOld,E.lastValue)||b.push({field:_,value:E.lastValue,...E.hasOld?{oldValue:E.firstOld}:{}});b.length!==0&&d.push({subject:m.subject,verb:"modified",fields:b})}return{fromSeq:o,toSeq:r,entries:d}}function $d(e){const n=new Map,o=i=>{let a=n.get(i);return a||(a={verb:"modified",changedAttributeIds:new Set,changedOperationIds:new Set},n.set(i,a)),a};for(const i of e.entries){const a=i.subject;if(a.kind==="entity"){if(i.verb==="removed")continue;o(a.ref).verb=i.verb}else if((a.kind==="attribute"||a.kind==="operation"||a.kind==="index")&&a.entityRef){const r=o(a.entityRef);i.verb!=="removed"&&(a.kind==="attribute"?r.changedAttributeIds.add(a.ref):a.kind==="operation"&&r.changedOperationIds.add(a.ref))}}return n}class Tl{constructor(n){st(this,"undoStack",[]);st(this,"redoStack",[]);st(this,"savePoint",null);st(this,"listeners",new Set);st(this,"commandListeners",new Set);st(this,"coalesceSealed",!1);this.state=n}execute(n){n.apply(this.state);const o=this.undoStack.at(-1),i=!this.coalesceSealed&&n.coalesceKey!=null&&!!o&&o.coalesceKey===n.coalesceKey;this.coalesceSealed=!1,i?(n.invert=o.invert,this.undoStack[this.undoStack.length-1]=n):this.undoStack.push(n),this.redoStack=[],this.emitCommand(n,"do",i),this.emit()}undo(){const n=this.undoStack.pop();n&&(n.invert(this.state),this.redoStack.push(n),this.emitCommand(n,"undo",!1),this.emit())}redo(){const n=this.redoStack.pop();n&&(n.apply(this.state),this.undoStack.push(n),this.emitCommand(n,"redo",!1),this.emit())}sealCoalesce(){this.coalesceSealed=!0}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}markSavePoint(){this.savePoint=this.undoStack.at(-1)??null,this.sealCoalesce(),this.emit()}get isDirty(){return(this.undoStack.at(-1)??null)!==this.savePoint}onChange(n){return this.listeners.add(n),()=>this.listeners.delete(n)}onCommand(n){return this.commandListeners.add(n),()=>this.commandListeners.delete(n)}emit(){for(const n of this.listeners)n()}emitCommand(n,o,i){for(const a of this.commandListeners)a(n,o,i)}}function Bt(e){const n={};for(const[o,i]of Object.entries(e))n[o]=i===void 0?null:i;return n}function Td(e,n){return e.logical.entities.findIndex(o=>o.modelId===n)}function Nt(e,n){return e.layout.entityLayouts.findIndex(o=>o.entityRef===n)}function Kt(e,n){return e.layout.associationLayouts.find(o=>o.associationRef===n)}function dt(e,n){const o=e.logical.entities.find(i=>i.modelId===n);if(!o)throw new Error(`엔티티 없음: ${n}`);return o}function En(e,n,o){var i,a;return(a=(i=e.layout.notes.find(r=>r.modelId===n))==null?void 0:i.connections)==null?void 0:a.find(r=>r.targetRef===o)}function va(e,n,o){return{label:`엔티티 추가: ${e.name}`,apply(i){i.logical.entities.push(e),i.layout.entityLayouts.push({entityRef:e.modelId,geo:n,...o})},invert(i){const a=Td(i,e.modelId);a>=0&&i.logical.entities.splice(a,1);const r=Nt(i,e.modelId);r>=0&&i.layout.entityLayouts.splice(r,1)},emitOps(){const i={kind:"entity.add",casUnit:"logical",entityRef:e.modelId,value:e},a={kind:"entityLayout.add",casUnit:"layout",entityRef:e.modelId,value:{entityRef:e.modelId,geo:n,...o},incidental:!0};return{forward:[i,a],invert:[{kind:"entityLayout.remove",casUnit:"layout",entityRef:e.modelId,incidental:!0},{kind:"entity.remove",casUnit:"logical",entityRef:e.modelId}]}}}}function Md(e){let n=null;const o=i=>i.end1.entityRef===e||i.end2.entityRef===e;return{label:"엔티티 삭제",apply(i){const a=Td(i,e);if(a<0)throw new Error(`엔티티 없음: ${e}`);const r=Nt(i,e),l=[];i.logical.associations.forEach((u,m)=>{o(u)&&l.push({item:u,index:m})});const s=new Set(l.map(u=>u.item.modelId)),c=[];i.layout.associationLayouts.forEach((u,m)=>{s.has(u.associationRef)&&c.push({item:u,index:m})});const d=[];i.logical.groups.forEach(u=>{const m=u.memberEntityRefs.indexOf(e);m>=0&&d.push({groupId:u.modelId,index:m})}),n={entity:{item:i.logical.entities[a],index:a},entityLayout:r>=0?{item:i.layout.entityLayouts[r],index:r}:void 0,assocs:l,assocLayouts:c,groupMemberships:d},[...c].sort((u,m)=>m.index-u.index).forEach(u=>i.layout.associationLayouts.splice(u.index,1)),[...l].sort((u,m)=>m.index-u.index).forEach(u=>i.logical.associations.splice(u.index,1));for(const u of d){const m=i.logical.groups.find(p=>p.modelId===u.groupId);m==null||m.memberEntityRefs.splice(u.index,1)}r>=0&&i.layout.entityLayouts.splice(r,1),i.logical.entities.splice(a,1)},invert(i){if(n){i.logical.entities.splice(n.entity.index,0,n.entity.item),n.entityLayout&&i.layout.entityLayouts.splice(n.entityLayout.index,0,n.entityLayout.item),[...n.assocs].sort((a,r)=>a.index-r.index).forEach(a=>i.logical.associations.splice(a.index,0,a.item)),[...n.assocLayouts].sort((a,r)=>a.index-r.index).forEach(a=>i.layout.associationLayouts.splice(a.index,0,a.item));for(const a of n.groupMemberships){const r=i.logical.groups.find(l=>l.modelId===a.groupId);r==null||r.memberEntityRefs.splice(a.index,0,e)}}},emitOps(){if(!n)return{forward:[],invert:[]};const i=[],a=[];for(const r of n.assocs)i.push({kind:"association.remove",casUnit:"logical",associationRef:r.item.modelId}),a.push({kind:"association.add",casUnit:"logical",associationRef:r.item.modelId,value:r.item});for(const r of n.assocLayouts)i.push({kind:"associationLayout.remove",casUnit:"layout",associationRef:r.item.associationRef,incidental:!0}),a.push({kind:"associationLayout.add",casUnit:"layout",associationRef:r.item.associationRef,value:r.item,incidental:!0});for(const r of n.groupMemberships)i.push({kind:"group.removeMember",casUnit:"logical",containerRef:r.groupId,groupRef:r.groupId,entityRef:e}),a.push({kind:"group.addMember",casUnit:"logical",containerRef:r.groupId,groupRef:r.groupId,entityRef:e});return n.entityLayout&&(i.push({kind:"entityLayout.remove",casUnit:"layout",entityRef:e,incidental:!0}),a.push({kind:"entityLayout.add",casUnit:"layout",entityRef:e,value:n.entityLayout.item,incidental:!0})),i.push({kind:"entity.remove",casUnit:"logical",entityRef:e}),a.push({kind:"entity.add",casUnit:"logical",entityRef:e,value:n.entity.item}),{forward:i,invert:a.reverse()}}}}function Ml(e,n){const o={};return{label:"엔티티 수정",apply(i){const a=dt(i,e);for(const r of Object.keys(n))o[r]=a[r];Object.assign(a,n)},invert(i){Object.assign(dt(i,e),o)},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:Bt(n)}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:Bt(o)}]}}}}function Vd(e,n){let o="";return{label:`엔티티 이름 변경: ${n}`,apply(i){const a=dt(i,e);o=a.name,a.name=n},invert(i){dt(i,e).name=o},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:{name:n}}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:{name:o}}]}}}}function Fo(e,n){let o=null;return{label:"엔티티 이동",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a].geo;o={...r.location},r.location={...n}},invert(i){const a=Nt(i,e);a>=0&&o&&(i.layout.entityLayouts[a].geo.location=o)},emitOps(){const i=a=>({kind:"entityLayout.move",casUnit:"layout",entityRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function Bd(e,n){let o=null;return{label:"엔티티 크기 변경",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a].geo;o={...r.size},r.size={...n}},invert(i){const a=Nt(i,e);a>=0&&o&&(i.layout.entityLayouts[a].geo.size=o)},emitOps(){const i=a=>({kind:"entityLayout.resize",casUnit:"layout",entityRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function _i(e,n){const o={...(e==null?void 0:e.properties)??{}};return n?o.swatch=n:delete o.swatch,Object.keys(o).length?{properties:o}:void 0}function Dd(e,n){let o;return{label:"엔티티 색상 변경",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.style,r.style=_i(r.style,n)},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].style=o)},emitOps(i){const a=Nt(i,e),r=a>=0?i.layout.entityLayouts[a].style:void 0,l=s=>({kind:"entityLayout.setStyle",casUnit:"layout",entityRef:e,value:{style:s}});return{forward:[l(r)],invert:[l(o)]}}}}function Od(e,n){let o;return{label:n?"엔티티 접기":"엔티티 펼치기",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.collapsed,r.collapsed=n},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].collapsed=o)},emitOps(){const i=a=>({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:e,value:{collapsed:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Ld(e,n){let o;return{label:n?"엔티티 잠금":"엔티티 잠금 해제",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.locked,r.locked=n},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].locked=o)},emitOps(){const i=a=>({kind:"entityLayout.setLocked",casUnit:"layout",entityRef:e,value:{locked:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Vl(e){let n=[];return{label:e?"모두 접기":"모두 펼치기",apply(o){n=o.layout.entityLayouts.map(i=>i.collapsed);for(const i of o.layout.entityLayouts)i.collapsed=e},invert(o){o.layout.entityLayouts.forEach((i,a)=>{i.collapsed=n[a]})},emitOps(o){const i=[],a=[];return o.layout.entityLayouts.forEach((r,l)=>{i.push({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:r.entityRef,value:{collapsed:e}}),a.push({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:r.entityRef,value:{collapsed:n[l]}})}),{forward:i,invert:a}}}}function Ca(e,n,o){let i;return{label:"속성 색상 변경",apply(a){const r=Nt(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.attributeStyles;const s={...l.attributeStyles},c=_i(s[n],o);c?s[n]=c:delete s[n],l.attributeStyles=Object.keys(s).length?s:void 0},invert(a){const r=Nt(a,e);r>=0&&(a.layout.entityLayouts[r].attributeStyles=i)},emitOps(a){const r=Nt(a,e),l=r>=0?a.layout.entityLayouts[r].attributeStyles:void 0,s=c=>({kind:"entityLayout.setAttrStyle",casUnit:"layout",entityRef:e,value:{attributeStyles:c}});return{forward:[s(l)],invert:[s(i)]}}}}function Sa(e,n,o){return{label:"그룹 추가",apply(i){i.logical.groups.push(e),i.layout.groupLayouts.push({groupRef:e.modelId,geo:n,...o})},invert(i){const a=i.logical.groups.findIndex(l=>l.modelId===e.modelId);a>=0&&i.logical.groups.splice(a,1);const r=i.layout.groupLayouts.findIndex(l=>l.groupRef===e.modelId);r>=0&&i.layout.groupLayouts.splice(r,1)},emitOps(){const i={kind:"group.add",casUnit:"logical",groupRef:e.modelId,value:e},a={kind:"groupLayout.add",casUnit:"layout",groupRef:e.modelId,value:{groupRef:e.modelId,geo:n,...o},incidental:!0};return{forward:[i,a],invert:[{kind:"groupLayout.remove",casUnit:"layout",groupRef:e.modelId,incidental:!0},{kind:"group.remove",casUnit:"logical",groupRef:e.modelId}]}}}}function Pd(e,n){const o={},i=a=>{const r=a.logical.groups.find(l=>l.modelId===e);if(!r)throw new Error(`그룹 없음: ${e}`);return r};return{label:"그룹 수정",apply(a){const r=i(a);for(const l of Object.keys(n))o[l]=r[l];Object.assign(r,n)},invert(a){Object.assign(i(a),o)},emitOps(){return{forward:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:Bt(n)}],invert:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:Bt(o)}]}}}}function zd(e){let n=null;return{label:"그룹 해제",apply(o){const i=o.logical.groups.findIndex(r=>r.modelId===e);if(i<0)throw new Error(`그룹 없음: ${e}`);const a=o.layout.groupLayouts.findIndex(r=>r.groupRef===e);n={group:{item:o.logical.groups[i],index:i},layout:a>=0?{item:o.layout.groupLayouts[a],index:a}:void 0},a>=0&&o.layout.groupLayouts.splice(a,1),o.logical.groups.splice(i,1)},invert(o){n&&(o.logical.groups.splice(n.group.index,0,n.group.item),n.layout&&o.layout.groupLayouts.splice(n.layout.index,0,n.layout.item))},emitOps(){if(!n)return{forward:[],invert:[]};const o=[],i=[];return n.layout&&(o.push({kind:"groupLayout.remove",casUnit:"layout",groupRef:e,incidental:!0}),i.push({kind:"groupLayout.add",casUnit:"layout",groupRef:e,value:n.layout.item,incidental:!0})),o.push({kind:"group.remove",casUnit:"logical",groupRef:e}),i.push({kind:"group.add",casUnit:"logical",groupRef:e,value:n.group.item}),{forward:o,invert:i.reverse()}}}}function Fd(e,n){let o=!1;const i=a=>a.logical.groups.find(r=>r.modelId===e);return{label:"그룹에 편입",apply(a){const r=i(a);r&&!r.memberEntityRefs.includes(n)&&(r.memberEntityRefs.push(n),o=!0)},invert(a){if(!o)return;const r=i(a),l=(r==null?void 0:r.memberEntityRefs.indexOf(n))??-1;l>=0&&r.memberEntityRefs.splice(l,1)},emitOps(){return o?{forward:[{kind:"group.addMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}],invert:[{kind:"group.removeMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}]}:{forward:[],invert:[]}}}}function xa(e,n){let o=-1;const i=a=>a.logical.groups.find(r=>r.modelId===e);return{label:"그룹에서 제외",apply(a){const r=i(a);o=(r==null?void 0:r.memberEntityRefs.indexOf(n))??-1,o>=0&&r.memberEntityRefs.splice(o,1)},invert(a){var r;o<0||(r=i(a))==null||r.memberEntityRefs.splice(o,0,n)},emitOps(){return o<0?{forward:[],invert:[]}:{forward:[{kind:"group.removeMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}],invert:[{kind:"group.addMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}]}}}}function Ud(e,n){let o=null;return{label:"그룹 이동",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o={...a.geo.location},a.geo.location={...n}},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&o&&(a.geo.location=o)},emitOps(){const i=a=>({kind:"groupLayout.move",casUnit:"layout",groupRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function Hd(e,n){let o=null;return{label:"그룹 크기 변경",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o={...a.geo.size},a.geo.size={...n}},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&o&&(a.geo.size=o)},emitOps(){const i=a=>({kind:"groupLayout.resize",casUnit:"layout",groupRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function jd(e,n){let o;return{label:"그룹 색상 변경",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o=a.style,a.style=_i(a.style,n)},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&(a.style=o)},emitOps(i){const a=i.layout.groupLayouts.find(l=>l.groupRef===e),r=l=>({kind:"groupLayout.setStyle",casUnit:"layout",groupRef:e,value:{style:l}});return{forward:[r(a==null?void 0:a.style)],invert:[r(o)]}}}}function Kd(e,n){let o;return{label:n?"그룹 잠금":"그룹 잠금 해제",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o=a.locked,a.locked=n},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&(a.locked=o)},emitOps(){const i=a=>({kind:"groupLayout.setLocked",casUnit:"layout",groupRef:e,value:{locked:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Gt(e,n){return{label:`속성 추가: ${n.name}`,apply(o){dt(o,e).attributes.push(n)},invert(o){const i=dt(o,e),a=i.attributes.findIndex(r=>r.modelId===n.modelId);a>=0&&i.attributes.splice(a,1)},emitOps(){return{forward:[{kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n.modelId}]}}}}function Yt(e,n,o){const i={},a=r=>{const l=dt(r,e).attributes.find(s=>s.modelId===n);if(!l)throw new Error(`속성 없음: ${n}`);return l};return{label:"속성 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:Bt(o)}],invert:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:Bt(i)}]}}}}function Gd(e,n){let o=null;return{label:"속성 삭제",apply(i){const a=dt(i,e),r=a.attributes.findIndex(l=>l.modelId===n);if(r<0)throw new Error(`속성 없음: ${n}`);o={item:a.attributes[r],index:r},a.attributes.splice(r,1)},invert(i){o&&dt(i,e).attributes.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n}],invert:[{kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}function Yd(e,n,o,i,a){const r=new Map(a.map(c=>[c.modelId,c.order])),l=[],s=[];for(const c of i){const d=r.get(c.modelId);if(d===c.order)continue;const u=n==="attributeRef"?{attributeRef:c.modelId}:{operationRef:c.modelId};l.push({kind:e,casUnit:"logical",containerRef:o,entityRef:o,...u,patch:{order:c.order}}),s.push({kind:e,casUnit:"logical",containerRef:o,entityRef:o,...u,patch:{order:d??c.order}})}return{forward:l,invert:s}}function Bl(e,n,o){let i=null;return{label:"속성 재정렬",apply(a){const r=dt(a,e);i=r.attributes.map(s=>({...s}));const l=wl([...r.attributes].sort((s,c)=>s.order-c.order),n,o);r.attributes.splice(0,r.attributes.length,...l),r.attributes.forEach((s,c)=>s.order=c)},invert(a){i&&dt(a,e).attributes.splice(0,1/0,...i)},emitOps(a){const r=dt(a,e).attributes;return Yd("attribute.update","attributeRef",e,r,i??[])}}}function qd(e,n){let o=!1;return{label:`메서드 추가: ${n.name}`,apply(i){const a=dt(i,e);a.operations||(a.operations=[],o=!0),a.operations.push(n)},invert(i){var l;const a=dt(i,e),r=((l=a.operations)==null?void 0:l.findIndex(s=>s.modelId===n.modelId))??-1;r>=0&&a.operations.splice(r,1),o&&a.operations&&a.operations.length===0&&(a.operations=void 0)},emitOps(){return{forward:[{kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n.modelId}]}}}}function Wd(e,n,o){const i={},a=r=>{var s;const l=(s=dt(r,e).operations)==null?void 0:s.find(c=>c.modelId===n);if(!l)throw new Error(`메서드 없음: ${n}`);return l};return{label:"메서드 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:Bt(o)}],invert:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:Bt(i)}]}}}}function Jd(e,n){let o=null;return{label:"메서드 삭제",apply(i){var s;const a=dt(i,e),r=((s=a.operations)==null?void 0:s.findIndex(c=>c.modelId===n))??-1;if(r<0)throw new Error(`메서드 없음: ${n}`);const l=a.operations.length===1;o={item:a.operations[r],index:r,wasSole:l},a.operations.splice(r,1),l&&(a.operations=void 0)},invert(i){if(!o)return;const a=dt(i,e);a.operations||(a.operations=[]),a.operations.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n}],invert:[{kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}function Xd(e,n,o){let i=null;return{label:"메서드 재정렬",apply(a){const r=dt(a,e),l=r.operations??[];i=l.map(c=>({...c}));const s=wl([...l].sort((c,d)=>c.order-d.order),n,o);l.splice(0,l.length,...s),l.forEach((c,d)=>c.order=d),r.operations=l},invert(a){if(!i)return;const r=dt(a,e);r.operations&&r.operations.splice(0,1/0,...i)},emitOps(a){const r=dt(a,e).operations??[];return Yd("operation.update","operationRef",e,r,i??[])}}}function Zd(e,n,o){let i;return{label:"메서드 색상 변경",apply(a){const r=Nt(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.operationStyles;const s={...l.operationStyles},c=_i(s[n],o);c?s[n]=c:delete s[n],l.operationStyles=Object.keys(s).length?s:void 0},invert(a){const r=Nt(a,e);r>=0&&(a.layout.entityLayouts[r].operationStyles=i)},emitOps(a){const r=Nt(a,e),l=r>=0?a.layout.entityLayouts[r].operationStyles:void 0,s=c=>({kind:"entityLayout.setOpStyle",casUnit:"layout",entityRef:e,value:{operationStyles:c}});return{forward:[s(l)],invert:[s(i)]}}}}function Ra(e,n){return{label:"관계 추가",apply(o){o.logical.associations.push(e),o.layout.associationLayouts.push(n)},invert(o){const i=o.logical.associations.findIndex(r=>r.modelId===e.modelId);i>=0&&o.logical.associations.splice(i,1);const a=o.layout.associationLayouts.findIndex(r=>r.associationRef===e.modelId);a>=0&&o.layout.associationLayouts.splice(a,1)},emitOps(){const o={kind:"association.add",casUnit:"logical",associationRef:e.modelId,value:e},i={kind:"associationLayout.add",casUnit:"layout",associationRef:e.modelId,value:n,incidental:!0};return{forward:[o,i],invert:[{kind:"associationLayout.remove",casUnit:"layout",associationRef:e.modelId,incidental:!0},{kind:"association.remove",casUnit:"logical",associationRef:e.modelId}]}}}}function Qd(e){let n=null;return{label:"관계 삭제",apply(o){const i=o.logical.associations.findIndex(r=>r.modelId===e);if(i<0)throw new Error(`관계 없음: ${e}`);const a=o.layout.associationLayouts.findIndex(r=>r.associationRef===e);n={assoc:{item:o.logical.associations[i],index:i},layout:a>=0?{item:o.layout.associationLayouts[a],index:a}:void 0},a>=0&&o.layout.associationLayouts.splice(a,1),o.logical.associations.splice(i,1)},invert(o){n&&(o.logical.associations.splice(n.assoc.index,0,n.assoc.item),n.layout&&o.layout.associationLayouts.splice(n.layout.index,0,n.layout.item))},emitOps(){if(!n)return{forward:[],invert:[]};const o=[],i=[];return n.layout&&(o.push({kind:"associationLayout.remove",casUnit:"layout",associationRef:e,incidental:!0}),i.push({kind:"associationLayout.add",casUnit:"layout",associationRef:e,value:n.layout.item,incidental:!0})),o.push({kind:"association.remove",casUnit:"logical",associationRef:e}),i.push({kind:"association.add",casUnit:"logical",associationRef:e,value:n.assoc.item}),{forward:o,invert:i.reverse()}}}}function Aa(e,n){const o={},i=a=>{const r=a.logical.associations.find(l=>l.modelId===e);if(!r)throw new Error(`관계 없음: ${e}`);return r};return{label:"관계 수정",apply(a){const r=i(a);for(const l of Object.keys(n))o[l]=r[l];Object.assign(r,n)},invert(a){Object.assign(i(a),o)},emitOps(){return{forward:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:Bt(n)}],invert:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:Bt(o)}]}}}}function qt(e,n,o){const i={},a=r=>{const l=r.logical.associations.find(s=>s.modelId===e);if(!l)throw new Error(`관계 없음: ${e}`);return l[n]};return{label:"관계 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:Bt(o)}],invert:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:Bt(i)}]}}}}function eu(e,n){return{label:"인덱스 추가",apply(o){const i=dt(o,e);(i.indexes??(i.indexes=[])).push(n)},invert(o){var r;const i=dt(o,e),a=((r=i.indexes)==null?void 0:r.findIndex(l=>l.modelId===n.modelId))??-1;a>=0&&i.indexes.splice(a,1)},emitOps(){return{forward:[{kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n.modelId}]}}}}function $a(e,n,o){const i={},a=r=>{var s;const l=(s=dt(r,e).indexes)==null?void 0:s.find(c=>c.modelId===n);if(!l)throw new Error(`인덱스 없음: ${n}`);return l};return{label:"인덱스 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:Bt(o)}],invert:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:Bt(i)}]}}}}function tu(e,n){let o=null;return{label:"인덱스 삭제",apply(i){var l;const a=dt(i,e),r=((l=a.indexes)==null?void 0:l.findIndex(s=>s.modelId===n))??-1;if(r<0)throw new Error(`인덱스 없음: ${n}`);o={item:a.indexes[r],index:r},a.indexes.splice(r,1)},invert(i){o&&dt(i,e).indexes.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n}],invert:[{kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}const ln=(e,n)=>({kind:"associationLayout.setWaypoints",casUnit:"layout",associationRef:e,value:{waypoints:n}}),ki=(e,n)=>{var o;return((o=Kt(e,n))==null?void 0:o.waypoints.map(i=>({...i})))??[]};function nu(e,n,o){let i=null;return{label:"waypoint 이동",coalesceKey:`waypoint:${e}`,apply(a){const r=Kt(a,e);if(!r||!r.waypoints[n])throw new Error(`waypoint 없음: ${e}[${n}]`);i={...r.waypoints[n]},r.waypoints.splice(n,1,{...o})},invert(a){const r=Kt(a,e);r&&i&&r.waypoints.splice(n,1,i)},emitOps(a){const r=ki(a,e),l=r.map((s,c)=>c===n&&i?{...i}:s);return{forward:[ln(e,r)],invert:[ln(e,l)]}}}}function ou(e,n){let o=null;return{label:"waypoint 제거",apply(i){const a=Kt(i,e);if(!a||!a.waypoints[n])throw new Error(`waypoint 없음: ${e}[${n}]`);o={...a.waypoints[n]},a.waypoints.splice(n,1)},invert(i){const a=Kt(i,e);a&&o&&a.waypoints.splice(n,0,o)},emitOps(i){const a=ki(i,e),r=a.slice();return o&&r.splice(n,0,{...o}),{forward:[ln(e,a)],invert:[ln(e,r)]}}}}function iu(e,n,o){let i=null;return{label:"waypoint 평행이동",apply(a){const r=Kt(a,e);if(!r)throw new Error(`관계 레이아웃 없음: ${e}`);i=r.waypoints.map(l=>({...l})),r.waypoints=i.map(l=>({x:l.x+n,y:l.y+o}))},invert(a){const r=Kt(a,e);r&&i&&(r.waypoints=i)},emitOps(a){return{forward:[ln(e,ki(a,e))],invert:[ln(e,i??[])]}}}}function au(e){let n=null;return{label:"꺾은선 풀기",apply(o){const i=Kt(o,e);if(!i)throw new Error(`관계 레이아웃 없음: ${e}`);n=i.waypoints.map(a=>({...a})),i.waypoints=[]},invert(o){const i=Kt(o,e);i&&n&&(i.waypoints=n)},emitOps(o){return{forward:[ln(e,ki(o,e))],invert:[ln(e,n??[])]}}}}function ru(e,n,o){return{label:"waypoint 추가",apply(i){const a=Kt(i,e);if(!a)throw new Error(`관계 레이아웃 없음: ${e}`);a.waypoints.splice(n,0,{...o})},invert(i){const a=Kt(i,e);a==null||a.waypoints.splice(n,1)},emitOps(i){const a=ki(i,e),r=a.slice();return r.splice(n,1),{forward:[ln(e,a)],invert:[ln(e,r)]}}}}function lu(e){return{label:"노트 추가",apply(n){n.layout.notes.push(e)},invert(n){const o=n.layout.notes.findIndex(i=>i.modelId===e.modelId);o>=0&&n.layout.notes.splice(o,1)},emitOps(){return{forward:[{kind:"note.add",casUnit:"layout",noteRef:e.modelId,value:e}],invert:[{kind:"note.remove",casUnit:"layout",noteRef:e.modelId}]}}}}function su(e){let n=null;return{label:"노트 삭제",apply(o){const i=o.layout.notes.findIndex(a=>a.modelId===e);if(i<0)throw new Error(`노트 없음: ${e}`);n={item:o.layout.notes[i],index:i},o.layout.notes.splice(i,1)},invert(o){n&&o.layout.notes.splice(n.index,0,n.item)},emitOps(){return n?{forward:[{kind:"note.remove",casUnit:"layout",noteRef:e}],invert:[{kind:"note.add",casUnit:"layout",noteRef:e,value:n.item}]}:{forward:[],invert:[]}}}}function Ei(e,n){let o=null;return{label:"노트 이동",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o={...a.geo.location},a.geo.location={...n}},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&o&&(a.geo.location=o)},emitOps(){const i=a=>({kind:"note.move",casUnit:"layout",noteRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function cu(e,n){let o=null;return{label:"노트 크기 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o={...a.geo.size},a.geo.size={...n}},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&o&&(a.geo.size=o)},emitOps(){const i=a=>({kind:"note.resize",casUnit:"layout",noteRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function du(e,n){let o="";return{label:"노트 내용 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o=a.memo,a.memo=n},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&(a.memo=o)},emitOps(){const i=a=>({kind:"note.setMemo",casUnit:"layout",noteRef:e,value:{memo:a}});return{forward:[i(n)],invert:[i(o)]}}}}function uu(e,n){let o;return{label:"노트 색상 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o=a.style,a.style=_i(a.style,n)},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&(a.style=o)},emitOps(i){const a=i.layout.notes.find(l=>l.modelId===e),r=l=>({kind:"note.setStyle",casUnit:"layout",noteRef:e,value:{style:l}});return{forward:[r(a==null?void 0:a.style)],invert:[r(o)]}}}}function mu(e,n){let o=!1,i=!1;const a=r=>r.layout.groupLayouts.find(l=>l.groupRef===e);return{label:"그룹에 노트 편입",apply(r){const l=a(r);l&&(l.memberNoteRefs||(l.memberNoteRefs=[],i=!0),!l.memberNoteRefs.includes(n)&&(l.memberNoteRefs.push(n),o=!0))},invert(r){if(!o)return;const l=a(r);if(!(l!=null&&l.memberNoteRefs))return;const s=l.memberNoteRefs.indexOf(n);s>=0&&l.memberNoteRefs.splice(s,1),i&&delete l.memberNoteRefs},emitOps(){return o?{forward:[{kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:e,noteRef:n}],invert:[{kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:e,noteRef:n}]}:{forward:[],invert:[]}}}}function fu(e,n){let o=-1;const i=a=>a.layout.groupLayouts.find(r=>r.groupRef===e);return{label:"그룹에서 노트 제외",apply(a){var l;const r=i(a);o=((l=r==null?void 0:r.memberNoteRefs)==null?void 0:l.indexOf(n))??-1,o>=0&&r.memberNoteRefs.splice(o,1)},invert(a){if(o<0)return;const r=i(a);r&&(r.memberNoteRefs||(r.memberNoteRefs=[]),r.memberNoteRefs.splice(o,0,n))},emitOps(){return o<0?{forward:[],invert:[]}:{forward:[{kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:e,noteRef:n}],invert:[{kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:e,noteRef:n}]}}}}const Pn=(e,n,o)=>({kind:"noteConnection.setWaypoints",casUnit:"layout",noteRef:e,targetRef:n,value:{waypoints:o}}),Ta=(e,n,o)=>{var i;return((i=En(e,n,o))==null?void 0:i.waypoints.map(a=>({...a})))??[]};function pu(e,n){let o=!1,i=!1;return{label:"노트 연결 추가",apply(a){const r=a.layout.notes.find(l=>l.modelId===e);if(!r)throw new Error(`노트 없음: ${e}`);if(r.connections||(r.connections=[],i=!0),r.connections.some(l=>l.targetRef===n)){o=!1;return}r.connections.push({targetRef:n,waypoints:[]}),o=!0},invert(a){if(!o)return;const r=a.layout.notes.find(s=>s.modelId===e);if(!(r!=null&&r.connections))return;const l=r.connections.findIndex(s=>s.targetRef===n);l>=0&&r.connections.splice(l,1),i&&delete r.connections},emitOps(){return o?{forward:[{kind:"noteConnection.add",casUnit:"layout",noteRef:e,targetRef:n,value:{targetRef:n,waypoints:[]}}],invert:[{kind:"noteConnection.remove",casUnit:"layout",noteRef:e,targetRef:n}]}:{forward:[],invert:[]}}}}function hu(e,n){let o=null;return{label:"노트 연결 삭제",apply(i){var l;const a=i.layout.notes.find(s=>s.modelId===e),r=((l=a==null?void 0:a.connections)==null?void 0:l.findIndex(s=>s.targetRef===n))??-1;if(!(a!=null&&a.connections)||r<0)throw new Error(`노트 연결 없음: ${e}→${n}`);o={item:a.connections[r],index:r},a.connections.splice(r,1)},invert(i){if(!o)return;const a=i.layout.notes.find(r=>r.modelId===e);a!=null&&a.connections&&a.connections.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"noteConnection.remove",casUnit:"layout",noteRef:e,targetRef:n}],invert:[{kind:"noteConnection.add",casUnit:"layout",noteRef:e,targetRef:n,value:o.item}]}:{forward:[],invert:[]}}}}function yu(e,n,o,i){let a=null;return{label:"waypoint 이동",coalesceKey:`noteConnWaypoint:${e}:${n}`,apply(r){const l=En(r,e,n);if(!l||!l.waypoints[o])throw new Error(`waypoint 없음: ${e}→${n}[${o}]`);a={...l.waypoints[o]},l.waypoints.splice(o,1,{...i})},invert(r){const l=En(r,e,n);l&&a&&l.waypoints.splice(o,1,a)},emitOps(r){const l=Ta(r,e,n),s=l.map((c,d)=>d===o&&a?{...a}:c);return{forward:[Pn(e,n,l)],invert:[Pn(e,n,s)]}}}}function gu(e,n,o,i){return{label:"waypoint 추가",apply(a){const r=En(a,e,n);if(!r)throw new Error(`노트 연결 없음: ${e}→${n}`);r.waypoints.splice(o,0,{...i})},invert(a){const r=En(a,e,n);r==null||r.waypoints.splice(o,1)},emitOps(a){const r=Ta(a,e,n),l=r.slice();return l.splice(o,1),{forward:[Pn(e,n,r)],invert:[Pn(e,n,l)]}}}}function bu(e,n,o){let i=null;return{label:"waypoint 제거",apply(a){const r=En(a,e,n);if(!r||!r.waypoints[o])throw new Error(`waypoint 없음: ${e}→${n}[${o}]`);i={...r.waypoints[o]},r.waypoints.splice(o,1)},invert(a){const r=En(a,e,n);r&&i&&r.waypoints.splice(o,0,i)},emitOps(a){const r=Ta(a,e,n),l=r.slice();return i&&l.splice(o,0,{...i}),{forward:[Pn(e,n,r)],invert:[Pn(e,n,l)]}}}}function _u(e,n){let o=null;return{label:"꺾은선 풀기",apply(i){const a=En(i,e,n);if(!a)throw new Error(`노트 연결 없음: ${e}→${n}`);o=a.waypoints.map(r=>({...r})),a.waypoints=[]},invert(i){const a=En(i,e,n);a&&o&&(a.waypoints=o)},emitOps(i){return{forward:[Pn(e,n,Ta(i,e,n))],invert:[Pn(e,n,o??[])]}}}}function at(e,n,o){return{label:e,coalesceKey:o,apply(i){for(const a of n)a.apply(i)},invert(i){for(let a=n.length-1;a>=0;a--)n[a].invert(i)},emitOps(i){const a=n.map(r=>{if(!r.emitOps)throw new Error(`emitOps 미구현 command가 composite에 포함됨: ${r.label}`);return r.emitOps(i)});return{forward:a.flatMap(r=>r.forward),invert:a.slice().reverse().flatMap(r=>r.invert)}}}}const Tb=Object.freeze(Object.defineProperty({__proto__:null,addAssociation:Ra,addAttribute:Gt,addEntity:va,addEntityToGroup:Fd,addGroup:Sa,addIndex:eu,addNote:lu,addNoteConnection:pu,addNoteConnectionWaypoint:gu,addNoteToGroup:mu,addOperation:qd,addWaypoint:ru,clearNoteConnectionWaypoints:_u,clearWaypoints:au,composite:at,moveEntity:Fo,moveGroup:Ud,moveNote:Ei,moveNoteConnectionWaypoint:yu,moveWaypoint:nu,removeAssociation:Qd,removeAttribute:Gd,removeEntity:Md,removeEntityFromGroup:xa,removeGroup:zd,removeIndex:tu,removeNote:su,removeNoteConnection:hu,removeNoteConnectionWaypoint:bu,removeNoteFromGroup:fu,removeOperation:Jd,removeWaypoint:ou,renameEntity:Vd,reorderAttributes:Bl,reorderOperations:Xd,resizeEntity:Bd,resizeGroup:Hd,resizeNote:cu,setAllEntitiesCollapsed:Vl,setAttributeSwatch:Ca,setEntityCollapsed:Od,setEntityLocked:Ld,setEntitySwatch:Dd,setGroupLocked:Kd,setGroupSwatch:jd,setNoteMemo:du,setNoteSwatch:uu,setOperationSwatch:Zd,translateWaypoints:iu,updateAssociation:Aa,updateAssociationEnd:qt,updateAttribute:Yt,updateEntity:Ml,updateGroup:Pd,updateIndex:$a,updateOperation:Wd},Symbol.toStringTag,{value:"Module"}));class ku{constructor(){st(this,"revs",new Map);st(this,"layoutVersion",0);st(this,"logicalVersion",0)}seed(n){this.revs.clear();for(const[o,i]of Object.entries(n.revs??{}))this.revs.set(o,i);this.layoutVersion=n.layoutVersion??0,this.logicalVersion=n.logicalVersion??0}rev(n){return this.revs.get(n)??0}setRev(n,o){this.revs.set(n,o)}deleteRev(n){this.revs.delete(n)}snapshot(){return{revs:Object.fromEntries(this.revs),layoutVersion:this.layoutVersion,logicalVersion:this.logicalVersion}}}const Mb=[400,1200];function Vb(e){var o;if(typeof e!="object"||e===null)return;const n=e;for(const i of[n.statusCode,n.status,(o=n.response)==null?void 0:o.status])if(typeof i=="number"&&Number.isFinite(i))return i}function Bb(e){const n=Vb(e);return n==null||n===408||n===429?!0:n<400||n>=500}const Db=e=>new Promise(n=>setTimeout(n,e));class Eu{constructor(n){st(this,"cache",new ku);st(this,"newClientOpId");st(this,"debounceMs");st(this,"retryDelaysMs");st(this,"emissions",new WeakMap);st(this,"open",null);st(this,"debounceHandle",null);st(this,"queue",[]);st(this,"sending",!1);st(this,"_frozen",!1);st(this,"stack",null);st(this,"settledWaiters",[]);this.opts=n,this.newClientOpId=n.newClientOpId??Pe,this.debounceMs=n.debounceMs??300,this.retryDelaysMs=n.retryDelaysMs??Mb}seed(n){this.cache.seed(n)}attach(n){this.stack=n,n.sealCoalesce();const o=n.onCommand((i,a,r)=>this.handle(i,a,r));return()=>{o(),this.stack===n&&(this.stack=null)}}get frozen(){return this._frozen}get hasPending(){return this.open!==null||this.queue.length>0||this.sending}cacheSnapshot(){return this.cache.snapshot()}flush(){this.flushOpen(!0)}whenSettled(){return this.hasPending?new Promise(n=>this.settledWaiters.push(n)):Promise.resolve()}handle(n,o,i){var l,s,c;if(this._frozen)return;let a;if(o==="do"){const d=(l=n.emitOps)==null?void 0:l.call(n,this.opts.state);if(!d)throw new Error(`op-mode에서 emitOps 미구현 command 실행: ${n.label}`);a=d}else{const d=this.emissions.get(n);if(!d)throw new Error(`op-mode ${o} 대상 command의 emission 미기록: ${n.label}`);a=d}const r=o==="undo"?a.invert:a.forward;if(o==="do"&&i&&this.open&&this.open.coalesceKey===n.coalesceKey){this.open.fwd=r,this.emissions.set(n,{forward:r,invert:this.open.inv}),this.resetDebounce();return}if(i){const d=new Error(`op-mode coalesce 경계 불일치: 스택은 병합했으나 어댑터에 대응 그룹이 없음 (${n.label}, key=${String(n.coalesceKey)})`);console.error("[op-sync]",d),(c=(s=this.opts).onError)==null||c.call(s,d)}if(this.flushOpen(!1),o==="do"&&(this.emissions.set(n,a),n.coalesceKey!=null)){this.open={coalesceKey:n.coalesceKey,fwd:r,inv:a.invert},this.startDebounce();return}r.length&&this.enqueue(this.buildBatch(r))}flushOpen(n){var i;this.cancelDebounce();const o=this.open;this.open=null,o&&o.fwd.length&&this.enqueue(this.buildBatch(o.fwd)),n&&((i=this.stack)==null||i.sealCoalesce())}startDebounce(){this.cancelDebounce(),this.debounceHandle=setTimeout(()=>{this.debounceHandle=null,this.flushOpen(!0)},this.debounceMs)}resetDebounce(){this.startDebounce()}cancelDebounce(){this.debounceHandle!=null&&(clearTimeout(this.debounceHandle),this.debounceHandle=null)}buildBatch(n){const o={},i=new Set;let a=!1,r=!1;for(const l of n)if(l.casUnit==="logical")if(a=!0,l.containerRef)i.add(l.containerRef);else{const s=l.entityRef??l.associationRef??l.groupRef;s&&(l.kind.endsWith(".add")?this.cache.setRev(s,0):l.kind.endsWith(".remove")&&this.cache.deleteRev(s))}else l.incidental||(r=!0);if(i.size){o.revs={};for(const l of i){const s=this.cache.rev(l);o.revs[l]=s,this.cache.setRev(l,s+1)}}return r&&(o.layout=this.cache.layoutVersion,this.cache.layoutVersion=o.layout+1),a&&(this.cache.logicalVersion+=1),{diagramId:this.opts.diagramId,ops:n,cas:o,origin:this.opts.origin??"gui",clientOpId:this.newClientOpId()}}enqueue(n){this.queue.push(n),this.pump()}async pump(){var i,a;if(this.sending||this._frozen)return;const n=this.queue.shift();if(!n){this.notifySettled();return}this.sending=!0;let o;for(let r=0;;r++)try{o=await this.opts.transport(n);break}catch(l){const s=this.retryDelaysMs.length+1;console.error(`[op-sync] op 전송 실패 (시도 ${r+1}/${s}):`,l),(a=(i=this.opts).onError)==null||a.call(i,l);const c=this.retryDelaysMs[r];if(c==null||!Bb(l)){this.sending=!1,console.error("[op-sync] 전송 실패 확정 → 하드 프리즈(kind:missing)"),this.freeze({kind:"missing"});return}await Db(c)}this.sending=!1,o.ok?(this.reconcile(o),this.pump()):this.freeze(o.conflict)}reconcile(n){if(!(this.queue.length>0)){for(const[o,i]of Object.entries(n.revs))this.cache.setRev(o,i);this.cache.layoutVersion=n.layoutVersion,this.cache.logicalVersion=n.logicalVersion}}freeze(n){var o,i;this._frozen=!0,this.queue.length=0,this.open=null,this.cancelDebounce(),(i=(o=this.opts).onFreeze)==null||i.call(o,n),this.notifySettled()}notifySettled(){if(this.hasPending)return;const n=this.settledWaiters;this.settledWaiters=[];for(const o of n)o()}}const Nu=["entity.add","entity.update","entity.remove","attribute.add","attribute.update","attribute.remove","association.add","association.remove","association.update","associationEnd.update","index.add","index.update","index.remove","operation.add","operation.update","operation.remove","attribute.reorder","operation.reorder","group.add","group.update","group.remove","group.addMember","group.removeMember"],wu=["NORMAL","RELATION_OWN","RELATION_REF","EMBED_OWN","EMBED_REF","EMBED_PREDEF","DIVIDER"];function Iu(e,n){var r;if(!n.length||!((r=e.indexes)!=null&&r.length))return[];const o=new Set(n),i=new Set;for(const l of e.attributes)if(o.has(l.modelId)){i.add(l.modelId);for(const s of l.dbAttrs)i.add(s.modelId)}if(!i.size)return[];const a=[];for(const l of e.indexes){const s=l.columns.filter(c=>!i.has(c.columnRef));s.length!==l.columns.length&&a.push({indexRef:l.modelId,columns:s})}return a}function Ob(e){return gn(e).length}function Dl(e,n){return new Set(e.associations.filter(o=>{const i=o.end1.entityRef===n?o.end1:o.end2;return i.multiplicity==="ZERO_OR_MORE_INSTANCES"||i.multiplicity==="ONE_OR_MORE_INSTANCES"}).map(o=>o.modelId))}function Lb(e,n,o,i){var r;const a=new Set;for(const l of e.attributes)l.dbAttrs.forEach((s,c)=>{if(s.sharedColumnRef!=null)return;const d=ci(l,s,c,e,i);d&&a.add(d)});for(let l=n.dbAttrs.length;l<o.length;l++){const s=(r=o[l])==null?void 0:r.physicalName;if(s&&a.has(s))return!0}return!1}function vu(e,n,o=Pe){const i=e.entities.find(c=>c.modelId===n);if(!i)return[];const a=Ob(i);if(a===0)return[];const r=Dl(e,n),l=gn(i).map(c=>c.col),s=[];for(const c of e.entities){const d=c.attributes.filter(u=>{var m;return u.attrType==="EMBED_OWN"&&((m=u.embedded)==null?void 0:m.embeddableRef)===n&&!r.has(u.embedded.associationRef)&&a-u.dbAttrs.length>0});if(!(d.length>1))for(const u of d){const m=a-u.dbAttrs.length;Lb(c,u,l,e)||s.push({entityId:c.modelId,attributeId:u.modelId,dbAttrs:[...u.dbAttrs,...Array.from({length:m},()=>({modelId:o(),physicalName:"",dataType:""}))],added:m})}}return s}function Cu(e,n,o){var p;const i=e.entities.find(f=>f.modelId===n);if(!i)return[];const a=i.attributes;if(o.length!==a.length)return[];const r=new Map(a.map(f=>[f.modelId,f])),l=[];for(const f of o){const h=r.get(f);if(!h)return[];l.push(h)}const s=a.flatMap(f=>f.dbAttrs).map(f=>f.modelId),c=l.flatMap(f=>f.dbAttrs).map(f=>f.modelId);if(s.length!==c.length)return[];if(s.every((f,h)=>f===c[h]))return[];const d=new Map(s.map((f,h)=>[f,h])),u=Dl(e,n),m=[];for(const f of e.entities)for(const h of f.attributes){if(h.attrType!=="EMBED_OWN"||((p=h.embedded)==null?void 0:p.embeddableRef)!==n||u.has(h.embedded.associationRef)||h.dbAttrs.length!==s.length)continue;const g=c.map(_=>h.dbAttrs[d.get(_)]),b=g.reduce((_,E,N)=>E===h.dbAttrs[N]?_:_+1,0);b&&m.push({entityId:f.modelId,attributeId:h.modelId,dbAttrs:g,moved:b})}return m}function Su(e,n,o){var p;const i=e.entities.find(f=>f.modelId===n);if(!i)return[];const a=new Set(o),r=i.attributes.filter(f=>!a.has(f.modelId));if(r.length===i.attributes.length)return[];const l=gn(i).map(f=>f.col),s=l.map(f=>f.modelId),c=new Set(gn({...i,attributes:r}).map(f=>f.col.modelId)),d=new Set;if(s.forEach((f,h)=>{c.has(f)&&d.add(h)}),d.size===s.length)return[];const u=Dl(e,n),m=[];for(const f of e.entities)for(const h of f.attributes){if(h.attrType!=="EMBED_OWN"||((p=h.embedded)==null?void 0:p.embeddableRef)!==n||u.has(h.embedded.associationRef)||h.dbAttrs.length!==s.length)continue;const g=h.dbAttrs.filter((E,N)=>d.has(N)),b=h.dbAttrs.filter((E,N)=>!d.has(N));h.dbAttrs.some((E,N)=>{if(d.has(N))return!1;const y=l[N],k=!!E.physicalName&&E.physicalName!==((y==null?void 0:y.physicalName)??""),S=E.sharedColumnRef!=null&&E.sharedColumnRef!==(y==null?void 0:y.sharedColumnRef);return k||S})||m.push({entityId:f.modelId,attributeId:h.modelId,dbAttrs:g,dropped:b})}return m}function Pb(e,n){const o=()=>e.entities.filter(r=>{var l;return((l=r.table)==null?void 0:l.physicalName)===n.ref}),i=()=>e.entities.filter(r=>r.name===n.ref);if(n.by==="modelId")return e.entities.filter(r=>r.modelId===n.ref);if(n.by==="physicalName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function zb(e,n){const o=()=>e.attributes.filter(r=>r.name===n.ref),i=()=>e.attributes.filter(r=>r.dbAttrs.some(l=>l.physicalName===n.ref));if(n.by==="modelId")return e.attributes.filter(r=>r.modelId===n.ref);if(n.by==="name")return o();if(n.by==="physicalName")return i();const a=o();return a.length?a:i()}function xu(e,n,o){return e.associations.filter(i=>{const a=[i.end1.entityRef,i.end2.entityRef];return a.includes(n)&&a.includes(o)})}function St(e,n){const o=Pb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>Hb(i,e))}}function Fb(e,n){const o=()=>e.groups.filter(r=>r.packageName===n.ref),i=()=>e.groups.filter(r=>Object.values(r.name??{}).some(l=>l===n.ref));if(n.by==="modelId")return e.groups.filter(r=>r.modelId===n.ref);if(n.by==="packageName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function Ol(e,n){const o=Fb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>({modelId:i.modelId,name:i.name??null,packageName:i.packageName??null,members:i.memberEntityRefs.length}))}}function Ll(e,n,o){return e.reason==="not-found"?{code:"group-not-found",opIndex:n,handle:o}:{code:"group-ambiguous",opIndex:n,handle:o,matches:e.matches}}const Ub=new Set(["name","description","packageName","excludeDDLGeneration"]);function Hb(e,n){var a;const o=To(e,n).value,i=n.associations.filter(r=>{var l,s;return((l=r.end1)==null?void 0:l.entityRef)===e.modelId||((s=r.end2)==null?void 0:s.entityRef)===e.modelId});return{modelId:e.modelId,stereotype:e.stereotype,packageName:o||null,table:((a=e.table)==null?void 0:a.physicalName)||null,attributes:e.attributes.length,references:i.length,referencedBy:[...new Set(i.map(r=>{var c,d,u,m;const l=((c=r.end1)==null?void 0:c.entityRef)===e.modelId?(d=r.end2)==null?void 0:d.entityRef:(u=r.end1)==null?void 0:u.entityRef,s=n.entities.find(p=>p.modelId===l);return(s==null?void 0:s.name)||((m=s==null?void 0:s.table)==null?void 0:m.physicalName)||String(l??"?")}))]}}function Ru(e,n){const o=zb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function jb(e,n){const o=()=>e.attributes.flatMap(r=>r.dbAttrs).filter(r=>r.physicalName===n.ref),i=()=>e.attributes.filter(r=>r.name===n.ref).flatMap(r=>r.dbAttrs);if(n.by==="modelId")return e.attributes.flatMap(r=>r.dbAttrs).filter(r=>r.modelId===n.ref);if(n.by==="physicalName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function Kb(e,n){const o=jb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Au(e,n){const o=e.filter(i=>i.physicalName===n.ref);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Pl(e){return e.by!==void 0&&e.by!=="name"}function Gb(e,n){return(e.indexes??[]).filter(o=>o.name===n.ref)}function Yb(e,n){return(e.operations??[]).filter(o=>o.name===n.ref)}function qb(e,n){const o=Gb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function $u(e,n){const o=Yb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Tu(e){return e.physicalName!=null||e.dataType!=null||e.length!=null||e.scale!=null||e.columnLogicalName!=null||e.unique!=null||e.updatable!=null}function Mu(e){return Tu(e)&&e.dataType==null}function Vu(e,n,o){const i=Tu(e);return{modelId:o(),name:e.name,type:e.type,attrType:"NORMAL",identifier:e.identifier??!1,notNull:e.notNull??!1,order:n,...e.transient?{transient:!0}:{},...e.groupCode?{groupCode:e.groupCode}:{},...e.defaultValue!=null?{defaultValue:e.defaultValue}:{},...e.attributeGroup?{attributeGroup:e.attributeGroup}:{},...e.description?{description:e.description}:{},dbAttrs:i?[{modelId:o(),physicalName:e.physicalName??e.name,dataType:e.dataType??"",...e.length?{length:e.length}:{},...e.scale?{scale:e.scale}:{},...e.columnLogicalName?{logicalName:e.columnLogicalName}:{},...e.unique!=null?{unique:e.unique}:{},...e.updatable!=null?{updatable:e.updatable}:{}}]:[]}}function Bu(e,n,o,i,a,r,l,s,c){const d=c(),u=new Map((e.embeddableOverrides??[]).map(f=>[f.field,f])),m=[];let p=!1;for(const f of n.fields){const h=u.get(f.name);if(h!=null&&h.sharedColumnPhysicalName){const g={ref:h.sharedColumnPhysicalName,by:"physicalName"},b=Au(Dn(i,a),g);if(!b.ok){s.push(b.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:g}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:g,matches:b.matches}),p=!0;continue}m.push({modelId:c(),physicalName:"",dataType:"",sharedColumnRef:b.value.modelId});continue}m.push({modelId:c(),physicalName:(h==null?void 0:h.physicalName)??"",dataType:"",...h!=null&&h.length?{length:h.length}:{},...h!=null&&h.scale?{scale:h.scale}:{},...(h==null?void 0:h.insertable)!=null?{insertable:h.insertable}:{},...(h==null?void 0:h.updatable)!=null?{updatable:h.updatable}:{}})}return p?null:{modelId:d,name:e.name,type:n.type,attrType:"EMBED_PREDEF",identifier:e.identifier??!1,notNull:e.notNull??!1,order:o,...e.defaultValue!=null?{defaultValue:e.defaultValue}:{},...e.attributeGroup?{attributeGroup:e.attributeGroup}:{},...e.description?{description:e.description}:{},dbAttrs:m}}const Wb=new Set(["name","type","customType","attrType","identifier","notNull","transient","naturalId","naturalIdMutable","description","attributeGroup","groupCode","defaultValue","personalInfoAttributeType","order","dbAttrs","derivedIdFieldName","collectionType"]),Uo=e=>new Set(Object.keys(e)),Jb=Uo({name:!0,stereotype:!0,physicalName:!0,useVersion:!0,attributes:!0,indexes:!0,operations:!0,serialization:!0}),Du=Uo({name:!0,type:!0,identifier:!0,notNull:!0,transient:!0,physicalName:!0,dataType:!0,length:!0,scale:!0,groupCode:!0,defaultValue:!0,attributeGroup:!0,description:!0,columnLogicalName:!0,unique:!0,updatable:!0,embeddableOverrides:!0,collectionType:!0}),Ou=Uo({name:!0,unique:!0,columns:!0,description:!0,parameters:!0}),Lu=Uo({name:!0,visibility:!0,sourceCode:!0,description:!0,personalInfoAttributeType:!0}),Xb=Uo({from:!0,to:!0,fromMultiplicity:!0,toMultiplicity:!0,identifying:!0,composition:!0}),Zb=Uo({name:!0,packageName:!0,description:!0,excludeDDLGeneration:!0,members:!0});function Nn(e,n){return uo(e,n)}const Qb=new Set(["name","stereotype","packageName","superClass","schema","description","abstractClass","hasPersonalInfo","declarationOfInterfaces","table","referenceOnly","serialization"]),e_=new Set(["description","identifying"]),t_=new Set(["multiplicity","navigable","composition"]),n_=new Set(["name","unique","description","parameters"]),o_=new Set(["name","visibility","sourceCode","description","order","personalInfoAttributeType"]);function uo(e,n,o=[]){const i=[];for(const a of Object.keys(e)){if(a.includes(".")){o.some(r=>a.startsWith(r))||i.push(a);continue}n.has(a)||i.push(a)}return i}const zl=new Set(["physicalName","logicalName","dataType","length","scale","unique","autoIncrement","updatable","insertable","sharedColumnRef","multiValue","multiValueSeparator","sequenceName"]),i_=new Set([...zl].filter(e=>e!=="sharedColumnRef"));function a_(e,n,o,i){if(i||o.some(l=>!i_.has(l))||e.attrType!=="NORMAL"||e.dbAttrs.length!==1)return null;const a={...e.dbAttrs[0]};for(const l of o)a[l]=n[l];const r={};for(const[l,s]of Object.entries(n))zl.has(l)||(r[l]=s);return{...r,dbAttrs:[a]}}function r_(e,n,o,i,a,r,l,s){const c=new Map(o.map(m=>[m.field,m])),d=[];let u=!1;return e.dbAttrs.forEach((m,p)=>{const f=n.fields[p],h=f?c.get(f.name):void 0;if(!h){d.push(m);return}if(h.sharedColumnPhysicalName){const b={ref:h.sharedColumnPhysicalName,by:"physicalName"},_=Au(Dn(i,a),b);if(!_.ok){s.push(_.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:b}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:b,matches:_.matches}),u=!0;return}d.push({modelId:m.modelId,physicalName:"",dataType:"",sharedColumnRef:_.value.modelId});return}const g={...m};delete g.sharedColumnRef,d.push({...g,...h.physicalName!=null?{physicalName:h.physicalName}:{},...h.length!=null?{length:h.length}:{},...h.scale!=null?{scale:h.scale}:{},...h.insertable!=null?{insertable:h.insertable}:{},...h.updatable!=null?{updatable:h.updatable}:{}})}),u?null:d}function Pu(e,n,o){return{modelId:o(),name:e.name,order:n,...e.visibility?{visibility:e.visibility}:{},...e.sourceCode?{sourceCode:e.sourceCode}:{},...e.description?{description:e.description}:{},...e.personalInfoAttributeType?{personalInfoAttributeType:e.personalInfoAttributeType}:{}}}function zu(e,n,o,i,a,r){const l=[];let s=!1;for(const c of n.columns){const d=Kb(e,c.column);if(!d.ok){a.push(d.reason==="not-found"?{code:"column-not-found",opIndex:o,entity:i,handle:c.column}:{code:"column-ambiguous",opIndex:o,entity:i,handle:c.column,matches:d.matches}),s=!0;continue}l.push({columnRef:d.value.modelId,descending:c.descending??!1})}return s?null:{modelId:r(),name:n.name,unique:n.unique??!1,columns:l,...n.description?{description:n.description}:{},...n.parameters?{parameters:n.parameters}:{}}}function Ho(e,n,o,i){const a=`${o}:${i}`;n.seen.has(a)||(n.seen.add(a),n.pairs.push({entityId:o,attributeId:i}),e.push({kind:"attribute.remove",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:i}))}function l_(e,n,o,i){const a=new Map;for(const{entityId:r,attributeId:l}of o.pairs){if(i.has(r))continue;const s=a.get(r)??[];s.push(l),a.set(r,s)}for(const[r,l]of a){const s=n.entities.find(c=>c.modelId===r);if(s)for(const c of Iu(s,l))e.push({kind:"index.update",casUnit:"logical",containerRef:r,entityRef:r,indexRef:c.indexRef,patch:{columns:c.columns}})}}function s_(e,n,o,i,a,r){const l=m=>{const p=new Map;for(const{entityId:f,item:h}of m){if(a.has(f))continue;const g=p.get(f)??[];g.push(h),p.set(f,g)}return p},s=l(o.pairs.map(m=>({entityId:m.entityId,item:m.attributeId}))),c=l(i.map(m=>({entityId:m.entityId,item:m.attribute}))),d=new Set(e.filter(m=>m.kind==="attribute.update").map(m=>m.attributeRef)),u=m=>{d.has(m.attributeId)||(d.add(m.attributeId),e.push({kind:"attribute.update",casUnit:"logical",containerRef:m.entityId,entityRef:m.entityId,attributeRef:m.attributeId,patch:{dbAttrs:m.dbAttrs}}))};for(const[m,p]of s)if(!c.has(m))for(const f of Su(n,m,p))u(f);for(const[m,p]of c){if(s.has(m))continue;const f={...n,entities:n.entities.map(h=>h.modelId===m?{...h,attributes:[...h.attributes,...p]}:h)};for(const h of vu(f,m,r))u(h)}}function Fu(e,n){const o={...e},i=[];for(const[a,r]of Object.entries(n)){if(!a.includes(".")){o[a]=r===null?void 0:r;continue}const l=/^dbAttrs\.(\d+)\.(.+)$/.exec(a);l&&i.push([Number(l[1]),l[2],r])}if(i.length){const a=(o.dbAttrs??[]).map(r=>({...r}));for(const[r,l,s]of i)a[r]&&(a[r][l]=s===null?void 0:s);o.dbAttrs=a}return o}function Uu(e,n,o,i,a,r,l){var p;for(const f of i.remove)Ho(e,r,o,f);for(const f of i.update)e.push({kind:"attribute.update",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:f.attributeId,patch:f.patch}),a.attrPatches.push({entityId:o,attributeId:f.attributeId,patch:f.patch});const s=((p=n.entities.find(f=>f.modelId===o))==null?void 0:p.attributes)??[],c=[];for(const f of i.add){const h={...f,order:l(o,s)};e.push({kind:"attribute.add",casUnit:"logical",containerRef:o,entityRef:o,value:h}),a.cascadeAdds.push({entityId:o,attribute:h}),c.push(h)}const d=new Set(i.remove),u=[...s.filter(f=>!d.has(f.modelId)),...c],m=new Set(u.map(f=>f.modelId));for(const f of n.associations){if(f.end2.entityRef!==o)continue;const h=f.end2.attributeRef;if(h&&m.has(h))continue;const b=u.filter(_=>{var E;return((E=_.derivedFrom)==null?void 0:E.associationRef)===f.modelId&&_.dbAttrs.length>0}).sort((_,E)=>_.order-E.order)[0];b&&(e.push({kind:"associationEnd.update",casUnit:"logical",containerRef:f.modelId,associationRef:f.modelId,end:"end2",patch:{attributeRef:b.modelId}}),a.endPatches.push({associationRef:f.modelId,end:"end2",patch:{attributeRef:b.modelId}}))}}function Fl(e,n,o,i,a,r,l){for(const{entityId:s,plan:c}of od(n,o,i))Uu(e,n,s,c,a,r,l)}function c_(e,n,o,i,a,r){const l=new Map;for(const{entityId:p,attributeId:f}of i.pairs)l.has(p)||l.set(p,new Set),l.get(p).add(f);const s=new Map;for(const p of r.attrPatches)s.has(p.entityId)||s.set(p.entityId,[]),s.get(p.entityId).push(p);const c=new Map;for(const{entityId:p,attribute:f}of[...a,...r.cascadeAdds])c.has(p)||c.set(p,[]),c.get(p).push(f);const d=p=>{const f={};for(const[h,g]of Object.entries(p))h.includes(".")||(f[h]=g===null?void 0:g);return f},u=e.entities.filter(p=>!n.has(p.modelId)).map(p=>{const f=l.get(p.modelId),h=s.get(p.modelId),g=c.get(p.modelId);if(!f&&!h&&!g)return p;let b=p.attributes;return f&&(b=b.filter(_=>!f.has(_.modelId))),h&&(b=b.map(_=>{const E=h.filter(N=>N.attributeId===_.modelId);return E.length?E.reduce((N,y)=>Fu(N,y.patch),_):_})),g&&(b=[...b,...g]),{...p,attributes:b}}),m=e.associations.filter(p=>!o.has(p.modelId)&&!n.has(p.end1.entityRef)&&!n.has(p.end2.entityRef)).map(p=>{let f=p;for(const h of r.assocPatches)h.associationRef===p.modelId&&(f={...f,...d(h.patch)});for(const h of r.endPatches)h.associationRef===p.modelId&&(f={...f,[h.end]:{...f[h.end],...d(h.patch)}});return f}).concat(r.addedAssociations);return{...e,entities:u,associations:m}}function d_(e,n,o,i,a,r,l,s,c){if(!l.identifierCascadeParents.size)return;const d=c_(n,o,i,a,r,l),u=new Map;for(const m of l.identifierCascadeParents)for(const[p,f]of sl(d,m,s)){const h=u.get(p);u.set(p,h?ll(h,f):f)}for(const[m,p]of u)Uu(e,d,m,nd(p),l,a,c)}function u_(e,n,o={}){const i=o.mkId??Pe,a=o.embeddableCatalog??[],r=y=>a.find(k=>k.type===y),l=[],s=[],c=new Map,d=(y,k)=>{const S=c.get(y)??Ht(k);return c.set(y,S+1),S},u=new Map,m=new Set,p=new Set,f={seen:new Set,pairs:[]},h=[],g={attrPatches:[],cascadeAdds:[],addedAssociations:[],assocPatches:[],endPatches:[],identifierCascadeParents:new Set},b=new Set,_=(y,k)=>`${y}\0${k}`,E=new Set;for(const y of n)y.kind==="entity.add"&&(E.add(y.spec.name),y.spec.physicalName&&E.add(y.spec.physicalName));const N=new Set;return n.forEach((y,k)=>{var S,T,O,A,V;switch(y.kind){case"entity.add":{{const M={ref:y.spec.name},x=Nn(y.spec,Jb);if(x.length){s.push({code:"entity-spec-unknown-key",opIndex:k,handle:M,keys:x});break}let P=!1;for(const q of y.spec.attributes??[]){const ce=Nn(q,Du);ce.length&&(s.push({code:"attribute-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}for(const q of y.spec.indexes??[]){const ce=Nn(q,Ou);ce.length&&(s.push({code:"index-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}for(const q of y.spec.operations??[]){const ce=Nn(q,Lu);ce.length&&(s.push({code:"operation-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}if(P)break}const C=e.entities.filter(M=>M.name===y.spec.name).map(M=>M.modelId);if(C.length||N.has(y.spec.name)){s.push({code:"entity-name-conflict",opIndex:k,handle:{ref:y.spec.name},matches:C});break}N.add(y.spec.name);const R=i(),$={modelId:R,name:y.spec.name,stereotype:y.spec.stereotype??"JPA_ENTITY",attributes:[],...y.spec.useVersion?{jpaAttrs:{useVersion:!0}}:{},...y.spec.physicalName?{table:{physicalName:y.spec.physicalName}}:{},...y.spec.serialization?{serialization:y.spec.serialization}:{}},w={ref:y.spec.name};let I=!1;for(const[M,x]of(y.spec.attributes??[]).entries()){if(x.type==="GroupCodeEnum"&&!x.groupCode){s.push({code:"groupcode-required",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0;continue}if(!r(x.type)&&!((S=x.embeddableOverrides)!=null&&S.length)&&Mu(x)){s.push({code:"datatype-required",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0;continue}const P=r(x.type);if(P){const q=Bu(x,P,M,$,e.entities,k,w,s,i);q?$.attributes.push(q):I=!0}else(T=x.embeddableOverrides)!=null&&T.length?(s.push({code:"embeddable-type-unresolved",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0):$.attributes.push(Vu(x,M,i))}const v=(y.spec.operations??[]).map((M,x)=>Pu(M,x,i));v.length&&($.operations=v);const B=[];for(const M of y.spec.indexes??[]){const x=zu($,M,k,w,s,i);x?B.push(x):I=!0}if(B.length&&($.indexes=B),I)break;l.push({kind:"entity.add",casUnit:"logical",entityRef:R,value:$});break}case"entity.update":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=uo(y.patch,Qb,["jpaAttrs.","table.","serialization."]);if(R.length){s.push({code:"entity-patch-unknown-key",opIndex:k,entity:y.entity,keys:R});break}const $=y.patch.stereotype;if(typeof $=="string"&&$!==C.value.stereotype){const w=$==="JPA_EMBEDDABLE"||C.value.stereotype==="JPA_EMBEDDABLE",I=$==="SERIALIZED_TYPE"||C.value.stereotype==="SERIALIZED_TYPE";if(w||I){s.push({code:w?"stereotype-embeddable-transition-unsupported":"stereotype-serialized-transition-unsupported",opIndex:k,entity:y.entity,from:C.value.stereotype??"",to:$});break}}l.push({kind:"entity.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,patch:y.patch});break}case"entity.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=C.value.modelId,$=e.associations.filter(B=>B.end1.entityRef===R||B.end2.entityRef===R),w=new Set($.map(B=>B.modelId));for(const B of $)m.has(B.modelId)||(m.add(B.modelId),l.push({kind:"association.remove",casUnit:"logical",associationRef:B.modelId}));for(const B of e.entities)if(B.modelId!==R)for(const M of B.attributes)M.embedded&&w.has(M.embedded.associationRef)&&Ho(l,f,B.modelId,M.modelId);for(const B of $){if(B.end1.entityRef===R||!B.end1.attributeRef)continue;const M=e.entities.find(P=>P.modelId===B.end1.entityRef),x=M==null?void 0:M.attributes.find(P=>P.modelId===B.end1.attributeRef&&P.attrType==="RELATION_REF");x&&Ho(l,f,M.modelId,x.modelId)}const I={...e,entities:e.entities.filter(B=>B.modelId!==R),associations:e.associations.filter(B=>!w.has(B.modelId))},v=new Set($.filter(B=>B.end1.entityRef===R&&B.end2.entityRef!==R).map(B=>B.end2.entityRef));Fl(l,I,[...v],i,g,f,d);for(const B of e.groups)B.memberEntityRefs.includes(R)&&(b.has(_(B.modelId,R))||(b.add(_(B.modelId,R)),l.push({kind:"group.removeMember",casUnit:"logical",containerRef:B.modelId,groupRef:B.modelId,entityRef:R})));p.add(R),l.push({kind:"entity.remove",casUnit:"logical",entityRef:R});break}case"attribute.add":{{const I=Nn(y.spec,Du);if(I.length){s.push({code:"attribute-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:I});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(y.spec.type==="GroupCodeEnum"&&!y.spec.groupCode){s.push({code:"groupcode-required",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}if(!r(y.spec.type)&&!((O=y.spec.embeddableOverrides)!=null&&O.length)&&Mu(y.spec)){s.push({code:"datatype-required",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}const R=d(C.value.modelId,C.value.attributes),$=r(y.spec.type);let w;if($)w=Bu(y.spec,$,R,C.value,e.entities,k,y.entity,s,i);else if((A=y.spec.embeddableOverrides)!=null&&A.length){s.push({code:"embeddable-type-unresolved",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}else w=Vu(y.spec,R,i);if(!w)break;l.push({kind:"attribute.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,value:w}),h.push({entityId:C.value.modelId,attribute:w}),w.identifier&&g.identifierCascadeParents.add(C.value.modelId);break}case"attribute.update":case"attribute.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=Ru(C.value,y.attribute);if(!R.ok){s.push(R.reason==="not-found"?{code:"attribute-not-found",opIndex:k,entity:y.entity,handle:y.attribute}:{code:"attribute-ambiguous",opIndex:k,entity:y.entity,handle:y.attribute,matches:R.matches});break}if(y.kind==="attribute.update"){const $=[],w=[];let I=!1;for(const x of Object.keys(y.patch)){if(x.includes(".")){x.startsWith("dbAttrs.")?I=!0:w.push(x);continue}zl.has(x)?$.push(x):Wb.has(x)||w.push(x)}if(w.length){s.push({code:"attribute-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.attribute,keys:w});break}if("attrType"in y.patch){const x=String(y.patch.attrType),P=wu.includes(x)?x!==R.value.attrType?"transition":void 0:"unknown-value";if(P){s.push({code:"attribute-attrtype-unsupported",opIndex:k,entity:y.entity,handle:y.attribute,reason:P,current:R.value.attrType,requested:x});break}}const v="type"in y.patch?y.patch.type:R.value.type,B="groupCode"in y.patch?y.patch.groupCode:R.value.groupCode;if(v==="GroupCodeEnum"&&!B){s.push({code:"groupcode-required",opIndex:k,entity:y.entity,handle:y.attribute});break}let M=y.patch;if($.length){const x=a_(R.value,y.patch,$,I);if(!x){s.push({code:"attribute-patch-dbattr-flat-key",opIndex:k,entity:y.entity,handle:y.attribute,keys:$});break}M=x}if((V=y.embeddableOverrides)!=null&&V.length){const x=r(R.value.type);if(!x||R.value.attrType!=="EMBED_PREDEF"){s.push({code:"embeddable-type-unresolved",opIndex:k,entity:y.entity,handle:y.attribute});break}const P=r_(R.value,x,y.embeddableOverrides,C.value,e.entities,k,y.entity,s);if(!P)break;M={...M,dbAttrs:P}}l.push({kind:"attribute.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,attributeRef:R.value.modelId,patch:M}),g.attrPatches.push({entityId:C.value.modelId,attributeId:R.value.modelId,patch:M});{const x=R.value,P=Fu(x,M),q=(P.identifier??!1)!==(x.identifier??!1),ce=(x.identifier||P.identifier)&&("type"in M||"customType"in M||"dbAttrs"in M||Object.keys(M).some(ge=>ge.startsWith("dbAttrs.")));(q||ce)&&g.identifierCascadeParents.add(C.value.modelId)}}else{const $=Lo(e,C.value.modelId,R.value.modelId);if($){const w=I=>{var v;return((v=e.entities.find(B=>B.modelId===I))==null?void 0:v.name)??I};s.push({code:"attribute-fk-managed",opIndex:k,entity:y.entity,handle:y.attribute,association:{from:w($.end1.entityRef),to:w($.end2.entityRef)}});break}Ho(l,f,C.value.modelId,R.value.modelId),R.value.identifier&&g.identifierCascadeParents.add(C.value.modelId)}break}case"association.add":{{const B=Nn(y.spec,Xb);if(B.length){s.push({code:"association-spec-unknown-key",opIndex:k,handle:{from:y.spec.from,to:y.spec.to},keys:B});break}}const C=St(e,y.spec.from),R=St(e,y.spec.to);if(C.ok||s.push(xt(C.reason,k,y.spec.from,C.matches,E)),R.ok||s.push(xt(R.reason,k,y.spec.to,R.matches,E)),!C.ok||!R.ok)break;if(y.spec.identifying&&C.value.modelId===R.value.modelId){s.push({code:"self-identifying",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}if(C.value.stereotype==="JPA_EMBEDDABLE"||R.value.stereotype==="JPA_EMBEDDABLE"){s.push({code:"embeddable-relation-unsupported",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}if(C.value.stereotype==="SERIALIZED_TYPE"||R.value.stereotype==="SERIALIZED_TYPE"){s.push({code:"serialized-relation-invalid",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}const $=i(),w={modelId:$,...y.spec.identifying!=null?{identifying:y.spec.identifying}:{},end1:{entityRef:C.value.modelId,multiplicity:y.spec.fromMultiplicity??"EXACTLY_ONE_INSTANCE",navigable:!1,composition:!1},end2:{entityRef:R.value.modelId,multiplicity:y.spec.toMultiplicity??"ZERO_OR_MORE_INSTANCES",navigable:!0,composition:y.spec.composition??!1}},I={...e,associations:[...e.associations,w]},v=pi(I,R.value.modelId,i);v.add[0]&&(w.end2.attributeRef=v.add[0].modelId),l.push({kind:"association.add",casUnit:"logical",associationRef:$,value:w}),g.addedAssociations.push(w);for(const B of v.add){const M={...B,order:d(R.value.modelId,R.value.attributes)};l.push({kind:"attribute.add",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,value:M}),g.cascadeAdds.push({entityId:R.value.modelId,attribute:M})}break}case"association.remove":{const C=St(e,y.association.from),R=St(e,y.association.to);if(C.ok||s.push(xt(C.reason,k,y.association.from,C.matches,E)),R.ok||s.push(xt(R.reason,k,y.association.to,R.matches,E)),!C.ok||!R.ok)break;const $=xu(e,C.value.modelId,R.value.modelId);if($.length!==1){s.push($.length===0?{code:"association-not-found",opIndex:k,handle:y.association}:{code:"association-ambiguous",opIndex:k,handle:y.association,matches:$.map(B=>B.modelId)});break}const w=$[0];m.has(w.modelId)||(m.add(w.modelId),l.push({kind:"association.remove",casUnit:"logical",associationRef:w.modelId}));const I=e.entities.find(B=>B.attributes.some(M=>{var x;return((x=M.embedded)==null?void 0:x.associationRef)===w.modelId}));if(I){const B=I.attributes.find(M=>{var x;return((x=M.embedded)==null?void 0:x.associationRef)===w.modelId});Ho(l,f,I.modelId,B.modelId);break}if(w.end1.attributeRef){const B=e.entities.find(x=>x.modelId===w.end1.entityRef),M=B==null?void 0:B.attributes.find(x=>x.modelId===w.end1.attributeRef&&x.attrType==="RELATION_REF");M&&Ho(l,f,B.modelId,M.modelId)}const v={...e,associations:e.associations.filter(B=>B.modelId!==w.modelId)};Fl(l,v,[w.end2.entityRef],i,g,f,d);break}case"association.update":{const C=Hu(e,y.association,k,s,E);if(!C)break;const R=y.patch.identifying,$=typeof R=="boolean"?R:void 0;if($===!0&&C.end1.entityRef===C.end2.entityRef){s.push({code:"self-identifying",opIndex:k,handle:y.association});break}const w=uo(y.patch,e_);if(w.length){s.push({code:"association-patch-unknown-key",opIndex:k,handle:y.association,keys:w});break}if(l.push({kind:"association.update",casUnit:"logical",containerRef:C.modelId,associationRef:C.modelId,patch:y.patch}),g.assocPatches.push({associationRef:C.modelId,patch:y.patch}),$!==void 0&&$!==(C.identifying??!1)){const I={...e,associations:e.associations.map(v=>v.modelId===C.modelId?{...v,identifying:$}:v)};Fl(l,I,[C.end2.entityRef],i,g,f,d)}break}case"associationEnd.update":{const C=Hu(e,y.association,k,s,E);if(!C)break;const R=y.end==="from"?"end1":"end2";if(Object.prototype.hasOwnProperty.call(y.patch,"navigable")){s.push({code:"navigable-toggle-unsupported",opIndex:k,handle:y.association});break}const $=uo(y.patch,t_,["jpa."]);if($.length){s.push({code:"association-end-patch-unknown-key",opIndex:k,handle:y.association,keys:$});break}l.push({kind:"associationEnd.update",casUnit:"logical",containerRef:C.modelId,associationRef:C.modelId,end:R,patch:y.patch}),g.endPatches.push({associationRef:C.modelId,end:R,patch:y.patch});break}case"index.add":{{const $=Nn(y.spec,Ou);if($.length){s.push({code:"index-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:$});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=zu(C.value,y.spec,k,y.entity,s,i);if(!R)break;l.push({kind:"index.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.modelId,value:R});break}case"index.update":case"index.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(Pl(y.index)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:y.index,target:"index"});break}const R=qb(C.value,y.index);if(!R.ok){s.push(R.reason==="not-found"?{code:"index-not-found",opIndex:k,entity:y.entity,handle:y.index}:{code:"index-ambiguous",opIndex:k,entity:y.entity,handle:y.index,matches:R.matches});break}if(y.kind==="index.update"){if("columns"in y.patch){s.push({code:"index-columns-patch-unsupported",opIndex:k,entity:y.entity,handle:y.index});break}const $=uo(y.patch,n_);if($.length){s.push({code:"index-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.index,keys:$});break}l.push({kind:"index.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.value.modelId,patch:y.patch})}else l.push({kind:"index.remove",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.value.modelId});break}case"operation.add":{{const w=Nn(y.spec,Lu);if(w.length){s.push({code:"operation-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:w});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=u.get(C.value.modelId)??(C.value.operations?Ht(C.value.operations):0);u.set(C.value.modelId,R+1);const $=Pu(y.spec,R,i);l.push({kind:"operation.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:$.modelId,value:$});break}case"operation.update":case"operation.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(Pl(y.operation)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:y.operation,target:"operation"});break}const R=$u(C.value,y.operation);if(!R.ok){s.push(R.reason==="not-found"?{code:"operation-not-found",opIndex:k,entity:y.entity,handle:y.operation}:{code:"operation-ambiguous",opIndex:k,entity:y.entity,handle:y.operation,matches:R.matches});break}if(y.kind==="operation.update"){const $=uo(y.patch,o_);if($.length){s.push({code:"operation-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.operation,keys:$});break}l.push({kind:"operation.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:R.value.modelId,patch:y.patch})}else l.push({kind:"operation.remove",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:R.value.modelId});break}case"attribute.reorder":case"operation.reorder":{const C=y.kind==="attribute.reorder",R=St(e,y.entity);if(!R.ok){s.push(xt(R.reason,k,y.entity,R.matches,E));break}const $=C?y.order:y.operations,w=[],I=new Set;let v=!1;for(const P of $){if(!C&&Pl(P)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:P,target:"operation"}),v=!0;continue}const q=C?Ru(R.value,P):$u(R.value,P);if(!q.ok){s.push(q.reason==="not-found"?{code:"reorder-handle-not-found",opIndex:k,entity:y.entity,handle:P}:{code:"reorder-handle-ambiguous",opIndex:k,entity:y.entity,handle:P,matches:q.matches}),v=!0;continue}if(I.has(q.value.modelId)){s.push({code:"reorder-handle-duplicate",opIndex:k,entity:y.entity,handle:P}),v=!0;continue}I.add(q.value.modelId),w.push(q.value)}if(v)break;const M=[...C?R.value.attributes:R.value.operations??[]].sort((P,q)=>P.order-q.order).filter(P=>!I.has(P.modelId)),x=[...w,...M];if(x.forEach((P,q)=>{P.order!==q&&l.push(C?{kind:"attribute.update",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,attributeRef:P.modelId,patch:{order:q}}:{kind:"operation.update",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,operationRef:P.modelId,patch:{order:q}})}),C)for(const P of Cu(e,R.value.modelId,x.map(q=>q.modelId)))l.push({kind:"attribute.update",casUnit:"logical",containerRef:P.entityId,entityRef:P.entityId,attributeRef:P.attributeId,patch:{dbAttrs:P.dbAttrs}});break}case"group.add":{{const I=Nn(y.spec,Zb);if(I.length){s.push({code:"group-spec-unknown-key",opIndex:k,keys:I});break}}const C=[];let R=!1;for(const I of y.spec.members){const v=St(e,I);if(!v.ok){s.push(xt(v.reason,k,I,v.matches,E)),R=!0;continue}C.push(v.value.modelId)}if(R)break;const $=i(),w={modelId:$,excludeDDLGeneration:y.spec.excludeDDLGeneration??!1,memberEntityRefs:C,...y.spec.name?{name:y.spec.name}:{},...y.spec.packageName?{packageName:y.spec.packageName}:{},...y.spec.description?{description:y.spec.description}:{}};l.push({kind:"group.add",casUnit:"logical",groupRef:$,value:w});break}case"group.update":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}const R=uo(y.patch,Ub);if(R.length){s.push({code:"group-patch-unknown-key",opIndex:k,handle:y.group,keys:R});break}l.push({kind:"group.update",casUnit:"logical",containerRef:C.value.modelId,groupRef:C.value.modelId,patch:y.patch});break}case"group.remove":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}l.push({kind:"group.remove",casUnit:"logical",groupRef:C.value.modelId});break}case"group.addMember":case"group.removeMember":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}const R=St(e,y.entity);if(!R.ok){s.push(xt(R.reason,k,y.entity,R.matches,E));break}const $=C.value.memberEntityRefs.includes(R.value.modelId);if(y.kind==="group.addMember"?$:!$)break;if(y.kind==="group.removeMember"){if(b.has(_(C.value.modelId,R.value.modelId)))break;b.add(_(C.value.modelId,R.value.modelId))}l.push({kind:y.kind,casUnit:"logical",containerRef:C.value.modelId,groupRef:C.value.modelId,entityRef:R.value.modelId});break}}}),s.length||d_(l,e,p,m,f,h,g,i,d),s.length||l_(l,e,f,p),s.length||s_(l,e,f,h,p,i),s.length?{ok:!1,errors:s}:{ok:!0,ops:l}}function xt(e,n,o,i,a){return e==="not-found"&&(a!=null&&a.has(o.ref))?{code:"pending-entity-ref",opIndex:n,handle:o}:e==="not-found"?{code:"entity-not-found",opIndex:n,handle:o}:{code:"entity-ambiguous",opIndex:n,handle:o,matches:i}}function Hu(e,n,o,i,a){const r=St(e,n.from),l=St(e,n.to);if(r.ok||i.push(xt(r.reason,o,n.from,r.matches,a)),l.ok||i.push(xt(l.reason,o,n.to,l.matches,a)),!r.ok||!l.ok)return null;const s=xu(e,r.value.modelId,l.value.modelId);return s.length!==1?(i.push(s.length===0?{code:"association-not-found",opIndex:o,handle:n}:{code:"association-ambiguous",opIndex:o,handle:n,matches:s.map(c=>c.modelId)}),null):s[0]}const ju={type:"object",description:"요소 지정 핸들. 엔티티: 물리명(table.physicalName) 우선, 논리명(name) 보조. 속성: 소속 엔티티 내 속성명 또는 컬럼 물리명.",properties:{ref:{type:"string",description:"매칭할 이름/물리명. by:'modelId'면 modelId 원문."},by:{type:"string",enum:["physicalName","name","modelId"],description:"매칭 키 고정(미지정 시 대상별 기본 순서). 'modelId'는 모호 해소 전용 탈출구 — 평시엔 쓰지 말고, entity-ambiguous 응답의 후보를 사용자에게 제시해 확인받은 뒤 그 modelId로 재전송할 때만 쓴다."}},required:["ref"],additionalProperties:!1},m_={type:"object",description:"엔티티 내 이름으로 지정(인덱스명·메서드명). 물리명 차원이 없어 매칭 키 고정(`by`)을 받지 않는다.",properties:{ref:{type:"string",description:"매칭할 이름."}},required:["ref"],additionalProperties:!1},f_={type:"object",description:"관계는 무명이라 양 끝 엔티티로 주소. from=부모(end1), to=자식(end2). 같은 쌍 복수 관계는 모호 보고.",properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"}},required:["from","to"],additionalProperties:!1},p_={type:"object",description:"신규 엔티티. 자식(속성·인덱스·operation)은 별도 attribute.add 등이 아니라 여기 inline 배열로 담아라 — 같은 배치에서 갓 추가된 엔티티에 닿는 child op은 silent no-op이 된다(서버가 pending-entity-ref로 거부). 관계는 inline 불가 → 엔티티 추가 배치 확정 후 별도 배치로 association.add.",properties:{name:{type:"string"},stereotype:{type:"string",enum:["UNDEFINED","JPA_ENTITY","JPA_EMBEDDABLE","JPA_MULTI_LANGUAGE_ENTITY","SERIALIZED_TYPE"],description:"기본 JPA_ENTITY."},physicalName:{type:"string",description:"설정 시 table.physicalName."},useVersion:{type:"boolean",description:'JPA @Version(낙관적 락) → jpaAttrs.useVersion. @Version 필드는 별도 속성이 아니라 이 엔티티 플래그로 흡수 (버전 컬럼은 코드젠 소유). 기존 엔티티는 entity.update patch의 dotted key {"jpaAttrs.useVersion":true} 사용.'},attributes:{type:"array",description:"inline 속성(배열 순서가 order). attribute.add와 동일 규칙 — GroupCodeEnum은 groupCode 동반 필수.",items:{$ref:"#/$defs/attrSpec"}},indexes:{type:"array",description:"inline 인덱스. 컬럼 핸들은 이 엔티티가 inline으로 만드는 dbAttr 내에서 해소된다(attributes 동반 전제).",items:{$ref:"#/$defs/indexSpec"}},operations:{type:"array",description:"inline 도메인 메서드(배열 순서가 order).",items:{$ref:"#/$defs/operationSpec"}},serialization:{$ref:"#/$defs/serialization"}},required:["name"],additionalProperties:!1},h_={type:"object",description:"직렬화 타입의 컨테이너(SERIALIZED_TYPE 전용). 미지정 = 컬렉션이 아닌 단일 값(한 컬럼에 구조 하나). 신규 엔티티는 entity.add 에 함께 줘야 한다 — 같은 배치의 entity.update 는 갓 만든 엔티티에 닿지 못한다.",properties:{collectionType:{type:"string",enum:["LIST","SET","MAP"],description:"컨테이너 종류. 코퍼스 실재가 java.util 3종뿐이라 그만 표현한다(미지 컨테이너는 발명하지 않는다)."},mapKeyType:{type:"string",description:"collectionType='MAP' 일 때의 키 타입(단순명 또는 FQN). 그 외엔 무의미."}},additionalProperties:!1},zn={type:"object",properties:{ko:{type:"string"},en:{type:"string"},ja:{type:"string"},zh:{type:"string"}},additionalProperties:!1},y_={type:"object",properties:{name:{type:"string"},type:{type:"string",description:"Java 타입(예: Long, String). GroupCodeEnum은 파생 타입이라 groupCode 동반 필수(없으면 거부). 호스트 임베더블 카탈로그에 등록된 predefined 임베더블 타입(예: Money, EmbeddableAddress)이면 EMBED_PREDEF로 다중 컬럼 확장(서브컬럼 조정은 embeddableOverrides)."},identifier:{type:"boolean"},notNull:{type:"boolean"},transient:{type:"boolean",description:"JPA @Transient(비영속) → Attribute.transient. 컬럼을 만들지 않으므로 physicalName/dataType 등 컬럼 필드는 함께 주지 않는다. 기존 속성은 attribute.update patch {transient:true}로도 가능."},physicalName:{type:"string",description:"설정 시 단일 dbAttr 컬럼 생성(미설정이면 name을 물리명으로)."},dataType:{type:"string",description:"dbAttr 물리 타입(예: BIGINT). physicalName/dataType/length/scale 중 하나라도 있으면 컬럼 생성."},length:{type:"integer",description:"dbAttr 컬럼 길이(VARCHAR(n)·DECIMAL precision)."},scale:{type:"integer",description:"dbAttr 소수 자릿수(DECIMAL/NUMERIC scale). length 동반이 일반적."},groupCode:{type:"string",description:"코드성 속성의 group code 바인딩. type=GroupCodeEnum이면 필수."},defaultValue:{type:"string",description:"속성 기본값(문자열 패스스루)."},attributeGroup:{type:"string",description:"속성 분류 그룹(예: 'code'·'amt')."},description:{...zn,description:"속성 설명(다국어)."},columnLogicalName:{...zn,description:'dbAttr 컬럼 논리명(다국어, 예: {ko:"체크아웃유형"}). 한글 업무명 보존 위치.'},unique:{type:"boolean",description:"dbAttr UNIQUE 제약."},updatable:{type:"boolean",description:"dbAttr 갱신 가능(JPA @Column(updatable=))."},embeddableOverrides:{$ref:"#/$defs/embeddableOverrides"},collectionType:{type:"string",enum:["LIST","SET"],description:"이 «필드»가 컬렉션인가 — **직렬화 타입(SERIALIZED_TYPE)의 자기 필드 전용**(예: Set<String>·List<StoredFile>). 컬럼 있는 자리는 읽지 않는다 — 그쪽 컨테이너는 요소 타입이 소유한다(entity 의 serialization.collectionType). 요소가 문서 안 직렬화 타입이면 그 타입이 이미 감싸므로 지정하지 않는다. 미지정 = 컬렉션 아님."}},required:["name","type"],additionalProperties:!1},g_={type:"array",description:"predefined 임베더블 서브컬럼 오버라이드(속성 type이 카탈로그 엔트리이자 EMBED_PREDEF일 때만). field=카탈로그 필드명으로 매칭(@AttributeOverride 대응). 미설정 서브컬럼은 add=카탈로그 기본 상속 / update=기존값 유지. currency 등 공유 컬럼은 sharedColumnPhysicalName으로 SHARED_REF.",items:{type:"object",properties:{field:{type:"string",description:"대상 카탈로그 필드명(예: amount·currency)."},physicalName:{type:"string",description:"서브컬럼 물리명 오버라이드(@AttributeOverride column name). 미설정 시 카탈로그 기본."},length:{type:"integer",description:"서브컬럼 길이 오버라이드."},scale:{type:"integer",description:"서브컬럼 소수 자릿수 오버라이드."},insertable:{type:"boolean",description:"JPA @Column(insertable=). OWN 컬럼에만 저장."},updatable:{type:"boolean",description:"JPA @Column(updatable=). OWN 컬럼에만 저장."},sharedColumnPhysicalName:{type:"string",description:"SHARED_REF — 같은 엔터티(임베더블이면 owner 합집합) 다른 컬럼(물리명)을 공유해 read-only 투영(대표: currency). 설정 시 자체 컬럼 미보유, 타깃은 해소 시점 존재 필수."}},required:["field"],additionalProperties:!1}},Ku={type:"string",enum:["NO_INSTANCE_OR_ONE_INSTANCE","EXACTLY_ONE_INSTANCE","ZERO_OR_MORE_INSTANCES","ONE_OR_MORE_INSTANCES"]},b_={type:"object",description:'일반 연관 생성. 양 end 는 일반 엔티티여야 한다 — 임베더블(JPA_EMBEDDABLE)·직렬화 타입을 end 로 주면 거부된다. 직렬화 타입은 관계가 아니라 소비 속성의 type 으로 지목한다(attribute.update {type: "<타입명>"}). (임베드는 EMBED 관계여야 하고 이 어휘엔 없다 → 캔버스에서 연결).',properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"},fromMultiplicity:{...Ku,description:"end1 다중성(기본 EXACTLY_ONE_INSTANCE)."},toMultiplicity:{...Ku,description:"end2 다중성(기본 ZERO_OR_MORE_INSTANCES)."},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK로 전파). self-association은 식별 불가."},composition:{type:"boolean",description:"end2 composition."}},required:["from","to"],additionalProperties:!1},__={type:"object",properties:{name:{type:"string"},unique:{type:"boolean",description:"UNIQUE 인덱스 여부(기본 false)."},columns:{type:"array",description:"인덱스 컬럼(순서 의미 있음).",items:{type:"object",properties:{column:{...ju,description:"컬럼 핸들 — 컬럼 물리명 우선, 속성명 보조(단일 컬럼 속성만). 엔티티 내에서 dbAttr modelId로 해소."},descending:{type:"boolean",description:"내림차순(기본 false)."}},required:["column"],additionalProperties:!1}},description:{type:"string",description:"인덱스 설명(평문)."},parameters:{type:"string",description:"인덱스 파라미터(패스스루)."}},required:["name","columns"],additionalProperties:!1},k_={type:"object",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"],description:"가시성(기본 미설정)."},sourceCode:{type:"string",description:"Java 메서드 본문(멀티라인, 파라미터·반환 시그니처 포함)."},description:{...zn,description:"메서드 설명(다국어)."},personalInfoAttributeType:{type:"string",description:"개인정보 속성 유형(패스스루)."}},required:["name"],additionalProperties:!1},E_={type:"object",properties:{name:{...zn,description:'그룹 논리명(다국어, 예: {ko:"주문"}).'},packageName:{type:"string",description:"자바 패키지명 등 그룹 물리 식별(레거시 LogicalGroup.packageName)."},description:{type:"string",description:"그룹 설명(자유 텍스트 — 도메인 경계 메모)."},excludeDDLGeneration:{type:"boolean",description:"DDL 생성 제외(기본 false)."},members:{type:"array",description:"멤버 엔티티 핸들(물리명 우선/논리명 보조). 기존 엔티티여야 함 — 같은 배치 신규 엔티티는 별도 배치 후.",items:{$ref:"#/$defs/handle"}}},required:["members"],additionalProperties:!1},N_={type:"object",description:"기존 속성 부분 patch. 논리 필드 + 스칼라 단일 컬럼의 물리 필드(physicalName·dataType·length·scale 등 — 서버가 dbAttrs[0]에 매핑). EMBED_PREDEF/Money 서브컬럼 조정은 op-레벨 embeddableOverrides로(평탄 키는 다중 컬럼서 모호해 거부).",properties:{name:{type:"string"},type:{type:"string"},customType:{type:"string"},attrType:{type:"string",enum:[...wu],description:"속성 종류. **현재 값과 다르게 주면 거부된다** — 관계/임베드/구분선은 동반 구조(관계 소유·embedded·빈 dbAttrs)가 있어야 성립하고 patch로는 표현할 수 없다. 관계 실체화는 association.add, 임베드 서브컬럼은 embeddableOverrides 소관."},identifier:{type:"boolean"},notNull:{type:"boolean"},transient:{type:"boolean"},naturalId:{type:"boolean"},naturalIdMutable:{type:"boolean"},derivedIdFieldName:{type:"string",description:"파생 식별(@MapsId) FK가 매핑되는 **스칼라 @Id 필드명**. 이 속성의 name은 연관 필드명(@MapsId @OneToOne 필드)이고 같은 관계가 두 Java 필드를 만든다. 단일 컬럼 @OneToOne 식별 FK에만 의미가 있고, 미설정 시 부모 PK 물리명의 camelCase로 파생된다(실물 관행). 컬럼은 공유하므로 속성은 하나이며 물리명은 지정하지 않는다."},description:{...zn,description:"속성 설명(다국어)."},attributeGroup:{type:"string"},groupCode:{type:"string"},defaultValue:{type:"string"},personalInfoAttributeType:{type:"string"},order:{type:"integer"},physicalName:{type:"string"},dataType:{type:"string"},length:{type:"integer"},scale:{type:"integer"},unique:{type:"boolean"},updatable:{type:"boolean"},insertable:{type:"boolean"},autoIncrement:{type:"boolean"},multiValue:{type:"boolean"},multiValueSeparator:{type:"string"},sequenceName:{type:"string"},logicalName:{...zn,description:"컬럼 논리명(다국어)."}},additionalProperties:!1},w_={type:"object",description:"관계 부분 patch. 양 end 설정(multiplicity·nav·jpa)은 associationEnd.update로.",properties:{description:{type:"string"},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK 일부로 전파)."}},additionalProperties:!1},I_={type:"object",description:"인덱스 부분 patch. columns(컬럼 구성) 변경은 index.remove+index.add로(패치 불가).",properties:{name:{type:"string"},unique:{type:"boolean"},description:{type:"string"},parameters:{type:"string"}},additionalProperties:!1},v_={type:"object",description:"메서드 부분 patch.",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"]},sourceCode:{type:"string"},description:{...zn,description:"메서드 설명(다국어)."},order:{type:"integer"},personalInfoAttributeType:{type:"string"}},additionalProperties:!1},C_={type:"object",description:'엔티티 부분 patch. 논리 키: name·stereotype·packageName·superClass·schema·description·abstractClass·hasPersonalInfo·referenceOnly·declarationOfInterfaces·table·serialization. serialization(직렬화 타입 컨테이너)은 통째로 주거나(예: {"serialization":{"collectionType":"LIST"}}) dotted-key로 준다({"serialization.collectionType":"LIST"}). 컬렉션 아님으로 되돌릴 땐 null 로 비운다(wire clear 규약). jpaAttrs 플래그(useVersion 등)는 형제 클로버 방지를 위해 dotted-key로 준다: {"jpaAttrs.useVersion": true}. 자식(attributes/indexes/operations)은 patch가 아니라 전용 op로 변경. stereotype 은 값 타입(JPA_EMBEDDABLE·SERIALIZED_TYPE) 경계를 넘을 수 없다 — 들어가고 나오는 전환은 PK 해제/부여·FK reconcile·EMBED 복원/해체가 동반되는 composite라 patch로 표현되지 않는다(거부. 전환은 GUI 소관).'},S_={type:"object",description:'관계 end 부분 patch. 논리 키: multiplicity·navigable·composition. jpa 설정(cascadeTypes·fetchType·orphanRemoval·orderBy·collectionType·collectionTable·orderColumn)은 형제 클로버 방지를 위해 dotted-key로: {"jpa.orphanRemoval": true}.'};function ft(e,n){return{type:"object",properties:{kind:{const:e},...n.properties},required:["kind",...n.required],additionalProperties:!1}}const x_={"entity.add":ft("entity.add",{properties:{spec:{$ref:"#/$defs/entitySpec"}},required:["spec"]}),"entity.update":ft("entity.update",{properties:{entity:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/entityUpdatePatch"}},required:["entity","patch"]}),"entity.remove":ft("entity.remove",{properties:{entity:{$ref:"#/$defs/handle"}},required:["entity"]}),"attribute.add":ft("attribute.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/attrSpec"}},required:["entity","spec"]}),"attribute.update":ft("attribute.update",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/attrUpdatePatch"},embeddableOverrides:{$ref:"#/$defs/embeddableOverrides"}},required:["entity","attribute","patch"]}),"attribute.remove":ft("attribute.remove",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"}},required:["entity","attribute"]}),"association.add":ft("association.add",{properties:{spec:{$ref:"#/$defs/assocSpec"}},required:["spec"]}),"association.remove":ft("association.remove",{properties:{association:{$ref:"#/$defs/assocHandle"}},required:["association"]}),"association.update":ft("association.update",{properties:{association:{$ref:"#/$defs/assocHandle"},patch:{$ref:"#/$defs/assocUpdatePatch"}},required:["association","patch"]}),"associationEnd.update":ft("associationEnd.update",{properties:{association:{$ref:"#/$defs/assocHandle"},end:{type:"string",enum:["from","to"],description:"from=부모(end1), to=자식(end2)."},patch:{$ref:"#/$defs/assocEndUpdatePatch"}},required:["association","end","patch"]}),"index.add":ft("index.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/indexSpec"}},required:["entity","spec"]}),"index.update":ft("index.update",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/indexUpdatePatch"}},required:["entity","index","patch"]}),"index.remove":ft("index.remove",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"}},required:["entity","index"]}),"operation.add":ft("operation.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/operationSpec"}},required:["entity","spec"]}),"operation.update":ft("operation.update",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/operationUpdatePatch"}},required:["entity","operation","patch"]}),"operation.remove":ft("operation.remove",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"}},required:["entity","operation"]}),"attribute.reorder":ft("attribute.reorder",{properties:{entity:{$ref:"#/$defs/handle"},order:{type:"array",items:{$ref:"#/$defs/handle"},minItems:1}},required:["entity","order"]}),"operation.reorder":ft("operation.reorder",{properties:{entity:{$ref:"#/$defs/handle"},operations:{type:"array",items:{$ref:"#/$defs/nameHandle"},minItems:1}},required:["entity","operations"]}),"group.add":ft("group.add",{properties:{spec:{$ref:"#/$defs/groupSpec"}},required:["spec"]}),"group.update":ft("group.update",{properties:{group:{$ref:"#/$defs/groupHandle"},patch:{$ref:"#/$defs/groupUpdatePatch"}},required:["group","patch"]}),"group.remove":ft("group.remove",{properties:{group:{$ref:"#/$defs/groupHandle"}},required:["group"]}),"group.addMember":ft("group.addMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]}),"group.removeMember":ft("group.removeMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]})},R_={type:"object",description:"그룹 지정 핸들. 패키지명(packageName) 우선, 이름(name) 보조 — 이름은 다국어라 어느 로케일 값이든 일치하면 매칭. 'modelId'는 모호 해소 전용(group-ambiguous 후보를 사용자에게 확인받은 뒤).",properties:{ref:{type:"string",description:"매칭할 패키지명/이름. by:'modelId'면 modelId 원문."},by:{type:"string",enum:["packageName","name","modelId"],description:"매칭 키 고정(미지정 시 packageName → name)."}},required:["ref"],additionalProperties:!1},A_={type:"object",description:"그룹 부분 patch. 멤버 변경은 group.addMember/removeMember로(배열 통째 교체는 동시 편집이 서로를 덮는다).",properties:{name:{...zn,description:"그룹 논리명(다국어)."},packageName:{type:"string"},description:{type:"string"},excludeDDLGeneration:{type:"boolean"}},additionalProperties:!1},Gu={anyOf:Nu.map(e=>x_[e])},$_={type:"object",description:"엔티티 모델을 생성·수정·삭제할 때 호출한다. ops는 사람 핸들(엔티티 물리명/논리명, 속성명)로 지정하며 서버가 modelId로 해소한다. 모호하면 에러로 후보를 돌려주니 리소스로 현재 모델을 먼저 읽어 핸들을 확정하라.",properties:{ops:{type:"array",items:{$ref:"#/$defs/symbolicOp"}}},required:["ops"],additionalProperties:!1,$defs:{handle:ju,nameHandle:m_,groupHandle:R_,assocHandle:f_,entitySpec:p_,serialization:h_,attrSpec:y_,embeddableOverrides:g_,assocSpec:b_,indexSpec:__,operationSpec:k_,groupSpec:E_,entityUpdatePatch:C_,attrUpdatePatch:N_,assocUpdatePatch:w_,assocEndUpdatePatch:S_,indexUpdatePatch:I_,operationUpdatePatch:v_,groupUpdatePatch:A_,symbolicOp:Gu}};function T_(e,n,o,i={}){const a=i.mkClientOpId??Pe,r=new Set;for(const s of o)s.casUnit==="logical"&&s.containerRef&&r.add(s.containerRef);const l={};if(r.size){l.revs={};for(const s of r)l.revs[s]=n[s]??0}return{diagramId:e,ops:o,cas:l,origin:i.origin??"agent",clientOpId:a()}}const Yu={location:{x:0,y:0},size:{width:220,height:140}};function qu(e){return{modelId:e.modelId,physicalName:e.physicalName,logicalName:e.logicalName,dataType:e.dataType,length:e.length,scale:e.scale,unique:e.unique,autoIncrement:e.autoIncrement,updatable:e.updatable,insertable:e.insertable,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}const M_=/^[-=_*~\s]{3,}$/;function V_(e){return e.attrType&&e.attrType!=="NORMAL"||!M_.test(e.name??"")?!1:!(e.dbAttrs??[]).some(n=>n.physicalName||n.dataType)}function B_(e){return e.type===_n&&e.customType==="java.util.Currency"?{type:"Currency",customType:void 0}:{type:e.type,customType:e.customType}}function D_(e,n){if(e.attrType==="DIVIDER"||V_(e))return{modelId:e.modelId,name:e.attrType==="DIVIDER"?e.name:"",type:"",attrType:"DIVIDER",identifier:!1,notNull:!1,order:e.order??n,dbAttrs:[]};const o=B_(e);return{modelId:e.modelId,name:e.name,type:o.type,customType:o.customType,attrType:e.attrType,identifier:e.identifier,notNull:e.notNull,transient:e.transient_,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:e.order??n,dbAttrs:e.dbAttrs.map(qu)}}function O_(e,n){const{modelId:o,name:i,visibility:a,sourceCode:r,description:l,order:s,personalInfoAttributeType:c,style:d,...u}=e;return{modelId:o,name:i,visibility:a,sourceCode:r,description:l?{ko:l}:void 0,order:s??n,personalInfoAttributeType:c,legacyRaw:Object.keys(u).length?u:void 0}}function L_(e){return{modelId:e.modelId,name:e.name,unique:e.unique,description:e.description,parameters:e.parameters,columns:e.indexColumns.map(n=>({columnRef:n.targetColumn.refId,descending:n.descending}))}}function P_(e){var n,o;return{modelId:e.modelId,name:e.name,stereotype:e.stereotype,packageName:e.packageName,superClass:e.superClass,schema:e.schema,description:e.description,abstractClass:e.abstractClass,hasPersonalInfo:e.hasPersonalInfo,declarationOfInterfaces:e.declarationOfInterfaces,attributes:e.attributes.map(D_),operations:(n=e.operations)==null?void 0:n.map(O_),indexes:(o=e.indexes)==null?void 0:o.map(L_),jpaAttrs:e.jpaAttrs,table:e.dbAttrs?{physicalName:e.dbAttrs.physicalName,logicalName:e.dbAttrs.logicalName}:void 0}}function z_(e){const n={};for(const i of e.attributes)i.style&&(n[i.modelId]=i.style);const o={};for(const i of e.operations??[])i.style&&(o[i.modelId]=i.style);return{entityRef:e.modelId,geo:e.geo??{...Yu},style:e.style,attributeStyles:Object.keys(n).length?n:void 0,operationStyles:Object.keys(o).length?o:void 0,collapsed:e.collapsed,locked:e.locked}}function Wu(e){return e.jpaAttribute?{fetchType:e.jpaAttribute.fetchType,cascadeTypes:e.jpaAttribute.cascadeTypes,orphanRemoval:e.jpaAttribute.orphanRemoval,orderBy:e.jpaAttribute.orderBy,collectionType:e.jpaAttribute.collectionType,collectionTable:e.jpaAttribute.collectionTable,orderColumn:e.jpaAttribute.orderColumn}:void 0}function Ul(e){var n;return{entityRef:e.endModel.refId,multiplicity:e.multiplicity,navigable:e.navigable,composition:e.composition,attributeRef:(n=e.attribute)==null?void 0:n.modelId,jpa:Wu(e)}}function F_(e){if(e.end1.endModel.refId===e.end2.endModel.refId)return;const n=o=>Hl(o)&&(o==null?void 0:o.identifier)===!0;return n(e.end1.attribute)||n(e.end2.attribute)?!0:void 0}function U_(e){var i,a;const n={modelId:e.modelId,description:e.description,identifying:F_(e),end1:Ul(e.end1),end2:Ul(e.end2)},o={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:(i=e.end1.attribute)==null?void 0:i.modelId,targetColumnRef:(a=e.end2.attribute)==null?void 0:a.modelId,style:e.style};return{assoc:n,layout:o}}function Hl(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("RELATION")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function Ju(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("EMBED")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function Xu(e){var o;const n=e.attribute;return(n==null?void 0:n.attrType)==="EMBED_OWN"&&(((o=n.dbAttrs)==null?void 0:o.length)??0)===0&&(e.multiplicity==="ZERO_OR_MORE_INSTANCES"||e.multiplicity==="ONE_OR_MORE_INSTANCES")}function Zu(e,n){return{modelId:e.modelId,name:e.name??"",type:e.type??"",customType:e.customType,attrType:e.attrType??"RELATION_OWN",identifier:e.identifier??!1,notNull:e.notNull??!1,transient:e.transient_,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:n,dbAttrs:(e.dbAttrs??[]).map(qu)}}function H_(e,n,o){var y,k;const i=Hl(e.end1.attribute),a=Hl(e.end2.attribute);if(i===a)return U_(e);const r=i?e.end1:e.end2,l=i?e.end2:e.end1,s=r.attribute,c=(k=(y=s.dbAttrs)==null?void 0:y[0])==null?void 0:k.targetModelId,d=c?o.get(c):void 0,u=n.get(l.endModel.refId),m=u?u.attributes.reduce((S,T)=>Math.max(S,T.order),-1)+1:s.order??0,p={...Zu(s,m),attrType:"RELATION_OWN",derivedFrom:d?{associationRef:e.modelId,sourceAttributeRef:d}:void 0};u&&u.attributes.push(p);const f=n.get(r.endModel.refId),h=l.attribute;let g;if(h&&f&&r.navigable){const S=ca(l.multiplicity);g={modelId:h.modelId??crypto.randomUUID(),name:to(h.name??ua((u==null?void 0:u.name)??l.endModel.refId,S),new Set(f.attributes.map(T=>T.name))),type:(u==null?void 0:u.name)??l.endModel.refId,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:f.attributes.reduce((T,O)=>Math.max(T,O.order),-1)+1,dbAttrs:[]},f.attributes.push(g)}const b=(S,T)=>({entityRef:S.endModel.refId,multiplicity:S.multiplicity,navigable:S.navigable,composition:S.composition,attributeRef:T?g==null?void 0:g.modelId:p.modelId,jpa:Wu(S)}),_=r.endModel.refId===l.endModel.refId,E={modelId:e.modelId,description:e.description,identifying:!_&&p.identifier===!0?!0:void 0,end1:b(e.end1,i),end2:b(e.end2,a)},N={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:i?d:p.modelId,targetColumnRef:i?p.modelId:d,style:e.style};return{assoc:E,layout:N}}function j_(e,n){const o=e.targetModelId?n.get(e.targetModelId):void 0;return{modelId:e.modelId,physicalName:e.physicalName||(o==null?void 0:o.physicalName)||"",logicalName:e.logicalName??(o==null?void 0:o.logicalName),dataType:e.dataType||(o==null?void 0:o.dataType)||"",length:e.length??(o==null?void 0:o.length),scale:e.scale??(o==null?void 0:o.scale),unique:e.unique??(o==null?void 0:o.unique),autoIncrement:e.autoIncrement??(o==null?void 0:o.autoIncrement),updatable:e.updatable??(o==null?void 0:o.updatable),insertable:e.insertable??(o==null?void 0:o.insertable)}}function K_(e,n,o){var h;const i=((h=e.end1.attribute)==null?void 0:h.attrType)==="EMBED_OWN",a=i?e.end1:e.end2,r=i?e.end2:e.end1,l=a.attribute,s=n.get(r.endModel.refId),c=s?s.attributes.reduce((g,b)=>Math.max(g,b.order),-1)+1:l.order??0,d={...Zu(l,c),attrType:l.attrType??"EMBED_OWN",dbAttrs:(l.dbAttrs??[]).map(g=>j_(g,o)),embedded:{associationRef:e.modelId,embeddableRef:a.endModel.refId}};s&&s.attributes.push(d);const u=g=>({...Ul(g),legacyEmbedRaw:g.attribute}),m={modelId:e.modelId,description:e.description,end1:u(e.end1),end2:u(e.end2)},p=!i,f={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:p?d.modelId:void 0,targetColumnRef:p?void 0:d.modelId,style:e.style};return{assoc:m,layout:f}}function G_(e,n){var i,a,r,l;const o=[];for(const s of n){const c=(a=(i=s.end1)==null?void 0:i.endModel)==null?void 0:a.refId,d=(l=(r=s.end2)==null?void 0:r.endModel)==null?void 0:l.refId,u=c===e?d:c;!u||u===e||o.push({targetRef:u,waypoints:s.locations??[]})}return o}function Qu(e,n={x:0,y:0}){const{modelId:o,memo:i,geo:a,style:r,connections:l,ownedConnections:s,...c}=e;let d=l;if(!d&&Array.isArray(s)){const u=G_(o,s);u.length&&(d=u)}return{modelId:o,memo:i,geo:{location:{x:a.location.x+n.x,y:a.location.y+n.y},size:a.size},style:r,connections:d,legacyRaw:Object.keys(c).length?c:void 0}}function em(e,n,o){if(!(o!=null&&o.length))return;const i=new Map(e.map(l=>[l.modelId,l])),a=new Map(n.map(l=>[l.modelId,l])),r=(l,s)=>{var c;return!!s&&!!((c=i.get(l??""))!=null&&c.attributes.some(d=>d.modelId===s))};for(const l of o){const s=a.get(l.associationRef);s&&(l.sourceColumnRef&&!r(s.end1.entityRef,l.sourceColumnRef)&&(l.sourceColumnRef=void 0),l.targetColumnRef&&!r(s.end2.entityRef,l.targetColumnRef)&&(l.targetColumnRef=void 0))}}function Y_(e,n){const o=new Map(e.map(i=>[i.modelId,i]));for(const i of n){if(i.end1.navigable!==!0)continue;const a=o.get(i.end1.entityRef),r=o.get(i.end2.entityRef);if(!a||!r||gt(a.stereotype)||gt(r.stereotype))continue;const l=i.end1.attributeRef?a.attributes.find(p=>p.modelId===i.end1.attributeRef):void 0;if((l==null?void 0:l.attrType)==="RELATION_REF")continue;const s=`nav:${i.modelId}`,c=a.attributes.find(p=>p.modelId===s);if((c==null?void 0:c.attrType)==="RELATION_REF"){i.end1.attributeRef=s;continue}const d=ca(i.end2.multiplicity),u=ua(r.name,d),m=to(u,new Set(a.attributes.map(p=>p.name)));a.attributes.push({modelId:s,name:m,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:a.attributes.reduce((p,f)=>Math.max(p,f.order),-1)+1,dbAttrs:[]}),i.end1.attributeRef=s}}function q_(e,n){const o=new Map(e.map(i=>[i.modelId,i]));for(const i of n){if(i.identifying===!0||i.end1.entityRef===i.end2.entityRef)continue;const a=o.get(i.end1.entityRef),r=o.get(i.end2.entityRef);if(!a||!r||gt(a.stereotype)||gt(r.stereotype))continue;const l=r.attributes.find(s=>s.modelId===i.end2.attributeRef);l&&l.attrType.startsWith("RELATION")&&l.dbAttrs.length>0&&l.identifier===!0&&(i.identifying=!0)}}function tm(e,n){var i;const o=new Map(e.map(a=>[a.modelId,a]));for(const a of n){const r=o.get(a.end2.entityRef);if(!r)continue;const l=o.get(a.end1.entityRef);if(l&&gt(l.stereotype))continue;const s=a.end1.entityRef===a.end2.entityRef,c=a.identifying===!0||!s&&!Dc(a.end1.multiplicity);for(const d of r.attributes)!d.attrType.startsWith("RELATION")||d.dbAttrs.length===0||!(((i=d.derivedFrom)==null?void 0:i.associationRef)===a.modelId||!d.derivedFrom&&d.modelId===a.end2.attributeRef)||(d.notNull=c)}}function nm(e){const n=JSON.parse(JSON.stringify(e));return(n.schemaVersion??1)>=2&&"logical"in n?W_(n):J_(n)}function W_(e){const n=e.id??e.logical.modelId??"",o={},i=m=>{const{rev:p,...f}=m;return p!=null&&(o[m.modelId]=p),f},a=e.logical.entities.map(i),r=e.logical.associations.map(i),l=e.logical.groups.map(i);Y_(a,r),q_(a,r),tm(a,r);const{version:s,...c}=e.layout;em(a,r,c.associationLayouts);const d={logical:{modelId:e.logical.modelId??n,packageName:e.logical.packageName,entities:a,associations:r,groups:l},layout:{...c,diagramId:c.diagramId??n,logicalModelRef:c.logicalModelRef??n}},u={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion,opWriteEnabled:e.opWriteEnabled,referenceOnly:e.referenceOnly,revSeed:{revs:o,layoutVersion:s??0,logicalVersion:e.logical.version??0}};return{state:d,meta:u}}function J_(e){var _,E;const n=e.id??"",o=[],i=[],a=[],r=[],l=[],s=[],c=[],d=(N,y)=>{o.push(P_(N));const k=z_(N);k.geo={location:{x:k.geo.location.x+y.x,y:k.geo.location.y+y.y},size:k.geo.size},i.push(k);for(const S of N.ownedAssociations??[])c.push(S)},u={x:0,y:0};for(const N of e.entities??[])d(N,u);const m=[];for(const N of e.groups??[]){const y=N.entities??[];l.push({modelId:N.modelId,name:N.name,description:N.description,packageName:N.packageName,excludeDDLGeneration:N.excludeDDLGeneration??!1,memberEntityRefs:y.map(S=>S.modelId)});const k=((_=N.geo)==null?void 0:_.location)??u;if(N.geo){const S=(N.notes??[]).map(T=>T.modelId);s.push({groupRef:N.modelId,geo:N.geo,style:N.style,locked:N.locked,memberNoteRefs:S.length?S:void 0})}for(const S of y)d(S,k);for(const S of N.notes??[])m.push(Qu(S,k))}const p=new Map(o.map(N=>[N.modelId,N])),f=new Map,h=new Map;for(const N of o)for(const y of N.attributes)for(const k of y.dbAttrs)f.set(k.modelId,y.modelId),h.set(k.modelId,k);for(const N of c)for(const y of[N.end1,N.end2]){const k=y.attribute;if(k&&(((E=k.dbAttrs)==null?void 0:E.length)??0)>0)for(const S of k.dbAttrs)S.modelId&&f.set(S.modelId,k.modelId)}for(const N of c){const y=Ju(N.end1.attribute),k=Ju(N.end2.attribute),S=Xu(N.end1)||Xu(N.end2),{assoc:T,layout:O}=y!==k||S?K_(N,p,h):H_(N,p,f);a.push(T),r.push(O)}em(o,a,r),Id(o),tm(o,a);const g={logical:{modelId:n,packageName:e.packageName,entities:o,associations:a,groups:l},layout:{diagramId:n,logicalModelRef:n,canvasSize:e.size,entityLayouts:i,associationLayouts:r,groupLayouts:s,notes:[...(e.notes??[]).map(N=>Qu(N)),...m]}},b={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion??1};return{state:g,meta:b}}function om(e){return{modelId:e.modelId,physicalName:e.physicalName,logicalName:e.logicalName,dataType:e.dataType,length:e.length,scale:e.scale,unique:e.unique,autoIncrement:e.autoIncrement,updatable:e.updatable,insertable:e.insertable,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}function X_(e,n){return{modelId:e.modelId,name:e.name,type:e.type,customType:e.customType,attrType:e.attrType,identifier:e.identifier,notNull:e.notNull,transient_:e.transient,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:e.order,dbAttrs:e.dbAttrs.map(om),style:n}}function Z_(e,n){var o;return{...e.legacyRaw,modelId:e.modelId,name:e.name,visibility:e.visibility,sourceCode:e.sourceCode,description:(o=e.description)==null?void 0:o.ko,order:e.order,personalInfoAttributeType:e.personalInfoAttributeType,style:n}}function Q_(e){return{modelId:e.modelId,name:e.name,unique:e.unique,description:e.description,parameters:e.parameters,indexColumns:e.columns.map(n=>({targetColumn:{refId:n.columnRef},descending:n.descending}))}}function Fn(e,n){return{endModel:{refId:e.entityRef},multiplicity:e.multiplicity,navigable:e.navigable,composition:e.composition,jpaAttribute:e.jpa,attribute:n??(e.attributeRef?{modelId:e.attributeRef}:void 0)}}function ek(e,n){const o=n==null?void 0:n.attributes.find(i=>{var a;return i.modelId===((a=e.derivedFrom)==null?void 0:a.sourceAttributeRef)});return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_REF",identifier:e.identifier,notNull:e.notNull,transient_:e.transient,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,order:e.order,dbAttrs:e.dbAttrs.map((i,a)=>{var r;return{...om(i),targetModelId:(r=o==null?void 0:o.dbAttrs[a])==null?void 0:r.modelId}})}}function tk(e){return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_OWN",dbAttrs:[]}}function im(e,n){const o=l=>{if(!l.attributeRef)return;const s=n.logical.entities.find(c=>c.modelId===l.entityRef);return s==null?void 0:s.attributes.find(c=>c.modelId===l.attributeRef)},i=o(e.end1),a=o(e.end2),r=l=>(l==null?void 0:l.attrType)==="RELATION_OWN"?l:void 0;return(i==null?void 0:i.attrType)==="RELATION_REF"?{navEnd:e.end1,fkEnd:e.end2,navAttr:i,fk:r(a)}:(a==null?void 0:a.attrType)==="RELATION_REF"?{navEnd:e.end2,fkEnd:e.end1,navAttr:a,fk:r(i)}:null}function nk(e){const n=new Set;for(const o of e.logical.associations){const i=im(o,e);i&&(n.add(i.navAttr.modelId),i.fk&&n.add(i.fk.modelId))}return n}function ok(e){const n=new Set;for(const o of e.logical.entities)for(const i of o.attributes)i.embedded&&n.add(i.modelId);return n}function ik(e,n){return e===n||JSON.stringify(e??null)===JSON.stringify(n??null)}function ak(e,n){const o=(i,a)=>i===a?void 0:i;return{modelId:e.modelId,targetModelId:n==null?void 0:n.modelId,physicalName:e.physicalName===((n==null?void 0:n.physicalName)??"")?"":e.physicalName,logicalName:ik(e.logicalName,n==null?void 0:n.logicalName)?void 0:e.logicalName,dataType:e.dataType===((n==null?void 0:n.dataType)??"")?"":e.dataType,length:o(e.length,n==null?void 0:n.length),scale:o(e.scale,n==null?void 0:n.scale),unique:o(e.unique,n==null?void 0:n.unique),autoIncrement:o(e.autoIncrement,n==null?void 0:n.autoIncrement),updatable:o(e.updatable,n==null?void 0:n.updatable),insertable:o(e.insertable,n==null?void 0:n.insertable)}}function rk(e,n,o){let i;for(const m of n.logical.entities){const p=m.attributes.find(f=>{var h;return((h=f.embedded)==null?void 0:h.associationRef)===e.modelId});if(p){i=p;break}}if(!i)return;const a=i.embedded.embeddableRef,r=n.logical.entities.find(m=>m.modelId===a);if(!r)return;const l=r.attributes.flatMap(m=>m.dbAttrs),s={modelId:i.modelId,name:i.name,type:i.type,attrType:i.attrType,identifier:i.identifier,notNull:i.notNull,transient_:i.transient,description:i.description,attributeGroup:i.attributeGroup,groupCode:i.groupCode,order:i.order,dbAttrs:i.dbAttrs.map((m,p)=>ak(m,l[p]))},c=e.end1.entityRef===a,d=c?e.end2:e.end1,u=d.attributeRef?{modelId:d.attributeRef,attrType:"EMBED_REF",dbAttrs:[]}:void 0;return{...o,end1:Fn(e.end1,c?s:u),end2:Fn(e.end2,c?u:s)}}function lk(e,n,o){const i={modelId:e.modelId,description:e.description,locations:(o==null?void 0:o.waypoints)??[],style:o==null?void 0:o.style};if(e.end1.legacyEmbedRaw||e.end2.legacyEmbedRaw)return{...i,end1:Fn(e.end1,e.end1.legacyEmbedRaw),end2:Fn(e.end2,e.end2.legacyEmbedRaw)};const a=rk(e,n,i);if(a)return a;const r=im(e,n);if(r){const l=n.logical.entities.find(d=>d.modelId===r.navEnd.entityRef),s=r.fk?ek(r.fk,l):void 0,c=tk(r.navAttr);return{...i,end1:Fn(e.end1,r.navEnd===e.end1?s:c),end2:Fn(e.end2,r.navEnd===e.end2?s:c)}}return{...i,end1:Fn(e.end1),end2:Fn(e.end2)}}function am(e,n,o,i,a={x:0,y:0}){var u,m;const r=n.layout.entityLayouts.find(p=>p.entityRef===e.modelId),l=n.logical.associations.filter(p=>p.end1.entityRef===e.modelId),s=p=>n.layout.associationLayouts.find(f=>f.associationRef===p),c=(r==null?void 0:r.geo)??{...Yu},d={location:{x:c.location.x-a.x,y:c.location.y-a.y},size:c.size};return{modelId:e.modelId,name:e.name,stereotype:e.stereotype,packageName:e.packageName,superClass:e.superClass,schema:e.schema,description:e.description,abstractClass:e.abstractClass,hasPersonalInfo:e.hasPersonalInfo,declarationOfInterfaces:e.declarationOfInterfaces,attributes:e.attributes.filter(p=>!o.has(p.modelId)&&!i.has(p.modelId)).map(p=>{var f;return X_(p,(f=r==null?void 0:r.attributeStyles)==null?void 0:f[p.modelId])}),operations:(u=e.operations)==null?void 0:u.map(p=>{var f;return Z_(p,(f=r==null?void 0:r.operationStyles)==null?void 0:f[p.modelId])}),ownedAssociations:l.map(p=>lk(p,n,s(p.modelId))),indexes:(m=e.indexes)==null?void 0:m.map(Q_),jpaAttrs:e.jpaAttrs,dbAttrs:e.table?{physicalName:e.table.physicalName,logicalName:e.table.logicalName}:void 0,geo:d,style:r==null?void 0:r.style,collapsed:r==null?void 0:r.collapsed,locked:r==null?void 0:r.locked}}function sk(e,n,o,i){const a=n.layout.groupLayouts.find(c=>c.groupRef===e.modelId),r=e.memberEntityRefs.map(c=>n.logical.entities.find(d=>d.modelId===c)).filter(c=>!!c),l=(a==null?void 0:a.geo.location)??{x:0,y:0},s=((a==null?void 0:a.memberNoteRefs)??[]).map(c=>n.layout.notes.find(d=>d.modelId===c)).filter(c=>!!c).map(c=>rm(c,l));return{modelId:e.modelId,name:e.name,description:e.description,packageName:e.packageName,excludeDDLGeneration:e.excludeDDLGeneration,entities:r.map(c=>am(c,n,o,i,l)),notes:s.length?s:void 0,geo:a==null?void 0:a.geo,style:a==null?void 0:a.style,locked:a==null?void 0:a.locked}}function rm(e,n={x:0,y:0}){return{...e.legacyRaw,modelId:e.modelId,memo:e.memo,geo:{location:{x:e.geo.location.x-n.x,y:e.geo.location.y-n.y},size:e.geo.size},style:e.style,connections:e.connections}}function ck(e,n={}){const o=new Set(e.logical.groups.flatMap(s=>s.memberEntityRefs)),i=e.logical.entities.filter(s=>!o.has(s.modelId)),a=nk(e),r=ok(e),l=new Set(e.layout.groupLayouts.flatMap(s=>s.memberNoteRefs??[]));return{id:n.id,diagramVersion:n.diagramVersion,version:n.version,size:n.size??e.layout.canvasSize,packageName:n.packageName??e.logical.packageName,entities:i.map(s=>am(s,e,a,r)),groups:e.logical.groups.map(s=>sk(s,e,a,r)),notes:e.layout.notes.filter(s=>!l.has(s.modelId)).map(s=>rm(s))}}function dk(e,n={}){var a,r,l;const o=((a=n.revSeed)==null?void 0:a.revs)??{},i=s=>({...s,rev:o[s.modelId]??0});return{id:n.id,schemaVersion:2,opWriteEnabled:n.opWriteEnabled,referenceOnly:n.referenceOnly,version:n.version,diagramVersion:n.diagramVersion,packageName:n.packageName,size:n.size,logical:{version:((r=n.revSeed)==null?void 0:r.logicalVersion)??0,modelId:e.logical.modelId,packageName:e.logical.packageName,entities:e.logical.entities.map(i),associations:e.logical.associations.map(i),groups:e.logical.groups.map(i)},layout:{...e.layout,version:((l=n.revSeed)==null?void 0:l.layoutVersion)??0}}}const uk=["notNull"];function mk(e){var u;const n=()=>({navAdds:0,navRefPatches:0,identifyingPatches:0,attributeFieldPatches:0,attributeFieldsByName:{}});if((e.schemaVersion??1)<2||!("logical"in e))return{ops:[],revs:{},summary:n()};const o=e,{state:i,meta:a}=nm(e),r=((u=a.revSeed)==null?void 0:u.revs)??{},l=[],s=n(),c=new Map(o.logical.entities.map(m=>[m.modelId,new Map(m.attributes.map(p=>[p.modelId,p]))]));for(const m of i.logical.entities){const p=c.get(m.modelId);if(p)for(const f of m.attributes){const h=p.get(f.modelId);if(!h){l.push({kind:"attribute.add",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,value:f}),s.navAdds++;continue}const g={};for(const b of uk)f[b]===!0!=(h[b]===!0)&&(g[b]=f[b],s.attributeFieldsByName[b]=(s.attributeFieldsByName[b]??0)+1);Object.keys(g).length!==0&&(l.push({kind:"attribute.update",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,attributeRef:f.modelId,patch:g}),s.attributeFieldPatches++)}}const d=new Map(o.logical.associations.map(m=>[m.modelId,m]));for(const m of i.logical.associations){const p=d.get(m.modelId);p&&(m.end1.attributeRef&&m.end1.attributeRef!==p.end1.attributeRef&&(l.push({kind:"associationEnd.update",casUnit:"logical",containerRef:m.modelId,associationRef:m.modelId,end:"end1",patch:{attributeRef:m.end1.attributeRef}}),s.navRefPatches++),m.identifying===!0&&p.identifying!==!0&&(l.push({kind:"association.update",casUnit:"logical",containerRef:m.modelId,associationRef:m.modelId,patch:{identifying:!0}}),s.identifyingPatches++))}return{ops:l,revs:r,summary:s}}function Ni(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function wn(e){return typeof e=="function"?e():t.unref(e)}const fk=typeof window<"u"&&typeof document<"u",pk=e=>typeof e<"u",hk=Object.prototype.toString,yk=e=>hk.call(e)==="[object Object]",gk=()=>{};function bk(e,n){function o(...i){return new Promise((a,r)=>{Promise.resolve(e(()=>n.apply(this,i),{fn:n,thisArg:this,args:i})).then(a).catch(r)})}return o}const lm=e=>e();function _k(e=lm){const n=t.ref(!0);function o(){n.value=!1}function i(){n.value=!0}const a=(...r)=>{n.value&&e(...r)};return{isActive:t.readonly(n),pause:o,resume:i,eventFilter:a}}function sm(e,n=!1,o="Timeout"){return new Promise((i,a)=>{setTimeout(n?()=>a(o):i,e)})}function kk(e,n,o={}){const{eventFilter:i=lm,...a}=o;return t.watch(e,bk(i,n),a)}function jo(e,n,o={}){const{eventFilter:i,...a}=o,{eventFilter:r,pause:l,resume:s,isActive:c}=_k(i);return{stop:kk(e,n,{...a,eventFilter:r}),pause:l,resume:s,isActive:c}}function Ek(e,n={}){if(!t.isRef(e))return t.toRefs(e);const o=Array.isArray(e.value)?Array.from({length:e.value.length}):{};for(const i in e.value)o[i]=t.customRef(()=>({get(){return e.value[i]},set(a){var r;if((r=wn(n.replaceRef))!=null?r:!0)if(Array.isArray(e.value)){const s=[...e.value];s[i]=a,e.value=s}else{const s={...e.value,[i]:a};Object.setPrototypeOf(s,Object.getPrototypeOf(e.value)),e.value=s}else e.value[i]=a}}));return o}function jl(e,n=!1){function o(m,{flush:p="sync",deep:f=!1,timeout:h,throwOnTimeout:g}={}){let b=null;const E=[new Promise(N=>{b=t.watch(e,y=>{m(y)!==n&&(b==null||b(),N(y))},{flush:p,deep:f,immediate:!0})})];return h!=null&&E.push(sm(h,g).then(()=>wn(e)).finally(()=>b==null?void 0:b())),Promise.race(E)}function i(m,p){if(!t.isRef(m))return o(y=>y===m,p);const{flush:f="sync",deep:h=!1,timeout:g,throwOnTimeout:b}=p??{};let _=null;const N=[new Promise(y=>{_=t.watch([e,m],([k,S])=>{n!==(k===S)&&(_==null||_(),y(k))},{flush:f,deep:h,immediate:!0})})];return g!=null&&N.push(sm(g,b).then(()=>wn(e)).finally(()=>(_==null||_(),wn(e)))),Promise.race(N)}function a(m){return o(p=>!!p,m)}function r(m){return i(null,m)}function l(m){return i(void 0,m)}function s(m){return o(Number.isNaN,m)}function c(m,p){return o(f=>{const h=Array.from(f);return h.includes(m)||h.includes(wn(m))},p)}function d(m){return u(1,m)}function u(m=1,p){let f=-1;return o(()=>(f+=1,f>=m),p)}return Array.isArray(wn(e))?{toMatch:o,toContains:c,changed:d,changedTimes:u,get not(){return jl(e,!n)}}:{toMatch:o,toBe:i,toBeTruthy:a,toBeNull:r,toBeNaN:s,toBeUndefined:l,changed:d,changedTimes:u,get not(){return jl(e,!n)}}}function Kl(e){return jl(e)}function Nk(e){var n;const o=wn(e);return(n=o==null?void 0:o.$el)!=null?n:o}const cm=fk?window:void 0;function dm(...e){let n,o,i,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,i,a]=e,n=cm):[n,o,i,a]=e,!n)return gk;Array.isArray(o)||(o=[o]),Array.isArray(i)||(i=[i]);const r=[],l=()=>{r.forEach(u=>u()),r.length=0},s=(u,m,p,f)=>(u.addEventListener(m,p,f),()=>u.removeEventListener(m,p,f)),c=t.watch(()=>[Nk(n),wn(a)],([u,m])=>{if(l(),!u)return;const p=yk(m)?{...m}:m;r.push(...o.flatMap(f=>i.map(h=>s(u,f,h,p))))},{immediate:!0,flush:"post"}),d=()=>{c(),l()};return Ni(d),d}function wk(e){return typeof e=="function"?e:typeof e=="string"?n=>n.key===e:Array.isArray(e)?n=>e.includes(n.key):()=>!0}function um(...e){let n,o,i={};e.length===3?(n=e[0],o=e[1],i=e[2]):e.length===2?typeof e[1]=="object"?(n=!0,o=e[0],i=e[1]):(n=e[0],o=e[1]):(n=!0,o=e[0]);const{target:a=cm,eventName:r="keydown",passive:l=!1,dedupe:s=!1}=i,c=wk(n);return dm(a,r,u=>{u.repeat&&wn(s)||c(u)&&o(u)},l)}function Ik(e){return JSON.parse(JSON.stringify(e))}function Gl(e,n,o,i={}){var a,r,l;const{clone:s=!1,passive:c=!1,eventName:d,deep:u=!1,defaultValue:m,shouldEmit:p}=i,f=t.getCurrentInstance(),h=o||(f==null?void 0:f.emit)||((a=f==null?void 0:f.$emit)==null?void 0:a.bind(f))||((l=(r=f==null?void 0:f.proxy)==null?void 0:r.$emit)==null?void 0:l.bind(f==null?void 0:f.proxy));let g=d;n||(n="modelValue"),g=g||`update:${n.toString()}`;const b=N=>s?typeof s=="function"?s(N):Ik(N):N,_=()=>pk(e[n])?b(e[n]):m,E=N=>{p?p(N)&&h(g,N):h(g,N)};if(c){const N=_(),y=t.ref(N);let k=!1;return t.watch(()=>e[n],S=>{k||(k=!0,y.value=b(S),t.nextTick(()=>k=!1))}),t.watch(y,S=>{!k&&(S!==e[n]||u)&&E(S)},{deep:u}),y}else return t.computed({get(){return _()},set(N){E(N)}})}var vk={value:()=>{}};function Ma(){for(var e=0,n=arguments.length,o={},i;e<n;++e){if(!(i=arguments[e]+"")||i in o||/[\s.]/.test(i))throw new Error("illegal type: "+i);o[i]=[]}return new Va(o)}function Va(e){this._=e}function Ck(e,n){return e.trim().split(/^|\s+/).map(function(o){var i="",a=o.indexOf(".");if(a>=0&&(i=o.slice(a+1),o=o.slice(0,a)),o&&!n.hasOwnProperty(o))throw new Error("unknown type: "+o);return{type:o,name:i}})}Va.prototype=Ma.prototype={constructor:Va,on:function(e,n){var o=this._,i=Ck(e+"",o),a,r=-1,l=i.length;if(arguments.length<2){for(;++r<l;)if((a=(e=i[r]).type)&&(a=Sk(o[a],e.name)))return a;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++r<l;)if(a=(e=i[r]).type)o[a]=mm(o[a],e.name,n);else if(n==null)for(a in o)o[a]=mm(o[a],e.name,null);return this},copy:function(){var e={},n=this._;for(var o in n)e[o]=n[o].slice();return new Va(e)},call:function(e,n){if((a=arguments.length-2)>0)for(var o=new Array(a),i=0,a,r;i<a;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(n,o)},apply:function(e,n,o){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],a=0,r=i.length;a<r;++a)i[a].value.apply(n,o)}};function Sk(e,n){for(var o=0,i=e.length,a;o<i;++o)if((a=e[o]).name===n)return a.value}function mm(e,n,o){for(var i=0,a=e.length;i<a;++i)if(e[i].name===n){e[i]=vk,e=e.slice(0,i).concat(e.slice(i+1));break}return o!=null&&e.push({name:n,value:o}),e}var Yl="http://www.w3.org/1999/xhtml";const fm={svg:"http://www.w3.org/2000/svg",xhtml:Yl,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ba(e){var n=e+="",o=n.indexOf(":");return o>=0&&(n=e.slice(0,o))!=="xmlns"&&(e=e.slice(o+1)),fm.hasOwnProperty(n)?{space:fm[n],local:e}:e}function xk(e){return function(){var n=this.ownerDocument,o=this.namespaceURI;return o===Yl&&n.documentElement.namespaceURI===Yl?n.createElement(e):n.createElementNS(o,e)}}function Rk(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function pm(e){var n=Ba(e);return(n.local?Rk:xk)(n)}function Ak(){}function ql(e){return e==null?Ak:function(){return this.querySelector(e)}}function $k(e){typeof e!="function"&&(e=ql(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=new Array(l),c,d,u=0;u<l;++u)(c=r[u])&&(d=e.call(c,c.__data__,u,r))&&("__data__"in c&&(d.__data__=c.__data__),s[u]=d);return new Ft(i,this._parents)}function Tk(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Mk(){return[]}function hm(e){return e==null?Mk:function(){return this.querySelectorAll(e)}}function Vk(e){return function(){return Tk(e.apply(this,arguments))}}function Bk(e){typeof e=="function"?e=Vk(e):e=hm(e);for(var n=this._groups,o=n.length,i=[],a=[],r=0;r<o;++r)for(var l=n[r],s=l.length,c,d=0;d<s;++d)(c=l[d])&&(i.push(e.call(c,c.__data__,d,l)),a.push(c));return new Ft(i,a)}function ym(e){return function(){return this.matches(e)}}function gm(e){return function(n){return n.matches(e)}}var Dk=Array.prototype.find;function Ok(e){return function(){return Dk.call(this.children,e)}}function Lk(){return this.firstElementChild}function Pk(e){return this.select(e==null?Lk:Ok(typeof e=="function"?e:gm(e)))}var zk=Array.prototype.filter;function Fk(){return Array.from(this.children)}function Uk(e){return function(){return zk.call(this.children,e)}}function Hk(e){return this.selectAll(e==null?Fk:Uk(typeof e=="function"?e:gm(e)))}function jk(e){typeof e!="function"&&(e=ym(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=[],c,d=0;d<l;++d)(c=r[d])&&e.call(c,c.__data__,d,r)&&s.push(c);return new Ft(i,this._parents)}function bm(e){return new Array(e.length)}function Kk(){return new Ft(this._enter||this._groups.map(bm),this._parents)}function Da(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}Da.prototype={constructor:Da,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,n){return this._parent.insertBefore(e,n)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Gk(e){return function(){return e}}function Yk(e,n,o,i,a,r){for(var l=0,s,c=n.length,d=r.length;l<d;++l)(s=n[l])?(s.__data__=r[l],i[l]=s):o[l]=new Da(e,r[l]);for(;l<c;++l)(s=n[l])&&(a[l]=s)}function qk(e,n,o,i,a,r,l){var s,c,d=new Map,u=n.length,m=r.length,p=new Array(u),f;for(s=0;s<u;++s)(c=n[s])&&(p[s]=f=l.call(c,c.__data__,s,n)+"",d.has(f)?a[s]=c:d.set(f,c));for(s=0;s<m;++s)f=l.call(e,r[s],s,r)+"",(c=d.get(f))?(i[s]=c,c.__data__=r[s],d.delete(f)):o[s]=new Da(e,r[s]);for(s=0;s<u;++s)(c=n[s])&&d.get(p[s])===c&&(a[s]=c)}function Wk(e){return e.__data__}function Jk(e,n){if(!arguments.length)return Array.from(this,Wk);var o=n?qk:Yk,i=this._parents,a=this._groups;typeof e!="function"&&(e=Gk(e));for(var r=a.length,l=new Array(r),s=new Array(r),c=new Array(r),d=0;d<r;++d){var u=i[d],m=a[d],p=m.length,f=Xk(e.call(u,u&&u.__data__,d,i)),h=f.length,g=s[d]=new Array(h),b=l[d]=new Array(h),_=c[d]=new Array(p);o(u,m,g,b,_,f,n);for(var E=0,N=0,y,k;E<h;++E)if(y=g[E]){for(E>=N&&(N=E+1);!(k=b[N])&&++N<h;);y._next=k||null}}return l=new Ft(l,i),l._enter=s,l._exit=c,l}function Xk(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Zk(){return new Ft(this._exit||this._groups.map(bm),this._parents)}function Qk(e,n,o){var i=this.enter(),a=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),n!=null&&(a=n(a),a&&(a=a.selection())),o==null?r.remove():o(r),i&&a?i.merge(a).order():a}function eE(e){for(var n=e.selection?e.selection():e,o=this._groups,i=n._groups,a=o.length,r=i.length,l=Math.min(a,r),s=new Array(a),c=0;c<l;++c)for(var d=o[c],u=i[c],m=d.length,p=s[c]=new Array(m),f,h=0;h<m;++h)(f=d[h]||u[h])&&(p[h]=f);for(;c<a;++c)s[c]=o[c];return new Ft(s,this._parents)}function tE(){for(var e=this._groups,n=-1,o=e.length;++n<o;)for(var i=e[n],a=i.length-1,r=i[a],l;--a>=0;)(l=i[a])&&(r&&l.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(l,r),r=l);return this}function nE(e){e||(e=oE);function n(m,p){return m&&p?e(m.__data__,p.__data__):!m-!p}for(var o=this._groups,i=o.length,a=new Array(i),r=0;r<i;++r){for(var l=o[r],s=l.length,c=a[r]=new Array(s),d,u=0;u<s;++u)(d=l[u])&&(c[u]=d);c.sort(n)}return new Ft(a,this._parents).order()}function oE(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function iE(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function aE(){return Array.from(this)}function rE(){for(var e=this._groups,n=0,o=e.length;n<o;++n)for(var i=e[n],a=0,r=i.length;a<r;++a){var l=i[a];if(l)return l}return null}function lE(){let e=0;for(const n of this)++e;return e}function sE(){return!this.node()}function cE(e){for(var n=this._groups,o=0,i=n.length;o<i;++o)for(var a=n[o],r=0,l=a.length,s;r<l;++r)(s=a[r])&&e.call(s,s.__data__,r,a);return this}function dE(e){return function(){this.removeAttribute(e)}}function uE(e){return function(){this.removeAttributeNS(e.space,e.local)}}function mE(e,n){return function(){this.setAttribute(e,n)}}function fE(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function pE(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttribute(e):this.setAttribute(e,o)}}function hE(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,o)}}function yE(e,n){var o=Ba(e);if(arguments.length<2){var i=this.node();return o.local?i.getAttributeNS(o.space,o.local):i.getAttribute(o)}return this.each((n==null?o.local?uE:dE:typeof n=="function"?o.local?hE:pE:o.local?fE:mE)(o,n))}function _m(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function gE(e){return function(){this.style.removeProperty(e)}}function bE(e,n,o){return function(){this.style.setProperty(e,n,o)}}function _E(e,n,o){return function(){var i=n.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,o)}}function kE(e,n,o){return arguments.length>1?this.each((n==null?gE:typeof n=="function"?_E:bE)(e,n,o??"")):Ko(this.node(),e)}function Ko(e,n){return e.style.getPropertyValue(n)||_m(e).getComputedStyle(e,null).getPropertyValue(n)}function EE(e){return function(){delete this[e]}}function NE(e,n){return function(){this[e]=n}}function wE(e,n){return function(){var o=n.apply(this,arguments);o==null?delete this[e]:this[e]=o}}function IE(e,n){return arguments.length>1?this.each((n==null?EE:typeof n=="function"?wE:NE)(e,n)):this.node()[e]}function km(e){return e.trim().split(/^|\s+/)}function Wl(e){return e.classList||new Em(e)}function Em(e){this._node=e,this._names=km(e.getAttribute("class")||"")}Em.prototype={add:function(e){var n=this._names.indexOf(e);n<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var n=this._names.indexOf(e);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Nm(e,n){for(var o=Wl(e),i=-1,a=n.length;++i<a;)o.add(n[i])}function wm(e,n){for(var o=Wl(e),i=-1,a=n.length;++i<a;)o.remove(n[i])}function vE(e){return function(){Nm(this,e)}}function CE(e){return function(){wm(this,e)}}function SE(e,n){return function(){(n.apply(this,arguments)?Nm:wm)(this,e)}}function xE(e,n){var o=km(e+"");if(arguments.length<2){for(var i=Wl(this.node()),a=-1,r=o.length;++a<r;)if(!i.contains(o[a]))return!1;return!0}return this.each((typeof n=="function"?SE:n?vE:CE)(o,n))}function RE(){this.textContent=""}function AE(e){return function(){this.textContent=e}}function $E(e){return function(){var n=e.apply(this,arguments);this.textContent=n??""}}function TE(e){return arguments.length?this.each(e==null?RE:(typeof e=="function"?$E:AE)(e)):this.node().textContent}function ME(){this.innerHTML=""}function VE(e){return function(){this.innerHTML=e}}function BE(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n??""}}function DE(e){return arguments.length?this.each(e==null?ME:(typeof e=="function"?BE:VE)(e)):this.node().innerHTML}function OE(){this.nextSibling&&this.parentNode.appendChild(this)}function LE(){return this.each(OE)}function PE(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function zE(){return this.each(PE)}function FE(e){var n=typeof e=="function"?e:pm(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function UE(){return null}function HE(e,n){var o=typeof e=="function"?e:pm(e),i=n==null?UE:typeof n=="function"?n:ql(n);return this.select(function(){return this.insertBefore(o.apply(this,arguments),i.apply(this,arguments)||null)})}function jE(){var e=this.parentNode;e&&e.removeChild(this)}function KE(){return this.each(jE)}function GE(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function YE(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function qE(e){return this.select(e?YE:GE)}function WE(e){return arguments.length?this.property("__data__",e):this.node().__data__}function JE(e){return function(n){e.call(this,n,this.__data__)}}function XE(e){return e.trim().split(/^|\s+/).map(function(n){var o="",i=n.indexOf(".");return i>=0&&(o=n.slice(i+1),n=n.slice(0,i)),{type:n,name:o}})}function ZE(e){return function(){var n=this.__on;if(n){for(var o=0,i=-1,a=n.length,r;o<a;++o)r=n[o],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):n[++i]=r;++i?n.length=i:delete this.__on}}}function QE(e,n,o){return function(){var i=this.__on,a,r=JE(n);if(i){for(var l=0,s=i.length;l<s;++l)if((a=i[l]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=r,a.options=o),a.value=n;return}}this.addEventListener(e.type,r,o),a={type:e.type,name:e.name,value:n,listener:r,options:o},i?i.push(a):this.__on=[a]}}function e1(e,n,o){var i=XE(e+""),a,r=i.length,l;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,d=s.length,u;c<d;++c)for(a=0,u=s[c];a<r;++a)if((l=i[a]).type===u.type&&l.name===u.name)return u.value}return}for(s=n?QE:ZE,a=0;a<r;++a)this.each(s(i[a],n,o));return this}function Im(e,n,o){var i=_m(e),a=i.CustomEvent;typeof a=="function"?a=new a(n,o):(a=i.document.createEvent("Event"),o?(a.initEvent(n,o.bubbles,o.cancelable),a.detail=o.detail):a.initEvent(n,!1,!1)),e.dispatchEvent(a)}function t1(e,n){return function(){return Im(this,e,n)}}function n1(e,n){return function(){return Im(this,e,n.apply(this,arguments))}}function o1(e,n){return this.each((typeof n=="function"?n1:t1)(e,n))}function*i1(){for(var e=this._groups,n=0,o=e.length;n<o;++n)for(var i=e[n],a=0,r=i.length,l;a<r;++a)(l=i[a])&&(yield l)}var vm=[null];function Ft(e,n){this._groups=e,this._parents=n}function wi(){return new Ft([[document.documentElement]],vm)}function a1(){return this}Ft.prototype=wi.prototype={constructor:Ft,select:$k,selectAll:Bk,selectChild:Pk,selectChildren:Hk,filter:jk,data:Jk,enter:Kk,exit:Zk,join:Qk,merge:eE,selection:a1,order:tE,sort:nE,call:iE,nodes:aE,node:rE,size:lE,empty:sE,each:cE,attr:yE,style:kE,property:IE,classed:xE,text:TE,html:DE,raise:LE,lower:zE,append:FE,insert:HE,remove:KE,clone:qE,datum:WE,on:e1,dispatch:o1,[Symbol.iterator]:i1};function Wt(e){return typeof e=="string"?new Ft([[document.querySelector(e)]],[document.documentElement]):new Ft([[e]],vm)}function r1(e){let n;for(;n=e.sourceEvent;)e=n;return e}function sn(e,n){if(e=r1(e),n===void 0&&(n=e.currentTarget),n){var o=n.ownerSVGElement||n;if(o.createSVGPoint){var i=o.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(n.getScreenCTM().inverse()),[i.x,i.y]}if(n.getBoundingClientRect){var a=n.getBoundingClientRect();return[e.clientX-a.left-n.clientLeft,e.clientY-a.top-n.clientTop]}}return[e.pageX,e.pageY]}const l1={passive:!1},Ii={capture:!0,passive:!1};function Jl(e){e.stopImmediatePropagation()}function Go(e){e.preventDefault(),e.stopImmediatePropagation()}function Cm(e){var n=e.document.documentElement,o=Wt(e).on("dragstart.drag",Go,Ii);"onselectstart"in n?o.on("selectstart.drag",Go,Ii):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Sm(e,n){var o=e.document.documentElement,i=Wt(e).on("dragstart.drag",null);n&&(i.on("click.drag",Go,Ii),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in o?i.on("selectstart.drag",null):(o.style.MozUserSelect=o.__noselect,delete o.__noselect)}const Oa=e=>()=>e;function Xl(e,{sourceEvent:n,subject:o,target:i,identifier:a,active:r,x:l,y:s,dx:c,dy:d,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:o,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:l,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:u}})}Xl.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function s1(e){return!e.ctrlKey&&!e.button}function c1(){return this.parentNode}function d1(e,n){return n??{x:e.x,y:e.y}}function u1(){return navigator.maxTouchPoints||"ontouchstart"in this}function m1(){var e=s1,n=c1,o=d1,i=u1,a={},r=Ma("start","drag","end"),l=0,s,c,d,u,m=0;function p(y){y.on("mousedown.drag",f).filter(i).on("touchstart.drag",b).on("touchmove.drag",_,l1).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(y,k){if(!(u||!e.call(this,y,k))){var S=N(this,n.call(this,y,k),y,k,"mouse");S&&(Wt(y.view).on("mousemove.drag",h,Ii).on("mouseup.drag",g,Ii),Cm(y.view),Jl(y),d=!1,s=y.clientX,c=y.clientY,S("start",y))}}function h(y){if(Go(y),!d){var k=y.clientX-s,S=y.clientY-c;d=k*k+S*S>m}a.mouse("drag",y)}function g(y){Wt(y.view).on("mousemove.drag mouseup.drag",null),Sm(y.view,d),Go(y),a.mouse("end",y)}function b(y,k){if(e.call(this,y,k)){var S=y.changedTouches,T=n.call(this,y,k),O=S.length,A,V;for(A=0;A<O;++A)(V=N(this,T,y,k,S[A].identifier,S[A]))&&(Jl(y),V("start",y,S[A]))}}function _(y){var k=y.changedTouches,S=k.length,T,O;for(T=0;T<S;++T)(O=a[k[T].identifier])&&(Go(y),O("drag",y,k[T]))}function E(y){var k=y.changedTouches,S=k.length,T,O;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),T=0;T<S;++T)(O=a[k[T].identifier])&&(Jl(y),O("end",y,k[T]))}function N(y,k,S,T,O,A){var V=r.copy(),C=sn(A||S,k),R,$,w;if((w=o.call(y,new Xl("beforestart",{sourceEvent:S,target:p,identifier:O,active:l,x:C[0],y:C[1],dx:0,dy:0,dispatch:V}),T))!=null)return R=w.x-C[0]||0,$=w.y-C[1]||0,function I(v,B,M){var x=C,P;switch(v){case"start":a[O]=I,P=l++;break;case"end":delete a[O],--l;case"drag":C=sn(M||B,k),P=l;break}V.call(v,y,new Xl(v,{sourceEvent:B,subject:w,target:p,identifier:O,active:P,x:C[0]+R,y:C[1]+$,dx:C[0]-x[0],dy:C[1]-x[1],dispatch:V}),T)}}return p.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Oa(!!y),p):e},p.container=function(y){return arguments.length?(n=typeof y=="function"?y:Oa(y),p):n},p.subject=function(y){return arguments.length?(o=typeof y=="function"?y:Oa(y),p):o},p.touchable=function(y){return arguments.length?(i=typeof y=="function"?y:Oa(!!y),p):i},p.on=function(){var y=r.on.apply(r,arguments);return y===r?p:y},p.clickDistance=function(y){return arguments.length?(m=(y=+y)*y,p):Math.sqrt(m)},p}function Zl(e,n,o){e.prototype=n.prototype=o,o.constructor=e}function xm(e,n){var o=Object.create(e.prototype);for(var i in n)o[i]=n[i];return o}function vi(){}var Ci=.7,La=1/Ci,Yo="\\s*([+-]?\\d+)\\s*",Si="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",cn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",f1=/^#([0-9a-f]{3,8})$/,p1=new RegExp(`^rgb\\(${Yo},${Yo},${Yo}\\)$`),h1=new RegExp(`^rgb\\(${cn},${cn},${cn}\\)$`),y1=new RegExp(`^rgba\\(${Yo},${Yo},${Yo},${Si}\\)$`),g1=new RegExp(`^rgba\\(${cn},${cn},${cn},${Si}\\)$`),b1=new RegExp(`^hsl\\(${Si},${cn},${cn}\\)$`),_1=new RegExp(`^hsla\\(${Si},${cn},${cn},${Si}\\)$`),Rm={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Zl(vi,mo,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Am,formatHex:Am,formatHex8:k1,formatHsl:E1,formatRgb:$m,toString:$m});function Am(){return this.rgb().formatHex()}function k1(){return this.rgb().formatHex8()}function E1(){return Dm(this).formatHsl()}function $m(){return this.rgb().formatRgb()}function mo(e){var n,o;return e=(e+"").trim().toLowerCase(),(n=f1.exec(e))?(o=n[1].length,n=parseInt(n[1],16),o===6?Tm(n):o===3?new Dt(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):o===8?Pa(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):o===4?Pa(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|n&240,((n&15)<<4|n&15)/255):null):(n=p1.exec(e))?new Dt(n[1],n[2],n[3],1):(n=h1.exec(e))?new Dt(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=y1.exec(e))?Pa(n[1],n[2],n[3],n[4]):(n=g1.exec(e))?Pa(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=b1.exec(e))?Bm(n[1],n[2]/100,n[3]/100,1):(n=_1.exec(e))?Bm(n[1],n[2]/100,n[3]/100,n[4]):Rm.hasOwnProperty(e)?Tm(Rm[e]):e==="transparent"?new Dt(NaN,NaN,NaN,0):null}function Tm(e){return new Dt(e>>16&255,e>>8&255,e&255,1)}function Pa(e,n,o,i){return i<=0&&(e=n=o=NaN),new Dt(e,n,o,i)}function N1(e){return e instanceof vi||(e=mo(e)),e?(e=e.rgb(),new Dt(e.r,e.g,e.b,e.opacity)):new Dt}function Ql(e,n,o,i){return arguments.length===1?N1(e):new Dt(e,n,o,i??1)}function Dt(e,n,o,i){this.r=+e,this.g=+n,this.b=+o,this.opacity=+i}Zl(Dt,Ql,xm(vi,{brighter(e){return e=e==null?La:Math.pow(La,e),new Dt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ci:Math.pow(Ci,e),new Dt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Dt(fo(this.r),fo(this.g),fo(this.b),za(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Mm,formatHex:Mm,formatHex8:w1,formatRgb:Vm,toString:Vm}));function Mm(){return`#${po(this.r)}${po(this.g)}${po(this.b)}`}function w1(){return`#${po(this.r)}${po(this.g)}${po(this.b)}${po((isNaN(this.opacity)?1:this.opacity)*255)}`}function Vm(){const e=za(this.opacity);return`${e===1?"rgb(":"rgba("}${fo(this.r)}, ${fo(this.g)}, ${fo(this.b)}${e===1?")":`, ${e})`}`}function za(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function fo(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function po(e){return e=fo(e),(e<16?"0":"")+e.toString(16)}function Bm(e,n,o,i){return i<=0?e=n=o=NaN:o<=0||o>=1?e=n=NaN:n<=0&&(e=NaN),new Jt(e,n,o,i)}function Dm(e){if(e instanceof Jt)return new Jt(e.h,e.s,e.l,e.opacity);if(e instanceof vi||(e=mo(e)),!e)return new Jt;if(e instanceof Jt)return e;e=e.rgb();var n=e.r/255,o=e.g/255,i=e.b/255,a=Math.min(n,o,i),r=Math.max(n,o,i),l=NaN,s=r-a,c=(r+a)/2;return s?(n===r?l=(o-i)/s+(o<i)*6:o===r?l=(i-n)/s+2:l=(n-o)/s+4,s/=c<.5?r+a:2-r-a,l*=60):s=c>0&&c<1?0:l,new Jt(l,s,c,e.opacity)}function I1(e,n,o,i){return arguments.length===1?Dm(e):new Jt(e,n,o,i??1)}function Jt(e,n,o,i){this.h=+e,this.s=+n,this.l=+o,this.opacity=+i}Zl(Jt,I1,xm(vi,{brighter(e){return e=e==null?La:Math.pow(La,e),new Jt(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ci:Math.pow(Ci,e),new Jt(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,n=isNaN(e)||isNaN(this.s)?0:this.s,o=this.l,i=o+(o<.5?o:1-o)*n,a=2*o-i;return new Dt(es(e>=240?e-240:e+120,a,i),es(e,a,i),es(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new Jt(Om(this.h),Fa(this.s),Fa(this.l),za(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=za(this.opacity);return`${e===1?"hsl(":"hsla("}${Om(this.h)}, ${Fa(this.s)*100}%, ${Fa(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Om(e){return e=(e||0)%360,e<0?e+360:e}function Fa(e){return Math.max(0,Math.min(1,e||0))}function es(e,n,o){return(e<60?n+(o-n)*e/60:e<180?o:e<240?n+(o-n)*(240-e)/60:n)*255}const ts=e=>()=>e;function v1(e,n){return function(o){return e+o*n}}function C1(e,n,o){return e=Math.pow(e,o),n=Math.pow(n,o)-e,o=1/o,function(i){return Math.pow(e+i*n,o)}}function S1(e){return(e=+e)==1?Lm:function(n,o){return o-n?C1(n,o,e):ts(isNaN(n)?o:n)}}function Lm(e,n){var o=n-e;return o?v1(e,o):ts(isNaN(e)?n:e)}const Ua=(function e(n){var o=S1(n);function i(a,r){var l=o((a=Ql(a)).r,(r=Ql(r)).r),s=o(a.g,r.g),c=o(a.b,r.b),d=Lm(a.opacity,r.opacity);return function(u){return a.r=l(u),a.g=s(u),a.b=c(u),a.opacity=d(u),a+""}}return i.gamma=e,i})(1);function x1(e,n){n||(n=[]);var o=e?Math.min(n.length,e.length):0,i=n.slice(),a;return function(r){for(a=0;a<o;++a)i[a]=e[a]*(1-r)+n[a]*r;return i}}function R1(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function A1(e,n){var o=n?n.length:0,i=e?Math.min(o,e.length):0,a=new Array(i),r=new Array(o),l;for(l=0;l<i;++l)a[l]=xi(e[l],n[l]);for(;l<o;++l)r[l]=n[l];return function(s){for(l=0;l<i;++l)r[l]=a[l](s);return r}}function $1(e,n){var o=new Date;return e=+e,n=+n,function(i){return o.setTime(e*(1-i)+n*i),o}}function dn(e,n){return e=+e,n=+n,function(o){return e*(1-o)+n*o}}function T1(e,n){var o={},i={},a;(e===null||typeof e!="object")&&(e={}),(n===null||typeof n!="object")&&(n={});for(a in n)a in e?o[a]=xi(e[a],n[a]):i[a]=n[a];return function(r){for(a in o)i[a]=o[a](r);return i}}var ns=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,os=new RegExp(ns.source,"g");function M1(e){return function(){return e}}function V1(e){return function(n){return e(n)+""}}function Pm(e,n){var o=ns.lastIndex=os.lastIndex=0,i,a,r,l=-1,s=[],c=[];for(e=e+"",n=n+"";(i=ns.exec(e))&&(a=os.exec(n));)(r=a.index)>o&&(r=n.slice(o,r),s[l]?s[l]+=r:s[++l]=r),(i=i[0])===(a=a[0])?s[l]?s[l]+=a:s[++l]=a:(s[++l]=null,c.push({i:l,x:dn(i,a)})),o=os.lastIndex;return o<n.length&&(r=n.slice(o),s[l]?s[l]+=r:s[++l]=r),s.length<2?c[0]?V1(c[0].x):M1(n):(n=c.length,function(d){for(var u=0,m;u<n;++u)s[(m=c[u]).i]=m.x(d);return s.join("")})}function xi(e,n){var o=typeof n,i;return n==null||o==="boolean"?ts(n):(o==="number"?dn:o==="string"?(i=mo(n))?(n=i,Ua):Pm:n instanceof mo?Ua:n instanceof Date?$1:R1(n)?x1:Array.isArray(n)?A1:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?T1:dn)(e,n)}var zm=180/Math.PI,is={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Fm(e,n,o,i,a,r){var l,s,c;return(l=Math.sqrt(e*e+n*n))&&(e/=l,n/=l),(c=e*o+n*i)&&(o-=e*c,i-=n*c),(s=Math.sqrt(o*o+i*i))&&(o/=s,i/=s,c/=s),e*i<n*o&&(e=-e,n=-n,c=-c,l=-l),{translateX:a,translateY:r,rotate:Math.atan2(n,e)*zm,skewX:Math.atan(c)*zm,scaleX:l,scaleY:s}}var Ha;function B1(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?is:Fm(n.a,n.b,n.c,n.d,n.e,n.f)}function D1(e){return e==null||(Ha||(Ha=document.createElementNS("http://www.w3.org/2000/svg","g")),Ha.setAttribute("transform",e),!(e=Ha.transform.baseVal.consolidate()))?is:(e=e.matrix,Fm(e.a,e.b,e.c,e.d,e.e,e.f))}function Um(e,n,o,i){function a(d){return d.length?d.pop()+" ":""}function r(d,u,m,p,f,h){if(d!==m||u!==p){var g=f.push("translate(",null,n,null,o);h.push({i:g-4,x:dn(d,m)},{i:g-2,x:dn(u,p)})}else(m||p)&&f.push("translate("+m+n+p+o)}function l(d,u,m,p){d!==u?(d-u>180?u+=360:u-d>180&&(d+=360),p.push({i:m.push(a(m)+"rotate(",null,i)-2,x:dn(d,u)})):u&&m.push(a(m)+"rotate("+u+i)}function s(d,u,m,p){d!==u?p.push({i:m.push(a(m)+"skewX(",null,i)-2,x:dn(d,u)}):u&&m.push(a(m)+"skewX("+u+i)}function c(d,u,m,p,f,h){if(d!==m||u!==p){var g=f.push(a(f)+"scale(",null,",",null,")");h.push({i:g-4,x:dn(d,m)},{i:g-2,x:dn(u,p)})}else(m!==1||p!==1)&&f.push(a(f)+"scale("+m+","+p+")")}return function(d,u){var m=[],p=[];return d=e(d),u=e(u),r(d.translateX,d.translateY,u.translateX,u.translateY,m,p),l(d.rotate,u.rotate,m,p),s(d.skewX,u.skewX,m,p),c(d.scaleX,d.scaleY,u.scaleX,u.scaleY,m,p),d=u=null,function(f){for(var h=-1,g=p.length,b;++h<g;)m[(b=p[h]).i]=b.x(f);return m.join("")}}}var O1=Um(B1,"px, ","px)","deg)"),L1=Um(D1,", ",")",")"),P1=1e-12;function Hm(e){return((e=Math.exp(e))+1/e)/2}function z1(e){return((e=Math.exp(e))-1/e)/2}function F1(e){return((e=Math.exp(2*e))-1)/(e+1)}const ja=(function e(n,o,i){function a(r,l){var s=r[0],c=r[1],d=r[2],u=l[0],m=l[1],p=l[2],f=u-s,h=m-c,g=f*f+h*h,b,_;if(g<P1)_=Math.log(p/d)/n,b=function(T){return[s+T*f,c+T*h,d*Math.exp(n*T*_)]};else{var E=Math.sqrt(g),N=(p*p-d*d+i*g)/(2*d*o*E),y=(p*p-d*d-i*g)/(2*p*o*E),k=Math.log(Math.sqrt(N*N+1)-N),S=Math.log(Math.sqrt(y*y+1)-y);_=(S-k)/n,b=function(T){var O=T*_,A=Hm(k),V=d/(o*E)*(A*F1(n*O+k)-z1(k));return[s+V*f,c+V*h,d*A/Hm(n*O+k)]}}return b.duration=_*1e3*n/Math.SQRT2,b}return a.rho=function(r){var l=Math.max(.001,+r),s=l*l,c=s*s;return e(l,s,c)},a})(Math.SQRT2,2,4);var qo=0,Ri=0,Ai=0,jm=1e3,Ka,$i,Ga=0,ho=0,Ya=0,Ti=typeof performance=="object"&&performance.now?performance:Date,Km=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function as(){return ho||(Km(U1),ho=Ti.now()+Ya)}function U1(){ho=0}function qa(){this._call=this._time=this._next=null}qa.prototype=Gm.prototype={constructor:qa,restart:function(e,n,o){if(typeof e!="function")throw new TypeError("callback is not a function");o=(o==null?as():+o)+(n==null?0:+n),!this._next&&$i!==this&&($i?$i._next=this:Ka=this,$i=this),this._call=e,this._time=o,rs()},stop:function(){this._call&&(this._call=null,this._time=1/0,rs())}};function Gm(e,n,o){var i=new qa;return i.restart(e,n,o),i}function H1(){as(),++qo;for(var e=Ka,n;e;)(n=ho-e._time)>=0&&e._call.call(void 0,n),e=e._next;--qo}function Ym(){ho=(Ga=Ti.now())+Ya,qo=Ri=0;try{H1()}finally{qo=0,K1(),ho=0}}function j1(){var e=Ti.now(),n=e-Ga;n>jm&&(Ya-=n,Ga=e)}function K1(){for(var e,n=Ka,o,i=1/0;n;)n._call?(i>n._time&&(i=n._time),e=n,n=n._next):(o=n._next,n._next=null,n=e?e._next=o:Ka=o);$i=e,rs(i)}function rs(e){if(!qo){Ri&&(Ri=clearTimeout(Ri));var n=e-ho;n>24?(e<1/0&&(Ri=setTimeout(Ym,e-Ti.now()-Ya)),Ai&&(Ai=clearInterval(Ai))):(Ai||(Ga=Ti.now(),Ai=setInterval(j1,jm)),qo=1,Km(Ym))}}function qm(e,n,o){var i=new qa;return n=n==null?0:+n,i.restart(a=>{i.stop(),e(a+n)},n,o),i}var G1=Ma("start","end","cancel","interrupt"),Y1=[],Wm=0,Jm=1,ls=2,Wa=3,Xm=4,ss=5,Ja=6;function Xa(e,n,o,i,a,r){var l=e.__transition;if(!l)e.__transition={};else if(o in l)return;q1(e,o,{name:n,index:i,group:a,on:G1,tween:Y1,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:Wm})}function cs(e,n){var o=Xt(e,n);if(o.state>Wm)throw new Error("too late; already scheduled");return o}function un(e,n){var o=Xt(e,n);if(o.state>Wa)throw new Error("too late; already running");return o}function Xt(e,n){var o=e.__transition;if(!o||!(o=o[n]))throw new Error("transition not found");return o}function q1(e,n,o){var i=e.__transition,a;i[n]=o,o.timer=Gm(r,0,o.time);function r(d){o.state=Jm,o.timer.restart(l,o.delay,o.time),o.delay<=d&&l(d-o.delay)}function l(d){var u,m,p,f;if(o.state!==Jm)return c();for(u in i)if(f=i[u],f.name===o.name){if(f.state===Wa)return qm(l);f.state===Xm?(f.state=Ja,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete i[u]):+u<n&&(f.state=Ja,f.timer.stop(),f.on.call("cancel",e,e.__data__,f.index,f.group),delete i[u])}if(qm(function(){o.state===Wa&&(o.state=Xm,o.timer.restart(s,o.delay,o.time),s(d))}),o.state=ls,o.on.call("start",e,e.__data__,o.index,o.group),o.state===ls){for(o.state=Wa,a=new Array(p=o.tween.length),u=0,m=-1;u<p;++u)(f=o.tween[u].value.call(e,e.__data__,o.index,o.group))&&(a[++m]=f);a.length=m+1}}function s(d){for(var u=d<o.duration?o.ease.call(null,d/o.duration):(o.timer.restart(c),o.state=ss,1),m=-1,p=a.length;++m<p;)a[m].call(e,u);o.state===ss&&(o.on.call("end",e,e.__data__,o.index,o.group),c())}function c(){o.state=Ja,o.timer.stop(),delete i[n];for(var d in i)return;delete e.__transition}}function Za(e,n){var o=e.__transition,i,a,r=!0,l;if(o){n=n==null?null:n+"";for(l in o){if((i=o[l]).name!==n){r=!1;continue}a=i.state>ls&&i.state<ss,i.state=Ja,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete o[l]}r&&delete e.__transition}}function W1(e){return this.each(function(){Za(this,e)})}function J1(e,n){var o,i;return function(){var a=un(this,e),r=a.tween;if(r!==o){i=o=r;for(var l=0,s=i.length;l<s;++l)if(i[l].name===n){i=i.slice(),i.splice(l,1);break}}a.tween=i}}function X1(e,n,o){var i,a;if(typeof o!="function")throw new Error;return function(){var r=un(this,e),l=r.tween;if(l!==i){a=(i=l).slice();for(var s={name:n,value:o},c=0,d=a.length;c<d;++c)if(a[c].name===n){a[c]=s;break}c===d&&a.push(s)}r.tween=a}}function Z1(e,n){var o=this._id;if(e+="",arguments.length<2){for(var i=Xt(this.node(),o).tween,a=0,r=i.length,l;a<r;++a)if((l=i[a]).name===e)return l.value;return null}return this.each((n==null?J1:X1)(o,e,n))}function ds(e,n,o){var i=e._id;return e.each(function(){var a=un(this,i);(a.value||(a.value={}))[n]=o.apply(this,arguments)}),function(a){return Xt(a,i).value[n]}}function Zm(e,n){var o;return(typeof n=="number"?dn:n instanceof mo?Ua:(o=mo(n))?(n=o,Ua):Pm)(e,n)}function Q1(e){return function(){this.removeAttribute(e)}}function e0(e){return function(){this.removeAttributeNS(e.space,e.local)}}function t0(e,n,o){var i,a=o+"",r;return function(){var l=this.getAttribute(e);return l===a?null:l===i?r:r=n(i=l,o)}}function n0(e,n,o){var i,a=o+"",r;return function(){var l=this.getAttributeNS(e.space,e.local);return l===a?null:l===i?r:r=n(i=l,o)}}function o0(e,n,o){var i,a,r;return function(){var l,s=o(this),c;return s==null?void this.removeAttribute(e):(l=this.getAttribute(e),c=s+"",l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s)))}}function i0(e,n,o){var i,a,r;return function(){var l,s=o(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(l=this.getAttributeNS(e.space,e.local),c=s+"",l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s)))}}function a0(e,n){var o=Ba(e),i=o==="transform"?L1:Zm;return this.attrTween(e,typeof n=="function"?(o.local?i0:o0)(o,i,ds(this,"attr."+e,n)):n==null?(o.local?e0:Q1)(o):(o.local?n0:t0)(o,i,n))}function r0(e,n){return function(o){this.setAttribute(e,n.call(this,o))}}function l0(e,n){return function(o){this.setAttributeNS(e.space,e.local,n.call(this,o))}}function s0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&l0(e,r)),o}return a._value=n,a}function c0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&r0(e,r)),o}return a._value=n,a}function d0(e,n){var o="attr."+e;if(arguments.length<2)return(o=this.tween(o))&&o._value;if(n==null)return this.tween(o,null);if(typeof n!="function")throw new Error;var i=Ba(e);return this.tween(o,(i.local?s0:c0)(i,n))}function u0(e,n){return function(){cs(this,e).delay=+n.apply(this,arguments)}}function m0(e,n){return n=+n,function(){cs(this,e).delay=n}}function f0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?u0:m0)(n,e)):Xt(this.node(),n).delay}function p0(e,n){return function(){un(this,e).duration=+n.apply(this,arguments)}}function h0(e,n){return n=+n,function(){un(this,e).duration=n}}function y0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?p0:h0)(n,e)):Xt(this.node(),n).duration}function g0(e,n){if(typeof n!="function")throw new Error;return function(){un(this,e).ease=n}}function b0(e){var n=this._id;return arguments.length?this.each(g0(n,e)):Xt(this.node(),n).ease}function _0(e,n){return function(){var o=n.apply(this,arguments);if(typeof o!="function")throw new Error;un(this,e).ease=o}}function k0(e){if(typeof e!="function")throw new Error;return this.each(_0(this._id,e))}function E0(e){typeof e!="function"&&(e=ym(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=[],c,d=0;d<l;++d)(c=r[d])&&e.call(c,c.__data__,d,r)&&s.push(c);return new In(i,this._parents,this._name,this._id)}function N0(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,o=e._groups,i=n.length,a=o.length,r=Math.min(i,a),l=new Array(i),s=0;s<r;++s)for(var c=n[s],d=o[s],u=c.length,m=l[s]=new Array(u),p,f=0;f<u;++f)(p=c[f]||d[f])&&(m[f]=p);for(;s<i;++s)l[s]=n[s];return new In(l,this._parents,this._name,this._id)}function w0(e){return(e+"").trim().split(/^|\s+/).every(function(n){var o=n.indexOf(".");return o>=0&&(n=n.slice(0,o)),!n||n==="start"})}function I0(e,n,o){var i,a,r=w0(n)?cs:un;return function(){var l=r(this,e),s=l.on;s!==i&&(a=(i=s).copy()).on(n,o),l.on=a}}function v0(e,n){var o=this._id;return arguments.length<2?Xt(this.node(),o).on.on(e):this.each(I0(o,e,n))}function C0(e){return function(){var n=this.parentNode;for(var o in this.__transition)if(+o!==e)return;n&&n.removeChild(this)}}function S0(){return this.on("end.remove",C0(this._id))}function x0(e){var n=this._name,o=this._id;typeof e!="function"&&(e=ql(e));for(var i=this._groups,a=i.length,r=new Array(a),l=0;l<a;++l)for(var s=i[l],c=s.length,d=r[l]=new Array(c),u,m,p=0;p<c;++p)(u=s[p])&&(m=e.call(u,u.__data__,p,s))&&("__data__"in u&&(m.__data__=u.__data__),d[p]=m,Xa(d[p],n,o,p,d,Xt(u,o)));return new In(r,this._parents,n,o)}function R0(e){var n=this._name,o=this._id;typeof e!="function"&&(e=hm(e));for(var i=this._groups,a=i.length,r=[],l=[],s=0;s<a;++s)for(var c=i[s],d=c.length,u,m=0;m<d;++m)if(u=c[m]){for(var p=e.call(u,u.__data__,m,c),f,h=Xt(u,o),g=0,b=p.length;g<b;++g)(f=p[g])&&Xa(f,n,o,g,p,h);r.push(p),l.push(u)}return new In(r,l,n,o)}var A0=wi.prototype.constructor;function $0(){return new A0(this._groups,this._parents)}function T0(e,n){var o,i,a;return function(){var r=Ko(this,e),l=(this.style.removeProperty(e),Ko(this,e));return r===l?null:r===o&&l===i?a:a=n(o=r,i=l)}}function Qm(e){return function(){this.style.removeProperty(e)}}function M0(e,n,o){var i,a=o+"",r;return function(){var l=Ko(this,e);return l===a?null:l===i?r:r=n(i=l,o)}}function V0(e,n,o){var i,a,r;return function(){var l=Ko(this,e),s=o(this),c=s+"";return s==null&&(c=s=(this.style.removeProperty(e),Ko(this,e))),l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s))}}function B0(e,n){var o,i,a,r="style."+n,l="end."+r,s;return function(){var c=un(this,e),d=c.on,u=c.value[r]==null?s||(s=Qm(n)):void 0;(d!==o||a!==u)&&(i=(o=d).copy()).on(l,a=u),c.on=i}}function D0(e,n,o){var i=(e+="")=="transform"?O1:Zm;return n==null?this.styleTween(e,T0(e,i)).on("end.style."+e,Qm(e)):typeof n=="function"?this.styleTween(e,V0(e,i,ds(this,"style."+e,n))).each(B0(this._id,e)):this.styleTween(e,M0(e,i,n),o).on("end.style."+e,null)}function O0(e,n,o){return function(i){this.style.setProperty(e,n.call(this,i),o)}}function L0(e,n,o){var i,a;function r(){var l=n.apply(this,arguments);return l!==a&&(i=(a=l)&&O0(e,l,o)),i}return r._value=n,r}function P0(e,n,o){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(n==null)return this.tween(i,null);if(typeof n!="function")throw new Error;return this.tween(i,L0(e,n,o??""))}function z0(e){return function(){this.textContent=e}}function F0(e){return function(){var n=e(this);this.textContent=n??""}}function U0(e){return this.tween("text",typeof e=="function"?F0(ds(this,"text",e)):z0(e==null?"":e+""))}function H0(e){return function(n){this.textContent=e.call(this,n)}}function j0(e){var n,o;function i(){var a=e.apply(this,arguments);return a!==o&&(n=(o=a)&&H0(a)),n}return i._value=e,i}function K0(e){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,j0(e))}function G0(){for(var e=this._name,n=this._id,o=ef(),i=this._groups,a=i.length,r=0;r<a;++r)for(var l=i[r],s=l.length,c,d=0;d<s;++d)if(c=l[d]){var u=Xt(c,n);Xa(c,e,o,d,l,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new In(i,this._parents,e,o)}function Y0(){var e,n,o=this,i=o._id,a=o.size();return new Promise(function(r,l){var s={value:l},c={value:function(){--a===0&&r()}};o.each(function(){var d=un(this,i),u=d.on;u!==e&&(n=(e=u).copy(),n._.cancel.push(s),n._.interrupt.push(s),n._.end.push(c)),d.on=n}),a===0&&r()})}var q0=0;function In(e,n,o,i){this._groups=e,this._parents=n,this._name=o,this._id=i}function ef(){return++q0}var vn=wi.prototype;In.prototype={constructor:In,select:x0,selectAll:R0,selectChild:vn.selectChild,selectChildren:vn.selectChildren,filter:E0,merge:N0,selection:$0,transition:G0,call:vn.call,nodes:vn.nodes,node:vn.node,size:vn.size,empty:vn.empty,each:vn.each,on:v0,attr:a0,attrTween:d0,style:D0,styleTween:P0,text:U0,textTween:K0,remove:S0,tween:Z1,delay:f0,duration:y0,ease:b0,easeVarying:k0,end:Y0,[Symbol.iterator]:vn[Symbol.iterator]};function W0(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var J0={time:null,delay:0,duration:250,ease:W0};function X0(e,n){for(var o;!(o=e.__transition)||!(o=o[n]);)if(!(e=e.parentNode))throw new Error(`transition ${n} not found`);return o}function Z0(e){var n,o;e instanceof In?(n=e._id,e=e._name):(n=ef(),(o=J0).time=as(),e=e==null?null:e+"");for(var i=this._groups,a=i.length,r=0;r<a;++r)for(var l=i[r],s=l.length,c,d=0;d<s;++d)(c=l[d])&&Xa(c,e,n,d,l,o||X0(c,n));return new In(i,this._parents,e,n)}wi.prototype.interrupt=W1,wi.prototype.transition=Z0;const Qa=e=>()=>e;function Q0(e,{sourceEvent:n,target:o,transform:i,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function Cn(e,n,o){this.k=e,this.x=n,this.y=o}Cn.prototype={constructor:Cn,scale:function(e){return e===1?this:new Cn(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new Cn(this.k,this.x+this.k*e,this.y+this.k*n)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Wo=new Cn(1,0,0);Cn.prototype;function us(e){e.stopImmediatePropagation()}function Mi(e){e.preventDefault(),e.stopImmediatePropagation()}function eN(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function tN(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function tf(){return this.__zoom||Wo}function nN(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function oN(){return navigator.maxTouchPoints||"ontouchstart"in this}function iN(e,n,o){var i=e.invertX(n[0][0])-o[0][0],a=e.invertX(n[1][0])-o[1][0],r=e.invertY(n[0][1])-o[0][1],l=e.invertY(n[1][1])-o[1][1];return e.translate(a>i?(i+a)/2:Math.min(0,i)||Math.max(0,a),l>r?(r+l)/2:Math.min(0,r)||Math.max(0,l))}function aN(){var e=eN,n=tN,o=iN,i=nN,a=oN,r=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],s=250,c=ja,d=Ma("start","zoom","end"),u,m,p,f=500,h=150,g=0,b=10;function _(w){w.property("__zoom",tf).on("wheel.zoom",O,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",V).filter(a).on("touchstart.zoom",C).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",$).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(w,I,v,B){var M=w.selection?w.selection():w;M.property("__zoom",tf),w!==M?k(w,I,v,B):M.interrupt().each(function(){S(this,arguments).event(B).start().zoom(null,typeof I=="function"?I.apply(this,arguments):I).end()})},_.scaleBy=function(w,I,v,B){_.scaleTo(w,function(){var M=this.__zoom.k,x=typeof I=="function"?I.apply(this,arguments):I;return M*x},v,B)},_.scaleTo=function(w,I,v,B){_.transform(w,function(){var M=n.apply(this,arguments),x=this.__zoom,P=v==null?y(M):typeof v=="function"?v.apply(this,arguments):v,q=x.invert(P),ce=typeof I=="function"?I.apply(this,arguments):I;return o(N(E(x,ce),P,q),M,l)},v,B)},_.translateBy=function(w,I,v,B){_.transform(w,function(){return o(this.__zoom.translate(typeof I=="function"?I.apply(this,arguments):I,typeof v=="function"?v.apply(this,arguments):v),n.apply(this,arguments),l)},null,B)},_.translateTo=function(w,I,v,B,M){_.transform(w,function(){var x=n.apply(this,arguments),P=this.__zoom,q=B==null?y(x):typeof B=="function"?B.apply(this,arguments):B;return o(Wo.translate(q[0],q[1]).scale(P.k).translate(typeof I=="function"?-I.apply(this,arguments):-I,typeof v=="function"?-v.apply(this,arguments):-v),x,l)},B,M)};function E(w,I){return I=Math.max(r[0],Math.min(r[1],I)),I===w.k?w:new Cn(I,w.x,w.y)}function N(w,I,v){var B=I[0]-v[0]*w.k,M=I[1]-v[1]*w.k;return B===w.x&&M===w.y?w:new Cn(w.k,B,M)}function y(w){return[(+w[0][0]+ +w[1][0])/2,(+w[0][1]+ +w[1][1])/2]}function k(w,I,v,B){w.on("start.zoom",function(){S(this,arguments).event(B).start()}).on("interrupt.zoom end.zoom",function(){S(this,arguments).event(B).end()}).tween("zoom",function(){var M=this,x=arguments,P=S(M,x).event(B),q=n.apply(M,x),ce=v==null?y(q):typeof v=="function"?v.apply(M,x):v,ge=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=M.__zoom,pe=typeof I=="function"?I.apply(M,x):I,he=c(ie.invert(ce).concat(ge/ie.k),pe.invert(ce).concat(ge/pe.k));return function(_e){if(_e===1)_e=pe;else{var Ae=he(_e),je=ge/Ae[2];_e=new Cn(je,ce[0]-Ae[0]*je,ce[1]-Ae[1]*je)}P.zoom(null,_e)}})}function S(w,I,v){return!v&&w.__zooming||new T(w,I)}function T(w,I){this.that=w,this.args=I,this.active=0,this.sourceEvent=null,this.extent=n.apply(w,I),this.taps=0}T.prototype={event:function(w){return w&&(this.sourceEvent=w),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(w,I){return this.mouse&&w!=="mouse"&&(this.mouse[1]=I.invert(this.mouse[0])),this.touch0&&w!=="touch"&&(this.touch0[1]=I.invert(this.touch0[0])),this.touch1&&w!=="touch"&&(this.touch1[1]=I.invert(this.touch1[0])),this.that.__zoom=I,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(w){var I=Wt(this.that).datum();d.call(w,this.that,new Q0(w,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:d}),I)}};function O(w,...I){if(!e.apply(this,arguments))return;var v=S(this,I).event(w),B=this.__zoom,M=Math.max(r[0],Math.min(r[1],B.k*Math.pow(2,i.apply(this,arguments)))),x=sn(w);if(v.wheel)(v.mouse[0][0]!==x[0]||v.mouse[0][1]!==x[1])&&(v.mouse[1]=B.invert(v.mouse[0]=x)),clearTimeout(v.wheel);else{if(B.k===M)return;v.mouse=[x,B.invert(x)],Za(this),v.start()}Mi(w),v.wheel=setTimeout(P,h),v.zoom("mouse",o(N(E(B,M),v.mouse[0],v.mouse[1]),v.extent,l));function P(){v.wheel=null,v.end()}}function A(w,...I){if(p||!e.apply(this,arguments))return;var v=w.currentTarget,B=S(this,I,!0).event(w),M=Wt(w.view).on("mousemove.zoom",ce,!0).on("mouseup.zoom",ge,!0),x=sn(w,v),P=w.clientX,q=w.clientY;Cm(w.view),us(w),B.mouse=[x,this.__zoom.invert(x)],Za(this),B.start();function ce(ie){if(Mi(ie),!B.moved){var pe=ie.clientX-P,he=ie.clientY-q;B.moved=pe*pe+he*he>g}B.event(ie).zoom("mouse",o(N(B.that.__zoom,B.mouse[0]=sn(ie,v),B.mouse[1]),B.extent,l))}function ge(ie){M.on("mousemove.zoom mouseup.zoom",null),Sm(ie.view,B.moved),Mi(ie),B.event(ie).end()}}function V(w,...I){if(e.apply(this,arguments)){var v=this.__zoom,B=sn(w.changedTouches?w.changedTouches[0]:w,this),M=v.invert(B),x=v.k*(w.shiftKey?.5:2),P=o(N(E(v,x),B,M),n.apply(this,I),l);Mi(w),s>0?Wt(this).transition().duration(s).call(k,P,B,w):Wt(this).call(_.transform,P,B,w)}}function C(w,...I){if(e.apply(this,arguments)){var v=w.touches,B=v.length,M=S(this,I,w.changedTouches.length===B).event(w),x,P,q,ce;for(us(w),P=0;P<B;++P)q=v[P],ce=sn(q,this),ce=[ce,this.__zoom.invert(ce),q.identifier],M.touch0?!M.touch1&&M.touch0[2]!==ce[2]&&(M.touch1=ce,M.taps=0):(M.touch0=ce,x=!0,M.taps=1+!!u);u&&(u=clearTimeout(u)),x&&(M.taps<2&&(m=ce[0],u=setTimeout(function(){u=null},f)),Za(this),M.start())}}function R(w,...I){if(this.__zooming){var v=S(this,I).event(w),B=w.changedTouches,M=B.length,x,P,q,ce;for(Mi(w),x=0;x<M;++x)P=B[x],q=sn(P,this),v.touch0&&v.touch0[2]===P.identifier?v.touch0[0]=q:v.touch1&&v.touch1[2]===P.identifier&&(v.touch1[0]=q);if(P=v.that.__zoom,v.touch1){var ge=v.touch0[0],ie=v.touch0[1],pe=v.touch1[0],he=v.touch1[1],_e=(_e=pe[0]-ge[0])*_e+(_e=pe[1]-ge[1])*_e,Ae=(Ae=he[0]-ie[0])*Ae+(Ae=he[1]-ie[1])*Ae;P=E(P,Math.sqrt(_e/Ae)),q=[(ge[0]+pe[0])/2,(ge[1]+pe[1])/2],ce=[(ie[0]+he[0])/2,(ie[1]+he[1])/2]}else if(v.touch0)q=v.touch0[0],ce=v.touch0[1];else return;v.zoom("touch",o(N(P,q,ce),v.extent,l))}}function $(w,...I){if(this.__zooming){var v=S(this,I).event(w),B=w.changedTouches,M=B.length,x,P;for(us(w),p&&clearTimeout(p),p=setTimeout(function(){p=null},f),x=0;x<M;++x)P=B[x],v.touch0&&v.touch0[2]===P.identifier?delete v.touch0:v.touch1&&v.touch1[2]===P.identifier&&delete v.touch1;if(v.touch1&&!v.touch0&&(v.touch0=v.touch1,delete v.touch1),v.touch0)v.touch0[1]=this.__zoom.invert(v.touch0[0]);else if(v.end(),v.taps===2&&(P=sn(P,this),Math.hypot(m[0]-P[0],m[1]-P[1])<b)){var q=Wt(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return _.wheelDelta=function(w){return arguments.length?(i=typeof w=="function"?w:Qa(+w),_):i},_.filter=function(w){return arguments.length?(e=typeof w=="function"?w:Qa(!!w),_):e},_.touchable=function(w){return arguments.length?(a=typeof w=="function"?w:Qa(!!w),_):a},_.extent=function(w){return arguments.length?(n=typeof w=="function"?w:Qa([[+w[0][0],+w[0][1]],[+w[1][0],+w[1][1]]]),_):n},_.scaleExtent=function(w){return arguments.length?(r[0]=+w[0],r[1]=+w[1],_):[r[0],r[1]]},_.translateExtent=function(w){return arguments.length?(l[0][0]=+w[0][0],l[1][0]=+w[1][0],l[0][1]=+w[0][1],l[1][1]=+w[1][1],_):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},_.constrain=function(w){return arguments.length?(o=w,_):o},_.duration=function(w){return arguments.length?(s=+w,_):s},_.interpolate=function(w){return arguments.length?(c=w,_):c},_.on=function(){var w=d.on.apply(d,arguments);return w===d?_:w},_.clickDistance=function(w){return arguments.length?(g=(w=+w)*w,_):Math.sqrt(g)},_.tapDistance=function(w){return arguments.length?(b=+w,_):b},_}var Le=(e=>(e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom",e))(Le||{}),ms=(e=>(e.Partial="partial",e.Full="full",e))(ms||{}),yo=(e=>(e.Bezier="default",e.SimpleBezier="simple-bezier",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e))(yo||{}),Sn=(e=>(e.Strict="strict",e.Loose="loose",e))(Sn||{}),fs=(e=>(e.Arrow="arrow",e.ArrowClosed="arrowclosed",e))(fs||{}),Vi=(e=>(e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal",e))(Vi||{}),nf=(e=>(e.TopLeft="top-left",e.TopCenter="top-center",e.TopRight="top-right",e.BottomLeft="bottom-left",e.BottomCenter="bottom-center",e.BottomRight="bottom-right",e))(nf||{});const rN=["INPUT","SELECT","TEXTAREA"],lN=typeof document<"u"?document:null;function ps(e){var n,o;const i=((o=(n=e.composedPath)==null?void 0:n.call(e))==null?void 0:o[0])||e.target,a=typeof(i==null?void 0:i.hasAttribute)=="function"?i.hasAttribute("contenteditable"):!1,r=typeof(i==null?void 0:i.closest)=="function"?i.closest(".nokey"):null;return rN.includes(i==null?void 0:i.nodeName)||a||!!r}function sN(e){return e.ctrlKey||e.metaKey||e.shiftKey||e.altKey}function of(e,n,o,i){const a=n.replace("+",`
27
+ `}}const ao="com.example",Qg="command.domain";function kn(e,n,o={}){const i=To(e,n);if(i.kind==="explicit")return i.value;const a=o.packageConfig;if(a!=null&&a.basePackage){const r=i.value?`.${i.value}`:"",l=a.layerSuffix??Qg,s=l?`.${l}`:"";return`${a.basePackage}${r}${s}`}return n.packageName||""}const eb="CustomMoneyType",tb="Money";function nb(e){return!(e.type!==eb||e.attrType!=="NORMAL"||e.identifier||e.dbAttrs.length>1)}function ob(e){const n=e.dbAttrs[0]??{modelId:Pe(),physicalName:"",dataType:""},o={modelId:Pe(),physicalName:"",dataType:""},{customType:i,...a}=e;return{...a,type:tb,attrType:"EMBED_PREDEF",dbAttrs:[n,o]}}function ib(e){let n=!1;const o=e.entities.map(i=>{let a=!1;const r=i.attributes.map(l=>nb(l)?(a=!0,n=!0,ob(l)):l);return a?{...i,attributes:r}:i});return n?{...e,entities:o}:e}function ab(e,n){const o=new Map,i=[],a=new Map;for(const h of e.entities){const g=new Map,b=new Map,_=new Map,E=(N,y,k)=>{if(!N)return;o.get(N)||o.set(N,[{entityId:y,assignedId:N}]),i.push({id:N,entityId:y,sink:k}),k(N)};for(const N of h.attributes){E(N.modelId,h.modelId,y=>g.set(N,y));for(const y of N.dbAttrs)E(y.modelId,h.modelId,k=>b.set(y,k))}for(const N of h.indexes??[])E(N.modelId,h.modelId,y=>_.set(N,y));a.set(h,{attrs:g,cols:b,idx:_})}const r=new Set(o.keys()),l=new Map;for(const h of i){const g=(l.get(h.id)??0)+1;if(l.set(h.id,g),g===1)continue;const b=rb(h.id,g-1,r);r.add(b),o.get(h.id).push({entityId:h.entityId,assignedId:b}),h.sink(b)}const s=[...o.values()].reduce((h,g)=>h+Math.max(0,g.length-1),0);if(s===0)return{logical:e,layout:n,reissued:0};const c=(h,g)=>{var _;if(!g||!h)return g;const b=o.get(g);return!b||b.length<2?g:((_=b.find(E=>E.entityId===h))==null?void 0:_.assignedId)??g},d=new Map(e.associations.map(h=>[h.modelId,h])),u=(h,g)=>{const b=d.get(h);if(b)return b.end1.entityRef===g?b.end2.entityRef:b.end1.entityRef},m=e.entities.map(h=>{var N;const g=a.get(h),b=h.attributes.map(y=>{const k=g.attrs.get(y),S=y.dbAttrs.map(A=>{const V=g.cols.get(A);return V===A.modelId?A:{...A,modelId:V}});let T=y.derivedFrom;if(T){const A=u(T.associationRef,h.modelId),V=c(A,T.sourceAttributeRef);V!==T.sourceAttributeRef&&(T={...T,sourceAttributeRef:V})}return k!==y.modelId||T!==y.derivedFrom||S.some((A,V)=>A!==y.dbAttrs[V])?{...y,modelId:k,dbAttrs:S,derivedFrom:T}:y}),_=(N=h.indexes)==null?void 0:N.map(y=>{const k=g.idx.get(y),S=y.columns.map(O=>{const A=c(h.modelId,O.columnRef);return A===O.columnRef?O:{...O,columnRef:A}});return k!==y.modelId||S.some((O,A)=>O!==y.columns[A])?{...y,modelId:k,columns:S}:y});return b.some((y,k)=>y!==h.attributes[k])||_&&h.indexes&&_.some((y,k)=>y!==h.indexes[k])?{...h,attributes:b,..._?{indexes:_}:{}}:h}),p=e.associations.map(h=>{const g=c(h.end1.entityRef,h.end1.attributeRef),b=c(h.end2.entityRef,h.end2.attributeRef);return g===h.end1.attributeRef&&b===h.end2.attributeRef?h:{...h,end1:g===h.end1.attributeRef?h.end1:{...h.end1,attributeRef:g},end2:b===h.end2.attributeRef?h.end2:{...h.end2,attributeRef:b}}}),f=n.associationLayouts.map(h=>{const g=d.get(h.associationRef);if(!g)return h;const b=c(g.end1.entityRef,h.sourceColumnRef),_=c(g.end2.entityRef,h.targetColumnRef);return b===h.sourceColumnRef&&_===h.targetColumnRef?h:{...h,sourceColumnRef:b,targetColumnRef:_}});return{logical:{...e,entities:m,associations:p},layout:f.some((h,g)=>h!==n.associationLayouts[g])?{...n,associationLayouts:f}:n,reissued:s}}function rb(e,n,o){let i=n;for(;;){const a=`dup${i}:${e}`;if(!o.has(a))return a;i++}}const lb="5.2.8";function Ht(e){return e.reduce((n,o)=>Math.max(n,o.order),-1)+1}function wl(e,n,o){const i=new Set(n),a=e.filter(s=>i.has(s.modelId)),r=e.filter(s=>!i.has(s.modelId)),l=Math.max(0,Math.min(o,r.length));return[...r.slice(0,l),...a,...r.slice(l)]}function wd(e){return!!e.derivedFrom&&e.dbAttrs.length>0}function Id(e){for(const n of e){const o=[...n.attributes].sort((s,c)=>s.order-c.order),i=o.filter(wd);if(!i.length)continue;const a=o.filter(s=>!wd(s));let r=0;a.forEach((s,c)=>{s.identifier&&!s.derivedFrom&&(r=c+1)});const l=[...a.slice(0,r),...i,...a.slice(r)];l.forEach((s,c)=>s.order=c),n.attributes=l}}function zo(e){return JSON.parse(JSON.stringify(e))}function vd(e,n,o){var O;const i=o.idFactory??Pe,a=o.offset??{x:0,y:0},{logical:r,layout:l}=e,s=new Set(n);if(o.includeRelated){const A=new Set(n);for(const V of r.associations){const C=A.has(V.end1.entityRef),R=A.has(V.end2.entityRef);C!==R&&s.add(C?V.end2.entityRef:V.end1.entityRef)}}const c=r.entities.filter(A=>s.has(A.modelId)),d=new Set(c.map(A=>A.modelId)),u=r.associations.filter(A=>d.has(A.end1.entityRef)&&d.has(A.end2.entityRef)),m=new Set(u.map(A=>A.modelId)),p=new Map,f=A=>{let V=p.get(A);return V||(V=i(),p.set(A,V)),V};for(const A of c){f(A.modelId);for(const V of A.attributes){f(V.modelId);for(const C of V.dbAttrs)f(C.modelId)}for(const V of A.indexes??[])f(V.modelId);for(const V of A.operations??[])f(V.modelId)}for(const A of u)f(A.modelId);const h=A=>p.get(A),g=c.map(A=>{const V=zo(A);V.modelId=h(A.modelId),V.attributes=V.attributes.map(C=>sb(C,h,m,d));for(const C of V.indexes??[])C.modelId=h(C.modelId),C.columns=C.columns.map(R=>Xn(R.columnRef)?R:{...R,columnRef:h(R.columnRef)}).filter(R=>R.columnRef!==void 0);for(const C of V.operations??[])C.modelId=h(C.modelId);return V});Id(g);const b=u.map(A=>{const V=zo(A);return V.modelId=h(A.modelId),V.end1=Cd(V.end1,h),V.end2=Cd(V.end2,h),V}),_=[];for(const A of r.groups){const V=A.memberEntityRefs.filter(R=>d.has(R));if(V.length===0)continue;const C=zo(A);C.modelId=f(A.modelId),C.memberEntityRefs=V.map(R=>h(R)),_.push(C)}const E=o.collisionSuffix??"_imported",N=new Set(o.existing.entities.map(A=>A.name)),y=new Set(o.existing.entities.map(A=>{var V;return(V=A.table)==null?void 0:V.physicalName}).filter(A=>!!A));for(const A of g)N.has(A.name)&&(A.name=`${A.name}${E}`),(O=A.table)!=null&&O.physicalName&&y.has(A.table.physicalName)&&(A.table.physicalName=`${A.table.physicalName}${E}`);const k=[];for(const A of l.entityLayouts){const V=h(A.entityRef);if(!V)continue;const C=zo(A);C.entityRef=V,C.geo={...C.geo,location:Il(C.geo.location,a)},C.attributeStyles&&(C.attributeStyles=Na(C.attributeStyles,h)),C.operationStyles&&(C.operationStyles=Na(C.operationStyles,h)),k.push(C)}const S=[];for(const A of l.associationLayouts){const V=h(A.associationRef);if(!V)continue;const C=zo(A);C.associationRef=V,C.sourceColumnRef=A.sourceColumnRef?h(A.sourceColumnRef):void 0,C.targetColumnRef=A.targetColumnRef?h(A.targetColumnRef):void 0,C.waypoints=C.waypoints.map(R=>Il(R,a)),S.push(C)}const T=[];for(const A of l.groupLayouts){const V=h(A.groupRef);if(!V)continue;const C=zo(A);C.groupRef=V,C.geo={...C.geo,location:Il(C.geo.location,a)},delete C.memberNoteRefs,T.push(C)}return{logical:{entities:g,associations:b,groups:_},layout:{entityLayouts:k,associationLayouts:S,groupLayouts:T},idMap:p}}function Il(e,n){return{x:e.x+n.x,y:e.y+n.y}}function sb(e,n,o,i){e.modelId=n(e.modelId);for(const a of e.dbAttrs)if(a.modelId=n(a.modelId),a.sharedColumnRef!==void 0){const r=n(a.sharedColumnRef);r?a.sharedColumnRef=r:delete a.sharedColumnRef}return e.derivedFrom&&(o.has(e.derivedFrom.associationRef)?e.derivedFrom={associationRef:n(e.derivedFrom.associationRef),sourceAttributeRef:n(e.derivedFrom.sourceAttributeRef)??e.derivedFrom.sourceAttributeRef}:(delete e.derivedFrom,(e.attrType==="RELATION_OWN"||e.attrType==="RELATION_REF")&&(e.attrType="NORMAL"))),e.embedded&&(i.has(e.embedded.embeddableRef)?e.embedded={associationRef:n(e.embedded.associationRef)??e.embedded.associationRef,embeddableRef:n(e.embedded.embeddableRef)}:(delete e.embedded,e.attrType.startsWith("EMBED")&&(e.attrType="NORMAL"))),e}function Cd(e,n){return{...e,entityRef:n(e.entityRef),attributeRef:e.attributeRef?n(e.attributeRef):void 0}}function Na(e,n){const o={};for(const[i,a]of Object.entries(e)){const r=n(i);r&&(o[r]=a)}return o}function vl(e){if(!("rev"in e))return e;const{rev:n,...o}=e;return o}function ro(e,n){if(e===n||e==null&&n==null)return!0;if(e==null||n==null)return!1;if(Array.isArray(e)||Array.isArray(n))return!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length?!1:e.every((o,i)=>ro(o,n[i]));if(typeof e=="object"&&typeof n=="object"){const o=new Set([...Object.keys(e),...Object.keys(n)]);for(const i of o)if(!ro(e[i],n[i]))return!1;return!0}return!1}function lo(e,n,o){const i={},a=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of a)o.has(r)||ro(e[r],n[r])||(i[r]=n[r]===void 0?null:n[r]);return Object.keys(i).length?i:null}function so(e,n,o){const i=new Map(e.map(d=>[o(d),d])),a=new Map(n.map(d=>[o(d),d])),r=[],l=[],s=[];for(const[d,u]of a){const m=i.get(d);m?s.push({cur:m,tgt:u}):r.push(u)}for(const[d,u]of i)a.has(d)||l.push(u);const c=(d,u)=>o(d)<o(u)?-1:o(d)>o(u)?1:0;return r.sort(c),l.sort(c),s.sort((d,u)=>c(d.tgt,u.tgt)),{added:r,removed:l,common:s}}function cb(e,n){const o=new Set(e),i=new Set(n),a=n.filter(l=>!o.has(l)).sort(),r=e.filter(l=>!i.has(l)).sort();return{added:a,removed:r}}const db=new Set(["attributes","operations","indexes","rev"]),ub=new Set(["end1","end2","rev"]),mb=new Set(["memberEntityRefs","rev"]),Sd=new Set(["modelId"]),fb=new Set(["modelId","columns"]),pb=new Set([]);function hb(e,n,o,i){const a=so(n.attributes??[],o.attributes??[],s=>s.modelId);for(const s of a.removed)i.push({kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId});for(const s of a.added)i.push({kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of a.common){const d=lo(s,c,Sd);d&&i.push({kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId,patch:d})}const r=so(n.operations??[],o.operations??[],s=>s.modelId);for(const s of r.removed)i.push({kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId});for(const s of r.added)i.push({kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of r.common){const d=lo(s,c,Sd);d&&i.push({kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId,patch:d})}const l=so(n.indexes??[],o.indexes??[],s=>s.modelId);for(const s of l.removed)i.push({kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId});for(const s of l.added)i.push({kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:s});for(const{cur:s,tgt:c}of l.common){if(!ro(s.columns,c.columns)){i.push({kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId}),i.push({kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:c});continue}const d=lo(s,c,fb);d&&i.push({kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId,patch:d})}}function yb(e,n,o){const i=so(e.entities??[],n.entities??[],l=>l.modelId);for(const l of i.removed)o.push({kind:"entity.remove",casUnit:"logical",entityRef:l.modelId});for(const l of i.added)o.push({kind:"entity.add",casUnit:"logical",entityRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of i.common){const c=lo(l,s,db);c&&o.push({kind:"entity.update",casUnit:"logical",containerRef:l.modelId,entityRef:l.modelId,patch:c}),hb(l.modelId,l,s,o)}const a=so(e.associations??[],n.associations??[],l=>l.modelId);for(const l of a.removed)o.push({kind:"association.remove",casUnit:"logical",associationRef:l.modelId});for(const l of a.added)o.push({kind:"association.add",casUnit:"logical",associationRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of a.common){const c=lo(l,s,ub);c&&o.push({kind:"association.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,patch:c});for(const d of["end1","end2"]){const u=lo(l[d]??{},s[d]??{},pb);u&&o.push({kind:"associationEnd.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,end:d,patch:u})}}const r=so(e.groups??[],n.groups??[],l=>l.modelId);for(const l of r.removed)o.push({kind:"group.remove",casUnit:"logical",groupRef:l.modelId});for(const l of r.added)o.push({kind:"group.add",casUnit:"logical",groupRef:l.modelId,value:vl(l)});for(const{cur:l,tgt:s}of r.common){const c=lo(l,s,mb);c&&o.push({kind:"group.update",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,patch:c});const d=cb(l.memberEntityRefs??[],s.memberEntityRefs??[]);for(const u of d.removed)o.push({kind:"group.removeMember",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,entityRef:u});for(const u of d.added)o.push({kind:"group.addMember",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,entityRef:u})}}function wa(e,n,o,i,a,r,l){const s=so(e,n,o);for(const c of s.removed)l.push({kind:a,casUnit:"layout",[r]:o(c),value:void 0});for(const c of s.added)l.push({kind:i,casUnit:"layout",[r]:o(c),value:c});for(const{cur:c,tgt:d}of s.common)ro(c,d)||(l.push({kind:a,casUnit:"layout",[r]:o(c),value:void 0}),l.push({kind:i,casUnit:"layout",[r]:o(d),value:d}))}function gb(e,n,o){wa(e.entityLayouts??[],n.entityLayouts??[],i=>i.entityRef,"entityLayout.add","entityLayout.remove","entityRef",o),wa(e.associationLayouts??[],n.associationLayouts??[],i=>i.associationRef,"associationLayout.add","associationLayout.remove","associationRef",o),wa(e.groupLayouts??[],n.groupLayouts??[],i=>i.groupRef,"groupLayout.add","groupLayout.remove","groupRef",o),wa(e.notes??[],n.notes??[],i=>i.modelId,"note.add","note.remove","noteRef",o)}function bb(e,n){const o=[];return yb(e.logical,n.logical,o),gb(e.layout,n.layout,o),o}function _b(e){if(e.groupRef!=null)return"group";if(e.associationRef!=null)return e.end!=null?"associationEnd":"association";if(e.entityRef!=null&&e.attributeRef!=null)return"attribute";if(e.entityRef!=null&&e.operationRef!=null)return"operation";if(e.entityRef!=null&&e.indexRef!=null)return"index";if(e.entityRef!=null)return"entity";throw new Error("projectFieldAudit: 대상 로케이터가 비었습니다(entityRef/associationRef/groupRef 중 하나 필요).")}const kb={entity:new Set(["attributes","operations","indexes","rev","modelId"]),association:new Set(["end1","end2","rev","modelId"]),group:new Set(["memberEntityRefs","rev","modelId"]),attribute:new Set(["modelId"]),operation:new Set(["modelId"]),index:new Set(["modelId"]),associationEnd:new Set([])};class Eb{constructor(n){st(this,"out",[]);st(this,"last",new Map);this.fieldFilter=n}set(n,o,i){if(this.fieldFilter!=null&&o!==this.fieldFilter)return;const a=this.last.get(o);this.out.push({...bi(n),field:o,value:i,...this.last.has(o)?{oldValue:a}:{}}),this.last.set(o,i)}remove(n,o){if(o!=null){if(this.fieldFilter!=null&&o!==this.fieldFilter)return;this.out.push({...bi(n),field:o,value:void 0,removed:!0,...this.last.has(o)?{oldValue:this.last.get(o)}:{}}),this.last.delete(o);return}const i=this.fieldFilter!=null?[this.fieldFilter]:[...this.last.keys()];for(const a of i){if(!this.last.has(a)){this.out.push({...bi(n),field:a,value:void 0,removed:!0});continue}this.out.push({...bi(n),field:a,value:void 0,removed:!0,oldValue:this.last.get(a)}),this.last.delete(a)}}member(n,o,i){const a="memberEntityRefs";this.fieldFilter!=null&&a!==this.fieldFilter||this.out.push({...bi(n),field:a,value:o,...i?{removed:!0}:{}})}result(){return this.out}}function bi(e){const n={seq:e.seq};return e.ts!==void 0&&(n.ts=e.ts),e.origin!==void 0&&(n.origin=e.origin),e.author!==void 0&&(n.author=e.author),e.kind!==void 0&&(n.kind=e.kind),e.restoredFromSeq!==void 0&&(n.restoredFromSeq=e.restoredFromSeq),n}function rn(e,n,o,i){if(o==null||typeof o!="object")return;const a=kb[i];for(const[r,l]of Object.entries(o))a.has(r)||e.set(n,r,l)}function co(e,n,o){if(!(o==null||typeof o!="object"))for(const[i,a]of Object.entries(o))e.set(n,i,a)}function Cl(e,n){if(Array.isArray(e))return e.find(o=>o.modelId===n)}function Ln(e,n){var r,l,s,c,d,u,m,p;const o=_b(n),i=new Eb(n.field),a=[...e].sort((f,h)=>f.seq-h.seq);for(const f of a)for(const h of f.ops)switch(o){case"entity":if(h.entityRef!==n.entityRef)break;h.kind==="entity.add"?rn(i,f,h.value,"entity"):h.kind==="entity.update"?co(i,f,h.patch):h.kind==="entity.remove"&&i.remove(f);break;case"attribute":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((r=h.value)==null?void 0:r.attributes,n.attributeRef);g&&rn(i,f,g,"attribute")}else h.kind==="attribute.add"&&((l=h.value)==null?void 0:l.modelId)===n.attributeRef?rn(i,f,h.value,"attribute"):h.kind==="attribute.update"&&h.attributeRef===n.attributeRef?co(i,f,h.patch):(h.kind==="attribute.remove"&&h.attributeRef===n.attributeRef||h.kind==="entity.remove")&&i.remove(f);break;case"operation":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((s=h.value)==null?void 0:s.operations,n.operationRef);g&&rn(i,f,g,"operation")}else h.kind==="operation.add"&&((c=h.value)==null?void 0:c.modelId)===n.operationRef?rn(i,f,h.value,"operation"):h.kind==="operation.update"&&h.operationRef===n.operationRef?co(i,f,h.patch):(h.kind==="operation.remove"&&h.operationRef===n.operationRef||h.kind==="entity.remove")&&i.remove(f);break;case"index":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const g=Cl((d=h.value)==null?void 0:d.indexes,n.indexRef);g&&rn(i,f,g,"index")}else h.kind==="index.add"&&((u=h.value)==null?void 0:u.modelId)===n.indexRef?rn(i,f,h.value,"index"):h.kind==="index.update"&&h.indexRef===n.indexRef?co(i,f,h.patch):(h.kind==="index.remove"&&h.indexRef===n.indexRef||h.kind==="entity.remove")&&i.remove(f);break;case"association":if(h.associationRef!==n.associationRef)break;h.kind==="association.add"?rn(i,f,h.value,"association"):h.kind==="association.update"?co(i,f,h.patch):h.kind==="association.remove"&&i.remove(f);break;case"associationEnd":if(h.associationRef!==n.associationRef)break;if(h.kind==="association.add"){const g=(m=h.value)==null?void 0:m[n.end];rn(i,f,g,"associationEnd")}else h.kind==="associationEnd.update"&&h.end===n.end?co(i,f,h.patch):h.kind==="association.remove"&&i.remove(f);break;case"group":if(h.groupRef!==n.groupRef)break;if(h.kind==="group.add"){rn(i,f,h.value,"group");const g=(p=h.value)==null?void 0:p.memberEntityRefs;if(Array.isArray(g))for(const b of g)i.member(f,b,!1)}else h.kind==="group.update"?co(i,f,h.patch):h.kind==="group.remove"?i.remove(f):h.kind==="group.addMember"&&h.entityRef!=null?i.member(f,h.entityRef,!1):h.kind==="group.removeMember"&&h.entityRef!=null&&i.member(f,h.entityRef,!0);break}return i.result()}const rt={subject:null,existence:null,fieldAudit:!1,note:"레이아웃 축(LWW) — 감사·복원 diff는 논리 축 전용(AA-5: layout/note는 의도적 범위 밖)"},Nb={"entity.add":{subject:"entity",existence:"add",fieldAudit:!0},"entity.update":{subject:"entity",existence:null,fieldAudit:!0},"entity.remove":{subject:"entity",existence:"remove",fieldAudit:!0},"attribute.add":{subject:"attribute",existence:"add",fieldAudit:!0},"attribute.update":{subject:"attribute",existence:null,fieldAudit:!0},"attribute.remove":{subject:"attribute",existence:"remove",fieldAudit:!0},"operation.add":{subject:"operation",existence:"add",fieldAudit:!0},"operation.update":{subject:"operation",existence:null,fieldAudit:!0},"operation.remove":{subject:"operation",existence:"remove",fieldAudit:!0},"index.add":{subject:"index",existence:"add",fieldAudit:!0},"index.update":{subject:"index",existence:null,fieldAudit:!0},"index.remove":{subject:"index",existence:"remove",fieldAudit:!0},"attribute.reorder":{subject:null,existence:null,fieldAudit:!1,note:"과거 어휘(호스트 지원·lib 미방출). 컬렉션 순서 축이라 subject 단위 필드 변경으로 표현 안 됨"},"operation.reorder":{subject:null,existence:null,fieldAudit:!1,note:"과거 어휘(호스트 지원·lib 미방출). attribute.reorder와 동형"},"association.add":{subject:"association",existence:"add",fieldAudit:!0},"association.update":{subject:"association",existence:null,fieldAudit:!0},"association.remove":{subject:"association",existence:"remove",fieldAudit:!0},"associationEnd.update":{subject:"associationEnd",existence:null,fieldAudit:!0},"group.add":{subject:"group",existence:"add",fieldAudit:!0},"group.update":{subject:"group",existence:null,fieldAudit:!0},"group.remove":{subject:"group",existence:"remove",fieldAudit:!0},"group.addMember":{subject:"group",existence:null,fieldAudit:!0},"group.removeMember":{subject:"group",existence:null,fieldAudit:!0},"entityLayout.add":rt,"entityLayout.remove":rt,"entityLayout.move":rt,"entityLayout.resize":rt,"entityLayout.setCollapsed":rt,"entityLayout.setLocked":rt,"entityLayout.setStyle":rt,"entityLayout.setAttrStyle":rt,"entityLayout.setOpStyle":rt,"groupLayout.add":rt,"groupLayout.remove":rt,"groupLayout.move":rt,"groupLayout.resize":rt,"groupLayout.setLocked":rt,"groupLayout.setStyle":rt,"groupLayout.addNoteMember":rt,"groupLayout.removeNoteMember":rt,"associationLayout.add":rt,"associationLayout.remove":rt,"associationLayout.setWaypoints":rt,"note.add":rt,"note.remove":rt,"note.move":rt,"note.resize":rt,"note.setMemo":rt,"note.setStyle":rt,"noteConnection.add":rt,"noteConnection.remove":rt,"noteConnection.setWaypoints":rt},jt=e=>typeof e=="string"?e:void 0,wb=e=>{var n;return jt((n=e.value)==null?void 0:n.modelId)};function xd(e){return jt(e.containerRef)??jt(e.entityRef)}function Sl(e,n,o,i){var l;const a=(l=e.value)==null?void 0:l[n];if(!Array.isArray(a))return[];const r=[];for(const s of a){const c=jt(s.modelId);c&&r.push({subject:{kind:o,ref:c,...i?{entityRef:i}:{}},existence:"add",inline:!0})}return r}function xl(e){const n=Nb[e.kind];if(!n||!n.subject)return[];const o=e,i=n.existence??void 0;switch(n.subject){case"entity":{const a=jt(o.entityRef);if(!a)return[];const r={subject:{kind:"entity",ref:a},...i?{existence:i}:{}};return e.kind!=="entity.add"?[r]:[r,...Sl(o,"attributes","attribute",a),...Sl(o,"operations","operation",a),...Sl(o,"indexes","index",a)]}case"attribute":case"operation":case"index":{const a=n.subject,r=xd(o),l={attribute:"attributeRef",operation:"operationRef",index:"indexRef"}[a],s=i==="add"?wb(o):jt(o[l]);return s?[{subject:{kind:a,ref:s,...r?{entityRef:r}:{}},...i?{existence:i}:{}}]:[]}case"association":case"associationEnd":{const a=jt(o.associationRef);if(!a)return[];const r=o.end==="end1"||o.end==="end2"?o.end:void 0;return[{subject:{kind:n.subject,ref:a,...r?{end:r}:{}},...i?{existence:i}:{}}]}case"group":{const a=jt(o.groupRef);return a?[{subject:{kind:"group",ref:a},...i?{existence:i}:{}}]:[]}}}function Ib(e){const n=e,o=e.kind;if(o.startsWith("entity.")){const i=jt(n.entityRef);return i?{kind:"entity",ref:i}:null}if(o.startsWith("attribute.")||o.startsWith("operation.")||o.startsWith("index.")){const i=xd(n);return i?{kind:"entity",ref:i}:null}if(o.startsWith("associationEnd.")||o.startsWith("association.")){const i=jt(n.associationRef);return i?{kind:"association",ref:i}:null}if(o.startsWith("group.")){const i=jt(n.groupRef);return i?{kind:"group",ref:i}:null}return null}function vb(e,n){const o=e;return o.entityRef===n||o.containerRef===n}function Cb(e,n){const o=new Set,i=new Set,a=new Set,r={attribute:o,operation:i,index:a};for(const l of e)for(const s of l.ops)for(const{subject:c}of xl(s))c.kind==="entity"||c.entityRef!==n||c.kind in r&&r[c.kind].add(c.ref);return{attributes:o,operations:i,indexes:a}}function Ia(e,n){return e.map(o=>({...o,subject:n}))}function Rd(e,n){const o=e.filter(s=>s.ops.some(c=>vb(c,n))),{attributes:i,operations:a,indexes:r}=Cb(o,n),l=[...Ia(Ln(o,{entityRef:n}),{kind:"entity",ref:n})];for(const s of i)l.push(...Ia(Ln(o,{entityRef:n,attributeRef:s}),{kind:"attribute",ref:s}));for(const s of a)l.push(...Ia(Ln(o,{entityRef:n,operationRef:s}),{kind:"operation",ref:s}));for(const s of r)l.push(...Ia(Ln(o,{entityRef:n,indexRef:s}),{kind:"index",ref:s}));return l.map((s,c)=>({e:s,i:c})).sort((s,c)=>s.e.seq-c.e.seq||s.i-c.i).map(({e:s})=>s)}function Rl(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Sb(e){const n=new Set;for(const o of e)for(const i of o.ops)for(const a of xl(i))a.existence==="add"&&n.add(Rl(a.subject));return n}function xb(e){const n=new Set,o=new Set,i=new Set,a={entity:n,association:o,group:i};for(const r of e)for(const l of r.ops){const s=Ib(l);s&&a[s.kind].add(s.ref)}return{entities:n,associations:o,groups:i}}function Rb(e){const{entities:n,associations:o,groups:i}=xb(e),a=[];for(const r of n)for(const l of Rd(e,r))a.push({...l,subject:{...l.subject,entityRef:r}});for(const r of o){for(const l of Ln(e,{associationRef:r}))a.push({...l,subject:{kind:"association",ref:r}});for(const l of["end1","end2"])for(const s of Ln(e,{associationRef:r,end:l}))a.push({...s,subject:{kind:"associationEnd",ref:r,end:l}})}for(const r of i)for(const l of Ln(e,{groupRef:r}))a.push({...l,subject:{kind:"group",ref:r}});return a}function Al(e){const n=Rb(e),o=Sb(e),i=new Map;for(const l of n){const s=Rl(l.subject),c=i.get(s);(c===void 0||l.seq<c)&&i.set(s,l.seq)}const a=new Map;for(const l of n){let s=a.get(l.seq);s||(s={meta:l,subjects:new Map},a.set(l.seq,s));const c=Rl(l.subject);let d=s.subjects.get(c);if(!d){const u=l.removed?"remove":i.get(c)===l.seq&&o.has(c)?"add":"update";d={subject:l.subject,verb:u,fields:[]},s.subjects.set(c,d)}l.removed?d.verb="remove":d.fields.push({field:l.field,value:l.value,...l.oldValue!==void 0?{oldValue:l.oldValue}:{}})}const r=[];for(const[l,s]of a){const c=s.meta;r.push({seq:l,...c.ts!==void 0?{ts:c.ts}:{},...c.origin!==void 0?{origin:c.origin}:{},...c.author!==void 0?{author:c.author}:{},...c.kind!==void 0?{kind:c.kind}:{},...c.restoredFromSeq!==void 0?{restoredFromSeq:c.restoredFromSeq}:{},actions:[...s.subjects.values()]})}return r.sort((l,s)=>s.seq-l.seq)}function Ad(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Ab(e,n,o){const i=[];for(const a of e)if(!(a.seq<=n||a.seq>o))for(const r of a.ops)for(const l of xl(r)){if(!l.existence||l.inline)continue;const s=l.subject;$b.has(s.kind)&&!s.entityRef||i.push({seq:a.seq,subject:s,verb:l.existence,fields:[]})}return i}const $b=new Set(["attribute","operation","index"]);function $l(e,n){const{fromSeq:o}=n,i=Al(e);let a=o;for(const m of e)m.seq>a&&(a=m.seq);const r=n.toSeq??a,l=i.filter(m=>m.seq>o&&m.seq<=r).reverse(),s=new Map,c=m=>{const p=Ad(m.subject);let f=s.get(p);f||(f={subject:m.subject,evs:[]},s.set(p,f)),f.evs.push(m)};for(const m of l)for(const p of m.actions)c({seq:m.seq,subject:p.subject,verb:p.verb,fields:p.fields});for(const m of Ab(e,o,r)){const p=s.get(Ad(m.subject));p!=null&&p.evs.some(f=>f.seq===m.seq)||c(m)}const d=[],u=new Set;for(const m of s.values()){m.evs.sort((f,h)=>f.seq-h.seq);const p=m.evs[m.evs.length-1];m.subject.kind==="entity"&&p.verb==="remove"&&u.add(m.subject.ref)}for(const m of s.values()){const p=m.evs[0].verb==="add",f=m.evs[m.evs.length-1].verb==="remove";if(m.subject.kind!=="entity"&&m.subject.entityRef&&u.has(m.subject.entityRef)||p&&f)continue;const h=new Map;let g=null;for(const _ of m.evs){_.verb==="add"&&g!==null&&g!=="add"&&h.clear(),g=_.verb;for(const E of _.fields){const N=h.get(E.field);N?N.lastValue=E.value:h.set(E.field,{firstOld:E.oldValue,hasOld:E.oldValue!==void 0,lastValue:E.value})}}if(f){d.push({subject:m.subject,verb:"removed",fields:[]});continue}if(p){const _=[];for(const[E,N]of h)_.push({field:E,value:N.lastValue});d.push({subject:m.subject,verb:"added",fields:_});continue}const b=[];for(const[_,E]of h)E.hasOld&&ro(E.firstOld,E.lastValue)||b.push({field:_,value:E.lastValue,...E.hasOld?{oldValue:E.firstOld}:{}});b.length!==0&&d.push({subject:m.subject,verb:"modified",fields:b})}return{fromSeq:o,toSeq:r,entries:d}}function $d(e){const n=new Map,o=i=>{let a=n.get(i);return a||(a={verb:"modified",changedAttributeIds:new Set,changedOperationIds:new Set},n.set(i,a)),a};for(const i of e.entries){const a=i.subject;if(a.kind==="entity"){if(i.verb==="removed")continue;o(a.ref).verb=i.verb}else if((a.kind==="attribute"||a.kind==="operation"||a.kind==="index")&&a.entityRef){const r=o(a.entityRef);i.verb!=="removed"&&(a.kind==="attribute"?r.changedAttributeIds.add(a.ref):a.kind==="operation"&&r.changedOperationIds.add(a.ref))}}return n}class Tl{constructor(n){st(this,"undoStack",[]);st(this,"redoStack",[]);st(this,"savePoint",null);st(this,"listeners",new Set);st(this,"commandListeners",new Set);st(this,"coalesceSealed",!1);this.state=n}execute(n){n.apply(this.state);const o=this.undoStack.at(-1),i=!this.coalesceSealed&&n.coalesceKey!=null&&!!o&&o.coalesceKey===n.coalesceKey;this.coalesceSealed=!1,i?(n.invert=o.invert,this.undoStack[this.undoStack.length-1]=n):this.undoStack.push(n),this.redoStack=[],this.emitCommand(n,"do",i),this.emit()}undo(){const n=this.undoStack.pop();n&&(n.invert(this.state),this.redoStack.push(n),this.emitCommand(n,"undo",!1),this.emit())}redo(){const n=this.redoStack.pop();n&&(n.apply(this.state),this.undoStack.push(n),this.emitCommand(n,"redo",!1),this.emit())}sealCoalesce(){this.coalesceSealed=!0}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}markSavePoint(){this.savePoint=this.undoStack.at(-1)??null,this.sealCoalesce(),this.emit()}get isDirty(){return(this.undoStack.at(-1)??null)!==this.savePoint}onChange(n){return this.listeners.add(n),()=>this.listeners.delete(n)}onCommand(n){return this.commandListeners.add(n),()=>this.commandListeners.delete(n)}emit(){for(const n of this.listeners)n()}emitCommand(n,o,i){for(const a of this.commandListeners)a(n,o,i)}}function Bt(e){const n={};for(const[o,i]of Object.entries(e))n[o]=i===void 0?null:i;return n}function Td(e,n){return e.logical.entities.findIndex(o=>o.modelId===n)}function Nt(e,n){return e.layout.entityLayouts.findIndex(o=>o.entityRef===n)}function Kt(e,n){return e.layout.associationLayouts.find(o=>o.associationRef===n)}function dt(e,n){const o=e.logical.entities.find(i=>i.modelId===n);if(!o)throw new Error(`엔티티 없음: ${n}`);return o}function En(e,n,o){var i,a;return(a=(i=e.layout.notes.find(r=>r.modelId===n))==null?void 0:i.connections)==null?void 0:a.find(r=>r.targetRef===o)}function va(e,n,o){return{label:`엔티티 추가: ${e.name}`,apply(i){i.logical.entities.push(e),i.layout.entityLayouts.push({entityRef:e.modelId,geo:n,...o})},invert(i){const a=Td(i,e.modelId);a>=0&&i.logical.entities.splice(a,1);const r=Nt(i,e.modelId);r>=0&&i.layout.entityLayouts.splice(r,1)},emitOps(){const i={kind:"entity.add",casUnit:"logical",entityRef:e.modelId,value:e},a={kind:"entityLayout.add",casUnit:"layout",entityRef:e.modelId,value:{entityRef:e.modelId,geo:n,...o},incidental:!0};return{forward:[i,a],invert:[{kind:"entityLayout.remove",casUnit:"layout",entityRef:e.modelId,incidental:!0},{kind:"entity.remove",casUnit:"logical",entityRef:e.modelId}]}}}}function Md(e){let n=null;const o=i=>i.end1.entityRef===e||i.end2.entityRef===e;return{label:"엔티티 삭제",apply(i){const a=Td(i,e);if(a<0)throw new Error(`엔티티 없음: ${e}`);const r=Nt(i,e),l=[];i.logical.associations.forEach((u,m)=>{o(u)&&l.push({item:u,index:m})});const s=new Set(l.map(u=>u.item.modelId)),c=[];i.layout.associationLayouts.forEach((u,m)=>{s.has(u.associationRef)&&c.push({item:u,index:m})});const d=[];i.logical.groups.forEach(u=>{const m=u.memberEntityRefs.indexOf(e);m>=0&&d.push({groupId:u.modelId,index:m})}),n={entity:{item:i.logical.entities[a],index:a},entityLayout:r>=0?{item:i.layout.entityLayouts[r],index:r}:void 0,assocs:l,assocLayouts:c,groupMemberships:d},[...c].sort((u,m)=>m.index-u.index).forEach(u=>i.layout.associationLayouts.splice(u.index,1)),[...l].sort((u,m)=>m.index-u.index).forEach(u=>i.logical.associations.splice(u.index,1));for(const u of d){const m=i.logical.groups.find(p=>p.modelId===u.groupId);m==null||m.memberEntityRefs.splice(u.index,1)}r>=0&&i.layout.entityLayouts.splice(r,1),i.logical.entities.splice(a,1)},invert(i){if(n){i.logical.entities.splice(n.entity.index,0,n.entity.item),n.entityLayout&&i.layout.entityLayouts.splice(n.entityLayout.index,0,n.entityLayout.item),[...n.assocs].sort((a,r)=>a.index-r.index).forEach(a=>i.logical.associations.splice(a.index,0,a.item)),[...n.assocLayouts].sort((a,r)=>a.index-r.index).forEach(a=>i.layout.associationLayouts.splice(a.index,0,a.item));for(const a of n.groupMemberships){const r=i.logical.groups.find(l=>l.modelId===a.groupId);r==null||r.memberEntityRefs.splice(a.index,0,e)}}},emitOps(){if(!n)return{forward:[],invert:[]};const i=[],a=[];for(const r of n.assocs)i.push({kind:"association.remove",casUnit:"logical",associationRef:r.item.modelId}),a.push({kind:"association.add",casUnit:"logical",associationRef:r.item.modelId,value:r.item});for(const r of n.assocLayouts)i.push({kind:"associationLayout.remove",casUnit:"layout",associationRef:r.item.associationRef,incidental:!0}),a.push({kind:"associationLayout.add",casUnit:"layout",associationRef:r.item.associationRef,value:r.item,incidental:!0});for(const r of n.groupMemberships)i.push({kind:"group.removeMember",casUnit:"logical",containerRef:r.groupId,groupRef:r.groupId,entityRef:e}),a.push({kind:"group.addMember",casUnit:"logical",containerRef:r.groupId,groupRef:r.groupId,entityRef:e});return n.entityLayout&&(i.push({kind:"entityLayout.remove",casUnit:"layout",entityRef:e,incidental:!0}),a.push({kind:"entityLayout.add",casUnit:"layout",entityRef:e,value:n.entityLayout.item,incidental:!0})),i.push({kind:"entity.remove",casUnit:"logical",entityRef:e}),a.push({kind:"entity.add",casUnit:"logical",entityRef:e,value:n.entity.item}),{forward:i,invert:a.reverse()}}}}function Ml(e,n){const o={};return{label:"엔티티 수정",apply(i){const a=dt(i,e);for(const r of Object.keys(n))o[r]=a[r];Object.assign(a,n)},invert(i){Object.assign(dt(i,e),o)},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:Bt(n)}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:Bt(o)}]}}}}function Vd(e,n){let o="";return{label:`엔티티 이름 변경: ${n}`,apply(i){const a=dt(i,e);o=a.name,a.name=n},invert(i){dt(i,e).name=o},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:{name:n}}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:{name:o}}]}}}}function Fo(e,n){let o=null;return{label:"엔티티 이동",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a].geo;o={...r.location},r.location={...n}},invert(i){const a=Nt(i,e);a>=0&&o&&(i.layout.entityLayouts[a].geo.location=o)},emitOps(){const i=a=>({kind:"entityLayout.move",casUnit:"layout",entityRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function Bd(e,n){let o=null;return{label:"엔티티 크기 변경",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a].geo;o={...r.size},r.size={...n}},invert(i){const a=Nt(i,e);a>=0&&o&&(i.layout.entityLayouts[a].geo.size=o)},emitOps(){const i=a=>({kind:"entityLayout.resize",casUnit:"layout",entityRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function _i(e,n){const o={...(e==null?void 0:e.properties)??{}};return n?o.swatch=n:delete o.swatch,Object.keys(o).length?{properties:o}:void 0}function Dd(e,n){let o;return{label:"엔티티 색상 변경",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.style,r.style=_i(r.style,n)},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].style=o)},emitOps(i){const a=Nt(i,e),r=a>=0?i.layout.entityLayouts[a].style:void 0,l=s=>({kind:"entityLayout.setStyle",casUnit:"layout",entityRef:e,value:{style:s}});return{forward:[l(r)],invert:[l(o)]}}}}function Od(e,n){let o;return{label:n?"엔티티 접기":"엔티티 펼치기",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.collapsed,r.collapsed=n},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].collapsed=o)},emitOps(){const i=a=>({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:e,value:{collapsed:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Ld(e,n){let o;return{label:n?"엔티티 잠금":"엔티티 잠금 해제",apply(i){const a=Nt(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.locked,r.locked=n},invert(i){const a=Nt(i,e);a>=0&&(i.layout.entityLayouts[a].locked=o)},emitOps(){const i=a=>({kind:"entityLayout.setLocked",casUnit:"layout",entityRef:e,value:{locked:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Vl(e){let n=[];return{label:e?"모두 접기":"모두 펼치기",apply(o){n=o.layout.entityLayouts.map(i=>i.collapsed);for(const i of o.layout.entityLayouts)i.collapsed=e},invert(o){o.layout.entityLayouts.forEach((i,a)=>{i.collapsed=n[a]})},emitOps(o){const i=[],a=[];return o.layout.entityLayouts.forEach((r,l)=>{i.push({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:r.entityRef,value:{collapsed:e}}),a.push({kind:"entityLayout.setCollapsed",casUnit:"layout",entityRef:r.entityRef,value:{collapsed:n[l]}})}),{forward:i,invert:a}}}}function Ca(e,n,o){let i;return{label:"속성 색상 변경",apply(a){const r=Nt(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.attributeStyles;const s={...l.attributeStyles},c=_i(s[n],o);c?s[n]=c:delete s[n],l.attributeStyles=Object.keys(s).length?s:void 0},invert(a){const r=Nt(a,e);r>=0&&(a.layout.entityLayouts[r].attributeStyles=i)},emitOps(a){const r=Nt(a,e),l=r>=0?a.layout.entityLayouts[r].attributeStyles:void 0,s=c=>({kind:"entityLayout.setAttrStyle",casUnit:"layout",entityRef:e,value:{attributeStyles:c}});return{forward:[s(l)],invert:[s(i)]}}}}function Sa(e,n,o){return{label:"그룹 추가",apply(i){i.logical.groups.push(e),i.layout.groupLayouts.push({groupRef:e.modelId,geo:n,...o})},invert(i){const a=i.logical.groups.findIndex(l=>l.modelId===e.modelId);a>=0&&i.logical.groups.splice(a,1);const r=i.layout.groupLayouts.findIndex(l=>l.groupRef===e.modelId);r>=0&&i.layout.groupLayouts.splice(r,1)},emitOps(){const i={kind:"group.add",casUnit:"logical",groupRef:e.modelId,value:e},a={kind:"groupLayout.add",casUnit:"layout",groupRef:e.modelId,value:{groupRef:e.modelId,geo:n,...o},incidental:!0};return{forward:[i,a],invert:[{kind:"groupLayout.remove",casUnit:"layout",groupRef:e.modelId,incidental:!0},{kind:"group.remove",casUnit:"logical",groupRef:e.modelId}]}}}}function Pd(e,n){const o={},i=a=>{const r=a.logical.groups.find(l=>l.modelId===e);if(!r)throw new Error(`그룹 없음: ${e}`);return r};return{label:"그룹 수정",apply(a){const r=i(a);for(const l of Object.keys(n))o[l]=r[l];Object.assign(r,n)},invert(a){Object.assign(i(a),o)},emitOps(){return{forward:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:Bt(n)}],invert:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:Bt(o)}]}}}}function zd(e){let n=null;return{label:"그룹 해제",apply(o){const i=o.logical.groups.findIndex(r=>r.modelId===e);if(i<0)throw new Error(`그룹 없음: ${e}`);const a=o.layout.groupLayouts.findIndex(r=>r.groupRef===e);n={group:{item:o.logical.groups[i],index:i},layout:a>=0?{item:o.layout.groupLayouts[a],index:a}:void 0},a>=0&&o.layout.groupLayouts.splice(a,1),o.logical.groups.splice(i,1)},invert(o){n&&(o.logical.groups.splice(n.group.index,0,n.group.item),n.layout&&o.layout.groupLayouts.splice(n.layout.index,0,n.layout.item))},emitOps(){if(!n)return{forward:[],invert:[]};const o=[],i=[];return n.layout&&(o.push({kind:"groupLayout.remove",casUnit:"layout",groupRef:e,incidental:!0}),i.push({kind:"groupLayout.add",casUnit:"layout",groupRef:e,value:n.layout.item,incidental:!0})),o.push({kind:"group.remove",casUnit:"logical",groupRef:e}),i.push({kind:"group.add",casUnit:"logical",groupRef:e,value:n.group.item}),{forward:o,invert:i.reverse()}}}}function Fd(e,n){let o=!1;const i=a=>a.logical.groups.find(r=>r.modelId===e);return{label:"그룹에 편입",apply(a){const r=i(a);r&&!r.memberEntityRefs.includes(n)&&(r.memberEntityRefs.push(n),o=!0)},invert(a){if(!o)return;const r=i(a),l=(r==null?void 0:r.memberEntityRefs.indexOf(n))??-1;l>=0&&r.memberEntityRefs.splice(l,1)},emitOps(){return o?{forward:[{kind:"group.addMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}],invert:[{kind:"group.removeMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}]}:{forward:[],invert:[]}}}}function xa(e,n){let o=-1;const i=a=>a.logical.groups.find(r=>r.modelId===e);return{label:"그룹에서 제외",apply(a){const r=i(a);o=(r==null?void 0:r.memberEntityRefs.indexOf(n))??-1,o>=0&&r.memberEntityRefs.splice(o,1)},invert(a){var r;o<0||(r=i(a))==null||r.memberEntityRefs.splice(o,0,n)},emitOps(){return o<0?{forward:[],invert:[]}:{forward:[{kind:"group.removeMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}],invert:[{kind:"group.addMember",casUnit:"logical",containerRef:e,groupRef:e,entityRef:n}]}}}}function Ud(e,n){let o=null;return{label:"그룹 이동",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o={...a.geo.location},a.geo.location={...n}},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&o&&(a.geo.location=o)},emitOps(){const i=a=>({kind:"groupLayout.move",casUnit:"layout",groupRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function Hd(e,n){let o=null;return{label:"그룹 크기 변경",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o={...a.geo.size},a.geo.size={...n}},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&o&&(a.geo.size=o)},emitOps(){const i=a=>({kind:"groupLayout.resize",casUnit:"layout",groupRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function jd(e,n){let o;return{label:"그룹 색상 변경",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o=a.style,a.style=_i(a.style,n)},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&(a.style=o)},emitOps(i){const a=i.layout.groupLayouts.find(l=>l.groupRef===e),r=l=>({kind:"groupLayout.setStyle",casUnit:"layout",groupRef:e,value:{style:l}});return{forward:[r(a==null?void 0:a.style)],invert:[r(o)]}}}}function Kd(e,n){let o;return{label:n?"그룹 잠금":"그룹 잠금 해제",apply(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);if(!a)throw new Error(`그룹 레이아웃 없음: ${e}`);o=a.locked,a.locked=n},invert(i){const a=i.layout.groupLayouts.find(r=>r.groupRef===e);a&&(a.locked=o)},emitOps(){const i=a=>({kind:"groupLayout.setLocked",casUnit:"layout",groupRef:e,value:{locked:a}});return{forward:[i(n)],invert:[i(o)]}}}}function Gt(e,n){return{label:`속성 추가: ${n.name}`,apply(o){dt(o,e).attributes.push(n)},invert(o){const i=dt(o,e),a=i.attributes.findIndex(r=>r.modelId===n.modelId);a>=0&&i.attributes.splice(a,1)},emitOps(){return{forward:[{kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n.modelId}]}}}}function Yt(e,n,o){const i={},a=r=>{const l=dt(r,e).attributes.find(s=>s.modelId===n);if(!l)throw new Error(`속성 없음: ${n}`);return l};return{label:"속성 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:Bt(o)}],invert:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:Bt(i)}]}}}}function Gd(e,n){let o=null;return{label:"속성 삭제",apply(i){const a=dt(i,e),r=a.attributes.findIndex(l=>l.modelId===n);if(r<0)throw new Error(`속성 없음: ${n}`);o={item:a.attributes[r],index:r},a.attributes.splice(r,1)},invert(i){o&&dt(i,e).attributes.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"attribute.remove",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n}],invert:[{kind:"attribute.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}function Yd(e,n,o,i,a){const r=new Map(a.map(c=>[c.modelId,c.order])),l=[],s=[];for(const c of i){const d=r.get(c.modelId);if(d===c.order)continue;const u=n==="attributeRef"?{attributeRef:c.modelId}:{operationRef:c.modelId};l.push({kind:e,casUnit:"logical",containerRef:o,entityRef:o,...u,patch:{order:c.order}}),s.push({kind:e,casUnit:"logical",containerRef:o,entityRef:o,...u,patch:{order:d??c.order}})}return{forward:l,invert:s}}function Bl(e,n,o){let i=null;return{label:"속성 재정렬",apply(a){const r=dt(a,e);i=r.attributes.map(s=>({...s}));const l=wl([...r.attributes].sort((s,c)=>s.order-c.order),n,o);r.attributes.splice(0,r.attributes.length,...l),r.attributes.forEach((s,c)=>s.order=c)},invert(a){i&&dt(a,e).attributes.splice(0,1/0,...i)},emitOps(a){const r=dt(a,e).attributes;return Yd("attribute.update","attributeRef",e,r,i??[])}}}function qd(e,n){let o=!1;return{label:`메서드 추가: ${n.name}`,apply(i){const a=dt(i,e);a.operations||(a.operations=[],o=!0),a.operations.push(n)},invert(i){var l;const a=dt(i,e),r=((l=a.operations)==null?void 0:l.findIndex(s=>s.modelId===n.modelId))??-1;r>=0&&a.operations.splice(r,1),o&&a.operations&&a.operations.length===0&&(a.operations=void 0)},emitOps(){return{forward:[{kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n.modelId}]}}}}function Wd(e,n,o){const i={},a=r=>{var s;const l=(s=dt(r,e).operations)==null?void 0:s.find(c=>c.modelId===n);if(!l)throw new Error(`메서드 없음: ${n}`);return l};return{label:"메서드 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:Bt(o)}],invert:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:Bt(i)}]}}}}function Jd(e,n){let o=null;return{label:"메서드 삭제",apply(i){var s;const a=dt(i,e),r=((s=a.operations)==null?void 0:s.findIndex(c=>c.modelId===n))??-1;if(r<0)throw new Error(`메서드 없음: ${n}`);const l=a.operations.length===1;o={item:a.operations[r],index:r,wasSole:l},a.operations.splice(r,1),l&&(a.operations=void 0)},invert(i){if(!o)return;const a=dt(i,e);a.operations||(a.operations=[]),a.operations.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"operation.remove",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n}],invert:[{kind:"operation.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}function Xd(e,n,o){let i=null;return{label:"메서드 재정렬",apply(a){const r=dt(a,e),l=r.operations??[];i=l.map(c=>({...c}));const s=wl([...l].sort((c,d)=>c.order-d.order),n,o);l.splice(0,l.length,...s),l.forEach((c,d)=>c.order=d),r.operations=l},invert(a){if(!i)return;const r=dt(a,e);r.operations&&r.operations.splice(0,1/0,...i)},emitOps(a){const r=dt(a,e).operations??[];return Yd("operation.update","operationRef",e,r,i??[])}}}function Zd(e,n,o){let i;return{label:"메서드 색상 변경",apply(a){const r=Nt(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.operationStyles;const s={...l.operationStyles},c=_i(s[n],o);c?s[n]=c:delete s[n],l.operationStyles=Object.keys(s).length?s:void 0},invert(a){const r=Nt(a,e);r>=0&&(a.layout.entityLayouts[r].operationStyles=i)},emitOps(a){const r=Nt(a,e),l=r>=0?a.layout.entityLayouts[r].operationStyles:void 0,s=c=>({kind:"entityLayout.setOpStyle",casUnit:"layout",entityRef:e,value:{operationStyles:c}});return{forward:[s(l)],invert:[s(i)]}}}}function Ra(e,n){return{label:"관계 추가",apply(o){o.logical.associations.push(e),o.layout.associationLayouts.push(n)},invert(o){const i=o.logical.associations.findIndex(r=>r.modelId===e.modelId);i>=0&&o.logical.associations.splice(i,1);const a=o.layout.associationLayouts.findIndex(r=>r.associationRef===e.modelId);a>=0&&o.layout.associationLayouts.splice(a,1)},emitOps(){const o={kind:"association.add",casUnit:"logical",associationRef:e.modelId,value:e},i={kind:"associationLayout.add",casUnit:"layout",associationRef:e.modelId,value:n,incidental:!0};return{forward:[o,i],invert:[{kind:"associationLayout.remove",casUnit:"layout",associationRef:e.modelId,incidental:!0},{kind:"association.remove",casUnit:"logical",associationRef:e.modelId}]}}}}function Qd(e){let n=null;return{label:"관계 삭제",apply(o){const i=o.logical.associations.findIndex(r=>r.modelId===e);if(i<0)throw new Error(`관계 없음: ${e}`);const a=o.layout.associationLayouts.findIndex(r=>r.associationRef===e);n={assoc:{item:o.logical.associations[i],index:i},layout:a>=0?{item:o.layout.associationLayouts[a],index:a}:void 0},a>=0&&o.layout.associationLayouts.splice(a,1),o.logical.associations.splice(i,1)},invert(o){n&&(o.logical.associations.splice(n.assoc.index,0,n.assoc.item),n.layout&&o.layout.associationLayouts.splice(n.layout.index,0,n.layout.item))},emitOps(){if(!n)return{forward:[],invert:[]};const o=[],i=[];return n.layout&&(o.push({kind:"associationLayout.remove",casUnit:"layout",associationRef:e,incidental:!0}),i.push({kind:"associationLayout.add",casUnit:"layout",associationRef:e,value:n.layout.item,incidental:!0})),o.push({kind:"association.remove",casUnit:"logical",associationRef:e}),i.push({kind:"association.add",casUnit:"logical",associationRef:e,value:n.assoc.item}),{forward:o,invert:i.reverse()}}}}function Aa(e,n){const o={},i=a=>{const r=a.logical.associations.find(l=>l.modelId===e);if(!r)throw new Error(`관계 없음: ${e}`);return r};return{label:"관계 수정",apply(a){const r=i(a);for(const l of Object.keys(n))o[l]=r[l];Object.assign(r,n)},invert(a){Object.assign(i(a),o)},emitOps(){return{forward:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:Bt(n)}],invert:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:Bt(o)}]}}}}function qt(e,n,o){const i={},a=r=>{const l=r.logical.associations.find(s=>s.modelId===e);if(!l)throw new Error(`관계 없음: ${e}`);return l[n]};return{label:"관계 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:Bt(o)}],invert:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:Bt(i)}]}}}}function eu(e,n){return{label:"인덱스 추가",apply(o){const i=dt(o,e);(i.indexes??(i.indexes=[])).push(n)},invert(o){var r;const i=dt(o,e),a=((r=i.indexes)==null?void 0:r.findIndex(l=>l.modelId===n.modelId))??-1;a>=0&&i.indexes.splice(a,1)},emitOps(){return{forward:[{kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:n}],invert:[{kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n.modelId}]}}}}function $a(e,n,o){const i={},a=r=>{var s;const l=(s=dt(r,e).indexes)==null?void 0:s.find(c=>c.modelId===n);if(!l)throw new Error(`인덱스 없음: ${n}`);return l};return{label:"인덱스 수정",apply(r){const l=a(r);for(const s of Object.keys(o))i[s]=l[s];Object.assign(l,o)},invert(r){Object.assign(a(r),i)},emitOps(){return{forward:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:Bt(o)}],invert:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:Bt(i)}]}}}}function tu(e,n){let o=null;return{label:"인덱스 삭제",apply(i){var l;const a=dt(i,e),r=((l=a.indexes)==null?void 0:l.findIndex(s=>s.modelId===n))??-1;if(r<0)throw new Error(`인덱스 없음: ${n}`);o={item:a.indexes[r],index:r},a.indexes.splice(r,1)},invert(i){o&&dt(i,e).indexes.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"index.remove",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n}],invert:[{kind:"index.add",casUnit:"logical",containerRef:e,entityRef:e,value:o.item}]}:{forward:[],invert:[]}}}}const ln=(e,n)=>({kind:"associationLayout.setWaypoints",casUnit:"layout",associationRef:e,value:{waypoints:n}}),ki=(e,n)=>{var o;return((o=Kt(e,n))==null?void 0:o.waypoints.map(i=>({...i})))??[]};function nu(e,n,o){let i=null;return{label:"waypoint 이동",coalesceKey:`waypoint:${e}`,apply(a){const r=Kt(a,e);if(!r||!r.waypoints[n])throw new Error(`waypoint 없음: ${e}[${n}]`);i={...r.waypoints[n]},r.waypoints.splice(n,1,{...o})},invert(a){const r=Kt(a,e);r&&i&&r.waypoints.splice(n,1,i)},emitOps(a){const r=ki(a,e),l=r.map((s,c)=>c===n&&i?{...i}:s);return{forward:[ln(e,r)],invert:[ln(e,l)]}}}}function ou(e,n){let o=null;return{label:"waypoint 제거",apply(i){const a=Kt(i,e);if(!a||!a.waypoints[n])throw new Error(`waypoint 없음: ${e}[${n}]`);o={...a.waypoints[n]},a.waypoints.splice(n,1)},invert(i){const a=Kt(i,e);a&&o&&a.waypoints.splice(n,0,o)},emitOps(i){const a=ki(i,e),r=a.slice();return o&&r.splice(n,0,{...o}),{forward:[ln(e,a)],invert:[ln(e,r)]}}}}function iu(e,n,o){let i=null;return{label:"waypoint 평행이동",apply(a){const r=Kt(a,e);if(!r)throw new Error(`관계 레이아웃 없음: ${e}`);i=r.waypoints.map(l=>({...l})),r.waypoints=i.map(l=>({x:l.x+n,y:l.y+o}))},invert(a){const r=Kt(a,e);r&&i&&(r.waypoints=i)},emitOps(a){return{forward:[ln(e,ki(a,e))],invert:[ln(e,i??[])]}}}}function au(e){let n=null;return{label:"꺾은선 풀기",apply(o){const i=Kt(o,e);if(!i)throw new Error(`관계 레이아웃 없음: ${e}`);n=i.waypoints.map(a=>({...a})),i.waypoints=[]},invert(o){const i=Kt(o,e);i&&n&&(i.waypoints=n)},emitOps(o){return{forward:[ln(e,ki(o,e))],invert:[ln(e,n??[])]}}}}function ru(e,n,o){return{label:"waypoint 추가",apply(i){const a=Kt(i,e);if(!a)throw new Error(`관계 레이아웃 없음: ${e}`);a.waypoints.splice(n,0,{...o})},invert(i){const a=Kt(i,e);a==null||a.waypoints.splice(n,1)},emitOps(i){const a=ki(i,e),r=a.slice();return r.splice(n,1),{forward:[ln(e,a)],invert:[ln(e,r)]}}}}function lu(e){return{label:"노트 추가",apply(n){n.layout.notes.push(e)},invert(n){const o=n.layout.notes.findIndex(i=>i.modelId===e.modelId);o>=0&&n.layout.notes.splice(o,1)},emitOps(){return{forward:[{kind:"note.add",casUnit:"layout",noteRef:e.modelId,value:e}],invert:[{kind:"note.remove",casUnit:"layout",noteRef:e.modelId}]}}}}function su(e){let n=null;return{label:"노트 삭제",apply(o){const i=o.layout.notes.findIndex(a=>a.modelId===e);if(i<0)throw new Error(`노트 없음: ${e}`);n={item:o.layout.notes[i],index:i},o.layout.notes.splice(i,1)},invert(o){n&&o.layout.notes.splice(n.index,0,n.item)},emitOps(){return n?{forward:[{kind:"note.remove",casUnit:"layout",noteRef:e}],invert:[{kind:"note.add",casUnit:"layout",noteRef:e,value:n.item}]}:{forward:[],invert:[]}}}}function Ei(e,n){let o=null;return{label:"노트 이동",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o={...a.geo.location},a.geo.location={...n}},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&o&&(a.geo.location=o)},emitOps(){const i=a=>({kind:"note.move",casUnit:"layout",noteRef:e,value:{location:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function cu(e,n){let o=null;return{label:"노트 크기 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o={...a.geo.size},a.geo.size={...n}},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&o&&(a.geo.size=o)},emitOps(){const i=a=>({kind:"note.resize",casUnit:"layout",noteRef:e,value:{size:{...a}}});return{forward:[i(n)],invert:[i(o)]}}}}function du(e,n){let o="";return{label:"노트 내용 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o=a.memo,a.memo=n},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&(a.memo=o)},emitOps(){const i=a=>({kind:"note.setMemo",casUnit:"layout",noteRef:e,value:{memo:a}});return{forward:[i(n)],invert:[i(o)]}}}}function uu(e,n){let o;return{label:"노트 색상 변경",apply(i){const a=i.layout.notes.find(r=>r.modelId===e);if(!a)throw new Error(`노트 없음: ${e}`);o=a.style,a.style=_i(a.style,n)},invert(i){const a=i.layout.notes.find(r=>r.modelId===e);a&&(a.style=o)},emitOps(i){const a=i.layout.notes.find(l=>l.modelId===e),r=l=>({kind:"note.setStyle",casUnit:"layout",noteRef:e,value:{style:l}});return{forward:[r(a==null?void 0:a.style)],invert:[r(o)]}}}}function mu(e,n){let o=!1,i=!1;const a=r=>r.layout.groupLayouts.find(l=>l.groupRef===e);return{label:"그룹에 노트 편입",apply(r){const l=a(r);l&&(l.memberNoteRefs||(l.memberNoteRefs=[],i=!0),!l.memberNoteRefs.includes(n)&&(l.memberNoteRefs.push(n),o=!0))},invert(r){if(!o)return;const l=a(r);if(!(l!=null&&l.memberNoteRefs))return;const s=l.memberNoteRefs.indexOf(n);s>=0&&l.memberNoteRefs.splice(s,1),i&&delete l.memberNoteRefs},emitOps(){return o?{forward:[{kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:e,noteRef:n}],invert:[{kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:e,noteRef:n}]}:{forward:[],invert:[]}}}}function fu(e,n){let o=-1;const i=a=>a.layout.groupLayouts.find(r=>r.groupRef===e);return{label:"그룹에서 노트 제외",apply(a){var l;const r=i(a);o=((l=r==null?void 0:r.memberNoteRefs)==null?void 0:l.indexOf(n))??-1,o>=0&&r.memberNoteRefs.splice(o,1)},invert(a){if(o<0)return;const r=i(a);r&&(r.memberNoteRefs||(r.memberNoteRefs=[]),r.memberNoteRefs.splice(o,0,n))},emitOps(){return o<0?{forward:[],invert:[]}:{forward:[{kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:e,noteRef:n}],invert:[{kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:e,noteRef:n}]}}}}const Pn=(e,n,o)=>({kind:"noteConnection.setWaypoints",casUnit:"layout",noteRef:e,targetRef:n,value:{waypoints:o}}),Ta=(e,n,o)=>{var i;return((i=En(e,n,o))==null?void 0:i.waypoints.map(a=>({...a})))??[]};function pu(e,n){let o=!1,i=!1;return{label:"노트 연결 추가",apply(a){const r=a.layout.notes.find(l=>l.modelId===e);if(!r)throw new Error(`노트 없음: ${e}`);if(r.connections||(r.connections=[],i=!0),r.connections.some(l=>l.targetRef===n)){o=!1;return}r.connections.push({targetRef:n,waypoints:[]}),o=!0},invert(a){if(!o)return;const r=a.layout.notes.find(s=>s.modelId===e);if(!(r!=null&&r.connections))return;const l=r.connections.findIndex(s=>s.targetRef===n);l>=0&&r.connections.splice(l,1),i&&delete r.connections},emitOps(){return o?{forward:[{kind:"noteConnection.add",casUnit:"layout",noteRef:e,targetRef:n,value:{targetRef:n,waypoints:[]}}],invert:[{kind:"noteConnection.remove",casUnit:"layout",noteRef:e,targetRef:n}]}:{forward:[],invert:[]}}}}function hu(e,n){let o=null;return{label:"노트 연결 삭제",apply(i){var l;const a=i.layout.notes.find(s=>s.modelId===e),r=((l=a==null?void 0:a.connections)==null?void 0:l.findIndex(s=>s.targetRef===n))??-1;if(!(a!=null&&a.connections)||r<0)throw new Error(`노트 연결 없음: ${e}→${n}`);o={item:a.connections[r],index:r},a.connections.splice(r,1)},invert(i){if(!o)return;const a=i.layout.notes.find(r=>r.modelId===e);a!=null&&a.connections&&a.connections.splice(o.index,0,o.item)},emitOps(){return o?{forward:[{kind:"noteConnection.remove",casUnit:"layout",noteRef:e,targetRef:n}],invert:[{kind:"noteConnection.add",casUnit:"layout",noteRef:e,targetRef:n,value:o.item}]}:{forward:[],invert:[]}}}}function yu(e,n,o,i){let a=null;return{label:"waypoint 이동",coalesceKey:`noteConnWaypoint:${e}:${n}`,apply(r){const l=En(r,e,n);if(!l||!l.waypoints[o])throw new Error(`waypoint 없음: ${e}→${n}[${o}]`);a={...l.waypoints[o]},l.waypoints.splice(o,1,{...i})},invert(r){const l=En(r,e,n);l&&a&&l.waypoints.splice(o,1,a)},emitOps(r){const l=Ta(r,e,n),s=l.map((c,d)=>d===o&&a?{...a}:c);return{forward:[Pn(e,n,l)],invert:[Pn(e,n,s)]}}}}function gu(e,n,o,i){return{label:"waypoint 추가",apply(a){const r=En(a,e,n);if(!r)throw new Error(`노트 연결 없음: ${e}→${n}`);r.waypoints.splice(o,0,{...i})},invert(a){const r=En(a,e,n);r==null||r.waypoints.splice(o,1)},emitOps(a){const r=Ta(a,e,n),l=r.slice();return l.splice(o,1),{forward:[Pn(e,n,r)],invert:[Pn(e,n,l)]}}}}function bu(e,n,o){let i=null;return{label:"waypoint 제거",apply(a){const r=En(a,e,n);if(!r||!r.waypoints[o])throw new Error(`waypoint 없음: ${e}→${n}[${o}]`);i={...r.waypoints[o]},r.waypoints.splice(o,1)},invert(a){const r=En(a,e,n);r&&i&&r.waypoints.splice(o,0,i)},emitOps(a){const r=Ta(a,e,n),l=r.slice();return i&&l.splice(o,0,{...i}),{forward:[Pn(e,n,r)],invert:[Pn(e,n,l)]}}}}function _u(e,n){let o=null;return{label:"꺾은선 풀기",apply(i){const a=En(i,e,n);if(!a)throw new Error(`노트 연결 없음: ${e}→${n}`);o=a.waypoints.map(r=>({...r})),a.waypoints=[]},invert(i){const a=En(i,e,n);a&&o&&(a.waypoints=o)},emitOps(i){return{forward:[Pn(e,n,Ta(i,e,n))],invert:[Pn(e,n,o??[])]}}}}function at(e,n,o){return{label:e,coalesceKey:o,apply(i){for(const a of n)a.apply(i)},invert(i){for(let a=n.length-1;a>=0;a--)n[a].invert(i)},emitOps(i){const a=n.map(r=>{if(!r.emitOps)throw new Error(`emitOps 미구현 command가 composite에 포함됨: ${r.label}`);return r.emitOps(i)});return{forward:a.flatMap(r=>r.forward),invert:a.slice().reverse().flatMap(r=>r.invert)}}}}const Tb=Object.freeze(Object.defineProperty({__proto__:null,addAssociation:Ra,addAttribute:Gt,addEntity:va,addEntityToGroup:Fd,addGroup:Sa,addIndex:eu,addNote:lu,addNoteConnection:pu,addNoteConnectionWaypoint:gu,addNoteToGroup:mu,addOperation:qd,addWaypoint:ru,clearNoteConnectionWaypoints:_u,clearWaypoints:au,composite:at,moveEntity:Fo,moveGroup:Ud,moveNote:Ei,moveNoteConnectionWaypoint:yu,moveWaypoint:nu,removeAssociation:Qd,removeAttribute:Gd,removeEntity:Md,removeEntityFromGroup:xa,removeGroup:zd,removeIndex:tu,removeNote:su,removeNoteConnection:hu,removeNoteConnectionWaypoint:bu,removeNoteFromGroup:fu,removeOperation:Jd,removeWaypoint:ou,renameEntity:Vd,reorderAttributes:Bl,reorderOperations:Xd,resizeEntity:Bd,resizeGroup:Hd,resizeNote:cu,setAllEntitiesCollapsed:Vl,setAttributeSwatch:Ca,setEntityCollapsed:Od,setEntityLocked:Ld,setEntitySwatch:Dd,setGroupLocked:Kd,setGroupSwatch:jd,setNoteMemo:du,setNoteSwatch:uu,setOperationSwatch:Zd,translateWaypoints:iu,updateAssociation:Aa,updateAssociationEnd:qt,updateAttribute:Yt,updateEntity:Ml,updateGroup:Pd,updateIndex:$a,updateOperation:Wd},Symbol.toStringTag,{value:"Module"}));class ku{constructor(){st(this,"revs",new Map);st(this,"layoutVersion",0);st(this,"logicalVersion",0)}seed(n){this.revs.clear();for(const[o,i]of Object.entries(n.revs??{}))this.revs.set(o,i);this.layoutVersion=n.layoutVersion??0,this.logicalVersion=n.logicalVersion??0}rev(n){return this.revs.get(n)??0}setRev(n,o){this.revs.set(n,o)}deleteRev(n){this.revs.delete(n)}snapshot(){return{revs:Object.fromEntries(this.revs),layoutVersion:this.layoutVersion,logicalVersion:this.logicalVersion}}}const Mb=[400,1200];function Vb(e){var o;if(typeof e!="object"||e===null)return;const n=e;for(const i of[n.statusCode,n.status,(o=n.response)==null?void 0:o.status])if(typeof i=="number"&&Number.isFinite(i))return i}function Bb(e){const n=Vb(e);return n==null||n===408||n===429?!0:n<400||n>=500}const Db=e=>new Promise(n=>setTimeout(n,e));class Eu{constructor(n){st(this,"cache",new ku);st(this,"newClientOpId");st(this,"debounceMs");st(this,"retryDelaysMs");st(this,"emissions",new WeakMap);st(this,"open",null);st(this,"debounceHandle",null);st(this,"queue",[]);st(this,"sending",!1);st(this,"_frozen",!1);st(this,"stack",null);st(this,"settledWaiters",[]);this.opts=n,this.newClientOpId=n.newClientOpId??Pe,this.debounceMs=n.debounceMs??300,this.retryDelaysMs=n.retryDelaysMs??Mb}seed(n){this.cache.seed(n)}attach(n){this.stack=n,n.sealCoalesce();const o=n.onCommand((i,a,r)=>this.handle(i,a,r));return()=>{o(),this.stack===n&&(this.stack=null)}}get frozen(){return this._frozen}get hasPending(){return this.open!==null||this.queue.length>0||this.sending}cacheSnapshot(){return this.cache.snapshot()}flush(){this.flushOpen(!0)}whenSettled(){return this.hasPending?new Promise(n=>this.settledWaiters.push(n)):Promise.resolve()}handle(n,o,i){var l,s,c;if(this._frozen)return;let a;if(o==="do"){const d=(l=n.emitOps)==null?void 0:l.call(n,this.opts.state);if(!d)throw new Error(`op-mode에서 emitOps 미구현 command 실행: ${n.label}`);a=d}else{const d=this.emissions.get(n);if(!d)throw new Error(`op-mode ${o} 대상 command의 emission 미기록: ${n.label}`);a=d}const r=o==="undo"?a.invert:a.forward;if(o==="do"&&i&&this.open&&this.open.coalesceKey===n.coalesceKey){this.open.fwd=r,this.emissions.set(n,{forward:r,invert:this.open.inv}),this.resetDebounce();return}if(i){const d=new Error(`op-mode coalesce 경계 불일치: 스택은 병합했으나 어댑터에 대응 그룹이 없음 (${n.label}, key=${String(n.coalesceKey)})`);console.error("[op-sync]",d),(c=(s=this.opts).onError)==null||c.call(s,d)}if(this.flushOpen(!1),o==="do"&&(this.emissions.set(n,a),n.coalesceKey!=null)){this.open={coalesceKey:n.coalesceKey,fwd:r,inv:a.invert},this.startDebounce();return}r.length&&this.enqueue(this.buildBatch(r))}flushOpen(n){var i;this.cancelDebounce();const o=this.open;this.open=null,o&&o.fwd.length&&this.enqueue(this.buildBatch(o.fwd)),n&&((i=this.stack)==null||i.sealCoalesce())}startDebounce(){this.cancelDebounce(),this.debounceHandle=setTimeout(()=>{this.debounceHandle=null,this.flushOpen(!0)},this.debounceMs)}resetDebounce(){this.startDebounce()}cancelDebounce(){this.debounceHandle!=null&&(clearTimeout(this.debounceHandle),this.debounceHandle=null)}buildBatch(n){const o={},i=new Set;let a=!1,r=!1;for(const l of n)if(l.casUnit==="logical")if(a=!0,l.containerRef)i.add(l.containerRef);else{const s=l.entityRef??l.associationRef??l.groupRef;s&&(l.kind.endsWith(".add")?this.cache.setRev(s,0):l.kind.endsWith(".remove")&&this.cache.deleteRev(s))}else l.incidental||(r=!0);if(i.size){o.revs={};for(const l of i){const s=this.cache.rev(l);o.revs[l]=s,this.cache.setRev(l,s+1)}}return r&&(o.layout=this.cache.layoutVersion,this.cache.layoutVersion=o.layout+1),a&&(this.cache.logicalVersion+=1),{diagramId:this.opts.diagramId,ops:n,cas:o,origin:this.opts.origin??"gui",clientOpId:this.newClientOpId()}}enqueue(n){this.queue.push(n),this.pump()}async pump(){var i,a;if(this.sending||this._frozen)return;const n=this.queue.shift();if(!n){this.notifySettled();return}this.sending=!0;let o;for(let r=0;;r++)try{o=await this.opts.transport(n);break}catch(l){const s=this.retryDelaysMs.length+1;console.error(`[op-sync] op 전송 실패 (시도 ${r+1}/${s}):`,l),(a=(i=this.opts).onError)==null||a.call(i,l);const c=this.retryDelaysMs[r];if(c==null||!Bb(l)){this.sending=!1,console.error("[op-sync] 전송 실패 확정 → 하드 프리즈(kind:missing)"),this.freeze({kind:"missing"});return}await Db(c)}this.sending=!1,o.ok?(this.reconcile(o),this.pump()):this.freeze(o.conflict)}reconcile(n){if(!(this.queue.length>0)){for(const[o,i]of Object.entries(n.revs))this.cache.setRev(o,i);this.cache.layoutVersion=n.layoutVersion,this.cache.logicalVersion=n.logicalVersion}}freeze(n){var o,i;this._frozen=!0,this.queue.length=0,this.open=null,this.cancelDebounce(),(i=(o=this.opts).onFreeze)==null||i.call(o,n),this.notifySettled()}notifySettled(){if(this.hasPending)return;const n=this.settledWaiters;this.settledWaiters=[];for(const o of n)o()}}const Nu=["entity.add","entity.update","entity.remove","attribute.add","attribute.update","attribute.remove","association.add","association.remove","association.update","associationEnd.update","index.add","index.update","index.remove","operation.add","operation.update","operation.remove","attribute.reorder","operation.reorder","group.add","group.update","group.remove","group.addMember","group.removeMember"],wu=["NORMAL","RELATION_OWN","RELATION_REF","EMBED_OWN","EMBED_REF","EMBED_PREDEF","DIVIDER"];function Iu(e,n){var r;if(!n.length||!((r=e.indexes)!=null&&r.length))return[];const o=new Set(n),i=new Set;for(const l of e.attributes)if(o.has(l.modelId)){i.add(l.modelId);for(const s of l.dbAttrs)i.add(s.modelId)}if(!i.size)return[];const a=[];for(const l of e.indexes){const s=l.columns.filter(c=>!i.has(c.columnRef));s.length!==l.columns.length&&a.push({indexRef:l.modelId,columns:s})}return a}function Ob(e){return gn(e).length}function Dl(e,n){return new Set(e.associations.filter(o=>{const i=o.end1.entityRef===n?o.end1:o.end2;return i.multiplicity==="ZERO_OR_MORE_INSTANCES"||i.multiplicity==="ONE_OR_MORE_INSTANCES"}).map(o=>o.modelId))}function Lb(e,n,o,i){var r;const a=new Set;for(const l of e.attributes)l.dbAttrs.forEach((s,c)=>{if(s.sharedColumnRef!=null)return;const d=ci(l,s,c,e,i);d&&a.add(d)});for(let l=n.dbAttrs.length;l<o.length;l++){const s=(r=o[l])==null?void 0:r.physicalName;if(s&&a.has(s))return!0}return!1}function vu(e,n,o=Pe){const i=e.entities.find(c=>c.modelId===n);if(!i)return[];const a=Ob(i);if(a===0)return[];const r=Dl(e,n),l=gn(i).map(c=>c.col),s=[];for(const c of e.entities){const d=c.attributes.filter(u=>{var m;return u.attrType==="EMBED_OWN"&&((m=u.embedded)==null?void 0:m.embeddableRef)===n&&!r.has(u.embedded.associationRef)&&a-u.dbAttrs.length>0});if(!(d.length>1))for(const u of d){const m=a-u.dbAttrs.length;Lb(c,u,l,e)||s.push({entityId:c.modelId,attributeId:u.modelId,dbAttrs:[...u.dbAttrs,...Array.from({length:m},()=>({modelId:o(),physicalName:"",dataType:""}))],added:m})}}return s}function Cu(e,n,o){var p;const i=e.entities.find(f=>f.modelId===n);if(!i)return[];const a=i.attributes;if(o.length!==a.length)return[];const r=new Map(a.map(f=>[f.modelId,f])),l=[];for(const f of o){const h=r.get(f);if(!h)return[];l.push(h)}const s=a.flatMap(f=>f.dbAttrs).map(f=>f.modelId),c=l.flatMap(f=>f.dbAttrs).map(f=>f.modelId);if(s.length!==c.length)return[];if(s.every((f,h)=>f===c[h]))return[];const d=new Map(s.map((f,h)=>[f,h])),u=Dl(e,n),m=[];for(const f of e.entities)for(const h of f.attributes){if(h.attrType!=="EMBED_OWN"||((p=h.embedded)==null?void 0:p.embeddableRef)!==n||u.has(h.embedded.associationRef)||h.dbAttrs.length!==s.length)continue;const g=c.map(_=>h.dbAttrs[d.get(_)]),b=g.reduce((_,E,N)=>E===h.dbAttrs[N]?_:_+1,0);b&&m.push({entityId:f.modelId,attributeId:h.modelId,dbAttrs:g,moved:b})}return m}function Su(e,n,o){var p;const i=e.entities.find(f=>f.modelId===n);if(!i)return[];const a=new Set(o),r=i.attributes.filter(f=>!a.has(f.modelId));if(r.length===i.attributes.length)return[];const l=gn(i).map(f=>f.col),s=l.map(f=>f.modelId),c=new Set(gn({...i,attributes:r}).map(f=>f.col.modelId)),d=new Set;if(s.forEach((f,h)=>{c.has(f)&&d.add(h)}),d.size===s.length)return[];const u=Dl(e,n),m=[];for(const f of e.entities)for(const h of f.attributes){if(h.attrType!=="EMBED_OWN"||((p=h.embedded)==null?void 0:p.embeddableRef)!==n||u.has(h.embedded.associationRef)||h.dbAttrs.length!==s.length)continue;const g=h.dbAttrs.filter((E,N)=>d.has(N)),b=h.dbAttrs.filter((E,N)=>!d.has(N));h.dbAttrs.some((E,N)=>{if(d.has(N))return!1;const y=l[N],k=!!E.physicalName&&E.physicalName!==((y==null?void 0:y.physicalName)??""),S=E.sharedColumnRef!=null&&E.sharedColumnRef!==(y==null?void 0:y.sharedColumnRef);return k||S})||m.push({entityId:f.modelId,attributeId:h.modelId,dbAttrs:g,dropped:b})}return m}function Pb(e,n){const o=()=>e.entities.filter(r=>{var l;return((l=r.table)==null?void 0:l.physicalName)===n.ref}),i=()=>e.entities.filter(r=>r.name===n.ref);if(n.by==="modelId")return e.entities.filter(r=>r.modelId===n.ref);if(n.by==="physicalName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function zb(e,n){const o=()=>e.attributes.filter(r=>r.name===n.ref),i=()=>e.attributes.filter(r=>r.dbAttrs.some(l=>l.physicalName===n.ref));if(n.by==="modelId")return e.attributes.filter(r=>r.modelId===n.ref);if(n.by==="name")return o();if(n.by==="physicalName")return i();const a=o();return a.length?a:i()}function xu(e,n,o){return e.associations.filter(i=>{const a=[i.end1.entityRef,i.end2.entityRef];return a.includes(n)&&a.includes(o)})}function St(e,n){const o=Pb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>Hb(i,e))}}function Fb(e,n){const o=()=>e.groups.filter(r=>r.packageName===n.ref),i=()=>e.groups.filter(r=>Object.values(r.name??{}).some(l=>l===n.ref));if(n.by==="modelId")return e.groups.filter(r=>r.modelId===n.ref);if(n.by==="packageName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function Ol(e,n){const o=Fb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>({modelId:i.modelId,name:i.name??null,packageName:i.packageName??null,members:i.memberEntityRefs.length}))}}function Ll(e,n,o){return e.reason==="not-found"?{code:"group-not-found",opIndex:n,handle:o}:{code:"group-ambiguous",opIndex:n,handle:o,matches:e.matches}}const Ub=new Set(["name","description","packageName","excludeDDLGeneration"]);function Hb(e,n){var a;const o=To(e,n).value,i=n.associations.filter(r=>{var l,s;return((l=r.end1)==null?void 0:l.entityRef)===e.modelId||((s=r.end2)==null?void 0:s.entityRef)===e.modelId});return{modelId:e.modelId,stereotype:e.stereotype,packageName:o||null,table:((a=e.table)==null?void 0:a.physicalName)||null,attributes:e.attributes.length,references:i.length,referencedBy:[...new Set(i.map(r=>{var c,d,u,m;const l=((c=r.end1)==null?void 0:c.entityRef)===e.modelId?(d=r.end2)==null?void 0:d.entityRef:(u=r.end1)==null?void 0:u.entityRef,s=n.entities.find(p=>p.modelId===l);return(s==null?void 0:s.name)||((m=s==null?void 0:s.table)==null?void 0:m.physicalName)||String(l??"?")}))]}}function Ru(e,n){const o=zb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function jb(e,n){const o=()=>e.attributes.flatMap(r=>r.dbAttrs).filter(r=>r.physicalName===n.ref),i=()=>e.attributes.filter(r=>r.name===n.ref).flatMap(r=>r.dbAttrs);if(n.by==="modelId")return e.attributes.flatMap(r=>r.dbAttrs).filter(r=>r.modelId===n.ref);if(n.by==="physicalName")return o();if(n.by==="name")return i();const a=o();return a.length?a:i()}function Kb(e,n){const o=jb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Au(e,n){const o=e.filter(i=>i.physicalName===n.ref);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Pl(e){return e.by!==void 0&&e.by!=="name"}function Gb(e,n){return(e.indexes??[]).filter(o=>o.name===n.ref)}function Yb(e,n){return(e.operations??[]).filter(o=>o.name===n.ref)}function qb(e,n){const o=Gb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function $u(e,n){const o=Yb(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>i.modelId)}}function Tu(e){return e.physicalName!=null||e.dataType!=null||e.length!=null||e.scale!=null||e.columnLogicalName!=null||e.unique!=null||e.updatable!=null}function Mu(e){return Tu(e)&&e.dataType==null}function Vu(e,n,o){const i=Tu(e);return{modelId:o(),name:e.name,type:e.type,attrType:"NORMAL",identifier:e.identifier??!1,notNull:e.notNull??!1,order:n,...e.transient?{transient:!0}:{},...e.groupCode?{groupCode:e.groupCode}:{},...e.defaultValue!=null?{defaultValue:e.defaultValue}:{},...e.attributeGroup?{attributeGroup:e.attributeGroup}:{},...e.description?{description:e.description}:{},...e.collectionType?{collectionType:e.collectionType}:{},dbAttrs:i?[{modelId:o(),physicalName:e.physicalName??e.name,dataType:e.dataType??"",...e.length?{length:e.length}:{},...e.scale?{scale:e.scale}:{},...e.columnLogicalName?{logicalName:e.columnLogicalName}:{},...e.unique!=null?{unique:e.unique}:{},...e.updatable!=null?{updatable:e.updatable}:{}}]:[]}}function Bu(e,n,o,i,a,r,l,s,c){const d=c(),u=new Map((e.embeddableOverrides??[]).map(f=>[f.field,f])),m=[];let p=!1;for(const f of n.fields){const h=u.get(f.name);if(h!=null&&h.sharedColumnPhysicalName){const g={ref:h.sharedColumnPhysicalName,by:"physicalName"},b=Au(Dn(i,a),g);if(!b.ok){s.push(b.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:g}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:g,matches:b.matches}),p=!0;continue}m.push({modelId:c(),physicalName:"",dataType:"",sharedColumnRef:b.value.modelId});continue}m.push({modelId:c(),physicalName:(h==null?void 0:h.physicalName)??"",dataType:"",...h!=null&&h.length?{length:h.length}:{},...h!=null&&h.scale?{scale:h.scale}:{},...(h==null?void 0:h.insertable)!=null?{insertable:h.insertable}:{},...(h==null?void 0:h.updatable)!=null?{updatable:h.updatable}:{}})}return p?null:{modelId:d,name:e.name,type:n.type,attrType:"EMBED_PREDEF",identifier:e.identifier??!1,notNull:e.notNull??!1,order:o,...e.defaultValue!=null?{defaultValue:e.defaultValue}:{},...e.attributeGroup?{attributeGroup:e.attributeGroup}:{},...e.description?{description:e.description}:{},dbAttrs:m}}const Wb=new Set(["name","type","customType","attrType","identifier","notNull","transient","naturalId","naturalIdMutable","description","attributeGroup","groupCode","defaultValue","personalInfoAttributeType","order","dbAttrs","derivedIdFieldName","collectionType"]),Uo=e=>new Set(Object.keys(e)),Jb=Uo({name:!0,stereotype:!0,physicalName:!0,useVersion:!0,attributes:!0,indexes:!0,operations:!0,serialization:!0}),Du=Uo({name:!0,type:!0,identifier:!0,notNull:!0,transient:!0,physicalName:!0,dataType:!0,length:!0,scale:!0,groupCode:!0,defaultValue:!0,attributeGroup:!0,description:!0,columnLogicalName:!0,unique:!0,updatable:!0,embeddableOverrides:!0,collectionType:!0}),Ou=Uo({name:!0,unique:!0,columns:!0,description:!0,parameters:!0}),Lu=Uo({name:!0,visibility:!0,sourceCode:!0,description:!0,personalInfoAttributeType:!0}),Xb=Uo({from:!0,to:!0,fromMultiplicity:!0,toMultiplicity:!0,identifying:!0,composition:!0}),Zb=Uo({name:!0,packageName:!0,description:!0,excludeDDLGeneration:!0,members:!0});function Nn(e,n){return uo(e,n)}const Qb=new Set(["name","stereotype","packageName","superClass","schema","description","abstractClass","hasPersonalInfo","declarationOfInterfaces","table","referenceOnly","serialization"]),e_=new Set(["description","identifying"]),t_=new Set(["multiplicity","navigable","composition"]),n_=new Set(["name","unique","description","parameters"]),o_=new Set(["name","visibility","sourceCode","description","order","personalInfoAttributeType"]);function uo(e,n,o=[]){const i=[];for(const a of Object.keys(e)){if(a.includes(".")){o.some(r=>a.startsWith(r))||i.push(a);continue}n.has(a)||i.push(a)}return i}const zl=new Set(["physicalName","logicalName","dataType","length","scale","unique","autoIncrement","updatable","insertable","sharedColumnRef","multiValue","multiValueSeparator","sequenceName"]),i_=new Set([...zl].filter(e=>e!=="sharedColumnRef"));function a_(e,n,o,i){if(i||o.some(l=>!i_.has(l))||e.attrType!=="NORMAL"||e.dbAttrs.length!==1)return null;const a={...e.dbAttrs[0]};for(const l of o)a[l]=n[l];const r={};for(const[l,s]of Object.entries(n))zl.has(l)||(r[l]=s);return{...r,dbAttrs:[a]}}function r_(e,n,o,i,a,r,l,s){const c=new Map(o.map(m=>[m.field,m])),d=[];let u=!1;return e.dbAttrs.forEach((m,p)=>{const f=n.fields[p],h=f?c.get(f.name):void 0;if(!h){d.push(m);return}if(h.sharedColumnPhysicalName){const b={ref:h.sharedColumnPhysicalName,by:"physicalName"},_=Au(Dn(i,a),b);if(!_.ok){s.push(_.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:b}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:b,matches:_.matches}),u=!0;return}d.push({modelId:m.modelId,physicalName:"",dataType:"",sharedColumnRef:_.value.modelId});return}const g={...m};delete g.sharedColumnRef,d.push({...g,...h.physicalName!=null?{physicalName:h.physicalName}:{},...h.length!=null?{length:h.length}:{},...h.scale!=null?{scale:h.scale}:{},...h.insertable!=null?{insertable:h.insertable}:{},...h.updatable!=null?{updatable:h.updatable}:{}})}),u?null:d}function Pu(e,n,o){return{modelId:o(),name:e.name,order:n,...e.visibility?{visibility:e.visibility}:{},...e.sourceCode?{sourceCode:e.sourceCode}:{},...e.description?{description:e.description}:{},...e.personalInfoAttributeType?{personalInfoAttributeType:e.personalInfoAttributeType}:{}}}function zu(e,n,o,i,a,r){const l=[];let s=!1;for(const c of n.columns){const d=Kb(e,c.column);if(!d.ok){a.push(d.reason==="not-found"?{code:"column-not-found",opIndex:o,entity:i,handle:c.column}:{code:"column-ambiguous",opIndex:o,entity:i,handle:c.column,matches:d.matches}),s=!0;continue}l.push({columnRef:d.value.modelId,descending:c.descending??!1})}return s?null:{modelId:r(),name:n.name,unique:n.unique??!1,columns:l,...n.description?{description:n.description}:{},...n.parameters?{parameters:n.parameters}:{}}}function Ho(e,n,o,i){const a=`${o}:${i}`;n.seen.has(a)||(n.seen.add(a),n.pairs.push({entityId:o,attributeId:i}),e.push({kind:"attribute.remove",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:i}))}function l_(e,n,o,i){const a=new Map;for(const{entityId:r,attributeId:l}of o.pairs){if(i.has(r))continue;const s=a.get(r)??[];s.push(l),a.set(r,s)}for(const[r,l]of a){const s=n.entities.find(c=>c.modelId===r);if(s)for(const c of Iu(s,l))e.push({kind:"index.update",casUnit:"logical",containerRef:r,entityRef:r,indexRef:c.indexRef,patch:{columns:c.columns}})}}function s_(e,n,o,i,a,r){const l=m=>{const p=new Map;for(const{entityId:f,item:h}of m){if(a.has(f))continue;const g=p.get(f)??[];g.push(h),p.set(f,g)}return p},s=l(o.pairs.map(m=>({entityId:m.entityId,item:m.attributeId}))),c=l(i.map(m=>({entityId:m.entityId,item:m.attribute}))),d=new Set(e.filter(m=>m.kind==="attribute.update").map(m=>m.attributeRef)),u=m=>{d.has(m.attributeId)||(d.add(m.attributeId),e.push({kind:"attribute.update",casUnit:"logical",containerRef:m.entityId,entityRef:m.entityId,attributeRef:m.attributeId,patch:{dbAttrs:m.dbAttrs}}))};for(const[m,p]of s)if(!c.has(m))for(const f of Su(n,m,p))u(f);for(const[m,p]of c){if(s.has(m))continue;const f={...n,entities:n.entities.map(h=>h.modelId===m?{...h,attributes:[...h.attributes,...p]}:h)};for(const h of vu(f,m,r))u(h)}}function Fu(e,n){const o={...e},i=[];for(const[a,r]of Object.entries(n)){if(!a.includes(".")){o[a]=r===null?void 0:r;continue}const l=/^dbAttrs\.(\d+)\.(.+)$/.exec(a);l&&i.push([Number(l[1]),l[2],r])}if(i.length){const a=(o.dbAttrs??[]).map(r=>({...r}));for(const[r,l,s]of i)a[r]&&(a[r][l]=s===null?void 0:s);o.dbAttrs=a}return o}function Uu(e,n,o,i,a,r,l){var p;for(const f of i.remove)Ho(e,r,o,f);for(const f of i.update)e.push({kind:"attribute.update",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:f.attributeId,patch:f.patch}),a.attrPatches.push({entityId:o,attributeId:f.attributeId,patch:f.patch});const s=((p=n.entities.find(f=>f.modelId===o))==null?void 0:p.attributes)??[],c=[];for(const f of i.add){const h={...f,order:l(o,s)};e.push({kind:"attribute.add",casUnit:"logical",containerRef:o,entityRef:o,value:h}),a.cascadeAdds.push({entityId:o,attribute:h}),c.push(h)}const d=new Set(i.remove),u=[...s.filter(f=>!d.has(f.modelId)),...c],m=new Set(u.map(f=>f.modelId));for(const f of n.associations){if(f.end2.entityRef!==o)continue;const h=f.end2.attributeRef;if(h&&m.has(h))continue;const b=u.filter(_=>{var E;return((E=_.derivedFrom)==null?void 0:E.associationRef)===f.modelId&&_.dbAttrs.length>0}).sort((_,E)=>_.order-E.order)[0];b&&(e.push({kind:"associationEnd.update",casUnit:"logical",containerRef:f.modelId,associationRef:f.modelId,end:"end2",patch:{attributeRef:b.modelId}}),a.endPatches.push({associationRef:f.modelId,end:"end2",patch:{attributeRef:b.modelId}}))}}function Fl(e,n,o,i,a,r,l){for(const{entityId:s,plan:c}of od(n,o,i))Uu(e,n,s,c,a,r,l)}function c_(e,n,o,i,a,r){const l=new Map;for(const{entityId:p,attributeId:f}of i.pairs)l.has(p)||l.set(p,new Set),l.get(p).add(f);const s=new Map;for(const p of r.attrPatches)s.has(p.entityId)||s.set(p.entityId,[]),s.get(p.entityId).push(p);const c=new Map;for(const{entityId:p,attribute:f}of[...a,...r.cascadeAdds])c.has(p)||c.set(p,[]),c.get(p).push(f);const d=p=>{const f={};for(const[h,g]of Object.entries(p))h.includes(".")||(f[h]=g===null?void 0:g);return f},u=e.entities.filter(p=>!n.has(p.modelId)).map(p=>{const f=l.get(p.modelId),h=s.get(p.modelId),g=c.get(p.modelId);if(!f&&!h&&!g)return p;let b=p.attributes;return f&&(b=b.filter(_=>!f.has(_.modelId))),h&&(b=b.map(_=>{const E=h.filter(N=>N.attributeId===_.modelId);return E.length?E.reduce((N,y)=>Fu(N,y.patch),_):_})),g&&(b=[...b,...g]),{...p,attributes:b}}),m=e.associations.filter(p=>!o.has(p.modelId)&&!n.has(p.end1.entityRef)&&!n.has(p.end2.entityRef)).map(p=>{let f=p;for(const h of r.assocPatches)h.associationRef===p.modelId&&(f={...f,...d(h.patch)});for(const h of r.endPatches)h.associationRef===p.modelId&&(f={...f,[h.end]:{...f[h.end],...d(h.patch)}});return f}).concat(r.addedAssociations);return{...e,entities:u,associations:m}}function d_(e,n,o,i,a,r,l,s,c){if(!l.identifierCascadeParents.size)return;const d=c_(n,o,i,a,r,l),u=new Map;for(const m of l.identifierCascadeParents)for(const[p,f]of sl(d,m,s)){const h=u.get(p);u.set(p,h?ll(h,f):f)}for(const[m,p]of u)Uu(e,d,m,nd(p),l,a,c)}function u_(e,n,o={}){const i=o.mkId??Pe,a=o.embeddableCatalog??[],r=y=>a.find(k=>k.type===y),l=[],s=[],c=new Map,d=(y,k)=>{const S=c.get(y)??Ht(k);return c.set(y,S+1),S},u=new Map,m=new Set,p=new Set,f={seen:new Set,pairs:[]},h=[],g={attrPatches:[],cascadeAdds:[],addedAssociations:[],assocPatches:[],endPatches:[],identifierCascadeParents:new Set},b=new Set,_=(y,k)=>`${y}\0${k}`,E=new Set;for(const y of n)y.kind==="entity.add"&&(E.add(y.spec.name),y.spec.physicalName&&E.add(y.spec.physicalName));const N=new Set;return n.forEach((y,k)=>{var S,T,O,A,V;switch(y.kind){case"entity.add":{{const M={ref:y.spec.name},x=Nn(y.spec,Jb);if(x.length){s.push({code:"entity-spec-unknown-key",opIndex:k,handle:M,keys:x});break}let P=!1;for(const q of y.spec.attributes??[]){const ce=Nn(q,Du);ce.length&&(s.push({code:"attribute-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}for(const q of y.spec.indexes??[]){const ce=Nn(q,Ou);ce.length&&(s.push({code:"index-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}for(const q of y.spec.operations??[]){const ce=Nn(q,Lu);ce.length&&(s.push({code:"operation-spec-unknown-key",opIndex:k,entity:M,handle:{ref:q.name},keys:ce}),P=!0)}if(P)break}const C=e.entities.filter(M=>M.name===y.spec.name).map(M=>M.modelId);if(C.length||N.has(y.spec.name)){s.push({code:"entity-name-conflict",opIndex:k,handle:{ref:y.spec.name},matches:C});break}N.add(y.spec.name);const R=i(),$={modelId:R,name:y.spec.name,stereotype:y.spec.stereotype??"JPA_ENTITY",attributes:[],...y.spec.useVersion?{jpaAttrs:{useVersion:!0}}:{},...y.spec.physicalName?{table:{physicalName:y.spec.physicalName}}:{},...y.spec.serialization?{serialization:y.spec.serialization}:{}},w={ref:y.spec.name};let I=!1;for(const[M,x]of(y.spec.attributes??[]).entries()){if(x.type==="GroupCodeEnum"&&!x.groupCode){s.push({code:"groupcode-required",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0;continue}if(!r(x.type)&&!((S=x.embeddableOverrides)!=null&&S.length)&&Mu(x)){s.push({code:"datatype-required",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0;continue}const P=r(x.type);if(P){const q=Bu(x,P,M,$,e.entities,k,w,s,i);q?$.attributes.push(q):I=!0}else(T=x.embeddableOverrides)!=null&&T.length?(s.push({code:"embeddable-type-unresolved",opIndex:k,entity:w,handle:{ref:x.name}}),I=!0):$.attributes.push(Vu(x,M,i))}const v=(y.spec.operations??[]).map((M,x)=>Pu(M,x,i));v.length&&($.operations=v);const B=[];for(const M of y.spec.indexes??[]){const x=zu($,M,k,w,s,i);x?B.push(x):I=!0}if(B.length&&($.indexes=B),I)break;l.push({kind:"entity.add",casUnit:"logical",entityRef:R,value:$});break}case"entity.update":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=uo(y.patch,Qb,["jpaAttrs.","table.","serialization."]);if(R.length){s.push({code:"entity-patch-unknown-key",opIndex:k,entity:y.entity,keys:R});break}const $=y.patch.stereotype;if(typeof $=="string"&&$!==C.value.stereotype){const w=$==="JPA_EMBEDDABLE"||C.value.stereotype==="JPA_EMBEDDABLE",I=$==="SERIALIZED_TYPE"||C.value.stereotype==="SERIALIZED_TYPE";if(w||I){s.push({code:w?"stereotype-embeddable-transition-unsupported":"stereotype-serialized-transition-unsupported",opIndex:k,entity:y.entity,from:C.value.stereotype??"",to:$});break}}l.push({kind:"entity.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,patch:y.patch});break}case"entity.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=C.value.modelId,$=e.associations.filter(B=>B.end1.entityRef===R||B.end2.entityRef===R),w=new Set($.map(B=>B.modelId));for(const B of $)m.has(B.modelId)||(m.add(B.modelId),l.push({kind:"association.remove",casUnit:"logical",associationRef:B.modelId}));for(const B of e.entities)if(B.modelId!==R)for(const M of B.attributes)M.embedded&&w.has(M.embedded.associationRef)&&Ho(l,f,B.modelId,M.modelId);for(const B of $){if(B.end1.entityRef===R||!B.end1.attributeRef)continue;const M=e.entities.find(P=>P.modelId===B.end1.entityRef),x=M==null?void 0:M.attributes.find(P=>P.modelId===B.end1.attributeRef&&P.attrType==="RELATION_REF");x&&Ho(l,f,M.modelId,x.modelId)}const I={...e,entities:e.entities.filter(B=>B.modelId!==R),associations:e.associations.filter(B=>!w.has(B.modelId))},v=new Set($.filter(B=>B.end1.entityRef===R&&B.end2.entityRef!==R).map(B=>B.end2.entityRef));Fl(l,I,[...v],i,g,f,d);for(const B of e.groups)B.memberEntityRefs.includes(R)&&(b.has(_(B.modelId,R))||(b.add(_(B.modelId,R)),l.push({kind:"group.removeMember",casUnit:"logical",containerRef:B.modelId,groupRef:B.modelId,entityRef:R})));p.add(R),l.push({kind:"entity.remove",casUnit:"logical",entityRef:R});break}case"attribute.add":{{const I=Nn(y.spec,Du);if(I.length){s.push({code:"attribute-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:I});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(y.spec.type==="GroupCodeEnum"&&!y.spec.groupCode){s.push({code:"groupcode-required",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}if(!r(y.spec.type)&&!((O=y.spec.embeddableOverrides)!=null&&O.length)&&Mu(y.spec)){s.push({code:"datatype-required",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}const R=d(C.value.modelId,C.value.attributes),$=r(y.spec.type);let w;if($)w=Bu(y.spec,$,R,C.value,e.entities,k,y.entity,s,i);else if((A=y.spec.embeddableOverrides)!=null&&A.length){s.push({code:"embeddable-type-unresolved",opIndex:k,entity:y.entity,handle:{ref:y.spec.name}});break}else w=Vu(y.spec,R,i);if(!w)break;l.push({kind:"attribute.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,value:w}),h.push({entityId:C.value.modelId,attribute:w}),w.identifier&&g.identifierCascadeParents.add(C.value.modelId);break}case"attribute.update":case"attribute.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=Ru(C.value,y.attribute);if(!R.ok){s.push(R.reason==="not-found"?{code:"attribute-not-found",opIndex:k,entity:y.entity,handle:y.attribute}:{code:"attribute-ambiguous",opIndex:k,entity:y.entity,handle:y.attribute,matches:R.matches});break}if(y.kind==="attribute.update"){const $=[],w=[];let I=!1;for(const x of Object.keys(y.patch)){if(x.includes(".")){x.startsWith("dbAttrs.")?I=!0:w.push(x);continue}zl.has(x)?$.push(x):Wb.has(x)||w.push(x)}if(w.length){s.push({code:"attribute-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.attribute,keys:w});break}if("attrType"in y.patch){const x=String(y.patch.attrType),P=wu.includes(x)?x!==R.value.attrType?"transition":void 0:"unknown-value";if(P){s.push({code:"attribute-attrtype-unsupported",opIndex:k,entity:y.entity,handle:y.attribute,reason:P,current:R.value.attrType,requested:x});break}}const v="type"in y.patch?y.patch.type:R.value.type,B="groupCode"in y.patch?y.patch.groupCode:R.value.groupCode;if(v==="GroupCodeEnum"&&!B){s.push({code:"groupcode-required",opIndex:k,entity:y.entity,handle:y.attribute});break}let M=y.patch;if($.length){const x=a_(R.value,y.patch,$,I);if(!x){s.push({code:"attribute-patch-dbattr-flat-key",opIndex:k,entity:y.entity,handle:y.attribute,keys:$});break}M=x}if((V=y.embeddableOverrides)!=null&&V.length){const x=r(R.value.type);if(!x||R.value.attrType!=="EMBED_PREDEF"){s.push({code:"embeddable-type-unresolved",opIndex:k,entity:y.entity,handle:y.attribute});break}const P=r_(R.value,x,y.embeddableOverrides,C.value,e.entities,k,y.entity,s);if(!P)break;M={...M,dbAttrs:P}}l.push({kind:"attribute.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,attributeRef:R.value.modelId,patch:M}),g.attrPatches.push({entityId:C.value.modelId,attributeId:R.value.modelId,patch:M});{const x=R.value,P=Fu(x,M),q=(P.identifier??!1)!==(x.identifier??!1),ce=(x.identifier||P.identifier)&&("type"in M||"customType"in M||"dbAttrs"in M||Object.keys(M).some(ge=>ge.startsWith("dbAttrs.")));(q||ce)&&g.identifierCascadeParents.add(C.value.modelId)}}else{const $=Lo(e,C.value.modelId,R.value.modelId);if($){const w=I=>{var v;return((v=e.entities.find(B=>B.modelId===I))==null?void 0:v.name)??I};s.push({code:"attribute-fk-managed",opIndex:k,entity:y.entity,handle:y.attribute,association:{from:w($.end1.entityRef),to:w($.end2.entityRef)}});break}Ho(l,f,C.value.modelId,R.value.modelId),R.value.identifier&&g.identifierCascadeParents.add(C.value.modelId)}break}case"association.add":{{const B=Nn(y.spec,Xb);if(B.length){s.push({code:"association-spec-unknown-key",opIndex:k,handle:{from:y.spec.from,to:y.spec.to},keys:B});break}}const C=St(e,y.spec.from),R=St(e,y.spec.to);if(C.ok||s.push(xt(C.reason,k,y.spec.from,C.matches,E)),R.ok||s.push(xt(R.reason,k,y.spec.to,R.matches,E)),!C.ok||!R.ok)break;if(y.spec.identifying&&C.value.modelId===R.value.modelId){s.push({code:"self-identifying",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}if(C.value.stereotype==="JPA_EMBEDDABLE"||R.value.stereotype==="JPA_EMBEDDABLE"){s.push({code:"embeddable-relation-unsupported",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}if(C.value.stereotype==="SERIALIZED_TYPE"||R.value.stereotype==="SERIALIZED_TYPE"){s.push({code:"serialized-relation-invalid",opIndex:k,handle:{from:y.spec.from,to:y.spec.to}});break}const $=i(),w={modelId:$,...y.spec.identifying!=null?{identifying:y.spec.identifying}:{},end1:{entityRef:C.value.modelId,multiplicity:y.spec.fromMultiplicity??"EXACTLY_ONE_INSTANCE",navigable:!1,composition:!1},end2:{entityRef:R.value.modelId,multiplicity:y.spec.toMultiplicity??"ZERO_OR_MORE_INSTANCES",navigable:!0,composition:y.spec.composition??!1}},I={...e,associations:[...e.associations,w]},v=pi(I,R.value.modelId,i);v.add[0]&&(w.end2.attributeRef=v.add[0].modelId),l.push({kind:"association.add",casUnit:"logical",associationRef:$,value:w}),g.addedAssociations.push(w);for(const B of v.add){const M={...B,order:d(R.value.modelId,R.value.attributes)};l.push({kind:"attribute.add",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,value:M}),g.cascadeAdds.push({entityId:R.value.modelId,attribute:M})}break}case"association.remove":{const C=St(e,y.association.from),R=St(e,y.association.to);if(C.ok||s.push(xt(C.reason,k,y.association.from,C.matches,E)),R.ok||s.push(xt(R.reason,k,y.association.to,R.matches,E)),!C.ok||!R.ok)break;const $=xu(e,C.value.modelId,R.value.modelId);if($.length!==1){s.push($.length===0?{code:"association-not-found",opIndex:k,handle:y.association}:{code:"association-ambiguous",opIndex:k,handle:y.association,matches:$.map(B=>B.modelId)});break}const w=$[0];m.has(w.modelId)||(m.add(w.modelId),l.push({kind:"association.remove",casUnit:"logical",associationRef:w.modelId}));const I=e.entities.find(B=>B.attributes.some(M=>{var x;return((x=M.embedded)==null?void 0:x.associationRef)===w.modelId}));if(I){const B=I.attributes.find(M=>{var x;return((x=M.embedded)==null?void 0:x.associationRef)===w.modelId});Ho(l,f,I.modelId,B.modelId);break}if(w.end1.attributeRef){const B=e.entities.find(x=>x.modelId===w.end1.entityRef),M=B==null?void 0:B.attributes.find(x=>x.modelId===w.end1.attributeRef&&x.attrType==="RELATION_REF");M&&Ho(l,f,B.modelId,M.modelId)}const v={...e,associations:e.associations.filter(B=>B.modelId!==w.modelId)};Fl(l,v,[w.end2.entityRef],i,g,f,d);break}case"association.update":{const C=Hu(e,y.association,k,s,E);if(!C)break;const R=y.patch.identifying,$=typeof R=="boolean"?R:void 0;if($===!0&&C.end1.entityRef===C.end2.entityRef){s.push({code:"self-identifying",opIndex:k,handle:y.association});break}const w=uo(y.patch,e_);if(w.length){s.push({code:"association-patch-unknown-key",opIndex:k,handle:y.association,keys:w});break}if(l.push({kind:"association.update",casUnit:"logical",containerRef:C.modelId,associationRef:C.modelId,patch:y.patch}),g.assocPatches.push({associationRef:C.modelId,patch:y.patch}),$!==void 0&&$!==(C.identifying??!1)){const I={...e,associations:e.associations.map(v=>v.modelId===C.modelId?{...v,identifying:$}:v)};Fl(l,I,[C.end2.entityRef],i,g,f,d)}break}case"associationEnd.update":{const C=Hu(e,y.association,k,s,E);if(!C)break;const R=y.end==="from"?"end1":"end2";if(Object.prototype.hasOwnProperty.call(y.patch,"navigable")){s.push({code:"navigable-toggle-unsupported",opIndex:k,handle:y.association});break}const $=uo(y.patch,t_,["jpa."]);if($.length){s.push({code:"association-end-patch-unknown-key",opIndex:k,handle:y.association,keys:$});break}l.push({kind:"associationEnd.update",casUnit:"logical",containerRef:C.modelId,associationRef:C.modelId,end:R,patch:y.patch}),g.endPatches.push({associationRef:C.modelId,end:R,patch:y.patch});break}case"index.add":{{const $=Nn(y.spec,Ou);if($.length){s.push({code:"index-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:$});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=zu(C.value,y.spec,k,y.entity,s,i);if(!R)break;l.push({kind:"index.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.modelId,value:R});break}case"index.update":case"index.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(Pl(y.index)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:y.index,target:"index"});break}const R=qb(C.value,y.index);if(!R.ok){s.push(R.reason==="not-found"?{code:"index-not-found",opIndex:k,entity:y.entity,handle:y.index}:{code:"index-ambiguous",opIndex:k,entity:y.entity,handle:y.index,matches:R.matches});break}if(y.kind==="index.update"){if("columns"in y.patch){s.push({code:"index-columns-patch-unsupported",opIndex:k,entity:y.entity,handle:y.index});break}const $=uo(y.patch,n_);if($.length){s.push({code:"index-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.index,keys:$});break}l.push({kind:"index.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.value.modelId,patch:y.patch})}else l.push({kind:"index.remove",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,indexRef:R.value.modelId});break}case"operation.add":{{const w=Nn(y.spec,Lu);if(w.length){s.push({code:"operation-spec-unknown-key",opIndex:k,entity:y.entity,handle:{ref:y.spec.name},keys:w});break}}const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}const R=u.get(C.value.modelId)??(C.value.operations?Ht(C.value.operations):0);u.set(C.value.modelId,R+1);const $=Pu(y.spec,R,i);l.push({kind:"operation.add",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:$.modelId,value:$});break}case"operation.update":case"operation.remove":{const C=St(e,y.entity);if(!C.ok){s.push(xt(C.reason,k,y.entity,C.matches,E));break}if(Pl(y.operation)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:y.operation,target:"operation"});break}const R=$u(C.value,y.operation);if(!R.ok){s.push(R.reason==="not-found"?{code:"operation-not-found",opIndex:k,entity:y.entity,handle:y.operation}:{code:"operation-ambiguous",opIndex:k,entity:y.entity,handle:y.operation,matches:R.matches});break}if(y.kind==="operation.update"){const $=uo(y.patch,o_);if($.length){s.push({code:"operation-patch-unknown-key",opIndex:k,entity:y.entity,handle:y.operation,keys:$});break}l.push({kind:"operation.update",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:R.value.modelId,patch:y.patch})}else l.push({kind:"operation.remove",casUnit:"logical",containerRef:C.value.modelId,entityRef:C.value.modelId,operationRef:R.value.modelId});break}case"attribute.reorder":case"operation.reorder":{const C=y.kind==="attribute.reorder",R=St(e,y.entity);if(!R.ok){s.push(xt(R.reason,k,y.entity,R.matches,E));break}const $=C?y.order:y.operations,w=[],I=new Set;let v=!1;for(const P of $){if(!C&&Pl(P)){s.push({code:"handle-by-unsupported",opIndex:k,entity:y.entity,handle:P,target:"operation"}),v=!0;continue}const q=C?Ru(R.value,P):$u(R.value,P);if(!q.ok){s.push(q.reason==="not-found"?{code:"reorder-handle-not-found",opIndex:k,entity:y.entity,handle:P}:{code:"reorder-handle-ambiguous",opIndex:k,entity:y.entity,handle:P,matches:q.matches}),v=!0;continue}if(I.has(q.value.modelId)){s.push({code:"reorder-handle-duplicate",opIndex:k,entity:y.entity,handle:P}),v=!0;continue}I.add(q.value.modelId),w.push(q.value)}if(v)break;const M=[...C?R.value.attributes:R.value.operations??[]].sort((P,q)=>P.order-q.order).filter(P=>!I.has(P.modelId)),x=[...w,...M];if(x.forEach((P,q)=>{P.order!==q&&l.push(C?{kind:"attribute.update",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,attributeRef:P.modelId,patch:{order:q}}:{kind:"operation.update",casUnit:"logical",containerRef:R.value.modelId,entityRef:R.value.modelId,operationRef:P.modelId,patch:{order:q}})}),C)for(const P of Cu(e,R.value.modelId,x.map(q=>q.modelId)))l.push({kind:"attribute.update",casUnit:"logical",containerRef:P.entityId,entityRef:P.entityId,attributeRef:P.attributeId,patch:{dbAttrs:P.dbAttrs}});break}case"group.add":{{const I=Nn(y.spec,Zb);if(I.length){s.push({code:"group-spec-unknown-key",opIndex:k,keys:I});break}}const C=[];let R=!1;for(const I of y.spec.members){const v=St(e,I);if(!v.ok){s.push(xt(v.reason,k,I,v.matches,E)),R=!0;continue}C.push(v.value.modelId)}if(R)break;const $=i(),w={modelId:$,excludeDDLGeneration:y.spec.excludeDDLGeneration??!1,memberEntityRefs:C,...y.spec.name?{name:y.spec.name}:{},...y.spec.packageName?{packageName:y.spec.packageName}:{},...y.spec.description?{description:y.spec.description}:{}};l.push({kind:"group.add",casUnit:"logical",groupRef:$,value:w});break}case"group.update":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}const R=uo(y.patch,Ub);if(R.length){s.push({code:"group-patch-unknown-key",opIndex:k,handle:y.group,keys:R});break}l.push({kind:"group.update",casUnit:"logical",containerRef:C.value.modelId,groupRef:C.value.modelId,patch:y.patch});break}case"group.remove":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}l.push({kind:"group.remove",casUnit:"logical",groupRef:C.value.modelId});break}case"group.addMember":case"group.removeMember":{const C=Ol(e,y.group);if(!C.ok){s.push(Ll(C,k,y.group));break}const R=St(e,y.entity);if(!R.ok){s.push(xt(R.reason,k,y.entity,R.matches,E));break}const $=C.value.memberEntityRefs.includes(R.value.modelId);if(y.kind==="group.addMember"?$:!$)break;if(y.kind==="group.removeMember"){if(b.has(_(C.value.modelId,R.value.modelId)))break;b.add(_(C.value.modelId,R.value.modelId))}l.push({kind:y.kind,casUnit:"logical",containerRef:C.value.modelId,groupRef:C.value.modelId,entityRef:R.value.modelId});break}}}),s.length||d_(l,e,p,m,f,h,g,i,d),s.length||l_(l,e,f,p),s.length||s_(l,e,f,h,p,i),s.length?{ok:!1,errors:s}:{ok:!0,ops:l}}function xt(e,n,o,i,a){return e==="not-found"&&(a!=null&&a.has(o.ref))?{code:"pending-entity-ref",opIndex:n,handle:o}:e==="not-found"?{code:"entity-not-found",opIndex:n,handle:o}:{code:"entity-ambiguous",opIndex:n,handle:o,matches:i}}function Hu(e,n,o,i,a){const r=St(e,n.from),l=St(e,n.to);if(r.ok||i.push(xt(r.reason,o,n.from,r.matches,a)),l.ok||i.push(xt(l.reason,o,n.to,l.matches,a)),!r.ok||!l.ok)return null;const s=xu(e,r.value.modelId,l.value.modelId);return s.length!==1?(i.push(s.length===0?{code:"association-not-found",opIndex:o,handle:n}:{code:"association-ambiguous",opIndex:o,handle:n,matches:s.map(c=>c.modelId)}),null):s[0]}const ju={type:"object",description:"요소 지정 핸들. 엔티티: 물리명(table.physicalName) 우선, 논리명(name) 보조. 속성: 소속 엔티티 내 속성명 또는 컬럼 물리명.",properties:{ref:{type:"string",description:"매칭할 이름/물리명. by:'modelId'면 modelId 원문."},by:{type:"string",enum:["physicalName","name","modelId"],description:"매칭 키 고정(미지정 시 대상별 기본 순서). 'modelId'는 모호 해소 전용 탈출구 — 평시엔 쓰지 말고, entity-ambiguous 응답의 후보를 사용자에게 제시해 확인받은 뒤 그 modelId로 재전송할 때만 쓴다."}},required:["ref"],additionalProperties:!1},m_={type:"object",description:"엔티티 내 이름으로 지정(인덱스명·메서드명). 물리명 차원이 없어 매칭 키 고정(`by`)을 받지 않는다.",properties:{ref:{type:"string",description:"매칭할 이름."}},required:["ref"],additionalProperties:!1},f_={type:"object",description:"관계는 무명이라 양 끝 엔티티로 주소. from=부모(end1), to=자식(end2). 같은 쌍 복수 관계는 모호 보고.",properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"}},required:["from","to"],additionalProperties:!1},p_={type:"object",description:"신규 엔티티. 자식(속성·인덱스·operation)은 별도 attribute.add 등이 아니라 여기 inline 배열로 담아라 — 같은 배치에서 갓 추가된 엔티티에 닿는 child op은 silent no-op이 된다(서버가 pending-entity-ref로 거부). 관계는 inline 불가 → 엔티티 추가 배치 확정 후 별도 배치로 association.add.",properties:{name:{type:"string"},stereotype:{type:"string",enum:["UNDEFINED","JPA_ENTITY","JPA_EMBEDDABLE","JPA_MULTI_LANGUAGE_ENTITY","SERIALIZED_TYPE"],description:"기본 JPA_ENTITY."},physicalName:{type:"string",description:"설정 시 table.physicalName."},useVersion:{type:"boolean",description:'JPA @Version(낙관적 락) → jpaAttrs.useVersion. @Version 필드는 별도 속성이 아니라 이 엔티티 플래그로 흡수 (버전 컬럼은 코드젠 소유). 기존 엔티티는 entity.update patch의 dotted key {"jpaAttrs.useVersion":true} 사용.'},attributes:{type:"array",description:"inline 속성(배열 순서가 order). attribute.add와 동일 규칙 — GroupCodeEnum은 groupCode 동반 필수.",items:{$ref:"#/$defs/attrSpec"}},indexes:{type:"array",description:"inline 인덱스. 컬럼 핸들은 이 엔티티가 inline으로 만드는 dbAttr 내에서 해소된다(attributes 동반 전제).",items:{$ref:"#/$defs/indexSpec"}},operations:{type:"array",description:"inline 도메인 메서드(배열 순서가 order).",items:{$ref:"#/$defs/operationSpec"}},serialization:{$ref:"#/$defs/serialization"}},required:["name"],additionalProperties:!1},h_={type:"object",description:"직렬화 타입의 컨테이너(SERIALIZED_TYPE 전용). 미지정 = 컬렉션이 아닌 단일 값(한 컬럼에 구조 하나). 신규 엔티티는 entity.add 에 함께 줘야 한다 — 같은 배치의 entity.update 는 갓 만든 엔티티에 닿지 못한다.",properties:{collectionType:{type:"string",enum:["LIST","SET","MAP"],description:"컨테이너 종류. 코퍼스 실재가 java.util 3종뿐이라 그만 표현한다(미지 컨테이너는 발명하지 않는다)."},mapKeyType:{type:"string",description:"collectionType='MAP' 일 때의 키 타입(단순명 또는 FQN). 그 외엔 무의미."}},additionalProperties:!1},zn={type:"object",properties:{ko:{type:"string"},en:{type:"string"},ja:{type:"string"},zh:{type:"string"}},additionalProperties:!1},y_={type:"object",properties:{name:{type:"string"},type:{type:"string",description:"Java 타입(예: Long, String). GroupCodeEnum은 파생 타입이라 groupCode 동반 필수(없으면 거부). 호스트 임베더블 카탈로그에 등록된 predefined 임베더블 타입(예: Money, EmbeddableAddress)이면 EMBED_PREDEF로 다중 컬럼 확장(서브컬럼 조정은 embeddableOverrides)."},identifier:{type:"boolean"},notNull:{type:"boolean"},transient:{type:"boolean",description:"JPA @Transient(비영속) → Attribute.transient. 컬럼을 만들지 않으므로 physicalName/dataType 등 컬럼 필드는 함께 주지 않는다. 기존 속성은 attribute.update patch {transient:true}로도 가능."},physicalName:{type:"string",description:"설정 시 단일 dbAttr 컬럼 생성(미설정이면 name을 물리명으로)."},dataType:{type:"string",description:"dbAttr 물리 타입(예: BIGINT). physicalName/dataType/length/scale 중 하나라도 있으면 컬럼 생성."},length:{type:"integer",description:"dbAttr 컬럼 길이(VARCHAR(n)·DECIMAL precision)."},scale:{type:"integer",description:"dbAttr 소수 자릿수(DECIMAL/NUMERIC scale). length 동반이 일반적."},groupCode:{type:"string",description:"코드성 속성의 group code 바인딩. type=GroupCodeEnum이면 필수."},defaultValue:{type:"string",description:"속성 기본값(문자열 패스스루)."},attributeGroup:{type:"string",description:"속성 분류 그룹(예: 'code'·'amt')."},description:{...zn,description:"속성 설명(다국어)."},columnLogicalName:{...zn,description:'dbAttr 컬럼 논리명(다국어, 예: {ko:"체크아웃유형"}). 한글 업무명 보존 위치.'},unique:{type:"boolean",description:"dbAttr UNIQUE 제약."},updatable:{type:"boolean",description:"dbAttr 갱신 가능(JPA @Column(updatable=))."},embeddableOverrides:{$ref:"#/$defs/embeddableOverrides"},collectionType:{type:"string",enum:["LIST","SET"],description:"이 «필드»가 컬렉션인가 — **직렬화 타입(SERIALIZED_TYPE)의 자기 필드 전용**(예: Set<String>·List<StoredFile>). 컬럼 있는 자리는 읽지 않는다 — 그쪽 컨테이너는 요소 타입이 소유한다(entity 의 serialization.collectionType). 요소가 문서 안 직렬화 타입이면 그 타입이 이미 감싸므로 지정하지 않는다. 미지정 = 컬렉션 아님."}},required:["name","type"],additionalProperties:!1},g_={type:"array",description:"predefined 임베더블 서브컬럼 오버라이드(속성 type이 카탈로그 엔트리이자 EMBED_PREDEF일 때만). field=카탈로그 필드명으로 매칭(@AttributeOverride 대응). 미설정 서브컬럼은 add=카탈로그 기본 상속 / update=기존값 유지. currency 등 공유 컬럼은 sharedColumnPhysicalName으로 SHARED_REF.",items:{type:"object",properties:{field:{type:"string",description:"대상 카탈로그 필드명(예: amount·currency)."},physicalName:{type:"string",description:"서브컬럼 물리명 오버라이드(@AttributeOverride column name). 미설정 시 카탈로그 기본."},length:{type:"integer",description:"서브컬럼 길이 오버라이드."},scale:{type:"integer",description:"서브컬럼 소수 자릿수 오버라이드."},insertable:{type:"boolean",description:"JPA @Column(insertable=). OWN 컬럼에만 저장."},updatable:{type:"boolean",description:"JPA @Column(updatable=). OWN 컬럼에만 저장."},sharedColumnPhysicalName:{type:"string",description:"SHARED_REF — 같은 엔터티(임베더블이면 owner 합집합) 다른 컬럼(물리명)을 공유해 read-only 투영(대표: currency). 설정 시 자체 컬럼 미보유, 타깃은 해소 시점 존재 필수."}},required:["field"],additionalProperties:!1}},Ku={type:"string",enum:["NO_INSTANCE_OR_ONE_INSTANCE","EXACTLY_ONE_INSTANCE","ZERO_OR_MORE_INSTANCES","ONE_OR_MORE_INSTANCES"]},b_={type:"object",description:'일반 연관 생성. 양 end 는 일반 엔티티여야 한다 — 임베더블(JPA_EMBEDDABLE)·직렬화 타입을 end 로 주면 거부된다. 직렬화 타입은 관계가 아니라 소비 속성의 type 으로 지목한다(attribute.update {type: "<타입명>"}). (임베드는 EMBED 관계여야 하고 이 어휘엔 없다 → 캔버스에서 연결).',properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"},fromMultiplicity:{...Ku,description:"end1 다중성(기본 EXACTLY_ONE_INSTANCE)."},toMultiplicity:{...Ku,description:"end2 다중성(기본 ZERO_OR_MORE_INSTANCES)."},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK로 전파). self-association은 식별 불가."},composition:{type:"boolean",description:"end2 composition."}},required:["from","to"],additionalProperties:!1},__={type:"object",properties:{name:{type:"string"},unique:{type:"boolean",description:"UNIQUE 인덱스 여부(기본 false)."},columns:{type:"array",description:"인덱스 컬럼(순서 의미 있음).",items:{type:"object",properties:{column:{...ju,description:"컬럼 핸들 — 컬럼 물리명 우선, 속성명 보조(단일 컬럼 속성만). 엔티티 내에서 dbAttr modelId로 해소."},descending:{type:"boolean",description:"내림차순(기본 false)."}},required:["column"],additionalProperties:!1}},description:{type:"string",description:"인덱스 설명(평문)."},parameters:{type:"string",description:"인덱스 파라미터(패스스루)."}},required:["name","columns"],additionalProperties:!1},k_={type:"object",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"],description:"가시성(기본 미설정)."},sourceCode:{type:"string",description:"Java 메서드 본문(멀티라인, 파라미터·반환 시그니처 포함)."},description:{...zn,description:"메서드 설명(다국어)."},personalInfoAttributeType:{type:"string",description:"개인정보 속성 유형(패스스루)."}},required:["name"],additionalProperties:!1},E_={type:"object",properties:{name:{...zn,description:'그룹 논리명(다국어, 예: {ko:"주문"}).'},packageName:{type:"string",description:"자바 패키지명 등 그룹 물리 식별(레거시 LogicalGroup.packageName)."},description:{type:"string",description:"그룹 설명(자유 텍스트 — 도메인 경계 메모)."},excludeDDLGeneration:{type:"boolean",description:"DDL 생성 제외(기본 false)."},members:{type:"array",description:"멤버 엔티티 핸들(물리명 우선/논리명 보조). 기존 엔티티여야 함 — 같은 배치 신규 엔티티는 별도 배치 후.",items:{$ref:"#/$defs/handle"}}},required:["members"],additionalProperties:!1},N_={type:"object",description:"기존 속성 부분 patch. 논리 필드 + 스칼라 단일 컬럼의 물리 필드(physicalName·dataType·length·scale 등 — 서버가 dbAttrs[0]에 매핑). EMBED_PREDEF/Money 서브컬럼 조정은 op-레벨 embeddableOverrides로(평탄 키는 다중 컬럼서 모호해 거부).",properties:{name:{type:"string"},type:{type:"string"},customType:{type:"string"},attrType:{type:"string",enum:[...wu],description:"속성 종류. **현재 값과 다르게 주면 거부된다** — 관계/임베드/구분선은 동반 구조(관계 소유·embedded·빈 dbAttrs)가 있어야 성립하고 patch로는 표현할 수 없다. 관계 실체화는 association.add, 임베드 서브컬럼은 embeddableOverrides 소관."},identifier:{type:"boolean"},notNull:{type:"boolean"},transient:{type:"boolean"},naturalId:{type:"boolean"},naturalIdMutable:{type:"boolean"},derivedIdFieldName:{type:"string",description:"파생 식별(@MapsId) FK가 매핑되는 **스칼라 @Id 필드명**. 이 속성의 name은 연관 필드명(@MapsId @OneToOne 필드)이고 같은 관계가 두 Java 필드를 만든다. 단일 컬럼 @OneToOne 식별 FK에만 의미가 있고, 미설정 시 부모 PK 물리명의 camelCase로 파생된다(실물 관행). 컬럼은 공유하므로 속성은 하나이며 물리명은 지정하지 않는다."},description:{...zn,description:"속성 설명(다국어)."},attributeGroup:{type:"string"},groupCode:{type:"string"},defaultValue:{type:"string"},personalInfoAttributeType:{type:"string"},order:{type:"integer"},physicalName:{type:"string"},dataType:{type:"string"},length:{type:"integer"},scale:{type:"integer"},unique:{type:"boolean"},updatable:{type:"boolean"},insertable:{type:"boolean"},autoIncrement:{type:"boolean"},multiValue:{type:"boolean"},multiValueSeparator:{type:"string"},sequenceName:{type:"string"},logicalName:{...zn,description:"컬럼 논리명(다국어)."}},additionalProperties:!1},w_={type:"object",description:"관계 부분 patch. 양 end 설정(multiplicity·nav·jpa)은 associationEnd.update로.",properties:{description:{type:"string"},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK 일부로 전파)."}},additionalProperties:!1},I_={type:"object",description:"인덱스 부분 patch. columns(컬럼 구성) 변경은 index.remove+index.add로(패치 불가).",properties:{name:{type:"string"},unique:{type:"boolean"},description:{type:"string"},parameters:{type:"string"}},additionalProperties:!1},v_={type:"object",description:"메서드 부분 patch.",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"]},sourceCode:{type:"string"},description:{...zn,description:"메서드 설명(다국어)."},order:{type:"integer"},personalInfoAttributeType:{type:"string"}},additionalProperties:!1},C_={type:"object",description:'엔티티 부분 patch. 논리 키: name·stereotype·packageName·superClass·schema·description·abstractClass·hasPersonalInfo·referenceOnly·declarationOfInterfaces·table·serialization. serialization(직렬화 타입 컨테이너)은 통째로 주거나(예: {"serialization":{"collectionType":"LIST"}}) dotted-key로 준다({"serialization.collectionType":"LIST"}). 컬렉션 아님으로 되돌릴 땐 null 로 비운다(wire clear 규약). jpaAttrs 플래그(useVersion 등)는 형제 클로버 방지를 위해 dotted-key로 준다: {"jpaAttrs.useVersion": true}. 자식(attributes/indexes/operations)은 patch가 아니라 전용 op로 변경. stereotype 은 값 타입(JPA_EMBEDDABLE·SERIALIZED_TYPE) 경계를 넘을 수 없다 — 들어가고 나오는 전환은 PK 해제/부여·FK reconcile·EMBED 복원/해체가 동반되는 composite라 patch로 표현되지 않는다(거부. 전환은 GUI 소관).'},S_={type:"object",description:'관계 end 부분 patch. 논리 키: multiplicity·navigable·composition. jpa 설정(cascadeTypes·fetchType·orphanRemoval·orderBy·collectionType·collectionTable·orderColumn)은 형제 클로버 방지를 위해 dotted-key로: {"jpa.orphanRemoval": true}.'};function ft(e,n){return{type:"object",properties:{kind:{const:e},...n.properties},required:["kind",...n.required],additionalProperties:!1}}const x_={"entity.add":ft("entity.add",{properties:{spec:{$ref:"#/$defs/entitySpec"}},required:["spec"]}),"entity.update":ft("entity.update",{properties:{entity:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/entityUpdatePatch"}},required:["entity","patch"]}),"entity.remove":ft("entity.remove",{properties:{entity:{$ref:"#/$defs/handle"}},required:["entity"]}),"attribute.add":ft("attribute.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/attrSpec"}},required:["entity","spec"]}),"attribute.update":ft("attribute.update",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/attrUpdatePatch"},embeddableOverrides:{$ref:"#/$defs/embeddableOverrides"}},required:["entity","attribute","patch"]}),"attribute.remove":ft("attribute.remove",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"}},required:["entity","attribute"]}),"association.add":ft("association.add",{properties:{spec:{$ref:"#/$defs/assocSpec"}},required:["spec"]}),"association.remove":ft("association.remove",{properties:{association:{$ref:"#/$defs/assocHandle"}},required:["association"]}),"association.update":ft("association.update",{properties:{association:{$ref:"#/$defs/assocHandle"},patch:{$ref:"#/$defs/assocUpdatePatch"}},required:["association","patch"]}),"associationEnd.update":ft("associationEnd.update",{properties:{association:{$ref:"#/$defs/assocHandle"},end:{type:"string",enum:["from","to"],description:"from=부모(end1), to=자식(end2)."},patch:{$ref:"#/$defs/assocEndUpdatePatch"}},required:["association","end","patch"]}),"index.add":ft("index.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/indexSpec"}},required:["entity","spec"]}),"index.update":ft("index.update",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/indexUpdatePatch"}},required:["entity","index","patch"]}),"index.remove":ft("index.remove",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"}},required:["entity","index"]}),"operation.add":ft("operation.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/operationSpec"}},required:["entity","spec"]}),"operation.update":ft("operation.update",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/operationUpdatePatch"}},required:["entity","operation","patch"]}),"operation.remove":ft("operation.remove",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"}},required:["entity","operation"]}),"attribute.reorder":ft("attribute.reorder",{properties:{entity:{$ref:"#/$defs/handle"},order:{type:"array",items:{$ref:"#/$defs/handle"},minItems:1}},required:["entity","order"]}),"operation.reorder":ft("operation.reorder",{properties:{entity:{$ref:"#/$defs/handle"},operations:{type:"array",items:{$ref:"#/$defs/nameHandle"},minItems:1}},required:["entity","operations"]}),"group.add":ft("group.add",{properties:{spec:{$ref:"#/$defs/groupSpec"}},required:["spec"]}),"group.update":ft("group.update",{properties:{group:{$ref:"#/$defs/groupHandle"},patch:{$ref:"#/$defs/groupUpdatePatch"}},required:["group","patch"]}),"group.remove":ft("group.remove",{properties:{group:{$ref:"#/$defs/groupHandle"}},required:["group"]}),"group.addMember":ft("group.addMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]}),"group.removeMember":ft("group.removeMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]})},R_={type:"object",description:"그룹 지정 핸들. 패키지명(packageName) 우선, 이름(name) 보조 — 이름은 다국어라 어느 로케일 값이든 일치하면 매칭. 'modelId'는 모호 해소 전용(group-ambiguous 후보를 사용자에게 확인받은 뒤).",properties:{ref:{type:"string",description:"매칭할 패키지명/이름. by:'modelId'면 modelId 원문."},by:{type:"string",enum:["packageName","name","modelId"],description:"매칭 키 고정(미지정 시 packageName → name)."}},required:["ref"],additionalProperties:!1},A_={type:"object",description:"그룹 부분 patch. 멤버 변경은 group.addMember/removeMember로(배열 통째 교체는 동시 편집이 서로를 덮는다).",properties:{name:{...zn,description:"그룹 논리명(다국어)."},packageName:{type:"string"},description:{type:"string"},excludeDDLGeneration:{type:"boolean"}},additionalProperties:!1},Gu={anyOf:Nu.map(e=>x_[e])},$_={type:"object",description:"엔티티 모델을 생성·수정·삭제할 때 호출한다. ops는 사람 핸들(엔티티 물리명/논리명, 속성명)로 지정하며 서버가 modelId로 해소한다. 모호하면 에러로 후보를 돌려주니 리소스로 현재 모델을 먼저 읽어 핸들을 확정하라.",properties:{ops:{type:"array",items:{$ref:"#/$defs/symbolicOp"}}},required:["ops"],additionalProperties:!1,$defs:{handle:ju,nameHandle:m_,groupHandle:R_,assocHandle:f_,entitySpec:p_,serialization:h_,attrSpec:y_,embeddableOverrides:g_,assocSpec:b_,indexSpec:__,operationSpec:k_,groupSpec:E_,entityUpdatePatch:C_,attrUpdatePatch:N_,assocUpdatePatch:w_,assocEndUpdatePatch:S_,indexUpdatePatch:I_,operationUpdatePatch:v_,groupUpdatePatch:A_,symbolicOp:Gu}};function T_(e,n,o,i={}){const a=i.mkClientOpId??Pe,r=new Set;for(const s of o)s.casUnit==="logical"&&s.containerRef&&r.add(s.containerRef);const l={};if(r.size){l.revs={};for(const s of r)l.revs[s]=n[s]??0}return{diagramId:e,ops:o,cas:l,origin:i.origin??"agent",clientOpId:a()}}const Yu={location:{x:0,y:0},size:{width:220,height:140}};function qu(e){return{modelId:e.modelId,physicalName:e.physicalName,logicalName:e.logicalName,dataType:e.dataType,length:e.length,scale:e.scale,unique:e.unique,autoIncrement:e.autoIncrement,updatable:e.updatable,insertable:e.insertable,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}const M_=/^[-=_*~\s]{3,}$/;function V_(e){return e.attrType&&e.attrType!=="NORMAL"||!M_.test(e.name??"")?!1:!(e.dbAttrs??[]).some(n=>n.physicalName||n.dataType)}function B_(e){return e.type===_n&&e.customType==="java.util.Currency"?{type:"Currency",customType:void 0}:{type:e.type,customType:e.customType}}function D_(e,n){if(e.attrType==="DIVIDER"||V_(e))return{modelId:e.modelId,name:e.attrType==="DIVIDER"?e.name:"",type:"",attrType:"DIVIDER",identifier:!1,notNull:!1,order:e.order??n,dbAttrs:[]};const o=B_(e);return{modelId:e.modelId,name:e.name,type:o.type,customType:o.customType,attrType:e.attrType,identifier:e.identifier,notNull:e.notNull,transient:e.transient_,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:e.order??n,dbAttrs:e.dbAttrs.map(qu)}}function O_(e,n){const{modelId:o,name:i,visibility:a,sourceCode:r,description:l,order:s,personalInfoAttributeType:c,style:d,...u}=e;return{modelId:o,name:i,visibility:a,sourceCode:r,description:l?{ko:l}:void 0,order:s??n,personalInfoAttributeType:c,legacyRaw:Object.keys(u).length?u:void 0}}function L_(e){return{modelId:e.modelId,name:e.name,unique:e.unique,description:e.description,parameters:e.parameters,columns:e.indexColumns.map(n=>({columnRef:n.targetColumn.refId,descending:n.descending}))}}function P_(e){var n,o;return{modelId:e.modelId,name:e.name,stereotype:e.stereotype,packageName:e.packageName,superClass:e.superClass,schema:e.schema,description:e.description,abstractClass:e.abstractClass,hasPersonalInfo:e.hasPersonalInfo,declarationOfInterfaces:e.declarationOfInterfaces,attributes:e.attributes.map(D_),operations:(n=e.operations)==null?void 0:n.map(O_),indexes:(o=e.indexes)==null?void 0:o.map(L_),jpaAttrs:e.jpaAttrs,table:e.dbAttrs?{physicalName:e.dbAttrs.physicalName,logicalName:e.dbAttrs.logicalName}:void 0}}function z_(e){const n={};for(const i of e.attributes)i.style&&(n[i.modelId]=i.style);const o={};for(const i of e.operations??[])i.style&&(o[i.modelId]=i.style);return{entityRef:e.modelId,geo:e.geo??{...Yu},style:e.style,attributeStyles:Object.keys(n).length?n:void 0,operationStyles:Object.keys(o).length?o:void 0,collapsed:e.collapsed,locked:e.locked}}function Wu(e){return e.jpaAttribute?{fetchType:e.jpaAttribute.fetchType,cascadeTypes:e.jpaAttribute.cascadeTypes,orphanRemoval:e.jpaAttribute.orphanRemoval,orderBy:e.jpaAttribute.orderBy,collectionType:e.jpaAttribute.collectionType,collectionTable:e.jpaAttribute.collectionTable,orderColumn:e.jpaAttribute.orderColumn}:void 0}function Ul(e){var n;return{entityRef:e.endModel.refId,multiplicity:e.multiplicity,navigable:e.navigable,composition:e.composition,attributeRef:(n=e.attribute)==null?void 0:n.modelId,jpa:Wu(e)}}function F_(e){if(e.end1.endModel.refId===e.end2.endModel.refId)return;const n=o=>Hl(o)&&(o==null?void 0:o.identifier)===!0;return n(e.end1.attribute)||n(e.end2.attribute)?!0:void 0}function U_(e){var i,a;const n={modelId:e.modelId,description:e.description,identifying:F_(e),end1:Ul(e.end1),end2:Ul(e.end2)},o={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:(i=e.end1.attribute)==null?void 0:i.modelId,targetColumnRef:(a=e.end2.attribute)==null?void 0:a.modelId,style:e.style};return{assoc:n,layout:o}}function Hl(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("RELATION")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function Ju(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("EMBED")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function Xu(e){var o;const n=e.attribute;return(n==null?void 0:n.attrType)==="EMBED_OWN"&&(((o=n.dbAttrs)==null?void 0:o.length)??0)===0&&(e.multiplicity==="ZERO_OR_MORE_INSTANCES"||e.multiplicity==="ONE_OR_MORE_INSTANCES")}function Zu(e,n){return{modelId:e.modelId,name:e.name??"",type:e.type??"",customType:e.customType,attrType:e.attrType??"RELATION_OWN",identifier:e.identifier??!1,notNull:e.notNull??!1,transient:e.transient_,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:n,dbAttrs:(e.dbAttrs??[]).map(qu)}}function H_(e,n,o){var y,k;const i=Hl(e.end1.attribute),a=Hl(e.end2.attribute);if(i===a)return U_(e);const r=i?e.end1:e.end2,l=i?e.end2:e.end1,s=r.attribute,c=(k=(y=s.dbAttrs)==null?void 0:y[0])==null?void 0:k.targetModelId,d=c?o.get(c):void 0,u=n.get(l.endModel.refId),m=u?u.attributes.reduce((S,T)=>Math.max(S,T.order),-1)+1:s.order??0,p={...Zu(s,m),attrType:"RELATION_OWN",derivedFrom:d?{associationRef:e.modelId,sourceAttributeRef:d}:void 0};u&&u.attributes.push(p);const f=n.get(r.endModel.refId),h=l.attribute;let g;if(h&&f&&r.navigable){const S=ca(l.multiplicity);g={modelId:h.modelId??crypto.randomUUID(),name:to(h.name??ua((u==null?void 0:u.name)??l.endModel.refId,S),new Set(f.attributes.map(T=>T.name))),type:(u==null?void 0:u.name)??l.endModel.refId,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:f.attributes.reduce((T,O)=>Math.max(T,O.order),-1)+1,dbAttrs:[]},f.attributes.push(g)}const b=(S,T)=>({entityRef:S.endModel.refId,multiplicity:S.multiplicity,navigable:S.navigable,composition:S.composition,attributeRef:T?g==null?void 0:g.modelId:p.modelId,jpa:Wu(S)}),_=r.endModel.refId===l.endModel.refId,E={modelId:e.modelId,description:e.description,identifying:!_&&p.identifier===!0?!0:void 0,end1:b(e.end1,i),end2:b(e.end2,a)},N={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:i?d:p.modelId,targetColumnRef:i?p.modelId:d,style:e.style};return{assoc:E,layout:N}}function j_(e,n){const o=e.targetModelId?n.get(e.targetModelId):void 0;return{modelId:e.modelId,physicalName:e.physicalName||(o==null?void 0:o.physicalName)||"",logicalName:e.logicalName??(o==null?void 0:o.logicalName),dataType:e.dataType||(o==null?void 0:o.dataType)||"",length:e.length??(o==null?void 0:o.length),scale:e.scale??(o==null?void 0:o.scale),unique:e.unique??(o==null?void 0:o.unique),autoIncrement:e.autoIncrement??(o==null?void 0:o.autoIncrement),updatable:e.updatable??(o==null?void 0:o.updatable),insertable:e.insertable??(o==null?void 0:o.insertable)}}function K_(e,n,o){var h;const i=((h=e.end1.attribute)==null?void 0:h.attrType)==="EMBED_OWN",a=i?e.end1:e.end2,r=i?e.end2:e.end1,l=a.attribute,s=n.get(r.endModel.refId),c=s?s.attributes.reduce((g,b)=>Math.max(g,b.order),-1)+1:l.order??0,d={...Zu(l,c),attrType:l.attrType??"EMBED_OWN",dbAttrs:(l.dbAttrs??[]).map(g=>j_(g,o)),embedded:{associationRef:e.modelId,embeddableRef:a.endModel.refId}};s&&s.attributes.push(d);const u=g=>({...Ul(g),legacyEmbedRaw:g.attribute}),m={modelId:e.modelId,description:e.description,end1:u(e.end1),end2:u(e.end2)},p=!i,f={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:p?d.modelId:void 0,targetColumnRef:p?void 0:d.modelId,style:e.style};return{assoc:m,layout:f}}function G_(e,n){var i,a,r,l;const o=[];for(const s of n){const c=(a=(i=s.end1)==null?void 0:i.endModel)==null?void 0:a.refId,d=(l=(r=s.end2)==null?void 0:r.endModel)==null?void 0:l.refId,u=c===e?d:c;!u||u===e||o.push({targetRef:u,waypoints:s.locations??[]})}return o}function Qu(e,n={x:0,y:0}){const{modelId:o,memo:i,geo:a,style:r,connections:l,ownedConnections:s,...c}=e;let d=l;if(!d&&Array.isArray(s)){const u=G_(o,s);u.length&&(d=u)}return{modelId:o,memo:i,geo:{location:{x:a.location.x+n.x,y:a.location.y+n.y},size:a.size},style:r,connections:d,legacyRaw:Object.keys(c).length?c:void 0}}function em(e,n,o){if(!(o!=null&&o.length))return;const i=new Map(e.map(l=>[l.modelId,l])),a=new Map(n.map(l=>[l.modelId,l])),r=(l,s)=>{var c;return!!s&&!!((c=i.get(l??""))!=null&&c.attributes.some(d=>d.modelId===s))};for(const l of o){const s=a.get(l.associationRef);s&&(l.sourceColumnRef&&!r(s.end1.entityRef,l.sourceColumnRef)&&(l.sourceColumnRef=void 0),l.targetColumnRef&&!r(s.end2.entityRef,l.targetColumnRef)&&(l.targetColumnRef=void 0))}}function Y_(e,n){const o=new Map(e.map(i=>[i.modelId,i]));for(const i of n){if(i.end1.navigable!==!0)continue;const a=o.get(i.end1.entityRef),r=o.get(i.end2.entityRef);if(!a||!r||gt(a.stereotype)||gt(r.stereotype))continue;const l=i.end1.attributeRef?a.attributes.find(p=>p.modelId===i.end1.attributeRef):void 0;if((l==null?void 0:l.attrType)==="RELATION_REF")continue;const s=`nav:${i.modelId}`,c=a.attributes.find(p=>p.modelId===s);if((c==null?void 0:c.attrType)==="RELATION_REF"){i.end1.attributeRef=s;continue}const d=ca(i.end2.multiplicity),u=ua(r.name,d),m=to(u,new Set(a.attributes.map(p=>p.name)));a.attributes.push({modelId:s,name:m,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:a.attributes.reduce((p,f)=>Math.max(p,f.order),-1)+1,dbAttrs:[]}),i.end1.attributeRef=s}}function q_(e,n){const o=new Map(e.map(i=>[i.modelId,i]));for(const i of n){if(i.identifying===!0||i.end1.entityRef===i.end2.entityRef)continue;const a=o.get(i.end1.entityRef),r=o.get(i.end2.entityRef);if(!a||!r||gt(a.stereotype)||gt(r.stereotype))continue;const l=r.attributes.find(s=>s.modelId===i.end2.attributeRef);l&&l.attrType.startsWith("RELATION")&&l.dbAttrs.length>0&&l.identifier===!0&&(i.identifying=!0)}}function tm(e,n){var i;const o=new Map(e.map(a=>[a.modelId,a]));for(const a of n){const r=o.get(a.end2.entityRef);if(!r)continue;const l=o.get(a.end1.entityRef);if(l&&gt(l.stereotype))continue;const s=a.end1.entityRef===a.end2.entityRef,c=a.identifying===!0||!s&&!Dc(a.end1.multiplicity);for(const d of r.attributes)!d.attrType.startsWith("RELATION")||d.dbAttrs.length===0||!(((i=d.derivedFrom)==null?void 0:i.associationRef)===a.modelId||!d.derivedFrom&&d.modelId===a.end2.attributeRef)||(d.notNull=c)}}function nm(e){const n=JSON.parse(JSON.stringify(e));return(n.schemaVersion??1)>=2&&"logical"in n?W_(n):J_(n)}function W_(e){const n=e.id??e.logical.modelId??"",o={},i=m=>{const{rev:p,...f}=m;return p!=null&&(o[m.modelId]=p),f},a=e.logical.entities.map(i),r=e.logical.associations.map(i),l=e.logical.groups.map(i);Y_(a,r),q_(a,r),tm(a,r);const{version:s,...c}=e.layout;em(a,r,c.associationLayouts);const d={logical:{modelId:e.logical.modelId??n,packageName:e.logical.packageName,entities:a,associations:r,groups:l},layout:{...c,diagramId:c.diagramId??n,logicalModelRef:c.logicalModelRef??n}},u={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion,opWriteEnabled:e.opWriteEnabled,referenceOnly:e.referenceOnly,revSeed:{revs:o,layoutVersion:s??0,logicalVersion:e.logical.version??0}};return{state:d,meta:u}}function J_(e){var _,E;const n=e.id??"",o=[],i=[],a=[],r=[],l=[],s=[],c=[],d=(N,y)=>{o.push(P_(N));const k=z_(N);k.geo={location:{x:k.geo.location.x+y.x,y:k.geo.location.y+y.y},size:k.geo.size},i.push(k);for(const S of N.ownedAssociations??[])c.push(S)},u={x:0,y:0};for(const N of e.entities??[])d(N,u);const m=[];for(const N of e.groups??[]){const y=N.entities??[];l.push({modelId:N.modelId,name:N.name,description:N.description,packageName:N.packageName,excludeDDLGeneration:N.excludeDDLGeneration??!1,memberEntityRefs:y.map(S=>S.modelId)});const k=((_=N.geo)==null?void 0:_.location)??u;if(N.geo){const S=(N.notes??[]).map(T=>T.modelId);s.push({groupRef:N.modelId,geo:N.geo,style:N.style,locked:N.locked,memberNoteRefs:S.length?S:void 0})}for(const S of y)d(S,k);for(const S of N.notes??[])m.push(Qu(S,k))}const p=new Map(o.map(N=>[N.modelId,N])),f=new Map,h=new Map;for(const N of o)for(const y of N.attributes)for(const k of y.dbAttrs)f.set(k.modelId,y.modelId),h.set(k.modelId,k);for(const N of c)for(const y of[N.end1,N.end2]){const k=y.attribute;if(k&&(((E=k.dbAttrs)==null?void 0:E.length)??0)>0)for(const S of k.dbAttrs)S.modelId&&f.set(S.modelId,k.modelId)}for(const N of c){const y=Ju(N.end1.attribute),k=Ju(N.end2.attribute),S=Xu(N.end1)||Xu(N.end2),{assoc:T,layout:O}=y!==k||S?K_(N,p,h):H_(N,p,f);a.push(T),r.push(O)}em(o,a,r),Id(o),tm(o,a);const g={logical:{modelId:n,packageName:e.packageName,entities:o,associations:a,groups:l},layout:{diagramId:n,logicalModelRef:n,canvasSize:e.size,entityLayouts:i,associationLayouts:r,groupLayouts:s,notes:[...(e.notes??[]).map(N=>Qu(N)),...m]}},b={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion??1};return{state:g,meta:b}}function om(e){return{modelId:e.modelId,physicalName:e.physicalName,logicalName:e.logicalName,dataType:e.dataType,length:e.length,scale:e.scale,unique:e.unique,autoIncrement:e.autoIncrement,updatable:e.updatable,insertable:e.insertable,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}function X_(e,n){return{modelId:e.modelId,name:e.name,type:e.type,customType:e.customType,attrType:e.attrType,identifier:e.identifier,notNull:e.notNull,transient_:e.transient,naturalId:e.naturalId,naturalIdMutable:e.naturalIdMutable,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,defaultValue:e.defaultValue,personalInfoAttributeType:e.personalInfoAttributeType,order:e.order,dbAttrs:e.dbAttrs.map(om),style:n}}function Z_(e,n){var o;return{...e.legacyRaw,modelId:e.modelId,name:e.name,visibility:e.visibility,sourceCode:e.sourceCode,description:(o=e.description)==null?void 0:o.ko,order:e.order,personalInfoAttributeType:e.personalInfoAttributeType,style:n}}function Q_(e){return{modelId:e.modelId,name:e.name,unique:e.unique,description:e.description,parameters:e.parameters,indexColumns:e.columns.map(n=>({targetColumn:{refId:n.columnRef},descending:n.descending}))}}function Fn(e,n){return{endModel:{refId:e.entityRef},multiplicity:e.multiplicity,navigable:e.navigable,composition:e.composition,jpaAttribute:e.jpa,attribute:n??(e.attributeRef?{modelId:e.attributeRef}:void 0)}}function ek(e,n){const o=n==null?void 0:n.attributes.find(i=>{var a;return i.modelId===((a=e.derivedFrom)==null?void 0:a.sourceAttributeRef)});return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_REF",identifier:e.identifier,notNull:e.notNull,transient_:e.transient,description:e.description,attributeGroup:e.attributeGroup,groupCode:e.groupCode,order:e.order,dbAttrs:e.dbAttrs.map((i,a)=>{var r;return{...om(i),targetModelId:(r=o==null?void 0:o.dbAttrs[a])==null?void 0:r.modelId}})}}function tk(e){return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_OWN",dbAttrs:[]}}function im(e,n){const o=l=>{if(!l.attributeRef)return;const s=n.logical.entities.find(c=>c.modelId===l.entityRef);return s==null?void 0:s.attributes.find(c=>c.modelId===l.attributeRef)},i=o(e.end1),a=o(e.end2),r=l=>(l==null?void 0:l.attrType)==="RELATION_OWN"?l:void 0;return(i==null?void 0:i.attrType)==="RELATION_REF"?{navEnd:e.end1,fkEnd:e.end2,navAttr:i,fk:r(a)}:(a==null?void 0:a.attrType)==="RELATION_REF"?{navEnd:e.end2,fkEnd:e.end1,navAttr:a,fk:r(i)}:null}function nk(e){const n=new Set;for(const o of e.logical.associations){const i=im(o,e);i&&(n.add(i.navAttr.modelId),i.fk&&n.add(i.fk.modelId))}return n}function ok(e){const n=new Set;for(const o of e.logical.entities)for(const i of o.attributes)i.embedded&&n.add(i.modelId);return n}function ik(e,n){return e===n||JSON.stringify(e??null)===JSON.stringify(n??null)}function ak(e,n){const o=(i,a)=>i===a?void 0:i;return{modelId:e.modelId,targetModelId:n==null?void 0:n.modelId,physicalName:e.physicalName===((n==null?void 0:n.physicalName)??"")?"":e.physicalName,logicalName:ik(e.logicalName,n==null?void 0:n.logicalName)?void 0:e.logicalName,dataType:e.dataType===((n==null?void 0:n.dataType)??"")?"":e.dataType,length:o(e.length,n==null?void 0:n.length),scale:o(e.scale,n==null?void 0:n.scale),unique:o(e.unique,n==null?void 0:n.unique),autoIncrement:o(e.autoIncrement,n==null?void 0:n.autoIncrement),updatable:o(e.updatable,n==null?void 0:n.updatable),insertable:o(e.insertable,n==null?void 0:n.insertable)}}function rk(e,n,o){let i;for(const m of n.logical.entities){const p=m.attributes.find(f=>{var h;return((h=f.embedded)==null?void 0:h.associationRef)===e.modelId});if(p){i=p;break}}if(!i)return;const a=i.embedded.embeddableRef,r=n.logical.entities.find(m=>m.modelId===a);if(!r)return;const l=r.attributes.flatMap(m=>m.dbAttrs),s={modelId:i.modelId,name:i.name,type:i.type,attrType:i.attrType,identifier:i.identifier,notNull:i.notNull,transient_:i.transient,description:i.description,attributeGroup:i.attributeGroup,groupCode:i.groupCode,order:i.order,dbAttrs:i.dbAttrs.map((m,p)=>ak(m,l[p]))},c=e.end1.entityRef===a,d=c?e.end2:e.end1,u=d.attributeRef?{modelId:d.attributeRef,attrType:"EMBED_REF",dbAttrs:[]}:void 0;return{...o,end1:Fn(e.end1,c?s:u),end2:Fn(e.end2,c?u:s)}}function lk(e,n,o){const i={modelId:e.modelId,description:e.description,locations:(o==null?void 0:o.waypoints)??[],style:o==null?void 0:o.style};if(e.end1.legacyEmbedRaw||e.end2.legacyEmbedRaw)return{...i,end1:Fn(e.end1,e.end1.legacyEmbedRaw),end2:Fn(e.end2,e.end2.legacyEmbedRaw)};const a=rk(e,n,i);if(a)return a;const r=im(e,n);if(r){const l=n.logical.entities.find(d=>d.modelId===r.navEnd.entityRef),s=r.fk?ek(r.fk,l):void 0,c=tk(r.navAttr);return{...i,end1:Fn(e.end1,r.navEnd===e.end1?s:c),end2:Fn(e.end2,r.navEnd===e.end2?s:c)}}return{...i,end1:Fn(e.end1),end2:Fn(e.end2)}}function am(e,n,o,i,a={x:0,y:0}){var u,m;const r=n.layout.entityLayouts.find(p=>p.entityRef===e.modelId),l=n.logical.associations.filter(p=>p.end1.entityRef===e.modelId),s=p=>n.layout.associationLayouts.find(f=>f.associationRef===p),c=(r==null?void 0:r.geo)??{...Yu},d={location:{x:c.location.x-a.x,y:c.location.y-a.y},size:c.size};return{modelId:e.modelId,name:e.name,stereotype:e.stereotype,packageName:e.packageName,superClass:e.superClass,schema:e.schema,description:e.description,abstractClass:e.abstractClass,hasPersonalInfo:e.hasPersonalInfo,declarationOfInterfaces:e.declarationOfInterfaces,attributes:e.attributes.filter(p=>!o.has(p.modelId)&&!i.has(p.modelId)).map(p=>{var f;return X_(p,(f=r==null?void 0:r.attributeStyles)==null?void 0:f[p.modelId])}),operations:(u=e.operations)==null?void 0:u.map(p=>{var f;return Z_(p,(f=r==null?void 0:r.operationStyles)==null?void 0:f[p.modelId])}),ownedAssociations:l.map(p=>lk(p,n,s(p.modelId))),indexes:(m=e.indexes)==null?void 0:m.map(Q_),jpaAttrs:e.jpaAttrs,dbAttrs:e.table?{physicalName:e.table.physicalName,logicalName:e.table.logicalName}:void 0,geo:d,style:r==null?void 0:r.style,collapsed:r==null?void 0:r.collapsed,locked:r==null?void 0:r.locked}}function sk(e,n,o,i){const a=n.layout.groupLayouts.find(c=>c.groupRef===e.modelId),r=e.memberEntityRefs.map(c=>n.logical.entities.find(d=>d.modelId===c)).filter(c=>!!c),l=(a==null?void 0:a.geo.location)??{x:0,y:0},s=((a==null?void 0:a.memberNoteRefs)??[]).map(c=>n.layout.notes.find(d=>d.modelId===c)).filter(c=>!!c).map(c=>rm(c,l));return{modelId:e.modelId,name:e.name,description:e.description,packageName:e.packageName,excludeDDLGeneration:e.excludeDDLGeneration,entities:r.map(c=>am(c,n,o,i,l)),notes:s.length?s:void 0,geo:a==null?void 0:a.geo,style:a==null?void 0:a.style,locked:a==null?void 0:a.locked}}function rm(e,n={x:0,y:0}){return{...e.legacyRaw,modelId:e.modelId,memo:e.memo,geo:{location:{x:e.geo.location.x-n.x,y:e.geo.location.y-n.y},size:e.geo.size},style:e.style,connections:e.connections}}function ck(e,n={}){const o=new Set(e.logical.groups.flatMap(s=>s.memberEntityRefs)),i=e.logical.entities.filter(s=>!o.has(s.modelId)),a=nk(e),r=ok(e),l=new Set(e.layout.groupLayouts.flatMap(s=>s.memberNoteRefs??[]));return{id:n.id,diagramVersion:n.diagramVersion,version:n.version,size:n.size??e.layout.canvasSize,packageName:n.packageName??e.logical.packageName,entities:i.map(s=>am(s,e,a,r)),groups:e.logical.groups.map(s=>sk(s,e,a,r)),notes:e.layout.notes.filter(s=>!l.has(s.modelId)).map(s=>rm(s))}}function dk(e,n={}){var a,r,l;const o=((a=n.revSeed)==null?void 0:a.revs)??{},i=s=>({...s,rev:o[s.modelId]??0});return{id:n.id,schemaVersion:2,opWriteEnabled:n.opWriteEnabled,referenceOnly:n.referenceOnly,version:n.version,diagramVersion:n.diagramVersion,packageName:n.packageName,size:n.size,logical:{version:((r=n.revSeed)==null?void 0:r.logicalVersion)??0,modelId:e.logical.modelId,packageName:e.logical.packageName,entities:e.logical.entities.map(i),associations:e.logical.associations.map(i),groups:e.logical.groups.map(i)},layout:{...e.layout,version:((l=n.revSeed)==null?void 0:l.layoutVersion)??0}}}const uk=["notNull"];function mk(e){var u;const n=()=>({navAdds:0,navRefPatches:0,identifyingPatches:0,attributeFieldPatches:0,attributeFieldsByName:{}});if((e.schemaVersion??1)<2||!("logical"in e))return{ops:[],revs:{},summary:n()};const o=e,{state:i,meta:a}=nm(e),r=((u=a.revSeed)==null?void 0:u.revs)??{},l=[],s=n(),c=new Map(o.logical.entities.map(m=>[m.modelId,new Map(m.attributes.map(p=>[p.modelId,p]))]));for(const m of i.logical.entities){const p=c.get(m.modelId);if(p)for(const f of m.attributes){const h=p.get(f.modelId);if(!h){l.push({kind:"attribute.add",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,value:f}),s.navAdds++;continue}const g={};for(const b of uk)f[b]===!0!=(h[b]===!0)&&(g[b]=f[b],s.attributeFieldsByName[b]=(s.attributeFieldsByName[b]??0)+1);Object.keys(g).length!==0&&(l.push({kind:"attribute.update",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,attributeRef:f.modelId,patch:g}),s.attributeFieldPatches++)}}const d=new Map(o.logical.associations.map(m=>[m.modelId,m]));for(const m of i.logical.associations){const p=d.get(m.modelId);p&&(m.end1.attributeRef&&m.end1.attributeRef!==p.end1.attributeRef&&(l.push({kind:"associationEnd.update",casUnit:"logical",containerRef:m.modelId,associationRef:m.modelId,end:"end1",patch:{attributeRef:m.end1.attributeRef}}),s.navRefPatches++),m.identifying===!0&&p.identifying!==!0&&(l.push({kind:"association.update",casUnit:"logical",containerRef:m.modelId,associationRef:m.modelId,patch:{identifying:!0}}),s.identifyingPatches++))}return{ops:l,revs:r,summary:s}}function Ni(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function wn(e){return typeof e=="function"?e():t.unref(e)}const fk=typeof window<"u"&&typeof document<"u",pk=e=>typeof e<"u",hk=Object.prototype.toString,yk=e=>hk.call(e)==="[object Object]",gk=()=>{};function bk(e,n){function o(...i){return new Promise((a,r)=>{Promise.resolve(e(()=>n.apply(this,i),{fn:n,thisArg:this,args:i})).then(a).catch(r)})}return o}const lm=e=>e();function _k(e=lm){const n=t.ref(!0);function o(){n.value=!1}function i(){n.value=!0}const a=(...r)=>{n.value&&e(...r)};return{isActive:t.readonly(n),pause:o,resume:i,eventFilter:a}}function sm(e,n=!1,o="Timeout"){return new Promise((i,a)=>{setTimeout(n?()=>a(o):i,e)})}function kk(e,n,o={}){const{eventFilter:i=lm,...a}=o;return t.watch(e,bk(i,n),a)}function jo(e,n,o={}){const{eventFilter:i,...a}=o,{eventFilter:r,pause:l,resume:s,isActive:c}=_k(i);return{stop:kk(e,n,{...a,eventFilter:r}),pause:l,resume:s,isActive:c}}function Ek(e,n={}){if(!t.isRef(e))return t.toRefs(e);const o=Array.isArray(e.value)?Array.from({length:e.value.length}):{};for(const i in e.value)o[i]=t.customRef(()=>({get(){return e.value[i]},set(a){var r;if((r=wn(n.replaceRef))!=null?r:!0)if(Array.isArray(e.value)){const s=[...e.value];s[i]=a,e.value=s}else{const s={...e.value,[i]:a};Object.setPrototypeOf(s,Object.getPrototypeOf(e.value)),e.value=s}else e.value[i]=a}}));return o}function jl(e,n=!1){function o(m,{flush:p="sync",deep:f=!1,timeout:h,throwOnTimeout:g}={}){let b=null;const E=[new Promise(N=>{b=t.watch(e,y=>{m(y)!==n&&(b==null||b(),N(y))},{flush:p,deep:f,immediate:!0})})];return h!=null&&E.push(sm(h,g).then(()=>wn(e)).finally(()=>b==null?void 0:b())),Promise.race(E)}function i(m,p){if(!t.isRef(m))return o(y=>y===m,p);const{flush:f="sync",deep:h=!1,timeout:g,throwOnTimeout:b}=p??{};let _=null;const N=[new Promise(y=>{_=t.watch([e,m],([k,S])=>{n!==(k===S)&&(_==null||_(),y(k))},{flush:f,deep:h,immediate:!0})})];return g!=null&&N.push(sm(g,b).then(()=>wn(e)).finally(()=>(_==null||_(),wn(e)))),Promise.race(N)}function a(m){return o(p=>!!p,m)}function r(m){return i(null,m)}function l(m){return i(void 0,m)}function s(m){return o(Number.isNaN,m)}function c(m,p){return o(f=>{const h=Array.from(f);return h.includes(m)||h.includes(wn(m))},p)}function d(m){return u(1,m)}function u(m=1,p){let f=-1;return o(()=>(f+=1,f>=m),p)}return Array.isArray(wn(e))?{toMatch:o,toContains:c,changed:d,changedTimes:u,get not(){return jl(e,!n)}}:{toMatch:o,toBe:i,toBeTruthy:a,toBeNull:r,toBeNaN:s,toBeUndefined:l,changed:d,changedTimes:u,get not(){return jl(e,!n)}}}function Kl(e){return jl(e)}function Nk(e){var n;const o=wn(e);return(n=o==null?void 0:o.$el)!=null?n:o}const cm=fk?window:void 0;function dm(...e){let n,o,i,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,i,a]=e,n=cm):[n,o,i,a]=e,!n)return gk;Array.isArray(o)||(o=[o]),Array.isArray(i)||(i=[i]);const r=[],l=()=>{r.forEach(u=>u()),r.length=0},s=(u,m,p,f)=>(u.addEventListener(m,p,f),()=>u.removeEventListener(m,p,f)),c=t.watch(()=>[Nk(n),wn(a)],([u,m])=>{if(l(),!u)return;const p=yk(m)?{...m}:m;r.push(...o.flatMap(f=>i.map(h=>s(u,f,h,p))))},{immediate:!0,flush:"post"}),d=()=>{c(),l()};return Ni(d),d}function wk(e){return typeof e=="function"?e:typeof e=="string"?n=>n.key===e:Array.isArray(e)?n=>e.includes(n.key):()=>!0}function um(...e){let n,o,i={};e.length===3?(n=e[0],o=e[1],i=e[2]):e.length===2?typeof e[1]=="object"?(n=!0,o=e[0],i=e[1]):(n=e[0],o=e[1]):(n=!0,o=e[0]);const{target:a=cm,eventName:r="keydown",passive:l=!1,dedupe:s=!1}=i,c=wk(n);return dm(a,r,u=>{u.repeat&&wn(s)||c(u)&&o(u)},l)}function Ik(e){return JSON.parse(JSON.stringify(e))}function Gl(e,n,o,i={}){var a,r,l;const{clone:s=!1,passive:c=!1,eventName:d,deep:u=!1,defaultValue:m,shouldEmit:p}=i,f=t.getCurrentInstance(),h=o||(f==null?void 0:f.emit)||((a=f==null?void 0:f.$emit)==null?void 0:a.bind(f))||((l=(r=f==null?void 0:f.proxy)==null?void 0:r.$emit)==null?void 0:l.bind(f==null?void 0:f.proxy));let g=d;n||(n="modelValue"),g=g||`update:${n.toString()}`;const b=N=>s?typeof s=="function"?s(N):Ik(N):N,_=()=>pk(e[n])?b(e[n]):m,E=N=>{p?p(N)&&h(g,N):h(g,N)};if(c){const N=_(),y=t.ref(N);let k=!1;return t.watch(()=>e[n],S=>{k||(k=!0,y.value=b(S),t.nextTick(()=>k=!1))}),t.watch(y,S=>{!k&&(S!==e[n]||u)&&E(S)},{deep:u}),y}else return t.computed({get(){return _()},set(N){E(N)}})}var vk={value:()=>{}};function Ma(){for(var e=0,n=arguments.length,o={},i;e<n;++e){if(!(i=arguments[e]+"")||i in o||/[\s.]/.test(i))throw new Error("illegal type: "+i);o[i]=[]}return new Va(o)}function Va(e){this._=e}function Ck(e,n){return e.trim().split(/^|\s+/).map(function(o){var i="",a=o.indexOf(".");if(a>=0&&(i=o.slice(a+1),o=o.slice(0,a)),o&&!n.hasOwnProperty(o))throw new Error("unknown type: "+o);return{type:o,name:i}})}Va.prototype=Ma.prototype={constructor:Va,on:function(e,n){var o=this._,i=Ck(e+"",o),a,r=-1,l=i.length;if(arguments.length<2){for(;++r<l;)if((a=(e=i[r]).type)&&(a=Sk(o[a],e.name)))return a;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++r<l;)if(a=(e=i[r]).type)o[a]=mm(o[a],e.name,n);else if(n==null)for(a in o)o[a]=mm(o[a],e.name,null);return this},copy:function(){var e={},n=this._;for(var o in n)e[o]=n[o].slice();return new Va(e)},call:function(e,n){if((a=arguments.length-2)>0)for(var o=new Array(a),i=0,a,r;i<a;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(n,o)},apply:function(e,n,o){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],a=0,r=i.length;a<r;++a)i[a].value.apply(n,o)}};function Sk(e,n){for(var o=0,i=e.length,a;o<i;++o)if((a=e[o]).name===n)return a.value}function mm(e,n,o){for(var i=0,a=e.length;i<a;++i)if(e[i].name===n){e[i]=vk,e=e.slice(0,i).concat(e.slice(i+1));break}return o!=null&&e.push({name:n,value:o}),e}var Yl="http://www.w3.org/1999/xhtml";const fm={svg:"http://www.w3.org/2000/svg",xhtml:Yl,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ba(e){var n=e+="",o=n.indexOf(":");return o>=0&&(n=e.slice(0,o))!=="xmlns"&&(e=e.slice(o+1)),fm.hasOwnProperty(n)?{space:fm[n],local:e}:e}function xk(e){return function(){var n=this.ownerDocument,o=this.namespaceURI;return o===Yl&&n.documentElement.namespaceURI===Yl?n.createElement(e):n.createElementNS(o,e)}}function Rk(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function pm(e){var n=Ba(e);return(n.local?Rk:xk)(n)}function Ak(){}function ql(e){return e==null?Ak:function(){return this.querySelector(e)}}function $k(e){typeof e!="function"&&(e=ql(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=new Array(l),c,d,u=0;u<l;++u)(c=r[u])&&(d=e.call(c,c.__data__,u,r))&&("__data__"in c&&(d.__data__=c.__data__),s[u]=d);return new Ft(i,this._parents)}function Tk(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Mk(){return[]}function hm(e){return e==null?Mk:function(){return this.querySelectorAll(e)}}function Vk(e){return function(){return Tk(e.apply(this,arguments))}}function Bk(e){typeof e=="function"?e=Vk(e):e=hm(e);for(var n=this._groups,o=n.length,i=[],a=[],r=0;r<o;++r)for(var l=n[r],s=l.length,c,d=0;d<s;++d)(c=l[d])&&(i.push(e.call(c,c.__data__,d,l)),a.push(c));return new Ft(i,a)}function ym(e){return function(){return this.matches(e)}}function gm(e){return function(n){return n.matches(e)}}var Dk=Array.prototype.find;function Ok(e){return function(){return Dk.call(this.children,e)}}function Lk(){return this.firstElementChild}function Pk(e){return this.select(e==null?Lk:Ok(typeof e=="function"?e:gm(e)))}var zk=Array.prototype.filter;function Fk(){return Array.from(this.children)}function Uk(e){return function(){return zk.call(this.children,e)}}function Hk(e){return this.selectAll(e==null?Fk:Uk(typeof e=="function"?e:gm(e)))}function jk(e){typeof e!="function"&&(e=ym(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=[],c,d=0;d<l;++d)(c=r[d])&&e.call(c,c.__data__,d,r)&&s.push(c);return new Ft(i,this._parents)}function bm(e){return new Array(e.length)}function Kk(){return new Ft(this._enter||this._groups.map(bm),this._parents)}function Da(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}Da.prototype={constructor:Da,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,n){return this._parent.insertBefore(e,n)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Gk(e){return function(){return e}}function Yk(e,n,o,i,a,r){for(var l=0,s,c=n.length,d=r.length;l<d;++l)(s=n[l])?(s.__data__=r[l],i[l]=s):o[l]=new Da(e,r[l]);for(;l<c;++l)(s=n[l])&&(a[l]=s)}function qk(e,n,o,i,a,r,l){var s,c,d=new Map,u=n.length,m=r.length,p=new Array(u),f;for(s=0;s<u;++s)(c=n[s])&&(p[s]=f=l.call(c,c.__data__,s,n)+"",d.has(f)?a[s]=c:d.set(f,c));for(s=0;s<m;++s)f=l.call(e,r[s],s,r)+"",(c=d.get(f))?(i[s]=c,c.__data__=r[s],d.delete(f)):o[s]=new Da(e,r[s]);for(s=0;s<u;++s)(c=n[s])&&d.get(p[s])===c&&(a[s]=c)}function Wk(e){return e.__data__}function Jk(e,n){if(!arguments.length)return Array.from(this,Wk);var o=n?qk:Yk,i=this._parents,a=this._groups;typeof e!="function"&&(e=Gk(e));for(var r=a.length,l=new Array(r),s=new Array(r),c=new Array(r),d=0;d<r;++d){var u=i[d],m=a[d],p=m.length,f=Xk(e.call(u,u&&u.__data__,d,i)),h=f.length,g=s[d]=new Array(h),b=l[d]=new Array(h),_=c[d]=new Array(p);o(u,m,g,b,_,f,n);for(var E=0,N=0,y,k;E<h;++E)if(y=g[E]){for(E>=N&&(N=E+1);!(k=b[N])&&++N<h;);y._next=k||null}}return l=new Ft(l,i),l._enter=s,l._exit=c,l}function Xk(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Zk(){return new Ft(this._exit||this._groups.map(bm),this._parents)}function Qk(e,n,o){var i=this.enter(),a=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),n!=null&&(a=n(a),a&&(a=a.selection())),o==null?r.remove():o(r),i&&a?i.merge(a).order():a}function eE(e){for(var n=e.selection?e.selection():e,o=this._groups,i=n._groups,a=o.length,r=i.length,l=Math.min(a,r),s=new Array(a),c=0;c<l;++c)for(var d=o[c],u=i[c],m=d.length,p=s[c]=new Array(m),f,h=0;h<m;++h)(f=d[h]||u[h])&&(p[h]=f);for(;c<a;++c)s[c]=o[c];return new Ft(s,this._parents)}function tE(){for(var e=this._groups,n=-1,o=e.length;++n<o;)for(var i=e[n],a=i.length-1,r=i[a],l;--a>=0;)(l=i[a])&&(r&&l.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(l,r),r=l);return this}function nE(e){e||(e=oE);function n(m,p){return m&&p?e(m.__data__,p.__data__):!m-!p}for(var o=this._groups,i=o.length,a=new Array(i),r=0;r<i;++r){for(var l=o[r],s=l.length,c=a[r]=new Array(s),d,u=0;u<s;++u)(d=l[u])&&(c[u]=d);c.sort(n)}return new Ft(a,this._parents).order()}function oE(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function iE(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function aE(){return Array.from(this)}function rE(){for(var e=this._groups,n=0,o=e.length;n<o;++n)for(var i=e[n],a=0,r=i.length;a<r;++a){var l=i[a];if(l)return l}return null}function lE(){let e=0;for(const n of this)++e;return e}function sE(){return!this.node()}function cE(e){for(var n=this._groups,o=0,i=n.length;o<i;++o)for(var a=n[o],r=0,l=a.length,s;r<l;++r)(s=a[r])&&e.call(s,s.__data__,r,a);return this}function dE(e){return function(){this.removeAttribute(e)}}function uE(e){return function(){this.removeAttributeNS(e.space,e.local)}}function mE(e,n){return function(){this.setAttribute(e,n)}}function fE(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function pE(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttribute(e):this.setAttribute(e,o)}}function hE(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,o)}}function yE(e,n){var o=Ba(e);if(arguments.length<2){var i=this.node();return o.local?i.getAttributeNS(o.space,o.local):i.getAttribute(o)}return this.each((n==null?o.local?uE:dE:typeof n=="function"?o.local?hE:pE:o.local?fE:mE)(o,n))}function _m(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function gE(e){return function(){this.style.removeProperty(e)}}function bE(e,n,o){return function(){this.style.setProperty(e,n,o)}}function _E(e,n,o){return function(){var i=n.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,o)}}function kE(e,n,o){return arguments.length>1?this.each((n==null?gE:typeof n=="function"?_E:bE)(e,n,o??"")):Ko(this.node(),e)}function Ko(e,n){return e.style.getPropertyValue(n)||_m(e).getComputedStyle(e,null).getPropertyValue(n)}function EE(e){return function(){delete this[e]}}function NE(e,n){return function(){this[e]=n}}function wE(e,n){return function(){var o=n.apply(this,arguments);o==null?delete this[e]:this[e]=o}}function IE(e,n){return arguments.length>1?this.each((n==null?EE:typeof n=="function"?wE:NE)(e,n)):this.node()[e]}function km(e){return e.trim().split(/^|\s+/)}function Wl(e){return e.classList||new Em(e)}function Em(e){this._node=e,this._names=km(e.getAttribute("class")||"")}Em.prototype={add:function(e){var n=this._names.indexOf(e);n<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var n=this._names.indexOf(e);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Nm(e,n){for(var o=Wl(e),i=-1,a=n.length;++i<a;)o.add(n[i])}function wm(e,n){for(var o=Wl(e),i=-1,a=n.length;++i<a;)o.remove(n[i])}function vE(e){return function(){Nm(this,e)}}function CE(e){return function(){wm(this,e)}}function SE(e,n){return function(){(n.apply(this,arguments)?Nm:wm)(this,e)}}function xE(e,n){var o=km(e+"");if(arguments.length<2){for(var i=Wl(this.node()),a=-1,r=o.length;++a<r;)if(!i.contains(o[a]))return!1;return!0}return this.each((typeof n=="function"?SE:n?vE:CE)(o,n))}function RE(){this.textContent=""}function AE(e){return function(){this.textContent=e}}function $E(e){return function(){var n=e.apply(this,arguments);this.textContent=n??""}}function TE(e){return arguments.length?this.each(e==null?RE:(typeof e=="function"?$E:AE)(e)):this.node().textContent}function ME(){this.innerHTML=""}function VE(e){return function(){this.innerHTML=e}}function BE(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n??""}}function DE(e){return arguments.length?this.each(e==null?ME:(typeof e=="function"?BE:VE)(e)):this.node().innerHTML}function OE(){this.nextSibling&&this.parentNode.appendChild(this)}function LE(){return this.each(OE)}function PE(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function zE(){return this.each(PE)}function FE(e){var n=typeof e=="function"?e:pm(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function UE(){return null}function HE(e,n){var o=typeof e=="function"?e:pm(e),i=n==null?UE:typeof n=="function"?n:ql(n);return this.select(function(){return this.insertBefore(o.apply(this,arguments),i.apply(this,arguments)||null)})}function jE(){var e=this.parentNode;e&&e.removeChild(this)}function KE(){return this.each(jE)}function GE(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function YE(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function qE(e){return this.select(e?YE:GE)}function WE(e){return arguments.length?this.property("__data__",e):this.node().__data__}function JE(e){return function(n){e.call(this,n,this.__data__)}}function XE(e){return e.trim().split(/^|\s+/).map(function(n){var o="",i=n.indexOf(".");return i>=0&&(o=n.slice(i+1),n=n.slice(0,i)),{type:n,name:o}})}function ZE(e){return function(){var n=this.__on;if(n){for(var o=0,i=-1,a=n.length,r;o<a;++o)r=n[o],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):n[++i]=r;++i?n.length=i:delete this.__on}}}function QE(e,n,o){return function(){var i=this.__on,a,r=JE(n);if(i){for(var l=0,s=i.length;l<s;++l)if((a=i[l]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=r,a.options=o),a.value=n;return}}this.addEventListener(e.type,r,o),a={type:e.type,name:e.name,value:n,listener:r,options:o},i?i.push(a):this.__on=[a]}}function e1(e,n,o){var i=XE(e+""),a,r=i.length,l;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,d=s.length,u;c<d;++c)for(a=0,u=s[c];a<r;++a)if((l=i[a]).type===u.type&&l.name===u.name)return u.value}return}for(s=n?QE:ZE,a=0;a<r;++a)this.each(s(i[a],n,o));return this}function Im(e,n,o){var i=_m(e),a=i.CustomEvent;typeof a=="function"?a=new a(n,o):(a=i.document.createEvent("Event"),o?(a.initEvent(n,o.bubbles,o.cancelable),a.detail=o.detail):a.initEvent(n,!1,!1)),e.dispatchEvent(a)}function t1(e,n){return function(){return Im(this,e,n)}}function n1(e,n){return function(){return Im(this,e,n.apply(this,arguments))}}function o1(e,n){return this.each((typeof n=="function"?n1:t1)(e,n))}function*i1(){for(var e=this._groups,n=0,o=e.length;n<o;++n)for(var i=e[n],a=0,r=i.length,l;a<r;++a)(l=i[a])&&(yield l)}var vm=[null];function Ft(e,n){this._groups=e,this._parents=n}function wi(){return new Ft([[document.documentElement]],vm)}function a1(){return this}Ft.prototype=wi.prototype={constructor:Ft,select:$k,selectAll:Bk,selectChild:Pk,selectChildren:Hk,filter:jk,data:Jk,enter:Kk,exit:Zk,join:Qk,merge:eE,selection:a1,order:tE,sort:nE,call:iE,nodes:aE,node:rE,size:lE,empty:sE,each:cE,attr:yE,style:kE,property:IE,classed:xE,text:TE,html:DE,raise:LE,lower:zE,append:FE,insert:HE,remove:KE,clone:qE,datum:WE,on:e1,dispatch:o1,[Symbol.iterator]:i1};function Wt(e){return typeof e=="string"?new Ft([[document.querySelector(e)]],[document.documentElement]):new Ft([[e]],vm)}function r1(e){let n;for(;n=e.sourceEvent;)e=n;return e}function sn(e,n){if(e=r1(e),n===void 0&&(n=e.currentTarget),n){var o=n.ownerSVGElement||n;if(o.createSVGPoint){var i=o.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(n.getScreenCTM().inverse()),[i.x,i.y]}if(n.getBoundingClientRect){var a=n.getBoundingClientRect();return[e.clientX-a.left-n.clientLeft,e.clientY-a.top-n.clientTop]}}return[e.pageX,e.pageY]}const l1={passive:!1},Ii={capture:!0,passive:!1};function Jl(e){e.stopImmediatePropagation()}function Go(e){e.preventDefault(),e.stopImmediatePropagation()}function Cm(e){var n=e.document.documentElement,o=Wt(e).on("dragstart.drag",Go,Ii);"onselectstart"in n?o.on("selectstart.drag",Go,Ii):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Sm(e,n){var o=e.document.documentElement,i=Wt(e).on("dragstart.drag",null);n&&(i.on("click.drag",Go,Ii),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in o?i.on("selectstart.drag",null):(o.style.MozUserSelect=o.__noselect,delete o.__noselect)}const Oa=e=>()=>e;function Xl(e,{sourceEvent:n,subject:o,target:i,identifier:a,active:r,x:l,y:s,dx:c,dy:d,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:o,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:l,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:u}})}Xl.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function s1(e){return!e.ctrlKey&&!e.button}function c1(){return this.parentNode}function d1(e,n){return n??{x:e.x,y:e.y}}function u1(){return navigator.maxTouchPoints||"ontouchstart"in this}function m1(){var e=s1,n=c1,o=d1,i=u1,a={},r=Ma("start","drag","end"),l=0,s,c,d,u,m=0;function p(y){y.on("mousedown.drag",f).filter(i).on("touchstart.drag",b).on("touchmove.drag",_,l1).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(y,k){if(!(u||!e.call(this,y,k))){var S=N(this,n.call(this,y,k),y,k,"mouse");S&&(Wt(y.view).on("mousemove.drag",h,Ii).on("mouseup.drag",g,Ii),Cm(y.view),Jl(y),d=!1,s=y.clientX,c=y.clientY,S("start",y))}}function h(y){if(Go(y),!d){var k=y.clientX-s,S=y.clientY-c;d=k*k+S*S>m}a.mouse("drag",y)}function g(y){Wt(y.view).on("mousemove.drag mouseup.drag",null),Sm(y.view,d),Go(y),a.mouse("end",y)}function b(y,k){if(e.call(this,y,k)){var S=y.changedTouches,T=n.call(this,y,k),O=S.length,A,V;for(A=0;A<O;++A)(V=N(this,T,y,k,S[A].identifier,S[A]))&&(Jl(y),V("start",y,S[A]))}}function _(y){var k=y.changedTouches,S=k.length,T,O;for(T=0;T<S;++T)(O=a[k[T].identifier])&&(Go(y),O("drag",y,k[T]))}function E(y){var k=y.changedTouches,S=k.length,T,O;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),T=0;T<S;++T)(O=a[k[T].identifier])&&(Jl(y),O("end",y,k[T]))}function N(y,k,S,T,O,A){var V=r.copy(),C=sn(A||S,k),R,$,w;if((w=o.call(y,new Xl("beforestart",{sourceEvent:S,target:p,identifier:O,active:l,x:C[0],y:C[1],dx:0,dy:0,dispatch:V}),T))!=null)return R=w.x-C[0]||0,$=w.y-C[1]||0,function I(v,B,M){var x=C,P;switch(v){case"start":a[O]=I,P=l++;break;case"end":delete a[O],--l;case"drag":C=sn(M||B,k),P=l;break}V.call(v,y,new Xl(v,{sourceEvent:B,subject:w,target:p,identifier:O,active:P,x:C[0]+R,y:C[1]+$,dx:C[0]-x[0],dy:C[1]-x[1],dispatch:V}),T)}}return p.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Oa(!!y),p):e},p.container=function(y){return arguments.length?(n=typeof y=="function"?y:Oa(y),p):n},p.subject=function(y){return arguments.length?(o=typeof y=="function"?y:Oa(y),p):o},p.touchable=function(y){return arguments.length?(i=typeof y=="function"?y:Oa(!!y),p):i},p.on=function(){var y=r.on.apply(r,arguments);return y===r?p:y},p.clickDistance=function(y){return arguments.length?(m=(y=+y)*y,p):Math.sqrt(m)},p}function Zl(e,n,o){e.prototype=n.prototype=o,o.constructor=e}function xm(e,n){var o=Object.create(e.prototype);for(var i in n)o[i]=n[i];return o}function vi(){}var Ci=.7,La=1/Ci,Yo="\\s*([+-]?\\d+)\\s*",Si="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",cn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",f1=/^#([0-9a-f]{3,8})$/,p1=new RegExp(`^rgb\\(${Yo},${Yo},${Yo}\\)$`),h1=new RegExp(`^rgb\\(${cn},${cn},${cn}\\)$`),y1=new RegExp(`^rgba\\(${Yo},${Yo},${Yo},${Si}\\)$`),g1=new RegExp(`^rgba\\(${cn},${cn},${cn},${Si}\\)$`),b1=new RegExp(`^hsl\\(${Si},${cn},${cn}\\)$`),_1=new RegExp(`^hsla\\(${Si},${cn},${cn},${Si}\\)$`),Rm={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Zl(vi,mo,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Am,formatHex:Am,formatHex8:k1,formatHsl:E1,formatRgb:$m,toString:$m});function Am(){return this.rgb().formatHex()}function k1(){return this.rgb().formatHex8()}function E1(){return Dm(this).formatHsl()}function $m(){return this.rgb().formatRgb()}function mo(e){var n,o;return e=(e+"").trim().toLowerCase(),(n=f1.exec(e))?(o=n[1].length,n=parseInt(n[1],16),o===6?Tm(n):o===3?new Dt(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):o===8?Pa(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):o===4?Pa(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|n&240,((n&15)<<4|n&15)/255):null):(n=p1.exec(e))?new Dt(n[1],n[2],n[3],1):(n=h1.exec(e))?new Dt(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=y1.exec(e))?Pa(n[1],n[2],n[3],n[4]):(n=g1.exec(e))?Pa(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=b1.exec(e))?Bm(n[1],n[2]/100,n[3]/100,1):(n=_1.exec(e))?Bm(n[1],n[2]/100,n[3]/100,n[4]):Rm.hasOwnProperty(e)?Tm(Rm[e]):e==="transparent"?new Dt(NaN,NaN,NaN,0):null}function Tm(e){return new Dt(e>>16&255,e>>8&255,e&255,1)}function Pa(e,n,o,i){return i<=0&&(e=n=o=NaN),new Dt(e,n,o,i)}function N1(e){return e instanceof vi||(e=mo(e)),e?(e=e.rgb(),new Dt(e.r,e.g,e.b,e.opacity)):new Dt}function Ql(e,n,o,i){return arguments.length===1?N1(e):new Dt(e,n,o,i??1)}function Dt(e,n,o,i){this.r=+e,this.g=+n,this.b=+o,this.opacity=+i}Zl(Dt,Ql,xm(vi,{brighter(e){return e=e==null?La:Math.pow(La,e),new Dt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ci:Math.pow(Ci,e),new Dt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Dt(fo(this.r),fo(this.g),fo(this.b),za(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Mm,formatHex:Mm,formatHex8:w1,formatRgb:Vm,toString:Vm}));function Mm(){return`#${po(this.r)}${po(this.g)}${po(this.b)}`}function w1(){return`#${po(this.r)}${po(this.g)}${po(this.b)}${po((isNaN(this.opacity)?1:this.opacity)*255)}`}function Vm(){const e=za(this.opacity);return`${e===1?"rgb(":"rgba("}${fo(this.r)}, ${fo(this.g)}, ${fo(this.b)}${e===1?")":`, ${e})`}`}function za(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function fo(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function po(e){return e=fo(e),(e<16?"0":"")+e.toString(16)}function Bm(e,n,o,i){return i<=0?e=n=o=NaN:o<=0||o>=1?e=n=NaN:n<=0&&(e=NaN),new Jt(e,n,o,i)}function Dm(e){if(e instanceof Jt)return new Jt(e.h,e.s,e.l,e.opacity);if(e instanceof vi||(e=mo(e)),!e)return new Jt;if(e instanceof Jt)return e;e=e.rgb();var n=e.r/255,o=e.g/255,i=e.b/255,a=Math.min(n,o,i),r=Math.max(n,o,i),l=NaN,s=r-a,c=(r+a)/2;return s?(n===r?l=(o-i)/s+(o<i)*6:o===r?l=(i-n)/s+2:l=(n-o)/s+4,s/=c<.5?r+a:2-r-a,l*=60):s=c>0&&c<1?0:l,new Jt(l,s,c,e.opacity)}function I1(e,n,o,i){return arguments.length===1?Dm(e):new Jt(e,n,o,i??1)}function Jt(e,n,o,i){this.h=+e,this.s=+n,this.l=+o,this.opacity=+i}Zl(Jt,I1,xm(vi,{brighter(e){return e=e==null?La:Math.pow(La,e),new Jt(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ci:Math.pow(Ci,e),new Jt(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,n=isNaN(e)||isNaN(this.s)?0:this.s,o=this.l,i=o+(o<.5?o:1-o)*n,a=2*o-i;return new Dt(es(e>=240?e-240:e+120,a,i),es(e,a,i),es(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new Jt(Om(this.h),Fa(this.s),Fa(this.l),za(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=za(this.opacity);return`${e===1?"hsl(":"hsla("}${Om(this.h)}, ${Fa(this.s)*100}%, ${Fa(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Om(e){return e=(e||0)%360,e<0?e+360:e}function Fa(e){return Math.max(0,Math.min(1,e||0))}function es(e,n,o){return(e<60?n+(o-n)*e/60:e<180?o:e<240?n+(o-n)*(240-e)/60:n)*255}const ts=e=>()=>e;function v1(e,n){return function(o){return e+o*n}}function C1(e,n,o){return e=Math.pow(e,o),n=Math.pow(n,o)-e,o=1/o,function(i){return Math.pow(e+i*n,o)}}function S1(e){return(e=+e)==1?Lm:function(n,o){return o-n?C1(n,o,e):ts(isNaN(n)?o:n)}}function Lm(e,n){var o=n-e;return o?v1(e,o):ts(isNaN(e)?n:e)}const Ua=(function e(n){var o=S1(n);function i(a,r){var l=o((a=Ql(a)).r,(r=Ql(r)).r),s=o(a.g,r.g),c=o(a.b,r.b),d=Lm(a.opacity,r.opacity);return function(u){return a.r=l(u),a.g=s(u),a.b=c(u),a.opacity=d(u),a+""}}return i.gamma=e,i})(1);function x1(e,n){n||(n=[]);var o=e?Math.min(n.length,e.length):0,i=n.slice(),a;return function(r){for(a=0;a<o;++a)i[a]=e[a]*(1-r)+n[a]*r;return i}}function R1(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function A1(e,n){var o=n?n.length:0,i=e?Math.min(o,e.length):0,a=new Array(i),r=new Array(o),l;for(l=0;l<i;++l)a[l]=xi(e[l],n[l]);for(;l<o;++l)r[l]=n[l];return function(s){for(l=0;l<i;++l)r[l]=a[l](s);return r}}function $1(e,n){var o=new Date;return e=+e,n=+n,function(i){return o.setTime(e*(1-i)+n*i),o}}function dn(e,n){return e=+e,n=+n,function(o){return e*(1-o)+n*o}}function T1(e,n){var o={},i={},a;(e===null||typeof e!="object")&&(e={}),(n===null||typeof n!="object")&&(n={});for(a in n)a in e?o[a]=xi(e[a],n[a]):i[a]=n[a];return function(r){for(a in o)i[a]=o[a](r);return i}}var ns=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,os=new RegExp(ns.source,"g");function M1(e){return function(){return e}}function V1(e){return function(n){return e(n)+""}}function Pm(e,n){var o=ns.lastIndex=os.lastIndex=0,i,a,r,l=-1,s=[],c=[];for(e=e+"",n=n+"";(i=ns.exec(e))&&(a=os.exec(n));)(r=a.index)>o&&(r=n.slice(o,r),s[l]?s[l]+=r:s[++l]=r),(i=i[0])===(a=a[0])?s[l]?s[l]+=a:s[++l]=a:(s[++l]=null,c.push({i:l,x:dn(i,a)})),o=os.lastIndex;return o<n.length&&(r=n.slice(o),s[l]?s[l]+=r:s[++l]=r),s.length<2?c[0]?V1(c[0].x):M1(n):(n=c.length,function(d){for(var u=0,m;u<n;++u)s[(m=c[u]).i]=m.x(d);return s.join("")})}function xi(e,n){var o=typeof n,i;return n==null||o==="boolean"?ts(n):(o==="number"?dn:o==="string"?(i=mo(n))?(n=i,Ua):Pm:n instanceof mo?Ua:n instanceof Date?$1:R1(n)?x1:Array.isArray(n)?A1:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?T1:dn)(e,n)}var zm=180/Math.PI,is={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Fm(e,n,o,i,a,r){var l,s,c;return(l=Math.sqrt(e*e+n*n))&&(e/=l,n/=l),(c=e*o+n*i)&&(o-=e*c,i-=n*c),(s=Math.sqrt(o*o+i*i))&&(o/=s,i/=s,c/=s),e*i<n*o&&(e=-e,n=-n,c=-c,l=-l),{translateX:a,translateY:r,rotate:Math.atan2(n,e)*zm,skewX:Math.atan(c)*zm,scaleX:l,scaleY:s}}var Ha;function B1(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?is:Fm(n.a,n.b,n.c,n.d,n.e,n.f)}function D1(e){return e==null||(Ha||(Ha=document.createElementNS("http://www.w3.org/2000/svg","g")),Ha.setAttribute("transform",e),!(e=Ha.transform.baseVal.consolidate()))?is:(e=e.matrix,Fm(e.a,e.b,e.c,e.d,e.e,e.f))}function Um(e,n,o,i){function a(d){return d.length?d.pop()+" ":""}function r(d,u,m,p,f,h){if(d!==m||u!==p){var g=f.push("translate(",null,n,null,o);h.push({i:g-4,x:dn(d,m)},{i:g-2,x:dn(u,p)})}else(m||p)&&f.push("translate("+m+n+p+o)}function l(d,u,m,p){d!==u?(d-u>180?u+=360:u-d>180&&(d+=360),p.push({i:m.push(a(m)+"rotate(",null,i)-2,x:dn(d,u)})):u&&m.push(a(m)+"rotate("+u+i)}function s(d,u,m,p){d!==u?p.push({i:m.push(a(m)+"skewX(",null,i)-2,x:dn(d,u)}):u&&m.push(a(m)+"skewX("+u+i)}function c(d,u,m,p,f,h){if(d!==m||u!==p){var g=f.push(a(f)+"scale(",null,",",null,")");h.push({i:g-4,x:dn(d,m)},{i:g-2,x:dn(u,p)})}else(m!==1||p!==1)&&f.push(a(f)+"scale("+m+","+p+")")}return function(d,u){var m=[],p=[];return d=e(d),u=e(u),r(d.translateX,d.translateY,u.translateX,u.translateY,m,p),l(d.rotate,u.rotate,m,p),s(d.skewX,u.skewX,m,p),c(d.scaleX,d.scaleY,u.scaleX,u.scaleY,m,p),d=u=null,function(f){for(var h=-1,g=p.length,b;++h<g;)m[(b=p[h]).i]=b.x(f);return m.join("")}}}var O1=Um(B1,"px, ","px)","deg)"),L1=Um(D1,", ",")",")"),P1=1e-12;function Hm(e){return((e=Math.exp(e))+1/e)/2}function z1(e){return((e=Math.exp(e))-1/e)/2}function F1(e){return((e=Math.exp(2*e))-1)/(e+1)}const ja=(function e(n,o,i){function a(r,l){var s=r[0],c=r[1],d=r[2],u=l[0],m=l[1],p=l[2],f=u-s,h=m-c,g=f*f+h*h,b,_;if(g<P1)_=Math.log(p/d)/n,b=function(T){return[s+T*f,c+T*h,d*Math.exp(n*T*_)]};else{var E=Math.sqrt(g),N=(p*p-d*d+i*g)/(2*d*o*E),y=(p*p-d*d-i*g)/(2*p*o*E),k=Math.log(Math.sqrt(N*N+1)-N),S=Math.log(Math.sqrt(y*y+1)-y);_=(S-k)/n,b=function(T){var O=T*_,A=Hm(k),V=d/(o*E)*(A*F1(n*O+k)-z1(k));return[s+V*f,c+V*h,d*A/Hm(n*O+k)]}}return b.duration=_*1e3*n/Math.SQRT2,b}return a.rho=function(r){var l=Math.max(.001,+r),s=l*l,c=s*s;return e(l,s,c)},a})(Math.SQRT2,2,4);var qo=0,Ri=0,Ai=0,jm=1e3,Ka,$i,Ga=0,ho=0,Ya=0,Ti=typeof performance=="object"&&performance.now?performance:Date,Km=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function as(){return ho||(Km(U1),ho=Ti.now()+Ya)}function U1(){ho=0}function qa(){this._call=this._time=this._next=null}qa.prototype=Gm.prototype={constructor:qa,restart:function(e,n,o){if(typeof e!="function")throw new TypeError("callback is not a function");o=(o==null?as():+o)+(n==null?0:+n),!this._next&&$i!==this&&($i?$i._next=this:Ka=this,$i=this),this._call=e,this._time=o,rs()},stop:function(){this._call&&(this._call=null,this._time=1/0,rs())}};function Gm(e,n,o){var i=new qa;return i.restart(e,n,o),i}function H1(){as(),++qo;for(var e=Ka,n;e;)(n=ho-e._time)>=0&&e._call.call(void 0,n),e=e._next;--qo}function Ym(){ho=(Ga=Ti.now())+Ya,qo=Ri=0;try{H1()}finally{qo=0,K1(),ho=0}}function j1(){var e=Ti.now(),n=e-Ga;n>jm&&(Ya-=n,Ga=e)}function K1(){for(var e,n=Ka,o,i=1/0;n;)n._call?(i>n._time&&(i=n._time),e=n,n=n._next):(o=n._next,n._next=null,n=e?e._next=o:Ka=o);$i=e,rs(i)}function rs(e){if(!qo){Ri&&(Ri=clearTimeout(Ri));var n=e-ho;n>24?(e<1/0&&(Ri=setTimeout(Ym,e-Ti.now()-Ya)),Ai&&(Ai=clearInterval(Ai))):(Ai||(Ga=Ti.now(),Ai=setInterval(j1,jm)),qo=1,Km(Ym))}}function qm(e,n,o){var i=new qa;return n=n==null?0:+n,i.restart(a=>{i.stop(),e(a+n)},n,o),i}var G1=Ma("start","end","cancel","interrupt"),Y1=[],Wm=0,Jm=1,ls=2,Wa=3,Xm=4,ss=5,Ja=6;function Xa(e,n,o,i,a,r){var l=e.__transition;if(!l)e.__transition={};else if(o in l)return;q1(e,o,{name:n,index:i,group:a,on:G1,tween:Y1,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:Wm})}function cs(e,n){var o=Xt(e,n);if(o.state>Wm)throw new Error("too late; already scheduled");return o}function un(e,n){var o=Xt(e,n);if(o.state>Wa)throw new Error("too late; already running");return o}function Xt(e,n){var o=e.__transition;if(!o||!(o=o[n]))throw new Error("transition not found");return o}function q1(e,n,o){var i=e.__transition,a;i[n]=o,o.timer=Gm(r,0,o.time);function r(d){o.state=Jm,o.timer.restart(l,o.delay,o.time),o.delay<=d&&l(d-o.delay)}function l(d){var u,m,p,f;if(o.state!==Jm)return c();for(u in i)if(f=i[u],f.name===o.name){if(f.state===Wa)return qm(l);f.state===Xm?(f.state=Ja,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete i[u]):+u<n&&(f.state=Ja,f.timer.stop(),f.on.call("cancel",e,e.__data__,f.index,f.group),delete i[u])}if(qm(function(){o.state===Wa&&(o.state=Xm,o.timer.restart(s,o.delay,o.time),s(d))}),o.state=ls,o.on.call("start",e,e.__data__,o.index,o.group),o.state===ls){for(o.state=Wa,a=new Array(p=o.tween.length),u=0,m=-1;u<p;++u)(f=o.tween[u].value.call(e,e.__data__,o.index,o.group))&&(a[++m]=f);a.length=m+1}}function s(d){for(var u=d<o.duration?o.ease.call(null,d/o.duration):(o.timer.restart(c),o.state=ss,1),m=-1,p=a.length;++m<p;)a[m].call(e,u);o.state===ss&&(o.on.call("end",e,e.__data__,o.index,o.group),c())}function c(){o.state=Ja,o.timer.stop(),delete i[n];for(var d in i)return;delete e.__transition}}function Za(e,n){var o=e.__transition,i,a,r=!0,l;if(o){n=n==null?null:n+"";for(l in o){if((i=o[l]).name!==n){r=!1;continue}a=i.state>ls&&i.state<ss,i.state=Ja,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete o[l]}r&&delete e.__transition}}function W1(e){return this.each(function(){Za(this,e)})}function J1(e,n){var o,i;return function(){var a=un(this,e),r=a.tween;if(r!==o){i=o=r;for(var l=0,s=i.length;l<s;++l)if(i[l].name===n){i=i.slice(),i.splice(l,1);break}}a.tween=i}}function X1(e,n,o){var i,a;if(typeof o!="function")throw new Error;return function(){var r=un(this,e),l=r.tween;if(l!==i){a=(i=l).slice();for(var s={name:n,value:o},c=0,d=a.length;c<d;++c)if(a[c].name===n){a[c]=s;break}c===d&&a.push(s)}r.tween=a}}function Z1(e,n){var o=this._id;if(e+="",arguments.length<2){for(var i=Xt(this.node(),o).tween,a=0,r=i.length,l;a<r;++a)if((l=i[a]).name===e)return l.value;return null}return this.each((n==null?J1:X1)(o,e,n))}function ds(e,n,o){var i=e._id;return e.each(function(){var a=un(this,i);(a.value||(a.value={}))[n]=o.apply(this,arguments)}),function(a){return Xt(a,i).value[n]}}function Zm(e,n){var o;return(typeof n=="number"?dn:n instanceof mo?Ua:(o=mo(n))?(n=o,Ua):Pm)(e,n)}function Q1(e){return function(){this.removeAttribute(e)}}function e0(e){return function(){this.removeAttributeNS(e.space,e.local)}}function t0(e,n,o){var i,a=o+"",r;return function(){var l=this.getAttribute(e);return l===a?null:l===i?r:r=n(i=l,o)}}function n0(e,n,o){var i,a=o+"",r;return function(){var l=this.getAttributeNS(e.space,e.local);return l===a?null:l===i?r:r=n(i=l,o)}}function o0(e,n,o){var i,a,r;return function(){var l,s=o(this),c;return s==null?void this.removeAttribute(e):(l=this.getAttribute(e),c=s+"",l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s)))}}function i0(e,n,o){var i,a,r;return function(){var l,s=o(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(l=this.getAttributeNS(e.space,e.local),c=s+"",l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s)))}}function a0(e,n){var o=Ba(e),i=o==="transform"?L1:Zm;return this.attrTween(e,typeof n=="function"?(o.local?i0:o0)(o,i,ds(this,"attr."+e,n)):n==null?(o.local?e0:Q1)(o):(o.local?n0:t0)(o,i,n))}function r0(e,n){return function(o){this.setAttribute(e,n.call(this,o))}}function l0(e,n){return function(o){this.setAttributeNS(e.space,e.local,n.call(this,o))}}function s0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&l0(e,r)),o}return a._value=n,a}function c0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&r0(e,r)),o}return a._value=n,a}function d0(e,n){var o="attr."+e;if(arguments.length<2)return(o=this.tween(o))&&o._value;if(n==null)return this.tween(o,null);if(typeof n!="function")throw new Error;var i=Ba(e);return this.tween(o,(i.local?s0:c0)(i,n))}function u0(e,n){return function(){cs(this,e).delay=+n.apply(this,arguments)}}function m0(e,n){return n=+n,function(){cs(this,e).delay=n}}function f0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?u0:m0)(n,e)):Xt(this.node(),n).delay}function p0(e,n){return function(){un(this,e).duration=+n.apply(this,arguments)}}function h0(e,n){return n=+n,function(){un(this,e).duration=n}}function y0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?p0:h0)(n,e)):Xt(this.node(),n).duration}function g0(e,n){if(typeof n!="function")throw new Error;return function(){un(this,e).ease=n}}function b0(e){var n=this._id;return arguments.length?this.each(g0(n,e)):Xt(this.node(),n).ease}function _0(e,n){return function(){var o=n.apply(this,arguments);if(typeof o!="function")throw new Error;un(this,e).ease=o}}function k0(e){if(typeof e!="function")throw new Error;return this.each(_0(this._id,e))}function E0(e){typeof e!="function"&&(e=ym(e));for(var n=this._groups,o=n.length,i=new Array(o),a=0;a<o;++a)for(var r=n[a],l=r.length,s=i[a]=[],c,d=0;d<l;++d)(c=r[d])&&e.call(c,c.__data__,d,r)&&s.push(c);return new In(i,this._parents,this._name,this._id)}function N0(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,o=e._groups,i=n.length,a=o.length,r=Math.min(i,a),l=new Array(i),s=0;s<r;++s)for(var c=n[s],d=o[s],u=c.length,m=l[s]=new Array(u),p,f=0;f<u;++f)(p=c[f]||d[f])&&(m[f]=p);for(;s<i;++s)l[s]=n[s];return new In(l,this._parents,this._name,this._id)}function w0(e){return(e+"").trim().split(/^|\s+/).every(function(n){var o=n.indexOf(".");return o>=0&&(n=n.slice(0,o)),!n||n==="start"})}function I0(e,n,o){var i,a,r=w0(n)?cs:un;return function(){var l=r(this,e),s=l.on;s!==i&&(a=(i=s).copy()).on(n,o),l.on=a}}function v0(e,n){var o=this._id;return arguments.length<2?Xt(this.node(),o).on.on(e):this.each(I0(o,e,n))}function C0(e){return function(){var n=this.parentNode;for(var o in this.__transition)if(+o!==e)return;n&&n.removeChild(this)}}function S0(){return this.on("end.remove",C0(this._id))}function x0(e){var n=this._name,o=this._id;typeof e!="function"&&(e=ql(e));for(var i=this._groups,a=i.length,r=new Array(a),l=0;l<a;++l)for(var s=i[l],c=s.length,d=r[l]=new Array(c),u,m,p=0;p<c;++p)(u=s[p])&&(m=e.call(u,u.__data__,p,s))&&("__data__"in u&&(m.__data__=u.__data__),d[p]=m,Xa(d[p],n,o,p,d,Xt(u,o)));return new In(r,this._parents,n,o)}function R0(e){var n=this._name,o=this._id;typeof e!="function"&&(e=hm(e));for(var i=this._groups,a=i.length,r=[],l=[],s=0;s<a;++s)for(var c=i[s],d=c.length,u,m=0;m<d;++m)if(u=c[m]){for(var p=e.call(u,u.__data__,m,c),f,h=Xt(u,o),g=0,b=p.length;g<b;++g)(f=p[g])&&Xa(f,n,o,g,p,h);r.push(p),l.push(u)}return new In(r,l,n,o)}var A0=wi.prototype.constructor;function $0(){return new A0(this._groups,this._parents)}function T0(e,n){var o,i,a;return function(){var r=Ko(this,e),l=(this.style.removeProperty(e),Ko(this,e));return r===l?null:r===o&&l===i?a:a=n(o=r,i=l)}}function Qm(e){return function(){this.style.removeProperty(e)}}function M0(e,n,o){var i,a=o+"",r;return function(){var l=Ko(this,e);return l===a?null:l===i?r:r=n(i=l,o)}}function V0(e,n,o){var i,a,r;return function(){var l=Ko(this,e),s=o(this),c=s+"";return s==null&&(c=s=(this.style.removeProperty(e),Ko(this,e))),l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s))}}function B0(e,n){var o,i,a,r="style."+n,l="end."+r,s;return function(){var c=un(this,e),d=c.on,u=c.value[r]==null?s||(s=Qm(n)):void 0;(d!==o||a!==u)&&(i=(o=d).copy()).on(l,a=u),c.on=i}}function D0(e,n,o){var i=(e+="")=="transform"?O1:Zm;return n==null?this.styleTween(e,T0(e,i)).on("end.style."+e,Qm(e)):typeof n=="function"?this.styleTween(e,V0(e,i,ds(this,"style."+e,n))).each(B0(this._id,e)):this.styleTween(e,M0(e,i,n),o).on("end.style."+e,null)}function O0(e,n,o){return function(i){this.style.setProperty(e,n.call(this,i),o)}}function L0(e,n,o){var i,a;function r(){var l=n.apply(this,arguments);return l!==a&&(i=(a=l)&&O0(e,l,o)),i}return r._value=n,r}function P0(e,n,o){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(n==null)return this.tween(i,null);if(typeof n!="function")throw new Error;return this.tween(i,L0(e,n,o??""))}function z0(e){return function(){this.textContent=e}}function F0(e){return function(){var n=e(this);this.textContent=n??""}}function U0(e){return this.tween("text",typeof e=="function"?F0(ds(this,"text",e)):z0(e==null?"":e+""))}function H0(e){return function(n){this.textContent=e.call(this,n)}}function j0(e){var n,o;function i(){var a=e.apply(this,arguments);return a!==o&&(n=(o=a)&&H0(a)),n}return i._value=e,i}function K0(e){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,j0(e))}function G0(){for(var e=this._name,n=this._id,o=ef(),i=this._groups,a=i.length,r=0;r<a;++r)for(var l=i[r],s=l.length,c,d=0;d<s;++d)if(c=l[d]){var u=Xt(c,n);Xa(c,e,o,d,l,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new In(i,this._parents,e,o)}function Y0(){var e,n,o=this,i=o._id,a=o.size();return new Promise(function(r,l){var s={value:l},c={value:function(){--a===0&&r()}};o.each(function(){var d=un(this,i),u=d.on;u!==e&&(n=(e=u).copy(),n._.cancel.push(s),n._.interrupt.push(s),n._.end.push(c)),d.on=n}),a===0&&r()})}var q0=0;function In(e,n,o,i){this._groups=e,this._parents=n,this._name=o,this._id=i}function ef(){return++q0}var vn=wi.prototype;In.prototype={constructor:In,select:x0,selectAll:R0,selectChild:vn.selectChild,selectChildren:vn.selectChildren,filter:E0,merge:N0,selection:$0,transition:G0,call:vn.call,nodes:vn.nodes,node:vn.node,size:vn.size,empty:vn.empty,each:vn.each,on:v0,attr:a0,attrTween:d0,style:D0,styleTween:P0,text:U0,textTween:K0,remove:S0,tween:Z1,delay:f0,duration:y0,ease:b0,easeVarying:k0,end:Y0,[Symbol.iterator]:vn[Symbol.iterator]};function W0(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var J0={time:null,delay:0,duration:250,ease:W0};function X0(e,n){for(var o;!(o=e.__transition)||!(o=o[n]);)if(!(e=e.parentNode))throw new Error(`transition ${n} not found`);return o}function Z0(e){var n,o;e instanceof In?(n=e._id,e=e._name):(n=ef(),(o=J0).time=as(),e=e==null?null:e+"");for(var i=this._groups,a=i.length,r=0;r<a;++r)for(var l=i[r],s=l.length,c,d=0;d<s;++d)(c=l[d])&&Xa(c,e,n,d,l,o||X0(c,n));return new In(i,this._parents,e,n)}wi.prototype.interrupt=W1,wi.prototype.transition=Z0;const Qa=e=>()=>e;function Q0(e,{sourceEvent:n,target:o,transform:i,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function Cn(e,n,o){this.k=e,this.x=n,this.y=o}Cn.prototype={constructor:Cn,scale:function(e){return e===1?this:new Cn(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new Cn(this.k,this.x+this.k*e,this.y+this.k*n)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Wo=new Cn(1,0,0);Cn.prototype;function us(e){e.stopImmediatePropagation()}function Mi(e){e.preventDefault(),e.stopImmediatePropagation()}function eN(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function tN(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function tf(){return this.__zoom||Wo}function nN(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function oN(){return navigator.maxTouchPoints||"ontouchstart"in this}function iN(e,n,o){var i=e.invertX(n[0][0])-o[0][0],a=e.invertX(n[1][0])-o[1][0],r=e.invertY(n[0][1])-o[0][1],l=e.invertY(n[1][1])-o[1][1];return e.translate(a>i?(i+a)/2:Math.min(0,i)||Math.max(0,a),l>r?(r+l)/2:Math.min(0,r)||Math.max(0,l))}function aN(){var e=eN,n=tN,o=iN,i=nN,a=oN,r=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],s=250,c=ja,d=Ma("start","zoom","end"),u,m,p,f=500,h=150,g=0,b=10;function _(w){w.property("__zoom",tf).on("wheel.zoom",O,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",V).filter(a).on("touchstart.zoom",C).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",$).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(w,I,v,B){var M=w.selection?w.selection():w;M.property("__zoom",tf),w!==M?k(w,I,v,B):M.interrupt().each(function(){S(this,arguments).event(B).start().zoom(null,typeof I=="function"?I.apply(this,arguments):I).end()})},_.scaleBy=function(w,I,v,B){_.scaleTo(w,function(){var M=this.__zoom.k,x=typeof I=="function"?I.apply(this,arguments):I;return M*x},v,B)},_.scaleTo=function(w,I,v,B){_.transform(w,function(){var M=n.apply(this,arguments),x=this.__zoom,P=v==null?y(M):typeof v=="function"?v.apply(this,arguments):v,q=x.invert(P),ce=typeof I=="function"?I.apply(this,arguments):I;return o(N(E(x,ce),P,q),M,l)},v,B)},_.translateBy=function(w,I,v,B){_.transform(w,function(){return o(this.__zoom.translate(typeof I=="function"?I.apply(this,arguments):I,typeof v=="function"?v.apply(this,arguments):v),n.apply(this,arguments),l)},null,B)},_.translateTo=function(w,I,v,B,M){_.transform(w,function(){var x=n.apply(this,arguments),P=this.__zoom,q=B==null?y(x):typeof B=="function"?B.apply(this,arguments):B;return o(Wo.translate(q[0],q[1]).scale(P.k).translate(typeof I=="function"?-I.apply(this,arguments):-I,typeof v=="function"?-v.apply(this,arguments):-v),x,l)},B,M)};function E(w,I){return I=Math.max(r[0],Math.min(r[1],I)),I===w.k?w:new Cn(I,w.x,w.y)}function N(w,I,v){var B=I[0]-v[0]*w.k,M=I[1]-v[1]*w.k;return B===w.x&&M===w.y?w:new Cn(w.k,B,M)}function y(w){return[(+w[0][0]+ +w[1][0])/2,(+w[0][1]+ +w[1][1])/2]}function k(w,I,v,B){w.on("start.zoom",function(){S(this,arguments).event(B).start()}).on("interrupt.zoom end.zoom",function(){S(this,arguments).event(B).end()}).tween("zoom",function(){var M=this,x=arguments,P=S(M,x).event(B),q=n.apply(M,x),ce=v==null?y(q):typeof v=="function"?v.apply(M,x):v,ge=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=M.__zoom,pe=typeof I=="function"?I.apply(M,x):I,he=c(ie.invert(ce).concat(ge/ie.k),pe.invert(ce).concat(ge/pe.k));return function(_e){if(_e===1)_e=pe;else{var Ae=he(_e),je=ge/Ae[2];_e=new Cn(je,ce[0]-Ae[0]*je,ce[1]-Ae[1]*je)}P.zoom(null,_e)}})}function S(w,I,v){return!v&&w.__zooming||new T(w,I)}function T(w,I){this.that=w,this.args=I,this.active=0,this.sourceEvent=null,this.extent=n.apply(w,I),this.taps=0}T.prototype={event:function(w){return w&&(this.sourceEvent=w),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(w,I){return this.mouse&&w!=="mouse"&&(this.mouse[1]=I.invert(this.mouse[0])),this.touch0&&w!=="touch"&&(this.touch0[1]=I.invert(this.touch0[0])),this.touch1&&w!=="touch"&&(this.touch1[1]=I.invert(this.touch1[0])),this.that.__zoom=I,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(w){var I=Wt(this.that).datum();d.call(w,this.that,new Q0(w,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:d}),I)}};function O(w,...I){if(!e.apply(this,arguments))return;var v=S(this,I).event(w),B=this.__zoom,M=Math.max(r[0],Math.min(r[1],B.k*Math.pow(2,i.apply(this,arguments)))),x=sn(w);if(v.wheel)(v.mouse[0][0]!==x[0]||v.mouse[0][1]!==x[1])&&(v.mouse[1]=B.invert(v.mouse[0]=x)),clearTimeout(v.wheel);else{if(B.k===M)return;v.mouse=[x,B.invert(x)],Za(this),v.start()}Mi(w),v.wheel=setTimeout(P,h),v.zoom("mouse",o(N(E(B,M),v.mouse[0],v.mouse[1]),v.extent,l));function P(){v.wheel=null,v.end()}}function A(w,...I){if(p||!e.apply(this,arguments))return;var v=w.currentTarget,B=S(this,I,!0).event(w),M=Wt(w.view).on("mousemove.zoom",ce,!0).on("mouseup.zoom",ge,!0),x=sn(w,v),P=w.clientX,q=w.clientY;Cm(w.view),us(w),B.mouse=[x,this.__zoom.invert(x)],Za(this),B.start();function ce(ie){if(Mi(ie),!B.moved){var pe=ie.clientX-P,he=ie.clientY-q;B.moved=pe*pe+he*he>g}B.event(ie).zoom("mouse",o(N(B.that.__zoom,B.mouse[0]=sn(ie,v),B.mouse[1]),B.extent,l))}function ge(ie){M.on("mousemove.zoom mouseup.zoom",null),Sm(ie.view,B.moved),Mi(ie),B.event(ie).end()}}function V(w,...I){if(e.apply(this,arguments)){var v=this.__zoom,B=sn(w.changedTouches?w.changedTouches[0]:w,this),M=v.invert(B),x=v.k*(w.shiftKey?.5:2),P=o(N(E(v,x),B,M),n.apply(this,I),l);Mi(w),s>0?Wt(this).transition().duration(s).call(k,P,B,w):Wt(this).call(_.transform,P,B,w)}}function C(w,...I){if(e.apply(this,arguments)){var v=w.touches,B=v.length,M=S(this,I,w.changedTouches.length===B).event(w),x,P,q,ce;for(us(w),P=0;P<B;++P)q=v[P],ce=sn(q,this),ce=[ce,this.__zoom.invert(ce),q.identifier],M.touch0?!M.touch1&&M.touch0[2]!==ce[2]&&(M.touch1=ce,M.taps=0):(M.touch0=ce,x=!0,M.taps=1+!!u);u&&(u=clearTimeout(u)),x&&(M.taps<2&&(m=ce[0],u=setTimeout(function(){u=null},f)),Za(this),M.start())}}function R(w,...I){if(this.__zooming){var v=S(this,I).event(w),B=w.changedTouches,M=B.length,x,P,q,ce;for(Mi(w),x=0;x<M;++x)P=B[x],q=sn(P,this),v.touch0&&v.touch0[2]===P.identifier?v.touch0[0]=q:v.touch1&&v.touch1[2]===P.identifier&&(v.touch1[0]=q);if(P=v.that.__zoom,v.touch1){var ge=v.touch0[0],ie=v.touch0[1],pe=v.touch1[0],he=v.touch1[1],_e=(_e=pe[0]-ge[0])*_e+(_e=pe[1]-ge[1])*_e,Ae=(Ae=he[0]-ie[0])*Ae+(Ae=he[1]-ie[1])*Ae;P=E(P,Math.sqrt(_e/Ae)),q=[(ge[0]+pe[0])/2,(ge[1]+pe[1])/2],ce=[(ie[0]+he[0])/2,(ie[1]+he[1])/2]}else if(v.touch0)q=v.touch0[0],ce=v.touch0[1];else return;v.zoom("touch",o(N(P,q,ce),v.extent,l))}}function $(w,...I){if(this.__zooming){var v=S(this,I).event(w),B=w.changedTouches,M=B.length,x,P;for(us(w),p&&clearTimeout(p),p=setTimeout(function(){p=null},f),x=0;x<M;++x)P=B[x],v.touch0&&v.touch0[2]===P.identifier?delete v.touch0:v.touch1&&v.touch1[2]===P.identifier&&delete v.touch1;if(v.touch1&&!v.touch0&&(v.touch0=v.touch1,delete v.touch1),v.touch0)v.touch0[1]=this.__zoom.invert(v.touch0[0]);else if(v.end(),v.taps===2&&(P=sn(P,this),Math.hypot(m[0]-P[0],m[1]-P[1])<b)){var q=Wt(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return _.wheelDelta=function(w){return arguments.length?(i=typeof w=="function"?w:Qa(+w),_):i},_.filter=function(w){return arguments.length?(e=typeof w=="function"?w:Qa(!!w),_):e},_.touchable=function(w){return arguments.length?(a=typeof w=="function"?w:Qa(!!w),_):a},_.extent=function(w){return arguments.length?(n=typeof w=="function"?w:Qa([[+w[0][0],+w[0][1]],[+w[1][0],+w[1][1]]]),_):n},_.scaleExtent=function(w){return arguments.length?(r[0]=+w[0],r[1]=+w[1],_):[r[0],r[1]]},_.translateExtent=function(w){return arguments.length?(l[0][0]=+w[0][0],l[1][0]=+w[1][0],l[0][1]=+w[0][1],l[1][1]=+w[1][1],_):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},_.constrain=function(w){return arguments.length?(o=w,_):o},_.duration=function(w){return arguments.length?(s=+w,_):s},_.interpolate=function(w){return arguments.length?(c=w,_):c},_.on=function(){var w=d.on.apply(d,arguments);return w===d?_:w},_.clickDistance=function(w){return arguments.length?(g=(w=+w)*w,_):Math.sqrt(g)},_.tapDistance=function(w){return arguments.length?(b=+w,_):b},_}var Le=(e=>(e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom",e))(Le||{}),ms=(e=>(e.Partial="partial",e.Full="full",e))(ms||{}),yo=(e=>(e.Bezier="default",e.SimpleBezier="simple-bezier",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e))(yo||{}),Sn=(e=>(e.Strict="strict",e.Loose="loose",e))(Sn||{}),fs=(e=>(e.Arrow="arrow",e.ArrowClosed="arrowclosed",e))(fs||{}),Vi=(e=>(e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal",e))(Vi||{}),nf=(e=>(e.TopLeft="top-left",e.TopCenter="top-center",e.TopRight="top-right",e.BottomLeft="bottom-left",e.BottomCenter="bottom-center",e.BottomRight="bottom-right",e))(nf||{});const rN=["INPUT","SELECT","TEXTAREA"],lN=typeof document<"u"?document:null;function ps(e){var n,o;const i=((o=(n=e.composedPath)==null?void 0:n.call(e))==null?void 0:o[0])||e.target,a=typeof(i==null?void 0:i.hasAttribute)=="function"?i.hasAttribute("contenteditable"):!1,r=typeof(i==null?void 0:i.closest)=="function"?i.closest(".nokey"):null;return rN.includes(i==null?void 0:i.nodeName)||a||!!r}function sN(e){return e.ctrlKey||e.metaKey||e.shiftKey||e.altKey}function of(e,n,o,i){const a=n.replace("+",`
28
28
  `).replace(`
29
29
 
30
30
  `,`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@g1cloud/entity-modeler-next",
3
3
  "private": false,
4
- "version": "5.2.7",
4
+ "version": "5.2.8",
5
5
  "description": "Vue 3 visual entity-modeling / class-diagram editor",
6
6
  "type": "module",
7
7
  "files": [