@g1cloud/entity-modeler-next 5.2.54 → 5.2.55
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.
|
@@ -31,7 +31,7 @@ ${u}`:u}function rk(e){return`-- ══ ${e} ${"═".repeat(Math.max(3,56-e.leng
|
|
|
31
31
|
-- ⚠ @OrderColumn "${p}": 타입 근거가 모델에 없어 컬럼 생략(임베더블 속성으로 선언하면 방출됨)`:"",h=`CREATE TABLE ${c} (
|
|
32
32
|
${f.join(`,
|
|
33
33
|
`)}${y}
|
|
34
|
-
);`,_=[];if(n!=null&&n.commentLocale){let b=0,w=0;for(const $ of m){const k=Hl($.col.logicalName,n.commentLocale);k?_.push(`COMMENT ON COLUMN ${c}.${$.col.physicalName} IS '${k}';`):mu($.col.logicalName,n.commentLocale)==="other"?b++:w++}const I=fu(c,n.commentLocale,!1,b,w);I&&_.push(I)}o.tableBlocks.push({table:c,lines:[h,..._]});const N=Xo(r);if(xt(N)){o.tableBlocks.push({table:"",lines:[`-- ⚠ ${c}: 소유자 테이블명이 없어 FK 생략`]});continue}o.fks.push({child:c,parent:N,stmt:`ALTER TABLE ${c} ADD CONSTRAINT fk_${c}_${N} FOREIGN KEY (${d.map(b=>b.name).join(", ")}) REFERENCES ${N} (${d.map(b=>b.name).join(", ")});`})}}function ck(e,n){const o=n.associations.find(i=>{var a;return i.modelId===((a=e.embedded)==null?void 0:a.associationRef)});if(!(!o||!e.embedded))return o.end2.entityRef===e.embedded.embeddableRef?o.end2:o.end1}function dk(e,n,o){var r,l,s;if(e.attrType==="EMBED_PREDEF")return(((l=(r=o==null?void 0:o.embeddableCatalog)==null?void 0:r.find(c=>c.type===e.type))==null?void 0:l.fields)??[]).map(c=>({col:c}));const i=(s=e.embedded)==null?void 0:s.embeddableRef;if(i==null)return[];const a=n.entities.find(c=>c.modelId===i);return a?pu(a,n,o).map(c=>({col:c.col,attr:c.attr})):[]}const Gl="entity-modeler-diagram",ql=1;class Eo extends Error{constructor(n){super(n),this.name="InvalidDiagramJsonError"}}function hu(e,n){return JSON.stringify({format:Gl,version:ql,logical:e,layout:n},null,2)}const Va=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Zo=e=>Array.isArray(e)?e:[];function yu(e){let n;try{n=JSON.parse(e)}catch{throw new Eo("JSON 파싱 실패 — 올바른 JSON이 아닙니다.")}if(!Va(n))throw new Eo("최상위가 객체가 아닙니다.");if(n.format!==Gl)throw new Eo(`형식이 아닙니다(format=${String(n.format)}).`);if(typeof n.version!="number"||n.version>ql)throw new Eo(`지원하지 않는 버전(version=${String(n.version)}).`);const o=n.logical;if(!Va(o)||!Array.isArray(o.entities))throw new Eo("logical.entities 배열이 없습니다.");for(const l of o.entities)if(!Va(l)||typeof l.modelId!="string"||!Array.isArray(l.attributes))throw new Eo("엔티티 골격(modelId·attributes)이 올바르지 않습니다.");const i={modelId:typeof o.modelId=="string"?o.modelId:"imported",packageName:typeof o.packageName=="string"?o.packageName:void 0,entities:o.entities,associations:Zo(o.associations),groups:Zo(o.groups)},a=Va(n.layout)?n.layout:{},r={diagramId:typeof a.diagramId=="string"?a.diagramId:"imported",logicalModelRef:typeof a.logicalModelRef=="string"?a.logicalModelRef:i.modelId,entityLayouts:Zo(a.entityLayouts),associationLayouts:Zo(a.associationLayouts),groupLayouts:Zo(a.groupLayouts),notes:Zo(a.notes)};return{logical:i,layout:r}}const uk=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function jt(e){return e.replace(uk,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function je(e){return Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,"")}function gu(e){return`<text ${[`x="${je(e.x)}"`,`y="${je(e.y)}"`,`fill="${jt(e.fill)}"`,`font-size="${je(e.fontSize)}"`,e.fontFamily?`font-family="${jt(e.fontFamily)}"`:"",e.fontWeight!=null?`font-weight="${jt(String(e.fontWeight))}"`:"",e.fontStyle&&e.fontStyle!=="normal"?`font-style="${jt(e.fontStyle)}"`:"",e.anchor&&e.anchor!=="start"?`text-anchor="${e.anchor}"`:"",'dominant-baseline="central"'].filter(Boolean).join(" ")}>${jt(e.text)}</text>`}function mk(e){return`<line x1="${je(e.x1)}" y1="${je(e.y)}" x2="${je(e.x2)}" y2="${je(e.y)}" stroke="${jt(e.stroke)}" stroke-width="${je(e.strokeWidth??1)}" />`}function fk(e){return e==null?{tl:0,tr:0,br:0,bl:0}:typeof e=="number"?{tl:e,tr:e,br:e,bl:e}:e}function pk(e,n,o,i,a){return[`M${je(e+a.tl)},${je(n)}`,`L${je(e+o-a.tr)},${je(n)}`,a.tr?`Q${je(e+o)},${je(n)} ${je(e+o)},${je(n+a.tr)}`:"",`L${je(e+o)},${je(n+i-a.br)}`,a.br?`Q${je(e+o)},${je(n+i)} ${je(e+o-a.br)},${je(n+i)}`:"",`L${je(e+a.bl)},${je(n+i)}`,a.bl?`Q${je(e)},${je(n+i)} ${je(e)},${je(n+i-a.bl)}`:"",`L${je(e)},${je(n+a.tl)}`,a.tl?`Q${je(e)},${je(n)} ${je(e+a.tl)},${je(n)}`:"","Z"].filter(Boolean).join(" ")}function Yl(e){const n=fk(e.radius),o=n.tl||n.tr||n.br||n.bl,i=[`fill="${jt(e.fill)}"`,`stroke="${jt(e.stroke)}"`,`stroke-width="${je(e.strokeWidth??1)}"`,e.strokeDasharray?`stroke-dasharray="${jt(e.strokeDasharray)}"`:"",e.opacity!=null?`opacity="${je(e.opacity)}"`:""].filter(Boolean),r=[o?`<path d="${pk(e.x,e.y,e.w,e.h,n)}" ${i.join(" ")} />`:`<rect x="${je(e.x)}" y="${je(e.y)}" width="${je(e.w)}" height="${je(e.h)}" ${i.join(" ")} />`];for(const l of e.lines??[])r.push(mk(l));for(const l of e.texts)r.push(gu(l));for(const l of e.icons??[])r.push(l);return`<g>${r.join("")}</g>`}function hk(e){const o=[`<path ${[`d="${jt(e.d)}"`,'fill="none"',`stroke="${jt(e.stroke)}"`,`stroke-width="${je(e.strokeWidth)}"`,e.strokeDasharray?`stroke-dasharray="${jt(e.strokeDasharray)}"`:""].filter(Boolean).join(" ")} />`];for(const i of e.markers??[])o.push(i);for(const i of e.labels)o.push(gu(i));return`<g>${o.join("")}</g>`}function bu(e){const{x:n,y:o,w:i,h:a}=e.viewBox,r=[];e.background&&r.push(`<rect x="${je(n)}" y="${je(o)}" width="${je(i)}" height="${je(a)}" fill="${jt(e.background)}" />`);for(const l of e.groups)r.push(Yl(l));for(const l of e.edges)r.push(hk(l));for(const l of e.entities)r.push(Yl(l));for(const l of e.notes)r.push(Yl(l));return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${je(n)} ${je(o)} ${je(i)} ${je(a)}" width="${je(i)}" height="${je(a)}">`+r.join("")+"</svg>"}const xi=63;function Wl(e){if(!e)return null;const n=e.length;return n>xi?n:null}function $i(e){return e.dataType?e.length==null?e.dataType:e.scale==null?`${e.dataType}(${e.length})`:`${e.dataType}(${e.length},${e.scale})`:"(미지정)"}function $t(e){return!e||e.trim()===""}function ku(e,n){const o=e.trim();return o?!(n==="entity"?/^[A-Z][A-Za-z0-9]*$/:/^[a-z][A-Za-z0-9]*$/).test(o):!1}function Qo(e){return e==="ZERO_OR_MORE_INSTANCES"||e==="ONE_OR_MORE_INSTANCES"}function yk(e,n){const o=new Map;for(const m of n){if(m.identifying!==!0||m.end1.entityRef===m.end2.entityRef)continue;const f=o.get(m.end1.entityRef)??[];f.push(m.end2.entityRef),o.set(m.end1.entityRef,f)}const i=0,a=1,r=2,l=new Map,s=[],c=[],d=new Set,u=m=>{l.set(m,a),s.push(m);for(const f of o.get(m)??[]){const p=l.get(f)??i;if(p===i)u(f);else if(p===a){const g=s.slice(s.indexOf(f)),y=[...g].sort().join(" ");d.has(y)||(d.add(y),c.push(g))}}s.pop(),l.set(m,r)};for(const m of e)(l.get(m.modelId)??i)===i&&u(m.modelId);return c}function _u(e){return!at(e.stereotype)}function Eu(e){return e.filter(n=>!at(n.stereotype)&&!n.abstractClass)}function Jl(e){var n;return((n=e.table)==null?void 0:n.physicalName)||e.name||""}function gk(e,n){const o=new Set([e.modelId]);let i=e;for(;;){const a=$t(i.superClass)?void 0:n.get(i.superClass);if(!a||o.has(a.modelId))return i.modelId;o.add(a.modelId),i=a}}function bk(e,n){const o=new Map(n.entities.map(a=>[a.name,a]));return new Set(e.map(a=>gk(a,o))).size===1}function Xl(e,n){const o=new Map;for(const i of e){const a=n(i);if(a==null||a==="")continue;const r=o.get(a);r?r.push(i):o.set(a,[i])}return[...o.values()].filter(i=>i.length>1)}function Zl(e,n){const o=new Map;for(const i of e){const a=n(i);a==null||a===""||o.set(a,(o.get(a)??0)+1)}return e.filter(i=>{const a=n(i);return a!=null&&a!==""&&(o.get(a)??0)>1})}function La(e,n){var p,g,y,h,_,N,b,w,I,$;const o=[],i=new Map(e.entities.map(k=>[k.modelId,k])),a=new Map(e.associations.map(k=>[k.modelId,k])),r=dl(e.associations),l=pl(e),s=l.size===0?e.entities:ld(e),c=sd(e,l);for(const k of Xl(s,C=>C.name))for(const C of k){const x=k.filter(V=>V!==C),T=_u(C)&&x.some(_u),z=x.some(V=>!Rg(C,V,e));!T&&!z||o.push({ruleId:"CHK-NAME-3",severity:"warning",targetKind:"entity",targetRef:C.modelId,params:{name:C.name,reason:T?"entity":"package"}})}for(const k of Xl(Eu(s),Jl))if(new Set(k.map(C=>C.name)).size!==1&&!bk(k,e))for(const C of k)o.push({ruleId:"CHK-NAME-9",severity:"error",targetKind:"entity",targetRef:C.modelId,params:{name:Jl(C)}});const d=s.flatMap(k=>(k.indexes??[]).map(C=>({e:k,ix:C})));for(const k of Zl(d,C=>C.ix.name))o.push({ruleId:"CHK-NAME-10",severity:"error",targetKind:"index",targetRef:k.ix.modelId,contextRef:k.e.modelId,params:{name:k.ix.name}});const u=Eu(s).flatMap(k=>{const C=Jl(k);return k.attributes.filter(x=>x.attrType!=="DIVIDER"&&!x.transient).flatMap(x=>x.dbAttrs.flatMap((T,z)=>{if(At(x,T,z,k,e,n).sharedColumnRef!=null)return[];const V=Go(x,T,z,k,e,n);if($t(V))return[];const D=du(T,C,V);return D?[{e:k,a:x,col:T,claim:D}]:[]}))});for(const k of Xl(u,C=>C.claim.name)){const C=k.filter(x=>x.claim.kind==="derived");if(C.length!==0)for(const x of C){const T=k.find(z=>z!==x);o.push({ruleId:"CHK-NAME-12",severity:"error",targetKind:"column",targetRef:x.col.modelId,contextRef:x.e.modelId,params:{name:x.a.name,seq:x.claim.name,other:`${T.e.name}.${T.a.name}`}})}}for(const k of s){const C=k.attributes.filter(S=>S.attrType!=="DIVIDER");if($t(k.name)?o.push({ruleId:"CHK-NAME-4",severity:"info",targetKind:"entity",targetRef:k.modelId}):ku(k.name,"entity")&&o.push({ruleId:"CHK-NAME-11",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{name:k.name}}),k.stereotype==="JPA_ENTITY"&&!k.abstractClass&&(C.some(S=>S.identifier)||o.push({ruleId:"CHK-JPA-1",severity:"error",targetKind:"entity",targetRef:k.modelId}),$t((p=k.table)==null?void 0:p.physicalName)&&o.push({ruleId:"CHK-JPA-8",severity:"warning",targetKind:"entity",targetRef:k.modelId})),at(k.stereotype))for(const S of C.filter(R=>R.identifier))o.push({ruleId:"CHK-JPA-2",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.identifier&&R.transient))o.push({ruleId:"CHK-JPA-12",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C)if(!S.identifier)for(const R of S.dbAttrs)R.autoIncrement&&o.push({ruleId:"CHK-JPA-13",severity:"error",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:S.name}});const x=C.filter(S=>S.identifier&&!S.transient);if(x.reduce((S,R)=>S+R.dbAttrs.length,0)>=2)for(const S of x)for(const R of S.dbAttrs)R.autoIncrement&&o.push({ruleId:"CHK-JPA-20",severity:"error",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&R.identifier))o.push({ruleId:"CHK-JPA-15",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&R.transient))o.push({ruleId:"CHK-JPA-16",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&!R.notNull&&!R.identifier&&!R.transient))o.push({ruleId:"CHK-JPA-17",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});!k.abstractClass&&C.length===0&&o.push({ruleId:"CHK-DSN-2",severity:"warning",targetKind:"entity",targetRef:k.modelId}),(n==null?void 0:n.largeEntityThreshold)!=null&&C.length>n.largeEntityThreshold&&o.push({ruleId:"CHK-DSN-4",severity:"info",targetKind:"entity",targetRef:k.modelId,params:{count:C.length,threshold:n.largeEntityThreshold}});for(const S of Zl(C,R=>R.name))o.push({ruleId:"CHK-NAME-1",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C)if($t(S.name)){const R=(S.attrType.startsWith("RELATION")||S.attrType.startsWith("EMBED"))&&!ul(S,k,r);o.push({ruleId:R?"CHK-NAME-7":"CHK-NAME-4",severity:R?"error":"info",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,...R?{params:{attrType:S.attrType}}:{}})}else ku(S.name,"attribute")&&o.push({ruleId:"CHK-NAME-11",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});const T=C.flatMap(S=>S.dbAttrs.map((R,H)=>({attr:S,index:H,col:R,eff:At(S,R,H,k,e,n),name:Go(S,R,H,k,e,n)})).filter(R=>R.eff.sharedColumnRef==null));for(const S of Zl(T,R=>R.name))o.push({ruleId:"CHK-NAME-2",severity:"error",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of T){if(!$t(S.name)||S.attr.transient||$t(S.attr.name)&&(S.attr.attrType.startsWith("RELATION")||S.attr.attrType.startsWith("EMBED"))||S.attr.attrType==="EMBED_PREDEF"&&!(n!=null&&n.embeddableCatalog))continue;const R=ba(S.attr,k,e.entities,e.associations,S.index);$t(R==null?void 0:R.physicalName)&&o.push({ruleId:"CHK-NAME-8",severity:"warning",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.attr.name}})}for(const S of T){const R=S.col,H=Wl(R.physicalName);H!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{max:xi,len:H}}),n!=null&&n.reservedWords&&!$t(R.physicalName)&&n.reservedWords.has(R.physicalName.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:R.physicalName}}),n!=null&&n.selectableDataTypes&&!$t(R.dataType)&&!n.selectableDataTypes.has(R.dataType)&&o.push({ruleId:"CHK-TYPE-1",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:R.dataType}});const P=S.attr.transient||R.multiValue||S.attr.attrType.startsWith("EMBED")||S.attr.attrType.startsWith("RELATION")?void 0:Tg(S.attr.type,R.dataType,n==null?void 0:n.predefinedCustomTypes);if(P===!1&&o.push({ruleId:"CHK-TYPE-7",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:S.attr.type,dataType:$i(R)}}),S.attr.attrType==="NORMAL"&&!S.attr.transient){const L=S.attr.type===An;if(R.modelId===((g=S.attr.dbAttrs[0])==null?void 0:g.modelId)&&_a(S.attr.type,S.attr.groupCode)&&o.push({ruleId:"CHK-TYPE-9",severity:"warning",targetKind:"attribute",targetRef:S.attr.modelId,contextRef:k.modelId,params:{type:S.attr.type||"(미지정)",groupCode:S.attr.groupCode||"(없음)"}}),L){const j=(R.physicalName??"").trim();j!==""&&!/_code$/.test(j)&&o.push({ruleId:"CHK-TYPE-9",severity:"info",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{physicalName:j}}),!$t(R.dataType)&&R.length!=null&&(R.dataType.toUpperCase()!=="VARCHAR"||R.length<30)&&o.push({ruleId:"CHK-TYPE-9",severity:"info",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:$i(R)}})}}k.stereotype!=="SERIALIZED_TYPE"&&S.attr.attrType==="NORMAL"&&!S.attr.transient&&!S.attr.identifier&&!fo(S.attr,R)&&!$t(R.dataType)&&P!==!1&&Bg(S.attr.type,R.dataType,R.multiValue)&&o.push({ruleId:"CHK-TYPE-8",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:Wo(S.attr.type),boxed:Mg(S.attr.type)??"",dataType:$i(R)}}),P!==!1&&!$t(R.dataType)&&Sg.has(R.dataType)&&!R.length&&(At(S.attr,R,S.index,k,e,n).length||o.push({ruleId:"CHK-TYPE-2",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:R.dataType}}))}for(const S of T)$t(S.col.dataType)&&(S.attr.transient||S.attr.attrType.startsWith("EMBED")||S.attr.attrType.startsWith("RELATION")||o.push({ruleId:"CHK-TYPE-6",severity:"warning",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.attr.name}}));if((y=n==null?void 0:n.embeddableCatalog)!=null&&y.length){const S=po(xn(k,e.entities));for(const R of C){if(R.attrType!=="EMBED_PREDEF")continue;const H=n.embeddableCatalog.find(P=>P.type===R.type);H&&R.dbAttrs.forEach((P,L)=>{if(P.sharedColumnRef==null)return;const j=H.fields[L],X=S.get(P.sharedColumnRef);if(!j||!X)return;(X.dataType!==j.dataType||(X.length??null)!==(j.length??null)||(X.scale??null)!==(j.scale??null))&&o.push({ruleId:"CHK-TYPE-3",severity:"warning",targetKind:"column",targetRef:P.modelId,contextRef:k.modelId,params:{targetType:$i(X),metaName:j.name,metaType:$i(j)}})})}}for(const S of C){const R=S.dbAttrs[0];if(!(R!=null&&R.multiValue))continue;S.type===An&&R.dataType==="VARCHAR"||o.push({ruleId:"CHK-TYPE-4",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:S.type||"",dataType:R.dataType||""}})}for(const S of C){if(S.attrType!=="EMBED_OWN"||!S.embedded)continue;const R=i.get(S.embedded.embeddableRef);if(!R)continue;const H=a.get(S.embedded.associationRef),P=H==null?void 0:H.end1.entityRef===S.embedded.embeddableRef?H.end1:H.end2;if(P&&Qo(P.multiplicity))continue;const L=pn(R).length;S.dbAttrs.length!==L&&o.push({ruleId:"CHK-JPA-21",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name,embeddable:R.name,slots:S.dbAttrs.length,declared:L}})}const z=(h=k.table)==null?void 0:h.physicalName,V=Wl(z);V!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{max:xi,len:V}}),n!=null&&n.reservedWords&&!$t(z)&&n.reservedWords.has(z.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{name:z}});const D=new Set;for(const S of k.attributes){D.add(S.modelId);for(const R of S.dbAttrs)D.add(R.modelId)}const E=new Set(_i(k,(n==null?void 0:n.superClassCatalog)??[]).map(S=>S.modelId)),v=(((_=n==null?void 0:n.superClassCatalog)==null?void 0:_.length)??0)>0,A=uo(k.attributes);for(const S of k.indexes??[]){const R=Wl(S.name);R!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{max:xi,len:R}}),n!=null&&n.reservedWords&&!$t(S.name)&&n.reservedWords.has(S.name.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const H of S.columns){const P=H.columnRef;if(D.has(P)||E.has(P))continue;const L=mo(P);L&&!v||o.push({ruleId:"CHK-DSN-5",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:L?{name:S.name,field:((N=cl(P))==null?void 0:N.field)??P}:{name:S.name}})}S.columns.length===0&&o.push({ruleId:"CHK-DSN-6",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}}),new Set(S.columns.map(H=>A.canon(H.columnRef))).size!==S.columns.length&&o.push({ruleId:"CHK-DSN-7",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}})}}const m=new Map;for(const k of e.entities)for(const C of k.attributes)C.attrType==="EMBED_OWN"&&C.embedded&&m.set(C.embedded.associationRef,C);for(const k of c){if(Qo(k.end1.multiplicity)&&Qo(k.end2.multiplicity)&&o.push({ruleId:"CHK-DSN-1",severity:"info",targetKind:"association",targetRef:k.modelId}),m.has(k.modelId)&&k.identifying&&o.push({ruleId:"CHK-JPA-11",severity:"error",targetKind:"association",targetRef:k.modelId}),!m.has(k.modelId)){const C=!!k.end2.attributeRef&&(((w=(b=k.end2.jpa)==null?void 0:b.cascadeTypes)==null?void 0:w.length)??0)>0,x=!!k.end1.attributeRef&&k.end1.navigable&&((($=(I=k.end1.jpa)==null?void 0:I.cascadeTypes)==null?void 0:$.length)??0)>0;C&&x&&o.push({ruleId:"CHK-JPA-18",severity:"warning",targetKind:"association",targetRef:k.modelId})}if(!m.has(k.modelId)&&k.end1.navigable&&k.end1.attributeRef){const C=i.get(k.end1.entityRef),x=C==null?void 0:C.attributes.some(V=>V.modelId===k.end1.attributeRef),T=i.get(k.end2.entityRef),z=wd(e,k).length>0;x&&T&&z&&(k.end2.attributeRef&&T.attributes.some(D=>D.modelId===k.end2.attributeRef)||o.push({ruleId:"CHK-JPA-19",severity:"error",targetKind:"association",targetRef:k.modelId,params:{child:T.name}}))}for(const C of["end1","end2"]){const x=k[C].jpa;if(!x)continue;const T=x.cascadeTypes??[];T.includes("ALL")&&T.length>1&&o.push({ruleId:"CHK-JPA-5",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),Qo(k[C].multiplicity)&&x.fetchType==="EAGER"&&o.push({ruleId:"CHK-JPA-7",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),x.orphanRemoval&&Qo(k[C==="end1"?"end2":"end1"].multiplicity)&&o.push({ruleId:"CHK-JPA-14",severity:"error",targetKind:"association",targetRef:k.modelId,params:{which:C}}),!Qo(k[C].multiplicity)&&(x.collectionType||x.collectionTable||x.orderColumn)&&o.push({ruleId:"CHK-JPA-9",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),x.collectionType==="SET"&&x.orderColumn&&o.push({ruleId:"CHK-JPA-10",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}})}}const f=new Map(e.entities.map(k=>[k.modelId,k.name||k.modelId]));for(const k of yk(s,c)){const C=[...k,k[0]].map(x=>f.get(x)??x).join(" → ");for(const x of k)o.push({ruleId:"CHK-JPA-4",severity:"warning",targetKind:"entity",targetRef:x,params:{path:C}})}if(n!=null&&n.flagEntitiesWithoutRelations){const k=new Set;for(const x of e.associations)k.add(x.end1.entityRef),k.add(x.end2.entityRef);const C=new Map(e.entities.map(x=>[x.name,x.modelId]));for(const x of e.entities){for(const T of x.attributes)T.embedded&&(k.add(x.modelId),k.add(T.embedded.embeddableRef));if(!$t(x.superClass)){k.add(x.modelId);const T=C.get(x.superClass);T&&k.add(T)}}for(const x of s)k.has(x.modelId)||o.push({ruleId:"CHK-DSN-3",severity:"info",targetKind:"entity",targetRef:x.modelId})}return o}function Ql(e,n){var r,l;if(e.ruleId==="CHK-DSN-7")return kk(e,n);const o=(r=e.params)==null?void 0:r.which;if(o!=="end1"&&o!=="end2"||!e.targetRef)return null;const i=n.associations.find(s=>s.modelId===e.targetRef);if(!i)return null;const a=((l=i[o].jpa)==null?void 0:l.cascadeTypes)??[];return e.ruleId==="CHK-JPA-5"?!a.includes("ALL")||a.length<=1?null:{ruleId:e.ruleId,kind:"setEndCascades",assocRef:i.modelId,which:o,cascades:["ALL"]}:null}function kk(e,n){var s;if(!e.targetRef||!e.contextRef)return null;const o=n.entities.find(c=>c.modelId===e.contextRef),i=(s=o==null?void 0:o.indexes)==null?void 0:s.find(c=>c.modelId===e.targetRef);if(!o||!i)return null;const a=uo(o.attributes),r=new Set,l=i.columns.filter(c=>{const d=a.canon(c.columnRef);return r.has(d)?!1:(r.add(d),!0)});return l.length===i.columns.length?null:{ruleId:e.ruleId,kind:"setIndexColumns",entityRef:o.modelId,indexRef:i.modelId,columns:l}}const _k="CustomMoneyType",Ek="Money";function Nk(e){return!(e.type!==_k||e.attrType!=="NORMAL"||e.identifier||e.dbAttrs.length>1)}function wk(e){const n=e.dbAttrs[0]??{modelId:Fe(),physicalName:"",dataType:""},o={modelId:Fe(),physicalName:"",dataType:""},{customType:i,...a}=e;return{...a,type:Ek,attrType:"EMBED_PREDEF",dbAttrs:[n,o]}}function Ik(e){let n=!1;const o=e.entities.map(i=>{let a=!1;const r=i.attributes.map(l=>Nk(l)?(a=!0,n=!0,wk(l)):l);return a?{...i,attributes:r}:i});return n?{...e,entities:o}:e}function vk(e,n){const o=new Map,i=[],a=new Map;for(const g of e.entities){const y=new Map,h=new Map,_=new Map,N=(b,w,I)=>{if(!b)return;o.get(b)||o.set(b,[{entityId:w,assignedId:b}]),i.push({id:b,entityId:w,sink:I}),I(b)};for(const b of g.attributes){N(b.modelId,g.modelId,w=>y.set(b,w));for(const w of b.dbAttrs)N(w.modelId,g.modelId,I=>h.set(w,I))}for(const b of g.indexes??[])N(b.modelId,g.modelId,w=>_.set(b,w));a.set(g,{attrs:y,cols:h,idx:_})}const r=new Set(o.keys()),l=new Map;for(const g of i){const y=(l.get(g.id)??0)+1;if(l.set(g.id,y),y===1)continue;const h=Ck(g.id,y-1,r);r.add(h),o.get(g.id).push({entityId:g.entityId,assignedId:h}),g.sink(h)}const s=[...o.values()].reduce((g,y)=>g+Math.max(0,y.length-1),0);if(s===0)return{logical:e,layout:n,reissued:0};const c=(g,y)=>{var _;if(!y||!g)return y;const h=o.get(y);return!h||h.length<2?y:((_=h.find(N=>N.entityId===g))==null?void 0:_.assignedId)??y},d=new Map(e.associations.map(g=>[g.modelId,g])),u=(g,y)=>{const h=d.get(g);if(h)return h.end1.entityRef===y?h.end2.entityRef:h.end1.entityRef},m=e.entities.map(g=>{var b;const y=a.get(g),h=g.attributes.map(w=>{const I=y.attrs.get(w),$=w.dbAttrs.map(x=>{const T=y.cols.get(x);return T===x.modelId?x:{...x,modelId:T}});let k=w.derivedFrom;if(k){const x=u(k.associationRef,g.modelId),T=c(x,k.sourceAttributeRef);T!==k.sourceAttributeRef&&(k={...k,sourceAttributeRef:T})}return I!==w.modelId||k!==w.derivedFrom||$.some((x,T)=>x!==w.dbAttrs[T])?{...w,modelId:I,dbAttrs:$,derivedFrom:k}:w}),_=(b=g.indexes)==null?void 0:b.map(w=>{const I=y.idx.get(w),$=w.columns.map(C=>{const x=c(g.modelId,C.columnRef);return x===C.columnRef?C:{...C,columnRef:x}});return I!==w.modelId||$.some((C,x)=>C!==w.columns[x])?{...w,modelId:I,columns:$}:w});return h.some((w,I)=>w!==g.attributes[I])||_&&g.indexes&&_.some((w,I)=>w!==g.indexes[I])?{...g,attributes:h,..._?{indexes:_}:{}}:g}),f=e.associations.map(g=>{const y=c(g.end1.entityRef,g.end1.attributeRef),h=c(g.end2.entityRef,g.end2.attributeRef);return y===g.end1.attributeRef&&h===g.end2.attributeRef?g:{...g,end1:y===g.end1.attributeRef?g.end1:{...g.end1,attributeRef:y},end2:h===g.end2.attributeRef?g.end2:{...g.end2,attributeRef:h}}}),p=n.associationLayouts.map(g=>{const y=d.get(g.associationRef);if(!y)return g;const h=c(y.end1.entityRef,g.sourceColumnRef),_=c(y.end2.entityRef,g.targetColumnRef);return h===g.sourceColumnRef&&_===g.targetColumnRef?g:{...g,sourceColumnRef:h,targetColumnRef:_}});return{logical:{...e,entities:m,associations:f},layout:p.some((g,y)=>g!==n.associationLayouts[y])?{...n,associationLayouts:p}:n,reissued:s}}function Ck(e,n,o){let i=n;for(;;){const a=`dup${i}:${e}`;if(!o.has(a))return a;i++}}const Sk="5.2.54";function Yt(e){return e.reduce((n,o)=>Math.max(n,o.order),-1)+1}function es(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 Nu(e){return!!e.derivedFrom&&e.dbAttrs.length>0}function wu(e){for(const n of e){const o=[...n.attributes].sort((s,c)=>s.order-c.order),i=o.filter(Nu);if(!i.length)continue;const a=o.filter(s=>!Nu(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 ei(e){return JSON.parse(JSON.stringify(e))}function Iu(e,n,o){var C;const i=o.idFactory??Fe,a=o.offset??{x:0,y:0},{logical:r,layout:l}=e,s=new Set(n);if(o.includeRelated){const x=new Set(n);for(const T of r.associations){const z=x.has(T.end1.entityRef),V=x.has(T.end2.entityRef);z!==V&&s.add(z?T.end2.entityRef:T.end1.entityRef)}}const c=r.entities.filter(x=>s.has(x.modelId)),d=new Set(c.map(x=>x.modelId)),u=r.associations.filter(x=>d.has(x.end1.entityRef)&&d.has(x.end2.entityRef)),m=new Set(u.map(x=>x.modelId)),f=new Map,p=x=>{let T=f.get(x);return T||(T=i(),f.set(x,T)),T};for(const x of c){p(x.modelId);for(const T of x.attributes){p(T.modelId);for(const z of T.dbAttrs)p(z.modelId)}for(const T of x.indexes??[])p(T.modelId);for(const T of x.operations??[])p(T.modelId)}for(const x of u)p(x.modelId);const g=x=>f.get(x),y=c.map(x=>{const T=ei(x);T.modelId=g(x.modelId),T.attributes=T.attributes.map(z=>Rk(z,g,m,d));for(const z of T.indexes??[])z.modelId=g(z.modelId),z.columns=z.columns.map(V=>mo(V.columnRef)?V:{...V,columnRef:g(V.columnRef)}).filter(V=>V.columnRef!==void 0);for(const z of T.operations??[])z.modelId=g(z.modelId);return T});wu(y);const h=u.map(x=>{const T=ei(x);return T.modelId=g(x.modelId),T.end1=vu(T.end1,g),T.end2=vu(T.end2,g),T}),_=[];for(const x of r.groups){const T=x.memberEntityRefs.filter(V=>d.has(V));if(T.length===0)continue;const z=ei(x);z.modelId=p(x.modelId),z.memberEntityRefs=T.map(V=>g(V)),_.push(z)}const N=o.collisionSuffix??"_imported",b=new Set(o.existing.entities.map(x=>x.name)),w=new Set(o.existing.entities.map(x=>{var T;return(T=x.table)==null?void 0:T.physicalName}).filter(x=>!!x));for(const x of y)b.has(x.name)&&(x.name=`${x.name}${N}`),(C=x.table)!=null&&C.physicalName&&w.has(x.table.physicalName)&&(x.table.physicalName=`${x.table.physicalName}${N}`);const I=[];for(const x of l.entityLayouts){const T=g(x.entityRef);if(!T)continue;const z=ei(x);z.entityRef=T,z.geo={...z.geo,location:ts(z.geo.location,a)},z.attributeStyles&&(z.attributeStyles=Ba(z.attributeStyles,g)),z.operationStyles&&(z.operationStyles=Ba(z.operationStyles,g)),I.push(z)}const $=[];for(const x of l.associationLayouts){const T=g(x.associationRef);if(!T)continue;const z=ei(x);z.associationRef=T,z.sourceColumnRef=x.sourceColumnRef?g(x.sourceColumnRef):void 0,z.targetColumnRef=x.targetColumnRef?g(x.targetColumnRef):void 0,z.waypoints=z.waypoints.map(V=>ts(V,a)),$.push(z)}const k=[];for(const x of l.groupLayouts){const T=g(x.groupRef);if(!T)continue;const z=ei(x);z.groupRef=T,z.geo={...z.geo,location:ts(z.geo.location,a)},delete z.memberNoteRefs,k.push(z)}return{logical:{entities:y,associations:h,groups:_},layout:{entityLayouts:I,associationLayouts:$,groupLayouts:k},idMap:f}}function ts(e,n){return{x:e.x+n.x,y:e.y+n.y}}function Rk(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 vu(e,n){return{...e,entityRef:n(e.entityRef),attributeRef:e.attributeRef?n(e.attributeRef):void 0}}function Ba(e,n){const o={};for(const[i,a]of Object.entries(e)){const r=n(i);r&&(o[r]=a)}return o}function ns(e){if(!("rev"in e))return e;const{rev:n,...o}=e;return o}function No(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)=>No(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(!No(e[i],n[i]))return!1;return!0}return!1}function wo(e,n,o){const i={},a=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of a)o.has(r)||No(e[r],n[r])||(i[r]=n[r]===void 0?null:n[r]);return Object.keys(i).length?i:null}function Io(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 Ak(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 xk=new Set(["attributes","operations","indexes","rev"]),$k=new Set(["end1","end2","rev"]),Tk=new Set(["memberEntityRefs","rev"]),Cu=new Set(["modelId"]),Mk=new Set(["modelId","columns"]),Vk=new Set([]);function Lk(e,n,o,i){const a=Io(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=wo(s,c,Cu);d&&i.push({kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId,patch:d})}const r=Io(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=wo(s,c,Cu);d&&i.push({kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId,patch:d})}const l=Io(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(!No(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=wo(s,c,Mk);d&&i.push({kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId,patch:d})}}function Bk(e,n,o){const i=Io(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:ns(l)});for(const{cur:l,tgt:s}of i.common){const c=wo(l,s,xk);c&&o.push({kind:"entity.update",casUnit:"logical",containerRef:l.modelId,entityRef:l.modelId,patch:c}),Lk(l.modelId,l,s,o)}const a=Io(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:ns(l)});for(const{cur:l,tgt:s}of a.common){const c=wo(l,s,$k);c&&o.push({kind:"association.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,patch:c});for(const d of["end1","end2"]){const u=wo(l[d]??{},s[d]??{},Vk);u&&o.push({kind:"associationEnd.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,end:d,patch:u})}}const r=Io(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:ns(l)});for(const{cur:l,tgt:s}of r.common){const c=wo(l,s,Tk);c&&o.push({kind:"group.update",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,patch:c});const d=Ak(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 Da(e,n,o,i,a,r,l){const s=Io(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)No(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 Dk(e,n,o){Da(e.entityLayouts??[],n.entityLayouts??[],i=>i.entityRef,"entityLayout.add","entityLayout.remove","entityRef",o),Da(e.associationLayouts??[],n.associationLayouts??[],i=>i.associationRef,"associationLayout.add","associationLayout.remove","associationRef",o),Da(e.groupLayouts??[],n.groupLayouts??[],i=>i.groupRef,"groupLayout.add","groupLayout.remove","groupRef",o),Da(e.notes??[],n.notes??[],i=>i.modelId,"note.add","note.remove","noteRef",o)}function Ok(e,n){const o=[];return Bk(e.logical,n.logical,o),Dk(e.layout,n.layout,o),o}function Pk(e){if(e.groupRef!=null)return"group";if(e.noteRef!=null)return"note";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/noteRef 중 하나 필요).")}const zk={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([]),note:new Set(["geo","style","connections","legacyRaw","modelId"])};class Fk{constructor(n){rt(this,"out",[]);rt(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({...Ti(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({...Ti(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({...Ti(n),field:a,value:void 0,removed:!0});continue}this.out.push({...Ti(n),field:a,value:void 0,removed:!0,oldValue:this.last.get(a)}),this.last.delete(a)}}collectionMember(n,o,i,a){this.fieldFilter!=null&&o!==this.fieldFilter||this.out.push({...Ti(n),field:o,value:i,...a?{removed:!0}:{}})}member(n,o,i){this.collectionMember(n,"memberEntityRefs",o,i)}result(){return this.out}}function Ti(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 en(e,n,o,i){if(o==null||typeof o!="object")return;const a=zk[i];for(const[r,l]of Object.entries(o))a.has(r)||e.set(n,r,l)}function vo(e,n,o){if(!(o==null||typeof o!="object"))for(const[i,a]of Object.entries(o))e.set(n,i,a)}function os(e,n){if(Array.isArray(e))return e.find(o=>o.modelId===n)}function Mn(e,n){var r,l,s,c,d,u,m,f,p,g;const o=Pk(n),i=new Fk(n.field),a=[...e].sort((y,h)=>y.seq-h.seq);for(const y of a)for(const h of y.ops)switch(o){case"entity":if(h.entityRef!==n.entityRef)break;h.kind==="entity.add"?en(i,y,h.value,"entity"):h.kind==="entity.update"?vo(i,y,h.patch):h.kind==="entity.remove"&&i.remove(y);break;case"attribute":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((r=h.value)==null?void 0:r.attributes,n.attributeRef);_&&en(i,y,_,"attribute")}else h.kind==="attribute.add"&&((l=h.value)==null?void 0:l.modelId)===n.attributeRef?en(i,y,h.value,"attribute"):h.kind==="attribute.update"&&h.attributeRef===n.attributeRef?vo(i,y,h.patch):(h.kind==="attribute.remove"&&h.attributeRef===n.attributeRef||h.kind==="entity.remove")&&i.remove(y);break;case"operation":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((s=h.value)==null?void 0:s.operations,n.operationRef);_&&en(i,y,_,"operation")}else h.kind==="operation.add"&&((c=h.value)==null?void 0:c.modelId)===n.operationRef?en(i,y,h.value,"operation"):h.kind==="operation.update"&&h.operationRef===n.operationRef?vo(i,y,h.patch):(h.kind==="operation.remove"&&h.operationRef===n.operationRef||h.kind==="entity.remove")&&i.remove(y);break;case"index":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((d=h.value)==null?void 0:d.indexes,n.indexRef);_&&en(i,y,_,"index")}else h.kind==="index.add"&&((u=h.value)==null?void 0:u.modelId)===n.indexRef?en(i,y,h.value,"index"):h.kind==="index.update"&&h.indexRef===n.indexRef?vo(i,y,h.patch):(h.kind==="index.remove"&&h.indexRef===n.indexRef||h.kind==="entity.remove")&&i.remove(y);break;case"association":if(h.associationRef!==n.associationRef)break;h.kind==="association.add"?en(i,y,h.value,"association"):h.kind==="association.update"?vo(i,y,h.patch):h.kind==="association.remove"&&i.remove(y);break;case"associationEnd":if(h.associationRef!==n.associationRef)break;if(h.kind==="association.add"){const _=(m=h.value)==null?void 0:m[n.end];en(i,y,_,"associationEnd")}else h.kind==="associationEnd.update"&&h.end===n.end?vo(i,y,h.patch):h.kind==="association.remove"&&i.remove(y);break;case"group":if(h.groupRef!==n.groupRef)break;if(h.kind==="group.add"){en(i,y,h.value,"group");const _=(f=h.value)==null?void 0:f.memberEntityRefs;if(Array.isArray(_))for(const N of _)i.member(y,N,!1)}else h.kind==="group.update"?vo(i,y,h.patch):h.kind==="group.remove"?i.remove(y):h.kind==="group.addMember"&&h.entityRef!=null?i.member(y,h.entityRef,!1):h.kind==="group.removeMember"&&h.entityRef!=null&&i.member(y,h.entityRef,!0);break;case"note":if(h.noteRef!==n.noteRef)break;if(h.kind==="note.add"){en(i,y,h.value,"note");const _=(p=h.value)==null?void 0:p.connections;if(Array.isArray(_))for(const N of _){const b=N.targetRef;typeof b=="string"&&i.collectionMember(y,"connections",b,!1)}}else if(h.kind==="note.setMemo"){const _=(g=h.value)==null?void 0:g.memo;_!==void 0&&i.set(y,"memo",_)}else h.kind==="note.remove"?i.remove(y):h.kind==="noteConnection.add"&&typeof h.targetRef=="string"?i.collectionMember(y,"connections",h.targetRef,!1):h.kind==="noteConnection.remove"&&typeof h.targetRef=="string"&&i.collectionMember(y,"connections",h.targetRef,!0);break}return i.result()}const gt={subject:null,existence:null,fieldAudit:!1,note:"레이아웃 축(LWW) — 감사·복원 diff는 논리 축 전용(AA-5: 좌표·크기·스타일은 의도적 범위 밖)"},Oa={subject:null,existence:null,fieldAudit:!1,note:"노트의 기하·스타일 축 — 캔버스에서 가장 자주 바뀌어 편입하면 이력을 덮는다(존재·메모·연결만 편입)"},Uk={"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":gt,"entityLayout.remove":gt,"entityLayout.move":gt,"entityLayout.resize":gt,"entityLayout.setCollapsed":gt,"entityLayout.setLocked":gt,"entityLayout.setStyle":gt,"entityLayout.setAttrStyle":gt,"entityLayout.setOpStyle":gt,"groupLayout.add":gt,"groupLayout.remove":gt,"groupLayout.move":gt,"groupLayout.resize":gt,"groupLayout.setLocked":gt,"groupLayout.setStyle":gt,"groupLayout.addNoteMember":gt,"groupLayout.removeNoteMember":gt,"associationLayout.add":gt,"associationLayout.remove":gt,"associationLayout.setWaypoints":gt,"note.add":{subject:"note",existence:"add",fieldAudit:!0},"note.remove":{subject:"note",existence:"remove",fieldAudit:!0},"note.setMemo":{subject:"note",existence:null,fieldAudit:!0},"note.move":Oa,"note.resize":Oa,"note.setStyle":Oa,"noteConnection.add":{subject:"note",existence:null,fieldAudit:!0},"noteConnection.remove":{subject:"note",existence:null,fieldAudit:!0},"noteConnection.setWaypoints":Oa},Kt=e=>typeof e=="string"?e:void 0,Hk=e=>{var n;return Kt((n=e.value)==null?void 0:n.modelId)};function Su(e){return Kt(e.containerRef)??Kt(e.entityRef)}function is(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=Kt(s.modelId);c&&r.push({subject:{kind:o,ref:c,...i?{entityRef:i}:{}},existence:"add",inline:!0})}return r}function Pa(e){const n=Uk[e.kind];if(!n||!n.subject)return[];const o=e,i=n.existence??void 0;switch(n.subject){case"entity":{const a=Kt(o.entityRef);if(!a)return[];const r={subject:{kind:"entity",ref:a},...i?{existence:i}:{}};return e.kind!=="entity.add"?[r]:[r,...is(o,"attributes","attribute",a),...is(o,"operations","operation",a),...is(o,"indexes","index",a)]}case"attribute":case"operation":case"index":{const a=n.subject,r=Su(o),l={attribute:"attributeRef",operation:"operationRef",index:"indexRef"}[a],s=i==="add"?Hk(o):Kt(o[l]);return s?[{subject:{kind:a,ref:s,...r?{entityRef:r}:{}},...i?{existence:i}:{}}]:[]}case"association":case"associationEnd":{const a=Kt(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=Kt(o.groupRef);return a?[{subject:{kind:"group",ref:a},...i?{existence:i}:{}}]:[]}case"note":{const a=Kt(o.noteRef);return a?[{subject:{kind:"note",ref:a},...i?{existence:i}:{}}]:[]}}}function jk(e){const n=e,o=e.kind;if(o.startsWith("entity.")){const i=Kt(n.entityRef);return i?{kind:"entity",ref:i}:null}if(o.startsWith("attribute.")||o.startsWith("operation.")||o.startsWith("index.")){const i=Su(n);return i?{kind:"entity",ref:i}:null}if(o.startsWith("associationEnd.")||o.startsWith("association.")){const i=Kt(n.associationRef);return i?{kind:"association",ref:i}:null}if(o.startsWith("group.")){const i=Kt(n.groupRef);return i?{kind:"group",ref:i}:null}if(o.startsWith("note.")||o.startsWith("noteConnection.")){const i=Kt(n.noteRef);return i?{kind:"note",ref:i}:null}return null}function Kk(e,n){const o=e;return o.entityRef===n||o.containerRef===n}function Gk(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 Pa(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 za(e,n){return e.map(o=>({...o,subject:n}))}function Ru(e,n){const o=e.filter(s=>s.ops.some(c=>Kk(c,n))),{attributes:i,operations:a,indexes:r}=Gk(o,n),l=[...za(Mn(o,{entityRef:n}),{kind:"entity",ref:n})];for(const s of i)l.push(...za(Mn(o,{entityRef:n,attributeRef:s}),{kind:"attribute",ref:s}));for(const s of a)l.push(...za(Mn(o,{entityRef:n,operationRef:s}),{kind:"operation",ref:s}));for(const s of r)l.push(...za(Mn(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 Fa(e){return`${e.kind}:${e.ref}:${e.end??""}`}function qk(e){const n=new Set;for(const o of e)for(const i of o.ops)for(const a of Pa(i))a.existence==="add"&&n.add(Fa(a.subject));return n}function Yk(e){const n=new Map;for(const o of e)for(const i of o.ops)for(const a of Pa(i)){if(a.existence!=="remove")continue;let r=n.get(o.seq);r||(r=new Map,n.set(o.seq,r)),r.set(Fa(a.subject),a.subject)}return n}function Wk(e){const n=new Set,o=new Set,i=new Set,a=new Set,r={entity:n,association:o,group:i,note:a};for(const l of e)for(const s of l.ops){const c=jk(s);c&&r[c.kind].add(c.ref)}return{entities:n,associations:o,groups:i,notes:a}}function Jk(e){const{entities:n,associations:o,groups:i,notes:a}=Wk(e),r=[];for(const l of n)for(const s of Ru(e,l))r.push({...s,subject:{...s.subject,entityRef:l}});for(const l of o){for(const s of Mn(e,{associationRef:l}))r.push({...s,subject:{kind:"association",ref:l}});for(const s of["end1","end2"])for(const c of Mn(e,{associationRef:l,end:s}))r.push({...c,subject:{kind:"associationEnd",ref:l,end:s}})}for(const l of i)for(const s of Mn(e,{groupRef:l}))r.push({...s,subject:{kind:"group",ref:l}});for(const l of a)for(const s of Mn(e,{noteRef:l}))r.push({...s,subject:{kind:"note",ref:l}});return r}function as(e){const n=Jk(e),o=qk(e),i=Yk(e),a=(c,d)=>{var u;return((u=i.get(c))==null?void 0:u.has(d))===!0},r=new Map;for(const c of n){const d=Fa(c.subject),u=r.get(d);(u===void 0||c.seq<u)&&r.set(d,c.seq)}const l=new Map;for(const c of n){let d=l.get(c.seq);d||(d={meta:c,subjects:new Map},l.set(c.seq,d));const u=Fa(c.subject),m=a(c.seq,u);let f=d.subjects.get(u);if(!f){const p=m?"remove":r.get(u)===c.seq&&o.has(u)?"add":"update";f={subject:c.subject,verb:p,fields:[]},d.subjects.set(u,f)}m&&c.removed||f.fields.push({field:c.field,value:c.value,...c.oldValue!==void 0?{oldValue:c.oldValue}:{},...c.removed?{removed:!0}:{}})}for(const c of e){const d=i.get(c.seq);if(!d)continue;let u=l.get(c.seq);u||(u={meta:c,subjects:new Map},l.set(c.seq,u));for(const[m,f]of d){const p=u.subjects.get(m),g=f.kind==="entity"?{...f,entityRef:f.ref}:f;p?p.verb="remove":u.subjects.set(m,{subject:g,verb:"remove",fields:[]})}}const s=[];for(const[c,d]of l){const u=d.meta;s.push({seq:c,...u.ts!==void 0?{ts:u.ts}:{},...u.origin!==void 0?{origin:u.origin}:{},...u.author!==void 0?{author:u.author}:{},...u.kind!==void 0?{kind:u.kind}:{},...u.restoredFromSeq!==void 0?{restoredFromSeq:u.restoredFromSeq}:{},actions:[...d.subjects.values()]})}return s.sort((c,d)=>d.seq-c.seq)}function Au(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Xk(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 Pa(r)){if(!l.existence||l.inline)continue;const s=l.subject;Zk.has(s.kind)&&!s.entityRef||i.push({seq:a.seq,subject:s,verb:l.existence,fields:[]})}return i}const Zk=new Set(["attribute","operation","index"]);function rs(e,n){const{fromSeq:o}=n,i=as(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 f=Au(m.subject);let p=s.get(f);p||(p={subject:m.subject,evs:[]},s.set(f,p)),p.evs.push(m)};for(const m of l)for(const f of m.actions)c({seq:m.seq,subject:f.subject,verb:f.verb,fields:f.fields});for(const m of Xk(e,o,r)){const f=s.get(Au(m.subject));f!=null&&f.evs.some(p=>p.seq===m.seq)||c(m)}const d=[],u=new Set;for(const m of s.values()){m.evs.sort((p,g)=>p.seq-g.seq);const f=m.evs[m.evs.length-1];m.subject.kind==="entity"&&f.verb==="remove"&&u.add(m.subject.ref)}for(const m of s.values()){const f=m.evs[0].verb==="add",p=m.evs[m.evs.length-1].verb==="remove";if(m.subject.kind!=="entity"&&m.subject.entityRef&&u.has(m.subject.entityRef)||f&&p)continue;const g=new Map;let y=null;for(const _ of m.evs){_.verb==="add"&&y!==null&&y!=="add"&&g.clear(),y=_.verb;for(const N of _.fields){const b=g.get(N.field);b?b.lastValue=N.value:g.set(N.field,{firstOld:N.oldValue,hasOld:N.oldValue!==void 0,lastValue:N.value})}}if(p){d.push({subject:m.subject,verb:"removed",fields:[]});continue}if(f){const _=[];for(const[N,b]of g)_.push({field:N,value:b.lastValue});d.push({subject:m.subject,verb:"added",fields:_});continue}const h=[];for(const[_,N]of g)N.hasOld&&No(N.firstOld,N.lastValue)||h.push({field:_,value:N.lastValue,...N.hasOld?{oldValue:N.firstOld}:{}});h.length!==0&&d.push({subject:m.subject,verb:"modified",fields:h})}return{fromSeq:o,toSeq:r,entries:d}}function xu(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 ls{constructor(n){rt(this,"undoStack",[]);rt(this,"redoStack",[]);rt(this,"savePoint",null);rt(this,"listeners",new Set);rt(this,"commandListeners",new Set);rt(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 zt(e){const n={};for(const[o,i]of Object.entries(e))n[o]=i===void 0?null:i;return n}function $u(e,n){var r,l;const o={logical:structuredClone(e.logical),layout:structuredClone(e.layout)},i=[],a=[];for(const s of n){s.apply(o);const c=((l=(r=s.emitOps)==null?void 0:r.call(s,o))==null?void 0:l.forward)??[];c.length===0&&a.push(s.label),i.push(...c)}return{ops:i,skipped:a}}function Tu(e,n){return e.logical.entities.findIndex(o=>o.modelId===n)}function It(e,n){return e.layout.entityLayouts.findIndex(o=>o.entityRef===n)}function tn(e,n){return e.layout.associationLayouts.find(o=>o.associationRef===n)}function st(e,n){const o=e.logical.entities.find(i=>i.modelId===n);if(!o)throw new Error(`엔티티 없음: ${n}`);return o}function Vn(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 Ua(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=Tu(i,e.modelId);a>=0&&i.logical.entities.splice(a,1);const r=It(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 Mu(e){let n=null;const o=i=>i.end1.entityRef===e||i.end2.entityRef===e;return{label:"엔티티 삭제",apply(i){const a=Tu(i,e);if(a<0)throw new Error(`엔티티 없음: ${e}`);const r=It(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(f=>f.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 Ha(e,n){const o={};return{label:"엔티티 수정",apply(i){const a=st(i,e);for(const r of Object.keys(n))o[r]=a[r];Object.assign(a,n)},invert(i){Object.assign(st(i,e),o)},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:zt(n)}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:zt(o)}]}}}}function Vu(e,n){let o="";return{label:`엔티티 이름 변경: ${n}`,apply(i){const a=st(i,e);o=a.name,a.name=n},invert(i){st(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 ti(e,n){let o=null;return{label:"엔티티 이동",apply(i){const a=It(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=It(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 Lu(e,n){let o=null;return{label:"엔티티 크기 변경",apply(i){const a=It(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=It(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 Mi(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 Bu(e,n){let o;return{label:"엔티티 색상 변경",apply(i){const a=It(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.style,r.style=Mi(r.style,n)},invert(i){const a=It(i,e);a>=0&&(i.layout.entityLayouts[a].style=o)},emitOps(i){const a=It(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 Du(e,n){let o;return{label:n?"엔티티 접기":"엔티티 펼치기",apply(i){const a=It(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=It(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 Ou(e,n){let o;return{label:n?"엔티티 잠금":"엔티티 잠금 해제",apply(i){const a=It(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=It(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 ss(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 ja(e,n,o){let i;return{label:"속성 색상 변경",apply(a){const r=It(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.attributeStyles;const s={...l.attributeStyles},c=Mi(s[n],o);c?s[n]=c:delete s[n],l.attributeStyles=Object.keys(s).length?s:void 0},invert(a){const r=It(a,e);r>=0&&(a.layout.entityLayouts[r].attributeStyles=i)},emitOps(a){const r=It(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 Ka(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 Pu(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:zt(n)}],invert:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:zt(o)}]}}}}function zu(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 Fu(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 Ga(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 Uu(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 Hu(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 ju(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=Mi(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 Ku(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 Wt(e,n){return{label:`속성 추가: ${n.name}`,apply(o){st(o,e).attributes.push(n)},invert(o){const i=st(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 nn(e,n,o){const i={},a=r=>{const l=st(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:zt(o)}],invert:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:zt(i)}]}}}}function Gu(e,n){let o=null;return{label:"속성 삭제",apply(i){const a=st(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&&st(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 qu(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 cs(e,n,o){let i=null;return{label:"속성 재정렬",apply(a){const r=st(a,e);i=r.attributes.map(s=>({...s}));const l=es([...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&&st(a,e).attributes.splice(0,1/0,...i)},emitOps(a){const r=st(a,e).attributes;return qu("attribute.update","attributeRef",e,r,i??[])}}}function Yu(e,n){let o=!1;return{label:`메서드 추가: ${n.name}`,apply(i){const a=st(i,e);a.operations||(a.operations=[],o=!0),a.operations.push(n)},invert(i){var l;const a=st(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 Wu(e,n,o){const i={},a=r=>{var s;const l=(s=st(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:zt(o)}],invert:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:zt(i)}]}}}}function Ju(e,n){let o=null;return{label:"메서드 삭제",apply(i){var s;const a=st(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=st(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 Xu(e,n,o){let i=null;return{label:"메서드 재정렬",apply(a){const r=st(a,e),l=r.operations??[];i=l.map(c=>({...c}));const s=es([...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=st(a,e);r.operations&&r.operations.splice(0,1/0,...i)},emitOps(a){const r=st(a,e).operations??[];return qu("operation.update","operationRef",e,r,i??[])}}}function Zu(e,n,o){let i;return{label:"메서드 색상 변경",apply(a){const r=It(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.operationStyles;const s={...l.operationStyles},c=Mi(s[n],o);c?s[n]=c:delete s[n],l.operationStyles=Object.keys(s).length?s:void 0},invert(a){const r=It(a,e);r>=0&&(a.layout.entityLayouts[r].operationStyles=i)},emitOps(a){const r=It(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 qa(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 Qu(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 Ya(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:zt(n)}],invert:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:zt(o)}]}}}}function on(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:zt(o)}],invert:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:zt(i)}]}}}}function em(e,n){return{label:"인덱스 추가",apply(o){const i=st(o,e);(i.indexes??(i.indexes=[])).push(n)},invert(o){var r;const i=st(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 Wa(e,n,o){const i={},a=r=>{var s;const l=(s=st(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:zt(o)}],invert:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:zt(i)}]}}}}function tm(e,n){let o=null;return{label:"인덱스 삭제",apply(i){var l;const a=st(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&&st(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 yn=(e,n)=>({kind:"associationLayout.setWaypoints",casUnit:"layout",associationRef:e,value:{waypoints:n}}),Vi=(e,n)=>{var o;return((o=tn(e,n))==null?void 0:o.waypoints.map(i=>({...i})))??[]};function nm(e,n,o){let i=null;return{label:"waypoint 이동",coalesceKey:`waypoint:${e}`,apply(a){const r=tn(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=tn(a,e);r&&i&&r.waypoints.splice(n,1,i)},emitOps(a){const r=Vi(a,e),l=r.map((s,c)=>c===n&&i?{...i}:s);return{forward:[yn(e,r)],invert:[yn(e,l)]}}}}function om(e,n){let o=null;return{label:"waypoint 제거",apply(i){const a=tn(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=tn(i,e);a&&o&&a.waypoints.splice(n,0,o)},emitOps(i){const a=Vi(i,e),r=a.slice();return o&&r.splice(n,0,{...o}),{forward:[yn(e,a)],invert:[yn(e,r)]}}}}function im(e,n,o){let i=null;return{label:"waypoint 평행이동",apply(a){const r=tn(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=tn(a,e);r&&i&&(r.waypoints=i)},emitOps(a){return{forward:[yn(e,Vi(a,e))],invert:[yn(e,i??[])]}}}}function am(e){let n=null;return{label:"꺾은선 풀기",apply(o){const i=tn(o,e);if(!i)throw new Error(`관계 레이아웃 없음: ${e}`);n=i.waypoints.map(a=>({...a})),i.waypoints=[]},invert(o){const i=tn(o,e);i&&n&&(i.waypoints=n)},emitOps(o){return{forward:[yn(e,Vi(o,e))],invert:[yn(e,n??[])]}}}}function rm(e,n,o){return{label:"waypoint 추가",apply(i){const a=tn(i,e);if(!a)throw new Error(`관계 레이아웃 없음: ${e}`);a.waypoints.splice(n,0,{...o})},invert(i){const a=tn(i,e);a==null||a.waypoints.splice(n,1)},emitOps(i){const a=Vi(i,e),r=a.slice();return r.splice(n,1),{forward:[yn(e,a)],invert:[yn(e,r)]}}}}function lm(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 sm(e){let n=null,o=null;return{label:"노트 삭제",apply(i){var r;const a=i.layout.notes.findIndex(l=>l.modelId===e);if(a<0)throw new Error(`노트 없음: ${e}`);n={item:i.layout.notes[a],index:a},i.layout.notes.splice(a,1);for(const l of i.layout.groupLayouts){const s=((r=l.memberNoteRefs)==null?void 0:r.indexOf(e))??-1;if(!(s<0)){l.memberNoteRefs.splice(s,1),o={groupRef:l.groupRef,index:s};break}}},invert(i){if(n&&i.layout.notes.splice(n.index,0,n.item),!o)return;const a=i.layout.groupLayouts.find(r=>r.groupRef===o.groupRef);a&&(a.memberNoteRefs||(a.memberNoteRefs=[]),a.memberNoteRefs.splice(o.index,0,e))},emitOps(){if(!n)return{forward:[],invert:[]};const i=[],a=[];return o&&(i.push({kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:o.groupRef,noteRef:e,incidental:!0}),a.push({kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:o.groupRef,noteRef:e,incidental:!0})),i.push({kind:"note.remove",casUnit:"layout",noteRef:e}),a.push({kind:"note.add",casUnit:"layout",noteRef:e,value:n.item}),{forward:i,invert:a.reverse()}}}}function Li(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 cm(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 dm(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 um(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=Mi(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 mm(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 fm(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 Zn=(e,n,o)=>({kind:"noteConnection.setWaypoints",casUnit:"layout",noteRef:e,targetRef:n,value:{waypoints:o}}),Ja=(e,n,o)=>{var i;return((i=Vn(e,n,o))==null?void 0:i.waypoints.map(a=>({...a})))??[]};function pm(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 hm(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 ym(e,n,o,i){let a=null;return{label:"waypoint 이동",coalesceKey:`noteConnWaypoint:${e}:${n}`,apply(r){const l=Vn(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=Vn(r,e,n);l&&a&&l.waypoints.splice(o,1,a)},emitOps(r){const l=Ja(r,e,n),s=l.map((c,d)=>d===o&&a?{...a}:c);return{forward:[Zn(e,n,l)],invert:[Zn(e,n,s)]}}}}function gm(e,n,o,i){return{label:"waypoint 추가",apply(a){const r=Vn(a,e,n);if(!r)throw new Error(`노트 연결 없음: ${e}→${n}`);r.waypoints.splice(o,0,{...i})},invert(a){const r=Vn(a,e,n);r==null||r.waypoints.splice(o,1)},emitOps(a){const r=Ja(a,e,n),l=r.slice();return l.splice(o,1),{forward:[Zn(e,n,r)],invert:[Zn(e,n,l)]}}}}function bm(e,n,o){let i=null;return{label:"waypoint 제거",apply(a){const r=Vn(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=Vn(a,e,n);r&&i&&r.waypoints.splice(o,0,i)},emitOps(a){const r=Ja(a,e,n),l=r.slice();return i&&l.splice(o,0,{...i}),{forward:[Zn(e,n,r)],invert:[Zn(e,n,l)]}}}}function km(e,n){let o=null;return{label:"꺾은선 풀기",apply(i){const a=Vn(i,e,n);if(!a)throw new Error(`노트 연결 없음: ${e}→${n}`);o=a.waypoints.map(r=>({...r})),a.waypoints=[]},invert(i){const a=Vn(i,e,n);a&&o&&(a.waypoints=o)},emitOps(i){return{forward:[Zn(e,n,Ja(i,e,n))],invert:[Zn(e,n,o??[])]}}}}function it(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 Qk=Object.freeze(Object.defineProperty({__proto__:null,addAssociation:qa,addAttribute:Wt,addEntity:Ua,addEntityToGroup:Fu,addGroup:Ka,addIndex:em,addNote:lm,addNoteConnection:pm,addNoteConnectionWaypoint:gm,addNoteToGroup:mm,addOperation:Yu,addWaypoint:rm,clearNoteConnectionWaypoints:km,clearWaypoints:am,composite:it,moveEntity:ti,moveGroup:Uu,moveNote:Li,moveNoteConnectionWaypoint:ym,moveWaypoint:nm,removeAssociation:Qu,removeAttribute:Gu,removeEntity:Mu,removeEntityFromGroup:Ga,removeGroup:zu,removeIndex:tm,removeNote:sm,removeNoteConnection:hm,removeNoteConnectionWaypoint:bm,removeNoteFromGroup:fm,removeOperation:Ju,removeWaypoint:om,renameEntity:Vu,reorderAttributes:cs,reorderOperations:Xu,resizeEntity:Lu,resizeGroup:Hu,resizeNote:cm,setAllEntitiesCollapsed:ss,setAttributeSwatch:ja,setEntityCollapsed:Du,setEntityLocked:Ou,setEntitySwatch:Bu,setGroupLocked:Ku,setGroupSwatch:ju,setNoteMemo:dm,setNoteSwatch:um,setOperationSwatch:Zu,translateWaypoints:im,updateAssociation:Ya,updateAssociationEnd:on,updateAttribute:nn,updateEntity:Ha,updateGroup:Pu,updateIndex:Wa,updateOperation:Wu},Symbol.toStringTag,{value:"Module"}));class _m{constructor(){rt(this,"revs",new Map);rt(this,"layoutVersion",0);rt(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 e_=[400,1200];function t_(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 n_(e){const n=t_(e);return n==null||n===408||n===429?!0:n<400||n>=500}const o_=e=>new Promise(n=>setTimeout(n,e));class Em{constructor(n){rt(this,"cache",new _m);rt(this,"newClientOpId");rt(this,"debounceMs");rt(this,"retryDelaysMs");rt(this,"emissions",new WeakMap);rt(this,"open",null);rt(this,"debounceHandle",null);rt(this,"queue",[]);rt(this,"sending",!1);rt(this,"_frozen",!1);rt(this,"stack",null);rt(this,"settledWaiters",[]);this.opts=n,this.newClientOpId=n.newClientOpId??Fe,this.debounceMs=n.debounceMs??300,this.retryDelaysMs=n.retryDelaysMs??e_}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||!n_(l)){this.sending=!1,console.error("[op-sync] 전송 실패 확정 → 하드 프리즈(kind:missing)"),this.freeze({kind:"missing"});return}await o_(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 Nm=["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"],wm=["NORMAL","RELATION_OWN","RELATION_REF","EMBED_OWN","EMBED_REF","EMBED_PREDEF","DIVIDER"];function Im(e,n,o){var c;if(!n.length||!((c=e.indexes)!=null&&c.length))return[];const i=new Set(n),a=new Set,r=new Map,l=d=>{const u=o==null?void 0:o.get(d);u===void 0?a.add(d):u!==d&&r.set(d,u)};for(const d of e.attributes)if(i.has(d.modelId)){l(d.modelId);for(const u of d.dbAttrs)l(u.modelId)}if(!a.size&&!r.size)return[];const s=[];for(const d of e.indexes){let u=!1;const m=[];for(const f of d.columns){if(a.has(f.columnRef)){u=!0;continue}const p=r.get(f.columnRef);p===void 0?m.push(f):(m.push({...f,columnRef:p}),u=!0)}u&&s.push({indexRef:d.modelId,columns:m})}return s}function i_(e){return pn(e).length}function ds(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 a_(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=Go(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 vm(e,n,o=Fe){const i=e.entities.find(c=>c.modelId===n);if(!i)return[];const a=i_(i);if(a===0)return[];const r=ds(e,n),l=pn(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;a_(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 Cm(e,n,o){var f;const i=e.entities.find(p=>p.modelId===n);if(!i)return[];const a=i.attributes;if(o.length!==a.length)return[];const r=new Map(a.map(p=>[p.modelId,p])),l=[];for(const p of o){const g=r.get(p);if(!g)return[];l.push(g)}const s=a.flatMap(p=>p.dbAttrs).map(p=>p.modelId),c=l.flatMap(p=>p.dbAttrs).map(p=>p.modelId);if(s.length!==c.length)return[];if(s.every((p,g)=>p===c[g]))return[];const d=new Map(s.map((p,g)=>[p,g])),u=ds(e,n),m=[];for(const p of e.entities)for(const g of p.attributes){if(g.attrType!=="EMBED_OWN"||((f=g.embedded)==null?void 0:f.embeddableRef)!==n||u.has(g.embedded.associationRef)||g.dbAttrs.length!==s.length)continue;const y=c.map(_=>g.dbAttrs[d.get(_)]),h=y.reduce((_,N,b)=>N===g.dbAttrs[b]?_:_+1,0);h&&m.push({entityId:p.modelId,attributeId:g.modelId,dbAttrs:y,moved:h})}return m}function Sm(e,n,o){const i=e.entities.find(l=>l.modelId===n);if(!i)return[];const a=new Set(o),r=i.attributes.filter(l=>!a.has(l.modelId));return r.length===i.attributes.length?[]:r_(e,n,{...i,attributes:r})}function r_(e,n,o){var l;const i=[],a=new Set;let r=new Map([[n,o]]);for(;r.size;){const s=new Map;for(const[c,d]of r){const u=e.entities.find(h=>h.modelId===c);if(!u)continue;const m=pn(u).map(h=>h.col),f=m.map(h=>h.modelId),p=new Set(pn(d).map(h=>h.col.modelId)),g=new Set;if(f.forEach((h,_)=>{p.has(h)&&g.add(_)}),g.size===f.length)continue;const y=ds(e,c);for(const h of e.entities)for(const _ of h.attributes){if(_.attrType!=="EMBED_OWN"||((l=_.embedded)==null?void 0:l.embeddableRef)!==c||y.has(_.embedded.associationRef)||_.dbAttrs.length!==f.length)continue;const N=`${h.modelId}\0${_.modelId}`;if(a.has(N))continue;const b=_.dbAttrs.filter((k,C)=>g.has(C)),w=_.dbAttrs.filter((k,C)=>!g.has(C));if(_.dbAttrs.some((k,C)=>{if(g.has(C))return!1;const x=m[C],T=!!k.physicalName&&k.physicalName!==((x==null?void 0:x.physicalName)??""),z=k.sharedColumnRef!=null&&k.sharedColumnRef!==(x==null?void 0:x.sharedColumnRef);return T||z}))continue;a.add(N),i.push({entityId:h.modelId,attributeId:_.modelId,dbAttrs:b,dropped:w});const $=s.get(h.modelId)??new Map;$.set(_.modelId,b),s.set(h.modelId,$)}}r=new Map([...s].flatMap(([c,d])=>{const u=e.entities.find(f=>f.modelId===c);if(!u)return[];const m={...u,attributes:u.attributes.map(f=>d.has(f.modelId)?{...f,dbAttrs:d.get(f.modelId)}:f)};return[[c,m]]}))}return i}function Rm(e,n,o,i=[]){var d;if(n===o)return[n];const a=new Map,r=(u,m)=>{const f=a.get(u)??[];f.push(m),a.set(u,f)};for(const u of e)for(const m of u.attributes){const f=m.attrType==="EMBED_OWN"?(d=m.embedded)==null?void 0:d.embeddableRef:void 0;f!=null&&r(u.modelId,f)}for(const u of i)r(u.ownerId,u.embeddableRef);const l=new Map,s=new Set([o]),c=[o];for(;c.length;){const u=c.shift();for(const m of a.get(u)??[]){if(m===n){const f=[u];for(let p=u;l.has(p);)p=l.get(p),f.push(p);return[n,...f.reverse()]}s.has(m)||(s.add(m),l.set(m,u),c.push(m))}}return null}function gn(e,n,o){const i=new Set(o.map(r=>`${r.entityId}\0${r.attributeId}`)),a=[];for(const r of n){const l=`${e}\0${r}`;i.has(l)||(i.add(l),a.push(r),o.push({entityId:e,attributeId:r}))}return a.map(r=>Gu(e,r))}function Jt(e,n,o){if(!n.length)return[];const i=new Map;for(const{entityId:r,attributeId:l}of n){const s=i.get(r)??[];s.push(l),i.set(r,s)}const a=[];for(const[r,l]of i){const s=e.entities.find(c=>c.modelId===r);if(s)for(const c of Im(s,l,o))a.push(Wa(r,c.indexRef,{columns:c.columns}))}return a}function Xa(e,n,o,i){var c;const a=[];a.push(...gn(n,o.remove,i));for(const d of o.update)a.push(nn(n,d.attributeId,d.patch));for(const d of o.add)a.push(Wt(n,d));const r=new Set(o.remove),l=[...(((c=e.entities.find(d=>d.modelId===n))==null?void 0:c.attributes)??[]).filter(d=>!r.has(d.modelId)),...o.add],s=new Set(l.map(d=>d.modelId));for(const d of e.associations){if(d.end2.entityRef!==n)continue;const u=d.end2.attributeRef;if(u&&s.has(u))continue;const f=l.filter(p=>{var g;return((g=p.derivedFrom)==null?void 0:g.associationRef)===d.modelId&&p.dbAttrs.length>0}).sort((p,g)=>p.order-g.order)[0];f&&a.push(on(d.modelId,"end2",{attributeRef:f.modelId}))}return a}function Ln(e,n,o){return{...e,entities:e.entities.map(i=>i.modelId===n?{...i,attributes:o(i.attributes)}:i)}}function Bi(e,n,o){return[...Am(e,n,o),...$m(e,n)]}function Am(e,n,o){const i=[];for(const[a,r]of wl(e,n,Fe))i.push(...Xa(e,a,r,o));return i}function l_(e,n,o,i){const a=e.entities.find(l=>l.modelId===n);if(!a)return[];const r=es([...a.attributes].sort((l,s)=>l.order-s.order),o,i).map(l=>l.modelId);return Cm(e,n,r).map(l=>nn(l.entityId,l.attributeId,{dbAttrs:l.dbAttrs}))}function Di(e,n,o){return xm(e,n,o).commands}function xm(e,n,o){const i=Sm(e,n,o),a=i.map(l=>nn(l.entityId,l.attributeId,{dbAttrs:l.dbAttrs})),r=i.reduce((l,s)=>Ln(l,s.entityId,c=>c.map(d=>d.modelId===s.attributeId?{...d,dbAttrs:s.dbAttrs}:d)),e);return{commands:a,projected:r}}function $m(e,n){return vm(e,n,Fe).map(o=>nn(o.entityId,o.attributeId,{dbAttrs:o.dbAttrs}))}function s_(e,n,o){const i=new Set(o.remove);return Ln(e,n,a=>[...a.filter(r=>!i.has(r.modelId)).map(r=>{const l=o.update.find(s=>s.attributeId===r.modelId);return l?{...r,...l.patch}:r}),...o.add])}function Za(e,n,o){const i=[];for(const{entityId:a,plan:r}of Cd(e,n,Fe))i.push(...Xa(e,a,r,o));return i}function Tm(e,n,o=new Set){var r,l,s,c;if(!mn(n))return[];const i=[];for(const d of e.attributes){if(o.has(d.modelId))continue;const u={},m=(r=d.dbAttrs.find(f=>fn(f.logicalName)))==null?void 0:r.logicalName;m&&!fn(d.fieldLogicalName)&&(u.fieldLogicalName=m),d.dbAttrs.length>0&&(u.dbAttrs=[]),d.notNull&&(u.notNull=!1),Object.keys(u).length>0&&i.push(nn(e.modelId,d.modelId,u))}const a={};return fn((l=e.table)==null?void 0:l.logicalName)&&!fn(e.classLogicalName)&&(a.classLogicalName=e.table.logicalName),(s=e.table)!=null&&s.physicalName&&(a.table=null),(c=e.indexes)!=null&&c.length&&(a.indexes=[]),e.schema&&(a.schema=null),e.jpaAttrs&&(a.jpaAttrs=null),Object.keys(a).length>0&&i.push(Ha(e.modelId,a)),i}function Mm(e){return pn(e).map(n=>({...n.col,modelId:Fe()}))}function Vm(e,n){var m;const o=e.entities.find(f=>f.modelId===n);if(!o)return[];const i=[];let a;if(!o.attributes.some(f=>f.identifier)){const f=Yt(o.attributes),p=new Set(o.attributes.map(y=>y.name));let g="id";for(let y=2;p.has(g);y++)g=`id${y}`;a={modelId:Fe(),name:g,type:"Long",attrType:"NORMAL",identifier:!0,notNull:!0,order:f,dbAttrs:[{modelId:Fe(),physicalName:g.toLowerCase(),dataType:"BIGINT"}]},i.push(Wt(n,a))}const r=[];for(const f of e.entities)for(const p of f.attributes){if(((m=p.embedded)==null?void 0:m.embeddableRef)!==n)continue;const g=e.associations.find(N=>N.modelId===p.embedded.associationRef);if(!g)continue;const y=g.end1.entityRef===f.modelId,h=y?g.end1:g.end2,_=y?g.end2:g.end1;r.push({ownerId:f.modelId,dispId:p.modelId,assocId:g.modelId,end1:{entityRef:f.modelId,multiplicity:h.multiplicity,navigable:h.navigable,composition:!1},end2:{entityRef:n,multiplicity:_.multiplicity,navigable:_.navigable,composition:!1}})}const l={...e,entities:e.entities.map(f=>{if(f.modelId===n)return a?{...f,stereotype:"JPA_ENTITY",attributes:[...f.attributes,a]}:{...f,stereotype:"JPA_ENTITY"};const p=new Set(r.filter(g=>g.ownerId===f.modelId).map(g=>g.dispId));return p.size?{...f,attributes:f.attributes.filter(g=>!p.has(g.modelId))}:f}),associations:e.associations.map(f=>{const p=r.find(g=>g.assocId===f.modelId);return p?{...f,end1:p.end1,end2:p.end2}:f})},s=vi(l,n,Fe);for(const f of r){const p=s.add.find(g=>{var y;return((y=g.derivedFrom)==null?void 0:y.associationRef)===f.assocId});p&&(f.end2.attributeRef=p.modelId)}const c=[],d=new Map;for(const f of r)i.push(...gn(f.ownerId,[f.dispId],c)),i.push(Ya(f.assocId,{end1:f.end1,end2:f.end2})),d.set(f.ownerId,[...d.get(f.ownerId)??[],f.dispId]);for(const[f,p]of d)i.push(...Di(e,f,p));i.push(...Xa(l,n,s,c));const u=s_(l,n,s);return i.push(...Bi(u,n,c)),i.push(...Jt(e,c)),i}function Lm(e,n,o){const i=e.associations.find(l=>l.modelId===n);if(!i||i.end1.navigable===o)return null;const a=e.entities.find(l=>l.modelId===i.end1.entityRef),r=e.entities.find(l=>l.modelId===i.end2.entityRef);if(!a||!r||a.stereotype==="JPA_EMBEDDABLE"||r.stereotype==="JPA_EMBEDDABLE")return null;if(o===!0&&!i.end1.attributeRef){const l=Ea(i.end2.multiplicity),s=i.end1.navFieldNameHint||wa(r.name,l),c=yo(s,new Set(a.attributes.map(m=>m.name))),d=Fe(),u={modelId:d,name:c,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:Yt(a.attributes),dbAttrs:[]};return{cmds:[Wt(i.end1.entityRef,u)],endPatch:{attributeRef:d,navFieldNameHint:void 0}}}if(o===!1&&i.end1.attributeRef){const l=i.end1.attributeRef,s=a.attributes.find(m=>m.modelId===l&&m.attrType==="RELATION_REF"),c={attributeRef:void 0,navFieldNameHint:(s==null?void 0:s.name)??i.end1.navFieldNameHint};if(!s)return{cmds:[],endPatch:c};const d=[],u=[...gn(i.end1.entityRef,[l],d)];return u.push(...Jt(e,d)),{cmds:u,endPatch:c}}return null}function Bm(e,n,o){const i=e.entities.find(u=>u.modelId===n);if(!i)return[];const a=i.attributes.filter(u=>u.identifier&&!u.derivedFrom).map(u=>nn(n,u.modelId,{identifier:!1})),r=Ln({...e,entities:e.entities.map(u=>u.modelId===n?{...u,stereotype:o}:u)},n,u=>u.map(m=>m.identifier&&!m.derivedFrom?{...m,identifier:!1}:m)),l=[],s=Za(r,[n],l);s.push(...Jt(e,l));const c=o==="JPA_EMBEDDABLE"?c_(e,n):[],d=Tm(i,o,new Set(l.filter(u=>u.entityId===n).map(u=>u.attributeId)));return[...a,...s,...c,...d]}function c_(e,n){const o=e.entities.find(r=>r.modelId===n);if(!o)return[];const i=[],a=r=>r&&r.charAt(0).toLowerCase()+r.slice(1);for(const r of e.associations){if(r.end1.entityRef===r.end2.entityRef)continue;const l=r.end1.entityRef===n,s=r.end2.entityRef===n;if(!l&&!s)continue;const c=l?r.end2.entityRef:r.end1.entityRef,d=e.entities.find(b=>b.modelId===c);if(!d||d.attributes.some(b=>{var w;return((w=b.embedded)==null?void 0:w.associationRef)===r.modelId}))continue;const u=Fe(),m=Yt(d.attributes),f=new Set(d.attributes.map(b=>b.name)),p=a(o.name);let g=p;for(let b=2;f.has(g);b++)g=`${p}${b}`;const y=o.attributes.filter(b=>!b.identifier&&!b.derivedFrom).flatMap(b=>b.dbAttrs).map(b=>({...b,modelId:Fe()})),h={modelId:u,name:g,type:o.name,attrType:"EMBED_OWN",identifier:!1,notNull:!1,order:m,dbAttrs:y,embedded:{associationRef:r.modelId,embeddableRef:n}};i.push(Wt(c,h));const _=l?"end2":"end1",N=l?"end1":"end2";i.push(Ya(r.modelId,{identifying:!1,[_]:{entityRef:c,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!1,attributeRef:Fe()},[N]:{entityRef:n,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!0,attributeRef:u}}))}return i}function Dm(e,n,o,i){var d;const a=e.layout.groupLayouts.find(u=>u.groupRef===n),r=(a==null?void 0:a.geo.location)??o,l=o.x-r.x,s=o.y-r.y,c=[Uu(n,o),...i.map(u=>ti(u.id,u.location))];if(l||s){const u=new Set(((d=e.logical.groups.find(m=>m.modelId===n))==null?void 0:d.memberEntityRefs)??[]);for(const m of e.logical.associations){if(!u.has(m.end1.entityRef)||!u.has(m.end2.entityRef))continue;const f=e.layout.associationLayouts.find(p=>p.associationRef===m.modelId);f&&f.waypoints.length&&c.push(im(m.modelId,l,s))}for(const m of(a==null?void 0:a.memberNoteRefs)??[]){const f=e.layout.notes.find(p=>p.modelId===m);f&&c.push(Li(m,{x:f.geo.location.x+l,y:f.geo.location.y+s}))}}return c}const Om={diagramId:"",logicalModelRef:"",entityLayouts:[],associationLayouts:[],groupLayouts:[],notes:[]};function d_(e,n){const o=n.dbAttrs;if(Array.isArray(o))return o.length;let i=e.dbAttrs.length;for(const a of Object.keys(n)){const r=/^dbAttrs\.(\d+)\./.exec(a);r&&(i=Math.max(i,Number(r[1])+1))}return i}function Pm(e,n,o){for(const[i,a]of Object.entries(n)){if(i==="dbAttrs"){if(!Array.isArray(a))continue;a.forEach((l,s)=>{if(l&&typeof l=="object")for(const[c,d]of Object.entries(l))o(s,c,d,`dbAttrs.${s}.${c}`)});continue}const r=/^dbAttrs\.(\d+)\.(.+)$/.exec(i);if(r){o(Number(r[1]),r[2],a,i);continue}e.dbAttrs.length===1&&Qa.has(i)&&o(0,i,a,i)}}function u_(e,n){const o=new Set,i=new Set,a=r=>r!=null;for(const[r,l]of Object.entries(n))r==="dbAttrs"||r.startsWith("dbAttrs.")||(Wc.attr.includes(r)?o.add(r):Jc.attr.includes(r)&&a(l)&&i.add(r));return Pm(e,n,(r,l,s,c)=>{Wc.column.includes(l)?o.add(c):Jc.column.includes(l)&&a(s)&&i.add(c)}),{locked:[...o],inapplicable:[...i]}}function m_(e,n,o,i,a){const r=a?{embeddableCatalog:a}:void 0,l=d=>{const u=e.dbAttrs[d];return u?rd(u,At(e,u,d,n,o,r)):[]},s=new Map;Pm(e,i,(d,u,m)=>{m!=null&&id.includes(u)&&(s.has(d)||s.set(d,new Set),s.get(d).add(u))});const c=[];for(const[d,u]of[...s.entries()].sort((m,f)=>m[0]-f[0])){const m=l(d).filter(f=>u.has(f));m.length&&c.push([d,m])}return c}function f_(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 p_(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 zm(e,n,o){return e.associations.filter(i=>{const a=[i.end1.entityRef,i.end2.entityRef];return a.includes(n)&&a.includes(o)})}function Tt(e,n){if(!er(n))return{ok:!1,reason:"shape",matches:[]};const o=f_(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>g_(i,e))}}function h_(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 us(e,n){const o=h_(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 ms(e,n,o){return e.reason==="shape"?{code:"handle-shape-invalid",opIndex:n,where:"group",expected:"{ref, by?}",got:hs(o)}:e.reason==="not-found"?{code:"group-not-found",opIndex:n,handle:o}:{code:"group-ambiguous",opIndex:n,handle:o,matches:e.matches}}const y_=new Set(["name","description","packageName","excludeDDLGeneration"]);function g_(e,n){var a;const o=qo(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(f=>f.modelId===l);return(s==null?void 0:s.name)||((m=s==null?void 0:s.table)==null?void 0:m.physicalName)||String(l??"?")}))]}}function Fm(e,n){const o=p_(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 b_(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 k_(e,n){const o=b_(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 Um(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 fs(e){return e.by!==void 0&&e.by!=="name"}function __(e,n){return(e.indexes??[]).filter(o=>o.name===n.ref)}function E_(e,n){return(e.operations??[]).filter(o=>o.name===n.ref)}function N_(e,n){const o=__(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 Hm(e,n){const o=E_(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 jm(e){return e.physicalName!=null||e.dataType!=null||e.length!=null||e.scale!=null||e.columnLogicalName!=null||e.unique!=null||e.updatable!=null||e.sequenceName!=null}function Km(e){return jm(e)&&e.dataType==null}function Gm(e,n,o){var a;const i=jm(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}:{},...e.fieldLogicalName?{fieldLogicalName:e.fieldLogicalName}:{},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}:{},...(a=e.sequenceName)!=null&&a.trim()?{sequenceName:e.sequenceName.trim()}:{}}]:[]}}function qm(e,n,o,i,a,r,l,s,c){const d=Xm(e.embeddableOverrides);if(d.length)return s.push({code:"embeddable-override-unknown-key",opIndex:r,entity:l,handle:{ref:e.name},keys:d}),null;const u=c(),m=new Map((e.embeddableOverrides??[]).map(g=>[g.field,g])),f=[];let p=!1;for(const g of n.fields){const y=m.get(g.name);if(y!=null&&y.sharedColumnPhysicalName){const h={ref:y.sharedColumnPhysicalName,by:"physicalName"},_=Um(xn(i,a),h);if(!_.ok){s.push(_.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:h}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:h,matches:_.matches}),p=!0;continue}f.push({modelId:c(),physicalName:"",dataType:"",sharedColumnRef:_.value.modelId});continue}f.push({modelId:c(),physicalName:(y==null?void 0:y.physicalName)??"",dataType:"",...y!=null&&y.length?{length:y.length}:{},...y!=null&&y.scale?{scale:y.scale}:{},...(y==null?void 0:y.insertable)!=null?{insertable:y.insertable}:{},...(y==null?void 0:y.updatable)!=null?{updatable:y.updatable}:{},...(y==null?void 0:y.notNull)!=null?{notNull:y.notNull}:{}})}return p?null:{modelId:u,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:f}}const w_=new Set(["name","type","customType","attrType","identifier","notNull","transient","naturalId","naturalIdMutable","description","attributeGroup","groupCode","defaultValue","personalInfoAttributeType","order","dbAttrs","derivedIdFieldName","collectionType","fieldLogicalName"]),Co=e=>new Set(Object.keys(e)),I_=Co({name:!0,stereotype:!0,physicalName:!0,useVersion:!0,attributes:!0,indexes:!0,operations:!0,serialization:!0,classLogicalName:!0}),Ym=Co({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,fieldLogicalName:!0,sequenceName:!0}),v_=Co({field:!0,physicalName:!0,length:!0,scale:!0,insertable:!0,updatable:!0,notNull:!0,sharedColumnPhysicalName:!0}),Wm=Co({name:!0,unique:!0,columns:!0,description:!0,parameters:!0}),Jm=Co({name:!0,visibility:!0,sourceCode:!0,description:!0,personalInfoAttributeType:!0}),C_=Co({from:!0,to:!0,fromMultiplicity:!0,toMultiplicity:!0,identifying:!0,composition:!0}),S_=Co({name:!0,packageName:!0,description:!0,excludeDDLGeneration:!0,members:!0});function bn(e,n){return So(e,n)}function Xm(e){const n=new Set;for(const o of e??[])for(const i of bn(o,v_))n.add(i);return[...n]}const R_=new Set(["name","stereotype","packageName","superClass","schema","description","abstractClass","hasPersonalInfo","declarationOfInterfaces","table","classLogicalName","referenceOnly","serialization"]),A_=new Set(["description","identifying"]),x_=new Set(["multiplicity","navigable","composition"]),$_=new Set(["name","unique","description","parameters"]),T_=new Set(["name","visibility","sourceCode","description","order","personalInfoAttributeType"]);function So(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 Qa=new Set(["physicalName","logicalName","dataType","length","scale","unique","autoIncrement","updatable","insertable","sharedColumnRef","multiValue","multiValueSeparator","sequenceName"]),M_=new Set([...Qa].filter(e=>e!=="sharedColumnRef"));function V_(e,n,o,i){if(i||o.some(l=>!M_.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))Qa.has(l)||(r[l]=s);return{...r,dbAttrs:[a]}}function L_(e,n,o,i,a,r,l,s){const c=Xm(o);if(c.length)return s.push({code:"embeddable-override-unknown-key",opIndex:r,entity:l,handle:{ref:e.name},keys:c}),null;const d=new Map(o.map(f=>[f.field,f])),u=[];let m=!1;return e.dbAttrs.forEach((f,p)=>{const g=n.fields[p],y=g?d.get(g.name):void 0;if(!y){u.push(f);return}if(y.sharedColumnPhysicalName){const _={ref:y.sharedColumnPhysicalName,by:"physicalName"},N=Um(xn(i,a),_);if(!N.ok){s.push(N.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:_}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:_,matches:N.matches}),m=!0;return}u.push({modelId:f.modelId,physicalName:"",dataType:"",sharedColumnRef:N.value.modelId});return}const h={...f};delete h.sharedColumnRef,u.push({...h,...y.physicalName!=null?{physicalName:y.physicalName}:{},...y.length!=null?{length:y.length}:{},...y.scale!=null?{scale:y.scale}:{},...y.notNull!=null?{notNull:y.notNull}:{},...y.insertable!=null?{insertable:y.insertable}:{},...y.updatable!=null?{updatable:y.updatable}:{}})}),m?null:u}function Zm(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 Qm(e,n,o,i,a,r){const l=[];let s=!1;for(const c of n.columns){const d=k_(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 ni(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 B_(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 Im(s,l))e.push({kind:"index.update",casUnit:"logical",containerRef:r,entityRef:r,indexRef:c.indexRef,patch:{columns:c.columns}})}}function D_(e,n,o,i,a,r){const l=m=>{const f=new Map;for(const{entityId:p,item:g}of m){if(a.has(p))continue;const y=f.get(p)??[];y.push(g),f.set(p,y)}return f},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,f]of s)if(!c.has(m))for(const p of Sm(n,m,f))u(p);for(const[m,f]of c){if(s.has(m))continue;const p={...n,entities:n.entities.map(g=>g.modelId===m?{...g,attributes:[...g.attributes,...f]}:g)};for(const g of vm(p,m,r))u(g)}}function ef(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 tf(e,n,o,i,a,r,l){var f;for(const p of i.remove)ni(e,r,o,p);for(const p of i.update)e.push({kind:"attribute.update",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:p.attributeId,patch:p.patch}),a.attrPatches.push({entityId:o,attributeId:p.attributeId,patch:p.patch});const s=((f=n.entities.find(p=>p.modelId===o))==null?void 0:f.attributes)??[],c=[];for(const p of i.add){const g={...p,order:l(o,s)};e.push({kind:"attribute.add",casUnit:"logical",containerRef:o,entityRef:o,value:g}),a.cascadeAdds.push({entityId:o,attribute:g}),c.push(g)}const d=new Set(i.remove),u=[...s.filter(p=>!d.has(p.modelId)),...c],m=new Set(u.map(p=>p.modelId));for(const p of n.associations){if(p.end2.entityRef!==o)continue;const g=p.end2.attributeRef;if(g&&m.has(g))continue;const h=u.filter(_=>{var N;return((N=_.derivedFrom)==null?void 0:N.associationRef)===p.modelId&&_.dbAttrs.length>0}).sort((_,N)=>_.order-N.order)[0];h&&(e.push({kind:"associationEnd.update",casUnit:"logical",containerRef:p.modelId,associationRef:p.modelId,end:"end2",patch:{attributeRef:h.modelId}}),a.endPatches.push({associationRef:p.modelId,end:"end2",patch:{attributeRef:h.modelId}}))}}function ps(e,n,o,i,a,r,l){for(const{entityId:s,plan:c}of Cd(n,o,i))tf(e,n,s,c,a,r,l)}function O_(e,n,o,i,a,r){const l=new Map;for(const{entityId:f,attributeId:p}of i.pairs)l.has(f)||l.set(f,new Set),l.get(f).add(p);const s=new Map;for(const f of r.attrPatches)s.has(f.entityId)||s.set(f.entityId,[]),s.get(f.entityId).push(f);const c=new Map;for(const{entityId:f,attribute:p}of[...a,...r.cascadeAdds])c.has(f)||c.set(f,[]),c.get(f).push(p);const d=f=>{const p={};for(const[g,y]of Object.entries(f))g.includes(".")||(p[g]=y===null?void 0:y);return p},u=e.entities.filter(f=>!n.has(f.modelId)).map(f=>{const p=l.get(f.modelId),g=s.get(f.modelId),y=c.get(f.modelId);if(!p&&!g&&!y)return f;let h=f.attributes;return p&&(h=h.filter(_=>!p.has(_.modelId))),g&&(h=h.map(_=>{const N=g.filter(b=>b.attributeId===_.modelId);return N.length?N.reduce((b,w)=>ef(b,w.patch),_):_})),y&&(h=[...h,...y]),{...f,attributes:h}}),m=e.associations.filter(f=>!o.has(f.modelId)&&!n.has(f.end1.entityRef)&&!n.has(f.end2.entityRef)).map(f=>{let p=f;for(const g of r.assocPatches)g.associationRef===f.modelId&&(p={...p,...d(g.patch)});for(const g of r.endPatches)g.associationRef===f.modelId&&(p={...p,[g.end]:{...p[g.end],...d(g.patch)}});return p}).concat(r.addedAssociations);return{...e,entities:u,associations:m}}function P_(e,n,o,i,a,r,l,s,c){if(!l.identifierCascadeParents.size)return;const d=O_(n,o,i,a,r,l),u=new Map;for(const m of l.identifierCascadeParents)for(const[f,p]of wl(d,m,s)){const g=u.get(f);u.set(f,g?Nl(g,p):p)}for(const[m,f]of u)tf(e,d,m,vd(f),l,a,c)}const z_=e=>e==="ZERO_OR_MORE_INSTANCES"||e==="ONE_OR_MORE_INSTANCES";function F_(e,n,o,i,a,r,l){const s=i(),c=i(),d=i(),u=o??"EXACTLY_ONE_INSTANCE",m=z_(u),f=N=>N&&N.charAt(0).toLowerCase()+N.slice(1),p=new Set(e.attributes.map(N=>N.name)),g=f(n.name);let y=g;for(let N=2;p.has(y);N++)y=`${g}${N}`;const h={modelId:c,name:y,type:n.name,attrType:"EMBED_OWN",identifier:!1,notNull:!1,order:a(e.modelId,e.attributes),dbAttrs:m?[]:pn(n).map(N=>({...N.col,modelId:i()})),embedded:{associationRef:s,embeddableRef:n.modelId}},_={modelId:s,end1:{entityRef:e.modelId,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!1,attributeRef:d},end2:{entityRef:n.modelId,multiplicity:u,navigable:!0,composition:!0,attributeRef:c,...m?{jpa:{collectionType:"LIST"}}:{}}};return l.push({entityId:e.modelId,attribute:h}),r.addedAssociations.push(_),[{kind:"attribute.add",casUnit:"logical",containerRef:e.modelId,entityRef:e.modelId,value:h},{kind:"association.add",casUnit:"logical",associationRef:s,value:_}]}const U_=new Set(["classLogicalName","columnLogicalName","fieldLogicalName","logicalName"]),H_=[{key:"name",kinds:new Set(["group.add","group.update"])},{key:"description",kinds:new Set(["attribute.add","attribute.update","operation.add","operation.update"])}];function j_(e){const n=[],o=e.kind??"",i=l=>U_.has(l)||H_.some(s=>s.key===l&&s.kinds.has(o)),a=l=>l===null?"null":Array.isArray(l)?"array":typeof l,r=(l,s)=>{if(!(l==null||typeof l!="object")){if(Array.isArray(l)){l.forEach((c,d)=>r(c,`${s}[${d}]`));return}for(const[c,d]of Object.entries(l)){const u=c.includes(".")?c.split(".").pop():c,m=s?`${s}.${c}`:c;i(u)&&!Eg(d)?n.push({path:m,got:a(d)}):r(d,m)}}};return r(e,""),n}function K_(e){const n=i=>{if(i==null||typeof i!="object"||Array.isArray(i))return!1;const a=Object.keys(i);return a.length>0&&a.every(r=>Wn.includes(r))},o=i=>{if(n(i))return Xc(i)??null;if(Array.isArray(i)){const a=i.map(o);return a.some((r,l)=>r!==i[l])?a:i}if(i!=null&&typeof i=="object"){const a=i;let r=!1;const l={};for(const[s,c]of Object.entries(a))l[s]=o(c),l[s]!==c&&(r=!0);return r?l:i}return i};return e.map(i=>o(i))}function G_(e,n,o={}){const i=K_(n),a=o.mkId??Fe,r=o.embeddableCatalog??[],l=k=>r.find(C=>C.type===k),s=[],c=[],d=[],u=new Set;n.forEach((k,C)=>{for(const x of j_(k))u.add(C),c.push({code:"multilang-shape-invalid",opIndex:C,where:x.path,expected:"{ko?,en?,ja?,zh?} | null | {}",got:x.got})});const m=new Map,f=(k,C)=>{const x=m.get(k)??Yt(C);return m.set(k,x+1),x},p=new Map,g=new Set,y=new Set,h={seen:new Set,pairs:[]},_=[],N={attrPatches:[],cascadeAdds:[],addedAssociations:[],assocPatches:[],endPatches:[],identifierCascadeParents:new Set},b=new Set,w=(k,C)=>`${k}\0${C}`,I=new Set;for(const k of i)k.kind==="entity.add"&&(I.add(k.spec.name),k.spec.physicalName&&I.add(k.spec.physicalName));const $=new Set;return i.forEach((k,C)=>{var x,T,z,V,D;if(!u.has(C)&&Y_(k,C,c))switch(k.kind){case"entity.add":{{const L={ref:k.spec.name},j=bn(k.spec,I_);if(j.length){c.push({code:"entity-spec-unknown-key",opIndex:C,handle:L,keys:j});break}let X=!1;for(const J of k.spec.attributes??[]){const re=bn(J,Ym);re.length&&(c.push({code:"attribute-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}for(const J of k.spec.indexes??[]){const re=bn(J,Wm);re.length&&(c.push({code:"index-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}for(const J of k.spec.operations??[]){const re=bn(J,Jm);re.length&&(c.push({code:"operation-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}if(X)break}const E=e.entities.filter(L=>L.name===k.spec.name).map(L=>L.modelId);if(E.length||$.has(k.spec.name)){c.push({code:"entity-name-conflict",opIndex:C,handle:{ref:k.spec.name},matches:E});break}$.add(k.spec.name);const v=a(),A={modelId:v,name:k.spec.name,stereotype:k.spec.stereotype??"JPA_ENTITY",attributes:[],...k.spec.useVersion?{jpaAttrs:{useVersion:!0}}:{},...k.spec.physicalName?{table:{physicalName:k.spec.physicalName}}:{},...k.spec.serialization?{serialization:k.spec.serialization}:{},...k.spec.classLogicalName?{classLogicalName:k.spec.classLogicalName}:{}},S={ref:k.spec.name};let R=!1;for(const[L,j]of(k.spec.attributes??[]).entries()){if(_a(j.type,j.groupCode)){c.push(j.groupCode?{code:"groupcode-type-mismatch",opIndex:C,entity:S,handle:{ref:j.name},type:String(j.type??""),groupCode:j.groupCode}:{code:"groupcode-required",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0;continue}if(!l(j.type)&&!((x=j.embeddableOverrides)!=null&&x.length)&&Km(j)){c.push({code:"datatype-required",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0;continue}const X=l(j.type);if(X){const J=qm(j,X,L,A,e.entities,C,S,c,a);J?A.attributes.push(J):R=!0}else(T=j.embeddableOverrides)!=null&&T.length?(c.push({code:"embeddable-type-unresolved",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0):A.attributes.push(Gm(j,L,a))}const H=(k.spec.operations??[]).map((L,j)=>Zm(L,j,a));H.length&&(A.operations=H);const P=[];for(const L of k.spec.indexes??[]){const j=Qm(A,L,C,S,c,a);j?P.push(j):R=!0}if(P.length&&(A.indexes=P),R)break;s.push({kind:"entity.add",casUnit:"logical",entityRef:v,value:A});break}case"entity.update":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=So(k.patch,R_,["jpaAttrs.","table.","serialization."]);if(v.length){c.push({code:"entity-patch-unknown-key",opIndex:C,entity:k.entity,keys:v});break}const A=k.patch.stereotype;if(typeof A=="string"&&A!==E.value.stereotype){const S=E.value.stereotype,R=A,H=at(R)&&!at(S),P=!at(R)&&at(S);if(R!==S&&at(R)&&at(S)&&e.entities.filter(J=>J.attributes.some(re=>{var me;return((me=re.embedded)==null?void 0:me.embeddableRef)===E.value.modelId})).length>0){c.push({code:"stereotype-embeddable-transition-unsupported",opIndex:C,entity:k.entity,from:S??"",to:R});break}if(R==="SERIALIZED_TYPE"&&e.associations.filter(J=>J.end1.entityRef===E.value.modelId||J.end2.entityRef===E.value.modelId).length>0){c.push({code:"stereotype-serialized-transition-unsupported",opIndex:C,entity:k.entity,from:S??"",to:R});break}const j=H?Bm(e,E.value.modelId,R):P?Vm(e,E.value.modelId):[];if(j.length){const X=Ha(E.value.modelId,k.patch),J=$u({logical:e,layout:Om},[X,...j]);s.push(...J.ops);break}}s.push({kind:"entity.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,patch:k.patch});break}case"entity.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=E.value.modelId,A=e.associations.filter(P=>P.end1.entityRef===v||P.end2.entityRef===v),S=new Set(A.map(P=>P.modelId));for(const P of A)g.has(P.modelId)||(g.add(P.modelId),s.push({kind:"association.remove",casUnit:"logical",associationRef:P.modelId}));for(const P of e.entities)if(P.modelId!==v)for(const L of P.attributes)L.embedded&&S.has(L.embedded.associationRef)&&ni(s,h,P.modelId,L.modelId);for(const P of A){if(P.end1.entityRef===v||!P.end1.attributeRef)continue;const L=e.entities.find(X=>X.modelId===P.end1.entityRef),j=L==null?void 0:L.attributes.find(X=>X.modelId===P.end1.attributeRef&&X.attrType==="RELATION_REF");j&&ni(s,h,L.modelId,j.modelId)}const R={...e,entities:e.entities.filter(P=>P.modelId!==v),associations:e.associations.filter(P=>!S.has(P.modelId))},H=new Set(A.filter(P=>P.end1.entityRef===v&&P.end2.entityRef!==v).map(P=>P.end2.entityRef));ps(s,R,[...H],a,N,h,f);for(const P of e.groups)P.memberEntityRefs.includes(v)&&(b.has(w(P.modelId,v))||(b.add(w(P.modelId,v)),s.push({kind:"group.removeMember",casUnit:"logical",containerRef:P.modelId,groupRef:P.modelId,entityRef:v})));y.add(v),s.push({kind:"entity.remove",casUnit:"logical",entityRef:v});break}case"attribute.add":{{const R=bn(k.spec,Ym);if(R.length){c.push({code:"attribute-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:R});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(_a(k.spec.type,k.spec.groupCode)){c.push(k.spec.groupCode?{code:"groupcode-type-mismatch",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},type:String(k.spec.type??""),groupCode:k.spec.groupCode}:{code:"groupcode-required",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}if(!l(k.spec.type)&&!((z=k.spec.embeddableOverrides)!=null&&z.length)&&Km(k.spec)){c.push({code:"datatype-required",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}{const R=new Map(e.entities.map(P=>[P.modelId,P])),H=E.value.attributes.find(P=>{const L=Al(P,E.value,e,R);return!!L&&L===k.spec.name});if(H){c.push({code:"derived-id-scalar-conflict",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},fk:H.name});break}}const v=f(E.value.modelId,E.value.attributes),A=l(k.spec.type);let S;if(A)S=qm(k.spec,A,v,E.value,e.entities,C,k.entity,c,a);else if((V=k.spec.embeddableOverrides)!=null&&V.length){c.push({code:"embeddable-type-unresolved",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}else S=Gm(k.spec,v,a);if(!S)break;s.push({kind:"attribute.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,value:S}),_.push({entityId:E.value.modelId,attribute:S}),S.identifier&&N.identifierCascadeParents.add(E.value.modelId);break}case"attribute.update":case"attribute.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=Fm(E.value,k.attribute);if(!v.ok){c.push(v.reason==="not-found"?{code:"attribute-not-found",opIndex:C,entity:k.entity,handle:k.attribute}:{code:"attribute-ambiguous",opIndex:C,entity:k.entity,handle:k.attribute,matches:v.matches});break}if(k.kind==="attribute.update"){const A=[],S=[];let R=!1;for(const J of Object.keys(k.patch)){if(J.includes(".")){J.startsWith("dbAttrs.")?R=!0:S.push(J);continue}Qa.has(J)?A.push(J):w_.has(J)||S.push(J)}if(S.length){c.push({code:"attribute-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.attribute,keys:S});break}if(Ei(v.value)){const J=u_(v.value,k.patch);if(J.locked.length){const re=Xn(e,E.value.modelId,v.value.modelId),me=se=>{var Ie;return((Ie=e.entities.find(Oe=>Oe.modelId===se))==null?void 0:Ie.name)??se};c.push({code:"attribute-fk-derived-field-locked",opIndex:C,entity:k.entity,handle:k.attribute,fields:J.locked,...re?{association:{from:me(re.end1.entityRef),to:me(re.end2.entityRef)}}:{}});break}J.inapplicable.length&&d.push({code:"fk-derived-inapplicable-field",opIndex:C,entity:k.entity,attribute:k.attribute,fields:J.inapplicable})}const H=Array.isArray(k.patch.dbAttrs)?k.patch.dbAttrs:v.value.dbAttrs,P="type"in k.patch?Og({attrType:v.value.attrType,type:v.value.type,dbAttrs:H},String(k.patch.type),r):void 0;for(const[J,re]of m_(v.value,E.value,e,k.patch,r))d.push({code:"inherited-slot-override",opIndex:C,entity:k.entity,attribute:k.attribute,columnIndex:J,fields:re});if("attrType"in k.patch){const J=String(k.patch.attrType),re=P?"EMBED_PREDEF":void 0,me=wm.includes(J)?J!==v.value.attrType&&J!==re?"transition":void 0:"unknown-value";if(me){c.push({code:"attribute-attrtype-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,reason:me,current:v.value.attrType,requested:J});break}}if("type"in k.patch&&!P){const J=String(k.patch.type);if(kd(v.value,J,r)){const re=kl(v.value),me=re==="association"?"association-owned":re==="derived"?"derived":"column-count";c.push({code:"attribute-type-conversion-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,reason:me,current:v.value.type,requested:J});break}}const L="type"in k.patch?k.patch.type:v.value.type,j="groupCode"in k.patch?k.patch.groupCode:v.value.groupCode;if(_a(L,j)){c.push(j?{code:"groupcode-type-mismatch",opIndex:C,entity:k.entity,handle:k.attribute,type:String(L??""),groupCode:String(j)}:{code:"groupcode-required",opIndex:C,entity:k.entity,handle:k.attribute});break}let X=k.patch;if(P&&v.value.attrType!=="EMBED_PREDEF"&&(X={...X,attrType:"EMBED_PREDEF"}),P&&v.value.customType!==void 0&&!("customType"in X)&&(X={...X,customType:null}),A.length){const J=V_(v.value,k.patch,A,R);if(!J){c.push({code:"attribute-patch-dbattr-flat-key",opIndex:C,entity:k.entity,handle:k.attribute,keys:A});break}X=J}if((D=k.embeddableOverrides)!=null&&D.length){const J=l(v.value.type);if(!J||v.value.attrType!=="EMBED_PREDEF"){c.push({code:"embeddable-type-unresolved",opIndex:C,entity:k.entity,handle:k.attribute});break}const re=L_(v.value,J,k.embeddableOverrides,E.value,e.entities,C,k.entity,c);if(!re)break;X={...X,dbAttrs:re}}{const J=X.attrType??v.value.attrType,re=d_(v.value,X);if(J==="NORMAL"&&re>1){c.push({code:"attribute-column-count-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,attrType:J,current:v.value.dbAttrs.length,requested:re});break}}s.push({kind:"attribute.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,attributeRef:v.value.modelId,patch:X}),N.attrPatches.push({entityId:E.value.modelId,attributeId:v.value.modelId,patch:X});{const J=v.value,re=ef(J,X),me=(re.identifier??!1)!==(J.identifier??!1),se=(J.identifier||re.identifier)&&("type"in X||"customType"in X||"dbAttrs"in X||Object.keys(X).some(Ie=>Ie.startsWith("dbAttrs.")));(me||se)&&N.identifierCascadeParents.add(E.value.modelId)}}else{const A=Xn(e,E.value.modelId,v.value.modelId);if(A){const S=R=>{var H;return((H=e.entities.find(P=>P.modelId===R))==null?void 0:H.name)??R};c.push({code:"attribute-fk-managed",opIndex:C,entity:k.entity,handle:k.attribute,association:{from:S(A.end1.entityRef),to:S(A.end2.entityRef)}});break}ni(s,h,E.value.modelId,v.value.modelId),v.value.identifier&&N.identifierCascadeParents.add(E.value.modelId)}break}case"association.add":{{const P=bn(k.spec,C_);if(P.length){c.push({code:"association-spec-unknown-key",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},keys:P});break}}const E=Tt(e,k.spec.from),v=Tt(e,k.spec.to);if(E.ok||c.push(Mt(E.reason,C,k.spec.from,E.matches,I)),v.ok||c.push(Mt(v.reason,C,k.spec.to,v.matches,I)),!E.ok||!v.ok)break;if(k.spec.identifying&&E.value.modelId===v.value.modelId){c.push({code:"self-identifying",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}if(v.value.stereotype==="JPA_EMBEDDABLE"){const P=_.flatMap(({entityId:X,attribute:J})=>{var re;return J.attrType==="EMBED_OWN"&&((re=J.embedded)!=null&&re.embeddableRef)?[{ownerId:X,embeddableRef:J.embedded.embeddableRef}]:[]}),L=Rm(e.entities,E.value.modelId,v.value.modelId,P);if(L){const X=J=>{var re;return((re=e.entities.find(me=>me.modelId===J))==null?void 0:re.name)??J};c.push(L.length===1?{code:"embed-self-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}}:{code:"embed-cycle-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},path:L.map(X)});break}const j=["identifying","composition","fromMultiplicity"].filter(X=>k.spec[X]!=null);if(j.length){c.push({code:"embed-spec-inapplicable",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},fields:[...j]});break}s.push(...F_(E.value,v.value,k.spec.toMultiplicity,a,f,N,_));break}if(E.value.stereotype==="JPA_EMBEDDABLE"){c.push({code:"embeddable-relation-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}if(E.value.stereotype==="SERIALIZED_TYPE"||v.value.stereotype==="SERIALIZED_TYPE"){c.push({code:"serialized-relation-invalid",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}const A=a(),S={modelId:A,...k.spec.identifying!=null?{identifying:k.spec.identifying}:{},end1:{entityRef:E.value.modelId,multiplicity:k.spec.fromMultiplicity??"EXACTLY_ONE_INSTANCE",navigable:!1,composition:!1},end2:{entityRef:v.value.modelId,multiplicity:k.spec.toMultiplicity??"ZERO_OR_MORE_INSTANCES",navigable:!0,composition:k.spec.composition??!1}},R={...e,associations:[...e.associations,S]},H=vi(R,v.value.modelId,a);H.add[0]&&(S.end2.attributeRef=H.add[0].modelId),s.push({kind:"association.add",casUnit:"logical",associationRef:A,value:S}),N.addedAssociations.push(S);for(const P of H.add){const L={...P,order:f(v.value.modelId,v.value.attributes)};s.push({kind:"attribute.add",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,value:L}),N.cascadeAdds.push({entityId:v.value.modelId,attribute:L})}break}case"association.remove":{const E=Tt(e,k.association.from),v=Tt(e,k.association.to);if(E.ok||c.push(Mt(E.reason,C,k.association.from,E.matches,I)),v.ok||c.push(Mt(v.reason,C,k.association.to,v.matches,I)),!E.ok||!v.ok)break;const A=zm(e,E.value.modelId,v.value.modelId);if(A.length!==1){c.push(A.length===0?{code:"association-not-found",opIndex:C,handle:k.association}:{code:"association-ambiguous",opIndex:C,handle:k.association,matches:A.map(P=>P.modelId)});break}const S=A[0];g.has(S.modelId)||(g.add(S.modelId),s.push({kind:"association.remove",casUnit:"logical",associationRef:S.modelId}));const R=e.entities.find(P=>P.attributes.some(L=>{var j;return((j=L.embedded)==null?void 0:j.associationRef)===S.modelId}));if(R){const P=R.attributes.find(L=>{var j;return((j=L.embedded)==null?void 0:j.associationRef)===S.modelId});ni(s,h,R.modelId,P.modelId);break}if(S.end1.attributeRef){const P=e.entities.find(j=>j.modelId===S.end1.entityRef),L=P==null?void 0:P.attributes.find(j=>j.modelId===S.end1.attributeRef&&j.attrType==="RELATION_REF");L&&ni(s,h,P.modelId,L.modelId)}const H={...e,associations:e.associations.filter(P=>P.modelId!==S.modelId)};ps(s,H,[S.end2.entityRef],a,N,h,f);break}case"association.update":{const E=nf(e,k.association,C,c,I);if(!E)break;const v=k.patch.identifying,A=typeof v=="boolean"?v:void 0;if(A===!0&&E.end1.entityRef===E.end2.entityRef){c.push({code:"self-identifying",opIndex:C,handle:k.association});break}const S=So(k.patch,A_);if(S.length){c.push({code:"association-patch-unknown-key",opIndex:C,handle:k.association,keys:S});break}if(s.push({kind:"association.update",casUnit:"logical",containerRef:E.modelId,associationRef:E.modelId,patch:k.patch}),N.assocPatches.push({associationRef:E.modelId,patch:k.patch}),A!==void 0&&A!==(E.identifying??!1)){const R={...e,associations:e.associations.map(H=>H.modelId===E.modelId?{...H,identifying:A}:H)};ps(s,R,[E.end2.entityRef],a,N,h,f)}break}case"associationEnd.update":{const E=nf(e,k.association,C,c,I);if(!E)break;const v=k.end==="from"?"end1":"end2";if(Object.prototype.hasOwnProperty.call(k.patch,"navigable")){if(v==="end2"){c.push({code:"navigable-toggle-unsupported",opIndex:C,handle:k.association});break}const S=k.patch.navigable===!0;if(E.end1.navigable!==S){const R=Lm(e,E.modelId,S);if(R){const H=on(E.modelId,"end1",{...k.patch,...R.endPatch}),P=$u({logical:e,layout:Om},[...R.cmds,H]);s.push(...P.ops);break}}}const A=So(k.patch,x_,["jpa."]);if(A.length){c.push({code:"association-end-patch-unknown-key",opIndex:C,handle:k.association,keys:A});break}s.push({kind:"associationEnd.update",casUnit:"logical",containerRef:E.modelId,associationRef:E.modelId,end:v,patch:k.patch}),N.endPatches.push({associationRef:E.modelId,end:v,patch:k.patch});break}case"index.add":{{const A=bn(k.spec,Wm);if(A.length){c.push({code:"index-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:A});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=Qm(E.value,k.spec,C,k.entity,c,a);if(!v)break;s.push({kind:"index.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.modelId,value:v});break}case"index.update":case"index.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(fs(k.index)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:k.index,target:"index"});break}const v=N_(E.value,k.index);if(!v.ok){c.push(v.reason==="not-found"?{code:"index-not-found",opIndex:C,entity:k.entity,handle:k.index}:{code:"index-ambiguous",opIndex:C,entity:k.entity,handle:k.index,matches:v.matches});break}if(k.kind==="index.update"){if("columns"in k.patch){c.push({code:"index-columns-patch-unsupported",opIndex:C,entity:k.entity,handle:k.index});break}const A=So(k.patch,$_);if(A.length){c.push({code:"index-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.index,keys:A});break}s.push({kind:"index.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.value.modelId,patch:k.patch})}else s.push({kind:"index.remove",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.value.modelId});break}case"operation.add":{{const S=bn(k.spec,Jm);if(S.length){c.push({code:"operation-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:S});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=p.get(E.value.modelId)??(E.value.operations?Yt(E.value.operations):0);p.set(E.value.modelId,v+1);const A=Zm(k.spec,v,a);s.push({kind:"operation.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:A.modelId,value:A});break}case"operation.update":case"operation.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(fs(k.operation)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:k.operation,target:"operation"});break}const v=Hm(E.value,k.operation);if(!v.ok){c.push(v.reason==="not-found"?{code:"operation-not-found",opIndex:C,entity:k.entity,handle:k.operation}:{code:"operation-ambiguous",opIndex:C,entity:k.entity,handle:k.operation,matches:v.matches});break}if(k.kind==="operation.update"){const A=So(k.patch,T_);if(A.length){c.push({code:"operation-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.operation,keys:A});break}s.push({kind:"operation.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:v.value.modelId,patch:k.patch})}else s.push({kind:"operation.remove",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:v.value.modelId});break}case"attribute.reorder":case"operation.reorder":{const E=k.kind==="attribute.reorder",v=Tt(e,k.entity);if(!v.ok){c.push(Mt(v.reason,C,k.entity,v.matches,I));break}const A=E?k.order:k.operations;if(A.length===0){c.push({code:"reorder-empty",opIndex:C,entity:k.entity});break}const S=[],R=new Set;let H=!1;for(const X of A){if(!E&&fs(X)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:X,target:"operation"}),H=!0;continue}const J=E?Fm(v.value,X):Hm(v.value,X);if(!J.ok){c.push(J.reason==="not-found"?{code:"reorder-handle-not-found",opIndex:C,entity:k.entity,handle:X}:{code:"reorder-handle-ambiguous",opIndex:C,entity:k.entity,handle:X,matches:J.matches}),H=!0;continue}if(R.has(J.value.modelId)){c.push({code:"reorder-handle-duplicate",opIndex:C,entity:k.entity,handle:X}),H=!0;continue}R.add(J.value.modelId),S.push(J.value)}if(H)break;const L=[...E?v.value.attributes:v.value.operations??[]].sort((X,J)=>X.order-J.order).filter(X=>!R.has(X.modelId)),j=[...S,...L];if(j.forEach((X,J)=>{X.order!==J&&s.push(E?{kind:"attribute.update",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,attributeRef:X.modelId,patch:{order:J}}:{kind:"operation.update",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,operationRef:X.modelId,patch:{order:J}})}),E)for(const X of Cm(e,v.value.modelId,j.map(J=>J.modelId)))s.push({kind:"attribute.update",casUnit:"logical",containerRef:X.entityId,entityRef:X.entityId,attributeRef:X.attributeId,patch:{dbAttrs:X.dbAttrs}});break}case"group.add":{{const R=bn(k.spec,S_);if(R.length){c.push({code:"group-spec-unknown-key",opIndex:C,keys:R});break}}const E=[];let v=!1;for(const R of k.spec.members){const H=Tt(e,R);if(!H.ok){c.push(Mt(H.reason,C,R,H.matches,I)),v=!0;continue}E.push(H.value.modelId)}if(v)break;const A=a(),S={modelId:A,excludeDDLGeneration:k.spec.excludeDDLGeneration??!1,memberEntityRefs:E,...k.spec.name?{name:k.spec.name}:{},...k.spec.packageName?{packageName:k.spec.packageName}:{},...k.spec.description?{description:k.spec.description}:{}};s.push({kind:"group.add",casUnit:"logical",groupRef:A,value:S});break}case"group.update":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}const v=So(k.patch,y_);if(v.length){c.push({code:"group-patch-unknown-key",opIndex:C,handle:k.group,keys:v});break}s.push({kind:"group.update",casUnit:"logical",containerRef:E.value.modelId,groupRef:E.value.modelId,patch:k.patch});break}case"group.remove":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}s.push({kind:"group.remove",casUnit:"logical",groupRef:E.value.modelId});break}case"group.addMember":case"group.removeMember":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}const v=Tt(e,k.entity);if(!v.ok){c.push(Mt(v.reason,C,k.entity,v.matches,I));break}const A=E.value.memberEntityRefs.includes(v.value.modelId);if(k.kind==="group.addMember"?A:!A)break;if(k.kind==="group.removeMember"){if(b.has(w(E.value.modelId,v.value.modelId)))break;b.add(w(E.value.modelId,v.value.modelId))}s.push({kind:k.kind,casUnit:"logical",containerRef:E.value.modelId,groupRef:E.value.modelId,entityRef:v.value.modelId});break}}}),c.length||P_(s,e,y,g,h,_,N,a,f),c.length||B_(s,e,h,y),c.length||D_(s,e,h,_,y,a),c.length?{ok:!1,errors:c}:d.length?{ok:!0,ops:s,notices:d}:{ok:!0,ops:s}}function Mt(e,n,o,i,a){return e==="shape"?{code:"handle-shape-invalid",opIndex:n,where:"entity",expected:"{ref, by?}",got:hs(o)}: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}}const er=e=>!!e&&typeof e=="object"&&typeof e.ref=="string",q_=e=>!!e&&typeof e=="object"&&er(e.from)&&er(e.to),hs=e=>e===void 0?"undefined":e===null?"null":typeof e!="object"?typeof e:`{${Object.keys(e).join(",")}}`;function Y_(e,n,o){const i=e,a=[];for(const l of["attribute","index","operation","group"])l in i&&a.push([l,i[l],er(i[l])]);(e.kind==="association.update"||e.kind==="association.remove"||e.kind==="associationEnd.update")&&a.push(["association",i.association,q_(i.association)]);let r=!0;for(const[l,s,c]of a)c||(r=!1,o.push({code:"handle-shape-invalid",opIndex:n,where:l,expected:l==="association"?"{from:{ref}, to:{ref}}":"{ref, by?}",got:hs(s)}));return r}function nf(e,n,o,i,a){const r=Tt(e,n.from),l=Tt(e,n.to);if(r.ok||i.push(Mt(r.reason,o,n.from,r.matches,a)),l.ok||i.push(Mt(l.reason,o,n.to,l.matches,a)),!r.ok||!l.ok)return null;const s=zm(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 of={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},W_={type:"object",description:"엔티티 내 이름으로 지정(인덱스명·메서드명). 물리명 차원이 없어 매칭 키 고정(`by`)을 받지 않는다.",properties:{ref:{type:"string",description:"매칭할 이름."}},required:["ref"],additionalProperties:!1},J_={type:"object",description:"관계는 무명이라 양 끝 엔티티로 주소. from=부모(end1), to=자식(end2). 같은 쌍 복수 관계는 모호 보고.",properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"}},required:["from","to"],additionalProperties:!1},an={type:"object",properties:{ko:{type:"string"},en:{type:"string"},ja:{type:"string"},zh:{type:"string"}},additionalProperties:!1},X_={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."},classLogicalName:{...an,description:"**클래스** 논리명(다국어). 테이블이 없는 자리(직렬화 타입 SERIALIZED_TYPE)의 논리명이 여기 산다 — 그 타입은 table 자체를 갖지 않아 table.logicalName 을 줄 데가 없다. ⚠️테이블이 있는 엔티티는 table.logicalName 이 이기므로 그쪽을 쓴다."},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},Z_={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},Q_={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:{...an,description:"속성 설명(다국어)."},columnLogicalName:{...an,description:'dbAttr 컬럼 논리명(다국어, 예: {ko:"체크아웃유형"}). 한글 업무명 보존 위치.'},fieldLogicalName:{...an,description:"**필드** 논리명(다국어). 평탄 `logicalName`(컬럼 논리명)과 **다른 축**이다 — 컬럼이 없는 자리(직렬화 타입 SERIALIZED_TYPE 의 자기 필드)는 dbAttrs 가 0이라 컬럼 논리명을 줄 데가 없고, 그 자리의 논리명이 여기 산다(캔버스 논리 뷰·탐색기 검색·코드젠 javadoc 이 읽는다). 컬럼이 있는 자리에서는 컬럼 논리명이 이긴다."},unique:{type:"boolean",description:"dbAttr UNIQUE 제약."},updatable:{type:"boolean",description:"dbAttr 갱신 가능(JPA @Column(updatable=))."},sequenceName:{type:"string",description:"dbAttr 채번 시퀀스명. **비PK·autoIncrement 없는 컬럼**에 주면 «애플리케이션 채번»(DB 는 CREATE SEQUENCE 만 · 값은 채번기가 접두어를 입혀 생성) — 여러 속성이 **같은 이름을 공유**해도 정상(공유 채번기 · /text 의 `sequence=` 로 기존 이름 확인). 컬럼 생성 트리거 필드(dataType 동반)."},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},eE={type:"array",description:"predefined 임베더블 서브컬럼 오버라이드(속성 type이 카탈로그 엔트리이자 EMBED_PREDEF일 때만). field=카탈로그 필드명으로 매칭(@AttributeOverride 대응). 미설정 서브컬럼은 add=카탈로그 기본 상속 / update=기존값 유지. currency 등 공유 컬럼은 sharedColumnPhysicalName으로 SHARED_REF. ⚠️바인딩 축만 덮는다 — 서브컬럼 **논리명**은 여기 없고 patch의 dotted `dbAttrs.<i>.logicalName`이 받는다.",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 컬럼에만 저장."},notNull:{type:"boolean",description:"JPA @Column(nullable=false) — **이 서브컬럼 하나의** NOT NULL. 미설정이면 속성 축(notNull)을 따른다. ★임베더블은 컬럼마다 제약이 갈릴 수 있어(실측: ChangedBy 는 type 컬럼만 NOT NULL) 속성 축 하나로는 담기지 않는다. OWN 컬럼에만 저장."},sharedColumnPhysicalName:{type:"string",description:"SHARED_REF — 같은 엔터티(임베더블이면 owner 합집합) 다른 컬럼(물리명)을 공유해 read-only 투영(대표: currency). 설정 시 자체 컬럼 미보유, 타깃은 해소 시점 존재 필수."}},required:["field"],additionalProperties:!1}},af={type:"string",enum:["NO_INSTANCE_OR_ONE_INSTANCE","EXACTLY_ONE_INSTANCE","ZERO_OR_MORE_INSTANCES","ONE_OR_MORE_INSTANCES"]},tE={type:"object",description:'연관 생성. **to 가 임베더블(JPA_EMBEDDABLE)이면 EMBED 관계로 생성된다** — owner(from)에 EMBED_OWN 표시 속성이 생기고 컬럼은 임베더블 선언에서 평탄화되므로 따로 주지 않는다. 단일/컬렉션은 toMultiplicity 로 가른다(0..*·1..* = @ElementCollection). EMBED 일 때 identifying·composition·fromMultiplicity 는 성립하지 않아 거부된다(embed-spec-inapplicable). from 만 임베더블이면 거부된다 — 임베더블은 테이블·PK 가 없어 FK 부모가 될 수 없다. 임베더블이 다른 임베더블을 품는 연쇄는 정당하고, 순환(자기·간접)만 거부된다(embed-self-unsupported·embed-cycle-unsupported). 직렬화 타입은 관계가 아니라 소비 속성의 type 으로 지목한다(attribute.update {type: "<타입명>"}).',properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"},fromMultiplicity:{...af,description:"end1 다중성(기본 EXACTLY_ONE_INSTANCE). EMBED 에는 성립하지 않는다."},toMultiplicity:{...af,description:"end2 다중성. FK 기본은 ZERO_OR_MORE_INSTANCES 이지만 **EMBED 기본은 EXACTLY_ONE_INSTANCE** 다. EMBED 에서 0..*·1..* 는 @ElementCollection(컬럼이 owner 가 아니라 임베더블에 남는다), 1·0..1 은 단일 @Embedded."},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK로 전파). self-association은 식별 불가. EMBED 에는 성립하지 않는다."},composition:{type:"boolean",description:"end2 composition. EMBED 는 항상 true 라 지정 대상이 아니다."}},required:["from","to"],additionalProperties:!1},nE={type:"object",properties:{name:{type:"string"},unique:{type:"boolean",description:"UNIQUE 인덱스 여부(기본 false)."},columns:{type:"array",description:"인덱스 컬럼(순서 의미 있음).",items:{type:"object",properties:{column:{...of,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},oE={type:"object",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"],description:"가시성(기본 미설정)."},sourceCode:{type:"string",description:"Java 메서드 본문(멀티라인, 파라미터·반환 시그니처 포함)."},description:{...an,description:"메서드 설명(다국어)."},personalInfoAttributeType:{type:"string",description:"개인정보 속성 유형(패스스루)."}},required:["name"],additionalProperties:!1},iE={type:"object",properties:{name:{...an,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},aE={type:"object",description:'기존 속성 부분 patch. 논리 필드 + 스칼라 단일 컬럼의 물리 필드(physicalName·dataType·length·scale 등 — 서버가 dbAttrs[0]에 매핑). ⚠️평탄 물리 키는 **attrType 이 NORMAL 이고 컬럼이 하나일 때만** 매핑된다 — FK 파생(RELATION_*)·임베드·직렬화 타입 자리에서는 거부되고 **dotted 로 지목**해야 한다(`{"dbAttrs.0.physicalName":"…"}`). EMBED_PREDEF/Money 서브컬럼 «바인딩» 조정만 op-레벨 embeddableOverrides 소관이다(그 배열엔 논리명·dataType 축이 없다). ★다중 컬럼 속성의 **개별 컬럼 필드**는 dotted 키로 지목한다 — `{"dbAttrs.<i>.logicalName":{ko:"…"}}` 처럼. dotted 허용 접두는 `dbAttrs.` 하나뿐이고, 같은 op에서 평탄 키와 섞으면 $set 충돌로 거부된다. ⚠️★**NORMAL 속성의 컬럼을 둘 이상으로 늘릴 수 없다**(dbAttrs 배열 교체·없는 dotted 슬롯 둘 다 거부 — attribute-column-count-unsupported). 다중 컬럼이 필요하면 **임베더블 엔터티를 만들고 association.add 로 연결**한다(EMBED) — 컬럼은 그 선언에서 파생된다.',properties:{name:{type:"string"},type:{type:"string",description:"자바 타입. **컬럼 개수가 바뀌는 전환만 거부된다**(임베더블 타입으로 1→N, 임베더블을 다른 타입으로 N→1). 그 전환은 attribute.remove + attribute.add 로 내고(자리를 지키려면 같은 배치에 attribute.reorder). ★반대로 **개수가 같은 값 타입 재지정은 이 patch 하나로 된다** — 1컬럼 속성을 1필드 임베더블로 바꾸는 등. attrType은 목적지에서 파생되므로 생략해도 되고(EMBED_PREDEF로 자동), 실어 보내면 그 파생값과 같아야 한다. dbAttrs는 modelId째 보존되어 물리명·논리명·길이·인덱스 ref·order가 그대로 살아남는다. 임베드 서브컬럼 «바인딩» 조정만 embeddableOverrides 소관이다."},customType:{type:"string"},attrType:{type:"string",enum:[...wm],description:"속성 종류. **현재 값과 다르게 주면 거부된다** — 관계/임베드/구분선은 동반 구조(관계 소유·embedded·빈 dbAttrs)가 있어야 성립하고 patch로는 표현할 수 없다. 관계 실체화는 association.add, 임베드 서브컬럼은 embeddableOverrides 소관. ★예외 하나 — 같은 patch의 type이 «컬럼 개수가 같은» 임베더블을 가리키면 NORMAL→EMBED_PREDEF 동반 전환이 허용된다(생략해도 파생된다)."},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:{...an,description:"속성 설명(다국어)."},fieldLogicalName:{...an,description:"**필드** 논리명(다국어). 평탄 `logicalName`(컬럼 논리명)과 **다른 축**이다 — 컬럼이 없는 자리(직렬화 타입 SERIALIZED_TYPE 의 자기 필드)는 dbAttrs 가 0이라 컬럼 논리명을 줄 데가 없고, 그 자리의 논리명이 여기 산다(캔버스 논리 뷰·탐색기 검색·코드젠 javadoc 이 읽는다). 컬럼이 있는 자리에서는 컬럼 논리명이 이긴다."},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",description:"채번 시퀀스명 — autoIncrement 없이 주면 애플리케이션 채번(공유 가능). attribute.add 의 같은 필드 설명 참조."},logicalName:{...an,description:"**컬럼** 논리명(다국어). 대상이 스칼라 단일 컬럼일 때 dbAttrs[0]에 매핑된다. ★대상이 **다중 컬럼**(EMBED_PREDEF·Money 등)이면 이 평탄 키는 «어느 컬럼인지 모호» 로 거부되고, dotted `dbAttrs.<i>.logicalName` 이 그 값을 받는다(embeddableOverrides 에는 논리명 축이 없다). dbAttrs 가 0인 속성(직렬화 타입 필드·transient)에 주면 거부되고, 그 자리는 `fieldLogicalName` 이 받는다."}},additionalProperties:!1},rE={type:"object",description:"관계 부분 patch. 양 end 설정(multiplicity·nav·jpa)은 associationEnd.update로.",properties:{description:{type:"string"},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK 일부로 전파)."}},additionalProperties:!1},lE={type:"object",description:"인덱스 부분 patch. columns(컬럼 구성) 변경은 index.remove+index.add로(패치 불가).",properties:{name:{type:"string"},unique:{type:"boolean"},description:{type:"string"},parameters:{type:"string"}},additionalProperties:!1},sE={type:"object",description:"메서드 부분 patch.",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"]},sourceCode:{type:"string"},description:{...an,description:"메서드 설명(다국어)."},order:{type:"integer"},personalInfoAttributeType:{type:"string"}},additionalProperties:!1},cE={type:"object",description:'엔티티 부분 patch. 논리 키: name·stereotype·packageName·superClass·schema·description·abstractClass·hasPersonalInfo·referenceOnly·declarationOfInterfaces·table·serialization·classLogicalName. classLogicalName = **클래스** 논리명(테이블 없는 직렬화 타입의 논리명이 사는 곳 — 그 타입은 table 을 갖지 않는다). 테이블이 있는 엔티티는 table.logicalName(dotted-key)이 이긴다. 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 소관).'},dE={type:"object",description:'관계 end 부분 patch. 논리 키: multiplicity·navigable·composition. jpa 설정(cascadeTypes·fetchType·orphanRemoval·orderBy·collectionType·collectionTable·orderColumn)은 형제 클로버 방지를 위해 dotted-key로: {"jpa.orphanRemoval": true}.'};function pt(e,n){return{type:"object",properties:{kind:{const:e},...n.properties},required:["kind",...n.required],additionalProperties:!1}}const uE={"entity.add":pt("entity.add",{properties:{spec:{$ref:"#/$defs/entitySpec"}},required:["spec"]}),"entity.update":pt("entity.update",{properties:{entity:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/entityUpdatePatch"}},required:["entity","patch"]}),"entity.remove":pt("entity.remove",{properties:{entity:{$ref:"#/$defs/handle"}},required:["entity"]}),"attribute.add":pt("attribute.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/attrSpec"}},required:["entity","spec"]}),"attribute.update":pt("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":pt("attribute.remove",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"}},required:["entity","attribute"]}),"association.add":pt("association.add",{properties:{spec:{$ref:"#/$defs/assocSpec"}},required:["spec"]}),"association.remove":pt("association.remove",{properties:{association:{$ref:"#/$defs/assocHandle"}},required:["association"]}),"association.update":pt("association.update",{properties:{association:{$ref:"#/$defs/assocHandle"},patch:{$ref:"#/$defs/assocUpdatePatch"}},required:["association","patch"]}),"associationEnd.update":pt("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":pt("index.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/indexSpec"}},required:["entity","spec"]}),"index.update":pt("index.update",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/indexUpdatePatch"}},required:["entity","index","patch"]}),"index.remove":pt("index.remove",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"}},required:["entity","index"]}),"operation.add":pt("operation.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/operationSpec"}},required:["entity","spec"]}),"operation.update":pt("operation.update",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/operationUpdatePatch"}},required:["entity","operation","patch"]}),"operation.remove":pt("operation.remove",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"}},required:["entity","operation"]}),"attribute.reorder":pt("attribute.reorder",{properties:{entity:{$ref:"#/$defs/handle"},order:{type:"array",items:{$ref:"#/$defs/handle"}}},required:["entity","order"]}),"operation.reorder":pt("operation.reorder",{properties:{entity:{$ref:"#/$defs/handle"},operations:{type:"array",items:{$ref:"#/$defs/nameHandle"}}},required:["entity","operations"]}),"group.add":pt("group.add",{properties:{spec:{$ref:"#/$defs/groupSpec"}},required:["spec"]}),"group.update":pt("group.update",{properties:{group:{$ref:"#/$defs/groupHandle"},patch:{$ref:"#/$defs/groupUpdatePatch"}},required:["group","patch"]}),"group.remove":pt("group.remove",{properties:{group:{$ref:"#/$defs/groupHandle"}},required:["group"]}),"group.addMember":pt("group.addMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]}),"group.removeMember":pt("group.removeMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]})},mE={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},fE={type:"object",description:"그룹 부분 patch. 멤버 변경은 group.addMember/removeMember로(배열 통째 교체는 동시 편집이 서로를 덮는다).",properties:{name:{...an,description:"그룹 논리명(다국어)."},packageName:{type:"string"},description:{type:"string"},excludeDDLGeneration:{type:"boolean"}},additionalProperties:!1},rf={anyOf:Nm.map(e=>uE[e])},pE={type:"object",description:"엔티티 모델을 생성·수정·삭제할 때 호출한다. ops는 사람 핸들(엔티티 물리명/논리명, 속성명)로 지정하며 서버가 modelId로 해소한다. 모호하면 에러로 후보를 돌려주니 리소스로 현재 모델을 먼저 읽어 핸들을 확정하라.",properties:{ops:{type:"array",items:{$ref:"#/$defs/symbolicOp"}}},required:["ops"],additionalProperties:!1,$defs:{handle:of,nameHandle:W_,groupHandle:mE,assocHandle:J_,entitySpec:X_,serialization:Z_,attrSpec:Q_,embeddableOverrides:eE,assocSpec:tE,indexSpec:nE,operationSpec:oE,groupSpec:iE,entityUpdatePatch:cE,attrUpdatePatch:aE,assocUpdatePatch:rE,assocEndUpdatePatch:dE,indexUpdatePatch:lE,operationUpdatePatch:sE,groupUpdatePatch:fE,symbolicOp:rf}};function hE(e,n,o,i={}){const a=i.mkClientOpId??Fe,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 lf={location:{x:0,y:0},size:{width:220,height:140}};function sf(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,notNull:e.notNull,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}const yE=/^[-=_*~\s]{3,}$/;function gE(e){return e.attrType&&e.attrType!=="NORMAL"||!yE.test(e.name??"")?!1:!(e.dbAttrs??[]).some(n=>n.physicalName||n.dataType)}function bE(e){return e.type===hn&&e.customType==="java.util.Currency"?{type:"Currency",customType:void 0}:{type:e.type,customType:e.customType}}function kE(e,n){if(e.attrType==="DIVIDER"||gE(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=bE(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(sf)}}function _E(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 EE(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 NE(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(kE),operations:(n=e.operations)==null?void 0:n.map(_E),indexes:(o=e.indexes)==null?void 0:o.map(EE),jpaAttrs:e.jpaAttrs,table:e.dbAttrs?{physicalName:e.dbAttrs.physicalName,logicalName:e.dbAttrs.logicalName}:void 0}}function wE(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??{...lf},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 cf(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 ys(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:cf(e)}}function IE(e){if(e.end1.endModel.refId===e.end2.endModel.refId)return;const n=o=>gs(o)&&(o==null?void 0:o.identifier)===!0;return n(e.end1.attribute)||n(e.end2.attribute)?!0:void 0}function vE(e){var i,a;const n={modelId:e.modelId,description:e.description,identifying:IE(e),end1:ys(e.end1),end2:ys(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 gs(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("RELATION")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function df(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("EMBED")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function uf(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 mf(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(sf)}}function CE(e,n,o){var w,I;const i=gs(e.end1.attribute),a=gs(e.end2.attribute);if(i===a)return vE(e);const r=i?e.end1:e.end2,l=i?e.end2:e.end1,s=r.attribute,c=(I=(w=s.dbAttrs)==null?void 0:w[0])==null?void 0:I.targetModelId,d=c?o.get(c):void 0,u=n.get(l.endModel.refId),m=u?u.attributes.reduce(($,k)=>Math.max($,k.order),-1)+1:s.order??0,f={...mf(s,m),attrType:"RELATION_OWN",derivedFrom:d?{associationRef:e.modelId,sourceAttributeRef:d}:void 0};u&&u.attributes.push(f);const p=n.get(r.endModel.refId),g=l.attribute;let y;if(g&&p&&r.navigable){const $=Ea(l.multiplicity);y={modelId:g.modelId??crypto.randomUUID(),name:yo(g.name??wa((u==null?void 0:u.name)??l.endModel.refId,$),new Set(p.attributes.map(k=>k.name))),type:(u==null?void 0:u.name)??l.endModel.refId,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:p.attributes.reduce((k,C)=>Math.max(k,C.order),-1)+1,dbAttrs:[]},p.attributes.push(y)}const h=($,k)=>({entityRef:$.endModel.refId,multiplicity:$.multiplicity,navigable:$.navigable,composition:$.composition,attributeRef:k?y==null?void 0:y.modelId:f.modelId,jpa:cf($)}),_=r.endModel.refId===l.endModel.refId,N={modelId:e.modelId,description:e.description,identifying:!_&&f.identifier===!0?!0:void 0,end1:h(e.end1,i),end2:h(e.end2,a)},b={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:i?d:f.modelId,targetColumnRef:i?f.modelId:d,style:e.style};return{assoc:N,layout:b}}function SE(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),notNull:e.notNull??(o==null?void 0:o.notNull)}}function RE(e,n,o){var g;const i=((g=e.end1.attribute)==null?void 0:g.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((y,h)=>Math.max(y,h.order),-1)+1:l.order??0,d={...mf(l,c),attrType:l.attrType??"EMBED_OWN",dbAttrs:(l.dbAttrs??[]).map(y=>SE(y,o)),embedded:{associationRef:e.modelId,embeddableRef:a.endModel.refId}};s&&s.attributes.push(d);const u=y=>({...ys(y),legacyEmbedRaw:y.attribute}),m={modelId:e.modelId,description:e.description,end1:u(e.end1),end2:u(e.end2)},f=!i,p={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:f?d.modelId:void 0,targetColumnRef:f?void 0:d.modelId,style:e.style};return{assoc:m,layout:p}}function AE(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 ff(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=AE(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 pf(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 hf(e,n){const o=(i,a)=>{if(i==null)return;const r=i[a];if(r==null)return;const l=Xc(r);l!==r&&(l===void 0?delete i[a]:i[a]=l)};for(const i of n)o(i,"name");for(const i of e){o(i,"classLogicalName"),o(i,"description"),o(i.table,"logicalName");for(const a of i.operations??[])o(a,"description");for(const a of i.attributes){o(a,"fieldLogicalName"),o(a,"description");for(const r of a.dbAttrs??[])o(r,"logicalName")}}}function xE(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||at(a.stereotype)||at(r.stereotype))continue;const l=i.end1.attributeRef?a.attributes.find(f=>f.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(f=>f.modelId===s);if((c==null?void 0:c.attrType)==="RELATION_REF"){i.end1.attributeRef=s;continue}const d=Ea(i.end2.multiplicity),u=wa(r.name,d),m=yo(u,new Set(a.attributes.map(f=>f.name)));a.attributes.push({modelId:s,name:m,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:a.attributes.reduce((f,p)=>Math.max(f,p.order),-1)+1,dbAttrs:[]}),i.end1.attributeRef=s}}function $E(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||at(a.stereotype)||at(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 yf(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&&at(l.stereotype))continue;const s=a.end1.entityRef===a.end2.entityRef,c=a.identifying===!0||!s&&!Ed(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 gf(e){const n=JSON.parse(JSON.stringify(e));return(n.schemaVersion??1)>=2&&"logical"in n?TE(n):ME(n)}function TE(e){const n=e.id??e.logical.modelId??"",o={},i=m=>{const{rev:f,...p}=m;return f!=null&&(o[m.modelId]=f),p},a=e.logical.entities.map(i),r=e.logical.associations.map(i),l=e.logical.groups.map(i);xE(a,r),$E(a,r),yf(a,r),hf(a,l);const{version:s,...c}=e.layout;pf(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 ME(e){var _,N;const n=e.id??"",o=[],i=[],a=[],r=[],l=[],s=[],c=[],d=(b,w)=>{o.push(NE(b));const I=wE(b);I.geo={location:{x:I.geo.location.x+w.x,y:I.geo.location.y+w.y},size:I.geo.size},i.push(I);for(const $ of b.ownedAssociations??[])c.push($)},u={x:0,y:0};for(const b of e.entities??[])d(b,u);const m=[];for(const b of e.groups??[]){const w=b.entities??[];l.push({modelId:b.modelId,name:b.name,description:b.description,packageName:b.packageName,excludeDDLGeneration:b.excludeDDLGeneration??!1,memberEntityRefs:w.map($=>$.modelId)});const I=((_=b.geo)==null?void 0:_.location)??u;if(b.geo){const $=(b.notes??[]).map(k=>k.modelId);s.push({groupRef:b.modelId,geo:b.geo,style:b.style,locked:b.locked,memberNoteRefs:$.length?$:void 0})}for(const $ of w)d($,I);for(const $ of b.notes??[])m.push(ff($,I))}const f=new Map(o.map(b=>[b.modelId,b])),p=new Map,g=new Map;for(const b of o)for(const w of b.attributes)for(const I of w.dbAttrs)p.set(I.modelId,w.modelId),g.set(I.modelId,I);for(const b of c)for(const w of[b.end1,b.end2]){const I=w.attribute;if(I&&(((N=I.dbAttrs)==null?void 0:N.length)??0)>0)for(const $ of I.dbAttrs)$.modelId&&p.set($.modelId,I.modelId)}for(const b of c){const w=df(b.end1.attribute),I=df(b.end2.attribute),$=uf(b.end1)||uf(b.end2),{assoc:k,layout:C}=w!==I||$?RE(b,f,g):CE(b,f,p);a.push(k),r.push(C)}pf(o,a,r),wu(o),yf(o,a),hf(o,l);const y={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(b=>ff(b)),...m]}},h={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion??1};return{state:y,meta:h}}function bf(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,notNull:e.notNull,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}function VE(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(bf),style:n}}function LE(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 BE(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 Qn(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 DE(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{...bf(i),targetModelId:(r=o==null?void 0:o.dbAttrs[a])==null?void 0:r.modelId}})}}function OE(e){return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_OWN",dbAttrs:[]}}function kf(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 PE(e){const n=new Set;for(const o of e.logical.associations){const i=kf(o,e);i&&(n.add(i.navAttr.modelId),i.fk&&n.add(i.fk.modelId))}return n}function zE(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 FE(e,n){return e===n||JSON.stringify(e??null)===JSON.stringify(n??null)}function UE(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:FE(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),notNull:o(e.notNull,n==null?void 0:n.notNull)}}function HE(e,n,o){let i;for(const m of n.logical.entities){const f=m.attributes.find(p=>{var g;return((g=p.embedded)==null?void 0:g.associationRef)===e.modelId});if(f){i=f;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,f)=>UE(m,l[f]))},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:Qn(e.end1,c?s:u),end2:Qn(e.end2,c?u:s)}}function jE(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:Qn(e.end1,e.end1.legacyEmbedRaw),end2:Qn(e.end2,e.end2.legacyEmbedRaw)};const a=HE(e,n,i);if(a)return a;const r=kf(e,n);if(r){const l=n.logical.entities.find(d=>d.modelId===r.navEnd.entityRef),s=r.fk?DE(r.fk,l):void 0,c=OE(r.navAttr);return{...i,end1:Qn(e.end1,r.navEnd===e.end1?s:c),end2:Qn(e.end2,r.navEnd===e.end2?s:c)}}return{...i,end1:Qn(e.end1),end2:Qn(e.end2)}}function _f(e,n,o,i,a={x:0,y:0}){var u,m;const r=n.layout.entityLayouts.find(f=>f.entityRef===e.modelId),l=n.logical.associations.filter(f=>f.end1.entityRef===e.modelId),s=f=>n.layout.associationLayouts.find(p=>p.associationRef===f),c=(r==null?void 0:r.geo)??{...lf},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(f=>!o.has(f.modelId)&&!i.has(f.modelId)).map(f=>{var p;return VE(f,(p=r==null?void 0:r.attributeStyles)==null?void 0:p[f.modelId])}),operations:(u=e.operations)==null?void 0:u.map(f=>{var p;return LE(f,(p=r==null?void 0:r.operationStyles)==null?void 0:p[f.modelId])}),ownedAssociations:l.map(f=>jE(f,n,s(f.modelId))),indexes:(m=e.indexes)==null?void 0:m.map(BE),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 KE(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=>Ef(c,l));return{modelId:e.modelId,name:e.name,description:e.description,packageName:e.packageName,excludeDDLGeneration:e.excludeDDLGeneration,entities:r.map(c=>_f(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 Ef(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 GE(e,n={}){const o=new Set(e.logical.groups.flatMap(s=>s.memberEntityRefs)),i=e.logical.entities.filter(s=>!o.has(s.modelId)),a=PE(e),r=zE(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=>_f(s,e,a,r)),groups:e.logical.groups.map(s=>KE(s,e,a,r)),notes:e.layout.notes.filter(s=>!l.has(s.modelId)).map(s=>Ef(s))}}function qE(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 YE=["notNull"];function WE(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}=gf(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(f=>[f.modelId,f]))]));for(const m of i.logical.entities){const f=c.get(m.modelId);if(f)for(const p of m.attributes){const g=f.get(p.modelId);if(!g){l.push({kind:"attribute.add",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,value:p}),s.navAdds++;continue}const y={};for(const h of YE)p[h]===!0!=(g[h]===!0)&&(y[h]=p[h],s.attributeFieldsByName[h]=(s.attributeFieldsByName[h]??0)+1);Object.keys(y).length!==0&&(l.push({kind:"attribute.update",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,attributeRef:p.modelId,patch:y}),s.attributeFieldPatches++)}}const d=new Map(o.logical.associations.map(m=>[m.modelId,m]));for(const m of i.logical.associations){const f=d.get(m.modelId);f&&(m.end1.attributeRef&&m.end1.attributeRef!==f.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&&f.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 Oi(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function Bn(e){return typeof e=="function"?e():t.unref(e)}const JE=typeof window<"u"&&typeof document<"u",XE=e=>typeof e<"u",ZE=Object.prototype.toString,QE=e=>ZE.call(e)==="[object Object]",eN=()=>{};function tN(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 Nf=e=>e();function nN(e=Nf){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 wf(e,n=!1,o="Timeout"){return new Promise((i,a)=>{setTimeout(n?()=>a(o):i,e)})}function oN(e,n,o={}){const{eventFilter:i=Nf,...a}=o;return t.watch(e,tN(i,n),a)}function oi(e,n,o={}){const{eventFilter:i,...a}=o,{eventFilter:r,pause:l,resume:s,isActive:c}=nN(i);return{stop:oN(e,n,{...a,eventFilter:r}),pause:l,resume:s,isActive:c}}function iN(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=Bn(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 bs(e,n=!1){function o(m,{flush:f="sync",deep:p=!1,timeout:g,throwOnTimeout:y}={}){let h=null;const N=[new Promise(b=>{h=t.watch(e,w=>{m(w)!==n&&(h==null||h(),b(w))},{flush:f,deep:p,immediate:!0})})];return g!=null&&N.push(wf(g,y).then(()=>Bn(e)).finally(()=>h==null?void 0:h())),Promise.race(N)}function i(m,f){if(!t.isRef(m))return o(w=>w===m,f);const{flush:p="sync",deep:g=!1,timeout:y,throwOnTimeout:h}=f??{};let _=null;const b=[new Promise(w=>{_=t.watch([e,m],([I,$])=>{n!==(I===$)&&(_==null||_(),w(I))},{flush:p,deep:g,immediate:!0})})];return y!=null&&b.push(wf(y,h).then(()=>Bn(e)).finally(()=>(_==null||_(),Bn(e)))),Promise.race(b)}function a(m){return o(f=>!!f,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,f){return o(p=>{const g=Array.from(p);return g.includes(m)||g.includes(Bn(m))},f)}function d(m){return u(1,m)}function u(m=1,f){let p=-1;return o(()=>(p+=1,p>=m),f)}return Array.isArray(Bn(e))?{toMatch:o,toContains:c,changed:d,changedTimes:u,get not(){return bs(e,!n)}}:{toMatch:o,toBe:i,toBeTruthy:a,toBeNull:r,toBeNaN:s,toBeUndefined:l,changed:d,changedTimes:u,get not(){return bs(e,!n)}}}function ks(e){return bs(e)}function aN(e){var n;const o=Bn(e);return(n=o==null?void 0:o.$el)!=null?n:o}const If=JE?window:void 0;function vf(...e){let n,o,i,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,i,a]=e,n=If):[n,o,i,a]=e,!n)return eN;Array.isArray(o)||(o=[o]),Array.isArray(i)||(i=[i]);const r=[],l=()=>{r.forEach(u=>u()),r.length=0},s=(u,m,f,p)=>(u.addEventListener(m,f,p),()=>u.removeEventListener(m,f,p)),c=t.watch(()=>[aN(n),Bn(a)],([u,m])=>{if(l(),!u)return;const f=QE(m)?{...m}:m;r.push(...o.flatMap(p=>i.map(g=>s(u,p,g,f))))},{immediate:!0,flush:"post"}),d=()=>{c(),l()};return Oi(d),d}function rN(e){return typeof e=="function"?e:typeof e=="string"?n=>n.key===e:Array.isArray(e)?n=>e.includes(n.key):()=>!0}function Cf(...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=If,eventName:r="keydown",passive:l=!1,dedupe:s=!1}=i,c=rN(n);return vf(a,r,u=>{u.repeat&&Bn(s)||c(u)&&o(u)},l)}function lN(e){return JSON.parse(JSON.stringify(e))}function _s(e,n,o,i={}){var a,r,l;const{clone:s=!1,passive:c=!1,eventName:d,deep:u=!1,defaultValue:m,shouldEmit:f}=i,p=t.getCurrentInstance(),g=o||(p==null?void 0:p.emit)||((a=p==null?void 0:p.$emit)==null?void 0:a.bind(p))||((l=(r=p==null?void 0:p.proxy)==null?void 0:r.$emit)==null?void 0:l.bind(p==null?void 0:p.proxy));let y=d;n||(n="modelValue"),y=y||`update:${n.toString()}`;const h=b=>s?typeof s=="function"?s(b):lN(b):b,_=()=>XE(e[n])?h(e[n]):m,N=b=>{f?f(b)&&g(y,b):g(y,b)};if(c){const b=_(),w=t.ref(b);let I=!1;return t.watch(()=>e[n],$=>{I||(I=!0,w.value=h($),t.nextTick(()=>I=!1))}),t.watch(w,$=>{!I&&($!==e[n]||u)&&N($)},{deep:u}),w}else return t.computed({get(){return _()},set(b){N(b)}})}var sN={value:()=>{}};function tr(){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 nr(o)}function nr(e){this._=e}function cN(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}})}nr.prototype=tr.prototype={constructor:nr,on:function(e,n){var o=this._,i=cN(e+"",o),a,r=-1,l=i.length;if(arguments.length<2){for(;++r<l;)if((a=(e=i[r]).type)&&(a=dN(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]=Sf(o[a],e.name,n);else if(n==null)for(a in o)o[a]=Sf(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 nr(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 dN(e,n){for(var o=0,i=e.length,a;o<i;++o)if((a=e[o]).name===n)return a.value}function Sf(e,n,o){for(var i=0,a=e.length;i<a;++i)if(e[i].name===n){e[i]=sN,e=e.slice(0,i).concat(e.slice(i+1));break}return o!=null&&e.push({name:n,value:o}),e}var Es="http://www.w3.org/1999/xhtml";const Rf={svg:"http://www.w3.org/2000/svg",xhtml:Es,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function or(e){var n=e+="",o=n.indexOf(":");return o>=0&&(n=e.slice(0,o))!=="xmlns"&&(e=e.slice(o+1)),Rf.hasOwnProperty(n)?{space:Rf[n],local:e}:e}function uN(e){return function(){var n=this.ownerDocument,o=this.namespaceURI;return o===Es&&n.documentElement.namespaceURI===Es?n.createElement(e):n.createElementNS(o,e)}}function mN(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Af(e){var n=or(e);return(n.local?mN:uN)(n)}function fN(){}function Ns(e){return e==null?fN:function(){return this.querySelector(e)}}function pN(e){typeof e!="function"&&(e=Ns(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 Gt(i,this._parents)}function hN(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function yN(){return[]}function xf(e){return e==null?yN:function(){return this.querySelectorAll(e)}}function gN(e){return function(){return hN(e.apply(this,arguments))}}function bN(e){typeof e=="function"?e=gN(e):e=xf(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 Gt(i,a)}function $f(e){return function(){return this.matches(e)}}function Tf(e){return function(n){return n.matches(e)}}var kN=Array.prototype.find;function _N(e){return function(){return kN.call(this.children,e)}}function EN(){return this.firstElementChild}function NN(e){return this.select(e==null?EN:_N(typeof e=="function"?e:Tf(e)))}var wN=Array.prototype.filter;function IN(){return Array.from(this.children)}function vN(e){return function(){return wN.call(this.children,e)}}function CN(e){return this.selectAll(e==null?IN:vN(typeof e=="function"?e:Tf(e)))}function SN(e){typeof e!="function"&&(e=$f(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 Gt(i,this._parents)}function Mf(e){return new Array(e.length)}function RN(){return new Gt(this._enter||this._groups.map(Mf),this._parents)}function ir(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}ir.prototype={constructor:ir,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 AN(e){return function(){return e}}function xN(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 ir(e,r[l]);for(;l<c;++l)(s=n[l])&&(a[l]=s)}function $N(e,n,o,i,a,r,l){var s,c,d=new Map,u=n.length,m=r.length,f=new Array(u),p;for(s=0;s<u;++s)(c=n[s])&&(f[s]=p=l.call(c,c.__data__,s,n)+"",d.has(p)?a[s]=c:d.set(p,c));for(s=0;s<m;++s)p=l.call(e,r[s],s,r)+"",(c=d.get(p))?(i[s]=c,c.__data__=r[s],d.delete(p)):o[s]=new ir(e,r[s]);for(s=0;s<u;++s)(c=n[s])&&d.get(f[s])===c&&(a[s]=c)}function TN(e){return e.__data__}function MN(e,n){if(!arguments.length)return Array.from(this,TN);var o=n?$N:xN,i=this._parents,a=this._groups;typeof e!="function"&&(e=AN(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],f=m.length,p=VN(e.call(u,u&&u.__data__,d,i)),g=p.length,y=s[d]=new Array(g),h=l[d]=new Array(g),_=c[d]=new Array(f);o(u,m,y,h,_,p,n);for(var N=0,b=0,w,I;N<g;++N)if(w=y[N]){for(N>=b&&(b=N+1);!(I=h[b])&&++b<g;);w._next=I||null}}return l=new Gt(l,i),l._enter=s,l._exit=c,l}function VN(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function LN(){return new Gt(this._exit||this._groups.map(Mf),this._parents)}function BN(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 DN(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,f=s[c]=new Array(m),p,g=0;g<m;++g)(p=d[g]||u[g])&&(f[g]=p);for(;c<a;++c)s[c]=o[c];return new Gt(s,this._parents)}function ON(){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 PN(e){e||(e=zN);function n(m,f){return m&&f?e(m.__data__,f.__data__):!m-!f}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 Gt(a,this._parents).order()}function zN(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function FN(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function UN(){return Array.from(this)}function HN(){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 jN(){let e=0;for(const n of this)++e;return e}function KN(){return!this.node()}function GN(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 qN(e){return function(){this.removeAttribute(e)}}function YN(e){return function(){this.removeAttributeNS(e.space,e.local)}}function WN(e,n){return function(){this.setAttribute(e,n)}}function JN(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function XN(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttribute(e):this.setAttribute(e,o)}}function ZN(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 QN(e,n){var o=or(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?YN:qN:typeof n=="function"?o.local?ZN:XN:o.local?JN:WN)(o,n))}function Vf(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function e1(e){return function(){this.style.removeProperty(e)}}function t1(e,n,o){return function(){this.style.setProperty(e,n,o)}}function n1(e,n,o){return function(){var i=n.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,o)}}function o1(e,n,o){return arguments.length>1?this.each((n==null?e1:typeof n=="function"?n1:t1)(e,n,o??"")):ii(this.node(),e)}function ii(e,n){return e.style.getPropertyValue(n)||Vf(e).getComputedStyle(e,null).getPropertyValue(n)}function i1(e){return function(){delete this[e]}}function a1(e,n){return function(){this[e]=n}}function r1(e,n){return function(){var o=n.apply(this,arguments);o==null?delete this[e]:this[e]=o}}function l1(e,n){return arguments.length>1?this.each((n==null?i1:typeof n=="function"?r1:a1)(e,n)):this.node()[e]}function Lf(e){return e.trim().split(/^|\s+/)}function ws(e){return e.classList||new Bf(e)}function Bf(e){this._node=e,this._names=Lf(e.getAttribute("class")||"")}Bf.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 Df(e,n){for(var o=ws(e),i=-1,a=n.length;++i<a;)o.add(n[i])}function Of(e,n){for(var o=ws(e),i=-1,a=n.length;++i<a;)o.remove(n[i])}function s1(e){return function(){Df(this,e)}}function c1(e){return function(){Of(this,e)}}function d1(e,n){return function(){(n.apply(this,arguments)?Df:Of)(this,e)}}function u1(e,n){var o=Lf(e+"");if(arguments.length<2){for(var i=ws(this.node()),a=-1,r=o.length;++a<r;)if(!i.contains(o[a]))return!1;return!0}return this.each((typeof n=="function"?d1:n?s1:c1)(o,n))}function m1(){this.textContent=""}function f1(e){return function(){this.textContent=e}}function p1(e){return function(){var n=e.apply(this,arguments);this.textContent=n??""}}function h1(e){return arguments.length?this.each(e==null?m1:(typeof e=="function"?p1:f1)(e)):this.node().textContent}function y1(){this.innerHTML=""}function g1(e){return function(){this.innerHTML=e}}function b1(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n??""}}function k1(e){return arguments.length?this.each(e==null?y1:(typeof e=="function"?b1:g1)(e)):this.node().innerHTML}function _1(){this.nextSibling&&this.parentNode.appendChild(this)}function E1(){return this.each(_1)}function N1(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function w1(){return this.each(N1)}function I1(e){var n=typeof e=="function"?e:Af(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function v1(){return null}function C1(e,n){var o=typeof e=="function"?e:Af(e),i=n==null?v1:typeof n=="function"?n:Ns(n);return this.select(function(){return this.insertBefore(o.apply(this,arguments),i.apply(this,arguments)||null)})}function S1(){var e=this.parentNode;e&&e.removeChild(this)}function R1(){return this.each(S1)}function A1(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function x1(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function $1(e){return this.select(e?x1:A1)}function T1(e){return arguments.length?this.property("__data__",e):this.node().__data__}function M1(e){return function(n){e.call(this,n,this.__data__)}}function V1(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 L1(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 B1(e,n,o){return function(){var i=this.__on,a,r=M1(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 D1(e,n,o){var i=V1(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?B1:L1,a=0;a<r;++a)this.each(s(i[a],n,o));return this}function Pf(e,n,o){var i=Vf(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 O1(e,n){return function(){return Pf(this,e,n)}}function P1(e,n){return function(){return Pf(this,e,n.apply(this,arguments))}}function z1(e,n){return this.each((typeof n=="function"?P1:O1)(e,n))}function*F1(){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 zf=[null];function Gt(e,n){this._groups=e,this._parents=n}function Pi(){return new Gt([[document.documentElement]],zf)}function U1(){return this}Gt.prototype=Pi.prototype={constructor:Gt,select:pN,selectAll:bN,selectChild:NN,selectChildren:CN,filter:SN,data:MN,enter:RN,exit:LN,join:BN,merge:DN,selection:U1,order:ON,sort:PN,call:FN,nodes:UN,node:HN,size:jN,empty:KN,each:GN,attr:QN,style:o1,property:l1,classed:u1,text:h1,html:k1,raise:E1,lower:w1,append:I1,insert:C1,remove:R1,clone:$1,datum:T1,on:D1,dispatch:z1,[Symbol.iterator]:F1};function rn(e){return typeof e=="string"?new Gt([[document.querySelector(e)]],[document.documentElement]):new Gt([[e]],zf)}function H1(e){let n;for(;n=e.sourceEvent;)e=n;return e}function kn(e,n){if(e=H1(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 j1={passive:!1},zi={capture:!0,passive:!1};function Is(e){e.stopImmediatePropagation()}function ai(e){e.preventDefault(),e.stopImmediatePropagation()}function Ff(e){var n=e.document.documentElement,o=rn(e).on("dragstart.drag",ai,zi);"onselectstart"in n?o.on("selectstart.drag",ai,zi):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Uf(e,n){var o=e.document.documentElement,i=rn(e).on("dragstart.drag",null);n&&(i.on("click.drag",ai,zi),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 ar=e=>()=>e;function vs(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}})}vs.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function K1(e){return!e.ctrlKey&&!e.button}function G1(){return this.parentNode}function q1(e,n){return n??{x:e.x,y:e.y}}function Y1(){return navigator.maxTouchPoints||"ontouchstart"in this}function W1(){var e=K1,n=G1,o=q1,i=Y1,a={},r=tr("start","drag","end"),l=0,s,c,d,u,m=0;function f(w){w.on("mousedown.drag",p).filter(i).on("touchstart.drag",h).on("touchmove.drag",_,j1).on("touchend.drag touchcancel.drag",N).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(w,I){if(!(u||!e.call(this,w,I))){var $=b(this,n.call(this,w,I),w,I,"mouse");$&&(rn(w.view).on("mousemove.drag",g,zi).on("mouseup.drag",y,zi),Ff(w.view),Is(w),d=!1,s=w.clientX,c=w.clientY,$("start",w))}}function g(w){if(ai(w),!d){var I=w.clientX-s,$=w.clientY-c;d=I*I+$*$>m}a.mouse("drag",w)}function y(w){rn(w.view).on("mousemove.drag mouseup.drag",null),Uf(w.view,d),ai(w),a.mouse("end",w)}function h(w,I){if(e.call(this,w,I)){var $=w.changedTouches,k=n.call(this,w,I),C=$.length,x,T;for(x=0;x<C;++x)(T=b(this,k,w,I,$[x].identifier,$[x]))&&(Is(w),T("start",w,$[x]))}}function _(w){var I=w.changedTouches,$=I.length,k,C;for(k=0;k<$;++k)(C=a[I[k].identifier])&&(ai(w),C("drag",w,I[k]))}function N(w){var I=w.changedTouches,$=I.length,k,C;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),k=0;k<$;++k)(C=a[I[k].identifier])&&(Is(w),C("end",w,I[k]))}function b(w,I,$,k,C,x){var T=r.copy(),z=kn(x||$,I),V,D,E;if((E=o.call(w,new vs("beforestart",{sourceEvent:$,target:f,identifier:C,active:l,x:z[0],y:z[1],dx:0,dy:0,dispatch:T}),k))!=null)return V=E.x-z[0]||0,D=E.y-z[1]||0,function v(A,S,R){var H=z,P;switch(A){case"start":a[C]=v,P=l++;break;case"end":delete a[C],--l;case"drag":z=kn(R||S,I),P=l;break}T.call(A,w,new vs(A,{sourceEvent:S,subject:E,target:f,identifier:C,active:P,x:z[0]+V,y:z[1]+D,dx:z[0]-H[0],dy:z[1]-H[1],dispatch:T}),k)}}return f.filter=function(w){return arguments.length?(e=typeof w=="function"?w:ar(!!w),f):e},f.container=function(w){return arguments.length?(n=typeof w=="function"?w:ar(w),f):n},f.subject=function(w){return arguments.length?(o=typeof w=="function"?w:ar(w),f):o},f.touchable=function(w){return arguments.length?(i=typeof w=="function"?w:ar(!!w),f):i},f.on=function(){var w=r.on.apply(r,arguments);return w===r?f:w},f.clickDistance=function(w){return arguments.length?(m=(w=+w)*w,f):Math.sqrt(m)},f}function Cs(e,n,o){e.prototype=n.prototype=o,o.constructor=e}function Hf(e,n){var o=Object.create(e.prototype);for(var i in n)o[i]=n[i];return o}function Fi(){}var Ui=.7,rr=1/Ui,ri="\\s*([+-]?\\d+)\\s*",Hi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",_n="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",J1=/^#([0-9a-f]{3,8})$/,X1=new RegExp(`^rgb\\(${ri},${ri},${ri}\\)$`),Z1=new RegExp(`^rgb\\(${_n},${_n},${_n}\\)$`),Q1=new RegExp(`^rgba\\(${ri},${ri},${ri},${Hi}\\)$`),e0=new RegExp(`^rgba\\(${_n},${_n},${_n},${Hi}\\)$`),t0=new RegExp(`^hsl\\(${Hi},${_n},${_n}\\)$`),n0=new RegExp(`^hsla\\(${Hi},${_n},${_n},${Hi}\\)$`),jf={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};Cs(Fi,Ro,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Kf,formatHex:Kf,formatHex8:o0,formatHsl:i0,formatRgb:Gf,toString:Gf});function Kf(){return this.rgb().formatHex()}function o0(){return this.rgb().formatHex8()}function i0(){return Xf(this).formatHsl()}function Gf(){return this.rgb().formatRgb()}function Ro(e){var n,o;return e=(e+"").trim().toLowerCase(),(n=J1.exec(e))?(o=n[1].length,n=parseInt(n[1],16),o===6?qf(n):o===3?new Ft(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):o===8?lr(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):o===4?lr(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=X1.exec(e))?new Ft(n[1],n[2],n[3],1):(n=Z1.exec(e))?new Ft(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=Q1.exec(e))?lr(n[1],n[2],n[3],n[4]):(n=e0.exec(e))?lr(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=t0.exec(e))?Jf(n[1],n[2]/100,n[3]/100,1):(n=n0.exec(e))?Jf(n[1],n[2]/100,n[3]/100,n[4]):jf.hasOwnProperty(e)?qf(jf[e]):e==="transparent"?new Ft(NaN,NaN,NaN,0):null}function qf(e){return new Ft(e>>16&255,e>>8&255,e&255,1)}function lr(e,n,o,i){return i<=0&&(e=n=o=NaN),new Ft(e,n,o,i)}function a0(e){return e instanceof Fi||(e=Ro(e)),e?(e=e.rgb(),new Ft(e.r,e.g,e.b,e.opacity)):new Ft}function Ss(e,n,o,i){return arguments.length===1?a0(e):new Ft(e,n,o,i??1)}function Ft(e,n,o,i){this.r=+e,this.g=+n,this.b=+o,this.opacity=+i}Cs(Ft,Ss,Hf(Fi,{brighter(e){return e=e==null?rr:Math.pow(rr,e),new Ft(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ui:Math.pow(Ui,e),new Ft(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ft(Ao(this.r),Ao(this.g),Ao(this.b),sr(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:Yf,formatHex:Yf,formatHex8:r0,formatRgb:Wf,toString:Wf}));function Yf(){return`#${xo(this.r)}${xo(this.g)}${xo(this.b)}`}function r0(){return`#${xo(this.r)}${xo(this.g)}${xo(this.b)}${xo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Wf(){const e=sr(this.opacity);return`${e===1?"rgb(":"rgba("}${Ao(this.r)}, ${Ao(this.g)}, ${Ao(this.b)}${e===1?")":`, ${e})`}`}function sr(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ao(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function xo(e){return e=Ao(e),(e<16?"0":"")+e.toString(16)}function Jf(e,n,o,i){return i<=0?e=n=o=NaN:o<=0||o>=1?e=n=NaN:n<=0&&(e=NaN),new ln(e,n,o,i)}function Xf(e){if(e instanceof ln)return new ln(e.h,e.s,e.l,e.opacity);if(e instanceof Fi||(e=Ro(e)),!e)return new ln;if(e instanceof ln)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 ln(l,s,c,e.opacity)}function l0(e,n,o,i){return arguments.length===1?Xf(e):new ln(e,n,o,i??1)}function ln(e,n,o,i){this.h=+e,this.s=+n,this.l=+o,this.opacity=+i}Cs(ln,l0,Hf(Fi,{brighter(e){return e=e==null?rr:Math.pow(rr,e),new ln(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ui:Math.pow(Ui,e),new ln(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 Ft(Rs(e>=240?e-240:e+120,a,i),Rs(e,a,i),Rs(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new ln(Zf(this.h),cr(this.s),cr(this.l),sr(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=sr(this.opacity);return`${e===1?"hsl(":"hsla("}${Zf(this.h)}, ${cr(this.s)*100}%, ${cr(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Zf(e){return e=(e||0)%360,e<0?e+360:e}function cr(e){return Math.max(0,Math.min(1,e||0))}function Rs(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 As=e=>()=>e;function s0(e,n){return function(o){return e+o*n}}function c0(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 d0(e){return(e=+e)==1?Qf:function(n,o){return o-n?c0(n,o,e):As(isNaN(n)?o:n)}}function Qf(e,n){var o=n-e;return o?s0(e,o):As(isNaN(e)?n:e)}const dr=(function e(n){var o=d0(n);function i(a,r){var l=o((a=Ss(a)).r,(r=Ss(r)).r),s=o(a.g,r.g),c=o(a.b,r.b),d=Qf(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 u0(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 m0(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function f0(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]=ji(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 p0(e,n){var o=new Date;return e=+e,n=+n,function(i){return o.setTime(e*(1-i)+n*i),o}}function En(e,n){return e=+e,n=+n,function(o){return e*(1-o)+n*o}}function h0(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]=ji(e[a],n[a]):i[a]=n[a];return function(r){for(a in o)i[a]=o[a](r);return i}}var xs=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,$s=new RegExp(xs.source,"g");function y0(e){return function(){return e}}function g0(e){return function(n){return e(n)+""}}function ep(e,n){var o=xs.lastIndex=$s.lastIndex=0,i,a,r,l=-1,s=[],c=[];for(e=e+"",n=n+"";(i=xs.exec(e))&&(a=$s.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:En(i,a)})),o=$s.lastIndex;return o<n.length&&(r=n.slice(o),s[l]?s[l]+=r:s[++l]=r),s.length<2?c[0]?g0(c[0].x):y0(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 ji(e,n){var o=typeof n,i;return n==null||o==="boolean"?As(n):(o==="number"?En:o==="string"?(i=Ro(n))?(n=i,dr):ep:n instanceof Ro?dr:n instanceof Date?p0:m0(n)?u0:Array.isArray(n)?f0:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?h0:En)(e,n)}var tp=180/Math.PI,Ts={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function np(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)*tp,skewX:Math.atan(c)*tp,scaleX:l,scaleY:s}}var ur;function b0(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?Ts:np(n.a,n.b,n.c,n.d,n.e,n.f)}function k0(e){return e==null||(ur||(ur=document.createElementNS("http://www.w3.org/2000/svg","g")),ur.setAttribute("transform",e),!(e=ur.transform.baseVal.consolidate()))?Ts:(e=e.matrix,np(e.a,e.b,e.c,e.d,e.e,e.f))}function op(e,n,o,i){function a(d){return d.length?d.pop()+" ":""}function r(d,u,m,f,p,g){if(d!==m||u!==f){var y=p.push("translate(",null,n,null,o);g.push({i:y-4,x:En(d,m)},{i:y-2,x:En(u,f)})}else(m||f)&&p.push("translate("+m+n+f+o)}function l(d,u,m,f){d!==u?(d-u>180?u+=360:u-d>180&&(d+=360),f.push({i:m.push(a(m)+"rotate(",null,i)-2,x:En(d,u)})):u&&m.push(a(m)+"rotate("+u+i)}function s(d,u,m,f){d!==u?f.push({i:m.push(a(m)+"skewX(",null,i)-2,x:En(d,u)}):u&&m.push(a(m)+"skewX("+u+i)}function c(d,u,m,f,p,g){if(d!==m||u!==f){var y=p.push(a(p)+"scale(",null,",",null,")");g.push({i:y-4,x:En(d,m)},{i:y-2,x:En(u,f)})}else(m!==1||f!==1)&&p.push(a(p)+"scale("+m+","+f+")")}return function(d,u){var m=[],f=[];return d=e(d),u=e(u),r(d.translateX,d.translateY,u.translateX,u.translateY,m,f),l(d.rotate,u.rotate,m,f),s(d.skewX,u.skewX,m,f),c(d.scaleX,d.scaleY,u.scaleX,u.scaleY,m,f),d=u=null,function(p){for(var g=-1,y=f.length,h;++g<y;)m[(h=f[g]).i]=h.x(p);return m.join("")}}}var _0=op(b0,"px, ","px)","deg)"),E0=op(k0,", ",")",")"),N0=1e-12;function ip(e){return((e=Math.exp(e))+1/e)/2}function w0(e){return((e=Math.exp(e))-1/e)/2}function I0(e){return((e=Math.exp(2*e))-1)/(e+1)}const mr=(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],f=l[2],p=u-s,g=m-c,y=p*p+g*g,h,_;if(y<N0)_=Math.log(f/d)/n,h=function(k){return[s+k*p,c+k*g,d*Math.exp(n*k*_)]};else{var N=Math.sqrt(y),b=(f*f-d*d+i*y)/(2*d*o*N),w=(f*f-d*d-i*y)/(2*f*o*N),I=Math.log(Math.sqrt(b*b+1)-b),$=Math.log(Math.sqrt(w*w+1)-w);_=($-I)/n,h=function(k){var C=k*_,x=ip(I),T=d/(o*N)*(x*I0(n*C+I)-w0(I));return[s+T*p,c+T*g,d*x/ip(n*C+I)]}}return h.duration=_*1e3*n/Math.SQRT2,h}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 li=0,Ki=0,Gi=0,ap=1e3,fr,qi,pr=0,$o=0,hr=0,Yi=typeof performance=="object"&&performance.now?performance:Date,rp=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ms(){return $o||(rp(v0),$o=Yi.now()+hr)}function v0(){$o=0}function yr(){this._call=this._time=this._next=null}yr.prototype=lp.prototype={constructor:yr,restart:function(e,n,o){if(typeof e!="function")throw new TypeError("callback is not a function");o=(o==null?Ms():+o)+(n==null?0:+n),!this._next&&qi!==this&&(qi?qi._next=this:fr=this,qi=this),this._call=e,this._time=o,Vs()},stop:function(){this._call&&(this._call=null,this._time=1/0,Vs())}};function lp(e,n,o){var i=new yr;return i.restart(e,n,o),i}function C0(){Ms(),++li;for(var e=fr,n;e;)(n=$o-e._time)>=0&&e._call.call(void 0,n),e=e._next;--li}function sp(){$o=(pr=Yi.now())+hr,li=Ki=0;try{C0()}finally{li=0,R0(),$o=0}}function S0(){var e=Yi.now(),n=e-pr;n>ap&&(hr-=n,pr=e)}function R0(){for(var e,n=fr,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:fr=o);qi=e,Vs(i)}function Vs(e){if(!li){Ki&&(Ki=clearTimeout(Ki));var n=e-$o;n>24?(e<1/0&&(Ki=setTimeout(sp,e-Yi.now()-hr)),Gi&&(Gi=clearInterval(Gi))):(Gi||(pr=Yi.now(),Gi=setInterval(S0,ap)),li=1,rp(sp))}}function cp(e,n,o){var i=new yr;return n=n==null?0:+n,i.restart(a=>{i.stop(),e(a+n)},n,o),i}var A0=tr("start","end","cancel","interrupt"),x0=[],dp=0,up=1,Ls=2,gr=3,mp=4,Bs=5,br=6;function kr(e,n,o,i,a,r){var l=e.__transition;if(!l)e.__transition={};else if(o in l)return;$0(e,o,{name:n,index:i,group:a,on:A0,tween:x0,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:dp})}function Ds(e,n){var o=sn(e,n);if(o.state>dp)throw new Error("too late; already scheduled");return o}function Nn(e,n){var o=sn(e,n);if(o.state>gr)throw new Error("too late; already running");return o}function sn(e,n){var o=e.__transition;if(!o||!(o=o[n]))throw new Error("transition not found");return o}function $0(e,n,o){var i=e.__transition,a;i[n]=o,o.timer=lp(r,0,o.time);function r(d){o.state=up,o.timer.restart(l,o.delay,o.time),o.delay<=d&&l(d-o.delay)}function l(d){var u,m,f,p;if(o.state!==up)return c();for(u in i)if(p=i[u],p.name===o.name){if(p.state===gr)return cp(l);p.state===mp?(p.state=br,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete i[u]):+u<n&&(p.state=br,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete i[u])}if(cp(function(){o.state===gr&&(o.state=mp,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=gr,a=new Array(f=o.tween.length),u=0,m=-1;u<f;++u)(p=o.tween[u].value.call(e,e.__data__,o.index,o.group))&&(a[++m]=p);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=Bs,1),m=-1,f=a.length;++m<f;)a[m].call(e,u);o.state===Bs&&(o.on.call("end",e,e.__data__,o.index,o.group),c())}function c(){o.state=br,o.timer.stop(),delete i[n];for(var d in i)return;delete e.__transition}}function _r(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<Bs,i.state=br,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete o[l]}r&&delete e.__transition}}function T0(e){return this.each(function(){_r(this,e)})}function M0(e,n){var o,i;return function(){var a=Nn(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 V0(e,n,o){var i,a;if(typeof o!="function")throw new Error;return function(){var r=Nn(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 L0(e,n){var o=this._id;if(e+="",arguments.length<2){for(var i=sn(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?M0:V0)(o,e,n))}function Os(e,n,o){var i=e._id;return e.each(function(){var a=Nn(this,i);(a.value||(a.value={}))[n]=o.apply(this,arguments)}),function(a){return sn(a,i).value[n]}}function fp(e,n){var o;return(typeof n=="number"?En:n instanceof Ro?dr:(o=Ro(n))?(n=o,dr):ep)(e,n)}function B0(e){return function(){this.removeAttribute(e)}}function D0(e){return function(){this.removeAttributeNS(e.space,e.local)}}function O0(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 P0(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 z0(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 F0(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 U0(e,n){var o=or(e),i=o==="transform"?E0:fp;return this.attrTween(e,typeof n=="function"?(o.local?F0:z0)(o,i,Os(this,"attr."+e,n)):n==null?(o.local?D0:B0)(o):(o.local?P0:O0)(o,i,n))}function H0(e,n){return function(o){this.setAttribute(e,n.call(this,o))}}function j0(e,n){return function(o){this.setAttributeNS(e.space,e.local,n.call(this,o))}}function K0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&j0(e,r)),o}return a._value=n,a}function G0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&H0(e,r)),o}return a._value=n,a}function q0(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=or(e);return this.tween(o,(i.local?K0:G0)(i,n))}function Y0(e,n){return function(){Ds(this,e).delay=+n.apply(this,arguments)}}function W0(e,n){return n=+n,function(){Ds(this,e).delay=n}}function J0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?Y0:W0)(n,e)):sn(this.node(),n).delay}function X0(e,n){return function(){Nn(this,e).duration=+n.apply(this,arguments)}}function Z0(e,n){return n=+n,function(){Nn(this,e).duration=n}}function Q0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?X0:Z0)(n,e)):sn(this.node(),n).duration}function ew(e,n){if(typeof n!="function")throw new Error;return function(){Nn(this,e).ease=n}}function tw(e){var n=this._id;return arguments.length?this.each(ew(n,e)):sn(this.node(),n).ease}function nw(e,n){return function(){var o=n.apply(this,arguments);if(typeof o!="function")throw new Error;Nn(this,e).ease=o}}function ow(e){if(typeof e!="function")throw new Error;return this.each(nw(this._id,e))}function iw(e){typeof e!="function"&&(e=$f(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 Dn(i,this._parents,this._name,this._id)}function aw(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),f,p=0;p<u;++p)(f=c[p]||d[p])&&(m[p]=f);for(;s<i;++s)l[s]=n[s];return new Dn(l,this._parents,this._name,this._id)}function rw(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 lw(e,n,o){var i,a,r=rw(n)?Ds:Nn;return function(){var l=r(this,e),s=l.on;s!==i&&(a=(i=s).copy()).on(n,o),l.on=a}}function sw(e,n){var o=this._id;return arguments.length<2?sn(this.node(),o).on.on(e):this.each(lw(o,e,n))}function cw(e){return function(){var n=this.parentNode;for(var o in this.__transition)if(+o!==e)return;n&&n.removeChild(this)}}function dw(){return this.on("end.remove",cw(this._id))}function uw(e){var n=this._name,o=this._id;typeof e!="function"&&(e=Ns(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,f=0;f<c;++f)(u=s[f])&&(m=e.call(u,u.__data__,f,s))&&("__data__"in u&&(m.__data__=u.__data__),d[f]=m,kr(d[f],n,o,f,d,sn(u,o)));return new Dn(r,this._parents,n,o)}function mw(e){var n=this._name,o=this._id;typeof e!="function"&&(e=xf(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 f=e.call(u,u.__data__,m,c),p,g=sn(u,o),y=0,h=f.length;y<h;++y)(p=f[y])&&kr(p,n,o,y,f,g);r.push(f),l.push(u)}return new Dn(r,l,n,o)}var fw=Pi.prototype.constructor;function pw(){return new fw(this._groups,this._parents)}function hw(e,n){var o,i,a;return function(){var r=ii(this,e),l=(this.style.removeProperty(e),ii(this,e));return r===l?null:r===o&&l===i?a:a=n(o=r,i=l)}}function pp(e){return function(){this.style.removeProperty(e)}}function yw(e,n,o){var i,a=o+"",r;return function(){var l=ii(this,e);return l===a?null:l===i?r:r=n(i=l,o)}}function gw(e,n,o){var i,a,r;return function(){var l=ii(this,e),s=o(this),c=s+"";return s==null&&(c=s=(this.style.removeProperty(e),ii(this,e))),l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s))}}function bw(e,n){var o,i,a,r="style."+n,l="end."+r,s;return function(){var c=Nn(this,e),d=c.on,u=c.value[r]==null?s||(s=pp(n)):void 0;(d!==o||a!==u)&&(i=(o=d).copy()).on(l,a=u),c.on=i}}function kw(e,n,o){var i=(e+="")=="transform"?_0:fp;return n==null?this.styleTween(e,hw(e,i)).on("end.style."+e,pp(e)):typeof n=="function"?this.styleTween(e,gw(e,i,Os(this,"style."+e,n))).each(bw(this._id,e)):this.styleTween(e,yw(e,i,n),o).on("end.style."+e,null)}function _w(e,n,o){return function(i){this.style.setProperty(e,n.call(this,i),o)}}function Ew(e,n,o){var i,a;function r(){var l=n.apply(this,arguments);return l!==a&&(i=(a=l)&&_w(e,l,o)),i}return r._value=n,r}function Nw(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,Ew(e,n,o??""))}function ww(e){return function(){this.textContent=e}}function Iw(e){return function(){var n=e(this);this.textContent=n??""}}function vw(e){return this.tween("text",typeof e=="function"?Iw(Os(this,"text",e)):ww(e==null?"":e+""))}function Cw(e){return function(n){this.textContent=e.call(this,n)}}function Sw(e){var n,o;function i(){var a=e.apply(this,arguments);return a!==o&&(n=(o=a)&&Cw(a)),n}return i._value=e,i}function Rw(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,Sw(e))}function Aw(){for(var e=this._name,n=this._id,o=hp(),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=sn(c,n);kr(c,e,o,d,l,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Dn(i,this._parents,e,o)}function xw(){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=Nn(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 $w=0;function Dn(e,n,o,i){this._groups=e,this._parents=n,this._name=o,this._id=i}function hp(){return++$w}var On=Pi.prototype;Dn.prototype={constructor:Dn,select:uw,selectAll:mw,selectChild:On.selectChild,selectChildren:On.selectChildren,filter:iw,merge:aw,selection:pw,transition:Aw,call:On.call,nodes:On.nodes,node:On.node,size:On.size,empty:On.empty,each:On.each,on:sw,attr:U0,attrTween:q0,style:kw,styleTween:Nw,text:vw,textTween:Rw,remove:dw,tween:L0,delay:J0,duration:Q0,ease:tw,easeVarying:ow,end:xw,[Symbol.iterator]:On[Symbol.iterator]};function Tw(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Mw={time:null,delay:0,duration:250,ease:Tw};function Vw(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 Lw(e){var n,o;e instanceof Dn?(n=e._id,e=e._name):(n=hp(),(o=Mw).time=Ms(),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])&&kr(c,e,n,d,l,o||Vw(c,n));return new Dn(i,this._parents,e,n)}Pi.prototype.interrupt=T0,Pi.prototype.transition=Lw;const Er=e=>()=>e;function Bw(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 Pn(e,n,o){this.k=e,this.x=n,this.y=o}Pn.prototype={constructor:Pn,scale:function(e){return e===1?this:new Pn(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new Pn(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 si=new Pn(1,0,0);Pn.prototype;function Ps(e){e.stopImmediatePropagation()}function Wi(e){e.preventDefault(),e.stopImmediatePropagation()}function Dw(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ow(){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 yp(){return this.__zoom||si}function Pw(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function zw(){return navigator.maxTouchPoints||"ontouchstart"in this}function Fw(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 Uw(){var e=Dw,n=Ow,o=Fw,i=Pw,a=zw,r=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],s=250,c=mr,d=tr("start","zoom","end"),u,m,f,p=500,g=150,y=0,h=10;function _(E){E.property("__zoom",yp).on("wheel.zoom",C,{passive:!1}).on("mousedown.zoom",x).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",z).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",D).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(E,v,A,S){var R=E.selection?E.selection():E;R.property("__zoom",yp),E!==R?I(E,v,A,S):R.interrupt().each(function(){$(this,arguments).event(S).start().zoom(null,typeof v=="function"?v.apply(this,arguments):v).end()})},_.scaleBy=function(E,v,A,S){_.scaleTo(E,function(){var R=this.__zoom.k,H=typeof v=="function"?v.apply(this,arguments):v;return R*H},A,S)},_.scaleTo=function(E,v,A,S){_.transform(E,function(){var R=n.apply(this,arguments),H=this.__zoom,P=A==null?w(R):typeof A=="function"?A.apply(this,arguments):A,L=H.invert(P),j=typeof v=="function"?v.apply(this,arguments):v;return o(b(N(H,j),P,L),R,l)},A,S)},_.translateBy=function(E,v,A,S){_.transform(E,function(){return o(this.__zoom.translate(typeof v=="function"?v.apply(this,arguments):v,typeof A=="function"?A.apply(this,arguments):A),n.apply(this,arguments),l)},null,S)},_.translateTo=function(E,v,A,S,R){_.transform(E,function(){var H=n.apply(this,arguments),P=this.__zoom,L=S==null?w(H):typeof S=="function"?S.apply(this,arguments):S;return o(si.translate(L[0],L[1]).scale(P.k).translate(typeof v=="function"?-v.apply(this,arguments):-v,typeof A=="function"?-A.apply(this,arguments):-A),H,l)},S,R)};function N(E,v){return v=Math.max(r[0],Math.min(r[1],v)),v===E.k?E:new Pn(v,E.x,E.y)}function b(E,v,A){var S=v[0]-A[0]*E.k,R=v[1]-A[1]*E.k;return S===E.x&&R===E.y?E:new Pn(E.k,S,R)}function w(E){return[(+E[0][0]+ +E[1][0])/2,(+E[0][1]+ +E[1][1])/2]}function I(E,v,A,S){E.on("start.zoom",function(){$(this,arguments).event(S).start()}).on("interrupt.zoom end.zoom",function(){$(this,arguments).event(S).end()}).tween("zoom",function(){var R=this,H=arguments,P=$(R,H).event(S),L=n.apply(R,H),j=A==null?w(L):typeof A=="function"?A.apply(R,H):A,X=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),J=R.__zoom,re=typeof v=="function"?v.apply(R,H):v,me=c(J.invert(j).concat(X/J.k),re.invert(j).concat(X/re.k));return function(se){if(se===1)se=re;else{var Ie=me(se),Oe=X/Ie[2];se=new Pn(Oe,j[0]-Ie[0]*Oe,j[1]-Ie[1]*Oe)}P.zoom(null,se)}})}function $(E,v,A){return!A&&E.__zooming||new k(E,v)}function k(E,v){this.that=E,this.args=v,this.active=0,this.sourceEvent=null,this.extent=n.apply(E,v),this.taps=0}k.prototype={event:function(E){return E&&(this.sourceEvent=E),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(E,v){return this.mouse&&E!=="mouse"&&(this.mouse[1]=v.invert(this.mouse[0])),this.touch0&&E!=="touch"&&(this.touch0[1]=v.invert(this.touch0[0])),this.touch1&&E!=="touch"&&(this.touch1[1]=v.invert(this.touch1[0])),this.that.__zoom=v,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(E){var v=rn(this.that).datum();d.call(E,this.that,new Bw(E,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:d}),v)}};function C(E,...v){if(!e.apply(this,arguments))return;var A=$(this,v).event(E),S=this.__zoom,R=Math.max(r[0],Math.min(r[1],S.k*Math.pow(2,i.apply(this,arguments)))),H=kn(E);if(A.wheel)(A.mouse[0][0]!==H[0]||A.mouse[0][1]!==H[1])&&(A.mouse[1]=S.invert(A.mouse[0]=H)),clearTimeout(A.wheel);else{if(S.k===R)return;A.mouse=[H,S.invert(H)],_r(this),A.start()}Wi(E),A.wheel=setTimeout(P,g),A.zoom("mouse",o(b(N(S,R),A.mouse[0],A.mouse[1]),A.extent,l));function P(){A.wheel=null,A.end()}}function x(E,...v){if(f||!e.apply(this,arguments))return;var A=E.currentTarget,S=$(this,v,!0).event(E),R=rn(E.view).on("mousemove.zoom",j,!0).on("mouseup.zoom",X,!0),H=kn(E,A),P=E.clientX,L=E.clientY;Ff(E.view),Ps(E),S.mouse=[H,this.__zoom.invert(H)],_r(this),S.start();function j(J){if(Wi(J),!S.moved){var re=J.clientX-P,me=J.clientY-L;S.moved=re*re+me*me>y}S.event(J).zoom("mouse",o(b(S.that.__zoom,S.mouse[0]=kn(J,A),S.mouse[1]),S.extent,l))}function X(J){R.on("mousemove.zoom mouseup.zoom",null),Uf(J.view,S.moved),Wi(J),S.event(J).end()}}function T(E,...v){if(e.apply(this,arguments)){var A=this.__zoom,S=kn(E.changedTouches?E.changedTouches[0]:E,this),R=A.invert(S),H=A.k*(E.shiftKey?.5:2),P=o(b(N(A,H),S,R),n.apply(this,v),l);Wi(E),s>0?rn(this).transition().duration(s).call(I,P,S,E):rn(this).call(_.transform,P,S,E)}}function z(E,...v){if(e.apply(this,arguments)){var A=E.touches,S=A.length,R=$(this,v,E.changedTouches.length===S).event(E),H,P,L,j;for(Ps(E),P=0;P<S;++P)L=A[P],j=kn(L,this),j=[j,this.__zoom.invert(j),L.identifier],R.touch0?!R.touch1&&R.touch0[2]!==j[2]&&(R.touch1=j,R.taps=0):(R.touch0=j,H=!0,R.taps=1+!!u);u&&(u=clearTimeout(u)),H&&(R.taps<2&&(m=j[0],u=setTimeout(function(){u=null},p)),_r(this),R.start())}}function V(E,...v){if(this.__zooming){var A=$(this,v).event(E),S=E.changedTouches,R=S.length,H,P,L,j;for(Wi(E),H=0;H<R;++H)P=S[H],L=kn(P,this),A.touch0&&A.touch0[2]===P.identifier?A.touch0[0]=L:A.touch1&&A.touch1[2]===P.identifier&&(A.touch1[0]=L);if(P=A.that.__zoom,A.touch1){var X=A.touch0[0],J=A.touch0[1],re=A.touch1[0],me=A.touch1[1],se=(se=re[0]-X[0])*se+(se=re[1]-X[1])*se,Ie=(Ie=me[0]-J[0])*Ie+(Ie=me[1]-J[1])*Ie;P=N(P,Math.sqrt(se/Ie)),L=[(X[0]+re[0])/2,(X[1]+re[1])/2],j=[(J[0]+me[0])/2,(J[1]+me[1])/2]}else if(A.touch0)L=A.touch0[0],j=A.touch0[1];else return;A.zoom("touch",o(b(P,L,j),A.extent,l))}}function D(E,...v){if(this.__zooming){var A=$(this,v).event(E),S=E.changedTouches,R=S.length,H,P;for(Ps(E),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),H=0;H<R;++H)P=S[H],A.touch0&&A.touch0[2]===P.identifier?delete A.touch0:A.touch1&&A.touch1[2]===P.identifier&&delete A.touch1;if(A.touch1&&!A.touch0&&(A.touch0=A.touch1,delete A.touch1),A.touch0)A.touch0[1]=this.__zoom.invert(A.touch0[0]);else if(A.end(),A.taps===2&&(P=kn(P,this),Math.hypot(m[0]-P[0],m[1]-P[1])<h)){var L=rn(this).on("dblclick.zoom");L&&L.apply(this,arguments)}}}return _.wheelDelta=function(E){return arguments.length?(i=typeof E=="function"?E:Er(+E),_):i},_.filter=function(E){return arguments.length?(e=typeof E=="function"?E:Er(!!E),_):e},_.touchable=function(E){return arguments.length?(a=typeof E=="function"?E:Er(!!E),_):a},_.extent=function(E){return arguments.length?(n=typeof E=="function"?E:Er([[+E[0][0],+E[0][1]],[+E[1][0],+E[1][1]]]),_):n},_.scaleExtent=function(E){return arguments.length?(r[0]=+E[0],r[1]=+E[1],_):[r[0],r[1]]},_.translateExtent=function(E){return arguments.length?(l[0][0]=+E[0][0],l[1][0]=+E[1][0],l[0][1]=+E[0][1],l[1][1]=+E[1][1],_):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},_.constrain=function(E){return arguments.length?(o=E,_):o},_.duration=function(E){return arguments.length?(s=+E,_):s},_.interpolate=function(E){return arguments.length?(c=E,_):c},_.on=function(){var E=d.on.apply(d,arguments);return E===d?_:E},_.clickDistance=function(E){return arguments.length?(y=(E=+E)*E,_):Math.sqrt(y)},_.tapDistance=function(E){return arguments.length?(h=+E,_):h},_}var Be=(e=>(e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom",e))(Be||{}),zs=(e=>(e.Partial="partial",e.Full="full",e))(zs||{}),To=(e=>(e.Bezier="default",e.SimpleBezier="simple-bezier",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e))(To||{}),zn=(e=>(e.Strict="strict",e.Loose="loose",e))(zn||{}),Fs=(e=>(e.Arrow="arrow",e.ArrowClosed="arrowclosed",e))(Fs||{}),Ji=(e=>(e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal",e))(Ji||{}),gp=(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))(gp||{});const Hw=["INPUT","SELECT","TEXTAREA"],jw=typeof document<"u"?document:null;function Us(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 Hw.includes(i==null?void 0:i.nodeName)||a||!!r}function Kw(e){return e.ctrlKey||e.metaKey||e.shiftKey||e.altKey}function bp(e,n,o,i){const a=n.replace("+",`
|
|
34
|
+
);`,_=[];if(n!=null&&n.commentLocale){let b=0,w=0;for(const $ of m){const k=Hl($.col.logicalName,n.commentLocale);k?_.push(`COMMENT ON COLUMN ${c}.${$.col.physicalName} IS '${k}';`):mu($.col.logicalName,n.commentLocale)==="other"?b++:w++}const I=fu(c,n.commentLocale,!1,b,w);I&&_.push(I)}o.tableBlocks.push({table:c,lines:[h,..._]});const N=Xo(r);if(xt(N)){o.tableBlocks.push({table:"",lines:[`-- ⚠ ${c}: 소유자 테이블명이 없어 FK 생략`]});continue}o.fks.push({child:c,parent:N,stmt:`ALTER TABLE ${c} ADD CONSTRAINT fk_${c}_${N} FOREIGN KEY (${d.map(b=>b.name).join(", ")}) REFERENCES ${N} (${d.map(b=>b.name).join(", ")});`})}}function ck(e,n){const o=n.associations.find(i=>{var a;return i.modelId===((a=e.embedded)==null?void 0:a.associationRef)});if(!(!o||!e.embedded))return o.end2.entityRef===e.embedded.embeddableRef?o.end2:o.end1}function dk(e,n,o){var r,l,s;if(e.attrType==="EMBED_PREDEF")return(((l=(r=o==null?void 0:o.embeddableCatalog)==null?void 0:r.find(c=>c.type===e.type))==null?void 0:l.fields)??[]).map(c=>({col:c}));const i=(s=e.embedded)==null?void 0:s.embeddableRef;if(i==null)return[];const a=n.entities.find(c=>c.modelId===i);return a?pu(a,n,o).map(c=>({col:c.col,attr:c.attr})):[]}const Gl="entity-modeler-diagram",ql=1;class Eo extends Error{constructor(n){super(n),this.name="InvalidDiagramJsonError"}}function hu(e,n){return JSON.stringify({format:Gl,version:ql,logical:e,layout:n},null,2)}const Va=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Zo=e=>Array.isArray(e)?e:[];function yu(e){let n;try{n=JSON.parse(e)}catch{throw new Eo("JSON 파싱 실패 — 올바른 JSON이 아닙니다.")}if(!Va(n))throw new Eo("최상위가 객체가 아닙니다.");if(n.format!==Gl)throw new Eo(`형식이 아닙니다(format=${String(n.format)}).`);if(typeof n.version!="number"||n.version>ql)throw new Eo(`지원하지 않는 버전(version=${String(n.version)}).`);const o=n.logical;if(!Va(o)||!Array.isArray(o.entities))throw new Eo("logical.entities 배열이 없습니다.");for(const l of o.entities)if(!Va(l)||typeof l.modelId!="string"||!Array.isArray(l.attributes))throw new Eo("엔티티 골격(modelId·attributes)이 올바르지 않습니다.");const i={modelId:typeof o.modelId=="string"?o.modelId:"imported",packageName:typeof o.packageName=="string"?o.packageName:void 0,entities:o.entities,associations:Zo(o.associations),groups:Zo(o.groups)},a=Va(n.layout)?n.layout:{},r={diagramId:typeof a.diagramId=="string"?a.diagramId:"imported",logicalModelRef:typeof a.logicalModelRef=="string"?a.logicalModelRef:i.modelId,entityLayouts:Zo(a.entityLayouts),associationLayouts:Zo(a.associationLayouts),groupLayouts:Zo(a.groupLayouts),notes:Zo(a.notes)};return{logical:i,layout:r}}const uk=/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;function jt(e){return e.replace(uk,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function je(e){return Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.?0+$/,"")}function gu(e){return`<text ${[`x="${je(e.x)}"`,`y="${je(e.y)}"`,`fill="${jt(e.fill)}"`,`font-size="${je(e.fontSize)}"`,e.fontFamily?`font-family="${jt(e.fontFamily)}"`:"",e.fontWeight!=null?`font-weight="${jt(String(e.fontWeight))}"`:"",e.fontStyle&&e.fontStyle!=="normal"?`font-style="${jt(e.fontStyle)}"`:"",e.anchor&&e.anchor!=="start"?`text-anchor="${e.anchor}"`:"",'dominant-baseline="central"'].filter(Boolean).join(" ")}>${jt(e.text)}</text>`}function mk(e){return`<line x1="${je(e.x1)}" y1="${je(e.y)}" x2="${je(e.x2)}" y2="${je(e.y)}" stroke="${jt(e.stroke)}" stroke-width="${je(e.strokeWidth??1)}" />`}function fk(e){return e==null?{tl:0,tr:0,br:0,bl:0}:typeof e=="number"?{tl:e,tr:e,br:e,bl:e}:e}function pk(e,n,o,i,a){return[`M${je(e+a.tl)},${je(n)}`,`L${je(e+o-a.tr)},${je(n)}`,a.tr?`Q${je(e+o)},${je(n)} ${je(e+o)},${je(n+a.tr)}`:"",`L${je(e+o)},${je(n+i-a.br)}`,a.br?`Q${je(e+o)},${je(n+i)} ${je(e+o-a.br)},${je(n+i)}`:"",`L${je(e+a.bl)},${je(n+i)}`,a.bl?`Q${je(e)},${je(n+i)} ${je(e)},${je(n+i-a.bl)}`:"",`L${je(e)},${je(n+a.tl)}`,a.tl?`Q${je(e)},${je(n)} ${je(e+a.tl)},${je(n)}`:"","Z"].filter(Boolean).join(" ")}function Yl(e){const n=fk(e.radius),o=n.tl||n.tr||n.br||n.bl,i=[`fill="${jt(e.fill)}"`,`stroke="${jt(e.stroke)}"`,`stroke-width="${je(e.strokeWidth??1)}"`,e.strokeDasharray?`stroke-dasharray="${jt(e.strokeDasharray)}"`:"",e.opacity!=null?`opacity="${je(e.opacity)}"`:""].filter(Boolean),r=[o?`<path d="${pk(e.x,e.y,e.w,e.h,n)}" ${i.join(" ")} />`:`<rect x="${je(e.x)}" y="${je(e.y)}" width="${je(e.w)}" height="${je(e.h)}" ${i.join(" ")} />`];for(const l of e.lines??[])r.push(mk(l));for(const l of e.texts)r.push(gu(l));for(const l of e.icons??[])r.push(l);return`<g>${r.join("")}</g>`}function hk(e){const o=[`<path ${[`d="${jt(e.d)}"`,'fill="none"',`stroke="${jt(e.stroke)}"`,`stroke-width="${je(e.strokeWidth)}"`,e.strokeDasharray?`stroke-dasharray="${jt(e.strokeDasharray)}"`:""].filter(Boolean).join(" ")} />`];for(const i of e.markers??[])o.push(i);for(const i of e.labels)o.push(gu(i));return`<g>${o.join("")}</g>`}function bu(e){const{x:n,y:o,w:i,h:a}=e.viewBox,r=[];e.background&&r.push(`<rect x="${je(n)}" y="${je(o)}" width="${je(i)}" height="${je(a)}" fill="${jt(e.background)}" />`);for(const l of e.groups)r.push(Yl(l));for(const l of e.edges)r.push(hk(l));for(const l of e.entities)r.push(Yl(l));for(const l of e.notes)r.push(Yl(l));return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${je(n)} ${je(o)} ${je(i)} ${je(a)}" width="${je(i)}" height="${je(a)}">`+r.join("")+"</svg>"}const xi=63;function Wl(e){if(!e)return null;const n=e.length;return n>xi?n:null}function $i(e){return e.dataType?e.length==null?e.dataType:e.scale==null?`${e.dataType}(${e.length})`:`${e.dataType}(${e.length},${e.scale})`:"(미지정)"}function $t(e){return!e||e.trim()===""}function ku(e,n){const o=e.trim();return o?!(n==="entity"?/^[A-Z][A-Za-z0-9]*$/:/^[a-z][A-Za-z0-9]*$/).test(o):!1}function Qo(e){return e==="ZERO_OR_MORE_INSTANCES"||e==="ONE_OR_MORE_INSTANCES"}function yk(e,n){const o=new Map;for(const m of n){if(m.identifying!==!0||m.end1.entityRef===m.end2.entityRef)continue;const f=o.get(m.end1.entityRef)??[];f.push(m.end2.entityRef),o.set(m.end1.entityRef,f)}const i=0,a=1,r=2,l=new Map,s=[],c=[],d=new Set,u=m=>{l.set(m,a),s.push(m);for(const f of o.get(m)??[]){const p=l.get(f)??i;if(p===i)u(f);else if(p===a){const g=s.slice(s.indexOf(f)),y=[...g].sort().join(" ");d.has(y)||(d.add(y),c.push(g))}}s.pop(),l.set(m,r)};for(const m of e)(l.get(m.modelId)??i)===i&&u(m.modelId);return c}function _u(e){return!at(e.stereotype)}function Eu(e){return e.filter(n=>!at(n.stereotype)&&!n.abstractClass)}function Jl(e){var n;return((n=e.table)==null?void 0:n.physicalName)||e.name||""}function gk(e,n){const o=new Set([e.modelId]);let i=e;for(;;){const a=$t(i.superClass)?void 0:n.get(i.superClass);if(!a||o.has(a.modelId))return i.modelId;o.add(a.modelId),i=a}}function bk(e,n){const o=new Map(n.entities.map(a=>[a.name,a]));return new Set(e.map(a=>gk(a,o))).size===1}function Xl(e,n){const o=new Map;for(const i of e){const a=n(i);if(a==null||a==="")continue;const r=o.get(a);r?r.push(i):o.set(a,[i])}return[...o.values()].filter(i=>i.length>1)}function Zl(e,n){const o=new Map;for(const i of e){const a=n(i);a==null||a===""||o.set(a,(o.get(a)??0)+1)}return e.filter(i=>{const a=n(i);return a!=null&&a!==""&&(o.get(a)??0)>1})}function La(e,n){var p,g,y,h,_,N,b,w,I,$;const o=[],i=new Map(e.entities.map(k=>[k.modelId,k])),a=new Map(e.associations.map(k=>[k.modelId,k])),r=dl(e.associations),l=pl(e),s=l.size===0?e.entities:ld(e),c=sd(e,l);for(const k of Xl(s,C=>C.name))for(const C of k){const x=k.filter(V=>V!==C),T=_u(C)&&x.some(_u),z=x.some(V=>!Rg(C,V,e));!T&&!z||o.push({ruleId:"CHK-NAME-3",severity:"warning",targetKind:"entity",targetRef:C.modelId,params:{name:C.name,reason:T?"entity":"package"}})}for(const k of Xl(Eu(s),Jl))if(new Set(k.map(C=>C.name)).size!==1&&!bk(k,e))for(const C of k)o.push({ruleId:"CHK-NAME-9",severity:"error",targetKind:"entity",targetRef:C.modelId,params:{name:Jl(C)}});const d=s.flatMap(k=>(k.indexes??[]).map(C=>({e:k,ix:C})));for(const k of Zl(d,C=>C.ix.name))o.push({ruleId:"CHK-NAME-10",severity:"error",targetKind:"index",targetRef:k.ix.modelId,contextRef:k.e.modelId,params:{name:k.ix.name}});const u=Eu(s).flatMap(k=>{const C=Jl(k);return k.attributes.filter(x=>x.attrType!=="DIVIDER"&&!x.transient).flatMap(x=>x.dbAttrs.flatMap((T,z)=>{if(At(x,T,z,k,e,n).sharedColumnRef!=null)return[];const V=Go(x,T,z,k,e,n);if($t(V))return[];const D=du(T,C,V);return D?[{e:k,a:x,col:T,claim:D}]:[]}))});for(const k of Xl(u,C=>C.claim.name)){const C=k.filter(x=>x.claim.kind==="derived");if(C.length!==0)for(const x of C){const T=k.find(z=>z!==x);o.push({ruleId:"CHK-NAME-12",severity:"error",targetKind:"column",targetRef:x.col.modelId,contextRef:x.e.modelId,params:{name:x.a.name,seq:x.claim.name,other:`${T.e.name}.${T.a.name}`}})}}for(const k of s){const C=k.attributes.filter(S=>S.attrType!=="DIVIDER");if($t(k.name)?o.push({ruleId:"CHK-NAME-4",severity:"info",targetKind:"entity",targetRef:k.modelId}):ku(k.name,"entity")&&o.push({ruleId:"CHK-NAME-11",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{name:k.name}}),k.stereotype==="JPA_ENTITY"&&!k.abstractClass&&(C.some(S=>S.identifier)||o.push({ruleId:"CHK-JPA-1",severity:"error",targetKind:"entity",targetRef:k.modelId}),$t((p=k.table)==null?void 0:p.physicalName)&&o.push({ruleId:"CHK-JPA-8",severity:"warning",targetKind:"entity",targetRef:k.modelId})),at(k.stereotype))for(const S of C.filter(R=>R.identifier))o.push({ruleId:"CHK-JPA-2",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.identifier&&R.transient))o.push({ruleId:"CHK-JPA-12",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C)if(!S.identifier)for(const R of S.dbAttrs)R.autoIncrement&&o.push({ruleId:"CHK-JPA-13",severity:"error",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:S.name}});const x=C.filter(S=>S.identifier&&!S.transient);if(x.reduce((S,R)=>S+R.dbAttrs.length,0)>=2)for(const S of x)for(const R of S.dbAttrs)R.autoIncrement&&o.push({ruleId:"CHK-JPA-20",severity:"error",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&R.identifier))o.push({ruleId:"CHK-JPA-15",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&R.transient))o.push({ruleId:"CHK-JPA-16",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C.filter(R=>R.naturalId&&!R.notNull&&!R.identifier&&!R.transient))o.push({ruleId:"CHK-JPA-17",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});!k.abstractClass&&C.length===0&&o.push({ruleId:"CHK-DSN-2",severity:"warning",targetKind:"entity",targetRef:k.modelId}),(n==null?void 0:n.largeEntityThreshold)!=null&&C.length>n.largeEntityThreshold&&o.push({ruleId:"CHK-DSN-4",severity:"info",targetKind:"entity",targetRef:k.modelId,params:{count:C.length,threshold:n.largeEntityThreshold}});for(const S of Zl(C,R=>R.name))o.push({ruleId:"CHK-NAME-1",severity:"error",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of C)if($t(S.name)){const R=(S.attrType.startsWith("RELATION")||S.attrType.startsWith("EMBED"))&&!ul(S,k,r);o.push({ruleId:R?"CHK-NAME-7":"CHK-NAME-4",severity:R?"error":"info",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,...R?{params:{attrType:S.attrType}}:{}})}else ku(S.name,"attribute")&&o.push({ruleId:"CHK-NAME-11",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});const T=C.flatMap(S=>S.dbAttrs.map((R,H)=>({attr:S,index:H,col:R,eff:At(S,R,H,k,e,n),name:Go(S,R,H,k,e,n)})).filter(R=>R.eff.sharedColumnRef==null));for(const S of Zl(T,R=>R.name))o.push({ruleId:"CHK-NAME-2",severity:"error",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.name}});for(const S of T){if(!$t(S.name)||S.attr.transient||$t(S.attr.name)&&(S.attr.attrType.startsWith("RELATION")||S.attr.attrType.startsWith("EMBED"))||S.attr.attrType==="EMBED_PREDEF"&&!(n!=null&&n.embeddableCatalog))continue;const R=ba(S.attr,k,e.entities,e.associations,S.index);$t(R==null?void 0:R.physicalName)&&o.push({ruleId:"CHK-NAME-8",severity:"warning",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.attr.name}})}for(const S of T){const R=S.col,H=Wl(R.physicalName);H!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{max:xi,len:H}}),n!=null&&n.reservedWords&&!$t(R.physicalName)&&n.reservedWords.has(R.physicalName.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{name:R.physicalName}}),n!=null&&n.selectableDataTypes&&!$t(R.dataType)&&!n.selectableDataTypes.has(R.dataType)&&o.push({ruleId:"CHK-TYPE-1",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:R.dataType}});const P=S.attr.transient||R.multiValue||S.attr.attrType.startsWith("EMBED")||S.attr.attrType.startsWith("RELATION")?void 0:Tg(S.attr.type,R.dataType,n==null?void 0:n.predefinedCustomTypes);if(P===!1&&o.push({ruleId:"CHK-TYPE-7",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:S.attr.type,dataType:$i(R)}}),S.attr.attrType==="NORMAL"&&!S.attr.transient){const L=S.attr.type===An;if(R.modelId===((g=S.attr.dbAttrs[0])==null?void 0:g.modelId)&&_a(S.attr.type,S.attr.groupCode)&&o.push({ruleId:"CHK-TYPE-9",severity:"warning",targetKind:"attribute",targetRef:S.attr.modelId,contextRef:k.modelId,params:{type:S.attr.type||"(미지정)",groupCode:S.attr.groupCode||"(없음)"}}),L){const j=(R.physicalName??"").trim();j!==""&&!/_code$/.test(j)&&o.push({ruleId:"CHK-TYPE-9",severity:"info",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{physicalName:j}}),!$t(R.dataType)&&R.length!=null&&(R.dataType.toUpperCase()!=="VARCHAR"||R.length<30)&&o.push({ruleId:"CHK-TYPE-9",severity:"info",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:$i(R)}})}}k.stereotype!=="SERIALIZED_TYPE"&&S.attr.attrType==="NORMAL"&&!S.attr.transient&&!S.attr.identifier&&!fo(S.attr,R)&&!$t(R.dataType)&&P!==!1&&Bg(S.attr.type,R.dataType,R.multiValue)&&o.push({ruleId:"CHK-TYPE-8",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:Wo(S.attr.type),boxed:Mg(S.attr.type)??"",dataType:$i(R)}}),P!==!1&&!$t(R.dataType)&&Sg.has(R.dataType)&&!R.length&&(At(S.attr,R,S.index,k,e,n).length||o.push({ruleId:"CHK-TYPE-2",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{dataType:R.dataType}}))}for(const S of T)$t(S.col.dataType)&&(S.attr.transient||S.attr.attrType.startsWith("EMBED")||S.attr.attrType.startsWith("RELATION")||o.push({ruleId:"CHK-TYPE-6",severity:"warning",targetKind:"column",targetRef:S.col.modelId,contextRef:k.modelId,params:{name:S.attr.name}}));if((y=n==null?void 0:n.embeddableCatalog)!=null&&y.length){const S=po(xn(k,e.entities));for(const R of C){if(R.attrType!=="EMBED_PREDEF")continue;const H=n.embeddableCatalog.find(P=>P.type===R.type);H&&R.dbAttrs.forEach((P,L)=>{if(P.sharedColumnRef==null)return;const j=H.fields[L],X=S.get(P.sharedColumnRef);if(!j||!X)return;(X.dataType!==j.dataType||(X.length??null)!==(j.length??null)||(X.scale??null)!==(j.scale??null))&&o.push({ruleId:"CHK-TYPE-3",severity:"warning",targetKind:"column",targetRef:P.modelId,contextRef:k.modelId,params:{targetType:$i(X),metaName:j.name,metaType:$i(j)}})})}}for(const S of C){const R=S.dbAttrs[0];if(!(R!=null&&R.multiValue))continue;S.type===An&&R.dataType==="VARCHAR"||o.push({ruleId:"CHK-TYPE-4",severity:"warning",targetKind:"column",targetRef:R.modelId,contextRef:k.modelId,params:{type:S.type||"",dataType:R.dataType||""}})}for(const S of C){if(S.attrType!=="EMBED_OWN"||!S.embedded)continue;const R=i.get(S.embedded.embeddableRef);if(!R)continue;const H=a.get(S.embedded.associationRef),P=H==null?void 0:H.end1.entityRef===S.embedded.embeddableRef?H.end1:H.end2;if(P&&Qo(P.multiplicity))continue;const L=pn(R).length;S.dbAttrs.length!==L&&o.push({ruleId:"CHK-JPA-21",severity:"warning",targetKind:"attribute",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name,embeddable:R.name,slots:S.dbAttrs.length,declared:L}})}const z=(h=k.table)==null?void 0:h.physicalName,V=Wl(z);V!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{max:xi,len:V}}),n!=null&&n.reservedWords&&!$t(z)&&n.reservedWords.has(z.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"entity",targetRef:k.modelId,params:{name:z}});const D=new Set;for(const S of k.attributes){D.add(S.modelId);for(const R of S.dbAttrs)D.add(R.modelId)}const E=new Set(_i(k,(n==null?void 0:n.superClassCatalog)??[]).map(S=>S.modelId)),v=(((_=n==null?void 0:n.superClassCatalog)==null?void 0:_.length)??0)>0,A=uo(k.attributes);for(const S of k.indexes??[]){const R=Wl(S.name);R!=null&&o.push({ruleId:"CHK-NAME-5",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{max:xi,len:R}}),n!=null&&n.reservedWords&&!$t(S.name)&&n.reservedWords.has(S.name.toUpperCase())&&o.push({ruleId:"CHK-NAME-6",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}});for(const H of S.columns){const P=H.columnRef;if(D.has(P)||E.has(P))continue;const L=mo(P);L&&!v||o.push({ruleId:"CHK-DSN-5",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:L?{name:S.name,field:((N=cl(P))==null?void 0:N.field)??P}:{name:S.name}})}S.columns.length===0&&o.push({ruleId:"CHK-DSN-6",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}}),new Set(S.columns.map(H=>A.canon(H.columnRef))).size!==S.columns.length&&o.push({ruleId:"CHK-DSN-7",severity:"warning",targetKind:"index",targetRef:S.modelId,contextRef:k.modelId,params:{name:S.name}})}}const m=new Map;for(const k of e.entities)for(const C of k.attributes)C.attrType==="EMBED_OWN"&&C.embedded&&m.set(C.embedded.associationRef,C);for(const k of c){if(Qo(k.end1.multiplicity)&&Qo(k.end2.multiplicity)&&o.push({ruleId:"CHK-DSN-1",severity:"info",targetKind:"association",targetRef:k.modelId}),m.has(k.modelId)&&k.identifying&&o.push({ruleId:"CHK-JPA-11",severity:"error",targetKind:"association",targetRef:k.modelId}),!m.has(k.modelId)){const C=!!k.end2.attributeRef&&(((w=(b=k.end2.jpa)==null?void 0:b.cascadeTypes)==null?void 0:w.length)??0)>0,x=!!k.end1.attributeRef&&k.end1.navigable&&((($=(I=k.end1.jpa)==null?void 0:I.cascadeTypes)==null?void 0:$.length)??0)>0;C&&x&&o.push({ruleId:"CHK-JPA-18",severity:"warning",targetKind:"association",targetRef:k.modelId})}if(!m.has(k.modelId)&&k.end1.navigable&&k.end1.attributeRef){const C=i.get(k.end1.entityRef),x=C==null?void 0:C.attributes.some(V=>V.modelId===k.end1.attributeRef),T=i.get(k.end2.entityRef),z=wd(e,k).length>0;x&&T&&z&&(k.end2.attributeRef&&T.attributes.some(D=>D.modelId===k.end2.attributeRef)||o.push({ruleId:"CHK-JPA-19",severity:"error",targetKind:"association",targetRef:k.modelId,params:{child:T.name}}))}for(const C of["end1","end2"]){const x=k[C].jpa;if(!x)continue;const T=x.cascadeTypes??[];T.includes("ALL")&&T.length>1&&o.push({ruleId:"CHK-JPA-5",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),Qo(k[C].multiplicity)&&x.fetchType==="EAGER"&&o.push({ruleId:"CHK-JPA-7",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),x.orphanRemoval&&Qo(k[C==="end1"?"end2":"end1"].multiplicity)&&o.push({ruleId:"CHK-JPA-14",severity:"error",targetKind:"association",targetRef:k.modelId,params:{which:C}}),!Qo(k[C].multiplicity)&&(x.collectionType||x.collectionTable||x.orderColumn)&&o.push({ruleId:"CHK-JPA-9",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}}),x.collectionType==="SET"&&x.orderColumn&&o.push({ruleId:"CHK-JPA-10",severity:"warning",targetKind:"association",targetRef:k.modelId,params:{which:C}})}}const f=new Map(e.entities.map(k=>[k.modelId,k.name||k.modelId]));for(const k of yk(s,c)){const C=[...k,k[0]].map(x=>f.get(x)??x).join(" → ");for(const x of k)o.push({ruleId:"CHK-JPA-4",severity:"warning",targetKind:"entity",targetRef:x,params:{path:C}})}if(n!=null&&n.flagEntitiesWithoutRelations){const k=new Set;for(const x of e.associations)k.add(x.end1.entityRef),k.add(x.end2.entityRef);const C=new Map(e.entities.map(x=>[x.name,x.modelId]));for(const x of e.entities){for(const T of x.attributes)T.embedded&&(k.add(x.modelId),k.add(T.embedded.embeddableRef));if(!$t(x.superClass)){k.add(x.modelId);const T=C.get(x.superClass);T&&k.add(T)}}for(const x of s)k.has(x.modelId)||o.push({ruleId:"CHK-DSN-3",severity:"info",targetKind:"entity",targetRef:x.modelId})}return o}function Ql(e,n){var r,l;if(e.ruleId==="CHK-DSN-7")return kk(e,n);const o=(r=e.params)==null?void 0:r.which;if(o!=="end1"&&o!=="end2"||!e.targetRef)return null;const i=n.associations.find(s=>s.modelId===e.targetRef);if(!i)return null;const a=((l=i[o].jpa)==null?void 0:l.cascadeTypes)??[];return e.ruleId==="CHK-JPA-5"?!a.includes("ALL")||a.length<=1?null:{ruleId:e.ruleId,kind:"setEndCascades",assocRef:i.modelId,which:o,cascades:["ALL"]}:null}function kk(e,n){var s;if(!e.targetRef||!e.contextRef)return null;const o=n.entities.find(c=>c.modelId===e.contextRef),i=(s=o==null?void 0:o.indexes)==null?void 0:s.find(c=>c.modelId===e.targetRef);if(!o||!i)return null;const a=uo(o.attributes),r=new Set,l=i.columns.filter(c=>{const d=a.canon(c.columnRef);return r.has(d)?!1:(r.add(d),!0)});return l.length===i.columns.length?null:{ruleId:e.ruleId,kind:"setIndexColumns",entityRef:o.modelId,indexRef:i.modelId,columns:l}}const _k="CustomMoneyType",Ek="Money";function Nk(e){return!(e.type!==_k||e.attrType!=="NORMAL"||e.identifier||e.dbAttrs.length>1)}function wk(e){const n=e.dbAttrs[0]??{modelId:Fe(),physicalName:"",dataType:""},o={modelId:Fe(),physicalName:"",dataType:""},{customType:i,...a}=e;return{...a,type:Ek,attrType:"EMBED_PREDEF",dbAttrs:[n,o]}}function Ik(e){let n=!1;const o=e.entities.map(i=>{let a=!1;const r=i.attributes.map(l=>Nk(l)?(a=!0,n=!0,wk(l)):l);return a?{...i,attributes:r}:i});return n?{...e,entities:o}:e}function vk(e,n){const o=new Map,i=[],a=new Map;for(const g of e.entities){const y=new Map,h=new Map,_=new Map,N=(b,w,I)=>{if(!b)return;o.get(b)||o.set(b,[{entityId:w,assignedId:b}]),i.push({id:b,entityId:w,sink:I}),I(b)};for(const b of g.attributes){N(b.modelId,g.modelId,w=>y.set(b,w));for(const w of b.dbAttrs)N(w.modelId,g.modelId,I=>h.set(w,I))}for(const b of g.indexes??[])N(b.modelId,g.modelId,w=>_.set(b,w));a.set(g,{attrs:y,cols:h,idx:_})}const r=new Set(o.keys()),l=new Map;for(const g of i){const y=(l.get(g.id)??0)+1;if(l.set(g.id,y),y===1)continue;const h=Ck(g.id,y-1,r);r.add(h),o.get(g.id).push({entityId:g.entityId,assignedId:h}),g.sink(h)}const s=[...o.values()].reduce((g,y)=>g+Math.max(0,y.length-1),0);if(s===0)return{logical:e,layout:n,reissued:0};const c=(g,y)=>{var _;if(!y||!g)return y;const h=o.get(y);return!h||h.length<2?y:((_=h.find(N=>N.entityId===g))==null?void 0:_.assignedId)??y},d=new Map(e.associations.map(g=>[g.modelId,g])),u=(g,y)=>{const h=d.get(g);if(h)return h.end1.entityRef===y?h.end2.entityRef:h.end1.entityRef},m=e.entities.map(g=>{var b;const y=a.get(g),h=g.attributes.map(w=>{const I=y.attrs.get(w),$=w.dbAttrs.map(x=>{const T=y.cols.get(x);return T===x.modelId?x:{...x,modelId:T}});let k=w.derivedFrom;if(k){const x=u(k.associationRef,g.modelId),T=c(x,k.sourceAttributeRef);T!==k.sourceAttributeRef&&(k={...k,sourceAttributeRef:T})}return I!==w.modelId||k!==w.derivedFrom||$.some((x,T)=>x!==w.dbAttrs[T])?{...w,modelId:I,dbAttrs:$,derivedFrom:k}:w}),_=(b=g.indexes)==null?void 0:b.map(w=>{const I=y.idx.get(w),$=w.columns.map(C=>{const x=c(g.modelId,C.columnRef);return x===C.columnRef?C:{...C,columnRef:x}});return I!==w.modelId||$.some((C,x)=>C!==w.columns[x])?{...w,modelId:I,columns:$}:w});return h.some((w,I)=>w!==g.attributes[I])||_&&g.indexes&&_.some((w,I)=>w!==g.indexes[I])?{...g,attributes:h,..._?{indexes:_}:{}}:g}),f=e.associations.map(g=>{const y=c(g.end1.entityRef,g.end1.attributeRef),h=c(g.end2.entityRef,g.end2.attributeRef);return y===g.end1.attributeRef&&h===g.end2.attributeRef?g:{...g,end1:y===g.end1.attributeRef?g.end1:{...g.end1,attributeRef:y},end2:h===g.end2.attributeRef?g.end2:{...g.end2,attributeRef:h}}}),p=n.associationLayouts.map(g=>{const y=d.get(g.associationRef);if(!y)return g;const h=c(y.end1.entityRef,g.sourceColumnRef),_=c(y.end2.entityRef,g.targetColumnRef);return h===g.sourceColumnRef&&_===g.targetColumnRef?g:{...g,sourceColumnRef:h,targetColumnRef:_}});return{logical:{...e,entities:m,associations:f},layout:p.some((g,y)=>g!==n.associationLayouts[y])?{...n,associationLayouts:p}:n,reissued:s}}function Ck(e,n,o){let i=n;for(;;){const a=`dup${i}:${e}`;if(!o.has(a))return a;i++}}const Sk="5.2.55";function Yt(e){return e.reduce((n,o)=>Math.max(n,o.order),-1)+1}function es(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 Nu(e){return!!e.derivedFrom&&e.dbAttrs.length>0}function wu(e){for(const n of e){const o=[...n.attributes].sort((s,c)=>s.order-c.order),i=o.filter(Nu);if(!i.length)continue;const a=o.filter(s=>!Nu(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 ei(e){return JSON.parse(JSON.stringify(e))}function Iu(e,n,o){var C;const i=o.idFactory??Fe,a=o.offset??{x:0,y:0},{logical:r,layout:l}=e,s=new Set(n);if(o.includeRelated){const x=new Set(n);for(const T of r.associations){const z=x.has(T.end1.entityRef),V=x.has(T.end2.entityRef);z!==V&&s.add(z?T.end2.entityRef:T.end1.entityRef)}}const c=r.entities.filter(x=>s.has(x.modelId)),d=new Set(c.map(x=>x.modelId)),u=r.associations.filter(x=>d.has(x.end1.entityRef)&&d.has(x.end2.entityRef)),m=new Set(u.map(x=>x.modelId)),f=new Map,p=x=>{let T=f.get(x);return T||(T=i(),f.set(x,T)),T};for(const x of c){p(x.modelId);for(const T of x.attributes){p(T.modelId);for(const z of T.dbAttrs)p(z.modelId)}for(const T of x.indexes??[])p(T.modelId);for(const T of x.operations??[])p(T.modelId)}for(const x of u)p(x.modelId);const g=x=>f.get(x),y=c.map(x=>{const T=ei(x);T.modelId=g(x.modelId),T.attributes=T.attributes.map(z=>Rk(z,g,m,d));for(const z of T.indexes??[])z.modelId=g(z.modelId),z.columns=z.columns.map(V=>mo(V.columnRef)?V:{...V,columnRef:g(V.columnRef)}).filter(V=>V.columnRef!==void 0);for(const z of T.operations??[])z.modelId=g(z.modelId);return T});wu(y);const h=u.map(x=>{const T=ei(x);return T.modelId=g(x.modelId),T.end1=vu(T.end1,g),T.end2=vu(T.end2,g),T}),_=[];for(const x of r.groups){const T=x.memberEntityRefs.filter(V=>d.has(V));if(T.length===0)continue;const z=ei(x);z.modelId=p(x.modelId),z.memberEntityRefs=T.map(V=>g(V)),_.push(z)}const N=o.collisionSuffix??"_imported",b=new Set(o.existing.entities.map(x=>x.name)),w=new Set(o.existing.entities.map(x=>{var T;return(T=x.table)==null?void 0:T.physicalName}).filter(x=>!!x));for(const x of y)b.has(x.name)&&(x.name=`${x.name}${N}`),(C=x.table)!=null&&C.physicalName&&w.has(x.table.physicalName)&&(x.table.physicalName=`${x.table.physicalName}${N}`);const I=[];for(const x of l.entityLayouts){const T=g(x.entityRef);if(!T)continue;const z=ei(x);z.entityRef=T,z.geo={...z.geo,location:ts(z.geo.location,a)},z.attributeStyles&&(z.attributeStyles=Ba(z.attributeStyles,g)),z.operationStyles&&(z.operationStyles=Ba(z.operationStyles,g)),I.push(z)}const $=[];for(const x of l.associationLayouts){const T=g(x.associationRef);if(!T)continue;const z=ei(x);z.associationRef=T,z.sourceColumnRef=x.sourceColumnRef?g(x.sourceColumnRef):void 0,z.targetColumnRef=x.targetColumnRef?g(x.targetColumnRef):void 0,z.waypoints=z.waypoints.map(V=>ts(V,a)),$.push(z)}const k=[];for(const x of l.groupLayouts){const T=g(x.groupRef);if(!T)continue;const z=ei(x);z.groupRef=T,z.geo={...z.geo,location:ts(z.geo.location,a)},delete z.memberNoteRefs,k.push(z)}return{logical:{entities:y,associations:h,groups:_},layout:{entityLayouts:I,associationLayouts:$,groupLayouts:k},idMap:f}}function ts(e,n){return{x:e.x+n.x,y:e.y+n.y}}function Rk(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 vu(e,n){return{...e,entityRef:n(e.entityRef),attributeRef:e.attributeRef?n(e.attributeRef):void 0}}function Ba(e,n){const o={};for(const[i,a]of Object.entries(e)){const r=n(i);r&&(o[r]=a)}return o}function ns(e){if(!("rev"in e))return e;const{rev:n,...o}=e;return o}function No(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)=>No(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(!No(e[i],n[i]))return!1;return!0}return!1}function wo(e,n,o){const i={},a=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of a)o.has(r)||No(e[r],n[r])||(i[r]=n[r]===void 0?null:n[r]);return Object.keys(i).length?i:null}function Io(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 Ak(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 xk=new Set(["attributes","operations","indexes","rev"]),$k=new Set(["end1","end2","rev"]),Tk=new Set(["memberEntityRefs","rev"]),Cu=new Set(["modelId"]),Mk=new Set(["modelId","columns"]),Vk=new Set([]);function Lk(e,n,o,i){const a=Io(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=wo(s,c,Cu);d&&i.push({kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:s.modelId,patch:d})}const r=Io(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=wo(s,c,Cu);d&&i.push({kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:s.modelId,patch:d})}const l=Io(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(!No(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=wo(s,c,Mk);d&&i.push({kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:s.modelId,patch:d})}}function Bk(e,n,o){const i=Io(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:ns(l)});for(const{cur:l,tgt:s}of i.common){const c=wo(l,s,xk);c&&o.push({kind:"entity.update",casUnit:"logical",containerRef:l.modelId,entityRef:l.modelId,patch:c}),Lk(l.modelId,l,s,o)}const a=Io(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:ns(l)});for(const{cur:l,tgt:s}of a.common){const c=wo(l,s,$k);c&&o.push({kind:"association.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,patch:c});for(const d of["end1","end2"]){const u=wo(l[d]??{},s[d]??{},Vk);u&&o.push({kind:"associationEnd.update",casUnit:"logical",containerRef:l.modelId,associationRef:l.modelId,end:d,patch:u})}}const r=Io(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:ns(l)});for(const{cur:l,tgt:s}of r.common){const c=wo(l,s,Tk);c&&o.push({kind:"group.update",casUnit:"logical",containerRef:l.modelId,groupRef:l.modelId,patch:c});const d=Ak(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 Da(e,n,o,i,a,r,l){const s=Io(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)No(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 Dk(e,n,o){Da(e.entityLayouts??[],n.entityLayouts??[],i=>i.entityRef,"entityLayout.add","entityLayout.remove","entityRef",o),Da(e.associationLayouts??[],n.associationLayouts??[],i=>i.associationRef,"associationLayout.add","associationLayout.remove","associationRef",o),Da(e.groupLayouts??[],n.groupLayouts??[],i=>i.groupRef,"groupLayout.add","groupLayout.remove","groupRef",o),Da(e.notes??[],n.notes??[],i=>i.modelId,"note.add","note.remove","noteRef",o)}function Ok(e,n){const o=[];return Bk(e.logical,n.logical,o),Dk(e.layout,n.layout,o),o}function Pk(e){if(e.groupRef!=null)return"group";if(e.noteRef!=null)return"note";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/noteRef 중 하나 필요).")}const zk={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([]),note:new Set(["geo","style","connections","legacyRaw","modelId"])};class Fk{constructor(n){rt(this,"out",[]);rt(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({...Ti(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({...Ti(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({...Ti(n),field:a,value:void 0,removed:!0});continue}this.out.push({...Ti(n),field:a,value:void 0,removed:!0,oldValue:this.last.get(a)}),this.last.delete(a)}}collectionMember(n,o,i,a){this.fieldFilter!=null&&o!==this.fieldFilter||this.out.push({...Ti(n),field:o,value:i,...a?{removed:!0}:{}})}member(n,o,i){this.collectionMember(n,"memberEntityRefs",o,i)}result(){return this.out}}function Ti(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 en(e,n,o,i){if(o==null||typeof o!="object")return;const a=zk[i];for(const[r,l]of Object.entries(o))a.has(r)||e.set(n,r,l)}function vo(e,n,o){if(!(o==null||typeof o!="object"))for(const[i,a]of Object.entries(o))e.set(n,i,a)}function os(e,n){if(Array.isArray(e))return e.find(o=>o.modelId===n)}function Mn(e,n){var r,l,s,c,d,u,m,f,p,g;const o=Pk(n),i=new Fk(n.field),a=[...e].sort((y,h)=>y.seq-h.seq);for(const y of a)for(const h of y.ops)switch(o){case"entity":if(h.entityRef!==n.entityRef)break;h.kind==="entity.add"?en(i,y,h.value,"entity"):h.kind==="entity.update"?vo(i,y,h.patch):h.kind==="entity.remove"&&i.remove(y);break;case"attribute":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((r=h.value)==null?void 0:r.attributes,n.attributeRef);_&&en(i,y,_,"attribute")}else h.kind==="attribute.add"&&((l=h.value)==null?void 0:l.modelId)===n.attributeRef?en(i,y,h.value,"attribute"):h.kind==="attribute.update"&&h.attributeRef===n.attributeRef?vo(i,y,h.patch):(h.kind==="attribute.remove"&&h.attributeRef===n.attributeRef||h.kind==="entity.remove")&&i.remove(y);break;case"operation":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((s=h.value)==null?void 0:s.operations,n.operationRef);_&&en(i,y,_,"operation")}else h.kind==="operation.add"&&((c=h.value)==null?void 0:c.modelId)===n.operationRef?en(i,y,h.value,"operation"):h.kind==="operation.update"&&h.operationRef===n.operationRef?vo(i,y,h.patch):(h.kind==="operation.remove"&&h.operationRef===n.operationRef||h.kind==="entity.remove")&&i.remove(y);break;case"index":if(h.entityRef!==n.entityRef)break;if(h.kind==="entity.add"){const _=os((d=h.value)==null?void 0:d.indexes,n.indexRef);_&&en(i,y,_,"index")}else h.kind==="index.add"&&((u=h.value)==null?void 0:u.modelId)===n.indexRef?en(i,y,h.value,"index"):h.kind==="index.update"&&h.indexRef===n.indexRef?vo(i,y,h.patch):(h.kind==="index.remove"&&h.indexRef===n.indexRef||h.kind==="entity.remove")&&i.remove(y);break;case"association":if(h.associationRef!==n.associationRef)break;h.kind==="association.add"?en(i,y,h.value,"association"):h.kind==="association.update"?vo(i,y,h.patch):h.kind==="association.remove"&&i.remove(y);break;case"associationEnd":if(h.associationRef!==n.associationRef)break;if(h.kind==="association.add"){const _=(m=h.value)==null?void 0:m[n.end];en(i,y,_,"associationEnd")}else h.kind==="associationEnd.update"&&h.end===n.end?vo(i,y,h.patch):h.kind==="association.remove"&&i.remove(y);break;case"group":if(h.groupRef!==n.groupRef)break;if(h.kind==="group.add"){en(i,y,h.value,"group");const _=(f=h.value)==null?void 0:f.memberEntityRefs;if(Array.isArray(_))for(const N of _)i.member(y,N,!1)}else h.kind==="group.update"?vo(i,y,h.patch):h.kind==="group.remove"?i.remove(y):h.kind==="group.addMember"&&h.entityRef!=null?i.member(y,h.entityRef,!1):h.kind==="group.removeMember"&&h.entityRef!=null&&i.member(y,h.entityRef,!0);break;case"note":if(h.noteRef!==n.noteRef)break;if(h.kind==="note.add"){en(i,y,h.value,"note");const _=(p=h.value)==null?void 0:p.connections;if(Array.isArray(_))for(const N of _){const b=N.targetRef;typeof b=="string"&&i.collectionMember(y,"connections",b,!1)}}else if(h.kind==="note.setMemo"){const _=(g=h.value)==null?void 0:g.memo;_!==void 0&&i.set(y,"memo",_)}else h.kind==="note.remove"?i.remove(y):h.kind==="noteConnection.add"&&typeof h.targetRef=="string"?i.collectionMember(y,"connections",h.targetRef,!1):h.kind==="noteConnection.remove"&&typeof h.targetRef=="string"&&i.collectionMember(y,"connections",h.targetRef,!0);break}return i.result()}const gt={subject:null,existence:null,fieldAudit:!1,note:"레이아웃 축(LWW) — 감사·복원 diff는 논리 축 전용(AA-5: 좌표·크기·스타일은 의도적 범위 밖)"},Oa={subject:null,existence:null,fieldAudit:!1,note:"노트의 기하·스타일 축 — 캔버스에서 가장 자주 바뀌어 편입하면 이력을 덮는다(존재·메모·연결만 편입)"},Uk={"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":gt,"entityLayout.remove":gt,"entityLayout.move":gt,"entityLayout.resize":gt,"entityLayout.setCollapsed":gt,"entityLayout.setLocked":gt,"entityLayout.setStyle":gt,"entityLayout.setAttrStyle":gt,"entityLayout.setOpStyle":gt,"groupLayout.add":gt,"groupLayout.remove":gt,"groupLayout.move":gt,"groupLayout.resize":gt,"groupLayout.setLocked":gt,"groupLayout.setStyle":gt,"groupLayout.addNoteMember":gt,"groupLayout.removeNoteMember":gt,"associationLayout.add":gt,"associationLayout.remove":gt,"associationLayout.setWaypoints":gt,"note.add":{subject:"note",existence:"add",fieldAudit:!0},"note.remove":{subject:"note",existence:"remove",fieldAudit:!0},"note.setMemo":{subject:"note",existence:null,fieldAudit:!0},"note.move":Oa,"note.resize":Oa,"note.setStyle":Oa,"noteConnection.add":{subject:"note",existence:null,fieldAudit:!0},"noteConnection.remove":{subject:"note",existence:null,fieldAudit:!0},"noteConnection.setWaypoints":Oa},Kt=e=>typeof e=="string"?e:void 0,Hk=e=>{var n;return Kt((n=e.value)==null?void 0:n.modelId)};function Su(e){return Kt(e.containerRef)??Kt(e.entityRef)}function is(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=Kt(s.modelId);c&&r.push({subject:{kind:o,ref:c,...i?{entityRef:i}:{}},existence:"add",inline:!0})}return r}function Pa(e){const n=Uk[e.kind];if(!n||!n.subject)return[];const o=e,i=n.existence??void 0;switch(n.subject){case"entity":{const a=Kt(o.entityRef);if(!a)return[];const r={subject:{kind:"entity",ref:a},...i?{existence:i}:{}};return e.kind!=="entity.add"?[r]:[r,...is(o,"attributes","attribute",a),...is(o,"operations","operation",a),...is(o,"indexes","index",a)]}case"attribute":case"operation":case"index":{const a=n.subject,r=Su(o),l={attribute:"attributeRef",operation:"operationRef",index:"indexRef"}[a],s=i==="add"?Hk(o):Kt(o[l]);return s?[{subject:{kind:a,ref:s,...r?{entityRef:r}:{}},...i?{existence:i}:{}}]:[]}case"association":case"associationEnd":{const a=Kt(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=Kt(o.groupRef);return a?[{subject:{kind:"group",ref:a},...i?{existence:i}:{}}]:[]}case"note":{const a=Kt(o.noteRef);return a?[{subject:{kind:"note",ref:a},...i?{existence:i}:{}}]:[]}}}function jk(e){const n=e,o=e.kind;if(o.startsWith("entity.")){const i=Kt(n.entityRef);return i?{kind:"entity",ref:i}:null}if(o.startsWith("attribute.")||o.startsWith("operation.")||o.startsWith("index.")){const i=Su(n);return i?{kind:"entity",ref:i}:null}if(o.startsWith("associationEnd.")||o.startsWith("association.")){const i=Kt(n.associationRef);return i?{kind:"association",ref:i}:null}if(o.startsWith("group.")){const i=Kt(n.groupRef);return i?{kind:"group",ref:i}:null}if(o.startsWith("note.")||o.startsWith("noteConnection.")){const i=Kt(n.noteRef);return i?{kind:"note",ref:i}:null}return null}function Kk(e,n){const o=e;return o.entityRef===n||o.containerRef===n}function Gk(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 Pa(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 za(e,n){return e.map(o=>({...o,subject:n}))}function Ru(e,n){const o=e.filter(s=>s.ops.some(c=>Kk(c,n))),{attributes:i,operations:a,indexes:r}=Gk(o,n),l=[...za(Mn(o,{entityRef:n}),{kind:"entity",ref:n})];for(const s of i)l.push(...za(Mn(o,{entityRef:n,attributeRef:s}),{kind:"attribute",ref:s}));for(const s of a)l.push(...za(Mn(o,{entityRef:n,operationRef:s}),{kind:"operation",ref:s}));for(const s of r)l.push(...za(Mn(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 Fa(e){return`${e.kind}:${e.ref}:${e.end??""}`}function qk(e){const n=new Set;for(const o of e)for(const i of o.ops)for(const a of Pa(i))a.existence==="add"&&n.add(Fa(a.subject));return n}function Yk(e){const n=new Map;for(const o of e)for(const i of o.ops)for(const a of Pa(i)){if(a.existence!=="remove")continue;let r=n.get(o.seq);r||(r=new Map,n.set(o.seq,r)),r.set(Fa(a.subject),a.subject)}return n}function Wk(e){const n=new Set,o=new Set,i=new Set,a=new Set,r={entity:n,association:o,group:i,note:a};for(const l of e)for(const s of l.ops){const c=jk(s);c&&r[c.kind].add(c.ref)}return{entities:n,associations:o,groups:i,notes:a}}function Jk(e){const{entities:n,associations:o,groups:i,notes:a}=Wk(e),r=[];for(const l of n)for(const s of Ru(e,l))r.push({...s,subject:{...s.subject,entityRef:l}});for(const l of o){for(const s of Mn(e,{associationRef:l}))r.push({...s,subject:{kind:"association",ref:l}});for(const s of["end1","end2"])for(const c of Mn(e,{associationRef:l,end:s}))r.push({...c,subject:{kind:"associationEnd",ref:l,end:s}})}for(const l of i)for(const s of Mn(e,{groupRef:l}))r.push({...s,subject:{kind:"group",ref:l}});for(const l of a)for(const s of Mn(e,{noteRef:l}))r.push({...s,subject:{kind:"note",ref:l}});return r}function as(e){const n=Jk(e),o=qk(e),i=Yk(e),a=(c,d)=>{var u;return((u=i.get(c))==null?void 0:u.has(d))===!0},r=new Map;for(const c of n){const d=Fa(c.subject),u=r.get(d);(u===void 0||c.seq<u)&&r.set(d,c.seq)}const l=new Map;for(const c of n){let d=l.get(c.seq);d||(d={meta:c,subjects:new Map},l.set(c.seq,d));const u=Fa(c.subject),m=a(c.seq,u);let f=d.subjects.get(u);if(!f){const p=m?"remove":r.get(u)===c.seq&&o.has(u)?"add":"update";f={subject:c.subject,verb:p,fields:[]},d.subjects.set(u,f)}m&&c.removed||f.fields.push({field:c.field,value:c.value,...c.oldValue!==void 0?{oldValue:c.oldValue}:{},...c.removed?{removed:!0}:{}})}for(const c of e){const d=i.get(c.seq);if(!d)continue;let u=l.get(c.seq);u||(u={meta:c,subjects:new Map},l.set(c.seq,u));for(const[m,f]of d){const p=u.subjects.get(m),g=f.kind==="entity"?{...f,entityRef:f.ref}:f;p?p.verb="remove":u.subjects.set(m,{subject:g,verb:"remove",fields:[]})}}const s=[];for(const[c,d]of l){const u=d.meta;s.push({seq:c,...u.ts!==void 0?{ts:u.ts}:{},...u.origin!==void 0?{origin:u.origin}:{},...u.author!==void 0?{author:u.author}:{},...u.kind!==void 0?{kind:u.kind}:{},...u.restoredFromSeq!==void 0?{restoredFromSeq:u.restoredFromSeq}:{},actions:[...d.subjects.values()]})}return s.sort((c,d)=>d.seq-c.seq)}function Au(e){return`${e.kind}:${e.ref}:${e.end??""}`}function Xk(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 Pa(r)){if(!l.existence||l.inline)continue;const s=l.subject;Zk.has(s.kind)&&!s.entityRef||i.push({seq:a.seq,subject:s,verb:l.existence,fields:[]})}return i}const Zk=new Set(["attribute","operation","index"]);function rs(e,n){const{fromSeq:o}=n,i=as(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 f=Au(m.subject);let p=s.get(f);p||(p={subject:m.subject,evs:[]},s.set(f,p)),p.evs.push(m)};for(const m of l)for(const f of m.actions)c({seq:m.seq,subject:f.subject,verb:f.verb,fields:f.fields});for(const m of Xk(e,o,r)){const f=s.get(Au(m.subject));f!=null&&f.evs.some(p=>p.seq===m.seq)||c(m)}const d=[],u=new Set;for(const m of s.values()){m.evs.sort((p,g)=>p.seq-g.seq);const f=m.evs[m.evs.length-1];m.subject.kind==="entity"&&f.verb==="remove"&&u.add(m.subject.ref)}for(const m of s.values()){const f=m.evs[0].verb==="add",p=m.evs[m.evs.length-1].verb==="remove";if(m.subject.kind!=="entity"&&m.subject.entityRef&&u.has(m.subject.entityRef)||f&&p)continue;const g=new Map;let y=null;for(const _ of m.evs){_.verb==="add"&&y!==null&&y!=="add"&&g.clear(),y=_.verb;for(const N of _.fields){const b=g.get(N.field);b?b.lastValue=N.value:g.set(N.field,{firstOld:N.oldValue,hasOld:N.oldValue!==void 0,lastValue:N.value})}}if(p){d.push({subject:m.subject,verb:"removed",fields:[]});continue}if(f){const _=[];for(const[N,b]of g)_.push({field:N,value:b.lastValue});d.push({subject:m.subject,verb:"added",fields:_});continue}const h=[];for(const[_,N]of g)N.hasOld&&No(N.firstOld,N.lastValue)||h.push({field:_,value:N.lastValue,...N.hasOld?{oldValue:N.firstOld}:{}});h.length!==0&&d.push({subject:m.subject,verb:"modified",fields:h})}return{fromSeq:o,toSeq:r,entries:d}}function xu(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 ls{constructor(n){rt(this,"undoStack",[]);rt(this,"redoStack",[]);rt(this,"savePoint",null);rt(this,"listeners",new Set);rt(this,"commandListeners",new Set);rt(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 zt(e){const n={};for(const[o,i]of Object.entries(e))n[o]=i===void 0?null:i;return n}function $u(e,n){var r,l;const o={logical:structuredClone(e.logical),layout:structuredClone(e.layout)},i=[],a=[];for(const s of n){s.apply(o);const c=((l=(r=s.emitOps)==null?void 0:r.call(s,o))==null?void 0:l.forward)??[];c.length===0&&a.push(s.label),i.push(...c)}return{ops:i,skipped:a}}function Tu(e,n){return e.logical.entities.findIndex(o=>o.modelId===n)}function It(e,n){return e.layout.entityLayouts.findIndex(o=>o.entityRef===n)}function tn(e,n){return e.layout.associationLayouts.find(o=>o.associationRef===n)}function st(e,n){const o=e.logical.entities.find(i=>i.modelId===n);if(!o)throw new Error(`엔티티 없음: ${n}`);return o}function Vn(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 Ua(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=Tu(i,e.modelId);a>=0&&i.logical.entities.splice(a,1);const r=It(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 Mu(e){let n=null;const o=i=>i.end1.entityRef===e||i.end2.entityRef===e;return{label:"엔티티 삭제",apply(i){const a=Tu(i,e);if(a<0)throw new Error(`엔티티 없음: ${e}`);const r=It(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(f=>f.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 Ha(e,n){const o={};return{label:"엔티티 수정",apply(i){const a=st(i,e);for(const r of Object.keys(n))o[r]=a[r];Object.assign(a,n)},invert(i){Object.assign(st(i,e),o)},emitOps(){return{forward:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:zt(n)}],invert:[{kind:"entity.update",casUnit:"logical",containerRef:e,entityRef:e,patch:zt(o)}]}}}}function Vu(e,n){let o="";return{label:`엔티티 이름 변경: ${n}`,apply(i){const a=st(i,e);o=a.name,a.name=n},invert(i){st(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 ti(e,n){let o=null;return{label:"엔티티 이동",apply(i){const a=It(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=It(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 Lu(e,n){let o=null;return{label:"엔티티 크기 변경",apply(i){const a=It(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=It(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 Mi(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 Bu(e,n){let o;return{label:"엔티티 색상 변경",apply(i){const a=It(i,e);if(a<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const r=i.layout.entityLayouts[a];o=r.style,r.style=Mi(r.style,n)},invert(i){const a=It(i,e);a>=0&&(i.layout.entityLayouts[a].style=o)},emitOps(i){const a=It(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 Du(e,n){let o;return{label:n?"엔티티 접기":"엔티티 펼치기",apply(i){const a=It(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=It(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 Ou(e,n){let o;return{label:n?"엔티티 잠금":"엔티티 잠금 해제",apply(i){const a=It(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=It(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 ss(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 ja(e,n,o){let i;return{label:"속성 색상 변경",apply(a){const r=It(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.attributeStyles;const s={...l.attributeStyles},c=Mi(s[n],o);c?s[n]=c:delete s[n],l.attributeStyles=Object.keys(s).length?s:void 0},invert(a){const r=It(a,e);r>=0&&(a.layout.entityLayouts[r].attributeStyles=i)},emitOps(a){const r=It(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 Ka(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 Pu(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:zt(n)}],invert:[{kind:"group.update",casUnit:"logical",containerRef:e,groupRef:e,patch:zt(o)}]}}}}function zu(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 Fu(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 Ga(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 Uu(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 Hu(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 ju(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=Mi(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 Ku(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 Wt(e,n){return{label:`속성 추가: ${n.name}`,apply(o){st(o,e).attributes.push(n)},invert(o){const i=st(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 nn(e,n,o){const i={},a=r=>{const l=st(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:zt(o)}],invert:[{kind:"attribute.update",casUnit:"logical",containerRef:e,entityRef:e,attributeRef:n,patch:zt(i)}]}}}}function Gu(e,n){let o=null;return{label:"속성 삭제",apply(i){const a=st(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&&st(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 qu(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 cs(e,n,o){let i=null;return{label:"속성 재정렬",apply(a){const r=st(a,e);i=r.attributes.map(s=>({...s}));const l=es([...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&&st(a,e).attributes.splice(0,1/0,...i)},emitOps(a){const r=st(a,e).attributes;return qu("attribute.update","attributeRef",e,r,i??[])}}}function Yu(e,n){let o=!1;return{label:`메서드 추가: ${n.name}`,apply(i){const a=st(i,e);a.operations||(a.operations=[],o=!0),a.operations.push(n)},invert(i){var l;const a=st(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 Wu(e,n,o){const i={},a=r=>{var s;const l=(s=st(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:zt(o)}],invert:[{kind:"operation.update",casUnit:"logical",containerRef:e,entityRef:e,operationRef:n,patch:zt(i)}]}}}}function Ju(e,n){let o=null;return{label:"메서드 삭제",apply(i){var s;const a=st(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=st(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 Xu(e,n,o){let i=null;return{label:"메서드 재정렬",apply(a){const r=st(a,e),l=r.operations??[];i=l.map(c=>({...c}));const s=es([...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=st(a,e);r.operations&&r.operations.splice(0,1/0,...i)},emitOps(a){const r=st(a,e).operations??[];return qu("operation.update","operationRef",e,r,i??[])}}}function Zu(e,n,o){let i;return{label:"메서드 색상 변경",apply(a){const r=It(a,e);if(r<0)throw new Error(`엔티티 레이아웃 없음: ${e}`);const l=a.layout.entityLayouts[r];i=l.operationStyles;const s={...l.operationStyles},c=Mi(s[n],o);c?s[n]=c:delete s[n],l.operationStyles=Object.keys(s).length?s:void 0},invert(a){const r=It(a,e);r>=0&&(a.layout.entityLayouts[r].operationStyles=i)},emitOps(a){const r=It(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 qa(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 Qu(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 Ya(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:zt(n)}],invert:[{kind:"association.update",casUnit:"logical",containerRef:e,associationRef:e,patch:zt(o)}]}}}}function on(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:zt(o)}],invert:[{kind:"associationEnd.update",casUnit:"logical",containerRef:e,associationRef:e,end:n,patch:zt(i)}]}}}}function em(e,n){return{label:"인덱스 추가",apply(o){const i=st(o,e);(i.indexes??(i.indexes=[])).push(n)},invert(o){var r;const i=st(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 Wa(e,n,o){const i={},a=r=>{var s;const l=(s=st(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:zt(o)}],invert:[{kind:"index.update",casUnit:"logical",containerRef:e,entityRef:e,indexRef:n,patch:zt(i)}]}}}}function tm(e,n){let o=null;return{label:"인덱스 삭제",apply(i){var l;const a=st(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&&st(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 yn=(e,n)=>({kind:"associationLayout.setWaypoints",casUnit:"layout",associationRef:e,value:{waypoints:n}}),Vi=(e,n)=>{var o;return((o=tn(e,n))==null?void 0:o.waypoints.map(i=>({...i})))??[]};function nm(e,n,o){let i=null;return{label:"waypoint 이동",coalesceKey:`waypoint:${e}`,apply(a){const r=tn(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=tn(a,e);r&&i&&r.waypoints.splice(n,1,i)},emitOps(a){const r=Vi(a,e),l=r.map((s,c)=>c===n&&i?{...i}:s);return{forward:[yn(e,r)],invert:[yn(e,l)]}}}}function om(e,n){let o=null;return{label:"waypoint 제거",apply(i){const a=tn(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=tn(i,e);a&&o&&a.waypoints.splice(n,0,o)},emitOps(i){const a=Vi(i,e),r=a.slice();return o&&r.splice(n,0,{...o}),{forward:[yn(e,a)],invert:[yn(e,r)]}}}}function im(e,n,o){let i=null;return{label:"waypoint 평행이동",apply(a){const r=tn(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=tn(a,e);r&&i&&(r.waypoints=i)},emitOps(a){return{forward:[yn(e,Vi(a,e))],invert:[yn(e,i??[])]}}}}function am(e){let n=null;return{label:"꺾은선 풀기",apply(o){const i=tn(o,e);if(!i)throw new Error(`관계 레이아웃 없음: ${e}`);n=i.waypoints.map(a=>({...a})),i.waypoints=[]},invert(o){const i=tn(o,e);i&&n&&(i.waypoints=n)},emitOps(o){return{forward:[yn(e,Vi(o,e))],invert:[yn(e,n??[])]}}}}function rm(e,n,o){return{label:"waypoint 추가",apply(i){const a=tn(i,e);if(!a)throw new Error(`관계 레이아웃 없음: ${e}`);a.waypoints.splice(n,0,{...o})},invert(i){const a=tn(i,e);a==null||a.waypoints.splice(n,1)},emitOps(i){const a=Vi(i,e),r=a.slice();return r.splice(n,1),{forward:[yn(e,a)],invert:[yn(e,r)]}}}}function lm(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 sm(e){let n=null,o=null;return{label:"노트 삭제",apply(i){var r;const a=i.layout.notes.findIndex(l=>l.modelId===e);if(a<0)throw new Error(`노트 없음: ${e}`);n={item:i.layout.notes[a],index:a},i.layout.notes.splice(a,1);for(const l of i.layout.groupLayouts){const s=((r=l.memberNoteRefs)==null?void 0:r.indexOf(e))??-1;if(!(s<0)){l.memberNoteRefs.splice(s,1),o={groupRef:l.groupRef,index:s};break}}},invert(i){if(n&&i.layout.notes.splice(n.index,0,n.item),!o)return;const a=i.layout.groupLayouts.find(r=>r.groupRef===o.groupRef);a&&(a.memberNoteRefs||(a.memberNoteRefs=[]),a.memberNoteRefs.splice(o.index,0,e))},emitOps(){if(!n)return{forward:[],invert:[]};const i=[],a=[];return o&&(i.push({kind:"groupLayout.removeNoteMember",casUnit:"layout",groupRef:o.groupRef,noteRef:e,incidental:!0}),a.push({kind:"groupLayout.addNoteMember",casUnit:"layout",groupRef:o.groupRef,noteRef:e,incidental:!0})),i.push({kind:"note.remove",casUnit:"layout",noteRef:e}),a.push({kind:"note.add",casUnit:"layout",noteRef:e,value:n.item}),{forward:i,invert:a.reverse()}}}}function Li(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 cm(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 dm(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 um(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=Mi(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 mm(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 fm(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 Zn=(e,n,o)=>({kind:"noteConnection.setWaypoints",casUnit:"layout",noteRef:e,targetRef:n,value:{waypoints:o}}),Ja=(e,n,o)=>{var i;return((i=Vn(e,n,o))==null?void 0:i.waypoints.map(a=>({...a})))??[]};function pm(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 hm(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 ym(e,n,o,i){let a=null;return{label:"waypoint 이동",coalesceKey:`noteConnWaypoint:${e}:${n}`,apply(r){const l=Vn(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=Vn(r,e,n);l&&a&&l.waypoints.splice(o,1,a)},emitOps(r){const l=Ja(r,e,n),s=l.map((c,d)=>d===o&&a?{...a}:c);return{forward:[Zn(e,n,l)],invert:[Zn(e,n,s)]}}}}function gm(e,n,o,i){return{label:"waypoint 추가",apply(a){const r=Vn(a,e,n);if(!r)throw new Error(`노트 연결 없음: ${e}→${n}`);r.waypoints.splice(o,0,{...i})},invert(a){const r=Vn(a,e,n);r==null||r.waypoints.splice(o,1)},emitOps(a){const r=Ja(a,e,n),l=r.slice();return l.splice(o,1),{forward:[Zn(e,n,r)],invert:[Zn(e,n,l)]}}}}function bm(e,n,o){let i=null;return{label:"waypoint 제거",apply(a){const r=Vn(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=Vn(a,e,n);r&&i&&r.waypoints.splice(o,0,i)},emitOps(a){const r=Ja(a,e,n),l=r.slice();return i&&l.splice(o,0,{...i}),{forward:[Zn(e,n,r)],invert:[Zn(e,n,l)]}}}}function km(e,n){let o=null;return{label:"꺾은선 풀기",apply(i){const a=Vn(i,e,n);if(!a)throw new Error(`노트 연결 없음: ${e}→${n}`);o=a.waypoints.map(r=>({...r})),a.waypoints=[]},invert(i){const a=Vn(i,e,n);a&&o&&(a.waypoints=o)},emitOps(i){return{forward:[Zn(e,n,Ja(i,e,n))],invert:[Zn(e,n,o??[])]}}}}function it(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 Qk=Object.freeze(Object.defineProperty({__proto__:null,addAssociation:qa,addAttribute:Wt,addEntity:Ua,addEntityToGroup:Fu,addGroup:Ka,addIndex:em,addNote:lm,addNoteConnection:pm,addNoteConnectionWaypoint:gm,addNoteToGroup:mm,addOperation:Yu,addWaypoint:rm,clearNoteConnectionWaypoints:km,clearWaypoints:am,composite:it,moveEntity:ti,moveGroup:Uu,moveNote:Li,moveNoteConnectionWaypoint:ym,moveWaypoint:nm,removeAssociation:Qu,removeAttribute:Gu,removeEntity:Mu,removeEntityFromGroup:Ga,removeGroup:zu,removeIndex:tm,removeNote:sm,removeNoteConnection:hm,removeNoteConnectionWaypoint:bm,removeNoteFromGroup:fm,removeOperation:Ju,removeWaypoint:om,renameEntity:Vu,reorderAttributes:cs,reorderOperations:Xu,resizeEntity:Lu,resizeGroup:Hu,resizeNote:cm,setAllEntitiesCollapsed:ss,setAttributeSwatch:ja,setEntityCollapsed:Du,setEntityLocked:Ou,setEntitySwatch:Bu,setGroupLocked:Ku,setGroupSwatch:ju,setNoteMemo:dm,setNoteSwatch:um,setOperationSwatch:Zu,translateWaypoints:im,updateAssociation:Ya,updateAssociationEnd:on,updateAttribute:nn,updateEntity:Ha,updateGroup:Pu,updateIndex:Wa,updateOperation:Wu},Symbol.toStringTag,{value:"Module"}));class _m{constructor(){rt(this,"revs",new Map);rt(this,"layoutVersion",0);rt(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 e_=[400,1200];function t_(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 n_(e){const n=t_(e);return n==null||n===408||n===429?!0:n<400||n>=500}const o_=e=>new Promise(n=>setTimeout(n,e));class Em{constructor(n){rt(this,"cache",new _m);rt(this,"newClientOpId");rt(this,"debounceMs");rt(this,"retryDelaysMs");rt(this,"emissions",new WeakMap);rt(this,"open",null);rt(this,"debounceHandle",null);rt(this,"queue",[]);rt(this,"sending",!1);rt(this,"_frozen",!1);rt(this,"stack",null);rt(this,"settledWaiters",[]);this.opts=n,this.newClientOpId=n.newClientOpId??Fe,this.debounceMs=n.debounceMs??300,this.retryDelaysMs=n.retryDelaysMs??e_}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||!n_(l)){this.sending=!1,console.error("[op-sync] 전송 실패 확정 → 하드 프리즈(kind:missing)"),this.freeze({kind:"missing"});return}await o_(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 Nm=["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"],wm=["NORMAL","RELATION_OWN","RELATION_REF","EMBED_OWN","EMBED_REF","EMBED_PREDEF","DIVIDER"];function Im(e,n,o){var c;if(!n.length||!((c=e.indexes)!=null&&c.length))return[];const i=new Set(n),a=new Set,r=new Map,l=d=>{const u=o==null?void 0:o.get(d);u===void 0?a.add(d):u!==d&&r.set(d,u)};for(const d of e.attributes)if(i.has(d.modelId)){l(d.modelId);for(const u of d.dbAttrs)l(u.modelId)}if(!a.size&&!r.size)return[];const s=[];for(const d of e.indexes){let u=!1;const m=[];for(const f of d.columns){if(a.has(f.columnRef)){u=!0;continue}const p=r.get(f.columnRef);p===void 0?m.push(f):(m.push({...f,columnRef:p}),u=!0)}u&&s.push({indexRef:d.modelId,columns:m})}return s}function i_(e){return pn(e).length}function ds(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 a_(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=Go(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 vm(e,n,o=Fe){const i=e.entities.find(c=>c.modelId===n);if(!i)return[];const a=i_(i);if(a===0)return[];const r=ds(e,n),l=pn(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;a_(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 Cm(e,n,o){var f;const i=e.entities.find(p=>p.modelId===n);if(!i)return[];const a=i.attributes;if(o.length!==a.length)return[];const r=new Map(a.map(p=>[p.modelId,p])),l=[];for(const p of o){const g=r.get(p);if(!g)return[];l.push(g)}const s=a.flatMap(p=>p.dbAttrs).map(p=>p.modelId),c=l.flatMap(p=>p.dbAttrs).map(p=>p.modelId);if(s.length!==c.length)return[];if(s.every((p,g)=>p===c[g]))return[];const d=new Map(s.map((p,g)=>[p,g])),u=ds(e,n),m=[];for(const p of e.entities)for(const g of p.attributes){if(g.attrType!=="EMBED_OWN"||((f=g.embedded)==null?void 0:f.embeddableRef)!==n||u.has(g.embedded.associationRef)||g.dbAttrs.length!==s.length)continue;const y=c.map(_=>g.dbAttrs[d.get(_)]),h=y.reduce((_,N,b)=>N===g.dbAttrs[b]?_:_+1,0);h&&m.push({entityId:p.modelId,attributeId:g.modelId,dbAttrs:y,moved:h})}return m}function Sm(e,n,o){const i=e.entities.find(l=>l.modelId===n);if(!i)return[];const a=new Set(o),r=i.attributes.filter(l=>!a.has(l.modelId));return r.length===i.attributes.length?[]:r_(e,n,{...i,attributes:r})}function r_(e,n,o){var l;const i=[],a=new Set;let r=new Map([[n,o]]);for(;r.size;){const s=new Map;for(const[c,d]of r){const u=e.entities.find(h=>h.modelId===c);if(!u)continue;const m=pn(u).map(h=>h.col),f=m.map(h=>h.modelId),p=new Set(pn(d).map(h=>h.col.modelId)),g=new Set;if(f.forEach((h,_)=>{p.has(h)&&g.add(_)}),g.size===f.length)continue;const y=ds(e,c);for(const h of e.entities)for(const _ of h.attributes){if(_.attrType!=="EMBED_OWN"||((l=_.embedded)==null?void 0:l.embeddableRef)!==c||y.has(_.embedded.associationRef)||_.dbAttrs.length!==f.length)continue;const N=`${h.modelId}\0${_.modelId}`;if(a.has(N))continue;const b=_.dbAttrs.filter((k,C)=>g.has(C)),w=_.dbAttrs.filter((k,C)=>!g.has(C));if(_.dbAttrs.some((k,C)=>{if(g.has(C))return!1;const x=m[C],T=!!k.physicalName&&k.physicalName!==((x==null?void 0:x.physicalName)??""),z=k.sharedColumnRef!=null&&k.sharedColumnRef!==(x==null?void 0:x.sharedColumnRef);return T||z}))continue;a.add(N),i.push({entityId:h.modelId,attributeId:_.modelId,dbAttrs:b,dropped:w});const $=s.get(h.modelId)??new Map;$.set(_.modelId,b),s.set(h.modelId,$)}}r=new Map([...s].flatMap(([c,d])=>{const u=e.entities.find(f=>f.modelId===c);if(!u)return[];const m={...u,attributes:u.attributes.map(f=>d.has(f.modelId)?{...f,dbAttrs:d.get(f.modelId)}:f)};return[[c,m]]}))}return i}function Rm(e,n,o,i=[]){var d;if(n===o)return[n];const a=new Map,r=(u,m)=>{const f=a.get(u)??[];f.push(m),a.set(u,f)};for(const u of e)for(const m of u.attributes){const f=m.attrType==="EMBED_OWN"?(d=m.embedded)==null?void 0:d.embeddableRef:void 0;f!=null&&r(u.modelId,f)}for(const u of i)r(u.ownerId,u.embeddableRef);const l=new Map,s=new Set([o]),c=[o];for(;c.length;){const u=c.shift();for(const m of a.get(u)??[]){if(m===n){const f=[u];for(let p=u;l.has(p);)p=l.get(p),f.push(p);return[n,...f.reverse()]}s.has(m)||(s.add(m),l.set(m,u),c.push(m))}}return null}function gn(e,n,o){const i=new Set(o.map(r=>`${r.entityId}\0${r.attributeId}`)),a=[];for(const r of n){const l=`${e}\0${r}`;i.has(l)||(i.add(l),a.push(r),o.push({entityId:e,attributeId:r}))}return a.map(r=>Gu(e,r))}function Jt(e,n,o){if(!n.length)return[];const i=new Map;for(const{entityId:r,attributeId:l}of n){const s=i.get(r)??[];s.push(l),i.set(r,s)}const a=[];for(const[r,l]of i){const s=e.entities.find(c=>c.modelId===r);if(s)for(const c of Im(s,l,o))a.push(Wa(r,c.indexRef,{columns:c.columns}))}return a}function Xa(e,n,o,i){var c;const a=[];a.push(...gn(n,o.remove,i));for(const d of o.update)a.push(nn(n,d.attributeId,d.patch));for(const d of o.add)a.push(Wt(n,d));const r=new Set(o.remove),l=[...(((c=e.entities.find(d=>d.modelId===n))==null?void 0:c.attributes)??[]).filter(d=>!r.has(d.modelId)),...o.add],s=new Set(l.map(d=>d.modelId));for(const d of e.associations){if(d.end2.entityRef!==n)continue;const u=d.end2.attributeRef;if(u&&s.has(u))continue;const f=l.filter(p=>{var g;return((g=p.derivedFrom)==null?void 0:g.associationRef)===d.modelId&&p.dbAttrs.length>0}).sort((p,g)=>p.order-g.order)[0];f&&a.push(on(d.modelId,"end2",{attributeRef:f.modelId}))}return a}function Ln(e,n,o){return{...e,entities:e.entities.map(i=>i.modelId===n?{...i,attributes:o(i.attributes)}:i)}}function Bi(e,n,o){return[...Am(e,n,o),...$m(e,n)]}function Am(e,n,o){const i=[];for(const[a,r]of wl(e,n,Fe))i.push(...Xa(e,a,r,o));return i}function l_(e,n,o,i){const a=e.entities.find(l=>l.modelId===n);if(!a)return[];const r=es([...a.attributes].sort((l,s)=>l.order-s.order),o,i).map(l=>l.modelId);return Cm(e,n,r).map(l=>nn(l.entityId,l.attributeId,{dbAttrs:l.dbAttrs}))}function Di(e,n,o){return xm(e,n,o).commands}function xm(e,n,o){const i=Sm(e,n,o),a=i.map(l=>nn(l.entityId,l.attributeId,{dbAttrs:l.dbAttrs})),r=i.reduce((l,s)=>Ln(l,s.entityId,c=>c.map(d=>d.modelId===s.attributeId?{...d,dbAttrs:s.dbAttrs}:d)),e);return{commands:a,projected:r}}function $m(e,n){return vm(e,n,Fe).map(o=>nn(o.entityId,o.attributeId,{dbAttrs:o.dbAttrs}))}function s_(e,n,o){const i=new Set(o.remove);return Ln(e,n,a=>[...a.filter(r=>!i.has(r.modelId)).map(r=>{const l=o.update.find(s=>s.attributeId===r.modelId);return l?{...r,...l.patch}:r}),...o.add])}function Za(e,n,o){const i=[];for(const{entityId:a,plan:r}of Cd(e,n,Fe))i.push(...Xa(e,a,r,o));return i}function Tm(e,n,o=new Set){var r,l,s,c;if(!mn(n))return[];const i=[];for(const d of e.attributes){if(o.has(d.modelId))continue;const u={},m=(r=d.dbAttrs.find(f=>fn(f.logicalName)))==null?void 0:r.logicalName;m&&!fn(d.fieldLogicalName)&&(u.fieldLogicalName=m),d.dbAttrs.length>0&&(u.dbAttrs=[]),d.notNull&&(u.notNull=!1),Object.keys(u).length>0&&i.push(nn(e.modelId,d.modelId,u))}const a={};return fn((l=e.table)==null?void 0:l.logicalName)&&!fn(e.classLogicalName)&&(a.classLogicalName=e.table.logicalName),(s=e.table)!=null&&s.physicalName&&(a.table=null),(c=e.indexes)!=null&&c.length&&(a.indexes=[]),e.schema&&(a.schema=null),e.jpaAttrs&&(a.jpaAttrs=null),Object.keys(a).length>0&&i.push(Ha(e.modelId,a)),i}function Mm(e){return pn(e).map(n=>({...n.col,modelId:Fe()}))}function Vm(e,n){var m;const o=e.entities.find(f=>f.modelId===n);if(!o)return[];const i=[];let a;if(!o.attributes.some(f=>f.identifier)){const f=Yt(o.attributes),p=new Set(o.attributes.map(y=>y.name));let g="id";for(let y=2;p.has(g);y++)g=`id${y}`;a={modelId:Fe(),name:g,type:"Long",attrType:"NORMAL",identifier:!0,notNull:!0,order:f,dbAttrs:[{modelId:Fe(),physicalName:g.toLowerCase(),dataType:"BIGINT"}]},i.push(Wt(n,a))}const r=[];for(const f of e.entities)for(const p of f.attributes){if(((m=p.embedded)==null?void 0:m.embeddableRef)!==n)continue;const g=e.associations.find(N=>N.modelId===p.embedded.associationRef);if(!g)continue;const y=g.end1.entityRef===f.modelId,h=y?g.end1:g.end2,_=y?g.end2:g.end1;r.push({ownerId:f.modelId,dispId:p.modelId,assocId:g.modelId,end1:{entityRef:f.modelId,multiplicity:h.multiplicity,navigable:h.navigable,composition:!1},end2:{entityRef:n,multiplicity:_.multiplicity,navigable:_.navigable,composition:!1}})}const l={...e,entities:e.entities.map(f=>{if(f.modelId===n)return a?{...f,stereotype:"JPA_ENTITY",attributes:[...f.attributes,a]}:{...f,stereotype:"JPA_ENTITY"};const p=new Set(r.filter(g=>g.ownerId===f.modelId).map(g=>g.dispId));return p.size?{...f,attributes:f.attributes.filter(g=>!p.has(g.modelId))}:f}),associations:e.associations.map(f=>{const p=r.find(g=>g.assocId===f.modelId);return p?{...f,end1:p.end1,end2:p.end2}:f})},s=vi(l,n,Fe);for(const f of r){const p=s.add.find(g=>{var y;return((y=g.derivedFrom)==null?void 0:y.associationRef)===f.assocId});p&&(f.end2.attributeRef=p.modelId)}const c=[],d=new Map;for(const f of r)i.push(...gn(f.ownerId,[f.dispId],c)),i.push(Ya(f.assocId,{end1:f.end1,end2:f.end2})),d.set(f.ownerId,[...d.get(f.ownerId)??[],f.dispId]);for(const[f,p]of d)i.push(...Di(e,f,p));i.push(...Xa(l,n,s,c));const u=s_(l,n,s);return i.push(...Bi(u,n,c)),i.push(...Jt(e,c)),i}function Lm(e,n,o){const i=e.associations.find(l=>l.modelId===n);if(!i||i.end1.navigable===o)return null;const a=e.entities.find(l=>l.modelId===i.end1.entityRef),r=e.entities.find(l=>l.modelId===i.end2.entityRef);if(!a||!r||a.stereotype==="JPA_EMBEDDABLE"||r.stereotype==="JPA_EMBEDDABLE")return null;if(o===!0&&!i.end1.attributeRef){const l=Ea(i.end2.multiplicity),s=i.end1.navFieldNameHint||wa(r.name,l),c=yo(s,new Set(a.attributes.map(m=>m.name))),d=Fe(),u={modelId:d,name:c,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:Yt(a.attributes),dbAttrs:[]};return{cmds:[Wt(i.end1.entityRef,u)],endPatch:{attributeRef:d,navFieldNameHint:void 0}}}if(o===!1&&i.end1.attributeRef){const l=i.end1.attributeRef,s=a.attributes.find(m=>m.modelId===l&&m.attrType==="RELATION_REF"),c={attributeRef:void 0,navFieldNameHint:(s==null?void 0:s.name)??i.end1.navFieldNameHint};if(!s)return{cmds:[],endPatch:c};const d=[],u=[...gn(i.end1.entityRef,[l],d)];return u.push(...Jt(e,d)),{cmds:u,endPatch:c}}return null}function Bm(e,n,o){const i=e.entities.find(u=>u.modelId===n);if(!i)return[];const a=i.attributes.filter(u=>u.identifier&&!u.derivedFrom).map(u=>nn(n,u.modelId,{identifier:!1})),r=Ln({...e,entities:e.entities.map(u=>u.modelId===n?{...u,stereotype:o}:u)},n,u=>u.map(m=>m.identifier&&!m.derivedFrom?{...m,identifier:!1}:m)),l=[],s=Za(r,[n],l);s.push(...Jt(e,l));const c=o==="JPA_EMBEDDABLE"?c_(e,n):[],d=Tm(i,o,new Set(l.filter(u=>u.entityId===n).map(u=>u.attributeId)));return[...a,...s,...c,...d]}function c_(e,n){const o=e.entities.find(r=>r.modelId===n);if(!o)return[];const i=[],a=r=>r&&r.charAt(0).toLowerCase()+r.slice(1);for(const r of e.associations){if(r.end1.entityRef===r.end2.entityRef)continue;const l=r.end1.entityRef===n,s=r.end2.entityRef===n;if(!l&&!s)continue;const c=l?r.end2.entityRef:r.end1.entityRef,d=e.entities.find(b=>b.modelId===c);if(!d||d.attributes.some(b=>{var w;return((w=b.embedded)==null?void 0:w.associationRef)===r.modelId}))continue;const u=Fe(),m=Yt(d.attributes),f=new Set(d.attributes.map(b=>b.name)),p=a(o.name);let g=p;for(let b=2;f.has(g);b++)g=`${p}${b}`;const y=o.attributes.filter(b=>!b.identifier&&!b.derivedFrom).flatMap(b=>b.dbAttrs).map(b=>({...b,modelId:Fe()})),h={modelId:u,name:g,type:o.name,attrType:"EMBED_OWN",identifier:!1,notNull:!1,order:m,dbAttrs:y,embedded:{associationRef:r.modelId,embeddableRef:n}};i.push(Wt(c,h));const _=l?"end2":"end1",N=l?"end1":"end2";i.push(Ya(r.modelId,{identifying:!1,[_]:{entityRef:c,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!1,attributeRef:Fe()},[N]:{entityRef:n,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!0,attributeRef:u}}))}return i}function Dm(e,n,o,i){var d;const a=e.layout.groupLayouts.find(u=>u.groupRef===n),r=(a==null?void 0:a.geo.location)??o,l=o.x-r.x,s=o.y-r.y,c=[Uu(n,o),...i.map(u=>ti(u.id,u.location))];if(l||s){const u=new Set(((d=e.logical.groups.find(m=>m.modelId===n))==null?void 0:d.memberEntityRefs)??[]);for(const m of e.logical.associations){if(!u.has(m.end1.entityRef)||!u.has(m.end2.entityRef))continue;const f=e.layout.associationLayouts.find(p=>p.associationRef===m.modelId);f&&f.waypoints.length&&c.push(im(m.modelId,l,s))}for(const m of(a==null?void 0:a.memberNoteRefs)??[]){const f=e.layout.notes.find(p=>p.modelId===m);f&&c.push(Li(m,{x:f.geo.location.x+l,y:f.geo.location.y+s}))}}return c}const Om={diagramId:"",logicalModelRef:"",entityLayouts:[],associationLayouts:[],groupLayouts:[],notes:[]};function d_(e,n){const o=n.dbAttrs;if(Array.isArray(o))return o.length;let i=e.dbAttrs.length;for(const a of Object.keys(n)){const r=/^dbAttrs\.(\d+)\./.exec(a);r&&(i=Math.max(i,Number(r[1])+1))}return i}function Pm(e,n,o){for(const[i,a]of Object.entries(n)){if(i==="dbAttrs"){if(!Array.isArray(a))continue;a.forEach((l,s)=>{if(l&&typeof l=="object")for(const[c,d]of Object.entries(l))o(s,c,d,`dbAttrs.${s}.${c}`)});continue}const r=/^dbAttrs\.(\d+)\.(.+)$/.exec(i);if(r){o(Number(r[1]),r[2],a,i);continue}e.dbAttrs.length===1&&Qa.has(i)&&o(0,i,a,i)}}function u_(e,n){const o=new Set,i=new Set,a=r=>r!=null;for(const[r,l]of Object.entries(n))r==="dbAttrs"||r.startsWith("dbAttrs.")||(Wc.attr.includes(r)?o.add(r):Jc.attr.includes(r)&&a(l)&&i.add(r));return Pm(e,n,(r,l,s,c)=>{Wc.column.includes(l)?o.add(c):Jc.column.includes(l)&&a(s)&&i.add(c)}),{locked:[...o],inapplicable:[...i]}}function m_(e,n,o,i,a){const r=a?{embeddableCatalog:a}:void 0,l=d=>{const u=e.dbAttrs[d];return u?rd(u,At(e,u,d,n,o,r)):[]},s=new Map;Pm(e,i,(d,u,m)=>{m!=null&&id.includes(u)&&(s.has(d)||s.set(d,new Set),s.get(d).add(u))});const c=[];for(const[d,u]of[...s.entries()].sort((m,f)=>m[0]-f[0])){const m=l(d).filter(f=>u.has(f));m.length&&c.push([d,m])}return c}function f_(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 p_(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 zm(e,n,o){return e.associations.filter(i=>{const a=[i.end1.entityRef,i.end2.entityRef];return a.includes(n)&&a.includes(o)})}function Tt(e,n){if(!er(n))return{ok:!1,reason:"shape",matches:[]};const o=f_(e,n);return o.length===1?{ok:!0,value:o[0]}:{ok:!1,reason:o.length===0?"not-found":"ambiguous",matches:o.map(i=>g_(i,e))}}function h_(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 us(e,n){const o=h_(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 ms(e,n,o){return e.reason==="shape"?{code:"handle-shape-invalid",opIndex:n,where:"group",expected:"{ref, by?}",got:hs(o)}:e.reason==="not-found"?{code:"group-not-found",opIndex:n,handle:o}:{code:"group-ambiguous",opIndex:n,handle:o,matches:e.matches}}const y_=new Set(["name","description","packageName","excludeDDLGeneration"]);function g_(e,n){var a;const o=qo(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(f=>f.modelId===l);return(s==null?void 0:s.name)||((m=s==null?void 0:s.table)==null?void 0:m.physicalName)||String(l??"?")}))]}}function Fm(e,n){const o=p_(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 b_(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 k_(e,n){const o=b_(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 Um(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 fs(e){return e.by!==void 0&&e.by!=="name"}function __(e,n){return(e.indexes??[]).filter(o=>o.name===n.ref)}function E_(e,n){return(e.operations??[]).filter(o=>o.name===n.ref)}function N_(e,n){const o=__(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 Hm(e,n){const o=E_(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 jm(e){return e.physicalName!=null||e.dataType!=null||e.length!=null||e.scale!=null||e.columnLogicalName!=null||e.unique!=null||e.updatable!=null||e.sequenceName!=null}function Km(e){return jm(e)&&e.dataType==null}function Gm(e,n,o){var a;const i=jm(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}:{},...e.fieldLogicalName?{fieldLogicalName:e.fieldLogicalName}:{},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}:{},...(a=e.sequenceName)!=null&&a.trim()?{sequenceName:e.sequenceName.trim()}:{}}]:[]}}function qm(e,n,o,i,a,r,l,s,c){const d=Xm(e.embeddableOverrides);if(d.length)return s.push({code:"embeddable-override-unknown-key",opIndex:r,entity:l,handle:{ref:e.name},keys:d}),null;const u=c(),m=new Map((e.embeddableOverrides??[]).map(g=>[g.field,g])),f=[];let p=!1;for(const g of n.fields){const y=m.get(g.name);if(y!=null&&y.sharedColumnPhysicalName){const h={ref:y.sharedColumnPhysicalName,by:"physicalName"},_=Um(xn(i,a),h);if(!_.ok){s.push(_.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:h}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:h,matches:_.matches}),p=!0;continue}f.push({modelId:c(),physicalName:"",dataType:"",sharedColumnRef:_.value.modelId});continue}f.push({modelId:c(),physicalName:(y==null?void 0:y.physicalName)??"",dataType:"",...y!=null&&y.length?{length:y.length}:{},...y!=null&&y.scale?{scale:y.scale}:{},...(y==null?void 0:y.insertable)!=null?{insertable:y.insertable}:{},...(y==null?void 0:y.updatable)!=null?{updatable:y.updatable}:{},...(y==null?void 0:y.notNull)!=null?{notNull:y.notNull}:{}})}return p?null:{modelId:u,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:f}}const w_=new Set(["name","type","customType","attrType","identifier","notNull","transient","naturalId","naturalIdMutable","description","attributeGroup","groupCode","defaultValue","personalInfoAttributeType","order","dbAttrs","derivedIdFieldName","collectionType","fieldLogicalName"]),Co=e=>new Set(Object.keys(e)),I_=Co({name:!0,stereotype:!0,physicalName:!0,useVersion:!0,attributes:!0,indexes:!0,operations:!0,serialization:!0,classLogicalName:!0}),Ym=Co({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,fieldLogicalName:!0,sequenceName:!0}),v_=Co({field:!0,physicalName:!0,length:!0,scale:!0,insertable:!0,updatable:!0,notNull:!0,sharedColumnPhysicalName:!0}),Wm=Co({name:!0,unique:!0,columns:!0,description:!0,parameters:!0}),Jm=Co({name:!0,visibility:!0,sourceCode:!0,description:!0,personalInfoAttributeType:!0}),C_=Co({from:!0,to:!0,fromMultiplicity:!0,toMultiplicity:!0,identifying:!0,composition:!0}),S_=Co({name:!0,packageName:!0,description:!0,excludeDDLGeneration:!0,members:!0});function bn(e,n){return So(e,n)}function Xm(e){const n=new Set;for(const o of e??[])for(const i of bn(o,v_))n.add(i);return[...n]}const R_=new Set(["name","stereotype","packageName","superClass","schema","description","abstractClass","hasPersonalInfo","declarationOfInterfaces","table","classLogicalName","referenceOnly","serialization"]),A_=new Set(["description","identifying"]),x_=new Set(["multiplicity","navigable","composition"]),$_=new Set(["name","unique","description","parameters"]),T_=new Set(["name","visibility","sourceCode","description","order","personalInfoAttributeType"]);function So(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 Qa=new Set(["physicalName","logicalName","dataType","length","scale","unique","autoIncrement","updatable","insertable","sharedColumnRef","multiValue","multiValueSeparator","sequenceName"]),M_=new Set([...Qa].filter(e=>e!=="sharedColumnRef"));function V_(e,n,o,i){if(i||o.some(l=>!M_.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))Qa.has(l)||(r[l]=s);return{...r,dbAttrs:[a]}}function L_(e,n,o,i,a,r,l,s){const c=Xm(o);if(c.length)return s.push({code:"embeddable-override-unknown-key",opIndex:r,entity:l,handle:{ref:e.name},keys:c}),null;const d=new Map(o.map(f=>[f.field,f])),u=[];let m=!1;return e.dbAttrs.forEach((f,p)=>{const g=n.fields[p],y=g?d.get(g.name):void 0;if(!y){u.push(f);return}if(y.sharedColumnPhysicalName){const _={ref:y.sharedColumnPhysicalName,by:"physicalName"},N=Um(xn(i,a),_);if(!N.ok){s.push(N.reason==="not-found"?{code:"shared-column-target-not-found",opIndex:r,entity:l,handle:_}:{code:"shared-column-target-ambiguous",opIndex:r,entity:l,handle:_,matches:N.matches}),m=!0;return}u.push({modelId:f.modelId,physicalName:"",dataType:"",sharedColumnRef:N.value.modelId});return}const h={...f};delete h.sharedColumnRef,u.push({...h,...y.physicalName!=null?{physicalName:y.physicalName}:{},...y.length!=null?{length:y.length}:{},...y.scale!=null?{scale:y.scale}:{},...y.notNull!=null?{notNull:y.notNull}:{},...y.insertable!=null?{insertable:y.insertable}:{},...y.updatable!=null?{updatable:y.updatable}:{}})}),m?null:u}function Zm(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 Qm(e,n,o,i,a,r){const l=[];let s=!1;for(const c of n.columns){const d=k_(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 ni(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 B_(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 Im(s,l))e.push({kind:"index.update",casUnit:"logical",containerRef:r,entityRef:r,indexRef:c.indexRef,patch:{columns:c.columns}})}}function D_(e,n,o,i,a,r){const l=m=>{const f=new Map;for(const{entityId:p,item:g}of m){if(a.has(p))continue;const y=f.get(p)??[];y.push(g),f.set(p,y)}return f},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,f]of s)if(!c.has(m))for(const p of Sm(n,m,f))u(p);for(const[m,f]of c){if(s.has(m))continue;const p={...n,entities:n.entities.map(g=>g.modelId===m?{...g,attributes:[...g.attributes,...f]}:g)};for(const g of vm(p,m,r))u(g)}}function ef(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 tf(e,n,o,i,a,r,l){var f;for(const p of i.remove)ni(e,r,o,p);for(const p of i.update)e.push({kind:"attribute.update",casUnit:"logical",containerRef:o,entityRef:o,attributeRef:p.attributeId,patch:p.patch}),a.attrPatches.push({entityId:o,attributeId:p.attributeId,patch:p.patch});const s=((f=n.entities.find(p=>p.modelId===o))==null?void 0:f.attributes)??[],c=[];for(const p of i.add){const g={...p,order:l(o,s)};e.push({kind:"attribute.add",casUnit:"logical",containerRef:o,entityRef:o,value:g}),a.cascadeAdds.push({entityId:o,attribute:g}),c.push(g)}const d=new Set(i.remove),u=[...s.filter(p=>!d.has(p.modelId)),...c],m=new Set(u.map(p=>p.modelId));for(const p of n.associations){if(p.end2.entityRef!==o)continue;const g=p.end2.attributeRef;if(g&&m.has(g))continue;const h=u.filter(_=>{var N;return((N=_.derivedFrom)==null?void 0:N.associationRef)===p.modelId&&_.dbAttrs.length>0}).sort((_,N)=>_.order-N.order)[0];h&&(e.push({kind:"associationEnd.update",casUnit:"logical",containerRef:p.modelId,associationRef:p.modelId,end:"end2",patch:{attributeRef:h.modelId}}),a.endPatches.push({associationRef:p.modelId,end:"end2",patch:{attributeRef:h.modelId}}))}}function ps(e,n,o,i,a,r,l){for(const{entityId:s,plan:c}of Cd(n,o,i))tf(e,n,s,c,a,r,l)}function O_(e,n,o,i,a,r){const l=new Map;for(const{entityId:f,attributeId:p}of i.pairs)l.has(f)||l.set(f,new Set),l.get(f).add(p);const s=new Map;for(const f of r.attrPatches)s.has(f.entityId)||s.set(f.entityId,[]),s.get(f.entityId).push(f);const c=new Map;for(const{entityId:f,attribute:p}of[...a,...r.cascadeAdds])c.has(f)||c.set(f,[]),c.get(f).push(p);const d=f=>{const p={};for(const[g,y]of Object.entries(f))g.includes(".")||(p[g]=y===null?void 0:y);return p},u=e.entities.filter(f=>!n.has(f.modelId)).map(f=>{const p=l.get(f.modelId),g=s.get(f.modelId),y=c.get(f.modelId);if(!p&&!g&&!y)return f;let h=f.attributes;return p&&(h=h.filter(_=>!p.has(_.modelId))),g&&(h=h.map(_=>{const N=g.filter(b=>b.attributeId===_.modelId);return N.length?N.reduce((b,w)=>ef(b,w.patch),_):_})),y&&(h=[...h,...y]),{...f,attributes:h}}),m=e.associations.filter(f=>!o.has(f.modelId)&&!n.has(f.end1.entityRef)&&!n.has(f.end2.entityRef)).map(f=>{let p=f;for(const g of r.assocPatches)g.associationRef===f.modelId&&(p={...p,...d(g.patch)});for(const g of r.endPatches)g.associationRef===f.modelId&&(p={...p,[g.end]:{...p[g.end],...d(g.patch)}});return p}).concat(r.addedAssociations);return{...e,entities:u,associations:m}}function P_(e,n,o,i,a,r,l,s,c){if(!l.identifierCascadeParents.size)return;const d=O_(n,o,i,a,r,l),u=new Map;for(const m of l.identifierCascadeParents)for(const[f,p]of wl(d,m,s)){const g=u.get(f);u.set(f,g?Nl(g,p):p)}for(const[m,f]of u)tf(e,d,m,vd(f),l,a,c)}const z_=e=>e==="ZERO_OR_MORE_INSTANCES"||e==="ONE_OR_MORE_INSTANCES";function F_(e,n,o,i,a,r,l){const s=i(),c=i(),d=i(),u=o??"EXACTLY_ONE_INSTANCE",m=z_(u),f=N=>N&&N.charAt(0).toLowerCase()+N.slice(1),p=new Set(e.attributes.map(N=>N.name)),g=f(n.name);let y=g;for(let N=2;p.has(y);N++)y=`${g}${N}`;const h={modelId:c,name:y,type:n.name,attrType:"EMBED_OWN",identifier:!1,notNull:!1,order:a(e.modelId,e.attributes),dbAttrs:m?[]:pn(n).map(N=>({...N.col,modelId:i()})),embedded:{associationRef:s,embeddableRef:n.modelId}},_={modelId:s,end1:{entityRef:e.modelId,multiplicity:"EXACTLY_ONE_INSTANCE",navigable:!0,composition:!1,attributeRef:d},end2:{entityRef:n.modelId,multiplicity:u,navigable:!0,composition:!0,attributeRef:c,...m?{jpa:{collectionType:"LIST"}}:{}}};return l.push({entityId:e.modelId,attribute:h}),r.addedAssociations.push(_),[{kind:"attribute.add",casUnit:"logical",containerRef:e.modelId,entityRef:e.modelId,value:h},{kind:"association.add",casUnit:"logical",associationRef:s,value:_}]}const U_=new Set(["classLogicalName","columnLogicalName","fieldLogicalName","logicalName"]),H_=[{key:"name",kinds:new Set(["group.add","group.update"])},{key:"description",kinds:new Set(["attribute.add","attribute.update","operation.add","operation.update"])}];function j_(e){const n=[],o=e.kind??"",i=l=>U_.has(l)||H_.some(s=>s.key===l&&s.kinds.has(o)),a=l=>l===null?"null":Array.isArray(l)?"array":typeof l,r=(l,s)=>{if(!(l==null||typeof l!="object")){if(Array.isArray(l)){l.forEach((c,d)=>r(c,`${s}[${d}]`));return}for(const[c,d]of Object.entries(l)){const u=c.includes(".")?c.split(".").pop():c,m=s?`${s}.${c}`:c;i(u)&&!Eg(d)?n.push({path:m,got:a(d)}):r(d,m)}}};return r(e,""),n}function K_(e){const n=i=>{if(i==null||typeof i!="object"||Array.isArray(i))return!1;const a=Object.keys(i);return a.length>0&&a.every(r=>Wn.includes(r))},o=i=>{if(n(i))return Xc(i)??null;if(Array.isArray(i)){const a=i.map(o);return a.some((r,l)=>r!==i[l])?a:i}if(i!=null&&typeof i=="object"){const a=i;let r=!1;const l={};for(const[s,c]of Object.entries(a))l[s]=o(c),l[s]!==c&&(r=!0);return r?l:i}return i};return e.map(i=>o(i))}function G_(e,n,o={}){const i=K_(n),a=o.mkId??Fe,r=o.embeddableCatalog??[],l=k=>r.find(C=>C.type===k),s=[],c=[],d=[],u=new Set;n.forEach((k,C)=>{for(const x of j_(k))u.add(C),c.push({code:"multilang-shape-invalid",opIndex:C,where:x.path,expected:"{ko?,en?,ja?,zh?} | null | {}",got:x.got})});const m=new Map,f=(k,C)=>{const x=m.get(k)??Yt(C);return m.set(k,x+1),x},p=new Map,g=new Set,y=new Set,h={seen:new Set,pairs:[]},_=[],N={attrPatches:[],cascadeAdds:[],addedAssociations:[],assocPatches:[],endPatches:[],identifierCascadeParents:new Set},b=new Set,w=(k,C)=>`${k}\0${C}`,I=new Set;for(const k of i)k.kind==="entity.add"&&(I.add(k.spec.name),k.spec.physicalName&&I.add(k.spec.physicalName));const $=new Set;return i.forEach((k,C)=>{var x,T,z,V,D;if(!u.has(C)&&Y_(k,C,c))switch(k.kind){case"entity.add":{{const L={ref:k.spec.name},j=bn(k.spec,I_);if(j.length){c.push({code:"entity-spec-unknown-key",opIndex:C,handle:L,keys:j});break}let X=!1;for(const J of k.spec.attributes??[]){const re=bn(J,Ym);re.length&&(c.push({code:"attribute-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}for(const J of k.spec.indexes??[]){const re=bn(J,Wm);re.length&&(c.push({code:"index-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}for(const J of k.spec.operations??[]){const re=bn(J,Jm);re.length&&(c.push({code:"operation-spec-unknown-key",opIndex:C,entity:L,handle:{ref:J.name},keys:re}),X=!0)}if(X)break}const E=e.entities.filter(L=>L.name===k.spec.name).map(L=>L.modelId);if(E.length||$.has(k.spec.name)){c.push({code:"entity-name-conflict",opIndex:C,handle:{ref:k.spec.name},matches:E});break}$.add(k.spec.name);const v=a(),A={modelId:v,name:k.spec.name,stereotype:k.spec.stereotype??"JPA_ENTITY",attributes:[],...k.spec.useVersion?{jpaAttrs:{useVersion:!0}}:{},...k.spec.physicalName?{table:{physicalName:k.spec.physicalName}}:{},...k.spec.serialization?{serialization:k.spec.serialization}:{},...k.spec.classLogicalName?{classLogicalName:k.spec.classLogicalName}:{}},S={ref:k.spec.name};let R=!1;for(const[L,j]of(k.spec.attributes??[]).entries()){if(_a(j.type,j.groupCode)){c.push(j.groupCode?{code:"groupcode-type-mismatch",opIndex:C,entity:S,handle:{ref:j.name},type:String(j.type??""),groupCode:j.groupCode}:{code:"groupcode-required",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0;continue}if(!l(j.type)&&!((x=j.embeddableOverrides)!=null&&x.length)&&Km(j)){c.push({code:"datatype-required",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0;continue}const X=l(j.type);if(X){const J=qm(j,X,L,A,e.entities,C,S,c,a);J?A.attributes.push(J):R=!0}else(T=j.embeddableOverrides)!=null&&T.length?(c.push({code:"embeddable-type-unresolved",opIndex:C,entity:S,handle:{ref:j.name}}),R=!0):A.attributes.push(Gm(j,L,a))}const H=(k.spec.operations??[]).map((L,j)=>Zm(L,j,a));H.length&&(A.operations=H);const P=[];for(const L of k.spec.indexes??[]){const j=Qm(A,L,C,S,c,a);j?P.push(j):R=!0}if(P.length&&(A.indexes=P),R)break;s.push({kind:"entity.add",casUnit:"logical",entityRef:v,value:A});break}case"entity.update":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=So(k.patch,R_,["jpaAttrs.","table.","serialization."]);if(v.length){c.push({code:"entity-patch-unknown-key",opIndex:C,entity:k.entity,keys:v});break}const A=k.patch.stereotype;if(typeof A=="string"&&A!==E.value.stereotype){const S=E.value.stereotype,R=A,H=at(R)&&!at(S),P=!at(R)&&at(S);if(R!==S&&at(R)&&at(S)&&e.entities.filter(J=>J.attributes.some(re=>{var me;return((me=re.embedded)==null?void 0:me.embeddableRef)===E.value.modelId})).length>0){c.push({code:"stereotype-embeddable-transition-unsupported",opIndex:C,entity:k.entity,from:S??"",to:R});break}if(R==="SERIALIZED_TYPE"&&e.associations.filter(J=>J.end1.entityRef===E.value.modelId||J.end2.entityRef===E.value.modelId).length>0){c.push({code:"stereotype-serialized-transition-unsupported",opIndex:C,entity:k.entity,from:S??"",to:R});break}const j=H?Bm(e,E.value.modelId,R):P?Vm(e,E.value.modelId):[];if(j.length){const X=Ha(E.value.modelId,k.patch),J=$u({logical:e,layout:Om},[X,...j]);s.push(...J.ops);break}}s.push({kind:"entity.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,patch:k.patch});break}case"entity.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=E.value.modelId,A=e.associations.filter(P=>P.end1.entityRef===v||P.end2.entityRef===v),S=new Set(A.map(P=>P.modelId));for(const P of A)g.has(P.modelId)||(g.add(P.modelId),s.push({kind:"association.remove",casUnit:"logical",associationRef:P.modelId}));for(const P of e.entities)if(P.modelId!==v)for(const L of P.attributes)L.embedded&&S.has(L.embedded.associationRef)&&ni(s,h,P.modelId,L.modelId);for(const P of A){if(P.end1.entityRef===v||!P.end1.attributeRef)continue;const L=e.entities.find(X=>X.modelId===P.end1.entityRef),j=L==null?void 0:L.attributes.find(X=>X.modelId===P.end1.attributeRef&&X.attrType==="RELATION_REF");j&&ni(s,h,L.modelId,j.modelId)}const R={...e,entities:e.entities.filter(P=>P.modelId!==v),associations:e.associations.filter(P=>!S.has(P.modelId))},H=new Set(A.filter(P=>P.end1.entityRef===v&&P.end2.entityRef!==v).map(P=>P.end2.entityRef));ps(s,R,[...H],a,N,h,f);for(const P of e.groups)P.memberEntityRefs.includes(v)&&(b.has(w(P.modelId,v))||(b.add(w(P.modelId,v)),s.push({kind:"group.removeMember",casUnit:"logical",containerRef:P.modelId,groupRef:P.modelId,entityRef:v})));y.add(v),s.push({kind:"entity.remove",casUnit:"logical",entityRef:v});break}case"attribute.add":{{const R=bn(k.spec,Ym);if(R.length){c.push({code:"attribute-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:R});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(_a(k.spec.type,k.spec.groupCode)){c.push(k.spec.groupCode?{code:"groupcode-type-mismatch",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},type:String(k.spec.type??""),groupCode:k.spec.groupCode}:{code:"groupcode-required",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}if(!l(k.spec.type)&&!((z=k.spec.embeddableOverrides)!=null&&z.length)&&Km(k.spec)){c.push({code:"datatype-required",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}{const R=new Map(e.entities.map(P=>[P.modelId,P])),H=E.value.attributes.find(P=>{const L=Al(P,E.value,e,R);return!!L&&L===k.spec.name});if(H){c.push({code:"derived-id-scalar-conflict",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},fk:H.name});break}}const v=f(E.value.modelId,E.value.attributes),A=l(k.spec.type);let S;if(A)S=qm(k.spec,A,v,E.value,e.entities,C,k.entity,c,a);else if((V=k.spec.embeddableOverrides)!=null&&V.length){c.push({code:"embeddable-type-unresolved",opIndex:C,entity:k.entity,handle:{ref:k.spec.name}});break}else S=Gm(k.spec,v,a);if(!S)break;s.push({kind:"attribute.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,value:S}),_.push({entityId:E.value.modelId,attribute:S}),S.identifier&&N.identifierCascadeParents.add(E.value.modelId);break}case"attribute.update":case"attribute.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=Fm(E.value,k.attribute);if(!v.ok){c.push(v.reason==="not-found"?{code:"attribute-not-found",opIndex:C,entity:k.entity,handle:k.attribute}:{code:"attribute-ambiguous",opIndex:C,entity:k.entity,handle:k.attribute,matches:v.matches});break}if(k.kind==="attribute.update"){const A=[],S=[];let R=!1;for(const J of Object.keys(k.patch)){if(J.includes(".")){J.startsWith("dbAttrs.")?R=!0:S.push(J);continue}Qa.has(J)?A.push(J):w_.has(J)||S.push(J)}if(S.length){c.push({code:"attribute-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.attribute,keys:S});break}if(Ei(v.value)){const J=u_(v.value,k.patch);if(J.locked.length){const re=Xn(e,E.value.modelId,v.value.modelId),me=se=>{var Ie;return((Ie=e.entities.find(Oe=>Oe.modelId===se))==null?void 0:Ie.name)??se};c.push({code:"attribute-fk-derived-field-locked",opIndex:C,entity:k.entity,handle:k.attribute,fields:J.locked,...re?{association:{from:me(re.end1.entityRef),to:me(re.end2.entityRef)}}:{}});break}J.inapplicable.length&&d.push({code:"fk-derived-inapplicable-field",opIndex:C,entity:k.entity,attribute:k.attribute,fields:J.inapplicable})}const H=Array.isArray(k.patch.dbAttrs)?k.patch.dbAttrs:v.value.dbAttrs,P="type"in k.patch?Og({attrType:v.value.attrType,type:v.value.type,dbAttrs:H},String(k.patch.type),r):void 0;for(const[J,re]of m_(v.value,E.value,e,k.patch,r))d.push({code:"inherited-slot-override",opIndex:C,entity:k.entity,attribute:k.attribute,columnIndex:J,fields:re});if("attrType"in k.patch){const J=String(k.patch.attrType),re=P?"EMBED_PREDEF":void 0,me=wm.includes(J)?J!==v.value.attrType&&J!==re?"transition":void 0:"unknown-value";if(me){c.push({code:"attribute-attrtype-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,reason:me,current:v.value.attrType,requested:J});break}}if("type"in k.patch&&!P){const J=String(k.patch.type);if(kd(v.value,J,r)){const re=kl(v.value),me=re==="association"?"association-owned":re==="derived"?"derived":"column-count";c.push({code:"attribute-type-conversion-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,reason:me,current:v.value.type,requested:J});break}}const L="type"in k.patch?k.patch.type:v.value.type,j="groupCode"in k.patch?k.patch.groupCode:v.value.groupCode;if(_a(L,j)){c.push(j?{code:"groupcode-type-mismatch",opIndex:C,entity:k.entity,handle:k.attribute,type:String(L??""),groupCode:String(j)}:{code:"groupcode-required",opIndex:C,entity:k.entity,handle:k.attribute});break}let X=k.patch;if(P&&v.value.attrType!=="EMBED_PREDEF"&&(X={...X,attrType:"EMBED_PREDEF"}),P&&v.value.customType!==void 0&&!("customType"in X)&&(X={...X,customType:null}),A.length){const J=V_(v.value,k.patch,A,R);if(!J){c.push({code:"attribute-patch-dbattr-flat-key",opIndex:C,entity:k.entity,handle:k.attribute,keys:A});break}X=J}if((D=k.embeddableOverrides)!=null&&D.length){const J=l(v.value.type);if(!J||v.value.attrType!=="EMBED_PREDEF"){c.push({code:"embeddable-type-unresolved",opIndex:C,entity:k.entity,handle:k.attribute});break}const re=L_(v.value,J,k.embeddableOverrides,E.value,e.entities,C,k.entity,c);if(!re)break;X={...X,dbAttrs:re}}{const J=X.attrType??v.value.attrType,re=d_(v.value,X);if(J==="NORMAL"&&re>1){c.push({code:"attribute-column-count-unsupported",opIndex:C,entity:k.entity,handle:k.attribute,attrType:J,current:v.value.dbAttrs.length,requested:re});break}}s.push({kind:"attribute.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,attributeRef:v.value.modelId,patch:X}),N.attrPatches.push({entityId:E.value.modelId,attributeId:v.value.modelId,patch:X});{const J=v.value,re=ef(J,X),me=(re.identifier??!1)!==(J.identifier??!1),se=(J.identifier||re.identifier)&&("type"in X||"customType"in X||"dbAttrs"in X||Object.keys(X).some(Ie=>Ie.startsWith("dbAttrs.")));(me||se)&&N.identifierCascadeParents.add(E.value.modelId)}}else{const A=Xn(e,E.value.modelId,v.value.modelId);if(A){const S=R=>{var H;return((H=e.entities.find(P=>P.modelId===R))==null?void 0:H.name)??R};c.push({code:"attribute-fk-managed",opIndex:C,entity:k.entity,handle:k.attribute,association:{from:S(A.end1.entityRef),to:S(A.end2.entityRef)}});break}ni(s,h,E.value.modelId,v.value.modelId),v.value.identifier&&N.identifierCascadeParents.add(E.value.modelId)}break}case"association.add":{{const P=bn(k.spec,C_);if(P.length){c.push({code:"association-spec-unknown-key",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},keys:P});break}}const E=Tt(e,k.spec.from),v=Tt(e,k.spec.to);if(E.ok||c.push(Mt(E.reason,C,k.spec.from,E.matches,I)),v.ok||c.push(Mt(v.reason,C,k.spec.to,v.matches,I)),!E.ok||!v.ok)break;if(k.spec.identifying&&E.value.modelId===v.value.modelId){c.push({code:"self-identifying",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}if(v.value.stereotype==="JPA_EMBEDDABLE"){const P=_.flatMap(({entityId:X,attribute:J})=>{var re;return J.attrType==="EMBED_OWN"&&((re=J.embedded)!=null&&re.embeddableRef)?[{ownerId:X,embeddableRef:J.embedded.embeddableRef}]:[]}),L=Rm(e.entities,E.value.modelId,v.value.modelId,P);if(L){const X=J=>{var re;return((re=e.entities.find(me=>me.modelId===J))==null?void 0:re.name)??J};c.push(L.length===1?{code:"embed-self-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}}:{code:"embed-cycle-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},path:L.map(X)});break}const j=["identifying","composition","fromMultiplicity"].filter(X=>k.spec[X]!=null);if(j.length){c.push({code:"embed-spec-inapplicable",opIndex:C,handle:{from:k.spec.from,to:k.spec.to},fields:[...j]});break}s.push(...F_(E.value,v.value,k.spec.toMultiplicity,a,f,N,_));break}if(E.value.stereotype==="JPA_EMBEDDABLE"){c.push({code:"embeddable-relation-unsupported",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}if(E.value.stereotype==="SERIALIZED_TYPE"||v.value.stereotype==="SERIALIZED_TYPE"){c.push({code:"serialized-relation-invalid",opIndex:C,handle:{from:k.spec.from,to:k.spec.to}});break}const A=a(),S={modelId:A,...k.spec.identifying!=null?{identifying:k.spec.identifying}:{},end1:{entityRef:E.value.modelId,multiplicity:k.spec.fromMultiplicity??"EXACTLY_ONE_INSTANCE",navigable:!1,composition:!1},end2:{entityRef:v.value.modelId,multiplicity:k.spec.toMultiplicity??"ZERO_OR_MORE_INSTANCES",navigable:!0,composition:k.spec.composition??!1}},R={...e,associations:[...e.associations,S]},H=vi(R,v.value.modelId,a);H.add[0]&&(S.end2.attributeRef=H.add[0].modelId),s.push({kind:"association.add",casUnit:"logical",associationRef:A,value:S}),N.addedAssociations.push(S);for(const P of H.add){const L={...P,order:f(v.value.modelId,v.value.attributes)};s.push({kind:"attribute.add",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,value:L}),N.cascadeAdds.push({entityId:v.value.modelId,attribute:L})}break}case"association.remove":{const E=Tt(e,k.association.from),v=Tt(e,k.association.to);if(E.ok||c.push(Mt(E.reason,C,k.association.from,E.matches,I)),v.ok||c.push(Mt(v.reason,C,k.association.to,v.matches,I)),!E.ok||!v.ok)break;const A=zm(e,E.value.modelId,v.value.modelId);if(A.length!==1){c.push(A.length===0?{code:"association-not-found",opIndex:C,handle:k.association}:{code:"association-ambiguous",opIndex:C,handle:k.association,matches:A.map(P=>P.modelId)});break}const S=A[0];g.has(S.modelId)||(g.add(S.modelId),s.push({kind:"association.remove",casUnit:"logical",associationRef:S.modelId}));const R=e.entities.find(P=>P.attributes.some(L=>{var j;return((j=L.embedded)==null?void 0:j.associationRef)===S.modelId}));if(R){const P=R.attributes.find(L=>{var j;return((j=L.embedded)==null?void 0:j.associationRef)===S.modelId});ni(s,h,R.modelId,P.modelId);break}if(S.end1.attributeRef){const P=e.entities.find(j=>j.modelId===S.end1.entityRef),L=P==null?void 0:P.attributes.find(j=>j.modelId===S.end1.attributeRef&&j.attrType==="RELATION_REF");L&&ni(s,h,P.modelId,L.modelId)}const H={...e,associations:e.associations.filter(P=>P.modelId!==S.modelId)};ps(s,H,[S.end2.entityRef],a,N,h,f);break}case"association.update":{const E=nf(e,k.association,C,c,I);if(!E)break;const v=k.patch.identifying,A=typeof v=="boolean"?v:void 0;if(A===!0&&E.end1.entityRef===E.end2.entityRef){c.push({code:"self-identifying",opIndex:C,handle:k.association});break}const S=So(k.patch,A_);if(S.length){c.push({code:"association-patch-unknown-key",opIndex:C,handle:k.association,keys:S});break}if(s.push({kind:"association.update",casUnit:"logical",containerRef:E.modelId,associationRef:E.modelId,patch:k.patch}),N.assocPatches.push({associationRef:E.modelId,patch:k.patch}),A!==void 0&&A!==(E.identifying??!1)){const R={...e,associations:e.associations.map(H=>H.modelId===E.modelId?{...H,identifying:A}:H)};ps(s,R,[E.end2.entityRef],a,N,h,f)}break}case"associationEnd.update":{const E=nf(e,k.association,C,c,I);if(!E)break;const v=k.end==="from"?"end1":"end2";if(Object.prototype.hasOwnProperty.call(k.patch,"navigable")){if(v==="end2"){c.push({code:"navigable-toggle-unsupported",opIndex:C,handle:k.association});break}const S=k.patch.navigable===!0;if(E.end1.navigable!==S){const R=Lm(e,E.modelId,S);if(R){const H=on(E.modelId,"end1",{...k.patch,...R.endPatch}),P=$u({logical:e,layout:Om},[...R.cmds,H]);s.push(...P.ops);break}}}const A=So(k.patch,x_,["jpa."]);if(A.length){c.push({code:"association-end-patch-unknown-key",opIndex:C,handle:k.association,keys:A});break}s.push({kind:"associationEnd.update",casUnit:"logical",containerRef:E.modelId,associationRef:E.modelId,end:v,patch:k.patch}),N.endPatches.push({associationRef:E.modelId,end:v,patch:k.patch});break}case"index.add":{{const A=bn(k.spec,Wm);if(A.length){c.push({code:"index-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:A});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=Qm(E.value,k.spec,C,k.entity,c,a);if(!v)break;s.push({kind:"index.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.modelId,value:v});break}case"index.update":case"index.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(fs(k.index)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:k.index,target:"index"});break}const v=N_(E.value,k.index);if(!v.ok){c.push(v.reason==="not-found"?{code:"index-not-found",opIndex:C,entity:k.entity,handle:k.index}:{code:"index-ambiguous",opIndex:C,entity:k.entity,handle:k.index,matches:v.matches});break}if(k.kind==="index.update"){if("columns"in k.patch){c.push({code:"index-columns-patch-unsupported",opIndex:C,entity:k.entity,handle:k.index});break}const A=So(k.patch,$_);if(A.length){c.push({code:"index-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.index,keys:A});break}s.push({kind:"index.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.value.modelId,patch:k.patch})}else s.push({kind:"index.remove",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,indexRef:v.value.modelId});break}case"operation.add":{{const S=bn(k.spec,Jm);if(S.length){c.push({code:"operation-spec-unknown-key",opIndex:C,entity:k.entity,handle:{ref:k.spec.name},keys:S});break}}const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}const v=p.get(E.value.modelId)??(E.value.operations?Yt(E.value.operations):0);p.set(E.value.modelId,v+1);const A=Zm(k.spec,v,a);s.push({kind:"operation.add",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:A.modelId,value:A});break}case"operation.update":case"operation.remove":{const E=Tt(e,k.entity);if(!E.ok){c.push(Mt(E.reason,C,k.entity,E.matches,I));break}if(fs(k.operation)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:k.operation,target:"operation"});break}const v=Hm(E.value,k.operation);if(!v.ok){c.push(v.reason==="not-found"?{code:"operation-not-found",opIndex:C,entity:k.entity,handle:k.operation}:{code:"operation-ambiguous",opIndex:C,entity:k.entity,handle:k.operation,matches:v.matches});break}if(k.kind==="operation.update"){const A=So(k.patch,T_);if(A.length){c.push({code:"operation-patch-unknown-key",opIndex:C,entity:k.entity,handle:k.operation,keys:A});break}s.push({kind:"operation.update",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:v.value.modelId,patch:k.patch})}else s.push({kind:"operation.remove",casUnit:"logical",containerRef:E.value.modelId,entityRef:E.value.modelId,operationRef:v.value.modelId});break}case"attribute.reorder":case"operation.reorder":{const E=k.kind==="attribute.reorder",v=Tt(e,k.entity);if(!v.ok){c.push(Mt(v.reason,C,k.entity,v.matches,I));break}const A=E?k.order:k.operations;if(A.length===0){c.push({code:"reorder-empty",opIndex:C,entity:k.entity});break}const S=[],R=new Set;let H=!1;for(const X of A){if(!E&&fs(X)){c.push({code:"handle-by-unsupported",opIndex:C,entity:k.entity,handle:X,target:"operation"}),H=!0;continue}const J=E?Fm(v.value,X):Hm(v.value,X);if(!J.ok){c.push(J.reason==="not-found"?{code:"reorder-handle-not-found",opIndex:C,entity:k.entity,handle:X}:{code:"reorder-handle-ambiguous",opIndex:C,entity:k.entity,handle:X,matches:J.matches}),H=!0;continue}if(R.has(J.value.modelId)){c.push({code:"reorder-handle-duplicate",opIndex:C,entity:k.entity,handle:X}),H=!0;continue}R.add(J.value.modelId),S.push(J.value)}if(H)break;const L=[...E?v.value.attributes:v.value.operations??[]].sort((X,J)=>X.order-J.order).filter(X=>!R.has(X.modelId)),j=[...S,...L];if(j.forEach((X,J)=>{X.order!==J&&s.push(E?{kind:"attribute.update",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,attributeRef:X.modelId,patch:{order:J}}:{kind:"operation.update",casUnit:"logical",containerRef:v.value.modelId,entityRef:v.value.modelId,operationRef:X.modelId,patch:{order:J}})}),E)for(const X of Cm(e,v.value.modelId,j.map(J=>J.modelId)))s.push({kind:"attribute.update",casUnit:"logical",containerRef:X.entityId,entityRef:X.entityId,attributeRef:X.attributeId,patch:{dbAttrs:X.dbAttrs}});break}case"group.add":{{const R=bn(k.spec,S_);if(R.length){c.push({code:"group-spec-unknown-key",opIndex:C,keys:R});break}}const E=[];let v=!1;for(const R of k.spec.members){const H=Tt(e,R);if(!H.ok){c.push(Mt(H.reason,C,R,H.matches,I)),v=!0;continue}E.push(H.value.modelId)}if(v)break;const A=a(),S={modelId:A,excludeDDLGeneration:k.spec.excludeDDLGeneration??!1,memberEntityRefs:E,...k.spec.name?{name:k.spec.name}:{},...k.spec.packageName?{packageName:k.spec.packageName}:{},...k.spec.description?{description:k.spec.description}:{}};s.push({kind:"group.add",casUnit:"logical",groupRef:A,value:S});break}case"group.update":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}const v=So(k.patch,y_);if(v.length){c.push({code:"group-patch-unknown-key",opIndex:C,handle:k.group,keys:v});break}s.push({kind:"group.update",casUnit:"logical",containerRef:E.value.modelId,groupRef:E.value.modelId,patch:k.patch});break}case"group.remove":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}s.push({kind:"group.remove",casUnit:"logical",groupRef:E.value.modelId});break}case"group.addMember":case"group.removeMember":{const E=us(e,k.group);if(!E.ok){c.push(ms(E,C,k.group));break}const v=Tt(e,k.entity);if(!v.ok){c.push(Mt(v.reason,C,k.entity,v.matches,I));break}const A=E.value.memberEntityRefs.includes(v.value.modelId);if(k.kind==="group.addMember"?A:!A)break;if(k.kind==="group.removeMember"){if(b.has(w(E.value.modelId,v.value.modelId)))break;b.add(w(E.value.modelId,v.value.modelId))}s.push({kind:k.kind,casUnit:"logical",containerRef:E.value.modelId,groupRef:E.value.modelId,entityRef:v.value.modelId});break}}}),c.length||P_(s,e,y,g,h,_,N,a,f),c.length||B_(s,e,h,y),c.length||D_(s,e,h,_,y,a),c.length?{ok:!1,errors:c}:d.length?{ok:!0,ops:s,notices:d}:{ok:!0,ops:s}}function Mt(e,n,o,i,a){return e==="shape"?{code:"handle-shape-invalid",opIndex:n,where:"entity",expected:"{ref, by?}",got:hs(o)}: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}}const er=e=>!!e&&typeof e=="object"&&typeof e.ref=="string",q_=e=>!!e&&typeof e=="object"&&er(e.from)&&er(e.to),hs=e=>e===void 0?"undefined":e===null?"null":typeof e!="object"?typeof e:`{${Object.keys(e).join(",")}}`;function Y_(e,n,o){const i=e,a=[];for(const l of["attribute","index","operation","group"])l in i&&a.push([l,i[l],er(i[l])]);(e.kind==="association.update"||e.kind==="association.remove"||e.kind==="associationEnd.update")&&a.push(["association",i.association,q_(i.association)]);let r=!0;for(const[l,s,c]of a)c||(r=!1,o.push({code:"handle-shape-invalid",opIndex:n,where:l,expected:l==="association"?"{from:{ref}, to:{ref}}":"{ref, by?}",got:hs(s)}));return r}function nf(e,n,o,i,a){const r=Tt(e,n.from),l=Tt(e,n.to);if(r.ok||i.push(Mt(r.reason,o,n.from,r.matches,a)),l.ok||i.push(Mt(l.reason,o,n.to,l.matches,a)),!r.ok||!l.ok)return null;const s=zm(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 of={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},W_={type:"object",description:"엔티티 내 이름으로 지정(인덱스명·메서드명). 물리명 차원이 없어 매칭 키 고정(`by`)을 받지 않는다.",properties:{ref:{type:"string",description:"매칭할 이름."}},required:["ref"],additionalProperties:!1},J_={type:"object",description:"관계는 무명이라 양 끝 엔티티로 주소. from=부모(end1), to=자식(end2). 같은 쌍 복수 관계는 모호 보고.",properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"}},required:["from","to"],additionalProperties:!1},an={type:"object",properties:{ko:{type:"string"},en:{type:"string"},ja:{type:"string"},zh:{type:"string"}},additionalProperties:!1},X_={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."},classLogicalName:{...an,description:"**클래스** 논리명(다국어). 테이블이 없는 자리(직렬화 타입 SERIALIZED_TYPE)의 논리명이 여기 산다 — 그 타입은 table 자체를 갖지 않아 table.logicalName 을 줄 데가 없다. ⚠️테이블이 있는 엔티티는 table.logicalName 이 이기므로 그쪽을 쓴다."},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},Z_={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},Q_={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:{...an,description:"속성 설명(다국어)."},columnLogicalName:{...an,description:'dbAttr 컬럼 논리명(다국어, 예: {ko:"체크아웃유형"}). 한글 업무명 보존 위치.'},fieldLogicalName:{...an,description:"**필드** 논리명(다국어). 평탄 `logicalName`(컬럼 논리명)과 **다른 축**이다 — 컬럼이 없는 자리(직렬화 타입 SERIALIZED_TYPE 의 자기 필드)는 dbAttrs 가 0이라 컬럼 논리명을 줄 데가 없고, 그 자리의 논리명이 여기 산다(캔버스 논리 뷰·탐색기 검색·코드젠 javadoc 이 읽는다). 컬럼이 있는 자리에서는 컬럼 논리명이 이긴다."},unique:{type:"boolean",description:"dbAttr UNIQUE 제약."},updatable:{type:"boolean",description:"dbAttr 갱신 가능(JPA @Column(updatable=))."},sequenceName:{type:"string",description:"dbAttr 채번 시퀀스명. **비PK·autoIncrement 없는 컬럼**에 주면 «애플리케이션 채번»(DB 는 CREATE SEQUENCE 만 · 값은 채번기가 접두어를 입혀 생성) — 여러 속성이 **같은 이름을 공유**해도 정상(공유 채번기 · /text 의 `sequence=` 로 기존 이름 확인). 컬럼 생성 트리거 필드(dataType 동반)."},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},eE={type:"array",description:"predefined 임베더블 서브컬럼 오버라이드(속성 type이 카탈로그 엔트리이자 EMBED_PREDEF일 때만). field=카탈로그 필드명으로 매칭(@AttributeOverride 대응). 미설정 서브컬럼은 add=카탈로그 기본 상속 / update=기존값 유지. currency 등 공유 컬럼은 sharedColumnPhysicalName으로 SHARED_REF. ⚠️바인딩 축만 덮는다 — 서브컬럼 **논리명**은 여기 없고 patch의 dotted `dbAttrs.<i>.logicalName`이 받는다.",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 컬럼에만 저장."},notNull:{type:"boolean",description:"JPA @Column(nullable=false) — **이 서브컬럼 하나의** NOT NULL. 미설정이면 속성 축(notNull)을 따른다. ★임베더블은 컬럼마다 제약이 갈릴 수 있어(실측: ChangedBy 는 type 컬럼만 NOT NULL) 속성 축 하나로는 담기지 않는다. OWN 컬럼에만 저장."},sharedColumnPhysicalName:{type:"string",description:"SHARED_REF — 같은 엔터티(임베더블이면 owner 합집합) 다른 컬럼(물리명)을 공유해 read-only 투영(대표: currency). 설정 시 자체 컬럼 미보유, 타깃은 해소 시점 존재 필수."}},required:["field"],additionalProperties:!1}},af={type:"string",enum:["NO_INSTANCE_OR_ONE_INSTANCE","EXACTLY_ONE_INSTANCE","ZERO_OR_MORE_INSTANCES","ONE_OR_MORE_INSTANCES"]},tE={type:"object",description:'연관 생성. **to 가 임베더블(JPA_EMBEDDABLE)이면 EMBED 관계로 생성된다** — owner(from)에 EMBED_OWN 표시 속성이 생기고 컬럼은 임베더블 선언에서 평탄화되므로 따로 주지 않는다. 단일/컬렉션은 toMultiplicity 로 가른다(0..*·1..* = @ElementCollection). EMBED 일 때 identifying·composition·fromMultiplicity 는 성립하지 않아 거부된다(embed-spec-inapplicable). from 만 임베더블이면 거부된다 — 임베더블은 테이블·PK 가 없어 FK 부모가 될 수 없다. 임베더블이 다른 임베더블을 품는 연쇄는 정당하고, 순환(자기·간접)만 거부된다(embed-self-unsupported·embed-cycle-unsupported). 직렬화 타입은 관계가 아니라 소비 속성의 type 으로 지목한다(attribute.update {type: "<타입명>"}).',properties:{from:{$ref:"#/$defs/handle"},to:{$ref:"#/$defs/handle"},fromMultiplicity:{...af,description:"end1 다중성(기본 EXACTLY_ONE_INSTANCE). EMBED 에는 성립하지 않는다."},toMultiplicity:{...af,description:"end2 다중성. FK 기본은 ZERO_OR_MORE_INSTANCES 이지만 **EMBED 기본은 EXACTLY_ONE_INSTANCE** 다. EMBED 에서 0..*·1..* 는 @ElementCollection(컬럼이 owner 가 아니라 임베더블에 남는다), 1·0..1 은 단일 @Embedded."},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK로 전파). self-association은 식별 불가. EMBED 에는 성립하지 않는다."},composition:{type:"boolean",description:"end2 composition. EMBED 는 항상 true 라 지정 대상이 아니다."}},required:["from","to"],additionalProperties:!1},nE={type:"object",properties:{name:{type:"string"},unique:{type:"boolean",description:"UNIQUE 인덱스 여부(기본 false)."},columns:{type:"array",description:"인덱스 컬럼(순서 의미 있음).",items:{type:"object",properties:{column:{...of,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},oE={type:"object",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"],description:"가시성(기본 미설정)."},sourceCode:{type:"string",description:"Java 메서드 본문(멀티라인, 파라미터·반환 시그니처 포함)."},description:{...an,description:"메서드 설명(다국어)."},personalInfoAttributeType:{type:"string",description:"개인정보 속성 유형(패스스루)."}},required:["name"],additionalProperties:!1},iE={type:"object",properties:{name:{...an,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},aE={type:"object",description:'기존 속성 부분 patch. 논리 필드 + 스칼라 단일 컬럼의 물리 필드(physicalName·dataType·length·scale 등 — 서버가 dbAttrs[0]에 매핑). ⚠️평탄 물리 키는 **attrType 이 NORMAL 이고 컬럼이 하나일 때만** 매핑된다 — FK 파생(RELATION_*)·임베드·직렬화 타입 자리에서는 거부되고 **dotted 로 지목**해야 한다(`{"dbAttrs.0.physicalName":"…"}`). EMBED_PREDEF/Money 서브컬럼 «바인딩» 조정만 op-레벨 embeddableOverrides 소관이다(그 배열엔 논리명·dataType 축이 없다). ★다중 컬럼 속성의 **개별 컬럼 필드**는 dotted 키로 지목한다 — `{"dbAttrs.<i>.logicalName":{ko:"…"}}` 처럼. dotted 허용 접두는 `dbAttrs.` 하나뿐이고, 같은 op에서 평탄 키와 섞으면 $set 충돌로 거부된다. ⚠️★**NORMAL 속성의 컬럼을 둘 이상으로 늘릴 수 없다**(dbAttrs 배열 교체·없는 dotted 슬롯 둘 다 거부 — attribute-column-count-unsupported). 다중 컬럼이 필요하면 **임베더블 엔터티를 만들고 association.add 로 연결**한다(EMBED) — 컬럼은 그 선언에서 파생된다.',properties:{name:{type:"string"},type:{type:"string",description:"자바 타입. **컬럼 개수가 바뀌는 전환만 거부된다**(임베더블 타입으로 1→N, 임베더블을 다른 타입으로 N→1). 그 전환은 attribute.remove + attribute.add 로 내고(자리를 지키려면 같은 배치에 attribute.reorder). ★반대로 **개수가 같은 값 타입 재지정은 이 patch 하나로 된다** — 1컬럼 속성을 1필드 임베더블로 바꾸는 등. attrType은 목적지에서 파생되므로 생략해도 되고(EMBED_PREDEF로 자동), 실어 보내면 그 파생값과 같아야 한다. dbAttrs는 modelId째 보존되어 물리명·논리명·길이·인덱스 ref·order가 그대로 살아남는다. 임베드 서브컬럼 «바인딩» 조정만 embeddableOverrides 소관이다."},customType:{type:"string"},attrType:{type:"string",enum:[...wm],description:"속성 종류. **현재 값과 다르게 주면 거부된다** — 관계/임베드/구분선은 동반 구조(관계 소유·embedded·빈 dbAttrs)가 있어야 성립하고 patch로는 표현할 수 없다. 관계 실체화는 association.add, 임베드 서브컬럼은 embeddableOverrides 소관. ★예외 하나 — 같은 patch의 type이 «컬럼 개수가 같은» 임베더블을 가리키면 NORMAL→EMBED_PREDEF 동반 전환이 허용된다(생략해도 파생된다)."},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:{...an,description:"속성 설명(다국어)."},fieldLogicalName:{...an,description:"**필드** 논리명(다국어). 평탄 `logicalName`(컬럼 논리명)과 **다른 축**이다 — 컬럼이 없는 자리(직렬화 타입 SERIALIZED_TYPE 의 자기 필드)는 dbAttrs 가 0이라 컬럼 논리명을 줄 데가 없고, 그 자리의 논리명이 여기 산다(캔버스 논리 뷰·탐색기 검색·코드젠 javadoc 이 읽는다). 컬럼이 있는 자리에서는 컬럼 논리명이 이긴다."},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",description:"채번 시퀀스명 — autoIncrement 없이 주면 애플리케이션 채번(공유 가능). attribute.add 의 같은 필드 설명 참조."},logicalName:{...an,description:"**컬럼** 논리명(다국어). 대상이 스칼라 단일 컬럼일 때 dbAttrs[0]에 매핑된다. ★대상이 **다중 컬럼**(EMBED_PREDEF·Money 등)이면 이 평탄 키는 «어느 컬럼인지 모호» 로 거부되고, dotted `dbAttrs.<i>.logicalName` 이 그 값을 받는다(embeddableOverrides 에는 논리명 축이 없다). dbAttrs 가 0인 속성(직렬화 타입 필드·transient)에 주면 거부되고, 그 자리는 `fieldLogicalName` 이 받는다."}},additionalProperties:!1},rE={type:"object",description:"관계 부분 patch. 양 end 설정(multiplicity·nav·jpa)은 associationEnd.update로.",properties:{description:{type:"string"},identifying:{type:"boolean",description:"식별 관계(부모 PK가 자식 PK 일부로 전파)."}},additionalProperties:!1},lE={type:"object",description:"인덱스 부분 patch. columns(컬럼 구성) 변경은 index.remove+index.add로(패치 불가).",properties:{name:{type:"string"},unique:{type:"boolean"},description:{type:"string"},parameters:{type:"string"}},additionalProperties:!1},sE={type:"object",description:"메서드 부분 patch.",properties:{name:{type:"string"},visibility:{type:"string",enum:["PUBLIC","PRIVATE","PROTECTED","PACKAGE"]},sourceCode:{type:"string"},description:{...an,description:"메서드 설명(다국어)."},order:{type:"integer"},personalInfoAttributeType:{type:"string"}},additionalProperties:!1},cE={type:"object",description:'엔티티 부분 patch. 논리 키: name·stereotype·packageName·superClass·schema·description·abstractClass·hasPersonalInfo·referenceOnly·declarationOfInterfaces·table·serialization·classLogicalName. classLogicalName = **클래스** 논리명(테이블 없는 직렬화 타입의 논리명이 사는 곳 — 그 타입은 table 을 갖지 않는다). 테이블이 있는 엔티티는 table.logicalName(dotted-key)이 이긴다. 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 소관).'},dE={type:"object",description:'관계 end 부분 patch. 논리 키: multiplicity·navigable·composition. jpa 설정(cascadeTypes·fetchType·orphanRemoval·orderBy·collectionType·collectionTable·orderColumn)은 형제 클로버 방지를 위해 dotted-key로: {"jpa.orphanRemoval": true}.'};function pt(e,n){return{type:"object",properties:{kind:{const:e},...n.properties},required:["kind",...n.required],additionalProperties:!1}}const uE={"entity.add":pt("entity.add",{properties:{spec:{$ref:"#/$defs/entitySpec"}},required:["spec"]}),"entity.update":pt("entity.update",{properties:{entity:{$ref:"#/$defs/handle"},patch:{$ref:"#/$defs/entityUpdatePatch"}},required:["entity","patch"]}),"entity.remove":pt("entity.remove",{properties:{entity:{$ref:"#/$defs/handle"}},required:["entity"]}),"attribute.add":pt("attribute.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/attrSpec"}},required:["entity","spec"]}),"attribute.update":pt("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":pt("attribute.remove",{properties:{entity:{$ref:"#/$defs/handle"},attribute:{$ref:"#/$defs/handle"}},required:["entity","attribute"]}),"association.add":pt("association.add",{properties:{spec:{$ref:"#/$defs/assocSpec"}},required:["spec"]}),"association.remove":pt("association.remove",{properties:{association:{$ref:"#/$defs/assocHandle"}},required:["association"]}),"association.update":pt("association.update",{properties:{association:{$ref:"#/$defs/assocHandle"},patch:{$ref:"#/$defs/assocUpdatePatch"}},required:["association","patch"]}),"associationEnd.update":pt("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":pt("index.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/indexSpec"}},required:["entity","spec"]}),"index.update":pt("index.update",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/indexUpdatePatch"}},required:["entity","index","patch"]}),"index.remove":pt("index.remove",{properties:{entity:{$ref:"#/$defs/handle"},index:{$ref:"#/$defs/nameHandle"}},required:["entity","index"]}),"operation.add":pt("operation.add",{properties:{entity:{$ref:"#/$defs/handle"},spec:{$ref:"#/$defs/operationSpec"}},required:["entity","spec"]}),"operation.update":pt("operation.update",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"},patch:{$ref:"#/$defs/operationUpdatePatch"}},required:["entity","operation","patch"]}),"operation.remove":pt("operation.remove",{properties:{entity:{$ref:"#/$defs/handle"},operation:{$ref:"#/$defs/nameHandle"}},required:["entity","operation"]}),"attribute.reorder":pt("attribute.reorder",{properties:{entity:{$ref:"#/$defs/handle"},order:{type:"array",items:{$ref:"#/$defs/handle"}}},required:["entity","order"]}),"operation.reorder":pt("operation.reorder",{properties:{entity:{$ref:"#/$defs/handle"},operations:{type:"array",items:{$ref:"#/$defs/nameHandle"}}},required:["entity","operations"]}),"group.add":pt("group.add",{properties:{spec:{$ref:"#/$defs/groupSpec"}},required:["spec"]}),"group.update":pt("group.update",{properties:{group:{$ref:"#/$defs/groupHandle"},patch:{$ref:"#/$defs/groupUpdatePatch"}},required:["group","patch"]}),"group.remove":pt("group.remove",{properties:{group:{$ref:"#/$defs/groupHandle"}},required:["group"]}),"group.addMember":pt("group.addMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]}),"group.removeMember":pt("group.removeMember",{properties:{group:{$ref:"#/$defs/groupHandle"},entity:{$ref:"#/$defs/handle"}},required:["group","entity"]})},mE={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},fE={type:"object",description:"그룹 부분 patch. 멤버 변경은 group.addMember/removeMember로(배열 통째 교체는 동시 편집이 서로를 덮는다).",properties:{name:{...an,description:"그룹 논리명(다국어)."},packageName:{type:"string"},description:{type:"string"},excludeDDLGeneration:{type:"boolean"}},additionalProperties:!1},rf={anyOf:Nm.map(e=>uE[e])},pE={type:"object",description:"엔티티 모델을 생성·수정·삭제할 때 호출한다. ops는 사람 핸들(엔티티 물리명/논리명, 속성명)로 지정하며 서버가 modelId로 해소한다. 모호하면 에러로 후보를 돌려주니 리소스로 현재 모델을 먼저 읽어 핸들을 확정하라.",properties:{ops:{type:"array",items:{$ref:"#/$defs/symbolicOp"}}},required:["ops"],additionalProperties:!1,$defs:{handle:of,nameHandle:W_,groupHandle:mE,assocHandle:J_,entitySpec:X_,serialization:Z_,attrSpec:Q_,embeddableOverrides:eE,assocSpec:tE,indexSpec:nE,operationSpec:oE,groupSpec:iE,entityUpdatePatch:cE,attrUpdatePatch:aE,assocUpdatePatch:rE,assocEndUpdatePatch:dE,indexUpdatePatch:lE,operationUpdatePatch:sE,groupUpdatePatch:fE,symbolicOp:rf}};function hE(e,n,o,i={}){const a=i.mkClientOpId??Fe,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 lf={location:{x:0,y:0},size:{width:220,height:140}};function sf(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,notNull:e.notNull,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}const yE=/^[-=_*~\s]{3,}$/;function gE(e){return e.attrType&&e.attrType!=="NORMAL"||!yE.test(e.name??"")?!1:!(e.dbAttrs??[]).some(n=>n.physicalName||n.dataType)}function bE(e){return e.type===hn&&e.customType==="java.util.Currency"?{type:"Currency",customType:void 0}:{type:e.type,customType:e.customType}}function kE(e,n){if(e.attrType==="DIVIDER"||gE(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=bE(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(sf)}}function _E(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 EE(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 NE(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(kE),operations:(n=e.operations)==null?void 0:n.map(_E),indexes:(o=e.indexes)==null?void 0:o.map(EE),jpaAttrs:e.jpaAttrs,table:e.dbAttrs?{physicalName:e.dbAttrs.physicalName,logicalName:e.dbAttrs.logicalName}:void 0}}function wE(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??{...lf},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 cf(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 ys(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:cf(e)}}function IE(e){if(e.end1.endModel.refId===e.end2.endModel.refId)return;const n=o=>gs(o)&&(o==null?void 0:o.identifier)===!0;return n(e.end1.attribute)||n(e.end2.attribute)?!0:void 0}function vE(e){var i,a;const n={modelId:e.modelId,description:e.description,identifying:IE(e),end1:ys(e.end1),end2:ys(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 gs(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("RELATION")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function df(e){var n;return!!e&&typeof e.attrType=="string"&&e.attrType.startsWith("EMBED")&&(((n=e.dbAttrs)==null?void 0:n.length)??0)>0}function uf(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 mf(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(sf)}}function CE(e,n,o){var w,I;const i=gs(e.end1.attribute),a=gs(e.end2.attribute);if(i===a)return vE(e);const r=i?e.end1:e.end2,l=i?e.end2:e.end1,s=r.attribute,c=(I=(w=s.dbAttrs)==null?void 0:w[0])==null?void 0:I.targetModelId,d=c?o.get(c):void 0,u=n.get(l.endModel.refId),m=u?u.attributes.reduce(($,k)=>Math.max($,k.order),-1)+1:s.order??0,f={...mf(s,m),attrType:"RELATION_OWN",derivedFrom:d?{associationRef:e.modelId,sourceAttributeRef:d}:void 0};u&&u.attributes.push(f);const p=n.get(r.endModel.refId),g=l.attribute;let y;if(g&&p&&r.navigable){const $=Ea(l.multiplicity);y={modelId:g.modelId??crypto.randomUUID(),name:yo(g.name??wa((u==null?void 0:u.name)??l.endModel.refId,$),new Set(p.attributes.map(k=>k.name))),type:(u==null?void 0:u.name)??l.endModel.refId,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:p.attributes.reduce((k,C)=>Math.max(k,C.order),-1)+1,dbAttrs:[]},p.attributes.push(y)}const h=($,k)=>({entityRef:$.endModel.refId,multiplicity:$.multiplicity,navigable:$.navigable,composition:$.composition,attributeRef:k?y==null?void 0:y.modelId:f.modelId,jpa:cf($)}),_=r.endModel.refId===l.endModel.refId,N={modelId:e.modelId,description:e.description,identifying:!_&&f.identifier===!0?!0:void 0,end1:h(e.end1,i),end2:h(e.end2,a)},b={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:i?d:f.modelId,targetColumnRef:i?f.modelId:d,style:e.style};return{assoc:N,layout:b}}function SE(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),notNull:e.notNull??(o==null?void 0:o.notNull)}}function RE(e,n,o){var g;const i=((g=e.end1.attribute)==null?void 0:g.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((y,h)=>Math.max(y,h.order),-1)+1:l.order??0,d={...mf(l,c),attrType:l.attrType??"EMBED_OWN",dbAttrs:(l.dbAttrs??[]).map(y=>SE(y,o)),embedded:{associationRef:e.modelId,embeddableRef:a.endModel.refId}};s&&s.attributes.push(d);const u=y=>({...ys(y),legacyEmbedRaw:y.attribute}),m={modelId:e.modelId,description:e.description,end1:u(e.end1),end2:u(e.end2)},f=!i,p={associationRef:e.modelId,waypoints:e.locations??[],sourceColumnRef:f?d.modelId:void 0,targetColumnRef:f?void 0:d.modelId,style:e.style};return{assoc:m,layout:p}}function AE(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 ff(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=AE(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 pf(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 hf(e,n){const o=(i,a)=>{if(i==null)return;const r=i[a];if(r==null)return;const l=Xc(r);l!==r&&(l===void 0?delete i[a]:i[a]=l)};for(const i of n)o(i,"name");for(const i of e){o(i,"classLogicalName"),o(i,"description"),o(i.table,"logicalName");for(const a of i.operations??[])o(a,"description");for(const a of i.attributes){o(a,"fieldLogicalName"),o(a,"description");for(const r of a.dbAttrs??[])o(r,"logicalName")}}}function xE(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||at(a.stereotype)||at(r.stereotype))continue;const l=i.end1.attributeRef?a.attributes.find(f=>f.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(f=>f.modelId===s);if((c==null?void 0:c.attrType)==="RELATION_REF"){i.end1.attributeRef=s;continue}const d=Ea(i.end2.multiplicity),u=wa(r.name,d),m=yo(u,new Set(a.attributes.map(f=>f.name)));a.attributes.push({modelId:s,name:m,type:r.name,attrType:"RELATION_REF",identifier:!1,notNull:!1,order:a.attributes.reduce((f,p)=>Math.max(f,p.order),-1)+1,dbAttrs:[]}),i.end1.attributeRef=s}}function $E(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||at(a.stereotype)||at(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 yf(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&&at(l.stereotype))continue;const s=a.end1.entityRef===a.end2.entityRef,c=a.identifying===!0||!s&&!Ed(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 gf(e){const n=JSON.parse(JSON.stringify(e));return(n.schemaVersion??1)>=2&&"logical"in n?TE(n):ME(n)}function TE(e){const n=e.id??e.logical.modelId??"",o={},i=m=>{const{rev:f,...p}=m;return f!=null&&(o[m.modelId]=f),p},a=e.logical.entities.map(i),r=e.logical.associations.map(i),l=e.logical.groups.map(i);xE(a,r),$E(a,r),yf(a,r),hf(a,l);const{version:s,...c}=e.layout;pf(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 ME(e){var _,N;const n=e.id??"",o=[],i=[],a=[],r=[],l=[],s=[],c=[],d=(b,w)=>{o.push(NE(b));const I=wE(b);I.geo={location:{x:I.geo.location.x+w.x,y:I.geo.location.y+w.y},size:I.geo.size},i.push(I);for(const $ of b.ownedAssociations??[])c.push($)},u={x:0,y:0};for(const b of e.entities??[])d(b,u);const m=[];for(const b of e.groups??[]){const w=b.entities??[];l.push({modelId:b.modelId,name:b.name,description:b.description,packageName:b.packageName,excludeDDLGeneration:b.excludeDDLGeneration??!1,memberEntityRefs:w.map($=>$.modelId)});const I=((_=b.geo)==null?void 0:_.location)??u;if(b.geo){const $=(b.notes??[]).map(k=>k.modelId);s.push({groupRef:b.modelId,geo:b.geo,style:b.style,locked:b.locked,memberNoteRefs:$.length?$:void 0})}for(const $ of w)d($,I);for(const $ of b.notes??[])m.push(ff($,I))}const f=new Map(o.map(b=>[b.modelId,b])),p=new Map,g=new Map;for(const b of o)for(const w of b.attributes)for(const I of w.dbAttrs)p.set(I.modelId,w.modelId),g.set(I.modelId,I);for(const b of c)for(const w of[b.end1,b.end2]){const I=w.attribute;if(I&&(((N=I.dbAttrs)==null?void 0:N.length)??0)>0)for(const $ of I.dbAttrs)$.modelId&&p.set($.modelId,I.modelId)}for(const b of c){const w=df(b.end1.attribute),I=df(b.end2.attribute),$=uf(b.end1)||uf(b.end2),{assoc:k,layout:C}=w!==I||$?RE(b,f,g):CE(b,f,p);a.push(k),r.push(C)}pf(o,a,r),wu(o),yf(o,a),hf(o,l);const y={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(b=>ff(b)),...m]}},h={id:e.id,version:e.version,diagramVersion:e.diagramVersion,size:e.size,packageName:e.packageName,schemaVersion:e.schemaVersion??1};return{state:y,meta:h}}function bf(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,notNull:e.notNull,sharedColumnRef:e.sharedColumnRef,multiValue:e.multiValue,multiValueSeparator:e.multiValueSeparator,sequenceName:e.sequenceName}}function VE(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(bf),style:n}}function LE(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 BE(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 Qn(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 DE(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{...bf(i),targetModelId:(r=o==null?void 0:o.dbAttrs[a])==null?void 0:r.modelId}})}}function OE(e){return{modelId:e.modelId,name:e.name,type:e.type,attrType:"RELATION_OWN",dbAttrs:[]}}function kf(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 PE(e){const n=new Set;for(const o of e.logical.associations){const i=kf(o,e);i&&(n.add(i.navAttr.modelId),i.fk&&n.add(i.fk.modelId))}return n}function zE(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 FE(e,n){return e===n||JSON.stringify(e??null)===JSON.stringify(n??null)}function UE(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:FE(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),notNull:o(e.notNull,n==null?void 0:n.notNull)}}function HE(e,n,o){let i;for(const m of n.logical.entities){const f=m.attributes.find(p=>{var g;return((g=p.embedded)==null?void 0:g.associationRef)===e.modelId});if(f){i=f;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,f)=>UE(m,l[f]))},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:Qn(e.end1,c?s:u),end2:Qn(e.end2,c?u:s)}}function jE(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:Qn(e.end1,e.end1.legacyEmbedRaw),end2:Qn(e.end2,e.end2.legacyEmbedRaw)};const a=HE(e,n,i);if(a)return a;const r=kf(e,n);if(r){const l=n.logical.entities.find(d=>d.modelId===r.navEnd.entityRef),s=r.fk?DE(r.fk,l):void 0,c=OE(r.navAttr);return{...i,end1:Qn(e.end1,r.navEnd===e.end1?s:c),end2:Qn(e.end2,r.navEnd===e.end2?s:c)}}return{...i,end1:Qn(e.end1),end2:Qn(e.end2)}}function _f(e,n,o,i,a={x:0,y:0}){var u,m;const r=n.layout.entityLayouts.find(f=>f.entityRef===e.modelId),l=n.logical.associations.filter(f=>f.end1.entityRef===e.modelId),s=f=>n.layout.associationLayouts.find(p=>p.associationRef===f),c=(r==null?void 0:r.geo)??{...lf},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(f=>!o.has(f.modelId)&&!i.has(f.modelId)).map(f=>{var p;return VE(f,(p=r==null?void 0:r.attributeStyles)==null?void 0:p[f.modelId])}),operations:(u=e.operations)==null?void 0:u.map(f=>{var p;return LE(f,(p=r==null?void 0:r.operationStyles)==null?void 0:p[f.modelId])}),ownedAssociations:l.map(f=>jE(f,n,s(f.modelId))),indexes:(m=e.indexes)==null?void 0:m.map(BE),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 KE(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=>Ef(c,l));return{modelId:e.modelId,name:e.name,description:e.description,packageName:e.packageName,excludeDDLGeneration:e.excludeDDLGeneration,entities:r.map(c=>_f(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 Ef(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 GE(e,n={}){const o=new Set(e.logical.groups.flatMap(s=>s.memberEntityRefs)),i=e.logical.entities.filter(s=>!o.has(s.modelId)),a=PE(e),r=zE(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=>_f(s,e,a,r)),groups:e.logical.groups.map(s=>KE(s,e,a,r)),notes:e.layout.notes.filter(s=>!l.has(s.modelId)).map(s=>Ef(s))}}function qE(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 YE=["notNull"];function WE(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}=gf(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(f=>[f.modelId,f]))]));for(const m of i.logical.entities){const f=c.get(m.modelId);if(f)for(const p of m.attributes){const g=f.get(p.modelId);if(!g){l.push({kind:"attribute.add",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,value:p}),s.navAdds++;continue}const y={};for(const h of YE)p[h]===!0!=(g[h]===!0)&&(y[h]=p[h],s.attributeFieldsByName[h]=(s.attributeFieldsByName[h]??0)+1);Object.keys(y).length!==0&&(l.push({kind:"attribute.update",casUnit:"logical",containerRef:m.modelId,entityRef:m.modelId,attributeRef:p.modelId,patch:y}),s.attributeFieldPatches++)}}const d=new Map(o.logical.associations.map(m=>[m.modelId,m]));for(const m of i.logical.associations){const f=d.get(m.modelId);f&&(m.end1.attributeRef&&m.end1.attributeRef!==f.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&&f.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 Oi(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function Bn(e){return typeof e=="function"?e():t.unref(e)}const JE=typeof window<"u"&&typeof document<"u",XE=e=>typeof e<"u",ZE=Object.prototype.toString,QE=e=>ZE.call(e)==="[object Object]",eN=()=>{};function tN(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 Nf=e=>e();function nN(e=Nf){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 wf(e,n=!1,o="Timeout"){return new Promise((i,a)=>{setTimeout(n?()=>a(o):i,e)})}function oN(e,n,o={}){const{eventFilter:i=Nf,...a}=o;return t.watch(e,tN(i,n),a)}function oi(e,n,o={}){const{eventFilter:i,...a}=o,{eventFilter:r,pause:l,resume:s,isActive:c}=nN(i);return{stop:oN(e,n,{...a,eventFilter:r}),pause:l,resume:s,isActive:c}}function iN(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=Bn(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 bs(e,n=!1){function o(m,{flush:f="sync",deep:p=!1,timeout:g,throwOnTimeout:y}={}){let h=null;const N=[new Promise(b=>{h=t.watch(e,w=>{m(w)!==n&&(h==null||h(),b(w))},{flush:f,deep:p,immediate:!0})})];return g!=null&&N.push(wf(g,y).then(()=>Bn(e)).finally(()=>h==null?void 0:h())),Promise.race(N)}function i(m,f){if(!t.isRef(m))return o(w=>w===m,f);const{flush:p="sync",deep:g=!1,timeout:y,throwOnTimeout:h}=f??{};let _=null;const b=[new Promise(w=>{_=t.watch([e,m],([I,$])=>{n!==(I===$)&&(_==null||_(),w(I))},{flush:p,deep:g,immediate:!0})})];return y!=null&&b.push(wf(y,h).then(()=>Bn(e)).finally(()=>(_==null||_(),Bn(e)))),Promise.race(b)}function a(m){return o(f=>!!f,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,f){return o(p=>{const g=Array.from(p);return g.includes(m)||g.includes(Bn(m))},f)}function d(m){return u(1,m)}function u(m=1,f){let p=-1;return o(()=>(p+=1,p>=m),f)}return Array.isArray(Bn(e))?{toMatch:o,toContains:c,changed:d,changedTimes:u,get not(){return bs(e,!n)}}:{toMatch:o,toBe:i,toBeTruthy:a,toBeNull:r,toBeNaN:s,toBeUndefined:l,changed:d,changedTimes:u,get not(){return bs(e,!n)}}}function ks(e){return bs(e)}function aN(e){var n;const o=Bn(e);return(n=o==null?void 0:o.$el)!=null?n:o}const If=JE?window:void 0;function vf(...e){let n,o,i,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,i,a]=e,n=If):[n,o,i,a]=e,!n)return eN;Array.isArray(o)||(o=[o]),Array.isArray(i)||(i=[i]);const r=[],l=()=>{r.forEach(u=>u()),r.length=0},s=(u,m,f,p)=>(u.addEventListener(m,f,p),()=>u.removeEventListener(m,f,p)),c=t.watch(()=>[aN(n),Bn(a)],([u,m])=>{if(l(),!u)return;const f=QE(m)?{...m}:m;r.push(...o.flatMap(p=>i.map(g=>s(u,p,g,f))))},{immediate:!0,flush:"post"}),d=()=>{c(),l()};return Oi(d),d}function rN(e){return typeof e=="function"?e:typeof e=="string"?n=>n.key===e:Array.isArray(e)?n=>e.includes(n.key):()=>!0}function Cf(...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=If,eventName:r="keydown",passive:l=!1,dedupe:s=!1}=i,c=rN(n);return vf(a,r,u=>{u.repeat&&Bn(s)||c(u)&&o(u)},l)}function lN(e){return JSON.parse(JSON.stringify(e))}function _s(e,n,o,i={}){var a,r,l;const{clone:s=!1,passive:c=!1,eventName:d,deep:u=!1,defaultValue:m,shouldEmit:f}=i,p=t.getCurrentInstance(),g=o||(p==null?void 0:p.emit)||((a=p==null?void 0:p.$emit)==null?void 0:a.bind(p))||((l=(r=p==null?void 0:p.proxy)==null?void 0:r.$emit)==null?void 0:l.bind(p==null?void 0:p.proxy));let y=d;n||(n="modelValue"),y=y||`update:${n.toString()}`;const h=b=>s?typeof s=="function"?s(b):lN(b):b,_=()=>XE(e[n])?h(e[n]):m,N=b=>{f?f(b)&&g(y,b):g(y,b)};if(c){const b=_(),w=t.ref(b);let I=!1;return t.watch(()=>e[n],$=>{I||(I=!0,w.value=h($),t.nextTick(()=>I=!1))}),t.watch(w,$=>{!I&&($!==e[n]||u)&&N($)},{deep:u}),w}else return t.computed({get(){return _()},set(b){N(b)}})}var sN={value:()=>{}};function tr(){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 nr(o)}function nr(e){this._=e}function cN(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}})}nr.prototype=tr.prototype={constructor:nr,on:function(e,n){var o=this._,i=cN(e+"",o),a,r=-1,l=i.length;if(arguments.length<2){for(;++r<l;)if((a=(e=i[r]).type)&&(a=dN(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]=Sf(o[a],e.name,n);else if(n==null)for(a in o)o[a]=Sf(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 nr(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 dN(e,n){for(var o=0,i=e.length,a;o<i;++o)if((a=e[o]).name===n)return a.value}function Sf(e,n,o){for(var i=0,a=e.length;i<a;++i)if(e[i].name===n){e[i]=sN,e=e.slice(0,i).concat(e.slice(i+1));break}return o!=null&&e.push({name:n,value:o}),e}var Es="http://www.w3.org/1999/xhtml";const Rf={svg:"http://www.w3.org/2000/svg",xhtml:Es,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function or(e){var n=e+="",o=n.indexOf(":");return o>=0&&(n=e.slice(0,o))!=="xmlns"&&(e=e.slice(o+1)),Rf.hasOwnProperty(n)?{space:Rf[n],local:e}:e}function uN(e){return function(){var n=this.ownerDocument,o=this.namespaceURI;return o===Es&&n.documentElement.namespaceURI===Es?n.createElement(e):n.createElementNS(o,e)}}function mN(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Af(e){var n=or(e);return(n.local?mN:uN)(n)}function fN(){}function Ns(e){return e==null?fN:function(){return this.querySelector(e)}}function pN(e){typeof e!="function"&&(e=Ns(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 Gt(i,this._parents)}function hN(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function yN(){return[]}function xf(e){return e==null?yN:function(){return this.querySelectorAll(e)}}function gN(e){return function(){return hN(e.apply(this,arguments))}}function bN(e){typeof e=="function"?e=gN(e):e=xf(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 Gt(i,a)}function $f(e){return function(){return this.matches(e)}}function Tf(e){return function(n){return n.matches(e)}}var kN=Array.prototype.find;function _N(e){return function(){return kN.call(this.children,e)}}function EN(){return this.firstElementChild}function NN(e){return this.select(e==null?EN:_N(typeof e=="function"?e:Tf(e)))}var wN=Array.prototype.filter;function IN(){return Array.from(this.children)}function vN(e){return function(){return wN.call(this.children,e)}}function CN(e){return this.selectAll(e==null?IN:vN(typeof e=="function"?e:Tf(e)))}function SN(e){typeof e!="function"&&(e=$f(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 Gt(i,this._parents)}function Mf(e){return new Array(e.length)}function RN(){return new Gt(this._enter||this._groups.map(Mf),this._parents)}function ir(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}ir.prototype={constructor:ir,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 AN(e){return function(){return e}}function xN(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 ir(e,r[l]);for(;l<c;++l)(s=n[l])&&(a[l]=s)}function $N(e,n,o,i,a,r,l){var s,c,d=new Map,u=n.length,m=r.length,f=new Array(u),p;for(s=0;s<u;++s)(c=n[s])&&(f[s]=p=l.call(c,c.__data__,s,n)+"",d.has(p)?a[s]=c:d.set(p,c));for(s=0;s<m;++s)p=l.call(e,r[s],s,r)+"",(c=d.get(p))?(i[s]=c,c.__data__=r[s],d.delete(p)):o[s]=new ir(e,r[s]);for(s=0;s<u;++s)(c=n[s])&&d.get(f[s])===c&&(a[s]=c)}function TN(e){return e.__data__}function MN(e,n){if(!arguments.length)return Array.from(this,TN);var o=n?$N:xN,i=this._parents,a=this._groups;typeof e!="function"&&(e=AN(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],f=m.length,p=VN(e.call(u,u&&u.__data__,d,i)),g=p.length,y=s[d]=new Array(g),h=l[d]=new Array(g),_=c[d]=new Array(f);o(u,m,y,h,_,p,n);for(var N=0,b=0,w,I;N<g;++N)if(w=y[N]){for(N>=b&&(b=N+1);!(I=h[b])&&++b<g;);w._next=I||null}}return l=new Gt(l,i),l._enter=s,l._exit=c,l}function VN(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function LN(){return new Gt(this._exit||this._groups.map(Mf),this._parents)}function BN(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 DN(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,f=s[c]=new Array(m),p,g=0;g<m;++g)(p=d[g]||u[g])&&(f[g]=p);for(;c<a;++c)s[c]=o[c];return new Gt(s,this._parents)}function ON(){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 PN(e){e||(e=zN);function n(m,f){return m&&f?e(m.__data__,f.__data__):!m-!f}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 Gt(a,this._parents).order()}function zN(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function FN(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function UN(){return Array.from(this)}function HN(){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 jN(){let e=0;for(const n of this)++e;return e}function KN(){return!this.node()}function GN(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 qN(e){return function(){this.removeAttribute(e)}}function YN(e){return function(){this.removeAttributeNS(e.space,e.local)}}function WN(e,n){return function(){this.setAttribute(e,n)}}function JN(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function XN(e,n){return function(){var o=n.apply(this,arguments);o==null?this.removeAttribute(e):this.setAttribute(e,o)}}function ZN(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 QN(e,n){var o=or(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?YN:qN:typeof n=="function"?o.local?ZN:XN:o.local?JN:WN)(o,n))}function Vf(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function e1(e){return function(){this.style.removeProperty(e)}}function t1(e,n,o){return function(){this.style.setProperty(e,n,o)}}function n1(e,n,o){return function(){var i=n.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,o)}}function o1(e,n,o){return arguments.length>1?this.each((n==null?e1:typeof n=="function"?n1:t1)(e,n,o??"")):ii(this.node(),e)}function ii(e,n){return e.style.getPropertyValue(n)||Vf(e).getComputedStyle(e,null).getPropertyValue(n)}function i1(e){return function(){delete this[e]}}function a1(e,n){return function(){this[e]=n}}function r1(e,n){return function(){var o=n.apply(this,arguments);o==null?delete this[e]:this[e]=o}}function l1(e,n){return arguments.length>1?this.each((n==null?i1:typeof n=="function"?r1:a1)(e,n)):this.node()[e]}function Lf(e){return e.trim().split(/^|\s+/)}function ws(e){return e.classList||new Bf(e)}function Bf(e){this._node=e,this._names=Lf(e.getAttribute("class")||"")}Bf.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 Df(e,n){for(var o=ws(e),i=-1,a=n.length;++i<a;)o.add(n[i])}function Of(e,n){for(var o=ws(e),i=-1,a=n.length;++i<a;)o.remove(n[i])}function s1(e){return function(){Df(this,e)}}function c1(e){return function(){Of(this,e)}}function d1(e,n){return function(){(n.apply(this,arguments)?Df:Of)(this,e)}}function u1(e,n){var o=Lf(e+"");if(arguments.length<2){for(var i=ws(this.node()),a=-1,r=o.length;++a<r;)if(!i.contains(o[a]))return!1;return!0}return this.each((typeof n=="function"?d1:n?s1:c1)(o,n))}function m1(){this.textContent=""}function f1(e){return function(){this.textContent=e}}function p1(e){return function(){var n=e.apply(this,arguments);this.textContent=n??""}}function h1(e){return arguments.length?this.each(e==null?m1:(typeof e=="function"?p1:f1)(e)):this.node().textContent}function y1(){this.innerHTML=""}function g1(e){return function(){this.innerHTML=e}}function b1(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n??""}}function k1(e){return arguments.length?this.each(e==null?y1:(typeof e=="function"?b1:g1)(e)):this.node().innerHTML}function _1(){this.nextSibling&&this.parentNode.appendChild(this)}function E1(){return this.each(_1)}function N1(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function w1(){return this.each(N1)}function I1(e){var n=typeof e=="function"?e:Af(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function v1(){return null}function C1(e,n){var o=typeof e=="function"?e:Af(e),i=n==null?v1:typeof n=="function"?n:Ns(n);return this.select(function(){return this.insertBefore(o.apply(this,arguments),i.apply(this,arguments)||null)})}function S1(){var e=this.parentNode;e&&e.removeChild(this)}function R1(){return this.each(S1)}function A1(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function x1(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function $1(e){return this.select(e?x1:A1)}function T1(e){return arguments.length?this.property("__data__",e):this.node().__data__}function M1(e){return function(n){e.call(this,n,this.__data__)}}function V1(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 L1(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 B1(e,n,o){return function(){var i=this.__on,a,r=M1(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 D1(e,n,o){var i=V1(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?B1:L1,a=0;a<r;++a)this.each(s(i[a],n,o));return this}function Pf(e,n,o){var i=Vf(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 O1(e,n){return function(){return Pf(this,e,n)}}function P1(e,n){return function(){return Pf(this,e,n.apply(this,arguments))}}function z1(e,n){return this.each((typeof n=="function"?P1:O1)(e,n))}function*F1(){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 zf=[null];function Gt(e,n){this._groups=e,this._parents=n}function Pi(){return new Gt([[document.documentElement]],zf)}function U1(){return this}Gt.prototype=Pi.prototype={constructor:Gt,select:pN,selectAll:bN,selectChild:NN,selectChildren:CN,filter:SN,data:MN,enter:RN,exit:LN,join:BN,merge:DN,selection:U1,order:ON,sort:PN,call:FN,nodes:UN,node:HN,size:jN,empty:KN,each:GN,attr:QN,style:o1,property:l1,classed:u1,text:h1,html:k1,raise:E1,lower:w1,append:I1,insert:C1,remove:R1,clone:$1,datum:T1,on:D1,dispatch:z1,[Symbol.iterator]:F1};function rn(e){return typeof e=="string"?new Gt([[document.querySelector(e)]],[document.documentElement]):new Gt([[e]],zf)}function H1(e){let n;for(;n=e.sourceEvent;)e=n;return e}function kn(e,n){if(e=H1(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 j1={passive:!1},zi={capture:!0,passive:!1};function Is(e){e.stopImmediatePropagation()}function ai(e){e.preventDefault(),e.stopImmediatePropagation()}function Ff(e){var n=e.document.documentElement,o=rn(e).on("dragstart.drag",ai,zi);"onselectstart"in n?o.on("selectstart.drag",ai,zi):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Uf(e,n){var o=e.document.documentElement,i=rn(e).on("dragstart.drag",null);n&&(i.on("click.drag",ai,zi),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 ar=e=>()=>e;function vs(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}})}vs.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function K1(e){return!e.ctrlKey&&!e.button}function G1(){return this.parentNode}function q1(e,n){return n??{x:e.x,y:e.y}}function Y1(){return navigator.maxTouchPoints||"ontouchstart"in this}function W1(){var e=K1,n=G1,o=q1,i=Y1,a={},r=tr("start","drag","end"),l=0,s,c,d,u,m=0;function f(w){w.on("mousedown.drag",p).filter(i).on("touchstart.drag",h).on("touchmove.drag",_,j1).on("touchend.drag touchcancel.drag",N).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(w,I){if(!(u||!e.call(this,w,I))){var $=b(this,n.call(this,w,I),w,I,"mouse");$&&(rn(w.view).on("mousemove.drag",g,zi).on("mouseup.drag",y,zi),Ff(w.view),Is(w),d=!1,s=w.clientX,c=w.clientY,$("start",w))}}function g(w){if(ai(w),!d){var I=w.clientX-s,$=w.clientY-c;d=I*I+$*$>m}a.mouse("drag",w)}function y(w){rn(w.view).on("mousemove.drag mouseup.drag",null),Uf(w.view,d),ai(w),a.mouse("end",w)}function h(w,I){if(e.call(this,w,I)){var $=w.changedTouches,k=n.call(this,w,I),C=$.length,x,T;for(x=0;x<C;++x)(T=b(this,k,w,I,$[x].identifier,$[x]))&&(Is(w),T("start",w,$[x]))}}function _(w){var I=w.changedTouches,$=I.length,k,C;for(k=0;k<$;++k)(C=a[I[k].identifier])&&(ai(w),C("drag",w,I[k]))}function N(w){var I=w.changedTouches,$=I.length,k,C;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),k=0;k<$;++k)(C=a[I[k].identifier])&&(Is(w),C("end",w,I[k]))}function b(w,I,$,k,C,x){var T=r.copy(),z=kn(x||$,I),V,D,E;if((E=o.call(w,new vs("beforestart",{sourceEvent:$,target:f,identifier:C,active:l,x:z[0],y:z[1],dx:0,dy:0,dispatch:T}),k))!=null)return V=E.x-z[0]||0,D=E.y-z[1]||0,function v(A,S,R){var H=z,P;switch(A){case"start":a[C]=v,P=l++;break;case"end":delete a[C],--l;case"drag":z=kn(R||S,I),P=l;break}T.call(A,w,new vs(A,{sourceEvent:S,subject:E,target:f,identifier:C,active:P,x:z[0]+V,y:z[1]+D,dx:z[0]-H[0],dy:z[1]-H[1],dispatch:T}),k)}}return f.filter=function(w){return arguments.length?(e=typeof w=="function"?w:ar(!!w),f):e},f.container=function(w){return arguments.length?(n=typeof w=="function"?w:ar(w),f):n},f.subject=function(w){return arguments.length?(o=typeof w=="function"?w:ar(w),f):o},f.touchable=function(w){return arguments.length?(i=typeof w=="function"?w:ar(!!w),f):i},f.on=function(){var w=r.on.apply(r,arguments);return w===r?f:w},f.clickDistance=function(w){return arguments.length?(m=(w=+w)*w,f):Math.sqrt(m)},f}function Cs(e,n,o){e.prototype=n.prototype=o,o.constructor=e}function Hf(e,n){var o=Object.create(e.prototype);for(var i in n)o[i]=n[i];return o}function Fi(){}var Ui=.7,rr=1/Ui,ri="\\s*([+-]?\\d+)\\s*",Hi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",_n="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",J1=/^#([0-9a-f]{3,8})$/,X1=new RegExp(`^rgb\\(${ri},${ri},${ri}\\)$`),Z1=new RegExp(`^rgb\\(${_n},${_n},${_n}\\)$`),Q1=new RegExp(`^rgba\\(${ri},${ri},${ri},${Hi}\\)$`),e0=new RegExp(`^rgba\\(${_n},${_n},${_n},${Hi}\\)$`),t0=new RegExp(`^hsl\\(${Hi},${_n},${_n}\\)$`),n0=new RegExp(`^hsla\\(${Hi},${_n},${_n},${Hi}\\)$`),jf={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};Cs(Fi,Ro,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Kf,formatHex:Kf,formatHex8:o0,formatHsl:i0,formatRgb:Gf,toString:Gf});function Kf(){return this.rgb().formatHex()}function o0(){return this.rgb().formatHex8()}function i0(){return Xf(this).formatHsl()}function Gf(){return this.rgb().formatRgb()}function Ro(e){var n,o;return e=(e+"").trim().toLowerCase(),(n=J1.exec(e))?(o=n[1].length,n=parseInt(n[1],16),o===6?qf(n):o===3?new Ft(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):o===8?lr(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):o===4?lr(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=X1.exec(e))?new Ft(n[1],n[2],n[3],1):(n=Z1.exec(e))?new Ft(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=Q1.exec(e))?lr(n[1],n[2],n[3],n[4]):(n=e0.exec(e))?lr(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=t0.exec(e))?Jf(n[1],n[2]/100,n[3]/100,1):(n=n0.exec(e))?Jf(n[1],n[2]/100,n[3]/100,n[4]):jf.hasOwnProperty(e)?qf(jf[e]):e==="transparent"?new Ft(NaN,NaN,NaN,0):null}function qf(e){return new Ft(e>>16&255,e>>8&255,e&255,1)}function lr(e,n,o,i){return i<=0&&(e=n=o=NaN),new Ft(e,n,o,i)}function a0(e){return e instanceof Fi||(e=Ro(e)),e?(e=e.rgb(),new Ft(e.r,e.g,e.b,e.opacity)):new Ft}function Ss(e,n,o,i){return arguments.length===1?a0(e):new Ft(e,n,o,i??1)}function Ft(e,n,o,i){this.r=+e,this.g=+n,this.b=+o,this.opacity=+i}Cs(Ft,Ss,Hf(Fi,{brighter(e){return e=e==null?rr:Math.pow(rr,e),new Ft(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ui:Math.pow(Ui,e),new Ft(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ft(Ao(this.r),Ao(this.g),Ao(this.b),sr(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:Yf,formatHex:Yf,formatHex8:r0,formatRgb:Wf,toString:Wf}));function Yf(){return`#${xo(this.r)}${xo(this.g)}${xo(this.b)}`}function r0(){return`#${xo(this.r)}${xo(this.g)}${xo(this.b)}${xo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Wf(){const e=sr(this.opacity);return`${e===1?"rgb(":"rgba("}${Ao(this.r)}, ${Ao(this.g)}, ${Ao(this.b)}${e===1?")":`, ${e})`}`}function sr(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ao(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function xo(e){return e=Ao(e),(e<16?"0":"")+e.toString(16)}function Jf(e,n,o,i){return i<=0?e=n=o=NaN:o<=0||o>=1?e=n=NaN:n<=0&&(e=NaN),new ln(e,n,o,i)}function Xf(e){if(e instanceof ln)return new ln(e.h,e.s,e.l,e.opacity);if(e instanceof Fi||(e=Ro(e)),!e)return new ln;if(e instanceof ln)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 ln(l,s,c,e.opacity)}function l0(e,n,o,i){return arguments.length===1?Xf(e):new ln(e,n,o,i??1)}function ln(e,n,o,i){this.h=+e,this.s=+n,this.l=+o,this.opacity=+i}Cs(ln,l0,Hf(Fi,{brighter(e){return e=e==null?rr:Math.pow(rr,e),new ln(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ui:Math.pow(Ui,e),new ln(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 Ft(Rs(e>=240?e-240:e+120,a,i),Rs(e,a,i),Rs(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new ln(Zf(this.h),cr(this.s),cr(this.l),sr(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=sr(this.opacity);return`${e===1?"hsl(":"hsla("}${Zf(this.h)}, ${cr(this.s)*100}%, ${cr(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Zf(e){return e=(e||0)%360,e<0?e+360:e}function cr(e){return Math.max(0,Math.min(1,e||0))}function Rs(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 As=e=>()=>e;function s0(e,n){return function(o){return e+o*n}}function c0(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 d0(e){return(e=+e)==1?Qf:function(n,o){return o-n?c0(n,o,e):As(isNaN(n)?o:n)}}function Qf(e,n){var o=n-e;return o?s0(e,o):As(isNaN(e)?n:e)}const dr=(function e(n){var o=d0(n);function i(a,r){var l=o((a=Ss(a)).r,(r=Ss(r)).r),s=o(a.g,r.g),c=o(a.b,r.b),d=Qf(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 u0(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 m0(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function f0(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]=ji(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 p0(e,n){var o=new Date;return e=+e,n=+n,function(i){return o.setTime(e*(1-i)+n*i),o}}function En(e,n){return e=+e,n=+n,function(o){return e*(1-o)+n*o}}function h0(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]=ji(e[a],n[a]):i[a]=n[a];return function(r){for(a in o)i[a]=o[a](r);return i}}var xs=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,$s=new RegExp(xs.source,"g");function y0(e){return function(){return e}}function g0(e){return function(n){return e(n)+""}}function ep(e,n){var o=xs.lastIndex=$s.lastIndex=0,i,a,r,l=-1,s=[],c=[];for(e=e+"",n=n+"";(i=xs.exec(e))&&(a=$s.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:En(i,a)})),o=$s.lastIndex;return o<n.length&&(r=n.slice(o),s[l]?s[l]+=r:s[++l]=r),s.length<2?c[0]?g0(c[0].x):y0(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 ji(e,n){var o=typeof n,i;return n==null||o==="boolean"?As(n):(o==="number"?En:o==="string"?(i=Ro(n))?(n=i,dr):ep:n instanceof Ro?dr:n instanceof Date?p0:m0(n)?u0:Array.isArray(n)?f0:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?h0:En)(e,n)}var tp=180/Math.PI,Ts={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function np(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)*tp,skewX:Math.atan(c)*tp,scaleX:l,scaleY:s}}var ur;function b0(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?Ts:np(n.a,n.b,n.c,n.d,n.e,n.f)}function k0(e){return e==null||(ur||(ur=document.createElementNS("http://www.w3.org/2000/svg","g")),ur.setAttribute("transform",e),!(e=ur.transform.baseVal.consolidate()))?Ts:(e=e.matrix,np(e.a,e.b,e.c,e.d,e.e,e.f))}function op(e,n,o,i){function a(d){return d.length?d.pop()+" ":""}function r(d,u,m,f,p,g){if(d!==m||u!==f){var y=p.push("translate(",null,n,null,o);g.push({i:y-4,x:En(d,m)},{i:y-2,x:En(u,f)})}else(m||f)&&p.push("translate("+m+n+f+o)}function l(d,u,m,f){d!==u?(d-u>180?u+=360:u-d>180&&(d+=360),f.push({i:m.push(a(m)+"rotate(",null,i)-2,x:En(d,u)})):u&&m.push(a(m)+"rotate("+u+i)}function s(d,u,m,f){d!==u?f.push({i:m.push(a(m)+"skewX(",null,i)-2,x:En(d,u)}):u&&m.push(a(m)+"skewX("+u+i)}function c(d,u,m,f,p,g){if(d!==m||u!==f){var y=p.push(a(p)+"scale(",null,",",null,")");g.push({i:y-4,x:En(d,m)},{i:y-2,x:En(u,f)})}else(m!==1||f!==1)&&p.push(a(p)+"scale("+m+","+f+")")}return function(d,u){var m=[],f=[];return d=e(d),u=e(u),r(d.translateX,d.translateY,u.translateX,u.translateY,m,f),l(d.rotate,u.rotate,m,f),s(d.skewX,u.skewX,m,f),c(d.scaleX,d.scaleY,u.scaleX,u.scaleY,m,f),d=u=null,function(p){for(var g=-1,y=f.length,h;++g<y;)m[(h=f[g]).i]=h.x(p);return m.join("")}}}var _0=op(b0,"px, ","px)","deg)"),E0=op(k0,", ",")",")"),N0=1e-12;function ip(e){return((e=Math.exp(e))+1/e)/2}function w0(e){return((e=Math.exp(e))-1/e)/2}function I0(e){return((e=Math.exp(2*e))-1)/(e+1)}const mr=(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],f=l[2],p=u-s,g=m-c,y=p*p+g*g,h,_;if(y<N0)_=Math.log(f/d)/n,h=function(k){return[s+k*p,c+k*g,d*Math.exp(n*k*_)]};else{var N=Math.sqrt(y),b=(f*f-d*d+i*y)/(2*d*o*N),w=(f*f-d*d-i*y)/(2*f*o*N),I=Math.log(Math.sqrt(b*b+1)-b),$=Math.log(Math.sqrt(w*w+1)-w);_=($-I)/n,h=function(k){var C=k*_,x=ip(I),T=d/(o*N)*(x*I0(n*C+I)-w0(I));return[s+T*p,c+T*g,d*x/ip(n*C+I)]}}return h.duration=_*1e3*n/Math.SQRT2,h}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 li=0,Ki=0,Gi=0,ap=1e3,fr,qi,pr=0,$o=0,hr=0,Yi=typeof performance=="object"&&performance.now?performance:Date,rp=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ms(){return $o||(rp(v0),$o=Yi.now()+hr)}function v0(){$o=0}function yr(){this._call=this._time=this._next=null}yr.prototype=lp.prototype={constructor:yr,restart:function(e,n,o){if(typeof e!="function")throw new TypeError("callback is not a function");o=(o==null?Ms():+o)+(n==null?0:+n),!this._next&&qi!==this&&(qi?qi._next=this:fr=this,qi=this),this._call=e,this._time=o,Vs()},stop:function(){this._call&&(this._call=null,this._time=1/0,Vs())}};function lp(e,n,o){var i=new yr;return i.restart(e,n,o),i}function C0(){Ms(),++li;for(var e=fr,n;e;)(n=$o-e._time)>=0&&e._call.call(void 0,n),e=e._next;--li}function sp(){$o=(pr=Yi.now())+hr,li=Ki=0;try{C0()}finally{li=0,R0(),$o=0}}function S0(){var e=Yi.now(),n=e-pr;n>ap&&(hr-=n,pr=e)}function R0(){for(var e,n=fr,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:fr=o);qi=e,Vs(i)}function Vs(e){if(!li){Ki&&(Ki=clearTimeout(Ki));var n=e-$o;n>24?(e<1/0&&(Ki=setTimeout(sp,e-Yi.now()-hr)),Gi&&(Gi=clearInterval(Gi))):(Gi||(pr=Yi.now(),Gi=setInterval(S0,ap)),li=1,rp(sp))}}function cp(e,n,o){var i=new yr;return n=n==null?0:+n,i.restart(a=>{i.stop(),e(a+n)},n,o),i}var A0=tr("start","end","cancel","interrupt"),x0=[],dp=0,up=1,Ls=2,gr=3,mp=4,Bs=5,br=6;function kr(e,n,o,i,a,r){var l=e.__transition;if(!l)e.__transition={};else if(o in l)return;$0(e,o,{name:n,index:i,group:a,on:A0,tween:x0,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:dp})}function Ds(e,n){var o=sn(e,n);if(o.state>dp)throw new Error("too late; already scheduled");return o}function Nn(e,n){var o=sn(e,n);if(o.state>gr)throw new Error("too late; already running");return o}function sn(e,n){var o=e.__transition;if(!o||!(o=o[n]))throw new Error("transition not found");return o}function $0(e,n,o){var i=e.__transition,a;i[n]=o,o.timer=lp(r,0,o.time);function r(d){o.state=up,o.timer.restart(l,o.delay,o.time),o.delay<=d&&l(d-o.delay)}function l(d){var u,m,f,p;if(o.state!==up)return c();for(u in i)if(p=i[u],p.name===o.name){if(p.state===gr)return cp(l);p.state===mp?(p.state=br,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete i[u]):+u<n&&(p.state=br,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete i[u])}if(cp(function(){o.state===gr&&(o.state=mp,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=gr,a=new Array(f=o.tween.length),u=0,m=-1;u<f;++u)(p=o.tween[u].value.call(e,e.__data__,o.index,o.group))&&(a[++m]=p);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=Bs,1),m=-1,f=a.length;++m<f;)a[m].call(e,u);o.state===Bs&&(o.on.call("end",e,e.__data__,o.index,o.group),c())}function c(){o.state=br,o.timer.stop(),delete i[n];for(var d in i)return;delete e.__transition}}function _r(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<Bs,i.state=br,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete o[l]}r&&delete e.__transition}}function T0(e){return this.each(function(){_r(this,e)})}function M0(e,n){var o,i;return function(){var a=Nn(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 V0(e,n,o){var i,a;if(typeof o!="function")throw new Error;return function(){var r=Nn(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 L0(e,n){var o=this._id;if(e+="",arguments.length<2){for(var i=sn(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?M0:V0)(o,e,n))}function Os(e,n,o){var i=e._id;return e.each(function(){var a=Nn(this,i);(a.value||(a.value={}))[n]=o.apply(this,arguments)}),function(a){return sn(a,i).value[n]}}function fp(e,n){var o;return(typeof n=="number"?En:n instanceof Ro?dr:(o=Ro(n))?(n=o,dr):ep)(e,n)}function B0(e){return function(){this.removeAttribute(e)}}function D0(e){return function(){this.removeAttributeNS(e.space,e.local)}}function O0(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 P0(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 z0(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 F0(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 U0(e,n){var o=or(e),i=o==="transform"?E0:fp;return this.attrTween(e,typeof n=="function"?(o.local?F0:z0)(o,i,Os(this,"attr."+e,n)):n==null?(o.local?D0:B0)(o):(o.local?P0:O0)(o,i,n))}function H0(e,n){return function(o){this.setAttribute(e,n.call(this,o))}}function j0(e,n){return function(o){this.setAttributeNS(e.space,e.local,n.call(this,o))}}function K0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&j0(e,r)),o}return a._value=n,a}function G0(e,n){var o,i;function a(){var r=n.apply(this,arguments);return r!==i&&(o=(i=r)&&H0(e,r)),o}return a._value=n,a}function q0(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=or(e);return this.tween(o,(i.local?K0:G0)(i,n))}function Y0(e,n){return function(){Ds(this,e).delay=+n.apply(this,arguments)}}function W0(e,n){return n=+n,function(){Ds(this,e).delay=n}}function J0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?Y0:W0)(n,e)):sn(this.node(),n).delay}function X0(e,n){return function(){Nn(this,e).duration=+n.apply(this,arguments)}}function Z0(e,n){return n=+n,function(){Nn(this,e).duration=n}}function Q0(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?X0:Z0)(n,e)):sn(this.node(),n).duration}function ew(e,n){if(typeof n!="function")throw new Error;return function(){Nn(this,e).ease=n}}function tw(e){var n=this._id;return arguments.length?this.each(ew(n,e)):sn(this.node(),n).ease}function nw(e,n){return function(){var o=n.apply(this,arguments);if(typeof o!="function")throw new Error;Nn(this,e).ease=o}}function ow(e){if(typeof e!="function")throw new Error;return this.each(nw(this._id,e))}function iw(e){typeof e!="function"&&(e=$f(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 Dn(i,this._parents,this._name,this._id)}function aw(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),f,p=0;p<u;++p)(f=c[p]||d[p])&&(m[p]=f);for(;s<i;++s)l[s]=n[s];return new Dn(l,this._parents,this._name,this._id)}function rw(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 lw(e,n,o){var i,a,r=rw(n)?Ds:Nn;return function(){var l=r(this,e),s=l.on;s!==i&&(a=(i=s).copy()).on(n,o),l.on=a}}function sw(e,n){var o=this._id;return arguments.length<2?sn(this.node(),o).on.on(e):this.each(lw(o,e,n))}function cw(e){return function(){var n=this.parentNode;for(var o in this.__transition)if(+o!==e)return;n&&n.removeChild(this)}}function dw(){return this.on("end.remove",cw(this._id))}function uw(e){var n=this._name,o=this._id;typeof e!="function"&&(e=Ns(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,f=0;f<c;++f)(u=s[f])&&(m=e.call(u,u.__data__,f,s))&&("__data__"in u&&(m.__data__=u.__data__),d[f]=m,kr(d[f],n,o,f,d,sn(u,o)));return new Dn(r,this._parents,n,o)}function mw(e){var n=this._name,o=this._id;typeof e!="function"&&(e=xf(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 f=e.call(u,u.__data__,m,c),p,g=sn(u,o),y=0,h=f.length;y<h;++y)(p=f[y])&&kr(p,n,o,y,f,g);r.push(f),l.push(u)}return new Dn(r,l,n,o)}var fw=Pi.prototype.constructor;function pw(){return new fw(this._groups,this._parents)}function hw(e,n){var o,i,a;return function(){var r=ii(this,e),l=(this.style.removeProperty(e),ii(this,e));return r===l?null:r===o&&l===i?a:a=n(o=r,i=l)}}function pp(e){return function(){this.style.removeProperty(e)}}function yw(e,n,o){var i,a=o+"",r;return function(){var l=ii(this,e);return l===a?null:l===i?r:r=n(i=l,o)}}function gw(e,n,o){var i,a,r;return function(){var l=ii(this,e),s=o(this),c=s+"";return s==null&&(c=s=(this.style.removeProperty(e),ii(this,e))),l===c?null:l===i&&c===a?r:(a=c,r=n(i=l,s))}}function bw(e,n){var o,i,a,r="style."+n,l="end."+r,s;return function(){var c=Nn(this,e),d=c.on,u=c.value[r]==null?s||(s=pp(n)):void 0;(d!==o||a!==u)&&(i=(o=d).copy()).on(l,a=u),c.on=i}}function kw(e,n,o){var i=(e+="")=="transform"?_0:fp;return n==null?this.styleTween(e,hw(e,i)).on("end.style."+e,pp(e)):typeof n=="function"?this.styleTween(e,gw(e,i,Os(this,"style."+e,n))).each(bw(this._id,e)):this.styleTween(e,yw(e,i,n),o).on("end.style."+e,null)}function _w(e,n,o){return function(i){this.style.setProperty(e,n.call(this,i),o)}}function Ew(e,n,o){var i,a;function r(){var l=n.apply(this,arguments);return l!==a&&(i=(a=l)&&_w(e,l,o)),i}return r._value=n,r}function Nw(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,Ew(e,n,o??""))}function ww(e){return function(){this.textContent=e}}function Iw(e){return function(){var n=e(this);this.textContent=n??""}}function vw(e){return this.tween("text",typeof e=="function"?Iw(Os(this,"text",e)):ww(e==null?"":e+""))}function Cw(e){return function(n){this.textContent=e.call(this,n)}}function Sw(e){var n,o;function i(){var a=e.apply(this,arguments);return a!==o&&(n=(o=a)&&Cw(a)),n}return i._value=e,i}function Rw(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,Sw(e))}function Aw(){for(var e=this._name,n=this._id,o=hp(),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=sn(c,n);kr(c,e,o,d,l,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Dn(i,this._parents,e,o)}function xw(){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=Nn(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 $w=0;function Dn(e,n,o,i){this._groups=e,this._parents=n,this._name=o,this._id=i}function hp(){return++$w}var On=Pi.prototype;Dn.prototype={constructor:Dn,select:uw,selectAll:mw,selectChild:On.selectChild,selectChildren:On.selectChildren,filter:iw,merge:aw,selection:pw,transition:Aw,call:On.call,nodes:On.nodes,node:On.node,size:On.size,empty:On.empty,each:On.each,on:sw,attr:U0,attrTween:q0,style:kw,styleTween:Nw,text:vw,textTween:Rw,remove:dw,tween:L0,delay:J0,duration:Q0,ease:tw,easeVarying:ow,end:xw,[Symbol.iterator]:On[Symbol.iterator]};function Tw(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Mw={time:null,delay:0,duration:250,ease:Tw};function Vw(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 Lw(e){var n,o;e instanceof Dn?(n=e._id,e=e._name):(n=hp(),(o=Mw).time=Ms(),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])&&kr(c,e,n,d,l,o||Vw(c,n));return new Dn(i,this._parents,e,n)}Pi.prototype.interrupt=T0,Pi.prototype.transition=Lw;const Er=e=>()=>e;function Bw(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 Pn(e,n,o){this.k=e,this.x=n,this.y=o}Pn.prototype={constructor:Pn,scale:function(e){return e===1?this:new Pn(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new Pn(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 si=new Pn(1,0,0);Pn.prototype;function Ps(e){e.stopImmediatePropagation()}function Wi(e){e.preventDefault(),e.stopImmediatePropagation()}function Dw(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ow(){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 yp(){return this.__zoom||si}function Pw(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function zw(){return navigator.maxTouchPoints||"ontouchstart"in this}function Fw(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 Uw(){var e=Dw,n=Ow,o=Fw,i=Pw,a=zw,r=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],s=250,c=mr,d=tr("start","zoom","end"),u,m,f,p=500,g=150,y=0,h=10;function _(E){E.property("__zoom",yp).on("wheel.zoom",C,{passive:!1}).on("mousedown.zoom",x).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",z).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",D).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(E,v,A,S){var R=E.selection?E.selection():E;R.property("__zoom",yp),E!==R?I(E,v,A,S):R.interrupt().each(function(){$(this,arguments).event(S).start().zoom(null,typeof v=="function"?v.apply(this,arguments):v).end()})},_.scaleBy=function(E,v,A,S){_.scaleTo(E,function(){var R=this.__zoom.k,H=typeof v=="function"?v.apply(this,arguments):v;return R*H},A,S)},_.scaleTo=function(E,v,A,S){_.transform(E,function(){var R=n.apply(this,arguments),H=this.__zoom,P=A==null?w(R):typeof A=="function"?A.apply(this,arguments):A,L=H.invert(P),j=typeof v=="function"?v.apply(this,arguments):v;return o(b(N(H,j),P,L),R,l)},A,S)},_.translateBy=function(E,v,A,S){_.transform(E,function(){return o(this.__zoom.translate(typeof v=="function"?v.apply(this,arguments):v,typeof A=="function"?A.apply(this,arguments):A),n.apply(this,arguments),l)},null,S)},_.translateTo=function(E,v,A,S,R){_.transform(E,function(){var H=n.apply(this,arguments),P=this.__zoom,L=S==null?w(H):typeof S=="function"?S.apply(this,arguments):S;return o(si.translate(L[0],L[1]).scale(P.k).translate(typeof v=="function"?-v.apply(this,arguments):-v,typeof A=="function"?-A.apply(this,arguments):-A),H,l)},S,R)};function N(E,v){return v=Math.max(r[0],Math.min(r[1],v)),v===E.k?E:new Pn(v,E.x,E.y)}function b(E,v,A){var S=v[0]-A[0]*E.k,R=v[1]-A[1]*E.k;return S===E.x&&R===E.y?E:new Pn(E.k,S,R)}function w(E){return[(+E[0][0]+ +E[1][0])/2,(+E[0][1]+ +E[1][1])/2]}function I(E,v,A,S){E.on("start.zoom",function(){$(this,arguments).event(S).start()}).on("interrupt.zoom end.zoom",function(){$(this,arguments).event(S).end()}).tween("zoom",function(){var R=this,H=arguments,P=$(R,H).event(S),L=n.apply(R,H),j=A==null?w(L):typeof A=="function"?A.apply(R,H):A,X=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),J=R.__zoom,re=typeof v=="function"?v.apply(R,H):v,me=c(J.invert(j).concat(X/J.k),re.invert(j).concat(X/re.k));return function(se){if(se===1)se=re;else{var Ie=me(se),Oe=X/Ie[2];se=new Pn(Oe,j[0]-Ie[0]*Oe,j[1]-Ie[1]*Oe)}P.zoom(null,se)}})}function $(E,v,A){return!A&&E.__zooming||new k(E,v)}function k(E,v){this.that=E,this.args=v,this.active=0,this.sourceEvent=null,this.extent=n.apply(E,v),this.taps=0}k.prototype={event:function(E){return E&&(this.sourceEvent=E),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(E,v){return this.mouse&&E!=="mouse"&&(this.mouse[1]=v.invert(this.mouse[0])),this.touch0&&E!=="touch"&&(this.touch0[1]=v.invert(this.touch0[0])),this.touch1&&E!=="touch"&&(this.touch1[1]=v.invert(this.touch1[0])),this.that.__zoom=v,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(E){var v=rn(this.that).datum();d.call(E,this.that,new Bw(E,{sourceEvent:this.sourceEvent,target:_,transform:this.that.__zoom,dispatch:d}),v)}};function C(E,...v){if(!e.apply(this,arguments))return;var A=$(this,v).event(E),S=this.__zoom,R=Math.max(r[0],Math.min(r[1],S.k*Math.pow(2,i.apply(this,arguments)))),H=kn(E);if(A.wheel)(A.mouse[0][0]!==H[0]||A.mouse[0][1]!==H[1])&&(A.mouse[1]=S.invert(A.mouse[0]=H)),clearTimeout(A.wheel);else{if(S.k===R)return;A.mouse=[H,S.invert(H)],_r(this),A.start()}Wi(E),A.wheel=setTimeout(P,g),A.zoom("mouse",o(b(N(S,R),A.mouse[0],A.mouse[1]),A.extent,l));function P(){A.wheel=null,A.end()}}function x(E,...v){if(f||!e.apply(this,arguments))return;var A=E.currentTarget,S=$(this,v,!0).event(E),R=rn(E.view).on("mousemove.zoom",j,!0).on("mouseup.zoom",X,!0),H=kn(E,A),P=E.clientX,L=E.clientY;Ff(E.view),Ps(E),S.mouse=[H,this.__zoom.invert(H)],_r(this),S.start();function j(J){if(Wi(J),!S.moved){var re=J.clientX-P,me=J.clientY-L;S.moved=re*re+me*me>y}S.event(J).zoom("mouse",o(b(S.that.__zoom,S.mouse[0]=kn(J,A),S.mouse[1]),S.extent,l))}function X(J){R.on("mousemove.zoom mouseup.zoom",null),Uf(J.view,S.moved),Wi(J),S.event(J).end()}}function T(E,...v){if(e.apply(this,arguments)){var A=this.__zoom,S=kn(E.changedTouches?E.changedTouches[0]:E,this),R=A.invert(S),H=A.k*(E.shiftKey?.5:2),P=o(b(N(A,H),S,R),n.apply(this,v),l);Wi(E),s>0?rn(this).transition().duration(s).call(I,P,S,E):rn(this).call(_.transform,P,S,E)}}function z(E,...v){if(e.apply(this,arguments)){var A=E.touches,S=A.length,R=$(this,v,E.changedTouches.length===S).event(E),H,P,L,j;for(Ps(E),P=0;P<S;++P)L=A[P],j=kn(L,this),j=[j,this.__zoom.invert(j),L.identifier],R.touch0?!R.touch1&&R.touch0[2]!==j[2]&&(R.touch1=j,R.taps=0):(R.touch0=j,H=!0,R.taps=1+!!u);u&&(u=clearTimeout(u)),H&&(R.taps<2&&(m=j[0],u=setTimeout(function(){u=null},p)),_r(this),R.start())}}function V(E,...v){if(this.__zooming){var A=$(this,v).event(E),S=E.changedTouches,R=S.length,H,P,L,j;for(Wi(E),H=0;H<R;++H)P=S[H],L=kn(P,this),A.touch0&&A.touch0[2]===P.identifier?A.touch0[0]=L:A.touch1&&A.touch1[2]===P.identifier&&(A.touch1[0]=L);if(P=A.that.__zoom,A.touch1){var X=A.touch0[0],J=A.touch0[1],re=A.touch1[0],me=A.touch1[1],se=(se=re[0]-X[0])*se+(se=re[1]-X[1])*se,Ie=(Ie=me[0]-J[0])*Ie+(Ie=me[1]-J[1])*Ie;P=N(P,Math.sqrt(se/Ie)),L=[(X[0]+re[0])/2,(X[1]+re[1])/2],j=[(J[0]+me[0])/2,(J[1]+me[1])/2]}else if(A.touch0)L=A.touch0[0],j=A.touch0[1];else return;A.zoom("touch",o(b(P,L,j),A.extent,l))}}function D(E,...v){if(this.__zooming){var A=$(this,v).event(E),S=E.changedTouches,R=S.length,H,P;for(Ps(E),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),H=0;H<R;++H)P=S[H],A.touch0&&A.touch0[2]===P.identifier?delete A.touch0:A.touch1&&A.touch1[2]===P.identifier&&delete A.touch1;if(A.touch1&&!A.touch0&&(A.touch0=A.touch1,delete A.touch1),A.touch0)A.touch0[1]=this.__zoom.invert(A.touch0[0]);else if(A.end(),A.taps===2&&(P=kn(P,this),Math.hypot(m[0]-P[0],m[1]-P[1])<h)){var L=rn(this).on("dblclick.zoom");L&&L.apply(this,arguments)}}}return _.wheelDelta=function(E){return arguments.length?(i=typeof E=="function"?E:Er(+E),_):i},_.filter=function(E){return arguments.length?(e=typeof E=="function"?E:Er(!!E),_):e},_.touchable=function(E){return arguments.length?(a=typeof E=="function"?E:Er(!!E),_):a},_.extent=function(E){return arguments.length?(n=typeof E=="function"?E:Er([[+E[0][0],+E[0][1]],[+E[1][0],+E[1][1]]]),_):n},_.scaleExtent=function(E){return arguments.length?(r[0]=+E[0],r[1]=+E[1],_):[r[0],r[1]]},_.translateExtent=function(E){return arguments.length?(l[0][0]=+E[0][0],l[1][0]=+E[1][0],l[0][1]=+E[0][1],l[1][1]=+E[1][1],_):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},_.constrain=function(E){return arguments.length?(o=E,_):o},_.duration=function(E){return arguments.length?(s=+E,_):s},_.interpolate=function(E){return arguments.length?(c=E,_):c},_.on=function(){var E=d.on.apply(d,arguments);return E===d?_:E},_.clickDistance=function(E){return arguments.length?(y=(E=+E)*E,_):Math.sqrt(y)},_.tapDistance=function(E){return arguments.length?(h=+E,_):h},_}var Be=(e=>(e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom",e))(Be||{}),zs=(e=>(e.Partial="partial",e.Full="full",e))(zs||{}),To=(e=>(e.Bezier="default",e.SimpleBezier="simple-bezier",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e))(To||{}),zn=(e=>(e.Strict="strict",e.Loose="loose",e))(zn||{}),Fs=(e=>(e.Arrow="arrow",e.ArrowClosed="arrowclosed",e))(Fs||{}),Ji=(e=>(e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal",e))(Ji||{}),gp=(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))(gp||{});const Hw=["INPUT","SELECT","TEXTAREA"],jw=typeof document<"u"?document:null;function Us(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 Hw.includes(i==null?void 0:i.nodeName)||a||!!r}function Kw(e){return e.ctrlKey||e.metaKey||e.shiftKey||e.altKey}function bp(e,n,o,i){const a=n.replace("+",`
|
|
35
35
|
`).replace(`
|
|
36
36
|
|
|
37
37
|
`,`
|