@sentropic/design-system-elements 0.1.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.THIRD-PARTY.md +44 -1
- package/README.md +123 -12
- package/catalog.json +401 -7
- package/dist/browser/chunks/{Modeler-BfAmwsmK.js → Modeler-D87tL_OJ.js} +4 -4
- package/dist/browser/chunks/Viewer-D9zjRrp2.js +4 -0
- package/dist/browser/chunks/bpmn-canvas-BevbP_6a.js +1 -0
- package/dist/browser/chunks/bpmn-mount-BhO_zb0S.js +2202 -0
- package/dist/browser/chunks/dist-DRauAwm2.js +6 -0
- package/dist/browser/chunks/{entropic-CM5BHERN.js → entropic-MwNVEq6w.js} +639 -0
- package/dist/browser/chunks/focus-renderer-BWm7DlQD.js +55 -0
- package/dist/browser/chunks/{forge-B8hrW4lA.js → forge-CzwO8Hbe.js} +639 -0
- package/dist/browser/chunks/layout-T3X333Za.js +1 -0
- package/dist/browser/elements.js +671 -6
- package/dist/browser/sri.json +52 -45
- package/dist/contracts/bar-chart.js +2 -2
- package/dist/contracts/decision-dossier.d.ts +4 -8
- package/dist/contracts/decision-dossier.js +8 -12
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/time-series-chart.d.ts +49 -0
- package/dist/contracts/time-series-chart.js +37 -0
- package/dist/dossier/dossier-mount.js +845 -0
- package/dist/dossier/renderer/dossier.css +2 -0
- package/dist/element/bpmn-mount.d.ts +11 -0
- package/dist/element/bpmn-mount.js +56 -0
- package/dist/element/bpmn-types.d.ts +27 -0
- package/dist/element/bpmn-types.js +12 -0
- package/dist/element/bpmn.d.ts +10 -0
- package/dist/element/bpmn.js +39 -0
- package/dist/element/dom/dossier-mount.d.ts +25 -0
- package/dist/element/dom/dossier-review-mount.d.ts +25 -0
- package/dist/element/dom/dossier-review-state.svelte.d.ts +13 -0
- package/dist/element/dom/engines/bpmn-canvas.d.ts +11 -0
- package/dist/element/dom/engines/bpmn-canvas.js +11 -0
- package/dist/element/dom/engines/dossier-diagrams.d.ts +5 -0
- package/dist/element/dom/engines/dossier-evidence.d.ts +9 -0
- package/dist/element/dom/engines/dossier-styles.d.ts +21 -0
- package/dist/element/dom/engines/focus-renderer.d.ts +60 -0
- package/dist/element/dom/engines/focus-snapshot.d.ts +3 -0
- package/dist/element/dom/intents.d.ts +20 -0
- package/dist/element/markdown/minimal-markdown.d.ts +1 -2
- package/dist/element/markdown/minimal-markdown.js +19 -1
- package/dist/element/validator.d.ts +26 -0
- package/dist/element/validator.js +54 -0
- package/dist/focus-diagrams/diagram-layout.d.ts +140 -0
- package/dist/focus-diagrams/diagram-layout.js +190 -0
- package/dist/focus-diagrams/diagram-source.d.ts +11 -0
- package/dist/focus-diagrams/diagram-source.js +147 -0
- package/dist/focus-diagrams/dossier-views.d.ts +21 -0
- package/dist/focus-diagrams/dossier-views.js +57 -0
- package/dist/focus-diagrams/ecosystem.json +853 -0
- package/dist/focus-kit/index.html +13 -0
- package/dist/focus-kit/renderer/dossier.css +2 -0
- package/dist/focus-kit/renderer/dossier.js +845 -0
- package/dist/focus-kit-manifest.json +1 -0
- package/dist/focus-kit.d.ts +9 -0
- package/dist/focus-kit.js +30 -0
- package/dist/format-time-series-markdown.d.ts +5 -0
- package/dist/format-time-series-markdown.js +24 -0
- package/dist/generator/parity.js +6 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/ports/dossier-views.d.ts +3 -0
- package/dist/ports/dossier-views.js +3 -0
- package/dist/ports/focus.d.ts +0 -1
- package/dist/ports/types.d.ts +0 -1
- package/dist/shells/BarChart.html +8494 -0
- package/dist/shells/BarChart.js +8482 -0
- package/dist/shells/DecisionDossier.html +8502 -0
- package/dist/shells/DecisionDossier.js +8490 -0
- package/dist/shells/TimeSeriesChart.html +8475 -0
- package/dist/shells/TimeSeriesChart.js +8463 -0
- package/dist/shells/manifest.json +108 -0
- package/dist/structure/interpreter.d.ts +1 -1
- package/dist/structure/interpreter.js +14 -4
- package/dist/time-series.d.ts +13 -0
- package/dist/time-series.js +15 -0
- package/dist/validate/envelope.js +5 -1
- package/dist/validate/time-series.d.ts +5 -0
- package/dist/validate/time-series.js +28 -0
- package/fixtures/time-series-multi.json +46 -0
- package/fixtures/time-series-single.json +28 -0
- package/fixtures/time-series-thresholds.json +52 -0
- package/package.json +40 -6
- package/schemas/BarChart.v1.json +2 -2
- package/schemas/DecisionDossier.v1.json +155 -5
- package/schemas/TimeSeriesChart.v1.json +287 -0
- package/skill/SKILL.md +27 -0
- package/dist/browser/chunks/Viewer-eYLzc3fD.js +0 -4
- package/dist/browser/chunks/bpmn-canvas-DeAWdJFy.js +0 -2207
- package/dist/browser/chunks/dist-O6_2ByYB.js +0 -1
- package/dist/browser/chunks/focus-renderer-BgsZGo7n.js +0 -8
- package/dist/browser/chunks/layout-q0TR9-aY.js +0 -1
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
function e(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function t(t,n,r=``){let i=e(t),a=t?.length,o=n!==void 0;if(!i||o&&a!==n){let e=r&&`"${r}" `,s=o?` of length ${n}`:``,c=i?`length=${a}`:`type=${typeof t}`;throw Error(e+`expected Uint8Array`+s+`, got `+c)}return t}function n(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function r(e,n){t(e,void 0,`digestInto() output`);let r=n.outputLen;if(e.length<r)throw Error(`"digestInto() output" expected to be of length >=`+r)}function i(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function a(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function o(e,t){return e<<32-t|e>>>t}var s=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,c=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function l(e){if(t(e),s)return e.toHex();let n=``;for(let t=0;t<e.length;t++)n+=c[e[t]];return n}function u(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}var d=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function f(e,t,n){return e&t^~e&n}function p(e,t,n){return e&t^e&n^t&n}var m=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=a(this.buffer)}update(e){n(this),t(e);let{view:r,buffer:i,blockLen:o}=this,s=e.length;for(let t=0;t<s;){let n=Math.min(o-this.pos,s-t);if(n===o){let n=a(e);for(;o<=s-t;t+=o)this.process(n,t)}else i.set(e.subarray(t,t+n),this.pos),this.pos+=n,t+=n,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){n(this),r(e,this),this.finished=!0;let{buffer:t,view:o,blockLen:s,isLE:c}=this,{pos:l}=this;t[l++]=128,i(this.buffer.subarray(l)),this.padOffset>s-l&&(this.process(o,0),l=0);for(let e=l;e<s;e++)t[e]=0;o.setBigUint64(s-8,BigInt(this.length*8),c),this.process(o,0);let u=a(e),d=this.outputLen;if(d%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let f=d/4,p=this.get();if(f>p.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<f;e++)u.setUint32(4*e,p[e],c)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},h=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),g=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_=new Uint32Array(64),v=class extends m{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)_[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=_[e-15],n=_[e-2],r=o(t,7)^o(t,18)^t>>>3,i=o(n,17)^o(n,19)^n>>>10;_[e]=i+_[e-7]+r+_[e-16]|0}let{A:n,B:r,C:i,D:a,E:s,F:c,G:l,H:u}=this;for(let e=0;e<64;e++){let t=o(s,6)^o(s,11)^o(s,25),d=u+t+f(s,c,l)+g[e]+_[e]|0,m=(o(n,2)^o(n,13)^o(n,22))+p(n,r,i)|0;u=l,l=c,c=s,s=a+d|0,a=i,i=r,r=n,n=d+m|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,r,i,a,s,c,l,u)}roundClean(){i(_)}destroy(){this.set(0,0,0,0,0,0,0,0),i(this.buffer)}},y=class extends v{A=h[0]|0;B=h[1]|0;C=h[2]|0;D=h[3]|0;E=h[4]|0;F=h[5]|0;G=h[6]|0;H=h[7]|0;constructor(){super(32)}},b=u(()=>new y,d(1));function x(e){let t=new Set,n=e=>{for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){let n=e.charCodeAt(++t);if(!(n>=56320&&n<=57343))throw Error(`Non-I-JSON surrogate`)}else if(n>=56320&&n<=57343)throw Error(`Non-I-JSON surrogate`)}return JSON.stringify(e)},r=e=>{if(e===null)return`null`;if(typeof e==`string`)return n(e);if(typeof e==`boolean`)return String(e);if(typeof e==`number`&&Number.isFinite(e))return JSON.stringify(e);if(typeof e!=`object`||t.has(e))throw Error(`Expected acyclic JSON value`);t.add(e);let i;if(Array.isArray(e)){if(Object.keys(e).length!==e.length)throw Error(`Expected dense JSON array`);i=`[${e.map(r).join(`,`)}]`}else{if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw Error(`Expected JSON object`);i=`{${Object.keys(e).sort().map(t=>`${n(t)}:${r(e[t])}`).join(`,`)}}`}return t.delete(e),i};return r(e)}var S=e=>`sha256:${l(b(new TextEncoder().encode(x(e))))}`,C=e=>`kind`in e&&e.kind===`report`,w=e=>`schemaVersion`in e&&e.schemaVersion===2;function T(e){return e.trim().replace(/^\|/,``).replace(/\|$/,``).split(/(?<!\\)\|/).map(e=>e.trim().replace(/\\\|/g,`|`))}var E={low:2,medium:8,high:30},D={minOwnerRequestQuoteLength:8,minStakesLength:20,minQuestionContextLength:20,minOptionsPerQuestion:2,maxOptionsPerQuestion:4,maxQuestionReadingMinutes:2,maxDossierBudgetMinutes:30,wordsPerMinute:180,maxHeadingLength:100,maxDecisionLineLength:300,maxOptionLabelLength:100,maxConsequenceLength:160,maxOptionBodyLength:300,maxCellWords:60,maxBlockCombinedWords:60,maxSentenceWords:22,maxInputLabelWords:12,maxInputLabelLength:100,maxCompletionCriterionSentences:1,maxCompletionCriterionWords:22,maxCompletionCriterionLength:160},O=/\b(?:[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+|[A-Z][A-Z0-9]*\d[A-Z0-9]*[a-z]?|[A-Z]{2,})\b/g,k=new Set([`GO`,`NO-GO`,`NO`,`PENDING`,`DEFERRED`,`LR`,`RL`,`TB`,`BT`,`TD`,`UTF-8`]),A=/\beither\b[\s\S]{0,160}?\bor\b|\bsoit\b[\s\S]{0,160}?\bsoit\b|\b(?:instead of|rather than|plut[oô]t que|versus|vs\.?|choos(?:e|ing) between|choisir entre)\b/i,j=/(?:^|[\n\r\u2028\u2029])\s*(?:[-*+•‣>]|\d+[.)]|[a-z][.)])\s+\S|\([a-z]\)[\s\S]*\([a-z]\)|\b(?:sub[- ]?options?|sous[- ]?options?)\b/i,M=/[\n\r\u2028\u2029]/,ee=/\b01[0-9A-HJKMNP-TV-Z]{24}\b/,te=/\b(?:sha256:)?[0-9a-f]{7,64}\b/i,ne=/\b(?:WP\d+(?:\.\d+)?|D-\d+|O\d{3,4}|A\d{2}|T\d{2}|r\d+-D\d+|J\d+|M\d+|Q\d+|Q-[A-Z]|F\d+|LOT-\d+|AC-\d+|rel-\d+|PR\s*#?\d+|hrpn\/#\d+)\b/,N=/\b(?!h2a\b)\S*\d\S*\b/gi,P=/^(?:En bref\s*:\s+|In short:\s+)/,F=e=>!e?.trim(),I=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{},re=e=>(e.join(` `).match(/\S+/gu)?.length??0)/D.wordsPerMinute,L=e=>String(e??``).trim().split(/\s+/).filter(Boolean),R=e=>String(e??``).trim().split(/(?<=[.!?])\s+/).map(e=>e.trim()).filter(Boolean),ie=e=>e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,` `).replace(/<[^>]+>/g,` `).replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`),z=(e,t)=>{let n=C(e),r=n||(t?.profile??(e.ref===`decision:s1-hello`&&e.hash.startsWith(`draft:s1-hello-`)?`legacy`:`strict`))===`strict`,i=[],a=(e,t,n)=>{i.push({path:e,code:t,message:n})},o=e.readability,s=o?.ownerRequestQuote?.trim()??``;o?.noOwnerRequest===!0?a(`$.readability.noOwnerRequest`,s?`conflicting_owner_request`:`presentation_blocked`,s?`A quoted owner request conflicts with noOwnerRequest: keep the literal request and remove the flag.`:`No owner request: presentation is blocked until the owner's literal request is quoted.`):s?s.length<D.minOwnerRequestQuoteLength&&a(`$.readability.ownerRequestQuote`,`owner_request_too_short`,`Quote the full literal owner request so the owner recognizes their own intention.`):a(`$.readability.ownerRequestQuote`,`missing_owner_request`,`Quote the literal owner request this dossier serves, or set noOwnerRequest to block presentation explicitly.`),F(o?.stakes)?a(`$.readability.stakes`,`missing_stakes`,`State why the decision matters to the owner, using plain words about cost, time or consequences.`):o.stakes.trim().length<D.minStakesLength&&a(`$.readability.stakes`,`stakes_too_short`,`Explain the actual consequence for the owner in at least 20 characters; an internal label is insufficient.`);let c=o?.stakesLevel;(!c||!Object.hasOwn(E,c))&&a(`$.readability.stakesLevel`,`missing_stakes_level`,`Declare stakesLevel: low for a small reversible inconvenience, medium for cost/disruption, high for lasting or major impact.`);let l=o?.readingBudgetMinutes,u=l!==void 0&&Number.isFinite(l)&&l>=1&&l<=D.maxDossierBudgetMinutes;l===void 0?a(`$.readability.readingBudgetMinutes`,`missing_reading_budget`,`Declare a total reading budget in minutes proportionate to the stakes: low up to 2, medium up to 8, high up to 30.`):u?c&&Object.hasOwn(E,c)&&l>E[c]&&a(`$.readability.readingBudgetMinutes`,`reading_budget_disproportionate`,`The ${c} stakes budget is at most ${E[c]} minutes; shorten this dossier or justify a different stakes level.`):a(`$.readability.readingBudgetMinutes`,`reading_budget_out_of_range`,`The total reading budget must be a finite number between 1 and 30 minutes.`);let d=new Map;o?.glossary?.forEach((e,t)=>{if(F(e.term)||F(e.definition))a(`$.readability.glossary[${t}]`,`empty_glossary_entry`,`Give every glossary term a definition in plain words, present and findable when the glossary is opened.`);else{let n=e.term.trim();(d.has(n)||e.definition.trim()===n)&&a(`$.readability.glossary[${t}]`,`invalid_glossary_entry`,`Use one definition per term and expand its meaning; repeating the code does not explain it.`),(e.definition.match(O)??[]).some(e=>!k.has(e))&&a(`$.readability.glossary[${t}].definition`,`invalid_glossary_entry`,`Explain each term independently in plain words, without itself or another code, even one defined elsewhere.`),d.set(n,e.definition)}});let f=(e,t)=>{for(let n of new Set(e?.match(O)??[]))!k.has(n)&&!d.has(n)&&a(t,`undefined_code`,`Unexpanded code or acronym "${n}": define it in the glossary in plain words (folded but present and findable), or rewrite it.`)},p=[],m=(e,t)=>{f(e,t),e&&p.push(e)};w(e)&&(e.sources.forEach((e,t)=>{f(e.title,`$.sources[${t}].title`),f(e.alt,`$.sources[${t}].alt`)}),e.citations.forEach((e,t)=>{f(e.label,`$.citations[${t}].label`),e.locator.kind===`image`&&f(e.locator.caption,`$.citations[${t}].locator.caption`)}),e.evidenceGroups.forEach((e,t)=>{m(e.summary,`$.evidenceGroups[${t}].summary`),S(e.summary,`$.evidenceGroups[${t}].summary`,{requireTakeaway:!0})}),e.annexes.forEach((e,t)=>{m(e.title,`$.annexes[${t}].title`),m(e.summary,`$.annexes[${t}].summary`),S(e.summary,`$.annexes[${t}].summary`,{requireTakeaway:!0}),e.blocks.forEach((e,n)=>{let r=`$.annexes[${t}].blocks[${n}]`;e.kind===`text`&&(f(e.text,`${r}.text`),S(e.text,`${r}.text`,{requireTakeaway:!0})),e.kind===`table`&&([...e.columns,...e.rows.flat()].forEach(e=>f(e,r)),e.rows.forEach((e,t)=>e.forEach((e,n)=>S(e,`${r}.rows[${t}][${n}]`,{requireTakeaway:!1}))))})}));for(let t of[`title`,`subject`])m(e[t],`$.${t}`),F(e[t])&&a(`$.${t}`,`empty_heading`,`Name the subject and decision in a short, non-empty line the owner understands.`),ae(e[t],`$.${t}`,D.maxHeadingLength);s&&p.push(s),m(o?.stakes,`$.readability.stakes`),z(o?.stakes,`$.readability.stakes`),o?.glossary?.forEach((e,t)=>{p.push(e.term),m(e.definition,`$.readability.glossary[${t}].definition`)});let h=(e,t)=>{e.forEach((e,n)=>{m(e.author,`${t}[${n}].author`),m(e.summary,`${t}[${n}].summary`)})};h(e.amendmentTrace,`$.amendmentTrace`),e.interactions.forEach((e,t)=>m(e.label,`$.interactions[${t}].label`));let g=e.sections.filter(e=>e.kind===`question`);n&&(e.sections[0]?.kind!==`prose`||!P.test(e.sections[0].markdown.trim()))&&a(`$.sections[0]`,`report_summary_first`,`Start the report with an En bref : or In short: summary.`);let _=new Set(g.map(e=>e.id));!n&&!g.length&&a(`$.sections`,`missing_question`,`A decision dossier needs an explicit question with context, options and a recommendation.`);let v=(e,t,n)=>{F(e)?n&&a(t,`hidden_decision`,`This content implies a choice without an explicit question: set questionId to the question the owner must answer.`):_.has(e)||a(t,`unknown_question_ref`,`Question "${e}" does not exist in this dossier; link to an explicit question.`)},y=e.sections.filter(e=>e.kind===`optionSet`),b=0;return e.sections.forEach((e,t)=>{let n=`$.sections[${t}]`;switch(e.kind){case`prose`:m(e.markdown,`${n}.markdown`),z(e.markdown,`${n}.markdown`),v(e.questionId,`${n}.questionId`,A.test(e.markdown)),x(e,n);break;case`outcome`:m(e.statement,`${n}.statement`),z(e.statement,`${n}.statement`),v(e.questionId,`${n}.questionId`,e.modality!==`comment`||A.test(e.statement));break;case`diagram`:m(e.alt,`${n}.alt`),e.source!==void 0&&(e.scene===void 0?m(e.source,`${n}.source`):f(e.source,`${n}.source`));for(let[t,r]of[[`entities`,`name`],[`relations`,`label`]])for(let[i,a]of Object.entries(I(e.scene?.[t]))){let e=I(I(I(a).attributes)[r]);e.kind===`text`&&typeof e.value==`string`&&m(e.value,`${n}.scene.${t}.${i}.attributes.${r}.value`)}break;case`amendmentTrace`:h(e.steps,`${n}.steps`);break;case`optionSet`:v(e.questionId,`${n}.questionId`,!0),f(e.title,`${n}.title`),ae(e.title,`${n}.title`,D.maxHeadingLength),e.options.forEach((e,t)=>B(e,`${n}.options[${t}]`));break;case`question`:{F(e.question)&&a(`${n}.question`,`empty_question`,`State the explicit decision the owner needs to make in this question.`),F(e.context)?a(`${n}.context`,`missing_question_context`,`Add representative context in plain words so the question can be understood on its own.`):e.context.trim().length<D.minQuestionContextLength&&a(`${n}.context`,`question_context_too_short`,`Give representative context of at least 20 characters, including what changes for the owner.`),F(e.recommendedAnswer)&&a(`${n}.recommendedAnswer`,`missing_recommendation`,`Recommend an option with a short reason that relates to the owner's request and stakes.`),ae(e.question,`${n}.question`,D.maxDecisionLineLength),ae(e.recommendedAnswer,`${n}.recommendedAnswer`,D.maxDecisionLineLength);let t=y.filter(t=>t.questionId===e.id),r=t.flatMap(e=>e.options);(r.length<2||r.length>4)&&a(n,`option_count`,`Each question needs 2–4 short options; this question has ${r.length}.`),r.some(t=>t.id===e.recommendedOptionId)||a(`${n}.recommendedOptionId`,`unknown_recommended_option`,`Identify the recommended option by its id among this question's options, with the reason in recommendedAnswer.`);let i=[e.question,e.context,e.recommendedAnswer,e.answer,r.find(t=>t.id===e.recommendedOptionId)?.label,...t.map(e=>e.title),...r.flatMap(e=>[e.label,e.consequence,e.body,e.annotationComment])];f(e.question,`${n}.question`),f(e.context,`${n}.context`),f(e.recommendedAnswer,`${n}.recommendedAnswer`),f(e.answer,`${n}.answer`),z(e.context,`${n}.context`),S(e.recommendedAnswer,`${n}.recommendedAnswer`,{requireTakeaway:!0}),S(e.answer,`${n}.answer`,{requireTakeaway:!0}),x(e,n,i);let o=e.readingTimeMinutes,s=re(i);o===void 0?a(`${n}.readingTimeMinutes`,`missing_reading_time`,`Estimate the time to read this question, context and options in readingTimeMinutes (up to 2 minutes).`):!Number.isFinite(o)||o<=0||o>2?a(`${n}.readingTimeMinutes`,`reading_time_exceeded`,`Each question must take a positive finite time of at most 2 minutes; shorten or split it.`):(o<s&&a(`${n}.readingTimeMinutes`,`reading_time_underestimated`,`This question needs at least ${s.toFixed(2)} minutes at 180 words/minute; shorten it or correct its estimate (maximum 2 minutes).`),b+=Math.max(o,s));break}}}),u&&b+re(p)>l&&a(`$.readability.readingBudgetMinutes`,`reading_budget_exceeded`,`The questions plus shared context and glossary exceed the declared reading budget; shorten the dossier to match its stakes.`),i;function x(e,t,n){if(e.inputs?.forEach((e,i)=>{if(e.label===void 0)return;let o=`${t}.inputs[${i}].label`;m(e.label,o),n!==void 0&&n.push(e.label),r&&(L(e.label).length>D.maxInputLabelWords||e.label.trim().length>D.maxInputLabelLength||M.test(e.label))&&a(o,`input_label_too_long`,`Keep each input label to one short line of at most ${D.maxInputLabelWords} words and ${D.maxInputLabelLength} characters.`),S(e.label,o,{requireTakeaway:!1})}),e.completionCriterion!==void 0){let i=e.completionCriterion,o=`${t}.completionCriterion`;m(i,o),n!==void 0&&n.push(i),r&&(R(i).length>D.maxCompletionCriterionSentences||L(i).length>D.maxCompletionCriterionWords||i.trim().length>D.maxCompletionCriterionLength||M.test(i))&&a(o,`completion_criterion_too_long`,`Keep completionCriterion to one sentence of at most ${D.maxCompletionCriterionWords} words and ${D.maxCompletionCriterionLength} characters.`),S(i,o,{requireTakeaway:!1})}}function S(e,t,n){if(!r||!e)return;let i=(n?.isCleaned?e:ie(e)).trim();if(!i)return;let o=L(i).length;o>D.maxCellWords&&a(t,`cell_max_60_words`,`Keep each prose cell or paragraph to at most ${D.maxCellWords} words (found ${o} words).`);let s=R(i);n?.requireTakeaway!==!1&&s.length>1&&!P.test(i)&&a(t,`missing_en_bref_takeaway`,`Start multi-sentence prose blocks with "En bref : " or "In short: " so the reader gets the takeaway first.`),i.includes(`;`)&&a(t,`one_idea_per_sentence_no_semicolon`,`Express one idea per sentence without semicolons; split into separate sentences or use a list.`),/[()]/.test(i)&&a(t,`one_idea_per_sentence_no_parentheses`,`Express one idea per sentence without parenthetical asides; state the point directly or omit it.`),ee.test(i)&&a(t,`no_ulid_in_prose`,`Do not embed ULIDs in prose; keep identifiers in structured fields and use plain words in text.`),te.test(i)&&a(t,`no_hash_or_sha_in_prose`,`Do not embed hashes or SHAs in prose; keep digests in provenance or evidence fields.`),ne.test(i)&&a(t,`no_internal_id_or_lot_code_in_prose`,`Do not embed internal IDs or lot codes in prose, even if listed in the glossary; describe the subject in plain words.`),(i.match(N)??[]).map(e=>e.replace(/^[.,!?:;"'`]+|[.,!?:;"'`]+$/g,``)).some(e=>e.length>0&&!k.has(e.toUpperCase()))&&a(t,`no_raw_count_or_number_in_prose`,`Do not embed raw counts or numbers in prose, even if listed in the glossary; write out plain qualitative words.`);for(let e of s){let n=L(e).length;n>D.maxSentenceWords&&a(t,`sentence_max_22_words`,`Keep every sentence to at most ${D.maxSentenceWords} words (found ${n} words).`),(e.match(/,/g)??[]).length>=3&&a(t,`no_enumeration_in_prose_sentence`,`Avoid three or more commas in a single prose sentence; use a bullet list or table instead of inline enumerations.`),(e.match(/:/g)??[]).length>1&&a(t,`one_idea_per_sentence_max_one_colon`,`Use at most one colon per sentence so each sentence carries a single clear idea.`)}}function z(e,t){if(!r||!e)return;let i=(n?e:ie(e)).split(/\r?\n/),o=[],s=[],c=[],l=()=>{s.length>0&&(o.push({kind:`paragraph`,lines:s}),s=[])},u=()=>{c.length>0&&(o.push({kind:`bullets`,lines:c}),c=[])};for(let e of i){let t=e.trim();if(!t){l(),u();continue}if(/^#{1,6}\s+/.test(t)){l(),u(),o.push({kind:`heading`,lines:[t.replace(/^#{1,6}\s+/,``)]});continue}if(/^\|.*\|$/.test(t)){l(),u(),o.push({kind:`table`,lines:[t]});continue}let n=t.match(/^(?:[-*+•]|\d+[.)])\s+(.*)$/);n?(l(),c.push(n[1])):(u(),s.push(t))}l(),u();for(let e=0;e<o.length;e++){let n=o[e];if(n.kind===`heading`)S(n.lines[0],t,{requireTakeaway:!1,isCleaned:!0});else if(n.kind===`table`){let e=n.lines[0],r=T(e);if(r.every(e=>/^[-:]+$/.test(e)))continue;for(let e of r)S(e,t,{requireTakeaway:!1,isCleaned:!0})}else if(n.kind===`bullets`){L([e>0&&o[e-1].kind===`paragraph`?o[e-1].lines.join(` `):``,...n.lines].filter(Boolean).join(` `)).length>D.maxBlockCombinedWords&&a(t,`block_combined_max_60_words`,`Keep each lead-and-bullet block to at most ${D.maxBlockCombinedWords} words combined.`);for(let e of n.lines)S(e,t,{requireTakeaway:!1,isCleaned:!0})}else S(n.lines.join(` `),t,{requireTakeaway:!0,isCleaned:!0})}}function ae(e,t,n){e&&((e.trim().length>n||M.test(e))&&a(t,`decision_line_too_long`,`Use one short line of at most ${n} characters; put explanation in the question context.`),j.test(e)&&a(t,`nested_suboptions`,`Expose sub-choices as separate options or questions, without nested lists or inline branches.`))}function B(e,t){let n=[{field:`label`,text:e.label,max:D.maxOptionLabelLength,code:`option_too_long`},{field:`consequence`,text:e.consequence,max:D.maxConsequenceLength,code:`consequence_too_long`},{field:`body`,text:e.body,max:D.maxOptionBodyLength,code:`option_too_long`},{field:`annotationComment`,text:e.annotationComment,max:D.maxOptionBodyLength,code:`option_too_long`}];F(e.label)&&a(`${t}.label`,`empty_option_label`,`Name this option in a few plain words so the owner can compare it at a glance.`),F(e.consequence)&&a(`${t}.consequence`,`missing_consequence`,`Add a one-line consequence: what choosing this option changes for the owner.`);for(let{field:e,text:r,max:i,code:o}of n)r&&(f(r,`${t}.${e}`),(r.trim().length>i||M.test(r))&&a(`${t}.${e}`,o,`Keep this option ${e} to one short line of at most ${i} characters; move necessary context to the question.`),(j.test(r)||A.test(r))&&a(`${t}.${e}`,`nested_suboptions`,`This option hides sub-options: expose the choices as separate options or as a separate question.`),e!==`label`&&S(r,`${t}.${e}`,{requireTakeaway:!0}))}},ae=class extends Error{issue;constructor(e){super(e.message),this.issue=e}},B=(e,t,n)=>{throw new ae({path:e,code:t,message:n})};function oe(e,t,n,r=[]){(!e||typeof e!=`object`||Array.isArray(e))&&B(t,`invalid_evidence`,`Expected a closed object`);let i=e;for(let e of Object.keys(i))[...n,...r].includes(e)||B(`${t}.${e}`,`invalid_evidence`,`Unknown evidence field`);for(let e of n)Object.hasOwn(i,e)||B(`${t}.${e}`,`invalid_evidence`,`Missing evidence field`);return i}function se(e,t,n=!1){return(typeof e!=`string`||!n&&!e.trim())&&B(t,`invalid_evidence`,`Expected a non-empty string`),e}function ce(e,t){return Array.isArray(e)||B(t,`invalid_evidence`,`Expected an array`),e}var le=(e,t)=>ce(e,t).map((e,n)=>se(e,`${t}[${n}]`));function ue(e,t){let n=t=>new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t);if(t===`image/png`){if(e.length>=33&&[137,80,78,71,13,10,26,10].every((t,n)=>e[n]===t)&&n(8)===13&&n(12)===1229472850)return[n(16),n(20)]}else if(e[0]===255&&e[1]===216){let t=2;for(;t+4<e.length&&e[t]===255;){let n=e[t+1],r=e[t+2]<<8|e[t+3];if(r<2||t+2+r>e.length)break;if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(n)&&r>=8)return[e[t+7]<<8|e[t+8],e[t+5]<<8|e[t+6]];t+=r+2}}}var V=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],de=(e,t)=>e>>>t|e<<32-t;function fe(e){let t=new Uint8Array(Math.ceil((e.length+9)/64)*64);t.set(e),t[e.length]=128;let n=new DataView(t.buffer),r=e.length*8;n.setUint32(t.length-8,Math.floor(r/4294967296)),n.setUint32(t.length-4,r>>>0);let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],a=new Int32Array(64);for(let e=0;e<t.length;e+=64){for(let t=0;t<16;t++)a[t]=n.getInt32(e+t*4);for(let e=16;e<64;e++){let t=a[e-15],n=a[e-2];a[e]=a[e-16]+(de(t,7)^de(t,18)^t>>>3)+a[e-7]+(de(n,17)^de(n,19)^n>>>10)}let[t,r,o,s,c,l,u,d]=i;for(let e=0;e<64;e++){let n=d+(de(c,6)^de(c,11)^de(c,25))+(c&l^~c&u)+V[e]+a[e]|0,i=(de(t,2)^de(t,13)^de(t,22))+(t&r^t&o^r&o)|0;d=u,u=l,l=c,c=s+n|0,s=o,o=r,r=t,t=n+i|0}[t,r,o,s,c,l,u,d].forEach((e,t)=>{i[t]=i[t]+e|0})}return i.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}function pe(e){if(e.length%4||/[^A-Za-z0-9+/]/.test(e.replace(/={1,2}$/,``)))throw Error(`Invalid base64`);let t=atob(e);if(btoa(t)!==e)throw Error(`Non-canonical base64`);let n=new Uint8Array(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}var me=e=>new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e),he=e=>e.split(/\r\n|\n|\r/),ge=e=>/^text\/[a-z0-9.+-]+$/.test(e)||[`application/json`,`application/yaml`,`application/x-yaml`,`application/x-ndjson`].includes(e);function _e(e,t){let n=new Map;return{sources:ce(e,`$.sources`).map((e,r)=>{let i=`$.sources[${r}]`,a=oe(e,i,[`id`,`title`,`origin`,`mediaType`,`encoding`,`data`,`sha256`,`size`],[`width`,`height`,`alt`]);for(let e of[`id`,`title`,`mediaType`,`sha256`])se(a[e],`${i}.${e}`);t(a.id,`${i}.id`);let o=a.origin,s=o&&Object.hasOwn(o,`uri`)?[`uri`]:[`repo`,`revision`,`path`];oe(o,`${i}.origin`,s);for(let e of s)se(o[e],`${i}.origin.${e}`);a.encoding!==`base64`&&B(`${i}.encoding`,`source_encoding`,`Only original base64 bytes are accepted`);let c=a.mediaType;!ge(c)&&![`image/png`,`image/jpeg`].includes(c)&&B(`${i}.mediaType`,`unsupported_media`,`Unsupported media for source ${a.id}`);let l;try{l=pe(se(a.data,`${i}.data`,!0))}catch{return B(`${i}.data`,`source_encoding`,`Invalid base64 for source ${a.id}`)}if((!Number.isSafeInteger(a.size)||a.size!==l.length)&&B(`${i}.size`,`source_size`,`Byte size mismatch for source ${a.id}`),(!/^[a-f0-9]{64}$/.test(a.sha256)||fe(l)!==a.sha256)&&B(`${i}.sha256`,`source_digest`,`SHA-256 mismatch for source ${a.id}`),ge(c)){try{n.set(a.id,he(me(l)).length)}catch{B(`${i}.data`,`source_encoding`,`Invalid UTF-8 for source ${a.id}`)}for(let e of[`width`,`height`,`alt`])a[e]!==void 0&&B(`${i}.${e}`,`invalid_evidence`,`Image metadata on text`)}else{se(a.alt,`${i}.alt`);let e=ue(l,c);(!e||!Number.isSafeInteger(a.width)||!Number.isSafeInteger(a.height)||e[0]<=0||e[1]<=0||e[0]!==a.width||e[1]!==a.height)&&B(i,`image_metadata`,`Image dimensions/signature mismatch for source ${a.id}`)}return a}),lineCounts:n}}function ve(e,t){try{let{schemaVersion:n,sources:r,citations:i,evidenceGroups:a,annexes:o,...s}=e,c=new Map,l=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return e;let{citationRefs:n,...r}=e;return n!==void 0&&c.set(t,le(n,`${t}.citationRefs`)),r};Array.isArray(s.sections)&&(s.sections=s.sections.map((e,t)=>{let n=l(e,`$.sections[${t}]`);return n?.kind===`optionSet`&&Array.isArray(n.options)?{...n,options:n.options.map((e,n)=>l(e,`$.sections[${t}].options[${n}]`))}:n}));let u=t(s);if(!u.ok)return u;let d=u.value,f=new Set,p=new Set([d.ref]),m=(e,t)=>{f.has(e)&&B(t,`duplicate_id`,`Duplicate id ${e}`),f.add(e)};d.sections.forEach(e=>{m(e.id,`$.sections`),p.add(e.id),p.add(e.targetRef),e.kind===`optionSet`&&e.options.forEach(e=>{m(e.id,`$.sections.options`),p.add(e.id),p.add(e.targetRef)})});let{sources:h,lineCounts:g}=_e(r,m),_=new Map(h.map(e=>[e.id,e])),v=ce(i,`$.citations`).map((e,t)=>{let n=`$.citations[${t}]`,r=oe(e,n,[`id`,`sourceId`,`label`,`locator`]);for(let e of[`id`,`sourceId`,`label`])se(r[e],`${n}.${e}`);m(r.id,`${n}.id`);let i=_.get(r.sourceId)??B(`${n}.sourceId`,`unresolved_source`,`Unknown source ${r.sourceId}`),a=r.locator;return a?.kind===`lines`?(oe(a,`${n}.locator`,[`kind`,`start`,`end`]),g.has(i.id)||B(`${n}.locator`,`citation_media`,`Source ${i.id} is not text`),(!Number.isSafeInteger(a.start)||!Number.isSafeInteger(a.end)||a.start<1||a.end<a.start||a.end>g.get(i.id))&&B(`${n}.locator`,`citation_range`,`Invalid inclusive line range for ${i.id}`)):a?.kind===`image`?(oe(a,`${n}.locator`,[`kind`,`caption`]),se(a.caption,`${n}.locator.caption`),i.mediaType.startsWith(`image/`)||B(`${n}.locator`,`citation_media`,`Source ${i.id} is not an image`)):B(`${n}.locator`,`invalid_evidence`,`Unknown citation locator`),r}),y=new Set(v.map(e=>e.id)),b=(e,t,n,r)=>{let i=le(e,t);for(let e of i)n.has(e)||B(t,r,`Unresolved reference ${e}`);return i};for(let[e,t]of c)b(t,`${e}.citationRefs`,y,`unresolved_citation`);let x=ce(a,`$.evidenceGroups`).map((e,t)=>{let n=`$.evidenceGroups[${t}]`,r=oe(e,n,[`id`,`summary`,`citationRefs`,`sourceRefs`]);return m(se(r.id,`${n}.id`),`${n}.id`),se(r.summary,`${n}.summary`),b(r.citationRefs,`${n}.citationRefs`,y,`unresolved_citation`),b(r.sourceRefs,`${n}.sourceRefs`,new Set(_.keys()),`unresolved_source`),r}),S=ce(o,`$.annexes`).map((e,t)=>{let n=`$.annexes[${t}]`,r=oe(e,n,[`id`,`title`,`summary`,`blocks`,`backRefs`]);return m(se(r.id,`${n}.id`),`${n}.id`),se(r.title,`${n}.title`),se(r.summary,`${n}.summary`),b(r.backRefs,`${n}.backRefs`,p,`unresolved_target`),ce(r.blocks,`${n}.blocks`).forEach((e,t)=>{let r=`${n}.blocks[${t}]`,i=e?.kind;if(i===`text`||i===`code`){let t=oe(e,r,[`kind`,`text`],i===`code`?[`language`]:[]);se(t.text,`${r}.text`,!0),t.language!==void 0&&se(t.language,`${r}.language`)}else if(i===`table`){let t=oe(e,r,[`kind`,`columns`,`rows`]),n=le(t.columns,`${r}.columns`);n.length||B(r,`invalid_evidence`,`A table needs columns`),ce(t.rows,`${r}.rows`).forEach((e,t)=>{let i=ce(e,`${r}.rows[${t}]`);i.forEach((e,n)=>se(e,`${r}.rows[${t}][${n}]`,!0)),i.length!==n.length&&B(r,`invalid_evidence`,`Table row width mismatch`)})}else if(i===`references`){let t=oe(e,r,[`kind`,`citationRefs`]);b(t.citationRefs,`${r}.citationRefs`,y,`unresolved_citation`)}else B(`${r}.kind`,`invalid_evidence`,`Unsupported annex block (no decisions or active content)`)}),r}),C=(e,t)=>c.has(t)?{...e,citationRefs:c.get(t)}:e,w=d.sections.map((e,t)=>C(e.kind===`optionSet`?{...e,options:e.options.map((e,n)=>C(e,`$.sections[${t}].options[${n}]`))}:e,`$.sections[${t}]`));return{ok:!0,value:{...d,schemaVersion:2,sections:w,sources:h,citations:v,evidenceGroups:x,annexes:S}}}catch(e){if(e instanceof ae)return{ok:!1,issues:[e.issue]};throw e}}var ye=class extends Error{issues;constructor(e){super(`invalid DecisionDossierDocument: ${e.map(e=>`${e.path} ${e.code}: ${e.message}`).join(`; `)}`),this.name=`DecisionDossierValidationError`,this.issues=e}},be=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xe=(e,t,n)=>({path:e,code:t,message:n}),Se=(e,t,n,r,i,a)=>{if(!be(e)){a.push(xe(t,`invalid_type`,`expected an object`));return}let o=new Set(n);for(let n of Object.keys(e))o.has(n)||a.push(xe(`${t}.${n}`,`unknown_field`,`field not in the closed schema`));for(let n of r)e[n]===void 0&&a.push(xe(`${t}.${n}`,`missing_field`,`required field is missing`));for(let n of i)e[n]!==void 0&&typeof e[n]!=`string`&&a.push(xe(`${t}.${n}`,`invalid_type`,`expected a string`));return e},Ce=(e,t,n,r)=>{(typeof e!=`string`||!n.includes(e))&&r.push(xe(t,`invalid_enum`,`expected one of: ${n.join(` | `)}`))},we=[`ref`,`subject`,`title`,`hash`,`cursor`,`sections`,`interactions`,`provenance`,`amendmentTrace`],Te=[`ref`,`subject`,`title`,`hash`,`cursor`],Ee=[...we,`readability`],De=(e,t,n)=>{let r=n.length,i=Se(e,t,[`kind`,`id`,`targetRef`,`label`,`body`,`annotation`,`annotationComment`,`consequence`],[`kind`,`id`,`targetRef`,`label`,`annotation`],[`id`,`targetRef`,`label`,`body`,`annotationComment`,`consequence`],n);if(i!==void 0&&(i.kind!==`option`&&n.push(xe(`${t}.kind`,`invalid_discriminator`,`expected "option"`)),Ce(i.annotation,`${t}.annotation`,[`none`,`accept`,`reject`,`comment`],n),n.length===r))return{kind:`option`,id:i.id,targetRef:i.targetRef,label:i.label,...typeof i.body==`string`?{body:i.body}:{},annotation:i.annotation,...typeof i.annotationComment==`string`?{annotationComment:i.annotationComment}:{},...typeof i.consequence==`string`?{consequence:i.consequence}:{}}},Oe=(e,t,n)=>{let r=n.length,i=Se(e,t,[`at`,`author`,`summary`],[`at`,`author`,`summary`],[`at`,`author`,`summary`],n);if(i!==void 0&&n.length===r)return{at:i.at,author:i.author,summary:i.summary}},ke=/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/,Ae=/^[A-Za-z][A-Za-z0-9-]*$/,je=(e,t,n)=>{typeof e==`string`&&e.trim().length===0&&n.push(xe(t,`invalid_type`,`expected a non-blank string`))},Me=(e,t,n)=>{let r=n.length,i=Se(e,t,[`ref`,`kind`,`label`],[`ref`,`kind`],[`ref`,`kind`,`label`],n);if(i!==void 0&&(je(i.ref,`${t}.ref`,n),je(i.kind,`${t}.kind`,n),je(i.label,`${t}.label`,n),n.length===r))return{ref:i.ref,kind:i.kind,...typeof i.label==`string`?{label:i.label}:{}}},Ne=(e,t,n)=>{if(e===void 0)return;if(!Array.isArray(e)){n.push(xe(t,`invalid_type`,`expected an array`));return}let r=[];return e.forEach((e,i)=>{let a=Me(e,`${t}[${i}]`,n);a!==void 0&&r.push(a)}),r},Pe=(e,t,n)=>{if(!be(e)){n.push(xe(t,`invalid_type`,`expected an object`));return}let r=e.kind;if(r!==`prose`&&r!==`question`&&r!==`optionSet`&&r!==`outcome`&&r!==`amendmentTrace`&&r!==`diagram`){n.push(xe(`${t}.kind`,r===void 0?`missing_field`:`unknown_node_kind`,`unknown section kind ${typeof r==`string`?`"${r}"`:` discriminant`}`));return}let i=n.length;switch(r){case`prose`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`markdown`,`questionId`,`inputs`,`completionCriterion`],[`kind`,`id`,`targetRef`,`markdown`],[`id`,`targetRef`,`markdown`,`questionId`,`completionCriterion`],n);if(r===void 0)return;let a=Ne(r.inputs,`${t}.inputs`,n);return je(r.completionCriterion,`${t}.completionCriterion`,n),n.length===i?{kind:`prose`,id:r.id,targetRef:r.targetRef,markdown:r.markdown,...typeof r.questionId==`string`?{questionId:r.questionId}:{},...a===void 0?{}:{inputs:a},...typeof r.completionCriterion==`string`?{completionCriterion:r.completionCriterion}:{}}:void 0}case`question`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`question`,`recommendedAnswer`,`answer`,`state`,`context`,`readingTimeMinutes`,`recommendedOptionId`,`inputs`,`completionCriterion`],[`kind`,`id`,`targetRef`,`question`,`state`],[`id`,`targetRef`,`question`,`recommendedAnswer`,`answer`,`context`,`recommendedOptionId`,`completionCriterion`],n);if(r===void 0)return;Ce(r.state,`${t}.state`,[`open`,`answered`,`validated`],n),r.readingTimeMinutes!==void 0&&(typeof r.readingTimeMinutes!=`number`||!Number.isFinite(r.readingTimeMinutes))&&n.push(xe(`${t}.readingTimeMinutes`,`invalid_type`,`expected a finite number`));let a=Ne(r.inputs,`${t}.inputs`,n);return je(r.completionCriterion,`${t}.completionCriterion`,n),n.length===i?{kind:`question`,id:r.id,targetRef:r.targetRef,question:r.question,...typeof r.recommendedAnswer==`string`?{recommendedAnswer:r.recommendedAnswer}:{},...typeof r.answer==`string`?{answer:r.answer}:{},state:r.state,...typeof r.context==`string`?{context:r.context}:{},...typeof r.recommendedOptionId==`string`?{recommendedOptionId:r.recommendedOptionId}:{},...typeof r.readingTimeMinutes==`number`?{readingTimeMinutes:r.readingTimeMinutes}:{},...a===void 0?{}:{inputs:a},...typeof r.completionCriterion==`string`?{completionCriterion:r.completionCriterion}:{}}:void 0}case`optionSet`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`title`,`options`,`questionId`],[`kind`,`id`,`targetRef`,`options`],[`id`,`targetRef`,`title`,`questionId`],n);if(r===void 0)return;let a=[];return Array.isArray(r.options)?r.options.forEach((e,r)=>{let i=De(e,`${t}.options[${r}]`,n);i!==void 0&&a.push(i)}):n.push(xe(`${t}.options`,`invalid_type`,`expected an array`)),n.length===i?{kind:`optionSet`,id:r.id,targetRef:r.targetRef,...typeof r.title==`string`?{title:r.title}:{},options:a,...typeof r.questionId==`string`?{questionId:r.questionId}:{}}:void 0}case`outcome`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`modality`,`statement`,`questionId`],[`kind`,`id`,`targetRef`,`modality`,`statement`],[`id`,`targetRef`,`statement`,`questionId`],n);return r===void 0||(Ce(r.modality,`${t}.modality`,[`decision`,`orientation`,`amendment`,`comment`],n),n.length!==i)?void 0:{kind:`outcome`,id:r.id,targetRef:r.targetRef,modality:r.modality,statement:r.statement,...typeof r.questionId==`string`?{questionId:r.questionId}:{}}}case`amendmentTrace`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`steps`],[`kind`,`id`,`targetRef`,`steps`],[`id`,`targetRef`],n);if(r===void 0)return;let a=[];return Array.isArray(r.steps)?r.steps.forEach((e,r)=>{let i=Oe(e,`${t}.steps[${r}]`,n);i!==void 0&&a.push(i)}):n.push(xe(`${t}.steps`,`invalid_type`,`expected an array`)),n.length===i?{kind:`amendmentTrace`,id:r.id,targetRef:r.targetRef,steps:a}:void 0}case`diagram`:{let r=Se(e,t,[`kind`,`id`,`targetRef`,`syntax`,`source`,`sourceRef`,`renderComponent`,`alt`,`scene`],[`kind`,`id`,`targetRef`,`alt`],[`id`,`targetRef`,`source`,`sourceRef`,`renderComponent`,`alt`],n);if(r===void 0)return;je(r.alt,`${t}.alt`,n);let a=r.source!==void 0,o=r.sourceRef!==void 0,s=r.syntax!==void 0,c=r.renderComponent!==void 0,l=r.scene!==void 0;return a&&je(r.source,`${t}.source`,n),s&&Ce(r.syntax,`${t}.syntax`,[`mermaid`,`plantuml`],n),o&&typeof r.sourceRef==`string`&&!ke.test(r.sourceRef)&&n.push(xe(`${t}.sourceRef`,`invalid_type`,`expected a URI-like <scheme>:<opaque-id> reference`)),c&&typeof r.renderComponent==`string`&&!Ae.test(r.renderComponent)&&n.push(xe(`${t}.renderComponent`,`invalid_type`,`expected a component identifier matching /^[A-Za-z][A-Za-z0-9-]*$/`)),l&&!be(r.scene)&&n.push(xe(`${t}.scene`,`invalid_type`,`expected a diagram-core SemanticDocument object`)),!a&&!o?(n.push(xe(t,`diagram_source_missing`,`diagram requires either inline (syntax + source) or reference (sourceRef + renderComponent)`)),(s||c)&&n.push(xe(t,`diagram_source_conflict`,`syntax requires source and renderComponent requires sourceRef`))):a&&o?n.push(xe(t,`diagram_source_conflict`,`diagram cannot mix inline source and reference sourceRef`)):a?(s||n.push(xe(`${t}.syntax`,`diagram_source_conflict`,`inline diagram source requires syntax`)),c&&n.push(xe(`${t}.renderComponent`,`diagram_source_conflict`,`inline diagram cannot declare renderComponent`))):(c||n.push(xe(`${t}.renderComponent`,`diagram_source_conflict`,`reference diagram sourceRef requires renderComponent`)),s&&n.push(xe(`${t}.syntax`,`diagram_source_conflict`,`reference diagram cannot declare syntax`)),l&&n.push(xe(`${t}.scene`,`diagram_source_conflict`,`reference diagram cannot carry an inline scene`))),n.length===i?a?{kind:`diagram`,id:r.id,targetRef:r.targetRef,syntax:r.syntax,source:r.source,alt:r.alt,...l?{scene:r.scene}:{}}:{kind:`diagram`,id:r.id,targetRef:r.targetRef,sourceRef:r.sourceRef,renderComponent:r.renderComponent,alt:r.alt}:void 0}}},Fe=(e,t,n)=>{let r=n.length,i=Se(e,t,[`name`,`targetRef`,`label`,`enabled`],[`name`,`targetRef`,`label`,`enabled`],[`name`,`targetRef`,`label`],n);if(i!==void 0&&(i.enabled!==!1&&n.push(xe(`${t}.enabled`,`enabled_action`,`snapshot interactions must stay disabled (enabled:false)`)),n.length===r))return{name:i.name,targetRef:i.targetRef,label:i.label,enabled:!1}},Ie=(e,t,n)=>{let r=n.length,i=Se(e,t,[`term`,`definition`],[`term`,`definition`],[`term`,`definition`],n);if(i!==void 0&&n.length===r)return{term:i.term,definition:i.definition}},Le=(e,t,n)=>{let r=n.length,i=Se(e,t,[`ownerRequestQuote`,`noOwnerRequest`,`stakes`,`stakesLevel`,`readingBudgetMinutes`,`glossary`],[],[`ownerRequestQuote`,`stakes`],n);if(i===void 0)return;i.stakesLevel!==void 0&&Ce(i.stakesLevel,`${t}.stakesLevel`,[`low`,`medium`,`high`],n),i.noOwnerRequest!==void 0&&typeof i.noOwnerRequest!=`boolean`&&n.push(xe(`${t}.noOwnerRequest`,`invalid_type`,`expected a boolean`)),i.readingBudgetMinutes!==void 0&&(typeof i.readingBudgetMinutes!=`number`||!Number.isFinite(i.readingBudgetMinutes))&&n.push(xe(`${t}.readingBudgetMinutes`,`invalid_type`,`expected a finite number`));let a;if(i.glossary!==void 0&&(a=[],Array.isArray(i.glossary)?i.glossary.forEach((e,r)=>{let i=Ie(e,`${t}.glossary[${r}]`,n);i!==void 0&&a.push(i)}):n.push(xe(`${t}.glossary`,`invalid_type`,`expected an array`))),n.length===r)return{...typeof i.ownerRequestQuote==`string`?{ownerRequestQuote:i.ownerRequestQuote}:{},...typeof i.noOwnerRequest==`boolean`?{noOwnerRequest:i.noOwnerRequest}:{},...typeof i.stakes==`string`?{stakes:i.stakes}:{},...i.stakesLevel===void 0?{}:{stakesLevel:i.stakesLevel},...typeof i.readingBudgetMinutes==`number`?{readingBudgetMinutes:i.readingBudgetMinutes}:{},...a===void 0?{}:{glossary:a}}},Re=e=>{let t=[],n=Se(e,`$`,[...Ee],[...we],[...Te],t);if(n===void 0)return{ok:!1,issues:t};let r=[];Array.isArray(n.sections)?n.sections.forEach((e,n)=>{let i=Pe(e,`$.sections[${n}]`,t);i!==void 0&&r.push(i)}):t.push(xe(`$.sections`,`invalid_type`,`expected an array`));let i=[];Array.isArray(n.interactions)?n.interactions.forEach((e,n)=>{let r=Fe(e,`$.interactions[${n}]`,t);r!==void 0&&i.push(r)}):t.push(xe(`$.interactions`,`invalid_type`,`expected an array`));let a,o=Se(n.provenance,`$.provenance`,[`source`,`readAt`,`comprehensionEvidence`],[`source`,`readAt`],[`source`,`readAt`],t);if(o!==void 0){let e;if(o.comprehensionEvidence!==void 0){let n=t.length,r=Se(o.comprehensionEvidence,`$.provenance.comprehensionEvidence`,[`subject`,`dossierHash`,`signature`],[`subject`,`dossierHash`],[`subject`,`dossierHash`,`signature`],t);r!==void 0&&t.length===n&&(e={subject:r.subject,dossierHash:r.dossierHash,...typeof r.signature==`string`?{signature:r.signature}:{}})}a={source:o.source,readAt:o.readAt,...e===void 0?{}:{comprehensionEvidence:e}}}let s=[];Array.isArray(n.amendmentTrace)?n.amendmentTrace.forEach((e,n)=>{let r=Oe(e,`$.amendmentTrace[${n}]`,t);r!==void 0&&s.push(r)}):t.push(xe(`$.amendmentTrace`,`invalid_type`,`expected an array`));let c;return n.readability!==void 0&&(c=Le(n.readability,`$.readability`,t)),t.length>0||a===void 0||n.readability!==void 0&&c===void 0||typeof n.ref!=`string`||typeof n.subject!=`string`||typeof n.title!=`string`||typeof n.hash!=`string`||typeof n.cursor!=`string`?{ok:!1,issues:t}:{ok:!0,value:{ref:n.ref,subject:n.subject,title:n.title,hash:n.hash,cursor:n.cursor,sections:r,interactions:i,provenance:a,amendmentTrace:s,...c===void 0?{}:{readability:c}}}},ze=e=>be(e)&&Object.hasOwn(e,`schemaVersion`)?e.schemaVersion===2?ve(e,Re):{ok:!1,issues:[xe(`$.schemaVersion`,`unsupported_version`,`Supported explicit version: 2; omit schemaVersion for legacy v1`)]}:Re(e),Be=e=>{let t=[],n=new Map,r=(e,r)=>{let i=n.get(e);i===void 0?n.set(e,r):t.push(xe(r,`duplicate_id`,`node id "${e}" already used at ${i}`))};e.sections.forEach((e,t)=>{let n=`$.sections[${t}]`;r(e.id,`${n}.id`),e.kind===`optionSet`&&e.options.forEach((e,t)=>{r(e.id,`${n}.options[${t}].id`)})});let i=new Set(e.sections.filter(e=>e.kind===`question`).map(e=>e.id)),a=new Map;e.sections.forEach((e,n)=>{if(e.kind!==`prose`&&e.kind!==`question`||!e.inputs?.length)return;let r=`$.sections[${n}]`,o=new Map,s=e.kind===`question`?e.id:e.questionId!==void 0&&i.has(e.questionId)?e.questionId:void 0,c=s===void 0?void 0:a.get(s);s!==void 0&&c===void 0&&(c=new Map,a.set(s,c)),e.inputs.forEach((e,n)=>{let i=`${r}.inputs[${n}].ref`,a=o.get(e.ref);if(a!==void 0)t.push(xe(i,`duplicate_input_ref`,`input ref "${e.ref}" already declared at ${a}`));else if(o.set(e.ref,i),c!==void 0){let n=c.get(e.ref);if(n!==void 0){t.push(xe(i,`duplicate_input_ref`,`input ref "${e.ref}" already declared on linked section at ${n}`));return}c.set(e.ref,i)}})});let o=new Set([e.ref]);for(let t of e.sections)if(o.add(t.id),o.add(t.targetRef),t.kind===`optionSet`)for(let e of t.options)o.add(e.id),o.add(e.targetRef);e.interactions.forEach((e,n)=>{o.has(e.targetRef)||t.push(xe(`$.interactions[${n}].targetRef`,`unresolved_target`,`interaction target "${e.targetRef}" resolves to no node`))});let s=e.provenance.comprehensionEvidence;return s!==void 0&&s.dossierHash!==e.hash&&t.push(xe(`$.provenance.comprehensionEvidence.dossierHash`,`evidence_mismatch`,`comprehension evidence does not match the snapshot hash`)),t},Ve=e=>{let t=ze(e);if(!t.ok)return t;let n=Be(t.value);return n.length>0?{ok:!1,issues:n}:t},He=e=>{if(!be(e)||e.kind!==`report`)return Ve(e);if(e.schemaVersion!==2)return{ok:!1,issues:[xe(`$.schemaVersion`,`unsupported_version`,`Reports require the evidence envelope schemaVersion: 2.`)]};let{kind:t,...n}=e,r=Ve(n);if(!r.ok)return r;let i=[];return r.value.sections.forEach((e,t)=>{(![`prose`,`diagram`,`amendmentTrace`].includes(e.kind)||`questionId`in e)&&i.push(xe(`$.sections[`+t+`]`,`report_decision_content`,`Reports cannot contain questions, choices, outcomes or question references.`))}),r.value.interactions.length&&i.push(xe(`$.interactions`,`report_interactions`,`Reports have no decision interactions.`)),i.length?{ok:!1,issues:i}:{ok:!0,value:{...r.value,kind:`report`}}},Ue=e=>{let t=He(e);if(!t.ok)throw new ye(t.issues);return t.value},We=e=>{let t=He(e);if(!t.ok)return t;let n=z(t.value);return n.length?{ok:!1,issues:n}:t},Ge=e=>{let t=We(e);if(!t.ok)throw new ye(t.issues);return t.value};function Ke(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function qe(e){let t=[],n=e=>(t.push(e),`\u0000${t.length-1}\u0000`),r=Ke(e);return r=r.replace(/`([^`]+)`/g,(e,t)=>n(`<code>${t}</code>`)),r=r.replace(/\[([^\]]*)\]\((https:\/\/[^)\s]+)\)/g,(e,t,r)=>{let i=r.replace(/"/g,`%22`);return n(`<a href="${i}">${t}</a>`)}),r=r.replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`),r=r.replace(/\*([^*]+)\*/g,`<em>$1</em>`),r.replace(/\u0000(\d+)\u0000/g,(e,n)=>t[Number(n)]??``)}function Je(e,t){return e[t]??``}function Ye(e){return/^- /.test(e)}function Xe(e,t=!1){let n=e.replace(/\r\n?/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`),r=[],i=0;for(;i<n.length;){let e=Je(n,i);if(e.trim()===``){i+=1;continue}if(Ye(e)){let e=[];for(;i<n.length&&Ye(Je(n,i));)e.push(`<li>${qe(Je(n,i).slice(2))}</li>`),i+=1;r.push(`<ul>\n${e.join(`
|
|
4
|
+
`)}\n</ul>`);continue}if(t&&e.includes(`|`)&&Je(n,i+1).includes(`|`)){let t=e=>e.trim().replace(/^\||(?<!\\)\|$/g,``).split(/(?<!\\)\|/).map(e=>e.trim().replace(/\\\|/g,`|`)),a=t(e),o=t(Je(n,i+1));if(a.length===o.length&&o.every(e=>/^:?-{3,}:?$/.test(e))){let e=a.map(e=>`<th>${qe(e)}</th>`).join(``),o=[];for(i+=2;Je(n,i).includes(`|`);){let e=t(Je(n,i));o.push(`<tr>${a.map((t,n)=>`<td>${qe(e[n]??``)}</td>`).join(``)}</tr>`),i+=1}r.push(`<table><thead><tr>${e}</tr></thead><tbody>${o.join(``)}</tbody></table>`);continue}}let a=[];for(;i<n.length;){let e=Je(n,i);if(e.trim()===``||Ye(e))break;a.push(qe(e)),i+=1}r.push(`<p>${a.join(`
|
|
5
|
+
`)}</p>`)}return r.join(`
|
|
6
|
+
`)}var Ze={gapMin:96,gapMinBlock:72,gapBase:64,gapBaseBlock:8,trackSpacing:14,trackSpacingBlock:7,labelBand:30,gapMax:240,containerPadding:16,zoneGutter:96,routeSpacing:24,routeBorderClearance:15},Qe=`M8 53L32 44L56 53L32 62Z`;function $e(e,t,n){return{base:Qe,face:e,...t===void 0||t===``?{}:{line:t},...n}}var et={base:$e(`M10 12H54V48H10Z`,`M18 22H46M18 32H40`),s3:$e(`M12 18Q32 6 52 18L47 47Q32 58 17 47Z`,`M12 18Q32 30 52 18M18 29Q32 38 46 29`,{text:`S3`}),postgres:$e(`M12 16Q32 4 52 16V47Q32 59 12 47Z`,`M12 16Q32 28 52 16M12 28Q32 40 52 28M12 40Q32 52 52 40`),cluster:$e(`M32 7L54 20V44L32 57L10 44V20Z`,`M32 19V32M21 26L32 32L43 26M32 32V46M32 32L20 40M32 32L44 40`),web:$e(`M8 12H56V49H8Z`,`M8 23H56M15 18H17M22 18H24M16 31H30V42H16ZM37 32H48M37 40H48`),api:$e(`M8 12H56V50H8Z`,`M22 24L15 31L22 38M42 24L49 31L42 38M35 22L29 40`),cronjob:$e(`M32 8A24 24 0 1 1 31.9 8Z`,`M32 16V32L43 39M17 16L12 21M47 16L52 21`),identity:$e(`M32 6L52 14V31Q50 48 32 58Q14 48 12 31V14Z`,`M26 29V24A6 6 0 0 1 38 24V29M23 29H41V42H23ZM32 34V37`),workstation:$e(`M8 10H56V42H8Z`,`M13 15H51V37H13ZM24 43V51M40 43V51M17 53H47M18 23L24 27L18 31M30 31H39`),document:$e(`M15 6H37L50 19V57H15Z`,`M37 6V19H50M23 28H42M23 36H42M23 44H35`),map:$e(`M7 16L24 9L41 16L57 9V49L41 56L24 49L7 56Z`,`M24 9V49M41 16V56M13 29L24 25L41 35L51 31`),join:$e(`M8 12H24V27H8ZM40 12H56V27H40ZM24 42H40V57H24Z`,`M16 27V34H48V27M32 34V42`,{darkLine:!0}),graph:$e(`M7 10H23V26H7ZM41 10H57V26H41ZM24 42H40V58H24Z`,`M23 18H41M15 26L27 42M49 26L37 42`,{darkLine:!0}),check:$e(`M14 8H50V57H14Z`,`M23 8V15H41V8M23 35L30 42L43 27`),release:$e(`M12 31L32 20L52 31V50L32 61L12 50Z`,`M12 31L32 42L52 31M32 42V61M32 5V25M24 13L32 5L40 13`),user:$e(`M22 17A10 10 0 1 1 42 17A10 10 0 1 1 22 17ZM12 54V44Q12 31 25 31H39Q52 31 52 44V54Z`,`M20 44V54M44 44V54`),url:$e(`M32 7A25 25 0 1 1 31.9 7Z`,`M7 32H57M12 19H52M12 45H52M32 7C16 19 16 45 32 57C48 45 48 19 32 7Z`),llm:$e(`M17 17H47V47H17Z`,`M25 25H39V39H25ZM25 8V17M39 8V17M25 47V56M39 47V56M8 25H17M8 39H17M47 25H56M47 39H56`),network:$e(`M24 7H40V23H24ZM5 42H21V58H5ZM43 42H59V58H43Z`,`M32 23V33M13 42V33H51V42`,{darkLine:!0}),unknown:$e(`M32 6L59 55H5Z`,`M32 24V38M32 45V46`),people:$e(`M22 10a8 8 0 1 1 0 16a8 8 0 1 1 0-16Z M42 14a7 7 0 1 1 0 14a7 7 0 1 1 0-14Z M8 46c0-9 6-15 14-15s14 6 14 15Z M34 46c0-8 4-13 9-13s12 5 12 13Z`),window:$e(`M9 11h46v36H9Z`,`M9 19h46 M16 28h32 M16 35h22`),server:$e(`M14 8h36v14H14Z M14 25h36v14H14Z`,`M20 15h10 M20 32h10 M42 15h.1 M42 32h.1`),brain:$e(`M32 12c-4-7-15-5-16 3c-8 1-11 11-6 17c-5 8 0 17 8 17c5 5 12 3 14-2c2 5 9 7 14 2c8 0 13-9 8-17c5-6 2-16-6-17c-1-8-12-10-16-3Z`,`M32 12v35 M16 15c0 6 4 9 9 9 M10 32c4-4 9-3 12 1 M18 49c-2-5 0-10 5-12 M48 15c0-6-4-9-9-9 M54 32c-4-4-9-3-12 1 M46 49c2-5 0-10-5-12`),robot:$e(`M14 16h36v31H14Z M8 25h6v13H8Z M50 25h6v13h-6Z M29 6h6v5h-6Z`,`M32 11v5 M23 27h.1 M41 27h.1 M23 38h18`),link:$e(`M10 12h16v14H10Z M38 30h16v14H38Z`,`M26 19h12v11`,{darkLine:!0}),db:$e(`M14 13c0-4 8-7 18-7s18 3 18 7v29c0 4-8 7-18 7s-18-3-18-7Z`,`M14 13c0 4 8 7 18 7s18-3 18-7 M14 27c0 4 8 7 18 7s18-3 18-7`),shield:$e(`M32 7l20 7v13c0 12-8 20-20 25C20 47 12 39 12 27V14Z`,`M23 29l6 6 12-13`),cloud:$e(`M18 44a10 10 0 0 1 0-20a14 14 0 0 1 27-4a11 11 0 0 1 3 24Z`)};Object.keys(et);function tt(e){return Object.hasOwn(et,e)?et[e]:void 0}var nt={width:460,height:200,borderWidth:2,accentWidth:8,padding:8,headerInset:16,iconSize:70,iconTextGap:6,kicker:{size:22,weight:400,lineHeight:1.3,letterSpacingEm:.04},title:{size:32,weight:700,lineHeight:1.3},gap:6,body:{size:24,weight:400,lineHeight:1.3},edgeLabel:{size:18,weight:400,lineHeight:22/18},bodyInsetFromBar:14,ruleHeight:1,ruleMargin:4,ruleInsetStart:16,ruleInsetEnd:10,footer:{size:24,weight:700,lineHeight:1.3},footerBottomInset:9.25,toggleAllocation:66,toggleBoxSize:32,toggleInset:8,foldedHeaderTextWidth:290,allocatedLines:{kicker:1,title:2,body:2,footer:1}},rt={...nt,width:352,height:154,padding:6,accentWidth:6,headerInset:12,iconSize:52,iconTextGap:4,bodyInsetFromBar:10,foldedHeaderTextWidth:210,allocatedLines:{kicker:1,title:1,body:2,footer:1}};function it(e){return e===`v2`?rt:nt}function at(e,t){return e===`v1`?`left`:t??`left`}var ot={size:16,lineHeight:20},st={size:18,weight:400,lineHeight:22};function ct(e){return Math.floor(e*1.3*64)/64}function lt(e,t){return e+(t===24?22:t)}function ut(e,t){if(e===void 0||e.form!==`card`)return{kind:`label`};let n=e.text.title??``;if(n===``)return{kind:`label`};let r=[];e.text.body!==void 0&&e.text.body!==``&&r.push(e.text.body);let i=0;e.text.detail!==void 0&&e.text.detail!==``&&(r.push(e.text.detail),i=1);let a=e.icon??`base`;return{kind:`card`,props:{entityId:t.entityId,...e.text.kicker===void 0||e.text.kicker===``?{}:{kicker:e.text.kicker},title:n,body:r,...i===0?{}:{detailCount:i},...e.text.footer===void 0||e.text.footer===``?{}:{footer:e.text.footer},...a===void 0?{}:{icon:a},...a===void 0||t.resolveGlyph===void 0?{}:(()=>{let e=t.resolveGlyph(a);return e===void 0?{}:{iconGlyph:e}})(),...e.categoryRef===void 0?{}:{tone:e.categoryRef},...e.proposed===void 0?{}:{proposed:e.proposed},...t.toggle===void 0?{}:{toggle:t.toggle},...(()=>{let n=e.anatomy??t.anatomy;return n===void 0?{}:{anatomy:n}})(),...(()=>{let n=e.align??t.align;return n===void 0?{}:{align:n}})()}}}function dt(e,t,n=!1,r){return Object.assign((t,i,a)=>{let o=[],s=!1;for(let r of t.split(`
|
|
7
|
+
`)){let t=``,c=!1;for(let l of r.match(/\s+|[^\s·/_.-]+[·/_.-]?|[·/_.-]/gu)??[]){if(/^\s+$/.test(l)){c=!0;continue}let r=c&&t!==``?` `:``;c=!1;let u=t+r+l;if(t!==``&&e(u,i)>a&&(o.push(t),t=``),n&&e(l,i)>a)for(let n of l)t!==``&&e(t+n,i)>a&&(o.push(t),t=``),t+=n,e(n,i)>a&&(s=!0);else t=t===``?l:u,e(l,i)>a&&(s=!0)}t!==``&&o.push(t)}let c=r?.(i);return{lines:o,tooWide:s,lineWidths:o.map(t=>e(t,i)),...c===void 0?{}:{lineHeight:c}}},{version:t})}function ft(e){let t=e.version;return t?.endsWith(`:scene-wrap`)||e(`Mm09`,`body`,1e3,1).lineWidths===void 0?e:dt((t,n)=>{let r=e(t,n,2**53-1,2**53-1),i=Math.max(0,...r.lineWidths??[t.length*nt[n].size]);return e===_t?i===0?0:(i-2)*ht+2:i},`${t??`inter-fallback-1.12-v2`}:scene-wrap`,!0,t=>e(`Mg`,t,1e3,1).lineHeight)}var pt={0:.67,1:.43,2:.63,3:.65,4:.68,5:.62,6:.65,7:.58,8:.65,9:.65,"\n":.24," ":.24,'"':.55,"#":.65,"%":1.02,"&":.67,"'":.34,"(":.38,")":.38,"*":.56,"+":.68,",":.33,"-":.47,".":.33,"/":.39,":":.33,";":.34,"<":.68,"=":.68,">":.68,"@":1.02,A:.75,B:.66,C:.74,D:.72,E:.61,F:.59,G:.75,H:.75,I:.28,J:.58,K:.72,L:.57,M:.93,N:.76,O:.77,P:.65,Q:.78,R:.66,S:.65,T:.67,U:.73,V:.75,W:1.04,X:.74,Y:.73,Z:.66,"[":.38,"\\":.39,"]":.38,_:.48,a:.58,b:.63,c:.59,d:.63,e:.6,f:.4,g:.63,h:.62,i:.27,j:.27,k:.58,l:.27,m:.91,n:.62,o:.61,p:.63,q:.63,r:.41,s:.56,t:.37,u:.62,v:.6,w:.85,x:.58,y:.6,z:.57,"{":.47,"}":.47,"§":.57,"«":.66,"·":.33,"»":.66,À:.75,Ç:.74,È:.61,É:.61,"×":.68,à:.58,â:.58,ç:.59,è:.6,é:.6,ê:.6,î:.27,ô:.61,ù:.62,"–":.5,"’":.31,"…":1,"→":1,"↔":1,"≠":.83203,"≥":.83203},mt={0:.59961,1:.59961,2:.59961,3:.59961,4:.59961,5:.59961,6:.59961,7:.59961,8:.59961,9:.59961,"\n":.2998," ":.2998,'"':.45996,"#":.59961,"%":.69922,"&":.67969,"'":.2998,"(":.2998,")":.2998,"*":.59961,"+":.59961,",":.2998,"-":.2998,".":.2998,"/":.51953,":":.2998,";":.2998,"<":.59961,"=":.59961,">":.59961,"@":.7998,A:.55957,B:.61914,C:.61914,D:.65918,E:.55957,F:.47949,G:.65918,H:.65918,I:.25977,J:.39941,K:.61914,L:.5,M:.81934,N:.65918,O:.65918,P:.55957,Q:.65918,R:.61914,S:.61914,T:.5,U:.63965,V:.55957,W:.81934,X:.53906,Y:.55957,Z:.53906,"[":.2998,"\\":.51953,"]":.2998,_:.5,a:.53906,b:.53906,c:.47949,d:.53906,e:.53906,f:.2998,g:.5,h:.53906,i:.23926,j:.21973,k:.5,l:.23926,m:.81934,n:.53906,o:.53906,p:.53906,q:.53906,r:.31934,s:.51953,t:.31934,u:.53906,v:.43945,w:.65918,x:.43945,y:.41992,z:.41992,"{":.2998,"}":.2998,"§":.59961,"«":.39941,"·":.23926,"»":.39941,À:.55957,Ç:.61914,È:.55957,É:.55957,"×":.59961,à:.53906,â:.53906,ç:.47949,è:.53906,é:.53906,ê:.53906,î:.23926,ô:.53906,ù:.53906,"–":.55566,"’":.22168,"…":1,"→":1,"↔":1,"≠":.83203,"≥":.83203},ht=1.12,gt=`inter-fallback-1.12-v2`;function _t(e,t,n){let r=t===`kicker`?nt.kicker.size:t===`title`?nt.title.size:t===`footer`?nt.footer.size:nt.body.size,i=t===`title`||t===`footer`?pt:mt,a=t===`kicker`?r*nt.kicker.letterSpacingEm:0;return dt(e=>{if(e.length===0)return 0;let n=t===`kicker`?e.toUpperCase():e,o=0;for(let e of n)o+=(i[e]??.7)*r+a;return o+2},gt,!0)(e,t,n,2**53-1)}function vt(e=_t){return Object.assign(t=>{let n=t.role===`kicker`||t.role===`title`||t.role===`footer`?t.role:`body`;if(t.role===`edge-label`||t.role===`flow-badge`){let n=t.role===`flow-badge`?ot.size:st.size,r=t.role===`flow-badge`?ot.lineHeight:st.lineHeight,i=n/nt.body.size,a=e(t.text,`body`,t.availableWidth/i,t.allocatedLines);return{lines:a.lines,width:a.lineWidths===void 0?t.availableWidth:Math.max(0,...a.lineWidths)*i,height:a.lines.length*Math.max(r,(a.lineHeight??0)*i),overflow:a.tooWide||a.lines.length>t.allocatedLines}}let r=e(t.text,n,t.availableWidth,t.allocatedLines),i=n===`kicker`?nt.kicker.size:n===`title`?nt.title.size:nt.body.size,a=r.lineWidths===void 0?t.availableWidth:Math.max(0,...r.lineWidths);return{lines:r.lines,width:a,height:r.lines.length*ct(i),overflow:r.tooWide||r.lines.length>t.allocatedLines}},{version:e.version??`inter-fallback-1.12-v2`})}function yt(e){let t=nt,n=ct(t.kicker.size),r=ct(t.title.size),i=e.kickerLines*n+e.titleLines*r,a=e.iconSize??t.iconSize,o=e.hasIcon?Math.max(a,i):i;return{kickerHeight:n,titleHeight:r,contentHeight:i,blockHeight:o,textTopOffset:(o-i)/2,iconTopOffset:e.hasIcon?(o-a)/2:0}}function bt(e,t,n,r,i,a){let o=i(e,t,n,r),s=e=>{let r=i(e,t,n,1);return!r.tooWide&&r.lines.length<=1&&(r.lineWidths?.[0]??n)<=n},c=o.lines.slice(0,r).map((e,t)=>o.lineWidths?.[t]!==void 0&&o.lineWidths[t]<=n||s(e)?e:l(e));function l(e){let t=[...e];for(;t.length>0&&!s(t.join(``).trimEnd()+`…`);)t.pop();let n=t.join(``).trimEnd(),r=n.replace(/\s+\S*$/u,``);return(r&&r!==n?r:n)+`…`}return o.lines.length>r&&c.length>0&&(c[c.length-1]=l(c.at(-1).replace(/…$/u,``))),(o.lines.length>r||c.some((e,t)=>e!==o.lines[t]))&&a({neededPx:o.lines.length*ct(nt[t].size),allocatedPx:r*ct(nt[t].size),text:e,severity:`info`,reason:`truncated`,hiddenLength:Math.max(1,e.length-c.join(` `).replaceAll(`…`,``).length)}),c}function xt(e){return[e.kicker,e.title,...e.body,e.footer].filter(Boolean).join(`
|
|
8
|
+
`)}function St(e){return[e.kicker,e.title,e.subtitle,e.footer].filter(Boolean).join(`
|
|
9
|
+
`)}function Ct(e,t,n,r){let i=e.icon??`base`,a=i===`none`,o=!a&&e.iconGlyph===void 0&&tt(i)===void 0;e={...e,autoSize:e.autoSize??!0,icon:o?`unknown`:i,iconGlyph:a?{face:``}:e.iconGlyph??tt(i)??tt(`unknown`)};let s=it(n),c=o?[{code:`card-icon-missing`,slot:`icon`,entityId:e.entityId,neededPx:1,allocatedPx:0}]:[],l=e.bodyMode??`leaf`,u=s.borderWidth+s.padding,d=s.width-s.borderWidth-s.padding,f=!a&&e.icon!==void 0&&e.iconGlyph!==void 0,p=f?s.headerInset+s.iconSize+s.iconTextGap:s.headerInset,m=e.toggle===void 0?d-p:f?s.foldedHeaderTextWidth:d-s.toggleAllocation-p,h=r===`center`?`middle`:`start`,g=r===`center`?p+m/2:p,_=(n,r,i,a,o=r)=>bt(n,r,i,a,t,t=>c.push({...t,code:`card-overflow`,slot:o,entityId:e.entityId}));o&&c.push({code:`card-icon-unknown`,slot:`icon`,entityId:e.entityId,neededPx:1,allocatedPx:0});let v=e.kicker===void 0?[]:_(e.kicker,`kicker`,m,s.allocatedLines.kicker),y=e.footer===void 0?s.borderWidth+s.padding:ct(s.footer.size)+s.ruleHeight+2*s.ruleMargin+s.borderWidth+s.footerBottomInset,b=Math.max(1,Math.min(s.allocatedLines.title,Math.floor((s.height-u-s.gap-y-(e.body.length>0?ct(s.body.size):0)-v.length*ct(s.kicker.size))/ct(s.title.size)))),x=_(e.title,`title`,m,b),S=yt({hasIcon:f,kickerLines:v.length,titleLines:x.length,iconSize:s.iconSize}),C=S.kickerHeight,w=S.titleHeight,T=S.blockHeight,E=u+S.textTopOffset,D=f?{x:s.headerInset,y:u+S.iconTopOffset,size:s.iconSize}:void 0,O=ct(s.body.size),k=u+T+s.gap,A=l===`subtitle`,j=s.width-2*(Dt(n).collapsedInset+Dt(n).collapsedSubtitleMarginInline),M=A?(s.width-j)/2:s.bodyInsetFromBar,ee=A?j:d-M,te=M+ee/2,ne=[],N=0;for(let[n,r]of e.body.entries()){let i=t(r,`body`,ee,s.allocatedLines.body);ne.push(...i.lines),n>=e.body.length-(e.detailCount??0)&&(N+=i.lines.length)}let P=A?`collapsed-subtitle`:`body`,F=e.body.join(`
|
|
10
|
+
`),I=ct(s.footer.size),re=s.height-s.borderWidth-s.footerBottomInset,L=[],R;if(e.footer!==void 0){let t=d-s.headerInset,n=_(e.footer,`footer`,t,s.allocatedLines.footer),i=r===`center`?`middle`:`start`,a=i===`middle`?s.headerInset+t/2:s.headerInset,o=n.length*I;L=n.map((e,t)=>({text:e,x:a,baseline:lt(re-o+t*I,s.footer.size),size:s.footer.size,weight:s.footer.weight,secondary:!1,anchor:i})),R=re-o-s.ruleHeight-s.ruleMargin}let ie=R===void 0?s.height-s.borderWidth-s.padding:R-s.ruleMargin,z=_(F,`body`,ee,Math.max(0,Math.floor((ie-k)/O)),P),ae=k+Math.max(0,(ie-k-z.length*O)/2),B=ne.length-N,oe=z.map((t,n)=>({text:t,x:te,baseline:lt(ae+n*O,s.body.size),size:s.body.size,weight:s.body.weight,secondary:!A&&n>=B&&(e.detailCount??0)>0,anchor:`middle`})),se=ae+z.length*O,ce=v.map((e,t)=>({text:e,x:g,baseline:lt(E+t*C,s.kicker.size),size:s.kicker.size,weight:s.kicker.weight,secondary:!0,anchor:h})),le=E+v.length*C,ue=x.map((e,t)=>({text:e,x:g,baseline:lt(le+t*w,s.title.size),size:s.title.size,weight:s.title.weight,secondary:!1,anchor:h})),V=e.toggle===void 0?void 0:{x:s.width-s.toggleInset-s.toggleBoxSize,y:s.toggleInset,size:s.toggleBoxSize};return{icon:{name:e.icon,glyph:e.iconGlyph},box:{width:s.width,height:s.height},contentTop:u,contentRight:d,...D===void 0?{}:{iconBox:D},headerTextX:p,headerTextWidth:m,kicker:ce,title:ue,headerBlockHeight:T,bodyX:M,bodyWidth:ee,bodyArea:{top:k,bottom:ie},body:oe,bodyBottom:se,...R===void 0?{}:{ruleY:R},ruleX1:s.ruleInsetStart,ruleX2:s.width-s.ruleInsetEnd,footerLines:L,footerBottom:re,...V===void 0?{}:{toggleBox:V},diagnostics:c}}function wt(e,t){let n=at(e.anatomy,e.align),r=Ct(e,t,e.anatomy,n);if(e.anatomy!==`v2`)return r;let i=r.diagnostics.filter(e=>e.code===`card-overflow`);if(i.length===0)return r;let a=Ct(e,t,`v1`,`left`),o=a.diagnostics.some(e=>e.code===`card-overflow`)?[...a.diagnostics]:[...a.diagnostics,...i.map(e=>({code:`card-overflow`,slot:e.slot,entityId:e.entityId,neededPx:e.neededPx,allocatedPx:e.allocatedPx,...e.text===void 0?{}:{text:e.text},severity:`info`,reason:`fallback-v1`}))];return{...a,anatomyFallback:`v1`,diagnostics:o}}var Tt={radius:0,borderWidth:1.5,headerInset:nt.headerInset,iconSize:nt.iconSize,iconTextGap:nt.iconTextGap,kicker:nt.kicker,title:nt.title,subtitle:nt.body,subtitleGap:nt.gap,headerRuleGap:4,contentInsetTop:Ze.containerPadding,contentInsetBottom:Ze.containerPadding,contentInsetInline:Ze.containerPadding,ruleHeight:nt.ruleHeight,ruleMargin:nt.ruleMargin,ruleInsetStart:nt.ruleInsetStart,ruleInsetEnd:nt.ruleInsetEnd,footer:nt.footer,footerBottomInset:nt.footerBottomInset,toggleAllocation:nt.toggleAllocation,toggleBoxSize:nt.toggleBoxSize,toggleTopInset:nt.toggleInset,toggleInset:nt.toggleInset,headerTextInset:178,collapsedWidth:nt.width,collapsedHeight:nt.height,collapsedInset:16,collapsedSubtitleMarginInline:16,allocatedLines:{kicker:1,title:2,subtitle:2,footer:1}},Et={...Tt,headerInset:rt.headerInset,iconSize:rt.iconSize,iconTextGap:rt.iconTextGap,headerTextInset:154,collapsedWidth:rt.width,collapsedHeight:rt.height,collapsedInset:12,collapsedSubtitleMarginInline:12,allocatedLines:{kicker:1,title:1,subtitle:2,footer:1}};function Dt(e){return e===`v2`?Et:Tt}function Ot(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.floor(e))}function kt(e,t=0){return(Ot(e)+t)%2==0?`surface1`:`surface2`}Tt.collapsedWidth-2*(Tt.collapsedInset+Tt.collapsedSubtitleMarginInline);function At(e){return e={...e,icon:e.icon??`cluster`},{...e.autoSize===void 0?{}:{autoSize:e.autoSize},...e.height===void 0?{}:{height:e.height},...e.anatomy===void 0?{}:{anatomy:e.anatomy},entityId:e.entityId,...e.kicker===void 0?{}:{kicker:e.kicker},title:e.title,body:e.subtitle===void 0||e.subtitle===``?[]:[e.subtitle],...e.footer===void 0?{}:{footer:e.footer},...e.icon===void 0?{}:{icon:e.icon},...e.iconGlyph===void 0?{}:{iconGlyph:e.iconGlyph},...e.tone===void 0?{}:{tone:e.tone},...e.proposed===void 0?{}:{proposed:e.proposed},...e.toggleLabel===void 0?{}:{toggle:{collapsed:!0,label:e.toggleLabel}},...e.align===void 0?{}:{align:e.align},...e.depth===void 0&&e.depthParityStart===void 0?{}:{surface:kt(e.depth,e.depthParityStart)},bodyMode:`subtitle`}}function jt(e,t){return e.kind===`card`?e.card===void 0?nt.height:wt(e.card,t).box.height:e.zone===void 0?Tt.collapsedHeight:Mt(e.zone,t,e.children??[]).box.height}function Mt(e,t,n=[]){let r=e.icon??`cluster`,i=r===`none`,a=!i&&e.iconGlyph===void 0&&tt(r)===void 0;e={...e,autoSize:e.autoSize??!0,icon:a?`unknown`:r,iconGlyph:i?{face:``}:e.iconGlyph??tt(r)??tt(`unknown`)};let o={...Dt(e.anatomy),...e.containerPadding===void 0?{}:{contentInsetTop:e.containerPadding,contentInsetBottom:e.containerPadding,contentInsetInline:e.containerPadding}},s=e.x??0,c=e.y??0,l=a?[{code:`card-icon-missing`,slot:`icon`,entityId:e.entityId,neededPx:1,allocatedPx:0}]:[],u=e.depth!==void 0||e.depthParityStart!==void 0,d=Ot(e.depth),f=kt(e.depth,e.depthParityStart);if(e.reportSurfaceSame===!0&&f===`surface1`&&n.some(e=>e.kind===`card`&&e.zone===void 0&&e.card?.tone===void 0)&&l.push({code:`zone-surface-same`,slot:`surface`,entityId:e.entityId,neededPx:1,allocatedPx:0}),a&&l.push({code:`zone-icon-unknown`,slot:`icon`,entityId:e.entityId,neededPx:1,allocatedPx:0}),e.collapsed){let n=wt(At(e),t);for(let e of n.diagnostics)l.push({code:e.code===`card-icon-missing`?`card-icon-missing`:e.code===`card-icon-unknown`?`zone-icon-unknown`:e.code===`card-grown`?`zone-grown`:`zone-overflow`,slot:e.slot,entityId:e.entityId,neededPx:e.neededPx,allocatedPx:e.allocatedPx,...e.text===void 0?{}:{text:e.text},...e.severity===void 0?{}:{severity:e.severity},...e.reason===void 0?{}:{reason:e.reason},...e.hiddenLength===void 0?{}:{hiddenLength:e.hiddenLength}});return{icon:{name:e.icon,glyph:e.iconGlyph},box:{x:s,y:c,width:n.box.width,height:n.box.height},collapsed:!0,...u?{surface:f,depth:d}:{},card:n,diagnostics:l}}let p=e.width??o.collapsedWidth;s+p-o.contentInsetInline;let m=!i&&e.icon!==void 0&&e.iconGlyph!==void 0,h=m?s+o.headerInset+o.iconSize+o.iconTextGap:s+o.headerInset,g=e.toggleLabel===void 0?o.headerInset:o.headerTextInset-(o.headerInset+o.iconSize+o.iconTextGap),_=Math.max(0,s+p-h-g),v=at(e.anatomy,e.align),y=v===`center`?`middle`:`start`,b=v===`center`?h+_/2:h,x=(n,r,i,a,o=r)=>bt(n,r,i,a,t,t=>l.push({...t,code:`zone-overflow`,slot:o,entityId:e.entityId})),S=ct(o.subtitle.size),C=e.kicker===void 0?[]:x(e.kicker,`kicker`,_,o.allocatedLines.kicker),w=x(e.title,`title`,_,o.allocatedLines.title),T=yt({hasIcon:m,kickerLines:C.length,titleLines:w.length,iconSize:o.iconSize}),E=T.kickerHeight,D=T.titleHeight,O=T.blockHeight,k=c+o.headerInset,A=k+T.textTopOffset,j=m?{x:s+o.headerInset,y:k+T.iconTopOffset,size:o.iconSize}:void 0,M=C.map((e,t)=>({text:e,x:b,baseline:lt(A+t*E,o.kicker.size),size:o.kicker.size,weight:o.kicker.weight,secondary:!0,anchor:y})),ee=A+C.length*E,te=w.map((e,t)=>({text:e,x:b,baseline:lt(ee+t*D,o.title.size),size:o.title.size,weight:o.title.weight,secondary:!1,anchor:y})),ne=s+o.headerInset,N=Math.min(p,o.collapsedWidth)-o.ruleInsetStart-o.ruleInsetEnd,P=v===`center`?`middle`:`start`,F=v===`center`?ne+N/2:ne,I=x(e.subtitle??``,`body`,N,o.allocatedLines.subtitle,`subtitle`),re=k+O+o.subtitleGap,L=I.map((e,t)=>({text:e,x:F,baseline:lt(re+t*S,o.subtitle.size),size:o.subtitle.size,weight:o.subtitle.weight,secondary:!1,anchor:P})),R=I.length===0?re:re+I.length*S,ie=I.length>0?R+o.headerRuleGap:k+O+o.headerRuleGap,z=ie+o.contentInsetTop,ae=ct(o.footer.size),B=s+o.contentInsetInline,oe=s+p-o.contentInsetInline-B,se=e.footer===void 0?void 0:t(e.footer,`footer`,oe,o.allocatedLines.footer),ce=x(e.footer??``,`footer`,oe,o.allocatedLines.footer),le=ce.length*ae,ue=n.reduce((e,n)=>Math.max(e,n.y+jt(n,t)),c),V=ce.length===0?0:le+o.ruleHeight+2*o.ruleMargin+o.footerBottomInset,de=Math.max(ue,z)+o.contentInsetBottom-c+V,fe=e.autoSize?Math.max(e.height??o.collapsedHeight,de):e.height??Math.max(o.collapsedHeight,de);!e.autoSize&&e.height!==void 0&&de>e.height&&l.push({code:`zone-overflow`,slot:`frame`,entityId:e.entityId,neededPx:de,allocatedPx:e.height,text:e.title});let pe=e.toggleLabel===void 0?void 0:{x:s+p-o.toggleInset-o.toggleBoxSize,y:c+o.toggleInset,size:o.toggleBoxSize},me=c+fe-o.borderWidth-o.footerBottomInset,he=[],ge;if(se!==void 0){let e=v===`center`?`middle`:`start`,t=e===`middle`?B+oe/2:B;he=ce.map((n,r)=>({text:n,x:t,baseline:lt(me-le+r*ae,o.footer.size),size:o.footer.size,weight:o.footer.weight,secondary:!1,anchor:e})),ge=me-le-o.ruleHeight-o.ruleMargin}return{icon:{name:e.icon,glyph:e.iconGlyph},box:{x:s,y:c,width:p,height:fe},collapsed:!1,...u?{surface:f,depth:d}:{},header:{...j===void 0?{}:{iconBox:j},headerTextX:h,headerTextWidth:_,kicker:M,title:te,headerBlockHeight:O,subtitle:L,subtitleWidth:N,subtitleBottom:R,ruleY:ie,contentTop:z,...pe===void 0?{}:{toggleBox:pe},footer:he,...ge===void 0?{}:{footerRuleY:ge},footerBottom:me},diagnostics:l}}function Nt(e,t){if(e===void 0||e.form!==`container`&&e.form!==`legend`)return{kind:`label`};let n=e.text.title??``;if(n===``)return{kind:`label`};let r=e.icon??`cluster`;return{kind:`zone`,props:{entityId:t.entityId,...t.containerPadding===void 0?{}:{containerPadding:t.containerPadding},...e.text.kicker===void 0||e.text.kicker===``?{}:{kicker:e.text.kicker},title:n,...e.text.subtitle===void 0||e.text.subtitle===``?{}:{subtitle:e.text.subtitle},...e.text.footer===void 0||e.text.footer===``?{}:{footer:e.text.footer},...r===void 0?{}:{icon:r},...r===void 0||t.resolveGlyph===void 0?{}:(()=>{let e=t.resolveGlyph(r);return e===void 0?{}:{iconGlyph:e}})(),...e.categoryRef===void 0?{}:{tone:e.categoryRef},...e.proposed===void 0?{}:{proposed:e.proposed},...(()=>{let n=e.anatomy??t.anatomy;return n===void 0?{}:{anatomy:n}})(),collapsed:t.collapsed,...t.toggleLabel===void 0?{}:{toggleLabel:t.toggleLabel},...(()=>{let n=e.align??t.align;return n===void 0?{}:{align:n}})(),...(()=>{let n=e.depth??t.depth;return n===void 0?{}:{depth:n}})(),...(()=>{let n=e.depthParityStart??t.depthParityStart;return n===void 0?{}:{depthParityStart:n}})(),...t.x===void 0?{}:{x:t.x},...t.y===void 0?{}:{y:t.y},...t.width===void 0?{}:{width:t.width},...t.height===void 0?{}:{height:t.height}}}}function H(e){return{code:e.code,severity:e.severity??`error`,path:e.path,message:e.message,...e.refs===void 0?{}:{refs:e.refs},...e.details===void 0?{}:{details:e.details}}}var Pt=e=>e.some(e=>e.severity===`error`),Ft=[`entity`,`relation`,`occurrence`,`port`,`view`,`resource`,`document`],It=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,Lt=class extends Error{kind;localId;constructor(e,t){super(`invalid ${e} local id ${JSON.stringify(t)}: expected /${It.source}/ (a reference is \`<namespace>:<localId>\`, so the local id may not contain \`:\`)`),this.name=`RefFormatError`,this.kind=e,this.localId=t}};function Rt(e,t){if(!It.test(t))throw new Lt(e,t);return`${e}:${t}`}function zt(e,t){if(typeof e!=`string`)return!1;let n=e.indexOf(`:`);return n!==t.length||!e.startsWith(`${t}:`)?!1:It.test(e.slice(n+1))}var Bt=e=>Rt(`occurrence`,e),Vt=e=>Rt(`view`,e);function Ht(e){for(let t of Ft)if(zt(e,t))return t}function Ut(e){return e.slice(e.indexOf(`:`)+1)}function Wt(e,t,n){if(zt(t,e))return{ok:!0,ref:t};let r=Ht(t);return r===void 0?{ok:!1,diagnostic:H({code:`malformed-ref`,path:n,message:`expected a ${e} reference, got ${JSON.stringify(t)}`,details:{expectedKind:e}})}:{ok:!1,diagnostic:H({code:`reference-type-mismatch`,path:n,message:`expected a ${e} reference, got a ${r} reference (${String(t)})`,refs:[String(t)],details:{expectedKind:e,seenKind:r}})}}function Gt(e,t){try{return new RegExp(e).test(t)}catch{return!0}}var Kt=/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})?)?$/;function qt(e){if(!Kt.test(e))return!1;let[t,n,r]=e.slice(0,10).split(`-`).map(Number),i=new Date(Date.UTC(t,n-1,r));return i.getUTCFullYear()===t&&i.getUTCMonth()===n-1&&i.getUTCDate()===r}function Jt(e,t,n,r){if(t.kind!==e.kind)return[H({code:`attribute-type-mismatch`,path:n,message:`expected a ${e.kind} value, got ${t.kind}`,details:{expectedKind:e.kind,seenKind:t.kind}})];switch(e.kind){case`text`:{let i=t.value;return e.maxLength!==void 0&&i.length>e.maxLength?[H({code:`text-too-long`,path:n,message:`text is ${i.length} characters, the schema allows ${e.maxLength}`,details:{length:i.length,maxLength:e.maxLength}})]:e.minLength!==void 0&&i.length<e.minLength?[H({code:`text-pattern-mismatch`,path:n,message:`value is shorter than the minimum length for ${r}`,refs:[],details:{pattern:`min-length`,length:i.length,minLength:e.minLength}})]:e.pattern!==void 0&&!Gt(e.pattern,i)?[H({code:`text-pattern-mismatch`,path:n,message:`value does not match the ${e.patternName} grammar`,refs:[],details:e.maxLength===void 0?{pattern:e.patternName,length:i.length}:{pattern:e.patternName,length:i.length,maxLength:e.maxLength}})]:[]}case`boolean`:return[];case`date`:{let e=t.value;return qt(e)?[]:[H({code:`date-not-iso8601`,path:n,message:`${JSON.stringify(e)} is not an ISO-8601 date or date-time`})]}case`quantity`:{let r=t,i=[];return typeof r.unit!=`string`||r.unit.length===0?i.push(H({code:`quantity-unit-missing`,path:n,message:`a quantity carries a unit; none was given`,details:{allowedUnits:e.units.join(`,`)}})):e.units.includes(r.unit)||i.push(H({code:`quantity-unit-not-allowed`,path:n,message:`unit ${JSON.stringify(r.unit)} is not one of ${e.units.join(`, `)}`,details:{unit:r.unit,allowedUnits:e.units.join(`,`)}})),Number.isFinite(r.value)||i.push(H({code:`value-not-finite`,path:n,message:`quantity magnitude is not finite (${String(r.value)})`})),typeof r.value==`number`&&Number.isFinite(r.value)&&(e.integer===!0&&!Number.isInteger(r.value)?i.push(H({code:`quantity-not-integer`,path:n,message:`value ${String(r.value)} is not an integer`,refs:[],details:{value:r.value,integer:`required`}})):e.min!==void 0&&r.value<e.min?i.push(H({code:`quantity-below-min`,path:n,message:`value ${String(r.value)} is below the minimum ${String(e.min)}`,refs:[],details:{value:r.value,min:e.min}})):e.max!==void 0&&r.value>e.max&&i.push(H({code:`quantity-above-max`,path:n,message:`value ${String(r.value)} is above the maximum ${String(e.max)}`,refs:[],details:{value:r.value,max:e.max}}))),i}case`enum`:{let r=t.value;return e.values.includes(r)?[]:[H({code:`enum-value-not-allowed`,path:n,message:`${JSON.stringify(r)} is not one of ${e.values.join(`, `)}`,details:{value:r,allowedValues:e.values.join(`,`)}})]}case`reference`:{let r=t.value,i=Ht(r);return i===void 0?[H({code:`malformed-ref`,path:n,message:`${JSON.stringify(r)} carries no identity namespace`,details:{expectedKind:e.refKind}})]:i===e.refKind?[]:[H({code:`reference-type-mismatch`,path:n,message:`expected a ${e.refKind} reference, got a ${i} reference`,refs:[r],details:{expectedKind:e.refKind,seenKind:i}})]}}}function Yt(e,t,n){if(e.kind===`collection`){if(t.kind!==`collection`)return[H({code:`attribute-type-mismatch`,path:n,message:`expected a collection of ${e.item.kind}, got ${t.kind}`,details:{expectedKind:`collection`,seenKind:t.kind}})];let r=[],i=e.minItems??0;return t.items.length>e.maxItems&&r.push(H({code:`collection-bound-exceeded`,path:n,message:`collection holds ${t.items.length} items, the bound is ${e.maxItems}`,details:{bound:`max`,items:t.items.length,maxItems:e.maxItems}})),t.items.length<i&&r.push(H({code:`collection-bound-exceeded`,path:n,message:`collection holds ${t.items.length} items, the minimum is ${i}`,details:{bound:`min`,items:t.items.length,minItems:i}})),t.items.forEach((t,i)=>{r.push(...Jt(e.item,t,`${n}[${i}]`,e.name))}),r}return t.kind===`collection`?[H({code:`attribute-type-mismatch`,path:n,message:`expected a ${e.kind} value, got a collection`,details:{expectedKind:e.kind,seenKind:`collection`}})]:e.kind===`struct`?t.kind===`struct`?[]:[H({code:`attribute-type-mismatch`,path:n,message:`expected a struct value, got ${t.kind}`,details:{expectedKind:`struct`,seenKind:t.kind}})]:t.kind===`struct`?[H({code:`attribute-type-mismatch`,path:n,message:`expected a ${e.kind} value, got struct`,details:{expectedKind:e.kind,seenKind:`struct`}})]:Jt(e,t,n,e.name)}function Xt(e,t){if(e.kind===`collection`){if(t.kind!==`collection`||e.item.kind!==`reference`)return[];let n=e.item.refKind,r=[];return t.items.forEach((e,t)=>{e.kind===`reference`&&r.push({raw:e.value,refKind:n,index:t})}),r}return e.kind!==`reference`||t.kind!==`reference`?[]:[{raw:t.value,refKind:e.refKind}]}var Zt=14695981039346656037n,Qt=1099511628211n,$t=18446744073709551615n;function en(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){let t=e.charCodeAt(n+1);t>=56320&&t<=57343&&(r=(r-55296)*1024+(t-56320)+65536,n+=1)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|r&63):r<65536?t.push(224|r>>12,128|r>>6&63,128|r&63):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return t}var tn=`fnv1a64`;function nn(e){let t=Zt;for(let n of en(e))t=(t^BigInt(n))*Qt&$t;return`${tn}:${t.toString(16).padStart(16,`0`)}`}function rn(e){for(let t=0;t<e.length;t+=1){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){let n=t+1<e.length?e.charCodeAt(t+1):-1;if(n<56320||n>57343)throw Error(`invalid-unicode:lone-surrogate`);t+=1}else if(n>=56320&&n<=57343)throw Error(`invalid-unicode:lone-surrogate`)}}function an(e,t=new Set){if(e===null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`non-finite-number`);return Number.isInteger(e)?String(e):JSON.stringify(e)}if(typeof e==`string`)return rn(e),JSON.stringify(e);if(typeof e==`object`){if(t.has(e))throw Error(`invalid-json:cycle`);let n=Array.isArray(e);if(!n&&![Object.prototype,null].includes(Object.getPrototypeOf(e)))throw Error(`invalid-json:prototype`);if(Reflect.ownKeys(e).some(e=>typeof e!=`string`))throw Error(`invalid-json:key`);let r=Object.getOwnPropertyDescriptors(e),i=Object.keys(r).filter(e=>!(n&&e===`length`));for(let e of i){rn(e);let t=r[e];if(t===void 0||!t.enumerable||!(`value`in t))throw Error(`invalid-json:property`)}if(n&&(i.length!==e.length||i.some((e,t)=>e!==String(t))))throw Error(`invalid-json:array`);t.add(e);let a=n?`[${i.map(e=>an(r[e].value,t)).join(`,`)}]`:`{${i.sort().map(e=>`${JSON.stringify(e)}:${an(r[e].value,t)}`).join(`,`)}}`;return t.delete(e),a}throw Error(`unserializable:${typeof e}`)}function on(e){return an(e)}function sn(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){let t=e.charCodeAt(n+1);t>=56320&&t<=57343&&(r=(r-55296)*1024+(t-56320)+65536,n+=1)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|r&63):r<65536?t.push(224|r>>12,128|r>>6&63,128|r&63):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return t}var cn=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function ln(e,t){return e>>>t|e<<32-t}function un(e){let t=sn(e),n=Math.floor(t.length*8/4294967296),r=t.length*8>>>0,i=[...t,128];for(;i.length%64!=56;)i.push(0);i.push(n>>>24&255,n>>>16&255,n>>>8&255,n&255,r>>>24&255,r>>>16&255,r>>>8&255,r&255);let a=1779033703,o=3144134277,s=1013904242,c=2773480762,l=1359893119,u=2600822924,d=528734635,f=1541459225,p=Array(64).fill(0);for(let e=0;e<i.length;e+=64){for(let t=0;t<16;t+=1){let n=e+t*4;p[t]=i[n]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3]}for(let e=16;e<64;e+=1){let t=ln(p[e-15],7)^ln(p[e-15],18)^p[e-15]>>>3,n=ln(p[e-2],17)^ln(p[e-2],19)^p[e-2]>>>10;p[e]=p[e-16]+t+p[e-7]+n|0}let t=a,n=o,r=s,m=c,h=l,g=u,_=d,v=f;for(let e=0;e<64;e+=1){let i=ln(h,6)^ln(h,11)^ln(h,25),a=h&g^~h&_,o=(v+i+a+cn[e]+p[e]|0)>>>0,s=(ln(t,2)^ln(t,13)^ln(t,22))+(t&n^t&r^n&r)|0;v=_,_=g,g=h,h=m+o|0,m=r,r=n,n=t,t=o+s|0}a=a+t|0,o=o+n|0,s=s+r|0,c=c+m|0,l=l+h|0,u=u+g|0,d=d+_|0,f=f+v|0}return[a,o,s,c,l,u,d,f].map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}var dn=`legacy-constraints@1`,fn=`scoped-constraints@1`,pn={"generic@1":dn,"archimate@1":dn,"bpmn@1":dn,"uml@1":dn,"erd@1":fn,"generic@2":fn,"archimate@2":fn,"uml@2":fn};function mn(e){return pn[e]}var hn=[`generic@1`,`archimate@1`,`bpmn@1`,`uml@1`];function gn(e){return hn.includes(e)}function _n(e){return{schemaVersion:`1`,rows:e.map(e=>{let t=mn(e.id);if(t===void 0)throw Error(`no imposed executor adapter for profile ${e.id}; pass an explicit binding row`);return Sn(e,t)})}}function vn(e){if(e===null)return`null`;switch(typeof e){case`string`:return JSON.stringify(e);case`boolean`:return e?`true`:`false`;case`number`:if(!Number.isFinite(e))throw Error(`stableStringify: non-finite number`);return JSON.stringify(e===0?0:e);case`undefined`:return`null`}if(Array.isArray(e))return`[${e.map(e=>vn(e)).join(`,`)}]`;if(typeof e==`object`)return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${vn(e[t])}`).join(`,`)}}`;throw Error(`stableStringify: unsupported ${typeof e}`)}function yn(e){return{completeness:e.completeness,constraints:[...e.constraints],entityTypes:[...e.entityTypes],limits:{maxEntities:e.limits.maxEntities??null,maxRelations:e.limits.maxRelations??null,maxEndpointsPerRelation:e.limits.maxEndpointsPerRelation??null},portTypes:[...e.portTypes],profile:e.id,relationTypes:[...e.relationTypes]}}function bn(e){return un(on(yn(e)))}var xn=e=>nn(vn(e));function Sn(e,t){return{profileId:e.id,profilePin:{id:e.id,version:e.version,contentDigest:bn(e)},declarationAdapter:t}}function Cn(e,t){let n=[];if(e.schemaVersion!==`1`)return[H({code:`type-definition-conflict`,path:`bindings.schemaVersion`,message:`executor bindings schema version ${JSON.stringify(e.schemaVersion)} is not readable by this build`,details:{seen:String(e.schemaVersion)}})];let r=new Set;return e.rows.forEach((e,i)=>{let a=`bindings.rows[${i}]`;if(r.has(e.profileId)){n.push(H({code:`type-definition-conflict`,path:a,message:`executor binding for profile ${e.profileId} is declared twice`,details:{profile:e.profileId}}));return}r.add(e.profileId);let o=t.get(e.profileId);if(o===void 0){n.push(H({code:`unknown-profile`,path:a,message:`executor binding names profile ${e.profileId}, which is not in the registry`,details:{profile:e.profileId}}));return}if(e.declarationAdapter!==`legacy-constraints@1`&&e.declarationAdapter!==`scoped-constraints@1`){n.push(H({code:`type-definition-conflict`,path:`${a}.declarationAdapter`,message:`executor binding for ${e.profileId} names an unknown adapter`,details:{profile:e.profileId}}));return}(e.profilePin.id!==o.id||e.profilePin.version!==o.version||e.profilePin.contentDigest!==bn(o))&&n.push(H({code:`type-definition-conflict`,path:a,message:`binding for ${e.profileId} does not match the registered bytes`,details:{profile:e.profileId}}));let s=mn(e.profileId);e.declarationAdapter===`legacy-constraints@1`&&!gn(e.profileId)&&s===void 0&&n.push(H({code:`type-definition-conflict`,path:a,message:`executor binding for ${e.profileId} must use ${fn}, not ${dn}`,refs:[],details:{profile:e.profileId}})),s!==void 0&&e.declarationAdapter!==s&&n.push(H({code:`type-definition-conflict`,path:a,message:`executor binding for ${e.profileId} must use ${s}, not ${e.declarationAdapter}`,refs:[],details:{profile:e.profileId}}))}),n}function wn(e,t){return e===void 0?dn:e.rows.find(e=>e.profileId===t)?.declarationAdapter}var Tn=class extends Error{diagnostics;constructor(e){super(`value is not canonically serialisable: ${e.map(e=>e.message).join(`; `)}`),this.name=`CanonicalisationError`,this.diagnostics=e}};function En(e,t,n,r){if(e===null)return`null`;switch(typeof e){case`string`:return JSON.stringify(e);case`boolean`:return e?`true`:`false`;case`number`:if(!Number.isFinite(e)){r.push(H({code:`value-not-finite`,path:t,message:`${String(e)} is not a finite number`}));return}return JSON.stringify(e===0?0:e);case`undefined`:return;case`bigint`:case`function`:case`symbol`:r.push(H({code:`value-not-serialisable`,path:t,message:`a ${typeof e} cannot be part of a document`,details:{valueType:typeof e}}));return}let i=e;if(n.has(i)){r.push(H({code:`value-not-serialisable`,path:t,message:`cyclic value`}));return}let a=new Set(n).add(i);if(Array.isArray(i))return`[${i.map((e,n)=>En(e,`${t}[${n}]`,a,r)??`null`).join(`,`)}]`;let o=[];for(let e of Object.keys(i).sort()){let n=En(i[e],`${t}.${e}`,a,r);n!==void 0&&o.push(`${JSON.stringify(e)}:${n}`)}return`{${o.join(`,`)}}`}function Dn(e,t=`$`){let n=[],r=En(e,t,new Set,n);return n.length>0||r===void 0?{ok:!1,diagnostics:n.length>0?n:[H({code:`value-not-serialisable`,path:t,message:`value encodes to nothing`})]}:{ok:!0,text:r}}function On(e,t=`$`){let n=Dn(e,t);if(!n.ok)throw new Tn(n.diagnostics);return n.text}function kn(e){if(e.chainPredicates===void 0)return[];let t=`profiles.${e.id}.chainPredicates`,n=Dn(e.chainPredicates,t);if(!n.ok)return n.diagnostics;let r=[],i=new Set(e.entityTypes.map(e=>e.id)),a=new Set(e.relationTypes.map(e=>e.id)),o=new Set(e.entityTypes.flatMap(e=>e.attributes.map(e=>e.name))),s=new Set;for(let[n,c]of e.chainPredicates.entries()){let l=`${t}[${n}]`,u=(e,t)=>{r.push(H({code:`type-definition-conflict`,path:`${l}${t}`,message:`chain predicate ${c.id} fails check ${e}`,details:{check:e}}))},d=(e,t,n)=>{(e.length===0||e.some(e=>!t.has(e)))&&u(`chain-unknown-type`,n)},f=(e,t)=>{for(let[n,r]of(e??[]).entries())o.has(r.attribute)||u(`chain-unknown-type`,`${t}[${n}].attribute`)},p=(e,t)=>{d(e.endTypes,i,`${t}.endTypes`),f(e.endConstraints,`${t}.endConstraints`),e.steps.length===0&&u(`chain-unknown-type`,`${t}.steps`);for(let[n,r]of e.steps.entries())d(r.relationTypes,a,`${t}.steps[${n}].relationTypes`),r.direction!==`forward`&&r.direction!==`inverse`&&u(`chain-invalid-direction`,`${t}.steps[${n}].direction`),[`one`,`zeroOrMore`,`oneOrMore`].includes(r.repeat)||u(`chain-invalid-repeat`,`${t}.steps[${n}].repeat`)};(c.id.length===0||s.has(c.id))&&u(`chain-duplicate-id`,`.id`),s.add(c.id),d(c.appliesTo.relationTypes,a,`.appliesTo.relationTypes`),d(c.appliesTo.startTypes,i,`.appliesTo.startTypes`);let m=new Set(e.relationTypes.filter(e=>c.appliesTo.relationTypes.includes(e.id)).flatMap(e=>e.roles.map(e=>e.role)));d(c.appliesTo.roles,m,`.appliesTo.roles`),f(c.startConstraints,`.startConstraints`),c.alternatives.length===0&&u(`chain-unknown-type`,`.alternatives`),c.alternatives.forEach((e,t)=>p(e,`.alternatives[${t}]`));let h=c.aggregation,g=c;c.selection===`aggregate`?h?.memberRelationTypes===void 0||h.memberTargetChain===void 0||h.memberSourceChain===void 0?u(`chain-members-not-aggregate`,`.aggregation`):(d(h.memberRelationTypes,a,`.aggregation.memberRelationTypes`),p(h.memberTargetChain,`.aggregation.memberTargetChain`),p(h.memberSourceChain,`.aggregation.memberSourceChain`),h.sort!==void 0&&h.sort!==`sourceId,targetId,relationId`&&u(`chain-members-not-aggregate`,`.aggregation.sort`)):(h!==void 0||g.sort!==void 0||g.members!==void 0)&&u(`chain-members-not-aggregate`,`.aggregation`)}return r}function An(e){let t=new Map;for(let n of e){if(t.get(n.id)!==void 0)throw Error(`profile ${n.id} registered twice; a profile id is a version, not a name`);t.set(n.id,n)}return{get:e=>t.get(e),has:e=>t.has(e),list:()=>[...t.keys()].sort()}}var jn=(e,t)=>e.entityTypes.find(e=>e.id===t),Mn=(e,t)=>e.portTypes.find(e=>e.id===t),Nn=(e,t)=>e.relationTypes.find(e=>e.id===t),Pn=(e,t)=>e.roles.find(e=>e.role===t);function Fn(e,t=`legacy-constraints@1`){let n=[],r=`profiles.${e.id}`,i=new Set;for(let t of e.entityTypes)i.has(t.id)&&n.push(H({code:`duplicate-id`,path:`${r}.entityTypes.${t.id}`,message:`entity type declared twice`})),i.add(t.id),n.push(...qn(t.attributes,`${r}.entityTypes.${t.id}.attributes`));for(let t of e.relationTypes){let e=new Set(t.roles.map(e=>e.role));for(let e of t.roles){(e.cardinality.max<e.cardinality.min||e.cardinality.min<0)&&n.push(H({code:`endpoint-cardinality-violation`,path:`${r}.relationTypes.${t.id}.roles.${e.role}`,message:`declared cardinality ${e.cardinality.min}..${e.cardinality.max} is empty or negative`}));for(let a of e.entityTypes??[])i.has(a)||n.push(H({code:`unknown-entity-type`,path:`${r}.relationTypes.${t.id}.roles.${e.role}.entityTypes`,message:`role accepts entity type ${a}, which the profile does not declare`}))}let a=t.hierarchy;if(a!==void 0)for(let i of[a.parentRole,a.childRole])e.has(i)||n.push(H({code:`endpoint-role-unknown`,path:`${r}.relationTypes.${t.id}.hierarchy`,message:`hierarchy ${a.id} names role ${i}, which the relation type does not declare`}))}for(let[a,o]of e.constraints.entries())o.kind===`acyclic-hierarchy`?e.relationTypes.some(e=>e.hierarchy?.id===o.hierarchyId)||n.push(H({code:`type-definition-conflict`,path:`${r}.constraints`,message:`constraint names hierarchy ${o.hierarchyId}, which no relation type declares`})):(o.kind===`unique-attribute`||o.kind===`max-entities-of-type`)&&(i.has(o.entityType)||n.push(H({code:`unknown-entity-type`,path:`${r}.constraints`,message:`constraint names entity type ${o.entityType}, which the profile does not declare`})),o.kind===`unique-attribute`&&t===`scoped-constraints@1`&&o.scope===void 0&&n.push(H({code:`type-definition-conflict`,path:`${r}.constraints[${a}]`,message:`unique-attribute constraint for ${o.entityType}.${o.attribute} requires an explicit scope`,refs:[],details:{check:`unique-scope-missing`,type:o.entityType,attribute:o.attribute}})));return n.push(...In(e,i,t)),n.push(...kn(e)),n}function In(e,t,n){let r=[],i=`profiles.${e.id}`;return e.entityTypes.forEach((e,t)=>{e.abstract===!0&&e.container===!0&&r.push(H({code:`type-definition-conflict`,path:`${i}.entityTypes[${t}]`,message:`abstract type ${e.id} cannot declare container capability`,refs:[],details:{check:`abstract-container`,type:e.id}})),e.attributes.forEach((e,n)=>{r.push(...Wn(e,`${i}.entityTypes[${t}].attributes[${n}]`))})}),e.portTypes.forEach((e,t)=>{(e.attributes??[]).forEach((e,n)=>{r.push(...Wn(e,`${i}.portTypes[${t}].attributes[${n}]`))})}),e.relationTypes.forEach((e,t)=>{(e.attributes??[]).forEach((e,n)=>{r.push(...Wn(e,`${i}.relationTypes[${t}].attributes[${n}]`))})}),r.push(...Kn(e)),e.constraints.forEach((a,o)=>{let s=`${i}.constraints[${o}]`;switch(a.kind){case`unique-attribute`:a.scope!==void 0&&n===`scoped-constraints@1`&&r.push(...Hn(e,a.entityType,a.attribute,a.scope,s));break;case`relationship-matrix`:{let n=new Set,i=!1;for(let r of a.tuples){let a=`${r.relationType}\n${r.sourceType}\n${r.targetType}`,o=r.sourceType===`@relation`||t.has(r.sourceType),s=r.targetType===`@relation`||t.has(r.targetType);if(r.relationType.length===0||r.sourceType.length===0||r.targetType.length===0||n.has(a)||e.relationTypes.every(e=>e.id!==r.relationType)||!o||!s){i=!0;break}n.add(a)}i&&r.push(H({code:`type-definition-conflict`,path:s,message:`relationship matrix ${a.matrixId} has an invalid or duplicate tuple`,refs:[],details:{check:`matrix-constraint-invalid`,matrixId:a.matrixId}}));break}case`hierarchy`:{let t=e.relationTypes.find(e=>e.id===a.relationType),n=t?.hierarchy;(t===void 0||n===void 0||n.id!==a.hierarchyId||n.parentRole!==a.parentRole||n.childRole!==a.childRole)&&r.push(H({code:`type-definition-conflict`,path:s,message:`hierarchy constraint names relation type ${a.relationType}, which does not declare hierarchy ${a.hierarchyId} with roles ${a.parentRole}/${a.childRole}`,refs:[],details:{check:`hierarchy-constraint-invalid`,relationType:a.relationType,hierarchyId:a.hierarchyId}}));break}case`parent-family`:r.push(...Rn(e,a.hierarchyId,s));for(let e of a.familyRoots)Ln(t,e,s,r);break;case`children-restricted`:case`required-parent`:r.push(...Rn(e,a.hierarchyId,s));for(let e of a.parentFamilyRoots)Ln(t,e,s,r);for(let e of a.childTypes)Ln(t,e,s,r);break;case`bound-pair`:Ln(t,a.valueType,s,r);break;case`reference-application`:Ln(t,a.declarationType,s,r);break;case`incident-type-uniformity`:Ln(t,a.entityType,s,r);for(let t of a.relationTypes)e.relationTypes.every(e=>e.id!==t)&&r.push(H({code:`unknown-relation-type`,path:s,message:`constraint names relation type ${t}, which the profile does not declare`}));break;case`at-most-value`:e.relationTypes.every(e=>e.id!==a.relationType)&&r.push(H({code:`unknown-relation-type`,path:s,message:`constraint names relation type ${a.relationType}, which the profile does not declare`}));break;case`collection-unique`:Ln(t,a.entityType,s,r)}}),r}function Ln(e,t,n,r){e.has(t)||r.push(H({code:`unknown-entity-type`,path:n,message:`constraint names entity type ${t}, which the profile does not declare`}))}function Rn(e,t,n){return e.relationTypes.some(e=>e.hierarchy?.id===t)?[]:[H({code:`type-definition-conflict`,path:n,message:`constraint names hierarchy ${t}, which no relation type declares`})]}function zn(e,t){let n=[t],r=new Set([t]),i=[t];for(;i.length>0;){let t=i.pop(),a=e.entityTypes.find(e=>e.id===t);for(let e of a?.supertypes??[])r.has(e)||(r.add(e),n.push(e),i.push(e))}return n}function Bn(e,t,n){let r=e.relationTypes.filter(r=>{let i=r.hierarchy;if(i===void 0)return!1;let a=r.roles.find(e=>e.role===i.parentRole),o=r.roles.find(e=>e.role===i.childRole);return!(a===void 0||o===void 0||!Vn(e,o,t)||n!==void 0&&!Vn(e,a,n))});if(r.length===1)return{hierarchyId:r[0].hierarchy.id}}function Vn(e,t,n){return t.targets.includes(`entity`)?t.entityTypes===void 0||t.entityTypes.some(t=>zn(e,n).includes(t)):!1}function Hn(e,t,n,r,i){if(r===`document`)return[];let a=()=>[H({code:`type-definition-conflict`,path:i,message:`unique-attribute constraint for ${t}.${n} selects no unique hierarchy`,refs:[],details:{check:`unique-hierarchy-selection`,type:t,attribute:n}})];return r===`siblings`?Bn(e,t)===void 0?a():[]:e.entityTypes.some(e=>e.id===r.withinType)?Bn(e,t,r.withinType)===void 0?a():[]:[H({code:`unknown-entity-type`,path:i,message:`constraint names entity type ${r.withinType}, which the profile does not declare`})]}function Un(e){if(e.length===0||e[0]!==`^`||!/^[\x00-\x7F]*$/.test(e))return!1;let t=0;for(let n=e.length-2;n>=0&&e[n]===`\\`;--n)t+=1;if(e[e.length-1]!==`$`||t%2==1)return!1;try{return new RegExp(e),!0}catch{return!1}}function Wn(e,t){if(e.kind===`collection`){let n=e.item;return n.kind===`text`||n.kind===`quantity`?Gn(n,`${t}.item`,e.name):[]}return e.kind===`text`||e.kind===`quantity`?Gn(e,t,e.name):[]}function Gn(e,t,n){return e.kind===`text`?e.pattern!==void 0&&(e.patternName===void 0||!Un(e.pattern))||e.minLength!==void 0&&e.minLength<0||e.maxLength!==void 0&&e.maxLength<0||e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength?[H({code:`type-definition-conflict`,path:t,message:`text schema for ${n} has an invalid pattern or length bounds`,refs:[],details:{check:`text-pattern-invalid`,attribute:n}})]:[]:e.min!==void 0&&(typeof e.min!=`number`||!Number.isFinite(e.min))||e.max!==void 0&&(typeof e.max!=`number`||!Number.isFinite(e.max))||e.min!==void 0&&e.max!==void 0&&e.min>e.max?[H({code:`type-definition-conflict`,path:t,message:`quantity schema for ${n} has invalid numeric bounds`,refs:[],details:{check:`numeric-constraint-invalid`,attribute:n}})]:[]}function Kn(e){let t=[],n=`profiles.${e.id}`,r=new Map(e.entityTypes.map(e=>[e.id,e])),i=new Set,a=new Set,o=new Map,s=new Map,c=(e,r,a)=>{i.has(r)||(i.add(r),t.push(H({code:`supertype-unknown`,path:`${n}.entityTypes.${e}.supertypes[${a}]`,message:`supertype ${r} is not declared`,refs:[],details:{supertype:r}})))},l=(e,r)=>{let i=[...r].sort()[0],o=r.indexOf(i),s=JSON.stringify([...r.slice(o),...r.slice(0,o)]);a.has(s)||(a.add(s),t.push(H({code:`supertype-cycle`,path:`${n}.entityTypes.${e}.supertypes`,message:`supertype chain for ${e} is cyclic`,refs:[],details:{type:e}})))},u=e=>{let t=o.get(e);if(t!==void 0)return t;let n=r.get(e);if(n===void 0)return!0;let i=n.supertypes??[];if(i.length===0)return o.set(e,!1),!1;let a=!1,s=[e],u=new Set([e]),d=[{id:e,supers:i,next:0,broken:!1}];for(;d.length>0;){let e=d[d.length-1];if(e.next<e.supers.length){let t=e.supers[e.next],n=e.next;e.next+=1;let i=r.get(t);if(i===void 0){e.broken=!0,a=!0,c(e.id,t,n);continue}if(u.has(t)){e.broken=!0,a=!0,l(e.id,s.slice(s.indexOf(t)));continue}let f=o.get(t);if(f!==void 0){f&&(e.broken=!0,a=!0);continue}s.push(t),u.add(t),d.push({id:t,supers:i.supertypes??[],next:0,broken:!1})}else{o.set(e.id,e.broken),d.pop();let t=s.pop();if(u.delete(t),e.broken){a=!0;let e=d[d.length-1];e!==void 0&&(e.broken=!0)}}}return o.set(e,a),a},d=e=>{let t=s.get(e);if(t!==void 0)return t;let n=[],i=new Set([e]),a=[],o=[],c=r.get(e);if(c===void 0){let t=new Map;return s.set(e,t),t}for(o.push({id:e,next:0,supers:c.supertypes??[]});o.length>0;){let e=o[o.length-1];if(e.next<e.supers.length){let t=e.supers[e.next];if(e.next+=1,i.has(t))continue;let a=r.get(t);if(a===void 0)continue;i.add(t),n.push(t),o.push({id:t,next:0,supers:a.supertypes??[]})}else a.push(e.id),o.pop()}for(let e of a){if(s.has(e))continue;let t=r.get(e);if(t===void 0)continue;let n=new Map;for(let e of t.supertypes??[]){let t=s.get(e);if(t!==void 0)for(let[e,r]of t){let t=n.get(e);t===void 0?n.set(e,[...r]):t.push(...r)}let i=r.get(e);if(i!==void 0)for(let e of i.attributes){let t=n.get(e.name);t===void 0?n.set(e.name,[e]):t.push(e)}}s.set(e,n)}return s.get(e)??new Map};for(let r of e.entityTypes){let e=r.supertypes;if(e===void 0||e.length===0||u(r.id))continue;let i=d(r.id),a=new Map(r.attributes.map(e=>[e.name,e]));for(let[e,o]of i){let i=[...o.map(e=>vn(e))],s=a.get(e);s!==void 0&&i.push(vn(s)),new Set(i).size>1&&t.push(H({code:`attribute-conflict`,path:`${n}.entityTypes.${r.id}.attributes.${e}`,message:`inherited attribute ${e} has incompatible schemas on ${r.id}`,refs:[],details:{attribute:e,type:r.id}}))}}return t}function qn(e,t){let n=new Set,r=[];for(let i of e)n.has(i.name)&&r.push(H({code:`duplicate-id`,path:`${t}.${i.name}`,message:`attribute declared twice`})),n.add(i.name);return r}var Jn=[{name:`ApplicationCollaboration`,id:`application-collaboration`,layer:`application`,aspect:`active`},{name:`ApplicationComponent`,id:`application-component`,layer:`application`,aspect:`active`},{name:`ApplicationEvent`,id:`application-event`,layer:`application`,aspect:`behaviour`},{name:`ApplicationFunction`,id:`application-function`,layer:`application`,aspect:`behaviour`},{name:`ApplicationInteraction`,id:`application-interaction`,layer:`application`,aspect:`behaviour`},{name:`ApplicationInterface`,id:`application-interface`,layer:`application`,aspect:`active`},{name:`ApplicationProcess`,id:`application-process`,layer:`application`,aspect:`behaviour`},{name:`ApplicationService`,id:`application-service`,layer:`application`,aspect:`behaviour`},{name:`Artifact`,id:`artifact`,layer:`technology`,aspect:`passive`},{name:`Assessment`,id:`assessment`,layer:`motivation`,aspect:`motivation`},{name:`BusinessActor`,id:`business-actor`,layer:`business`,aspect:`active`},{name:`BusinessCollaboration`,id:`business-collaboration`,layer:`business`,aspect:`active`},{name:`BusinessEvent`,id:`business-event`,layer:`business`,aspect:`behaviour`},{name:`BusinessFunction`,id:`business-function`,layer:`business`,aspect:`behaviour`},{name:`BusinessInteraction`,id:`business-interaction`,layer:`business`,aspect:`behaviour`},{name:`BusinessInterface`,id:`business-interface`,layer:`business`,aspect:`active`},{name:`BusinessObject`,id:`business-object`,layer:`business`,aspect:`passive`},{name:`BusinessProcess`,id:`business-process`,layer:`business`,aspect:`behaviour`},{name:`BusinessRole`,id:`business-role`,layer:`business`,aspect:`active`},{name:`BusinessService`,id:`business-service`,layer:`business`,aspect:`behaviour`},{name:`Capability`,id:`capability`,layer:`strategy`,aspect:`behaviour`},{name:`CommunicationNetwork`,id:`communication-network`,layer:`technology`,aspect:`active`},{name:`Constraint`,id:`constraint`,layer:`motivation`,aspect:`motivation`},{name:`Contract`,id:`contract`,layer:`business`,aspect:`passive`},{name:`CourseOfAction`,id:`course-of-action`,layer:`strategy`,aspect:`behaviour`},{name:`DataObject`,id:`data-object`,layer:`application`,aspect:`passive`},{name:`Deliverable`,id:`deliverable`,layer:`implementation`,aspect:`passive`},{name:`Device`,id:`device`,layer:`technology`,aspect:`active`},{name:`DistributionNetwork`,id:`distribution-network`,layer:`physical`,aspect:`active`},{name:`Driver`,id:`driver`,layer:`motivation`,aspect:`motivation`},{name:`Equipment`,id:`equipment`,layer:`physical`,aspect:`active`},{name:`Facility`,id:`facility`,layer:`physical`,aspect:`active`},{name:`Gap`,id:`gap`,layer:`implementation`,aspect:`passive`},{name:`Goal`,id:`goal`,layer:`motivation`,aspect:`motivation`},{name:`Grouping`,id:`grouping`,layer:`none`,aspect:`composite`},{name:`ImplementationEvent`,id:`implementation-event`,layer:`implementation`,aspect:`behaviour`},{name:`Junction`,id:`junction`,layer:`none`,aspect:`other`},{name:`Location`,id:`location`,layer:`none`,aspect:`composite`},{name:`Material`,id:`material`,layer:`physical`,aspect:`passive`},{name:`Meaning`,id:`meaning`,layer:`motivation`,aspect:`motivation`},{name:`Node`,id:`node`,layer:`technology`,aspect:`active`},{name:`Outcome`,id:`outcome`,layer:`motivation`,aspect:`motivation`},{name:`Path`,id:`path`,layer:`technology`,aspect:`active`},{name:`Plateau`,id:`plateau`,layer:`implementation`,aspect:`composite`},{name:`Principle`,id:`principle`,layer:`motivation`,aspect:`motivation`},{name:`Product`,id:`product`,layer:`business`,aspect:`composite`},{name:`Representation`,id:`representation`,layer:`business`,aspect:`passive`},{name:`Requirement`,id:`requirement`,layer:`motivation`,aspect:`motivation`},{name:`Resource`,id:`resource`,layer:`strategy`,aspect:`active`},{name:`Stakeholder`,id:`stakeholder`,layer:`motivation`,aspect:`motivation`},{name:`SystemSoftware`,id:`system-software`,layer:`technology`,aspect:`active`},{name:`TechnologyCollaboration`,id:`technology-collaboration`,layer:`technology`,aspect:`active`},{name:`TechnologyEvent`,id:`technology-event`,layer:`technology`,aspect:`behaviour`},{name:`TechnologyFunction`,id:`technology-function`,layer:`technology`,aspect:`behaviour`},{name:`TechnologyInteraction`,id:`technology-interaction`,layer:`technology`,aspect:`behaviour`},{name:`TechnologyInterface`,id:`technology-interface`,layer:`technology`,aspect:`active`},{name:`TechnologyProcess`,id:`technology-process`,layer:`technology`,aspect:`behaviour`},{name:`TechnologyService`,id:`technology-service`,layer:`technology`,aspect:`behaviour`},{name:`Value`,id:`value`,layer:`motivation`,aspect:`motivation`},{name:`ValueStream`,id:`value-stream`,layer:`strategy`,aspect:`behaviour`},{name:`WorkPackage`,id:`work-package`,layer:`implementation`,aspect:`behaviour`}],Yn=`ApplicationCollaboration.ApplicationComponent.ApplicationEvent.ApplicationFunction.ApplicationInteraction.ApplicationInterface.ApplicationProcess.ApplicationService.Artifact.Assessment.BusinessActor.BusinessCollaboration.BusinessEvent.BusinessFunction.BusinessInteraction.BusinessInterface.BusinessObject.BusinessProcess.BusinessRole.BusinessService.Capability.CommunicationNetwork.Constraint.Contract.CourseOfAction.DataObject.Deliverable.Device.DistributionNetwork.Driver.Equipment.Facility.Gap.Goal.Grouping.ImplementationEvent.Junction.Location.Material.Meaning.Node.Outcome.Path.Plateau.Principle.Product.Relationship.Representation.Requirement.Resource.Stakeholder.SystemSoftware.TechnologyCollaboration.TechnologyEvent.TechnologyFunction.TechnologyInteraction.TechnologyInterface.TechnologyProcess.TechnologyService.Value.ValueStream.WorkPackage`.split(`.`),Xn=`cfgostv fgortv fiortv fiortv fiortv cfgortv fiortv fiortv ao no fotv fotv fortv fortv fortv fortv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv cfgorstv fiortv fiortv fiortv cfgortv fiortv fiortv ao no fotv fotv fortv fortv fortv fortv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv cfgostv fotv fotv fotv fotv fotv ao no fotv fotv fortv fotv fotv fotv ao fotv fotv fotv o fotv nor ao o ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no o o.fotv fotv fotv cfgostv cfgotv fotv cfgotv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv cfgotv cfgostv fotv cfgotv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv fotv fotv cfgostv fotv fiotv ao no fotv fotv fotv fotv fotv fortv ao fotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv cfgotv cfgotv fotv cfgostv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv fotv fotv fotv fotv cfgostv ao no fotv fotv fotv fotv fotv fotv ao fotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.or or or or or or or or cgors no o o or or or or or or o or or o nor or or or o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o nor or no or o or or or or or or no or o.o o o o o o o o o cgnos o o o o o o o o o o o o no o o o o o o no o o o no cgnos o acfginorstv o o no o no o o no o o o no o no o o o o o o o o no o o.fotv fotv fotv fotv fotv fotv fotv fotv ao no cfgostv fotv fiotv fiotv fiotv cfgiotv ao fiotv fiotv fiortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv io acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or ino fotv fotv fotv fotv fotv fotv fotv fotv no or io.fotv fotv fotv fotv fotv fotv fotv fotv ao no fgotv cfgostv fiotv fiotv fiotv cfgiotv ao fiotv fgiotv fiortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv io acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or ino fotv fotv fotv fotv fotv fotv fotv fotv no or io.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv cfgostv fotv fotv fotv ao fotv fotv fotv o fotv nor ao o ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no o o.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fotv cfgostv cfgotv fotv ao cfgotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fotv cfgotv cfgostv fotv ao cfgotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fotv fotv fotv cfgostv ao fotv fotv fiotv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no fotv fotv fotv fotv fotv fotv fotv fotv no or o.o o o o o o o o o no o o o o o o cgos o o o or o nor cgos or o o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o nor or no o o o o o o o o no or o.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fotv cfgotv cfgotv fotv ao cfgostv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fiotv fiotv fiotv cfgotv ao fiotv cfgostv fiortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv io acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or ino fotv fotv fotv fotv fotv fotv fotv fotv no or io.fotv fotv fotv fotv fotv fotv fotv fotv ao no fotv fotv fotv fotv fotv fotv ao fotv fotv cfgostv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv fotv no or o.o o o o o o o o o no o o o o o o o o o o cfgostv o nor o fortv o o o o no o o o nor cfgnorstv o acfginorstv o o no o nor o o nor o o o nor fotv no o o o o o o o o no fotv o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fortv fortv fortv fortv fortv fortv ao fortv fortv fortv or cfgostv nor ao or ao o fgortv fotv no fortv fortv o nor acfginorstv o acfginorstv fotv ao no fortv nor fortv o nor fotv o ao nor or nor fgiortv fortv fiortv fiortv fiortv fgiortv fiortv fiortv no or o.o o o o o o o o o no o o o o o o o o o o o o cgnos o o o o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o cgnos o no o o o o o o o o no o o.o o o o o o o o o no o o o o o o cgos o o o or o nor cgos or o o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o nor or no o o o o o o o o no or o.o o o o o o o o o no o o o o o o o o o o fotv o nor o cfgostv o o o o no o o o nor cfgnorstv o acfginorstv o o no o nor o o nor o o o nor fotv no o o o o o o o o no fotv o.o o o o o o o o o no o o o o o o or o o o or o nor or or cgos o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o nor or no o o o o o o o o no or o.or or or or or or or or or no or or or or or or or or or or or or nor or or or cgos or or no or or o nor cgnors o acfginorstv or or no or nor or or nor or o or nor or nor or or or or or or or or no or o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fotv fotv fortv fortv fortv fortv ao fortv fotv fortv or fotv nor ao or ao o cfgostv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no cfgiortv fotv fiortv fiortv fiortv cfgiortv fiortv fiortv no or o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fiortv fiortv fiortv fiortv fiortv fiortv ao fiortv fiortv fiortv or fotv nor ao or ao o fgiortv cfgostv no fgiortv fgiortv o nor acfginorstv io acfginorstv fotv aio no fgiortv nor fortv o nor fotv o ao nor or inor fgiortv fortv fiortv fiortv fiortv fgiortv fiortv fiortv no or io.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o cgnos o o o no cgnos o acfginorstv o o no o no o o no o o o no o no o o o o o o o o no o o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fotv fotv fortv fortv fortv fortv ao fortv fotv fortv or fotv nor ao or ao o cfgortv fotv no cfgorstv fotv o nor acfginorstv o acfginorstv fotv aio no fotv nor fotv o nor fotv o ao nor or no cfgiortv fotv fiortv fiortv fiortv cfgiortv fiortv fiortv no or o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fiotv fiotv fiortv fiortv fiortv fiortv ao fiortv fiotv fiortv or fotv nor ao or ao o cfgiortv fotv no cfgiortv cfgiostv o nor acfginorstv io acfginorstv fotv aio no cfgiotv nor fotv o nor fotv o ao nor or ino cfgiortv fotv fiortv fiortv fiortv cfgiortv fiortv fiortv no or io.o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o cgos o cgos o acfginorstv o o o o o o o o o o o o o o o o o o o o o o o o o.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o cgnos cgnos o acfginorstv o o no o no o o no o o o no o no o o o o o o o o no o o.cfgorstv cfgorstv cfgiorstv cfgiorstv cfgiorstv cfgorstv cfgiorstv cfgiorstv acgiors cgnos cfgiorstv cfgiorstv cfgiorstv cfgiorstv cfgiorstv cfgiorstv acgors cfgiorstv cfgiorstv cfgiorstv cfgiorstv cfgorstv cgnors acgors cfgorstv acgors acgors cfgiorstv cfgorstv cgnos cfgiorstv cfgiorstv cgos cgnors acfginorstv cfgiost acfginorstv cfgorstv acgiors cgnos cfgiorstv cgnors cfgorstv cfgorst cgnors cfgorstv cgo acgors cgnors cfgorstv cginors cfgiorstv cfgorstv cfgiorstv cfgiorstv cfgiorstv cfgiorstv cfgiorstv cfgiorstv cgnos cfgiorstv cfgiost.o o o o o o o o o no o o o o o o o o o o o o no o o o ao o o no o o o no acfgnost cfgost acfginorstv o o no o no o fot no o o o no o no o o o o o o o o no o fot.fortv fortv fiortv fiortv fiortv fortv fiortv fiortv aior no fiortv fiortv fiortv fiortv fiortv fiortv aor fiortv fiortv fiortv fiortv fortv nor aor fortv aor aor fiortv fortv no fiortv fiortv o nor afinortv fiot acfginorstv fortv aior no fiortv nor fortv fort nor fortv - aor nor fortv inor fiortv fortv fiortv fiortv fiortv fiortv fiortv fiortv no fiortv fiot.cfgortv cfgortv cfgiortv cfgiortv cfgiortv cfgortv cfgiortv cfgiortv acgio cgno cfgiortv cfgiortv cfgiortv cfgiortv cfgiortv cfgiortv acgo cfgiortv cfgiortv cfgiortv cgor cfgotv cgnor acgo cgor acgo cgo cfgiortv cfgotv cgno cfgiortv cfgiortv cgo cgnor acfginorstv cgio acfginorstv cfgostv acgio cgno cfgiortv cgnor cfgortv cgo cgnor cfgotv cgo acgo cgnor cgor cginor cfgiortv cfgortv cfgiortv cfgiortv cfgiortv cfgiortv cfgiortv cfgiortv cgno cgor cgio.or or or or or or or or or no o o or or or or or or o or or o nor or or or o or o no or o o nor cgnors o acfginorstv o cgors no o nor o o nor o o o nor or no or o or or or or or or no or o.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o no cgnos o acfginorstv o o cgnos o no o o no o o o no o no o o o o o o o o no o o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fiotv fiotv fiortv fiortv fiortv fiortv ao fiortv fiotv fiortv or fotv nor ao or ao o cfgiortv fotv no cfgiortv cfgiotv o nor acfginorstv io acfginorstv fotv aio no cfgiostv nor fotv o nor fotv o ao nor or ino cfgiortv fotv fiortv fiortv fiortv cfgiortv fiortv fiortv no or io.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o nor cgnors o acfginorstv o o no o cgnos o o no o o o no o no o o o o o o o o no o o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fiotv fiotv fiortv fiortv fiortv fiortv ao fiortv fiotv fiortv or fotv nor ao or ao o fgiortv fotv no fgiortv fgiotv o nor acfginorstv io acfginorstv fotv aio no fgiotv nor cfgostv o nor fotv o ao nor or ino fgiortv fgotv fiortv fiortv fiortv fgiortv fiortv fiortv no or io.cgor cgor cgor cgor cgor cgor cgor cgor cgor no cgor cgor cgor cgor cgor cgor cgor cgor cgor cgor cgor cgor cgnor cgor cgor cgor ao cgor cgor no cgor cgor o cgnor acfginorst fot acfginorstv cgor cgor no cgor cgnor cgor cfgost nor cgor cgo cgor cgnor cgor inor cgor cgor cgor cgor cgor cgor cgor cgor no cgor fot.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o nor cgnors o acfginorstv o o no o nor o o cgnos o o o no o no o o o o o o o o no o o.fortv fortv fortv fortv fortv fortv fortv cfgortv acgo no fotv fotv fortv fortv fortv fortv acgo fortv fotv cfgortv or fotv nor acgo or acgo o fortv fotv no fortv fotv o nor acfgnorstv o acfginorstv fotv acgo no fotv nor fotv o nor cfgostv o acgo nor or no fortv fotv fortv fortv fortv fortv fortv cfgortv no or o.o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o - o o o o o o o o o - o o o o o o o o o o o o o o o.o o o o o o o o o no o o o o o o or o o o or o nor or or o o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o cgos nor or no o o o o o o o o no or o.o o o o o o o o o no o o o o o o o o o o o o cgnos o o o o o o no o o o nor cgnors o acfginorstv o o no o nor o o nor o o o cgnos o no o o o o o o o o no o o.o o o o o o o o o no o o o o o o o o o o fiotv o nor o fortv o o o o no o o o nor cfginorstv o acfginorstv o o no o nor o o nor o o o nor cfgostv no o o o o o o o o no fiotv o.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o no cgnos o acfginorstv o o no o no o o no o o o no o cgnos o o o o o o o o no o o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fotv fotv fortv fortv fortv fortv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no cfgiorstv fotv fiortv fiortv fiortv cfgiortv fiortv fiortv no or o.fortv fortv fortv fortv fortv fortv fortv fortv aio no fiotv fiotv fiortv fiortv fiortv fiortv ao fiortv fiotv fiortv or fotv nor ao or ao o fgiortv fotv no fgiortv fgiotv o nor acfginorstv io acfginorstv fotv aio no fgiotv nor fotv o nor fotv o ao nor or ino fgiortv cfgostv fiortv fiortv fiortv cfgiortv fiortv fiortv no or io.fotv fotv fortv fotv fotv fotv fotv fotv ao no fotv fotv fortv fotv fotv fotv ao fotv fotv fotv o fotv nor ao o ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv cfgostv fotv fotv fotv fotv fotv no o o.fotv fotv fotv fortv fortv fotv fortv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv cfgostv cfgotv fotv cfgotv fortv no or o.fotv fotv fotv fortv fortv fotv fortv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv cfgotv cfgostv fotv cfgotv fortv no or o.fotv fotv fotv fotv fotv fortv fotv fortv ao no fotv fotv fotv fotv fotv fortv ao fotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfginorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor or no fotv fotv fotv fotv fotv cfgostv fotv fiotv no or o.fotv fotv fotv fortv fortv fotv fortv fortv ao no fotv fotv fotv fortv fortv fotv ao fortv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv cfgotv cfgotv fotv cfgostv fortv no or o.fotv fotv fotv fotv fotv fotv fotv fortv ao no fotv fotv fotv fotv fotv fotv ao fotv fotv fortv or fotv nor ao or ao o fotv fotv no fotv fotv o nor acfgnorstv o acfginorstv fotv ao no fotv nor fotv o nor fotv o ao nor o no fotv fotv fotv fotv fotv fotv fotv cfgostv no or o.o o o o o o o o o no o o o o o o o o o o o o no o o o o o o no o o o no cgnos o acfginorstv o o no o no o o no o o o no o no o o o o o o o o cgnos o o.o o o o o o o o o no o o o o o o o o o o fotv o nor o fortv o o o o no o o o nor cfgnorstv o acfginorstv o o no o nor o o nor o o o nor fotv no o o o o o o o o no cfgostv o.or or or or or or or or or no or or or or or or or or or or or or nor or or or aor or or no or or o nor acfgnorst fot acfginorstv or or no or nor or fort nor or o or nor or nor or or or or or or or or no or cfgost`.split(`.`),Zn={a:`access`,c:`composition`,f:`flow`,g:`aggregation`,i:`assignment`,n:`influence`,o:`association`,r:`realization`,s:`specialization`,t:`triggering`,v:`serving`},Qn=`bpmn@1`,$n=`archimate@1`,er=`uml@1`;function tr(e,t,n){let r=n===void 0?{}:{entityTypes:n};return{id:e,label:t,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`],...r},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`],...r}]}}var nr={id:Qn,name:`bpmn`,version:1,completeness:`skeleton`,entityTypes:[{id:`process`,label:`Process`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200}]},{id:`participant`,label:`Participant (pool)`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200}]},{id:`lane`,label:`Lane`,attributes:[{name:`name`,kind:`text`,maxLength:200}]},{id:`task`,label:`Task`,attributes:[{name:`name`,kind:`text`,maxLength:200}]},{id:`subProcess`,label:`Sub-process`,attributes:[{name:`name`,kind:`text`,maxLength:200}]},{id:`event`,label:`Event`,attributes:[{name:`name`,kind:`text`,maxLength:200},{name:`position`,kind:`enum`,values:[`start`,`intermediate`,`end`],required:!0}]},{id:`gateway`,label:`Gateway`,attributes:[{name:`name`,kind:`text`,maxLength:200},{name:`gatewayKind`,kind:`enum`,values:[`exclusive`,`inclusive`,`parallel`,`eventBased`,`complex`],required:!0}]}],portTypes:[{id:`flowPort`,label:`Flow port`,directions:[`in`,`out`]}],relationTypes:[{id:`sequenceFlow`,label:`Sequence flow`,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`,`port`]},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`,`port`]}],attributes:[{name:`condition`,kind:`text`,maxLength:400},{name:`default`,kind:`boolean`}]},tr(`messageFlow`,`Message flow`),tr(`association`,`Association`),{id:`flowElementContainment`,label:`Flow element containment`,direction:`directed`,roles:[{role:`parent`,cardinality:{min:1,max:1},targets:[`entity`],entityTypes:[`process`,`subProcess`,`participant`,`lane`]},{role:`child`,cardinality:{min:1,max:1},targets:[`entity`]}],hierarchy:{id:`bpmn-containment`,shape:`tree`,parentRole:`parent`,childRole:`child`}}],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:`bpmn-containment`}],limits:{maxEndpointsPerRelation:2},notes:[`SKELETON. Declared: element types, sequence/message/association arity, a containment tree.`,`NOT declared: sequence flow contained in its process, message flow between participants, event nature and direction, gateway arity, BPMN DI, IDs and refs of the XML serialisation.`,`A diagram this profile validates is not an executable process. Execution engines are out of scope.`,`Qualification fixtures are partial: fixtures/valid/bpmn-skeleton-document.json only.`]},rr={id:$n,name:`archimate`,version:1,completeness:`skeleton`,entityTypes:[{id:`element`,label:`Element`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`layer`,kind:`enum`,required:!0,values:[`strategy`,`business`,`application`,`technology`,`physical`,`motivation`,`implementation`]},{name:`aspect`,kind:`enum`,values:[`active`,`behaviour`,`passive`,`motivation`]}]},{id:`junction`,label:`Junction`,attributes:[{name:`operator`,kind:`enum`,values:[`and`,`or`],required:!0}]},{id:`grouping`,label:`Grouping`,attributes:[{name:`name`,kind:`text`,maxLength:200}]}],portTypes:[],relationTypes:[`composition`,`aggregation`,`assignment`,`realization`,`serving`,`access`,`influence`,`triggering`,`flow`,`association`,`specialization`].map(e=>tr(e,e)),constraints:[],limits:{maxEndpointsPerRelation:2},notes:[`SKELETON. Declared: element/junction/grouping, the eleven relation names with 1..1 arity.`,`NOT declared: the versioned relation/source/target matrix, access mode, viewpoints, Open Group Model Exchange namespaces.`,`No ArchiMate conformance is claimed. Conformance needs a fixture per matrix constraint (GD-M3).`,`Qualification fixtures are partial: fixtures/valid/archimate-skeleton-document.json only.`]},ir={id:er,name:`uml`,version:1,completeness:`skeleton`,entityTypes:[{id:`class`,label:`Class`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`abstract`,kind:`boolean`},{name:`stereotypes`,kind:`collection`,item:{kind:`text`,maxLength:60},maxItems:8}]},{id:`interface`,label:`Interface`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200}]},{id:`package`,label:`Package`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200}]},{id:`property`,label:`Property`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`typeName`,kind:`text`,maxLength:200},{name:`multiplicity`,kind:`text`,maxLength:20}]},{id:`operation`,label:`Operation`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`returnTypeName`,kind:`text`,maxLength:200}]}],portTypes:[],relationTypes:[{id:`association`,label:`Association`,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`]},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`]}],attributes:[{name:`sourceMultiplicity`,kind:`text`,maxLength:20},{name:`targetMultiplicity`,kind:`text`,maxLength:20}]},tr(`generalization`,`Generalization`,[`class`,`interface`]),tr(`dependency`,`Dependency`),{id:`packageContainment`,label:`Package containment`,direction:`directed`,roles:[{role:`parent`,cardinality:{min:1,max:1},targets:[`entity`],entityTypes:[`package`]},{role:`child`,cardinality:{min:1,max:1},targets:[`entity`]}],hierarchy:{id:`uml-package-containment`,shape:`tree`,parentRole:`parent`,childRole:`child`}}],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:`uml-package-containment`}],limits:{maxEndpointsPerRelation:2},notes:[`SKELETON. Declared subset: classifiers, properties, operations, association/generalization/dependency, a package containment tree.`,`NOT declared: full multiplicity semantics, profiles and stereotype application rules, activity/sequence/state families (their own profiles).`,`UML does not reduce to PlantUML text; the pivot is a codec concern (GD-M4).`,`Qualification fixtures are partial: fixtures/valid/uml-skeleton-document.json only.`]},ar=[`composition`,`aggregation`,`assignment`,`realization`,`serving`,`access`,`influence`,`triggering`,`flow`,`association`,`specialization`];function or(){let e=e=>e===`Relationship`?`@relation`:e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),t=[];return Xn.forEach((n,r)=>{n.split(` `).forEach((n,i)=>{if(n!==`-`)for(let a of n)t.push({relationType:Zn[a],sourceType:e(Yn[r]),targetType:e(Yn[i])})})}),t}var sr=(e,t,n=!1)=>({name:e,kind:`text`,...n?{required:!0}:{},...t===void 0?{}:{maxLength:t}}),cr=e=>({name:e,kind:`boolean`}),lr=(e,t,n=!1)=>({name:e,kind:`enum`,values:[...t],...n?{required:!0}:{}}),ur=(e,t,n)=>({role:e,cardinality:{min:1,max:1},targets:[...t],...n===void 0?{}:{entityTypes:[...n]}}),dr=(e,t,n=[`entity`])=>({id:e,label:e,direction:`directed`,roles:[ur(`source`,n,t),ur(`target`,n,t)]}),fr=(e,t,n,r)=>({id:e,label:e,direction:`directed`,roles:[ur(`parent`,[`entity`],[n]),ur(`child`,[`entity`],r)],hierarchy:{id:t,shape:`tree`,parentRole:`parent`,childRole:`child`}});function pr(){let e=or();return{id:`archimate@2`,name:`archimate`,version:2,completeness:`complete`,entityTypes:[{id:`element`,label:`Element`,abstract:!0,attributes:[]},...Jn.map(e=>({id:e.id,label:e.name,supertypes:[`element`],...e.id===`grouping`?{container:!0}:{},attributes:[...e.id===`junction`?[lr(`operator`,[`and`,`or`],!0)]:[sr(`name`,200,e.id!==`grouping`)],...e.layer===`none`?[]:[lr(`layer`,[e.layer],!0)],lr(`aspect`,[e.aspect])]}))],portTypes:[],relationTypes:[...ar.map(e=>({...dr(e,void 0,[`entity`,`relation`]),...e===`access`?{attributes:[lr(`accessMode`,[`write`,`read`,`unspecified`,`read-write`])]}:e===`influence`?{attributes:[sr(`strength`)]}:e===`association`?{attributes:[cr(`directed`)]}:{}})),fr(`groupingContainment`,`archimate-grouping`,`grouping`,[`element`])],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:`archimate-grouping`},{kind:`relationship-matrix`,matrixId:`archimate-3.2`,sourceRole:`source`,targetRole:`target`,tuples:e},{kind:`incident-type-uniformity`,matrixId:`archimate-3.2`,entityType:`junction`,relationTypes:[...ar]}],limits:{maxEndpointsPerRelation:2},notes:[]}}var mr=pr(),hr=(e,t,n=!1)=>({name:e,kind:`text`,...n?{required:!0}:{},...t===void 0?{}:{maxLength:t}}),gr=e=>({name:e,kind:`boolean`}),_r=(e,t,n=!1)=>({name:e,kind:`enum`,values:[...t],...n?{required:!0}:{}}),vr=(e,t,n)=>({role:e,cardinality:{min:1,max:1},targets:[...t],...n===void 0?{}:{entityTypes:[...n]}}),yr=(e,t,n=[`entity`])=>({id:e,label:e,direction:`directed`,roles:[vr(`source`,n,t),vr(`target`,n,t)]}),br=(e,t,n,r)=>({id:e,label:e,direction:`directed`,roles:[vr(`parent`,[`entity`],[n]),vr(`child`,[`entity`],r)],hierarchy:{id:t,shape:`tree`,parentRole:`parent`,childRole:`child`}}),xr=()=>_r(`visibility`,[`public`,`protected`,`private`,`package`]),Sr=()=>({name:`stereotypes`,kind:`collection`,item:{kind:`reference`,refKind:`entity`,targetTypes:[`stereotype`]},maxItems:8}),Cr=()=>[hr(`name`,200,!0),xr(),Sr()],wr=e=>({name:e,kind:`struct`,targetTypes:[`multiplicity`]}),Tr=e=>_r(e,[`none`,`shared`,`composite`]);function Er(){let e=yr(`generalization`,[`class`,`interface`]);return e.hierarchy={id:`uml-generalization`,shape:`dag`,parentRole:`target`,childRole:`source`},{id:`uml@2`,name:`uml`,version:2,completeness:`complete`,entityTypes:[{id:`class`,label:`Class`,attributes:[...Cr(),gr(`abstract`),gr(`isStatic`)]},{id:`interface`,label:`Interface`,attributes:Cr()},{id:`package`,label:`Package`,container:!0,attributes:Cr()},{id:`property`,label:`Property`,attributes:[...Cr(),hr(`typeName`,200),wr(`multiplicity`),gr(`isDerived`),gr(`isStatic`)]},{id:`operation`,label:`Operation`,attributes:[...Cr(),hr(`returnTypeName`,200),gr(`isStatic`)]},{id:`stereotype`,label:`Stereotype`,attributes:[hr(`name`,60,!0),{name:`extends`,kind:`collection`,required:!0,item:{kind:`enum`,values:[`class`,`interface`,`package`,`property`,`operation`]},minItems:1,maxItems:5}]},{id:`multiplicity`,label:`Multiplicity`,abstract:!0,attributes:[{name:`lower`,kind:`quantity`,required:!0,units:[`unit`],integer:!0,min:0,max:9007199254740991},{name:`upper`,kind:`quantity`,required:!0,units:[`unit`],integer:!0,min:-1,max:9007199254740991},gr(`isOrdered`),gr(`isUnique`)]}],portTypes:[],relationTypes:[{...yr(`association`,[`class`,`interface`]),attributes:[wr(`sourceMultiplicity`),wr(`targetMultiplicity`),Tr(`sourceAggregation`),Tr(`targetAggregation`)]},e,yr(`dependency`),br(`packageContainment`,`uml-package-containment`,`package`)],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:`uml-package-containment`},{kind:`acyclic-hierarchy`,hierarchyId:`uml-generalization`},{kind:`bound-pair`,valueType:`multiplicity`,lowerField:`lower`,upperField:`upper`,unboundedUpper:-1},{kind:`reference-application`,attribute:`stereotypes`,declarationType:`stereotype`,allowedTypesField:`extends`},{kind:`at-most-value`,relationType:`association`,attributes:[`sourceAggregation`,`targetAggregation`],value:`composite`,max:1},{kind:`collection-unique`,entityType:`stereotype`,attribute:`extends`}],limits:{maxEndpointsPerRelation:2},notes:[]}}var Dr=Er();function Or(e,t,n){if(Nn(t,n.type)!==void 0)return n.type;let r=e.typeDefinitions[n.type];return r?.profile===t.id?r.baseType:n.type}function kr(e,t,n){let r=Nn(t,Or(e,t,n));if(r===void 0)return;let i=e.typeDefinitions[n.type];return n.type===r.id||i?.profile!==t.id?r:{...r,attributes:[...r.attributes??[],...i.attributes]}}function Ar(e,t,n){let r=[],i=(e,t,n)=>r.push(H({code:e,path:t,message:n}));for(let r of Object.values(e.entities).filter(e=>e.profile===t.id)){let a=Object.values(e.ports).filter(e=>e.owner===r.id),o=`entities.`+r.id,s=a.filter(e=>e.attributes.pk?.kind===`boolean`&&e.attributes.pk.value);s.length!==1&&i(s.length?`erd-multiple-pk`:`erd-missing-pk`,o,`An entity requires exactly one primary key`),a.length>n&&i(`limit-exceeded`,o,`Too many attribute rows: `+a.length),(new Set(a.map(e=>e.name)).size!==a.length||new Set(a.map(e=>e.attributes.ordinal?.kind===`quantity`?e.attributes.ordinal.value:-1)).size!==a.length)&&i(`erd-duplicate-field`,o,`Field names and ordinals must be distinct`);for(let n of a){let r=n.attributes.fk;if(r?.kind!==`reference`)continue;let a=e.ports[r.value];a?(a.profile!==t.id||a.attributes.pk?.kind!==`boolean`||!a.attributes.pk.value)&&i(`erd-invalid-fk-target`,`ports.`+n.id,`Foreign key must target a primary key`):i(`erd-dangling-fk`,`ports.`+n.id,`Foreign key target is missing: `+r.value)}}for(let n of Object.values(e.relations).filter(e=>e.profile===t.id))for(let e of[`from`,`to`])n.endpoints.some(t=>t.role===e)||i(`erd-missing-end`,`relations.`+n.id,`Missing relationship end: `+e);return r}var jr=`erd@1`,Mr=[`1`,`0..1`,`1..n`,`0..n`],Nr={id:jr,name:`ERD`,version:1,completeness:`complete`,entityTypes:[{id:`entity`,label:`Entity`,foldable:!0,attributes:[{name:`name`,kind:`text`,required:!0},{name:`schema`,kind:`text`}]}],portTypes:[{id:`field`,label:`Attribute row`,directions:[`inout`],attributes:[{name:`dataType`,kind:`text`,required:!0},{name:`pk`,kind:`boolean`,required:!0},{name:`fk`,kind:`reference`,refKind:`port`},{name:`nullable`,kind:`boolean`,required:!0},{name:`ordinal`,kind:`quantity`,units:[`index`],integer:!0,min:0,required:!0}]}],relationTypes:[{id:`relationship`,label:`Relationship`,direction:`undirected`,roles:[`from`,`to`].map(e=>({role:e,cardinality:{min:1,max:1},targets:[`entity`,`port`]})),attributes:[{name:`name`,kind:`text`,required:!0},{name:`label`,kind:`text`},...[`from`,`to`].flatMap(e=>[{name:e+`Cardinality`,kind:`enum`,values:Mr,required:!0},{name:e+`Role`,kind:`text`,required:!0}])]}],constraints:[{kind:`erd-keys`,maxFields:17}],limits:{maxEntities:1e3,maxRelations:1e4,maxEndpointsPerRelation:2},notes:[`Exactly one primary key per entity; no composite keys. Many-to-many remains one relationship.`]},Pr=`generic@1`,Fr=`containment`,Ir={id:Pr,name:`generic`,version:1,completeness:`complete`,entityTypes:[{id:`node`,label:`Node`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`state`,kind:`enum`,values:[`draft`,`active`,`retired`]},{name:`weight`,kind:`quantity`,units:[`unit`]},{name:`duration`,kind:`quantity`,units:[`s`,`min`,`h`]},{name:`createdAt`,kind:`date`},{name:`pinned`,kind:`boolean`},{name:`tags`,kind:`collection`,item:{kind:`text`,maxLength:40},maxItems:8},{name:`owner`,kind:`reference`,refKind:`entity`}]},{id:`container`,label:`Container`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`collapsed`,kind:`boolean`}]}],portTypes:[{id:`port`,label:`Port`,directions:[`in`,`out`,`inout`],attributes:[{name:`label`,kind:`text`,maxLength:80}]}],relationTypes:[{id:`link`,label:`Link`,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`,`port`]},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`,`port`]}],attributes:[{name:`label`,kind:`text`,maxLength:120},{name:`weight`,kind:`quantity`,units:[`unit`]}]},{id:`contains`,label:`Contains`,direction:`directed`,roles:[{role:`parent`,cardinality:{min:1,max:1},targets:[`entity`],entityTypes:[`container`]},{role:`child`,cardinality:{min:1,max:1},targets:[`entity`]}],hierarchy:{id:Fr,shape:`tree`,parentRole:`parent`,childRole:`child`}},{id:`association`,label:`Association`,direction:`undirected`,roles:[{role:`member`,cardinality:{min:2,max:8},targets:[`entity`]}],attributes:[{name:`label`,kind:`text`,maxLength:120}]}],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:Fr},{kind:`unique-attribute`,entityType:`container`,attribute:`name`},{kind:`max-entities-of-type`,entityType:`container`,max:64}],limits:{maxEntities:1e5,maxRelations:5e5,maxEndpointsPerRelation:8},notes:[`Complete profile: every declaration here is exercised by a test or a fixture in this package.`,"Business cycles are legal through `link` and `association`; only the declared `containment` tree refuses them.",`No BPMN/ArchiMate/UML status is induced by any shape or name in this profile.`]},Lr=`generic@2`,Rr=`containment`,zr=`^[a-z][a-z0-9-]*$`,Br=(e,t)=>({name:e,kind:`text`,...t?{required:!0}:{},minLength:1,maxLength:40,pattern:zr,patternName:`key`}),Vr={id:Lr,name:`generic`,version:2,completeness:`complete`,entityTypes:[{id:`node`,label:`Node`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`state`,kind:`enum`,values:[`draft`,`active`,`retired`]},{name:`weight`,kind:`quantity`,units:[`unit`]},{name:`duration`,kind:`quantity`,units:[`s`,`min`,`h`]},{name:`createdAt`,kind:`date`},{name:`pinned`,kind:`boolean`},{name:`tags`,kind:`collection`,item:{kind:`text`,maxLength:40},maxItems:8},{name:`owner`,kind:`reference`,refKind:`entity`},Br(`category`,!1)]},{id:`container`,label:`Container`,container:!0,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},Br(`category`,!1)]},{id:`legend`,label:`Legend`,container:!0,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`description`,kind:`text`,maxLength:600}]},{id:`legend-key`,label:`Legend key`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:120},Br(`category`,!0),{name:`description`,kind:`text`,maxLength:200}]}],portTypes:[{id:`port`,label:`Port`,directions:[`in`,`out`,`inout`],attributes:[{name:`label`,kind:`text`,maxLength:80}]}],relationTypes:[{id:`link`,label:`Link`,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`,`port`]},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`,`port`]}],attributes:[{name:`label`,kind:`text`,maxLength:200},{name:`weight`,kind:`quantity`,units:[`unit`]}]},{id:`contains`,label:`Contains`,direction:`directed`,roles:[{role:`parent`,cardinality:{min:1,max:1},targets:[`entity`],entityTypes:[`container`,`legend`]},{role:`child`,cardinality:{min:1,max:1},targets:[`entity`]}],hierarchy:{id:Rr,shape:`tree`,parentRole:`parent`,childRole:`child`}},{id:`association`,label:`Association`,direction:`undirected`,roles:[{role:`member`,cardinality:{min:2,max:8},targets:[`entity`]}],attributes:[{name:`label`,kind:`text`,maxLength:120}]}],constraints:[{kind:`hierarchy`,relationType:`contains`,hierarchyId:Rr,parentRole:`parent`,childRole:`child`},{kind:`parent-family`,hierarchyId:Rr,familyRoots:[`container`,`legend`]},{kind:`children-restricted`,parentFamilyRoots:[`legend`],childTypes:[`legend-key`],hierarchyId:Rr},{kind:`required-parent`,childTypes:[`legend-key`],parentFamilyRoots:[`legend`],hierarchyId:Rr},{kind:`acyclic-hierarchy`,hierarchyId:Rr},{kind:`unique-attribute`,entityType:`legend-key`,attribute:`category`,scope:{withinType:`legend`}}],limits:{maxEntities:1e5,maxRelations:5e5,maxEndpointsPerRelation:8},notes:[`Complete profile: the replacement base for generic@1, not its child.`,"Business cycles are legal through `link` and `association`; only the declared `containment` tree refuses them.",`Category is domain data; tokens, icons, order and footprints live in the view/presentation contract.`]},Hr=[Ir],Ur=[nr,rr,ir];An([...Hr,...Ur]),An([...Hr,...Ur,Vr,mr,Dr,Nr]),An([...Hr,...Ur,Vr,mr,Dr,Nr]);function Wr(e){let t;return{schemaVersion:`1`,get rows(){return t===void 0&&(t=_n([...e])),t.rows}}}[...Hr,...Ur];var Gr=Wr([...Hr,...Ur]),Kr={major:1,minor:1},qr=e=>e.kind===`document`?void 0:e.target,Jr=class{cycle;constructor(e){this.cycle=e}},Yr=class{fromId;baseId;constructor(e,t){this.fromId=e,this.baseId=t}},Xr=class{definitionId;attribute;baseType;constructor(e,t,n){this.definitionId=e,this.attribute=t,this.baseType=n}},Zr=class{typeId;attribute;constructor(e,t){this.typeId=e,this.attribute=t}};function Qr(e){let t=e.revision,n=new Map,r=(t,n)=>{if(jn(t,n)!==void 0)return{kind:`profile`,id:n};let r=e.typeDefinitions[n];if(r!==void 0&&r.profile===t.id)return{kind:`definition`,definition:r}},i=(e,t)=>{if(r(e,t)===void 0)return{ok:!1,diagnostic:H({code:`unknown-entity-type`,path:`profiles.${e.id}.entityTypes.${t}`,message:`neither profile ${e.id} nor the document declares entity type ${t}`,details:{type:t,profile:e.id}}),failedType:t};let n=[],i=[],a=new Set,o=new Set,s=[],c=new Set,l=!1,u=t=>t.kind===`definition`?[t.definition.baseType]:jn(e,t.id)?.supertypes??[],d=t=>{let{id:r,node:s}=t;if(s.kind===`definition`){for(let e of s.definition.attributes)if(a.has(e.name))throw new Xr(s.definition.id,e.name,s.definition.baseType)}else{jn(e,s.id)?.container===!0&&(l=!0);let t=jn(e,s.id)?.attributes??[];for(let e of t)if(a.has(e.name)&&i.filter(t=>t.name===e.name).some(t=>vn(t)!==vn(e)))throw new Zr(s.id,e.name)}let c=s.kind===`profile`?jn(e,s.id)?.attributes??[]:s.definition.attributes;for(let e of c)a.has(e.name)||(i.push(e),a.add(e.name));o.add(r),n.push(r)};try{let n=r(e,t),i=[{id:t,node:n,bases:u(n),nextBase:0}];for(s.push(t),c.add(t);i.length>0;){let t=i[i.length-1];if(t.nextBase<t.bases.length){let n=t.bases[t.nextBase];if(t.nextBase+=1,o.has(n))continue;if(c.has(n))throw new Jr([...s.slice(s.indexOf(n)),n]);let a=r(e,n);if(a===void 0)throw new Yr(t.id,n);i.push({id:n,node:a,bases:u(a),nextBase:0}),s.push(n),c.add(n)}else d(t),i.pop(),s.pop(),c.delete(t.id)}}catch(n){if(n instanceof Jr){let e=n.cycle.join(`>`);return{ok:!1,diagnostic:H({code:`type-definition-conflict`,path:`typeDefinitions.${t}.baseType`,message:`type definition ${t} closes base cycle ${e}`,refs:[],details:{check:`resolution-cycle`,cycle:e}}),failedType:t}}if(n instanceof Yr)return{ok:!1,diagnostic:H({code:`unknown-entity-type`,path:`typeDefinitions.${n.fromId}.baseType`,message:`profile ${e.id} does not declare base type ${n.baseId}`}),failedType:t};if(n instanceof Xr)return{ok:!1,diagnostic:H({code:`type-definition-conflict`,path:`typeDefinitions.${n.definitionId}.attributes.${n.attribute}`,message:`type definition ${n.definitionId} redeclares ${n.attribute}, which base type ${n.baseType} already declares; refinements are additive only`,details:{attribute:n.attribute,baseType:n.baseType}}),failedType:t};if(n instanceof Zr)return{ok:!1,diagnostic:H({code:`attribute-conflict`,path:`profiles.${e.id}.entityTypes.${n.typeId}.attributes.${n.attribute}`,message:`inherited attribute ${n.attribute} has incompatible schemas on ${n.typeId}`,refs:[],details:{attribute:n.attribute,type:n.typeId}}),failedType:t};throw n}let f=[...n].reverse(),p=f.find(t=>jn(e,t)!==void 0)??t,m=jn(e,t);return{ok:!0,resolved:{profileId:e.id,typeId:t,ancestry:f,familyType:p,schemas:i,container:l,abstract:m?.abstract===!0}}};return{get revision(){return t},resolve:(r,a)=>{e.revision!==t&&(t=e.revision,n=new Map);let o=`${r.id}::${xn(r)}::${a}`,s=n.get(o);if(s!==void 0)return s;let c=i(r,a);return n.set(o,c),c}}}var $r=[`solid`,`dashed`,`dotted`],ei=[`arrow`,`none`],ti=[`default`,`emphasis`];function ni(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))ni(t);return Object.freeze(e)}var ri=ni({solid:{style:`solid`,meaning:`default`,dashArray:[]},dashed:{style:`dashed`,meaning:`proposed`,dashArray:[8,6],tokenName:`linkDashDashed`},dotted:{style:`dotted`,meaning:`dotted`,dashArray:[2,5],tokenName:`linkDashDotted`}}),ii=ni({arrow:{kind:`arrow`,canonicalKind:`arrow`,shape:`triangle`,fill:`stroke`,outlined:!1},none:{kind:`none`,canonicalKind:`none`,shape:`none`,fill:`none`,outlined:!1}}),ai=ni({default:{emphasis:`default`,strokeToken:`edgeStroke`,widthToken:`linkStrokeWidth`,changesDash:!1},emphasis:{emphasis:`emphasis`,strokeToken:`linkEmphasisStroke`,widthToken:`linkEmphasisStrokeWidth`,changesDash:!1}}),oi=new Set($r),si=new Set(ei),ci=new Set(ti);function li(e){return typeof e==`string`&&oi.has(e)}function ui(e){return typeof e==`string`&&si.has(e)}function di(e){return typeof e==`string`&&ci.has(e)}function fi(e){return e===void 0?ri.solid:li(e)?ri[e]:void 0}function pi(e){return e===void 0?ii.arrow:ui(e)?ii[e]:void 0}function mi(e){return e===void 0?ai.default:di(e)?ai[e]:void 0}var hi=`/**
|
|
11
|
+
* Presentation view validation (M3 §3.2–§3.6, C.3/C.6).
|
|
12
|
+
*
|
|
13
|
+
* Views without \`presentation.diagram\` validate exactly as on main; views
|
|
14
|
+
* carrying it execute the closed presentation checks. No folds, no
|
|
15
|
+
* measurement, no archimate@2/uml@2, no migrations.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { diagnostic, type Diagnostic } from "./diagnostics.js";
|
|
19
|
+
import type { SemanticDocument } from "./document.js";
|
|
20
|
+
import {
|
|
21
|
+
isPresentationContractPin,
|
|
22
|
+
type DiagramPresentation,
|
|
23
|
+
type PresentationPin,
|
|
24
|
+
} from "./presentation.js";
|
|
25
|
+
import { createTypeResolver } from "./resolver.js";
|
|
26
|
+
import { refKindOf } from "./refs.js";
|
|
27
|
+
import type { ProfileRegistry } from "./profile.js";
|
|
28
|
+
import type { ValidationOptions } from "./validate.js";
|
|
29
|
+
import type { ViewDocument } from "./view.js";
|
|
30
|
+
|
|
31
|
+
const KEY_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
32
|
+
const TOKEN_PATTERN = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$/;
|
|
33
|
+
const DIGEST_PATTERN = /^[0-9a-f]{64}$/;
|
|
34
|
+
|
|
35
|
+
function shapeMismatch(path: string): Diagnostic {
|
|
36
|
+
return diagnostic({
|
|
37
|
+
code: "occurrence-endpoint-mismatch",
|
|
38
|
+
severity: "error",
|
|
39
|
+
path,
|
|
40
|
+
message: "diagram presentation fails check presentation-shape-invalid",
|
|
41
|
+
refs: [],
|
|
42
|
+
details: { check: "presentation-shape-invalid" },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function pinMismatch(path: string): Diagnostic {
|
|
47
|
+
return diagnostic({
|
|
48
|
+
code: "occurrence-endpoint-mismatch",
|
|
49
|
+
severity: "error",
|
|
50
|
+
path,
|
|
51
|
+
message: "diagram presentation fails check presentation-pin-mismatch",
|
|
52
|
+
refs: [],
|
|
53
|
+
details: { check: "presentation-pin-mismatch" },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function formMismatch(path: string): Diagnostic {
|
|
58
|
+
return diagnostic({
|
|
59
|
+
code: "occurrence-endpoint-mismatch",
|
|
60
|
+
severity: "error",
|
|
61
|
+
path,
|
|
62
|
+
message: "diagram presentation fails check form-selector-mismatch",
|
|
63
|
+
refs: [],
|
|
64
|
+
details: { check: "form-selector-mismatch" },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function orderMismatch(path: string): Diagnostic {
|
|
69
|
+
return diagnostic({
|
|
70
|
+
code: "occurrence-endpoint-mismatch",
|
|
71
|
+
severity: "error",
|
|
72
|
+
path,
|
|
73
|
+
message: "diagram presentation fails check legend-order-invalid",
|
|
74
|
+
refs: [],
|
|
75
|
+
details: { check: "legend-order-invalid" },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function tokenConflict(path: string): Diagnostic {
|
|
80
|
+
return diagnostic({
|
|
81
|
+
code: "occurrence-endpoint-mismatch",
|
|
82
|
+
severity: "error",
|
|
83
|
+
path,
|
|
84
|
+
message: "diagram presentation fails check token-binding-conflict",
|
|
85
|
+
refs: [],
|
|
86
|
+
details: { check: "token-binding-conflict" },
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
91
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function textTooLong(path: string, length: number, maxLength: number): Diagnostic {
|
|
95
|
+
return diagnostic({
|
|
96
|
+
code: "text-too-long",
|
|
97
|
+
severity: "error",
|
|
98
|
+
path,
|
|
99
|
+
message: \`text is \${length} characters, the schema allows \${maxLength}\`,
|
|
100
|
+
details: { length, maxLength },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function patternMismatch(
|
|
105
|
+
path: string,
|
|
106
|
+
patternName: string,
|
|
107
|
+
length: number,
|
|
108
|
+
maxLength?: number,
|
|
109
|
+
): Diagnostic {
|
|
110
|
+
return diagnostic({
|
|
111
|
+
code: "text-pattern-mismatch",
|
|
112
|
+
severity: "error",
|
|
113
|
+
path,
|
|
114
|
+
message: \`value does not match the \${patternName} grammar\`,
|
|
115
|
+
refs: [],
|
|
116
|
+
details:
|
|
117
|
+
maxLength === undefined
|
|
118
|
+
? { pattern: patternName, length }
|
|
119
|
+
: { pattern: patternName, length, maxLength },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function minLengthMismatch(path: string, attribute: string, length: number, minLength: number): Diagnostic {
|
|
124
|
+
return diagnostic({
|
|
125
|
+
code: "text-pattern-mismatch",
|
|
126
|
+
severity: "error",
|
|
127
|
+
path,
|
|
128
|
+
message: \`value is shorter than the minimum length for \${attribute}\`,
|
|
129
|
+
refs: [],
|
|
130
|
+
details: { pattern: "min-length", length, minLength },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function danglingPresentation(path: string, targetId: string): Diagnostic {
|
|
135
|
+
return diagnostic({
|
|
136
|
+
code: "dangling-reference",
|
|
137
|
+
severity: "error",
|
|
138
|
+
path,
|
|
139
|
+
message: \`presentation reference \${targetId} does not resolve\`,
|
|
140
|
+
refs: [targetId],
|
|
141
|
+
details: {},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function wrongNamespacePresentation(path: string, targetId: string, expectedKind: string): Diagnostic {
|
|
146
|
+
return diagnostic({
|
|
147
|
+
code: "reference-type-mismatch",
|
|
148
|
+
severity: "error",
|
|
149
|
+
path,
|
|
150
|
+
message: \`presentation reference \${targetId} must be a \${expectedKind}\`,
|
|
151
|
+
refs: [targetId],
|
|
152
|
+
details: { expectedKind },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const GENERIC2_PROFILE_ID = "generic@2" as const;
|
|
157
|
+
|
|
158
|
+
interface FamilySets {
|
|
159
|
+
readonly legendHierarchyIds: ReadonlySet<string>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function collectFamilySets(registry: ProfileRegistry, profileIds: readonly string[]): FamilySets {
|
|
163
|
+
const legendHierarchyIds = new Set<string>();
|
|
164
|
+
for (const id of profileIds) {
|
|
165
|
+
if (id !== GENERIC2_PROFILE_ID) continue;
|
|
166
|
+
const profile = registry.get(id as never);
|
|
167
|
+
if (profile === undefined) continue;
|
|
168
|
+
for (const constraint of profile.constraints) {
|
|
169
|
+
if (constraint.kind === "children-restricted" || constraint.kind === "required-parent") {
|
|
170
|
+
const typed = constraint as {
|
|
171
|
+
readonly hierarchyId: string;
|
|
172
|
+
};
|
|
173
|
+
legendHierarchyIds.add(typed.hierarchyId);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { legendHierarchyIds };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isGeneric2Legend(
|
|
181
|
+
document: SemanticDocument,
|
|
182
|
+
registry: ProfileRegistry,
|
|
183
|
+
resolver: ReturnType<typeof createTypeResolver>,
|
|
184
|
+
entityId: string,
|
|
185
|
+
): boolean {
|
|
186
|
+
const entity = document.entities[entityId];
|
|
187
|
+
if (entity === undefined) return false;
|
|
188
|
+
if (entity.profile !== GENERIC2_PROFILE_ID) return false;
|
|
189
|
+
const owner = registry.get(entity.profile as never);
|
|
190
|
+
if (owner === undefined) return false;
|
|
191
|
+
const resolution = resolver.resolve(owner, entity.type);
|
|
192
|
+
if (!resolution.ok) return false;
|
|
193
|
+
return resolution.resolved.ancestry.includes("legend");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isGeneric2Key(
|
|
197
|
+
document: SemanticDocument,
|
|
198
|
+
registry: ProfileRegistry,
|
|
199
|
+
resolver: ReturnType<typeof createTypeResolver>,
|
|
200
|
+
entityId: string,
|
|
201
|
+
): boolean {
|
|
202
|
+
const entity = document.entities[entityId];
|
|
203
|
+
if (entity === undefined) return false;
|
|
204
|
+
if (entity.profile !== GENERIC2_PROFILE_ID) return false;
|
|
205
|
+
const owner = registry.get(entity.profile as never);
|
|
206
|
+
if (owner === undefined) return false;
|
|
207
|
+
const resolution = resolver.resolve(owner, entity.type);
|
|
208
|
+
if (!resolution.ok) return false;
|
|
209
|
+
return resolution.resolved.ancestry.includes("legend-key");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function satisfiesExplicitForm(
|
|
213
|
+
form: string,
|
|
214
|
+
ownerId: string,
|
|
215
|
+
ancestry: readonly string[],
|
|
216
|
+
container: boolean,
|
|
217
|
+
): boolean {
|
|
218
|
+
if (form === "card") return container === false;
|
|
219
|
+
if (form === "container") return container === true;
|
|
220
|
+
if (form === "legend") return ownerId === GENERIC2_PROFILE_ID && ancestry.includes("legend");
|
|
221
|
+
if (form === "legend-key") return ownerId === GENERIC2_PROFILE_ID && ancestry.includes("legend-key");
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function hierarchyChildren(
|
|
226
|
+
document: SemanticDocument,
|
|
227
|
+
registry: ProfileRegistry,
|
|
228
|
+
hierarchyIds: ReadonlySet<string>,
|
|
229
|
+
): Map<string, string[]> {
|
|
230
|
+
const childToParents = new Map<string, string[]>();
|
|
231
|
+
void registry;
|
|
232
|
+
void hierarchyIds;
|
|
233
|
+
void childToParents;
|
|
234
|
+
return new Map();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function validateDiagramPresentation(
|
|
238
|
+
document: SemanticDocument,
|
|
239
|
+
view: ViewDocument,
|
|
240
|
+
options: ValidationOptions,
|
|
241
|
+
): readonly Diagnostic[] {
|
|
242
|
+
const diagram = view.presentation.diagram as DiagramPresentation | undefined;
|
|
243
|
+
if (diagram === undefined) return [];
|
|
244
|
+
const diagnostics: Diagnostic[] = [];
|
|
245
|
+
const registry = options.registry;
|
|
246
|
+
const resolver = createTypeResolver(document);
|
|
247
|
+
const familySets = collectFamilySets(
|
|
248
|
+
registry,
|
|
249
|
+
document.profileRefs as readonly string[],
|
|
250
|
+
);
|
|
251
|
+
for (const key of Object.keys(view.relationOccurrences).sort()) {
|
|
252
|
+
const occurrence = view.relationOccurrences[key] as unknown as Record<string, unknown>;
|
|
253
|
+
const style = occurrence["strokeStyle"];
|
|
254
|
+
if (style !== undefined && style !== "solid" && style !== "dashed") {
|
|
255
|
+
diagnostics.push(shapeMismatch(\`relationOccurrences.\${key}.strokeStyle\`));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const shapeFailed = new Set<string>();
|
|
260
|
+
|
|
261
|
+
if (!isRecord(diagram)) {
|
|
262
|
+
diagnostics.push(shapeMismatch("presentation.diagram"));
|
|
263
|
+
return diagnostics;
|
|
264
|
+
}
|
|
265
|
+
const allowedDiagramKeys = new Set(["contractPin", "entities", "legends", "categoryTokens"]);
|
|
266
|
+
for (const key of Object.keys(diagram as unknown as Record<string, unknown>)) {
|
|
267
|
+
if (!allowedDiagramKeys.has(key)) {
|
|
268
|
+
diagnostics.push(shapeMismatch(\`presentation.diagram.\${key}\`));
|
|
269
|
+
shapeFailed.add(\`presentation.diagram.\${key}\`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
for (const required of ["contractPin", "entities", "legends", "categoryTokens"]) {
|
|
273
|
+
if ((diagram as unknown as Record<string, unknown>)[required] === undefined) {
|
|
274
|
+
diagnostics.push(shapeMismatch(\`presentation.diagram.\${required}\`));
|
|
275
|
+
shapeFailed.add(\`presentation.diagram.\${required}\`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (shapeFailed.size > 0) {
|
|
279
|
+
return diagnostics;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const contractPin = diagram.contractPin as unknown;
|
|
283
|
+
if (!isRecord(contractPin)) {
|
|
284
|
+
diagnostics.push(shapeMismatch("presentation.diagram.contractPin"));
|
|
285
|
+
return diagnostics;
|
|
286
|
+
}
|
|
287
|
+
const allowedPinKeys = new Set(["id", "version", "contentDigest"]);
|
|
288
|
+
for (const key of Object.keys(contractPin)) {
|
|
289
|
+
if (!allowedPinKeys.has(key)) {
|
|
290
|
+
diagnostics.push(shapeMismatch(\`presentation.diagram.contractPin.\${key}\`));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (const required of ["id", "version", "contentDigest"]) {
|
|
294
|
+
if (contractPin[required] === undefined) {
|
|
295
|
+
diagnostics.push(shapeMismatch(\`presentation.diagram.contractPin.\${required}\`));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (
|
|
299
|
+
typeof contractPin["id"] !== "string" ||
|
|
300
|
+
typeof contractPin["version"] !== "string" ||
|
|
301
|
+
typeof contractPin["contentDigest"] !== "string"
|
|
302
|
+
) {
|
|
303
|
+
diagnostics.push(shapeMismatch("presentation.diagram.contractPin"));
|
|
304
|
+
return diagnostics;
|
|
305
|
+
}
|
|
306
|
+
if (
|
|
307
|
+
!isPresentationContractPin(contractPin as unknown as PresentationPin) ||
|
|
308
|
+
!DIGEST_PATTERN.test(contractPin["contentDigest"] as string)
|
|
309
|
+
) {
|
|
310
|
+
diagnostics.push(pinMismatch("presentation.diagram.contractPin"));
|
|
311
|
+
return diagnostics;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!isRecord(diagram.entities as unknown)) {
|
|
315
|
+
diagnostics.push(shapeMismatch("presentation.diagram.entities"));
|
|
316
|
+
return diagnostics;
|
|
317
|
+
}
|
|
318
|
+
if (!isRecord(diagram.legends as unknown)) {
|
|
319
|
+
diagnostics.push(shapeMismatch("presentation.diagram.legends"));
|
|
320
|
+
return diagnostics;
|
|
321
|
+
}
|
|
322
|
+
if (!Array.isArray(diagram.categoryTokens as unknown)) {
|
|
323
|
+
diagnostics.push(shapeMismatch("presentation.diagram.categoryTokens"));
|
|
324
|
+
return diagnostics;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const entities = diagram.entities as unknown as Record<string, unknown>;
|
|
328
|
+
const legends = diagram.legends as unknown as Record<string, unknown>;
|
|
329
|
+
const categoryTokens = diagram.categoryTokens as unknown as readonly unknown[];
|
|
330
|
+
|
|
331
|
+
const validEntityOccurrences = new Set<string>();
|
|
332
|
+
for (const key of Object.keys(entities).sort()) {
|
|
333
|
+
const entryPath = \`presentation.diagram.entities.\${key}\`;
|
|
334
|
+
if (refKindOf(key) !== "occurrence") {
|
|
335
|
+
diagnostics.push(wrongNamespacePresentation(entryPath, key, "occurrence"));
|
|
336
|
+
shapeFailed.add(entryPath);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (view.entityOccurrences[key] === undefined) {
|
|
340
|
+
diagnostics.push(danglingPresentation(entryPath, key));
|
|
341
|
+
shapeFailed.add(entryPath);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
validEntityOccurrences.add(key);
|
|
345
|
+
const entry = entities[key] as unknown;
|
|
346
|
+
if (!isRecord(entry)) {
|
|
347
|
+
diagnostics.push(shapeMismatch(entryPath));
|
|
348
|
+
shapeFailed.add(entryPath);
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const allowed = new Set(["form", "text", "icon", "categoryRef"]);
|
|
352
|
+
for (const field of Object.keys(entry)) {
|
|
353
|
+
if (!allowed.has(field)) {
|
|
354
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.\${field}\`));
|
|
355
|
+
shapeFailed.add(\`\${entryPath}.\${field}\`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (entry["form"] === undefined || entry["text"] === undefined) {
|
|
359
|
+
if (entry["form"] === undefined) {
|
|
360
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.form\`));
|
|
361
|
+
shapeFailed.add(\`\${entryPath}.form\`);
|
|
362
|
+
}
|
|
363
|
+
if (entry["text"] === undefined) {
|
|
364
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.text\`));
|
|
365
|
+
shapeFailed.add(\`\${entryPath}.text\`);
|
|
366
|
+
}
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (
|
|
370
|
+
entry["form"] !== "card" &&
|
|
371
|
+
entry["form"] !== "container" &&
|
|
372
|
+
entry["form"] !== "legend" &&
|
|
373
|
+
entry["form"] !== "legend-key"
|
|
374
|
+
) {
|
|
375
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.form\`));
|
|
376
|
+
shapeFailed.add(\`\${entryPath}.form\`);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const textValue = entry["text"] as unknown;
|
|
380
|
+
if (!isRecord(textValue)) {
|
|
381
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.text\`));
|
|
382
|
+
shapeFailed.add(\`\${entryPath}.text\`);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const allowedText = new Set(["title", "kicker", "body", "detail", "subtitle", "footer"]);
|
|
386
|
+
for (const slot of Object.keys(textValue)) {
|
|
387
|
+
if (!allowedText.has(slot)) {
|
|
388
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.text.\${slot}\`));
|
|
389
|
+
shapeFailed.add(\`\${entryPath}.text.\${slot}\`);
|
|
390
|
+
} else if (typeof textValue[slot] !== "string") {
|
|
391
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.text.\${slot}\`));
|
|
392
|
+
shapeFailed.add(\`\${entryPath}.text.\${slot}\`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (entry["icon"] !== undefined && typeof entry["icon"] !== "string") {
|
|
396
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.icon\`));
|
|
397
|
+
shapeFailed.add(\`\${entryPath}.icon\`);
|
|
398
|
+
}
|
|
399
|
+
if (entry["categoryRef"] !== undefined && typeof entry["categoryRef"] !== "string") {
|
|
400
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.categoryRef\`));
|
|
401
|
+
shapeFailed.add(\`\${entryPath}.categoryRef\`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
for (const key of Object.keys(legends).sort()) {
|
|
406
|
+
const entryPath = \`presentation.diagram.legends.\${key}\`;
|
|
407
|
+
if (refKindOf(key) !== "occurrence") {
|
|
408
|
+
diagnostics.push(wrongNamespacePresentation(entryPath, key, "occurrence"));
|
|
409
|
+
shapeFailed.add(entryPath);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (view.entityOccurrences[key] === undefined) {
|
|
413
|
+
diagnostics.push(danglingPresentation(entryPath, key));
|
|
414
|
+
shapeFailed.add(entryPath);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
const entry = legends[key] as unknown;
|
|
418
|
+
if (!isRecord(entry)) {
|
|
419
|
+
diagnostics.push(shapeMismatch(entryPath));
|
|
420
|
+
shapeFailed.add(entryPath);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
for (const field of Object.keys(entry)) {
|
|
424
|
+
if (field !== "order") {
|
|
425
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.\${field}\`));
|
|
426
|
+
shapeFailed.add(\`\${entryPath}.\${field}\`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (entry["order"] === undefined) {
|
|
430
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.order\`));
|
|
431
|
+
shapeFailed.add(\`\${entryPath}.order\`);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (!Array.isArray(entry["order"])) {
|
|
435
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.order\`));
|
|
436
|
+
shapeFailed.add(\`\${entryPath}.order\`);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const order = entry["order"] as readonly unknown[];
|
|
440
|
+
let orderShapeBad = false;
|
|
441
|
+
order.forEach((item, index) => {
|
|
442
|
+
if (typeof item !== "string") {
|
|
443
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.order[\${index}]\`));
|
|
444
|
+
shapeFailed.add(\`\${entryPath}.order\`);
|
|
445
|
+
orderShapeBad = true;
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
if (orderShapeBad) continue;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
categoryTokens.forEach((item, index) => {
|
|
452
|
+
const itemPath = \`presentation.diagram.categoryTokens[\${index}]\`;
|
|
453
|
+
if (!isRecord(item)) {
|
|
454
|
+
diagnostics.push(shapeMismatch(itemPath));
|
|
455
|
+
shapeFailed.add(itemPath);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const allowed = new Set(["legendRef", "category", "token"]);
|
|
459
|
+
for (const field of Object.keys(item)) {
|
|
460
|
+
if (!allowed.has(field)) {
|
|
461
|
+
diagnostics.push(shapeMismatch(\`\${itemPath}.\${field}\`));
|
|
462
|
+
shapeFailed.add(\`\${itemPath}.\${field}\`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
for (const required of ["legendRef", "category", "token"]) {
|
|
466
|
+
if (item[required] === undefined) {
|
|
467
|
+
diagnostics.push(shapeMismatch(\`\${itemPath}.\${required}\`));
|
|
468
|
+
shapeFailed.add(\`\${itemPath}.\${required}\`);
|
|
469
|
+
} else if (typeof item[required] !== "string") {
|
|
470
|
+
diagnostics.push(shapeMismatch(\`\${itemPath}.\${required}\`));
|
|
471
|
+
shapeFailed.add(\`\${itemPath}.\${required}\`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
if (diagnostics.some((entry) => entry.details !== undefined && (entry.details as Record<string, unknown>)["check"] === "presentation-shape-invalid")) {
|
|
477
|
+
const onlyShape = diagnostics.filter(
|
|
478
|
+
(entry) => (entry.details as Record<string, unknown> | undefined)?.["check"] === "presentation-shape-invalid",
|
|
479
|
+
);
|
|
480
|
+
if (diagnostics.length > 0 && onlyShape.length > 0 && shapeFailed.size > 0) {
|
|
481
|
+
return onlyShape;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
for (const key of Object.keys(entities).sort()) {
|
|
486
|
+
if (shapeFailed.has(\`presentation.diagram.entities.\${key}\`)) continue;
|
|
487
|
+
if (!validEntityOccurrences.has(key)) continue;
|
|
488
|
+
const entry = entities[key] as { form: string; text: Record<string, string>; icon?: string };
|
|
489
|
+
const entryPath = \`presentation.diagram.entities.\${key}\`;
|
|
490
|
+
const occurrence = view.entityOccurrences[key];
|
|
491
|
+
if (occurrence === undefined) continue;
|
|
492
|
+
const semantic = document.entities[occurrence.entity];
|
|
493
|
+
if (semantic === undefined) continue;
|
|
494
|
+
const owner = registry.get(semantic.profile as never);
|
|
495
|
+
if (owner === undefined) continue;
|
|
496
|
+
const resolution = resolver.resolve(owner, semantic.type);
|
|
497
|
+
if (!resolution.ok) continue;
|
|
498
|
+
const ancestry = resolution.resolved.ancestry;
|
|
499
|
+
const container = resolution.resolved.container;
|
|
500
|
+
if (!satisfiesExplicitForm(entry.form, owner.id, ancestry, container)) {
|
|
501
|
+
diagnostics.push(formMismatch(\`\${entryPath}.form\`));
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
const textValue = entry.text as Record<string, string>;
|
|
505
|
+
const maxFor = (slot: string): number => {
|
|
506
|
+
if (slot === "title") return entry.form === "legend-key" ? 120 : 200;
|
|
507
|
+
if (slot === "kicker") return 80;
|
|
508
|
+
if (slot === "body" || slot === "detail") return 400;
|
|
509
|
+
if (slot === "subtitle") return 600;
|
|
510
|
+
return 120;
|
|
511
|
+
};
|
|
512
|
+
for (const slot of Object.keys(textValue).sort()) {
|
|
513
|
+
const value = textValue[slot] as string;
|
|
514
|
+
if (typeof value !== "string") continue;
|
|
515
|
+
if ((entry.form === "card" || entry.form === "legend-key") && slot === "subtitle") {
|
|
516
|
+
diagnostics.push(shapeMismatch(\`\${entryPath}.text.\${slot}\`));
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
const max = maxFor(slot);
|
|
520
|
+
if ([...value].length > max) {
|
|
521
|
+
diagnostics.push(textTooLong(\`\${entryPath}.text.\${slot}\`, [...value].length, max));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (typeof entry.icon === "string") {
|
|
525
|
+
const length = [...entry.icon].length;
|
|
526
|
+
if (length > 40) {
|
|
527
|
+
diagnostics.push(textTooLong(\`\${entryPath}.icon\`, length, 40));
|
|
528
|
+
} else if (length < 1) {
|
|
529
|
+
diagnostics.push(minLengthMismatch(\`\${entryPath}.icon\`, "icon", length, 1));
|
|
530
|
+
} else if (!KEY_PATTERN.test(entry.icon)) {
|
|
531
|
+
diagnostics.push(patternMismatch(\`\${entryPath}.icon\`, "key", length, 40));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
categoryTokens.forEach((item, index) => {
|
|
537
|
+
const itemPath = \`presentation.diagram.categoryTokens[\${index}]\`;
|
|
538
|
+
if (shapeFailed.has(itemPath)) return;
|
|
539
|
+
const typed = item as { legendRef: string; category: string; token: string };
|
|
540
|
+
if (typeof typed.legendRef !== "string" || typeof typed.category !== "string" || typeof typed.token !== "string") {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (refKindOf(typed.legendRef) !== "entity") {
|
|
544
|
+
diagnostics.push(wrongNamespacePresentation(\`\${itemPath}.legendRef\`, typed.legendRef, "entity"));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const target = document.entities[typed.legendRef];
|
|
548
|
+
if (target === undefined) {
|
|
549
|
+
diagnostics.push(danglingPresentation(\`\${itemPath}.legendRef\`, typed.legendRef));
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (!isGeneric2Legend(document, registry, resolver, typed.legendRef)) {
|
|
553
|
+
diagnostics.push({
|
|
554
|
+
code: "tone-category-unknown",
|
|
555
|
+
severity: "error",
|
|
556
|
+
path: \`\${itemPath}.legendRef\`,
|
|
557
|
+
message: \`legendRef names \${typed.legendRef}, which is not a legend\`,
|
|
558
|
+
refs: [typed.legendRef],
|
|
559
|
+
details: {
|
|
560
|
+
value: typed.category,
|
|
561
|
+
legendBinding: "bound-target-not-legend",
|
|
562
|
+
categoryType: "legend-key",
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const categoryLength = [...typed.category].length;
|
|
568
|
+
if (typed.category.length === 0 || categoryLength > 40 || !KEY_PATTERN.test(typed.category)) {
|
|
569
|
+
if (categoryLength > 40) {
|
|
570
|
+
diagnostics.push(textTooLong(\`\${itemPath}.category\`, categoryLength, 40));
|
|
571
|
+
} else if (categoryLength < 1) {
|
|
572
|
+
diagnostics.push(minLengthMismatch(\`\${itemPath}.category\`, "category", categoryLength, 1));
|
|
573
|
+
} else {
|
|
574
|
+
diagnostics.push(patternMismatch(\`\${itemPath}.category\`, "key", categoryLength, 40));
|
|
575
|
+
}
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const tokenLength = [...typed.token].length;
|
|
579
|
+
if (tokenLength > 80) {
|
|
580
|
+
diagnostics.push(textTooLong(\`\${itemPath}.token\`, tokenLength, 80));
|
|
581
|
+
} else if (tokenLength < 1) {
|
|
582
|
+
diagnostics.push(minLengthMismatch(\`\${itemPath}.token\`, "token", tokenLength, 1));
|
|
583
|
+
} else if (!TOKEN_PATTERN.test(typed.token)) {
|
|
584
|
+
diagnostics.push(patternMismatch(\`\${itemPath}.token\`, "token-name", tokenLength, 80));
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
const seenBindings = new Map<string, number>();
|
|
589
|
+
categoryTokens.forEach((item, index) => {
|
|
590
|
+
const typed = item as { legendRef?: unknown; category?: unknown };
|
|
591
|
+
if (typeof typed.legendRef !== "string" || typeof typed.category !== "string") return;
|
|
592
|
+
const key = \`\${typed.legendRef}\\n\${typed.category}\`;
|
|
593
|
+
if (seenBindings.has(key)) {
|
|
594
|
+
diagnostics.push(tokenConflict(\`presentation.diagram.categoryTokens[\${index}]\`));
|
|
595
|
+
} else {
|
|
596
|
+
seenBindings.set(key, index);
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
for (const key of Object.keys(entities).sort()) {
|
|
601
|
+
if (shapeFailed.has(\`presentation.diagram.entities.\${key}\`)) continue;
|
|
602
|
+
if (!validEntityOccurrences.has(key)) continue;
|
|
603
|
+
const entry = entities[key] as { categoryRef?: unknown };
|
|
604
|
+
const entryPath = \`presentation.diagram.entities.\${key}.categoryRef\`;
|
|
605
|
+
if (entry.categoryRef === undefined) continue;
|
|
606
|
+
if (typeof entry.categoryRef !== "string") continue;
|
|
607
|
+
const targetId = entry.categoryRef as string;
|
|
608
|
+
if (refKindOf(targetId) !== "entity") {
|
|
609
|
+
diagnostics.push(wrongNamespacePresentation(entryPath, targetId, "entity"));
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (document.entities[targetId] === undefined) {
|
|
613
|
+
diagnostics.push(danglingPresentation(entryPath, targetId));
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (!isGeneric2Key(document, registry, resolver, targetId)) {
|
|
617
|
+
diagnostics.push(wrongNamespacePresentation(entryPath, targetId, "legend-key"));
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
void hierarchyChildren;
|
|
622
|
+
|
|
623
|
+
const legendChildren = new Map<string, string[]>();
|
|
624
|
+
const buildLegendChildren = (): void => {
|
|
625
|
+
if (legendChildren.size > 0) return;
|
|
626
|
+
const hierarchyIds = familySets.legendHierarchyIds;
|
|
627
|
+
if (hierarchyIds.size === 0) return;
|
|
628
|
+
for (const profileId of document.profileRefs) {
|
|
629
|
+
if (profileId !== GENERIC2_PROFILE_ID) continue;
|
|
630
|
+
const profile = registry.get(profileId as never);
|
|
631
|
+
if (profile === undefined) continue;
|
|
632
|
+
const declarations = profile.relationTypes.filter((declaration) =>
|
|
633
|
+
declaration.hierarchy !== undefined && hierarchyIds.has(declaration.hierarchy.id),
|
|
634
|
+
);
|
|
635
|
+
for (const declaration of declarations) {
|
|
636
|
+
const hierarchy = declaration.hierarchy as { parentRole: string; childRole: string };
|
|
637
|
+
for (const relation of Object.values(document.relations)) {
|
|
638
|
+
if (relation.profile !== profile.id || relation.type !== declaration.id) continue;
|
|
639
|
+
const parents = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.parentRole);
|
|
640
|
+
const kids = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.childRole);
|
|
641
|
+
for (const parent of parents) {
|
|
642
|
+
if (refKindOf(parent.target) !== "entity") continue;
|
|
643
|
+
for (const kid of kids) {
|
|
644
|
+
if (refKindOf(kid.target) !== "entity") continue;
|
|
645
|
+
legendChildren.set(parent.target, [...(legendChildren.get(parent.target) ?? []), kid.target]);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
for (const kids of legendChildren.values()) kids.sort();
|
|
652
|
+
};
|
|
653
|
+
buildLegendChildren();
|
|
654
|
+
|
|
655
|
+
const directKeysOf = (legendEntityId: string): string[] => {
|
|
656
|
+
if (!isGeneric2Legend(document, registry, resolver, legendEntityId)) return [];
|
|
657
|
+
const kids = legendChildren.get(legendEntityId) ?? [];
|
|
658
|
+
return kids.filter((kid) => isGeneric2Key(document, registry, resolver, kid));
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
const isLegendEntity = (entityId: string): boolean =>
|
|
662
|
+
isGeneric2Legend(document, registry, resolver, entityId);
|
|
663
|
+
|
|
664
|
+
categoryTokens.forEach((item, index) => {
|
|
665
|
+
const itemPath = \`presentation.diagram.categoryTokens[\${index}]\`;
|
|
666
|
+
if (shapeFailed.has(itemPath)) return;
|
|
667
|
+
const typed = item as { legendRef?: unknown; category?: unknown; token?: unknown };
|
|
668
|
+
if (typeof typed.legendRef !== "string" || typeof typed.category !== "string" || typeof typed.token !== "string") {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (refKindOf(typed.legendRef) !== "entity") return;
|
|
672
|
+
if (document.entities[typed.legendRef] === undefined) return;
|
|
673
|
+
if (!isGeneric2Legend(document, registry, resolver, typed.legendRef)) return;
|
|
674
|
+
const categoryLength = [...typed.category].length;
|
|
675
|
+
if (typed.category.length === 0 || categoryLength > 40 || !KEY_PATTERN.test(typed.category)) return;
|
|
676
|
+
const tokenValue = typed.token;
|
|
677
|
+
if (typeof tokenValue !== "string") return;
|
|
678
|
+
const tokenLength = [...tokenValue].length;
|
|
679
|
+
if (tokenLength < 1 || tokenLength > 80 || !TOKEN_PATTERN.test(tokenValue)) return;
|
|
680
|
+
const direct = directKeysOf(typed.legendRef);
|
|
681
|
+
const categories = new Set<string>();
|
|
682
|
+
for (const kid of direct) {
|
|
683
|
+
const keyEntity = document.entities[kid];
|
|
684
|
+
if (keyEntity === undefined) continue;
|
|
685
|
+
const keyValue = keyEntity.attributes["category"];
|
|
686
|
+
if (keyValue !== undefined && keyValue.kind === "text") {
|
|
687
|
+
const value = (keyValue as { value: string }).value;
|
|
688
|
+
if (typeof value === "string") categories.add(value);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (!categories.has(typed.category)) {
|
|
692
|
+
diagnostics.push({
|
|
693
|
+
code: "tone-category-unknown",
|
|
694
|
+
severity: "error",
|
|
695
|
+
path: \`\${itemPath}.category\`,
|
|
696
|
+
message: \`category \${typed.category} is not a direct key category of legend \${typed.legendRef}\`,
|
|
697
|
+
refs: [typed.legendRef],
|
|
698
|
+
details: { value: typed.category, legendBinding: "undeclared", categoryType: "legend-key" },
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
for (const key of Object.keys(entities).sort()) {
|
|
704
|
+
if (shapeFailed.has(\`presentation.diagram.entities.\${key}\`)) continue;
|
|
705
|
+
if (!validEntityOccurrences.has(key)) continue;
|
|
706
|
+
const entry = entities[key] as { categoryRef?: string };
|
|
707
|
+
if (entry.categoryRef !== undefined) continue;
|
|
708
|
+
const occurrence = view.entityOccurrences[key];
|
|
709
|
+
if (occurrence === undefined) continue;
|
|
710
|
+
const semantic = document.entities[occurrence.entity];
|
|
711
|
+
if (semantic === undefined) continue;
|
|
712
|
+
const owner = registry.get(semantic.profile as never);
|
|
713
|
+
if (owner === undefined) continue;
|
|
714
|
+
const resolution = resolver.resolve(owner, semantic.type);
|
|
715
|
+
if (!resolution.ok) continue;
|
|
716
|
+
const ancestry = resolution.resolved.ancestry;
|
|
717
|
+
const isKeyType = owner.id === GENERIC2_PROFILE_ID && ancestry.includes("legend-key");
|
|
718
|
+
const isLegendType = owner.id === GENERIC2_PROFILE_ID && ancestry.includes("legend");
|
|
719
|
+
if (isKeyType || isLegendType) continue;
|
|
720
|
+
const schemas = resolution.resolved.schemas;
|
|
721
|
+
const categorySchema = schemas.find((schema) => schema.name === "category");
|
|
722
|
+
if (categorySchema === undefined || categorySchema.kind !== "text") continue;
|
|
723
|
+
const value = semantic.attributes["category"];
|
|
724
|
+
if (value === undefined || value.kind !== "text") continue;
|
|
725
|
+
const category = (value as { value: string }).value;
|
|
726
|
+
if (typeof category !== "string" || category.length === 0) continue;
|
|
727
|
+
const matchingLegends: string[] = [];
|
|
728
|
+
for (const entityId of Object.keys(document.entities).sort()) {
|
|
729
|
+
if (!isLegendEntity(entityId)) continue;
|
|
730
|
+
const keys = directKeysOf(entityId);
|
|
731
|
+
for (const kid of keys) {
|
|
732
|
+
const keyEntity = document.entities[kid];
|
|
733
|
+
if (keyEntity === undefined) continue;
|
|
734
|
+
const keyValue = keyEntity.attributes["category"];
|
|
735
|
+
if (keyValue !== undefined && keyValue.kind === "text" && (keyValue as { value: string }).value === category) {
|
|
736
|
+
matchingLegends.push(entityId);
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (matchingLegends.length === 0) {
|
|
742
|
+
diagnostics.push({
|
|
743
|
+
code: "tone-category-unknown",
|
|
744
|
+
severity: "error",
|
|
745
|
+
path: \`presentation.diagram.entities.\${key}.categoryRef\`,
|
|
746
|
+
message: \`category \${category} on occurrence \${key} is not declared by any legend in this document\`,
|
|
747
|
+
refs: [key],
|
|
748
|
+
details: { value: category, legendBinding: "undeclared", categoryType: "legend-key" },
|
|
749
|
+
});
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
const tokens = new Set<string>();
|
|
753
|
+
for (const legendId of matchingLegends) {
|
|
754
|
+
for (const [index, item] of (categoryTokens as readonly unknown[]).entries()) {
|
|
755
|
+
void index;
|
|
756
|
+
const typed = item as { legendRef: string; category: string; token: string };
|
|
757
|
+
if (typed.legendRef === legendId && typed.category === category && typeof typed.token === "string") {
|
|
758
|
+
tokens.add(typed.token);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (tokens.size === 0) {
|
|
763
|
+
diagnostics.push({
|
|
764
|
+
code: "tone-category-unknown",
|
|
765
|
+
severity: "error",
|
|
766
|
+
path: \`presentation.diagram.entities.\${key}.categoryRef\`,
|
|
767
|
+
message: \`category \${category} on occurrence \${key} is not declared by any legend in this document\`,
|
|
768
|
+
refs: [key],
|
|
769
|
+
details: { value: category, legendBinding: "undeclared", categoryType: "legend-key" },
|
|
770
|
+
});
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (tokens.size > 1) {
|
|
774
|
+
diagnostics.push({
|
|
775
|
+
code: "tone-category-unknown",
|
|
776
|
+
severity: "error",
|
|
777
|
+
path: \`presentation.diagram.entities.\${key}.categoryRef\`,
|
|
778
|
+
message: \`category \${category} on occurrence \${key} resolves ambiguously across legends; set categoryRef to bind it\`,
|
|
779
|
+
refs: [key],
|
|
780
|
+
details: { value: category, legendBinding: "ambiguous", categoryType: "legend-key" },
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
for (const key of Object.keys(legends).sort()) {
|
|
786
|
+
const entryPath = \`presentation.diagram.legends.\${key}.order\`;
|
|
787
|
+
const entryKeyPath = \`presentation.diagram.legends.\${key}\`;
|
|
788
|
+
if (shapeFailed.has(entryPath) || shapeFailed.has(entryKeyPath)) continue;
|
|
789
|
+
const occurrence = view.entityOccurrences[key];
|
|
790
|
+
if (occurrence === undefined) continue;
|
|
791
|
+
const semantic = document.entities[occurrence.entity];
|
|
792
|
+
if (semantic === undefined) continue;
|
|
793
|
+
if (!isGeneric2Legend(document, registry, resolver, semantic.id)) {
|
|
794
|
+
diagnostics.push(formMismatch(entryKeyPath));
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
const entry = legends[key] as { order: readonly unknown[] };
|
|
798
|
+
const actual = (entry.order ?? []) as readonly unknown[];
|
|
799
|
+
let referencesOk = true;
|
|
800
|
+
actual.forEach((item, index) => {
|
|
801
|
+
if (typeof item !== "string") return;
|
|
802
|
+
const itemPath = \`\${entryPath}[\${index}]\`;
|
|
803
|
+
if (refKindOf(item) !== "entity") {
|
|
804
|
+
diagnostics.push(wrongNamespacePresentation(itemPath, item, "entity"));
|
|
805
|
+
referencesOk = false;
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (document.entities[item] === undefined) {
|
|
809
|
+
diagnostics.push(danglingPresentation(itemPath, item));
|
|
810
|
+
referencesOk = false;
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
if (!referencesOk) continue;
|
|
814
|
+
const expected = directKeysOf(semantic.id).slice().sort();
|
|
815
|
+
const actualStrings = actual.filter((item): item is string => typeof item === "string");
|
|
816
|
+
const actualSorted = [...actualStrings].sort();
|
|
817
|
+
const uniqueActual = new Set(actualStrings);
|
|
818
|
+
if (
|
|
819
|
+
uniqueActual.size !== actualStrings.length ||
|
|
820
|
+
actualSorted.length !== expected.length ||
|
|
821
|
+
actualSorted.some((value, index) => value !== expected[index])
|
|
822
|
+
) {
|
|
823
|
+
diagnostics.push(orderMismatch(entryPath));
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return diagnostics;
|
|
828
|
+
}
|
|
829
|
+
`;function gi(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;let t=e;for(let e of Object.keys(t)){let n=t[e];typeof n==`object`&&n&&gi(n)}return Object.freeze(e)}var _i={format:`sentropic.registry-entry/v1`,contractVersion:`1.1.4`,kind:`ontology`,id:`engram-diagram-presentation-1`,name:`diagram-presentation@1`,description:`Governed typed presentation contract (S1 draft).`,entryVersion:`1`,publisher:{packageName:`engram-diagram-lot`,packageVersion:`0.1.0`},compatibility:{entryContract:`1.1.4`,packages:[],schemaProfiles:[`diagram-presentation-schema/1`],requiredHostFeatures:[`ontology-descriptors`],optionalHostFeatures:[]},parameters:{schemaVersion:`1`,schema:{$ref:`engram:diagram-presentation-schema`},defaults:{}},bindings:[{key:`profile`,contract:`engram:diagram-profile/1#sha256=60e3997a1f67259219eb8a7a9aa5ab8da4c89b85fe19b96e67326bc7fd386a2a`,required:!0}],assets:[{role:`profile-data`,path:`contracts/diagram-presentation-1.json`,mediaType:`application/json`,sha256:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`}],ontology:{canonicalRef:`engram:diagram-presentation@1`,namespace:`diagram`,owner:`engram`,profileShape:`mechanism-descriptor`,artifactKind:`contract`,profilePin:{id:`diagram-presentation`,version:`1`,contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`},stack:[{id:`diagram-presentation`,version:`1`,contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`}],digests:{contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`,pinsDigest:`9be4a5ef9dcffa7697ffd3f279d2b062cff799ab36814a80c4371d7cebc41a80`,resultEvidence:{evidenceState:`unresolved`}},ruleSheets:[],lifecycle:`draft`,provenance:{sourceRef:`m3/SPEC_EVOL_GD_M3_DIAGRAM_MODEL-FROZEN-deb64b75.md`,sourceRevision:`deb64b75e884bfefbdd97de698c899805568271ea1fc521fffe02cbc20288c2f`},lineage:{parents:[],mappings:[],migrations:[]},conflictPolicy:`engram:g0-conflicts@1`,completeness:`complete`,corpusRef:{ref:`engram:diagram-lot-corpus/1`,digest:`e946288de536075611c25e7b5e6078ea3def433b66d7a6ea60c1eb20cfebcf6e`},receipts:[],migrations:[],consumers:[],compatibility:{renderer:`transitional:ds-diagram-core-executor-unqualified`,adapter:`transitional:ds-schema-adapter-unqualified`},visibility:`public`,linkedTools:[],artifactBinding:{artifactKind:`contract`,schemaPin:{id:`diagram-presentation-schema`,version:`1`,contentDigest:`f13d595793e17e1e4740c9203b19d8381fc55b90e37121d61f5037cb79f0281a`},compatibilityMatrixVersion:`1`}}},vi={format:`sentropic.registry-entry/v1`,contractVersion:`1.1.4`,kind:`ontology`,id:`engram-diagram-presentation-2`,name:`diagram-presentation@1`,description:`Governed typed presentation contract with qualified DS adapter/renderer refs (entry revision 2; revises entry 1).`,entryVersion:`2`,publisher:{packageName:`engram-diagram-lot`,packageVersion:`0.1.0`},compatibility:{entryContract:`1.1.4`,packages:[],schemaProfiles:[`diagram-presentation-schema/1`],requiredHostFeatures:[`ontology-descriptors`],optionalHostFeatures:[]},parameters:{schemaVersion:`1`,schema:{$ref:`engram:diagram-presentation-schema`},defaults:{}},bindings:[{key:`profile`,contract:`engram:diagram-profile/1#sha256=60e3997a1f67259219eb8a7a9aa5ab8da4c89b85fe19b96e67326bc7fd386a2a`,required:!0}],assets:[{role:`profile-data`,path:`contracts/diagram-presentation-1.json`,mediaType:`application/json`,sha256:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`}],ontology:{canonicalRef:`engram:diagram-presentation@1`,namespace:`diagram`,owner:`engram`,profileShape:`mechanism-descriptor`,artifactKind:`contract`,profilePin:{id:`diagram-presentation`,version:`1`,contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`},stack:[{id:`diagram-presentation`,version:`1`,contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`}],digests:{contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`,pinsDigest:`9be4a5ef9dcffa7697ffd3f279d2b062cff799ab36814a80c4371d7cebc41a80`,resultEvidence:{evidenceState:`unresolved`}},ruleSheets:[],lifecycle:`draft`,provenance:{sourceRef:`m3/SPEC_EVOL_GD_M3_DIAGRAM_MODEL-FROZEN-deb64b75.md`,sourceRevision:`deb64b75e884bfefbdd97de698c899805568271ea1fc521fffe02cbc20288c2f`},lineage:{parents:[],mappings:[],migrations:[]},conflictPolicy:`engram:g0-conflicts@1`,completeness:`complete`,corpusRef:{ref:`engram:diagram-lot-corpus/1`,digest:`e946288de536075611c25e7b5e6078ea3def433b66d7a6ea60c1eb20cfebcf6e`},receipts:[],migrations:[],consumers:[],compatibility:{renderer:`ds:rhanka/sent-tech-design-system/packages/diagram-core/src/presentation-apply.ts@ab7d1a7fd0142217672b5be6d40465b3e5309e50#sha256=28c3607e5c4868d44c137b66fe8e6f6ed99cb578fc52a52f67442cca41802cd8`,adapter:`ds:rhanka/sent-tech-design-system/packages/diagram-core/src/presentation-validate.ts@ab7d1a7fd0142217672b5be6d40465b3e5309e50#sha256=488d8499b8f4e624af56d0c4f4c07496cc09863ec1e65e9f522c6fc05a4db06e`},visibility:`public`,linkedTools:[],artifactBinding:{artifactKind:`contract`,schemaPin:{id:`diagram-presentation-schema`,version:`1`,contentDigest:`f13d595793e17e1e4740c9203b19d8381fc55b90e37121d61f5037cb79f0281a`},compatibilityMatrixVersion:`1`}}},yi={compatibilityAdapter:vi.ontology.compatibility.adapter,adapterBytes:hi,schemaPin:vi.ontology.artifactBinding.schemaPin,entry:vi,predecessor:_i,revision:{successor:{id:`engram-diagram-presentation-2`,entryVersion:`2`},predecessor:{id:`engram-diagram-presentation-1`,entryVersion:`1`,entryDigest:`a83e2c1d0ea9612d38a0b3ad1a0f0ae4e93e7f7a10fcee49ab57a6a06659da0a`}}};gi(yi);function bi(){return yi}function xi(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(e=>xi(e));let t=e,n={};for(let e of Object.keys(t))n[e]=xi(t[e]);return n}function Si(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;let t=e;for(let e of Object.keys(t)){let n=t[e];typeof n==`object`&&n&&Si(n)}return Object.freeze(e)}function Ci(e){return Si(xi(e))}var wi={type:`string`,minLength:1,maxLength:40,pattern:`^[a-z][a-z0-9-]*$`},Ti={type:`string`,minLength:1,maxLength:80,pattern:`^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$`},Ei={type:`object`,properties:{form:{enum:[`card`,`container`,`legend`,`legend-key`]},text:{type:`object`,properties:{title:{type:`string`,maxLength:200},kicker:{type:`string`,maxLength:80},body:{type:`string`,maxLength:400},detail:{type:`string`,maxLength:400},subtitle:{type:`string`,maxLength:600},footer:{type:`string`,maxLength:120}},additionalProperties:!1},icon:{type:`string`,minLength:1,maxLength:40,pattern:`^[a-z][a-z0-9-]*$`},categoryRef:{type:`string`,minLength:1}},required:[`form`,`text`],additionalProperties:!1,allOf:[{if:{properties:{form:{const:`legend-key`}},required:[`form`]},then:{properties:{text:{type:`object`,properties:{title:{type:`string`,maxLength:120}}}}}}]},Di={contractPin:{type:`object`,properties:{id:{const:`diagram-presentation`},version:{const:`1`},contentDigest:{type:`string`,pattern:`^[0-9a-f]{64}$`}},required:[`id`,`version`,`contentDigest`],additionalProperties:!1},entities:{type:`object`,additionalProperties:Ei},legends:{type:`object`,additionalProperties:{type:`object`,properties:{order:{type:`array`,items:{type:`string`,minLength:1},uniqueItems:!0}},required:[`order`],additionalProperties:!1}},categoryTokens:{type:`array`,items:{type:`object`,properties:{legendRef:{type:`string`,minLength:1},category:wi,token:Ti},required:[`legendRef`,`category`,`token`],additionalProperties:!1}}},Oi=[`contractPin`,`entities`,`legends`,`categoryTokens`],ki={$schema:`https://json-schema.org/draft/2020-12/schema`,$id:`engram:diagram-presentation-schema/1`,title:`diagram-presentation@1 contract`,type:`object`,properties:Di,required:[...Oi],additionalProperties:!1};Si(ki),Ci(ki);var Ai={id:`diagram-presentation-schema`,version:`1`,contentDigest:un(on(ki))};Si(Ai),Ci(Ai);var ji=`diagram-presentation@1`,Mi=`mechanism-descriptor`,Ni=`contract`,Pi={id:ji,artifactKind:Ni,schemaPin:{...Ai},compatibilityMatrixVersion:`1`};Si(Pi),Ci(Pi);var Fi=un(on(Pi)),Ii={id:`diagram-presentation`,version:`1`,contentDigest:Fi};Si(Ii),Ci(Ii);var Li={artifactKind:`contract`,schemaPin:{...Ai},compatibilityMatrixVersion:`1`};Si(Li),Ci(Li);var Ri=`engram:diagram-lot-corpus/1`,zi=`e946288de536075611c25e7b5e6078ea3def433b66d7a6ea60c1eb20cfebcf6e`;function Bi(e){return un(on({deltaDigest:null,layers:e.map(e=>({contentDigest:e.contentDigest,id:e.id,version:e.version})),mappingDigest:null,ruleSheets:[]}))}var Vi=Bi([Ii]),Hi={namespace:`diagram`,id:`diagram-presentation`,version:`1`,owner:`engram`,lifecycle:`draft`,completeness:`complete`,visibility:`public`,profileShape:Mi,artifactKind:Ni,profileRef:{canonicalRef:`engram:diagram-presentation@1`,contentDigest:Fi},corpusRef:{ref:Ri,digest:zi},digests:{contentDigest:Fi,pinsDigest:Vi,resultEvidence:{evidenceState:`unresolved`}},lineage:{parents:[],mappings:[],migrations:[]},consumers:[]};Si(Hi),Ci(Hi),Ci(bi().entry.ontology.compatibility);var Ui={compatibilityAdapter:bi().compatibilityAdapter,adapterBytes:bi().adapterBytes,schemaPin:{...bi().schemaPin}};Si(Ui),Ci(Ui);var Wi={...Ei,properties:{...Ei.properties,align:{enum:[`left`,`center`]}}},Gi={$schema:`https://json-schema.org/draft/2020-12/schema`,$id:`engram:diagram-presentation-schema/2`,title:`diagram-presentation@2 contract`,type:`object`,properties:{...Di,contractPin:{type:`object`,properties:{id:{const:`diagram-presentation`},version:{const:`2`},contentDigest:{type:`string`,pattern:`^[0-9a-f]{64}$`}},required:[`id`,`version`,`contentDigest`],additionalProperties:!1},entities:{type:`object`,additionalProperties:Wi}},required:[...Oi],additionalProperties:!1};Si(Gi),Ci(Gi);var Ki={id:`diagram-presentation-schema`,version:`2`,contentDigest:un(on(Gi))};Si(Ki),Ci(Ki);var qi={id:`diagram-presentation@2`,artifactKind:Ni,schemaPin:{...Ki},compatibilityMatrixVersion:`2`};Si(qi),Ci(qi);var Ji={id:`diagram-presentation`,version:`2`,contentDigest:un(on(qi))};Si(Ji),Ci(Ji);function Yi(e){return e===`diagram-presentation@1`||e===`diagram-presentation@2`}function Xi(e){return e.id===Ji.id&&e.version===Ji.version&&e.contentDigest===Ji.contentDigest}function Zi(e,t){let n=e.entityOccurrences[t];if(n===void 0||n.group===void 0)return;let r=e.groups[n.group]?.occurrence;if(r!==void 0&&e.entityOccurrences[r]!==void 0)return r}function Qi(e,t){let n=[],r=new Set,i=t;for(;i!==void 0&&!r.has(i);)r.add(i),n.push(i),i=Zi(e,i);return n}function $i(e,t,n){let r=e.portOccurrences[n];return r===void 0?e.entityOccurrences[n]!==void 0&&Qi(e,n).slice(1).some(e=>t.has(e)):$i(e,t,r.ownerOccurrence)}function ea(e,t,n){let r=Qi(e,n).filter(e=>t.has(e));return r.length===0?n:r[r.length-1]}function ta(e,t,n,r){let i=e.portOccurrences[r];if(i===void 0)return r;let a=ea(e,n,i.ownerOccurrence);if(i.ownerOccurrence===a&&n.has(a)&&t.ports[i.port]?.profile===`erd@1`)return a;let o=e.entityOccurrences[a]?.entity,s=t.ports[i.port],c=Object.values(e.portOccurrences).filter(e=>{if(e.ownerOccurrence!==a)return!1;let n=t.ports[e.port];return n===void 0||s===void 0||n.owner!==o?!1:n.direction===s.direction});return c.length===1?c[0].id:a}function na(e,t){let n=e.entityOccurrences[t];if(n!==void 0)return n.entity;let r=e.portOccurrences[t];if(r!==void 0)return r.port;let i=e.relationOccurrences[t];if(i!==void 0)return i.relation}function ra(e,t,n,r){let i=e.relations[t];if(i!==void 0)return i.endpoints.find(e=>e.role===n&&e.target===r)?.target}function ia(e,t,n){let r=new Map,i=!0;for(;i;){i=!1;let a=new Map(r),o=r=>e.relationOccurrences[r]===void 0?e.portOccurrences[r]===void 0?ea(e,n,r):ta(e,t,n,r):a.get(r)??r,s=t=>e.relationOccurrences[t]===void 0?$i(e,n,t):a.has(t);for(let t of Object.keys(e.relationOccurrences).sort()){let c=t;if(a.has(c))continue;let l=e.relationOccurrences[t],u=new Set(l.endpoints.map(e=>o(e.occurrence)));if(u.size!==1)continue;let d=[...u][0];n.has(d)&&e.entityOccurrences[d]!==void 0&&l.endpoints.some(e=>s(e.occurrence))&&(r.set(c,d),i=!0)}}return r}function aa(e){return new Set(Object.values(e.groups).filter(e=>e.collapsed===!0&&e.occurrence!==void 0).map(e=>e.occurrence))}function oa(e){let t=e,n=t.includes(`:`)?t.slice(t.indexOf(`:`)+1):t;return`grp.${n.length}.${n}`}function sa(e,t){let n={};for(let[r,i]of Object.entries(e.groups))if(i.occurrence===void 0)n[r]=i;else if(t.has(i.occurrence))n[r]={...i,collapsed:!0};else if(i.collapsed===void 0){let{collapsed:e,...t}=i;n[r]=t}else n[r]={...i,collapsed:!1};for(let e of t){if(Object.keys(n).find(t=>n[t]?.occurrence===e)!==void 0)continue;let t=oa(e);n[t]===void 0&&(n[t]={id:t,occurrence:e,collapsed:!0})}return n}function ca(e,t,n){let r=ia(e,t,n),i={};for(let a of Object.keys(e.relationOccurrences).sort()){let o=e.relationOccurrences[a];if(r.has(o.id)){i[a]={id:o.id,relation:o.relation,endpoints:o.endpoints.map(e=>e.chainProvenance===void 0?{role:e.role,occurrence:e.occurrence}:e),...o.waypoints===void 0?{}:{waypoints:o.waypoints.map(e=>({...e}))},...o.strokeStyle===void 0?{}:{strokeStyle:o.strokeStyle},...o.arrowhead===void 0?{}:{arrowhead:o.arrowhead},...o.emphasis===void 0?{}:{emphasis:o.emphasis}};continue}let s=o.endpoints.map(i=>{if(i.chainProvenance!==void 0)return i;let a=i.occurrence,s=e.relationOccurrences[a]!==void 0;if(!(s?r.has(a):$i(e,n,a)))return{role:i.role,occurrence:a};let c=s?r.get(a):e.portOccurrences[a]===void 0?ea(e,n,a):ta(e,t,n,a),l=na(e,a),u=l===void 0?void 0:ra(t,o.relation,i.role,l);return u===void 0?{role:i.role,occurrence:a}:{role:i.role,occurrence:c,semanticTarget:u,sourceOccurrence:a}});i[a]={id:o.id,relation:o.relation,endpoints:s,...o.waypoints===void 0?{}:{waypoints:o.waypoints.map(e=>({...e}))},...o.strokeStyle===void 0?{}:{strokeStyle:o.strokeStyle},...o.arrowhead===void 0?{}:{arrowhead:o.arrowhead},...o.emphasis===void 0?{}:{emphasis:o.emphasis}}}return i}function la(e,t,n){for(let e of Object.keys(t.relationOccurrences).sort()){let n=t.relationOccurrences[e],r=n.endpoints.findIndex(e=>e.semanticTarget!==void 0&&e.chainProvenance===void 0);if(r!==-1){let e=n.endpoints[r];throw{code:`occurrence-endpoint-mismatch`,severity:`error`,path:`relationOccurrences.${n.id}.endpoints[${r}].occurrence`,message:`projected endpoint for role ${e.role} fails check projection-source-projected`,refs:[n.id,e.occurrence],details:{role:e.role,check:`projection-source-projected`}}}}let r=new Set(n);return{...t,relationOccurrences:ca(t,e,r),groups:sa(t,r),filters:[...t.filters],...t.summaryLabels===void 0?{}:{summaryLabels:{...t.summaryLabels}},revision:t.revision}}function ua(e,t){let n=new Set([t]),r=new Map;for(let[t,n]of Object.entries(e.portOccurrences))r.set(t,n.ownerOccurrence);let i=!0;for(;i;){i=!1;for(let t of Object.keys(e.entityOccurrences)){if(n.has(t))continue;let r=Zi(e,t);r!==void 0&&n.has(r)&&(n.add(t),i=!0)}}for(let[e,t]of r)n.has(t)&&n.add(e);return n}function da(e,t,n){let r=e.relations[n];if(r===void 0)return!1;let i=t.get(r.profile),a=i===void 0?void 0:kr(e,i,r);return a!==void 0&&a.direction===`undirected`}function fa(e,t,n){let r=e.relations[n];if(r===void 0)return;let i=t.get(r.profile),a=i===void 0?void 0:kr(e,i,r);if(a!==void 0)return a.roles.map(e=>e.role)}function pa(e,t,n,r,i,a){let o=ua(e,r),s=ua(e,i),c=[];for(let r of Object.keys(e.relationOccurrences).sort()){let i=e.relationOccurrences[r];if(i.endpoints.length!==2||(i.strokeStyle??`solid`)!==a)continue;if(da(t,n,i.relation)){let[e,t]=i.endpoints,n=e.sourceOccurrence??e.occurrence,l=t.sourceOccurrence??t.occurrence,u=o.has(n)&&s.has(l),d=o.has(l)&&s.has(n);if(!u&&!d)continue;c.push({occurrence:r,relation:i.relation,style:a});continue}let l=fa(t,n,i.relation),u=new Map(i.endpoints.map(e=>[e.role,e]));if(l!==void 0&&l.length>=2&&u.has(l[0])&&u.has(l[1])){let e=u.get(l[0]),t=u.get(l[1]),n=e.sourceOccurrence??e.occurrence,d=t.sourceOccurrence??t.occurrence;if(!(o.has(n)&&s.has(d)))continue;c.push({occurrence:r,relation:i.relation,style:a});continue}let[d,f]=i.endpoints,p=d.sourceOccurrence??d.occurrence,m=f.sourceOccurrence??f.occurrence;o.has(p)&&s.has(m)&&c.push({occurrence:r,relation:i.relation,style:a})}return c}function ma(e){return[...new Set(e)].sort()}function ha(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function ga(e,t,n){let r=e.summaryLabels??{},i=n.registry,a=new Set(n.filters?.hiddenByFilter??[]),o=e=>a.has(e.id)?!0:e.endpoints.some(e=>a.has(e.sourceOccurrence??e.occurrence)||a.has(e.occurrence)),s=[],c=new Set,l=new Map,u=new Map;for(let n of Object.keys(r).sort()){let a=r[n],o=a.strokeStyle??`solid`,d=`${a.sourceOccurrence}\u0000${a.targetOccurrence}\u0000${o}`,f=l.get(d);if(f!==void 0){s.push({id:n,check:`summary-duplicate-key`,firstId:f}),c.add(n);continue}if(l.set(d,n),e.entityOccurrences[a.sourceOccurrence]===void 0||e.entityOccurrences[a.targetOccurrence]===void 0||a.relationIds.length===0){s.push({id:n,check:`summary-constituents-mismatch`}),c.add(n);continue}if(a.relationOccurrences!==void 0){let r=[...a.relationOccurrences];if(!ha([...r].sort(),r)||new Set(r).size!==r.length){s.push({id:n,check:`summary-constituents-mismatch`}),c.add(n);continue}let l=pa(e,t,i,a.sourceOccurrence,a.targetOccurrence,o),d=new Set(l.map(e=>e.occurrence));if(!r.every(e=>d.has(e))){s.push({id:n,check:`summary-constituents-mismatch`}),c.add(n);continue}let f=ma(r.map(t=>e.relationOccurrences[t].relation));if(!f.every(e=>l.filter(t=>t.relation===e).every(e=>r.includes(e.occurrence)))||!ha(a.relationIds,f)){s.push({id:n,check:`summary-constituents-mismatch`}),c.add(n);continue}u.set(n,[...r].sort());continue}let p=pa(e,t,i,a.sourceOccurrence,a.targetOccurrence,o),m=new Map;for(let e of p){let t=m.get(e.relation)??[];t.push(e.occurrence),m.set(e.relation,t)}let h=[...m.entries()].filter(([,e])=>e.length>1).map(([e])=>e).sort()[0];if(h!==void 0){s.push({id:n,check:`summary-occurrence-ambiguous`,relationId:h}),c.add(n);continue}let g=ma(p.map(e=>e.relation));ha(a.relationIds,g)?u.set(n,p.map(e=>e.occurrence).sort()):(s.push({id:n,check:`summary-constituents-mismatch`}),c.add(n))}let d=aa(e),f=ia(e,t,d),p=new Map;for(let n of Object.keys(e.relationOccurrences).sort()){let r=e.relationOccurrences[n];if(f.has(n)||o(r)||r.endpoints.length!==2)continue;let a=da(t,i,r.relation),s;if(a){let[e,t]=r.endpoints,n=[e.occurrence,t.occurrence];s=n[0]<=n[1]?n:[n[1],n[0]]}else{let e=fa(t,i,r.relation),n=new Map(r.endpoints.map(e=>[e.role,e.occurrence]));if(e!==void 0&&e.length>=2&&n.has(e[0])&&n.has(e[1]))s=[n.get(e[0]),n.get(e[1])];else{let[e,n]=r.endpoints,a=fa(t,i,r.relation)??[],o=e=>{let t=a.indexOf(e);return t===-1?2**53-1:t},c=[e,n].sort((e,t)=>{let n=o(e.role)-o(t.role);return n===0?e.occurrence<t.occurrence?-1:+(e.occurrence>t.occurrence):n});s=[c[0]?.occurrence,c[1]?.occurrence]}}let c=r.strokeStyle??`solid`,l=`(${s[0]},${s[1]},${c})`,u=p.get(l)??{members:[],relationIds:[],projected:!1};u.members.push(n),u.relationIds.includes(r.relation)||u.relationIds.push(r.relation),r.endpoints.some(e=>e.semanticTarget!==void 0)&&(u.projected=!0),p.set(l,u)}for(let e of p.values())e.members.sort(),e.relationIds.sort();let m=new Map,h=new Map;for(let n of Object.keys(r).sort()){if(c.has(n))continue;let a=r[n],o=a.strokeStyle??`solid`,s=va(e,t,d,f,a.sourceOccurrence),l=va(e,t,d,f,a.targetOccurrence),m=a.relationIds.every(e=>da(t,i,e)===!0)&&s>l?[l,s]:[s,l],g=`(${m[0]},${m[1]},${o})`,_=p.get(g);if(_===void 0||!_.projected)continue;let v=u.get(n);if(v.length!==_.members.length||!v.every((e,t)=>e===_.members[t]))continue;let y=[...a.relationIds].sort();if(_.relationIds.length!==y.length||!_.relationIds.every((e,t)=>e===y[t]))continue;let b=h.get(g)??[];b.push({id:n,definition:a}),h.set(g,b)}let g=[];for(let[n,r]of[...h.entries()].sort(([e],[t])=>e<t?-1:+(e>t))){let i=[...r].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),a=i[0];if(i.length===1){let e=p.get(n);m.set(n,{key:n,definitionId:a.id,label:a.definition.label,members:[...e.members],relationIds:[...e.relationIds]})}for(let n of i.slice(1)){let r=n.definition.strokeStyle??`solid`,i=va(e,t,d,f,n.definition.sourceOccurrence),o=va(e,t,d,f,n.definition.targetOccurrence);g.push({id:n.id,check:`summary-active-key-conflict`,firstId:a.id,sourceRepresentative:i,targetRepresentative:o,strokeStyle:r})}}return g.sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),{sourceIssues:s,conflicts:g,actives:m}}function _a(e,t,n){return new Map(ga(e,t,n).actives)}function va(e,t,n,r,i){return e.relationOccurrences[i]===void 0?e.portOccurrences[i]===void 0?e.entityOccurrences[i]===void 0?i:ea(e,n,i):ta(e,t,n,i):r.get(i)??i}function ya(e,t,n){let r=jn(t,n);if(r!==void 0)return r.abstract===!0?{diagnostic:H({code:`unknown-entity-type`,path:`profiles.${t.id}.entityTypes.${n}`,message:`entity type ${n} is abstract and cannot be instantiated`,details:{abstract:!0}})}:{schemas:r.attributes};let i=e.typeDefinitions[n];if(i===void 0)return{diagnostic:H({code:`unknown-entity-type`,path:`profiles.${t.id}.entityTypes.${n}`,message:`neither profile ${t.id} nor the document declares entity type ${n}`,details:{type:n,profile:t.id}})};let a=jn(t,i.baseType);return a===void 0?{diagnostic:H({code:`unknown-entity-type`,path:`typeDefinitions.${n}.baseType`,message:`type definition ${n} refines ${i.baseType}, which profile ${t.id} does not declare`})}:{schemas:[...a.attributes,...i.attributes]}}function ba(e,t,n,r,i){let a=[],o=new Map(t.map(e=>[e.name,e]));for(let t of Object.keys(e).sort()){let s=o.get(t),c=e[t];if(s===void 0)a.push(H({code:`attribute-not-in-schema`,path:`${r}.${t}`,message:`attribute ${t} is not declared by the effective schema (declared: ${[...o.keys()].sort().join(`, `)||`none`})`,details:{attribute:t}}));else{a.push(...Yt(s,c,`${r}.${t}`)),s.kind===`struct`&&c.kind===`struct`&&i!==void 0&&a.push(...Sa(s,c,`${r}.${t}`,n,i));for(let e of Xt(s,c)){let o=e.index===void 0?`${r}.${t}`:`${r}.${t}[${e.index}]`;if(a.push(...Ca(n,e.raw,e.refKind,o)),i!==void 0){let t=s.kind===`collection`?s.item:s;a.push(...xa(n,i,t,e.raw,o))}}}}for(let n of t)n.required===!0&&e[n.name]===void 0&&a.push(H({code:`attribute-required-missing`,path:`${r}.${n.name}`,message:`attribute ${n.name} is required by the schema`,details:{attribute:n.name}}));return a}function xa(e,t,n,r,i){if(n?.kind!==`reference`||n.refKind!==`entity`)return[];let a=n.targetTypes;if(a===void 0||a.length===0)return[];let o=e.entities[r];if(o===void 0)return[];let s=t.registry.get(o.profile);if(s===void 0)return[];let c=t.resolver.resolve(s,o.type);return!c.ok||a.some(e=>c.resolved.ancestry.includes(e))?[]:[H({code:`reference-target-type`,path:i,message:`reference target ${r} has type ${o.type}; allowed types are ${a.join(`, `)}`,refs:[r],details:{seenType:o.type,allowed:a.join(`,`)}})]}function Sa(e,t,n,r,i){let a=i.resolver.resolve(i.owner,t.type);if(!a.ok)return[H({code:`struct-type-unknown`,path:n,message:`structured value type ${t.type} is not declared`,refs:[],details:{type:t.type}})];if(e.targetTypes.length>0&&!e.targetTypes.includes(t.type))return[H({code:`struct-type-not-allowed`,path:n,message:`structured type ${t.type} is not allowed here; allowed types are ${e.targetTypes.join(`, `)}`,refs:[],details:{type:t.type,allowed:e.targetTypes.join(`,`)}})];let o=a.resolved.schemas,s=[],c=new Map(o.map(e=>[e.name,e]));for(let e of Object.keys(t.fields).sort()){let a=c.get(e),o=`${n}.fields.${e}`,l=t.fields[e];if(a===void 0)s.push(H({code:`struct-field-not-in-schema`,path:o,message:`field ${e} is not declared by structured type ${t.type}`,refs:[],details:{type:t.type,field:e}}));else{s.push(...Yt(a,l,o)),a.kind===`struct`&&l.kind===`struct`&&s.push(...Sa(a,l,o,r,i));for(let e of Xt(a,l)){let t=e.index===void 0?o:`${o}[${e.index}]`;s.push(...Ca(r,e.raw,e.refKind,t));let n=a.kind===`collection`?a.item:a;s.push(...xa(r,i,n,e.raw,t))}}}for(let e of o)e.required===!0&&t.fields[e.name]===void 0&&s.push(H({code:`attribute-required-missing`,path:`${n}.fields.${e.name}`,message:`attribute ${e.name} is required by the schema`,details:{attribute:e.name}}));return s}function Ca(e,t,n,r){let i=Wt(n,t,r);return i.ok?(n===`entity`?e.entities[t]:n===`relation`?e.relations[t]:n===`port`?e.ports[t]:n===`resource`?e.resources[t]:void 0)===void 0?n===`occurrence`||n===`view`||n===`document`?[H({code:`reference-type-mismatch`,path:r,message:`a ${n} reference cannot be resolved from a semantic document`,refs:[t],details:{expectedKind:n}})]:[H({code:`dangling-reference`,path:r,message:`${t} resolves to no ${n} in this document`,refs:[t],details:{expectedKind:n}})]:[]:[i.diagnostic]}function wa(e,t,n,r,i,a=dn){let o=`entities.${t}`,s=[...Ya(t,e.id,`entity`,o)],c=Xa(n,e.profile,r,o);if(`diagnostic`in c)return[...s,c.diagnostic];if(a!==`legacy-constraints@1`&&i!==void 0)return[...s,...Ta(e,o,n,r,c.profile,i)];let l=ya(n,c.profile,e.type);return`diagnostic`in l?[...s,{...l.diagnostic,path:`${o}.type`}]:(s.push(...ba(e.attributes,l.schemas,n,`${o}.attributes`)),s)}function Ta(e,t,n,r,i,a){let o=a.resolve(i,e.type);return o.ok?o.resolved.abstract?[H({code:`abstract-instantiated`,severity:`error`,path:`${t}.type`,message:`abstract type ${e.type} cannot be instantiated as an entity`,refs:[e.id],details:{type:e.type}})]:ba(e.attributes,o.resolved.schemas,n,`${t}.attributes`,{owner:i,registry:r.registry,resolver:a}):o.diagnostic.path.startsWith(`typeDefinitions.`)?[]:[{...o.diagnostic,path:`${t}.type`}]}function Ea(e,t,n,r,i,a=dn){let o=`ports.${t}`,s=[...Ya(t,e.id,`port`,o)],c=Xa(n,e.profile,r,o);if(`diagnostic`in c)return[...s,c.diagnostic];s.push(...Ca(n,e.owner,`entity`,`${o}.owner`));let l=Mn(c.profile,e.type);if(l===void 0)return s.push(H({code:`unknown-port-type`,path:`${o}.type`,message:`profile ${e.profile} does not declare port type ${e.type}`,details:{type:e.type}})),s;l.directions.includes(e.direction)||s.push(H({code:`port-direction-not-allowed`,path:`${o}.direction`,message:`port type ${e.type} allows ${l.directions.join(`, `)}, not ${e.direction}`,details:{direction:e.direction,allowed:l.directions.join(`,`)}}));let u=a!==`legacy-constraints@1`&&i!==void 0?{owner:c.profile,registry:r.registry,resolver:i}:void 0;return s.push(...ba(e.attributes,l.attributes??[],n,`${o}.attributes`,u)),s}function Da(e,t,n,r,i,a=dn){let o=`relations.${t}`,s=[...Ya(t,e.id,`relation`,o)],c=Xa(n,e.profile,r,o);if(`diagnostic`in c)return[...s,c.diagnostic];let l=kr(n,c.profile,e);if(l===void 0)return s.push(H({code:`unknown-relation-type`,path:`${o}.type`,message:`profile ${e.profile} does not declare relation type ${e.type}`,details:{type:e.type}})),s;let u=c.profile.limits.maxEndpointsPerRelation;u!==void 0&&e.endpoints.length>u&&s.push(H({code:`limit-exceeded`,path:`${o}.endpoints`,message:`${e.endpoints.length} endpoints; profile ${c.profile.id} allows ${u}`,details:{limit:`maxEndpointsPerRelation`,seen:e.endpoints.length,max:u}}));let d=new Map;e.endpoints.forEach((t,c)=>{let u=`${o}.endpoints[${c}]`,f=Pn(l,t.role);if(f===void 0){s.push(H({code:`endpoint-role-unknown`,path:`${u}.role`,message:`relation type ${e.type} declares ${l.roles.map(e=>e.role).join(`, `)}, not ${t.role}`,details:{role:t.role}}));return}d.set(t.role,(d.get(t.role)??0)+1);let p=Ht(t.target);if(p!==`entity`&&p!==`port`&&(a===`legacy-constraints@1`||p!==`relation`)){s.push(H({code:p===void 0?`malformed-ref`:`reference-type-mismatch`,path:`${u}.target`,message:`an endpoint targets an entity or a port, not ${p??JSON.stringify(t.target)}`,refs:[String(t.target)],...p===void 0?{}:{details:{seenKind:p}}}));return}if(!f.targets.includes(p)){s.push(H({code:`endpoint-target-not-allowed`,path:`${u}.target`,message:`role ${t.role} accepts ${f.targets.join(`, `)}, not a ${p}`,refs:[t.target],details:{seenKind:p,allowed:f.targets.join(`,`)}}));return}let m=Ca(n,t.target,p,`${u}.target`);if(s.push(...m),!(m.length>0)){if(a!==`legacy-constraints@1`&&(p===`entity`||p===`port`||p===`relation`)){let r=p===`entity`?n.entities[t.target]?.profile:p===`port`?n.ports[t.target]?.profile:n.relations[t.target]?.profile;if(r!==void 0&&r!==e.profile){s.push(H({code:`endpoint-without-join`,path:`${u}.target`,message:`relation ${e.id} applies ${e.profile} ${e.type} to ${p} ${t.target} owned by profile ${r} with no admitted semantic join`,refs:[t.target],details:{profile:e.profile,targetProfile:r}}));return}}if(p===`entity`&&f.entityTypes!==void 0){let e=n.entities[t.target],o=a!==`legacy-constraints@1`&&i!==void 0?Oa(r.registry,i,e):[e.type];f.entityTypes.some(e=>o.includes(e))||s.push(H({code:`endpoint-target-not-allowed`,path:`${u}.target`,message:`role ${t.role} accepts entity types ${f.entityTypes.join(`, `)}; ${e.id} is a ${e.type}`,refs:[e.id],details:{seenType:e.type,allowed:f.entityTypes.join(`,`)}}))}}});for(let e of l.roles){let t=d.get(e.role)??0;(t<e.cardinality.min||t>e.cardinality.max)&&s.push(H({code:`endpoint-cardinality-violation`,path:`${o}.endpoints`,message:`role ${e.role} carries ${t} endpoints; the declared cardinality is ${e.cardinality.min}..${e.cardinality.max}`,details:{role:e.role,seen:t,min:e.cardinality.min,max:e.cardinality.max}}))}let f=a!==`legacy-constraints@1`&&i!==void 0?{owner:c.profile,registry:r.registry,resolver:i}:void 0;return s.push(...ba(e.attributes,l.attributes??[],n,`${o}.attributes`,f)),s}function Oa(e,t,n){let r=e.get(n.profile);if(r===void 0)return[n.type];let i=t.resolve(r,n.type);return i.ok?i.resolved.ancestry:[n.type]}function ka(e,t){let n=[];for(let{profile:r,declaration:i}of t){let t=i.hierarchy;if(t===void 0)continue;let a=new Map,o=new Map;for(let n of Object.values(e.relations)){if(n.profile!==r||(e.typeDefinitions[n.type]?.baseType??n.type)!==i.id)continue;let s=n.endpoints.filter(e=>e.role===t.parentRole),c=n.endpoints.filter(e=>e.role===t.childRole);for(let e of s)for(let t of c)a.set(t.target,[...a.get(t.target)??[],e.target]),o.set(e.target,[...o.get(e.target)??[],t.target])}if(t.shape===`tree`)for(let[e,r]of[...a.entries()].sort())r.length>1&&n.push(H({code:`hierarchy-multiple-parents`,path:`relations`,message:`hierarchy ${t.id} is declared a tree; ${e} has ${r.length} parents (${r.sort().join(`, `)})`,refs:[e,...r],details:{hierarchy:t.id,child:e,parents:r.length}}));let s=new Map,c=e=>{let r=[{node:e,path:[e]}];for(;r.length>0;){let e=r.pop();if(s.get(e.node)!==`done`){if(e.path.slice(0,-1).includes(e.node)){let r=e.path.slice(e.path.indexOf(e.node));n.push(H({code:`hierarchy-cycle`,path:`relations`,message:`hierarchy ${t.id} closes a cycle: ${r.join(` -> `)}`,refs:r,details:{hierarchy:t.id,shape:t.shape,length:r.length-1}}))}else{s.set(e.node,`visiting`);for(let t of(o.get(e.node)??[]).slice().sort())r.push({node:t,path:[...e.path,t]})}}}for(let[e,t]of s)t===`visiting`&&s.set(e,`done`)};for(let e of[...o.keys()].sort())c(e)}return n}function Aa(e,t,n,r,i){let a=[],o=Object.values(e.entities).filter(e=>e.profile===t.id);for(let s of t.constraints){if(s.kind===`erd-keys`){a.push(...Ar(e,t,s.maxFields));continue}if(s.kind===`acyclic-hierarchy`)continue;if(i!==`legacy-constraints@1`&&r!==void 0&&ja(s)){a.push(...Fa(e,t,n,r,s,o));continue}if(s.kind===`max-entities-of-type`){let e=o.filter(e=>e.type===s.entityType).length;e>s.max&&a.push(H({code:`limit-exceeded`,path:`entities`,message:`${e} entities of type ${s.entityType}; profile ${t.id} allows ${s.max}`,details:{type:s.entityType,seen:e,max:s.max}}));continue}if(s.kind!==`unique-attribute`)continue;if(i!==`legacy-constraints@1`&&s.scope!==void 0){a.push(...Ka(e,t,n.registry,r,s,o));continue}let c=new Map,l=o.filter(e=>e.type===s.entityType).slice().sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let e of l){let t=e.attributes[s.attribute];if(t===void 0)continue;let n=Dn(t,`value`);if(!n.ok)continue;let r=c.get(n.text);r===void 0?c.set(n.text,e.id):a.push(H({code:`unique-attribute-violation`,path:`entities.${e.id}.attributes.${s.attribute}`,message:`attribute ${s.attribute} must be unique among ${s.entityType} entities; ${r} carries the same value`,refs:[e.id,r],details:{attribute:s.attribute,type:s.entityType}}))}}return a}function ja(e){switch(e.kind){case`acyclic-hierarchy`:case`unique-attribute`:case`max-entities-of-type`:return!1;default:return!0}}function Ma(e,t,n){let r=e.get(n.profile);if(r===void 0)return;let i=t.resolve(r,n.type);if(!i.ok)return;let a=i.resolved.ancestry.find(e=>jn(r,e)!==void 0)??n.type;return{entity:n,chain:i.resolved.ancestry,familyType:a}}function Na(e,t,n,r){let i=e.entities[r];if(i===void 0)return;let a=t.get(i.profile);if(a===void 0)return{entity:i,chain:[i.type],familyType:i.type};let o=n.resolve(a,i.type);if(!o.ok)return{entity:i,chain:[i.type],familyType:i.type};let s=o.resolved.ancestry.find(e=>jn(a,e)!==void 0)??i.type;return{entity:i,chain:o.resolved.ancestry,familyType:s}}function Pa(e,t,n){let r=t.relationTypes.filter(e=>e.hierarchy?.id===n);if(r.length===0)return;let i=new Map;for(let n of r){let r=n.hierarchy;for(let a of Object.values(e.relations)){if(a.profile!==t.id||(e.typeDefinitions[a.type]?.baseType??a.type)!==n.id)continue;let o=a.endpoints.filter(e=>e.role===r.parentRole),s=a.endpoints.filter(e=>e.role===r.childRole);for(let e of o)if(Ht(e.target)===`entity`)for(let t of s)Ht(t.target)===`entity`&&i.set(t.target,[...i.get(t.target)??[],e.target])}}for(let e of i.values())e.sort();return{childToParents:i}}function Fa(e,t,n,r,i,a){switch(i.kind){case`hierarchy`:return[];case`parent-family`:return Ia(e,t,n.registry,r,i);case`children-restricted`:return La(e,t,n.registry,r,i);case`required-parent`:return Ra(e,t,n.registry,r,i,a);case`relationship-matrix`:return za(e,t,n.registry,r,i);case`bound-pair`:return Va(e,t,n.registry,r,i);case`reference-application`:return Ha(e,t,n.registry,r,i,a);case`incident-type-uniformity`:return Ua(e,t,n.registry,r,i,a);case`at-most-value`:return Wa(e,t,i);case`collection-unique`:return Ga(e,n.registry,r,i,a)}}function Ia(e,t,n,r,i){let a=[];for(let o of t.relationTypes){if(o.hierarchy?.id!==i.hierarchyId)continue;let s=o.hierarchy,c=Object.values(e.relations).filter(n=>n.profile===t.id&&Or(e,t,n)===o.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let t of c)t.endpoints.forEach((o,c)=>{if(o.role!==s.parentRole||Ht(o.target)!==`entity`)return;let l=Na(e,n,r,o.target);l!==void 0&&(i.familyRoots.some(e=>l.chain.includes(e))||a.push(H({code:`endpoint-target-not-allowed`,path:`relations.${t.id}.endpoints[${c}].target`,message:`role ${o.role} accepts entity types ${i.familyRoots.join(`, `)}; ${l.entity.id} is a ${l.entity.type}`,refs:[l.entity.id],details:{seenType:l.entity.type,allowed:i.familyRoots.join(`,`)}})))})}return a}function La(e,t,n,r,i){let a=[],o=new Set;for(let s of t.relationTypes){if(s.hierarchy?.id!==i.hierarchyId)continue;let c=s.hierarchy,l=Object.values(e.relations).filter(n=>n.profile===t.id&&Or(e,t,n)===s.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let t of l){let s=t.endpoints.filter(e=>e.role===c.parentRole),l=t.endpoints.filter(e=>e.role===c.childRole);for(let t of s){if(Ht(t.target)!==`entity`)continue;let s=Na(e,n,r,t.target);if(s===void 0||!i.parentFamilyRoots.some(e=>s.chain.includes(e)))continue;let c=i.parentFamilyRoots.join(`, `),u=i.childTypes.join(`, `);for(let d of l){if(Ht(d.target)!==`entity`||o.has(d.target))continue;let l=Na(e,n,r,d.target);l!==void 0&&(i.childTypes.some(e=>l.chain.includes(e))||(o.add(d.target),a.push(H({code:`legend-key-parent-invalid`,path:`entities.${d.target}`,message:`key entity ${d.target} is contained by ${c} ${t.target}; only ${u} entities may be contained by a ${c}`,refs:[d.target,t.target],details:{childType:l.entity.type,parentType:s.entity.type,constraint:`children-restricted`}}))))}}}}return a}function Ra(e,t,n,r,i,a){let o=Pa(e,t,i.hierarchyId);if(o===void 0)return[];let s=[],c=[...a].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let t of c){if(!i.childTypes.some(e=>Oa(n,r,t).includes(e)))continue;let a=i.parentFamilyRoots.join(`, `),c=i.childTypes.join(`, `),l=o.childToParents.get(t.id)??[];if(l.length===0){s.push(H({code:`legend-key-parent-invalid`,path:`entities.${t.id}`,message:`key entity ${t.id} has no hierarchy parent; a ${c} must be contained by a ${a}`,refs:[t.id],details:{childType:t.type,parentType:`none`,constraint:`required-parent`}}));continue}if(l.filter(t=>{let a=Na(e,n,r,t);return a!==void 0&&i.parentFamilyRoots.some(e=>a.chain.includes(e))}).length>0)continue;let u=l[0],d=Na(e,n,r,u);d!==void 0&&s.push(H({code:`legend-key-parent-invalid`,path:`entities.${t.id}`,message:`key entity ${t.id} is contained by ${u}, which is outside the ${a} family; a ${c} must be contained by a ${a}`,refs:[t.id,u],details:{childType:t.type,parentType:d.entity.type,constraint:`required-parent`}}))}return s}function za(e,t,n,r,i){let a=new Set(i.tuples.map(e=>`${e.relationType}\n${e.sourceType}\n${e.targetType}`)),o=[],s=Object.values(e.relations).filter(e=>e.profile===t.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let c of s){let s=kr(e,t,c);if(s===void 0)continue;let l=Pn(s,i.sourceRole),u=Pn(s,i.targetRole);if(l===void 0||u===void 0)continue;let d=c.endpoints.filter(e=>e.role===i.sourceRole),f=c.endpoints.filter(e=>e.role===i.targetRole);if(d.length!==1||f.length!==1)continue;let p=d[0],m=f[0],h=Ht(p.target),g=Ht(m.target);if(h!==`entity`&&h!==`relation`||g!==`entity`&&g!==`relation`||!l.targets.includes(h)||!u.targets.includes(g))continue;let _=new Map;for(let e of c.endpoints)_.set(e.role,(_.get(e.role)??0)+1);let v=_.get(i.sourceRole)??0,y=_.get(i.targetRole)??0;if(v<l.cardinality.min||v>l.cardinality.max||y<u.cardinality.min||y>u.cardinality.max)continue;let b;if(h===`entity`){let t=e.entities[p.target];if(t===void 0)continue;let i=Ma(n,r,t);if(i===void 0||l.entityTypes!==void 0&&!l.entityTypes.some(e=>i.chain.includes(e)))continue;b=i.familyType}else b=`@relation`;let x;if(g===`entity`){let t=e.entities[m.target];if(t===void 0)continue;let i=Ma(n,r,t);if(i===void 0||u.entityTypes!==void 0&&!u.entityTypes.some(e=>i.chain.includes(e)))continue;x=i.familyType}else x=`@relation`;a.has(`${Or(e,t,c)}\n${b}\n${x}`)||o.push(H({code:`relationship-matrix-violation`,path:`relations.${c.id}.endpoints`,message:`relation ${c.id} of type ${c.type} is not allowed from ${b} to ${x} by matrix ${i.matrixId}`,refs:[c.id,p.target,m.target],details:{matrixId:i.matrixId,relationType:c.type,sourceType:b,targetType:x}}))}return o}function Ba(e,t,n){let r=e.resolve(t,n);if(r.ok)return r.resolved.schemas}function Va(e,t,n,r,i){let a=[],o=(e,n)=>{if(e.kind===`struct`){if(e.type===i.valueType){let o=e.fields[i.lowerField],s=e.fields[i.upperField],c=Ba(r,t,e.type),l=c?.find(e=>e.name===i.lowerField),u=c?.find(e=>e.name===i.upperField),d=o!==void 0&&l!==void 0&&Yt(l,o,`${n}.fields.${i.lowerField}`).length===0,f=s!==void 0&&u!==void 0&&Yt(u,s,`${n}.fields.${i.upperField}`).length===0;d&&f&&o?.kind===`quantity`&&s?.kind===`quantity`&&typeof o.value==`number`&&typeof s.value==`number`&&Number.isFinite(o.value)&&Number.isFinite(s.value)&&s.value!==i.unboundedUpper&&o.value>s.value&&a.push(H({code:`multiplicity-invalid`,path:n,message:`multiplicity lower ${String(o.value)} exceeds finite upper ${String(s.value)}`,refs:[],details:{lower:o.value,upper:s.value,constraint:`bound-pair`}}))}for(let t of Object.keys(e.fields).sort())o(e.fields[t],`${n}.fields.${t}`)}},s=(e,t)=>{for(let n of Object.keys(t).sort())o(t[n],`${e}.attributes.${n}`)};for(let n of Object.values(e.entities).filter(e=>e.profile===t.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)))Ba(r,t,n.type)!==void 0&&s(`entities.${n.id}`,n.attributes);for(let n of Object.values(e.relations).filter(e=>e.profile===t.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)))kr(e,t,n)!==void 0&&s(`relations.${n.id}`,n.attributes);for(let n of Object.values(e.ports).filter(e=>e.profile===t.id).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)))Mn(t,n.type)!==void 0&&s(`ports.${n.id}`,n.attributes);return a}function Ha(e,t,n,r,i,a){let o=[],s=[...a].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let a of s){let s=Ba(r,t,a.type);if(s===void 0)continue;let c=s.find(e=>e.name===i.attribute);if(c===void 0)continue;let l=a.attributes[i.attribute];if(l===void 0)continue;let u=c.kind===`collection`?c.item:c;if(u.kind!==`reference`)continue;let d=l.kind===`collection`?l.items.map((e,t)=>({item:e,index:t})):[{item:l,index:void 0}];for(let{item:t,index:s}of d){if(t.kind!==`reference`)continue;let c=s===void 0?`entities.${a.id}.attributes.${i.attribute}`:`entities.${a.id}.attributes.${i.attribute}[${s}]`,l=e.entities[t.value];if(l===void 0)continue;let d=n.get(l.profile);if(d===void 0)continue;let f=r.resolve(d,l.type);if(!f.ok)continue;let p=u.targetTypes;if(p!==void 0&&p.length>0&&!p.some(e=>f.resolved.ancestry.includes(e)))continue;let m=f.resolved.schemas.find(e=>e.name===i.allowedTypesField);if(m?.kind!==`collection`||m.item.kind!==`enum`)continue;let h=l.attributes[i.allowedTypesField];if(h?.kind!==`collection`)continue;let g=h.items.flatMap(e=>e.kind===`enum`?[e.value]:[]),_=Na(e,n,r,a.id);_!==void 0&&(g.some(e=>_.chain.includes(e))||o.push(H({code:`stereotype-application-invalid`,path:c,message:`stereotype ${l.id} cannot be applied to type ${_.familyType}`,refs:[a.id,l.id],details:{attribute:i.attribute,targetType:_.familyType,allowed:g.join(`,`)}})))}}return o}function Ua(e,t,n,r,i,a){let o=[],s=[...a].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),c=Object.values(e.relations).filter(n=>n.profile===t.id&&i.relationTypes.includes(Or(e,t,n))).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let a of s){if(!Oa(n,r,a).includes(i.entityType))continue;let s=c.filter(e=>e.endpoints.some(e=>e.target===a.id)),l=[...new Set(s.map(n=>Or(e,t,n)))].sort();l.length<=1||o.push(H({code:`relationship-matrix-violation`,path:`entities.${a.id}`,message:`junction ${a.id} connects incompatible relation types ${l.join(`, `)}`,refs:[a.id,...s.map(e=>e.id)],details:{matrixId:i.matrixId,constraint:`incident-type-uniformity`,relationTypes:l.join(`,`)}}))}return o}function Wa(e,t,n){let r=[],i=Object.values(e.relations).filter(r=>r.profile===t.id&&Or(e,t,r)===n.relationType).sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let e of i){let t=n.attributes.filter(t=>{let r=e.attributes[t];return r!==void 0&&r.kind===`enum`&&r.value===n.value}).length;t<=n.max||r.push(H({code:`multiplicity-invalid`,path:`relations.${e.id}.attributes`,message:`relation ${e.id} has ${t} ${n.value} ends; at most ${n.max} is allowed`,refs:[e.id],details:{count:t,max:n.max,constraint:`at-most-value`}}))}return r}function Ga(e,t,n,r,i){let a=[],o=[...i].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id));for(let e of o){if(!Oa(t,n,e).includes(r.entityType))continue;let i=e.attributes[r.attribute];if(i?.kind!==`collection`)continue;let o=new Map;i.items.forEach((t,n)=>{let i=Dn(t,`value`);if(!i.ok)return;let s=o.get(i.text);s===void 0?o.set(i.text,n):a.push(H({code:`collection-bound-exceeded`,path:`entities.${e.id}.attributes.${r.attribute}[${n}]`,message:`collection ${r.attribute} repeats item ${n}; first occurrence is ${s}`,refs:[],details:{constraint:`collection-unique`,firstIndex:s,duplicateIndex:n}}))})}return a}function Ka(e,t,n,r,i,a){let o=i.scope??`document`,s=o===`document`?`document`:o===`siblings`?`siblings`:`within:${o.withinType}`,c;if(o===`document`)c=()=>`document`;else{let a=Bn(t,i.entityType,o===`siblings`?void 0:o.withinType);if(a===void 0)return[];let s=Pa(e,t,a.hierarchyId);if(s===void 0)return[];c=o===`siblings`?e=>s.childToParents.get(e)?.[0]??`roots`:t=>qa(e,n,r,s,t,o.withinType)}let l=c,u=[...a].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),d=new Map;for(let e of u){if(!Oa(n,r,e).includes(i.entityType))continue;let t=l(e.id);d.set(t,[...d.get(t)??[],e.id])}let f=[];for(let t of d.values()){let n=new Map;for(let r of t){let t=e.entities[r].attributes[i.attribute];if(t===void 0)continue;let a=Dn(t,`value`);if(!a.ok)continue;let o=n.get(a.text);o===void 0?n.set(a.text,r):f.push(H({code:`unique-attribute-violation`,path:`entities.${r}.attributes.${i.attribute}`,message:`attribute ${i.attribute} must be unique among ${i.entityType} entities in scope ${s}; ${o} carries the same value`,refs:[r,o],details:{attribute:i.attribute,type:i.entityType,scope:s}}))}}return f}function qa(e,t,n,r,i,a){let o=[i],s=new Set([i]);for(;o.length>0;){let i=[];for(let c of[...o].sort())for(let o of r.childToParents.get(c)??[]){if(s.has(o))continue;s.add(o);let r=Na(e,t,n,o);if(r!==void 0&&r.chain.includes(a))return o;i.push(o)}o=i}return`none:${i}`}function Ja(e){let t=[];return e.extensions.forEach((n,r)=>{let i=`extensions[${r}]`;n.validation===`unsupported`&&t.push(H({code:`extension-unsupported`,path:i,message:`extension ${n.namespace}@${n.schemaVersion} is unsupported: preserved for inspection and export, refused for write`,details:{namespace:n.namespace,schemaVersion:n.schemaVersion}}));let a=qr(n.scope);if(a!==void 0){let r=n.scope.kind;t.push(...Ca(e,a,r,`${i}.scope.target`))}n.contentHash.length===0?t.push(H({code:`extension-hash-mismatch`,path:`${i}.contentHash`,message:`an extension carries its content hash`})):n.source!==void 0&&nn(n.source)!==n.contentHash&&t.push(H({code:`extension-hash-mismatch`,path:`${i}.contentHash`,message:`recorded hash ${n.contentHash} is not the hash of the retained source (${nn(n.source)})`,details:{recorded:n.contentHash,computed:nn(n.source)}}))}),t}function Ya(e,t,n,r){let i=[],a=Wt(n,t,`${r}.id`);return a.ok||i.push(a.diagnostic),e!==t&&i.push(H({code:`record-key-mismatch`,path:r,message:`record key ${e} is not the element's own id ${t}`,refs:[e,t]})),i}function Xa(e,t,n,r){if(!e.profileRefs.includes(t))return{diagnostic:H({code:`profile-not-declared`,path:`${r}.profile`,message:`profile ${t} is used but not declared by the document (declared: ${e.profileRefs.join(`, `)||`none`})`,details:{profile:t}})};let i=n.registry.get(t);return i===void 0?{diagnostic:H({code:`unknown-profile`,path:`${r}.profile`,message:`profile ${t} is not in the registry (registered: ${n.registry.list().join(`, `)||`none`})`,details:{profile:t}})}:{profile:i}}function Za(e,t){if(typeof e!=`object`||!e)return[H({code:`document-not-an-object`,path:`document`,message:`a document is an object`})];let n=Array.isArray(e.profileRefs)?e.profileRefs.find(e=>Yi(e)):void 0;if(n!==void 0)return[H({code:`unknown-profile`,severity:`error`,path:`profileRefs`,message:`profile ${n} is not a diagram profile; ${n} is a contract artifact, not a semantic profile`,details:{profile:n}})];let r=t.bindings===void 0?void 0:t.bindings.rows.find(e=>Yi(e.profileId));if(r!==void 0){let e=r.profileId;return[H({code:`type-definition-conflict`,severity:`error`,path:`bindings.${e}`,message:`executor binding for ${e} is refused; a contract artifact is never a family layer`,details:{profile:e}})]}if(t.bindings!==void 0){let n=Cn(t.bindings,t.registry);if(n.length>0)return n;for(let n of e.profileRefs)if(wn(t.bindings,n)===void 0)return[H({code:`type-definition-conflict`,path:`bindings.${n}`,message:`no executor binding row selects an adapter for profile ${n}`,details:{profile:n}})]}else{for(let t of e.profileRefs)if(!gn(t))return[H({code:`type-definition-conflict`,path:`bindings.${t}`,message:`no executor binding row selects an adapter for profile ${t}`,details:{profile:t}})];let n=Cn({schemaVersion:`1`,rows:Gr.rows.filter(n=>e.profileRefs.includes(n.profileId)&&t.registry.get(n.profileId)!==void 0)},t.registry);if(n.length>0)return n}let i=[],a=e.schemaVersion;typeof a!=`object`||!Number.isInteger(a.major)||!Number.isInteger(a.minor)||a.major<1||a.minor<0?i.push(H({code:`schema-version-malformed`,path:`schemaVersion`,message:`expected { major, minor } integers, got ${JSON.stringify(a)}`})):a.major===Kr.major?a.minor!==Kr.minor&&i.push(H({code:`schema-migration-required`,path:`schemaVersion`,message:`schema ${a.major}.${a.minor} must be migrated to ${Kr.major}.${Kr.minor} before it is written`,details:{seenMinor:a.minor,currentMinor:Kr.minor}})):i.push(H({code:`unknown-schema-major`,path:`schemaVersion`,message:`schema major ${a.major} is not writable by this build (current ${Kr.major}.${Kr.minor}); preserved for inspection and export`,details:{seenMajor:a.major,currentMajor:Kr.major}})),(!Number.isInteger(e.revision)||e.revision<0)&&i.push(H({code:`value-not-finite`,path:`revision`,message:`a revision is a non-negative integer, got ${String(e.revision)}`}));let o=Wt(`document`,e.documentId,`documentId`);o.ok||i.push(o.diagnostic),e.profileRefs.length===0&&i.push(H({code:`profile-not-declared`,path:`profileRefs`,message:`a document declares at least one profile`}));let s=e=>wn(t.bindings,e)??`legacy-constraints@1`,c=Qr(e),l=[];for(let n of e.profileRefs){let e=t.registry.get(n);e===void 0?i.push(H({code:`unknown-profile`,path:`profileRefs`,message:`profile ${n} is not in the registry (registered: ${t.registry.list().join(`, `)||`none`})`,details:{profile:n}})):(l.push(e),i.push(...Fn(e,s(n))))}let u=new Set;for(let n of Object.keys(e.typeDefinitions).sort()){let r=e.typeDefinitions[n],a=`typeDefinitions.${n}`;r.id!==n&&i.push(H({code:`record-key-mismatch`,path:a,message:`record key ${n} is not the definition id ${r.id}`}));let o=Xa(e,r.profile,t,a);if(`diagnostic`in o){i.push(o.diagnostic);continue}let l=jn(o.profile,r.baseType),d=Nn(o.profile,r.baseType);if(jn(o.profile,n)!==void 0||Nn(o.profile,n)!==void 0){i.push(H({code:`type-definition-reserved`,path:a,message:`definition ${n} shadows a profile type`}));continue}if(l!==void 0&&d!==void 0){i.push(H({code:`type-definition-ambiguous`,path:`${a}.baseType`,message:`base ${r.baseType} exists in both namespaces`}));continue}if(s(r.profile)===`legacy-constraints@1`||d!==void 0){let e=l??d;if(e===void 0){i.push(H({code:`unknown-entity-type`,path:`${a}.baseType`,message:`profile ${r.profile} does not declare base type ${r.baseType}`}));continue}let t=new Set((e.attributes??[]).map(e=>e.name));for(let e of r.attributes)i.push(...Wn(e,`${a}.attributes.${e.name}`)),d!==void 0&&e.required===!0&&i.push(H({code:`type-definition-conflict`,path:`${a}.attributes.${e.name}`,message:`refinements add optional attributes only`})),t.has(e.name)&&i.push(H({code:`type-definition-conflict`,path:`${a}.attributes.${e.name}`,message:`type definition ${n} redeclares ${e.name}, which base type ${r.baseType} already declares; refinements are additive only`,details:{attribute:e.name,baseType:r.baseType}})),t.add(e.name);continue}let f=c.resolve(o.profile,n);f.ok?r.attributes.forEach((e,t)=>{i.push(...Wn(e,`${a}.attributes[${t}]`))}):u.has(f.diagnostic.path)||(u.add(f.diagnostic.path),i.push(f.diagnostic))}for(let n of Object.keys(e.entities).sort()){let r=e.entities[n];i.push(...wa(r,n,e,t,c,s(r.profile)))}for(let n of Object.keys(e.ports).sort()){let r=e.ports[n];i.push(...Ea(r,n,e,t,c,s(r.profile)))}for(let n of Object.keys(e.relations).sort()){let r=e.relations[n];i.push(...Da(r,n,e,t,c,s(r.profile)))}for(let t of Object.keys(e.resources).sort()){let n=e.resources[t],r=`resources.${t}`;i.push(...Ya(t,n.id,`resource`,r)),n.uri.length===0&&i.push(H({code:`value-not-serialisable`,path:`${r}.uri`,message:`a resource carries a uri`})),n.contentHash.length===0&&i.push(H({code:`extension-hash-mismatch`,path:`${r}.contentHash`,message:`a resource carries its content hash`})),n.byteLength!==void 0&&(!Number.isInteger(n.byteLength)||n.byteLength<0)&&i.push(H({code:`value-not-finite`,path:`${r}.byteLength`,message:`byteLength is a non-negative integer`}))}i.push(...ka(e,l.flatMap(e=>e.relationTypes.map(t=>({profile:e.id,declaration:t})))));for(let n of l)i.push(...Aa(e,n,t,c,s(n.id)));i.push(...Ja(e));for(let t of l){let n=Object.values(e.entities).filter(e=>e.profile===t.id).length,r=Object.values(e.relations).filter(e=>e.profile===t.id).length;t.limits.maxEntities!==void 0&&n>t.limits.maxEntities&&i.push(H({code:`limit-exceeded`,path:`entities`,message:`${n} entities of profile ${t.id}; the declared limit is ${t.limits.maxEntities}`,details:{limit:`maxEntities`,seen:n,max:t.limits.maxEntities}})),t.limits.maxRelations!==void 0&&r>t.limits.maxRelations&&i.push(H({code:`limit-exceeded`,path:`relations`,message:`${r} relations of profile ${t.id}; the declared limit is ${t.limits.maxRelations}`,details:{limit:`maxRelations`,seen:r,max:t.limits.maxRelations}}))}let d=Dn(e,`document`);return d.ok||i.push(...d.diagnostics),i}var Qa={camera:{x:0,y:0,zoom:1}};function $a(e){return{viewId:e.viewId,semanticDocumentId:e.semanticDocumentId,revision:e.revision??0,entityOccurrences:{},relationOccurrences:{},portOccurrences:{},groups:{},filters:[],presentation:e.presentation??Qa}}var eo=(e,t)=>e<t?-1:+(e>t);function to(e){let t=new Map,n=Object.values(e.entities).filter(e=>e.type===`flow-scenario`).sort((e,t)=>eo(e.id,t.id));for(let e of n){let n=e.attributes.name,r=e.attributes.order;t.set(e.id,{id:e.id,label:n?.kind===`text`?n.value:e.id,...r?.kind===`quantity`?{order:r.value}:{},steps:[]})}let r={},i={};for(let n of Object.values(e.relations).filter(e=>e.type===`flow-step`).sort((e,t)=>eo(e.id,t.id))){let r=n.attributes,i=r.step;if(i?.kind!==`quantity`||!Number.isInteger(i.value)||i.value<1||i.value>999)continue;let a=t=>{let r=n.endpoints.find(e=>e.role===t)?.target;return r?.startsWith(`port:`)?e.ports[r]?.owner:r?.startsWith(`entity:`)?r:void 0},o=a(`source`),s=a(`target`);if(o===void 0||s===void 0)continue;let c=r.scenario?.kind===`reference`?r.scenario.value:``;c===``&&!t.has(``)&&t.set(``,{id:``,label:``,steps:[]});let l=t.get(c);if(l===void 0)continue;let u=r.branch?.kind===`text`?r.branch.value:void 0,d=r.label?.kind===`text`?r.label.value:void 0,f=r.kind?.kind===`enum`?r.kind.value:void 0,p=r.realises?.kind===`text`?r.realises.value:void 0;l.steps.push({relation:n.id,scenario:c,step:i.value,...u===void 0?{}:{branch:u},ordinal:0,badge:String(i.value)+(u??``),source:o,target:s,self:o===s,...d===void 0?{}:{label:d},...f===void 0?{}:{kind:f},...p===void 0?{}:{realises:p}})}let a=[...t.values()].sort((e,t)=>e.id===``?-1:t.id===``?1:(e.order??1/0)-(t.order??1/0)||eo(e.id,t.id));for(let e of a){e.steps.sort((e,t)=>e.step-t.step||eo(e.branch??``,t.branch??``)||eo(e.relation,t.relation)),e.steps=e.steps.map((e,t)=>({...e,ordinal:t}));for(let t of e.steps){r[t.relation]=t;for(let e of new Set([t.source,t.target]))(i[e]??=[]).push(t.relation)}}return{scenarios:a,byRelation:r,byEntity:i}}function no(e){let t=[],n=new Map,r=new Set,i=new Set(Object.values(e.entities).filter(e=>e.type===`flow-scenario`).map(e=>e.id)),a=(e,n,r=`error`)=>{t.push(H({code:e,path:`relations.`+n,refs:[n],severity:r,message:e}))};for(let t of Object.values(e.relations).sort((e,t)=>eo(e.id,t.id))){for(let n of t.endpoints){let r=n.target.startsWith(`port:`)?e.ports[n.target]?.owner:n.target;r!==void 0&&i.has(r)&&(a(`flow-scenario-misused`,t.id),t.type===`flow-step`&&a(`flow-step-end-invalid`,t.id))}if(t.type!==`flow-step`)continue;let o=t.attributes.step;if(o===void 0){a(`flow-step-missing`,t.id);continue}if(o.kind!==`quantity`)continue;let s=t.attributes.scenario,c=s?.kind===`reference`?s.value:``;c!==``&&!i.has(c)&&a(`flow-scenario-unknown`,t.id);let l=t.attributes.branch,u=JSON.stringify([c,o.value,l?.kind===`text`?l.value:``]);r.has(u)&&a(`flow-step-duplicate`,t.id),r.add(u);let d=JSON.stringify([c,o.value]),f=n.get(d)??[];f.push(t),n.set(d,f)}for(let e of n.values()){e.length>26&&a(`flow-branch-overflow`,e[0].id);for(let t of e)e.length===1==(t.attributes.branch!==void 0)&&a(`flow-branch-without-sibling`,t.id,`warning`)}let o=new Map;for(let e of n.values()){let t=e[0],n=t.attributes.scenario,r=n?.kind===`reference`?n.value:``,i=t.attributes.step;i?.kind===`quantity`&&(o.get(r)??o.set(r,new Set).get(r)).add(i.value)}for(let[e,n]of o)[...n].sort((e,t)=>e-t).some((e,t)=>e!==t+1)&&t.push(H({code:`flow-step-gap`,severity:`warning`,path:`flows.`+e,message:`step numbers are not consecutive from 1`}));return t}var ro=e=>Bt(`e.`+e.slice(7)),io=(e,t=`east`)=>Bt(`p.`+t+`.`+e.slice(5));Object.keys({"endpoint-hidden":!0,"filtered-out":!0,"geometry-not-finite":!0,"group-collapsed":!0,"not-included":!0,"owner-hidden":!0,"unresolved-reference":!0}).sort();function ao(e){return e.kind===`collection`?e.items.map(e=>String(e.value)):e.kind===`struct`?[]:[String(e.value)]}function oo(e,t,n){let r=e[t];return r!==void 0&&ao(r).includes(n)}var so={visible:!0};function co(e,t){let n=0,r=!1;for(let i of e)if(i.mode===`exclude`){if(t(i))return{visible:!1,reason:`filtered-out`,cause:i.id}}else n+=1,t(i)&&(r=!0);return n>0&&!r?{visible:!1,reason:`not-included`}:so}function lo(e){for(let t of e)if(!t.visible)return t;return so}function uo(e,t){return(e.filters??[]).filter(e=>e.kind===t)}function fo(e,t){return lo([co(uo(e,`entity-type`),e=>e.kind===`entity-type`&&e.types.includes(t.type)),co(uo(e,`attribute-equals`),e=>e.kind===`attribute-equals`&&oo(t.attributes,e.attribute,e.value))])}function po(e,t,n){let r=n?.typeDefinitions?.[t.type];return lo([co(uo(e,`relation-type`),e=>e.kind===`relation-type`?e.types.includes(t.type)||r?.profile===t.profile&&e.types.includes(r.baseType):!1),co(uo(e,`attribute-equals`),e=>e.kind===`attribute-equals`&&oo(t.attributes,e.attribute,e.value))])}function mo(e,t){let n=new Set,r=t;for(;r!==void 0&&!n.has(r);){n.add(r);let t=e.entityOccurrences[r];if(t===void 0||t.group===void 0)return;let i=e.groups[t.group];if(i===void 0)return;if(i.collapsed===!0)return i.id;r=i.occurrence}}function ho({document:e,view:t}){let n=new Set,r=[];for(let i of Object.keys(t.entityOccurrences).sort()){let a=t.entityOccurrences[i],o=e.entities[a.entity];if(o===void 0){r.push({occurrence:a.id,kind:`entity`,reason:`unresolved-reference`,cause:a.entity});continue}let s=mo(t,a.id);if(s!==void 0){r.push({occurrence:a.id,kind:`entity`,reason:`group-collapsed`,cause:s});continue}let c=fo(t,o);c.visible?n.add(a.id):r.push({occurrence:a.id,kind:`entity`,reason:c.reason,...c.cause===void 0?{}:{cause:c.cause}})}for(let i of Object.keys(t.portOccurrences).sort()){let a=t.portOccurrences[i];e.ports[a.port]===void 0?r.push({occurrence:a.id,kind:`port`,reason:`unresolved-reference`,cause:a.port}):e.ports[a.port]?.profile===`erd@1`&&Object.values(t.groups).some(e=>e.occurrence===a.ownerOccurrence&&e.collapsed)||!n.has(a.ownerOccurrence)?r.push({occurrence:a.id,kind:`port`,reason:`owner-hidden`,cause:a.ownerOccurrence}):n.add(a.id)}for(let i of Object.keys(t.relationOccurrences).sort()){let a=t.relationOccurrences[i],o=e.relations[a.relation];if(o===void 0){r.push({occurrence:a.id,kind:`relation`,reason:`unresolved-reference`,cause:a.relation});continue}let s=po(t,o,e);if(!s.visible){r.push({occurrence:a.id,kind:`relation`,reason:s.reason,...s.cause===void 0?{}:{cause:s.cause}});continue}let c=a.endpoints.find(e=>!n.has(e.occurrence));c===void 0?n.add(a.id):r.push({occurrence:a.id,kind:`relation`,reason:`endpoint-hidden`,cause:c.occurrence})}return r.sort((e,t)=>e.occurrence<t.occurrence?-1:+(e.occurrence>t.occurrence)),{visible:n,exclusions:r}}function go(e){return{x:e.width<0?e.x+e.width:e.x,y:e.height<0?e.y+e.height:e.y,width:Math.abs(e.width),height:Math.abs(e.height)}}function _o(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height)}function vo(e,t){let n=go(e),r=go(t);return n.x<r.x+r.width&&r.x<n.x+n.width&&n.y<r.y+r.height&&r.y<n.y+n.height}function yo(e,t){let n=go(e),r=go(t),i=Math.min(n.x,r.x),a=Math.min(n.y,r.y);return{x:i,y:a,width:Math.max(n.x+n.width,r.x+r.width)-i,height:Math.max(n.y+n.height,r.y+r.height)-a}}function bo(e){if(e.length===0)return;let t=e[0].x,n=e[0].y,r=t,i=n;for(let a of e)a.x<t&&(t=a.x),a.x>r&&(r=a.x),a.y<n&&(n=a.y),a.y>i&&(i=a.y);return{x:t,y:n,width:r-t,height:i-n}}function xo(e){let t=go(e);return{x:t.x+t.width/2,y:t.y+t.height/2}}var So={edge:0,node:1,port:2};function Co(e,t,n){let r=go(e),i=n<0?0:n>1?1:n;switch(t){case`north`:return{x:r.x+i*r.width,y:r.y};case`south`:return{x:r.x+i*r.width,y:r.y+r.height};case`east`:return{x:r.x+r.width,y:r.y+i*r.height};case`west`:return{x:r.x,y:r.y+i*r.height}}}function wo(e,t){return{x:e.x-t/2,y:e.y-t/2,width:t,height:t}}var To=class extends Error{view;constructor(e){super(`view ${e} is not in this state`),this.name=`UnknownViewError`,this.view=e}};function Eo(e,t,n={}){let r=e.views[t];if(r===void 0)throw new To(t);let i=n.portSize??8,{visible:a,exclusions:o}=ho({document:e.document,view:r}),s=[...o],c=[],l=new Map;for(let e of Object.keys(r.entityOccurrences).sort()){let t=r.entityOccurrences[e];a.has(t.id)&&(_o(t.geometry)?l.set(t.id,{kind:`node`,occurrence:t.id,entity:t.entity,rect:go(t.geometry),z:t.z??0,...t.group===void 0?{}:{group:t.group}}):(s.push({occurrence:t.id,kind:`entity`,reason:`geometry-not-finite`}),c.push(H({code:`value-not-finite`,path:`entityOccurrences.${e}.geometry`,message:`a scene cannot place a non-finite rectangle (study invariant 8)`,refs:[t.id]}))))}let u=new Map;for(let e of Object.keys(r.portOccurrences).sort()){let t=r.portOccurrences[e];if(!a.has(t.id))continue;let n=l.get(t.ownerOccurrence);if(n===void 0){s.push({occurrence:t.id,kind:`port`,reason:`owner-hidden`,cause:t.ownerOccurrence});continue}if(!Number.isFinite(t.anchor)||!Number.isFinite(t.order)){s.push({occurrence:t.id,kind:`port`,reason:`geometry-not-finite`}),c.push(H({code:`value-not-finite`,path:`portOccurrences.${e}`,message:`a port needs a finite anchor and order to be placed`,refs:[t.id]}));continue}let o=Co(n.rect,t.side,t.anchor);u.set(t.id,{kind:`port`,occurrence:t.id,port:t.port,ownerOccurrence:t.ownerOccurrence,side:t.side,order:t.order,anchorPoint:o,rect:wo(o,i),z:n.z})}let d=[];for(let e of Object.keys(r.relationOccurrences).sort()){let t=r.relationOccurrences[e];if(!a.has(t.id))continue;let n=[...t.endpoints].sort((e,t)=>e.role<t.role?-1:e.role>t.role?1:e.occurrence<t.occurrence?-1:1),i=[],o=[],f;for(let e of n){let t=u.get(e.occurrence);if(t!==void 0){i.push(t.anchorPoint),o.push(t.z);continue}let n=l.get(e.occurrence);if(n!==void 0)i.push(xo(n.rect)),o.push(n.z);else{f=e.occurrence;break}}if(f!==void 0){s.push({occurrence:t.id,kind:`relation`,reason:`endpoint-hidden`,cause:f});continue}let p=(t.waypoints??[]).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));(t.waypoints??[]).length!==p.length&&c.push(H({code:`value-not-finite`,path:`relationOccurrences.${e}.waypoints`,message:`a non-finite waypoint is dropped from the route and reported`,refs:[t.id]}));let m=i.length<=1?i:[i[0],...p.map(e=>({x:e.x,y:e.y})),...i.slice(1)],h=bo(m);h===void 0?s.push({occurrence:t.id,kind:`relation`,reason:`geometry-not-finite`}):(o.length===0&&(o=[0]),d.push({kind:`edge`,occurrence:t.id,relation:t.relation,path:m,bounds:h,z:Math.min(...o)}))}let f=[...d,...l.values(),...u.values()].sort(Do),p;for(let e of f){let t=e.kind===`edge`?e.bounds:e.rect;p=p===void 0?t:yo(p,t)}s.sort((e,t)=>e.occurrence<t.occurrence?-1:e.occurrence>t.occurrence?1:e.reason<t.reason?-1:1);let m={view:r.viewId,semanticDocument:r.semanticDocumentId,documentRevision:e.document.revision,viewRevision:r.revision,items:f,...p===void 0?{}:{bounds:p},exclusions:s,diagnostics:c};return{sceneRevision:nn(On(m,`scene`)),...m}}function Do(e,t){if(e.z!==t.z)return e.z-t.z;let n=So[e.kind]-So[t.kind];return n===0?e.kind===`port`&&t.kind===`port`&&e.order!==t.order?e.order-t.order:e.occurrence<t.occurrence?-1:+(e.occurrence>t.occurrence):n}var Oo=e=>e.items.filter(e=>e.kind===`node`),ko=.45;function Ao(e,t){let n=e[t],r=e[t+1];return Math.abs(r.x-n.x)+Math.abs(r.y-n.y)}function jo(e,t,n){let r=e[t],i=e[t+1],a={x:(r.x+i.x)/2,y:(r.y+i.y)/2};return{segment:t,centre:a,box:{x:a.x-n.width/2,y:a.y-n.height/2,width:n.width,height:n.height}}}function Mo(e){let t=e.slice(1).map((e,t)=>t);return t.sort((t,n)=>Ao(e,n)-Ao(e,t)||t-n),t}function No(e,t){let n=Mo(e)[0];if(n!==void 0)return jo(e,n,t)}function Po(e,t,n){let r=new Map,i=[];for(let a of e){let e;for(let r of Mo(a.route)){let o=jo(a.route,r,a.size);if(Fo(o,a.route,r,a.size,t,i,n)){e=o;break}}r.set(a.id,e),e!==void 0&&i.push(e.box)}return r}function Fo(e,t,n,r,i,a,o){let s=t[n],c=t[n+1],l=s.y===c.y?r.width:r.height;if(Ao(t,n)<l+2*o)return!1;let u=Io(e.box,o);return!i.some(e=>vo(e,u))&&!a.some(e=>vo(e,u))}function Io(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Lo(e,t){let n=e.relationOccurrences[t];if(n===void 0)return;let r=[...n.endpoints].sort((e,t)=>e.role<t.role?-1:+(e.role>t.role)),i=t=>{let n=e.portOccurrences[t];if(n===void 0)return[];let r=e.entityOccurrences[n.ownerOccurrence];return r===void 0?[]:[Co(r.geometry,n.side,n.anchor)]},a=r[0],o=r[r.length-1];return[...a===void 0?[]:i(a.occurrence),...(n.waypoints??[]).map(e=>({x:e.x,y:e.y})),...o===void 0||o===a?[]:i(o.occurrence)]}function Ro(e,t,n,r,i=r){let{width:a,height:o}=e.size;for(let s of e.segmentOrder===`route-order`?e.route.slice(1).map((e,t)=>t):Mo(e.route)){let c=e.route[s],l=e.route[s+1],u=c.y===l.y;if(!u&&c.x!==l.x)continue;let d={x:(c.x+l.x)/2,y:(c.y+l.y)/2},f=r,p=i,m=u?f:p,h=u?p:f,g=u?a/4:Math.max(0,a/2-r),_=u?Math.max(0,o/2-r):o/4,v=[Math.min(c.x,l.x)-g,Math.max(c.x,l.x)+g],y=[Math.min(c.y,l.y)-_,Math.max(c.y,l.y)+_],b={x:v[0]-a/2-m,y:y[0]-o/2-h,width:v[1]-v[0]+a+2*m,height:y[1]-y[0]+o+2*h},x=[...t,...n].filter(e=>vo(e,b)),S=new Set([d.x,v[0],v[1]]),C=new Set([d.y,y[0],y[1]]);for(let e of x)S.add(e.x+e.width+m+a/2),S.add(e.x-m-a/2),C.add(e.y+e.height+h+o/2),C.add(e.y-h-o/2);let w=[e.within,e.limit].filter(e=>e!==void 0);for(let e of w)S.add(e.x+a/2),S.add(e.x+e.width-a/2),C.add(e.y+o/2),C.add(e.y+e.height-o/2);let T=(e,t)=>[...e].filter(e=>e>=t[0]&&e<=t[1]),E=[];for(let e of T(S,v))for(let t of T(C,y)){let n=Math.abs(e-d.x),r=Math.abs(t-d.y);E.push({x:e,y:t,cost:n+r,across:u?r:n})}E.sort((e,t)=>e.cost-t.cost||e.across-t.across||e.x-t.x||e.y-t.y);for(let e of E){let t={x:e.x-a/2,y:e.y-o/2,width:a,height:o};if(w.some(e=>t.x<e.x||t.y<e.y||t.x+t.width>e.x+e.width||t.y+t.height>e.y+e.height))continue;let n={x:t.x-m,y:t.y-h,width:a+2*m,height:o+2*h};if(!x.some(e=>vo(e,n)))return{segment:s,centre:{x:e.x,y:e.y},box:t}}}}var zo=Object.freeze({flowBadgeSize:28,flowBadgePaddingX:6,flowArrowLength:10,flowArrowWidth:10,flowTargetMinSize:24,flowFanOutMax:4,flowArrowPath:`M0 0L10 5L0 10Z`}),Bo=(e,t)=>e<t?-1:+(e>t);function Vo(e,t,n,r,i){let a=to(e),o={},s=new Set,c=new Map,l=[],u=new Map,d=a.scenarios.flatMap(e=>e.steps),f=new Map(d.map((e,t)=>[e.relation,t])),p=ho({document:e,view:t}).visible,m=new Set(r.collapsed??Object.values(t.groups).filter(e=>e.collapsed).map(e=>e.occurrence)),h=e=>ea(t,m,t.portOccurrences[e]?.ownerOccurrence??e);for(let n of Object.values(t.relationOccurrences).sort((e,t)=>(f.get(e.relation)??1/0)-(f.get(t.relation)??1/0)||Bo(e.id,t.id))){let r=a.byRelation[n.relation];if(r===void 0||(s.add(n.id),!po(t,e.relations[n.relation],e).visible))continue;let i=n.endpoints.find(e=>e.role===`source`),d=n.endpoints.find(e=>e.role===`target`);if(i===void 0||d===void 0)continue;let m=h(i.occurrence),g=h(d.occurrence);if(!p.has(m)||!p.has(g))continue;if(m===g||r.self){s.add(n.id),o[r.relation]={kind:`internal`,box:m};continue}let _=`flow:`+[m,g].sort().join(`|`)+`|`+(n.strokeStyle??`solid`),v={occurrence:n.id,step:r,source:m,target:g,retargeted:n.endpoints.some(e=>e.semanticTarget!==void 0),key:_,rank:f.get(r.relation)};s.delete(n.id),l.push(v),c.set(n.id,v.rank),(u.get(_)??u.set(_,[]).get(_)).push(v),o[r.relation]={kind:`edge`,occurrence:n.id,badge:!1}}let g=[],_=l.length===0?new Map:_a(t,e,{registry:n}),v=r.flows?.fanOutMax??r.flowTokens?.flowFanOutMax??zo.flowFanOutMax;for(let[e,t]of u){let n=t.length>=2&&t.some(e=>e.retargeted)?`fold`:t.length>v?`fan-out`:t.length>=2&&i.has(e)?`obstructed`:void 0;if(n===void 0)continue;let r=t[0],a=t.map(e=>({occurrence:e.occurrence,relation:e.step.relation,direction:e.source===r.source?`forward`:`backward`,source:e.step.source,target:e.step.target})),c={id:e,reason:n,carrier:r.occurrence,members:a,forward:a.filter(e=>e.direction===`forward`).length,backward:a.filter(e=>e.direction===`backward`).length,summaries:[..._].filter(([,e])=>e.members.some(e=>t.some(t=>t.occurrence===e))).map(([,e])=>e.definitionId).sort(Bo)};g.push(c);for(let n of t)n!==r&&s.add(n.occurrence),o[n.step.relation]={kind:`bundle`,id:e,occurrence:r.occurrence,badge:!1}}return{index:a,members:l,groups:u,bundles:g,suppressed:s,targets:o,ranks:c}}function Ho(e,t,n){let r=t?[...e].reverse():e,i=r.at(-1);if(i===void 0)return;let a=[...r].reverse().find(e=>e.x!==i.x||e.y!==i.y);if(a===void 0)return;let o=a.y===i.y?a.x<i.x?0:180:a.y<i.y?90:270,s=n.flowArrowLength,c=n.flowArrowWidth;return{tip:i,angle:o,box:o===0?{x:i.x-s,y:i.y-c/2,width:s,height:c}:o===180?{x:i.x,y:i.y-c/2,width:s,height:c}:o===90?{x:i.x-c/2,y:i.y-s,width:c,height:s}:{x:i.x-c/2,y:i.y,width:c,height:s}}}function Uo(e){let{plan:t}=e,n={...zo,...e.options.flowTokens},r={},i={},a={...t.targets},o=[],s=[];for(let i of t.members){if(t.suppressed.has(i.occurrence))continue;let a=e.routes.get(i.occurrence);if(a===void 0)continue;let o=t.bundles.find(e=>e.carrier===i.occurrence),c=Ho(a,!1,n),l=o!==void 0&&o.backward>0?Ho(a,!0,n):void 0;r[i.occurrence]=[c,l].filter(e=>e!==void 0),s.push(...r[i.occurrence].map(e=>e.box))}for(let r of t.members){if(t.suppressed.has(r.occurrence))continue;let c=e.routes.get(r.occurrence);if(c===void 0)continue;let l=t.bundles.find(e=>e.carrier===r.occurrence),u=l===void 0?r.step.badge:(e.options.flows?.countTemplate??`{n}`).replaceAll(`{n}`,String(l.members.length)),d=e.measure({text:u,role:`flow-badge`,availableWidth:2**53-1,allocatedLines:1,folded:!1}),f={width:Math.max(n.flowBadgeSize,d.width+2*n.flowBadgePaddingX),height:n.flowBadgeSize},p=e.within.get(r.occurrence),m=Ro({id:r.occurrence,route:c,size:f,segmentOrder:`route-order`,...p===void 0?{}:{within:p},...e.limit===void 0?{}:{limit:e.limit}},e.shapes,s,e.margin);m===void 0?o.push({code:`badge-unplaced`,refs:[r.occurrence],message:`no segment holds the flow badge`}):(i[r.occurrence]=m.box,s.push(m.box));for(let e of l?.members??[{relation:r.step.relation}]){let t=a[e.relation];t!==void 0&&t.kind!==`internal`&&(a[e.relation]={...t,badge:m!==void 0})}}for(let e of t.bundles)o.push({code:`flow-bundled`,refs:e.members.map(e=>e.occurrence),message:e.reason});return{arrows:r,badges:i,targets:a,warnings:o,taken:s}}Object.freeze({selection:null,hover:null,focus:null,muted:!1});var Wo=Object.freeze({step:`Step`,scenario:`Scenario`,count:`{n}`,node:`Component`,navigator:`Flow navigation`,previous:`Previous step`,next:`Next step`,allScenarios:`All scenarios`}),Go={width:460,headerHeight:64,rowHeight:32,lineHeight:24,padding:12,keyWidth:56,nameWidth:170,typeWidth:170,fontSize:18,titleFontSize:24,markerLength:24,markerHalfWidth:8,markerRadius:4,markerGap:4,strokeWidth:1.5,gapInline:160,gapBlock:120,labelWidth:240},Ko=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`);function qo(e,t){let n=e[t];return n&&`value`in n?String(n.value):``}var Jo=(e,t)=>e.attributes[t]?.kind===`boolean`&&e.attributes[t].value===!0;function Yo(e,t){return Object.values(e.ports).filter(e=>e.owner===t).sort((e,t)=>Number(qo(e.attributes,`ordinal`))-Number(qo(t.attributes,`ordinal`))||(e.id<t.id?-1:1))}function Xo(e,t,n,r=Go.fontSize){let i=e=>Math.max(Array.from(e).length*r*.6,n?n({text:e,role:`edge-label`,availableWidth:2**53-1,allocatedLines:1,folded:!1}).width*r/Go.fontSize:0),a=[],o=``;for(let n of e.replace(/([a-z0-9])([A-Z])/g,`$1$2`).split(/(?<=[_|(),.s])/u)){let e=n.replaceAll(``,``);o&&i(o+e)>t&&(a.push(o),o=``);for(let n of e)o&&i(o+n)>t&&(a.push(o),o=``),o+=n}return(o||!a.length)&&a.push(o),a}function Zo(e,t,n=!1,r){let i=Go,a=qo(e.entities[t].attributes,`name`),o=Xo(a,i.width-2*i.padding-i.titleFontSize,r,i.titleFontSize),s=Math.max(i.headerHeight,o.length*i.lineHeight+2*i.padding),c=s,l=n?[]:Yo(e,t).map(t=>{let n=Xo(t.name,i.nameWidth,r),a=Xo(qo(t.attributes,`dataType`),i.typeWidth,r),o=e.ports[qo(t.attributes,`fk`)],s=o?Xo(`→ `+qo(e.entities[o.owner].attributes,`name`)+`.`+o.name,i.width-2*i.padding,r):[],l=Math.max(i.rowHeight,(Math.max(n.length,a.length)+s.length)*i.lineHeight+i.padding),u={field:t,y:c,height:l,name:n,type:a,fk:s};return c+=l,u});return{title:a,titleLines:o,width:i.width,height:c,headerHeight:s,rows:l,collapsed:n}}function Qo(e){let t=Go,n=(e,n,r,i=`fontSize`,a=``)=>e.map((e,o)=>`<text x="`+n+`" y="`+(r+o*t.lineHeight)+`" font-size="var(--st-component-diagramErd-`+i+`)"`+a+`>`+Ko(e)+`</text>`).join(``),r=`<rect width="`+e.width+`" height="`+e.height+`" fill="var(--st-semantic-surface-default)" stroke="var(--st-semantic-border-strong)" stroke-width="var(--st-component-diagramErd-strokeWidth)"/>`+n(e.titleLines,t.padding,t.padding+t.lineHeight,`titleFontSize`);r+=n([e.collapsed?`+`:`−`],e.width-t.padding,t.padding+t.lineHeight,`titleFontSize`,` data-erd-fold-indicator="" text-anchor="end"`);for(let i of e.rows)r+=`<g data-erd-field="`+Ko(i.field.id)+`"><path d="M0 `+i.y+`H`+e.width+`" stroke="var(--st-semantic-border-strong)" stroke-width="var(--st-component-diagramErd-strokeWidth)"/>`,r+=n([[Jo(i.field,`pk`)?`PK`:``,i.field.attributes.fk?`FK`:``].filter(Boolean).join(`/`)],t.padding,i.y+t.lineHeight),r+=n(i.name,t.padding+t.keyWidth,i.y+t.lineHeight)+n(i.type,t.padding+t.keyWidth+t.nameWidth,i.y+t.lineHeight),r+=n([Jo(i.field,`nullable`)?`?`:`NN`],e.width-t.padding,i.y+t.lineHeight,`fontSize`,` text-anchor="end"`),r+=n(i.fk,t.padding,i.y+(Math.max(i.name.length,i.type.length)+1)*t.lineHeight)+`</g>`;return`<svg xmlns="http://www.w3.org/2000/svg" class="st-diagramErdCard" aria-hidden="true" width="100%" height="100%" viewBox="0 0 `+e.width+` `+e.height+`" style="color:var(--st-semantic-text-primary);font-family:var(--st-component-diagramErd-fontFamily);fill:currentColor">`+r+`</svg>`}function $o(e,t,n,r=Go){let i=Math.hypot(n.x,n.y)||1,a=n.x/i,o=n.y/i,s=(e,n)=>({x:t.x+a*e-o*n,y:t.y+o*e+a*n}),c=r.markerLength,l=r.markerHalfWidth,u=r.markerGap,d=e.endsWith(`n`),f=e.startsWith(`0`),p=d?[[s(c/2,0),s(u,-l)],[s(c/2,0),s(u,0)],[s(c/2,0),s(u,l)]]:[[s(u,-l),s(u,l)]];return f||p.push([s(c-u,-l),s(c-u,l)]),{lines:p,...f?{circle:{center:s(c-r.markerRadius,0),radius:r.markerRadius}}:{}}}function es(e,t,n){let r=$o(e,t,n);return`<g data-erd-marker="`+e+`" stroke="var(--st-semantic-border-strong)" stroke-width="var(--st-component-diagramErd-strokeWidth)" fill="none">`+r.lines.map(([e,t])=>`<path d="M`+e.x+` `+e.y+`L`+t.x+` `+t.y+`"/>`).join(``)+(r.circle?`<circle cx="`+r.circle.center.x+`" cy="`+r.circle.center.y+`" r="`+r.circle.radius+`" fill="var(--st-semantic-surface-default)"/>`:``)+`</g>`}function ts(e,t,n){let r=new Map,i=[...t],a=Po(e,t,n);for(let t of e){let e=a.get(t.id);e&&(r.set(t.id,{box:e.box}),i.push(e.box))}let o=e=>i.every(t=>!vo({x:e.x-n,y:e.y-n,width:e.width+2*n,height:e.height+2*n},t));for(let t of e){if(r.has(t.id))continue;let e=No(t.route,t.size);if(!e)continue;let n;for(let t=1;t<=64&&!n;t++)for(let[r,i]of[[0,-1],[0,1],[-1,0],[1,0],[-1,-1],[1,-1],[-1,1],[1,1]]){let a={...e.box,x:e.box.x+r*t*Go.rowHeight,y:e.box.y+i*t*Go.rowHeight};if(o(a)){n=a;break}}n||={...e.box,x:Math.max(0,...i.map(e=>e.x+e.width))+Go.padding};let a={x:Math.max(n.x,Math.min(e.centre.x,n.x+n.width)),y:Math.max(n.y,Math.min(e.centre.y,n.y+n.height))};r.set(t.id,{box:n,leader:[e.centre,a]}),i.push(n)}return r}var ns=.3,rs=.85,is=16/9;function as(e,t){if(!(t>0)||!Number.isFinite(t)||!Number.isFinite(e))return e;let n=1/t,r=Math.floor(e*n);return r/n>e?--r:(r+1)/n<=e&&(r+=1),r/n}function os(e,t,n=!1){return n?{width:e,height:Number.isFinite(t)?Math.max(0,t-24):e/is}:{width:e,height:Math.min(e/is,rs*t)}}function ss(e){let t=Math.max(ns,e.maxDisplayScale??.62),n=Math.min(t,Math.max(ns,e.minReadableScale??.3)),r=e.viewHeight!==void 0&&Number.isFinite(e.viewHeight)&&e.viewHeight>=0,i=r?{width:e.viewWidth,height:e.viewHeight}:os(e.viewWidth,e.windowHeight,e.fitToWindow??!1),a={width:i.width,height:Math.max(0,i.height-(e.scrollbarHeight??0))},o=e.bounds;if(o===void 0||!(o.width>0)||!(o.height>0))return{fitWidth:a.width,fitHeight:a.height,zoomFit:t,zoom:t,minZoom:t,maxZoom:t,pans:!1};let s=Math.min(Math.max(0,a.width-2)/o.width,Math.max(0,a.height-2)/o.height,t),c=e.zoomQuantum===void 0||s>=t?s:as(s,e.zoomQuantum),l=e.unconstrained===!0||e.fitToWindow===!0?c>0?c:s>0?s:n:Math.max(n,c),u=r?a.height:Math.min(a.height,Math.ceil((o.height*l+2)*64)/64);return{fitWidth:a.width,fitHeight:u,zoomFit:s,zoom:l,minZoom:l,maxZoom:t,pans:l>s}}function cs(e,t,n){return e.entities?.[n]?.anatomy??t?.presentation?.entityAnatomy?.[n]??t?.presentation?.anatomy??`v1`}function ls(e,t,n){if(n?.profileRefs?.length===1&&n.profileRefs[0]===`erd@1`)return!1;let r=(t?.filters?.length??0)>0,i=t==null?[]:Object.values(t.relationOccurrences??{}).filter(e=>{if(e==null)return!1;if(!r)return!0;let i=n?.relations?.[e.relation];if(i!==void 0&&!po(t,i,n).visible)return!1;if(n?.entities!=null&&t.entityOccurrences!=null)for(let r of e.endpoints??[]){let e=t.portOccurrences?.[r.occurrence]?.ownerOccurrence??r.occurrence,i=t.entityOccurrences[e]?.entity,a=i===void 0?void 0:n.entities[i];if(a!==void 0&&!fo(t,a).visible)return!1}return!0});if(n!=null){let e=(t==null?Object.values(n.relations??{}):i.map(e=>n.relations?.[e.relation])).flatMap(e=>e==null?[]:[e.type]);if(e.includes(`flow-step`)&&e.every(e=>e===`flow-step`||e===`contains`))return!1}let a=e??t?.presentation?.diagram;if(a!=null){let e=t?.entityOccurrences??a.entities;if(Object.keys(e??{}).some(e=>cs(a,t,e)===`v2`))return!0}if(t?.presentation?.anatomy===`v2`&&a==null)return!0;let o=e?.relations;if(t==null&&Object.keys(o??{}).length>0)return!0;let s=t?.presentation?.diagram?.contractPin,c=e?.contractPin,l=s===void 0&&(c===void 0||Xi(c));return i.some(e=>o?.[e.id]!=null||o?.[e.relation]!=null||e.strokeStyle===`dotted`||e.strokeStyle===`dashed`&&l||e.arrowhead!==void 0||e.emphasis!==void 0)}var us=`source-is-initiator`,ds=[`H2A`,`SENTROPIC`,`ENGRAM`,`DESIGN SYSTEM`,`SENTROPIC & 3RD PARTIES`,`SENTROPIC & TIERS`];function fs(e){return e.trim().replace(/\s+/g,` `).toUpperCase()}function ps(e){let t=new Set;for(let e of ds)t.add(fs(e));if(e!==void 0)for(let n of e)t.add(fs(n));return t}var ms=/^(?:(?=[A-Z0-9]*[A-Z])[A-Z0-9]{2,5}|[A-Z]{1,5}\d+[A-Z0-9]*)$/;function hs(e){if(e.length===0||/[a-z\u00e0-\u00ff]/.test(e)||!/[A-Z]/.test(e))return!1;let t=e.split(/[/-]+/).filter(e=>e.length>0);return t.length!==0&&t.every(e=>ms.test(e)||/^\d+$/.test(e))}function gs(e,t){let n=e.trim();if(n.length===0||ps(t).has(fs(n)))return!1;let r=n.split(/(?:\s+[—–-]\s+|\s*[·—–:|(),]+\s*|\s+)/).map(e=>e.trim()).filter(e=>e.length>0&&e!==`&`);return r.length!==0&&r.every(hs)}function _s(e){let t=e.trim();return t.startsWith(`entity:`)?t.slice(7):t.startsWith(`occurrence:e.`)?t.slice(13):t.startsWith(`occurrence:`)?t.slice(11):t}function vs(e,t){let n=e.trim(),r=_s(n);for(let e of t)if(e!==void 0&&(e===n||_s(e)===r))return!0;return!1}function ys(e){if(e===void 0)return;let t=e.attributes.initiator;if(t!==void 0&&t.kind===`text`&&t.value.trim().length>0)return t.value.trim()}function bs(e){let t=[];for(let n of e.edges){if(n.arrowhead===`none`)continue;let r=n.relationId===void 0?void 0:e.document?.relations[n.relationId],i=n.initiator??e.initiators?.[n.id]??(n.relationId===void 0?void 0:e.initiators?.[n.relationId])??ys(r);if(i===void 0||i.trim().length===0)continue;let a=[n.sourceEntity,n.sourceOccurrence,n.semanticSourceEntity],o=[n.targetEntity,n.targetOccurrence,n.semanticTargetEntity];if(vs(i,a))continue;let s=vs(i,o);t.push({severity:`info`,code:`arrow-direction-convention`,refs:[n.id],message:s?`edge ${n.id} points from ${n.sourceEntity} to ${n.targetEntity}, but ${i} is declared as initiator (convention: source = initiator)`:`edge ${n.id} declares initiator ${i} which does not match source ${n.sourceEntity} (convention: source = initiator)`,details:{convention:us,reason:s?`source-not-initiator`:`initiator-not-endpoint`,source:n.sourceEntity,target:n.targetEntity,initiator:i}})}return t}function xs(e){let t=[];for(let n of e.zones)n.tag!==void 0&&gs(n.tag,e.allowlist)&&t.push({severity:`info`,code:`zone-tag-opaque-acronym`,refs:[n.id],message:`zone ${n.id} uses opaque acronym tag "${n.tag.trim()}" without a descriptive label`,details:{zone:n.id,tag:n.tag.trim()}});return t}function Ss(e){let t=e.options;if(t===void 0)return[];let n=[];return t.arrowDirection===!0&&e.edges!==void 0&&n.push(...bs({...e.document===void 0?{}:{document:e.document},edges:e.edges,...t.initiators===void 0?{}:{initiators:t.initiators}})),t.zoneTagAcronyms===!0&&e.zones!==void 0&&n.push(...xs({zones:e.zones,...t.zoneTagAcronymAllowlist===void 0?{}:{allowlist:t.zoneTagAcronymAllowlist}})),n}function Cs(e,t,n=320,r=e.length){let i=(e,n)=>t({text:e,role:`edge-label`,availableWidth:n,allocatedLines:2**53-1,folded:!1}),a=`${r} liaisons`,o=i(a,n-8).height+8,s=e.map(e=>{let t=i(e,n-24),r={lines:t.lines,top:o,height:t.height+8};return o+=r.height,r});return{header:a,groups:s,layout:{lines:[a,...s.flatMap(e=>e.lines)],width:n,height:o,overflow:!1}}}function ws(e,t){return{gapMin:(t?e.gapMin:e.gapMinBlock)??(t?Ze.gapMin:Ze.gapMinBlock),gapBase:(t?e.gapBase:e.gapBaseBlock)??(t?Ze.gapBase:Ze.gapBaseBlock),trackSpacing:(t?e.trackSpacing:e.trackSpacingBlock)??(t?Ze.trackSpacing:Ze.trackSpacingBlock),labelBand:e.labelBand??Ze.labelBand,gapMax:(t?e.gapInlineMax:e.gapBlockMax)??e.gapMax??Ze.gapMax}}function Ts(e,t,n){return e===0?n.gapMin:Math.min(n.gapMax,Math.max(n.gapMin,n.gapBase+e*n.trackSpacing+(t?n.labelBand:0)))}function Es(e,t=Ze.routeSpacing,n=Ze.routeBorderClearance){let r=e-2*n;return r<0?0:t>0?Math.floor(r/t)+1:1}var Ds=Ze.routeSpacing,Os=Ze.routeBorderClearance,ks=1e-4;function As(e){let t=[];for(let n=0;n+1<e.length;n+=1){let r=e[n],i=e[n+1];Math.abs(r.x-i.x)<=ks&&Math.abs(r.y-i.y)<=ks||(Math.abs(r.y-i.y)<=ks?t.push({horizontal:!0,coord:(r.y+i.y)/2,lo:Math.min(r.x,i.x),hi:Math.max(r.x,i.x),index:n,a:r,b:i}):Math.abs(r.x-i.x)<=ks&&t.push({horizontal:!1,coord:(r.x+i.x)/2,lo:Math.min(r.y,i.y),hi:Math.max(r.y,i.y),index:n,a:r,b:i}))}return t}function js(e,t,n){let r=Math.min(e.x,t.x),i=Math.max(e.x,t.x),a=Math.min(e.y,t.y),o=Math.max(e.y,t.y),s=n.x+n.width,c=n.y+n.height,l=i<n.x?n.x-i:r>s?r-s:0,u=o<n.y?n.y-o:a>c?a-c:0;return Math.hypot(l,u)}function Ms(e,t,n){let r=n.x+n.width,i=n.y+n.height;if(Math.abs(e.y-t.y)<=ks&&Math.abs(e.x-t.x)>ks){let a=Math.min(e.x,t.x),o=Math.max(e.x,t.x),s=(e.y+t.y)/2,c=o<n.x?n.x-o:a>r?a-r:0;return Math.min(Math.hypot(c,Math.abs(s-n.y)),Math.hypot(c,Math.abs(s-i)))}if(Math.abs(e.x-t.x)<=ks&&Math.abs(e.y-t.y)>ks){let a=Math.min(e.y,t.y),o=Math.max(e.y,t.y),s=(e.x+t.x)/2,c=o<n.y?n.y-o:a>i?a-i:0;return Math.min(Math.hypot(Math.abs(s-n.x),c),Math.hypot(Math.abs(s-r),c))}return 1/0}function Ns(e,t){return Math.hypot(e.x-t.x,e.y-t.y)<=ks}function Ps(e,t,n,r,i,a){return!!(t===0&&i===0&&e.source===r.source&&e.sourcePort!==void 0&&e.sourcePort===r.sourcePort&&Ns(e.points[0],r.points[0])||t===n&&i===a&&e.target===r.target&&e.targetPort!==void 0&&e.targetPort===r.targetPort&&Ns(e.points.at(-1),r.points.at(-1))||t===0&&i===a&&e.source===r.target&&e.sourcePort!==void 0&&e.sourcePort===r.targetPort&&Ns(e.points[0],r.points.at(-1))||t===n&&i===0&&e.target===r.source&&e.targetPort!==void 0&&e.targetPort===r.sourcePort&&Ns(e.points.at(-1),r.points[0]))}function Fs(e){let t=e.routeSpacing??Ds,n=e.borderClearance??Os,r=[],i=e.routes.map(e=>({route:e,segments:As(e.points),elbows:e.points.length>2?e.points.slice(1,-1):[]}));for(let e=0;e<i.length;e+=1){let a=i[e],o=Math.max(0,a.route.points.length-2);for(let e=0;e<a.segments.length;e+=1){let n=a.segments[e];for(let i=e+2;i<a.segments.length;i+=1){let e=a.segments[i];if(n.horizontal!==e.horizontal||Math.min(n.hi,e.hi)-Math.max(n.lo,e.lo)<=ks)continue;let o=Math.abs(n.coord-e.coord);o<=ks?r.push({kind:`segment-overlap`,routes:[a.route.id],actual:0,required:t,message:`route ${a.route.id} folds back onto itself with overlapping segments`}):o<t-ks&&r.push({kind:`parallel-segment-spacing`,routes:[a.route.id],actual:Math.round(o*1e3)/1e3,required:t,message:`parallel segments of ${a.route.id} are ${o.toFixed(1)} apart (< ${t})`})}}for(let s=e+1;s<i.length;s+=1){let e=i[s],c=a.route.combGroupId!==void 0&&a.route.combGroupId===e.route.combGroupId,l=Math.max(0,e.route.points.length-2),u=!1,d=1/0;for(let r of a.segments)for(let i of e.segments){if(r.horizontal!==i.horizontal)continue;let s=Math.min(r.hi,i.hi)-Math.max(r.lo,i.lo);if(s<=ks)continue;let f=Math.abs(r.coord-i.coord);c&&f<=ks||s<=t+n+ks&&(o>0||l>0)&&Ps(a.route,r.index,o,e.route,i.index,l)||(f<=ks?u=!0:f<t-ks&&f<d&&(d=f))}u?r.push({kind:`segment-overlap`,routes:[a.route.id,e.route.id],actual:0,required:t,message:`routes ${a.route.id} and ${e.route.id} share an overlapping segment`}):d<t-ks&&r.push({kind:`parallel-segment-spacing`,routes:[a.route.id,e.route.id],actual:Math.round(d*1e3)/1e3,required:t,message:`parallel segments of ${a.route.id} and ${e.route.id} are ${d.toFixed(1)} apart (< ${t})`});let f=1/0;for(let t of a.elbows)for(let n of e.elbows){let e=Math.hypot(t.x-n.x,t.y-n.y);c&&e<=ks||e<f&&(f=e)}f<t-ks&&r.push({kind:`elbow-spacing`,routes:[a.route.id,e.route.id],actual:Math.round(f*1e3)/1e3,required:t,message:`neighbouring elbows of ${a.route.id} and ${e.route.id} are ${f.toFixed(1)} apart (< ${t})`})}}let a=new Map,o=[];for(let{route:e}of i){if(e.points.length<2)continue;let t=e.points[0],n=e.points[e.points.length-1],r=e.startArrowhead===!0,i=e.arrowhead!==`none`,s=e=>{let t=a.get(e.entity)??[];t.push(e),a.set(e.entity,t)},c={routeId:e.id,entity:e.source,point:t,port:e.sourcePort,isArrowhead:r,combGroupId:e.combGroupId},l={routeId:e.id,entity:e.target,point:n,port:e.targetPort,isArrowhead:i,combGroupId:e.combGroupId};s(c),s(l),r&&o.push(c),i&&o.push(l)}for(let[e,n]of a)for(let i=0;i<n.length;i+=1){let a=n[i];for(let o=i+1;o<n.length;o+=1){let i=n[o];if(a.port!==void 0&&a.port===i.port&&Ns(a.point,i.point)||a.combGroupId!==void 0&&a.combGroupId===i.combGroupId&&Ns(a.point,i.point)||a.isArrowhead&&i.isArrowhead)continue;let s=Math.hypot(a.point.x-i.point.x,a.point.y-i.point.y);s<t-ks&&r.push({kind:`port-spacing`,routes:a.routeId===i.routeId?[a.routeId]:[a.routeId,i.routeId],entity:e,actual:Math.round(s*1e3)/1e3,required:t,message:`ports on ${e} for ${a.routeId} and ${i.routeId} are ${s.toFixed(1)} apart (< ${t})`})}}for(let e=0;e<o.length;e+=1){let n=o[e];for(let i=e+1;i<o.length;i+=1){let e=o[i];if(n.entity===e.entity&&n.port!==void 0&&n.port===e.port&&Ns(n.point,e.point))continue;let a=Math.hypot(n.point.x-e.point.x,n.point.y-e.point.y);a<t-ks&&r.push({kind:`arrowhead-spacing`,routes:n.routeId===e.routeId?[n.routeId]:[n.routeId,e.routeId],...n.entity===e.entity?{entity:n.entity}:{},actual:Math.round(a*1e3)/1e3,required:t,message:`arrowheads of ${n.routeId} and ${e.routeId} are ${a.toFixed(1)} apart (< ${t})`})}}for(let{route:t,segments:a}of i){let i=Math.max(0,t.points.length-2);for(let[o,s]of e.rects){let e=t.passable?.has(o)===!0,c=1/0;for(let n of a){if(o===t.source&&n.index===0||o===t.target&&n.index===i)continue;let r=e?Ms(n.a,n.b,s):js(n.a,n.b,s);r<c&&(c=r)}c<n-ks&&r.push({kind:`link-to-border`,routes:[t.id],entity:o,actual:Math.round(c*1e3)/1e3,required:n,message:`route ${t.id} clears ${o} by ${c.toFixed(1)} (< ${n})`})}for(let o=0;o<(e.barriers?.length??0);o+=1){let s=e.barriers[o],c=`rect`in s?s.rect:s,l=`rect`in s?s.entity:void 0,u=1/0;for(let e of a){if(l!==void 0&&(l===t.source&&e.index===0||l===t.target&&e.index===i))continue;let n=js(e.a,e.b,c);n<u&&(u=n)}u<n-ks&&r.push({kind:`link-to-border`,routes:[t.id],entity:l??`barrier:${String(o)}`,actual:Math.round(u*1e3)/1e3,required:n,message:`route ${t.id} clears title barrier ${o} by ${u.toFixed(1)} (< ${n})`})}}let s={},c=[...e.rects.values()];for(let a of e.channels??[]){let e=Es(a.gap,t,n),o=a.axis===`vertical`,l=[],u=new Set,d=e=>{let t=o?e.y:e.x,n=o?e.y+e.height:e.x+e.width,r=o?e.x:e.y,i=o?e.x+e.width:e.y+e.height,a=[],s=[];for(let e of c){let c=o?e.y:e.x,l=o?e.y+e.height:e.x+e.width,u=o?e.x:e.y,d=o?e.x+e.width:e.y+e.height,f=Math.max(r,u),p=Math.min(i,d);p-f<=ks||(Math.abs(l-t)<=1&&a.push([f,p]),Math.abs(c-n)<=1&&s.push([f,p]))}if(a.length===0||s.length===0)return[[r,i]];let l=[];for(let[e,t]of a)for(let[n,r]of s){let i=Math.max(e,n),a=Math.min(t,r);a-i>ks&&l.push([i,a])}if(l.length===0)return[[r,i]];l.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let u=[l[0]];for(let e=1;e<l.length;e+=1){let t=u[u.length-1],n=l[e];n[0]<=t[1]+ks?t[1]=Math.max(t[1],n[1]):u.push([n[0],n[1]])}return u},f=new Map;for(let e of a.strips){let t=d(e);for(let{route:n,segments:r}of i)for(let i of r)if(i.horizontal===o&&(o?i.coord>=e.y-ks&&i.coord<=e.y+e.height+ks:i.coord>=e.x-ks&&i.coord<=e.x+e.width+ks))for(let[e,r]of t){let t=Math.max(i.lo,e),a=Math.min(i.hi,r);if(!(a-t<=ks)){if(u.add(n.id),n.combGroupId!==void 0){let e=`${n.combGroupId}|${String(Math.round(i.coord*100)/100)}`,r=f.get(e)??[];r.push([t,a]),f.set(e,r)}else l.push({pos:t,delta:1,routeId:n.id}),l.push({pos:a,delta:-1,routeId:n.id})}}}for(let[e,t]of f){t.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let n=[t[0]];for(let e=1;e<t.length;e+=1){let r=n[n.length-1],i=t[e];i[0]<=r[1]+ks?r[1]=Math.max(r[1],i[1]):n.push([i[0],i[1]])}for(let[t,r]of n)l.push({pos:t,delta:1,routeId:e}),l.push({pos:r,delta:-1,routeId:e})}l.sort((e,t)=>e.pos-t.pos||e.delta-t.delta);let p=0,m=0;for(let e of l)p+=e.delta,p>m&&(m=p);s[a.id]={capacity:e,demand:m,gap:a.gap},m>e&&r.push({kind:`channel-capacity-exceeded`,routes:[...u].sort(),channelId:a.id,actual:m,required:e,message:`channel ${a.id} (gap ${a.gap}) carries ${m} parallel tracks, exceeding capacity ${e}`})}return{conflictCount:r.length,conflicts:r,routeSpacing:t,borderClearance:n,channelCapacity:s}}function Is(e,t,n,r,i){let a=[],o=[],s=[],c=[],l=0,u=0;for(let i=0;i<e.length;i+=1){let d=e[i],f=c.length===0?d:l+r+d;c.length>0&&f>n+.5?(a.push(c),o.push(l),s.push(u),c=[i],l=d,u=t[i]):(c.push(i),l=f,u=Math.max(u,t[i]))}c.length>0&&(a.push(c),o.push(l),s.push(u));let d=Math.max(0,...o),f=0,p=0;return s.forEach((e,t)=>{f+=e+(t>0?i:0),p+=(d-o[t])*e}),{shelves:a,main:d,cross:f,slack:p}}function Ls(e,t,n,r){let i=e+r.chromeWidth,a=t+r.chromeHeight;if(i<=0||a<=0)return 0;let o=i/a/r.targetAspect,s=Math.abs(Math.log(o)),c=o<1?s*r.tallBias:s,l=e*t;return c+(l>0?r.emptyPenaltyWeight*(n/l):0)}function Rs(e,t,n){let r=e.length;if(r===0)return{width:0,height:0,rows:[],positions:[],score:0};let i=n===`rows`,a=e.map(e=>i?e.width:e.height),o=e.map(e=>i?e.height:e.width),s=i?t.gapX:t.gapY,c=i?t.gapY:t.gapX,l,u,d=new Set,f=0;for(let e=0;e<r;e+=1){f+=a[e]+(e>0?s:0);let n=Is(a,o,f,s,c),p=n.shelves.map(e=>e.length).join(`,`);if(d.has(p))continue;if(d.add(p),r>=2&&(i?n.shelves.length===r:n.shelves.length===1)){u??=n;continue}let m=i?n.main:n.cross,h=i?n.cross:n.main,g=r===1?0:Ls(m,h,n.slack,t);(l===void 0||g<l.score-1e-9||Math.abs(g-l.score)<=1e-9&&m>l.width)&&(l={shelves:n,score:g,width:m})}if(l===void 0){let e=u,n=i?e.main:e.cross;l={shelves:e,score:Ls(n,i?e.cross:e.main,e.slack,t),width:n}}let p=l.shelves,m=Array(r),h=0;return p.shelves.forEach((e,t)=>{let n=0,r=0;e.forEach((e,c)=>{m[e]=i?{x:n,y:h,row:t,col:c}:{x:h,y:n,row:t,col:c},n+=a[e]+s,r=Math.max(r,o[e])}),h+=r+c}),{width:i?p.main:p.cross,height:i?p.cross:p.main,rows:p.shelves,positions:m,score:l.score}}function zs(e,t){return Rs(e,t,`rows`)}function Bs(e,t){return Rs(e,t,`columns`)}function Vs(e,t,n,r,i){let a=n===`rows`,o=Array(e.length),s=0,c=0,l=0;return t.forEach((n,u)=>{let d=0,f=0;n.forEach((t,i)=>{let l=e[t];o[t]=a?{x:d,y:s}:{x:s,y:d};let p=a?l.width:l.height;c=Math.max(c,d+p),d+=p+(i+1<n.length?r(u,i):0),f=Math.max(f,a?l.height:l.width)}),l=s+f,s+=f+(u+1<t.length?i(u):0)}),{positions:o,width:a?c:l,height:a?l:c}}function Hs(e,t,n,r){let i=zs(e,t);if(e.length<=1)return{orientation:`rows`,result:i,scoreRows:i.score,scoreColumns:i.score};let a=Bs(e,t),o=Math.abs(i.score-a.score),s;return s=r!==void 0&&o<n?r:o<=1e-9||i.score<a.score?`rows`:`columns`,{orientation:s,result:s===`rows`?i:a,scoreRows:i.score,scoreColumns:a.score}}function Us(e,t,n,r=()=>!1){let i=[...e],a=new Map;e.forEach((e,n)=>{let r=t(e);r!==void 0&&(a.get(r)??a.set(r,[]).get(r)).push(n)});for(let t of a.values()){let a=t.map(t=>e[t]).sort((e,t)=>n(e)-n(t));r(a[0])&&a.reverse(),t.forEach((e,t)=>{i[e]=a[t]})}return i}function Ws(e,t){return Qs(e,t)||e.slice(1).some((n,r)=>t.slice(1).some((i,a)=>$s(e[r],n,t[a],i)))}var U=1e-4;function Gs(e,t,n){let r=t-e;if(!(r>=0)||!Number.isFinite(r))return[];let i=(e+t)/2;if(!(n>0)||!Number.isFinite(n)||r<n-U)return[i];let a=Math.min(16,Math.floor((r+U)/n)+1);if(a<=1)return[i];let o=[];for(let e=0;e<a;e+=1)o.push(i+(e-(a-1)/2)*n);return o}function Ks(e){let{request:t,shapes:n,earlier:r}=e,i=e.step??2,a=e.routeSpacing??0,o=e.borderClearance??0,s=e.allFixed??[],c=e.passableZones??[],l={x:t.start.x+i*t.startExit.x,y:t.start.y+i*t.startExit.y},u={x:t.end.x+i*t.endExit.x,y:t.end.y+i*t.endExit.y},d=e=>{let i=t.within;if(i!==void 0&&e.some(e=>e.x<i.x||e.x>i.x+i.width||e.y<i.y||e.y>i.y+i.height))return!1;let l=e.length-1;for(let i=1;i<e.length;i+=1){let u=e[i-1],d=e[i];if(n.some(e=>u.y===d.y?u.y>e.y&&u.y<e.y+e.height&&Math.max(Math.min(u.x,d.x),e.x)<Math.min(Math.max(u.x,d.x),e.x+e.width):u.x>e.x&&u.x<e.x+e.width&&Math.max(Math.min(u.y,d.y),e.y)<Math.min(Math.max(u.y,d.y),e.y+e.height)))return!1;if(o>0){let e=Math.min(u.x,d.x),r=Math.max(u.x,d.x),a=Math.min(u.y,d.y),s=Math.max(u.y,d.y),f=i===1,p=i===l;for(let i of n){if(f&&Ys(t.start,i)||p&&Ys(t.end,i))continue;let n=r<i.x?i.x-r:e>i.x+i.width?e-(i.x+i.width):0,c=s<i.y?i.y-s:a>i.y+i.height?a-(i.y+i.height):0;if(Math.hypot(n,c)<o-U)return!1}for(let n of c)if(!(f&&Ys(t.start,n))&&!(p&&Ys(t.end,n))){if(Math.abs(u.y-d.y)<=U&&Math.abs(u.x-d.x)>U){let t=(u.y+d.y)/2,i=r<n.x?n.x-r:e>n.x+n.width?e-(n.x+n.width):0;if(Math.hypot(i,Math.abs(t-n.y))<o-U||Math.hypot(i,Math.abs(t-(n.y+n.height)))<o-U)return!1}else if(Math.abs(u.x-d.x)<=U&&Math.abs(u.y-d.y)>U){let e=(u.x+d.x)/2,t=s<n.y?n.y-s:a>n.y+n.height?a-(n.y+n.height):0;if(Math.hypot(Math.abs(e-n.x),t)<o-U||Math.hypot(Math.abs(e-(n.x+n.width)),t)<o-U)return!1}}}if(tc(u,d,r)||ec(u,d,r)||a>0&&Zs(u,d,s,a))return!1;for(let t=1;t<i-1;t+=1){let n=e[t-1],r=e[t];if(Qs([u,d],[n,r])||$s(u,d,n,r)||a>0&&Xs(u,d,n,r,a))return!1}}if(a>0&&e.length>2)for(let t=1;t<e.length-1;t+=1){let n=e[t];for(let e of s)for(let t=1;t<e.length-1;t+=1)if(Math.hypot(n.x-e[t].x,n.y-e[t].y)<a-U)return!1}let u=e[1],d=e[e.length-2];return(u.x-t.start.x)*t.startExit.x+(u.y-t.start.y)*t.startExit.y>0&&(d.x-t.end.x)*t.endExit.x+(d.y-t.end.y)*t.endExit.y>0},f,p=1/0,m=n=>{let r=ic([t.start,l,...n,u,t.end]);if(f!==void 0&&r.length>f.length)return;let i=r.slice(1).reduce((e,t,n)=>e+Math.abs(t.x-r[n].x)+Math.abs(t.y-r[n].y),0);f!==void 0&&r.length===f.length&&i>=p||d(r)&&e.accepts(r)&&(f=r,p=i)};for(let t of e.ys){m([{x:l.x,y:t},{x:u.x,y:t}]);for(let n of e.xs)m([{x:n,y:l.y},{x:n,y:t},{x:u.x,y:t}]),m([{x:l.x,y:t},{x:n,y:t},{x:n,y:u.y}])}return f}var qs=[1,0,-1,0],Js=[0,1,0,-1];function Ys(e,t){let n=(Math.abs(e.x-t.x)<=U||Math.abs(e.x-(t.x+t.width))<=U)&&e.y>=t.y-U&&e.y<=t.y+t.height+U,r=(Math.abs(e.y-t.y)<=U||Math.abs(e.y-(t.y+t.height))<=U)&&e.x>=t.x-U&&e.x<=t.x+t.width+U;return n||r}function Xs(e,t,n,r,i){return Math.abs(e.y-t.y)<=U&&Math.abs(n.y-r.y)<=U?Math.abs(e.y-n.y)>=i-U?!1:Math.min(Math.max(e.x,t.x),Math.max(n.x,r.x))-Math.max(Math.min(e.x,t.x),Math.min(n.x,r.x))>U:Math.abs(e.x-t.x)<=U&&Math.abs(n.x-r.x)<=U?Math.abs(e.x-n.x)>=i-U?!1:Math.min(Math.max(e.y,t.y),Math.max(n.y,r.y))-Math.max(Math.min(e.y,t.y),Math.min(n.y,r.y))>U:!1}function Zs(e,t,n,r){if(Math.abs(e.x-t.x)<=U&&Math.abs(e.y-t.y)<=U)return!1;for(let i of n)for(let n=1;n<i.length;n+=1)if(Xs(e,t,i[n-1],i[n],r))return!0;return!1}function Qs(e,t){for(let n=1;n<e.length;n+=1)for(let r=1;r<t.length;r+=1){let i=e[n-1],a=e[n],o=t[r-1],s=t[r];if(i.y===a.y&&o.y===s.y&&i.y===o.y&&Math.min(Math.max(i.x,a.x),Math.max(o.x,s.x))-Math.max(Math.min(i.x,a.x),Math.min(o.x,s.x))>0||i.x===a.x&&o.x===s.x&&i.x===o.x&&Math.min(Math.max(i.y,a.y),Math.max(o.y,s.y))-Math.max(Math.min(i.y,a.y),Math.min(o.y,s.y))>0)return!0}return!1}function $s(e,t,n,r){let i=e.y===t.y&&e.x!==t.x,a=e.x===t.x&&e.y!==t.y,o=n.y===r.y&&n.x!==r.x,s=n.x===r.x&&n.y!==r.y;if(i&&s){let i=n.x,a=e.y;return i>Math.min(e.x,t.x)&&i<Math.max(e.x,t.x)&&a>Math.min(n.y,r.y)&&a<Math.max(n.y,r.y)}if(a&&o){let i=e.x,a=n.y;return i>Math.min(n.x,r.x)&&i<Math.max(n.x,r.x)&&a>Math.min(e.y,t.y)&&a<Math.max(e.y,t.y)}return!1}function ec(e,t,n){if(e.x===t.x&&e.y===t.y)return!1;for(let r of n)for(let n=1;n<r.length;n+=1)if($s(e,t,r[n-1],r[n]))return!0;return!1}function tc(e,t,n){if(e.x===t.x&&e.y===t.y)return!1;for(let r of n)for(let n=1;n<r.length;n+=1){let i=r[n-1],a=r[n];if(e.y===t.y&&i.y===a.y&&e.y===i.y){if(Math.min(Math.max(e.x,t.x),Math.max(i.x,a.x))-Math.max(Math.min(e.x,t.x),Math.min(i.x,a.x))>0)return!0}else if(e.x===t.x&&i.x===a.x&&e.x===i.x&&Math.min(Math.max(e.y,t.y),Math.max(i.y,a.y))-Math.max(Math.min(e.y,t.y),Math.min(i.y,a.y))>0)return!0}return!1}var nc=e=>e.x>0?0:e.y>0?1:e.x<0?2:3;function rc(e,t,n,r,i,a){let o=r-e,s=i-t;if(o===0&&s===0)return n===a?0:(n+2)%4===a?2:1;let c=o*qs[n]+s*Js[n],l=o*Js[n]-s*qs[n];return n===a&&l===0&&c>0?0:n%2!=a%2&&c>=0&&o*qs[a]+s*Js[a]>=0?1:2}function ic(e){let t=[];for(let n of e){let e=t[t.length-1];(e===void 0||e.x!==n.x||e.y!==n.y)&&t.push(n)}let n=[];for(let e of t){for(;n.length>=2;){let t=n[n.length-2],r=n[n.length-1];if(!(t.x===r.x&&r.x===e.x||t.y===r.y&&r.y===e.y))break;n.pop()}n.push(e)}return n}var ac=class{bends=[];lens=[];states=[];count=0;get size(){return this.count}clear(){this.count=0}push(e,t,n){let r=this.bends,i=this.lens,a=this.states,o=this.count++;for(o<r.length?(r[o]=e,i[o]=t,a[o]=n):(r.push(e),i.push(t),a.push(n));o>0;){let s=o-1>>1,c=r[s],l=i[s],u=a[s];if(!(e===c?t===l?n<u:t<l:e<c))break;r[o]=c,i[o]=l,a[o]=u,o=s}r[o]=e,i[o]=t,a[o]=n}pop(){let e=this.bends,t=this.lens,n=this.states,r=n[0],i=--this.count,a=e[i],o=t[i],s=n[i];if(i>0){let r=0;for(;;){let c=2*r+1;if(c>=i)break;let l=c+1,u=c;if(l<i){let r=e[c],i=t[c],a=n[c],o=e[l],s=t[l],d=n[l];(o===r?s===i?d<a:s<i:o<r)&&(u=l)}let d=e[u],f=t[u],p=n[u];if(!(d===a?f===o?p<s:f<o:d<a))break;e[r]=d,t[r]=f,n[r]=p,r=u}e[r]=a,t[r]=o,n[r]=s}return r}};function oc(e){let{rects:t,requests:n,clearance:r}=e,i=e.routeSpacing!==void 0&&e.routeSpacing>0?e.routeSpacing:0,a=i>0,o=e.barrierClearance??r,s=[...t.keys()].sort(),c=(e,t,n=r)=>({id:e,left:t.x-n,right:t.x+t.width+n,top:t.y-n,bottom:t.y+t.height+n}),l=[...s.map(e=>c(e,t.get(e),r)),...(e.barriers??[]).map((e,t)=>c(`barrier:${String(t)}`,e,o))],u=e=>{let t=new Set,n=new Set,r=[];for(let[i,a]of e)t.add(i),n.add(a),r.push(i,a);let o=[...new Set(r)].sort((e,t)=>e-t),s=[];for(let e=1;e<o.length;e+=1){let r=o[e-1],c=o[e],l=c-r;if(a){let e=n.has(r)&&t.has(c);e&&l<=300?s.push(...Gs(r,c,i)):(s.push((r+c)/2),e&&r+i<c-i&&s.push(r+i,c-i))}else s.push((r+c)/2)}return[...o,...s]},d=(e,t)=>({x:e.x+t.x*r,y:e.y+t.y*r}),f=u(l.map(e=>[e.left,e.right])),p=u(l.map(e=>[e.top,e.bottom]));if(a&&t.size>0){let e=new Set;for(let t of n)for(let n of t.passable)e.add(n);for(let n of e){let e=t.get(n);e!==void 0&&(e.width>2*r&&f.push(e.x+r,e.x+e.width-r),e.height>2*r&&p.push(e.y+r,e.y+e.height-r))}if(n.length>1){let e=[...t.values()],a=Math.min(...e.map(e=>e.x))-r,o=Math.max(...e.map(e=>e.x+e.width))+r,s=Math.min(...e.map(e=>e.y))-r,c=Math.max(...e.map(e=>e.y+e.height))+r,l=Math.min(Math.max(4,Math.ceil(n.length/3)),6);for(let e=1;e<=l;e+=1)f.push(a-e*i,o+e*i),p.push(s-e*i,c+e*i)}}for(let e of n)for(let t of[d(e.start,e.startExit),d(e.end,e.endExit)])f.push(t.x),p.push(t.y);for(let t of e.lanes?.xs??[])f.push(t);for(let t of e.lanes?.ys??[])p.push(t);let m=[...new Set(f)].sort((e,t)=>e-t),h=[...new Set(p)].sort((e,t)=>e-t),g=new Map(m.map((e,t)=>[e,t])),_=new Map(h.map((e,t)=>[e,t])),v=m.length,y=h.length,b=l.map(e=>({id:e.id,iL:g.get(e.left),iR:g.get(e.right),jT:_.get(e.top),jB:_.get(e.bottom)})),x=v+1,S=new Int32Array((v+1)*(y+1)),C=new Int32Array((v+1)*(y+1)),w=(e,t,n,r,i)=>{t>n||r>i||(e[r*x+t]+=1,--e[r*x+n+1],--e[(i+1)*x+t],e[(i+1)*x+n+1]+=1)};for(let e of b)w(S,e.iL,e.iR-1,e.jT+1,e.jB-1),w(C,e.iL+1,e.iR-1,e.jT,e.jB-1);let T=new Int32Array(v*y),E=new Int32Array(v*y);for(let e=0;e<y;e+=1){let t=0,n=0;for(let r=0;r<v;r+=1){t+=S[e*x+r],n+=C[e*x+r];let i=+(e>0);T[e*v+r]=t+(i?T[(e-1)*v+r]:0),E[e*v+r]=n+(i?E[(e-1)*v+r]:0)}}let D=(e,t,n)=>t>=e.iL&&t<=e.iR-1&&n>e.jT&&n<e.jB,O=(e,t,n)=>t>e.iL&&t<e.iR&&n>=e.jT&&n<=e.jB-1,k=v*y*4,A=new Int32Array(k),j=new Float64Array(k),M=new Int32Array(k),ee=new Int32Array(k),te=new Int32Array(k),ne=new Int32Array(k),N=new Int32Array(k),P=new Map,F=new Int32Array(2*v*y),I=new Map,re=e=>F[e]!==0,L=(e,t)=>{let n=F[e];if(n===0)return!1;if(n===t+1)return!0;let r=I.get(e);return r!==void 0&&r.includes(t)},R=(e,t)=>{let n=F[e];if(n===0){F[e]=t+1;return}if(n===t+1)return;let r=I.get(e);r===void 0?I.set(e,[t]):r.includes(t)||r.push(t)},ie=(e,t)=>{for(let n=1;n<e.length;n+=1){let r=e[n-1],i=e[n],a=g.get(r.x),o=_.get(r.y),s=g.get(i.x),c=_.get(i.y);if(a!==void 0&&o!==void 0&&s!==void 0&&c!==void 0){if(o===c){let e=Math.min(a,s),n=Math.max(a,s);for(let r=e;r<n;r+=1)R((o*v+r)*2,t)}else if(a===s){let e=Math.min(o,c),n=Math.max(o,c);for(let r=e;r<n;r+=1)R((r*v+a)*2+1,t)}}}},z=new Map,ae=[],B=[],oe=[],se=e=>{if(a){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t];Math.abs(n.y-r.y)<=U&&Math.abs(n.x-r.x)>U?ae.push({y:(n.y+r.y)/2,lo:Math.min(n.x,r.x),hi:Math.max(n.x,r.x)}):Math.abs(n.x-r.x)<=U&&Math.abs(n.y-r.y)>U&&B.push({x:(n.x+r.x)/2,lo:Math.min(n.y,r.y),hi:Math.max(n.y,r.y)})}for(let t=1;t+1<e.length;t+=1)oe.push(e[t])}};for(let t of e.reservedRoutes??[])se(t);let ce=0,le=new ac,ue=new Map,V=[],de=[],fe=(e,t,n)=>e.x===t.x||e.y===t.y?[]:n.x===0?[{x:e.x,y:t.y}]:[{x:t.x,y:e.y}],pe=[...t.values(),...e.barriers??[]],me=(e,t)=>{let n=0;for(let r of pe){let i=r.x,a=r.x+r.width,o=r.y,s=r.y+r.height;e.y===t.y?e.y>o&&e.y<s&&Math.max(Math.min(e.x,t.x),i)<Math.min(Math.max(e.x,t.x),a)&&(n+=1):e.x===t.x&&e.x>i&&e.x<a&&Math.max(Math.min(e.y,t.y),o)<Math.min(Math.max(e.y,t.y),s)&&(n+=1)}return n},he=e=>{let t=0;for(let n=1;n<e.length;n+=1)t+=me(e[n-1],e[n]);return t},ge=(e,t,n,i,a)=>{let o=[];if(t.x!==n.x&&t.y!==n.y&&(o.push([{x:n.x,y:t.y}]),o.push([{x:t.x,y:n.y}])),pe.length>0){let e=Math.min(...pe.map(e=>e.x))-r-4,i=Math.max(...pe.map(e=>e.x+e.width))+r+4,a=Math.min(...pe.map(e=>e.y))-r-4,s=Math.max(...pe.map(e=>e.y+e.height))+r+4;o.push([{x:t.x,y:a},{x:n.x,y:a}]),o.push([{x:t.x,y:s},{x:n.x,y:s}]),o.push([{x:e,y:t.y},{x:e,y:n.y}]),o.push([{x:i,y:t.y},{x:i,y:n.y}])}let s=fe(t,n,a),c=1/0;for(let r of o){let a=ic([e,t,...r,n,i]),o=he(a);if(o<c&&(c=o,s=r,o===0))break}return s},_e=e.priority,ve=Us([...n].sort((e,t)=>{if(a){if(_e!==void 0){let n=+!_e.has(e.id),r=+!_e.has(t.id);if(n!==r)return n-r}let n=+(e.within===void 0),r=+(t.within===void 0);if(n!==r)return n-r;let i=Math.abs(e.start.x-e.end.x)+Math.abs(e.start.y-e.end.y),a=Math.abs(t.start.x-t.end.x)+Math.abs(t.start.y-t.end.y);if(Math.abs(i-a)>U)return i-a}return e.id<t.id?-1:+(e.id>t.id)}),e=>e.flowRun,e=>e.flowRank),ye=(e,t)=>Math.abs(e.x-t.x)<=U&&Math.abs(e.y-t.y)<=U,be=ve.map(e=>{let t=d(e.start,e.startExit),n=d(e.end,e.endExit);return{start:e.start,startPoint:t,end:e.end,endPoint:n}}),xe=a?new Uint8Array(v*y):void 0,Se=a?new Uint8Array(v*y):void 0,Ce=a?new Uint8Array(v*y):void 0,we=(e,t)=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i]<t?n=i+1:r=i}return n};for(let n=0;n<ve.length;n+=1){let o=ve[n],s=-1,c=P.get(o.pairKey);c===void 0&&(c=P.size,P.set(o.pairKey,c));let l=c,u=z.get(o.pairKey)??[],d=u.length>0,f=be[n].startPoint,p=be[n].endPoint,x,S,C,w,F,I=[],pe=[];if(a){let e=[],t=[],r=[],a=(n,i)=>{ye(n,o.start)||ye(n,o.end)||(Math.abs(n.y-i.y)<=U&&Math.abs(n.x-i.x)>U?(e.push({y:(n.y+i.y)/2,lo:Math.min(n.x,i.x),hi:Math.max(n.x,i.x)}),pe.push({x:i.x,y:i.y})):Math.abs(n.x-i.x)<=U&&Math.abs(n.y-i.y)>U&&(t.push({x:(n.x+i.x)/2,lo:Math.min(n.y,i.y),hi:Math.max(n.y,i.y)}),I.push({y:i.y,x:i.x})),r.push(i))};for(let e=n+1;e<be.length;e+=1){let t=be[e];a(t.start,t.startPoint),a(t.end,t.endPoint)}let s=e.length>0?[...ae,...e]:ae,c=t.length>0?[...B,...t]:B,l=r.length>0?[...oe,...r]:oe;if(s.length>0||c.length>0||l.length>0){let e=i-U;x=Array.from({length:y},()=>[]),w=Se,w.fill(0);for(let t of s){let n=Math.max(0,we(m,t.lo+U)-1);for(let r=we(h,t.y-e);r<y&&h[r]<t.y+e;r+=1){x[r].push(t);let e=r*v;for(let r=n;r<v-1&&m[r]<t.hi-U;r+=1)m[r+1]>t.lo+U&&(w[e+r]=1)}}for(let e of I){let t=_.get(e.y);if(t===void 0)continue;let n=t*v,r=Math.max(0,we(m,e.x-U)-1);for(let t=r;t<v-1&&m[t]<=e.x+U;t+=1)m[t+1]>=e.x-U&&(w[n+t]=1)}S=Array.from({length:v},()=>[]),F=Ce,F.fill(0);for(let t of c){let n=Math.max(0,we(h,t.lo+U)-1);for(let r=we(m,t.x-e);r<v&&m[r]<t.x+e;r+=1){S[r].push(t);for(let e=n;e<y-1&&h[e]<t.hi-U;e+=1)h[e+1]>t.lo+U&&(F[e*v+r]=1)}}for(let e of pe){let t=g.get(e.x);if(t===void 0)continue;let n=Math.max(0,we(h,e.y-U)-1);for(let r=n;r<y-1&&h[r]<=e.y+U;r+=1)h[r+1]>=e.y-U&&(F[r*v+t]=1)}if(C=xe,C.fill(0),l.length>0){let t=e*e;for(let n of l){let r=we(h,n.y-e),i=we(m,n.x-e);for(let a=r;a<y&&h[a]<n.y+e;a+=1){let r=h[a]-n.y,o=r*r,s=a*v;for(let r=i;r<v&&m[r]<n.x+e;r+=1){let e=m[r]-n.x;e*e+o<t&&(C[s+r]=1)}}}}}}let me=(e,t,n)=>{let r=x?.[e],i=Math.min(t,n),a=Math.max(t,n);if(a-i<=U)return!1;if(r!==void 0){for(let e of r)if(Math.min(a,e.hi)-Math.max(i,e.lo)>U)return!0}let o=h[e];for(let e of I)if(Math.abs(o-e.y)<=U&&e.x>=i-U&&e.x<=a+U)return!0;return!1},he=(e,t,n)=>{let r=S?.[e],i=Math.min(t,n),a=Math.max(t,n);if(a-i<=U)return!1;if(r!==void 0){for(let e of r)if(Math.min(a,e.hi)-Math.max(i,e.lo)>U)return!0}let o=m[e];for(let e of pe)if(Math.abs(o-e.x)<=U&&e.y>=i-U&&e.y<=a+U)return!0;return!1},_e=(e,t)=>{if(Math.abs(e.y-t.y)<=U){let n=_.get(e.y);if(n!==void 0)return me(n,e.x,t.x);let r=Math.min(e.x,t.x),a=Math.max(e.x,t.x);return a-r>U&&ae.some(t=>Math.abs(t.y-e.y)<i-U&&Math.min(a,t.hi)-Math.max(r,t.lo)>U)}if(Math.abs(e.x-t.x)<=U){let n=g.get(e.x);if(n!==void 0)return he(n,e.y,t.y);let r=Math.min(e.y,t.y),a=Math.max(e.y,t.y);return a-r>U&&B.some(t=>Math.abs(t.x-e.x)<i-U&&Math.min(a,t.hi)-Math.max(r,t.lo)>U)}return!1},Te=(e,t)=>{if(Math.abs(e.y-t.y)<=U){let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x);if(r-n<=U)return!1;let i=_.get(e.y),a=i===void 0?ae:x?.[i];return a!==void 0&&a.some(t=>Math.abs(t.y-e.y)<=U&&Math.min(r,t.hi)-Math.max(n,t.lo)>U)}if(Math.abs(e.x-t.x)<=U){let n=Math.min(e.y,t.y),r=Math.max(e.y,t.y);if(r-n<=U)return!1;let i=g.get(e.x),a=i===void 0?B:S?.[i];return a!==void 0&&a.some(t=>Math.abs(t.x-e.x)<=U&&Math.min(r,t.hi)-Math.max(n,t.lo)>U)}return!1},Ee=[];if(a){let e=x!==void 0;o.within===void 0?(e&&Ee.push({clamp:void 0,strictSpacing:!0,allowCrossPairOverlap:!1}),Ee.push({clamp:void 0,strictSpacing:!1,allowCrossPairOverlap:!1}),Ee.push({clamp:void 0,strictSpacing:!1,allowCrossPairOverlap:!0})):(e&&Ee.push({clamp:o.within,strictSpacing:!0,allowCrossPairOverlap:!1}),Ee.push({clamp:o.within,strictSpacing:!1,allowCrossPairOverlap:!1}),Ee.push({clamp:o.within,strictSpacing:!1,allowCrossPairOverlap:!0}),e&&Ee.push({clamp:void 0,strictSpacing:!0,allowCrossPairOverlap:!1}),Ee.push({clamp:void 0,strictSpacing:!1,allowCrossPairOverlap:!1}),Ee.push({clamp:void 0,strictSpacing:!1,allowCrossPairOverlap:!0}))}else o.within===void 0||Ee.push({clamp:o.within,strictSpacing:!1,allowCrossPairOverlap:!0}),Ee.push({clamp:void 0,strictSpacing:!1,allowCrossPairOverlap:!0});let De=!1,Oe=o.within,ke=b.filter(e=>o.passable.has(e.id)),Ae=ke.length===0,je=a?ke.map(e=>t.get(e.id)).filter(e=>e!==void 0):[],Me=je.length>0?new Uint8Array(y):void 0,Ne=je.length>0?new Uint8Array(v):void 0;if(Me!==void 0&&Ne!==void 0){let e=r-U;for(let t of je){for(let n of[t.y,t.y+t.height])for(let t=we(h,n-e);t<y&&h[t]<n+e;t+=1)Me[t]=1;for(let n of[t.x,t.x+t.width])for(let t=we(m,n-e);t<v&&m[t]<n+e;t+=1)Ne[t]=1}}let Pe=(e,t)=>{if(Me[t]===0)return!1;let n=h[t],i=m[e],a=m[e+1];for(let e of je)if(!(a<=e.x-r+U||i>=e.x+e.width+r-U)&&(Math.abs(n-e.y)<r-U||Math.abs(n-(e.y+e.height))<r-U))return!0;return!1},Fe=(e,t)=>{if(Ne[e]===0)return!1;let n=m[e],i=h[t],a=h[t+1];for(let e of je)if(!(a<=e.y-r+U||i>=e.y+e.height+r-U)&&(Math.abs(n-e.x)<r-U||Math.abs(n-(e.x+e.width))<r-U))return!0;return!1},Ie=a&&_e(o.start,f),Le=a&&_e(p,o.end);for(let e of Ee){if(s>=0||De)break;let{clamp:t,strictSpacing:n,allowCrossPairOverlap:r}=e;if(n&&(Ie||Le))continue;let i=(e,n)=>t===void 0||e>=t.x&&e<=t.x+t.width&&n>=t.y&&n<=t.y+t.height;if(!i(f.x,f.y)||!i(p.x,p.y))continue;ce+=1,le.clear();let a=(e,t)=>{let n=T[t*v+e];for(let r of ke)D(r,e,t)&&--n;return n>0||je.length>0&&Pe(e,t)},c=(e,t)=>{let n=E[t*v+e];for(let r of ke)O(r,e,t)&&--n;return n>0||je.length>0&&Fe(e,t)},b=(e,t)=>T[t*v+e]>0,x=(e,t)=>E[t*v+e]>0,S=Ae?b:a,P=Ae?x:c,I=g.get(f.x),R=_.get(f.y),ie=g.get(p.x),z=_.get(p.y),ae=nc(o.startExit),B=nc({x:-o.endExit.x,y:-o.endExit.y});if(n&&C!==void 0&&C[z*v+ie]===1&&(I!==ie||R!==z||ae!==B)){let e=ie-qs[B],t=z-Js[B],n=e>=0&&t>=0&&e<v&&t<y&&i(m[e],h[t]);if(n){if(B%2==0){let t=Math.min(e,ie),r=(z*v+t)*2;(S(t,z)||re(r)||w!==void 0&&w[z*v+t]===1)&&(n=!1)}else{let e=Math.min(t,z),r=(e*v+ie)*2+1;(P(ie,e)||re(r)||F!==void 0&&F[e*v+ie]===1)&&(n=!1)}}if(!n)continue}let oe=k;if(d&&(tc(o.start,f,u)||ec(o.start,f,u)||tc(p,o.end,u)||ec(p,o.end,u))){De=!0;break}let se=(e,t,n)=>rc(m[e],h[t],n,p.x,p.y,B),ue=(e,t)=>Math.abs(p.x-m[e])+Math.abs(p.y-h[t]),V=(R*v+I)*4+ae;A[V]=0,j[V]=0,M[V]=I,ee[V]=R,te[V]=ce,N[V]=-1,le.push(se(I,R,ae),ue(I,R),V);let de=1/0,fe=1/0,pe=0;for(;le.size>0;){let e=le.pop();if(e===oe)break;if(ne[e]===ce)continue;if(ne[e]=ce,n&&++pe>24e3)break;let a=e&3,c=e>>2,g=c%v,_=(c-g)/v,b=A[e],x=j[e];if(g===ie&&_===z&&(a+2)%4!==B){let t=!0;if(n?a===B?_e(M[e]===I&&ee[e]===R&&a===ae?o.start:{x:m[M[e]],y:h[ee[e]]},o.end)&&(t=!1):(C!==void 0&&C[z*v+ie]===1||_e(p,o.end)||I===ie&&R===z&&_e(o.start,f))&&(t=!1):r||(a===B?Te(M[e]===I&&ee[e]===R&&a===ae?o.start:{x:m[M[e]],y:h[ee[e]]},o.end)&&(t=!1):Te(p,o.end)&&(t=!1)),t){if(d&&a===B){let t={x:m[M[e]],y:h[ee[e]]};if(!(ec(t,o.end,u)||tc(t,o.end,u))){let t=b,n=x;(t<de||t===de&&n<fe)&&(de=t,fe=n,s=e,le.push(t,n,oe))}}else{let t=b+(a===B?0:1),n=x;(t<de||t===de&&n<fe)&&(de=t,fe=n,s=e,le.push(t,n,oe))}}}let T=M[e],E=ee[e];for(let s=0;s<4;s+=1){if(s===(a+2)%4)continue;let c=g+qs[s],p=_+Js[s];if(c<0||p<0||c>=v||p>=y||t!==void 0&&!i(m[c],h[p]))continue;let D,O;if(s%2==0){let e=Math.min(g,c);if(S(e,_))continue;D=(_*v+e)*2,O=m[e+1]-m[e]}else{let e=Math.min(_,p);if(P(g,e))continue;D=(e*v+g)*2+1,O=h[e+1]-h[e]}let k=re(D);if(k&&(!r||L(D,l)))continue;let ie,z;if(s===a?(ie=T,z=E):(ie=g,z=_),n){if(s!==a&&(C!==void 0&&C[_*v+g]===1||g===I&&_===R&&_e(o.start,f)))continue;if(s%2==0){if(w!==void 0&&w[_*v+Math.min(g,c)]===1||g===I&&_===R&&s===ae&&me(_,o.start.x,f.x))continue}else if(F!==void 0&&F[Math.min(_,p)*v+g]===1||g===I&&_===R&&s===ae&&he(g,o.start.y,f.y))continue}else if(!r&&g===I&&_===R&&s===ae&&Te(o.start,f))continue;if(d){let e=ie===I&&z===R&&s===ae?o.start:{x:m[ie],y:h[z]},t={x:m[c],y:h[p]};if(ec(e,t,u)||tc(e,t,u))continue}let B=b+(s===a?0:1),oe=se(c,p,s);if(n&&B+oe>12)continue;let V=x+O*(k?3:1),de=(p*v+c)*4+s;if(te[de]===ce){let e=A[de],t=j[de];if(B>e||B===e&&V>=t)continue}ne[de]!==ce&&(te[de]=ce,A[de]=B,j[de]=V,M[de]=ie,ee[de]=z,N[de]=e,le.push(B+oe,V+ue(c,p),de))}}s>=0&&(Oe=t)}if(s>=0&&Oe===void 0&&o.within!==void 0&&de.push(o.id),s<0){V.push(o.id);let t=e.avoidFallbackInteriors===!0?ge(o.start,f,p,o.end,o.startExit):fe(f,p,o.startExit),n=ic([o.start,f,...t,p,o.end]);ue.set(o.id,n);let r=z.get(o.pairKey)??[];r.push(n),z.set(o.pairKey,r),se(n),ie([f,...t,p],l);continue}let Re=[];for(let e=s;e>=0;e=N[e])Re.push(e);Re.reverse();let ze=[],Be=[];for(let e=0;e<Re.length;e+=1){let t=Re[e]>>2,n=t%v,r=(t-n)/v;if(ze.push({x:m[n],y:h[r]}),e>0){let t=Re[e-1]>>2,i=t%v,a=(t-i)/v;Be.push(a===r?(r*v+Math.min(n,i))*2:(Math.min(r,a)*v+n)*2+1)}}let Ve=ic([o.start,...ze,o.end]),He=!1;if(d)for(let e of u){if(Qs(Ve,e)){He=!0;break}let t=!1;for(let n=1;n<Ve.length&&!t;n+=1)for(let r=1;r<e.length;r+=1)if($s(Ve[n-1],Ve[n],e[r-1],e[r])){t=!0;break}if(t){He=!0;break}}if(He){V.push(o.id);let t=e.avoidFallbackInteriors===!0?ge(o.start,f,p,o.end,o.startExit):fe(f,p,o.startExit),n=ic([o.start,f,...t,p,o.end]);ue.set(o.id,n);let r=z.get(o.pairKey)??[];r.push(n),z.set(o.pairKey,r),se(n),ie([f,...t,p],l);continue}for(let e of Be)R(e,l);ue.set(o.id,Ve);let Ue=z.get(o.pairKey)??[];Ue.push(Ve),z.set(o.pairKey,Ue),se(Ve)}return{routes:ue,obstructed:V,escaped:de}}var sc={targetAspect:1.78,tallBias:1.6,emptyPenaltyWeight:.4,orientationHysteresis:.08},cc=Ze.gapMin,lc=Ze.gapMax;Ze.zoneGutter;var uc=`root`;function dc(e){return{targetAspect:e?.targetAspect??sc.targetAspect,tallBias:e?.tallBias??sc.tallBias,emptyPenaltyWeight:e?.emptyPenaltyWeight??sc.emptyPenaltyWeight,orientationHysteresis:e?.orientationHysteresis??sc.orientationHysteresis}}function fc(e){let t=[],n=(n,r)=>{t.push({code:`row-pack-invalid`,path:`rowPack`,message:`rowPack.${n} ${r}, got ${String(e[n])}`})};(!Number.isFinite(e.targetAspect)||e.targetAspect<=0)&&n(`targetAspect`,`is a positive finite number`);for(let t of[`tallBias`,`emptyPenaltyWeight`,`orientationHysteresis`])(!Number.isFinite(e[t])||e[t]<0)&&n(t,`is a non-negative finite number`);return t}var pc={nodePaddingX:12,nodePaddingY:8,nodeMinWidth:64,nodeMinHeight:32,containerPadding:Ze.containerPadding,titlePaddingY:6,rankGap:56,nodeGap:24,slotSpacing:12,clearance:8,labelMargin:4},mc=.75;function hc(e,t,n){let r=Za(e,{registry:t.registry,...t.bindings?{bindings:t.bindings}:{}});if(r.some(e=>e.severity===`error`))return{status:`refused`,refusals:[{code:`document-invalid`,path:`document`,message:`Invalid ERD document`}],diagnostics:r};if(!Number.isFinite(t.targetWidth)||t.targetWidth<=0)return{status:`refused`,refusals:[{code:`target-width-invalid`,path:`targetWidth`,message:`Positive finite width required`}],diagnostics:[]};let i=dc(t.rowPack),a=fc(i);if(a.length)return{status:`refused`,refusals:a,diagnostics:[]};let o=new Set(t.collapsed??Object.values(n?.groups??{}).filter(e=>e.collapsed).map(e=>e.occurrence)),s=Object.values(e.entities).sort((e,t)=>e.id<t.id?-1:1),c=new Map(s.map(e=>[e.id,Object.values(n?.entityOccurrences??{}).find(t=>t.entity===e.id)?.id??ro(e.id)])),l=s.map(n=>Zo(e,n.id,o.has(c.get(n.id)),t.measureLines)),u=zs(l,{targetAspect:i.targetAspect,tallBias:i.tallBias,emptyPenaltyWeight:i.emptyPenaltyWeight,gapX:Math.max(Go.gapInline,t.metrics?.rowGapInline??0),gapY:Math.max(Go.gapBlock,t.metrics?.rowGapBlock??0),chromeWidth:0,chromeHeight:0}),d={},f={},p={},m={},h=new Map,g=new Map;s.forEach((t,n)=>{let r=c.get(t.id),i=l[n],a=u.positions[n],s={x:a.x+Go.gapInline,y:a.y+Go.gapBlock,width:i.width,height:i.height};d[r]={id:r,entity:t.id,geometry:s},h.set(t.id,s),g.set(t.id,i.headerHeight),m[`fold.`+r.slice(11)]={id:`fold.`+r.slice(11),occurrence:r,collapsed:o.has(r)};for(let n of Yo(e,t.id))for(let e of[`west`,`east`]){let t=i.rows.find(e=>e.field.id===n.id),a=io(n.id,e);f[a]={id:a,port:n.id,ownerOccurrence:r,side:e,order:t?i.rows.indexOf(t):0,anchor:t?(t.y+t.height/2)/i.height:.5}}});let _=Object.values(e.relations).sort((e,t)=>e.id<t.id?-1:1),v=_.flatMap(t=>[`from`,`to`].map(n=>{let r=t.endpoints.find(e=>e.role===n),i=t.endpoints.find(e=>e.role!==n),a=e.ports[r.target]?.owner??r.target,o=e.ports[i.target]?.owner??i.target,s=h.get(a),c=h.get(o);return{entity:a,side:c.x+c.width/2<s.x+s.width/2?`west`:`east`,target:r.target,role:n,relation:t.id}})),y=[],b=new Map,x=new Map;for(let t of _){let r=Object.values(n?.relationOccurrences??{}).find(e=>e.relation===t.id)?.id??Bt(t.id.slice(9)),i=[],a=[],s=[];for(let n of v.filter(e=>e.relation===t.id)){let t=c.get(n.entity),r=h.get(n.entity),l=e.ports[n.target],u=o.has(t),d=l?io(l.id,n.side):void 0,p=v.filter(r=>r.entity===n.entity&&r.side===n.side&&(o.has(t)||!e.ports[r.target])),m=p.indexOf(n),_=g.get(n.entity),y=l&&!u?r.y+f[d].anchor*r.height:r.y+Go.markerHalfWidth+(m+1)*(_-2*Go.markerHalfWidth)/(p.length+1);i.push({x:r.x+(n.side===`east`?r.width:0),y}),a.push({x:n.side===`east`?1:-1,y:0}),s.push({role:n.role,occurrence:l&&!u?d:t,...l&&u?{semanticTarget:l.id,sourceOccurrence:d}:{}})}p[r]={id:r,relation:t.id,endpoints:s};let l=v.filter(e=>e.relation===t.id).map(e=>e.entity);if(l[0]===l[1]){let e=l[0],n=(x.get(e)??0)+1;x.set(e,n);let r=h.get(e),a=r.x+r.width+Go.markerLength+Go.markerGap*n*2,o=i[0],s=i[1];b.set(t.id,o.y===s.y?[o,{x:a,y:o.y},{x:a,y:o.y+Go.rowHeight},{x:a+Go.markerGap,y:o.y+Go.rowHeight},{x:a+Go.markerGap,y:s.y},s]:[o,{x:a,y:o.y},{x:a,y:s.y},s])}else y.push({id:t.id,pairKey:t.id,start:i[0],end:i[1],startExit:a[0],endExit:a[1],passable:new Set})}let S=oc({rects:h,requests:y,clearance:Go.markerLength+Go.markerGap}),C=S.obstructed.map(e=>({code:`route-obstructed`,refs:[e],message:`Dense ERD routing uses an elbow fallback`}));for(let e of Object.values(p)){let t=b.get(e.relation)??S.routes.get(e.relation)??[],n=f[e.endpoints[0].occurrence],r=f[e.endpoints[1].occurrence];p[e.id]={...e,waypoints:t.slice(+!!n,r?t.length-1:t.length)}}return{status:`laid-out`,view:{...$a({viewId:t.viewId??n?.viewId??Vt(`erd`),semanticDocumentId:e.documentId,revision:e.revision}),entityOccurrences:d,portOccurrences:f,relationOccurrences:p,groups:m},fit:{direction:`left-to-right`,width:u.width+2*Go.gapInline,height:u.height+2*Go.gapBlock,zoom:1,pans:u.width>t.targetWidth,phone:t.targetWidth<=390},warnings:C,orientations:{root:`rows`}}}function gc(e,t){let n=[];for(let r=e.nodes.get(t)?.parent;r!==void 0;r=e.nodes.get(r)?.parent)n.push(r);return n}function _c(e,t,n){return gc(e,n).includes(t)}function vc(e,t){return t>0?Math.max(e.slotSpacing,t+e.labelMargin):e.slotSpacing}var yc={north:{x:0,y:-1},east:{x:1,y:0},south:{x:0,y:1},west:{x:-1,y:0}},bc=(e,t)=>e<t?-1:+(e>t),xc=e=>({x:e.x+e.width/2,y:e.y+e.height/2});function Sc(e,t,n){let r=t.x-(e.x+e.width),i=e.x-(t.x+t.width),a=t.y-(e.y+e.height),o=e.y-(t.y+t.height),s=r>=0?`east`:i>=0?`west`:void 0,c=a>=0?`south`:o>=0?`north`:void 0,l=n===`left-to-right`?s??c:c??s;if(l!==void 0)return l;let u=xc(e),d=xc(t),f=d.x-u.x,p=d.y-u.y;return Math.abs(f)>=Math.abs(p)?f>=0?`east`:`west`:p>=0?`south`:`north`}var Cc=1e9,wc=[`east`,`south`,`west`,`north`];function Tc(e,t){let n={east:t.x+t.width-(e.x+e.width),south:t.y+t.height-(e.y+e.height),west:e.x-t.x,north:e.y-t.y},r=`east`;for(let e of wc)n[e]<n[r]&&(r=e);return r}function Ec(e){let t=new Map;for(let n of e.edges){let e=[n.source.entity,n.target.entity].sort().join(`|`);t.set(e,(t.get(e)??0)+1)}let n=new Set;for(let r of e.edges){let e=[r.source.entity,r.target.entity].sort().join(`|`);(t.get(e)??0)>1&&n.add(r.id)}return n}function Dc(e){let{graph:t,rects:n,direction:r,metrics:i,labelSizes:a,fixed:o}=e,s=r===`left-to-right`,c=[];for(let i of t.edges){let o=i.source.entity,l=i.target.entity,u=a.get(i.id),d=(e,t,n,r,a)=>c.push({slot:i[e].slot,edge:i.id,role:e,entity:t,other:n,port:e===`source`?i.source.port:i.target.port,side:r,inner:a,label:u});if(o===l)d(`source`,o,l,s?`east`:`south`,!1),d(`target`,l,o,s?`north`:`west`,!1);else if(_c(t,o,l)||_c(t,l,o)){let e=_c(t,o,l),r=e?o:l,i=e?l:o,a=Tc(n.get(i),n.get(r));d(`source`,o,l,a,e),d(`target`,l,o,a,!e)}else{let t=e.sideOverrides?.get(i.id);d(`source`,o,l,t?.source??Sc(n.get(o),n.get(l),r),!1),d(`target`,l,o,t?.target??Sc(n.get(l),n.get(o),r),!1)}}let l=Ec(t),u=new Map;for(let e of[...c].sort((e,t)=>bc(e.edge,t.edge)||bc(e.role,t.role)))e.port!==void 0&&(u.has(e.port)||u.set(e.port,e.side));for(let e of c)e.port!==void 0&&(e.side=u.get(e.port));let d=new Map;for(let e of c){let t=`${e.entity}|${e.side}`;(d.get(t)??d.set(t,[]).get(t)).push(e)}let f=new Map,p=[],m=[];for(let r of[...d.keys()].sort(bc)){let a=d.get(r),s=a[0].entity,c=a[0].side,u=n.get(s),h=c===`east`||c===`west`,g=e=>e.slot===void 0?e.port!==void 0&&!l.has(e.edge)?`~${e.port}`:`${e.edge}#${e.role}`:`~`+e.slot,_=e=>[...e].sort((e,t)=>bc(e.edge,t.edge)||bc(e.role,t.role))[0],v=t=>e.sideOverrides?.get(t.edge)?.turn===!0,y=xc(u),b=e=>{let t=xc(n.get(e.other)),r=h?t.y:t.x;return v(e)?(r<(h?y.y:y.x)?-1e9:Cc)-r:r},x=new Map;for(let e of a)(x.get(g(e))??x.set(g(e),[]).get(g(e))).push(e);let S=[...x.keys()].sort((e,t)=>{let n=_(x.get(e)),r=_(x.get(t)),i=b(n),a=b(r);return i===a?v(n)&&v(r)&&i>0?bc(t,e):bc(e,t):i-a}),C=new Map(t.edges.filter(e=>e.flowRank!==void 0&&e.source.slot===void 0&&e.target.slot===void 0).map(e=>[e.id,e])),w=e=>{let t=x.get(e),n=_(t),r=C.get(n.edge);return t.length!==1||r===void 0?void 0:[r.source.entity,r.target.entity].sort().join(`|`)+`|`+String(v(n))},T=Us(S,w,e=>C.get(_(x.get(e)).edge).flowRank,e=>{let t=_(x.get(e));return v(t)&&b(t)>0}),E=S.some(e=>w(e)!==void 0&&S.filter(t=>w(t)===w(e)).length>1),D=a.reduce((e,t)=>t.label===void 0?e:Math.max(e,h?t.label.height:t.label.width),0),O=h?u.height:u.width,k=T.length,A=Math.max(vc(i,k>=2?D:0),E?(e.flowBadgeSize??0)+i.labelMargin:0);if(o===!0){let t=e.cornerInset!==void 0&&e.cornerInset>0?Math.min(e.cornerInset,O/2):0,n=Math.max(0,O-2*t),i=Math.max(1,Math.floor(n/A)+1),a=xc(u),o=e=>c===`east`?{x:u.x+u.width,y:a.y+e}:c===`west`?{x:u.x,y:a.y+e}:c===`north`?{x:a.x+e,y:u.y}:{x:a.x+e,y:u.y+u.height},l=e=>h?(e.y-u.y)/u.height:(e.x-u.x)/u.width,d=e.reservedSlots?.get(r);if(d!==void 0&&d.length>0&&k<=i){let e=(h?u.y:u.x)+t,n=(h?u.y+u.height:u.x+u.width)-t,r=[...d];T.forEach((t,i)=>{let u=(h?a.y:a.x)+(i-(k-1)/2)*A,d=Math.max(e,Math.min(n,u)),p=t=>t>=e-1e-4&&t<=n+1e-4&&r.every(e=>Math.abs(e-t)>=A-1e-4);if(!p(d))for(let e=1;e<=24;e+=1){let t=d+e*A;if(p(t)){d=t;break}let n=d-e*A;if(p(n)){d=n;break}}r.push(d);let m=o(d-(h?a.y:a.x)),g=l(m);for(let e of x.get(t)){let t=yc[c];f.set(`${e.edge}#${e.role}`,{entity:s,point:m,side:c,exit:e.inner?{x:-t.x,y:-t.y}:t,order:i,anchor:g,...e.port===void 0?{}:{port:e.port}})}})}else if(k<=i)T.forEach((e,t)=>{let n=(t-(k-1)/2)*A,r=o(n),i=l(r);for(let n of x.get(e)){let e=yc[c];f.set(`${n.edge}#${n.role}`,{entity:s,point:r,side:c,exit:n.inner?{x:-e.x,y:-e.y}:e,order:t,anchor:i,...n.port===void 0?{}:{port:n.port}})}});else{let e=[...x.keys()].sort(bc),t=new Set(e.slice(0,i)),n=T.filter(e=>t.has(e)),r=new Map;n.forEach((e,t)=>{let i=(t-(n.length-1)/2)*A,a=o(i),u=l(a);r.set(e,{point:a,anchor:u,order:t});for(let n of x.get(e)){let e=yc[c];f.set(`${n.edge}#${n.role}`,{entity:s,point:a,side:c,exit:n.inner?{x:-e.x,y:-e.y}:e,order:t,anchor:u,...n.port===void 0?{}:{port:n.port}})}});let u=new Map;T.forEach((e,t)=>u.set(e,t));let d=[...r.entries()];for(let t of e.slice(i)){let e=((u.get(t)??0)-(k-1)/2)*A,n=h?a.y+e:a.x+e,r=d[0],i=1/0;for(let[,e]of d){let t=h?e.point.y:e.point.x,a=Math.abs(t-n);a<i&&(i=a,r=d.find(([,t])=>t===e))}let o=r[1];for(let e of x.get(t)){let t=yc[c];f.set(`${e.edge}#${e.role}`,{entity:s,point:o.point,side:c,exit:e.inner?{x:-t.x,y:-t.y}:t,order:o.order,anchor:o.anchor,...e.port===void 0?{}:{port:e.port}})}}m.push({entity:s,side:c,required:k,fitted:i})}continue}k>=2&&A*(k+1)>O&&p.push({entity:s,side:c,needed:A*(k+1),available:O});let j=Math.min(A,O/(k+1)),M=xc(u);T.forEach((e,t)=>{let n=(t-(k-1)/2)*j,r=c===`east`?{x:u.x+u.width,y:M.y+n}:c===`west`?{x:u.x,y:M.y+n}:c===`north`?{x:M.x+n,y:u.y}:{x:M.x+n,y:u.y+u.height},i=h?(r.y-u.y)/u.height:(r.x-u.x)/u.width;for(let n of x.get(e)){let e=yc[c];f.set(`${n.edge}#${n.role}`,{entity:s,point:r,side:c,exit:n.inner?{x:-e.x,y:-e.y}:e,order:t,anchor:i,...n.port===void 0?{}:{port:n.port}})}})}let h=new Map;for(let e of t.edges)h.set(e.id,{source:f.get(`${e.id}#source`),target:f.get(`${e.id}#target`)});return{docks:h,demands:p,fixedOverflows:m}}var Oc=(e,t)=>e<t?-1:+(e>t),kc=e=>e===0?0:e,Ac=1e-4;function jc(e,t){let n=[],r=[],i=new Set,a=(e,a)=>{let o=new Map;for(let t of a){let n=e===`fan-in`?t.target:t.source,r=String(n.port??n.entity),i=`${r}\u0000${t.styleKey}`,a=o.get(i);a===void 0&&(a={hub:r,hubEntity:n.entity,...n.port===void 0?{}:{hubPort:n.port},styleKey:t.styleKey,members:[]},o.set(i,a)),a.members.push(t)}let s=[...o.keys()].sort((e,t)=>{let n=o.get(e),r=o.get(t);return Oc(n.hub,r.hub)||Oc(String(n.styleKey),String(r.styleKey))});for(let a of s){let s=o.get(a);if(s.members.length<2)continue;s.members.sort((e,t)=>Oc(e.occurrence,t.occurrence));let c=new Set;for(let e of s.members){let t=e.label?.trim();t!==void 0&&t.length>0&&c.add(t)}if(c.size>=2){r.push({hub:s.hub,members:s.members.map(e=>String(e.occurrence)),reason:`labels`});continue}for(let e of s.members)i.add(e.occurrence);if(!t.r7Routing){r.push({hub:s.hub,members:s.members.map(e=>String(e.occurrence)),reason:`v1-path`});continue}let l=[...c][0];n.push({id:`${e}|${s.hub}|${s.styleKey}`,kind:e,hub:s.hub,hubEntity:s.hubEntity,...s.hubPort===void 0?{}:{hubPort:s.hubPort},styleKey:s.styleKey,arrowhead:s.members[0].arrowhead,...l===void 0?{}:{label:l},members:s.members})}};return t.fanIn===`comb`&&a(`fan-in`,e),t.fanOut===`comb`&&a(`fan-out`,e.filter(e=>!i.has(e.occurrence))),{formed:n,fallbacks:r}}function Mc(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function Nc(e,t){let n=[],r=new Set,i=e;for(;i!==void 0&&!r.has(i);)r.add(i),n.push(i),i=t(i);return n}function Pc(e,t){if(e.length===0)return`root`;let n=e.map(e=>Nc(e,t).slice(1).reverse()),r=n[0],i;for(let e=0;e<r.length;e+=1){let t=r[e];if(n.every(n=>n[e]===t))i=t;else break}return i??`root`}function Fc(e,t,n){let r=e;for(;;){let e=n(r);if(t===`root`){if(e===void 0)return r}else if(e===t)return r;else if(e===void 0)return r;r=e}}function Ic(e){if(e.strips.length===0)return;let t=e.strips[0];return e.horizontal?{lo:t.y,hi:t.y+t.height}:{lo:t.x,hi:t.x+t.width}}function Lc(e){let{group:t,rects:n,placementParentOf:r,gridReports:i,gutters:a}=e,o=t.members.map(e=>t.kind===`fan-in`?e.source.entity:e.target.entity),s=t.hubEntity,c=n.get(s);if(c===void 0)return;let l=o.map(e=>n.get(e)).filter(e=>e!==void 0);if(l.length!==o.length)return;let u=Pc([s,...o],r),d=i[u],f=(e,t,n,r,i,o,s)=>{let c=a.find(r=>{if(r.horizontal!==e||s!==void 0&&!r.id.startsWith(`${s}|`))return!1;let i=Ic(r);return i!==void 0&&Math.abs(i.lo-t)<=1.5&&Math.abs(i.hi-n)<=1.5});if(c===void 0)return;let l=Ic(c);return{gutter:c,horizontal:e,gutterLo:l.lo,gutterHi:l.hi,gridSpanLo:r,gridSpanHi:i,ascending:o}};if(d!==void 0&&d.columns.length>0&&d.bands.length>0){let e=new Map(d.cells.map(e=>[e.entity,e])),t=Fc(s,u,r),n=e.get(t),i=o.map(t=>e.get(Fc(t,u,r)));if(n!==void 0&&i.every(e=>e!==void 0)){let e=i,t=Math.min(...d.columns.map(e=>e.start)),r=Math.max(...d.columns.map(e=>e.start+e.size)),a=Math.min(...d.bands.map(e=>e.start)),o=Math.max(...d.bands.map(e=>e.start+e.size)),s=e=>{if(e.colStart<0)return!1;let t=d.columns[e.colStart]?.kind;return t===`peripheral-start`||t===`peripheral-end`},u=Mc(c);if(e.every(e=>!s(e)&&e.bandStart>=0&&e.bandStart===e.bandEnd)&&e.every(t=>t.bandStart===e[0].bandStart)){let i=e[0].bandStart;if(!(!s(n)&&n.bandStart<=i&&n.bandEnd>=i)){let e=d.bands[i],n=u.y>e.start+e.size/2;if(n&&i+1<d.bands.length){let n=d.bands[i+1];return f(!0,e.start+e.size,n.start,t,r,!0,d.runKey)}if(!n&&i-1>=0){let n=d.bands[i-1];return f(!0,n.start+n.size,e.start,t,r,!1,d.runKey)}}}if(e.every(e=>e.colStart>=0&&e.colStart===e.colEnd)&&e.every(t=>t.colStart===e[0].colStart)){let t=e[0].colStart;if(!(n.colStart>=0&&n.colStart<=t&&n.colEnd>=t)){let e=d.columns[t],n=u.x>e.start+e.size/2;if(n&&t+1<d.columns.length){let n=d.columns[t+1];return f(!1,e.start+e.size,n.start,a,o,!0,d.runKey)}if(!n&&t-1>=0){let n=d.columns[t-1];return f(!1,n.start+n.size,e.start,a,o,!1,d.runKey)}}}let p=Math.min(...l.map(e=>e.x)),m=Math.max(...l.map(e=>e.x+e.width)),h=Math.min(...l.map(e=>e.y)),g=Math.max(...l.map(e=>e.y+e.height)),_=(p+m)/2,v=(h+g)/2,y=_-u.x,b=v-u.y;if(Math.abs(y)>=Math.abs(b)){let e=y>Ac?`east`:`west`;if(e===`east`&&n.colEnd>=0&&n.colEnd+1<d.columns.length){let e=d.columns[n.colEnd],t=d.columns[n.colEnd+1];return f(!1,e.start+e.size,t.start,a,o,!0,d.runKey)}if(e===`west`&&n.colStart>0){let e=d.columns[n.colStart-1],t=d.columns[n.colStart];return f(!1,e.start+e.size,t.start,a,o,!1,d.runKey)}}else{let e=b>0?`south`:`north`;if(e===`south`&&n.bandEnd>=0&&n.bandEnd+1<d.bands.length){let e=d.bands[n.bandEnd],i=d.bands[n.bandEnd+1];return f(!0,e.start+e.size,i.start,t,r,!0,d.runKey)}if(e===`north`&&n.bandStart>0){let e=d.bands[n.bandStart-1],i=d.bands[n.bandStart];return f(!0,e.start+e.size,i.start,t,r,!1,d.runKey)}}return}}let p=Mc(c),m=Math.min(...l.map(e=>e.x)),h=Math.max(...l.map(e=>e.x+e.width)),g=Math.min(...l.map(e=>e.y)),_=Math.max(...l.map(e=>e.y+e.height)),v=(m+h)/2-p.x,y=(g+_)/2-p.y,b=Math.abs(v)>=Math.abs(y)?v>Ac?`east`:`west`:y>0?`south`:`north`,x=b===`north`||b===`south`,S=b===`east`?c.x+c.width:b===`west`?c.x:b===`south`?c.y+c.height:c.y,C=a.filter(e=>{if(e.horizontal!==x)return!1;let t=Ic(e);return t===void 0?!1:b===`east`||b===`south`?Math.abs(t.lo-S)<=2:Math.abs(t.hi-S)<=2})[0];if(C===void 0)return;let w=Ic(C),T=Math.min(...C.strips.map(e=>x?e.x:e.y)),E=Math.max(...C.strips.map(e=>x?e.x+e.width:e.y+e.height));return{gutter:C,horizontal:x,gutterLo:w.lo,gutterHi:w.hi,gridSpanLo:T,gridSpanHi:E,ascending:b===`east`||b===`south`}}function Rc(e,t,n,r,i){let a=Math.max(t,r),o=Math.min(n,i);if(o-a<=Ac)return!0;let s=e.strips.map(t=>e.horizontal?[t.x,t.x+t.width]:[t.y,t.y+t.height]).sort((e,t)=>e[0]-t[0]||e[1]-t[1]);if(s.length===0)return!1;let c=[[s[0][0],s[0][1]]];for(let e=1;e<s.length;e+=1){let t=c[c.length-1],n=s[e];n[0]<=t[1]+1.5?t[1]=Math.max(t[1],n[1]):c.push([n[0],n[1]])}return c.some(([e,t])=>a>=e-1.5&&o<=t+1.5)}function zc(e,t,n,r,i,a,o,s){for(let[r,c]of n)if(!(a.has(r)&&s)){if(i.has(r)){if(Math.abs(e.y-t.y)<=Ac){let n=e.y,r=Math.min(e.x,t.x);if(Math.max(e.x,t.x)>c.x+Ac&&r<c.x+c.width-Ac&&(Math.abs(n-c.y)<o-Ac||Math.abs(n-(c.y+c.height))<o-Ac))return!1}else{let n=e.x,r=Math.min(e.y,t.y);if(Math.max(e.y,t.y)>c.y+Ac&&r<c.y+c.height-Ac&&(Math.abs(n-c.x)<o-Ac||Math.abs(n-(c.x+c.width))<o-Ac))return!1}}else if(js(e,t,c)<o-Ac)return!1}for(let n of r)if(!(s&&n.entity!==void 0&&a.has(n.entity))&&js(e,t,n.rect)<o-Ac)return!1;return!0}function Bc(e,t,n,r,i){let a=n===`east`||n===`west`?t.height>0?(r.y-t.y)/t.height:.5:t.width>0?(r.x-t.x)/t.width:.5;return{entity:e,point:{x:kc(r.x),y:kc(r.y)},side:n,exit:yc[n],order:0,anchor:kc(a),...i===void 0?{}:{port:i}}}function Vc(e,t,n,r,i,a){let o=t===`east`||t===`west`,s=(o?e.y:e.x)+a,c=(o?e.y+e.height:e.x+e.width)-a;if(c<s-Ac)return;let l=Math.max(s,Math.min(c,n)),u=e=>e>=s-Ac&&e<=c+Ac&&r.every(t=>Math.abs(t-e)>=i-Ac);if(u(l))return l;for(let e=1;e<=12;e+=1){let t=l+e*i;if(u(t))return t;let n=l-e*i;if(u(n))return n}}function Hc(e,t,n){let r=[...new Set(n.map(e=>Math.round(e*1e3)/1e3))].sort((e,t)=>e-t);if(r.length<2)return[];let i=n=>e?{x:kc(n),y:kc(t)}:{x:kc(t),y:kc(n)},a=[];for(let e=0;e+1<r.length;e+=1)r[e+1]-r[e]>Ac&&a.push([i(r[e]),i(r[e+1])]);a.sort((t,n)=>{let r=Math.hypot(t[1].x-t[0].x,t[1].y-t[0].y),i=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y);return Math.abs(r-i)>Ac?i-r:e?t[0].x-n[0].x:t[0].y-n[0].y});let o=[i(r[0]),i(r[r.length-1])];return a.length!==1&&a.push(o),a}function Uc(e){let{candidates:t,fanIn:n,fanOut:r,r7Routing:i,rects:a,placementParentOf:o,gridReports:s,gutters:c,barriers:l,isNorthBlockedByTitle:u,routeSpacing:d,borderClearance:f,cornerInset:p}=e,m=jc(t,{fanIn:n,fanOut:r,r7Routing:i}),h=[],g=[...m.fallbacks],_=new Map,v=new Map,y=new Map,b=new Set,x=new Set,S=new Map,C=new Map,w=[],T=[],E=new Map,D=(e,t,n)=>{let r=`${e}#${t}`,i=C.get(r)??[];i.push(n),C.set(r,i)};for(let e of m.formed){let t=Lc({group:e,rects:a,placementParentOf:o,gridReports:s,gutters:c});if(t===void 0){g.push({hub:e.hub,members:e.members.map(e=>String(e.occurrence)),reason:`gutter-full`});continue}let{gutter:n,horizontal:r,gutterLo:i,gutterHi:m,gridSpanLo:O,gridSpanHi:k,ascending:A}=t,j=Es(n.gap,d,f);if(j<=0){g.push({hub:e.hub,members:e.members.map(e=>String(e.occurrence)),reason:`gutter-full`});continue}let M=Gs(i+f,m-f,d).slice(0,j),ee=A?M:[...M].reverse(),te=a.get(e.hubEntity),ne=Mc(te),N=new Set(Nc(e.hubEntity,o).slice(1)),P=(e,t,n,i,o,s,c,m,h,g)=>{let _=r?{x:kc(s),y:kc(o)}:{x:kc(o),y:kc(s)},v=t=>[...C.get(`${e}#${t}`)??[],...h.get(`${e}#${t}`)??[]];if(!(i===`north`&&u(e))){let u=Vc(t,i,s,v(i),d,p);if(u!==void 0){let s=i===`east`?{x:t.x+t.width,y:u}:i===`west`?{x:t.x,y:u}:i===`north`?{x:u,y:t.y}:{x:u,y:t.y+t.height},d=r?{x:u,y:o}:{x:o,y:u};if(zc(s,d,a,l,c,new Set([e]),f,!0))return{dock:Bc(e,t,i,s,n),points:[s,d],joinAlong:u}}}let y=r?{x:0,y:Mc(t).y<o?-1:1}:{x:Mc(t).x<o?-1:1,y:0},b=[i,`south`,`north`,`west`,`east`].filter((t,n,r)=>r.indexOf(t)===n&&!(t===`north`&&u(e))),x=l.map(e=>e.rect);for(let i of b){let l=Vc(t,i,i===`east`||i===`west`?Mc(t).y:Mc(t).x,v(i),d,p);if(l===void 0)continue;let u=Bc(e,t,i,i===`east`?{x:t.x+t.width,y:l}:i===`west`?{x:t.x,y:l}:i===`north`?{x:l,y:t.y}:{x:l,y:t.y+t.height},n),h=_,b=oc({rects:a,requests:[{id:`__comb_seg__`,pairKey:`${e}|__trunk__`,start:u.point,startExit:u.exit,end:h,endExit:y,passable:new Set([...c,e]),...m===void 0?{}:{within:m}}],clearance:f,routeSpacing:d,barriers:x,avoidFallbackInteriors:!0,reservedRoutes:[...w,...g],lanes:r?{xs:[],ys:[o]}:{xs:[o],ys:[]}});if(b.obstructed.length>0)continue;let S=b.routes.get(`__comb_seg__`);if(!(S===void 0||S.length<2))return{dock:u,points:S,joinAlong:s}}},F=c.filter(e=>e.horizontal!==r).map(e=>{let t=Ic(e);return t===void 0?void 0:(t.lo+t.hi)/2}).filter(e=>e!==void 0),I=!1;for(let t=0;t<ee.length;t+=1){let i=ee[t],s=`${n.id}|${String(t)}`,c=new Map,u=(e,t,n)=>{let r=`${e}#${t}`,i=c.get(r)??[];i.push(n),c.set(r,i)},p=[],m=!0,g=[];for(let t of e.members){let n=e.kind===`fan-in`?t.source:t.target,s=a.get(n.entity),l=Mc(s),d=r?l.y<i?`south`:`north`:l.x<i?`east`:`west`,f=r?l.x:l.y,h=new Set(Nc(n.entity,o).slice(1)),_=P(n.entity,s,n.port,d,i,f,h,t.within,c,g);if(_===void 0){m=!1;break}u(n.entity,_.dock.side,r?_.dock.point.x:_.dock.point.y),g.push(_.points),p.push({edge:t,entity:n.entity,..._})}if(!m||p.length<2)continue;let C=Math.min(...p.map(e=>e.joinAlong)),A=Math.max(...p.map(e=>e.joinAlong)),j=r?ne.y<i?`south`:`north`:ne.x<i?`east`:`west`,M=r?ne.x:ne.y,re=[M,...[...F].sort((e,t)=>Math.abs(e-M)-Math.abs(t-M)),Math.max(C,Math.min(A,M)),(C+A)/2,C,A],L;for(let t of re){let n=P(e.hubEntity,te,e.hubPort,j,i,t,N,e.members[0].within,c,g);if(n!==void 0){L=n;break}}if(L===void 0)continue;let R=Math.min(C,L.joinAlong),ie=Math.max(A,L.joinAlong);if(!Rc(n,R,ie,O,k))continue;let z=E.get(s)??[];if(z.some(([e,t])=>R<t+d-Ac&&ie>e-d+Ac))continue;let ae=r?{x:kc(R),y:kc(i)}:{x:kc(i),y:kc(R)},B=r?{x:kc(ie),y:kc(i)}:{x:kc(i),y:kc(ie)},oe=new Set([...N]);for(let t of e.members)for(let e of t.passable)oe.add(e);if(!zc(ae,B,a,l,oe,new Set,f,!1))continue;let se=new Map,ce=new Map,le=[],ue=e.members[0].occurrence,V=L.points,de=[...V].reverse(),fe=r?{x:kc(L.joinAlong),y:kc(i)}:{x:kc(i),y:kc(L.joinAlong)};for(let t of p){let n=t.edge.occurrence,a=r?{x:kc(t.joinAlong),y:kc(i)}:{x:kc(i),y:kc(t.joinAlong)},o=ic(e.kind===`fan-in`?[...t.points,a,fe,...de]:[...V,fe,a,...[...t.points].reverse()]).map(e=>({x:kc(e.x),y:kc(e.y)}));se.set(n,o),ce.set(n,e.kind===`fan-in`?{source:t.dock,target:L.dock}:{source:L.dock,target:t.dock});let s=e.kind===`fan-in`&&t.edge.occurrence!==ue;le.push({id:String(t.edge.occurrence),source:String(t.edge.source.entity),target:String(t.edge.target.entity),points:o,...t.edge.source.port===void 0?{}:{sourcePort:String(t.edge.source.port)},...t.edge.target.port===void 0?{}:{targetPort:String(t.edge.target.port)},arrowhead:s?`none`:t.edge.arrowhead,passable:new Set([...t.edge.passable].map(String)),combGroupId:e.id})}if(Fs({rects:a,routes:[...T,...le],routeSpacing:d,borderClearance:f,barriers:l}).conflictCount>0)continue;z.push([R,ie]),E.set(s,z),D(e.hubEntity,L.dock.side,r?L.dock.point.x:L.dock.point.y);for(let e of p)D(e.entity,e.dock.side,r?e.dock.point.x:e.dock.point.y);for(let[e,t]of se)_.set(e,t),w.push(t);for(let[e,t]of ce)v.set(e,t);for(let e of le)T.push(e);for(let t of e.members)y.set(String(t.occurrence),e.id),t.occurrence!==ue&&(b.add(String(t.occurrence)),e.kind===`fan-in`&&x.add(String(t.occurrence)));e.label!==void 0&&S.set(String(ue),e.label);let pe=[...p.map(e=>e.joinAlong),L.joinAlong];h.push({id:e.id,kind:e.kind,hub:e.hub,carrier:ue,members:e.members.map(e=>e.occurrence),styleKey:e.styleKey,arrowhead:e.arrowhead,...e.label===void 0?{}:{label:e.label},trunkGutterId:n.id,trunk:[ae,B],trunkSegments:Hc(r,i,pe)}),I=!0;break}I||g.push({hub:e.hub,members:e.members.map(e=>String(e.occurrence)),reason:`gutter-full`})}return{groups:h,fallbacks:g,memberRoutes:_,memberDocks:v,memberCombId:y,suppressedLabels:b,suppressedArrowheads:x,carrierLabels:S,reservedSlots:C,reservedPolylines:w}}var Wc=e=>e===0?0:e;function Gc(e,t,n,r){if(!(r>0))return;let i=Math.ceil(r),a=n-t+1,o=Math.floor(i/a),s=i-o*a;for(let r=t;r<=n;r+=1)e[r]=(e[r]??0)+o+(r===n?s:0)}function Kc(e,t){let n=e??(t?`stretch`:`center`);return!t&&n===`stretch`?`center`:n}function qc(e,t,n,r,i){if(r===`stretch`&&i)return{pos:e,size:Math.max(n,t),stretched:!0};let a=Math.max(0,t-n);return r===`start`?{pos:e,size:n,stretched:!1}:r===`end`?{pos:e+a,size:n,stretched:!1}:{pos:e+a/2,size:n,stretched:!1}}function Jc(e,t,n,r,i,a){if(t)return{gap:r,base:r};let o=a?.get(e)??0;return{gap:Math.min(i,Math.max(n,o)),base:n}}function Yc(e,t){let n=new Set(t),r=Array.isArray(e.stage_columns)?e.stage_columns:void 0,i=e.transverse_bands.map(e=>e.id),a=new Set,o=new Set,s=new Set;r===void 0?e.transverse_bands.forEach((e,t)=>{e.items.some(e=>n.has(e))&&a.add(t)}):e.transverse_bands.forEach((t,c)=>{for(let l of t.items){if(!n.has(l))continue;let t=e.cells?.[l];if(t?.column===void 0)continue;let u=r.indexOf(t.column),d=t.to_column===void 0?u:r.indexOf(t.to_column),f=t.to_band===void 0?c:i.indexOf(t.to_band);if(!(u<0||d<u||f<c))for(let e=c;e<=f;e+=1){a.add(e);for(let t=u;t<=d;t+=1)o.add(t),s.add(`${String(e)}|${String(t)}`)}}});let c=[...a].sort((e,t)=>e-t);if(c.length===0)return;let l=new Map(c.map((e,t)=>[e,t])),u=[...o].sort((e,t)=>e-t),d=t=>(e.peripheral_columns??[]).filter(e=>e.side===t&&e.items.some(e=>n.has(e))).map(e=>{let t=0;if(e.from_band!==void 0){let n=i.indexOf(e.from_band);if(n>=0){let e;for(let t=n;t<i.length;t+=1){let n=l.get(t);if(n!==void 0){e=n;break}}t=e??c.length-1}}return{id:e.id,fromActive:t}}),f=d(`start`),p=d(`end`);for(let e=0;e<c.length;e+=1){let t=c[e],n=i[t];for(let t of f)if(e<t.fromActive)return{bandId:n,colId:t.id};if(r!==void 0){for(let e of u)if(!s.has(`${String(t)}|${String(e)}`))return{bandId:n,colId:r[e]}}for(let t of p)if(e<t.fromActive)return{bandId:n,colId:t.id}}}function Xc(e){let{scope:t,runKey:n,grid:r,visibleChildren:i,sizeOf:a,isContainer:o,isExpandedContainer:s,rowGaps:c,zoneGutter:l,widen:u,sigmaCols:d,sigmaBands:f,freeCellItem:p,inheritedContributions:m,onStageColumnsResolved:h}=e,g=new Set(i),_=new Set;for(let e of r.transverse_bands)for(let t of e.items)_.add(t);for(let e of r.peripheral_columns??[])for(let t of e.items)_.add(t);let v=i.filter(e=>!_.has(e)),y=Array.isArray(r.stage_columns)?r.stage_columns:void 0,b=y!==void 0,x=(r.peripheral_columns??[]).filter(e=>e.side===`start`),S=(r.peripheral_columns??[]).filter(e=>e.side===`end`),C=(e,t,i)=>{let d=e.items.filter(e=>g.has(e));if(d.length===0)return;let f=d.map(e=>{let t=a(e);return{entity:e,width:t.width,height:t.height,isContainer:o(e),isExpanded:s(e)}}),p=Math.max(...f.map(e=>e.width)),m=[],h=f.reduce((e,t)=>e+t.height,0);for(let t=0;t<f.length-1;t+=1){let r=f[t].isContainer||f[t+1].isContainer,i=`${n}|peripheral|${e.id}|${String(t)}`,{gap:a,base:o}=Jc(i,r,c.cardY,l,c.maxY,u);m.push({id:i,gap:a,base:o,zone:r}),h+=a}let _=0;if(e.from_band!==void 0&&i>0){let n=r.transverse_bands.findIndex(t=>t.id===e.from_band);if(n>=0){let e;for(let i=n;i<r.transverse_bands.length;i+=1){let n=t.get(i);if(n!==void 0){e=n;break}}_=e??i-1}}return{column:e,items:f,width:p,naturalHeight:h,itemGaps:m,hasContainer:f.some(e=>e.isContainer),fromBandActive:_}};return b?$c({scope:t,runKey:n,grid:r,stageCols:y,visibleSet:g,unplaced:v,startPeripheralsRaw:x,endPeripheralsRaw:S,buildPeripheral:C,sizeOf:a,isContainer:o,isExpandedContainer:s,rowGaps:c,zoneGutter:l,widen:u,sigmaCols:d,sigmaBands:f,freeCellItem:p,inheritedContributions:m,onStageColumnsResolved:h}):el({scope:t,runKey:n,grid:r,visibleSet:g,unplaced:v,startPeripheralsRaw:x,endPeripheralsRaw:S,buildPeripheral:C,sizeOf:a,isContainer:o,isExpandedContainer:s,rowGaps:c,zoneGutter:l,widen:u,sigmaCols:d,sigmaBands:f,freeCellItem:p})}function Zc(e,t,n,r,i,a,o,s,c){let l=Math.max(e.naturalHeight,Math.max(0,i-r))-e.naturalHeight,u=e.items.map((e,t)=>e.isExpanded?t:-1).filter(e=>e>=0),d=e.items.map(e=>e.height);if(l>0&&u.length>0){let e=Math.floor(l/u.length),t=l-e*u.length;u.forEach((n,r)=>{d[n]=d[n]+e+(r===u.length-1?t:0)})}let f=r;return e.items.forEach((r,i)=>{let l=d[i],u=r.isExpanded?Math.max(r.width,e.width):r.width,p=r.isExpanded?t:t+(e.width-u)/2,m={x:t,y:f,width:e.width,height:l};o.push({entity:r.entity,relX:Wc(p),relY:Wc(f),width:u,height:l,slotRelRect:m,stretchX:r.isExpanded&&u>r.width,stretchY:r.isExpanded&&l>r.height,isPeripheral:!0,colStart:n,colEnd:n,bandStart:e.fromBandActive,bandEnd:Math.max(e.fromBandActive,a)}),f+=l;let h=e.itemGaps[i];if(h!==void 0){let n=f;s.push((r,i)=>({id:h.id,horizontal:!0,strips:[{x:r+t,y:i+n,width:e.width,height:h.gap}],gap:h.gap,base:h.base,authoredBase:!1,max:c.maxY,zone:h.zone})),f+=h.gap}}),f}function Qc(e,t,n,r,i,a,o,s){let c=0,l=0,u=!1,d=t.map(e=>{let t=n(e),a=r(e);return a&&(u=!0),l=Math.max(l,t.height),{entity:e,width:t.width,height:t.height,isContainer:a,isExpanded:i(e)}}),f=[],p=[];return d.forEach((t,n)=>{f.push({entity:t.entity,relX:c,width:t.width,height:t.height,isExpanded:t.isExpanded}),c+=t.width;let r=d[n+1];if(r!==void 0){let i=t.isContainer||r.isContainer,l=`${e}|along|__trailing__|${String(n)}`,{gap:u,base:d}=Jc(l,i,a.cardX,o,a.maxX,s);p.push({id:l,startX:c,gap:u,base:d,zone:i}),c+=u}}),{width:c,height:l,hasContainer:u,items:f,gaps:p}}function $c(e){let{scope:t,runKey:n,grid:r,stageCols:i,visibleSet:a,unplaced:o,startPeripheralsRaw:s,endPeripheralsRaw:c,buildPeripheral:l,sizeOf:u,isContainer:d,isExpandedContainer:f,rowGaps:p,zoneGutter:m,widen:h,sigmaCols:g,sigmaBands:_,freeCellItem:v,inheritedContributions:y,onStageColumnsResolved:b}=e,x=r.transverse_bands.map(e=>e.id),S=[],C=0;r.transverse_bands.forEach((e,t)=>{for(let n of e.items){if(!a.has(n))continue;let e=r.cells?.[n];if(e?.column===void 0)continue;let o=i.indexOf(e.column),s=e.to_column===void 0?o:i.indexOf(e.to_column),c=e.to_band===void 0?t:x.indexOf(e.to_band);if(o<0||s<o||c<t)continue;let l=u(n);S.push({entity:n,declOrder:C,colStartDecl:o,colEndDecl:s,bandStartDecl:t,bandEndDecl:c,cell:e,width:l.width,height:l.height,isContainer:d(n),isExpanded:f(n)}),C+=1}});let w=new Set,T=new Set;for(let e of S){for(let t=e.colStartDecl;t<=e.colEndDecl;t+=1)w.add(t);for(let t=e.bandStartDecl;t<=e.bandEndDecl;t+=1)T.add(t)}for(let e of y??[])for(let t=e.colStartDecl;t<=e.colEndDecl;t+=1)w.add(t);let E=[...w].sort((e,t)=>e-t),D=[...T].sort((e,t)=>e-t),O=new Map(E.map((e,t)=>[e,t])),k=new Map(D.map((e,t)=>[e,t])),A=S.map(e=>({...e,colStart:O.get(e.colStartDecl),colEnd:O.get(e.colEndDecl),bandStart:k.get(e.bandStartDecl),bandEnd:k.get(e.bandEndDecl)})),j=s.map(e=>l(e,k,D.length)).filter(e=>e!==void 0),M=c.map(e=>l(e,k,D.length)).filter(e=>e!==void 0),ee=E.length,te=D.length,ne=Array.from({length:ee},()=>!1),N=Array.from({length:te},()=>!1);for(let e of A)if(e.isContainer){for(let t=e.colStart;t<=e.colEnd;t+=1)ne[t]=!0;for(let t=e.bandStart;t<=e.bandEnd;t+=1)N[t]=!0}let P=[...j.map(e=>({id:e.column.id,kind:`peripheral-start`,hasContainer:e.hasContainer,peripheral:e})),...E.map((e,t)=>({id:i[e],kind:`stage`,hasContainer:ne[t],stageIndex:t})),...M.map(e=>({id:e.column.id,kind:`peripheral-end`,hasContainer:e.hasContainer,peripheral:e}))],F=[];for(let e=0;e<P.length-1;e+=1){let t=P[e],r=P[e+1],i=t.hasContainer||r.hasContainer,a=`${n}|along|${t.id}`,{gap:o,base:s}=Jc(a,i,p.cardX,m,p.maxX,h);F.push({id:a,gap:o,base:s,zone:i})}let I=[];for(let e=0;e<te-1;e+=1){let t=r.transverse_bands[D[e]].id,i=N[e]||N[e+1],a=`${n}|across|${t}`,{gap:o,base:s}=Jc(a,i,p.cardY,m,p.maxY,h);I.push({id:a,gap:o,base:s,zone:i})}let re=Array.from({length:ee},()=>0);for(let e of A)e.colStart===e.colEnd&&(re[e.colStart]=Math.max(re[e.colStart],e.width));let L=v===void 0?-1:D.findIndex(e=>r.transverse_bands[e].id===v.bandId),R=v===void 0||L<0?-1:P.findIndex(e=>e.id===v.colId);if(v!==void 0&&R>=0){let e=P[R];e.kind===`stage`&&e.stageIndex!==void 0&&(re[e.stageIndex]=Math.max(re[e.stageIndex],v.width))}let ie=(y??[]).map(e=>({colStart:O.get(e.colStartDecl),colEnd:O.get(e.colEndDecl),neededWidth:e.neededWidth,declOrder:e.declOrder})).filter(e=>e.colStart!==void 0&&e.colEnd!==void 0&&e.colEnd>=e.colStart);for(let e of ie)e.colStart===e.colEnd&&(re[e.colStart]=Math.max(re[e.colStart],e.neededWidth));let z=j.length,ae=[...A.filter(e=>e.colEnd>e.colStart).map(e=>({colStart:e.colStart,colEnd:e.colEnd,width:e.width,declOrder:e.declOrder})),...ie.filter(e=>e.colEnd>e.colStart).map(e=>({colStart:e.colStart,colEnd:e.colEnd,width:e.neededWidth,declOrder:A.length+e.declOrder}))].sort((e,t)=>e.colEnd-e.colStart-(t.colEnd-t.colStart)||e.declOrder-t.declOrder);for(let e of ae){let t=0;for(let n=e.colStart;n<=e.colEnd;n+=1)t+=re[n],n<e.colEnd&&(t+=F[z+n].gap);Gc(re,e.colStart,e.colEnd,e.width-t)}g!==void 0&&E.forEach((e,t)=>{let n=g.get(i[e])??0;n>0&&(re[t]=re[t]+n)});let B=P.map((e,t)=>{let n=e.kind===`stage`?re[e.stageIndex]:e.peripheral.width;return v!==void 0&&t===R?Math.max(n,v.width):n}),oe=[],se=0;for(let e=0;e<P.length;e+=1)oe.push(se),se+=B[e],e<F.length&&(se+=F[e].gap);let ce=se,le=b?.({colIds:E.map(e=>i[e]),colStarts:E.map((e,t)=>oe[z+t]),colWidths:[...re],colGaps:Array.from({length:Math.max(0,ee-1)},(e,t)=>F[z+t].gap),declColToActive:O}),ue=le===void 0?A:A.map(e=>{let t=le.get(e.entity);return t===void 0?e:{...e,width:t.width,height:t.height}}),V=Array.from({length:te},()=>0);for(let e of ue)e.bandStart===e.bandEnd&&(V[e.bandStart]=Math.max(V[e.bandStart],e.height));v!==void 0&&L>=0&&R>=0&&(V[L]=Math.max(V[L],v.height));let de=ue.filter(e=>e.bandEnd>e.bandStart).sort((e,t)=>e.bandEnd-e.bandStart-(t.bandEnd-t.bandStart)||e.declOrder-t.declOrder);for(let e of de){let t=0;for(let n=e.bandStart;n<=e.bandEnd;n+=1)t+=V[n],n<e.bandEnd&&(t+=I[n].gap);Gc(V,e.bandStart,e.bandEnd,e.height-t)}_!==void 0&&D.forEach((e,t)=>{let n=_.get(r.transverse_bands[e].id)??0;n>0&&(V[t]=V[t]+n)});let fe=[],pe=0;for(let e=0;e<te;e+=1)fe.push(pe),pe+=V[e],e<I.length&&(pe+=I[e].gap);let me=pe,he=[],ge=[];for(let e of ue){let t=z+e.colStart,n=z+e.colEnd,r=oe[t],i=oe[n]+B[n]-r,a=fe[e.bandStart],o=fe[e.bandEnd]+V[e.bandEnd]-a,s=Kc(e.cell?.justify,e.isExpanded),c=Kc(e.cell?.align,e.isExpanded),l=qc(r,i,e.width,s,e.isExpanded),u=qc(a,o,e.height,c,e.isExpanded);he.push({entity:e.entity,relX:Wc(l.pos),relY:Wc(u.pos),width:l.size,height:u.size,slotRelRect:{x:Wc(r),y:Wc(a),width:i,height:o},stretchX:l.stretched,stretchY:u.stretched,isPeripheral:!1,colStart:t,colEnd:n,bandStart:e.bandStart,bandEnd:e.bandEnd})}let _e=me;P.forEach((e,t)=>{if(e.peripheral===void 0)return;let n=te>0?fe[e.peripheral.fromBandActive]:0,r=Zc(e.peripheral,oe[t],t,n,me,Math.max(0,te-1),he,ge,p);r>_e&&(_e=r)});let ve=[],ye=ce;if(o.length>0){let e=Qc(n,o,u,d,f,p,m,h),t=_e;if(_e>0){let r=te>0&&N[te-1]||e.hasContainer,i=`${n}|across|__trailing__`,{gap:a,base:o}=Jc(i,r,p.cardY,m,p.maxY,h),s=_e,c=Math.max(ce,e.width);ge.push((e,t)=>({id:i,horizontal:!0,strips:c>0?[{x:e,y:t+s,width:c,height:a}]:[],gap:a,base:o,authoredBase:!1,max:p.maxY,zone:r})),t+=a}let r=te;for(let n of e.items){let i=Kc(void 0,n.isExpanded),a=qc(t,e.height,n.height,i,n.isExpanded);he.push({entity:n.entity,relX:Wc(n.relX),relY:Wc(a.pos),width:n.width,height:a.size,slotRelRect:{x:Wc(n.relX),y:Wc(t),width:n.width,height:e.height},stretchX:!1,stretchY:a.stretched,isPeripheral:!1,colStart:-1,colEnd:-1,bandStart:r,bandEnd:r})}for(let n of e.gaps)ge.push((r,i)=>({id:n.id,horizontal:!1,strips:[{x:r+n.startX,y:i+t,width:n.gap,height:e.height}],gap:n.gap,base:n.base,authoredBase:!1,max:p.maxX,zone:n.zone}));ve.push({id:`__trailing__`,kind:`trailing`,start:t,size:e.height}),_e=t+e.height,ye=Math.max(ye,e.width)}for(let e=0;e<F.length;e+=1){let t=F[e],n=oe[e]+B[e],r=P[e],i=P[e+1],a=r.kind===`stage`&&i.kind===`stage`,o=r.stageIndex;ge.push((e,s)=>{let c=[],l,u,d=()=>{l!==void 0&&u!==void 0&&u>l&&c.push({x:e+n,y:s+l,width:t.gap,height:u-l}),l=void 0,u=void 0};for(let e=0;e<te;e+=1){let t=V[e];a&&o!==void 0&&A.some(t=>t.colStart<=o&&t.colEnd>=o+1&&t.bandStart<=e&&t.bandEnd>=e)?d():t>0&&(l===void 0&&(l=fe[e]),u=fe[e]+t)}if(!a&&_e>me){let e=Math.max(r.peripheral===void 0?me:(te>0?fe[r.peripheral.fromBandActive]:0)+r.peripheral.naturalHeight,i.peripheral===void 0?me:(te>0?fe[i.peripheral.fromBandActive]:0)+i.peripheral.naturalHeight);e>me&&(l===void 0&&(l=me),u=Math.max(u??me,e))}return d(),{id:t.id,horizontal:!1,strips:c,gap:t.gap,base:t.base,authoredBase:!1,max:p.maxX,zone:t.zone}})}for(let e=0;e<I.length;e+=1){let t=I[e],n=fe[e]+V[e];ge.push((r,i)=>{let a=[],o,s,c=()=>{o!==void 0&&s!==void 0&&s>o&&a.push({x:r+o,y:i+n,width:s-o,height:t.gap}),o=void 0,s=void 0};for(let t=0;t<ee;t+=1){let n=re[t];if(A.some(n=>n.bandStart<=e&&n.bandEnd>=e+1&&n.colStart<=t&&n.colEnd>=t)){c();continue}if(!(n>0))continue;let r=oe[z+t];o===void 0&&(o=r),s=r+n}return c(),{id:t.id,horizontal:!0,strips:a,gap:t.gap,base:t.base,authoredBase:!1,max:p.maxY,zone:t.zone}})}let be=P.map((e,t)=>({id:e.id,kind:e.kind,start:oe[t],size:B[t]})),xe=[...D.map((e,t)=>({id:r.transverse_bands[e].id,kind:`band`,start:fe[t],size:V[t]})),...ve],Se;if(v!==void 0&&L>=0&&R>=0){let e=oe[R],t=B[R],n=fe[L],r=V[L];Se={x:Wc(e+Math.max(0,t-v.width)/2),y:Wc(n+Math.max(0,r-v.height)/2),width:v.width,height:v.height}}return{scope:t,runKey:n,width:ye,height:_e,columns:be,bands:xe,placements:he,unplaced:o,...Se===void 0?{}:{freeCellRect:Se},emitGutters:(e,t)=>ge.map(n=>n(e,t)),toReport:(e,r)=>({scope:t,runKey:n,columns:be.map(t=>({...t,start:Wc(e+t.start)})),bands:xe.map(e=>({...e,start:Wc(r+e.start)})),cells:he.map(t=>({entity:t.entity,slotRect:{x:Wc(e+t.slotRelRect.x),y:Wc(r+t.slotRelRect.y),width:t.slotRelRect.width,height:t.slotRelRect.height},boxRect:{x:Wc(e+t.relX),y:Wc(r+t.relY),width:t.width,height:t.height},colStart:t.colStart,colEnd:t.colEnd,bandStart:t.bandStart,bandEnd:t.bandEnd}))})}}function el(e){let{scope:t,runKey:n,grid:r,visibleSet:i,unplaced:a,startPeripheralsRaw:o,endPeripheralsRaw:s,buildPeripheral:c,sizeOf:l,isContainer:u,isExpandedContainer:d,rowGaps:f,zoneGutter:p,widen:m,sigmaCols:h,sigmaBands:g,freeCellItem:_}=e,v=[],y=new Map;r.transverse_bands.forEach((e,t)=>{let a=e.items.filter(e=>i.has(e));if(a.length===0)return;y.set(t,v.length);let o=a.map(e=>{let t=l(e),n=d(e),i=r.cells?.[e];return{entity:e,width:t.width,height:t.height,isContainer:u(e),isExpanded:n,align:Kc(i?.align,n)}}),s=0,c=0,h=[],_=[];o.forEach((t,r)=>{c=Math.max(c,t.height),h.push({...t,relX:s}),s+=t.width;let i=o[r+1];if(i!==void 0){let a=t.isContainer||i.isContainer,o=`${n}|along|${e.id}|${String(r)}`,{gap:c,base:l}=Jc(o,a,f.cardX,p,f.maxX,m);_.push({id:o,startX:s,gap:c,base:l,zone:a}),s+=c}});let b=g?.get(e.id)??0;v.push({declIdx:t,id:e.id,items:h,intraGaps:_,width:s,height:c+(b>0?b:0),hasContainer:o.some(e=>e.isContainer)})});let b=o.map(e=>c(e,y,v.length)).filter(e=>e!==void 0),x=s.map(e=>c(e,y,v.length)).filter(e=>e!==void 0),S=h?.get(`__main__`)??0,C=(v.length>0?Math.max(...v.map(e=>e.width)):0)+(S>0?S:0),w=v.some(e=>e.hasContainer),T=_===void 0?-1:v.findIndex(e=>e.id===_.bandId);if(_!==void 0&&T>=0){let e=v[T];_.height>e.height&&(v[T]={...e,height:_.height})}let E=[...b.map(e=>({id:e.column.id,kind:`peripheral-start`,width:_!==void 0&&T>=0&&_.colId===e.column.id?Math.max(e.width,_.width):e.width,hasContainer:e.hasContainer,peripheral:e})),...v.length>0?[{id:`__main__`,kind:`stage`,width:C,hasContainer:w}]:[],...x.map(e=>({id:e.column.id,kind:`peripheral-end`,width:_!==void 0&&T>=0&&_.colId===e.column.id?Math.max(e.width,_.width):e.width,hasContainer:e.hasContainer,peripheral:e}))],D=[];for(let e=0;e<E.length-1;e+=1){let t=E[e].hasContainer||E[e+1].hasContainer,r=`${n}|along|${E[e].id}`,{gap:i,base:a}=Jc(r,t,f.cardX,p,f.maxX,m);D.push({id:r,gap:i,base:a,zone:t})}let O=[],k=0;for(let e=0;e<E.length;e+=1)O.push(k),k+=E[e].width,e<D.length&&(k+=D[e].gap);let A=E.findIndex(e=>e.kind===`stage`),j=A>=0?O[A]:0,M=[],ee=[],te=0;for(let e=0;e<v.length;e+=1)if(ee.push(te),te+=v[e].height,e<v.length-1){let t=v[e].hasContainer||v[e+1].hasContainer,r=`${n}|across|${v[e].id}`,{gap:i,base:a}=Jc(r,t,f.cardY,p,f.maxY,m);M.push({id:r,gap:i,base:a,zone:t}),te+=i}let ne=te,N=[],P=[];v.forEach((e,t)=>{let n=ee[t],r=Math.max(0,C-e.width),i=e.items.map((e,t)=>e.isExpanded?t:-1).filter(e=>e>=0),a=e.items.map(e=>e.width),o=e.items.map(()=>!1);if(S>0&&r>0&&i.length>0){let e=Math.floor(r/i.length),t=r-e*i.length;i.forEach((n,r)=>{let s=e+(r===i.length-1?t:0);s>0&&(a[n]=a[n]+s,o[n]=!0)})}let s=0;e.items.forEach((r,i)=>{let c=a[i],l=s,u=qc(n,e.height,r.height,r.align,r.isExpanded);N.push({entity:r.entity,relX:Wc(j+l),relY:Wc(u.pos),width:c,height:u.size,slotRelRect:{x:Wc(j+l),y:Wc(n),width:c,height:e.height},stretchX:o[i],stretchY:u.stretched,isPeripheral:!1,colStart:A,colEnd:A,bandStart:t,bandEnd:t}),s+=c;let d=e.intraGaps[i];if(d!==void 0){let t=s;P.push((r,i)=>({id:d.id,horizontal:!1,strips:[{x:r+j+t,y:i+n,width:d.gap,height:e.height}],gap:d.gap,base:d.base,authoredBase:!1,max:f.maxX,zone:d.zone})),s+=d.gap}})});for(let e=0;e<M.length;e+=1){let t=M[e],n=ee[e]+v[e].height;P.push((e,r)=>({id:t.id,horizontal:!0,strips:C>0?[{x:e+j,y:r+n,width:C,height:t.gap}]:[],gap:t.gap,base:t.base,authoredBase:!1,max:f.maxY,zone:t.zone}))}let F=ne;E.forEach((e,t)=>{if(e.peripheral===void 0)return;let n=v.length>0?ee[e.peripheral.fromBandActive]:0,r=Zc(e.peripheral,O[t],t,n,ne,Math.max(0,v.length-1),N,P,f);r>F&&(F=r)});for(let e=0;e<D.length;e+=1){let t=D[e],n=O[e]+E[e].width;P.push((e,r)=>({id:t.id,horizontal:!1,strips:F>0?[{x:e+n,y:r,width:t.gap,height:F}]:[],gap:t.gap,base:t.base,authoredBase:!1,max:f.maxX,zone:t.zone}))}let I=[],re=k;if(a.length>0){let e=Qc(n,a,l,u,d,f,p,m),t=F;if(F>0){let r=v.length>0&&v[v.length-1].hasContainer||e.hasContainer,i=`${n}|across|__trailing__`,{gap:a,base:o}=Jc(i,r,f.cardY,p,f.maxY,m),s=F,c=Math.max(re,e.width);P.push((e,t)=>({id:i,horizontal:!0,strips:c>0?[{x:e,y:t+s,width:c,height:a}]:[],gap:a,base:o,authoredBase:!1,max:f.maxY,zone:r})),t+=a}let r=v.length;for(let n of e.items){let i=Kc(void 0,n.isExpanded),a=qc(t,e.height,n.height,i,n.isExpanded);N.push({entity:n.entity,relX:Wc(n.relX),relY:Wc(a.pos),width:n.width,height:a.size,slotRelRect:{x:Wc(n.relX),y:Wc(t),width:n.width,height:e.height},stretchX:!1,stretchY:a.stretched,isPeripheral:!1,colStart:-1,colEnd:-1,bandStart:r,bandEnd:r})}for(let n of e.gaps)P.push((r,i)=>({id:n.id,horizontal:!1,strips:[{x:r+n.startX,y:i+t,width:n.gap,height:e.height}],gap:n.gap,base:n.base,authoredBase:!1,max:f.maxX,zone:n.zone}));I.push({id:`__trailing__`,kind:`trailing`,start:t,size:e.height}),F=t+e.height,re=Math.max(re,e.width)}let L=E.map((e,t)=>({id:e.id,kind:e.kind,start:O[t],size:e.width})),R=[...v.map((e,t)=>({id:e.id,kind:`band`,start:ee[t],size:e.height})),...I],ie;if(_!==void 0&&T>=0){let e=E.findIndex(e=>e.id===_.colId);if(e>=0){let t=O[e],n=E[e].width,r=ee[T],i=v[T].height;ie={x:Wc(t+Math.max(0,n-_.width)/2),y:Wc(r+Math.max(0,i-_.height)/2),width:_.width,height:_.height}}}return{scope:t,runKey:n,width:re,height:F,columns:L,bands:R,placements:N,unplaced:a,...ie===void 0?{}:{freeCellRect:ie},emitGutters:(e,t)=>P.map(n=>n(e,t)),toReport:(e,r)=>({scope:t,runKey:n,columns:L.map(t=>({...t,start:Wc(e+t.start)})),bands:R.map(e=>({...e,start:Wc(r+e.start)})),cells:N.map(t=>({entity:t.entity,slotRect:{x:Wc(e+t.slotRelRect.x),y:Wc(r+t.slotRelRect.y),width:t.slotRelRect.width,height:t.slotRelRect.height},boxRect:{x:Wc(e+t.relX),y:Wc(r+t.relY),width:t.width,height:t.height},colStart:t.colStart,colEnd:t.colEnd,bandStart:t.bandStart,bandEnd:t.bandEnd}))})}}function tl(e){let{scope:t,runKey:n,grid:r,visibleChildren:i,inherited:a,sizeOf:o,isContainer:s,isExpandedContainer:c,rowGaps:l,zoneGutter:u,widen:d}=e,f=new Set(i),p=new Set;for(let e of r.transverse_bands)for(let t of e.items)p.add(t);let m=i.filter(e=>!p.has(e)),{colIds:h,colStarts:g,colWidths:_,colGaps:v,firstColIdx:y,lastColIdx:b,containerSlotInset:x,contentInset:S}=a,C=g[y],w=g[b]+_[b],T=Math.max(0,w-C-2*x),E=Math.max(0,T-2*S),D=C+x+S,O=r.transverse_bands.map(e=>e.id),k=[],A=0;r.transverse_bands.forEach((e,t)=>{for(let n of e.items){if(!f.has(n))continue;let e=r.cells?.[n];if(e?.column===void 0)continue;let i=h.indexOf(e.column),a=e.to_column===void 0?i:h.indexOf(e.to_column),l=e.to_band===void 0?t:O.indexOf(e.to_band);if(i<y||a>b||a<i||l<t)continue;let u=o(n);k.push({entity:n,declOrder:A,colStartDecl:i,colEndDecl:a,bandStartDecl:t,bandEndDecl:l,cell:e,width:u.width,height:u.height,isContainer:s(n),isExpanded:c(n)}),A+=1}});let j=new Set;for(let e of k)for(let t=e.bandStartDecl;t<=e.bandEndDecl;t+=1)j.add(t);let M=[...j].sort((e,t)=>e-t),ee=new Map(M.map((e,t)=>[e,t])),te=k.map(e=>({...e,colStart:e.colStartDecl-y,colEnd:e.colEndDecl-y,bandStart:ee.get(e.bandStartDecl),bandEnd:ee.get(e.bandEndDecl)})),ne=b-y+1,N=M.length,P=Array.from({length:N},()=>!1);for(let e of te)if(e.isContainer)for(let t=e.bandStart;t<=e.bandEnd;t+=1)P[t]=!0;let F=[];for(let e=0;e<N-1;e+=1){let t=r.transverse_bands[M[e]].id,i=P[e]||P[e+1],a=`${n}|across|${t}`,{gap:o,base:s}=Jc(a,i,l.cardY,u,l.maxY,d);F.push({id:a,gap:o,base:s,zone:i})}let I=Array.from({length:N},()=>0);for(let e of te)e.bandStart===e.bandEnd&&(I[e.bandStart]=Math.max(I[e.bandStart],e.height));let re=te.filter(e=>e.bandEnd>e.bandStart).sort((e,t)=>e.bandEnd-e.bandStart-(t.bandEnd-t.bandStart)||e.declOrder-t.declOrder);for(let e of re){let t=0;for(let n=e.bandStart;n<=e.bandEnd;n+=1)t+=I[n],n<e.bandEnd&&(t+=F[n].gap);Gc(I,e.bandStart,e.bandEnd,e.height-t)}let L=[],R=0;for(let e=0;e<N;e+=1)L.push(R),R+=I[e],e<F.length&&(R+=F[e].gap);let ie=R,z=[],ae=[];for(let e of te){let t=e.colStartDecl===y||e.colEndDecl===b?x+S:0,n=g[e.colStartDecl]-D,r=g[e.colEndDecl]+_[e.colEndDecl]-D,i=n+t,a=Math.max(0,r-n-2*t),o=L[e.bandStart],s=L[e.bandEnd]+I[e.bandEnd]-o,c=Kc(e.cell?.justify,e.isExpanded),l=Kc(e.cell?.align,e.isExpanded),u=qc(i,a,e.width,c,e.isExpanded),d=qc(o,s,e.height,l,e.isExpanded);z.push({entity:e.entity,relX:Wc(u.pos),relY:Wc(d.pos),width:u.size,height:d.size,slotRelRect:{x:Wc(i),y:Wc(o),width:a,height:s},stretchX:u.stretched,stretchY:d.stretched,isPeripheral:!1,colStart:e.colStart,colEnd:e.colEnd,bandStart:e.bandStart,bandEnd:e.bandEnd})}let B=ie,oe=[],se=E;if(m.length>0){let e=Qc(n,m,o,s,c,l,u,d),t=B;if(B>0){let r=N>0&&P[N-1]||e.hasContainer,i=`${n}|across|__trailing__`,{gap:a,base:o}=Jc(i,r,l.cardY,u,l.maxY,d),s=B,c=Math.max(E,e.width);ae.push((e,t)=>({id:i,horizontal:!0,strips:c>0?[{x:e,y:t+s,width:c,height:a}]:[],gap:a,base:o,authoredBase:!1,max:l.maxY,zone:r})),t+=a}let r=N;for(let n of e.items){let i=Kc(void 0,n.isExpanded),a=qc(t,e.height,n.height,i,n.isExpanded);z.push({entity:n.entity,relX:Wc(n.relX),relY:Wc(a.pos),width:n.width,height:a.size,slotRelRect:{x:Wc(n.relX),y:Wc(t),width:n.width,height:e.height},stretchX:!1,stretchY:a.stretched,isPeripheral:!1,colStart:-1,colEnd:-1,bandStart:r,bandEnd:r})}for(let n of e.gaps)ae.push((r,i)=>({id:n.id,horizontal:!1,strips:[{x:r+n.startX,y:i+t,width:n.gap,height:e.height}],gap:n.gap,base:n.base,authoredBase:!1,max:l.maxX,zone:n.zone}));oe.push({id:`__trailing__`,kind:`trailing`,start:t,size:e.height}),B=t+e.height,se=Math.max(se,e.width)}for(let e=0;e<ne-1;e+=1){let t=y+e,r=g[t]+_[t]-D,i=v[t],a=`${n}|along|${h[t]}`;ae.push((t,n)=>{let o=[],s,c,d=()=>{s!==void 0&&c!==void 0&&c>s&&o.push({x:t+r,y:n+s,width:i,height:c-s}),s=void 0,c=void 0};for(let t=0;t<N;t+=1){let n=I[t];te.some(n=>n.colStart<=e&&n.colEnd>=e+1&&n.bandStart<=t&&n.bandEnd>=t)?d():n>0&&(s===void 0&&(s=L[t]),c=L[t]+n)}return d(),{id:a,horizontal:!1,strips:o,gap:i,base:u,authoredBase:!1,max:l.maxX,zone:!0}})}for(let e=0;e<F.length;e+=1){let t=F[e],n=L[e]+I[e];ae.push((r,i)=>{let a=[],o,s,c=()=>{o!==void 0&&s!==void 0&&s>o&&a.push({x:r+o,y:i+n,width:s-o,height:t.gap}),o=void 0,s=void 0};for(let t=0;t<ne;t+=1){let n=y+t;if(te.some(n=>n.bandStart<=e&&n.bandEnd>=e+1&&n.colStart<=t&&n.colEnd>=t)){c();continue}let r=_[n];if(!(r>0))continue;let i=Math.max(0,g[n]-D),a=Math.min(E,g[n]+r-D);a>i&&(o===void 0&&(o=i),s=a)}return c(),{id:t.id,horizontal:!0,strips:a,gap:t.gap,base:t.base,authoredBase:!1,max:l.maxY,zone:t.zone}})}let ce=Array.from({length:ne},(e,t)=>{let n=y+t;return{id:h[n],kind:`stage`,start:Wc(g[n]-D),size:_[n]}}),le=[...M.map((e,t)=>({id:r.transverse_bands[e].id,kind:`band`,start:L[t],size:I[t]})),...oe];return{scope:t,runKey:n,width:se,height:B,columns:ce,bands:le,placements:z,unplaced:m,emitGutters:(e,t)=>ae.map(n=>n(e,t)),toReport:(e,r)=>({scope:t,runKey:n,columns:ce.map(t=>({...t,start:Wc(e+t.start)})),bands:le.map(e=>({...e,start:Wc(r+e.start)})),cells:z.map(t=>({entity:t.entity,slotRect:{x:Wc(e+t.slotRelRect.x),y:Wc(r+t.slotRelRect.y),width:t.slotRelRect.width,height:t.slotRelRect.height},boxRect:{x:Wc(e+t.relX),y:Wc(r+t.relY),width:t.width,height:t.height},colStart:t.colStart,colEnd:t.colEnd,bandStart:t.bandStart,bandEnd:t.bandEnd}))})}}function nl(e){let{scope:t,runKey:n,stack:r,visibleChildren:i,sizeOf:a,isContainer:o,isExpandedContainer:s,rowGaps:c,zoneGutter:l,widen:u}=e,d=r.axis===`row`,f=r.align??`start`,p=i.map(e=>{let t=a(e);return{entity:e,width:t.width,height:t.height,isContainer:o(e),isExpanded:s(e)}});if(p.length===0)return{scope:t,runKey:n,axis:r.axis,width:0,height:0,placements:[],emitGutters:()=>[]};let m=Math.max(...p.map(e=>d?e.height:e.width)),h=[],g=[],_=0;p.forEach((e,t)=>{let r=Kc(f,e.isExpanded),i=qc(0,m,d?e.height:e.width,r,e.isExpanded);h.push({entity:e.entity,relX:Wc(d?_:i.pos),relY:Wc(d?i.pos:_),width:d?e.width:i.size,height:d?i.size:e.height,stretchX:!d&&i.stretched,stretchY:d&&i.stretched}),_+=d?e.width:e.height;let a=p[t+1];if(a!==void 0){let r=e.isContainer||a.isContainer,i=`${n}|${d?`along`:`across`}|${String(t)}`,{gap:o,base:s}=Jc(i,r,d?c.cardX:c.cardY,l,d?c.maxX:c.maxY,u);g.push({id:i,start:_,gap:o,base:s,zone:r}),_+=o}});let v=d?_:m,y=d?m:_;return{scope:t,runKey:n,axis:r.axis,width:v,height:y,placements:h,emitGutters:(e,t)=>g.map(n=>({id:n.id,horizontal:!d,strips:[d?{x:e+n.start,y:t,width:n.gap,height:m}:{x:e,y:t+n.start,width:m,height:n.gap}],gap:n.gap,base:n.base,authoredBase:!1,max:d?c.maxX:c.maxY,zone:n.zone}))}}var rl=Object.freeze({arrow:Object.freeze({viewBox:`0 0 10 10`,refX:9,refY:5,markerUnits:`userSpaceOnUse`,markerWidth:10.5,markerHeight:10.5,orient:`auto-start-reverse`,path:`M0 0L10 5L0 10Z`})}),il=`#001f33`,al=`var(--st-component-diagramScene-linkEmphasisStroke, var(--st-semantic-border-interactive, ${il}))`;function ol(e){return{filled:e,filledEmphasis:`${e}-emphasis`}}function sl(e){let t=fi(e);if(t!==void 0&&t.dashArray.length!==0)return t.dashArray.join(` `)}function cl(e){let t=sl(e);if(t!==void 0)return`stroke-dasharray:var(--st-component-diagramScene-${e===`dashed`?`linkDashDashed`:`linkDashDotted`}, ${t})`}function ll(e,t){return e.emphasis===`emphasis`?t?.linkEmphasisStrokeWidth??3.5:e.arrowhead===`none`?t?.linkRelatedStrokeWidth??3:t?.linkStrokeWidth??2.5}function ul(e){return pi(e)?.canonicalKind??`arrow`}function dl(e,t){if(e.markers===void 0&&e.directed!==!0&&ul(e.arrowhead)!==`none`)return`url(#${e.emphasis===`emphasis`?t.filledEmphasis:t.filled})`}function fl(e,t){let n=!1;for(let t of e)t.markers===void 0&&t.directed!==!0&&ul(t.arrowhead)!==`none`&&t.emphasis===`emphasis`&&(n=!0);let r=[];return n&&r.push({id:t.filledEmphasis,kind:`arrow`,emphasis:`emphasis`,...rl.arrow,fill:al}),r}var pl=Object.freeze([`solid`,`dashed`,`dotted`]),ml=Object.freeze([`default`,`emphasis`]),hl=Object.freeze([`arrow`,`none`]);Object.freeze(pl.flatMap(e=>ml.flatMap(t=>hl.map(n=>Object.freeze({strokeStyle:e,arrowhead:n,emphasis:t,key:`${e}:${n}:${t}`})))));var gl=18,_l=`var(--st-component-diagramScene-edgeStroke, #64748b)`,vl=al,yl=vt();function bl(e){return`${e.strokeStyle}:${e.arrowhead}:${e.emphasis}`}function xl(e){let t=[];return e.emphasis===`emphasis`&&t.push(`Emphasis`),e.strokeStyle===`dashed`?t.push(`Proposed (dashed)`):e.strokeStyle===`dotted`?t.push(`Dotted`):t.length===0&&t.push(`Link`),e.arrowhead===`none`&&t.push(`Undirected`),t.join(` · `)}function Sl(e){let t=pl.indexOf(e.strokeStyle),n=ml.indexOf(e.emphasis),r=hl.indexOf(e.arrowhead);return t*4+n*2+r}function Cl(e){let t=new Map;for(let n of e){if(n.markers!==void 0||n.directed===!0)continue;let e={strokeStyle:n.strokeStyle??`solid`,arrowhead:ul(n.arrowhead),emphasis:n.emphasis===`emphasis`?`emphasis`:`default`},r=bl(e),i=t.get(r);i===void 0?t.set(r,{...e,count:1}):i.count+=1}return t.size<2?[]:[...t.entries()].map(([e,t])=>({key:e,strokeStyle:t.strokeStyle,arrowhead:t.arrowhead,emphasis:t.emphasis,count:t.count})).sort((e,t)=>Sl(e)-Sl(t))}function wl(e,t){let n={text:t,role:`edge-label`,availableWidth:2**53-1,allocatedLines:1,folded:!1},r=e(n);return r.width>=n.availableWidth||!Number.isFinite(r.width)?yl(n).width:r.width}function Tl(e){let t=Cl(e.edges);if(t.length<2)return;let n=e.title??`Legend`,r=e.fontSize??gl,i=r>0&&Number.isFinite(r)?r/gl:1,a=i===1?30:Math.ceil(30*i),o=i===1?8:Math.ceil(8*i),s=Math.max(16,i===1?28:Math.ceil(28*i)),c=i===1?8:Math.ceil(8*i),l=t=>wl(e.measureLines,t)*i,u=l(n),d=0,f=t.map((t,n)=>{let r=e.labels?.[t.key]??xl(t),i=l(r);i>d&&(d=i);let u=16+a+o+n*(s+c);return{...t,label:r,rowY:u,rowHeight:s}}),p=Math.max(u,70+d);return{title:n,width:Math.ceil(Math.max(240,32+p)),height:32+a+o+f.length*s+Math.max(0,f.length-1)*c,entries:f,padding:16,headerHeight:a,headerGap:o,rowHeight:s,rowGap:c,swatchWidth:56,swatchHeight:16,swatchGap:14,fontSize:r}}function El(e,t,n,r){let i=t===`free-cell`&&r!==void 0?{x:r.x,y:r.y,width:e.width,height:e.height}:t===`bottom`?{x:n.x,y:n.y+n.height+48,width:e.width,height:e.height}:{x:n.x+n.width+48,y:n.y,width:e.width,height:e.height};return{anchor:t===`free-cell`&&r===void 0?`right`:t,title:e.title,rect:i,entries:e.entries,padding:e.padding,headerHeight:e.headerHeight,headerGap:e.headerGap,rowHeight:e.rowHeight,rowGap:e.rowGap,swatchWidth:e.swatchWidth,swatchHeight:e.swatchHeight,swatchGap:e.swatchGap,fontSize:e.fontSize}}function Dl(e){let t=e.anchor??`right`;if(t===`none`||e.contentBounds===void 0)return;let n=Tl(e);if(n!==void 0)return El(n,t,e.contentBounds)}function Ol(e,t){let n=e.emphasis===`emphasis`?vl:_l,r=ll(e,t),i=sl(e.strokeStyle),a=`M2 8H${e.arrowhead===`none`?54:46}`;return e.arrowhead===`none`?{viewBox:`0 0 56 16`,width:56,height:16,linePath:a,stroke:n,strokeWidth:r,...i===void 0?{}:{dashArray:i}}:{viewBox:`0 0 56 16`,width:56,height:16,linePath:a,arrowPath:`M44 3L54 8L44 13Z`,stroke:n,strokeWidth:r,...i===void 0?{}:{dashArray:i},arrowFill:n}}function kl(e){return typeof e!=`string`}function Al(e){let t=[],n=e=>{if(!kl(e))t.push(e);else for(let t of e.items)n(t)};for(let t of e.items)n(t);return t}function jl(e,t){let n=[],r=(e,t,r)=>{n.push({code:`layout-hint-invalid`,path:e,message:t,refs:r})};for(let[n,i]of Object.entries(e.ordering??{})){let e=n,a=new Set;for(let o of i)a.has(o)?r(`hints.ordering.${n}`,`duplicate member ${o} in the ordering of ${n}`,[o]):(a.add(o),!t.roots.has(o)&&!t.parentOf.has(o)?r(`hints.ordering.${n}`,`unknown member ${o} in the ordering of ${n}`,[o]):t.parentOf.get(o)!==e&&r(`hints.ordering.${n}`,`member ${o} is outside the sibling context of ${n}`,[o]))}let i=new Set;for(let n of e.rootOrder??[])(!t.roots.has(n)||i.has(n))&&r(`hints.rootOrder`,`${n} is not a root entity listed once in hints.rootOrder`,[n]),i.add(n);let a=(e,n)=>{let i=Al(e),o=new Set;for(let a of i)o.has(a)?r(`${n}.items`,`duplicate leaf ${a} in group ${e.id}`,[a]):(o.add(a),!t.roots.has(a)&&!t.parentOf.has(a)&&r(`${n}.items`,`unknown leaf ${a} in group ${e.id}`,[a]));let s=new Set;for(let e of new Set(i))t.roots.has(e)?s.add(void 0):s.add(t.parentOf.get(e));s.size>1&&r(`${n}.items`,`group ${e.id} mixes sibling contexts (${i.join(`, `)})`,[...new Set(i)]);for(let t of e.items)kl(t)&&a(t,`${n}.items.${t.id}`)};for(let t of e.grouping??[])a(t,`hints.grouping.${t.id}`);let o=new Map;for(let n of e.grouping??[]){let e=[...new Set(Al(n))],i=new Set;for(let n of e){let e=t.roots.has(n)?`__roots__`:`parent:${String(t.parentOf.get(n)??`__unknown__`)}`;i.add(e)}if(i.size!==1)continue;let a=[...i][0],s=o.get(a);s===void 0&&(s=new Map,o.set(a,s));for(let t of e){let e=s.get(t);e===void 0?s.set(t,n.id):r(`hints.grouping.${n.id}.items`,`duplicate leaf ${t} across groups ${e} and ${n.id}`,[t])}}return e.composition!==void 0&&Ml(e.composition,t,r),n}function Ml(e,t,n){let r=(e,t)=>e<t?-1:+(e>t),i=e=>t.roots.has(e)||t.parentOf.has(e),a=e=>t.containers?.has(e)??!1,o=e.grids;if(o===void 0||o.root===void 0){n(`hints.composition.grids.root`,`stage-columns composition requires a root grid`,[]);return}let s=new Map,c=new Set;for(let e of Object.keys(o).sort(r)){let l=o[e];if(l===void 0)continue;let u=`hints.composition.grids.${e}`;if(e!==`root`){let r=e;i(r)?t.containers!==void 0&&!a(r)&&n(u,`grid scope ${e} is not a container`,[r]):n(u,`unknown grid scope ${e}`,[r])}let d=(r,a)=>{c.has(r)?n(a,`duplicate placement of ${r} in composition`,[r]):c.add(r),i(r)?(e===`root`?t.roots.has(r):t.parentOf.get(r)===e)||n(a,`entity ${r} does not have ${e} as placement parent`,[r]):n(a,`unknown entity ${r} in grid ${e}`,[r])},f=new Set;for(let t of l.transverse_bands){let n=`${u}.transverse_bands.${t.id}.items`;for(let r of t.items)d(r,n),f.add(r),s.has(r)||s.set(r,e)}for(let e of l.peripheral_columns??[]){let t=`${u}.peripheral_columns.${e.id}.items`;for(let n of e.items)d(n,t)}for(let o of Object.keys(l.cells??{}).sort(r)){let r=o,s=l.cells?.[r];if(s===void 0)continue;let c=`${u}.cells.${o}`;i(r)?(f.has(r)||n(c,`cell entity ${o} is not a band item of grid ${e}`,[r]),t.containers!==void 0&&!a(r)&&(s.justify===`stretch`||s.align===`stretch`)&&n(c,`stretch alignment is admitted on containers only, not leaf ${o}`,[r])):n(c,`unknown cell entity ${o} in grid ${e}`,[r])}}let l=new Set,u=e=>{let t=o[e];if(t===void 0)return!1;if(t.stage_columns!==`inherit`)return t.stage_columns!==void 0;let r=`hints.composition.grids.${e}.stage_columns`;if(e===`root`||l.has(e))return n(r,`inherit on ${e} requires a cell in an enclosing staged grid`,e===`root`?[]:[e]),!1;let i=e,a=s.get(i),c=a===void 0?void 0:o[a],d=c?.cells?.[i];if(a===void 0||c===void 0||c.stage_columns===void 0||d?.column===void 0)return n(r,`inherit on ${e} requires a band cell in an enclosing staged grid`,[i]),!1;l.add(e);let f=u(a);return l.delete(e),f};for(let e of Object.keys(o).sort(r))o[e]?.stage_columns===`inherit`&&u(e);for(let s of Object.keys(e.stacks??{}).sort(r)){let c=s,l=e.stacks[c],u=`hints.composition.stacks.${s}`;if(!i(c))n(u,`unknown stack container ${s}`,[c]);else if(t.containers!==void 0&&!a(c))n(u,`stack key ${s} is not a container`,[c]);else if(o[c]!==void 0&&n(u,`container ${s} cannot declare both a grid and a stack`,[c]),l?.align===`stretch`&&t.containers!==void 0){let e=[];for(let[n,r]of t.parentOf)r===c&&!a(n)&&e.push(n);e.length>0&&n(`${u}.align`,`stretch alignment is admitted on containers only, not leaves in stack ${s}`,e.sort(r))}}}function Nl(e,t){let n=new Set(e),r=(t??[]).filter(e=>n.has(e)),i=e.filter(e=>!(t??[]).includes(e)).sort();return[...r,...i]}function Pl(e,t){return{cardGapX:e?.cardGapX??t.nodeGap,cardGapY:e?.cardGapY??t.nodeGap,zoneGapX:e?.zoneGapX??t.nodeGap,zoneGapY:e?.zoneGapY??t.nodeGap,rankGap:e?.rankGap??t.rankGap}}function Fl(e,t,n=!1){let r=n?Math.max(Ze.zoneGutter,t.zoneGutter??Ze.zoneGutter):void 0;return{cardX:e?.cardGapX??t.rowGapInline??t.gapMin??cc,cardY:e?.cardGapY??t.rowGapBlock??t.gapMinBlock??Ze.gapMinBlock,zoneX:r??e?.zoneGapX??t.rowGapInline??t.gapMin??cc,zoneY:r??e?.zoneGapY??t.rowGapBlock??t.gapMinBlock??Ze.gapMinBlock,maxX:t.gapInlineMax??t.gapMax??lc,maxY:t.gapBlockMax??t.gapMax??lc}}function Il(e,t){return e??t??!1}function Ll(e){let t=2166136261,n=16777619;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,16777619)>>>0,n=Math.imul(n^i+r,2166136261)>>>0}return t.toString(16).padStart(8,`0`)+n.toString(16).padStart(8,`0`)}var Rl=Ze.containerPadding;Ze.containerPadding,Ze.containerPadding;var zl=1e5;function Bl(e,t,n=18){if(t===void 0||!Number.isFinite(t)||t<=0||Math.abs(t-n)<1e-9)return e;let r=t/n;return t=>{if(t.role!==`edge-label`)return e(t);let n=Number.isFinite(t.availableWidth)?t.availableWidth/r:t.availableWidth,i=e({...t,availableWidth:n});return{...i,width:i.width*r,height:i.height*r}}}var Vl={kicker:1,title:2,body:4,detail:3,footer:1,subtitle:2,"legend-label":2,"edge-label":1,"flow-badge":1};function Hl(e){return e-2*Rl}function Ul(e,t){return t?e-66:e}function Wl(e,t,n){let r=t.height;return e!==void 0&&(r+=4+e.height),n!==void 0&&(r+=4+n.height),r}function Gl(e,t){let n=t=>e.allocatedLines[t]??Vl[t],r=(r,i,a)=>t({text:i,role:r,availableWidth:a,allocatedLines:n(r),folded:e.folded}),i=Ul(e.availableWidth,e.toggle),a=e.slots.kicker===void 0?void 0:r(`kicker`,e.slots.kicker,i),o=r(`title`,e.slots.title??``,i),s=e.slots.subtitle===void 0?void 0:r(`subtitle`,e.slots.subtitle,e.availableWidth),c=Wl(a,o,s);return{occurrence:e.occurrence,...a===void 0?{}:{kicker:a},title:o,...s===void 0?{}:{subtitle:s},height:c,overflow:(a?.overflow??!1)||o.overflow||(s?.overflow??!1)}}function Kl(e,t,n){let r=[],i=[[`kicker`,t.kicker],[`title`,t.title],[`subtitle`,t.subtitle]];for(let[a,o]of i){if(o===void 0||!o.overflow)continue;let i=e.allocatedLines[a]??Vl[a];r.push({occurrence:t.occurrence,slot:a,neededHeight:o.height,allocatedHeight:i*n(a),lines:o.lines.length,allocatedLines:i})}return r}var ql=(e,t)=>e<t?-1:+(e>t),Jl=e=>e===0?0:e,Yl=16/9,Xl=.02,Zl=[.56,.75,1,1.33,1.78,2.37,3.16,4.21];function Ql(e,t=Yl){let n=1e-9,r=1e-6,i=1e-9,a;for(let o of e){let e=o.height>0&&o.width>0?o.width/o.height:t,s=Math.abs(Math.log(e/t)),c={...o,ratio:e,distance:s};if(a===void 0)a=c;else if(c.distance<a.distance-n)a=c;else if(Math.abs(c.distance-a.distance)<=n){let e=c.width*c.height,t=a.width*a.height;if(e<t-r){a=c;continue}if(Math.abs(e-t)<=r){let e=Math.abs(c.tau-1.78),t=Math.abs(a.tau-1.78);if(e<t-i){a=c;continue}Math.abs(e-t)<=i&&c.tau<a.tau&&(a=c)}}}return a??{tau:1.78,width:0,height:0,ratio:t,distance:0}}function $l(e,t,n,r,i=!1){return n===void 0||r===`none`||i?{width:e,height:t}:r===`bottom`?{width:Math.max(e,n.width),height:t+48+n.height}:{width:e+48+n.width,height:Math.max(t,n.height)}}function eu(e){let t=e.target??1.7777777777777777,n=e.tolerance??.02;if(!(e.width>0)||!(e.height>0))return{sigmaCols:{},sigmaBands:{},capReached:!1,ratio:t};let r=e.width/e.height;if(Math.abs(r/t-1)<=n)return{sigmaCols:{},sigmaBands:{},capReached:!1,ratio:r};let i=(e,t,n)=>{let r=t.length;if(r===0||e<=0)return{map:{},capReached:e>0};let i=Math.floor(e/r),a=e-i*r,o={},s=!1;return t.forEach((e,t)=>{let c=i+(t===r-1?a:0);c>n&&(s=!0);let l=Math.min(n,c);l>0&&(o[e]=l)}),{map:Object.fromEntries(Object.entries(o).sort(([e],[t])=>ql(e,t))),capReached:s}};if(r<t){let{map:n,capReached:a}=i(Math.round(t*e.height-e.width),e.xTrackIds,e.capX);return{sigmaCols:n,sigmaBands:{},capReached:a,ratio:r}}let{map:a,capReached:o}=i(Math.round(e.width/t-e.height),e.yTrackIds,e.capY);return{sigmaCols:{},sigmaBands:a,capReached:o,ratio:r}}function tu(e){let t=new Set;for(let n of Object.values(e.entityOccurrences))n.group!==void 0&&t.add(n.group);let n={};for(let r of Object.keys(e.groups).sort(ql)){let i=e.groups[r];if(i.occurrence!==void 0&&r===oa(i.occurrence)&&i.label===void 0&&!t.has(r))continue;let{collapsed:a,...o}=i;n[r]=o}let r={};for(let t of Object.keys(e.relationOccurrences).sort(ql)){let n=e.relationOccurrences[t];r[t]={...n,endpoints:n.endpoints.map(e=>e.chainProvenance===void 0?e.sourceOccurrence===void 0?{role:e.role,occurrence:e.occurrence}:{role:e.role,occurrence:e.sourceOccurrence}:e)}}return{...e,groups:n,relationOccurrences:r,presentation:{...e.presentation,camera:void 0}}}function nu(e){return Ll(On(e))}function ru(e){let{gridReports:t,packedLevels:n,isContainer:r,zoneGutter:i}=e,a=new Set,o=[],s=e=>{let t=`${e.scope}|${e.axis}|${e.left}|${e.right}`;a.has(t)||(a.add(t),o.push(e))};for(let e of Object.keys(t).sort(ql)){let n=t[e],i=n.cells.filter(e=>r(e.entity));for(let t=0;t<i.length;t+=1){let r=i[t];for(let a=0;a<i.length;a+=1){if(t===a)continue;let o=i[a];if(r.colEnd>=0&&o.colStart>=0&&r.colEnd+1===o.colStart&&r.bandStart>=0&&o.bandStart>=0&&Math.max(r.bandStart,o.bandStart)<=Math.min(r.bandEnd,o.bandEnd)){let t=n.columns[r.colEnd],i=n.columns[o.colStart];if(t!==void 0&&i!==void 0){let n=Jl(i.start-(t.start+t.size)),a=Jl(t.start+t.size-(r.boxRect.x+r.boxRect.width)),c=Jl(o.boxRect.x-i.start),l=Jl(o.boxRect.x-(r.boxRect.x+r.boxRect.width));s({scope:e,axis:`horizontal`,left:r.entity,right:o.entity,paintedGap:l,token:n,slack:Jl(a+c),fromSlack:a,toSlack:c})}}if(r.bandEnd>=0&&o.bandStart>=0&&r.bandEnd+1===o.bandStart&&(r.colStart>=0&&o.colStart>=0?Math.max(r.colStart,o.colStart)<=Math.min(r.colEnd,o.colEnd):Math.min(r.boxRect.x+r.boxRect.width,o.boxRect.x+o.boxRect.width)>Math.max(r.boxRect.x,o.boxRect.x))){let t=n.bands[r.bandEnd],i=n.bands[o.bandStart];if(t!==void 0&&i!==void 0){let n=Jl(i.start-(t.start+t.size)),a=Jl(t.start+t.size-(r.boxRect.y+r.boxRect.height)),c=Jl(o.boxRect.y-i.start),l=Jl(o.boxRect.y-(r.boxRect.y+r.boxRect.height));s({scope:e,axis:`vertical`,left:r.entity,right:o.entity,paintedGap:l,token:n,slack:Jl(a+c),fromSlack:a,toSlack:c})}}}}}for(let e of n){let{scope:t,rows:n,shelves:a}=e;for(let e=0;e<a.length;e+=1){let o=a[e],c=Math.max(...n?o.map(e=>e.rect.y+e.rect.height):o.map(e=>e.rect.x+e.rect.width)),l=a[e+1],u=l===void 0?void 0:Math.min(...n?l.map(e=>e.rect.y):l.map(e=>e.rect.x));for(let e=0;e<o.length-1;e+=1){let a=o[e],c=o[e+1];if(!r(a.entity)||!r(c.entity))continue;let l=Jl(n?c.rect.x-(a.rect.x+a.rect.width):c.rect.y-(a.rect.y+a.rect.height));s({scope:t,axis:n?`horizontal`:`vertical`,left:a.entity,right:c.entity,paintedGap:l,token:i,slack:Jl(l-i),fromSlack:0,toSlack:Jl(l-i)})}if(l!==void 0&&u!==void 0){let e=Jl(u-c);for(let i of o)if(r(i.entity))for(let a of l){if(!r(a.entity)||!(n?Math.min(i.rect.x+i.rect.width,a.rect.x+a.rect.width)>Math.max(i.rect.x,a.rect.x):Math.min(i.rect.y+i.rect.height,a.rect.y+a.rect.height)>Math.max(i.rect.y,a.rect.y)))continue;let o=Jl(n?c-(i.rect.y+i.rect.height):c-(i.rect.x+i.rect.width)),l=Jl(n?a.rect.y-u:a.rect.x-u),d=Jl(n?a.rect.y-(i.rect.y+i.rect.height):a.rect.x-(i.rect.x+i.rect.width));s({scope:t,axis:n?`vertical`:`horizontal`,left:i.entity,right:a.entity,paintedGap:d,token:e,slack:Jl(o+l),fromSlack:o,toSlack:l})}}}}return o.sort((e,t)=>ql(e.scope,t.scope)||ql(e.axis,t.axis)||ql(e.left,t.left)||ql(e.right,t.right)),{all:o,aboveToken:o.filter(e=>e.paintedGap>i+1e-6)}}function iu(e,t,n,r,i,a){let o=e?.form===`container`||e?.form===`legend`,s=new Map,c=(e,t,n)=>{let a=JSON.stringify([e,t,n]),o=s.get(a);return o===void 0&&(o=i({text:e,role:t,availableWidth:n,allocatedLines:Vl[t],folded:r}),s.set(a,o)),o},l=(e,t,n,i)=>{let a=c(e,o&&!r&&t===`body`?`subtitle`:t,n);return{lines:a.lines,tooWide:a.width>n,lineWidths:a.lines.map(()=>a.width)}},u=()=>({face:``}),d=o?Nt(e,{entityId:t,collapsed:r,width:n,...a===void 0?{}:{containerPadding:a},toggleLabel:`toggle`,resolveGlyph:u}):ut(e,{entityId:t,resolveGlyph:u}),f=d.kind===`label`?{entityId:t,title:e?.text.title??``,body:[]}:d.props,p=d.kind===`zone`?Mt({...d.props,autoSize:!0},l):wt({...f,autoSize:!0},l),m=`collapsed`in p?p.card:p,h=it(m?.anatomyFallback??e?.anatomy),g=Dt(e?.anatomy),_=`collapsed`in p?p.header:void 0,v=m?.headerTextWidth??_.headerTextWidth,y=e?.text.kicker===void 0?void 0:c(e.text.kicker,`kicker`,v),b=c(e?.text.title??``,`title`,v),x=_===void 0||e?.text.subtitle===void 0?void 0:c(e.text.subtitle,`subtitle`,_.subtitleWidth),S=(e,t,n)=>e===void 0?void 0:{...e,lines:t?.map(e=>e.text)??[],height:(t?.length??0)*ct(n),overflow:!1},C=S(y,m?.kicker??_?.kicker,nt.kicker.size),w=S(b,m?.title??_?.title,nt.title.size),T=S(x,_?.subtitle,nt.body.size),E=Math.max(d.kind===`label`||e?.icon===`none`?0:h.iconSize,(C?.height??0)+w.height),D=_===void 0?E:E+g.headerRuleGap+(T===void 0||T.lines.length===0?0:g.subtitleGap+T.height),O={occurrence:t,...C===void 0?{}:{kicker:C},title:w,...T===void 0?{}:{subtitle:T},height:D,overflow:(C?.overflow??!1)||w.overflow||(T?.overflow??!1)},k=_===void 0||_.footer.length===0?0:_.footer.length*ct(g.footer.size)+g.ruleHeight+2*g.ruleMargin+g.footerBottomInset;return{width:p.box.width,height:p.box.height,header:O,bodyWidth:m?.bodyWidth??n-2*(a??g.contentInsetInline),footerWidth:m===void 0?n-2*(a??g.contentInsetInline):m.box.width-h.borderWidth-h.padding-h.headerInset,footerReserve:k,diagnostics:p.diagnostics}}var au=400,ou=(e,t)=>e<t?-1:+(e>t);function su(e,t){let n=e.entities[t]?.attributes?.name;return n!==void 0&&n.kind===`text`&&typeof n.value==`string`?n.value:``}function cu(e,t){return e.entities[t]?.form}function lu(e){let t=e.contractPin!==void 0&&Xi(e.contractPin),n={};for(let[r,i]of Object.entries(e.entities)){let e=i,a={};for(let[n,r]of Object.entries(e))n!==`anatomy`&&n!==`depth`&&n!==`depthParityStart`&&(n!==`align`||t)&&(a[n]=r);n[r]=a}let{relations:r,...i}=e;return{...i,entities:n}}function uu(e,t,n){if(e!==void 0)return e[t]??e[n]}var du=new Set([`id`,`relation`,`endpoints`,`waypoints`,`strokeStyle`,`arrowhead`,`emphasis`]);function fu(e,t,n){let r=[],i=t!==void 0&&Xi(t),a=t!==void 0&&!i;if(e!==void 0&&(typeof e!=`object`||!e||Array.isArray(e)))r.push({code:`document-invalid`,path:`presentation.relations`,message:`connector styles must be keyed by relation`});else if(e!==void 0){let t=Object.keys(e).sort(ou);if(a&&t.length>0)for(let e of t)r.push({code:`document-invalid`,path:`presentation.relations.${e}`,message:`presentation.relations requires diagram-presentation@2; frozen diagram-presentation@1 cannot persist DE-2 connector styles`});for(let n of t){let t=e[n];if(t!==void 0){if(typeof t!=`object`||!t||Array.isArray(t))r.push({code:`document-invalid`,path:`presentation.relations.${n}`,message:`connector style must be a record`});else{for(let e of Object.keys(t).sort(ou))e!==`strokeStyle`&&e!==`arrowhead`&&e!==`emphasis`&&r.push({code:`document-invalid`,path:`presentation.relations.${n}.${e}`,message:`unknown connector presentation field ${e}; select connectors by closed registry words only`});t.strokeStyle!==void 0&&!li(t.strokeStyle)&&r.push({code:`document-invalid`,path:`presentation.relations.${n}.strokeStyle`,message:`strokeStyle ${String(t.strokeStyle)} is not a closed dash-pattern registry word`}),t.arrowhead!==void 0&&!ui(t.arrowhead)&&r.push({code:`document-invalid`,path:`presentation.relations.${n}.arrowhead`,message:`arrowhead ${String(t.arrowhead)} is not a closed arrowhead registry word`}),t.emphasis!==void 0&&!di(t.emphasis)&&r.push({code:`document-invalid`,path:`presentation.relations.${n}.emphasis`,message:`emphasis ${String(t.emphasis)} is not a closed link-emphasis registry word`})}}}}if(n!==void 0)for(let e of Object.keys(n.relationOccurrences).sort(ou)){let t=n.relationOccurrences[e];if(t===void 0)continue;if(typeof t!=`object`||!t||Array.isArray(t)){r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}`,message:`relation occurrence must be a record`});continue}for(let n of Object.keys(t).sort(ou))du.has(n)||r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.${n}`,message:`unknown connector occurrence field ${n}; select connectors by closed registry words only`});let i=t.strokeStyle;i!==void 0&&(li(i)?a&&i===`dotted`&&r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.strokeStyle`,message:`strokeStyle dotted requires diagram-presentation@2 under view validation`}):r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.strokeStyle`,message:`strokeStyle ${String(i)} is not a closed dash-pattern registry word`}));let o=t.arrowhead;o!==void 0&&(ui(o)?a&&r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.arrowhead`,message:`arrowhead requires diagram-presentation@2 under view validation`}):r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.arrowhead`,message:`arrowhead ${String(o)} is not a closed arrowhead registry word`}));let s=t.emphasis;s!==void 0&&(di(s)?a&&r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.emphasis`,message:`emphasis requires diagram-presentation@2 under view validation`}):r.push({code:`document-invalid`,path:`sourceView.relationOccurrences.${e}.emphasis`,message:`emphasis ${String(s)} is not a closed link-emphasis registry word`}))}return r}function pu(e,t,n,r){let i=t.entities[n]?.text,a={};i?.kicker!==void 0&&(a.kicker=i.kicker);let o=i?.title??su(e,r);return o!==``&&(a.title=o),i?.body!==void 0&&(a.body=i.body),i?.detail!==void 0&&(a.detail=i.detail),i?.subtitle!==void 0&&(a.subtitle=i.subtitle),i?.footer!==void 0&&(a.footer=i.footer),a}function mu(e,t){let n=e.relations[t]?.attributes?.label;if(n!==void 0&&n.kind===`text`&&typeof n.value==`string`&&n.value!==``)return n.value}function hu(e){let t={};for(let[n,r]of Object.entries(e.relationOccurrences))t[n]={...r,endpoints:r.endpoints.map(e=>e.sourceOccurrence===void 0?{role:e.role,occurrence:e.occurrence}:{role:e.role,occurrence:e.sourceOccurrence})};return{...e,relationOccurrences:t}}function gu(e,t){let n={};if(e!==void 0)for(let[r,i]of Object.entries(e.groups)){let e=i;if(e.occurrence===void 0)n[r]={id:e.id,occurrence:void 0};else if(t.has(e.occurrence))n[r]={id:e.id,occurrence:e.occurrence,collapsed:!0};else if(e.collapsed===void 0){let{collapsed:t,...i}=e;n[r]=i}else n[r]={id:e.id,occurrence:e.occurrence,collapsed:!1}}for(let e of t){if(Object.keys(n).find(t=>n[t]?.occurrence===e)!==void 0)continue;let t=e,r=t.includes(`:`)?t.slice(t.indexOf(`:`)+1):t,i=`grp.${r.length}.${r}`;n[i]===void 0&&(n[i]={id:i,occurrence:e,collapsed:!0})}return n}var _u=e=>e===0?0:e,vu=6,yu=.5,bu=6,xu=(e,t)=>{let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>e[n]===t[n])};function Su(e,t,n){let r=n===void 0?void 0:tu(n),{previousOrientation:i,...a}=t,o={...a,collapsed:[]},s={sceneBoxCache:new Map};if(t.hints?.composition?.aspect!==`16:9`){let t=1.78,n={autoPackLevels:{},innerWiden:{}},i=wu(e,o,r,new Set,{mode:`nominal-plan`,tauOverride:t,capture:n,shared:s});if(i.status===`refused`)return{status:`refused`,result:i};let a=Object.fromEntries(Object.entries(n.autoPackLevels).sort(([e],[t])=>ou(e,t))),c=Object.fromEntries(Object.entries(n.innerWiden).sort(([e],[t])=>ou(e,t))),l={},u={},d=n.legendCell;return{status:`ok`,plan:{planDigest:nu({tau:t,autoPackLevels:a,innerWiden:c,sigmaCols:l,sigmaBands:u,...d===void 0?{}:{legendCell:d}}),tau:t,autoPackLevels:a,innerWiden:c,sigmaCols:l,sigmaBands:u,...d===void 0?{}:{legendCell:d}},...s.graph===void 0?{}:{graph:s.graph}}}let c=[],l,u,d=new Map;for(let t of Zl){let n={autoPackLevels:{},innerWiden:{}},i=wu(e,o,r,new Set,{mode:`nominal-plan`,tauOverride:t,sizingOnly:!0,capture:n,shared:s});if(i.status===`refused`)return{status:`refused`,result:i};let a=n.sizingReport;if(a===void 0)return{status:`refused`,result:i};u===void 0&&n.legendCell!==void 0&&(u=n.legendCell),d.set(t,a);let l=$l(a.rootWidth,a.rootHeight,a.legendSize,a.effectiveLegendAnchor,a.legendInsideCell);c.push({tau:t,width:l.width,height:l.height})}let f=Ql(c,Yl);l=d.get(f.tau);let p=eu({width:f.width,height:f.height,xTrackIds:l.xTrackIds,yTrackIds:l.yTrackIds,capX:l.capX,capY:l.capY}),m={autoPackLevels:{},innerWiden:{}},h=wu(e,o,r,new Set,{mode:`nominal-plan`,tauOverride:f.tau,sigmaColsOverride:p.sigmaCols,sigmaBandsOverride:p.sigmaBands,...u===void 0?{}:{legendCellOverride:u},capture:m,shared:s});if(h.status===`refused`)return{status:`refused`,result:h};let g=m.paintedBounds??{width:f.width,height:f.height},_=g.height>0&&g.width>0?g.width/g.height:Yl,v=Math.abs(Math.log(_/Yl)),y=m,b=p.sigmaCols,x=p.sigmaBands,S=_,C=0;if(Math.abs(_/1.7777777777777777-1)>.02){let t=Object.values(p.sigmaCols).reduce((e,t)=>e+t,0),n=Object.values(p.sigmaBands).reduce((e,t)=>e+t,0),i=eu({width:Math.max(1,g.width-t),height:Math.max(1,g.height-n),xTrackIds:l.xTrackIds,yTrackIds:l.yTrackIds,capX:l.capX,capY:l.capY});if(!xu(i.sigmaCols,p.sigmaCols)||!xu(i.sigmaBands,p.sigmaBands)){C=1;let t={autoPackLevels:{},innerWiden:{}};if(wu(e,o,r,new Set,{mode:`nominal-plan`,tauOverride:f.tau,sigmaColsOverride:i.sigmaCols,sigmaBandsOverride:i.sigmaBands,...u===void 0?{}:{legendCellOverride:u},capture:t,shared:s}).status===`laid-out`){let e=t.paintedBounds??g,n=e.height>0&&e.width>0?e.width/e.height:Yl;Math.abs(Math.log(n/1.7777777777777777))<v-1e-9&&(y=t,b=i.sigmaCols,x=i.sigmaBands,S=n)}}}let w=Object.fromEntries(Object.entries(y.autoPackLevels).sort(([e],[t])=>ou(e,t))),T=Object.fromEntries(Object.entries(y.innerWiden).sort(([e],[t])=>ou(e,t))),E=_u(Math.round(S*1e6)/1e6),D=Math.abs(S/Yl-1)>Xl,O=u??y.legendCell;return{status:`ok`,plan:{planDigest:nu({tau:f.tau,autoPackLevels:w,innerWiden:T,sigmaCols:b,sigmaBands:x,...O===void 0?{}:{legendCell:O}}),tau:f.tau,autoPackLevels:w,innerWiden:T,sigmaCols:b,sigmaBands:x,...O===void 0?{}:{legendCell:O},nominalAspect:E,postRouteCorrectionRounds:C,...D?{aspectUnreached:{achieved:E,target:Yl}}:{}},...s.graph===void 0?{}:{graph:s.graph}}}function Cu(e,t,n,r){let i=fu(t.presentation?.relations,t.presentation?.contractPin??n?.presentation.diagram?.contractPin,n);if(i.length>0)return{status:`refused`,refusals:i,diagnostics:[]};if(e.profileRefs.length===1&&e.profileRefs[0]===`erd@1`)return hc(e,t,n);let a;if(t.hints?.composition!==void 0){let i=r?.plan,o=r?.graph;if(i===void 0){let r=Su(e,t,n);if(r.status===`refused`)return r.result;i=r.plan,o=r.graph}a={mode:`state`,plan:i,...r?.memo===void 0?{}:{memo:r.memo},...o===void 0?{}:{shared:{graph:o}}}}let o=wu(e,t,n,new Set,a);if(o.status!==`laid-out`||o.flowTargets===void 0)return o;let s=new Set,c=new Set(o.warnings.filter(e=>e.code===`route-obstructed`||e.code===`badge-unplaced`).flatMap(e=>e.refs)),l=Vo(e,o.view,t.registry,t,new Set);for(let[e,t]of l.groups)t.length>=2&&!o.flowBundles?.some(t=>t.id===e)&&t.some(e=>c.has(e.occurrence))&&s.add(e);if(s.size===0)return o;let u=wu(e,t,n,s,a);return u.status===`laid-out`?{...u,flowRepairPasses:1}:u}function wu(e,t,n,r,i){if(!Number.isFinite(t.targetWidth)||t.targetWidth<=0)return{status:`refused`,refusals:[{code:`target-width-invalid`,path:`targetWidth`,message:`the target width is a positive number of CSS px, got ${String(t.targetWidth)}`}],diagnostics:[]};if(n!==void 0&&Object.values(n.entityOccurrences).some(t=>e.entities[t.entity]?.type===`flow-scenario`))return{status:`refused`,refusals:[{code:`document-invalid`,path:`sourceView.entityOccurrences`,message:`flow scenarios have no view occurrence`}],diagnostics:[]};let a=t.presentation;if(a===void 0)return{status:`refused`,refusals:[{code:`document-invalid`,path:`presentation`,message:`measured layout needs presentation.diagram`}],diagnostics:[]};let o=e=>cs(a,n,e),s=e=>it(o(e)).width;if(t.measureLines===void 0)return{status:`refused`,refusals:[{code:`measure-lines-missing`,path:`measureLines`,message:`measured layout needs an injected LineMeasurer through options.measureLines`}],diagnostics:[]};let c=t.measureLines,l=i?.shared?.sceneBoxCache??new Map,u=(e,t,n)=>{let r=`${e}|${t}|${n}`,i=l.get(r);if(i===void 0){let s=a.entities[e],u=s===void 0?void 0:{...s,anatomy:o(e)},d=B.get(A.entityOccurrences[e]?.entity);i=iu((d===`container-expanded`||d===`legend-expanded`)&&u?.form===`card`?{...u,form:`container`}:u,e,t,n,c,_.containerPadding),l.set(r,i)}return i},d=i?.shared?.graph;if(d===void 0){let n=[...Za(e,t.bindings===void 0?{registry:t.registry}:{registry:t.registry,bindings:t.bindings}),...no(e)];if(Pt(n))return{status:`refused`,refusals:[{code:`document-invalid`,path:`document`,message:`diagram-core refuses this document`}],diagnostics:n};let r=Ou(e,t.registry);if(`refusals`in r)return{status:`refused`,refusals:r.refusals,diagnostics:[]};d=r.graph,i?.shared!==void 0&&(i.shared.graph=d)}let f=ls(a,n,e),p=f?t.metrics?.routeSpacing??Ds:0,m=f?t.metrics?.routeBorderClearance??Os:t.metrics?.clearance??pc.clearance,h=p>0?Math.ceil(p/Math.SQRT2):0,g=t.metrics?.trackSpacing??ws({},!0).trackSpacing,_={...pc,...t.metrics,routeSpacing:p,routeBorderClearance:m,slotSpacing:t.metrics?.slotSpacing??(f?Math.max(p,g):g)},v=t.hints??{},y=v.composition,b=f||y!==void 0,x=Pl(t.hints,_),S=v.stretch??!1,C=dc(t.rowPack),w=_.containerPadding,T=Fl(v,_),E=Fl(v,_,b).zoneX;{let e=[...fc(C)],t=(t,n,r,i)=>{Number.isFinite(r)&&r>=0&&r<=i||e.push({code:`layout-hint-invalid`,path:t,message:`the sibling gap ${n} is within [0, ${String(i)}] (axis cap), got ${String(r)}`})};t(`hints.cardGapX`,`cardGapX`,T.cardX,T.maxX),t(`hints.zoneGapX`,`zoneGapX`,v.zoneGapX??T.zoneX,T.maxX),t(`hints.cardGapY`,`cardGapY`,T.cardY,T.maxY),t(`hints.zoneGapY`,`zoneGapY`,v.zoneGapY??T.zoneY,T.maxY);let n=(e,r)=>{e.gapAfter!==void 0&&t(`${r}.gapAfter`,`gapAfter of group ${e.id}`,e.gapAfter,Math.min(T.maxX,T.maxY));for(let t of e.items)kl(t)&&n(t,`${r}.items.${t.id}`)};for(let e of v.grouping??[])n(e,`hints.grouping.${e.id}`);if(e.length>0)return{status:`refused`,refusals:e,diagnostics:[]}}let D=e=>Bt(`e.${Ut(e)}`),O=t.collapsed===void 0?n===void 0?new Set:new Set([...aa(n)]):new Set(t.collapsed),k=()=>{let n=Qr(e),r=r=>{let i=e.entities[r],a=i===void 0?void 0:t.registry.get(i.profile);if(i===void 0||a===void 0)return!1;let o=n.resolve(a,i.type);return o.ok&&o.resolved.container},i={},o={};for(let e of d.nodes.keys()){let t=D(e),n=d.nodes.get(e)?.parent,a=n===void 0||!r(n)?void 0:oa(D(n));if(i[t]={id:t,entity:e,...a===void 0?{}:{group:a},geometry:{x:0,y:0,width:460,height:200}},a!==void 0){let e=D(n);o[a]??={id:a,occurrence:e}}}let s={},c=e=>`${e.length}.${e}`;for(let t of Object.keys(e.ports??{}).sort(ou)){let n=e.ports[t]?.owner;if(n===void 0||!d.nodes.has(n))continue;let r=Bt(`p.s.${c(Ut(t))}`);s[r]={id:r,port:t,ownerOccurrence:D(n),side:`south`,order:0,anchor:0}}let l={};for(let e of d.edges){let t=Bt(`r.${Ut(e.id)}`),n=e.source.port===void 0?D(e.source.entity):Bt(`p.s.${c(Ut(e.source.port))}`),r=e.target.port===void 0?D(e.target.entity):Bt(`p.s.${c(Ut(e.target.port))}`),i=uu(a.relations,t,e.id);l[t]={id:t,relation:e.id,endpoints:[{role:`source`,occurrence:n},{role:`target`,occurrence:r}],...i?.strokeStyle===void 0?{}:{strokeStyle:i.strokeStyle},...i?.arrowhead===void 0?{}:{arrowhead:i.arrowhead},...i?.emphasis===void 0?{}:{emphasis:i.emphasis}}}return{viewId:t.viewId??Vt(`layout`),semanticDocumentId:e.documentId,revision:e.revision,entityOccurrences:i,relationOccurrences:l,portOccurrences:s,groups:o,filters:[],presentation:{camera:{x:0,y:0,zoom:1},diagram:lu(a)}}},A;if(n!==void 0)try{A=la(e,hu(n),[...O])}catch{let e=gu(n,O);A={...n,groups:e}}else{let t=k();try{A=la(e,t,[...O])}catch{A=t}}let j=new Set;for(let t of Object.values(A.relationOccurrences))if(e.relations[t.relation]?.type===`flow-step`){if(j.has(t.relation))return{status:`refused`,refusals:[{code:`document-invalid`,path:`sourceView.relationOccurrences`,message:`one flow step must have at most one occurrence per view`}],diagnostics:[]};j.add(t.relation)}let M=Vo(e,A,t.registry,t,r),ee=j.size>0,te={...zo,...t.flowTokens},ne=new Map;for(let e of Object.values(A.entityOccurrences)){let t=ne.get(e.entity)??[];t.push(e.id),ne.set(e.entity,t)}for(let e of ne.values())e.sort(ou);let N=ho({document:e,view:A}).visible,P=new Set;for(let e of[...N].sort(ou)){let t=A.entityOccurrences[e]?.entity;t!==void 0&&d.nodes.has(t)&&P.add(t)}let F=e=>P.has(e),I=e=>{let t=ne.get(e)??[];return t.find(e=>N.has(e))??t[0]??D(e)},re=Object.fromEntries(Object.keys(A.entityOccurrences).flatMap(e=>{let t=a.entities[e]?.anatomy??n?.presentation.entityAnatomy?.[e];return t===void 0||t===(A.presentation.anatomy??`v1`)?[]:[[e,t]]})),{entityAnatomy:L,...R}=A.presentation,ie={groups:A.groups,filters:[...A.filters],presentationState:{...R,...Object.keys(re).length===0?{}:{entityAnatomy:re},diagram:lu(a)},summaryLabels:A.summaryLabels,projected:A,representativeOf:I},z=e=>O.has(I(e)),ae=e=>{let t=d.nodes.get(e),n=cu(a,I(e));return n===`legend-key`?`legend-key`:n===`legend`?z(e)?`legend-collapsed`:`legend-expanded`:n===`container`||t.kind===`container`?z(e)?`container-collapsed`:`container-expanded`:`leaf`},B=new Map;for(let e of d.nodes.keys())B.set(e,ae(e));let oe=new Set;for(let e of d.nodes.values()){let t=B.get(e.id);(e.kind===`container`||t===`container-expanded`||t===`container-collapsed`||t===`legend-expanded`||t===`legend-collapsed`)&&oe.add(e.id)}let se=jl(v,{roots:new Set(d.roots),parentOf:new Map([...d.nodes.values()].map(e=>[e.id,e.parent])),containers:oe});if(se.length>0)return{status:`refused`,refusals:se,diagnostics:[]};let ce=(e,t)=>{let n=t.filter(F);if(B.get(e)===`legend-expanded`){let t=a.legends[I(e)]?.order;return Nl(n,t)}return Nl(n,v.ordering?.[e])},le=e=>{let t=d.nodes.get(e)?.parent;for(;t!==void 0;){if(F(t)){let e=B.get(t);if(e===`container-expanded`||e===`legend-expanded`)return t}t=d.nodes.get(t)?.parent}},ue=e=>{let t=B.get(e);return t!==`container-expanded`&&t!==`legend-expanded`?[]:[...d.nodes.keys()].filter(t=>F(t)&&le(t)===e)},V=(e,t)=>Il(e.stretch,t),de=e=>{let t=S,n=-1,r=(i,a,o)=>{let s=V(i,o);Al(i).includes(e)&&a>n&&(t=s,n=a);for(let e of i.items)kl(e)&&r(e,a+1,s)};for(let e of v.grouping??[])r(e,0,S);return n>=0?t:S},fe=t=>{let n=pu(e,a,I(t),t),r=Ul(zl,!0),i=0;for(let e of[`kicker`,`title`]){let t=n[e];t!==void 0&&(i=Math.max(i,c({text:t,role:e,availableWidth:r,allocatedLines:1,folded:!1}).width))}return i},pe=e=>{let t=B.get(e);return t===`container-expanded`||t===`legend-expanded`},me=Nl([...d.nodes.keys()].filter(e=>F(e)&&le(e)===void 0).sort(ou),v.rootOrder),he=new Map,ge=e=>{let t=he.get(e);return t===void 0&&(t=ce(e,ue(e)),he.set(e,t)),t},_e=e=>e===void 0?uc:I(e),ve=(e,t,n)=>{let r=Il(e.stretch,n),i=[];for(let n of e.items)if(kl(n)){let e=ve(n,`${t}/${n.id}`,r);e.items.length>0&&i.push({run:e,gapAfter:n.gapAfter})}else F(n)&&i.push({entity:n});return{key:t,mode:e.direction,items:i,stretch:r}},ye=(e,t)=>{let n=_e(e),r=e===void 0?S:de(e),i=ku(t,v);return i===void 0?{key:n,mode:`auto`,items:t.map(e=>({entity:e})),stretch:r}:{key:n,mode:`auto`,items:i.map(e=>e.group===void 0?{run:{key:`${n}#rest`,mode:`auto`,items:e.members.map(e=>({entity:e})),stretch:r},gapAfter:void 0}:{run:ve(e.group,`${n}#${e.group.id}`,S),gapAfter:e.group.gapAfter}),stretch:!1}},be=e=>`entity`in e?B.get(e.entity)!==`leaf`:xe(e.run),xe=e=>e.items.some(be),Se=(e,t)=>t.some(t=>be(e.items[t])),Ce=e=>{let t=A.entityOccurrences[e];if(t!==void 0&&N.has(e))return{entity:t.entity};let n=A.portOccurrences[e];if(n!==void 0&&N.has(e)){let e=A.entityOccurrences[n.ownerOccurrence];return e===void 0||!N.has(n.ownerOccurrence)?void 0:{entity:e.entity,port:n.port}}},we=[];for(let n of Object.values(A.relationOccurrences).sort((e,t)=>ou(e.id,t.id))){let r=e.relations[n.relation],i=r===void 0?void 0:t.registry.get(r.profile);if(r===void 0||i===void 0||Or(e,i,r)!==`link`||!po(A,r,e).visible)continue;let a=n.endpoints.find(e=>e.role===`source`),o=n.endpoints.find(e=>e.role===`target`);if(a===void 0||o===void 0)continue;let s=Ce(a.occurrence),c=Ce(o.occurrence);s!==void 0&&c!==void 0&&(M.suppressed.has(n.id)||we.push({occurrence:n.id,relation:n.relation,source:s,target:c}))}let Te={},Ee=new Map;for(let e of we){if(j.has(e.relation))continue;let t=A.relationOccurrences[e.occurrence];if(!t.endpoints.some(e=>e.sourceOccurrence!==void 0))continue;let n;if(f){let r=uu(a.relations,t.id,t.relation),i=fi(t.strokeStyle??r?.strokeStyle)?.style??`solid`,o=pi(t.arrowhead??r?.arrowhead)?.canonicalKind??`arrow`,s=mi(t.emphasis??r?.emphasis)?.emphasis??`default`;n=JSON.stringify([e.source.entity,e.target.entity,i,o,s])}else n=JSON.stringify([e.source.entity,e.target.entity]);let r=Ee.get(n)??[];r.push(e),Ee.set(n,r)}let De=new Set;for(let t of Ee.values()){if(t.length<2)continue;let n=t[0];Te[n.occurrence]={members:t.map(e=>e.occurrence),label:`${t.length} liaisons`,relations:t.map(t=>mu(e,t.relation)).filter(e=>e!==void 0),title:t.map(t=>mu(e,t.relation)).filter(e=>e!==void 0).join(`
|
|
830
|
+
`)},t.slice(1).forEach(e=>De.add(e.occurrence))}for(let e=we.length-1;e>=0;--e)De.has(we[e].occurrence)&&we.splice(e,1);let Oe=new Map;if(ee)for(let e of we)for(let t of A.relationOccurrences[e.occurrence].endpoints)A.portOccurrences[t.occurrence]!==void 0&&Oe.set(t.occurrence,(Oe.get(t.occurrence)??0)+1);let ke=(e,t)=>{let n=A.relationOccurrences[e.occurrence].endpoints.find(e=>e.role===t)?.occurrence;return n!==void 0&&(Oe.get(n)??0)>1?n:void 0},Ae=new Map([...M.ranks].filter(([e])=>{let t=we.find(t=>t.occurrence===e);return t!==void 0&&ke(t,`source`)===void 0&&ke(t,`target`)===void 0})),je={nodes:new Map([...d.nodes].filter(([e])=>F(e))),roots:d.roots.filter(F),edges:we.map(e=>({...Ae.has(e.occurrence)?{flowRank:Ae.get(e.occurrence)}:{},id:e.occurrence,source:e.source.port===void 0?{entity:e.source.entity}:{entity:e.source.entity,port:e.source.port,...ke(e,`source`)===void 0?{}:{slot:ke(e,`source`)}},target:e.target.port===void 0?{entity:e.target.entity}:{entity:e.target.entity,port:e.target.port,...ke(e,`target`)===void 0?{}:{slot:ke(e,`target`)}}}))},Me=Bl(c,f?_.edgeLabelSize:void 0,18),Ne=new Map,Pe=new Map;for(let t of we){if(M.bundles.some(e=>e.carrier===t.occurrence))continue;let n=Te[t.occurrence]?.label??mu(e,t.relation);if(n===void 0)continue;let r=Te[t.occurrence],i=r?.relations===void 0?void 0:Cs(r.relations,Me,_.bundleLabelMaxWidth,r.members.length),a=i===void 0?Me({text:n,role:`edge-label`,availableWidth:au,allocatedLines:Vl[`edge-label`],folded:!1}):i.layout;r!==void 0&&i!==void 0&&(r.chip=i);let o=t.occurrence;Pe.set(o,a),Ne.set(o,{width:a.width,height:a.height})}let Fe=new Map(Ne);for(let e of M.members){if(M.suppressed.has(e.occurrence))continue;let n=M.bundles.find(t=>t.carrier===e.occurrence),r=c({text:n===void 0?e.step.badge:(t.flows?.countTemplate??`{n}`).replaceAll(`{n}`,String(n.members.length)),role:`flow-badge`,availableWidth:2**53-1,allocatedLines:1,folded:!1}),i=Fe.get(e.occurrence);Fe.set(e.occurrence,{width:Math.max(i?.width??0,te.flowBadgeSize,r.width+2*te.flowBadgePaddingX),height:Math.max(i?.height??0,te.flowBadgeSize)})}let Ie=e=>{let t=A.portOccurrences[e]?.ownerOccurrence??e,n=[],r=new Set,i=Zi(A,t);for(;i!==void 0&&!r.has(i);){r.add(i);let e=A.entityOccurrences[i]?.entity;e!==void 0&&F(e)&&n.push(e),i=Zi(A,i)}return n},Le=(e,t)=>{let n=new Set;for(let e=le(t);e!==void 0;e=le(e))n.add(e);for(let t=le(e);t!==void 0;t=le(t))if(n.has(t))return t},Re=e=>c({text:`Mg`,role:e,availableWidth:1e3,allocatedLines:1,folded:!1}).height,ze=y===void 0?`none`:y.legend===`host`?t.legend??`right`:y.legend,Be=(()=>{if(y===void 0||ze===`none`)return;let n=[];for(let t of we){let r=A.relationOccurrences[t.occurrence];if(r===void 0)continue;let i=e.relations[r.relation];if(i?.profile===`erd@1`||i?.type===`flow-step`)continue;let o=a.relations?.[r.id]??a.relations?.[r.relation],s=r.strokeStyle??o?.strokeStyle,c=s===void 0?void 0:fi(s)?.style,l=r.arrowhead??o?.arrowhead,u=l===void 0?void 0:pi(l)?.canonicalKind,d=r.emphasis??o?.emphasis,p=d===void 0?void 0:mi(d)?.emphasis;n.push({...f&&c!==void 0&&c!==`solid`?{strokeStyle:c}:{},...f&&u!==void 0&&u!==`arrow`?{arrowhead:u}:{},...f&&p===`emphasis`?{emphasis:p}:{}})}return Tl({edges:n,measureLines:c,...t.legendTitle===void 0?{}:{title:t.legendTitle},...t.legendLabels===void 0?{}:{labels:t.legendLabels},..._.edgeLabelSize===void 0?{}:{fontSize:_.edgeLabelSize}})})(),Ve=y!==void 0&&ze===`free-cell`?i?.mode===`state`?i.plan?.legendCell:i?.legendCellOverride??Yc(y.grids.root,me):void 0;i?.mode===`nominal-plan`&&i.capture!==void 0&&Ve!==void 0&&(i.capture.legendCell=Ve);let He=ze===`free-cell`&&Ve!==void 0&&Be!==void 0?{bandId:Ve.bandId,colId:Ve.colId,width:Be.width,height:Be.height}:void 0,Ue=i?.mode===`state`?i.plan:void 0,We=i?.mode===`state`?i.memo:void 0,Ge=Ue===void 0?void 0:new Map(Object.entries(Ue.innerWiden)),Ke=i?.sigmaColsOverride===void 0?Ue!==void 0&&Object.keys(Ue.sigmaCols).length>0?new Map(Object.entries(Ue.sigmaCols)):void 0:new Map(Object.entries(i.sigmaColsOverride)),qe=i?.sigmaBandsOverride===void 0?Ue!==void 0&&Object.keys(Ue.sigmaBands).length>0?new Map(Object.entries(Ue.sigmaBands)):void 0:new Map(Object.entries(i.sigmaBandsOverride)),Je=(r,l)=>{let g=[],S=[],D=(e,t)=>{S.push(e),g.push({code:t?`zone-overflow`:`card-overflow`,refs:[e.occurrence,e.slot],message:`overflow in ${e.slot}: needs ${e.neededHeight} over ${e.allocatedHeight}; every character is kept`,details:{occurrence:e.occurrence,slot:e.slot,neededHeight:e.neededHeight,allocatedHeight:e.allocatedHeight,lines:e.lines,allocatedLines:e.allocatedLines}})},k=new Map,j=new Map,ne=new Map,N=new Map,P=new Map,re=new Map,L=new Map,R=new Map,ae=new Map,oe=new Map,se=new Map,ce=new Map,ue=new Map,V=new Map,de=e=>Ue===void 0||e===`root`?r?.widen:Ge,he=e=>{let t=[],n=e=>{for(let r of ge(e))t.push(r),(B.get(r)===`container-expanded`||B.get(r)===`legend-expanded`)&&n(r)};return n(e),t},ve=e=>{let t=[];for(let n of he(e))z(n)&&t.push(n);return t.sort(ou),t.join(`,`)},Ce=(e,t)=>`${Ue.planDigest}|${e}|${ve(e)}|${t??``}`,Ee=e=>{for(let t of e.descendants)k.set(t.entity,t.outerWidth),j.set(t.entity,{width:t.packedSize.width,height:t.packedSize.height}),t.header!==void 0&&ce.set(t.entity,t.header),t.headerInput!==void 0&&ue.set(t.entity,t.headerInput),t.headerWidth!==void 0&&V.set(t.entity,t.headerWidth),t.composedGrid!==void 0&&P.set(t.runKey,t.composedGrid),t.composedStack!==void 0&&re.set(t.runKey,t.composedStack),t.composedUnplaced!==void 0&&L.set(t.runKey,t.composedUnplaced),t.packedRun!==void 0&&ne.set(t.runKey,t.packedRun),t.levelRun!==void 0&&N.set(t.entity,t.levelRun),t.chosen!==void 0&&ae.set(t.runKey,t.chosen),t.orientation!==void 0&&R.set(t.runKey,t.orientation)},De=e=>{let t=[e,...he(e)].map(e=>{let t=_e(e),n=ce.get(e),r=ue.get(e),i=V.get(e),a=P.get(t),o=re.get(t),s=L.get(t),c=ne.get(t),l=N.get(e),u=ae.get(t),d=R.get(t),f=j.get(e)??{width:0,height:0};return{entity:e,runKey:t,outerWidth:k.get(e)??f.width,packedSize:{width:f.width,height:f.height},...n===void 0?{}:{header:n},...r===void 0?{}:{headerInput:r},...i===void 0?{}:{headerWidth:i},...a===void 0?{}:{composedGrid:a},...o===void 0?{}:{composedStack:o},...s===void 0?{}:{composedUnplaced:s},...c===void 0?{}:{packedRun:c},...l===void 0?{}:{levelRun:l},...u===void 0?{}:{chosen:u},...d===void 0?{}:{orientation:d}}}),n=j.get(e);return{naturalSize:{width:n.width,height:n.height},descendants:t}},Oe=(t,n)=>{let r=ce.get(t);if(r!==void 0&&V.get(t)===n)return r;let i=B.get(t),o={entity:t,occurrence:I(t),effectiveType:`${e.entities[t]?.profile??``}:${e.entities[t]?.type??``}/${cu(a,I(t))??d.nodes.get(t).kind}`,folded:i===`container-collapsed`||i===`legend-collapsed`,toggle:i!==`leaf`,slots:pu(e,a,I(t),t),availableWidth:n,allocatedLines:{...Vl}},s=a.entities[I(t)]===void 0?Gl(o,c):u(I(t),n+2*Rl,o.folded).header;return ce.set(t,s),ue.set(t,o),V.set(t,n),s},ke=(e,t)=>(ce.get(e)??Oe(e,Hl(t))).height,Ve=(e,n,a)=>{let o=e.items.map(e=>`entity`in e?$e(e.entity):Ve(e.run,0,0));if(e.stretch){let t=0;e.items.forEach((e,n)=>{`entity`in e&&pe(e.entity)&&(t=Math.max(t,o[n].width))}),e.items.forEach((e,n)=>{`entity`in e&&pe(e.entity)&&(o[n]={width:t,height:o[n].height},k.set(e.entity,t),j.set(e.entity,o[n]))})}let s=xe(e),c=b&&e.items.filter(be).length>1,u=c?E:s?T.zoneX:T.cardX,d=c?E:s?T.zoneY:T.cardY,f={targetAspect:i?.mode===`nominal-plan`&&i.tauOverride!==void 0?i.tauOverride:C.targetAspect,gapX:u,gapY:d,chromeWidth:n,chromeHeight:a,tallBias:C.tallBias,emptyPenaltyWeight:C.emptyPenaltyWeight},p=Ue?.autoPackLevels[e.key],m=r?.frozen.get(e.key),h,g,_=e.mode===`auto`?l?.get(e.key):void 0;if(p!==void 0){let t=new Map;e.items.forEach((e,n)=>{`entity`in e&&t.set(e.entity,n)});let n=new Set,r=[];for(let e of p.shelves){let i=[];for(let r of e){let e=t.get(r);e!==void 0&&(i.push(e),n.add(e))}i.length>0&&r.push(i)}let i=[];e.items.forEach((e,t)=>{n.has(t)||i.push(t)}),i.length>0&&r.push(i),h=p.orientation,g=r}else if(_!==void 0)h=_,g=(_===`rows`?zs:Bs)(o,f).rows;else if(m!==void 0&&m.shelves.reduce((e,t)=>e+t.length,0)===o.length)h=m.orientation,g=m.shelves;else if(e.mode===`auto`){let n=i?.mode===`nominal-plan`?void 0:t.previousOrientation?.[e.key],r=Hs(o,f,C.orientationHysteresis,n);h=r.orientation,g=r.result.rows}else h=e.mode,g=(e.mode===`rows`?zs:Bs)(o,f).rows;if(p===void 0&&e.mode===`auto`&&h===`columns`&&g.every(e=>e.length===1)&&(h=`rows`,g=[g.flat()]),ae.set(e.key,{orientation:h,shelves:g}),i?.mode===`nominal-plan`&&r===void 0&&e.key!==`root`){let t=g.map(t=>t.map(t=>{let n=e.items[t];return n!==void 0&&`entity`in n?n.entity:void 0}).filter(e=>e!==void 0)).filter(e=>e.length>0);oe.set(e.key,{orientation:h,shelves:t})}e.mode===`auto`&&o.length>0&&R.set(e.key,h);let v=h===`rows`,y=v?u:d,x=v?d:u,S=v?T.cardX:T.cardY,w=v?T.cardY:T.cardX,D=v?T.zoneX:T.zoneY,O=v?T.zoneY:T.zoneX,A=de(e.key),M=t=>{let n=e.items[t];return`run`in n?n.gapAfter:void 0},ee=Vs(o,g,h,(t,n)=>{let r=g[t][n],i=g[t][n+1];if(b){let a=be(e.items[r]),o=be(e.items[i]);return a&&o?E:Math.max(M(r)??(a||o?D:S),A?.get(`${e.key}|along|${String(n)}`)??0,A?.get(`${e.key}|along|${String(n)}|${String(t)}`)??0)}return Math.max(M(r)??y,A?.get(`${e.key}|along|${String(n)}`)??0,A?.get(`${e.key}|along|${String(n)}|${String(t)}`)??0)},t=>{let n=g[t][g[t].length-1];if(b){let r=g[t+1],i=Se(e,g[t]),a=Se(e,r);if(i&&a)return E;let o=i||a?O:w;return Math.max(M(n)??o,A?.get(`${e.key}|across|${String(t)}`)??0)}return Math.max(M(n)??x,A?.get(`${e.key}|across|${String(t)}`)??0)});return ne.set(e.key,{run:e,rows:v,shelves:g,boxes:o,positions:ee.positions,alongBase:y,acrossBase:x}),{width:ee.width,height:ee.height}},Je=e=>{let t=d.nodes.get(e)?.parent;return s(I(t===void 0?e:t))},Ye=e=>B.get(e)!==`leaf`,Xe=e=>{let t=Dt(o(I(e))),n=a.entities[I(e)]?.icon!==`none`,r=t.headerTextInset-(n?0:t.iconSize+t.iconTextGap);return Math.max(t.collapsedWidth,fe(e)+r)},Ze=e=>pe(e)&&y?.grids[e]?.stage_columns===`inherit`,Qe=(e,t,n,r,i)=>{let a=de(t),s=e===`root`;if(!Array.isArray(n.stage_columns))return Xc({scope:e,runKey:t,grid:n,visibleChildren:r,sizeOf:$e,isContainer:Ye,isExpandedContainer:pe,rowGaps:T,zoneGutter:E,widen:a,...s&&Ke!==void 0?{sigmaCols:Ke}:{},...s&&qe!==void 0?{sigmaBands:qe}:{},...i===void 0?{}:{freeCellItem:i}});let c=n.stage_columns,l=new Map,d=[],f=0,p=(e,t,n,r)=>{let i=y.grids[e],a=ge(e),o=new Set(a),s=[],u={grid:i,firstDecl:t,lastDecl:n,containerSlotInset:r,childInheritors:s};l.set(e,u),d.push({colStartDecl:t,colEndDecl:n,neededWidth:Xe(e)+2*r,declOrder:f++});let m=new Set;for(let e of i.transverse_bands)for(let a of e.items){if(m.add(a),!o.has(a))continue;let e=i.cells?.[a];if(e?.column===void 0)continue;let l=c.indexOf(e.column),u=e.to_column===void 0?l:c.indexOf(e.to_column);if(l<t||u>n||u<l)continue;let h=l===t||u===n?r+w:0;if(Ze(a))s.push(a),p(a,l,u,h);else{let e=$e(a);d.push({colStartDecl:l,colEndDecl:u,neededWidth:e.width+2*h,declOrder:f++})}}let h=a.filter(e=>!m.has(e));if(h.length>0){let e=0;h.forEach((t,n)=>{let r=$e(t);if(e+=r.width,n+1<h.length){let r=Ye(t)||Ye(h[n+1]);e+=r?E:T.cardX}}),d.push({colStartDecl:t,colEndDecl:n,neededWidth:e+2*w+2*r,declOrder:f++})}},m=new Set(r),h=[];for(let e of n.transverse_bands)for(let t of e.items){if(!m.has(t)||!Ze(t))continue;let e=n.cells?.[t];if(e?.column===void 0)continue;let r=c.indexOf(e.column),i=e.to_column===void 0?r:c.indexOf(e.to_column);r<0||i<r||(h.push(t),p(t,r,i,0))}return Xc({scope:e,runKey:t,grid:n,visibleChildren:r,sizeOf:e=>l.has(e)?{width:Xe(e),height:0}:$e(e),isContainer:Ye,isExpandedContainer:pe,rowGaps:T,zoneGutter:E,widen:a,...s&&Ke!==void 0?{sigmaCols:Ke}:{},...s&&qe!==void 0?{sigmaBands:qe}:{},...i===void 0?{}:{freeCellItem:i},inheritedContributions:d,onStageColumnsResolved:h.length===0?void 0:e=>{let t=new Map,n=r=>{let i=l.get(r),a=e.declColToActive.get(i.firstDecl),s=e.declColToActive.get(i.lastDecl),c=`${e.colIds.slice(a,s+1).join(`,`)};${e.colWidths.slice(a,s+1).join(`,`)};${e.colGaps.slice(a,s).join(`,`)};${String(i.containerSlotInset)}`;if(We!==void 0&&Ue!==void 0){let e=Ce(r,c),n=We.get(e);if(n!==void 0)return Ee(n),t.set(r,n.naturalSize),n.naturalSize;se.set(r,e)}for(let e of i.childInheritors)n(e);let d=_e(r),f=tl({scope:r,runKey:d,grid:i.grid,visibleChildren:ge(r),inherited:{colIds:e.colIds,colStarts:e.colStarts,colWidths:e.colWidths,colGaps:e.colGaps,firstColIdx:a,lastColIdx:s,containerSlotInset:i.containerSlotInset,contentInset:w},sizeOf:e=>j.get(e)??$e(e),isContainer:Ye,isExpandedContainer:pe,rowGaps:T,zoneGutter:E,widen:de(d)});P.set(d,f),f.unplaced.length>0&&L.set(d,f.unplaced);let p=e.colStarts[s]+e.colWidths[s]-e.colStarts[a]-2*i.containerSlotInset,m=Dt(o(I(r))),h=Math.max(Xe(r),p),g=ke(r,h);k.set(r,h);let _={width:h,height:m.headerInset+g+w+f.height+w+u(I(r),h,!1).footerReserve};return j.set(r,_),t.set(r,_),_};for(let e of h)n(e);return t}})},$e=e=>{let t=B.get(e);if(t===`leaf`||t===`container-collapsed`||t===`legend-collapsed`){let n=a.entities[I(e)]===void 0?{width:460,height:200}:u(I(e),s(I(e)),t!==`leaf`);k.set(e,n.width);let r={width:n.width,height:n.height};return j.set(e,r),r}if(t===`legend-key`)return{width:Hl(Je(e)),height:64};if(We!==void 0&&Ue!==void 0&&t===`container-expanded`&&y?.grids[e]?.stage_columns!==`inherit`){let t=Ce(e),n=We.get(t);if(n!==void 0)return Ee(n),n.naturalSize;se.set(e,t)}let n=Dt(o(I(e))),r=a.entities[I(e)]?.icon!==`none`,i=n.headerTextInset-(r?0:n.iconSize+n.iconTextGap),c=fe(e)+i,l=Math.max(n.collapsedWidth,c),d=ge(e),f=ke(e,l);if(t===`legend-expanded`){k.set(e,l);let t=d.length*64+Math.max(0,d.length-1)*x.cardGapY,r={width:l,height:n.headerInset+f+w+t+w};return j.set(e,r),r}let p=y?.grids[e],m=y?.stacks[e],h=_e(e);if(m!==void 0){let t=nl({scope:e,runKey:h,stack:m,visibleChildren:d,sizeOf:$e,isContainer:Ye,isExpandedContainer:pe,rowGaps:T,zoneGutter:E,widen:de(h)});re.set(h,t);let r=Math.max(l,t.width+(d.length>0?2*w:0));k.set(e,r);let i={width:r,height:n.headerInset+f+w+t.height+w+u(I(e),r,!1).footerReserve};return j.set(e,i),i}if(p!==void 0&&p.stage_columns!==`inherit`){let t=Qe(e,h,p,d);P.set(h,t),t.unplaced.length>0&&L.set(h,t.unplaced);let r=Math.max(l,t.width+(d.length>0?2*w:0));k.set(e,r);let i={width:r,height:n.headerInset+f+w+t.height+w+u(I(e),r,!1).footerReserve};return j.set(e,i),i}let g=ye(e,d);N.set(e,g);let v=Ve(g,2*w,n.headerInset+f+w+w),b=ne.get(g.key),S=0;if(b!==void 0){let t=xe(g),n=b.rows?t?T.zoneX:T.cardX:t?T.zoneY:T.cardY;for(let t of we){if(le(t.source.entity)!==e||le(t.target.entity)!==e)continue;let r=Ne.get(t.occurrence);if(r===void 0)continue;let i=d.indexOf(t.source.entity),a=d.indexOf(t.target.entity);i<0||a<0||b.shelves.some(e=>e.includes(i)&&e.includes(a))&&(b.rows?r.width:r.height)+2*_.labelMargin>n&&(S+=r.height+2*_.labelMargin)}}let C=v.height+S,D=Math.max(l,v.width+(d.length>0?2*w:0));k.set(e,D);let O={width:D,height:n.headerInset+f+w+C+w+u(I(e),D,!1).footerReserve};return j.set(e,O),O},et={key:uc,mode:`auto`,items:[],stretch:!1},tt=()=>{if(k.clear(),j.clear(),ne.clear(),N.clear(),P.clear(),re.clear(),L.clear(),R.clear(),ae.clear(),oe.clear(),se.clear(),y?.grids.root!==void 0){let e=Qe(`root`,uc,y.grids.root,me,He);P.set(uc,e),e.unplaced.length>0&&L.set(uc,e.unplaced),et={key:uc,mode:`auto`,items:[],stretch:!1}}else et=ye(void 0,me),Ve(et,0,0)},nt=[...d.nodes.keys()].filter(e=>F(e)&&B.get(e)!==`legend-key`).sort(ou),rt=()=>{for(let e of nt){let t=B.get(e);Oe(e,Hl(t===`container-collapsed`||t===`legend-collapsed`?j.get(e)?.width??s(I(e)):k.get(e)??s(I(e))))}};tt();for(let e=0;e<vu;e+=1){rt();let e=new Map(k);if(tt(),e.size===k.size&&[...k].every(([t,n])=>e.get(t)===n))break}if(i?.sizingOnly===!0&&i.capture!==void 0){let e=P.get(uc),t=Be===void 0?void 0:{width:Be.width,height:Be.height};return i.capture.sizingReport={rootWidth:e?.width??0,rootHeight:e?.height??0,xTrackIds:(e?.columns??[]).filter(e=>e.kind===`stage`).map(e=>e.id),yTrackIds:(e?.bands??[]).filter(e=>e.kind===`band`).map(e=>e.id),capX:T.maxX,capY:T.maxY,...t===void 0?{}:{legendSize:t},effectiveLegendAnchor:ze,legendInsideCell:e?.freeCellRect!==void 0},{result:{status:`laid-out`,view:A,fit:{direction:`top-to-bottom`,width:0,height:0,zoom:1,pans:!1,phone:!1},warnings:[]},chosen:ae,requested:new Map,unused:[],unplaced:0}}if(i?.mode===`nominal-plan`&&r===void 0&&i.capture!==void 0)for(let[e,t]of oe)i.capture.autoPackLevels[e]=t;if(We!==void 0&&Ue!==void 0&&se.size>0)for(let[e,t]of se)j.has(e)&&We.set(t,De(e));for(let e of nt){let t=j.get(e),n=I(e);if(a.entities[n]!==void 0&&t!==void 0)for(let r of u(n,t.width,z(e)).diagnostics){if(r.reason!==`truncated`&&r.reason!==`fallback-v1`)continue;let t=r.reason===`fallback-v1`;g.push({code:B.get(e)===`leaf`?`card-overflow`:`zone-overflow`,severity:`info`,refs:[n,r.slot],message:t?`compact anatomy overflow on `+r.slot+`: fell back to v1 frozen box`:`truncated `+r.slot+`: `+r.hiddenLength+` hidden characters; full text in title/aria`,details:{slot:r.slot,reason:r.reason,...r.hiddenLength===void 0?{}:{hiddenLength:r.hiddenLength},neededHeight:r.neededPx,allocatedHeight:r.allocatedPx}})}else for(let t of Kl(ue.get(e),ce.get(e),Re))D(t,B.get(e)!==`leaf`)}if(t.reportSurfaceSame===!0)for(let e of nt){let t=B.get(e);if(t!==`container-expanded`&&t!==`legend-expanded`)continue;let n=I(e),r=a.entities[n],i=kt(r?.depth??d.nodes.get(e)?.depth??0,r?.depthParityStart);if(i===`surface1`)for(let t of ge(e)){if(B.get(t)!==`leaf`)continue;let e=I(t);a.entities[e]?.categoryRef===void 0&&g.push({code:`zone-surface-same`,severity:`info`,refs:[n,e],message:`white leaf card ${e} sits on same-colour surface1 zone ${n}`,details:{zone:n,card:e,surface:i}})}}for(let[e,t]of[...L].sort(([e],[t])=>ou(e,t)))g.push({severity:`info`,code:`composition-unplaced`,refs:t.map(e=>I(e)),message:`${String(t.length)} visible item(s) omitted from grid ${e} were placed in a trailing band`,details:{scope:e,count:t.length}});let it=new Map,at=new Map,ot=new Map,st=new Map,ct=new Map,lt=[],ut={},dt=(e,t,n)=>{for(let r of e.placements){let e=r.stretchX||r.stretchY?{width:r.width,height:r.height}:void 0;mt(r.entity,t+r.relX,n+r.relY,e)}lt.push(...e.emitGutters(t,n)),ut[e.scope]=e.toReport(t,n)},ft=(e,t,n)=>{for(let r of e.placements){let e=r.stretchX||r.stretchY?{width:r.width,height:r.height}:void 0;mt(r.entity,t+r.relX,n+r.relY,e)}lt.push(...e.emitGutters(t,n))},pt=(e,t,n)=>{let r=ne.get(e.key),i=[];e.items.forEach((e,a)=>{let o=r.positions[a],s=r.boxes[a],c=t+o.x,l=n+o.y;i.push({x:c,y:l,width:s.width,height:s.height}),`entity`in e?mt(e.entity,c,l):pt(e.run,c,l)}),ct.set(e.key,i)},mt=(e,t,n,r)=>{let i=B.get(e);if(i===`leaf`||i===`container-collapsed`||i===`legend-collapsed`){it.set(e,{x:t,y:n,...j.get(e)});return}if(i===`legend-key`){it.set(e,{x:t,y:n,width:Hl(Je(e)),height:64});return}let a=j.get(e),s=r===void 0?a:{width:Math.max(a.width,r.width),height:Math.max(a.height,r.height)},c=ce.get(e),l=Dt(o(I(e))),d=Hl(s.width);it.set(e,{x:t,y:n,width:s.width,height:s.height});let f=(l.ruleHeight/2+1)/ko;at.set(e,{x:t,y:n,width:s.width,height:l.headerInset+c.height});let p=u(I(e),s.width,!1).footerReserve;p>0&&ot.set(e,{x:t,y:n+s.height-p-l.borderWidth-f,width:s.width,height:p+l.borderWidth+f});let m=t+w,h=n+l.headerInset+c.height+w;if(i===`legend-expanded`){st.set(e,d),ge(e).forEach((e,t)=>{it.set(e,{x:m,y:h+t*(64+x.cardGapY),width:d,height:64})});return}let g=_e(e),_=P.get(g);if(_!==void 0){dt(_,m,h);return}let v=re.get(g);if(v!==void 0){ft(v,m,h);return}let y=N.get(e);y!==void 0&&pt(y,m,h)},ht=P.get(uc);ht===void 0?pt(et,0,0):dt(ht,0,0);let gt=[],_t=(e,t,n,r)=>{if(gt.push({occurrence:e,role:t,layout:n}),t===`legend-label`&&n.height>64){let i=Vl[t];D({occurrence:e,slot:t,neededHeight:n.height,allocatedHeight:64,lines:n.lines.length,allocatedLines:i},r)}else if(n.overflow&&(t===`edge-label`||a.entities[e]===void 0)){let i=Vl[t];D({occurrence:e,slot:t,neededHeight:n.height,allocatedHeight:i*Re(t),lines:n.lines.length,allocatedLines:i},r)}};for(let t of[...d.nodes.keys()].sort(ou)){if(!F(t))continue;let n=B.get(t),r=I(t),i=pu(e,a,r,t);if(n===`legend-key`){let e=d.nodes.get(t)?.parent,n=e!==void 0&&st.has(e)?st.get(e):Hl(Je(t));_t(r,`legend-label`,c({text:i.title??``,role:`legend-label`,availableWidth:n-32,allocatedLines:Vl[`legend-label`],folded:!1}),!1);continue}let o=n===`container-expanded`||n===`legend-expanded`;Hl(o?k.get(t)??s(r):s(r));let l=u(r,it.get(t).width,!o&&n!==`leaf`);for(let e of[`body`,`detail`,`footer`])i[e]!==void 0&&_t(r,e,c({text:i[e],role:e,availableWidth:e===`footer`?l.footerWidth:l.bodyWidth,allocatedLines:Vl[e],folded:!o&&n!==`leaf`}),o)}for(let e of[...we].sort((e,t)=>ou(e.occurrence,t.occurrence))){let t=Pe.get(e.occurrence);t!==void 0&&_t(e.occurrence,`edge-label`,t,!1)}let vt=[...[...it].filter(([e])=>!pe(e)).map(([,e])=>e),...at.values()],yt=(Tt.ruleHeight/2+1)/ko,bt=[...vt,...[...at.values()].map(e=>({x:e.x,y:e.y+e.height,width:e.width,height:Tt.ruleHeight/2+yt})),...ot.values()],xt=[...it].filter(([e])=>pe(e)),St=new Map,Ct=new Map;for(let e of we){let t=new Set;for(let n of[e.source.entity,e.target.entity])for(let e=le(n);e!==void 0;e=le(e))t.add(e);let n=e.occurrence;St.set(n,[...vt,...xt.filter(([e])=>!t.has(e)).map(([,e])=>e)]),Ct.set(n,xt.filter(([e])=>t.has(e)).map(([,e])=>e))}let wt=e=>St.get(e)??vt,Et=e=>Ct.get(e)??[],Ot=e=>{let t=it.get(e),n=at.get(e);if(t===void 0||n===void 0)return;let r=p>0?Math.max(4,m):4,i=n.y+n.height+r;return{x:t.x+r,y:i,width:Math.max(0,t.width-2*r),height:Math.max(0,t.y+t.height-i-r)}},At=new Map;for(let e of we){let t=Le(e.source.entity,e.target.entity),n=t===void 0?void 0:Ot(t);n!==void 0&&At.set(e.occurrence,n)}let jt=e=>Math.min(_.labelMargin,(Math.min(T.cardY,T.zoneY)-e)/2),Mt=Math.min(0,...[...it.values()].map(e=>e.y)),Nt=Math.max(0,...[...it.values()].map(e=>e.y+e.height)),H=new Map,Pt=new Map,Ft=new Map;for(let e of[...we].sort((e,t)=>ou(e.occurrence,t.occurrence))){let t=e.occurrence,n=Fe.get(t),r=e.source.entity,i=e.target.entity;if(n===void 0||r===i||_c(je,r,i)||_c(je,i,r))continue;let a=it.get(r),o=it.get(i),s=Math.max(o.x-(a.x+a.width),a.x-(o.x+o.width)),c=a.y<o.y+o.height&&o.y<a.y+a.height&&s>=0,l=Math.max(o.y-(a.y+a.height),a.y-(o.y+o.height)),u=!c&&a.x<o.x+o.width&&o.x<a.x+a.width&&l>=0;if(!c&&!u)continue;if(c){let e={x:Math.min(a.x+a.width,o.x+o.width),y:Math.max(a.y,o.y),width:s,height:Math.min(a.y+a.height,o.y+o.height)-Math.max(a.y,o.y)};if(s>=n.width+2*_.labelMargin&&!wt(t).some(t=>vo(t,e)))continue}else{let e={x:Math.max(a.x,o.x),y:Math.min(a.y+a.height,o.y+o.height),width:Math.min(a.x+a.width,o.x+o.width)-Math.max(a.x,o.x),height:l};if(l>=n.height+2*_.labelMargin&&!wt(t).some(t=>vo(t,e)))continue}let d=_.labelMargin,f=[r,i].sort().join(`|`),h=Pt.get(f)??0;Pt.set(f,h+1);let g=At.get(t),v=`${le(r)!==void 0&&le(r)===le(i)?le(r):`root`}|${c?Math.max(a.y+a.height,o.y+o.height):Math.max(a.x+a.width,o.x+o.width)}`,y=Ft.get(v)??0,b=(c?n.height:n.width)+2*d,x=Math.max(b+2*_.labelMargin,p>0?p:0),S=p>0?m:0,C=(e,n)=>{let r=e===`south`?Math.max(a.y+a.height,o.y+o.height)+S:Math.min(a.y,o.y)-b-S,i=e===`south`?r+n*x:r-n*x,s=[a.x+a.width/2,o.x+o.width/2],c={x:Math.min(...s),y:i,width:Math.abs(s[0]-s[1]),height:b};return g!==void 0&&(c.x<g.x||c.y<g.y||c.x+c.width>g.x+g.width||c.y+c.height>g.y+g.height)?!1:![S>0?{x:c.x,y:c.y-S,width:c.width,height:c.height+2*S}:c,...[a,o].map(t=>e===`south`?{x:t.x+t.width/2-1,y:t.y+t.height,width:2,height:i-(t.y+t.height)}:{x:t.x+t.width/2-1,y:i+b,width:2,height:t.y-(i+b)}).filter(e=>e.height>0)].some(e=>wt(t).some(t=>vo(t,e)))},w=(e,n)=>{let r=e===`east`?Math.max(a.x+a.width,o.x+o.width)+S:Math.min(a.x,o.x)-b-S,i=e===`east`?r+n*x:r-n*x,s=[a.y+a.height/2,o.y+o.height/2],c={x:i,y:Math.min(...s),width:b,height:Math.abs(s[0]-s[1])};return g!==void 0&&(c.x<g.x||c.y<g.y||c.x+c.width>g.x+g.width||c.y+c.height>g.y+g.height)?!1:![S>0?{x:c.x-S,y:c.y,width:c.width+2*S,height:c.height}:c,...[a,o].map(t=>e===`east`?{x:t.x+t.width,y:t.y+t.height/2-1,width:i-(t.x+t.width),height:2}:{x:i+b,y:t.y+t.height/2-1,width:t.x-(i+b),height:2}).filter(e=>e.width>0)].some(e=>wt(t).some(t=>vo(t,e)))},T=g!==void 0||!c?void 0:Math.min(a.y,o.y)<=Mt?`north`:Math.max(a.y+a.height,o.y+o.height)>=Nt?`south`:void 0,E=!1;if(c){let e=T===void 0?h%2==0?[`south`,`north`]:[`north`,`south`]:h%2==0?[T,T===`south`?`north`:`south`]:[T===`south`?`north`:`south`,T];for(let n of e){for(let e=y;e<y+3&&!E;e+=1)C(n,e)&&(H.set(t,{source:n,target:n,turn:!0}),Ft.set(v,e+1),E=!0);if(E)break}}else for(let e of[`east`,`west`]){for(let n=y;n<y+3&&!E;n+=1)w(e,n)&&(H.set(t,{source:e,target:e,turn:!0}),Ft.set(v,n+1),E=!0);if(E)break}}let It=e=>{let t=le(e);if(t===void 0)return!1;let n=at.get(t),r=it.get(e);return n===void 0||r===void 0?!1:r.y-(n.y+n.height)<2*m-1e-4},Lt=(e,t,n)=>{if(n===void 0)return!0;let r=it.get(e),i=m;return t===`west`?r.x-i>=n.x-1e-4:t===`east`?r.x+r.width+i<=n.x+n.width+1e-4:t===`north`?r.y-i>=n.y-1e-4:r.y+r.height+i<=n.y+n.height+1e-4};if(p>0){let e=(e,t)=>{for(let n=e;n!==void 0;n=le(n))if(n===t)return!0;return!1},t=(e,t,n)=>{let r=it.get(e),i=it.get(t),a=ot.get(t)?.height??0,o=[],s=e=>n===void 0?!0:e===`west`?i.x-m>=n.x-1e-4:e===`east`?i.x+i.width+m<=n.x+n.width+1e-4:i.y+i.height+m<=n.y+n.height+1e-4;return r.x-i.x<=w+1&&s(`west`)&&o.push(`west`),i.x+i.width-(r.x+r.width)<=w+1&&s(`east`)&&o.push(`east`),i.y+i.height-a-(r.y+r.height)<=w+1&&s(`south`)&&o.push(`south`),o},n=(n,r,i,a)=>{let o=it.get(n),s=it.get(r),c=o.x+o.width/2,l=o.y+o.height/2,u=s.x+s.width/2,d=s.y+s.height/2,f=le(n);if(f!==void 0&&!e(r,f)){let e=t(n,f,a);if(e.includes(i))return i;let r=e.filter(e=>e===`west`?u<c:e===`east`?u>c:d>l);if(r.length>0){let e=e=>e===`west`?-(c-u):e===`east`?-(u-c):-(d-l);return[...r].sort((t,n)=>e(t)-e(n))[0]}}if(i!==`north`||!It(n))return i;let p=[`east`,`west`,`south`].filter(e=>Lt(n,e,a));if(p.length===0)return i;if(s.x>=o.x+o.width&&p.includes(`east`))return`east`;if(o.x>=s.x+s.width&&p.includes(`west`))return`west`;if(Math.abs(u-c)>1e-4){let e=u>c?`east`:`west`;if(p.includes(e))return e}if(f!==void 0){let e=it.get(f),t=o.x-e.x<=e.x+e.width-(o.x+o.width)?`west`:`east`;if(p.includes(t))return t}return p[0]};for(let e of we){let t=e.occurrence;if(H.has(t))continue;let r=e.source.entity,i=e.target.entity;if(r===i||_c(je,r,i)||_c(je,i,r))continue;let a=At.get(t),o=Sc(it.get(r),it.get(i),`top-to-bottom`),s=Sc(it.get(i),it.get(r),`top-to-bottom`),c=n(r,i,o,a),l=n(i,r,s,a);(c!==o||l!==s)&&H.set(t,{source:c,target:l,turn:!1})}}let Rt=()=>{let e=[];for(let[t,n]of[...ne].sort(([e],[t])=>ou(e,t))){let r=ct.get(t);if(r===void 0||r.length<2)continue;let i=n.rows,a=xe(n.run),o=i?T.cardX:T.cardY,s=i?T.cardY:T.cardX,c=i?T.zoneX:T.zoneY,l=i?T.zoneY:T.zoneX,u=e=>{let t=n.run.items[e];return`run`in t?t.gapAfter:void 0},d=e=>i?[e.x,e.x+e.width]:[e.y,e.y+e.height],f=e=>i?[e.y,e.y+e.height]:[e.x,e.x+e.width],p=(e,t)=>i?{x:e[0],y:t[0],width:e[1]-e[0],height:t[1]-t[0]}:{x:t[0],y:e[0],width:t[1]-t[0],height:e[1]-e[0]},m=[Math.min(...r.map(e=>d(e)[0])),Math.max(...r.map(e=>d(e)[1]))],h=new Map;n.shelves.forEach((o,c)=>{let g=f(r[o[0]])[0],_=Math.max(...o.map(e=>f(r[e])[1])),v=n.shelves[c+1];if(v!==void 0){let d=f(r[v[0]])[0],h=Se(n.run,o),g=Se(n.run,v),y=b?h&&g:a,x=h||g,S=b?y?E:u(o.at(-1))??(x?l:s):u(o.at(-1))??n.acrossBase;e.push({id:`${t}|across|${String(c)}`,horizontal:i,strips:[p(m,[_,d])],gap:d-_,base:S,authoredBase:!1,max:i?T.maxY:T.maxX,zone:y})}o.forEach((e,t)=>{let i=o[t+1];if(i===void 0)return;let s=p([d(r[e])[1],d(r[i])[0]],[g,_]),l=be(n.run.items[e]),u=be(n.run.items[i]),f=b?l&&u:a;(h.get(t)??h.set(t,[]).get(t)).push({shelf:c,slot:e,strip:s,zone:f,bordersZone:b?l||u:a})})});for(let[r,a]of[...h].sort(([e],[t])=>e-t)){let s=e=>i?e.width:e.height,l=e=>i?e.x:e.y,d=a.every(({strip:e,zone:t,bordersZone:n})=>Math.abs(l(e)-l(a[0].strip))<=yu&&t===a[0].zone&&n===a[0].bordersZone),f=i?T.maxX:T.maxY,p=(e,t,r)=>b?t?E:u(e)??(r?c:o):u(e)??n.alongBase;if(d)e.push({id:`${t}|along|${String(r)}`,horizontal:!i,strips:a.map(({strip:e})=>e),gap:Math.max(...a.map(({strip:e})=>s(e))),base:Math.max(...a.map(({slot:e,zone:t,bordersZone:n})=>p(e,t,n))),authoredBase:!1,max:f,zone:a[0].zone});else for(let{shelf:n,slot:o,strip:c,zone:l,bordersZone:u}of a)e.push({id:`${t}|along|${String(r)}|${String(n)}`,horizontal:!i,strips:[c],gap:s(c),base:p(o,l,u),authoredBase:!1,max:f,zone:l})}}return e},zt=ht?.freeCellRect,Bt=[...[...at].sort(([e],[t])=>ou(e,t)).map(([e,t])=>({entity:String(e),rect:t})),...zt===void 0?[]:[{rect:zt}]],Vt;if(y!==void 0&&(y.fanIn===`comb`||y.fanOut===`comb`)){let t=[];for(let n of we){if(n.source.entity===n.target.entity||_c(je,n.source.entity,n.target.entity)||_c(je,n.target.entity,n.source.entity))continue;let r=A.relationOccurrences[n.occurrence];if(r===void 0)continue;let i=e.relations[r.relation];if(i?.profile===`erd@1`||i?.type===`flow-step`)continue;let o=uu(a.relations,r.id,r.relation),s=fi(r.strokeStyle??o?.strokeStyle)?.style??`solid`,c=pi(r.arrowhead??o?.arrowhead)?.canonicalKind??`arrow`,l=bl({strokeStyle:s,arrowhead:c,emphasis:mi(r.emphasis??o?.emphasis)?.emphasis??`default`}),u=r.endpoints.find(e=>e.role===`source`),d=r.endpoints.find(e=>e.role===`target`),f=new Set([...u===void 0?[]:Ie(u.occurrence),...d===void 0?[]:Ie(d.occurrence)]),p=n.occurrence,m=At.get(p),h=Te[n.occurrence]?.label??mu(e,n.relation);t.push({occurrence:n.occurrence,relation:n.relation,source:n.source,target:n.target,styleKey:l,arrowhead:c,...h===void 0?{}:{label:h},passable:f,...m===void 0?{}:{within:m}})}Vt=Uc({candidates:t,fanIn:y.fanIn,fanOut:y.fanOut,r7Routing:f,rects:it,placementParentOf:le,gridReports:ut,gutters:[...lt,...Rt()],barriers:Bt,isNorthBlockedByTitle:It,routeSpacing:p,borderClearance:m,cornerInset:h});for(let e of Vt.fallbacks)g.push({severity:`info`,code:`comb-fallback`,refs:e.members,message:`comb group at ${e.hub} routed separately (${e.reason})`,details:{hub:e.hub,members:e.members,reason:e.reason}})}let Ht=Vt===void 0?void 0:Vt.memberCombId,Ut=Ht===void 0||Ht.size===0?we:we.filter(e=>!Ht.has(String(e.occurrence))),Wt=Ht===void 0||Ht.size===0?je:{...je,edges:je.edges.filter(e=>!Ht.has(String(e.id)))},Gt=Dc({...ee?{flowBadgeSize:te.flowBadgeSize}:{},graph:Wt,rects:it,direction:`top-to-bottom`,metrics:_,labelSizes:new Map,fixed:!0,cornerInset:h,sideOverrides:H,...Vt!==void 0&&Vt.reservedSlots.size>0?{reservedSlots:Vt.reservedSlots}:{}}),Kt=new Map(Gt.docks);if(Vt!==void 0)for(let[e,t]of Vt.memberDocks)Kt.set(e,t);{let e=new Map;for(let t of Gt.fixedOverflows){let n=e.get(t.entity)??{sides:[],required:0,fitted:0};n.sides.push(t.side),n.required+=t.required,n.fitted+=t.fitted,e.set(t.entity,n)}for(let t of[...e.keys()].sort(ou)){let n=e.get(t),r=[...n.sides].sort(ou),i=I(t);g.push({code:`docking-overflow`,refs:[i],message:`sides ${r.join(`,`)} of ${i} need ${n.required} docks, fit ${n.fitted}`,details:{occurrence:i,sides:r.join(`,`),required:n.required,fitted:n.fitted}})}}let qt=e=>Ut.map(t=>{let n=A.relationOccurrences[t.occurrence],r=n.endpoints.find(e=>e.role===`source`),i=n.endpoints.find(e=>e.role===`target`),a=t.occurrence,o=e.get(a),s=new Set([...Ie(r.occurrence),...Ie(i.occurrence)]),c=At.get(a);return{...Ae.has(t.occurrence)?{flowRank:Ae.get(t.occurrence),flowRun:[t.source.entity,t.target.entity].sort().join(`|`)+`|`+String(H.get(a)?.turn===!0)}:{},id:a,pairKey:[t.source.entity,t.target.entity].sort().join(`|`),start:o.source.point,startExit:o.source.exit,end:o.target.point,endExit:o.target.exit,passable:s,...c===void 0?{}:{within:c}}}),Jt=qt(Kt),Yt=[],Xt=[],Zt,Qt=[...Fe.values()],$t=Math.max(_.clearance,m);if(Qt.length>0&&it.size>0){let e=Math.max(p,...Qt.map(e=>e.height+2*_.labelMargin)),t=Math.max(p,...Qt.map(e=>e.width+2*_.labelMargin)),n=Math.min(...[...it.values()].map(e=>e.x)),r=Math.max(...[...it.values()].map(e=>e.x+e.width)),i=r-n,a=Nt-Mt,o=Math.max(0,a*C.targetAspect-i)/2,s=Math.max(0,i/C.targetAspect-a)/2,c=$t+e;Zt={x:n-o-$t-t,y:Mt-s-c,width:i+2*(o+$t+t),height:a+2*(s+c)};let l=Math.min(Qt.length,bu,1+Math.floor(s/e));for(let t=1;t<=l;t+=1)Yt.push(Mt-$t-t*e,Nt+$t+t*e);let u=Math.min(Qt.length,bu,1+Math.floor(o/t));for(let e=1;e<=u;e+=1)Xt.push(n-$t-e*t,r+$t+e*t)}let en=[...at].sort(([e],[t])=>ou(e,t)),tn=[...en.map(([,e])=>e),...zt===void 0?[]:[zt]],nn=[...en.map(([e,t])=>({entity:String(e),rect:t})),...zt===void 0?[]:[{rect:zt}]],rn=(e,t)=>oc({rects:it,requests:e,avoidFallbackInteriors:!0,clearance:m,routeSpacing:p,barriers:tn,lanes:{xs:Xt,ys:Yt},...t===void 0?{}:{priority:t},...Vt!==void 0&&Vt.reservedPolylines.length>0?{reservedRoutes:Vt.reservedPolylines}:{}}),an=rn(Jt);if(p>0&&we.length>1){let e=e=>{let t=[];for(let n of we){let r=n.occurrence,i=Vt?.memberRoutes.get(r)??e.routes.get(r);if(i===void 0)continue;let o=A.relationOccurrences[n.occurrence],s=o.endpoints.find(e=>e.role===`source`),c=o.endpoints.find(e=>e.role===`target`),l=uu(a.relations,o.id,o.relation),u=pi(o.arrowhead??l?.arrowhead).canonicalKind,d=Vt?.suppressedArrowheads.has(String(n.occurrence))?`none`:u,f=Vt?.memberCombId.get(String(n.occurrence)),p=new Set([...Ie(s.occurrence),...Ie(c.occurrence)]);t.push({id:String(n.occurrence),source:String(n.source.entity),target:String(n.target.entity),points:i,...n.source.port===void 0?{}:{sourcePort:String(n.source.port)},...n.target.port===void 0?{}:{targetPort:String(n.target.port)},arrowhead:d,passable:p,...f===void 0?{}:{combGroupId:f}})}return Fs({rects:it,routes:t,routeSpacing:p,borderClearance:m,barriers:nn})},t=(e,t)=>e.obstructed.length*1e4+e.escaped.length*1e3+t.conflictCount,n=e(an),r=t(an,n),i;if(r>0){let a=it.size>25&&n.conflictCount>5&&an.obstructed.length===0?1:3,o=new Set;for(let s=0;s<a&&r>0;s+=1){let a=o.size;for(let e of an.obstructed)o.add(e);for(let e of an.escaped)o.add(e);for(let e of n.conflicts)for(let t of e.routes)o.add(t);if(o.size===a)break;let s=rn(Jt,o),c=e(s),l=t(s,c);if(l<r)an=s,n=c,r=l,i=new Set(o);else break}}if(r>0&&(n.conflictCount<=5||it.size<=25)){let a=new Map(H),o=[`west`,`east`,`south`,`north`],s=(e,t,n)=>{let r=it.get(e),i=it.get(t),a=i.x+i.width/2-(r.x+r.width/2),o=i.y+i.height/2-(r.y+r.height/2);return n===`east`?-a:n===`west`?a:n===`south`?-o:o},c=it.size>25?6:18,l=0;for(let u=0;u<4&&r>0&&l<c;u+=1){let u=new Map;for(let e of an.obstructed)u.set(String(e),(u.get(String(e))??0)+10);for(let e of an.escaped)u.set(String(e),(u.get(String(e))??0)+5);for(let e of n.conflicts)for(let t of e.routes)u.set(t,(u.get(t)??0)+1);let d=[...u.entries()].sort((e,t)=>t[1]-e[1]||ou(e[0],t[0])).map(([e])=>Ut.find(t=>String(t.occurrence)===e)).filter(e=>!(e===void 0||e.source.entity===e.target.entity||e.source.port!==void 0||e.target.port!==void 0||_c(je,e.source.entity,e.target.entity)||_c(je,e.target.entity,e.source.entity))),f=!1;for(let u of d.slice(0,2)){if(l>=c)break;let d=u.occurrence,p=At.get(d),m=Kt.get(d),g=o.filter(e=>(e!==`north`||!It(u.source.entity))&&Lt(u.source.entity,e,p)).sort((e,t)=>s(u.source.entity,u.target.entity,e)-s(u.source.entity,u.target.entity,t)),v=o.filter(e=>(e!==`north`||!It(u.target.entity))&&Lt(u.target.entity,e,p)).sort((e,t)=>s(u.target.entity,u.source.entity,e)-s(u.target.entity,u.source.entity,t)),y=[];for(let e of g)e!==m.source.side&&y.push([e,m.target.side]);for(let e of v)e!==m.target.side&&y.push([m.source.side,e]);let b,x,S,C,w,T=r;for(let[n,r]of y){if(l>=c)break;l+=1;let o=new Map(a);o.set(d,{source:n,target:r,turn:!1});let s=Dc({...ee?{flowBadgeSize:te.flowBadgeSize}:{},graph:Wt,rects:it,direction:`top-to-bottom`,metrics:_,labelSizes:new Map,fixed:!0,cornerInset:h,sideOverrides:o,...Vt!==void 0&&Vt.reservedSlots.size>0?{reservedSlots:Vt.reservedSlots}:{}});if(s.fixedOverflows.length>Gt.fixedOverflows.length)continue;let u=qt(s.docks),f=rn(u,i),p=e(f),m=t(f,p);if(m<T){T=m,b=o,x=s.docks,S=u,C=f,w=p;break}}if(C!==void 0&&x!==void 0&&S!==void 0&&w!==void 0&&b!==void 0){a.clear();for(let[e,t]of b)a.set(e,t);H.clear();for(let[e,t]of b)H.set(e,t);Kt.clear();for(let[e,t]of x)Kt.set(e,t);if(Vt!==void 0)for(let[e,t]of Vt.memberDocks)Kt.set(e,t);Jt=S,an=C,n=w,r=T,f=!0;break}}if(!f)break}}if(r>0&&it.size<=25){let i=new Map;[...Jt].sort((e,t)=>{let n=+(e.within===void 0),r=+(t.within===void 0);if(n!==r)return n-r;let i=Math.abs(e.start.x-e.end.x)+Math.abs(e.start.y-e.end.y),a=Math.abs(t.start.x-t.end.x)+Math.abs(t.start.y-t.end.y);return Math.abs(i-a)>1e-4?i-a:e.id<t.id?-1:+(e.id>t.id)}).forEach((e,t)=>i.set(String(e.id),t));let a=new Set;for(let e of an.obstructed)a.add(e);for(let e of an.escaped)a.add(e);for(let e of n.conflicts){let t=[...e.routes].sort((e,t)=>(i.get(t)??0)-(i.get(e)??0));t.length>0&&a.add(t[0])}if(a.size>0){let i=rn(Jt,a),o=e(i),s=t(i,o);s<r&&(an=i,n=o,r=s)}}}let on=new Map(an.routes);if(Vt!==void 0)for(let[e,t]of Vt.memberRoutes)on.set(e,t);let sn=new Set(an.obstructed),cn=e=>[...Jt.filter(t=>t.id!==e&&!sn.has(t.id)).map(e=>on.get(e.id)).filter(e=>e!==void 0),...Vt?.reservedPolylines??[]],ln=new Map;for(let e of Jt){if(Pe.has(e.id))continue;let t=ln.get(e.pairKey)??[];t.push(e),ln.set(e.pairKey,t)}for(let e of ln.values()){if(e.length<2)continue;e.sort((e,t)=>ou(e.id,t.id));let t=e[0],n=Math.abs(t.start.x-t.end.x)>=Math.abs(t.start.y-t.end.y),r=n?(t.start.x+t.end.x)/2:(t.start.y+t.end.y)/2,i=Math.max(p,(n?_.trackSpacing:_.trackSpacingBlock)??(n?14:7));e.forEach((t,a)=>{let o=r+(a-(e.length-1)/2)*i,s=n?[t.start,{x:o,y:t.start.y},{x:o,y:t.end.y},t.end]:[t.start,{x:t.start.x,y:o},{x:t.end.x,y:o},t.end],c=s.find(e=>e.x!==t.start.x||e.y!==t.start.y),l=[...s].reverse().find(e=>e.x!==t.end.x||e.y!==t.end.y);if(c===void 0||l===void 0||(c.x-t.start.x)*t.startExit.x+(c.y-t.start.y)*t.startExit.y<=0||(l.x-t.end.x)*t.endExit.x+(l.y-t.end.y)*t.endExit.y<=0)return;let u=Math.hypot(c.x-t.start.x,c.y-t.start.y),d=Math.hypot(l.x-t.end.x,l.y-t.end.y);if(p>0&&(u<m-1e-4||d<m-1e-4))return;let f=t.within;if(!(f!==void 0&&s.some(e=>e.x<f.x||e.y<f.y||e.x>f.x+f.width||e.y>f.y+f.height))&&!Jt.some(e=>e.id!==t.id&&e.pairKey===t.pairKey&&Ws(s,on.get(e.id)))&&!s.slice(1).some((e,n)=>{let r=s[n];return!!(wt(t.id).some(t=>vo(t,{x:Math.min(e.x,r.x),y:Math.min(e.y,r.y),width:Math.abs(e.x-r.x),height:Math.abs(e.y-r.y)})?!0:!(p>0)||n===0&&(Math.abs(r.x-t.x)<1e-4||Math.abs(r.x-(t.x+t.width))<1e-4||Math.abs(r.y-t.y)<1e-4||Math.abs(r.y-(t.y+t.height))<1e-4)||n===s.length-2&&(Math.abs(e.x-t.x)<1e-4||Math.abs(e.x-(t.x+t.width))<1e-4||Math.abs(e.y-t.y)<1e-4||Math.abs(e.y-(t.y+t.height))<1e-4)?!1:js(r,e,t)<m-1e-4)||p>0&&Et(t.id).some(t=>Ms(r,e,t)<m-1e-4))})){if(p>0){let e=s.slice(1,-1);if(cn(t.id).some(t=>{for(let e=1;e<s.length;e+=1){let n=s[e-1],r=s[e];for(let e=1;e<t.length;e+=1){let i=t[e-1],a=t[e];if(Math.abs(n.y-r.y)<1e-4&&Math.abs(i.y-a.y)<1e-4&&Math.abs(n.y-i.y)<p-1e-4&&Math.min(Math.max(n.x,r.x),Math.max(i.x,a.x))-Math.max(Math.min(n.x,r.x),Math.min(i.x,a.x))>1e-4||Math.abs(n.x-r.x)<1e-4&&Math.abs(i.x-a.x)<1e-4&&Math.abs(n.x-i.x)<p-1e-4&&Math.min(Math.max(n.y,r.y),Math.max(i.y,a.y))-Math.max(Math.min(n.y,r.y),Math.min(i.y,a.y))>1e-4)return!0}}for(let n of e)for(let e=1;e<t.length-1;e+=1)if(Math.hypot(n.x-t[e].x,n.y-t[e].y)<p-1e-4)return!0;return!1}))return}on.set(t.id,s),sn.delete(t.id)}})}if(sn.size>0&&!(p>0)){let e=new Set(sn),t=oc({rects:it,requests:Jt.filter(t=>e.has(t.id)),avoidFallbackInteriors:!0,clearance:2,barriers:[...at].sort(([e],[t])=>ou(e,t)).map(([,e])=>e),lanes:{xs:Xt,ys:Yt}});for(let[n,r]of t.routes){if(!e.has(n)||t.obstructed.includes(n)||t.escaped.includes(n))continue;let i=Jt.find(e=>e.id===n);Jt.some(e=>e.id!==n&&e.pairKey===i.pairKey&&Ws(r,on.get(e.id)))||(on.set(n,r),sn.delete(n))}}for(let e of[...an.escaped].sort(ou))g.push({code:`route-obstructed`,refs:[e],message:`route of ${e} leaves the content box of its shared container; no route inside it was found`});let un=new Set,dn=new Map,fn=Uo({plan:M,routes:on,shapes:[...bt,...xt.flatMap(([,e])=>[{x:e.x,y:e.y,width:e.width,height:_.labelMargin},{x:e.x,y:e.y+e.height-_.labelMargin,width:e.width,height:_.labelMargin},{x:e.x,y:e.y,width:_.labelMargin,height:e.height},{x:e.x+e.width-_.labelMargin,y:e.y,width:_.labelMargin,height:e.height}])],within:At,...Zt===void 0?{}:{limit:Zt},measure:c,options:t,margin:_.labelMargin});g.push(...fn.warnings);let pn=[...fn.taken,...zt===void 0?[]:[zt]],mn=[...Pe.entries()].filter(([e])=>Vt?.suppressedLabels.has(String(e))!==!0).sort(([e],[t])=>ou(e,t)).map(([e,t])=>{let n=At.get(e);return{id:e,route:on.get(e),size:{width:t.width,height:t.height},...n===void 0?{}:{within:n},...Zt===void 0?{}:{limit:Zt}}}),hn=[];if(Vt!==void 0)for(let e of Vt.groups){if(e.label===void 0)continue;let t=e.carrier;un.add(String(e.carrier));let n=Pe.get(t),r=n??Me({text:e.label,role:`edge-label`,availableWidth:au,allocatedLines:Vl[`edge-label`],folded:!1});n===void 0&&_t(e.carrier,`edge-label`,r,!1);let i={width:r.width,height:r.height},a=At.get(t),o;for(let n of e.trunkSegments)if(o=Ro({id:t,route:n,size:i,...a===void 0?{}:{within:a},...Zt===void 0?{}:{limit:Zt}},bt,pn,_.labelMargin),o!==void 0)break;if(o===void 0){let e=on.get(t);e!==void 0&&(o=Ro({id:t,route:e,size:i,...a===void 0?{}:{within:a},...Zt===void 0?{}:{limit:Zt}},bt,pn,_.labelMargin))}o===void 0?hn.push({id:t,route:on.get(t),size:i,...a===void 0?{}:{within:a},...Zt===void 0?{}:{limit:Zt}}):(dn.set(t,o.box),pn.push(o.box))}let gn=p>0?m:2,_n=p>0?m:0;for(let e of mn){if(un.has(String(e.id)))continue;let t=we.find(t=>t.occurrence===e.id),n=Ro(e,bt,pn,_.labelMargin);if(M.ranks.has(e.id)){n===void 0?hn.push(e):(dn.set(e.id,n.box),pn.push(n.box));continue}if(r?.external.has(e.id)&&Le(t.source.entity,t.target.entity)===void 0){let t=Jt.find(t=>t.id===e.id),{limit:r,...i}=e,a=Ks({request:t,shapes:wt(e.id),earlier:Jt.filter(e=>e.id!==t.id&&e.pairKey===t.pairKey&&!sn.has(e.id)).map(e=>on.get(e.id)),allFixed:cn(e.id),passableZones:Et(e.id),step:gn,routeSpacing:p,borderClearance:_n,xs:[...new Set([t.start.x,t.end.x,...Xt])].sort((e,t)=>e-t),ys:[...new Set([t.start.y,t.end.y,...Yt])].sort((e,t)=>e-t),accepts:e=>{let t=Ro({...i,route:e},bt,pn,_.labelMargin);return t!==void 0&&(t.box.y>=Nt||t.box.y+t.box.height<=Mt)}});a!==void 0&&(on.set(e.id,a),sn.delete(e.id),n=Ro({...i,route:a},bt,pn,_.labelMargin))}let i=jt(e.size.height);if(r===void 0&&n===void 0&&!sn.has(e.id)&&i>=0&&le(t.source.entity)===le(t.target.entity)&&Ro(e,bt,pn,_.labelMargin,i)!==void 0)hn.push(e);else{if(n===void 0||sn.has(e.id)){n=void 0;let r=Jt.find(t=>t.id===e.id),a=Jt.filter(t=>t.id!==e.id&&t.pairKey===r.pairKey&&!sn.has(t.id)).map(e=>on.get(e.id)),o=cn(e.id),s=wt(e.id),c=i,l=new Set([r.start.x,r.end.x]),u=new Set(Yt);for(let t of s){l.add(t.x-$t),l.add(t.x+t.width+$t);for(let n of[_.labelMargin,Math.max(0,c)]){let r=Math.max($t,e.size.height/2+n);u.add(t.y-r),u.add(t.y+t.height+r)}}for(let t of[r.start,r.end])l.add(t.x-e.size.width-2*_.labelMargin),l.add(t.x+e.size.width+2*_.labelMargin);let d=[...l].sort((e,t)=>e-t),f=[...u].sort((e,t)=>e-t),m=Et(e.id),g=Ks({request:r,shapes:s,earlier:a,allFixed:o,passableZones:m,step:gn,routeSpacing:p,borderClearance:_n,xs:d,ys:f,accepts:t=>Ro({...e,route:t},bt,pn,_.labelMargin)!==void 0}),v,b,x=()=>{if(v!==void 0&&b!==void 0)return{xs:v,ys:b};let t=new Set([...l,...Xt]),n=new Set(u),i=y===void 0?[r.start.x,r.end.x,...Xt]:[r.start.x,r.end.x,...Xt,...d];for(let e of i)t.add(e-p),t.add(e+p);if(y!==void 0)for(let e=0;e+1<d.length;e+=1)t.add((d[e]+d[e+1])/2);for(let e of[r.start.y,r.end.y,...Yt])n.add(e-p),n.add(e+p);if(y!==void 0){let t=Math.max($t,e.size.height/2+_.labelMargin);for(let e of pn)n.add(e.y-t),n.add(e.y+e.height+t)}return v=[...t].sort((e,t)=>e-t),b=[...n].sort((e,t)=>e-t),{xs:v,ys:b}};if(g===void 0&&p>0){let t=x();g=Ks({request:r,shapes:s,earlier:a,allFixed:o,passableZones:m,step:gn,routeSpacing:p,borderClearance:_n,xs:t.xs,ys:t.ys,accepts:t=>Ro({...e,route:t},bt,pn,_.labelMargin)!==void 0})}if(g!==void 0)on.set(e.id,g),sn.delete(e.id),n=Ro({...e,route:g},bt,pn,_.labelMargin);else if(c>=0){let t=Ks({request:r,shapes:s,earlier:a,allFixed:o,passableZones:m,step:gn,routeSpacing:p,borderClearance:_n,xs:d,ys:f,accepts:t=>Ro({...e,route:t},bt,pn,_.labelMargin,c)!==void 0});t!==void 0&&on.set(e.id,t)}let S=we.some(e=>e!==t&&[e.source.port,e.target.port].some(e=>e!==void 0&&(e===t.source.port||e===t.target.port)));if(n===void 0&&t.source.entity!==t.target.entity&&!S&&!_c(je,t.source.entity,t.target.entity)&&!_c(je,t.target.entity,t.source.entity)){let t=[`north`,`south`,`east`,`west`],i=[...t.map(e=>[e,e]),...t.flatMap(e=>t.filter(t=>t!==e).map(t=>[e,t]))],c=t=>{if(!(p>0))return!0;for(let[n,r]of Kt)if(n!==e.id){for(let e of[t.source,t.target])for(let t of[r.source,r.target])if((e.entity!==t.entity||e.port===void 0||e.port!==t.port)&&e.entity===t.entity&&Math.hypot(e.point.x-t.point.x,e.point.y-t.point.y)<p-1e-4)return!1;if(Math.hypot(t.target.point.x-r.target.point.x,t.target.point.y-r.target.point.y)<p-1e-4)return!1}return!0},l=(t,n)=>{let r=it.get(t.entity);if(r===void 0||t.port!==void 0||!(p>0))return t;let i=t.side===`east`||t.side===`west`,a=(i?r.y:r.x)+h,o=(i?r.y+r.height:r.x+r.width)-h,s=Math.max(p,_.slotSpacing),c=[];for(let[r,a]of Kt)if(r!==e.id){for(let e of[a.source,a.target])e.entity===t.entity&&e.side===t.side&&c.push(i?e.point.y:e.point.x);n===`target`&&a.target.entity===t.entity&&a.target.side===t.side&&c.push(i?a.target.point.y:a.target.point.x)}let l=i?t.point.y:t.point.x,u=e=>e>=a-1e-4&&e<=o+1e-4&&c.every(t=>Math.abs(t-e)>=p-1e-4);if(u(l))return t;for(let e=1;e<=16;e+=1)for(let n of[-e*s,e*s]){let e=l+n;if(!u(e))continue;let a=i?{x:t.point.x,y:e}:{x:e,y:t.point.y},o=i?(e-r.y)/r.height:(e-r.x)/r.width;return{...t,point:a,anchor:o}}return t};for(let[t,u]of i){let i=new Map(H);i.set(e.id,{source:t,target:u,turn:t===u});let g=Dc({graph:je,rects:it,direction:`top-to-bottom`,metrics:_,labelSizes:new Map,fixed:!0,cornerInset:h,sideOverrides:i}).docks.get(e.id);if(y!==void 0&&!c(g)&&p>0&&(g={source:l(g.source,`source`),target:l(g.target,`target`)}),!c(g))continue;let v={...r,start:g.source.point,startExit:g.source.exit,end:g.target.point,endExit:g.target.exit},b=Ks({request:v,shapes:s,earlier:a,allFixed:o,passableZones:m,step:gn,routeSpacing:p,borderClearance:_n,xs:d,ys:f,accepts:t=>Ro({...e,route:t},bt,pn,_.labelMargin)!==void 0});if(b===void 0&&y!==void 0&&p>0){let t=x();b=Ks({request:v,shapes:s,earlier:a,allFixed:o,passableZones:m,step:gn,routeSpacing:p,borderClearance:_n,xs:t.xs,ys:t.ys,accepts:t=>Ro({...e,route:t},bt,pn,_.labelMargin)!==void 0})}if(b!==void 0){on.set(e.id,b),sn.delete(e.id),Kt.set(e.id,g),n=Ro({...e,route:b},bt,pn,_.labelMargin);break}}}}if(n===void 0){let t=Jt.find(t=>t.id===e.id);if(e.within===void 0){let r=Math.max(...[...it.values()].map(e=>e.x+e.width)),i=Math.max(p,...[...Ne.values()].map(e=>e.height+2*_.labelMargin)),a=r+Math.max(...[...Ne.values()].map(e=>e.width))/2+$t,o=Nt+$t+(mn.indexOf(e)+1)*i,s=Mt-$t-(mn.indexOf(e)+1)*i,{limit:c,...l}=e,u=Jt.filter(n=>n.id!==e.id&&n.pairKey===t.pairKey&&!sn.has(n.id)).map(e=>on.get(e.id)),d=cn(e.id),f=(n=>Ks({request:t,shapes:wt(e.id),earlier:n,allFixed:d,passableZones:Et(e.id),step:gn,routeSpacing:p,borderClearance:_n,xs:[...new Set([t.start.x,t.end.x,a,...Xt])].sort((e,t)=>e-t),ys:[...new Set([t.start.y,t.end.y,s,o,...Yt])].sort((e,t)=>e-t),accepts:e=>Ro({...l,route:e},bt,pn,_.labelMargin)!==void 0}))(u);f!==void 0&&(on.set(e.id,f),sn.delete(e.id),n=Ro({...l,route:f},bt,pn,_.labelMargin))}}n===void 0?hn.push({...e,route:on.get(e.id)}):(dn.set(e.id,n.box),pn.push(n.box))}}for(let e of hn)g.push({code:`label-unplaced`,refs:[e.id],message:`no segment holds the label of ${e.id}`});for(let e of[...sn].sort(ou))g.push({code:`route-obstructed`,refs:[e],message:`no orthogonal route around the obstacles was found for ${e}; an elbow is drawn instead`});let vn=[...lt];for(let[e,t]of[...ne].sort(([e],[t])=>ou(e,t))){let n=ct.get(e);if(n===void 0||n.length<2)continue;let r=t.rows,i=xe(t.run),a=(e,t)=>(e?t?v?.zoneGapX:v?.cardGapX:t?v?.zoneGapY:v?.cardGapY)!==void 0,o=r?T.cardX:T.cardY,s=r?T.cardY:T.cardX,c=r?T.zoneX:T.zoneY,l=r?T.zoneY:T.zoneX,u=e=>{let n=t.run.items[e];return`run`in n?n.gapAfter:void 0},d=e=>r?[e.x,e.x+e.width]:[e.y,e.y+e.height],f=e=>r?[e.y,e.y+e.height]:[e.x,e.x+e.width],p=(e,t)=>r?{x:e[0],y:t[0],width:e[1]-e[0],height:t[1]-t[0]}:{x:t[0],y:e[0],width:t[1]-t[0],height:e[1]-e[0]},m=[Math.min(...n.map(e=>d(e)[0])),Math.max(...n.map(e=>d(e)[1]))],h=new Map;t.shelves.forEach((o,c)=>{let g=f(n[o[0]])[0],_=Math.max(...o.map(e=>f(n[e])[1])),v=t.shelves[c+1];if(v!==void 0){let d=f(n[v[0]])[0],h=Se(t.run,o),g=Se(t.run,v),y=b?h&&g:i,x=h||g,S=b?y?E:u(o.at(-1))??(x?l:s):u(o.at(-1))??t.acrossBase;vn.push({id:`${e}|across|${String(c)}`,horizontal:r,strips:[p(m,[_,d])],gap:d-_,base:S,authoredBase:b&&y?!1:u(o.at(-1))!==void 0||a(!r,b?x:i),max:r?T.maxY:T.maxX,zone:y})}o.forEach((e,r)=>{let a=o[r+1];if(a===void 0)return;let s=p([d(n[e])[1],d(n[a])[0]],[g,_]),l=be(t.run.items[e]),u=be(t.run.items[a]),f=b?l&&u:i;(h.get(r)??h.set(r,[]).get(r)).push({shelf:c,slot:e,strip:s,zone:f,bordersZone:b?l||u:i})})});for(let[n,i]of[...h].sort(([e],[t])=>e-t)){let s=e=>r?e.width:e.height,l=e=>r?e.x:e.y,d=i.every(({strip:e,zone:t,bordersZone:n})=>Math.abs(l(e)-l(i[0].strip))<=yu&&t===i[0].zone&&n===i[0].bordersZone),f=r?T.maxX:T.maxY,p=(e,n,r)=>b?n?E:u(e)??(r?c:o):u(e)??t.alongBase;if(d){let t=i[0].zone;vn.push({id:`${e}|along|${String(n)}`,horizontal:!r,strips:i.map(({strip:e})=>e),gap:Math.max(...i.map(({strip:e})=>s(e))),base:Math.max(...i.map(({slot:e,zone:t,bordersZone:n})=>p(e,t,n))),authoredBase:b&&t?!1:i.some(({slot:e})=>u(e)!==void 0)||a(r,i[0].bordersZone),max:f,zone:t})}else for(let{shelf:t,slot:o,strip:c,zone:l,bordersZone:d}of i)vn.push({id:`${e}|along|${String(n)}|${String(t)}`,horizontal:!r,strips:[c],gap:s(c),base:p(o,l,d),authoredBase:b&&l?!1:u(o)!==void 0||a(r,d),max:f,zone:l})}}let yn=vn.map(e=>{let t=[...on].filter(([,t])=>e.strips.some(e=>t.some((n,r)=>{let i=t[r+1];return i!==void 0&&vo(e,{x:Math.min(n.x,i.x),y:Math.min(n.y,i.y),width:Math.abs(n.x-i.x),height:Math.abs(n.y-i.y)})}))).map(([e])=>String(e)).sort(ou),n=new Set,r=t.reduce((e,t)=>{let r=Vt?.memberCombId.get(t);return r===void 0?e+(Te[t]?.members.length??1):n.has(r)?e:(n.add(r),e+1)},0),i=[...dn.values()].filter(t=>e.strips.some(e=>vo(e,t))),a=i.length>0,o=e.horizontal?`vertical`:`horizontal`,s=ws(_,o===`horizontal`),c=b&&e.zone?e.base:(()=>{let t=Math.max(0,...i.map(t=>(e.horizontal?t.height:t.width)+2*_.labelMargin).filter(t=>t<=e.max));return Math.min(e.max,Math.max(t,Ts(r,a,{...s,gapMin:e.authoredBase?e.base:Math.max(s.gapMin,e.base)})))})();return{id:e.id,axis:o,edges:t,strips:e.strips,n:r,labelled:a,gap:e.gap,expected:c,...f?{capacity:Es(e.gap,p,m)}:{},...b?{zone:e.zone}:{}}}),bn=e=>Ue!==void 0&&!e.startsWith(`root|`),xn=[],Sn=new Set(vn.map(e=>e.id));for(let e of[...r?.widen.keys()??[]].sort(ou))bn(e)||Sn.has(e)||xn.push(e);let Cn=new Map,wn=[...pn];for(let e of hn){let t=jt(e.size.height);if(t<0)continue;let n=Ro(e,bt,wn,_.labelMargin,t);if(n===void 0)continue;wn.push(n.box);let r=we.find(t=>t.occurrence===e.id),i=Le(r.source.entity,r.target.entity),a=i===void 0?uc:I(i);for(let t of vn){if(b&&t.zone||bn(t.id)||!t.id.startsWith(`${a}|`)||!t.strips.some(e=>vo(e,n.box)))continue;let r=(t.horizontal?e.size.height:e.size.width)+2*_.labelMargin;r>t.max||r<=t.gap||Cn.set(t.id,Math.max(Cn.get(t.id)??0,r))}}for(let e of yn){if(b&&e.zone||bn(e.id)){Cn.delete(e.id);continue}let t=Math.max(Cn.get(e.id)??0,e.expected);Math.abs(t-e.gap)>.5?Cn.set(e.id,t):Cn.delete(e.id)}let Tn=[],En=[];for(let n of we){let r=n.occurrence,i=on.get(r);if(i===void 0)continue;let o=A.relationOccurrences[n.occurrence],s=o.endpoints.find(e=>e.role===`source`),c=o.endpoints.find(e=>e.role===`target`),l=uu(a.relations,o.id,o.relation),u=pi(o.arrowhead??l?.arrowhead)?.canonicalKind??`arrow`,d=new Set([...Ie(s.occurrence),...Ie(c.occurrence)]),f=fn.arrows[n.occurrence],p=i[0],m=f!==void 0&&p!==void 0&&f.some(e=>Math.hypot(e.tip.x-p.x,e.tip.y-p.y)<=1e-4),h=Vt?.memberCombId.get(String(n.occurrence)),g=Vt?.suppressedArrowheads.has(String(n.occurrence))?`none`:u;if(Tn.push({id:String(n.occurrence),source:String(n.source.entity),target:String(n.target.entity),points:i,...n.source.port===void 0?{}:{sourcePort:String(n.source.port)},...n.target.port===void 0?{}:{targetPort:String(n.target.port)},arrowhead:g,...m?{startArrowhead:!0}:{},passable:d,...h===void 0?{}:{combGroupId:h}}),t.conventions?.arrowDirection===!0){let t=e.relations[o.relation],r=t?.endpoints.find(e=>e.role===`source`)?.target,i=t?.endpoints.find(e=>e.role===`target`)?.target;En.push({id:String(n.occurrence),relationId:String(o.relation),sourceEntity:String(n.source.entity),targetEntity:String(n.target.entity),sourceOccurrence:String(s.occurrence),targetOccurrence:String(c.occurrence),...r===void 0?{}:{semanticSourceEntity:String(r)},...i===void 0?{}:{semanticTargetEntity:String(i)},arrowhead:u})}}if(t.conventions!==void 0){let n=[];if(t.conventions.zoneTagAcronyms===!0)for(let e of[...it.keys()].sort(ou)){let t=B.get(e);if(t!==`container-expanded`&&t!==`container-collapsed`)continue;let r=I(e),i=a.entities[r];n.push({id:String(r),tag:i?.text?.kicker})}g.push(...Ss({options:t.conventions,document:e,edges:En,zones:n}))}let Dn=p>0?Fs({rects:it,routes:Tn,routeSpacing:p,borderClearance:m,channels:yn,barriers:nn}):void 0;if(Dn!==void 0)for(let e of Dn.conflicts)g.push({severity:`info`,code:e.kind===`channel-capacity-exceeded`?`channel-capacity-exceeded`:`route-spacing-conflict`,refs:e.routes,message:e.message,details:{kind:e.kind,actual:e.actual,required:e.required,...e.entity===void 0?{}:{entity:e.entity},...e.channelId===void 0?{}:{channelId:e.channelId}}});let On=Eu(e,je,it,Kt,on,t,ie,we,f&&n!==void 0&&n.presentation.diagram?.contractPin===void 0&&Xi(a.contractPin)),kn=Tu(it,on,new Map([...dn,...Object.entries(fn.badges).map(([e,t])=>[e,t]),...Object.entries(fn.arrows).flatMap(([e,t])=>t.map((t,n)=>[e+String(n),t.box])),...zt===void 0?[]:[[`__free_cell_legend__`,zt]]])),An=kn.width,jn=kn.empty?1:Math.min(1,Math.max(mc,t.targetWidth/An)),Mn=kn.empty?{x:0,y:0}:{x:kn.xmin,y:kn.ymin},Nn={...On,presentation:{...On.presentation,camera:{x:_u(Mn.x),y:_u(Mn.y),zoom:jn}}},Pn={headers:[...ce.values()].sort((e,t)=>ou(e.occurrence,t.occurrence)),slots:[...gt].sort((e,t)=>ou(e.occurrence,t.occurrence)||ou(e.role,t.role)),overflows:[...S].sort((e,t)=>ou(e.occurrence,t.occurrence)||ou(e.slot,t.slot))},Fn;if(v.composition!==void 0&&ze!==`none`&&Be!==void 0){if(ze===`free-cell`&&zt!==void 0)Fn=El(Be,`free-cell`,zt,zt);else{let e=new Map;for(let[t,n]of dn)e.set(t,{x:n.x-_.labelMargin,y:n.y-_.labelMargin,width:n.width+2*_.labelMargin,height:n.height+2*_.labelMargin});for(let[t,n]of Object.entries(fn.badges))e.set(t,n);for(let[t,n]of Object.entries(fn.arrows))n.forEach((n,r)=>e.set(t+String(r),n.box));let t=Tu(it,on,e);if(!t.empty){let e={x:t.xmin,y:t.ymin,width:t.width,height:t.height};Fn=El(Be,ze===`free-cell`?`right`:ze,e)}}}let In;if(y!==void 0){let e=Object.fromEntries(Object.entries(ut).sort(([e],[t])=>ou(e,t))),t=[];for(let[e,n]of[...ne].sort(([e],[t])=>ou(e,t))){let r=ct.get(e);if(r===void 0||r.length<2)continue;let i=n.shelves.map(e=>e.map(e=>{let t=n.run.items[e],i=r[e];if(t!==void 0&&`entity`in t&&i!==void 0)return{entity:t.entity,rect:i}}).filter(e=>e!==void 0)).filter(e=>e.length>0);i.length>0&&t.push({scope:e,rows:n.rows,shelves:i})}let n=ru({gridReports:e,packedLevels:t,isContainer:Ye,zoneGutter:E});if(Ue?.aspectUnreached!==void 0&&O.size===0&&g.push({severity:`info`,code:`aspect-unreached`,refs:[],message:`target 16:9 aspect ratio was not reached within the slack cap (achieved ${Ue.aspectUnreached.achieved.toFixed(3)})`,details:{achieved:Ue.aspectUnreached.achieved,target:Ue.aspectUnreached.target}}),i?.mode===`nominal-plan`&&i.capture!==void 0){let e=Tu(it,on,new Map([...dn,...Object.entries(fn.badges).map(([e,t])=>[e,t]),...Object.entries(fn.arrows).flatMap(([e,t])=>t.map((t,n)=>[e+String(n),t.box])),...Fn===void 0?[]:[[`__link_legend__`,Fn.rect]]]));i.capture.paintedBounds={width:e.width,height:e.height}}In={grids:e,...Ue===void 0?{}:{planDigest:Ue.planDigest},...Ue?.nominalAspect===void 0?{}:{nominalAspect:Ue.nominalAspect,tau:Ue.tau,sigmaCols:Ue.sigmaCols,sigmaBands:Ue.sigmaBands,...Ue.postRouteCorrectionRounds===void 0?{}:{postRouteCorrectionRounds:Ue.postRouteCorrectionRounds}},paintedGapsAboveToken:n.aboveToken,...Vt!==void 0&&Vt.fallbacks.length>0?{combFallbacks:Vt.fallbacks}:{}}}return{result:{status:`laid-out`,...ee?{badgeBoxes:fn.badges,arrowBoxes:fn.arrows,flowBundles:M.bundles,flowTargets:fn.targets,flowRepairPasses:0}:{},view:Nn,fit:{direction:`top-to-bottom`,width:An,height:kn.height,zoom:jn,pans:An*jn>t.targetWidth,phone:t.targetWidth<=390},warnings:g,measurements:Pn,orientations:Object.fromEntries([...R].sort(([e],[t])=>ou(e,t))),channels:yn,...Dn===void 0?{}:{routeSpacing:Dn},labelBoxes:Object.fromEntries([...dn].sort(([e],[t])=>ou(e,t)).map(([e,t])=>[e,{x:_u(t.x),y:_u(t.y),width:t.width,height:t.height}])),...Object.keys(Te).length===0?{}:{edgeBundles:Te},...y===void 0?{}:{legendResolved:!0,...Fn===void 0?{}:{linkLegend:Fn},...In===void 0?{}:{composition:In},...Vt!==void 0&&Vt.groups.length>0?{combGroups:Vt.groups}:{}}},chosen:ae,requested:Cn,unused:xn,unplaced:hn.length}},Ye=Je(void 0),Xe=Ye.chosen,Ze=new Map,Qe=new Set,$e=new Map,et=Ye,tt;for(let e=0;e<24&&(et.requested.size>0||et.unused.length>0);e+=1){let e=JSON.stringify(et.result.status===`laid-out`?et.result.channels?.map(e=>[e.id,e.gap,e.n,e.labelled]):[]);if($e.get(e)!==void 0&&et.result.status===`laid-out`){let e=et.result.channels??[];for(let t of we){if(Le(t.source.entity,t.target.entity)!==void 0)continue;let n=t.occurrence;if(!Pe.has(n))continue;let r=tt?.result.status===`laid-out`?(tt.result.channels??[]).filter(e=>e.edges.includes(n)).map(e=>e.id):[],i=e.filter(e=>e.edges.includes(n)).map(e=>e.id),a=tt?.result.status===`laid-out`?tt.result.labelBoxes?.[n]:void 0,o=et.result.labelBoxes?.[n],s=tt?.result.status===`laid-out`&&a!==void 0?(tt.result.channels??[]).filter(e=>e.strips.some(e=>vo(e,a))).map(e=>e.id):[],c=o===void 0?[]:e.filter(e=>e.strips.some(e=>vo(e,o))).map(e=>e.id);(JSON.stringify(r)!==JSON.stringify(i)||JSON.stringify(s)!==JSON.stringify(c))&&Qe.add(n)}$e.clear()}$e.set(e,et);for(let e of et.unused)Ze.delete(e);for(let[e,t]of et.requested)Ze.set(e,t);tt=et,et=Je({frozen:Xe,widen:Ze,external:Qe})}if(i?.mode===`nominal-plan`&&i.capture!==void 0)for(let[e,t]of[...Ze].sort(([e],[t])=>ou(e,t)))e.startsWith(`root|`)||(i.capture.innerWiden[e]=t);if(y===void 0&&p>0&&je.nodes.size<=25&&et.result.status===`laid-out`&&(et.result.routeSpacing?.conflictCount??0)>0){let e=new Set;for(let t of et.result.routeSpacing.conflicts){if(t.kind!==`channel-capacity-exceeded`||t.channelId===void 0)continue;let n=t.channelId.split(`|`)[0];n!==void 0&&et.result.orientations?.[n]!==void 0&&e.add(n)}let t=e=>e.result.status===`laid-out`?[e.result.warnings.filter(e=>e.code===`route-obstructed`).length,e.result.routeSpacing?.conflictCount??0,e.unplaced]:[1/0,1/0,1/0],n=t(et);for(let r of[...e].sort(ou).slice(0,2)){if(n[0]===0&&n[1]===0)break;let e=et.result.status===`laid-out`?et.result.orientations?.[r]:void 0;if(e===void 0)continue;let i=Je(void 0,new Map([[r,e===`rows`?`columns`:`rows`]])),a=t(i);a[0]===0&&a[1]===0&&(et=i,n=a)}}return et.result.status===`laid-out`&&et.requested.size>0?{...et.result,warnings:[...et.result.warnings,{code:`channel-unresolved`,refs:[...et.requested.keys()],message:`Channel demands did not settle within the bounded routing pass`}]}:et.result}function Tu(e,t,n){let r=!0,i=1/0,a=-1/0,o=1/0,s=-1/0,c=(e,t)=>{r=!1,e<i&&(i=e),e>a&&(a=e),t<o&&(o=t),t>s&&(s=t)};for(let t of e.values())c(t.x,t.y),c(t.x+t.width,t.y+t.height);for(let e of t.values())for(let t of e)c(t.x,t.y);for(let e of n.values())c(e.x,e.y),c(e.x+e.width,e.y+e.height);return r?{empty:!0,xmin:0,ymin:0,width:0,height:0}:{empty:!1,xmin:i,ymin:o,width:a-i,height:s-o}}function Eu(e,t,n,r,i,a,o,s,c){let l=o.projected,u=Math.max(-1,...[...t.nodes.values()].filter(e=>e.kind===`container`).map(e=>e.depth)),d={};for(let e of Object.values(l.entityOccurrences).sort((e,t)=>ou(e.id,t.id))){let r=n.get(e.entity),i=t.nodes.get(e.entity);r!==void 0&&i!==void 0?d[e.id]={...e,geometry:{x:_u(r.x),y:_u(r.y),width:_u(r.width),height:_u(r.height)},z:i.kind===`container`?i.depth-(u+1):0}:d[e.id]={...e}}let f={};for(let e of Object.values(l.portOccurrences))f[e.id]={...e};let p={};for(let t of Object.values(l.relationOccurrences).sort((e,t)=>ou(e.id,t.id))){let n=uu(a.presentation?.relations,t.id,t.relation),o=n?.strokeStyle!==void 0||c&&t.strokeStyle===`dashed`,s=n?.arrowhead??(o?`arrow`:void 0),l={...t,...t.strokeStyle===void 0&&n?.strokeStyle!==void 0?{strokeStyle:n.strokeStyle}:{},...t.arrowhead===void 0&&s!==void 0?{arrowhead:s}:{},...t.emphasis===void 0&&n?.emphasis!==void 0?{emphasis:n.emphasis}:{}},u=t.id,d=r.get(u),f=i.get(u);if(d!==void 0&&f!==void 0){let e=f.slice(d.source.port===void 0?0:1,d.target.port===void 0?f.length:f.length-1).map(e=>({x:_u(e.x),y:_u(e.y)}));p[t.id]={...l,waypoints:e}}else{let{waypoints:n,...r}=l;p[t.id]=e.relations[t.relation]?.type===`flow-step`?r:{...l}}}let m=new Map;for(let e of[...s].sort((e,t)=>ou(e.occurrence,t.occurrence))){let t=r.get(e.occurrence);if(t===void 0)continue;let n=l.relationOccurrences[e.occurrence];if(n!==void 0)for(let[r,i]of[[t.source,`source`],[t.target,`target`]]){if(r.port===void 0)continue;let t=n.endpoints.find(e=>e.role===i);if(t===void 0||l.portOccurrences[t.occurrence]===void 0)continue;let a=m.get(t.occurrence)??[];a.push({edge:e.occurrence,role:i,dock:r}),m.set(t.occurrence,a)}}for(let[e,t]of[...m].sort(([e],[t])=>ou(e,t))){let n=[...t].sort((e,t)=>ou(e.edge,t.edge)||ou(e.role,t.role))[0];f[e]={...f[e],side:n.dock.side,order:n.dock.order,anchor:_u(n.dock.anchor)}}let h=o.summaryLabels===void 0?void 0:Object.fromEntries(Object.entries(o.summaryLabels).filter(([,e])=>d[e.sourceOccurrence]!==void 0&&d[e.targetOccurrence]!==void 0));return{viewId:a.viewId??Vt(`layout`),semanticDocumentId:e.documentId,revision:e.revision,entityOccurrences:d,relationOccurrences:p,portOccurrences:f,groups:o.groups,filters:[...o.filters],presentation:o.presentationState,...h===void 0||Object.keys(h).length===0?{}:{summaryLabels:h}}}function Du(e,t,n){return t.semanticDocumentId===e.documentId?Cu(e,n,t):{status:`refused`,refusals:[{code:`document-invalid`,path:`sourceView`,message:`the source view draws another document`}],diagnostics:[]}}function Ou(e,t){let n=[],r=Qr(e),i=new Map;for(let a of Object.keys(e.entities).sort(ou)){let o=e.entities[a];if(o.type===`flow-scenario`)continue;let s=t.get(o.profile);if(s===void 0||o.profile!==`generic@1`&&o.profile!==`generic@2`){n.push({code:`entity-profile-unsupported`,path:`entities.${a}.profile`,message:`the layout engine lays out generic@1 and generic@2 entities; ${o.id} is ${o.profile}`,refs:[o.id]});continue}let c=r.resolve(s,o.type);if(!c.ok){n.push({code:`entity-type-unsupported`,path:`entities.${a}.type`,message:`the layout engine lays out node, container, legend and legend-key entities; ${o.id} is ${o.type}`,refs:[o.id]});continue}let l=c.resolved.familyType;if(!(o.profile===`generic@1`?[`node`,`container`]:[`node`,`container`,`legend`,`legend-key`]).includes(l)){n.push({code:`entity-type-unsupported`,path:`entities.${a}.type`,message:`the layout engine lays out node, container, legend and legend-key entities; ${o.id} is ${o.type}`,refs:[o.id]});continue}let u=o.profile===`generic@1`?l===`container`:c.resolved.container===!0;i.set(o.id,u?`container`:`node`)}let a=new Map,o=[];for(let r of Object.keys(e.relations).sort(ou)){let i=e.relations[r],s=t.get(i.profile),c=s===void 0?i.type:Or(e,s,i);if(i.profile!==`generic@1`&&i.profile!==`generic@2`||c!==`contains`&&c!==`link`){c===`contains`||c===`link`?n.push({code:`entity-profile-unsupported`,path:`relations.${r}.profile`,message:`the layout engine lays out generic@1 and generic@2 relations; ${i.id} is ${i.profile} ${i.type}`,refs:[i.id]}):n.push({code:`relation-type-unsupported`,path:`relations.${r}.type`,message:`the layout engine lays out link and contains relations; ${i.id} is ${i.profile} ${i.type}`,refs:[i.id]});continue}let l=e=>i.endpoints.find(t=>t.role===e)?.target;if(c===`contains`){let e=l(`parent`),t=l(`child`);e!==void 0&&t!==void 0&&a.set(t,e);continue}let u=t=>{let n=l(t);if(n!==void 0){if(n.startsWith(`port:`)){let t=e.ports[n];return t===void 0?void 0:{entity:t.owner,port:t.id}}return{entity:n}}},d=u(`source`),f=u(`target`);if(d===void 0||f===void 0)continue;let p=i.attributes?.label,m=p!==void 0&&p.kind===`text`&&typeof p.value==`string`&&p.value!==``?p.value:void 0;o.push({id:i.id,source:d,target:f,...m===void 0?{}:{label:m}})}if(n.length>0)return{refusals:n};let s=new Map;for(let e of i.keys())s.set(e,[]);for(let[e,t]of a)s.get(t)?.push(e);let c=e=>{let t=0;for(let n=a.get(e);n!==void 0;n=a.get(n))t+=1;return t},l=new Map;for(let t of[...i.keys()].sort(ou)){let n=e.entities[t]?.attributes?.name,r=n!==void 0&&n.kind===`text`&&typeof n.value==`string`?n.value:``;l.set(t,{id:t,kind:i.get(t),label:r,parent:a.get(t),children:[...s.get(t)??[]].sort(ou),depth:c(t)})}return{graph:{nodes:l,roots:[...l.values()].filter(e=>e.parent===void 0).map(e=>e.id),edges:o}}}function ku(e,t){let n=new Set(e);if(n.size===0)return;let r=(t.grouping??[]).filter(e=>{let t=Al(e);return t.length>0&&t.every(e=>n.has(e))});if(r.length===0)return;let i=new Set;for(let e of r)for(let t of Al(e))i.add(t);let a=e.filter(e=>!i.has(e));return[...r.map(e=>({group:e,members:Al(e)})),...a.length>0?[{members:a}]:[]]}var Au=1e-6;function ju(e){let t=Number(e.toPrecision(12));return String(t===0?0:t)}function Mu(e){if(e.length<=1)return e.map(e=>({x:e.x,y:e.y}));let t=[{x:e[0].x,y:e[0].y}];for(let n=1;n<e.length;n+=1){let r=e[n],i=t[t.length-1];Math.hypot(r.x-i.x,r.y-i.y)>Au&&t.push({x:r.x,y:r.y})}if(t.length===1){let n=e[e.length-1];return t.push({x:n.x,y:n.y}),t}let n=e[e.length-1];if(t[t.length-1]={x:n.x,y:n.y},t.length<=2)return t;let r=[t[0]];for(let e=1;e<t.length-1;e+=1){let n=r[r.length-1],i=t[e],a=t[e+1],o=i.x-n.x,s=i.y-n.y,c=a.x-i.x,l=a.y-i.y,u=Math.hypot(o,s),d=Math.hypot(c,l);if(u<=Au||d<=Au)continue;let f=(o*l-s*c)/(u*d),p=(o*c+s*l)/(u*d);Math.abs(f)<=Au&&p>0||r.push(i)}return r.push(t[t.length-1]),r}function Nu(e,t=12){if(e.length<2)return``;let n=Mu(e),r=Number.isFinite(t)&&t>0?t:0,i=n[0],a=[`M${ju(i.x)} ${ju(i.y)}`],o=i.x,s=i.y;for(let e=1;e<n.length-1;e+=1){let t=n[e-1],i=n[e],c=n[e+1],l=i.x-t.x,u=i.y-t.y,d=c.x-i.x,f=c.y-i.y,p=Math.hypot(l,u),m=Math.hypot(d,f),h=Math.min(r,p/2,m/2),g=p>Au&&m>Au?(l*f-u*d)/(p*m):0;if(h<=Au||Math.abs(g)<=Au){a.push(`L${ju(i.x)} ${ju(i.y)}`),o=i.x,s=i.y;continue}let _=i.x-l/p*h,v=i.y-u/p*h,y=i.x+d/m*h,b=i.y+f/m*h;Math.hypot(_-o,v-s)>Au&&a.push(`L${ju(_)} ${ju(v)}`),a.push(`Q${ju(i.x)} ${ju(i.y)} ${ju(y)} ${ju(b)}`),o=y,s=b}let c=n[n.length-1];return a.push(`L${ju(c.x)} ${ju(c.y)}`),a.join(` `)}function Pu(e,t=12){if(e.length<3||!Number.isFinite(t)||t<=0)return[];let n=Mu(e),r=[];for(let e=1;e<n.length-1;e+=1){let i=n[e-1],a=n[e],o=n[e+1],s=a.x-i.x,c=a.y-i.y,l=o.x-a.x,u=o.y-a.y,d=Math.hypot(s,c),f=Math.hypot(l,u),p=Math.min(t,d/2,f/2),m=d>Au&&f>Au?(s*u-c*l)/(d*f):0;if(p<=Au||Math.abs(m)<=Au)continue;let h=a.x-s/d*p,g=a.y-c/d*p,_=a.x+l/f*p,v=a.y+u/f*p,y=.25*h+.5*a.x+.25*_,b=.25*g+.5*a.y+.25*v;r.push({x:Math.min(h,y),y:Math.min(g,b),width:Math.abs(h-y),height:Math.abs(g-b)},{x:Math.min(y,_),y:Math.min(b,v),width:Math.abs(y-_),height:Math.abs(b-v)})}return r}function Fu(e,t,n,r,i=0,a){let o=n.map(go);for(let e=0;e<t.length;e++){let n=t[e],r=Math.max(0,a?.[e]??0);for(let e=1;e<n.length;e++){let t=n[e-1],i=n[e];o.push({x:Math.min(t.x,i.x)-r,y:Math.min(t.y,i.y)-r,width:Math.abs(t.x-i.x)+2*r,height:Math.abs(t.y-i.y)+2*r})}if(i>0)for(let e of Pu(n,i))o.push(r>0?{x:e.x-r,y:e.y-r,width:e.width+2*r,height:e.height+2*r}:e)}return e.map(e=>{let{box:t}=e,n=(e,n)=>({x:e-r,y:n-r,width:t.width+2*r,height:t.height+2*r}),i=[{x:t.x,y:t.y,cost:0}],a=(e,t)=>e.cost-t.cost||e.y-t.y||e.x-t.x,s=new Set([`${t.x},${t.y}`]),c=(e,n)=>{let r=`${e},${n}`;if(s.has(r))return;s.add(r);let o={x:e,y:n,cost:Math.abs(e-t.x)+Math.abs(n-t.y)},c=i.length;for(i.push(o);c>0;){let e=c-1>>1;if(a(i[e],o)<=0)break;i[c]=i[e],c=e}i[c]=o};for(;i.length>0;){let s=i[0],l=i.pop();if(i.length>0){let e=0;for(;2*e+1<i.length;){let t=2*e+1;if(t+1<i.length&&a(i[t+1],i[t])<0&&t++,a(l,i[t])<=0)break;i[e]=i[t],e=t}i[e]=l}let u=go(n(s.x,s.y)),d=u.x+u.width,f=u.y+u.height,p=o.findIndex(e=>u.x<e.x+e.width&&e.x<d&&u.y<e.y+e.height&&e.y<f),m=o[p];if(m===void 0){let n={...t,x:s.x,y:s.y};if(o.push(go(n)),s.cost===0)return e;let r=e.leader?.at(-2),i=r===void 0?void 0:[...e.leader.slice(0,-1),{x:Math.max(n.x,Math.min(r.x,n.x+n.width)),y:Math.max(n.y,Math.min(r.y,n.y+n.height))}];return{...e,box:n,...i===void 0?{}:{leader:i}}}c(m.x-r-t.width,s.y),c(m.x+m.width+r,s.y),c(s.x,m.y-r-t.height),c(s.x,m.y+m.height+r)}return e})}function Iu(e){return e?.status===`laid-out`?{width:e.fit.width,height:e.fit.height}:{width:0,height:0}}var Lu={card:`base`,zone:`cluster`,store:`db`,actor:`user`,api:`api`,runtime:`server`};function Ru(e,t,n={},r=!0,i,a=tt,o={}){let s=[],c=(e,n)=>{let r=cs(t,i,e),a=n.anatomy===void 0&&r===`v2`?{...n,anatomy:r}:n;if(a.anatomy!==`v2`&&a.align===`center`){let{align:e,...t}=a;return t}return a},l=Object.fromEntries(Object.entries(t.entities).map(([t,o])=>{if(o.form!==`card`&&o.form!==`container`&&o.form!==`legend`)return[t,c(t,o)];let l=i?.entityOccurrences[t]?.entity??t.replace(/^occurrence:e\./,`entity:`),u=e.entities[l];if(u?.profile===`erd@1`)return[t,c(t,o)];let d=n[u===void 0?``:u.profile+`:`+u.type]??n[u?.type??``];if(d?.shape!==void 0&&d.shape!==`component`)return[t,c(t,{...o,icon:o.icon??`none`})];let f=d?.role??(o.form===`card`?`card`:`zone`),p=o.icon??d?.icon??Lu[f];return p===`none`?[t,c(t,{...o,icon:`none`})]:p===void 0||a(p)===void 0?(s.push(t),[t,c(t,{...o,icon:r?`unknown`:`none`})]):[t,c(t,{...o,icon:p})]})),u=o.depthParityStart??0,d=i!==void 0&&Object.keys(i.groups).length>0,f=new Map;if(!d&&e.relations!==void 0)for(let t of Object.values(e.relations)){if((e.typeDefinitions?.[t.type]?.baseType??t.type)!==`contains`)continue;let n=t.endpoints.find(e=>e.role===`parent`)?.target,r=t.endpoints.find(e=>e.role===`child`)?.target;n!==void 0&&r!==void 0&&f.set(r,n)}let p=e=>{let t=0,n=new Set;if(d){for(let r=Zi(i,e);r!==void 0&&!n.has(r);r=Zi(i,r))n.add(r),t+=1;return t}let r=i?.entityOccurrences[e]?.entity??e.replace(/^occurrence:e\./,`entity:`);for(let e=f.get(r);e!==void 0&&!n.has(e);e=f.get(e))n.add(e),t+=1;return t},m=Object.fromEntries(Object.entries(l).map(([e,t])=>{let n=t;if(n.form!==`container`&&n.form!==`legend`)return[e,t];let r=n.depth===void 0?p(e):void 0,i=n.depthParityStart===void 0&&u!==0;return(r===void 0||r===0)&&!i?[e,t]:[e,{...t,...r===void 0||r===0?{}:{depth:r},...i?{depthParityStart:u}:{}}]}));return{presentation:{...t,entities:m},missing:s}}function zu(e){let t=Ru(e.document,e.presentation,e.iconBindings,e.strictIcons,e.view,e.resolveGlyph,e.depthParityStart===void 0?{}:{depthParityStart:e.depthParityStart}),n={registry:e.registry,...e.flows===void 0?{}:{flows:e.flows},...e.flowTokens===void 0?{}:{flowTokens:e.flowTokens},...e.bindings===void 0?{}:{bindings:e.bindings},measureText:t=>{let n=e.measureLines({text:t,role:`body`,availableWidth:2**53-1,allocatedLines:1,folded:!1});return{width:n.width,height:n.height}},presentation:t.presentation,measureLines:e.measureLines,collapsed:e.collapsed,...e.hints===void 0?{}:{hints:e.hints},...e.metrics===void 0?{}:{metrics:e.metrics},rowPack:e.rowPack??{},targetWidth:e.targetWidth??1440,...e.previousOrientation===void 0?{}:{previousOrientation:e.previousOrientation},...e.reportSurfaceSame===void 0?{}:{reportSurfaceSame:e.reportSurfaceSame},...e.conventions===void 0?{}:{conventions:e.conventions},...e.hints?.composition!==void 0&&e.legend!==void 0?{legend:e.legend}:{},...e.hints?.composition!==void 0&&e.legendTitle!==void 0?{legendTitle:e.legendTitle}:{},...e.hints?.composition!==void 0&&e.legendLabels!==void 0?{legendLabels:e.legendLabels}:{}},r=e.cache===void 0?e.view===void 0?Cu(e.document,n):Du(e.document,e.view,n):e.view===void 0?e.cache.layout(e.document,n):e.cache.layoutFolded(e.document,e.view,n);return r.status!==`laid-out`||t.missing.length===0?r:{...r,warnings:[...r.warnings,...t.missing.map(e=>({code:`card-icon-missing`,refs:[e],message:`No icon resolves for this component; strict mode displays unknown`}))]}}function Bu(e){if(e===void 0)return[];let t=[];for(let n of Object.keys(e.groups).sort()){let r=e.groups[n];r.collapsed===!0&&r.occurrence!==void 0&&t.push(r.occurrence)}return t}function Vu(e){return e.kind===`zone`&&!e.collapsed?`frame`:`box`}function Hu(e,t){return e.filter(e=>Vu(e)===t)}function Uu(e){if(e.bounds===void 0||e.connectorCutouts.length===0)return;let{x:t,y:n,width:r,height:i}=e.bounds;return{region:{x:t-64,y:n-64,width:r+128,height:i+128},cutouts:e.connectorCutouts}}var Wu=(e,t)=>e<t?-1:+(e>t);function Gu(e,t){let n=e.relations[t]?.attributes?.label;return n!==void 0&&n.kind===`text`&&typeof n.value==`string`&&n.value!==``?n.value:void 0}function Ku(e,t,n){let r=qu(e,t);if(!n?.fitToWindow||!r.r7Connectors)return r;let i=t.metrics?.edgeLabelSize??18,a=Math.max(ko,8/i);for(let i=0;i<4&&r.bounds!==void 0;i+=1){let{zoom:i}=Yu({...n,bounds:r.bounds});if(!(i>0&&i<a))break;a=i,r=qu(e,t,a)}return r}function qu(e,t,n){let r=e.view,i=Ru(t.document,t.presentation,t.iconBindings,t.strictIcons,r,t.resolveGlyph,t.depthParityStart===void 0?{}:{depthParityStart:t.depthParityStart}),a=Eo({document:t.document,views:{[r.viewId]:r}},r.viewId),o=new Set(Object.values(e.edgeBundles??{}).flatMap(e=>e.members.slice(1))),s=a.items.filter(e=>e.kind!==`edge`||!o.has(e.occurrence)),c=new Set(s.filter(e=>e.kind===`edge`).map(e=>e.occurrence)),l=new Set(Bu(r)),u=Oo(a).map(e=>{let n=i.presentation.entities[e.occurrence],r=n?.form,a=n?.text.title!==void 0&&n.text.title!==``,o=t.document.entities[e.entity]?.profile===`erd@1`,s=o?`erd`:r===`legend-key`?`legend-key`:a?r===`card`?`card`:r===`container`||r===`legend`?`zone`:`label`:`label`;return{occurrence:e.occurrence,entity:e.entity,kind:s,collapsed:(s===`zone`||s===`erd`)&&l.has(e.occurrence),...o?{erd:Zo(t.document,e.entity,l.has(e.occurrence),t.measureLines)}:{},rect:e.rect,...n===void 0?{}:{presentation:n},text:n?.text.title??n?.text.body??``}}),d=new Map((e.measurements?.slots??[]).filter(e=>e.role===`edge-label`).map(e=>[e.occurrence,e.layout])),f=new Map((e.measurements?.headers??[]).map(e=>[e.occurrence,e.height])),p=[],m=[],h=new Map((e.measurements?.slots??[]).filter(e=>e.role===`footer`).map(e=>[e.occurrence,e.layout.width])),g=t.metrics?.labelMargin??pc.labelMargin,_=t.document.profileRefs.length===1&&t.document.profileRefs[0]===`erd@1`,v=!_&&(e.routeSpacing!==void 0||ls(t.presentation,t.view??r,t.document)),y=Bl(t.measureLines,v?t.metrics?.edgeLabelSize:void 0,18),b=t.metrics?.edgeLabelSize??18,x=v&&n!==void 0&&b*n<8?Math.ceil(8/n*64)/64:void 0,S=x===void 0?1:x/b,C=Math.min(ko,n??.45),w=t.presentation.relations,T=v?t.metrics?.linkStrokeWidth??2.5:1.5,E=g+T/(2*C),D=t.metrics?.containerPadding??Tt.contentInsetInline,O=[];for(let e of u){if(e.kind!==`zone`||e.collapsed){p.push(e.rect);continue}let t=f.get(e.occurrence);if(t===void 0)continue;let n=Dt(e.presentation?.anatomy),r=(n.ruleHeight/2+1)/C;p.push({x:e.rect.x,y:e.rect.y,width:e.rect.width,height:n.headerInset+t+n.ruleHeight/2+r});let i=e.presentation?.text.footer?.trim()?ct(n.footer.size)+n.ruleHeight+2*n.ruleMargin+n.footerBottomInset:0;if(i>0){p.push({x:e.rect.x,y:e.rect.y+e.rect.height-i-n.borderWidth-r,width:e.rect.width,height:i+n.borderWidth+r});let t=Math.max(0,e.rect.width-2*D),a=ct(n.footer.size),o=e.rect.y+e.rect.height-n.borderWidth-n.footerBottomInset;O.push({node:e,inner:t,lineHeight:a,bottom:o})}}let k=to(t.document),A=e.flowTargets??{},j={scenarios:k.scenarios.map(e=>({...e,steps:e.steps.filter(e=>A[e.relation]!==void 0)})),byRelation:Object.fromEntries(Object.entries(k.byRelation).filter(([e])=>A[e]!==void 0)),byEntity:Object.fromEntries(Object.entries(k.byEntity).map(([e,t])=>[e,t.filter(e=>A[e]!==void 0)]))},M={};for(let e of u){let t=[];for(let n=Zi(r,e.occurrence);n!==void 0;n=Zi(r,n))t.push(n);M[e.occurrence]=t}let ee=Object.fromEntries(u.map(e=>[e.entity,e.occurrence]));for(let e of Object.values(r.entityOccurrences).sort((e,t)=>Wu(e.id,t.id))){let t=ea(r,l,e.id);ee[e.entity]===void 0&&u.some(e=>e.occurrence===t)&&(ee[e.entity]=t)}let te={};for(let[e,t]of Object.entries(A))te[e]=t.kind===`internal`?[t.box]:r.relationOccurrences[t.occurrence]?.endpoints.map(e=>r.portOccurrences[e.occurrence]?.ownerOccurrence??e.occurrence)??[];let ne=[],N=[],P=new Map,F=new Set,I=new Map;for(let t of e.combGroups??[])if(t.label!==void 0&&I.set(String(t.carrier),t.label),t.kind===`fan-in`)for(let e of t.members)e!==t.carrier&&F.add(String(e));for(let n of Object.keys(r.relationOccurrences).sort(Wu)){if(!c.has(n))continue;let i=r.relationOccurrences[n];if(i.waypoints===void 0||!c.has(n))continue;let a=Lo(r,i.id)??[];if(a.length<2)continue;let o=j.byRelation[i.relation],s=e.flowBundles?.find(e=>e.carrier===i.id),l=t.document.relations[i.relation],u;if(l?.profile===`erd@1`){let e=a[0],t=a[1],n=a[a.length-1],r=a[a.length-2];u=es(qo(l.attributes,`fromCardinality`),e,{x:t.x-e.x,y:t.y-e.y})+es(qo(l.attributes,`toCardinality`),n,{x:r.x-n.x,y:r.y-n.y})}let f=w?.[i.id]??w?.[i.relation],p=i.strokeStyle??f?.strokeStyle,m=p===void 0?void 0:fi(p)?.style,h=i.arrowhead??f?.arrowhead,g=h===void 0?void 0:pi(h)?.canonicalKind,_=F.has(i.id)?`none`:g,b=i.emphasis??f?.emphasis,x=b===void 0?void 0:mi(b)?.emphasis,S=v&&u===void 0&&o===void 0;if(ne.push({...u===void 0?{}:{markers:u},...S?{r7:!0}:{},occurrence:i.id,points:a,directed:o!==void 0,arrows:e.arrowBoxes?.[i.id]??[],...o===void 0?{}:{flow:o},...s===void 0?{}:{bundle:s},...S&&m!==void 0&&m!==`solid`?{strokeStyle:m}:{},...S&&_!==void 0&&_!==`arrow`?{arrowhead:_}:{},...S&&x===`emphasis`?{emphasis:x}:{}}),e.labelBoxes!==void 0&&e.labelBoxes[n]===void 0)continue;let C=e.edgeBundles?.[n]?.label??I.get(n)??(l?.profile===`erd@1`&&[`fromRole`,`toRole`].map(e=>qo(l.attributes,e)).filter(Boolean).join(` / `)||Gu(t.document,i.relation));if(C===void 0)continue;let T=d.get(n)??y({text:C,role:`edge-label`,availableWidth:400,allocatedLines:Vl[`edge-label`],folded:!1}),E=l?.profile===`erd@1`?Xo(C,Go.labelWidth,t.measureLines):T.lines;P.set(n,E),N.push({id:n,route:a,size:l?.profile===`erd@1`?{width:Go.labelWidth,height:E.length*Go.lineHeight}:{width:T.width,height:T.height}})}let re=[],L;for(let e of s){let t=e.kind===`edge`?e.bounds:e.rect;L=L===void 0?t:yo(L,t)}let R=_?ts(N,p,g):e.labelBoxes===void 0?Po(N,p,g):new Map(Object.entries(e.labelBoxes).map(([e,t])=>[e,{box:t}])),ie=new Set(N.map(e=>e.id));for(let[n,r]of R){if(r===void 0||!ie.has(n))continue;let{box:i}=r,a=S===1?i:{x:i.x-i.width*(S-1)/2,y:i.y-i.height*(S-1)/2,width:i.width*S,height:i.height*S},o=e.edgeBundles?.[n],s=o?.relations===void 0?void 0:o.chip??Cs(o.relations,y,t.metrics?.bundleLabelMaxWidth);re.push({occurrence:n,lines:P.get(n)??[],box:a,..._?{erd:!0}:{},...`leader`in r?{leader:r.leader}:{},...e.edgeBundles?.[n]===void 0?{}:{title:e.edgeBundles[n].title},...s===void 0?{}:{bundle:S===1?s:{...s,groups:s.groups.map(e=>({...e,top:e.top*S,height:e.height*S}))}}})}let z=[];for(let n of j.scenarios.flatMap(e=>e.steps)){let r=A[n.relation];if(r===void 0||r.kind===`internal`||!r.badge||z.some(e=>e.occurrence===r.occurrence))continue;let i=e.badgeBoxes?.[r.occurrence];if(i===void 0)continue;let a=e.flowBundles?.find(e=>e.id===(r.kind===`bundle`?r.id:``)),o=a===void 0?n.badge:(t.flows?.countTemplate??`{n}`).replaceAll(`{n}`,String(a.members.length));z.push({id:r.occurrence,occurrence:r.occurrence,kind:a===void 0?`step`:`count`,text:o,box:i,target:r.kind===`bundle`?{kind:`bundle`,id:r.id}:{kind:`edge`,occurrence:r.occurrence}}),L=L===void 0?i:yo(L,i)}for(let t of Object.values(e.arrowBoxes??{}))for(let e of t)L=L===void 0?e.box:yo(L,e.box);let ae=v?t.metrics?.edgeCornerRadius??12:0;for(let{node:e,inner:n,lineHeight:r,bottom:i}of O){if(!v){let t=E+3;m.push({x:e.rect.x+D-t,y:i-r-t,width:Math.min(h.get(e.occurrence)??n,n)+2*t,height:r+2*t});continue}let a=Math.max(E+3,g+T/C+1.15);for(let o of ne){if(!o.r7)continue;let s=ll(o,t.metrics),c=Math.max(g+s/(2*C)+3,g+s/C+1.15);if(c<=a)continue;let l=e.rect.x+D-c,u=l+Math.min(h.get(e.occurrence)??n,n)+2*c,d=i-r-c,f=Math.min(e.rect.y+e.rect.height,i+c);o.points.slice(1).some((e,t)=>{let n=o.points[t];return Math.min(n.x,e.x)<=u&&l<=Math.max(n.x,e.x)&&Math.min(n.y,e.y)<=f&&d<=Math.max(n.y,e.y)})&&(a=c)}let o=i-r-a,s=Math.min(e.rect.y+e.rect.height,i+a);m.push({x:e.rect.x+D-a,y:o,width:Math.min(h.get(e.occurrence)??n,n)+2*a,height:s-o})}let B=v?Fu(re,ne.map(e=>e.points),[...p,...z.map(e=>e.box),...ne.flatMap(e=>e.arrows.map(e=>e.box))],E,ae,ne.map(e=>e.r7?Math.max(0,ll(e,t.metrics)-T)/(2*C):0)):Fu(re,ne.map(e=>e.points),[...p,...z.map(e=>e.box),...ne.flatMap(e=>e.arrows.map(e=>e.box))],E);for(let{box:e}of B){let t={x:e.x-g,y:e.y-g,width:e.width+2*g,height:e.height+2*g};L=L===void 0?t:yo(L,t)}let oe=e.legendResolved?e.linkLegend:Dl({edges:ne,contentBounds:L,measureLines:t.measureLines,...t.legend===void 0?{}:{anchor:t.legend},...t.legendTitle===void 0?{}:{title:t.legendTitle},...t.legendLabels===void 0?{}:{labels:t.legendLabels},...t.metrics?.edgeLabelSize===void 0?{}:{fontSize:t.metrics.edgeLabelSize}});if(oe!==void 0&&(L=L===void 0?oe.rect:yo(L,oe.rect)),L!==void 0){let e=Math.floor(L.x*64)/64,t=Math.floor(L.y*64)/64;L={x:e,y:t,width:Math.ceil((L.x+L.width)*64)/64-e,height:Math.ceil((L.y+L.height)*64)/64-t}}return{badges:z,flows:j,flowTargets:A,nodeTargets:u.filter(e=>Object.values(te).some(t=>t.some(t=>t===e.occurrence||(M[t]??[]).includes(e.occurrence)))).map(e=>({occurrence:e.occurrence,entity:e.entity,anchor:{x:e.rect.x,y:e.rect.y}})),flowEnds:te,flowRepresentatives:ee,flowAncestors:M,flowSummaryLabels:Object.fromEntries(Object.entries(r.summaryLabels??{}).map(([e,t])=>[e,t.label])),contentSize:Iu(e),nodes:u,edges:ne,labels:B,...x===void 0?{}:{overviewEdgeLabelSize:x},r7Connectors:v,connectorCutouts:m,...oe===void 0?{}:{linkLegend:oe},...L===void 0?{}:{bounds:L},orientations:e.orientations??{}}}Object.freeze({...Wo,controls:`Zoom`,zoomIn:`Zoom in`,zoomOut:`Zoom out`,fit:`Fit`,viewAll:`View all`,fullscreen:`Fullscreen`,zoomLevel:e=>`Zoom ${e} %`,viewport:`Diagram`,expand:e=>`Expand ${e}`,collapse:e=>`Collapse ${e}`,contains:`includes`,legend:`Legend`});var Ju=.001;function Yu(e){return ss({...e.bounds===void 0?{}:{bounds:e.bounds},viewWidth:e.viewWidth,windowHeight:e.windowHeight,...e.viewHeight===void 0?{}:{viewHeight:e.viewHeight},...e.scrollbarHeight===void 0?{}:{scrollbarHeight:e.scrollbarHeight},...e.maxDisplayScale===void 0?{}:{maxDisplayScale:e.maxDisplayScale},...e.minReadableScale===void 0?{}:{minReadableScale:e.minReadableScale},...e.unconstrained===void 0?{}:{unconstrained:e.unconstrained},...e.fitToWindow===void 0?{}:{fitToWindow:e.fitToWindow},zoomQuantum:Ju})}function Xu(e){return String(e).replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}var Zu=`var(--st-font-sans, system-ui, sans-serif)`;function Qu(e,t,n,r,i){if(t===void 0)return``;let a=i/64,o=t.darkLine===!0?`var(--st-component-diagramIcon-lineDarkStroke, var(--st-semantic-feedback-info))`:`var(--st-component-diagramIcon-lineStroke, var(--st-semantic-surface-raised))`;return`<g class="st-diagramCard-icon" data-diagram-icon="${Xu(e)}" transform="translate(${n} ${r}) scale(${a})" aria-hidden="true"><path d="${Qe}" fill="var(--st-component-diagramIcon-baseFill, color-mix(in srgb, var(--st-semantic-feedback-info) 18%, var(--st-semantic-surface-raised)))"/><path d="${Xu(t.face)}" fill="var(--st-component-diagramIcon-faceFill, color-mix(in srgb, var(--st-semantic-feedback-info) 75%, var(--st-semantic-surface-raised)))" stroke="var(--st-component-diagramIcon-faceStroke, var(--st-semantic-feedback-info))" stroke-width="1.5" stroke-linejoin="round"/>`+(t.line===void 0?``:`<path d="${Xu(t.line)}" fill="none" stroke="${o}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>`)+(t.text===void 0?``:`<text x="32" y="47" text-anchor="middle" fill="var(--st-component-diagramIcon-lineStroke, var(--st-semantic-surface-raised))" font-size="13" font-weight="750">${Xu(t.text)}</text>`)+`</g>`}function $u(e,t,n,r){return e.map(e=>`<text class="${t}" x="${e.x}" y="${e.baseline}" text-anchor="${e.anchor===`middle`?`middle`:`start`}" font-size="${e.size}" font-weight="${e.weight}" fill="${n}"${r}>${Xu(e.text)}</text>`).join(``)}function ed(e,t=_t){let n=wt(e,t),r={...it(n.anatomyFallback??e.anatomy),width:n.box.width,height:n.box.height},i=[`<title>${Xu(xt(e))}</title><desc>${Xu(xt(e))}</desc>`],a=e.surface===void 0?`var(--st-component-diagramCard-surface, var(--st-semantic-surface-raised))`:`var(--st-component-diagramZone-${e.surface}, var(--st-semantic-surface-${e.surface===`surface1`?`raised`:`subtle`}))`;if(i.push(`<rect x="1" y="1" width="${r.width-2}" height="${r.height-2}" fill="${a}" stroke="var(--st-component-diagramCard-border, var(--st-semantic-border-strong))" stroke-width="${r.borderWidth}"${e.proposed===!0?` stroke-dasharray="var(--st-component-diagramCard-proposedDashArray, 4 5)"`:``}/>`),i.push(`<rect x="0" y="0" width="${r.accentWidth}" height="${r.height}" fill="var(--st-component-diagramCard-border, var(--st-semantic-border-strong))"/>`),n.iconBox!==void 0&&i.push(Qu(n.icon.name,n.icon.glyph,n.iconBox.x,n.iconBox.y,n.iconBox.size)),n.kicker.length>0&&i.push($u(n.kicker,`st-diagramCard-kicker`,`var(--st-component-diagramCard-secondaryText, var(--st-semantic-text-secondary))`,` letter-spacing="0.04em" style="text-transform:uppercase"`)),n.title.length>0&&i.push($u(n.title,`st-diagramCard-title`,`var(--st-component-diagramCard-text, var(--st-semantic-text-primary))`,``)),n.body.length>0){let e=n.body.filter(e=>e.secondary),t=n.body.filter(e=>!e.secondary);t.length>0&&i.push($u(t,`st-diagramCard-body`,`var(--st-component-diagramCard-text, var(--st-semantic-text-primary))`,``)),e.length>0&&i.push($u(e,`st-diagramCard-detail`,`var(--st-component-diagramCard-secondaryText, var(--st-semantic-text-secondary))`,``))}return n.ruleY!==void 0&&i.push(`<line class="st-diagramCard-rule" x1="${n.ruleX1}" x2="${n.ruleX2}" y1="${n.ruleY}" y2="${n.ruleY}" stroke="var(--st-component-diagramCard-rule, var(--st-semantic-border-subtle))" stroke-width="${r.ruleHeight}" vector-effect="non-scaling-stroke"/>`),n.footerLines.length>0&&i.push($u(n.footerLines,`st-diagramCard-footer`,`var(--st-component-diagramCard-text, var(--st-semantic-text-primary))`,``)),n.toggleBox!==void 0&&e.toggle!==void 0&&i.push(td(e.toggle,n.toggleBox)),{content:i.join(``),layout:n}}function td(e,t){let n=t.size/2,r=e.collapsed?`<path d="M ${n-7} ${n} H ${n+7} M ${n} ${n-7} V ${n+7}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>`:`<path d="M ${n-7} ${n} H ${n+7}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>`;return`<g class="st-diagramCard-toggle" data-toggle="true" data-collapsed="${e.collapsed?`true`:`false`}" transform="translate(${t.x} ${t.y})" color="var(--st-semantic-text-primary)" aria-hidden="true"><title>${Xu(e.label)}</title><rect width="${t.size}" height="${t.size}" fill="transparent"/>${r}</g>`}function nd(e,t=_t){let{content:n,layout:r}=ed(e,t),i={...it(r.anatomyFallback??e.anatomy),width:r.box.width,height:r.box.height},a=r.diagnostics.filter(e=>e.code===`card-overflow`&&e.reason!==`fallback-v1`).map(e=>e.slot),o=r.diagnostics.some(e=>e.code===`card-icon-unknown`),s=a.length===0?void 0:a[0];return{kind:`rendered`,svg:`<svg xmlns="http://www.w3.org/2000/svg" class="st-diagramCard" data-entity="${Xu(e.entityId)}"${e.tone===void 0?``:` data-tone="${Xu(e.tone)}"`}${e.proposed===!0?` data-proposed="true"`:``}${s===void 0?``:` data-card-overflow="${s}"`}${o?` data-card-icon-unknown=""`:``} width="${i.width}" height="${i.height}" viewBox="0 0 ${i.width} ${i.height}" role="img" aria-label="${Xu(e.title)}" aria-description="${Xu(xt(e))}" style="font-family:${Zu}">`+n+`</svg>`,diagnostics:r.diagnostics,layout:r}}function rd(e){return String(e).replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}var id=`var(--st-font-sans, system-ui, sans-serif)`;function ad(e,t,n,r){return e.map(e=>`<text class="${t}" x="${e.x}" y="${e.baseline}" text-anchor="${e.anchor===`middle`?`middle`:`start`}" font-size="${e.size}" font-weight="${e.weight}" fill="${n}"${r}>${rd(e.text)}</text>`).join(``)}function od(e,t){if(e.kind===`card`){if(e.card===void 0)throw Error(`fixture-error: card child without card props`);let{content:n,layout:r}=ed(e.card,t);return{content:n,diagnostics:r.diagnostics.map(e=>({code:e.code,slot:e.slot,entityId:e.entityId,neededPx:e.neededPx,allocatedPx:e.allocatedPx,...e.text===void 0?{}:{text:e.text},...e.hiddenLength===void 0?{}:{hiddenLength:e.hiddenLength,severity:`info`,reason:`truncated`}}))}}if(e.zone===void 0)throw Error(`fixture-error: zone child without zone props`);let n=sd(e.zone,e.children??[],t);return{content:n.content,diagnostics:n.diagnostics}}function sd(e,t,n){let r=Dt(e.anatomy),i=Mt(e,n,t),a=i.box.x,o=i.box.y,s=[`<title>${rd(St(e))}</title><desc>${rd(St(e))}</desc>`],c=[];if(i.collapsed){let{content:t}=ed(At(e),n);return s.push(t),{content:s.join(``),layout:i,diagnostics:i.diagnostics}}let l=i.header;if(l===void 0)throw Error(`fixture-error: expanded zone without header layout`);let u=i.box.width,d=i.box.height,f=e.depth===void 0&&e.depthParityStart===void 0?`var(--st-component-diagramZone-surface, var(--st-semantic-surface-raised))`:`var(--st-component-diagramZone-${i.surface??`surface1`}, var(--st-semantic-surface-${(i.surface??`surface1`)===`surface1`?`raised`:`subtle`}))`;s.push(`<rect class="st-diagramZone-frame" x="0" y="0" width="${u}" height="${d}" rx="${r.radius}" fill="${f}" stroke="var(--st-component-diagramZone-border, var(--st-semantic-border-strong))" stroke-width="${r.borderWidth}"${e.proposed===!0?` stroke-dasharray="var(--st-component-diagramZone-proposedDashArray, 4 5)"`:``}/>`),l.iconBox!==void 0&&s.push(Qu(i.icon.name,i.icon.glyph,l.iconBox.x-a,l.iconBox.y-o,l.iconBox.size)),l.kicker.length>0&&s.push(ad(l.kicker.map(e=>({...e,x:e.x-a,baseline:e.baseline-o})),`st-diagramZone-kicker`,`var(--st-component-diagramZone-secondaryText, var(--st-semantic-text-secondary))`,` letter-spacing="0.04em" style="text-transform:uppercase"`)),l.title.length>0&&s.push(ad(l.title.map(e=>({...e,x:e.x-a,baseline:e.baseline-o})),`st-diagramZone-title`,`var(--st-component-diagramZone-text, var(--st-semantic-text-primary))`,``)),l.subtitle.length>0&&s.push(ad(l.subtitle.map(e=>({...e,x:e.x-a,baseline:e.baseline-o})),`st-diagramZone-subtitle`,`var(--st-component-diagramZone-text, var(--st-semantic-text-primary))`,``)),s.push(`<line class="st-diagramZone-rule" x1="${r.ruleInsetStart}" x2="${u-r.ruleInsetEnd}" y1="${l.ruleY-o}" y2="${l.ruleY-o}" stroke="var(--st-component-diagramZone-rule, var(--st-semantic-border-subtle))" stroke-width="${r.ruleHeight}" vector-effect="non-scaling-stroke"/>`),l.toggleBox!==void 0&&e.toggleLabel!==void 0&&s.push(td({collapsed:!1,label:e.toggleLabel},{x:l.toggleBox.x-a,y:l.toggleBox.y-o,size:l.toggleBox.size})),l.footer.length>0&&(l.footerRuleY!==void 0&&s.push(`<line class="st-diagramZone-footerRule" x1="${r.ruleInsetStart}" x2="${u-r.ruleInsetEnd}" y1="${l.footerRuleY-o}" y2="${l.footerRuleY-o}" stroke="var(--st-component-diagramZone-rule, var(--st-semantic-border-subtle))" stroke-width="${r.ruleHeight}" vector-effect="non-scaling-stroke"/>`),s.push(ad(l.footer.map(e=>({...e,x:e.x-a,baseline:e.baseline-o})),`st-diagramZone-footer`,`var(--st-component-diagramZone-text, var(--st-semantic-text-primary))`,``)));for(let e of t){let t=od(e,n);c.push(...t.diagnostics),s.push(`<g class="st-diagramZone-child" data-child-kind="${e.kind}" transform="translate(${e.x-a} ${e.y-o})">${t.content}</g>`)}return{content:s.join(``),layout:i,diagnostics:[...i.diagnostics,...c]}}function cd(e,t={}){let n=t.measure??_t,{content:r,layout:i,diagnostics:a}=sd(e,t.children??[],n),{x:o,y:s,width:c,height:l}=i.box,u=a.filter(e=>e.code===`zone-overflow`&&e.reason!==`fallback-v1`).map(e=>e.slot),d=a.some(e=>e.code===`zone-icon-unknown`),f=u.length===0?void 0:u[0];return{kind:`rendered`,svg:`<svg xmlns="http://www.w3.org/2000/svg" class="st-diagramZoneSvg" width="${o+c}" height="${s+l}" viewBox="0 0 ${o+c} ${s+l}" role="img" aria-label="${rd(e.title)}" aria-description="${rd(St(e))}" style="font-family:${id}"><g class="st-diagramZone${i.collapsed?` st-diagramZone--collapsed`:` st-diagramZone--expanded`}" data-entity="${rd(e.entityId)}" data-collapsed="${i.collapsed?`true`:`false`}"${e.tone===void 0?``:` data-tone="${rd(e.tone)}"`}${e.proposed===!0?` data-proposed="true"`:``}${f===void 0?``:` data-zone-overflow="${f}"`}${d?` data-zone-icon-unknown=""`:``} transform="translate(${o} ${s})">`+r+`</g></svg>`,diagnostics:a,layout:i}}var ld=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`);function ud(e,t={}){let n=ft(_t),r=r=>t.measure??(e.measureLines===void 0?n:(t,n,i,a)=>{let o=e.measureLines({text:t,role:n,availableWidth:i,allocatedLines:a,folded:r});return{lines:o.lines,tooWide:o.width>i,lineWidths:o.lines.map(()=>o.width)}}),i=r(!1),a={...e,measureLines:t.measure===void 0?e.measureLines??vt(i):vt(i)},o=zu(a);if(o.status!==`laid-out`)throw Error(`Scene refused: `+JSON.stringify(o.refusals));let s=e.targetWidth??1440,c={viewWidth:s,windowHeight:t.windowHeight??900,fitToWindow:t.fitToWindow??!1},l=Ku(o,a,c),u=l.bounds??{x:0,y:0,width:1,height:1},d=Yu({bounds:u,...c}),f=e.metrics?.edgeCornerRadius??12,p=e.metrics?.linkStrokeWidth??2.5,m=l.overviewEdgeLabelSize??(l.r7Connectors?e.metrics?.edgeLabelSize:void 0)??18,h=ol(`scene-arrow`),g=fl(l.edges,h).map(e=>{let t=e.stroke===void 0?``:` stroke="${ld(e.stroke)}" stroke-width="${e.strokeWidth??1.5}"`;return`<marker id="${ld(e.id)}" data-arrowhead-kind="${ld(e.kind)}" data-arrowhead-emphasis="${ld(e.emphasis)}" viewBox="${e.viewBox}" refX="${e.refX}" refY="${e.refY}" markerUnits="${e.markerUnits}" markerWidth="${e.markerWidth}" markerHeight="${e.markerHeight}" orient="${e.orient}"><path d="${e.path}" fill="${ld(e.fill)}"${t}/></marker>`}).join(``),_=l.edges.map(t=>{if(!t.r7){let e=t.markers===void 0?` marker-end="url(#scene-arrow)"`:``;return`<polyline data-scene-edge="${ld(t.occurrence)}" points="${t.points.map(e=>e.x+`,`+e.y).join(` `)}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)" stroke-width="1.5" stroke-linejoin="round"${e}/>${t.markers??``}`}let n=t.emphasis===`emphasis`?al:`var(--st-component-diagramScene-edgeStroke, #64748b)`,r=ll(t,e.metrics),i=sl(t.strokeStyle),a=dl(t,h);return`<path ${[`data-scene-edge="${ld(t.occurrence)}"`,`data-connector-mode="r7"`,`d="${Nu(t.points,f)}"`,...t.strokeStyle===void 0?[]:[`data-edge-stroke="${ld(t.strokeStyle)}"`],...t.arrowhead===void 0?[]:[`data-edge-arrowhead="${ld(t.arrowhead)}"`],...t.emphasis===void 0?[]:[`data-edge-emphasis="${ld(t.emphasis)}"`],`fill="none"`,`stroke="${n}"`,`stroke-width="${r}"`,`vector-effect="non-scaling-stroke"`,`stroke-linejoin="round"`,...i===void 0?[]:[`stroke-dasharray="${i}"`,`style="${cl(t.strokeStyle)}"`],...a===void 0?[]:[`marker-end="${a}"`]].join(` `)}/>${t.markers??``}`}).join(``),v=t=>{let n=r(t.collapsed);if(t.kind===`erd`&&t.erd!==void 0)return`<g data-scene-occurrence="${ld(t.occurrence)}" transform="translate(${t.rect.x} ${t.rect.y})">${Qo(t.erd)}</g>`;let i={entityId:t.entity,resolveGlyph:e.resolveGlyph??tt},a=t.kind===`zone`?Nt(t.presentation,{...i,collapsed:t.collapsed,...e.metrics?.containerPadding===void 0?{}:{containerPadding:e.metrics.containerPadding},width:t.rect.width,height:t.rect.height,toggleLabel:t.collapsed?`Expand`:`Collapse`}):ut(t.presentation,i);if(a.kind===`label`)return`<text x="${t.rect.x}" y="${t.rect.y+24}">${ld(t.text)}</text>`;let o=a.kind===`zone`?cd({...a.props,autoSize:!0},{measure:n}):nd({...a.props,autoSize:!0,height:t.rect.height},n);if(o.kind!==`rendered`)throw Error(`Content must never refuse a component`);return`<g data-scene-occurrence="${ld(t.occurrence)}" transform="translate(${t.rect.x} ${t.rect.y})">${o.svg}</g>`},y=Uu(l),b=e=>`x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}"`,x=y===void 0?``:`<mask id="scene-connector-mask" maskUnits="userSpaceOnUse" ${b(y.region)}><rect ${b(y.region)} fill="#fff"/>${y.cutouts.map(e=>`<rect data-scene-cutout="" ${b(e)} fill="#000"/>`).join(``)}</mask>`,S=`<g data-scene-connectors=""${y===void 0?``:` mask="url(#scene-connector-mask)"`}>${_}</g>`,C=Hu(l.nodes,`frame`).map(v).join(``),w=Hu(l.nodes,`box`).map(v).join(``),T=l.labels.map(e=>{let t=e.box,n=Math.round(m/18*22),r=Math.round(m),i=``;return e.bundle?(i=`<text x="${t.width/2}" y="${n}" text-anchor="middle">${ld(e.bundle.header)}</text>`,e.bundle.groups.forEach((e,r)=>{i+=`<g data-bundle-relation="${r}"><path d="M0 ${e.top}H${t.width}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="5" y="${e.top+n}">•</text>`,e.lines.forEach((t,r)=>{i+=`<text x="22" y="${e.top+n+r*n}">${ld(t)}</text>`}),i+=`</g>`})):e.lines.forEach((e,a)=>{i+=`<text x="${t.width/2}" y="${r+a*n}" text-anchor="middle">${ld(e)}</text>`}),(e.leader===void 0?``:l.r7Connectors&&!e.erd?`<path data-scene-leader="${ld(e.occurrence)}" data-connector-mode="r7" d="${Nu(e.leader,f)}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)" stroke-width="${p}" vector-effect="non-scaling-stroke" stroke-linejoin="round"/>`:`<polyline points="${e.leader.map(e=>e.x+`,`+e.y).join(` `)}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)"/>`)+`<g data-scene-label="${ld(e.occurrence)}" transform="translate(${t.x} ${t.y})" font-size="${m}" fill="var(--st-component-diagramScene-labelText, #172033)"><rect width="${t.width}" height="${t.height}" fill="var(--st-component-diagramScene-labelSurface, #ffffff)" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/>${i}</g>`}).join(``),E=l.r7Connectors?`<marker id="scene-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="userSpaceOnUse" markerWidth="10.5" markerHeight="10.5" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)"/></marker>`:`<marker id="scene-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)"/></marker>`,D=(()=>{let t=l.linkLegend;if(t===void 0)return``;let n=t.rect,r=t.padding+t.headerHeight-.5,i=t.padding+t.headerHeight/2+t.fontSize*.35,a=t.entries.map(n=>{let r=Ol(n,e.metrics),i=n.rowY+(n.rowHeight-r.height)/2,a=[`data-legend-swatch="${ld(n.key)}"`,`d="${r.linePath}"`,`fill="none"`,`stroke="${ld(r.stroke)}"`,`stroke-width="${r.strokeWidth}"`,`vector-effect="non-scaling-stroke"`,...r.dashArray===void 0?[]:[`stroke-dasharray="${ld(r.dashArray)}"`,`style="${cl(n.strokeStyle)}"`]].join(` `),o=r.arrowPath===void 0?``:`<path d="${r.arrowPath}" fill="${ld(r.arrowFill??r.stroke)}"${r.arrowStroke===void 0?``:` stroke="${ld(r.arrowStroke)}" stroke-width="${r.arrowStrokeWidth??1.5}"`}/>`,s=t.padding+t.swatchWidth+t.swatchGap,c=n.rowY+n.rowHeight/2+t.fontSize*.35;return`<g data-legend-style="${ld(n.key)}" data-edge-stroke="${ld(n.strokeStyle)}" data-edge-arrowhead="${ld(n.arrowhead)}" data-edge-emphasis="${ld(n.emphasis)}"><g transform="translate(${t.padding} ${i})"><path ${a}/>${o}</g><text x="${s}" y="${c}" font-size="${t.fontSize}" fill="var(--st-component-diagramScene-labelText, #172033)">${ld(n.label)}</text></g>`}).join(``);return`<g data-scene-legend="" data-legend-anchor="${ld(t.anchor)}" transform="translate(${n.x} ${n.y})"><rect width="${n.width}" height="${n.height}" fill="var(--st-component-diagramScene-labelSurface, #ffffff)" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="${t.padding}" y="${i}" font-size="${t.fontSize}" font-weight="700" fill="var(--st-component-diagramScene-labelText, #172033)">${ld(t.title)}</text><path d="M${t.padding} ${r}H${n.width-t.padding}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/>${a}</g>`})();return{svg:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${u.x-2} ${u.y-2} ${u.width+4} ${u.height+4}" width="${(u.width+4)*d.zoom}" height="${(u.height+4)*d.zoom}" data-viewport-width="${s}" data-display-scale="${d.zoom}" role="img" aria-label="${ld(t.title??e.document.documentId)}" font-family="Inter, system-ui, sans-serif"><title>${ld(t.title??e.document.documentId)}</title><style>${l.r7Connectors?`@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg:root{--st-font-sans:Inter,system-ui,sans-serif;--st-semantic-surface-raised:#fff;--st-semantic-surface-subtle:#f8fafc;--st-component-diagramZone-surface1:#fff;--st-component-diagramZone-surface2:#f8fafc;--st-semantic-text-primary:#172033;--st-semantic-text-secondary:#475569;--st-semantic-border-strong:#64748b;--st-semantic-border-subtle:#cbd5e1;--st-semantic-border-interactive:#2563eb;--st-semantic-feedback-info:#2563eb;--st-component-diagramScene-edgeStroke:#64748b;--st-component-diagramScene-linkStrokeWidth:2.5px;--st-component-diagramScene-linkRelatedStrokeWidth:3px;--st-component-diagramScene-linkPrimaryStrokeWidth:3.5px;--st-component-diagramScene-linkEmphasisStroke:${il};--st-component-diagramScene-linkEmphasisStrokeWidth:3.5px;--st-component-diagramScene-linkDashDashed:8 6;--st-component-diagramScene-linkDashDotted:2 5;--st-component-diagramScene-edgeCornerRadius:12px;--st-component-diagramScene-edgeLabelSize:18px}`:`@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg:root{--st-font-sans:Inter,system-ui,sans-serif;--st-semantic-surface-raised:#fff;--st-semantic-surface-subtle:#f8fafc;--st-component-diagramZone-surface1:#fff;--st-component-diagramZone-surface2:#f8fafc;--st-semantic-text-primary:#172033;--st-semantic-text-secondary:#475569;--st-semantic-border-strong:#64748b;--st-semantic-border-subtle:#cbd5e1;--st-semantic-feedback-info:#2563eb}`}</style><defs>${E}${g}${x}</defs>${C}${S}${w}${T}${D}</svg>`,result:o,scene:l}}var dd=class extends Error{sectionId;code;diagnostics;constructor(e,t,n,r=[]){super(`Diagram "${e}": ${n}`),this.sectionId=e,this.code=t,this.diagnostics=r,this.name=`DossierDiagramError`}};function fd(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pd(e,t){return fd(e)&&Object.keys(e).every(e=>t.includes(e))}function md(e){return pd(e,[`kind`,`value`])&&e.kind===`text`&&typeof e.value==`string`}function hd(e,t){let n=()=>t(`Unsupported diagram-core document: expected generic@1 nodes/containers, links and a containment tree without views, geometry or layout hints`),{schemaVersion:r,documentId:i,revision:a,profileRefs:o,typeDefinitions:s,entities:c,relations:l,ports:u,resources:d,extensions:f}=e;if((!pd(e,[`documentId`,`schemaVersion`,`revision`,`profileRefs`,`typeDefinitions`,`entities`,`relations`,`ports`,`resources`,`extensions`])||typeof i!=`string`||!i.startsWith(`document:`)||!pd(r,[`major`,`minor`])||r.major!==1||r.minor!==1||typeof a!=`number`||!Number.isInteger(a)||a<0||!Array.isArray(o)||o.length!==1||o[0]!==`generic@1`||!pd(s,[])||!pd(u,[])||!pd(d,[])||!Array.isArray(f)||f.length!==0)&&n(),!fd(c)||!fd(l))return n();let p=Object.entries(c),m=Object.entries(l);(p.length===0||p.length>80||m.length>240)&&n();let h=new Set;for(let[e,t]of p){if(!e.startsWith(`entity:`)||!pd(t,[`id`,`profile`,`type`,`attributes`])||t.id!==e||t.profile!==`generic@1`||t.type!==`node`&&t.type!==`container`||!pd(t.attributes,[`name`])||!md(t.attributes.name))return n();t.type===`container`&&h.add(e)}let g=new Map;for(let[e,t]of m){if(!e.startsWith(`relation:`)||!pd(t,[`id`,`profile`,`type`,`endpoints`,`attributes`])||t.id!==e||t.profile!==`generic@1`||t.type!==`link`&&t.type!==`contains`||!Array.isArray(t.endpoints)||t.endpoints.length!==2||!t.endpoints.every(e=>pd(e,[`role`,`target`]))||!pd(t.attributes,t.type===`link`?[`label`]:[]))return n();let{endpoints:r,type:i,attributes:a}=t,o=r.find(e=>e.role===(i===`link`?`source`:`parent`))?.target,s=r.find(e=>e.role===(i===`link`?`target`:`child`))?.target;if(typeof o!=`string`||typeof s!=`string`||!Object.hasOwn(c,o)||!Object.hasOwn(c,s))return n();i===`contains`?((!h.has(o)||g.has(s))&&n(),g.set(s,o)):a.label!==void 0&&!md(a.label)&&n()}for(let e of g.keys()){let t=new Set;for(let r=e;r!==void 0;r=g.get(r))t.has(r)&&n(),t.add(r)}}function gd(e,t){let n=t=>{throw new dd(e,`diagram-source-unsupported`,t)};return fd(t)?(hd(t,n),t):n(`Expected a semantic scene object`)}var _d=ft(_t),vd=vt(_d),yd=new Set([`label-unplaced`,`label-budget-exhausted`,`route-obstructed`,`route-spacing-conflict`,`channel-unresolved`,`channel-capacity-exceeded`,`docking-overflow`]),bd={id:`diagram-presentation`,version:`1`,contentDigest:`74dadb9c31fff7653ca31692d8db3cfea782baea8d9268a3c20982ea8ab0aeae`},xd={id:`generic@1`,name:`generic`,version:1,completeness:`complete`,entityTypes:[{id:`node`,label:`Node`,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`state`,kind:`enum`,values:[`draft`,`active`,`retired`]},{name:`weight`,kind:`quantity`,units:[`unit`]},{name:`duration`,kind:`quantity`,units:[`s`,`min`,`h`]},{name:`createdAt`,kind:`date`},{name:`pinned`,kind:`boolean`},{name:`tags`,kind:`collection`,item:{kind:`text`,maxLength:40},maxItems:8},{name:`owner`,kind:`reference`,refKind:`entity`}]},{id:`container`,label:`Container`,container:!0,attributes:[{name:`name`,kind:`text`,required:!0,maxLength:200},{name:`collapsed`,kind:`boolean`}]}],portTypes:[{id:`port`,label:`Port`,directions:[`in`,`out`,`inout`],attributes:[{name:`label`,kind:`text`,maxLength:80}]}],relationTypes:[{id:`link`,label:`Link`,direction:`directed`,roles:[{role:`source`,cardinality:{min:1,max:1},targets:[`entity`,`port`]},{role:`target`,cardinality:{min:1,max:1},targets:[`entity`,`port`]}],attributes:[{name:`label`,kind:`text`,maxLength:120},{name:`weight`,kind:`quantity`,units:[`unit`]}]},{id:`contains`,label:`Contains`,direction:`directed`,roles:[{role:`parent`,cardinality:{min:1,max:1},targets:[`entity`],entityTypes:[`container`]},{role:`child`,cardinality:{min:1,max:1},targets:[`entity`]}],hierarchy:{id:`containment`,shape:`tree`,parentRole:`parent`,childRole:`child`}},{id:`association`,label:`Association`,direction:`undirected`,roles:[{role:`member`,cardinality:{min:2,max:8},targets:[`entity`]}],attributes:[{name:`label`,kind:`text`,maxLength:120}]}],constraints:[{kind:`acyclic-hierarchy`,hierarchyId:`containment`},{kind:`unique-attribute`,entityType:`container`,attribute:`name`},{kind:`max-entities-of-type`,entityType:`container`,max:64}],limits:{maxEntities:1e5,maxRelations:5e5,maxEndpointsPerRelation:8},notes:[`Foldable generic@1 profile for Focus dossier diagrams.`]},Sd={get:e=>e===`generic@1`?xd:void 0,has:e=>e===`generic@1`,list:()=>[`generic@1`]},Cd={schemaVersion:`1`,rows:[{profileId:`generic@1`,profilePin:{id:`generic@1`,version:1,contentDigest:`a003981971bdf75b50f455f19d701130c81fd896aeb7f4b0f0f9fe49dd874b8a`},declarationAdapter:`legacy-constraints@1`}]},wd=e=>e.slice(e.indexOf(`:`)+1),Td=e=>`occurrence:${e}`;function Ed(e){let t=Object.fromEntries(Object.values(e.entities).map(e=>[Td(`e.${wd(e.id)}`),{form:e.type===`container`?`container`:`card`,text:{title:e.attributes.name?.kind===`text`?e.attributes.name.value:e.id}}])),n=Object.entries(t).filter(([,e])=>e.form===`container`).map(([e])=>e);return{document:e,registry:Sd,bindings:Cd,presentation:{contractPin:bd,entities:t,legends:{},categoryTokens:[]},measureLines:vd,containers:n}}function Dd(e,t,n,r){let i={...n,collapsed:r},a;try{a=ud(i,{title:t,measure:_d})}catch(t){let n=zu(i);throw n.status===`laid-out`?t:new dd(e,`diagram-layout-refused`,`The DS engine refused the scene`,[...n.refusals,...n.diagnostics])}let o=a.scene.nodes.flatMap(e=>{let t={entityId:e.entity},n=e.kind===`zone`?Nt(e.presentation,{...t,collapsed:e.collapsed,width:e.rect.width,height:e.rect.height}):ut(e.presentation,t);return n.kind===`label`?[]:[...n.kind===`zone`?Mt({...n.props,autoSize:!0},_d).diagnostics:wt({...n.props,height:e.rect.height,autoSize:!0},_d).diagnostics].filter(e=>e.code===`card-overflow`||e.code===`zone-overflow`)}),s=a.result.warnings.filter(({code:e})=>yd.has(e)||e.endsWith(`-overflow`));return{...a,diagnostics:[...o,...s]}}function Od(e,t,n){let r=Ed(n),i=Dd(e,t,r,[]),a=r.containers.length===0?i:Dd(e,t,r,r.containers),o=a===i?i.diagnostics:[...i.diagnostics,...a.diagnostics];if(o.length!==0)throw new dd(e,`diagram-layout-refused`,`The DS engine reported ${o.map(({code:e})=>e).join(`, `)}`,o);return{layout:r,expanded:i,folded:a}}var kd=0;function Ad(e,t,n){let r=e.createElement(`template`);r.innerHTML=t.replace(/<style>[\s\S]*?<\/style>| style="[^"]*"/g,``);let i=r.content.querySelector(`svg`);for(let e of i.querySelectorAll(`[data-toggle]`))e.remove();for(let e of i.querySelectorAll(`[id]`))e.id=n+e.id;for(let e of i.querySelectorAll(`[marker-end], [mask]`))for(let t of[`marker-end`,`mask`]){let r=e.getAttribute(t);r?.startsWith(`url(#`)&&e.setAttribute(t,`url(#${n}${r.slice(5)}`)}return i}function jd(e,t,n){let r=t.scene??n?.scene;if(r===void 0)throw new dd(t.id,`diagram-views-invalid`,`A scene or a views companion is required`);let i=gd(t.id,r),{layout:a,expanded:o,folded:s}=Od(t.id,t.alt,i);if(n!==void 0&&(x(n.scene)!==x(i)||x(n.views)!==x({expanded:o.result.view,folded:s.result.view})))throw new dd(t.id,`diagram-views-invalid`,`The views companion does not match the scene`);let c=e.createElement(`div`);c.className=`st-dossier__diagramDrawing`;let l=e.createElement(`div`);l.className=`st-dossier__diagramViewport`;let u=`st-dossier-scene-${++kd}-`;if(l.append(Ad(e,o.svg,u)),c.append(l),a.containers.length!==0){let n=e.createElement(`button`);n.type=`button`,n.textContent=`Fold containers`,n.setAttribute(`aria-expanded`,`true`),n.setAttribute(`data-review-passthrough`,``),l.id=`${u}viewport`,n.setAttribute(`aria-controls`,l.id),n.addEventListener(`click`,()=>{let r=n.getAttribute(`aria-expanded`)===`true`,{svg:i}=Dd(t.id,t.alt,a,r?a.containers:[]);l.replaceChildren(Ad(e,i,u)),n.setAttribute(`aria-expanded`,String(!r)),n.textContent=r?`Expand containers`:`Fold containers`}),c.prepend(n)}return c}function Md(e){if(!fd(e)||e.contract!==`focus-dossier/1`||!Array.isArray(e.derived))throw Error(`Invalid focus-dossier/1 manifest`);let t=e.derived.filter(e=>fd(e)&&e.path===`views.json`);if(t.length>1)throw Error(`Duplicate views.json manifest entry`);return t[0]}function Nd(e,t,n,r){if(t===void 0&&n===void 0)return new Map;let i=Md(t);if(!fd(t)||!fd(t.document)||t.document.digest!==S(e))throw Error(`Dossier document digest does not match the manifest`);if(n===void 0&&i===void 0)return new Map;if(!fd(n)||n.contract!==`focus-views/1`||!fd(n.diagrams)||Object.keys(n).length!==4)throw Error(`Invalid focus-views/1 companion`);if(n.documentDigest!==t.document.digest)throw Error(`Views document digest does not match the manifest`);if(!fd(t.renderer)||typeof n.rendererDigest!=`string`||!/^sha256:[0-9a-f]{64}$/.test(n.rendererDigest)||n.rendererDigest!==t.renderer.digest)throw Error(`Views renderer digest does not match the manifest`);if(i?.mimeType!==`application/json`||i.digest!==S(n)||i.bytes!==new TextEncoder().encode(x(n)).length)throw Error(`Views file digest or size does not match the manifest`);return new Map(Object.entries(n.diagrams).map(([e,t])=>{if(!r.has(e)||!fd(t)||!fd(t.scene)||!fd(t.views)||Object.keys(t).length!==2||Object.keys(t.views).length!==2)throw Error(`Invalid views companion entry for diagram "${e}"`);return[e,{scene:t.scene,views:t.views}]}))}function Pd(e,t){this.v=e,this.k=t}function Fd(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Id(e){if(Array.isArray(e))return e}function Ld(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Rd(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
831
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zd(e,t){return Id(e)||Ld(e,t)||Bd(e,t)||Rd()}function Bd(e,t){if(e){if(typeof e==`string`)return Fd(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Fd(e,t):void 0}}function Vd(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Pd;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Vd.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Vd.prototype.next=function(e){return this._invoke(`next`,e)},Vd.prototype.throw=function(e){return this._invoke(`throw`,e)},Vd.prototype.return=function(e){return this._invoke(`return`,e)};var Hd=Object.entries,Ud=Object.setPrototypeOf,Wd=Object.isFrozen,Gd=Object.getPrototypeOf,Kd=Object.getOwnPropertyDescriptor,qd=Object.freeze,Jd=Object.seal,Yd=Object.create,Xd=typeof Reflect<`u`&&Reflect,Zd=Xd.apply,Qd=Xd.construct;qd||=function(e){return e},Jd||=function(e){return e},Zd||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},Qd||=function(e){return new e(...[...arguments].slice(1))};var $d=wf(Array.prototype.forEach);Array.prototype.indexOf;var ef=wf(Array.prototype.lastIndexOf),tf=wf(Array.prototype.pop),nf=wf(Array.prototype.push),rf=wf(Array.prototype.slice),af=wf(Array.prototype.splice),of=Array.isArray,sf=Tf(Set),cf=wf(Set.prototype.add),lf=wf(Set.prototype.has),uf=wf(String.prototype.toLowerCase),df=wf(String.prototype.toString),ff=wf(String.prototype.match),pf=wf(String.prototype.replace),mf=wf(String.prototype.indexOf),hf=wf(String.prototype.trim),gf=wf(Number.prototype.toString),_f=wf(Boolean.prototype.toString),vf=typeof BigInt>`u`?null:wf(BigInt.prototype.toString),yf=typeof Symbol>`u`?null:wf(Symbol.prototype.toString),bf=wf(Object.prototype.hasOwnProperty),xf=wf(Object.prototype.toString),Sf=wf(RegExp.prototype.test),Cf=Tf(TypeError);function wf(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return Zd(e,t,n)}}function Tf(e){return function(){return Qd(e,[...arguments])}}function Ef(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:uf;if(Ud&&Ud(e,null),!of(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(Wd(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Df(e){for(let t=0;t<e.length;t++)bf(e,t)||(e[t]=null);return e}function Of(e){let t=Yd(null);for(let r of Hd(e)){var n=zd(r,2);let i=n[0],a=n[1];bf(e,i)&&(t[i]=of(a)?Df(a):a&&typeof a==`object`&&a.constructor===Object?Of(a):a)}return t}function kf(e){switch(typeof e){case`string`:return e;case`number`:return gf(e);case`boolean`:return _f(e);case`bigint`:return vf?vf(e):`0`;case`symbol`:return yf?yf(e):`Symbol()`;case`undefined`:return xf(e);case`function`:case`object`:{if(e===null)return xf(e);let t=e,n=Af(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:xf(e)}return xf(e)}default:return xf(e)}}function Af(e,t){for(;e!==null;){let n=Kd(e,t);if(n){if(n.get)return wf(n.get);if(typeof n.value==`function`)return wf(n.value)}e=Gd(e)}function n(){return null}return n}function jf(e,t){for(;e!==null;){let n=Kd(e,t);if(n)return n.get?wf(n.get):null;e=Gd(e)}return null}function Mf(e){try{return Sf(e,``),!0}catch{return!1}}var Nf=qd(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Pf=qd(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),Ff=qd([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),If=qd([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),Lf=qd(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),Rf=qd([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),zf=qd([`#text`]),Bf=qd(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),Vf=qd(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),Hf=qd(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),Uf=qd([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Wf=Jd(/{{[\w\W]*|^[\w\W]*}}/g),Gf=Jd(/<%[\w\W]*|^[\w\W]*%>/g),Kf=Jd(/\${[\w\W]*/g),qf=Jd(/^data-[\-\w.\u00B7-\uFFFF]+$/),Jf=Jd(/^aria-[\-\w]+$/),Yf=Jd(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Xf=Jd(/^(?:\w+script|data):/i),Zf=Jd(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Qf=Jd(/^html$/i),$f=Jd(/^[a-z][.\w]*(-[.\w]+)+$/i),ep=Jd(/<[/\w!]/g),tp=Jd(/<[/\w]/g),np=Jd(/<\/no(script|embed|frames)/i),rp=Jd(/\/>/i),ip={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ap=qd(Ef({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),op=function(){return typeof window>`u`?null:window},sp=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},cp=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},lp=function(e,t,n,r){return bf(e,t)&&of(e[t])?Ef(r.base?Of(r.base):{},e[t],r.transform):n},up=function(e,t,n){let r=bf(e,t)?e[t]:void 0;return r&&typeof r==`object`?Of(r):n()};function dp(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:op(),t=e=>dp(e);if(t.version=`3.4.17`,t.removed=[],!e||!e.document||e.document.nodeType!==ip.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=Af(d,`cloneNode`),p=Af(d,`remove`),m=Af(d,`removeAttributeNode`),h=Af(d,`nextSibling`),g=Af(d,`childNodes`),_=Af(d,`parentNode`),v=Af(d,`shadowRoot`),y=Af(d,`attributes`),b=o&&o.prototype?Af(o.prototype,`nodeType`):null,x=o&&o.prototype?Af(o.prototype,`nodeName`):null,S=o&&o.prototype?Af(o.prototype,`ownerDocument`):null,C=function(e){return b?b(e):e.nodeType},w=function(e){return x?x(e):e.nodeName},T=jf(d,`namespaceURI`),E=function(e){return T?T(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let D,O=``,k,A=!1,j=0,M=function(){if(j>0)throw Cf(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},ee=function(e){M(),j++;try{return D.createHTML(e)}finally{j--}},te=function(e){M(),j++;try{return D.createScriptURL(e)}finally{j--}},ne=function(){return A||=(k=sp(u,i),!0),k},N=n,P=N.implementation,F=N.createNodeIterator,I=N.createDocumentFragment,re=N.getElementsByTagName,L=r.importNode,R=cp();t.isSupported=typeof Hd==`function`&&typeof _==`function`&&P&&P.createHTMLDocument!==void 0;let ie=Wf,z=Gf,ae=Kf,B=qf,oe=Jf,se=Xf,ce=Zf,le=$f,ue=Yf,V=null,de=Ef({},[...Nf,...Pf,...Ff,...Lf,...zf]),fe=null,pe=Ef({},[...Bf,...Vf,...Hf,...Uf]),me=Object.seal(Yd(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),he=null,ge=null,_e=Object.seal(Yd(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ve=!0,ye=!0,be=!1,xe=!0,Se=!1,Ce=!0,we=!1,Te=!1,Ee=null,De=null,Oe=!1,ke=!1,Ae=!1,je=!1,Me=!0,Ne=!1,Pe=`user-content-`,Fe=!0,Ie=!1,Le=null,Re={},ze=null,Be=Ef({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Ve=null,He=Ef({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ue=null,We=Ef({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Ge=`http://www.w3.org/1998/Math/MathML`,Ke=`http://www.w3.org/2000/svg`,qe=`http://www.w3.org/1999/xhtml`,Je=qe,Ye=!1,Xe=null,Ze=Ef({},[Ge,Ke,qe],df),Qe=qd([`mi`,`mo`,`mn`,`ms`,`mtext`]),$e=Ef({},Qe),et=qd([`annotation-xml`]),tt=Ef({},et),nt=Ef({},[`title`,`style`,`font`,`a`,`script`]),rt=null,it=[`application/xhtml+xml`,`text/html`],at=null,ot=null,st=n.createElement(`form`),ct=function(e){return e instanceof RegExp||e instanceof Function},lt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(ot&&ot===e)return;(!e||typeof e!=`object`)&&(e={}),e=Of(e),rt=it.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,at=rt===`application/xhtml+xml`?df:uf,V=lp(e,`ALLOWED_TAGS`,de,{transform:at}),fe=lp(e,`ALLOWED_ATTR`,pe,{transform:at}),Xe=lp(e,`ALLOWED_NAMESPACES`,Ze,{transform:df}),Ue=lp(e,`ADD_URI_SAFE_ATTR`,We,{transform:at,base:We}),Ve=lp(e,`ADD_DATA_URI_TAGS`,He,{transform:at,base:He}),ze=lp(e,`FORBID_CONTENTS`,Be,{transform:at}),he=lp(e,`FORBID_TAGS`,Of({}),{transform:at}),ge=lp(e,`FORBID_ATTR`,Of({}),{transform:at}),Re=bf(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Of(e.USE_PROFILES):e.USE_PROFILES:!1,ve=e.ALLOW_ARIA_ATTR!==!1,ye=e.ALLOW_DATA_ATTR!==!1,be=e.ALLOW_UNKNOWN_PROTOCOLS||!1,xe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Se=e.SAFE_FOR_TEMPLATES||!1,Ce=e.SAFE_FOR_XML!==!1,we=e.WHOLE_DOCUMENT||!1,ke=e.RETURN_DOM||!1,Ae=e.RETURN_DOM_FRAGMENT||!1,je=e.RETURN_TRUSTED_TYPE||!1,Oe=e.FORCE_BODY||!1,Me=e.SANITIZE_DOM!==!1,Ne=e.SANITIZE_NAMED_PROPS||!1,Fe=e.KEEP_CONTENT!==!1,Ie=e.IN_PLACE||!1,ue=Mf(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Yf,Je=typeof e.NAMESPACE==`string`?e.NAMESPACE:qe,$e=up(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>Ef({},Qe)),tt=up(e,`HTML_INTEGRATION_POINTS`,()=>Ef({},et));let t=up(e,`CUSTOM_ELEMENT_HANDLING`,()=>Yd(null));if(me=Yd(null),bf(t,`tagNameCheck`)&&ct(t.tagNameCheck)&&(me.tagNameCheck=t.tagNameCheck),bf(t,`attributeNameCheck`)&&ct(t.attributeNameCheck)&&(me.attributeNameCheck=t.attributeNameCheck),bf(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(me.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),Jd(me),Se&&(ye=!1),Ae&&(ke=!0),Re&&(V=Ef({},zf),fe=Yd(null),Re.html===!0&&(Ef(V,Nf),Ef(fe,Bf)),Re.svg===!0&&(Ef(V,Pf),Ef(fe,Vf),Ef(fe,Uf)),Re.svgFilters===!0&&(Ef(V,Ff),Ef(fe,Vf),Ef(fe,Uf)),Re.mathMl===!0&&(Ef(V,Lf),Ef(fe,Hf),Ef(fe,Uf))),_e.tagCheck=null,_e.attributeCheck=null,bf(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?_e.tagCheck=e.ADD_TAGS:of(e.ADD_TAGS)&&(V===de&&(V=Of(V)),Ef(V,e.ADD_TAGS,at))),bf(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?_e.attributeCheck=e.ADD_ATTR:of(e.ADD_ATTR)&&(fe===pe&&(fe=Of(fe)),Ef(fe,e.ADD_ATTR,at))),bf(e,`ADD_FORBID_CONTENTS`)&&of(e.ADD_FORBID_CONTENTS)&&(ze===Be&&(ze=Of(ze)),Ef(ze,e.ADD_FORBID_CONTENTS,at)),Fe&&(V[`#text`]=!0),we&&Ef(V,[`html`,`head`,`body`]),V.table&&(Ef(V,[`tbody`]),delete he.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Cf(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Cf(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=D;D=e.TRUSTED_TYPES_POLICY;try{O=ee(``)}catch(e){throw D=t,e}}else e.TRUSTED_TYPES_POLICY===null?(D=void 0,O=``):(D===void 0&&(D=ne()),D&&typeof O==`string`&&(O=ee(``)));qd&&qd(e),ot=e},ut=Ef({},[...Pf,...Ff,...If]),dt=Ef({},[...Lf,...Rf]),ft=function(e,t,n){return t.namespaceURI===qe?e===`svg`:t.namespaceURI===Ge?e===`svg`&&(n===`annotation-xml`||$e[n]):!!ut[e]},pt=function(e,t,n){return t.namespaceURI===qe?e===`math`:t.namespaceURI===Ke?e===`math`&&tt[n]:!!dt[e]},mt=function(e,t,n){return t.namespaceURI===Ke&&!tt[n]||t.namespaceURI===Ge&&!$e[n]?!1:!dt[e]&&(nt[e]||!ut[e])},ht=function(e){let t=E(e),n=uf(w(e)),r=_(e),i,a;return r&&C(r)===ip.element?(i={namespaceURI:E(r)},a=uf(w(r))):(i={namespaceURI:Je},a=`template`),Xe[t]?t===Ke?ft(n,i,a):t===Ge?pt(n,i,a):t===qe?mt(n,i,a):!!(rt===`application/xhtml+xml`&&Xe[t]):!1},gt=function(e){nf(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Cf(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},_t=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},vt=function(e){St(e);let t=g(e);t&&$d(rf(t),e=>{try{p(e)}catch{}});let n=C(e)===ip.element?y(e):null;if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&_t(e,r,i)}},yt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}nf(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(ke||Ae)try{gt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},bt=function(e){let t=y(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||fe[at(i)]||_t(e,r,i)}},xt=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&C(e)===ip.element){let t=v(e);It(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},St=function(e){xt(e,e=>{C(e)===ip.element&&bt(e)})},Ct=function(e){let t=[];return xt(e,e=>{t.push(e)},!0),t},wt=function(e,t){let n=sf();$d(Ct(e),e=>{C(e)===ip.element&&cf(n,e)}),$d(t,e=>{C(e)===ip.element&&!lf(n,e)&&bt(e)})},Tt=function(e,n){let r=!1;return $d(t.removed,t=>{t.element&&(r||=t.element===e,St(t.element))}),wt(e,n),r},Et=function(e,t){let n=Le,r=null,i=()=>(r||(r=sf(),$d(t,e=>{cf(r,e)})),r);for(let t=0;;t++){let r=Ct(e),a=[e],o=!1;if($d(r,e=>{C(e)===ip.documentFragment?nf(a,e):!o&&!lf(n,e)&&(o=lf(i(),e))}),!o)return;if(t>=8)throw Cf(`the tree kept changing during in-place sanitization; refusing to return it`);$d(a,(t,n)=>{Dt(t,n>0,e,i())})}},Dt=function(e,t,n,r){let i=Mt(e),a;for(;a=i.nextNode();)lf(r,a)&&!lf(Le,a)&&(t&&Rt(R.uponSanitizeShadowNode,a,null),Wt(a,n),Zt(a,n),It(a.content)&&Qt(a.content))},Ot=function(e){Le&&cf(Le,e)},kt=function(e,t){return Ce?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},At=function(e){Ce&&xt(e,e=>{let t=C(e);if(t===ip.processingInstruction||t===ip.comment&&Sf(tp,e.data)){try{p(e)}catch{}return!1}if(t===ip.element){let t=e,n=at(w(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&kt(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},jt=function(e){let t=null,r=null;if(Oe)e=`<remove></remove>`+e;else{let t=ff(e,/^[\r\n\t ]+/);r=t&&t[0]}rt===`application/xhtml+xml`&&Je===qe&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=D?ee(e):e;if(Je===qe)try{t=new l().parseFromString(i,rt)}catch{}if(!t||!t.documentElement){t=P.createDocument(Je,`template`,null);try{t.documentElement.innerHTML=Ye?O:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Je===qe?re.call(t,we?`html`:`body`)[0]:we?t.documentElement:a},Mt=function(e){let t=S?S(e):e.ownerDocument;return F.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Nt=function(e){return e=pf(e,ie,` `),e=pf(e,z,` `),e=pf(e,ae,` `),e},H=function(e){Pt(e);let t=e.querySelectorAll?.call(e,`template`);t&&$d(t,e=>{It(e.content)&&H(e.content)})},Pt=function(e){e.normalize();let t=S?S(e):e.ownerDocument,n=F.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=Nt(r.data),r=n.nextNode()},Ft=function(e){let t=x?x(e):null;return typeof t!=`string`||at(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==y(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==b(e)||e.childNodes!==g(e)},It=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return b(e)===ip.documentFragment}catch{return!1}},Lt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return typeof b(e)==`number`}catch{return!1}};function Rt(e,n,r){e.length!==0&&$d(e,e=>{e.call(t,n,r,ot)})}let zt=function(e,t){return!!(Ce&&e.hasChildNodes()&&!Lt(e.firstElementChild)&&Sf(ep,e.textContent)&&Sf(ep,e.innerHTML)||Ce&&ap[t]&&C(e)===ip.element&&E(e)===qe&&(Lt(e.firstElementChild)||typeof e.textContent==`string`&&Sf(ep,e.textContent))||e.nodeType===ip.processingInstruction||Ce&&e.nodeType===ip.comment&&Sf(tp,e.data))},Bt=function(e,t){return e instanceof RegExp?Sf(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Vt=function(e,t,n){if(!he[t]&&qt(t)&&Bt(me.tagNameCheck,t))return!1;if(Fe&&!ze[t]&&!ze[uf(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return gt(e),!0},Ht=function(e,t,n,r){return e.length===0?t:t===n||t===r?Of(t):t},Ut=function(e,t){return e===t||_(e)!==null?!1:(Ie&&St(e),!0)},Wt=function(e,n){if(Ot(e),Rt(R.beforeSanitizeElements,e,null),Ut(e,n))return!0;if(Ft(e))return gt(e),!0;let r=at(w(e));if(V=Ht(R.uponSanitizeElement,V,de,Ee),Rt(R.uponSanitizeElement,e,{tagName:r,allowedTags:V}),Ut(e,n))return!0;if(zt(e,r))return gt(e),!0;if(he[r]||!(_e.tagCheck instanceof Function&&_e.tagCheck(r))&&!V[r]){let t=Vt(e,r,n);return t===!1&&(Rt(R.afterSanitizeElements,e,null),Ut(e,n))?!0:t}if(C(e)===ip.element&&!ht(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&Sf(np,e.innerHTML))return gt(e),!0;if(Se&&e.nodeType===ip.text){let n=Nt(e.textContent);e.textContent!==n&&(nf(t.removed,{element:e.cloneNode()}),e.textContent=n)}return Rt(R.afterSanitizeElements,e,null),Ut(e,n)},Gt=function(e,t,r){if(ge[t]||kt(t,e)||Me&&(t===`id`||t===`name`)&&(r in n||r in st))return!1;let i=fe[t]||_e.attributeCheck instanceof Function&&_e.attributeCheck(t,e);return ye&&Sf(B,t)||ve&&Sf(oe,t)?!0:i?Ue[t]||Sf(ue,pf(r,ce,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&mf(r,`data:`)===0&&Ve[e]||be&&!Sf(se,pf(r,ce,``))?!0:!r:qt(e)&&Bt(me.tagNameCheck,e)&&Bt(me.attributeNameCheck,t,e)||t===`is`&&me.allowCustomizedBuiltInElements&&Bt(me.tagNameCheck,r)},Kt=Ef({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),qt=function(e){return!Kt[uf(e)]&&Sf(le,e)},Jt=function(e,t,n,r){if(D&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ee(r);case`TrustedScriptURL`:return te(r)}return r},Yt=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Ft(e)||(gt(e),!1)}catch{return yt(t,e),!1}},Xt=function(e,t){return Ce&&Sf(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,t)?!0:uf(e)===`attributename`&&ff(t,`href`)!==null},Zt=function(e,n){if(Rt(R.beforeSanitizeAttributes,e,null),Ut(e,n))return;let r=e.attributes;if(!r||Ft(e))return;fe=Ht(R.uponSanitizeAttribute,fe,pe,De);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:fe,forceKeepAttr:void 0},a=r.length,o=at(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=at(s),d=l,f=s===`value`?d:hf(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,Rt(R.uponSanitizeAttribute,e,i),f=i.attrValue,Ne&&(u===`id`||u===`name`)&&mf(f,Pe)!==0&&(yt(s,e,n),f=Pe+f,p=!0),Xt(s,f)?yt(s,e,n):i.forceKeepAttr||(i.keepAttr?!xe&&Sf(rp,f)?yt(s,e,n):(Se&&(f=Nt(f)),Gt(o,u,f)?(f=Jt(o,u,c,f),f!==d&&Yt(e,s,c,f)&&p&&tf(t.removed)):yt(s,e,n)):yt(s,e,n))}Rt(R.afterSanitizeAttributes,e,null),Ut(e,n)},Qt=function(e){let t=null,n=Mt(e);for(Rt(R.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(Rt(R.uponSanitizeShadowNode,t,null),Wt(t,e),Zt(t,e),It(t.content)&&Qt(t.content),C(t)===ip.element){let e=v(t);It(e)&&($t(e),Qt(e))}Se&&Pt(e),Rt(R.afterSanitizeShadowDOM,e,null)},$t=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Qt(e.shadow);continue}let n=e.node,r=C(n)===ip.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=x?x(n):null;if(typeof e==`string`&&at(e)===`template`){let e=n.content;It(e)&&t.push({node:e,shadow:null})}}if(r){let e=v(n);It(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Ye=!e,Ye&&(e=`<!-->`),typeof e!=`string`&&!Lt(e)&&(e=kf(e),typeof e!=`string`))throw Cf(`dirty is not a string, aborting`);if(!t.isSupported)return e;Te?(V=Ee,fe=De):lt(n),(R.uponSanitizeElement.length>0||R.uponSanitizeAttribute.length>0)&&(V=Of(V)),R.uponSanitizeAttribute.length>0&&(fe=Of(fe)),t.removed=[];let c=Ie&&typeof e!=`string`&&Lt(e),l=[],u=Le;if(c){At(e);let t=w(e);if(typeof t==`string`){let n=at(t);if(!V[n]||he[n])throw vt(e),Cf(`root node is forbidden and cannot be sanitized in-place`)}if(Ft(e))throw vt(e),Cf(`root node is clobbered and cannot be sanitized in-place`);l=Ct(e),Le=sf()}else if(Lt(e))i=jt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===ip.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),$t(i);else{if(!ke&&!Se&&!we&&e.indexOf(`<`)===-1)return D&&je?ee(e):e;if(i=jt(e),!i)return ke?null:je?O:``}i&&Oe&>(i.firstChild);let d=c?e:i;try{c&&$t(e);let t=Mt(d);for(;o=t.nextNode();)Wt(o,d),Zt(o,d),It(o.content)&&Qt(o.content);c&&Et(e,l)}catch(t){throw c&&(vt(e),Tt(e,l)),t}finally{Le=u}if(c){if(Tt(e,l))throw Cf(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return Se&&H(e),e}if(ke){if(Se&&H(i),Ae)for(s=I.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(fe.shadowroot||fe.shadowrootmode)&&(s=L.call(r,s,!0)),s}let f=we?i.outerHTML:i.innerHTML;return we&&V[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&Sf(Qf,i.ownerDocument.doctype.name)&&(f=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
832
|
+
`+f),Se&&(f=Nt(f)),D&&je?ee(f):f},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};lt(e),Te=!0,Ee=V,De=fe},t.clearConfig=function(){ot=null,Te=!1,Ee=null,De=null,D=k,O=``},t.isValidAttribute=function(e,t,n){ot||lt({});let r=at(e),i=at(t);return typeof n==`string`&&(Xt(t,n)||!xe&&Sf(rp,n))?!1:Gt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&bf(R,e)&&nf(R[e],t)},t.removeHook=function(e,t){if(bf(R,e)){if(t!==void 0){let n=ef(R[e],t);return n===-1?void 0:af(R[e],n,1)[0]}return tf(R[e])}},t.removeHooks=function(e){bf(R,e)&&(R[e]=[])},t.removeAllHooks=function(){R=cp()},t}var fp=dp(),pp=e=>{let t=Ge(e),n=t.sections.filter(e=>e.kind===`optionSet`),r=t.sections.flatMap(e=>{if(e.kind===`optionSet`)return[];if(e.kind!==`question`)return[e];let t=n.filter(t=>t.questionId===e.id),r=t.flatMap(e=>e.options).find(t=>t.id===e.recommendedOptionId),i=e.recommendedAnswer.trim(),a=r.label.trim(),o=i.toLowerCase().startsWith(a.toLowerCase())&&/^(?:$|[\s,:;.!?—–-])/.test(i.slice(a.length));return[{...e,recommendedAnswer:o?i:`${a} — ${i}`},...t]});return{...t,sections:r}};function mp(e){if(!w(e))return[];let t=Array.from(new TextEncoder().encode(e.ref),e=>e.toString(16).padStart(2,`0`)).join(``),n=new Set(e.sections.flatMap(e=>[e.id,...e.kind===`optionSet`?e.options.map(e=>e.id):[]]));return e.citations.map((r,i)=>{let a=`src-${t}-${i+1}`;for(;n.has(a);)a+=`-`;n.add(a);let o=e.sources.find(e=>e.id===r.sourceId),s=`path`in o.origin?`${o.origin.repo}@${o.origin.revision}:${o.origin.path}`:o.origin.uri,c=r.locator.kind===`lines`?`${s}:${r.locator.start}–${r.locator.end}`:`${s} · ${r.locator.caption}`;return{number:i+1,anchorId:a,citation:r,source:o,location:c}})}function hp(e){if(!w(e))return{sources:0,bytes:0,consultationMinutes:0};let t=e.sources.reduce((e,t)=>e+t.size,0),n=e.sources.filter(e=>!e.mediaType.startsWith(`image/`)).reduce((e,t)=>e+t.size,0)+e.annexes.reduce((e,t)=>e+new TextEncoder().encode(JSON.stringify(t.blocks)).length,0);return{sources:e.sources.length,bytes:t,consultationMinutes:Math.ceil(n/6/180)}}function gp(e){if(!w(e))return``;let t=hp(e),n=[`Evidence: ${t.sources} sources · ${t.bytes} bytes · estimated consultation ${t.consultationMinutes} min (6 bytes/word)`,`Raw supporting detail is separate from the primary reading budget.`];for(let t of e.sources)n.push(`Source ${t.id}: ${t.title} · ${t.mediaType} · ${t.size} bytes · SHA-256 ${t.sha256} · ${JSON.stringify(t.origin)}`);n.push(`Sources`);let r=mp(e),i=e=>e.map(e=>`[${r.find(t=>t.citation.id===e).number}]`).join(`, `);for(let{number:e,citation:t,source:i,location:a}of r)n.push(`[${e}] ${t.label} · ${i.title} · ${a}`);for(let t of e.sections)if(t.citationRefs?.length&&n.push(`${t.id} → ${i(t.citationRefs)}`),t.kind===`optionSet`)for(let e of t.options)e.citationRefs?.length&&n.push(`${e.id} → ${i(e.citationRefs)}`);for(let t of e.evidenceGroups)n.push(`${t.id}: ${t.summary} → ${[i(t.citationRefs),...t.sourceRefs.map(e=>`Source ${e}`)].filter(Boolean).join(`, `)}`);for(let t of e.annexes){n.push(`Annex ${t.id}: ${t.title} — ${t.summary} · ${t.blocks.length} support blocks · back: ${t.backRefs.join(`, `)}`);for(let e of t.blocks)e.kind===`references`&&n.push(`${t.id} → ${i(e.citationRefs)}`)}return n.push(`Full embedded evidence consultation/download requires the portable HTML renderer.`),n.join(`
|
|
833
|
+
`)}function _p(e,t){if(!C(e))return``;let n=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]),r=e=>e.replace(/\|/g,`\\|`).replace(/[\r\n]+/g,` `),i=e=>"`".repeat(Math.max(3,...Array.from(e.matchAll(/`+/g),e=>e[0].length+1)));return e.annexes.map(a=>{let o=a.blocks.map(a=>a.kind===`table`?t===`html`?`<table><thead><tr>${a.columns.map(e=>`<th>${n(e)}</th>`).join(``)}</tr></thead><tbody>${a.rows.map(e=>`<tr>${e.map(e=>`<td>${n(e)}</td>`).join(``)}</tr>`).join(``)}</tbody></table>`:[a.columns,a.columns.map(()=>`---`),...a.rows].map(e=>`| ${e.map(r).join(` | `)} |`).join(`
|
|
834
|
+
`):a.kind===`references`?a.citationRefs.map(r=>{let i=e.citations.find(e=>e.id===r).label;return t===`html`?`<p>${n(i)}</p>`:i}).join(`
|
|
835
|
+
`):t===`html`?a.kind===`code`?`<pre><code>${n(a.text)}</code></pre>`:`<p>${n(a.text)}</p>`:a.kind===`code`&&t===`markdown`?`${i(a.text)}\n${a.text}\n${i(a.text)}`:a.text).join(`
|
|
836
|
+
`);return t===`html`?`<section class="focus-annex"><h2>${n(a.title)}</h2><p>${n(a.summary)}</p>${o}</section>`:`## ${a.title}\n\n${a.summary}\n\n${o}`}).join(`
|
|
837
|
+
|
|
838
|
+
`)}var vp=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),yp=(e,t)=>{let n=[];if(e?.length){let t=e.map(e=>`<li><span class="focus-input-label">${vp(e.label??e.ref)}</span> <code>${vp(e.ref)}</code></li>`).join(``);n.push(`<ul class="focus-inputs">${t}</ul>`)}return t!==void 0&&n.push(`<p class="focus-completion-criterion">${vp(t)}</p>`),n.join(``)},bp=e=>{let t=[`<p class="focus-q"><strong>Q:</strong> ${vp(e.question)} <em>(${vp(e.state)})</em></p>`];e.context!==void 0&&t.push(`<p class="focus-context">${vp(e.context)}</p>`),e.readingTimeMinutes!==void 0&&t.push(`<p class="focus-reading-time">Reading time: ${e.readingTimeMinutes} min</p>`),e.recommendedAnswer!==void 0&&t.push(`<p class="focus-preco">préco: ${vp(e.recommendedAnswer)}</p>`),e.answer!==void 0&&t.push(`<p class="focus-answer">answer: ${vp(e.answer)}</p>`);let n=yp(e.inputs,e.completionCriterion);return n!==``&&t.push(n),`<section class="focus-question">${t.join(``)}</section>`},xp=e=>`<section class="focus-optionset">${e.title===void 0?`<h3>Options</h3>`:`<h3>Options — ${vp(e.title)}</h3>`}<ul>${e.options.map(e=>{let t=e.annotationComment===void 0?``:` <span class="focus-option-comment">— ${vp(e.annotationComment)}</span>`,n=e.body===void 0?``:`<div class="focus-option-body">${vp(e.body)}</div>`;return`<li class="focus-option" data-annotation="${vp(e.annotation)}"><strong>${vp(e.label)}</strong><p class="focus-consequence">${vp(e.consequence??``)}</p>${t}${n}</li>`}).join(``)}</ul></section>`,Sp=e=>e.length===0?`<section class="focus-amendment-trace"><h3>Amendment trace</h3><p><em>(none)</em></p></section>`:`<section class="focus-amendment-trace"><h3>Amendment trace</h3><ol>${e.map(e=>`<li><code>${vp(e.at)}</code> <strong>${vp(e.author)}</strong> — ${vp(e.summary)}</li>`).join(``)}</ol></section>`,Cp=e=>e.source===void 0?`<figure class="focus-diagram" data-render-component="${vp(e.renderComponent)}" data-source-ref="${vp(e.sourceRef)}"><figcaption>${vp(e.alt)}</figcaption><pre><code>${vp(e.renderComponent)}: ${vp(e.sourceRef)}</code></pre></figure>`:`<figure class="focus-diagram" data-syntax="${vp(e.syntax)}"><figcaption>${vp(e.alt)}</figcaption><pre><code class="language-${vp(e.syntax)}">${vp(e.source)}</code></pre></figure>`,wp=(e,t)=>{switch(e.kind){case`prose`:return`<section class="focus-prose">${t.renderMarkdown(e.markdown)}${yp(e.inputs,e.completionCriterion)}</section>`;case`question`:return bp(e);case`optionSet`:return xp(e);case`outcome`:return`<section class="focus-outcome" data-modality="${vp(e.modality)}"><h3>Outcome (${vp(e.modality)})</h3><p>${vp(e.statement)}</p></section>`;case`amendmentTrace`:return Sp(e.steps);case`diagram`:return Cp(e)}},Tp=e=>e.length===0?``:`<section class="focus-affordances"><h3>Affordances (read-only snapshot)</h3><ul>${e.map(e=>`<li class="focus-affordance" data-affordance="${vp(e.name)}" data-target="${vp(e.targetRef)}" aria-disabled="true"><del>${vp(e.label)}</del> <span class="focus-affordance-meta">${vp(e.name)} → ${vp(e.targetRef)} (disabled)</span></li>`).join(``)}</ul></section>`,Ep=(e,t)=>{e=pp(e);let n=e.readability,r=`<section class="focus-readability"><h2>Owner request</h2><blockquote>${vp(n.ownerRequestQuote)}</blockquote><h2>Stakes</h2><p>${vp(n.stakes)}</p><p>Reading budget: ${n.readingBudgetMinutes} min (${vp(n.stakesLevel)} stakes)</p>`+(n.glossary?.length?`<style>@media print { .focus-glossary { color: #000; background: #fff; } .focus-glossary::details-content { display: block; content-visibility: visible; } }</style><details class="focus-glossary"><summary>Glossary (${n.glossary.length} ${n.glossary.length===1?`term`:`terms`})</summary><dl>${n.glossary.map(e=>`<dt id="glossary-${vp(encodeURIComponent(e.term))}">${vp(e.term)}</dt><dd>${vp(e.definition)}</dd>`).join(``)}</dl></details>`:``)+`</section>`,i=`<header class="focus-header"><h1>${vp(e.title)}</h1><p class="focus-meta">subject: ${vp(e.subject)} · ref: <code>${vp(e.ref)}</code> · cursor: <code>${vp(e.cursor)}</code></p></header>`,a=mp(e),o=(e=[])=>e.map(e=>{let t=a.find(t=>t.citation.id===e);return t?`<sup><a class="focus-citation" href="#${t.anchorId}" aria-label="Source ${t.number}">[${t.number}]</a></sup>`:``}).join(``),s=e.sections.map(e=>wp(e,t)+o(e.citationRefs)+(e.kind===`optionSet`?e.options.map(e=>e.citationRefs?.length?`<p>${vp(e.label)} ${o(e.citationRefs)}</p>`:``).join(``):``)).join(``),c=new Set,l=a.length?`<section class="focus-sources" aria-label="Sources"><h2>Sources</h2><ol>${a.map(e=>{let t=!c.has(e.source.id);return c.add(e.source.id),`<li id="${e.anchorId}">${vp(e.citation.label)} · ${vp(e.source.title)} · ${vp(e.location)}`+(t?` · <a href="data:application/octet-stream;base64,${vp(e.source.data)}" download="evidence-${vp(e.source.id.replace(/[^a-zA-Z0-9._-]/g,`_`))}">Télécharger</a>`:``)+`</li>`}).join(``)}</ol></section>`:``,u=Sp(e.amendmentTrace),d=Tp(e.interactions),f=`<article class="focus-document" data-ref="${vp(e.ref)}">`+i+r+s+u+d+l+(gp(e)?`<section class="focus-evidence"><pre>${vp(gp(e))}</pre></section>`:``)+_p(e,`html`)+`</article>`;return t.sanitizeHtml(f)};function Dp(e,t){e.dataset.anchorId=t,e.dataset.commentable=``}function Op(e,t){let n=document.createElement(e);return n.textContent=t,e===`summary`&&n.setAttribute(`data-review-passthrough`,``),n}function kp(e,t){let n=document.createElement(`a`);return n.setAttribute(`href`,`#${encodeURIComponent(e)}`),n.setAttribute(`data-review-passthrough`,``),n.textContent=t,n}function Ap(e){return`uri`in e.origin?e.origin.uri:`${e.origin.repo}@${e.origin.revision}:${e.origin.path}`}function jp(e){let t=new Map(e?.citations.map((e,t)=>[e.id,t+1]));return(e,n)=>{if(!Array.isArray(e)||e.length===0)return;let r=document.createElement(n instanceof HTMLOListElement?`li`:`span`);r.className=`st-dossier__citations`;for(let n of e){let e=t.get(n);if(e===void 0)continue;let i=kp(n,`[${e}]`);i.setAttribute(`aria-label`,`Citation ${e}`),r.append(i)}r.hasChildNodes()&&n.append(r)}}function Mp(e,t){if(e.kind===`table`){let t=document.createElement(`table`),n=t.createTHead().insertRow();for(let t of e.columns){let e=Op(`th`,t);e.setAttribute(`scope`,`col`),n.append(e)}let r=t.createTBody();for(let t of e.rows){let e=r.insertRow();for(let n of t)e.insertCell().textContent=n}return t}if(e.kind===`references`){let n=document.createElement(`p`);return t(e.citationRefs,n),n}if(e.kind===`text`)return Op(`p`,e.text);let n=document.createElement(`pre`);return n.append(Op(`code`,e.text)),n}function Np(e,t){let n=document.createElement(`details`);if(Dp(n,e.id),n.append(Op(`summary`,e.title),Op(`p`,`${Ap(e)} · ${e.mediaType} · ${e.size} bytes · SHA-256 ${e.sha256}`)),!t){let t=document.createElement(`a`);t.setAttribute(`data-review-passthrough`,``),t.href=`data:application/octet-stream;base64,${e.data}`,t.download=`evidence-${e.id.replace(/[^a-zA-Z0-9._-]/g,`_`)}`,t.textContent=`Download source`,n.append(t)}if(e.mediaType===`image/png`||e.mediaType===`image/jpeg`){let t=document.createElement(`img`);t.src=`data:${e.mediaType};base64,${e.data}`,t.alt=e.alt??e.title,n.append(t)}else{let t=Uint8Array.from(atob(e.data),e=>e.charCodeAt(0));n.append(Op(`pre`,new TextDecoder().decode(t)))}return n}function Pp(e,t,n,r=!1){let i=document.createElement(`section`);i.className=`st-dossier__evidence`,i.append(Op(`h2`,r?`Embedded evidence`:`Evidence`));let a=new Map(t.sources.map(e=>[e.id,e])),o=new Set(r?t.citations.map(({sourceId:e})=>e):[]);if(a.size>0){r||i.append(Op(`h3`,`Sources`));for(let e of a.values())i.append(Np(e,o.has(e.id)))}if(!r&&t.citations.length>0){let e=document.createElement(`ol`);for(let n of t.citations){let t=Op(`li`,n.label);Dp(t,n.id);let r=a.get(n.sourceId),i=n.locator.kind===`image`?n.locator.caption:`lines ${n.locator.start}–${n.locator.end}`;r!==void 0&&t.append(` · `,kp(r.id,r.title)),t.append(` · ${i}`),e.append(t)}i.append(Op(`h3`,`Citations`),e)}for(let e of t.evidenceGroups){let t=Op(`p`,e.summary);Dp(t,e.id),n(e.citationRefs,t);for(let n of e.sourceRefs)t.append(` · `,kp(n,a.get(n)?.title??n));i.append(t)}let s=new Set(Array.from(e.querySelectorAll(`[data-anchor-id]`),e=>e.dataset.anchorId)),c=r&&C(t),l=new Map((c?t.citations:[]).map(({id:e,label:t})=>[e,t]));for(let e of t.annexes){let t=document.createElement(`details`);Dp(t,e.id);let r=document.createElement(`summary`);r.setAttribute(`data-review-passthrough`,``),c?r.append(Op(`h2`,e.title)):r.textContent=e.title,t.append(r,Op(`p`,e.summary));for(let r of e.blocks)if(c&&r.kind===`references`)for(let e of r.citationRefs){let n=document.createElement(`p`);n.append(kp(e,l.get(e))),t.append(n)}else t.append(Mp(r,n));if(e.backRefs.length>0){let n=Op(`p`,`Related blocks`);for(let t of e.backRefs)n.append(` · `,s.has(t)?kp(t,t):t);t.append(n)}i.append(t)}i.children.length>1&&e.append(i)}function Fp(e,t){return t||e<=2?`list`:`grid`}function W(e){return typeof e==`string`&&e.length>0?e:void 0}function Ip(e){let t=W(e.body);return t===void 0?[W(e.label)??``,W(e.consequence)??``].filter(e=>e.length>0).join(`
|
|
839
|
+
`):t}function Lp(e){return Ip(e).length>300}var Rp=[`p`,`ul`,`li`,`code`,`a`,`strong`,`em`],zp=[`table`,`thead`,`tbody`,`tr`,`th`,`td`],Bp=[`href`],Vp=/^https:\/\/[^\s"'<>]+$/i;function Hp(e,t=!1){return fp.sanitize(e,{ALLOWED_TAGS:t?[...Rp,...zp]:Rp,ALLOWED_ATTR:Bp,ALLOW_DATA_ATTR:!1,ALLOWED_URI_REGEXP:Vp})}function Up(e,t){let n=document.createElement(`div`);n.className=`st-dossier__prose`,n.innerHTML=Hp(Xe(e,t),t);for(let e of n.querySelectorAll(`a`))e.setAttribute(`data-review-passthrough`,``);return n}function Wp(e,t){if(Array.isArray(t.inputs)&&t.inputs.length>0){let n=document.createElement(`ul`);for(let e of t.inputs){let t=W(e.ref)??``,r=W(e.label)??t;n.append(Gp(`li`,`st-dossier__input`,r===t?t:`${r} (${t})`))}e.append(n)}let n=W(t.completionCriterion);n!==void 0&&e.append(Gp(`p`,`st-dossier__criterion`,n))}function Gp(e,t,n){let r=document.createElement(e);return t!==void 0&&(r.className=t),r.textContent=n,r}function Kp(e,t){if(e.append(Gp(`h3`,void 0,`Amendment trace`)),t.length===0){let t=document.createElement(`p`);t.append(Gp(`em`,void 0,`(none)`)),e.append(t);return}let n=document.createElement(`ol`);n.className=`st-dossier__trace`;for(let{at:e,author:r,summary:i}of t){let t=document.createElement(`li`);t.className=`st-dossier__traceStep`,t.setAttribute(`data-st-trace-step`,`${e} ${r}`.trim()),t.setAttribute(`data-st-trace-at`,e),t.append(Gp(`code`,void 0,e),` `,Gp(`strong`,void 0,r),` — ${i}`),n.append(t)}e.append(n)}function qp(e,t){return e.some(e=>typeof e==`object`&&!!e&&e.name===`choose-option`&&e.targetRef===t&&e.enabled===!1)}function Jp(e){let t=new Set;for(let n of e){if(typeof n!=`object`||!n)continue;let e=n;if(e.kind===`optionSet`&&Array.isArray(e.options))for(let n of e.options){if(typeof n!=`object`||!n)continue;let e=W(n.id);e!==void 0&&t.add(e)}}return t}function Yp(e){let t=new Map;for(let n of e){if(typeof n!=`object`||!n)continue;let e=n;if(e.kind!==`question`)continue;let r=W(e.id),i=W(e.recommendedOptionId);r!==void 0&&i!==void 0&&t.set(r,i)}return t}function Xp(e,t){let n=[];for(let r of e){if(typeof r!=`object`||!r)continue;let e=r;e.kind===`optionSet`&&W(e.questionId)===t&&n.push(e)}return n}function Zp(e,t){let n=W(e.recommendedAnswer);if(n===void 0)return;let r=n.trim(),i=W(e.id),a=W(e.recommendedOptionId);if(i===void 0||a===void 0)return r;let o=Xp(t,i).flatMap(e=>Array.isArray(e.options)?e.options:[]).find(e=>typeof e==`object`&&!!e&&W(e.id)===a),s=o===void 0?void 0:W(o.label);if(s===void 0)return r;let c=s.trim();return r.toLowerCase().startsWith(c.toLowerCase())&&/^(?:$|[\s,:;.!?—–-])/.test(r.slice(c.length))?r:`${c} — ${r}`}function Qp(e){if(e===void 0||e===`none`)return;let t=Gp(`span`,`st-dossier__optionAnnotation`,e);return t.setAttribute(`data-annotation`,e),t}function $p(e,t){let n=document.createElement(`div`);return n.className=`st-dossier__optionHead`,n.append(Gp(`span`,`st-dossier__optionLabel`,e)),t&&n.append(Gp(`span`,`st-dossier__badge`,`Recommended`)),n}function em(e,t){let n=W(e.id)??``,r=W(e.label)??``,i=W(e.consequence),a=W(e.annotationComment),o=W(e.body),s=Lp(e);if(t.disabled){let c=document.createElement(`div`);if(c.className=`st-dossier__optionCard st-dossier__optionCard--disabled`,c.setAttribute(`data-option-disabled`,n),c.setAttribute(`aria-disabled`,`true`),c.append($p(r,t.recommended)),s){if(o!==void 0){i!==void 0&&c.append(Gp(`span`,`st-dossier__optionConsequence`,i));let e=Gp(`span`,`st-dossier__optionBody`,o);e.id=`st-dossier-body-${n}`,e.setAttribute(`hidden`,``),c.append(e)}else{let t=Gp(`span`,`st-dossier__optionBody`,i??Ip(e));t.id=`st-dossier-body-${n}`,t.setAttribute(`hidden`,``),c.append(t)}}else i!==void 0&&c.append(Gp(`span`,`st-dossier__optionConsequence`,i)),o!==void 0&&c.append(Gp(`span`,`st-dossier__optionBody`,o));let l=Qp(W(e.annotation));return l!==void 0&&c.append(l),a!==void 0&&c.append(Gp(`span`,`st-dossier__optionAnnotationComment`,a)),c}let c=document.createElement(`div`);c.className=`st-dossier__optionCard`,c.setAttribute(`data-option-card`,n),c.setAttribute(`role`,`group`);let l=document.createElement(`button`);l.type=`button`,l.className=`st-dossier__optionSelect`,l.setAttribute(`data-option-id`,n),l.setAttribute(`aria-pressed`,t.selected?`true`:`false`),t.selected&&l.setAttribute(`data-st-selected`,`true`),l.append($p(r,t.recommended)),!(s&&o===void 0)&&i!==void 0&&l.append(Gp(`span`,`st-dossier__optionConsequence`,i));let u=Qp(W(e.annotation));if(u!==void 0&&l.append(u),a!==void 0&&l.append(Gp(`span`,`st-dossier__optionAnnotationComment`,a)),!s&&o!==void 0&&l.append(Gp(`span`,`st-dossier__optionBody`,o)),c.append(l),s){let r=document.createElement(`button`);r.type=`button`,r.className=`st-dossier__optionFold`,r.setAttribute(`data-option-fold`,n),r.setAttribute(`aria-expanded`,t.expanded?`true`:`false`),r.setAttribute(`aria-controls`,`st-dossier-body-${n}`),r.textContent=t.expanded?`Hide details`:`Show details`,c.append(r);let a=Gp(`span`,`st-dossier__optionBody`,o??i??Ip(e));a.id=`st-dossier-body-${n}`,t.expanded||a.setAttribute(`hidden`,``),c.append(a)}return c}function tm(e,t){let n=W(e.kind)??``;if(n===`prose`){let n=Up(W(e.markdown)??``,t.light);return Wp(n,e),n}if(n===`question`){let n=document.createElement(`div`);n.className=`st-dossier__question`,n.setAttribute(`data-st-question`,W(e.id)??``);let r=Gp(`h3`,`st-dossier__questionText`,W(e.question)??``);r.setAttribute(`data-st-question-text`,``),n.append(r);let i=W(e.state);if(i!==void 0){let e=Gp(`span`,`st-dossier__state`,i);e.setAttribute(`data-st-question-state`,i),n.append(e)}let a=W(e.context);a!==void 0&&n.append(Gp(`p`,`st-dossier__questionContext`,a));let o=e.readingTimeMinutes;typeof o==`number`&&n.append(Gp(`p`,`st-dossier__readingTime`,`Reading time: ${o} min`));let s=W(e.answer);s!==void 0&&n.append(Gp(`p`,`st-dossier__questionAnswer`,s));let c=W(e.recommendedAnswer);return c!==void 0&&n.append(Gp(`p`,`st-dossier__questionReco`,Zp(e,t.sections)??c)),Wp(n,e),n}if(n===`optionSet`){let n=document.createElement(`div`);n.className=`st-dossier__options`,n.setAttribute(`data-st-option-set`,W(e.id)??``);let r=(Array.isArray(e.options)?e.options:[]).filter(e=>typeof e==`object`&&!!e);n.setAttribute(`data-st-layout`,Fp(r.length,r.some(Lp)));let i=W(e.title);if(t.light){let t=typeof e.title==`string`?`Options — ${e.title}`:`Options`;n.append(Gp(`h3`,`st-dossier__optionsTitle`,t))}else i!==void 0&&n.append(Gp(`h4`,`st-dossier__optionsTitle`,i));let a=W(e.id)??``,o=W(e.questionId)??W(e.targetRef),s=o===void 0?void 0:t.recommended.get(o);for(let e of r){let r=W(e.id)??``,i=em(e,{disabled:qp(t.interactions,r),recommended:s!==void 0&&s===r,selected:t.selected.get(a)===r,expanded:t.expanded.has(r)});r!==``&&Dp(i,r),t.citationCalls(e.citationRefs,i),n.append(i)}return n}if(n===`outcome`){let n=document.createElement(`div`);n.className=`st-dossier__outcome`,n.setAttribute(`data-st-outcome`,W(e.id)??``);let r=W(e.modality);t.light&&r!==void 0&&n.append(Gp(`h3`,void 0,`Outcome (${r})`));let i=Gp(`p`,`st-dossier__outcomeText`,W(e.statement)??``);return i.setAttribute(`data-st-outcome-statement`,``),n.append(i),!t.light&&r!==void 0&&n.append(Gp(`span`,`st-dossier__modality`,r)),n}if(n===`amendmentTrace`){let n=Array.isArray(e.steps)?e.steps:[];if(t.light){let t=document.createElement(`section`);return t.setAttribute(`data-st-trace`,W(e.id)??``),Kp(t,n),t}let r=document.createElement(`ol`);r.className=`st-dossier__trace`,r.setAttribute(`data-st-trace`,W(e.id)??``);for(let e of n)if(typeof e==`object`&&e){let t=e,n=W(t.at)??``,i=W(t.author)??``,a=Gp(`li`,`st-dossier__traceStep`,W(t.summary)??``);a.setAttribute(`data-st-trace-step`,`${n} ${i}`.trim()),r.append(a)}return r}if(n===`diagram`){let n=document.createElement(`figure`);n.className=`st-dossier__diagram`,n.setAttribute(`data-st-diagram`,W(e.id)??``);let r=W(e.alt);r!==void 0&&n.append(Gp(`figcaption`,`st-dossier__diagramAlt`,r));let i=t.diagrams?.get(W(e.id)??``);if(i!==void 0)return n.append(i),n;let a=[W(e.renderComponent),W(e.sourceRef)].filter(Boolean).join(`: `),o=Gp(`pre`,`st-dossier__diagramSource`,W(e.source)??a);return o.setAttribute(`data-st-diagram-source`,``),n.append(o),n}return Gp(`div`,`st-dossier__unknownSection`,n)}function nm(e,t,n,r,i){let a=t??{},o=Array.isArray(a.sections)?a.sections:[],s=Array.isArray(a.interactions)?a.interactions:[],c=a.schemaVersion===2?t:void 0,l=jp(c),u=Yp(o),d=Jp(o),f=new Map,p=new Set,m=document.createElement(`article`);m.className=`st-dossier`,m.setAttribute(`data-st-dossier`,``);let h=document.createElement(`header`);h.className=`st-dossier__header`;let g=W(a.ref);g!==void 0&&Dp(h,g);let _=W(a.subject);_!==void 0&&h.append(Gp(`p`,`st-dossier__subject`,_)),h.append(Gp(r===`light`?`h1`:`h2`,`st-dossier__title`,W(a.title)??``)),h.setAttribute(`data-st-dossier-title`,``),m.append(h);let v=a.readability;if(r===`light`&&v!==void 0){let{ownerRequestQuote:e,stakes:t,readingBudgetMinutes:n,stakesLevel:r,glossary:i}=v,a=document.createElement(`section`);if(a.className=`st-dossier__readability`,e!==void 0&&a.append(Gp(`h2`,void 0,`Owner request`),Gp(`blockquote`,void 0,e)),t!==void 0&&a.append(Gp(`h2`,void 0,`Stakes`),Gp(`p`,void 0,t)),n!==void 0&&r!==void 0&&a.append(Gp(`p`,`st-dossier__readingTime`,`Reading budget: ${n} min (${r} stakes)`)),i?.length){let e=document.createElement(`details`),t=document.createElement(`dl`);for(let{term:e,definition:n}of i)t.append(Gp(`dt`,void 0,e),Gp(`dd`,void 0,n));let n=Gp(`summary`,void 0,`Glossary (${i.length} ${i.length===1?`term`:`terms`})`);n.setAttribute(`data-review-passthrough`,``),e.append(n,t),a.append(e)}a.hasChildNodes()&&m.append(a)}let y={interactions:s,recommended:u,knownOptions:d,selected:f,expanded:p,sections:o,light:r===`light`,citationCalls:l,diagrams:i};function b(e){let t=tm(e,y),n=W(e.id);return n!==void 0&&Dp(t,n),l(e.citationRefs,t),t}let x=new Set;for(let e of o){if(typeof e!=`object`||!e)continue;let t=e;if(t.kind!==`question`)continue;let n=W(t.id);n!==void 0&&x.add(n)}let S=[],C=new Set;for(let e of o){if(typeof e!=`object`||!e)continue;let t=e;if(t.kind===`optionSet`){let e=W(t.questionId);if(e!==void 0&&x.has(e))continue;let n=b(t);S.push(n),m.append(n)}else if(m.append(b(t)),t.kind===`question`){let e=W(t.id);if(e===void 0)continue;for(let t of Xp(o,e)){if(C.has(t))continue;C.add(t);let e=b(t);S.push(e),m.append(e)}}}let w=Array.isArray(a.amendmentTrace)?a.amendmentTrace:[];if(y.light||w.length>0){let e=document.createElement(`footer`);if(e.className=`st-dossier__traceFooter`,e.setAttribute(`data-st-trace-footer`,``),y.light)Kp(e,w);else for(let t of w)if(typeof t==`object`&&t){let n=t,r=Gp(`p`,`st-dossier__traceEntry`,W(n.summary)??``);r.setAttribute(`data-st-trace-at`,W(n.at)??``),e.append(r)}m.append(e)}let T=W((a.provenance??{}).source);if(T!==void 0){let e=Gp(`p`,`st-dossier__provenance`,T);e.setAttribute(`data-st-provenance`,T),m.append(e)}return c!==void 0&&Pp(m,c,l),rm(e,m,n,f,p)}function rm(e,t,n,r=new Map,i=new Set){let a=e=>{let t=e.getAttribute(`data-option-id`);if(t===null)return;let i=e.closest(`[data-st-option-set]`),a=i?.getAttribute(`data-st-option-set`)??``;if(r.get(a)===t){r.delete(a),e.removeAttribute(`data-st-selected`),e.setAttribute(`aria-pressed`,`false`);return}let o=i?.querySelector(`[data-st-selected="true"]`);o?.removeAttribute(`data-st-selected`),o?.setAttribute(`aria-pressed`,`false`),r.set(a,t),e.setAttribute(`data-st-selected`,`true`),e.setAttribute(`aria-pressed`,`true`),n(t)},o=t=>{let n=t.target;if(!(n instanceof Element)||n.closest(`[data-option-fold], a`)!==null)return;let r=n.closest(`[data-option-id]`);if(r!==null&&e.contains(r)&&r.closest(`[data-option-disabled]`)===null){a(r);return}let i=n.closest(`[data-option-card]`);if(i!==null&&e.contains(i)&&i.closest(`[data-option-disabled]`)===null){let e=i.querySelector(`[data-option-id]`);e!==null&&a(e)}},s=t=>{if(!(t instanceof KeyboardEvent)||t.key!==`Enter`&&t.key!==` `)return;let n=t.target;if(!(n instanceof Element)||n.closest(`[data-option-fold]`)!==null)return;let r=n.closest(`[data-option-id]`);r!==null&&e.contains(r)&&r.closest(`[data-option-disabled]`)===null&&(t.preventDefault(),a(r))},c=t=>{let n=t.target;if(!(n instanceof Element))return;let r=n.closest(`[data-option-fold]`);if(r===null||!e.contains(r))return;t.stopPropagation();let a=r.getAttribute(`data-option-fold`)??``,o=r.closest(`[data-option-card]`)?.querySelector(`.st-dossier__optionBody`)??void 0;i.has(a)?(i.delete(a),r.setAttribute(`aria-expanded`,`false`),r.textContent=`Show details`,o?.setAttribute(`hidden`,``)):(i.add(a),r.setAttribute(`aria-expanded`,`true`),r.textContent=`Hide details`,o?.removeAttribute(`hidden`))};e.addEventListener(`click`,o),e.addEventListener(`keydown`,s),e.addEventListener(`click`,c);let l=e.querySelector(`:scope > [data-st-dossier-review]`);if(l===null)e.replaceChildren(t);else{for(let t of Array.from(e.childNodes))t!==l&&t.remove();l.before(t)}function u(){e.removeEventListener(`click`,o),e.removeEventListener(`keydown`,s),e.removeEventListener(`click`,c),t.remove()}return{reviewRoot:t,destroy:u}}function im(e,t,n){let r=document.createElement(`template`);try{r.innerHTML=Ep(e,{renderMarkdown:t,sanitizeHtml:e=>e})}catch(e){if(e instanceof ye)return;throw e}let i=r.content.querySelector(`article`);i.classList.add(`st-dossier`),i.setAttribute(`data-st-dossier`,``);let a=i.querySelector(`header`);Dp(a,e.ref),a.classList.add(`st-dossier__header`),a.setAttribute(`data-st-dossier-title`,``),a.querySelector(`h1`).classList.add(`st-dossier__title`),a.querySelector(`p`).classList.add(`st-dossier__subject`),i.querySelector(`.focus-readability > style`)?.remove();let o=new Map;for(let t of e.sections){if(t.kind!==`optionSet`||t.questionId===void 0)continue;let e=o.get(t.questionId)??[];o.set(t.questionId,[...e,t])}let s=e.sections.flatMap(e=>e.kind===`optionSet`?[]:[e,...e.kind===`question`?o.get(e.id)??[]:[]]),c=i.querySelectorAll(`:scope > :is(.focus-prose, .focus-question, .focus-optionset, .focus-outcome, .focus-diagram, .focus-amendment-trace)`);if(c.length!==s.length+1)throw Error(`Unexpected Focus section count`);let l=new Set(e.interactions.filter(({name:e,enabled:t})=>e===`choose-option`&&!t).map(({targetRef:e})=>e)),u=new Set(e.sections.flatMap(e=>e.kind===`question`?[e.recommendedOptionId]:[]));for(let[e,t]of s.entries()){let r=c[e];for(Dp(r,t.id);r.nextElementSibling?.matches(`sup:has(> a.focus-citation)`);)r.append(r.nextElementSibling);if(t.kind===`diagram`&&(r.setAttribute(`data-st-diagram`,t.id),r.querySelector(`:scope > pre`).replaceWith(n.get(t.id))),t.kind!==`optionSet`)continue;r.setAttribute(`data-st-option-set`,t.id);let i=r.querySelectorAll(`:scope > ul > li`);if(i.length!==t.options.length)throw Error(`Unexpected Focus option count`);for(let[e,{id:n,annotation:a,citationRefs:o}]of t.options.entries()){let t=i[e],s=t.firstElementChild;Dp(t,n),s.classList.add(`st-dossier__optionLabel`);let c=Qp(a);if(c!==void 0&&t.querySelector(`:scope > .focus-consequence`).after(c),o?.length){let e=r.nextElementSibling;if(!e?.matches(`p:has(> sup > a.focus-citation)`))throw Error(`Missing Focus option citation calls`);t.append(...e.querySelectorAll(`:scope > sup`)),e.remove()}if(u.has(n)&&t.setAttribute(`data-st-recommended`,``),l.has(n)){t.setAttribute(`data-option-disabled`,n),t.setAttribute(`aria-disabled`,`true`);continue}t.setAttribute(`data-option-card`,n);let d=document.createElement(`button`);d.type=`button`,d.setAttribute(`data-option-id`,n),d.setAttribute(`aria-pressed`,`false`),s.before(d),d.append(s)}}if(w(e)){let t=new Map,n=new Map(e.sources.map(e=>[e.id,e])),r=i.querySelectorAll(`:scope > .focus-sources > ol > li`);if(r.length!==e.citations.length)throw Error(`Unexpected Focus citation count`);for(let[i,{id:a,label:o,sourceId:s,locator:c}]of e.citations.entries()){let e=r[i];t.set(`#${e.id}`,a),e.removeAttribute(`id`),Dp(e,a);let l=n.get(s),u=Ap(l),d=c.kind===`lines`?`${u}:${c.start}–${c.end}`:`${u} · ${c.caption}`,f=e.querySelector(`a[download]`);e.replaceChildren(`${o} · `,kp(s,l.title),` · ${d}`),f!==null&&e.append(` · `,f)}for(let e of i.querySelectorAll(`a.focus-citation`)){let n=t.get(e.getAttribute(`href`)??``);n!==void 0&&e.setAttribute(`href`,`#${encodeURIComponent(n)}`)}for(let e of i.querySelectorAll(`:scope > .focus-annex`))e.remove();Pp(i,e,jp(e),!0)}for(let e of i.querySelectorAll(`a, summary`))e.setAttribute(`data-review-passthrough`,``);return i}function am(e,t,n,r={}){let i={event:`intent`,name:t,target:n,context:r};e.dispatchEvent(new CustomEvent(`st-intent`,{detail:i,bubbles:!0,composed:!0}))}var om=Array.isArray,sm=Array.prototype.indexOf,cm=Array.prototype.includes,lm=Array.from,um=Object.defineProperty,dm=Object.getOwnPropertyDescriptor,fm=Object.getOwnPropertyDescriptors,pm=Object.prototype,mm=Array.prototype,hm=Object.getPrototypeOf,gm=Object.isExtensible;function _m(e){return typeof e==`function`}var vm=()=>{};function ym(e){for(var t=0;t<e.length;t++)e[t]()}function bm(){var e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function xm(e,t){if(Array.isArray(e))return e;if(t===void 0||!(Symbol.iterator in e))return Array.from(e);let n=[];for(let r of e)if(n.push(r),n.length===t)break;return n}var Sm=1<<24,Cm=1024,wm=2048,Tm=4096,Em=8192,Dm=16384,Om=32768,km=1<<25,Am=65536,jm=1<<19,Mm=1<<20,Nm=1<<25,Pm=65536,Fm=1<<21,Im=1<<22,Lm=1<<23,Rm=Symbol(`$state`),zm=Symbol(`legacy props`),Bm=Symbol(``),Vm=Symbol(`attributes`),Hm=Symbol(`class`),Um=Symbol(`style`),Wm=Symbol(`text`),Gm=Symbol(`form reset`),Km=new class extends Error{name=`StaleReactionError`;message="The reaction that called `getAbortSignal()` was re-run or destroyed"},qm=!!globalThis.document?.contentType&&globalThis.document.contentType.includes(`xml`);function Jm(){throw Error(`https://svelte.dev/e/async_derived_orphan`)}function Ym(e,t,n){throw Error(`https://svelte.dev/e/each_key_duplicate`)}function Xm(e){throw Error(`https://svelte.dev/e/effect_in_teardown`)}function Zm(){throw Error(`https://svelte.dev/e/effect_in_unowned_derived`)}function Qm(e){throw Error(`https://svelte.dev/e/effect_orphan`)}function $m(){throw Error(`https://svelte.dev/e/effect_update_depth_exceeded`)}function eh(e){throw Error(`https://svelte.dev/e/props_invalid_value`)}function th(){throw Error(`https://svelte.dev/e/state_descriptors_fixed`)}function nh(){throw Error(`https://svelte.dev/e/state_prototype_fixed`)}function rh(){throw Error(`https://svelte.dev/e/state_unsafe_mutation`)}function ih(){throw Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`)}var ah={},oh=Symbol(),sh=`http://www.w3.org/1999/xhtml`,ch=`http://www.w3.org/2000/svg`;function lh(){console.warn(`https://svelte.dev/e/derived_inert`)}function uh(e){console.warn(`https://svelte.dev/e/hydration_mismatch`)}function dh(){console.warn(`https://svelte.dev/e/select_multiple_invalid_value`)}function fh(){console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`)}var ph=!1;function mh(e){ph=e}var hh;function gh(e){if(e===null)throw uh(),ah;return hh=e}function _h(){return gh(Wg(hh))}function G(e){if(ph){if(Wg(hh)!==null)throw uh(),ah;hh=e}}function vh(e=1){if(ph){for(var t=e,n=hh;t--;)n=Wg(n);hh=n}}function yh(e=!0){for(var t=0,n=hh;;){if(n.nodeType===8){var r=n.data;if(r===`]`){if(t===0)return n;--t}else(r===`[`||r===`[!`||r[0]===`[`&&!isNaN(Number(r.slice(1))))&&(t+=1)}var i=Wg(n);e&&n.remove(),n=i}}function bh(e){if(!e||e.nodeType!==8)throw uh(),ah;return e.data}function xh(e){return e===this.v}function Sh(e,t){return e==e?e!==t||typeof e==`object`&&!!e||typeof e==`function`:t==t}function Ch(e){return!Sh(e,this.v)}var wh=null;function Th(e){wh=e}function Eh(e,t=!1,n){wh={p:wh,i:!1,c:null,e:null,s:e,x:null,r:F_,l:null}}function Dh(e){var t=wh,n=t.e;if(n!==null){t.e=null;for(var r of n)c_(r)}return e!==void 0&&(t.x=e),t.i=!0,wh=t.p,e??{}}function Oh(){return!0}var kh=[];function Ah(){var e=kh;kh=[],ym(e)}function jh(e){if(kh.length===0&&!qh){var t=kh;queueMicrotask(()=>{t===kh&&Ah()})}kh.push(e)}function Mh(){for(;kh.length>0;)Ah()}function Nh(e){var t=F_;if(t===null)return M_.f|=Lm,e;if(!(t.f&32768)&&!(t.f&4))throw e;Ph(e,t)}function Ph(e,t){for(;t!==null;){if(t.f&128){if(!(t.f&32768))throw e;try{t.b.error(e);return}catch(t){e=t}}t=t.parent}throw e}var Fh=~(wm|Tm|Cm);function Ih(e,t){e.f=e.f&Fh|t}function Lh(e){e.f&512||e.deps===null?Ih(e,Cm):Ih(e,Tm)}function Rh(e){if(e!==null)for(let t of e)t.f&2&&t.f&65536&&(t.f^=Pm,Rh(t.deps))}function zh(e,t,n){e.f&2048?t.add(e):e.f&4096&&n.add(e),Rh(e.deps),Ih(e,Cm)}var Bh=!1;function Vh(e){var t=Bh;try{return Bh=!1,[e(),Bh]}finally{Bh=t}}var Hh=null,Uh=null,Wh=null,Gh=null,Kh=null,qh=!1,Jh=!1,Yh=null,Xh=null,Zh=0,Qh=1,$h=class e{id=Qh++;#e=!1;linked=!0;#t=null;#n=null;async_deriveds=new Map;current=new Map;previous=new Map;unblocked=new Set;#r=new Set;#i=new Set;#a=new Set;#o=0;#s=new Map;#c=null;#l=[];#u=[];#d=new Set;#f=new Set;#p=new Map;#m=new Set;is_fork=!1;#h=!1;#g(){if(this.is_fork)return!0;for(let n of this.#s.keys()){for(var e=n,t=!1;e.parent!==null;){if(this.#p.has(e)){t=!0;break}e=e.parent}if(!t)return!0}return!1}skip_effect(e){this.#p.has(e)||this.#p.set(e,{d:[],m:[]}),this.#m.delete(e)}unskip_effect(e,t=e=>this.schedule(e)){var n=this.#p.get(e);if(n){this.#p.delete(e);for(var r of n.d)Ih(r,wm),t(r);for(r of n.m)Ih(r,Tm),t(r)}this.#m.add(e)}#_(){if(this.#e=!0,Zh++>1e3&&(this.#C(),tg()),!this.#g()){for(let e of this.#d)this.#f.delete(e),Ih(e,wm),this.schedule(e);for(let e of this.#f)Ih(e,Tm),this.schedule(e)}let t=this.#l;this.#l=[],this.apply();var n=Yh=[],r=[],i=Xh=[];for(let e of t)try{this.#v(e,n,r)}catch(t){throw og(e),t}if(Uh=null,i.length>0){var a=e.ensure();for(let e of i)a.schedule(e)}if(Yh=null,Xh=null,this.#g()){this.#x(r),this.#x(n);for(let[e,t]of this.#p)ag(e,t);i.length>0&&Uh.#_();return}let o=this.#y();if(o)o.#b(this);else{this.#d.clear(),this.#f.clear();for(let e of this.#r)e(this);this.#r.clear(),Wh=this,rg(r),rg(n),Wh=null,this.#c?.resolve();var s=Uh;if(this.linked&&this.#o===0&&this.#C(),this.#l.length>0){s===null&&(s=this,this.#S());let e=s;e.#l.push(...this.#l.filter(t=>!e.#l.includes(t)))}s!==null&&s.#_()}}#v(e,t,n){e.f^=Cm;for(var r=e.first;r!==null;){var i=r.f,a=!!(i&96);if(!(a&&i&1024||i&8192||this.#p.has(r))&&r.fn!==null){a?r.f^=Cm:i&4?t.push(r):J_(r)&&(i&16&&this.#f.add(r),$_(r));var o=r.first;if(o!==null){r=o;continue}}for(;r!==null;){var s=r.next;if(s!==null){r=s;break}r=r.parent}}}#y(){for(var e=this.#t;e!==null;){if(!e.is_fork){for(let[t,[,n]]of this.current)if(e.current.has(t)&&!n)return e}e=e.#t}return null}#b(e){for(let[t,n]of e.current)!this.previous.has(t)&&e.previous.has(t)&&this.previous.set(t,e.previous.get(t)),this.current.set(t,n);for(let[t,n]of e.async_deriveds){let e=this.async_deriveds.get(t);e&&n.promise.then(e.resolve)}let t=e=>{var n=e.reactions;if(n!==null)for(let e of n){var r=e.f;if(r&2)t(e);else{var i=e;r&4194320&&!this.async_deriveds.has(i)&&(this.#f.delete(i),Ih(i,wm),this.schedule(i))}}};for(let e of this.current.keys())t(e);this.oncommit(()=>e.discard()),e.#C(),Uh=this,this.#_()}#x(e){for(var t=0;t<e.length;t+=1)zh(e[t],this.#d,this.#f)}capture(e,t,n=!1){e.v!==oh&&!this.previous.has(e)&&this.previous.set(e,e.v),e.f&8388608||(this.current.set(e,[t,n]),Gh?.set(e,t)),this.is_fork||(e.v=t)}activate(){Uh=this}deactivate(){Uh=null,Gh=null}flush(){try{Jh=!0,Uh=this,this.#_()}finally{Zh=0,Kh=null,Yh=null,Xh=null,Jh=!1,Uh=null,Gh=null,Tg.clear()}}discard(){for(let e of this.#i)e(this);this.#i.clear(),this.#a.clear(),this.#C()}register_created_effect(e){this.#u.push(e)}increment(e,t){if(this.#o+=1,e){let e=this.#s.get(t)??0;this.#s.set(t,e+1)}}decrement(e,t){if(--this.#o,e){let e=this.#s.get(t)??0;e===1?this.#s.delete(t):this.#s.set(t,e-1)}this.#h||(this.#h=!0,jh(()=>{this.#h=!1,this.linked&&this.flush()}))}transfer_effects(e,t){for(let t of e)this.#d.add(t);for(let e of t)this.#f.add(e);e.clear(),t.clear()}oncommit(e){this.#r.add(e)}ondiscard(e){this.#i.add(e)}on_fork_commit(e){this.#a.add(e)}run_fork_commit_callbacks(){for(let e of this.#a)e(this);this.#a.clear()}settled(){return(this.#c??=bm()).promise}static ensure(){if(Uh===null){let t=Uh=new e;t.#S(),!Jh&&!qh&&jh(()=>{t.#e||t.flush()})}return Uh}apply(){Gh=null}schedule(e){if(Kh=e,e.b?.is_pending&&e.f&16777228&&!(e.f&32768))e.b.defer_effect(e);else{for(var t=e;t.parent!==null;){t=t.parent;var n=t.f;if(Yh!==null&&t===F_&&(M_===null||!(M_.f&2)))return;if(n&96){if(!(n&1024))return;t.f^=Cm}}this.#l.push(t)}}#S(){Hh===null?Hh=this:(Hh.#n=this,this.#t=Hh),Hh=this}#C(){var e=this.#t,t=this.#n;e===null||(e.#n=t),t===null?Hh=e:t.#t=e,this.linked=!1}};function eg(e){var t=qh;qh=!0;try{var n;for(e&&(Uh!==null&&!Uh.is_fork&&Uh.flush(),n=e());;){if(Mh(),Uh===null)return n;Uh.flush()}}finally{qh=t}}function tg(){try{$m()}catch(e){Ph(e,Kh)}}var ng=null;function rg(e){var t=e.length;if(t!==0){for(var n=0;n<t;){var r=e[n++];if(!(r.f&24576)&&J_(r)&&(ng=new Set,$_(r),r.deps===null&&r.first===null&&r.nodes===null&&r.teardown===null&&r.ac===null&&S_(r),ng?.size>0)){Tg.clear();for(let e of ng){if(e.f&24576)continue;let t=[e],n=e.parent;for(;n!==null;)ng.has(n)&&(ng.delete(n),t.push(n)),n=n.parent;for(let e=t.length-1;e>=0;e--){let n=t[e];n.f&24576||$_(n)}}ng.clear()}}ng=null}}function ig(e){Uh.schedule(e)}function ag(e,t){if(!(e.f&32&&e.f&1024)){e.f&2048?t.d.push(e):e.f&4096&&t.m.push(e),Ih(e,Cm);for(var n=e.first;n!==null;)ag(n,t),n=n.next}}function og(e){Ih(e,Cm);for(var t=e.first;t!==null;)og(t),t=t.next}function sg(e){let t=0,n=Dg(0),r;return()=>{a_()&&(X(n),f_(()=>(t===0&&(r=rv(()=>e(()=>Mg(n)))),t+=1,()=>{jh(()=>{--t,t===0&&(r?.(),r=void 0,Mg(n))})})))}}var cg=Am|jm;function lg(e,t,n,r){new ug(e,t,n,r)}var ug=class{parent;is_pending=!1;transform_error;#e;#t=ph?hh:null;#n;#r;#i;#a=null;#o=null;#s=null;#c=null;#l=0;#u=0;#d=!1;#f=new Set;#p=new Set;#m=null;#h=sg(()=>(this.#m=Dg(this.#l),()=>{this.#m=null}));constructor(e,t,n,r){this.#e=e,this.#n=t,this.#r=e=>{var t=F_;t.b=this,t.f|=128,n(e)},this.parent=F_.b,this.transform_error=r??this.parent?.transform_error??(e=>e),this.#i=m_(()=>{if(ph){let e=this.#t;_h();let t=e.data===`[!`;if(e.data.startsWith(`[?`)){let t=JSON.parse(e.data.slice(2));this.#_(t)}else t?this.#v():this.#g()}else this.#y()},cg),ph&&(this.#e=hh)}#g(){try{this.#a=g_(()=>this.#r(this.#e))}catch(e){this.error(e)}}#_(e){let t=this.#n.failed;t&&(this.#s=g_(()=>{t(this.#e,()=>e,()=>()=>{})}))}#v(){let e=this.#n.pending;e&&(this.is_pending=!0,this.#o=g_(()=>e(this.#e)),jh(()=>{var e=this.#c=document.createDocumentFragment(),t=Hg();e.append(t),this.#a=this.#x(()=>g_(()=>this.#r(t))),this.#u===0&&(this.#e.before(e),this.#c=null,C_(this.#o,()=>{this.#o=null}),this.#b(Uh))}))}#y(){try{if(this.is_pending=this.has_pending_snippet(),this.#u=0,this.#l=0,this.#a=g_(()=>{this.#r(this.#e)}),this.#u>0){var e=this.#c=document.createDocumentFragment();D_(this.#a,e);let t=this.#n.pending;this.#o=g_(()=>t(this.#e))}else this.#b(Uh)}catch(e){this.error(e)}}#b(e){this.is_pending=!1,e.transfer_effects(this.#f,this.#p)}defer_effect(e){zh(e,this.#f,this.#p)}is_rendered(){return!this.is_pending&&(!this.parent||this.parent.is_rendered())}has_pending_snippet(){return!!this.#n.pending}#x(e){var t=F_,n=M_,r=wh;I_(this.#i),P_(this.#i),Th(this.#i.ctx);try{return $h.ensure(),e()}catch(e){return Nh(e),null}finally{I_(t),P_(n),Th(r)}}#S(e,t){this.has_pending_snippet()?(this.#u+=e,this.#u===0&&(this.#b(t),this.#o&&C_(this.#o,()=>{this.#o=null}),this.#c&&=(this.#e.before(this.#c),null))):this.parent&&this.parent.#S(e,t)}update_pending_count(e,t){this.#S(e,t),this.#l+=e,!(!this.#m||this.#d)&&(this.#d=!0,jh(()=>{this.#d=!1,this.#m&&Ag(this.#m,this.#l)}))}get_effect_pending(){return this.#h(),X(this.#m)}error(e){if(!this.#n.onerror&&!this.#n.failed)throw e;Uh?.is_fork?(this.#a&&Uh.skip_effect(this.#a),this.#o&&Uh.skip_effect(this.#o),this.#s&&Uh.skip_effect(this.#s),Uh.on_fork_commit(()=>{this.#C(e)})):this.#C(e)}#C(e){this.#a&&=(b_(this.#a),null),this.#o&&=(b_(this.#o),null),this.#s&&=(b_(this.#s),null),ph&&(gh(this.#t),vh(),gh(yh()));var t=this.#n.onerror;let n=this.#n.failed;var r=!1,i=!1;let a=()=>{r?fh():(r=!0,i&&ih(),this.#s!==null&&C_(this.#s,()=>{this.#s=null}),this.#x(()=>{this.#y()}))},o=e=>{try{i=!0,t?.(e,a),i=!1}catch(e){Ph(e,this.#i&&this.#i.parent)}n&&(this.#s=this.#x(()=>{try{return g_(()=>{var t=F_;t.b=this,t.f|=128,n(this.#e,()=>e,()=>a)})}catch(e){return Ph(e,this.#i.parent),null}}))};jh(()=>{var t;try{t=this.transform_error(e)}catch(e){Ph(e,this.#i&&this.#i.parent);return}typeof t==`object`&&t&&typeof t.then==`function`?t.then(o,e=>Ph(e,this.#i&&this.#i.parent)):o(t)})}};function dg(e,t,n,r){let i=Oh()?hg:vg;var a=e.filter(e=>!e.settled);if(n.length===0&&a.length===0){r(t.map(i));return}var o=F_,s=fg(),c=a.length===1?a[0].promise:a.length>1?Promise.all(a.map(e=>e.promise)):null;function l(e){if(!(o.f&16384)){s();try{r(e)}catch(e){Ph(e,o)}pg()}}var u=mg();if(n.length===0){c.then(()=>l(t.map(i))).finally(u);return}function d(){Promise.all(n.map(e=>_g(e))).then(e=>l([...t.map(i),...e])).catch(e=>Ph(e,o)).finally(u)}c?c.then(()=>{s(),d(),pg()}):d()}function fg(){var e=F_,t=M_,n=wh,r=Uh;return function(i=!0){I_(e),P_(t),Th(n),i&&!(e.f&16384)&&(r?.activate(),r?.apply())}}function pg(e=!0){I_(null),P_(null),Th(null),e&&Uh?.deactivate()}function mg(){var e=F_,t=e.b,n=Uh,r=t.is_rendered();return t.update_pending_count(1,n),n.increment(r,e),()=>{t.update_pending_count(-1,n),n.decrement(r,e)}}function hg(e){var t=2|wm;return F_!==null&&(F_.f|=jm),{ctx:wh,deps:null,effects:null,equals:xh,f:t,fn:e,reactions:null,rv:0,v:oh,wv:0,parent:F_,ac:null}}var gg=Symbol(`obsolete`);function _g(e,t,n){let r=F_;r===null&&Jm();var i=void 0,a=Dg(oh),o=!M_,s=new Set;return d_(()=>{var t=F_,n=bm();i=n.promise;try{Promise.resolve(e()).then(n.resolve,e=>{e!==Km&&n.reject(e)}).finally(pg)}catch(e){n.reject(e),pg()}var c=Uh;if(o){if(t.f&32768)var l=mg();if(r.b.is_rendered())c.async_deriveds.get(t)?.reject(gg);else for(let e of s.values())e.reject(gg);s.add(n),c.async_deriveds.set(t,n)}let u=(e,t=void 0)=>{l?.(),s.delete(n),t!==gg&&(c.activate(),t?(a.f|=Lm,Ag(a,t)):(a.f&8388608&&(a.f^=Lm),Ag(a,e)),c.deactivate())};n.promise.then(u,e=>u(null,e||`unknown`))}),o_(()=>{for(let e of s)e.reject(gg)}),new Promise(e=>{function t(n){function r(){n===i?e(a):t(i)}n.then(r,r)}t(i)})}function K(e){let t=hg(e);return R_(t),t}function vg(e){let t=hg(e);return t.equals=Ch,t}function yg(e){var t=e.effects;if(t!==null){e.effects=null;for(var n=0;n<t.length;n+=1)b_(t[n])}}function bg(e){var t,n=F_,r=e.parent;if(!A_&&r!==null&&r.f&24576)return lh(),e.v;I_(r);try{e.f&=~Pm,yg(e),t=X_(e)}finally{I_(n)}return t}function xg(e){var t=bg(e);!e.equals(t)&&(e.wv=q_(),(!Uh?.is_fork||e.deps===null)&&(Uh===null?e.v=t:(Uh.capture(e,t,!0),Wh?.capture(e,t,!0)),e.deps===null))?Ih(e,Cm):A_||(Gh===null?Lh(e):(a_()||Uh?.is_fork)&&Gh.set(e,t))}function Sg(e){if(e.effects!==null)for(let t of e.effects)(t.teardown||t.ac)&&(t.teardown?.(),t.ac?.abort(Km),t.teardown=vm,t.ac=null,Q_(t,0),v_(t))}function Cg(e){if(e.effects!==null)for(let t of e.effects)t.teardown&&$_(t)}var wg=new Set,Tg=new Map,Eg=!1;function Dg(e,t){return{f:0,v:e,reactions:null,equals:xh,rv:0,wv:0}}function Og(e,t){let n=Dg(e,t);return R_(n),n}function kg(e,t=!1,n=!0){let r=Dg(e);return t||(r.equals=Ch),r}function q(e,t,n=!1){return M_!==null&&(!N_||M_.f&131072)&&Oh()&&M_.f&4325394&&(L_===null||!cm.call(L_,e))&&rh(),Ag(e,n?Pg(t):t,Xh)}function Ag(e,t,n=null){if(!e.equals(t)){Tg.set(e,A_?t:e.v);var r=$h.ensure();if(r.capture(e,t),e.f&2){let t=e;e.f&2048&&bg(t),Gh===null&&Lh(t)}e.wv=q_(),Ng(e,wm,n),Oh()&&F_!==null&&F_.f&1024&&!(F_.f&96)&&(V_===null?H_([e]):V_.push(e)),!r.is_fork&&wg.size>0&&!Eg&&jg()}return t}function jg(){Eg=!1;for(let e of wg){e.f&1024&&Ih(e,Tm);let t;try{t=J_(e)}catch{t=!0}t&&$_(e)}wg.clear()}function Mg(e){q(e,e.v+1)}function Ng(e,t,n){var r=e.reactions;if(r!==null)for(var i=Oh(),a=r.length,o=0;o<a;o++){var s=r[o],c=s.f;if(i||s!==F_){var l=(c&wm)===0;if(l&&Ih(s,t),c&131072)wg.add(s);else if(c&2){var u=s;Gh?.delete(u),c&65536||(c&512&&(F_===null||!(F_.f&2097152))&&(s.f|=Pm),Ng(u,Tm,n))}else if(l){var d=s;c&16&&ng!==null&&ng.add(d),n===null?ig(d):n.push(d)}}}}function Pg(e){if(typeof e!=`object`||!e||Rm in e)return e;let t=hm(e);if(t!==pm&&t!==mm)return e;var n=new Map,r=om(e),i=Og(0),a=null,o=G_,s=e=>{if(G_===o)return e();var t=M_,n=G_;P_(null),K_(o);var r=e();return P_(t),K_(n),r};return r&&n.set(`length`,Og(e.length,a)),new Proxy(e,{defineProperty(e,t,r){(!(`value`in r)||r.configurable===!1||r.enumerable===!1||r.writable===!1)&&th();var i=n.get(t);return i===void 0?s(()=>{var e=Og(r.value,a);return n.set(t,e),e}):q(i,r.value,!0),!0},deleteProperty(e,t){var r=n.get(t);if(r===void 0){if(t in e){let e=s(()=>Og(oh,a));n.set(t,e),Mg(i)}}else q(r,oh),Mg(i);return!0},get(t,r,i){if(r===Rm)return e;var o=n.get(r),c=r in t;if(o===void 0&&(!c||dm(t,r)?.writable)&&(o=s(()=>Og(Pg(c?t[r]:oh),a)),n.set(r,o)),o!==void 0){var l=X(o);return l===oh?void 0:l}return Reflect.get(t,r,i)},getOwnPropertyDescriptor(e,t){var r=Reflect.getOwnPropertyDescriptor(e,t);if(r&&`value`in r){var i=n.get(t);i&&(r.value=X(i))}else if(r===void 0){var a=n.get(t),o=a?.v;if(a!==void 0&&o!==oh)return{enumerable:!0,configurable:!0,value:o,writable:!0}}return r},has(e,t){if(t===Rm)return!0;var r=n.get(t),i=r!==void 0&&r.v!==oh||Reflect.has(e,t);return(r!==void 0||F_!==null&&(!i||dm(e,t)?.writable))&&(r===void 0&&(r=s(()=>Og(i?Pg(e[t]):oh,a)),n.set(t,r)),X(r)===oh)?!1:i},set(e,t,o,c){var l=n.get(t),u=t in e;if(r&&t===`length`)for(var d=o;d<l.v;d+=1){var f=n.get(d+``);f===void 0?d in e&&(f=s(()=>Og(oh,a)),n.set(d+``,f)):q(f,oh)}if(l===void 0)(!u||dm(e,t)?.writable)&&(l=s(()=>Og(void 0,a)),q(l,Pg(o)),n.set(t,l));else{u=l.v!==oh;var p=s(()=>Pg(o));q(l,p)}var m=Reflect.getOwnPropertyDescriptor(e,t);if(m?.set&&m.set.call(c,o),!u){if(r&&typeof t==`string`){var h=n.get(`length`),g=Number(t);Number.isInteger(g)&&g>=h.v&&q(h,g+1)}Mg(i)}return!0},ownKeys(e){X(i);var t=Reflect.ownKeys(e).filter(e=>{var t=n.get(e);return t===void 0||t.v!==oh});for(var[r,a]of n)a.v!==oh&&!(r in e)&&t.push(r);return t},setPrototypeOf(){nh()}})}function Fg(e){try{if(typeof e==`object`&&e&&Rm in e)return e[Rm]}catch{}return e}function Ig(e,t){return Object.is(Fg(e),Fg(t))}var Lg,Rg,zg,Bg;function Vg(){if(Lg===void 0){Lg=window,Rg=/Firefox/.test(navigator.userAgent);var e=Element.prototype,t=Node.prototype,n=Text.prototype;zg=dm(t,`firstChild`).get,Bg=dm(t,`nextSibling`).get,gm(e)&&(e[Hm]=void 0,e[Vm]=null,e[Um]=void 0,e.__e=void 0),gm(n)&&(n[Wm]=void 0)}}function Hg(e=``){return document.createTextNode(e)}function Ug(e){return zg.call(e)}function Wg(e){return Bg.call(e)}function J(e,t){if(!ph)return Ug(e);var n=Ug(hh);if(n===null)n=hh.appendChild(Hg());else if(t&&n.nodeType!==3){var r=Hg();return n?.before(r),gh(r),r}return t&&Yg(n),gh(n),n}function Gg(e,t=!1){if(!ph){var n=Ug(e);return n instanceof Comment&&n.data===``?Wg(n):n}if(t){if(hh?.nodeType!==3){var r=Hg();return hh?.before(r),gh(r),r}Yg(hh)}return hh}function Y(e,t=1,n=!1){let r=ph?hh:e;for(var i;t--;)i=r,r=Wg(r);if(!ph)return r;if(n){if(r?.nodeType!==3){var a=Hg();return r===null?i?.after(a):r.before(a),gh(a),a}Yg(r)}return gh(r),r}function Kg(e){e.textContent=``}function qg(){return!1}function Jg(e,t,n){let r=n?{is:n}:void 0;return document.createElementNS(t??`http://www.w3.org/1999/xhtml`,e,r)}function Yg(e){if(e.nodeValue.length<65536)return;let t=e.nextSibling;for(;t!==null&&t.nodeType===3;)t.remove(),e.nodeValue+=t.nodeValue,t=e.nextSibling}function Xg(e,t){if(t){let t=document.body;e.autofocus=!0,jh(()=>{document.activeElement===t&&e.focus()})}}function Zg(e){ph&&Ug(e)!==null&&Kg(e)}var Qg=!1;function $g(){Qg||(Qg=!0,document.addEventListener(`reset`,e=>{Promise.resolve().then(()=>{if(!e.defaultPrevented)for(let t of e.target.elements)t[Gm]?.()})},{capture:!0}))}function e_(e){var t=M_,n=F_;P_(null),I_(null);try{return e()}finally{P_(t),I_(n)}}function t_(e,t,n,r=n){e.addEventListener(t,()=>e_(n));let i=e[Gm];e[Gm]=i?()=>{i(),r(!0)}:()=>r(!0),$g()}function n_(e){F_===null&&(M_===null&&Qm(e),Zm()),A_&&Xm(e)}function r_(e,t){var n=t.last;n===null?t.last=t.first=e:(n.next=e,e.prev=n,t.last=e)}function i_(e,t){var n=F_;n!==null&&n.f&8192&&(e|=Em);var r={ctx:wh,deps:null,nodes:null,f:e|wm|512,first:null,fn:t,last:null,next:null,parent:n,b:n&&n.b,prev:null,teardown:null,wv:0,ac:null};Uh?.register_created_effect(r);var i=r;if(e&4)Yh===null?$h.ensure().schedule(r):Yh.push(r);else if(t!==null){try{$_(r)}catch(e){throw b_(r),e}i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&!(i.f&524288)&&(i=i.first,e&16&&e&65536&&i!==null&&(i.f|=Am))}if(i!==null&&(i.parent=n,n!==null&&r_(i,n),M_!==null&&M_.f&2&&!(e&64))){var a=M_;(a.effects??=[]).push(i)}return r}function a_(){return M_!==null&&!N_}function o_(e){let t=i_(8,null);return Ih(t,Cm),t.teardown=e,t}function s_(e){n_(`$effect`);var t=F_.f;if(!M_&&t&32&&!(t&32768)){var n=wh;(n.e??=[]).push(e)}else return c_(e)}function c_(e){return i_(4|Mm,e)}function l_(e){$h.ensure();let t=i_(64|jm,e);return(e={})=>new Promise(n=>{e.outro?C_(t,()=>{b_(t),n(void 0)}):(b_(t),n(void 0))})}function u_(e){return i_(4,e)}function d_(e){return i_(Im|jm,e)}function f_(e,t=0){return i_(8|t,e)}function p_(e,t=[],n=[],r=[]){dg(r,t,n,t=>{i_(8,()=>e(...t.map(X)))})}function m_(e,t=0){return i_(16|t,e)}function h_(e,t=0){return i_(Sm|t,e)}function g_(e){return i_(32|jm,e)}function __(e){var t=e.teardown;if(t!==null){let e=A_,n=M_;j_(!0),P_(null);try{t.call(null)}finally{j_(e),P_(n)}}}function v_(e,t=!1){var n=e.first;for(e.first=e.last=null;n!==null;){let e=n.ac;e!==null&&e_(()=>{e.abort(Km)});var r=n.next;n.f&64?n.parent=null:b_(n,t),n=r}}function y_(e){for(var t=e.first;t!==null;){var n=t.next;t.f&32||b_(t),t=n}}function b_(e,t=!0){var n=!1;(t||e.f&262144)&&e.nodes!==null&&e.nodes.end!==null&&(x_(e.nodes.start,e.nodes.end),n=!0),Ih(e,km),v_(e,t&&!n),Q_(e,0);var r=e.nodes&&e.nodes.t;if(r!==null)for(let e of r)e.stop();__(e),e.f^=km,e.f|=Dm;var i=e.parent;i!==null&&i.first!==null&&S_(e),e.next=e.prev=e.teardown=e.ctx=e.deps=e.fn=e.nodes=e.ac=e.b=null}function x_(e,t){for(;e!==null;){var n=e===t?null:Wg(e);e.remove(),e=n}}function S_(e){var t=e.parent,n=e.prev,r=e.next;n!==null&&(n.next=r),r!==null&&(r.prev=n),t!==null&&(t.first===e&&(t.first=r),t.last===e&&(t.last=n))}function C_(e,t,n=!0){var r=[];w_(e,r,!0);var i=()=>{n&&b_(e),t&&t()},a=r.length;if(a>0){var o=()=>--a||i();for(var s of r)s.out(o)}else i()}function w_(e,t,n){if(!(e.f&8192)){e.f^=Em;var r=e.nodes&&e.nodes.t;if(r!==null)for(let e of r)(e.is_global||n)&&t.push(e);for(var i=e.first;i!==null;){var a=i.next;if(!(i.f&64)){var o=!!(i.f&65536)||!!(i.f&32)&&!!(e.f&16);w_(i,t,o?n:!1)}i=a}}}function T_(e){E_(e,!0)}function E_(e,t){if(e.f&8192){e.f^=Em,e.f&1024||(Ih(e,wm),$h.ensure().schedule(e));for(var n=e.first;n!==null;){var r=n.next,i=!!(n.f&65536)||!!(n.f&32);E_(n,i?t:!1),n=r}var a=e.nodes&&e.nodes.t;if(a!==null)for(let e of a)(e.is_global||t)&&e.in()}}function D_(e,t){if(e.nodes)for(var n=e.nodes.start,r=e.nodes.end;n!==null;){var i=n===r?null:Wg(n);t.append(n),n=i}}var O_=null,k_=!1,A_=!1;function j_(e){A_=e}var M_=null,N_=!1;function P_(e){M_=e}var F_=null;function I_(e){F_=e}var L_=null;function R_(e){M_!==null&&(L_===null?L_=[e]:L_.push(e))}var z_=null,B_=0,V_=null;function H_(e){V_=e}var U_=1,W_=0,G_=W_;function K_(e){G_=e}function q_(){return++U_}function J_(e){var t=e.f;if(t&2048)return!0;if(t&2&&(e.f&=~Pm),t&4096){for(var n=e.deps,r=n.length,i=0;i<r;i++){var a=n[i];if(J_(a)&&xg(a),a.wv>e.wv)return!0}t&512&&Gh===null&&Ih(e,Cm)}return!1}function Y_(e,t,n=!0){var r=e.reactions;if(r!==null&&!(L_!==null&&cm.call(L_,e)))for(var i=0;i<r.length;i++){var a=r[i];a.f&2?Y_(a,t,!1):t===a&&(n?Ih(a,wm):a.f&1024&&Ih(a,Tm),ig(a))}}function X_(e){var t=z_,n=B_,r=V_,i=M_,a=L_,o=wh,s=N_,c=G_,l=e.f;z_=null,B_=0,V_=null,M_=l&96?null:e,L_=null,Th(e.ctx),N_=!1,G_=++W_,e.ac!==null&&(e_(()=>{e.ac.abort(Km)}),e.ac=null);try{e.f|=Fm;var u=e.fn,d=u();e.f|=Om;var f=e.deps,p=Uh?.is_fork;if(z_!==null){var m;if(p||Q_(e,B_),f!==null&&B_>0)for(f.length=B_+z_.length,m=0;m<z_.length;m++)f[B_+m]=z_[m];else e.deps=f=z_;if(a_()&&e.f&512)for(m=B_;m<f.length;m++)(f[m].reactions??=[]).push(e)}else!p&&f!==null&&B_<f.length&&(Q_(e,B_),f.length=B_);if(Oh()&&V_!==null&&!N_&&f!==null&&!(e.f&6146))for(m=0;m<V_.length;m++)Y_(V_[m],e);if(i!==null&&i!==e){if(W_++,i.deps!==null)for(let e=0;e<n;e+=1)i.deps[e].rv=W_;if(t!==null)for(let e of t)e.rv=W_;V_!==null&&(r===null?r=V_:r.push(...V_))}return e.f&8388608&&(e.f^=Lm),d}catch(e){return Nh(e)}finally{e.f^=Fm,z_=t,B_=n,V_=r,M_=i,L_=a,Th(o),N_=s,G_=c}}function Z_(e,t){let n=t.reactions;if(n!==null){var r=sm.call(n,e);if(r!==-1){var i=n.length-1;i===0?n=t.reactions=null:(n[r]=n[i],n.pop())}}if(n===null&&t.f&2&&(z_===null||!cm.call(z_,t))){var a=t;a.f&512&&(a.f^=512,a.f&=~Pm),a.v!==oh&&Lh(a),Sg(a),Q_(a,0)}}function Q_(e,t){var n=e.deps;if(n!==null)for(var r=t;r<n.length;r++)Z_(e,n[r])}function $_(e){var t=e.f;if(!(t&16384)){Ih(e,Cm);var n=F_,r=k_;F_=e,k_=!0;try{t&16777232?y_(e):v_(e),__(e);var i=X_(e);e.teardown=typeof i==`function`?i:null,e.wv=U_}finally{k_=r,F_=n}}}async function ev(){await Promise.resolve(),eg()}function X(e){var t=!!(e.f&2);if(O_?.add(e),M_!==null&&!N_&&!(F_!==null&&F_.f&16384)&&(L_===null||!cm.call(L_,e))){var n=M_.deps;if(M_.f&2097152)e.rv<W_&&(e.rv=W_,z_===null&&n!==null&&n[B_]===e?B_++:z_===null?z_=[e]:z_.push(e));else{(M_.deps??=[]).push(e);var r=e.reactions;r===null?e.reactions=[M_]:cm.call(r,M_)||r.push(M_)}}if(A_&&Tg.has(e))return Tg.get(e);if(t){var i=e;if(A_){var a=i.v;return(!(i.f&1024)&&i.reactions!==null||nv(i))&&(a=bg(i)),Tg.set(i,a),a}var o=!(i.f&512)&&!N_&&M_!==null&&(k_||!!(M_.f&512)),s=(i.f&Om)===0;J_(i)&&(o&&(i.f|=512),xg(i)),o&&!s&&(Cg(i),tv(i))}if(Gh?.has(e))return Gh.get(e);if(e.f&8388608)throw e.v;return e.v}function tv(e){if(e.f|=512,e.deps!==null)for(let t of e.deps)(t.reactions??=[]).push(e),t.f&2&&!(t.f&512)&&(Cg(t),tv(t))}function nv(e){if(e.v===oh)return!0;if(e.deps===null)return!1;for(let t of e.deps)if(Tg.has(t)||t.f&2&&nv(t))return!0;return!1}function rv(e){var t=N_;try{return N_=!0,e()}finally{N_=t}}function iv(e){return e.endsWith(`capture`)&&e!==`gotpointercapture`&&e!==`lostpointercapture`}var av=[`beforeinput`,`click`,`change`,`dblclick`,`contextmenu`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mousemove`,`mouseout`,`mouseover`,`mouseup`,`pointerdown`,`pointermove`,`pointerout`,`pointerover`,`pointerup`,`touchend`,`touchmove`,`touchstart`];function ov(e){return av.includes(e)}var sv=`allowfullscreen.async.autofocus.autoplay.checked.controls.default.disabled.formnovalidate.indeterminate.inert.ismap.loop.multiple.muted.nomodule.novalidate.open.playsinline.readonly.required.reversed.seamless.selected.webkitdirectory.defer.disablepictureinpicture.disableremoteplayback`.split(`.`),cv={formnovalidate:`formNoValidate`,ismap:`isMap`,nomodule:`noModule`,playsinline:`playsInline`,readonly:`readOnly`,defaultvalue:`defaultValue`,defaultchecked:`defaultChecked`,srcobject:`srcObject`,novalidate:`noValidate`,allowfullscreen:`allowFullscreen`,disablepictureinpicture:`disablePictureInPicture`,disableremoteplayback:`disableRemotePlayback`};function lv(e){return e=e.toLowerCase(),cv[e]??e}[...sv];var uv=[`touchstart`,`touchmove`];function dv(e){return uv.includes(e)}var fv=[`textarea`,`script`,`style`,`title`];function pv(e){return fv.includes(e)}var mv=Symbol(`events`),hv=new Set,gv=new Set;function _v(e,t,n,r={}){function i(e){if(r.capture||Sv.call(t,e),!e.cancelBubble)return e_(()=>n?.call(this,e))}return e.startsWith(`pointer`)||e.startsWith(`touch`)||e===`wheel`?jh(()=>{t.addEventListener(e,i,r)}):t.addEventListener(e,i,r),i}function vv(e,t,n,r,i){var a={capture:r,passive:i},o=_v(e,t,n,a);(t===document.body||t===window||t===document||t instanceof HTMLMediaElement)&&o_(()=>{t.removeEventListener(e,o,a)})}function yv(e,t,n){(t[mv]??={})[e]=n}function bv(e){for(var t=0;t<e.length;t++)hv.add(e[t]);for(var n of gv)n(e)}var xv=null;function Sv(e){var t=this,n=t.ownerDocument,r=e.type,i=e.composedPath?.()||[],a=i[0]||e.target;xv=e;var o=0,s=xv===e&&e[mv];if(s){var c=i.indexOf(s);if(c!==-1&&(t===document||t===window)){e[mv]=t;return}var l=i.indexOf(t);if(l===-1)return;c<=l&&(o=c)}if(a=i[o]||e.target,a!==t){um(e,`currentTarget`,{configurable:!0,get(){return a||n}});var u=M_,d=F_;P_(null),I_(null);try{for(var f,p=[];a!==null;){var m=a.assignedSlot||a.parentNode||a.host||null;try{var h=a[mv]?.[r];h!=null&&(!a.disabled||e.target===a)&&h.call(a,e)}catch(e){f?p.push(e):f=e}if(e.cancelBubble||m===t||m===null)break;a=m}if(f){for(let e of p)queueMicrotask(()=>{throw e});throw f}}finally{e[mv]=t,delete e.currentTarget,P_(u),I_(d)}}}var Cv=globalThis?.window?.trustedTypes&&globalThis.window.trustedTypes.createPolicy(`svelte-trusted-html`,{createHTML:e=>e});function wv(e){return Cv?.createHTML(e)??e}function Tv(e){var t=Jg(`template`);return t.innerHTML=wv(e.replaceAll(`<!>`,`<!---->`)),t.content}function Ev(e,t){var n=F_;n.nodes===null&&(n.nodes={start:e,end:t,a:null,t:null})}function Z(e,t){var n=!!(t&1),r=!!(t&2),i,a=!e.startsWith(`<!>`);return()=>{if(ph)return Ev(hh,null),hh;i===void 0&&(i=Tv(a?e:`<!>`+e),n||(i=Ug(i)));var t=r||Rg?document.importNode(i,!0):i.cloneNode(!0);if(n){var o=Ug(t),s=t.lastChild;Ev(o,s)}else Ev(t,t);return t}}function Dv(e,t,n=`svg`){var r=!e.startsWith(`<!>`),i=!!(t&1),a=`<${n}>${r?e:`<!>`+e}</${n}>`,o;return()=>{if(ph)return Ev(hh,null),hh;if(!o){var e=Ug(Tv(a));if(i)for(o=document.createDocumentFragment();Ug(e);)o.appendChild(Ug(e));else o=Ug(e)}var t=o.cloneNode(!0);if(i){var n=Ug(t),r=t.lastChild;Ev(n,r)}else Ev(t,t);return t}}function Ov(e,t){return Dv(e,t,`svg`)}function kv(e=``){if(!ph){var t=Hg(e+``);return Ev(t,t),t}var n=hh;return n.nodeType===3?Yg(n):(n.before(n=Hg()),gh(n)),Ev(n,n),n}function Av(){if(ph)return Ev(hh,null),hh;var e=document.createDocumentFragment(),t=document.createComment(``),n=Hg();return e.append(t,n),Ev(t,n),e}function Q(e,t){if(ph){var n=F_;(!(n.f&32768)||n.nodes.end===null)&&(n.nodes.end=hh),_h()}else e!==null&&e.before(t)}function jv(){if(ph&&hh&&hh.nodeType===8&&hh.textContent?.startsWith(`$`)){let e=hh.textContent.substring(1);return _h(),e}return(window.__svelte??={}).uid??=1,`c${window.__svelte.uid++}`}function Mv(e,t){var n=t==null?``:typeof t==`object`?`${t}`:t;n!==(e[Wm]??=e.nodeValue)&&(e[Wm]=n,e.nodeValue=`${n}`)}function Nv(e,t){return Fv(e,t)}var Pv=new Map;function Fv(e,{target:t,anchor:n,props:r={},events:i,context:a,intro:o=!0,transformError:s}){Vg();var c=void 0,l=l_(()=>{var o=n??t.appendChild(Hg());lg(o,{pending:()=>{}},t=>{Eh({});var n=wh;if(a&&(n.c=a),i&&(r.$$events=i),ph&&Ev(t,null),c=e(t,r)||{},ph&&(F_.nodes.end=hh,hh===null||hh.nodeType!==8||hh.data!==`]`))throw uh(),ah;Dh()},s);var l=new Set,u=e=>{for(var n=0;n<e.length;n++){var r=e[n];if(!l.has(r)){l.add(r);var i=dv(r);for(let e of[t,document]){var a=Pv.get(e);a===void 0&&(a=new Map,Pv.set(e,a));var o=a.get(r);o===void 0?(e.addEventListener(r,Sv,{passive:i}),a.set(r,1)):a.set(r,o+1)}}}};return u(lm(hv)),gv.add(u),()=>{for(var e of l)for(let n of[t,document]){var r=Pv.get(n),i=r.get(e);--i==0?(n.removeEventListener(e,Sv),r.delete(e),r.size===0&&Pv.delete(n)):r.set(e,i)}gv.delete(u),o!==n&&o.parentNode?.removeChild(o)}});return Iv.set(c,l),c}var Iv=new WeakMap;function Lv(e,t){let n=Iv.get(e);return n?(Iv.delete(e),n(t)):Promise.resolve()}var Rv=class{anchor;#e=new Map;#t=new Map;#n=new Map;#r=new Set;#i=!0;constructor(e,t=!0){this.anchor=e,this.#i=t}#a=e=>{if(this.#e.has(e)){var t=this.#e.get(e),n=this.#t.get(t);if(n)T_(n),this.#r.delete(t);else{var r=this.#n.get(t);r&&(this.#t.set(t,r.effect),this.#n.delete(t),r.fragment.lastChild.remove(),this.anchor.before(r.fragment),n=r.effect)}for(let[t,n]of this.#e){if(this.#e.delete(t),t===e)break;let r=this.#n.get(n);r&&(b_(r.effect),this.#n.delete(n))}for(let[e,r]of this.#t){if(e===t||this.#r.has(e))continue;let i=()=>{if(Array.from(this.#e.values()).includes(e)){var t=document.createDocumentFragment();D_(r,t),t.append(Hg()),this.#n.set(e,{effect:r,fragment:t})}else b_(r);this.#r.delete(e),this.#t.delete(e)};this.#i||!n?(this.#r.add(e),C_(r,i,!1)):i()}}};#o=e=>{this.#e.delete(e);let t=Array.from(this.#e.values());for(let[e,n]of this.#n)t.includes(e)||(b_(n.effect),this.#n.delete(e))};ensure(e,t){var n=Uh,r=qg();if(t&&!this.#t.has(e)&&!this.#n.has(e)){if(r){var i=document.createDocumentFragment(),a=Hg();i.append(a),this.#n.set(e,{effect:g_(()=>t(a)),fragment:i})}else this.#t.set(e,g_(()=>t(this.anchor)))}if(this.#e.set(n,e),r){for(let[t,r]of this.#t)t===e?n.unskip_effect(r):n.skip_effect(r);for(let[t,r]of this.#n)t===e?n.unskip_effect(r.effect):n.skip_effect(r.effect);n.oncommit(this.#a),n.ondiscard(this.#o)}else ph&&(this.anchor=hh),this.#a(n)}};function $(e,t,n=!1){var r;ph&&(r=hh,_h());var i=new Rv(e),a=n?Am:0;function o(e,t){if(ph){var n=bh(r);if(e!==parseInt(n.substring(1))){var a=yh();gh(a),i.anchor=a,mh(!1),i.ensure(e,t),mh(!0);return}}i.ensure(e,t)}m_(()=>{var e=!1;t((t,n=0)=>{e=!0,o(n,t)}),e||o(-1,null)},a)}function zv(e,t){return t}function Bv(e,t,n){for(var r=[],i=t.length,a,o=t.length,s=0;s<i;s++){let n=t[s];C_(n,()=>{if(a){if(a.pending.delete(n),a.done.add(n),a.pending.size===0){var t=e.outrogroups;Vv(e,lm(a.done)),t.delete(a),t.size===0&&(e.outrogroups=null)}}else--o},!1)}if(o===0){var c=r.length===0&&n!==null;if(c){var l=n,u=l.parentNode;Kg(u),u.append(l),e.items.clear()}Vv(e,t,!c)}else a={pending:new Set(t),done:new Set},(e.outrogroups??=new Set).add(a)}function Vv(e,t,n=!0){var r;if(e.pending.size>0){r=new Set;for(let t of e.pending.values())for(let n of t)r.add(e.items.get(n).e)}for(var i=0;i<t.length;i++){var a=t[i];r?.has(a)?(a.f|=Nm,D_(a,document.createDocumentFragment())):b_(t[i],n)}}var Hv;function Uv(e,t,n,r,i,a=null){var o=e,s=new Map;if(t&4){var c=e;o=ph?gh(Ug(c)):c.appendChild(Hg())}ph&&_h();var l=null,u=vg(()=>{var e=n();return om(e)?e:e==null?[]:lm(e)}),d,f=new Map,p=!0;function m(e){g.effect.f&16384||(g.pending.delete(e),g.fallback=l,Gv(g,d,o,t,r),l!==null&&(d.length===0?l.f&33554432?(l.f^=Nm,qv(l,null,o)):T_(l):C_(l,()=>{l=null})))}function h(e){g.pending.delete(e)}var g={effect:m_(()=>{d=X(u);var e=d.length;let c=!1;ph&&bh(o)===`[!`!=(e===0)&&(o=yh(),gh(o),mh(!1),c=!0);for(var g=new Set,_=Uh,v=qg(),y=0;y<e;y+=1){ph&&hh.nodeType===8&&hh.data===`]`&&(o=hh,c=!0,mh(!1));var b=d[y],x=r(b,y),S=p?null:s.get(x);S?(S.v&&Ag(S.v,b),S.i&&Ag(S.i,y),v&&_.unskip_effect(S.e)):(S=Kv(s,p?o:Hv??=Hg(),b,x,y,i,t,n),p||(S.e.f|=Nm),s.set(x,S)),g.add(x)}if(e===0&&a&&!l&&(p?l=g_(()=>a(o)):(l=g_(()=>a(Hv??=Hg())),l.f|=Nm)),e>g.size&&Ym(``,``,``),ph&&e>0&&gh(yh()),!p){if(f.set(_,g),v){for(let[e,t]of s)g.has(e)||_.skip_effect(t.e);_.oncommit(m),_.ondiscard(h)}else m(_)}c&&mh(!0),X(u)}),flags:t,items:s,pending:f,outrogroups:null,fallback:l};p=!1,ph&&(o=hh)}function Wv(e){for(;e!==null&&!(e.f&32);)e=e.next;return e}function Gv(e,t,n,r,i){var a=!!(r&8),o=t.length,s=e.items,c=Wv(e.effect.first),l,u=null,d,f=[],p=[],m,h,g,_;if(a)for(_=0;_<o;_+=1)m=t[_],h=i(m,_),g=s.get(h).e,g.f&33554432||(g.nodes?.a?.measure(),(d??=new Set).add(g));for(_=0;_<o;_+=1){if(m=t[_],h=i(m,_),g=s.get(h).e,e.outrogroups!==null)for(let t of e.outrogroups)t.pending.delete(g),t.done.delete(g);if(g.f&8192&&(T_(g),a&&(g.nodes?.a?.unfix(),(d??=new Set).delete(g))),g.f&33554432){if(g.f^=Nm,g===c)qv(g,null,n);else{var v=u?u.next:c;g===e.effect.last&&(e.effect.last=g.prev),g.prev&&(g.prev.next=g.next),g.next&&(g.next.prev=g.prev),Jv(e,u,g),Jv(e,g,v),qv(g,v,n),u=g,f=[],p=[],c=Wv(u.next);continue}}if(g!==c){if(l!==void 0&&l.has(g)){if(f.length<p.length){var y=p[0],b;u=y.prev;var x=f[0],S=f[f.length-1];for(b=0;b<f.length;b+=1)qv(f[b],y,n);for(b=0;b<p.length;b+=1)l.delete(p[b]);Jv(e,x.prev,S.next),Jv(e,u,x),Jv(e,S,y),c=y,u=S,--_,f=[],p=[]}else l.delete(g),qv(g,c,n),Jv(e,g.prev,g.next),Jv(e,g,u===null?e.effect.first:u.next),Jv(e,u,g),u=g;continue}for(f=[],p=[];c!==null&&c!==g;)(l??=new Set).add(c),p.push(c),c=Wv(c.next);if(c===null)continue}g.f&33554432||f.push(g),u=g,c=Wv(g.next)}if(e.outrogroups!==null){for(let t of e.outrogroups)t.pending.size===0&&(Vv(e,lm(t.done)),e.outrogroups?.delete(t));e.outrogroups.size===0&&(e.outrogroups=null)}if(c!==null||l!==void 0){var C=[];if(l!==void 0)for(g of l)g.f&8192||C.push(g);for(;c!==null;)!(c.f&8192)&&c!==e.fallback&&C.push(c),c=Wv(c.next);var w=C.length;if(w>0){var T=r&4&&o===0?n:null;if(a){for(_=0;_<w;_+=1)C[_].nodes?.a?.measure();for(_=0;_<w;_+=1)C[_].nodes?.a?.fix()}Bv(e,C,T)}}a&&jh(()=>{if(d!==void 0)for(g of d)g.nodes?.a?.apply()})}function Kv(e,t,n,r,i,a,o,s){var c=o&1?o&16?Dg(n):kg(n,!1,!1):null,l=o&2?Dg(i):null;return{v:c,i:l,e:g_(()=>(a(t,c??n,l??i,s),()=>{e.delete(r)}))}}function qv(e,t,n){if(e.nodes)for(var r=e.nodes.start,i=e.nodes.end,a=t&&!(t.f&33554432)?t.nodes.start:n;r!==null;){var o=Wg(r);if(a.before(r),r===i)return;r=o}}function Jv(e,t,n){t===null?e.effect.first=n:t.next=n,n===null?e.effect.last=t:n.prev=t}function Yv(e,t,...n){var r=new Rv(e);m_(()=>{let e=t()??null;r.ensure(e,e&&(t=>e(t,...n)))},Am)}function Xv(e,t,n,r,i,a){let o=ph;ph&&_h();var s=null;ph&&hh.nodeType===1&&(s=hh,_h());var c=ph?hh:e,l=new Rv(c,!1);m_(()=>{let e=t()||null;var a=i?i():n||e===`svg`?ch:void 0;if(e===null)l.ensure(null,null);else return l.ensure(e,t=>{if(e){if(s=ph?s:Jg(e,a),Ev(s,s),r){ph&&pv(e)&&s.append(document.createComment(``));var n=ph?Ug(s):s.appendChild(Hg());ph&&(n===null?mh(!1):gh(n)),r(s,n)}F_.nodes.end=s,t.before(s)}ph&&gh(t)}),()=>{}},Am),o_(()=>{}),o&&(mh(!0),gh(c))}function Zv(e,t){var n=void 0,r;h_(()=>{n!==(n=t())&&(r&&=(b_(r),null),n&&(r=g_(()=>{u_(()=>n(e))})))})}function Qv(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Qv(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function $v(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Qv(e))&&(r&&(r+=` `),r+=t);return r}function ey(e){return typeof e==`object`?$v(e):e??``}var ty=[...`
|
|
840
|
+
\r\f\xA0\v`];function ny(e,t,n){var r=e==null?``:``+e;if(t&&(r=r?r+` `+t:t),n){for(var i of Object.keys(n))if(n[i])r=r?r+` `+i:i;else if(r.length)for(var a=i.length,o=0;(o=r.indexOf(i,o))>=0;){var s=o+a;(o===0||ty.includes(r[o-1]))&&(s===r.length||ty.includes(r[s]))?r=(o===0?``:r.substring(0,o))+r.substring(s+1):o=s}}return r===``?null:r}function ry(e,t=!1){var n=t?` !important;`:`;`,r=``;for(var i of Object.keys(e)){var a=e[i];a!=null&&a!==``&&(r+=` `+i+`: `+a+n)}return r}function iy(e){return e[0]!==`-`||e[1]!==`-`?e.toLowerCase():e}function ay(e,t){if(t){var n=``,r,i;if(Array.isArray(t)?(r=t[0],i=t[1]):r=t,e){e=String(e).replaceAll(/\s*\/\*.*?\*\/\s*/g,``).trim();var a=!1,o=0,s=!1,c=[];r&&c.push(...Object.keys(r).map(iy)),i&&c.push(...Object.keys(i).map(iy));var l=0,u=-1;let t=e.length;for(var d=0;d<t;d++){var f=e[d];if(s?f===`/`&&e[d-1]===`*`&&(s=!1):a?a===f&&(a=!1):f===`/`&&e[d+1]===`*`?s=!0:f===`"`||f===`'`?a=f:f===`(`?o++:f===`)`&&o--,!s&&a===!1&&o===0){if(f===`:`&&u===-1)u=d;else if(f===`;`||d===t-1){if(u!==-1){var p=iy(e.substring(l,u).trim());if(!c.includes(p)){f!==`;`&&d++;var m=e.substring(l,d).trim();n+=` `+m+`;`}}l=d+1,u=-1}}}}return r&&(n+=ry(r)),i&&(n+=ry(i,!0)),n=n.trim(),n===``?null:n}return e==null?null:String(e)}function oy(e,t,n,r,i,a){var o=e[Hm];if(ph||o!==n||o===void 0){var s=ny(n,r,a);(!ph||s!==e.getAttribute(`class`))&&(s==null?e.removeAttribute(`class`):t?e.className=s:e.setAttribute(`class`,s)),e[Hm]=n}else if(a&&i!==a)for(var c in a){var l=!!a[c];(i==null||l!==!!i[c])&&e.classList.toggle(c,l)}return a}function sy(e,t={},n,r){for(var i in n){var a=n[i];t[i]!==a&&(n[i]==null?e.style.removeProperty(i):e.style.setProperty(i,a,r))}}function cy(e,t,n,r){var i=e[Um];if(ph||i!==t){var a=ay(t,r);(!ph||a!==e.getAttribute(`style`))&&(a==null?e.removeAttribute(`style`):e.style.cssText=a),e[Um]=t}else r&&(Array.isArray(r)?(sy(e,n?.[0],r[0]),sy(e,n?.[1],r[1],`important`)):sy(e,n,r));return r}function ly(e,t,n=!1){if(e.multiple){if(t==null)return;if(!om(t))return dh();for(var r of e.options)r.selected=t.includes(dy(r))}else{for(r of e.options)if(Ig(dy(r),t)){r.selected=!0;return}(!n||t!==void 0)&&(e.selectedIndex=-1)}}function uy(e){var t=new MutationObserver(()=>{ly(e,e.__value)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`]}),o_(()=>{t.disconnect()})}function dy(e){return`__value`in e?e.__value:e.value}var fy=Symbol(`class`),py=Symbol(`style`),my=Symbol(`is custom element`),hy=Symbol(`is html`),gy=qm?`link`:`LINK`,_y=qm?`input`:`INPUT`,vy=qm?`option`:`OPTION`,yy=qm?`select`:`SELECT`;function by(e){if(ph){var t=!1,n=()=>{if(!t){if(t=!0,e.hasAttribute(`value`)){var n=e.value;Sy(e,`value`,null),e.value=n}if(e.hasAttribute(`checked`)){var r=e.checked;Sy(e,`checked`,null),e.checked=r}}};e[Gm]=n,jh(n),$g()}}function xy(e,t){t?e.hasAttribute(`selected`)||e.setAttribute(`selected`,``):e.removeAttribute(`selected`)}function Sy(e,t,n,r){var i=Ty(e);ph&&(i[t]=e.getAttribute(t),t===`src`||t===`srcset`||t===`href`&&e.nodeName===gy)||i[t]!==(i[t]=n)&&(t===`loading`&&(e[Bm]=n),n==null?e.removeAttribute(t):typeof n!=`string`&&Dy(e).includes(t)?e[t]=n:e.setAttribute(t,n))}function Cy(e,t,n,r,i=!1,a=!1){if(ph&&i&&e.nodeName===_y){var o=e;(o.type===`checkbox`?`defaultChecked`:`defaultValue`)in n||by(o)}var s=Ty(e),c=s[my],l=!s[hy];let u=ph&&c;u&&mh(!1);var d=t||{},f=e.nodeName===vy;for(var p in t)p in n||(n[p]=null);n.class?n.class=ey(n.class):(r||n[fy])&&(n.class=null),n[py]&&(n.style??=null);var m=Dy(e);for(let i in n){let o=n[i];if(f&&i===`value`&&o==null)e.value=e.__value=``,d[i]=o;else if(i===`class`)oy(e,e.namespaceURI===`http://www.w3.org/1999/xhtml`,o,r,t?.[fy],n[fy]),d[i]=o,d[fy]=n[fy];else if(i===`style`)cy(e,o,t?.[py],n[py]),d[i]=o,d[py]=n[py];else{var h=d[i];if(o!==h||o===void 0&&e.hasAttribute(i)){d[i]=o;var g=i[0]+i[1];if(g!==`$$`){if(g===`on`){let t={},n=`$$`+i,r=i.slice(2);var _=ov(r);if(iv(r)&&(r=r.slice(0,-7),t.capture=!0),!_&&h){if(o!=null)continue;e.removeEventListener(r,d[n],t),d[n]=null}if(_)yv(r,e,o),bv([r]);else if(o!=null){function a(e){d[i].call(this,e)}d[n]=_v(r,e,a,t)}}else if(i===`style`)Sy(e,i,o);else if(i===`autofocus`)Xg(e,!!o);else if(!c&&(i===`__value`||i===`value`&&o!=null))e.value=e.__value=o;else if(i===`selected`&&f)xy(e,o);else{var v=i;l||(v=lv(v));var y=v===`defaultValue`||v===`defaultChecked`;if(o==null&&!c&&!y){if(s[i]=null,v===`value`||v===`checked`){let n=e,r=t===void 0;if(v===`value`){let e=n.defaultValue;n.removeAttribute(v),n.defaultValue=e,n.value=n.__value=r?e:null}else{let e=n.defaultChecked;n.removeAttribute(v),n.defaultChecked=e,n.checked=r?e:!1}}else e.removeAttribute(i)}else y||m.includes(v)&&(c||typeof o!=`string`)?(e[v]=o,v in s&&(s[v]=oh)):typeof o!=`function`&&Sy(e,v,o,a)}}}}}return u&&mh(!0),d}function wy(e,t,n=[],r=[],i=[],a,o=!1,s=!1){dg(i,n,r,n=>{var r=void 0,i={},c=e.nodeName===yy,l=!1;if(h_(()=>{var u=t(...n.map(X)),d=Cy(e,r,u,a,o,s);l&&c&&`value`in u&&ly(e,u.value);for(let e of Object.getOwnPropertySymbols(i))u[e]||b_(i[e]);for(let t of Object.getOwnPropertySymbols(u)){var f=u[t];t.description===`@attach`&&(!r||f!==r[t])&&(i[t]&&b_(i[t]),i[t]=g_(()=>Zv(e,()=>f))),d[t]=f}r=d}),c){var u=e;u_(()=>{ly(u,r.value,!0),uy(u)})}l=!0})}function Ty(e){return e[Vm]??={[my]:e.nodeName.includes(`-`),[hy]:e.namespaceURI===sh}}var Ey=new Map;function Dy(e){var t=e.getAttribute(`is`)||e.nodeName,n=Ey.get(t);if(n)return n;Ey.set(t,n=[]);for(var r,i=e,a=Element.prototype;a!==i;){for(var o in r=fm(i),r)r[o].set&&o!==`innerHTML`&&o!==`textContent`&&o!==`innerText`&&n.push(o);i=hm(i)}return n}function Oy(e,t,n=t){var r=new WeakSet;t_(e,`input`,async i=>{var a=i?e.defaultValue:e.value;if(a=ky(e)?Ay(a):a,n(a),Uh!==null&&r.add(Uh),await ev(),a!==(a=t())){var o=e.selectionStart,s=e.selectionEnd,c=e.value.length;if(e.value=a??``,s!==null){var l=e.value.length;o===s&&s===c&&l>c?(e.selectionStart=l,e.selectionEnd=l):(e.selectionStart=o,e.selectionEnd=Math.min(s,l))}}}),(ph&&e.defaultValue!==e.value||rv(t)==null&&e.value)&&(n(ky(e)?Ay(e.value):e.value),Uh!==null&&r.add(Uh)),f_(()=>{var n=t();if(e===document.activeElement){var i=Uh;if(r.has(i))return}ky(e)&&n===Ay(e.value)||(e.type!==`date`||n||e.value)&&n!==e.value&&(e.value=n??``)})}function ky(e){var t=e.type;return t===`number`||t===`range`}function Ay(e){return e===``?null:+e}function jy(e,t){return e===t||e?.[Rm]===t}function My(e={},t,n,r){var i=wh.r,a=F_;return u_(()=>{var o,s;return f_(()=>{o=s,s=r?.()||[],rv(()=>{jy(n(...s),e)||(t(e,...s),o&&jy(n(...o),e)&&t(null,...o))})}),()=>{let r=a;for(;r!==i&&r.parent!==null&&r.parent.f&33554432;)r=r.parent;let o=()=>{s&&jy(n(...s),e)&&t(null,...s)},c=r.teardown;r.teardown=()=>{o(),c?.()}}}),e}var Ny={get(e,t){if(!e.exclude.includes(t))return e.props[t]},set(e,t){return!1},getOwnPropertyDescriptor(e,t){if(!e.exclude.includes(t)&&t in e.props)return{enumerable:!0,configurable:!0,value:e.props[t]}},has(e,t){return!e.exclude.includes(t)&&t in e.props},ownKeys(e){return Reflect.ownKeys(e.props).filter(t=>!e.exclude.includes(t))}};function Py(e,t,n){return new Proxy({props:e,exclude:t},Ny)}var Fy={get(e,t){let n=e.props.length;for(;n--;){let r=e.props[n];if(_m(r)&&(r=r()),typeof r==`object`&&r&&t in r)return r[t]}},set(e,t,n){let r=e.props.length;for(;r--;){let i=e.props[r];_m(i)&&(i=i());let a=dm(i,t);if(a&&a.set)return a.set(n),!0}return!1},getOwnPropertyDescriptor(e,t){let n=e.props.length;for(;n--;){let r=e.props[n];if(_m(r)&&(r=r()),typeof r==`object`&&r&&t in r){let e=dm(r,t);return e&&!e.configurable&&(e.configurable=!0),e}}},has(e,t){if(t===Rm||t===zm)return!1;for(let n of e.props)if(_m(n)&&(n=n()),n!=null&&t in n)return!0;return!1},ownKeys(e){let t=[];for(let n of e.props)if(_m(n)&&(n=n()),n){for(let e in n)t.includes(e)||t.push(e);for(let e of Object.getOwnPropertySymbols(n))t.includes(e)||t.push(e)}return t}};function Iy(...e){return new Proxy({props:e},Fy)}function Ly(e,t,n,r){var i=!0,a=!!(n&8),o=!!(n&16),s=r,c=!0,l=void 0,u=()=>o&&i?(l??=hg(r),X(l)):(c&&(c=!1,s=o?rv(r):r),s);let d;if(a){var f=Rm in e||zm in e;d=dm(e,t)?.set??(f&&t in e?n=>e[t]=n:void 0)}var p,m=!1;a?[p,m]=Vh(()=>e[t]):p=e[t],p===void 0&&r!==void 0&&(p=u(),d&&(i&&eh(t),d(p)));var h=i?()=>{var n=e[t];return n===void 0?u():(c=!0,n)}:()=>{var n=e[t];return n!==void 0&&(s=void 0),n===void 0?s:n};if(i&&!(n&4))return h;if(d){var g=e.$$legacy;return(function(e,t){return arguments.length>0?((!i||!t||g||m)&&d(t?h():e),e):h()})}var _=!1,v=(n&1?hg:vg)(()=>(_=!1,h()));a&&X(v);var y=F_;return(function(e,t){if(arguments.length>0){let n=t?X(v):i&&a?Pg(e):e;return q(v,n),_=!0,s!==void 0&&(s=n),e}return A_&&_||y.f&16384?v.v:X(v)})}typeof window<`u`&&((window.__svelte??={}).v??=new Set).add(`5`);var Ry={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},zy=Ov(`<svg><!><!></svg>`);function By(e,t){Eh(t,!0);let n=Ly(t,`color`,3,`currentColor`),r=Ly(t,`size`,3,24),i=Ly(t,`strokeWidth`,3,2),a=Ly(t,`absoluteStrokeWidth`,3,!1),o=Ly(t,`iconNode`,19,()=>[]),s=Py(t,[`$$slots`,`$$events`,`$$legacy`,`name`,`color`,`size`,`strokeWidth`,`absoluteStrokeWidth`,`iconNode`,`children`]);var c=zy();wy(c,e=>({...Ry,...s,width:r(),height:r(),stroke:n(),"stroke-width":e,class:[`lucide-icon lucide`,t.name&&`lucide-${t.name}`,t.class]}),[()=>a()?Number(i())*24/Number(r()):i()]);var l=J(c);Uv(l,17,o,zv,(e,t)=>{var n=K(()=>xm(X(t),2));let r=()=>X(n)[0],i=()=>X(n)[1];var a=Av();Xv(Gg(a),r,!0,(e,t)=>{wy(e,()=>({...i()}))}),Q(e,a)}),Yv(Y(l),()=>t.children??vm),G(c),Q(e,c),Dh()}function Vy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`m12 19-7-7 7-7`}],[`path`,{d:`M19 12H5`}]];By(e,Iy({name:`arrow-left`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Hy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M12 8V4H8`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`}],[`path`,{d:`M2 14h2`}],[`path`,{d:`M20 14h2`}],[`path`,{d:`M15 13v2`}],[`path`,{d:`M9 13v2`}]];By(e,Iy({name:`bot`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Uy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M20 6 9 17l-5-5`}]];By(e,Iy({name:`check`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Wy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`circle`,{cx:`12`,cy:`12`,r:`10`}],[`path`,{d:`m9 12 2 2 4-4`}]];By(e,Iy({name:`circle-check`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Gy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M12 20v2`}],[`path`,{d:`M12 2v2`}],[`path`,{d:`M17 20v2`}],[`path`,{d:`M17 2v2`}],[`path`,{d:`M2 12h2`}],[`path`,{d:`M2 17h2`}],[`path`,{d:`M2 7h2`}],[`path`,{d:`M20 12h2`}],[`path`,{d:`M20 17h2`}],[`path`,{d:`M20 7h2`}],[`path`,{d:`M7 20v2`}],[`path`,{d:`M7 2v2`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`}]];By(e,Iy({name:`cpu`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Ky(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M15 3h6v6`}],[`path`,{d:`M10 14 21 3`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`}]];By(e,Iy({name:`external-link`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function qy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`}]];By(e,Iy({name:`link-2`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Jy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`}],[`path`,{d:`m15 5 4 4`}]];By(e,Iy({name:`pencil`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Yy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}],[`path`,{d:`M3 3v5h5`}]];By(e,Iy({name:`rotate-ccw`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Xy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M10 11v6`}],[`path`,{d:`M14 11v6`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`}],[`path`,{d:`M3 6h18`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}]];By(e,Iy({name:`trash-2`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Zy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71`}],[`path`,{d:`m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71`}],[`line`,{x1:`8`,x2:`8`,y1:`2`,y2:`5`}],[`line`,{x1:`2`,x2:`5`,y1:`8`,y2:`8`}],[`line`,{x1:`16`,x2:`16`,y1:`19`,y2:`22`}],[`line`,{x1:`19`,x2:`22`,y1:`16`,y2:`16`}]];By(e,Iy({name:`unlink`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function Qy(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`]),r=[[`path`,{d:`M18 6 6 18`}],[`path`,{d:`m6 6 12 12`}]];By(e,Iy({name:`x`},()=>n,{get iconNode(){return r},children:(e,n)=>{var r=Av();Yv(Gg(r),()=>t.children??vm),Q(e,r)},$$slots:{default:!0}})),Dh()}function $y(e){let t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?`?`:t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[t.length-1][0]).toUpperCase()}bv([`click`]);var eb=Z(`<span class="st-avatarGroup__overflow svelte-1pyotkr"> </span>`),tb=Z(`<div><!> <!></div>`);function nb(e,t){Eh(t,!0);let n=Ly(t,`size`,3,`md`),r=Py(t,[`$$slots`,`$$events`,`$$legacy`,`max`,`size`,`total`,`class`,`children`]),i=K(()=>t.max!=null&&t.total!=null&&t.total>t.max?t.total-t.max:0),a=K(()=>[`st-avatarGroup`,`st-avatarGroup--${n()}`,t.class].filter(Boolean).join(` `));var o=tb();wy(o,()=>({...r,class:X(a),[py]:{"--st-avatar-group-max":t.max??``}}),void 0,void 0,void 0,`svelte-1pyotkr`);var s=J(o);Yv(s,()=>t.children??vm);var c=Y(s,2),l=e=>{var t=eb(),n=J(t);G(t),p_(()=>{Sy(t,`aria-label`,`+${X(i)}`),Mv(n,`+${X(i)??``}`)}),Q(e,t)};$(c,e=>{X(i)>0&&e(l)}),G(o),Q(e,o),Dh()}var rb=Z(`<span><!></span>`);function ib(e,t){Eh(t,!0);let n=Ly(t,`tone`,3,`neutral`),r=Ly(t,`shape`,3,`pill`),i=Ly(t,`size`,3,`md`),a=Py(t,[`$$slots`,`$$events`,`$$legacy`,`tone`,`shape`,`size`,`class`,`children`]),o=()=>[`st-badge`,`st-badge--${n()}`,`st-badge--${r()}`,`st-badge--${i()}`,t.class].filter(Boolean).join(` `);var s=rb();wy(s,e=>({...a,class:e}),[()=>o()],void 0,void 0,`svelte-pdgh8u`),Yv(J(s),()=>t.children??vm),G(s),Q(e,s),Dh()}var ab=Z(`<button><!></button>`);function ob(e,t){Eh(t,!0);let n=Ly(t,`variant`,3,`primary`),r=Ly(t,`size`,3,`md`),i=Ly(t,`disabled`,3,!1),a=Ly(t,`type`,3,`button`),o=Py(t,[`$$slots`,`$$events`,`$$legacy`,`variant`,`size`,`disabled`,`type`,`class`,`children`]),s=()=>[`st-button`,`st-button--${n()}`,`st-button--${r()}`,t.class].filter(Boolean).join(` `);var c=ab();wy(c,e=>({...o,class:e,type:a(),disabled:i()}),[()=>s()],void 0,void 0,`svelte-121ausn`),Yv(J(c),()=>t.children??vm),G(c),Q(e,c),Dh()}var sb=Z(`<button><!></button>`);function cb(e,t){Eh(t,!0);let n=Ly(t,`size`,3,`md`),r=Ly(t,`variant`,3,`ghost`),i=Ly(t,`type`,3,`button`),a=Ly(t,`disabled`,3,!1),o=Py(t,[`$$slots`,`$$events`,`$$legacy`,`aria-label`,`size`,`variant`,`type`,`disabled`,`class`,`children`]),s=()=>[`st-iconButton`,`st-iconButton--${n()}`,`st-iconButton--${r()}`,t.class].filter(Boolean).join(` `);var c=sb();wy(c,e=>({...o,class:e,type:i(),disabled:a(),"aria-label":t[`aria-label`]}),[()=>s()],void 0,void 0,`svelte-iw4na2`),Yv(J(c),()=>t.children),G(c),Q(e,c),Dh()}var lb=Z(`<p class="st-drawer__description svelte-i68ybm"> </p>`),ub=Z(`<footer class="st-drawer__footer svelte-i68ybm"><!></footer>`),db=Z(`<div class="st-drawer__backdrop svelte-i68ybm" role="presentation"><aside><header class="st-drawer__header svelte-i68ybm"><div><h2 class="st-drawer__title svelte-i68ybm" tabindex="-1"> </h2> <!></div> <button class="st-drawer__close svelte-i68ybm" type="button"><span aria-hidden="true">x</span></button></header> <div class="st-drawer__body svelte-i68ybm"><!></div> <!></aside></div>`);function fb(e,t){Eh(t,!0);let n=Ly(t,`open`,15,!1),r=Ly(t,`side`,3,`right`),i=Ly(t,`closeLabel`,3,`Close`),a=Py(t,[`$$slots`,`$$events`,`$$legacy`,`open`,`title`,`description`,`side`,`closeLabel`,`class`,`children`,`footer`,`onclose`]),o=Og(void 0),s=Og(void 0),c=null,l=!1,u=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type='hidden'])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex='-1'])`].join(`,`),d=()=>[`st-drawer`,`st-drawer--${r()}`,t.class].filter(Boolean).join(` `);s_(()=>{if(n()&&!l)l=!0,c=document.activeElement instanceof HTMLElement?document.activeElement:null,ev().then(()=>{n()&&X(o)&&(X(o).contains(document.activeElement)||(X(s)??X(o)).focus())});else if(!n()&&l){l=!1;let e=c;c=null,ev().then(()=>{e?.isConnected&&e.focus()})}});function f(){n(!1),t.onclose?.()}function p(e){e.target===e.currentTarget&&f()}function m(e){if(!X(o)||e.key!==`Tab`)return;let t=Array.from(X(o).querySelectorAll(u)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`);if(t.length===0){e.preventDefault(),X(o).focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;X(o).contains(i)?e.shiftKey&&i===n?(e.preventDefault(),r.focus()):!e.shiftKey&&i===r&&(e.preventDefault(),n.focus()):(e.preventDefault(),n.focus())}function h(e){if(!n()||e.defaultPrevented)return;let t=e.target instanceof Element?e.target:null,r=document.activeElement instanceof Element?document.activeElement:null,i=t?.closest(`[aria-modal="true"]`)??r?.closest(`[aria-modal="true"]`);i&&i!==X(o)||(e.key===`Escape`?(e.preventDefault(),f()):m(e))}var g=Av();vv(`keydown`,Lg,h);var _=Gg(g),v=e=>{var n=db(),r=J(n);wy(r,e=>({...a,class:e,role:`dialog`,"aria-modal":`true`,"aria-label":t.title,tabindex:`-1`}),[()=>d()],void 0,void 0,`svelte-i68ybm`);var c=J(r),l=J(c),u=J(l),m=J(u,!0);G(u);var h=Y(u,2),g=e=>{var n=lb(),r=J(n,!0);G(n),p_(()=>Mv(r,t.description)),Q(e,n)};$(h,e=>{t.description&&e(g)}),G(l);var _=Y(l,2);My(_,e=>q(s,e),()=>X(s)),G(c);var v=Y(c,2);Yv(J(v),()=>t.children??vm),G(v);var y=Y(v,2),b=e=>{var n=ub();Yv(J(n),()=>t.footer),G(n),Q(e,n)};$(y,e=>{t.footer&&e(b)}),G(r),My(r,e=>q(o,e),()=>X(o)),G(n),p_(()=>{Mv(m,t.title),Sy(_,`aria-label`,i())}),yv(`click`,n,p),yv(`click`,_,f),Q(e,n)};$(_,e=>{n()&&e(v)}),Q(e,g),Dh()}bv([`click`]);var pb=Z(`<p class="st-empty-state__message svelte-1irw8xl"> </p>`),mb=Z(`<div class="st-empty-state__action svelte-1irw8xl"><!></div>`),hb=Z(`<section><div class="st-empty-state__content svelte-1irw8xl"><h2 class="st-empty-state__title svelte-1irw8xl"> </h2> <!> <!></div> <!></section>`);function gb(e,t){Eh(t,!0);let n=Py(t,[`$$slots`,`$$events`,`$$legacy`,`title`,`message`,`class`,`action`,`children`]),r=()=>[`st-empty-state`,t.class].filter(Boolean).join(` `);var i=hb();wy(i,e=>({...n,class:e}),[()=>r()],void 0,void 0,`svelte-1irw8xl`);var a=J(i),o=J(a),s=J(o,!0);G(o);var c=Y(o,2),l=e=>{var n=pb(),r=J(n,!0);G(n),p_(()=>Mv(r,t.message)),Q(e,n)};$(c,e=>{t.message&&e(l)}),Yv(Y(c,2),()=>t.children??vm),G(a);var u=Y(a,2),d=e=>{var n=mb();Yv(J(n),()=>t.action),G(n),Q(e,n)};$(u,e=>{t.action&&e(d)}),G(i),p_(()=>Mv(s,t.title)),Q(e,i),Dh()}var _b=2048,vb=Object.freeze({open:`Open`,closed:`Resolved`});function yb(e){return vb[e]}function bb(e){if(e.kind===`record`&&e.recordType===`artifact`){let t={kind:`artifact`,id:e.id};return e.sectionKey!==void 0&&(t.sectionKey=e.sectionKey),t}let t={kind:e.kind,id:e.id};return e.sectionKey!==void 0&&(t.sectionKey=e.sectionKey),e.recordType!==void 0&&(t.recordType=e.recordType),t}var xb=`#64748b`;function Sb(e,t,n){return n?.canModerate===!0||e.authorship.sponsor===void 0&&e.authorship.author.kind===`human`&&e.authorship.author.actorId===t.actorId&&e.author.id===t.actorId}var Cb=class extends Error{code;status;constructor(e,t,n){super(n),this.name=`ReviewAdapterError`,this.code=e,this.status=t}},wb=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,Tb=(()=>{let e=new Int16Array(128).fill(-1);for(let t=0;t<64;t++)e[wb.charCodeAt(t)]=t;return e})(),Eb=new TextEncoder,Db=new TextDecoder(`utf-8`,{fatal:!0}),Ob=class extends Error{code=`INVALID_ANCHOR`;constructor(e){super(e),this.name=`AnchorValidationError`}};function kb(e){let t=e.length;if(t===0)return``;let n=[],r=0;for(;r+2<t;r+=3){let t=e[r]<<16|e[r+1]<<8|e[r+2];n.push(wb[t>>>18&63],wb[t>>>12&63],wb[t>>>6&63],wb[t&63])}let i=t-r;if(i===1){let t=e[r];n.push(wb[t>>>2&63],wb[t<<4&63])}else if(i===2){let t=e[r]<<8|e[r+1];n.push(wb[t>>>10&63],wb[t>>>4&63],wb[t<<2&63])}return n.join(``)}function Ab(e){let t=e.length;if(t===0)return new Uint8Array;let n=t%4;if(n===1)return null;let r=(t-n)/4,i=r*3+(n===2?1:n===3?2:0),a=new Uint8Array(i),o=0,s=0;for(let t=0;t<r;t++){let t=e.charCodeAt(s++),n=e.charCodeAt(s++),r=e.charCodeAt(s++),i=e.charCodeAt(s++);if(t>=128||n>=128||r>=128||i>=128)return null;let c=Tb[t],l=Tb[n],u=Tb[r],d=Tb[i];if(c<0||l<0||u<0||d<0)return null;let f=c<<18|l<<12|u<<6|d;a[o++]=f>>>16&255,a[o++]=f>>>8&255,a[o++]=f&255}if(n===2){let t=e.charCodeAt(s++),n=e.charCodeAt(s++);if(t>=128||n>=128)return null;let r=Tb[t],i=Tb[n];if(r<0||i<0||i&15)return null;a[o++]=(r<<2|i>>>4)&255}else if(n===3){let t=e.charCodeAt(s++),n=e.charCodeAt(s++),r=e.charCodeAt(s++);if(t>=128||n>=128||r>=128)return null;let i=Tb[t],c=Tb[n],l=Tb[r];if(i<0||c<0||l<0||l&3)return null;let u=i<<10|c<<4|l>>>2;a[o++]=u>>>8&255,a[o++]=u&255}return a}function jb(e){return`a1:`+kb(Eb.encode(JSON.stringify(e)))}function Mb(e){if(!e||typeof e!=`object`)return!1;let{x:t,y:n,width:r,height:i}=e;return typeof t!=`number`||typeof n!=`number`||typeof r!=`number`||typeof i!=`number`||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?!1:t>=0&&n>=0&&r>0&&i>0&&t<=1&&n<=1&&t+r<=1.000000001&&n+i<=1.000000001}function Nb(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.start==`number`&&typeof t.end==`number`&&Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.end>=t.start}function Pb(e){if(!e||typeof e!=`object`)return{ok:!1,message:`Anchor payload must be an object.`};let t=e,n=t.v;if(typeof n!=`string`||n.length===0)return{ok:!1,message:"Anchor payload requires a non-empty string version `v`."};switch(t.t){case`text`:{let e=t.q;if(!e||typeof e!=`object`)return{ok:!1,message:"Text anchor requires quote object `q`."};let r=e;if(typeof r.exact!=`string`||r.exact.length===0)return{ok:!1,message:"Text anchor requires non-empty `q.exact`."};if(r.prefix!==void 0&&typeof r.prefix!=`string`)return{ok:!1,message:"Text anchor `q.prefix` must be a string."};if(r.suffix!==void 0&&typeof r.suffix!=`string`)return{ok:!1,message:"Text anchor `q.suffix` must be a string."};if(t.pos!==void 0&&!Nb(t.pos))return{ok:!1,message:"Text anchor `pos` must be valid non-negative integer offsets."};if(t.sel!==void 0&&(typeof t.sel!=`string`||t.sel.length===0))return{ok:!1,message:"Text anchor `sel` must be a non-empty string when present."};if(t.aid!==void 0&&(typeof t.aid!=`string`||t.aid.length===0))return{ok:!1,message:"Text anchor `aid` must be a non-empty string when present."};let i={exact:r.exact};typeof r.prefix==`string`&&r.prefix.length>0&&(i.prefix=r.prefix),typeof r.suffix==`string`&&r.suffix.length>0&&(i.suffix=r.suffix);let a={t:`text`,q:i,v:n};if(t.pos!==void 0){let e=t.pos;a.pos={start:e.start,end:e.end}}return typeof t.sel==`string`&&(a.sel=t.sel),typeof t.aid==`string`&&(a.aid=t.aid),{ok:!0,payload:a}}case`element`:{if(typeof t.sel!=`string`||t.sel.length===0)return{ok:!1,message:"Element anchor requires non-empty `sel`."};if(t.aid!==void 0&&(typeof t.aid!=`string`||t.aid.length===0))return{ok:!1,message:"Element anchor `aid` must be a non-empty string when present."};let e={t:`element`,sel:t.sel,v:n};return typeof t.aid==`string`&&(e.aid=t.aid),{ok:!0,payload:e}}case`region`:{if(!Mb(t.rect))return{ok:!1,message:"Region anchor `rect` must have finite coordinates inside [0, 1] with positive width and height."};let e=t.rect;return{ok:!0,payload:{t:`region`,rect:{x:e.x,y:e.y,width:e.width,height:e.height},v:n}}}default:return{ok:!1,message:`Unsupported anchor type: ${String(t.t)}`}}}function Fb(e,t,n,r){let i={exact:t};n.length>0&&(i.prefix=n),r.length>0&&(i.suffix=r);let a={t:`text`,q:i,v:e.v};return e.pos!==void 0&&(a.pos={start:e.pos.start,end:e.pos.end}),e.sel!==void 0&&(a.sel=e.sel),e.aid!==void 0&&(a.aid=e.aid),a}function Ib(e,t){let n=t?.maxLength??2048,r=Pb(e);if(!r.ok)return{ok:!1,code:`INVALID_ANCHOR`,message:r.message,maxLength:n};let i=r.payload;if(i.t!==`text`){let e=jb(i);return e.length>n?{ok:!1,code:`ANCHOR_TOO_LONG`,message:`Encoded anchor length (${e.length}) exceeds the ${n}-character cap.`,actualLength:e.length,maxLength:n}:{ok:!0,sectionKey:e,payload:i,truncated:!1}}let a=Array.from(i.q.prefix??``),o=Array.from(i.q.suffix??``),s=!1,c=a.length>32?(s=!0,a.slice(-32)):a,l=o.length>32?(s=!0,o.slice(0,32)):o,u=Fb(i,i.q.exact,c.join(``),l.join(``)),d=jb(u);if(d.length<=n)return{ok:!0,sectionKey:d,payload:u,truncated:s};let f=Fb(i,i.q.exact,``,``),p=jb(f);if(p.length<=n){let e=0,t=Math.max(c.length,l.length),r=f,a=p;for(;e<=t;){let o=e+t>>>1,s=o>0?c.slice(-Math.min(o,c.length)).join(``):``,u=o>0?l.slice(0,Math.min(o,l.length)).join(``):``,d=Fb(i,i.q.exact,s,u),f=jb(d);f.length<=n?(r=d,a=f,e=o+1):t=o-1}return{ok:!0,sectionKey:a,payload:r,truncated:!0}}let m=Array.from(i.q.exact),h=Fb(i,m[0],``,``),g=jb(h);if(g.length>n)return{ok:!1,code:`ANCHOR_TOO_LONG`,message:`Minimal encoded anchor length (${g.length}) exceeds the ${n}-character cap.`,actualLength:g.length,maxLength:n};let _=1,v=m.length-1,y=h,b=g;for(;_<=v;){let e=_+v>>>1,t=Fb(i,m.slice(0,e).join(``),``,``),r=jb(t);r.length<=n?(y=t,b=r,_=e+1):v=e-1}return{ok:!0,sectionKey:b,payload:y,truncated:!0}}function Lb(e,t){let n=t?.maxLength??2048;if(typeof e!=`string`||e.length===0||e.length>n||!e.startsWith(`a1:`))return null;let r=Ab(e.slice(3));if(!r)return null;let i;try{i=Db.decode(r)}catch{return null}let a;try{a=JSON.parse(i)}catch{return null}let o=Pb(a);return o.ok?o.payload:null}function Rb(e,t){let n=Date.parse(e),r=Date.parse(t);return Number.isFinite(n)&&Number.isFinite(r)&&n!==r?n-r:e<t?-1:+(e>t)}function zb(e,t){if(e.length===0)return[];let n=new Map;e.forEach((e,t)=>{let r=n.get(e.threadId);r?r.push({comment:e,order:t}):n.set(e.threadId,[{comment:e,order:t}])});let r=t?.decodeAnchor??Lb,i=[];for(let[e,t]of n){t.sort((e,t)=>{let n=Rb(e.comment.createdAt,t.comment.createdAt);return n===0?e.order-t.order:n});let n=t.map(e=>e.comment),a=n[0],o=n.some(e=>e.state===`closed`)?`closed`:`open`,s;for(let e of n){let t=e.target.sectionKey;if(typeof t==`string`&&t.length>0){s=t;break}}let c=bb(a.target),l={kind:c.kind,id:c.id};c.recordType!==void 0&&(l.recordType=c.recordType),s!==void 0&&(l.sectionKey=s);let u;for(let e=n.length-1;e>=0;e--){let t=n[e].assignedTo;if(typeof t==`string`&&t.length>0){u=t;break}}let d={threadId:e,target:l,comments:n,state:o,anchor:s!==void 0&&r?r(s):null};s!==void 0&&(d.sectionKey=s),u!==void 0&&(d.assignedTo=u),i.push({thread:d,earliestAt:a.createdAt})}return i.sort((e,t)=>{let n=Rb(e.earliestAt,t.earliestAt);return n===0?e.thread.threadId<t.thread.threadId?-1:+(e.thread.threadId>t.thread.threadId):n}),i.map(e=>e.thread)}function Bb(e,t){return t?e.comments.some(e=>e.authorship.author.actorId===t.actorId):!1}function Vb(e,t,n){switch(t){case`all`:return[...e];case`open`:return e.filter(e=>e.state===`open`);case`resolved`:return e.filter(e=>e.state===`closed`);case`mine`:return e.filter(e=>Bb(e,n))}}function Hb(e,t){let n=0,r=0,i=0;for(let a of e)a.state===`open`?n+=1:r+=1,Bb(a,t)&&(i+=1);return{all:e.length,open:n,resolved:r,mine:i}}function Ub(e,t){if(t==null)return;if(typeof t==`string`)return t.length>0?t:void 0;if(t instanceof Map){let n=t.get(e);return typeof n==`string`&&n.length>0?n:void 0}let n=t[e];return typeof n==`string`&&n.length>0?n:void 0}function Wb(e,t,n){return e.authorship.author.actorId===t.actorId?!1:n==null||n.length===0||Rb(e.createdAt,n)>0}function Gb(e,t,n){let r=Ub(e.threadId,n);return e.comments.some(e=>Wb(e,t,r))}function Kb(e,t,n){let r=Ub(e.threadId,n),i=0;for(let n of e.comments)Wb(n,t,r)&&(i+=1);return i}function qb(e,t,n){let r=0;for(let i of e)Gb(i,t,n)&&(r+=1);return r}function Jb(e,t){if(e.length===0)return[];let n=Math.max(0,t?.gap??28),r=t?.minY??0,i=t?.maxY!==void 0&&Number.isFinite(t.maxY)?Math.max(r,t.maxY):void 0,a=e.map((e,t)=>({pin:e,order:t})).sort((e,t)=>e.pin.targetY===t.pin.targetY?e.order-t.order:e.pin.targetY-t.pin.targetY),o=a.length,s=a.map(e=>Math.max(n,e.pin.height??n)),c=Array(o);c[0]=Math.max(r,a[0].pin.targetY);for(let e=1;e<o;e++)c[e]=Math.max(a[e].pin.targetY,c[e-1]+s[e-1]);if(i!==void 0&&c[o-1]>i){c[o-1]=i;for(let e=o-2;e>=0;e--){let t=c[e+1]-s[e];c[e]>t&&(c[e]=t)}if(c[0]<r){if(o===1||i===r)for(let e=0;e<o;e++)c[e]=r;else{let e=i-r;for(let t=0;t<o;t++)c[t]=r+t/(o-1)*e}}}return a.map((e,t)=>({id:e.pin.id,targetY:e.pin.targetY,y:c[t],index:t+1}))}var Yb=`data-anchor-id`,Xb=1,Zb=3,Qb=4;function $b(e){let t=e.ownerDocument.createTreeWalker(e,Qb),n=[],r=[],i=0,a=t.nextNode();for(;a!==null;){if(a.nodeType===Zb){let e=a,t=e.data;t.length>0&&(n.push({node:e,start:i,end:i+t.length}),r.push(t),i+=t.length)}a=t.nextNode()}return{fullText:r.join(``),segments:n}}function ex(e,t,n,r){if(t.length===0||r<=n)return null;let i=null,a=0,o=null,s=0;for(let e of t)if(i===null&&n>=e.start&&n<e.end&&(i=e.node,a=n-e.start),r>e.start&&r<=e.end){o=e.node,s=r-e.start;break}if(i===null||o===null)return null;let c=e.createRange();return c.setStart(i,a),c.setEnd(o,s),c}function tx(e,t){let n=e;for(;n!==null;){if(n.nodeType===Xb&&t.contains(n))return n;n=n.parentNode}return t}function nx(e,t){let n=e;for(;n!==null&&t.contains(n)&&n!==t;){let e=n.getAttribute(Yb);if(typeof e==`string`&&e.length>0)return e;n=n.parentElement}}function rx(e){return e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`)}function ix(e,t){if(t===e)return`:scope`;let n=[],r=t;for(;r!==null&&r!==e;){let e=r.parentElement;if(e===null)break;let t=r.localName.toLowerCase(),i=1,a=r.previousElementSibling;for(;a!==null;)a.localName.toLowerCase()===t&&(i+=1),a=a.previousElementSibling;n.push(`${rx(t)}:nth-of-type(${i})`),r=e}return n.reverse(),n.join(` > `)}function ax(e,t){if(e.getAttribute(Yb)===t)return e;let n=e.querySelectorAll(`[${Yb}]`);for(let e=0;e<n.length;e++){let r=n[e];if(r.getAttribute(Yb)===t)return r}return null}function ox(e,t){if(t===`:scope`)return e;try{let n=e.querySelector(`:scope > ${t}`);if(n!==null)return n}catch{}try{return e.querySelector(t)}catch{return null}}function sx(e){return typeof e==`object`&&!!e&&`rangeCount`in e&&typeof e.getRangeAt==`function`}function cx(e,t){let n=Array.from(e);return n.length<=t?e:n.slice(-t).join(``)}function lx(e,t){let n=Array.from(e);return n.length<=t?e:n.slice(0,t).join(``)}function ux(e,t,n){if(typeof n!=`string`||n.length===0)throw new Ob(`artifactVersion must be a non-empty string.`);let r;if(sx(t)){if(t.rangeCount===0)return null;r=t.getRangeAt(0)}else r=t;if(r.collapsed||!e.contains(r.commonAncestorContainer))return null;let i=r.toString();if(i.length===0)return null;let a=e.ownerDocument,{fullText:o}=$b(e),s=a.createRange();s.selectNodeContents(e),s.setEnd(r.startContainer,r.startOffset);let c=s.toString().length,l=c+i.length,u=cx(o.slice(0,c),32),d=lx(o.slice(l),32),f={exact:i};u.length>0&&(f.prefix=u),d.length>0&&(f.suffix=d);let p=tx(r.commonAncestorContainer,e),m=p===e?void 0:ix(e,p),h=nx(p,e),g={t:`text`,q:f,pos:{start:c,end:l},v:n};return m!==void 0&&m.length>0&&(g.sel=m),h!==void 0&&(g.aid=h),g}function dx(e,t,n){if(typeof n!=`string`||n.length===0)throw new Ob(`artifactVersion must be a non-empty string.`);if(!e.contains(t))return null;let r=ix(e,t),i=nx(t,e),a={t:`element`,sel:r,v:n};return typeof i==`string`&&i.length>0&&(a.aid=i),a}function fx(e,t){let n=Math.min(e.length,t.length),r=0;for(let i=1;i<=n&&e.charCodeAt(e.length-i)===t.charCodeAt(t.length-i);i++)r+=1;return r}function px(e,t){let n=Math.min(e.length,t.length),r=0;for(let i=0;i<n&&e.charCodeAt(i)===t.charCodeAt(i);i++)r+=1;return r}function mx(e,t){if(t===e)return 0;let n=e.ownerDocument.createRange();return n.selectNodeContents(e),n.setEndBefore(t),n.toString().length}function hx(e,t,n){let{fullText:r,segments:i}=$b(t),a=n.q.exact;if(a.length===0||r.length===0)return null;let o=[],s=0;for(;s<=r.length-a.length;){let e=r.indexOf(a,s);if(e===-1)break;o.push(e),s=e+1}if(o.length===0)return null;let c=n.q.prefix??``,l=n.q.suffix??``,u=mx(e,t),d=n.pos?.start,f=o[0],p=-1,m=1/0;for(let e of o){let t=0;c.length>0&&(t+=fx(r.slice(0,e),c)),l.length>0&&(t+=px(r.slice(e+a.length),l));let n=d===void 0?e:Math.abs(u+e-d);(t>p||t===p&&n<m)&&(p=t,m=n,f=e)}let h=ex(t.ownerDocument,i,f,f+a.length);return h===null?null:{range:h,element:tx(h.commonAncestorContainer,e)}}function gx(e){let t=[],n=[],r=[],i=0,a=-1,o=-1;for(;i<e.length;){let s=e[i];if(/\s/.test(s)){t.length>0&&(a===-1&&(a=i),o=i+1),i+=1;continue}a!==-1&&(t.push(` `),n.push(a),r.push(o),a=-1,o=-1);let c=s.toLowerCase();for(let e=0;e<c.length;e++)t.push(c[e]),n.push(i),r.push(i+1);i+=1}return{normalized:t.join(``),rawStarts:n,rawEnds:r}}function _x(e){return e.trim().replace(/\s+/g,` `).toLowerCase()}function vx(e,t,n){let r=_x(n.q.exact);if(r.length===0)return null;let{fullText:i,segments:a}=$b(t);if(i.length===0)return null;let o=gx(i);if(o.normalized.length<r.length)return null;let s=[],c=0;for(;c<=o.normalized.length-r.length;){let e=o.normalized.indexOf(r,c);if(e===-1)break;s.push(e),c=e+1}if(s.length===0)return null;let l=n.q.prefix?_x(n.q.prefix):``,u=n.q.suffix?_x(n.q.suffix):``,d=mx(e,t),f=n.pos?.start,p=s[0],m=-1,h=1/0;for(let e of s){let t=0;l.length>0&&(t+=fx(o.normalized.slice(0,e).trimEnd(),l)),u.length>0&&(t+=px(o.normalized.slice(e+r.length).trimStart(),u));let n=o.rawStarts[e],i=f===void 0?n:Math.abs(d+n-f);(t>m||t===m&&i<h)&&(m=t,h=i,p=e)}let g=o.rawStarts[p],_=o.rawEnds[p+r.length-1],v=ex(t.ownerDocument,a,g,_);return v===null?null:{range:v,element:tx(v.commonAncestorContainer,e)}}function yx(e,t,n){let r=n?.artifactVersion!==void 0&&n.artifactVersion!==t.v;if(t.t===`region`)return{status:`resolved`,kind:`region`,strategy:`region`,element:e,rect:{...t.rect},range:null,versionChanged:r};if(t.t===`element`){if(t.aid!==void 0){let n=ax(e,t.aid);return n===null?{status:`orphan`,kind:`element`,reason:`not-found`,element:null,range:null}:{status:`resolved`,kind:`element`,strategy:`aid`,element:n,range:null,versionChanged:r}}let n=ox(e,t.sel);return n===null?{status:`orphan`,kind:`element`,reason:`not-found`,element:null,range:null}:{status:`resolved`,kind:`element`,strategy:`selector`,element:n,range:null,versionChanged:r}}let i=null;if(t.aid!==void 0&&(i=ax(e,t.aid),i!==null)){let n=hx(e,i,t);if(n!==null)return{status:`resolved`,kind:`text`,strategy:`aid`,element:n.element,range:n.range,versionChanged:r};let a=vx(e,i,t);if(a!==null)return{status:`resolved`,kind:`text`,strategy:`aid`,element:a.element,range:a.range,versionChanged:r}}let a=hx(e,e,t);if(a!==null)return{status:`resolved`,kind:`text`,strategy:`text-quote`,element:a.element,range:a.range,versionChanged:r};if(t.sel!==void 0){let n=ox(e,t.sel);if(n!==null){let i=vx(e,n,t);if(i!==null)return{status:`resolved`,kind:`text`,strategy:`selector`,element:i.element,range:i.range,versionChanged:r}}}let o=vx(e,e,t);return o===null?i!==null&&i!==e?{status:`resolved`,kind:`text`,strategy:`aid`,element:i,range:null,versionChanged:r}:{status:`orphan`,kind:`text`,reason:`not-found`,element:null,range:null}:{status:`resolved`,kind:`text`,strategy:`fuzzy-quote`,element:o.element,range:o.range,versionChanged:r}}var bx=/^Ref:\s*(decision|track):([^\s]+)\s*$/i,xx=/^Resolved\s+in\s+([^\r\n]+?)\s*$/i,Sx=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,Cx=/^(?:rgba?|hsla?|oklch|oklab)\([0-9.,%\s/+deg-]+\)$/i,wx=/^var\(--st-[a-zA-Z0-9-]+\)$/;function Tx(e){if(typeof e!=`string`)return xb;let t=e.trim();return Sx.test(t)||Cx.test(t)||wx.test(t)?t:xb}function Ex(e){let t=e.trim();if(t.length===0)return{safe:!1,external:!1,href:``};if(t.startsWith(`/`)||t.startsWith(`#`))return{safe:!0,external:!1,href:t};try{let e=new URL(t),n=e.protocol.toLowerCase();if(n===`https:`||n===`http:`||n===`mailto:`)return{safe:!0,external:n!==`mailto:`,href:e.href}}catch{return{safe:!1,external:!1,href:``}}return{safe:!1,external:!1,href:``}}function Dx(e){let t=e.replace(/\r\n?/g,`
|
|
841
|
+
`).split(`
|
|
842
|
+
`).map(e=>e.trim()).find(e=>e.length>0);if(!t)return null;let n=xx.exec(t);if(!n)return null;let r=n[1].trim();return r.length>0?{version:r}:null}function Ox(e){let t=[],n=0,r=e=>{if(e.length===0)return;let n=t[t.length-1];n&&n.type===`text`?n.text+=e:t.push({type:`text`,text:e})};for(;n<e.length;){let i=e[n];if(i==="`"){let r=e.indexOf("`",n+1);if(r>n+1){t.push({type:`code`,text:e.slice(n+1,r)}),n=r+1;continue}}if(i===`[`){let i=e.indexOf(`]`,n+1);if(i>n+1&&e[i+1]===`(`){let a=e.indexOf(`)`,i+2);if(a>i+2){let o=e.slice(n+1,i),s=Ex(e.slice(i+2,a));s.safe?t.push({type:`link`,label:o,href:s.href,external:s.external}):r(o),n=a+1;continue}}}if(i===`*`&&e[n+1]===`*`){let r=e.indexOf(`**`,n+2);if(r>n+2){t.push({type:`bold`,children:Ox(e.slice(n+2,r))}),n=r+2;continue}}if(i===`~`&&e[n+1]===`~`){let r=e.indexOf(`~~`,n+2);if(r>n+2){t.push({type:`strike`,children:Ox(e.slice(n+2,r))}),n=r+2;continue}}if(i===`*`||i===`_`){let r=n>0?e[n-1]:``;if((i===`*`||r===``||/\s|[([{]/.test(r))&&e[n+1]!==i&&e[n+1]!==` `){let r=e.indexOf(i,n+1),a=r>=0&&r+1<e.length?e[r+1]:``,o=i===`*`||a===``||/\s|[)\]}.,!?;:]/.test(a);if(r>n+1&&e[r-1]!==` `&&o){t.push({type:`italic`,children:Ox(e.slice(n+1,r))}),n=r+1;continue}}}r(i),n+=1}return t}function kx(e){let t=[];return e.forEach((e,n)=>{n>0&&t.push({type:`break`}),t.push(...Ox(e))}),t}function Ax(e){let t=e.replace(/\r\n?/g,`
|
|
843
|
+
`),n=t.split(`
|
|
844
|
+
`),r=[],i=[];for(let e of n){let t=bx.exec(e.trim());t?r.push({kind:t[1].toLowerCase(),id:t[2],raw:e.trim()}):i.push(e)}let a=Dx(t),o=[],s=0;for(;s<i.length;){let e=i[s].trim();if(e.length===0){s+=1;continue}if(e.startsWith("```")){let t=e.slice(3).trim(),n=[];for(s+=1;s<i.length&&!i[s].trim().startsWith("```");)n.push(i[s]),s+=1;s<i.length&&(s+=1),o.push({type:`codeblock`,...t.length>0?{lang:t}:{},code:n.join(`
|
|
845
|
+
`)});continue}if(e.startsWith(`>`)){let e=[];for(;s<i.length&&i[s].trim().startsWith(`>`);)e.push(i[s].trim().replace(/^>\s?/,``)),s+=1;o.push({type:`blockquote`,inlines:kx(e)});continue}if(/^[-*]\s+/.test(e)){let e=[];for(;s<i.length&&/^[-*]\s+/.test(i[s].trim());)e.push(Ox(i[s].trim().replace(/^[-*]\s+/,``))),s+=1;o.push({type:`list`,ordered:!1,items:e});continue}if(/^\d+\.\s+/.test(e)){let e=[];for(;s<i.length&&/^\d+\.\s+/.test(i[s].trim());)e.push(Ox(i[s].trim().replace(/^\d+\.\s+/,``))),s+=1;o.push({type:`list`,ordered:!0,items:e});continue}let t=[];for(;s<i.length;){let e=i[s],n=e.trim();if(n.length===0||n.startsWith("```")||n.startsWith(`>`)||/^[-*]\s+/.test(n)||/^\d+\.\s+/.test(n))break;t.push(e),s+=1}o.push({type:`paragraph`,inlines:kx(t)})}return{blocks:o,refs:r,resolution:a}}function jx(e,t){let n=e.replace(/\s+/g,` `).trim(),r=Array.from(n);return r.length<=t?n:t<=1?`…`:`${r.slice(0,t-1).join(``)}…`}function Mx(e,t=140){return e===null?`Unattached`:e.t===`text`?jx(e.q.exact,t):e.t===`element`?jx(e.aid?`#${e.aid}`:e.sel,t):jx(`Region (${Math.round(e.rect.x*100)}%, ${Math.round(e.rect.y*100)}%)`,t)}function Nx(e){let{index:t,count:n,unreadCount:r=0,resolved:i=!1,excerpt:a}=e,o=[`Thread ${t}`,`${n} ${n===1?`comment`:`comments`}`];return r>0&&o.push(`${r} unread`),i&&o.push(`resolved`),a&&a.trim().length>0&&o.push(`on '${jx(a,60)}'`),o.join(`, `)}function Px(e){return e instanceof Cb?e.code===`SECTION_KEY_TOO_LONG`?`Selection anchor exceeds the ${_b}-character limit.`:e.message:e instanceof Error?/section_key_too_long|SECTION_KEY_TOO_LONG|ANCHOR_TOO_LONG/i.test(e.message)||e.code===`section_key_too_long`?`Selection anchor exceeds the ${_b}-character limit.`:e.message:`Action failed. Please try again.`}var Fx=[`a[href]`,`button:not([disabled])`,`textarea:not([disabled])`,`input:not([disabled]):not([type='hidden'])`,`select:not([disabled])`,`[tabindex]:not([tabindex='-1'])`].join(`, `);function Ix(e){return Array.from(e.querySelectorAll(Fx)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`)}function Lx(e,t){if(e.key!==`Tab`||!t)return;let n=Ix(t);if(n.length===0)return;let r=n[0],i=n[n.length-1],a=t.ownerDocument.activeElement;e.shiftKey?(!a||a===r||!t.contains(a))&&(e.preventDefault(),i.focus()):(!a||a===i||!t.contains(a))&&(e.preventDefault(),r.focus())}var Rx=Z(`<span class="st-review-authorship__initials svelte-ct96qr"> </span>`),zx=Z(`<span data-actor-kind="sponsor" aria-hidden="true"><span class="st-review-authorship__initials svelte-ct96qr"> </span></span>`),Bx=Z(`<span aria-hidden="true"><!></span> <!>`,1),Vx=Z(`<span class="st-review-authorship__sponsor svelte-ct96qr"> </span>`),Hx=Z(`<span class="st-review-authorship__label svelte-ct96qr"><span class="st-review-authorship__name svelte-ct96qr"> </span> <!> <!></span>`),Ux=Z(`<div><!> <!></div>`);function Wx(e,t){Eh(t,!0);let n=Ly(t,`size`,3,`sm`),r=Ly(t,`showLabel`,3,!0),i=Py(t,[`$$slots`,`$$events`,`$$legacy`,`author`,`sponsor`,`size`,`showLabel`,`class`]),a=K(()=>t.author.kind!==`human`),o=K(()=>Tx(t.author.color)),s=K(()=>t.sponsor?Tx(t.sponsor.color):void 0),c=K(()=>$y(t.author.displayLabel)),l=K(()=>t.sponsor?$y(t.sponsor.displayLabel):``),u=K(()=>n()===`sm`?13:n()===`md`?16:n()===`lg`?18:22),d=K(()=>t.author.kind===`nhi`?`NHI`:`Agent`),f=K(()=>t.sponsor?`Comment by ${t.author.displayLabel}, ${t.author.kind}, on behalf of ${t.sponsor.displayLabel}`:X(a)?`Comment by ${t.author.displayLabel}, ${t.author.kind}`:`Comment by ${t.author.displayLabel}`),p=K(()=>[`st-review-authorship`,`st-review-authorship--${n()}`,t.class].filter(Boolean).join(` `));var m=Ux();wy(m,()=>({...i,class:X(p),"data-author-kind":t.author.kind}),void 0,void 0,void 0,`svelte-ct96qr`);var h=J(m);nb(h,{get size(){return n()},class:`st-review-authorship__stack`,role:`img`,get"aria-label"(){return X(f)},children:(e,r)=>{var i=Bx(),d=Gg(i);let f,p;var m=J(d),h=e=>{Hy(e,{get size(){return X(u)},strokeWidth:2,"aria-hidden":`true`})},g=e=>{Gy(e,{get size(){return X(u)},strokeWidth:2,"aria-hidden":`true`})},_=e=>{var t=Rx(),n=J(t,!0);G(t),p_(()=>Mv(n,X(c))),Q(e,t)};$(m,e=>{t.author.kind===`agent`?e(h):t.author.kind===`nhi`?e(g,1):e(_,-1)}),G(d);var v=Y(d,2),y=e=>{var t=zx();let r;var i=J(t),a=J(i,!0);G(i),G(t),p_(()=>{oy(t,1,`st-review-authorship__vignette st-review-authorship__vignette--${n()??``} st-review-authorship__vignette--sponsor`,`svelte-ct96qr`),r=cy(t,``,r,{"--st-review-actor-color":X(s)}),Mv(a,X(l))}),Q(e,t)};$(v,e=>{t.sponsor&&e(y)}),p_(()=>{f=oy(d,1,`st-review-authorship__vignette st-review-authorship__vignette--${n()??``}`,`svelte-ct96qr`,f,{"st-review-authorship__vignette--agent":X(a)}),Sy(d,`data-actor-kind`,t.author.kind),p=cy(d,``,p,{"--st-review-actor-color":X(o)})}),Q(e,i)},$$slots:{default:!0}});var g=Y(h,2),_=e=>{var n=Hx(),r=J(n),i=J(r,!0);G(r);var o=Y(r,2),s=e=>{ib(e,{size:`sm`,tone:`info`,class:`st-review-authorship__kind`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,X(d))),Q(e,n)},$$slots:{default:!0}})};$(o,e=>{X(a)&&e(s)});var c=Y(o,2),l=e=>{var n=Vx(),r=J(n);G(n),p_(()=>Mv(r,`· on behalf of ${t.sponsor.displayLabel??``}`)),Q(e,n)};$(c,e=>{t.sponsor&&e(l)}),G(n),p_(()=>Mv(i,t.author.displayLabel)),Q(e,n)};$(g,e=>{r()&&e(_)}),G(m),Q(e,m),Dh()}var Gx=Z(`<span class="st-review-pin__count svelte-8s53ub" aria-hidden="true"> </span>`),Kx=Z(`<span class="st-review-pin__unread-dot svelte-8s53ub" aria-hidden="true"></span>`),qx=Z(`<button><span class="st-review-pin__glyph svelte-8s53ub" aria-hidden="true"><!></span> <!> <!></button>`);function Jx(e,t){Eh(t,!0);let n=Ly(t,`count`,3,1),r=Ly(t,`unread`,3,!1),i=Ly(t,`resolved`,3,!1),a=Ly(t,`active`,3,!1),o=Ly(t,`variant`,3,`inline`),s=Py(t,[`$$slots`,`$$events`,`$$legacy`,`index`,`count`,`unread`,`resolved`,`active`,`label`,`variant`,`tabindex`,`class`,`onActivate`,`onclick`]),c=K(()=>t.tabindex??(o()===`margin`?-1:0)),l=K(()=>[`st-review-pin`,`st-review-pin--${o()}`,i()?`st-review-pin--resolved`:void 0,a()?`st-review-pin--active`:void 0,r()?`st-review-pin--unread`:void 0,t.class].filter(Boolean).join(` `));function u(e){t.onclick?.(e),t.onActivate?.()}var d=qx();wy(d,()=>({...s,type:`button`,class:X(l),tabindex:X(c),"aria-label":t.label,"aria-pressed":a()?`true`:`false`,"data-pin-index":t.index,"data-pin-variant":o(),"data-resolved":i()?`true`:`false`,"data-unread":r()?`true`:`false`,"data-active":a()?`true`:`false`,onclick:u}),void 0,void 0,void 0,`svelte-8s53ub`);var f=J(d),p=J(f),m=e=>{Uy(e,{size:13,strokeWidth:2.5,"aria-hidden":`true`})},h=e=>{var n=kv();p_(()=>Mv(n,t.index)),Q(e,n)};$(p,e=>{i()?e(m):e(h,-1)}),G(f);var g=Y(f,2),_=e=>{var t=Gx(),r=J(t,!0);G(t),p_(()=>Mv(r,n())),Q(e,t)};$(g,e=>{n()>1&&e(_)});var v=Y(g,2),y=e=>{Q(e,Kx())};$(v,e=>{r()&&e(y)}),G(d),Q(e,d),Dh()}var Yx=Z(`<p class="st-review-composer__quote svelte-12chpsi"> </p>`),Xx=Z(`<div class="st-review-composer__error svelte-12chpsi" role="alert"> </div>`),Zx=Z(`<form><div class="st-review-composer__header svelte-12chpsi"><!></div> <!> <div class="st-review-composer__field svelte-12chpsi"><textarea class="st-review-composer__textarea svelte-12chpsi" rows="3"></textarea></div> <!> <div class="st-review-composer__footer svelte-12chpsi"><span class="st-review-composer__hint svelte-12chpsi"> </span> <div class="st-review-composer__actions svelte-12chpsi"><!> <!></div></div></form>`);function Qx(e,t){let n=jv();Eh(t,!0);let r=Ly(t,`placeholder`,3,`Add a comment…`),i=Ly(t,`submitLabel`,3,`Comment`),a=Ly(t,`cancelLabel`,3,`Cancel`),o=Ly(t,`initialBody`,3,``),s=Ly(t,`autofocus`,3,!0),c=Ly(t,`trapFocus`,3,!0),l=Ly(t,`disabled`,3,!1),u=Ly(t,`submitting`,3,!1),d=Ly(t,`anchorError`,3,null),f=Ly(t,`error`,3,null),p=Ly(t,`label`,3,`Comment body`),m=Py(t,[`$$slots`,`$$events`,`$$legacy`,`author`,`sponsor`,`placeholder`,`submitLabel`,`cancelLabel`,`initialBody`,`autofocus`,`trapFocus`,`disabled`,`submitting`,`anchorError`,`error`,`quotePreview`,`label`,`clearOnSubmit`,`class`,`onSubmit`,`onCancel`,`onDraftChange`]),h=Og(void 0),g=Og(void 0),_=Og(Pg(rv(()=>o()))),v=Og(null),y=Og(!1),b=!1,x=`st-review-composer-err-${n}`,S=K(()=>u()||X(y)),C=K(()=>d()??X(v)??f()),w=K(()=>t.clearOnSubmit??o().length===0),T=K(()=>[`st-review-composer`,t.class].filter(Boolean).join(` `));s_(()=>{s()&&X(g)&&!b&&(b=!0,X(g).focus())}),s_(()=>{let e=X(h);if(!e)return;let n=n=>{n.key===`Escape`?t.onCancel&&(n.preventDefault(),n.stopPropagation(),k()):c()&&n.key===`Tab`&&(n.stopPropagation(),Lx(n,e))};return e.addEventListener(`keydown`,n),()=>e.removeEventListener(`keydown`,n)});function E(){X(v)!==null&&q(v,null),t.onDraftChange?.(X(_))}async function D(){if(l()||X(S)||d())return;let e=X(_).trim();if(e.length===0){q(v,`Comment cannot be empty.`),X(g)?.focus();return}if(q(v,null),!t.onSubmit)return;let n=X(w),r=X(h)?.ownerDocument??(typeof document<`u`?document:null),i=!1;q(y,!0);try{await t.onSubmit(e),n&&(q(_,``),t.onDraftChange?.(``))}catch(e){i=!0,q(v,Px(e),!0)}finally{q(y,!1)}if(await ev(),X(g)?.isConnected&&!l()){let e=r?.activeElement??null,t=e===null||e===r?.body||X(h)!==void 0&&X(h).contains(e);(i||t)&&X(g).focus()}}function O(e){e.preventDefault(),D()}function k(){X(S)||t.onCancel?.()}function A(e){(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),e.stopPropagation(),D())}var j=Zx();wy(j,()=>({...m,class:X(T),novalidate:!0,onsubmit:O}),void 0,void 0,void 0,`svelte-12chpsi`);var M=J(j);Wx(J(M),{get author(){return t.author},get sponsor(){return t.sponsor},size:`sm`}),G(M);var ee=Y(M,2),te=e=>{var n=Yx(),r=J(n,!0);G(n),p_(()=>Mv(r,t.quotePreview)),Q(e,n)};$(ee,e=>{t.quotePreview&&e(te)});var ne=Y(ee,2),N=J(ne);Zg(N),My(N,e=>q(g,e),()=>X(g)),G(ne);var P=Y(ne,2),F=e=>{var t=Xx(),n=J(t,!0);G(t),p_(()=>{Sy(t,`id`,x),Mv(n,X(C))}),Q(e,t)};$(P,e=>{X(C)&&e(F)});var I=Y(P,2),re=J(I),L=J(re,!0);G(re);var R=Y(re,2),ie=J(R),z=e=>{ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(S)},onclick:k,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,a())),Q(e,n)},$$slots:{default:!0}})};$(ie,e=>{t.onCancel&&e(z)});var ae=Y(ie,2);{let e=K(()=>l()||X(S));ob(ae,{type:`submit`,variant:`primary`,size:`sm`,get disabled(){return X(e)},children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,i())),Q(e,n)},$$slots:{default:!0}})}G(R),G(I),G(j),My(j,e=>q(h,e),()=>X(h)),p_(()=>{Sy(N,`placeholder`,r()),N.disabled=l()||X(S),Sy(N,`aria-label`,p()),Sy(N,`aria-invalid`,X(C)?`true`:void 0),Sy(N,`aria-describedby`,X(C)?x:void 0),Mv(L,t.onCancel?`Cmd/Ctrl+Enter to submit · Esc to cancel`:`Cmd/Ctrl+Enter to submit`)}),yv(`input`,N,E),yv(`keydown`,N,A),Oy(N,()=>X(_),e=>q(_,e)),Q(e,j),Dh()}bv([`input`,`keydown`]);var $x=(e,t=vm)=>{var n=Av();Uv(Gg(n),17,t,zv,(e,t)=>{var n=Av(),r=Gg(n),i=e=>{var n=kv();p_(()=>Mv(n,X(t).text)),Q(e,n)},a=e=>{Q(e,eS())},o=e=>{var n=tS(),r=J(n,!0);G(n),p_(()=>Mv(r,X(t).text)),Q(e,n)},s=e=>{var n=nS();$x(J(n),()=>X(t).children),G(n),Q(e,n)},c=e=>{var n=rS();$x(J(n),()=>X(t).children),G(n),Q(e,n)},l=e=>{var n=iS();$x(J(n),()=>X(t).children),G(n),Q(e,n)},u=e=>{var n=aS(),r=J(n,!0);G(n),p_(()=>{Sy(n,`href`,X(t).href),Sy(n,`target`,X(t).external?`_blank`:void 0),Sy(n,`rel`,X(t).external?`noopener noreferrer`:void 0),Mv(r,X(t).label)}),Q(e,n)};$(r,e=>{X(t).type===`text`?e(i):X(t).type===`break`?e(a,1):X(t).type===`code`?e(o,2):X(t).type===`bold`?e(s,3):X(t).type===`italic`?e(c,4):X(t).type===`strike`?e(l,5):X(t).type===`link`&&e(u,6)}),Q(e,n)}),Q(e,n)},eS=Z(`<br/>`),tS=Z(`<code class="st-review-md__code svelte-144zrs4"> </code>`),nS=Z(`<strong><!></strong>`),rS=Z(`<em><!></em>`),iS=Z(`<del><!></del>`),aS=Z(`<a class="st-review-md__link svelte-144zrs4"> </a>`),oS=Z(`<header class="st-review-thread__header svelte-144zrs4"><!></header>`),sS=Z(`<span class="st-review-thread__assignee svelte-144zrs4"> </span>`),cS=Z(`<header class="st-review-thread__header svelte-144zrs4"><div class="st-review-thread__meta svelte-144zrs4"><p class="st-review-thread__anchor svelte-144zrs4"> </p> <div class="st-review-thread__badges svelte-144zrs4"><!> <!></div></div> <div class="st-review-thread__header-actions svelte-144zrs4"><!> <!></div></header>`),lS=Z(`<div class="st-review-thread__error svelte-144zrs4" role="alert"> </div>`),uS=Z(`<span class="st-review-thread__edited svelte-144zrs4">edited</span>`),dS=Z(`<a class="st-review-thread__run-link svelte-144zrs4"><!> <span> </span></a>`),fS=Z(`<div class="st-review-thread__item-actions svelte-144zrs4"><!> <!></div>`),pS=Z(`<div class="st-review-thread__resolution-banner svelte-144zrs4"><!> <span> </span></div>`),mS=Z(`<div class="st-review-thread__edit-form"><!></div>`),hS=Z(`<p class="st-review-md__p svelte-144zrs4"><!></p>`),gS=Z(`<pre class="st-review-md__pre svelte-144zrs4"><code> </code></pre>`),_S=Z(`<blockquote class="st-review-md__quote svelte-144zrs4"><!></blockquote>`),vS=Z(`<li><!></li>`),yS=Z(`<ol class="st-review-md__list svelte-144zrs4"></ol>`),bS=Z(`<li><!></li>`),xS=Z(`<ul class="st-review-md__list svelte-144zrs4"></ul>`),SS=Z(`<a class="st-review-ref-chip svelte-144zrs4"><!> <span> </span></a>`),CS=Z(`<div class="st-review-thread__refs svelte-144zrs4"></div>`),wS=Z(`<div class="st-review-thread__body svelte-144zrs4"><!></div> <!>`,1),TS=Z(`<li><div class="st-review-thread__item-header svelte-144zrs4"><!> <div class="st-review-thread__item-meta svelte-144zrs4"><time class="st-review-thread__time svelte-144zrs4"> </time> <!> <!> <!></div></div> <!> <!></li>`),ES=Z(`<!> <span>Reopen</span>`,1),DS=Z(`<div class="st-review-thread__resolved-notice svelte-144zrs4"><span>Comment resolved. Reopen to reply.</span> <!></div>`),OS=Z(`<div class="st-review-thread__reply"><!></div>`),kS=Z(`<section><!> <!> <ol class="st-review-thread__list svelte-144zrs4"></ol> <!></section>`);function AS(e,t){Eh(t,!0);let n=Ly(t,`canModerate`,3,!1),r=Ly(t,`canReply`,3,!0),i=Ly(t,`readState`,3,null),a=Py(t,[`$$slots`,`$$events`,`$$legacy`,`thread`,`currentUser`,`canModerate`,`canReply`,`readState`,`assigneeLabel`,`runHrefBuilder`,`refHrefBuilder`,`class`,`onReply`,`onResolve`,`onReopen`,`onEditComment`,`onDeleteComment`,`onReanchor`,`onRunClick`,`onRefClick`,`header`,`commentBody`]),o=Og(void 0),s=Og(null),c=Og(null),l=Og(null),u=Og(null),d=Og(Pg([])),f=Og(Pg({})),p=Og(!1),m=K(()=>X(u)??t.thread.state),h=K(()=>yb(X(m))),g=K(()=>Mx(t.thread.anchor,140)),_=K(()=>t.thread.anchor===null),v=K(()=>t.thread.comments.filter(e=>!X(d).includes(e.id)).map(e=>{let t=X(f)[e.id];return t===void 0?e:{...e,body:t}})),y=K(()=>{if(i()!==null&&i()!==void 0)return typeof i()==`string`?i():i()instanceof Map?i().get(t.thread.threadId):i()[t.thread.threadId]}),b=K(()=>[`st-review-thread`,X(m)===`closed`?`st-review-thread--resolved`:void 0,t.class].filter(Boolean).join(` `));function x(e){let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):e}function S(e,n){return t.runHrefBuilder?t.runHrefBuilder(e,n):`#run-${encodeURIComponent(e)}`}function C(e){return t.refHrefBuilder?t.refHrefBuilder(e):`#${encodeURIComponent(e.kind)}-${encodeURIComponent(e.id)}`}async function w(){if(t.onResolve&&!X(p)){q(l,null),q(u,`closed`),q(p,!0);try{await t.onResolve(t.thread.threadId)}catch(e){q(l,Px(e),!0)}finally{q(u,null),q(p,!1)}}}async function T(){if(t.onReopen&&!X(p)){q(l,null),q(u,`open`),q(p,!0);try{await t.onReopen(t.thread.threadId)}catch(e){q(l,Px(e),!0)}finally{q(u,null),q(p,!1)}}}async function E(){if(t.onReanchor&&!X(p)){q(l,null),q(p,!0);try{await t.onReanchor(t.thread.threadId)}catch(e){q(l,Px(e),!0)}finally{q(p,!1)}}}function D(e,t){ev().then(()=>{if(e&&X(o)){let t=X(o).querySelectorAll(`[data-comment-id]`);for(let n of t)if(n.getAttribute(`data-comment-id`)===e){let e=n.querySelector(`button[aria-label="Edit comment"]`);if(e){e.focus();return}}}t?.isConnected&&t.focus()})}function O(e,t){q(l,null),q(c,t.currentTarget,!0),q(s,e,!0)}function k(){let e=X(s),t=X(c);q(s,null),q(c,null),D(e,t)}async function A(e,n){if(!t.onEditComment)return;q(l,null);let r={...X(f)};q(f,{...X(f),[e]:n},!0);try{await t.onEditComment(e,n);let r=X(c);q(s,null),q(c,null);let i={...X(f)};delete i[e],q(f,i,!0),D(e,r)}catch(e){throw q(f,r,!0),q(l,Px(e),!0),e}}async function j(e){if(t.onDeleteComment&&!X(p)){q(l,null),q(d,[...X(d),e],!0),q(p,!0);try{await t.onDeleteComment(e)}catch(t){q(d,X(d).filter(t=>t!==e),!0),q(l,Px(t),!0)}finally{q(p,!1)}}}async function M(e){t.onReply&&(q(l,null),await t.onReply(t.thread.threadId,e))}var ee=kS();wy(ee,()=>({...a,class:X(b),"aria-label":`Comment thread ${t.thread.threadId}`,"data-thread-id":t.thread.threadId,"data-thread-state":X(m)}),void 0,void 0,void 0,`svelte-144zrs4`);var te=J(ee),ne=e=>{var n=oS();Yv(J(n),()=>t.header,()=>({thread:t.thread})),G(n),Q(e,n)},N=e=>{var n=cS(),r=J(n),i=J(r),a=J(i,!0);G(i);var o=Y(i,2),s=J(o);{let e=K(()=>X(m)===`closed`?`success`:`info`);ib(s,{size:`sm`,get tone(){return X(e)},class:`st-review-thread__state`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,X(h))),Q(e,n)},$$slots:{default:!0}})}var c=Y(s,2),l=e=>{var n=sS(),r=J(n);G(n),p_(()=>Mv(r,`Assigned to ${t.assigneeLabel??t.thread.assignedTo??``}`)),Q(e,n)};$(c,e=>{t.thread.assignedTo&&e(l)}),G(o),G(r);var u=Y(r,2),d=J(u),f=e=>{ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(p)},onclick:E,children:(e,t)=>{vh(),Q(e,kv(`Re-anchor`))},$$slots:{default:!0}})};$(d,e=>{X(_)&&t.onReanchor&&e(f)});var v=Y(d,2),y=e=>{ob(e,{type:`button`,variant:`secondary`,size:`sm`,get disabled(){return X(p)},onclick:w,children:(e,t)=>{vh(),Q(e,kv(`Resolve`))},$$slots:{default:!0}})},b=e=>{ob(e,{type:`button`,variant:`secondary`,size:`sm`,get disabled(){return X(p)},onclick:T,children:(e,t)=>{vh(),Q(e,kv(`Reopen`))},$$slots:{default:!0}})};$(v,e=>{X(m)===`open`&&t.onResolve?e(y):X(m)===`closed`&&t.onReopen&&e(b,1)}),G(u),G(n),p_(()=>{Sy(i,`title`,X(g)),Mv(a,X(g))}),Q(e,n)};$(te,e=>{t.header?e(ne):e(N,-1)});var P=Y(te,2),F=e=>{var t=lS(),n=J(t,!0);G(t),p_(()=>Mv(n,X(l))),Q(e,t)};$(P,e=>{X(l)&&e(F)});var I=Y(P,2);Uv(I,21,()=>X(v),e=>e.id,(e,r)=>{let i=K(()=>Ax(X(r).body)),a=K(()=>Sb(X(r),t.currentUser,{canModerate:n()})),o=K(()=>Wb(X(r),t.currentUser,X(y))),c=K(()=>X(r).updatedAt!==void 0&&X(r).updatedAt!==X(r).createdAt),l=K(()=>X(s)===X(r).id);var u=TS();let d;var f=J(u),m=J(f);Wx(m,{get author(){return X(r).authorship.author},get sponsor(){return X(r).authorship.sponsor},size:`sm`});var h=Y(m,2),g=J(h),_=J(g,!0);G(g);var v=Y(g,2),b=e=>{var t=uS();p_(()=>Sy(t,`title`,`Edited ${X(r).updatedAt}`)),Q(e,t)};$(v,e=>{X(c)&&e(b)});var w=Y(v,2),T=e=>{var n=dS(),i=J(n);Ky(i,{size:12,strokeWidth:2,"aria-hidden":`true`});var a=Y(i,2),o=J(a);G(a),G(n),p_(e=>{Sy(n,`href`,e),Mv(o,`Run ${X(r).authorship.runId??``}`)},[()=>S(X(r).authorship.runId,X(r))]),yv(`click`,n,e=>{t.onRunClick&&(e.preventDefault(),t.onRunClick(X(r).authorship.runId,X(r)))}),Q(e,n)};$(w,e=>{X(r).authorship.runId&&e(T)});var E=Y(w,2),D=e=>{var n=fS(),i=J(n),a=e=>{cb(e,{size:`sm`,variant:`ghost`,"aria-label":`Edit comment`,get disabled(){return X(p)},onclick:e=>O(X(r).id,e),children:(e,t)=>{Jy(e,{size:14,strokeWidth:2,"aria-hidden":`true`})},$$slots:{default:!0}})};$(i,e=>{t.onEditComment&&e(a)});var o=Y(i,2),s=e=>{cb(e,{size:`sm`,variant:`danger`,"aria-label":`Delete comment`,get disabled(){return X(p)},onclick:()=>j(X(r).id),children:(e,t)=>{Xy(e,{size:14,strokeWidth:2,"aria-hidden":`true`})},$$slots:{default:!0}})};$(o,e=>{t.onDeleteComment&&e(s)}),G(n),Q(e,n)};$(E,e=>{X(a)&&!X(l)&&e(D)}),G(h),G(f);var M=Y(f,2),ee=e=>{var t=pS(),n=J(t);Wy(n,{size:14,strokeWidth:2,"aria-hidden":`true`});var r=Y(n,2),a=J(r);G(r),G(t),p_(()=>Mv(a,`Resolved in ${X(i).resolution.version??``}`)),Q(e,t)};$(M,e=>{X(i).resolution!==null&&e(ee)});var te=Y(M,2),ne=e=>{var t=mS();Qx(J(t),{get author(){return X(r).authorship.author},get sponsor(){return X(r).authorship.sponsor},get initialBody(){return X(r).body},submitLabel:`Save`,cancelLabel:`Cancel`,label:`Edit comment`,autofocus:!0,trapFocus:!0,clearOnSubmit:!1,onSubmit:e=>A(X(r).id,e),onCancel:k}),G(t),Q(e,t)},N=e=>{var n=wS(),a=Gg(n),o=J(a),s=e=>{var n=Av();Yv(Gg(n),()=>t.commentBody,()=>({comment:X(r)})),Q(e,n)},c=e=>{var t=Av();Uv(Gg(t),17,()=>X(i).blocks,zv,(e,t)=>{var n=Av(),r=Gg(n),i=e=>{var n=hS();$x(J(n),()=>X(t).inlines),G(n),Q(e,n)},a=e=>{var n=gS(),r=J(n),i=J(r,!0);G(r),G(n),p_(()=>Mv(i,X(t).code)),Q(e,n)},o=e=>{var n=_S();$x(J(n),()=>X(t).inlines),G(n),Q(e,n)},s=e=>{var n=Av(),r=Gg(n),i=e=>{var n=yS();Uv(n,21,()=>X(t).items,zv,(e,t)=>{var n=vS();$x(J(n),()=>X(t)),G(n),Q(e,n)}),G(n),Q(e,n)},a=e=>{var n=xS();Uv(n,21,()=>X(t).items,zv,(e,t)=>{var n=bS();$x(J(n),()=>X(t)),G(n),Q(e,n)}),G(n),Q(e,n)};$(r,e=>{X(t).ordered?e(i):e(a,-1)}),Q(e,n)};$(r,e=>{X(t).type===`paragraph`?e(i):X(t).type===`codeblock`?e(a,1):X(t).type===`blockquote`?e(o,2):X(t).type===`list`&&e(s,3)}),Q(e,n)}),Q(e,t)};$(o,e=>{t.commentBody?e(s):e(c,-1)}),G(a);var l=Y(a,2),u=e=>{var n=CS();Uv(n,21,()=>X(i).refs,e=>`${e.kind}:${e.id}`,(e,n)=>{var i=SS(),a=J(i);qy(a,{size:12,strokeWidth:2,"aria-hidden":`true`});var o=Y(a,2),s=J(o);G(o),G(i),p_(e=>{Sy(i,`href`,e),Sy(i,`data-ref-kind`,X(n).kind),Sy(i,`data-ref-id`,X(n).id),Mv(s,`${X(n).kind??``}:${X(n).id??``}`)},[()=>C(X(n))]),yv(`click`,i,e=>{t.onRefClick&&(e.preventDefault(),t.onRefClick(X(n),X(r)))}),Q(e,i)}),G(n),Q(e,n)};$(l,e=>{X(i).refs.length>0&&e(u)}),Q(e,n)};$(te,e=>{X(l)?e(ne):e(N,-1)}),G(u),p_(e=>{d=oy(u,1,`st-review-thread__item svelte-144zrs4`,null,d,{"st-review-thread__item--unread":X(o),"st-review-thread__item--resolution":X(i).resolution!==null}),Sy(u,`data-comment-id`,X(r).id),Sy(u,`data-unread`,X(o)?`true`:`false`),Sy(u,`data-resolution-record`,X(i).resolution===null?void 0:`true`),Sy(g,`datetime`,X(r).createdAt),Mv(_,e)},[()=>x(X(r).createdAt)]),Q(e,u)}),G(I);var re=Y(I,2),L=e=>{var n=DS(),r=Y(J(n),2),i=e=>{ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(p)},onclick:T,children:(e,t)=>{var n=ES();Yy(Gg(n),{size:14,strokeWidth:2,"aria-hidden":`true`}),vh(2),Q(e,n)},$$slots:{default:!0}})};$(r,e=>{t.onReopen&&e(i)}),G(n),Q(e,n)},R=e=>{var n=OS();Qx(J(n),{get author(){return t.currentUser},placeholder:`Reply…`,submitLabel:`Reply`,label:`Reply to thread`,autofocus:!1,trapFocus:!1,onSubmit:M}),G(n),Q(e,n)};$(re,e=>{X(m)===`closed`?e(L):r()&&t.onReply&&e(R,1)}),G(ee),My(ee,e=>q(o,e),()=>X(o)),Q(e,ee),Dh()}bv([`click`]);var jS=Z(`<div class="st-review-orphans__error svelte-4qipl" role="alert"> </div>`),MS=Z(`<p class="st-review-orphans__preview svelte-4qipl"> </p>`),NS=Z(`<li><div class="st-review-orphans__item-top svelte-4qipl"><!> <!></div> <p class="st-review-orphans__excerpt svelte-4qipl"> </p> <!> <div class="st-review-orphans__actions svelte-4qipl"><!> <!> <!></div></li>`),PS=Z(`<ul class="st-review-orphans__list svelte-4qipl"></ul>`),FS=Z(`<section><header class="st-review-orphans__header svelte-4qipl"><h3 class="st-review-orphans__heading svelte-4qipl"><!> <span> </span></h3> <!></header> <!> <!></section>`);function IS(e,t){let n=jv();Eh(t,!0);let r=Ly(t,`readState`,3,null),i=Ly(t,`heading`,3,`No longer attached`),a=Py(t,[`$$slots`,`$$events`,`$$legacy`,`threads`,`currentUser`,`readState`,`heading`,`class`,`onSelect`,`onReanchor`,`onResolve`,`onReopen`]),o=Og(null),s=Og(null),c=`st-review-orphans-heading-${n}`,l=K(()=>[`st-review-orphans`,t.class].filter(Boolean).join(` `));async function u(e,t){if(t&&X(s)===null){q(o,null),q(s,e,!0);try{await t(e)}catch(e){q(o,Px(e),!0)}finally{q(s,null)}}}var d=FS();wy(d,()=>({...a,class:X(l),"aria-labelledby":c}),void 0,void 0,void 0,`svelte-4qipl`);var f=J(d),p=J(f),m=J(p);Zy(m,{size:14,strokeWidth:2,"aria-hidden":`true`});var h=Y(m,2),g=J(h,!0);G(h),G(p),ib(Y(p,2),{size:`sm`,tone:`warning`,class:`st-review-orphans__count`,children:(e,n)=>{vh();var r=kv();p_(()=>Mv(r,t.threads.length)),Q(e,r)},$$slots:{default:!0}}),G(f);var _=Y(f,2),v=e=>{var t=jS(),n=J(t,!0);G(t),p_(()=>Mv(n,X(o))),Q(e,t)};$(_,e=>{X(o)&&e(v)});var y=Y(_,2),b=e=>{gb(e,{title:`No unattached threads`,message:`All comment threads are currently anchored to the document.`})},x=e=>{var n=PS();Uv(n,21,()=>t.threads,e=>e.threadId,(e,n)=>{let i=K(()=>X(n).comments[0]),a=K(()=>Gb(X(n),t.currentUser,r())),o=K(()=>yb(X(n).state)),c=K(()=>X(n).anchor===null?`Original location removed`:Mx(X(n).anchor,100));var l=NS();let d;var f=J(l),p=J(f),m=e=>{Wx(e,{get author(){return X(i).authorship.author},get sponsor(){return X(i).authorship.sponsor},size:`sm`})};$(p,e=>{X(i)&&e(m)});var h=Y(p,2);{let e=K(()=>X(n).state===`closed`?`success`:`info`);ib(h,{size:`sm`,get tone(){return X(e)},children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,X(o))),Q(e,n)},$$slots:{default:!0}})}G(f);var g=Y(f,2),_=J(g,!0);G(g);var v=Y(g,2),y=e=>{var t=MS(),n=J(t,!0);G(t),p_(()=>Mv(n,X(i).body)),Q(e,t)};$(v,e=>{X(i)&&e(y)});var b=Y(v,2),x=J(b),S=e=>{{let r=K(()=>`Open thread ${X(n).threadId}`);ob(e,{type:`button`,variant:`secondary`,size:`sm`,get"aria-label"(){return X(r)},onclick:()=>t.onSelect(X(n).threadId),children:(e,t)=>{vh();var r=kv();p_(()=>Mv(r,`Open (${X(n).comments.length??``})`)),Q(e,r)},$$slots:{default:!0}})}};$(x,e=>{t.onSelect&&e(S)});var C=Y(x,2),w=e=>{{let r=K(()=>X(s)===X(n).threadId);ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(r)},onclick:()=>u(X(n).threadId,t.onReanchor),children:(e,t)=>{vh(),Q(e,kv(`Re-anchor`))},$$slots:{default:!0}})}};$(C,e=>{t.onReanchor&&e(w)});var T=Y(C,2),E=e=>{{let r=K(()=>X(s)===X(n).threadId);ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(r)},onclick:()=>u(X(n).threadId,t.onResolve),children:(e,t)=>{vh(),Q(e,kv(`Resolve`))},$$slots:{default:!0}})}},D=e=>{{let r=K(()=>X(s)===X(n).threadId);ob(e,{type:`button`,variant:`ghost`,size:`sm`,get disabled(){return X(r)},onclick:()=>u(X(n).threadId,t.onReopen),children:(e,t)=>{vh(),Q(e,kv(`Reopen`))},$$slots:{default:!0}})}};$(T,e=>{X(n).state===`open`&&t.onResolve?e(E):X(n).state===`closed`&&t.onReopen&&e(D,1)}),G(b),G(l),p_(()=>{d=oy(l,1,`st-review-orphans__item svelte-4qipl`,null,d,{"st-review-orphans__item--unread":X(a)}),Sy(l,`data-thread-id`,X(n).threadId),Sy(l,`data-thread-state`,X(n).state),Sy(l,`data-unread`,X(a)?`true`:`false`),Mv(_,X(c))}),Q(e,l)}),G(n),Q(e,n)};$(y,e=>{t.threads.length===0?e(b):e(x,-1)}),G(d),p_(()=>{Sy(p,`id`,c),Mv(g,i())}),Q(e,d),Dh()}var LS=Z(`<button type="button"><span> </span> <span class="st-review-panel__filter-count svelte-w8zayx"> </span></button>`),RS=Z(`<!> <span>All threads</span>`,1),zS=Z(`<div class="st-review-panel__detail svelte-w8zayx"><div class="st-review-panel__back-row svelte-w8zayx"><!></div> <!></div>`),BS=Z(`<span class="st-review-panel__unread-dot svelte-w8zayx" aria-label="Unread"></span>`),VS=Z(`<span class="st-review-panel__card-preview svelte-w8zayx"> </span>`),HS=Z(`<li><button type="button"><div class="st-review-panel__card-top svelte-w8zayx"><!> <div class="st-review-panel__card-badges svelte-w8zayx"><!> <!></div></div> <span class="st-review-panel__card-anchor svelte-w8zayx"> </span> <!> <span class="st-review-panel__card-count svelte-w8zayx"> </span></button></li>`),US=Z(`<ul class="st-review-panel__list svelte-w8zayx"></ul>`),WS=Z(`<!> <!>`,1),GS=Z(`<div class="st-review-panel__filters svelte-w8zayx" role="group" aria-label="Filter comment threads"></div> <div class="st-review-panel__content svelte-w8zayx"><!></div> <div class="st-review-panel__sr-live svelte-w8zayx" aria-live="polite" aria-atomic="true"> </div>`,1),KS=Z(`<div class="st-review-panel__header-actions svelte-w8zayx"><!></div>`),qS=Z(`<div class="st-review-panel__compact-meta svelte-w8zayx"><!> <!> <!></div> <!>`,1),JS=Z(`<aside><header class="st-review-panel__header svelte-w8zayx"><div class="st-review-panel__title-group svelte-w8zayx"><h2 tabindex="-1" class="st-review-panel__heading svelte-w8zayx"> </h2> <!> <!></div> <div class="st-review-panel__header-actions svelte-w8zayx"><!> <!></div></header> <!></aside>`);function YS(e,t){Eh(t,!0);let n=e=>{var n=GS(),i=Gg(n);Uv(i,21,()=>r,e=>e.id,(e,t)=>{let n=K(()=>X(C)[X(t).id]),r=K(()=>X(y)===X(t).id);var i=LS();let a;var o=J(i),s=J(o,!0);G(o);var c=Y(o,2),l=J(c,!0);G(c),G(i),p_(()=>{a=oy(i,1,`st-review-panel__filter-tab svelte-w8zayx`,null,a,{"st-review-panel__filter-tab--active":X(r)}),Sy(i,`aria-pressed`,X(r)?`true`:`false`),Mv(s,X(t).label),Mv(l,X(n))}),yv(`click`,i,()=>k(X(t).id)),Q(e,i)}),G(i);var a=Y(i,2),o=J(a),l=e=>{var n=zS(),r=J(n);ob(J(r),{type:`button`,variant:`ghost`,size:`sm`,onclick:()=>t.onSelect?.(null),children:(e,t)=>{var n=RS();Vy(Gg(n),{size:14,strokeWidth:2,"aria-hidden":`true`}),vh(2),Q(e,n)},$$slots:{default:!0}}),G(r);var i=Y(r,2);{let e=K(()=>t.onReply?ee:void 0),n=K(()=>t.onResolve?j:void 0),r=K(()=>t.onReopen?M:void 0);AS(i,{get thread(){return X(D)},get currentUser(){return t.currentUser},get canModerate(){return c()},get readState(){return s()},get onReply(){return X(e)},get onResolve(){return X(n)},get onReopen(){return X(r)},get onEditComment(){return t.onEditComment},get onDeleteComment(){return t.onDeleteComment},get onReanchor(){return t.onReanchor},get commentBody(){return t.commentBody}})}G(n),Q(e,n)},u=e=>{{let t=K(()=>X(y)===`all`?`Select text or click an element in Review mode to start a thread.`:`No threads match the "${X(y)}" filter.`);gb(e,{title:`No matching threads`,get message(){return X(t)}})}},d=e=>{var n=WS(),r=Gg(n),i=e=>{var n=US();Uv(n,21,()=>X(T),e=>e.threadId,(e,n)=>{let r=K(()=>X(n).comments[0]),i=K(()=>Gb(X(n),t.currentUser,s())),a=K(()=>yb(X(n).state)),o=K(()=>Mx(X(n).anchor,100));var c=HS(),l=J(c);let u;var d=J(l),f=J(d),p=e=>{Wx(e,{get author(){return X(r).authorship.author},get sponsor(){return X(r).authorship.sponsor},size:`sm`})};$(f,e=>{X(r)&&e(p)});var m=Y(f,2),h=J(m),g=e=>{Q(e,BS())};$(h,e=>{X(i)&&e(g)});var _=Y(h,2);{let e=K(()=>X(n).state===`closed`?`success`:`info`);ib(_,{size:`sm`,get tone(){return X(e)},children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,X(a))),Q(e,n)},$$slots:{default:!0}})}G(m),G(d);var v=Y(d,2),y=J(v,!0);G(v);var b=Y(v,2),x=e=>{var t=VS(),n=J(t,!0);G(t),p_(()=>Mv(n,X(r).body)),Q(e,t)};$(b,e=>{X(r)&&e(x)});var S=Y(b,2),C=J(S);G(S),G(l),G(c),p_(()=>{u=oy(l,1,`st-review-panel__thread-card svelte-w8zayx`,null,u,{"st-review-panel__thread-card--unread":X(i),"st-review-panel__thread-card--resolved":X(n).state===`closed`}),Sy(l,`data-thread-id`,X(n).threadId),Sy(l,`data-thread-state`,X(n).state),Sy(l,`data-unread`,X(i)?`true`:`false`),Mv(y,X(o)),Mv(C,`${X(n).comments.length??``} ${X(n).comments.length===1?`comment`:`comments`}`)}),yv(`click`,l,()=>A(X(n).threadId)),Q(e,c)}),G(n),Q(e,n)};$(r,e=>{X(T).length>0&&e(i)});var a=Y(r,2),o=e=>{{let n=K(()=>t.onResolve?j:void 0),r=K(()=>t.onReopen?M:void 0);IS(e,{get threads(){return X(E)},get currentUser(){return t.currentUser},get readState(){return s()},onSelect:A,get onResolve(){return X(n)},get onReopen(){return X(r)},get onReanchor(){return t.onReanchor}})}};$(a,e=>{X(E).length>0&&e(o)}),Q(e,n)};$(o,e=>{X(D)?e(l):X(T).length===0&&X(E).length===0?e(u,1):e(d,-1)}),G(a);var f=Y(a,2),p=J(f,!0);G(f),p_(()=>Mv(p,X(g))),Q(e,n)},r=[{id:`all`,label:`All`},{id:`open`,label:`Open`},{id:`resolved`,label:`Resolved`},{id:`mine`,label:`Mine`}],i=Ly(t,`orphaned`,19,()=>[]),a=Ly(t,`activeThreadId`,3,null),o=Ly(t,`open`,3,!0),s=Ly(t,`readState`,3,null),c=Ly(t,`canModerate`,3,!1),l=Ly(t,`title`,3,`Comments`),u=Py(t,`$$slots.$$events.$$legacy.threads.orphaned.currentUser.activeThreadId.filter.open.readState.canModerate.title.compact.class.onSelect.onFilterChange.onClose.onReply.onResolve.onReopen.onEditComment.onDeleteComment.onReanchor.onMarkRead.headerActions.commentBody`.split(`.`)),d=Og(void 0),f=Og(void 0),p=Og(void 0),m=Og(!1),h=Og(Pg(rv(()=>t.filter??`all`))),g=Og(``),_=rv(()=>a()),v=K(()=>t.compact??X(m)),y=K(()=>t.filter??X(h)),b=K(()=>new Set(i().map(e=>e.threadId))),x=K(()=>t.threads.filter(e=>!X(b).has(e.threadId))),S=K(()=>{let e=new Set,n=[];for(let r of t.threads)e.has(r.threadId)||(e.add(r.threadId),n.push(r));for(let t of i())e.has(t.threadId)||(e.add(t.threadId),n.push(t));return n}),C=K(()=>Hb(X(S),t.currentUser)),w=K(()=>qb(X(S),t.currentUser,s())),T=K(()=>Vb(X(x),X(y),t.currentUser)),E=K(()=>Vb(i(),X(y),t.currentUser)),D=K(()=>a()!==null&&a()!==void 0?X(S).find(e=>e.threadId===a())??null:null);s_(()=>{if(t.compact!==void 0||typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: 47.999rem)`);q(m,e.matches,!0);let n=e=>{q(m,e.matches,!0)};return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)});function O(){return X(f)?X(f):X(p)?.closest(`.st-drawer`)?.querySelector(`.st-drawer__title`)??null}s_(()=>{let e=a()??null,t=o();X(f),X(p),t&&e!==null&&e!==_&&ev().then(()=>{O()?.focus()}),_=e}),s_(()=>{let e=X(d);if(!e||X(v)||!o())return;let n=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a()!==null&&a()!==void 0?t.onSelect?.(null):t.onClose?.())};return e.addEventListener(`keydown`,n),()=>e.removeEventListener(`keydown`,n)});function k(e){q(h,e,!0),t.onFilterChange?.(e)}function A(e){t.onSelect?.(e),t.onMarkRead?.(e)}async function j(e){t.onResolve&&(await t.onResolve(e),q(g,`Thread resolved.`))}async function M(e){t.onReopen&&(await t.onReopen(e),q(g,`Thread reopened.`))}async function ee(e,n){t.onReply&&(await t.onReply(e,n),q(g,`Reply posted.`))}let te=K(()=>[`st-review-panel`,t.class].filter(Boolean).join(` `));var ne=Av(),N=Gg(ne),P=e=>{fb(e,{get open(){return o()},side:`bottom`,get title(){return l()},get class(){return t.class},onclose:()=>t.onClose?.(),children:(e,r)=>{var a=qS(),o=Gg(a),s=J(o),c=e=>{ib(e,{size:`sm`,tone:`info`,class:`st-review-panel__unread-count`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,`${X(w)??``} unread`)),Q(e,n)},$$slots:{default:!0}})};$(s,e=>{X(w)>0&&e(c)});var l=Y(s,2),u=e=>{ib(e,{size:`sm`,tone:`warning`,class:`st-review-panel__orphan-count`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,`${i().length??``} unattached`)),Q(e,n)},$$slots:{default:!0}})};$(l,e=>{i().length>0&&e(u)});var d=Y(l,2),f=e=>{var n=KS();Yv(J(n),()=>t.headerActions),G(n),Q(e,n)};$(d,e=>{t.headerActions&&e(f)}),G(o),My(o,e=>q(p,e),()=>X(p));var m=Y(o,2);n(m),Q(e,a)},$$slots:{default:!0}})},F=e=>{var r=JS();wy(r,()=>({...u,class:X(te),"aria-label":l()}),void 0,void 0,void 0,`svelte-w8zayx`);var a=J(r),o=J(a),s=J(o),c=J(s,!0);G(s),My(s,e=>q(f,e),()=>X(f));var p=Y(s,2),m=e=>{ib(e,{size:`sm`,tone:`info`,class:`st-review-panel__unread-count`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,`${X(w)??``} unread`)),Q(e,n)},$$slots:{default:!0}})};$(p,e=>{X(w)>0&&e(m)});var h=Y(p,2),g=e=>{ib(e,{size:`sm`,tone:`warning`,class:`st-review-panel__orphan-count`,children:(e,t)=>{vh();var n=kv();p_(()=>Mv(n,`${i().length??``} unattached`)),Q(e,n)},$$slots:{default:!0}})};$(h,e=>{i().length>0&&e(g)}),G(o);var _=Y(o,2),v=J(_),y=e=>{var n=Av();Yv(Gg(n),()=>t.headerActions),Q(e,n)};$(v,e=>{t.headerActions&&e(y)});var b=Y(v,2),x=e=>{cb(e,{size:`sm`,variant:`ghost`,"aria-label":`Close comments panel`,onclick:()=>t.onClose(),children:(e,t)=>{Qy(e,{size:16,strokeWidth:2,"aria-hidden":`true`})},$$slots:{default:!0}})};$(b,e=>{t.onClose&&e(x)}),G(_),G(a);var S=Y(a,2);n(S),G(r),My(r,e=>q(d,e),()=>X(d)),p_(()=>Mv(c,l())),Q(e,r)};$(N,e=>{X(v)?e(P):o()&&e(F,1)}),Q(e,ne),Dh()}bv([`click`]);var XS=Z(`<div class="st-review-layer__content svelte-18v5olh"><!></div>`),ZS=Z(`<div class="st-review-layer__hover-outline svelte-18v5olh" aria-hidden="true"></div>`),QS=Z(`<div class="st-review-layer__flash svelte-18v5olh" aria-hidden="true"></div>`),$S=Z(`<div class="st-review-layer__pin-anchor svelte-18v5olh"><!></div>`),eC=Z(`<div class="st-review-layer__gutter-pin svelte-18v5olh"><!></div>`),tC=Z(`<div class="st-review-layer__gutter svelte-18v5olh" aria-hidden="false"></div>`),nC=Z(`<li><button type="button" class="st-review-layer__cluster-item svelte-18v5olh"><span class="st-review-layer__cluster-index svelte-18v5olh"> </span> <span class="st-review-layer__cluster-preview svelte-18v5olh"> </span></button></li>`),rC=Z(`<div class="st-review-layer__cluster-popover svelte-18v5olh" role="dialog" aria-label="Clustered comment threads" tabindex="-1"><ul class="st-review-layer__cluster-list svelte-18v5olh"></ul></div>`),iC=Z(`<div class="st-review-layer__selection-trigger svelte-18v5olh"><!></div>`),aC=Z(`<div class="st-review-layer__composer svelte-18v5olh" role="dialog" aria-label="Add comment"><!></div>`),oC=Z(`<!> <!> <div class="st-review-layer__pins svelte-18v5olh" role="group" aria-label="Comment pins"></div> <!> <!> <!> <!>`,1),sC=Z(`<div class="st-review-layer__confirm svelte-18v5olh" role="alertdialog" aria-modal="true" aria-label="Discard unsaved comment draft" tabindex="-1"><p class="st-review-layer__confirm-text svelte-18v5olh">You have an unsaved comment draft. Discard it and exit review mode?</p> <div class="st-review-layer__confirm-actions svelte-18v5olh"><!> <!></div></div>`),cC=Z(`<div class="st-review-layer__panel"><!></div>`),lC=Z(`<div><!> <div class="st-review-layer__overlay svelte-18v5olh" data-review-overlay="true"><!> <!> <div class="st-review-layer__sr-live svelte-18v5olh" aria-live="polite" aria-atomic="true"> </div></div> <!></div>`);function uC(e,t){Eh(t,!0);let n=`a, button, input, select, textarea, summary, [role="button"], [role="link"]`,r=`st-review-text`,i=`st-review-text-active`,a=`st-review-text-resolved`,o=Ly(t,`rootEl`,3,null),s=Ly(t,`mode`,3,`view`),c=Ly(t,`readState`,3,null),l=Ly(t,`canModerate`,3,!1),u=Ly(t,`selectionSettleMs`,3,150),d=Py(t,`$$slots.$$events.$$legacy.rootEl.mode.target.artifactVersion.comments.currentUser.activeThreadId.readState.canModerate.panelOpen.panelFilter.panelCompact.selectionSettleMs.class.onCreate.onSelect.onMarkRead.onModeChange.onOrphansChange.onPanelFilterChange.onPanelClose.onReply.onResolve.onReopen.onEditComment.onDeleteComment.onReanchor.children.composer`.split(`.`)),f=Og(void 0),p=Og(void 0),m=Og(void 0),h=Og(void 0),g=Og(void 0),_=Og(void 0),v=Og(void 0),y=Og(0),b=Og(null),x=Og(null),S=Og(null),C=Og(null),w=Og(``),T=Og(!1),E=Og(null),D=Og(``),O=Og(null),k=Og(!1),A=K(()=>t.activeThreadId===void 0?X(O):t.activeThreadId),j=K(()=>t.onReply!==void 0||t.onResolve!==void 0||t.onReopen!==void 0||t.onEditComment!==void 0||t.onDeleteComment!==void 0||t.onReanchor!==void 0),M=K(()=>t.panelOpen!==void 0||X(j)),ee=K(()=>t.panelOpen===void 0?s()===`review`&&X(j)&&!X(k):t.panelOpen),te=rv(()=>s()),ne=new Set,N=!1,P,F,I,re=!1,L=null,R=null,ie=K(()=>o()?o():X(p)?X(p).querySelector(`[data-review-root]`)??X(p):null),z=K(()=>zb(t.comments));function ae(e,t){return{top:t.top-e.top,left:t.left-e.left,width:t.width,height:t.height}}function B(e,t){if(typeof e.getBoundingClientRect==`function`){let t=e.getBoundingClientRect();if(t.width>0||t.height>0)return t}return t.getBoundingClientRect()}function oe(e,t){if(e.element!==t.element){let n=e.element.compareDocumentPosition(t.element);if(n&Node.DOCUMENT_POSITION_FOLLOWING)return-1;if(n&Node.DOCUMENT_POSITION_PRECEDING)return 1}if(e.range&&t.range)try{let n=e.range.compareBoundaryPoints(Range.START_TO_START,t.range);if(n!==0)return n}catch{}if(e.box.top!==t.box.top)return e.box.top-t.box.top;let n=e.thread.comments[0]?.createdAt??``,r=t.thread.comments[0]?.createdAt??``;return n<r?-1:+(n>r)}let se=K(()=>{X(y),s();let e=X(ie),n=X(f),r=[],i=[];if(!e)return{resolved:r,orphaned:i,rootHeight:0,overlayBox:null};let a=e.getBoundingClientRect(),o=n?(()=>{let e=n.getBoundingClientRect();return{top:a.top-e.top,left:a.left-e.left,width:a.width,height:a.height}})():null;for(let n of X(z)){if(n.anchor===null){i.push(n);continue}let o=yx(e,n.anchor,{artifactVersion:t.artifactVersion});if(o.status===`orphan`){i.push(n);continue}let s;s=o.kind===`region`?{top:a.top+o.rect.y*a.height,left:a.left+o.rect.x*a.width,width:o.rect.width*a.width,height:o.rect.height*a.height}:o.kind===`text`&&o.range?B(o.range,o.element):o.element.getBoundingClientRect(),r.push({thread:n,anchorKind:o.kind,element:o.element,range:o.range,box:ae(a,s),index:0})}return r.sort(oe),r.forEach((e,t)=>{e.index=t+1}),{resolved:r,orphaned:i,rootHeight:a.height,overlayBox:o}}),ce=K(()=>{let e=[],n=new Map,r=new Map;for(let t of X(se).resolved)if(t.anchorKind===`element`||t.anchorKind===`text`&&t.range===null){let r=n.get(t.element);if(r)r.push(t);else{let r=[t];n.set(t.element,r),e.push(r)}}else if(t.thread.sectionKey){let n=r.get(t.thread.sectionKey);if(n)n.push(t);else{let n=[t];r.set(t.thread.sectionKey,n),e.push(n)}}else e.push([t]);return e.map(e=>{let n=e[0],r=e.reduce((e,t)=>e+t.thread.comments.length,0),i=e.reduce((e,n)=>e+Kb(n.thread,t.currentUser,c()),0),a=e.every(e=>e.thread.state===`closed`),o=e.some(e=>e.thread.threadId===X(A)),s=e.length>1,l=Mx(n.thread.anchor,60),u=s?`${e.length} threads clustered, ${r} comments${i>0?`, ${i} unread`:``}, on '${l}'`:Nx({index:n.index,count:r,unreadCount:i,resolved:a,excerpt:l});return{id:e.map(e=>e.thread.threadId).join(`+`),entries:e,box:n.box,primaryIndex:n.index,totalComments:r,unreadCount:i,allResolved:a,anyActive:o,variant:s?`cluster`:n.anchorKind===`element`?`element`:`inline`,ariaLabel:u}})}),le=K(()=>{if(X(ce).length===0)return[];let e=new Map(X(ce).map(e=>[e.id,e]));return Jb(X(ce).map(e=>({id:e.id,targetY:e.box.top})),{gap:28,minY:0,maxY:X(se).rootHeight>0?Math.max(0,X(se).rootHeight-24):void 0}).map(t=>{let n=e.get(t.id);return n?{cluster:n,positioned:t}:null}).filter(e=>e!==null)}),ue=K(()=>X(E)?X(ce).find(e=>e.id===X(E))??null:null);s_(()=>{let e=X(se).orphaned;t.onOrphansChange?.(e);let n=new Set(e.map(e=>e.threadId)),r=0;for(let e of n)ne.has(e)||(r+=1);r>0&&s()===`review`&&q(D,r===1?`1 comment thread is now unattached (orphan).`:`${r} comment threads are now unattached (orphans).`,!0),ne=n}),s_(()=>{let e=s();if(te===`review`&&e===`view`){if(X(C)!==null&&X(w).trim().length>0){let e=typeof document<`u`?document.activeElement:null;R=e instanceof HTMLElement&&!(X(m)&&X(m).contains(e))?e:X(C).invoker,q(T,!0)}else V()}else e===`review`&&(q(T,!1),R=null,q(k,!1));te=e}),s_(()=>{let e=s()===`review`,t=X(se).resolved,n=X(A),o=e=>{if(typeof CSS>`u`||CSS===null||!(`highlights`in CSS)||typeof Highlight>`u`)return;let o=CSS.highlights;if(o.delete(r),o.delete(i),o.delete(a),!e)return;let s=[],c=[],l=[];for(let e of t)e.range&&(e.thread.threadId===n?c.push(e.range):e.thread.state===`closed`?l.push(e.range):s.push(e.range));s.length>0&&o.set(r,new Highlight(...s)),c.length>0&&o.set(i,new Highlight(...c)),l.length>0&&o.set(a,new Highlight(...l))};return o(e),()=>o(!1)}),s_(()=>{let e=X(ie);if(s()!==`review`||!e)return;let t=()=>{N||(N=!0,queueMicrotask(()=>{N=!1,q(y,X(y)+1)}))},n=typeof MutationObserver<`u`?new MutationObserver(e=>{e.some(e=>!X(m)||!X(m).contains(e.target))&&t()}):null;n?.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`data-anchor-id`,`data-commentable`]});let r=typeof ResizeObserver<`u`?new ResizeObserver(t):null;return r?.observe(e),X(f)&&X(f)!==e&&r?.observe(X(f)),window.addEventListener(`resize`,t,{passive:!0}),window.addEventListener(`scroll`,t,{capture:!0,passive:!0}),()=>{n?.disconnect(),r?.disconnect(),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,{capture:!0})}}),s_(()=>{let e=X(ie);if(s()!==`review`||!e){q(b,null);return}let r=e.ownerDocument,i=e=>e!==null&&(X(m)!==void 0&&X(m).contains(e)||X(h)!==void 0&&X(h).contains(e)),a=e=>{if(!e||typeof e.tagName!=`string`)return!1;let t=e.tagName.toUpperCase();return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable===!0},o=t=>{let n=t.closest(`[data-review-passthrough]`);return n!==null&&e.contains(n)},c=t=>{if(!e.contains(t)||i(t))return null;let n=t.closest(`[data-commentable]`);if(n&&e.contains(n))return n;let r=t.closest(`[data-anchor-id]`);if(r&&e.contains(r)&&r!==e)return r;let a=t.closest(`p, h1, h2, h3, h4, h5, h6, li, figure, table, blockquote, pre, [data-anchor-id]`);return a&&e.contains(a)?a:null},l=a=>{let s=a.target;if(!s||i(s)||o(s))return;let l=s.closest(n);if(l&&e.contains(l)&&!l.hasAttribute(`data-commentable`)){a.preventDefault(),a.stopPropagation();return}let u=r.defaultView?.getSelection();if(u&&u.rangeCount>0&&!u.getRangeAt(0).collapsed&&e.contains(u.getRangeAt(0).commonAncestorContainer))return;let d=c(s);if(!d)return;let f=dx(e,d,t.artifactVersion);if(!f)return;let p=ae(e.getBoundingClientRect(),d.getBoundingClientRect());q(S,null),q(E,null),de(f,d,p.top+p.height,p.left)},d=t=>{if(!t||i(t)||o(t)){q(b,null);return}let r=t.closest(n);if(r&&e.contains(r)&&!r.hasAttribute(`data-commentable`)){q(b,null);return}let a=c(t);a?q(b,ae(e.getBoundingClientRect(),a.getBoundingClientRect()),!0):q(b,null)},f=e=>d(e.target),p=()=>{q(b,null)},v=e=>d(e.target),y=t=>{let n=t.relatedTarget;(!n||!e.contains(n))&&q(b,null)},x=()=>re||X(_)!==void 0&&r.activeElement!==null&&X(_).contains(r.activeElement),w=()=>{let t=r.defaultView?.getSelection();if(!t||t.rangeCount===0)return!1;let n=t.getRangeAt(0);return!n.collapsed&&n.toString().trim().length>0&&e.contains(n.commonAncestorContainer)&&!i(n.commonAncestorContainer)&&!a(r.activeElement)},D=()=>{F!==void 0&&(clearTimeout(F),F=void 0);let n=r.defaultView?.getSelection();if(!n||n.rangeCount===0){x()||q(S,null);return}let o=n.getRangeAt(0);if(o.collapsed||o.toString().trim().length===0||!e.contains(o.commonAncestorContainer)||i(o.commonAncestorContainer)||a(r.activeElement)){x()||q(S,null);return}let s=o.cloneRange();F=setTimeout(()=>{if(F=void 0,!e.contains(s.commonAncestorContainer)){q(S,null);return}let n=ux(e,s,t.artifactVersion);if(!n){q(S,null);return}let r=e.getBoundingClientRect(),i=s.endContainer.nodeType===Node.ELEMENT_NODE?s.endContainer:s.endContainer.parentElement??e,a=B(s,i);q(S,{anchor:n,top:a.bottom-r.top,left:Math.max(0,a.right-r.left)},!0)},u())},O=()=>{re&&(I!==void 0&&clearTimeout(I),I=setTimeout(()=>{I=void 0,re=!1,X(S)&&!X(C)&&!x()&&!w()&&q(S,null)},0))},k=n=>{if(n.key===`Escape`){if(X(T))return;if(X(E)&&!X(C)){let e=r.activeElement,t=L!==null&&e!==null&&(e===L||L.contains(e)),i=X(g)!==void 0&&e!==null&&X(g).contains(e);if(t||i){n.preventDefault(),n.stopPropagation();let e=L;q(E,null),L=null,e?.focus();return}}if(X(S)&&!X(C)&&!X(E)){n.preventDefault(),n.stopPropagation(),q(S,null);return}}if(n.altKey&&n.shiftKey&&n.key.toLowerCase()===`c`){let i=r.activeElement,o=n.target;if(a(i)||a(o))return;let s=r.defaultView?.getSelection();if(s&&s.rangeCount>0&&!s.getRangeAt(0).collapsed&&e.contains(s.getRangeAt(0).commonAncestorContainer)){let r=s.getRangeAt(0),a=ux(e,r,t.artifactVersion);if(a){n.preventDefault(),n.stopPropagation();let t=e.getBoundingClientRect(),o=B(r,r.endContainer.nodeType===Node.ELEMENT_NODE?r.endContainer:r.endContainer.parentElement??e);q(S,null),de(a,i,o.bottom-t.top,Math.max(0,o.left-t.left));return}}if(i&&e.contains(i)){let r=c(i);if(r){let i=dx(e,r,t.artifactVersion);if(i){n.preventDefault(),n.stopPropagation();let t=ae(e.getBoundingClientRect(),r.getBoundingClientRect());de(i,r,t.top+t.height,t.left)}}}}};return e.addEventListener(`click`,l,!0),e.addEventListener(`pointerover`,f),e.addEventListener(`pointerleave`,p),e.addEventListener(`focusin`,v),e.addEventListener(`focusout`,y),r.addEventListener(`selectionchange`,D),r.addEventListener(`keydown`,k),r.addEventListener(`mouseup`,O),r.addEventListener(`pointerup`,O),r.addEventListener(`pointercancel`,O),()=>{F!==void 0&&(clearTimeout(F),F=void 0),I!==void 0&&(clearTimeout(I),I=void 0),re=!1,P!==void 0&&(clearTimeout(P),P=void 0),e.removeEventListener(`click`,l,!0),e.removeEventListener(`pointerover`,f),e.removeEventListener(`pointerleave`,p),e.removeEventListener(`focusin`,v),e.removeEventListener(`focusout`,y),r.removeEventListener(`selectionchange`,D),r.removeEventListener(`keydown`,k),r.removeEventListener(`mouseup`,O),r.removeEventListener(`pointerup`,O),r.removeEventListener(`pointercancel`,O)}}),s_(()=>{let e=X(g);if(!e)return;(e.querySelector(`.st-review-layer__cluster-item`)??e).focus();let t=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation();let t=L;q(E,null),L=null,t?.focus()}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)}),s_(()=>{let e=X(v);if(!X(T)||!e)return;let t=e.ownerDocument;(Ix(e)[0]??e).focus();let n=t=>{t.key===`Escape`?(t.preventDefault(),t.stopPropagation(),Se()):t.key===`Tab`&&(t.stopPropagation(),Lx(t,e))},r=n=>{n.key===`Escape`?(n.preventDefault(),n.stopPropagation(),Se()):n.key===`Tab`&&!e.contains(t.activeElement)&&(n.stopPropagation(),Lx(n,e))};return e.addEventListener(`keydown`,n),t.addEventListener(`keydown`,r),()=>{e.removeEventListener(`keydown`,n),t.removeEventListener(`keydown`,r)}});function V(){q(b,null),q(x,null),q(S,null),re=!1,I!==void 0&&(clearTimeout(I),I=void 0),q(C,null),q(w,``),q(E,null),q(T,!1)}function de(e,t,n,r){let i=Ib(e);q(w,``),q(C,i.ok?{anchor:i.payload,sectionKey:i.sectionKey,error:null,top:n,left:r,invoker:t}:{anchor:e,sectionKey:null,error:i.message,top:n,left:r,invoker:t},!0)}function fe(e){e.preventDefault(),re=!0,I!==void 0&&(clearTimeout(I),I=void 0)}function pe(e){if(re)return;let t=e.relatedTarget;if(t&&X(_)?.contains(t))return;let n=X(ie);if(!n){q(S,null);return}let r=n.ownerDocument.defaultView?.getSelection();(!r||r.rangeCount===0||r.getRangeAt(0).collapsed||!n.contains(r.getRangeAt(0).commonAncestorContainer))&&q(S,null)}function me(e){if(re=!1,I!==void 0&&(clearTimeout(I),I=void 0),!X(S))return;let{anchor:t,top:n,left:r}=X(S);q(S,null),de(t,e.currentTarget,n,r)}function he(e){e?.isConnected&&e.tabIndex>=0?e.focus():X(f)?.focus()}async function ge(e){let n=X(C);if(!n||n.sectionKey===null)throw Error(n?.error??`Unable to encode anchor for this selection.`);let r=n.sectionKey,i=n.invoker,a={kind:t.target.kind,id:t.target.id,sectionKey:r};await t.onCreate?.({target:a,sectionKey:r,body:e}),q(C,null),q(w,``),q(D,`Comment thread created.`),await ev();let o=X(f)?.ownerDocument??(typeof document<`u`?document:null),s=o?.activeElement??null;if(s===null||s===o?.body){let e=X(ee)?X(h)?.querySelector(`.st-review-panel__heading, .st-drawer__title`)??null:null;if(e)e.focus();else{let e=X(m)?.querySelector(`.st-review-layer__pins [data-pin-section-key="${r.replace(/"/g,`\\"`)}"] button.st-review-pin`);e?e.focus():he(i)}}}function _e(){let e=X(C)?.invoker??null;q(C,null),q(w,``),ev().then(()=>{he(e)})}function ve(e){t.activeThreadId===void 0&&q(O,e,!0),e!==null&&q(k,!1),t.onSelect?.(e)}function ye(){t.panelOpen===void 0&&q(k,!0),t.onPanelClose?.()}function be(e){q(E,null),ve(e.thread.threadId),t.onMarkRead?.(e.thread.threadId),typeof e.element.scrollIntoView==`function`&&e.element.scrollIntoView({behavior:`smooth`,block:`center`}),q(x,e.box,!0),P!==void 0&&clearTimeout(P),P=setTimeout(()=>{q(x,null),P=void 0},900)}function xe(e,t){e.entries.length===1?be(e.entries[0]):X(E)===e.id?q(E,null):(L=t?.currentTarget??null,q(E,e.id,!0))}function Se(){let e=R;q(T,!1),t.onModeChange?.(`review`),ev().then(()=>{s()!==`review`&&(R=null,he(e))})}function Ce(){let e=R??X(C)?.invoker??null;R=null,V(),ev().then(()=>{he(e)})}let we=K(()=>[`st-review-layer`,`st-review-layer--${s()}`,t.class].filter(Boolean).join(` `));var Te=lC();wy(Te,()=>({...d,class:X(we),"data-review-mode":s(),tabindex:`-1`}),void 0,void 0,void 0,`svelte-18v5olh`);var Ee=J(Te),De=e=>{var n=XS();Yv(J(n),()=>t.children),G(n),My(n,e=>q(p,e),()=>X(p)),Q(e,n)};$(Ee,e=>{t.children&&e(De)});var Oe=Y(Ee,2);let ke;var Ae=J(Oe),je=e=>{var n=oC(),r=Gg(n),i=e=>{var t=ZS();let n;p_(()=>n=cy(t,``,n,{top:`${X(b).top}px`,left:`${X(b).left}px`,width:`${X(b).width}px`,height:`${X(b).height}px`})),Q(e,t)};$(r,e=>{X(b)&&e(i)});var a=Y(r,2),o=e=>{var t=QS();let n;p_(()=>n=cy(t,``,n,{top:`${X(x).top}px`,left:`${X(x).left}px`,width:`${X(x).width}px`,height:`${X(x).height}px`})),Q(e,t)};$(a,e=>{X(x)&&e(o)});var s=Y(a,2);Uv(s,21,()=>X(ce),e=>e.id,(e,t)=>{var n=$S();let r;var i=J(n);{let e=K(()=>X(t).unreadCount>0);Jx(i,{get index(){return X(t).primaryIndex},get count(){return X(t).totalComments},get unread(){return X(e)},get resolved(){return X(t).allResolved},get active(){return X(t).anyActive},get label(){return X(t).ariaLabel},get variant(){return X(t).variant},onclick:e=>xe(X(t),e)})}G(n),p_(()=>{Sy(n,`data-pin-section-key`,X(t).entries[0]?.thread.sectionKey??void 0),r=cy(n,``,r,{top:`${X(t).box.top}px`,left:`${X(t).box.left+X(t).box.width}px`})}),Q(e,n)}),G(s);var l=Y(s,2),u=e=>{var t=tC();Uv(t,21,()=>X(le),e=>e.cluster.id,(e,t)=>{var n=eC();let r;var i=J(n);{let e=K(()=>X(t).cluster.unreadCount>0);Jx(i,{get index(){return X(t).cluster.primaryIndex},get count(){return X(t).cluster.totalComments},get unread(){return X(e)},get resolved(){return X(t).cluster.allResolved},get active(){return X(t).cluster.anyActive},get label(){return X(t).cluster.ariaLabel},variant:`margin`,tabindex:-1,onclick:e=>xe(X(t).cluster,e)})}G(n),p_(()=>r=cy(n,``,r,{top:`${X(t).positioned.y}px`})),Q(e,n)}),G(t),Q(e,t)};$(l,e=>{X(le).length>0&&e(u)});var d=Y(l,2),f=e=>{var n=rC();let r;var i=J(n);Uv(i,21,()=>X(ue).entries,e=>e.thread.threadId,(e,n)=>{let r=K(()=>X(n).thread.comments[0]?.body??``),i=K(()=>Gb(X(n).thread,t.currentUser,c()));var a=nC(),o=J(a),s=J(o),l=J(s);G(s);var u=Y(s,2),d=J(u,!0);G(u),G(o),G(a),p_(()=>{Sy(o,`data-unread`,X(i)?`true`:`false`),Mv(l,`#${X(n).index??``}`),Mv(d,X(r))}),yv(`click`,o,()=>be(X(n))),Q(e,a)}),G(i),G(n),My(n,e=>q(g,e),()=>X(g)),p_(e=>r=cy(n,``,r,e),[()=>({top:`${X(ue).box.top+28}px`,left:`${Math.max(0,X(ue).box.left)}px`})]),Q(e,n)};$(d,e=>{X(ue)&&e(f)});var p=Y(d,2),m=e=>{var t=iC();let n;ob(J(t),{type:`button`,variant:`primary`,size:`sm`,onpointerdown:fe,onmousedown:fe,onfocusout:pe,onclick:me,children:(e,t)=>{vh(),Q(e,kv(`Add comment`))},$$slots:{default:!0}}),G(t),My(t,e=>q(_,e),()=>X(_)),p_(()=>n=cy(t,``,n,{top:`${X(S).top}px`,left:`${X(S).left}px`})),Q(e,t)};$(p,e=>{X(S)&&!X(C)&&e(m)});var h=Y(p,2),v=e=>{var n=aC();let r;var i=J(n),a=e=>{var n=Av();Yv(Gg(n),()=>t.composer,()=>({anchor:X(C).anchor,sectionKey:X(C).sectionKey,error:X(C).error,submit:ge,cancel:_e})),Q(e,n)},o=e=>{{let n=K(()=>Mx(X(C).anchor,140));Qx(e,{get author(){return t.currentUser},get initialBody(){return X(w)},get quotePreview(){return X(n)},get anchorError(){return X(C).error},autofocus:!0,trapFocus:!0,onSubmit:ge,onCancel:_e,onDraftChange:e=>{q(w,e,!0)}})}};$(i,e=>{t.composer?e(a):e(o,-1)}),G(n),p_(()=>r=cy(n,``,r,{top:`${X(C).top}px`,left:`${X(C).left}px`})),Q(e,n)};$(h,e=>{X(C)&&e(v)}),Q(e,n)};$(Ae,e=>{s()===`review`&&e(je)});var Me=Y(Ae,2),Ne=e=>{var t=sC(),n=Y(J(t),2),r=J(n);ob(r,{type:`button`,variant:`secondary`,size:`sm`,onclick:Se,children:(e,t)=>{vh(),Q(e,kv(`Keep editing`))},$$slots:{default:!0}}),ob(Y(r,2),{type:`button`,variant:`danger`,size:`sm`,onclick:Ce,children:(e,t)=>{vh(),Q(e,kv(`Discard draft`))},$$slots:{default:!0}}),G(n),G(t),My(t,e=>q(v,e),()=>X(v)),Q(e,t)};$(Me,e=>{X(T)&&e(Ne)});var Pe=Y(Me,2),Fe=J(Pe,!0);G(Pe),G(Oe),My(Oe,e=>q(m,e),()=>X(m));var Ie=Y(Oe,2),Le=e=>{var n=cC(),r=J(n);{let e=K(()=>X(se).resolved.map(e=>e.thread));YS(r,{get threads(){return X(e)},get orphaned(){return X(se).orphaned},get currentUser(){return t.currentUser},get activeThreadId(){return X(A)},get filter(){return t.panelFilter},get open(){return X(ee)},get readState(){return c()},get canModerate(){return l()},get compact(){return t.panelCompact},onSelect:ve,get onFilterChange(){return t.onPanelFilterChange},onClose:ye,get onReply(){return t.onReply},get onResolve(){return t.onResolve},get onReopen(){return t.onReopen},get onEditComment(){return t.onEditComment},get onDeleteComment(){return t.onDeleteComment},get onReanchor(){return t.onReanchor},get onMarkRead(){return t.onMarkRead}})}G(n),My(n,e=>q(h,e),()=>X(h)),Q(e,n)};$(Ie,e=>{X(M)&&e(Le)}),G(Te),My(Te,e=>q(f,e),()=>X(f)),p_(()=>{ke=cy(Oe,``,ke,{top:X(se).overlayBox?`${X(se).overlayBox.top}px`:void 0,left:X(se).overlayBox?`${X(se).overlayBox.left}px`:void 0,width:X(se).overlayBox?`${X(se).overlayBox.width}px`:void 0,height:X(se).overlayBox?`${X(se).overlayBox.height}px`:void 0}),Mv(Fe,X(D))}),Q(e,Te),Dh()}bv([`click`]);var dC=Z(`<div><!></div>`);function fC(e,t){Eh(t,!0);let n=Ly(t,`mode`,3,`view`),r=Og(Pg([])),i=Og(null);async function a(){q(r,await t.adapter.list(t.tenant,{...t.target}),!0)}s_(()=>{let e=e=>{let n=e.detail?.reviewRoot;if(n==null)return;let r=X(i);q(i,n,!0);let a=t.host.ownerDocument.defaultView?.getSelection();a!=null&&r!==null&&a.rangeCount>0&&!n.contains(a.getRangeAt(0).commonAncestorContainer)&&r.contains(a.getRangeAt(0).commonAncestorContainer)&&a.removeAllRanges()};t.host.addEventListener(`st-dossier-ready`,e);let n=t.host.querySelector(`article[data-st-dossier]`);return n!==null&&q(i,n,!0),()=>t.host.removeEventListener(`st-dossier-ready`,e)}),s_(()=>{a();let e=t.adapter.subscribe?.(t.tenant,{...t.target},e=>{q(r,e,!0)});return()=>e?.()});async function o(e){await t.adapter.create({tenant:t.tenant,target:e.target,body:e.body}),await a()}async function s(e,n){await t.adapter.reply({tenant:t.tenant,target:{...t.target},threadId:e,body:n}),await a()}async function c(e){await t.adapter.setState(t.tenant,e,`closed`),await a()}async function l(e){await t.adapter.setState(t.tenant,e,`open`),await a()}async function u(e,n){await t.adapter.edit(t.tenant,e,n),await a()}async function d(e){await t.adapter.remove(t.tenant,e),await a()}var f=dC();uC(J(f),{get rootEl(){return X(i)},get mode(){return n()},get target(){return t.target},get artifactVersion(){return t.artifactVersion},get comments(){return X(r)},get currentUser(){return t.currentUser},onCreate:o,onReply:s,onResolve:c,onReopen:l,onEditComment:u,onDeleteComment:d}),G(f),Q(e,f),Dh()}function pC(e){return Pg({adapter:e.adapter,tenant:e.tenant,target:e.target,artifactVersion:e.artifactVersion,currentUser:e.currentUser,host:e.host,mode:e.mode})}var mC=new WeakMap;function hC(e,t){let n=mC.get(e);if(n!==void 0)return n.setArtifactVersion(t.artifactVersion),t.mode!==void 0&&n.setMode(t.mode),n;let r=e.ownerDocument.createElement(`div`);r.className=`st-dossier-review`,r.setAttribute(`data-st-dossier-review`,``),e.append(r);let i=()=>{r.parentElement!==e&&e.append(r)};e.addEventListener(`st-dossier-ready`,i);let a=pC({...t,host:e,mode:t.mode??`view`}),o=Nv(fC,{target:r,props:a}),s=!1,c={get mode(){return a.mode},get artifactVersion(){return a.artifactVersion},setMode(e){a.mode=e},setArtifactVersion(e){a.artifactVersion=e},destroy(){s||(s=!0,e.removeEventListener(`st-dossier-ready`,i),Lv(o),r.remove(),mC.delete(e))}};return mC.set(e,c),c}function gC(e,t){let n,r=null,i=!1,a=e.ownerDocument.defaultView,o=t?.review;function s(){let e=n?.reviewRoot,t=a?.location.hash;if(e===void 0||t===void 0||t.length<2)return;let r;try{r=decodeURIComponent(t.slice(1))}catch{return}let i=Array.from(e.querySelectorAll(`[data-anchor-id]`)).find(e=>e.dataset.anchorId===r);if(i!==void 0){for(let t=i;t!==null&&t!==e;t=t.parentElement)t instanceof HTMLDetailsElement&&(t.open=!0);i.hasAttribute(`tabindex`)||(i.tabIndex=-1),i.scrollIntoView?.({block:`start`}),i.focus({preventScroll:!0})}}function c(e){if(e.defaultPrevented||e.button!==0||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let t=e.target instanceof Element?e.target.closest(`a[href^='#']`):null;t!==null&&n?.reviewRoot.contains(t)&&t.getAttribute(`href`)===a?.location.hash&&s()}a?.addEventListener(`hashchange`,s),e.addEventListener(`click`,c);function l(){let e=n;n=void 0,e?.destroy()}return{get reviewRoot(){return n?.reviewRoot??null},get review(){return r},render(t,a){if(i)throw Error(`The dossier mount has been destroyed`);let c=Ue(t),{ref:u,sections:d}=c,f=d.some(e=>e.id===u||e.kind===`optionSet`&&e.options.some(({id:e})=>e===u)),p=`sources`in c?[...c.sources,...c.citations,...c.evidenceGroups,...c.annexes]:[];if(f||p.some(({id:e})=>e===u))throw Error(`focus-anchor-equals-document-ref: ${u} is reserved for the header anchor`);let m=d.filter(e=>e.kind===`diagram`),h=Nd(t,a?.manifest,a?.views,new Set(m.map(({id:e})=>e))),g=new Map(m.map(t=>[t.id,jd(e.ownerDocument,t,h.get(t.id))])),_=im(c,e=>Hp(Xe(e,!0),!0),g),v=t=>am(e,`choose-option`,t);l();let y=_===void 0?nm(e,c,v,`light`,g):rm(e,_,v);if(n=y,o!==void 0){let n=o.artifactVersion??S(t);r===null?r=hC(e,{...o,artifactVersion:n}):r.setArtifactVersion(n)}e.dispatchEvent(new CustomEvent(`st-dossier-ready`,{detail:{reviewRoot:y.reviewRoot},bubbles:!0})),n===y&&s()},destroy(){i=!0,a?.removeEventListener(`hashchange`,s),e.removeEventListener(`click`,c),r?.destroy(),r=null,l()}}}export{gC as mountDossier,hC as mountDossierReview};
|