@likec4/core 1.59.2 → 1.59.3

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.
@@ -1 +1 @@
1
- import{i as e,r as t,t as n}from"../rolldown-runtime.mjs";import{r}from"./mdast.mjs";function bail(e){if(e)throw e}var i=e(n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function isArray(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function isPlainObject(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function setProperty(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function getProperty(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function extend(){var e,t,n,r,i,a,u=arguments[0],d=1,f=arguments.length,p=!1;for(typeof u==`boolean`&&(p=u,u=arguments[1]||{},d=2),(u==null||typeof u!=`object`&&typeof u!=`function`)&&(u={});d<f;++d)if(e=arguments[d],e!=null)for(t in e)n=l(u,t),r=l(e,t),u!==r&&(p&&r&&(s(r)||(i=o(r)))?(i?(i=!1,a=n&&o(n)?n:[]):a=n&&s(n)?n:{},c(u,{name:t,newValue:extend(p,a,r)})):r!==void 0&&c(u,{name:t,newValue:r}));return u}}))(),1);function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function trough(){let e=[],t={run,use};return t;function run(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);next(null,...t);function next(i,...a){let o=e[++n],s=-1;if(i){r(i);return}for(;++s<t.length;)(a[s]===null||a[s]===void 0)&&(a[s]=t[s]);t=a,o?wrap(o,next)(...a):r(null,...a)}}function use(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function wrap(e,t){let n;return wrapped;function wrapped(...t){let r=e.length>t.length,i;r&&t.push(done);try{i=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return done(t)}r||(i&&i.then&&typeof i.then==`function`?i.then(then,done):i instanceof Error?done(i):then(i))}function done(e,...r){n||(n=!0,t(e,...r))}function then(e){done(null,e)}}var VFileMessage=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let i=``,a={},o=!1;if(t&&(a=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?i=e:!a.cause&&e&&(o=!0,i=e.message,a.cause=e),!a.ruleId&&!a.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?a.ruleId=n:(a.source=n.slice(0,e),a.ruleId=n.slice(e+1))}if(!a.place&&a.ancestors&&a.ancestors){let e=a.ancestors[a.ancestors.length-1];e&&(a.place=e.position)}let s=a.place&&`start`in a.place?a.place.start:a.place;this.ancestors=a.ancestors||void 0,this.cause=a.cause||void 0,this.column=s?s.column:void 0,this.fatal=void 0,this.file,this.message=i,this.line=s?s.line:void 0,this.name=r(a.place)||`1:1`,this.place=a.place||void 0,this.reason=this.message,this.ruleId=a.ruleId||void 0,this.source=a.source||void 0,this.stack=o&&a.cause&&typeof a.cause.stack==`string`?a.cause.stack:``,this.actual,this.expected,this.note,this.url}};VFileMessage.prototype.file=``,VFileMessage.prototype.name=``,VFileMessage.prototype.reason=``,VFileMessage.prototype.message=``,VFileMessage.prototype.stack=``,VFileMessage.prototype.column=void 0,VFileMessage.prototype.line=void 0,VFileMessage.prototype.ancestors=void 0,VFileMessage.prototype.cause=void 0,VFileMessage.prototype.fatal=void 0,VFileMessage.prototype.place=void 0,VFileMessage.prototype.ruleId=void 0,VFileMessage.prototype.source=void 0;const a={basename,dirname,extname,join,sep:`/`};function basename(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);assertPath$1(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function dirname(e){if(assertPath$1(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function extname(e){assertPath$1(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function join(...e){let t=-1,n;for(;++t<e.length;)assertPath$1(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:normalize(n)}function normalize(e){assertPath$1(e);let t=e.codePointAt(0)===47,n=normalizeString(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function normalizeString(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(i!==o-1&&a!==1)if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function assertPath$1(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}t(assertPath$1,`assertPath`);const o={cwd};function cwd(){return`/`}function isUrl(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function urlToPath(e){if(typeof e==`string`)e=new URL(e);else if(!isUrl(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return getPathFromURLPosix(e)}function getPathFromURLPosix(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}const s=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`];var VFile=class{constructor(e){let t;t=e?isUrl(e)?{path:e}:typeof e==`string`||isUint8Array$1(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:o.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<s.length;){let e=s[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)s.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?a.basename(this.path):void 0}set basename(e){assertNonEmpty(e,`basename`),assertPart(e,`basename`),this.path=a.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?a.dirname(this.path):void 0}set dirname(e){assertPath(this.basename,`dirname`),this.path=a.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?a.extname(this.path):void 0}set extname(e){if(assertPart(e,`extname`),assertPath(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=a.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){isUrl(e)&&(e=urlToPath(e)),assertNonEmpty(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?a.basename(this.path,this.extname):void 0}set stem(e){assertNonEmpty(e,`stem`),assertPart(e,`stem`),this.path=a.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new VFileMessage(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function assertPart(e,t){if(e&&e.includes(a.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+a.sep+"`")}function assertNonEmpty(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function assertPath(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function isUint8Array$1(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}t(isUint8Array$1,`isUint8Array`);const CallableInstance=(function(e){let t=this.constructor.prototype,n=t[e],apply=function(){return n.apply(apply,arguments)};return Object.setPrototypeOf(apply,t),apply}),c={}.hasOwnProperty,l=new class Processor extends CallableInstance{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=trough()}copy(){let e=new Processor,t=-1;for(;++t<this.attachers.length;){let n=this.attachers[t];e.use(...n)}return e.data((0,i.default)(!0,{},this.namespace)),e}data(e,t){return typeof e==`string`?arguments.length===2?(assertUnfrozen(`data`,this.frozen),this.namespace[e]=t,this):c.call(this.namespace,e)&&this.namespace[e]||void 0:e?(assertUnfrozen(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=vfile(e),n=this.parser||this.Parser;return assertParser(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),assertParser(`process`,this.parser||this.Parser),assertCompiler(`process`,this.compiler||this.Compiler),t?executor(void 0,t):new Promise(executor);function executor(r,i){let a=vfile(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return realDone(e);let i=t,a=n.stringify(i,r);looksLikeAValue(a)?r.value=a:r.result=a,realDone(e,r)});function realDone(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),assertParser(`processSync`,this.parser||this.Parser),assertCompiler(`processSync`,this.compiler||this.Compiler),this.process(e,realDone),assertDone(`processSync`,`process`,t),n;function realDone(e,r){t=!0,bail(e),n=r}}run(e,t,n){assertNode(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?executor(void 0,n):new Promise(executor);function executor(i,a){let o=vfile(t);r.run(e,o,realDone);function realDone(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,realDone),assertDone(`runSync`,`run`,n),r;function realDone(e,t){bail(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=vfile(t),r=this.compiler||this.Compiler;return assertCompiler(`stringify`,r),assertNode(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(assertUnfrozen(`use`,this.frozen),e!=null)if(typeof e==`function`)addPlugin(e,t);else if(typeof e==`object`)Array.isArray(e)?addList(e):addPreset(e);else throw TypeError("Expected usable value, not `"+e+"`");return this;function add(e){if(typeof e==`function`)addPlugin(e,[]);else if(typeof e==`object`)if(Array.isArray(e)){let[t,...n]=e;addPlugin(t,n)}else addPreset(e);else throw TypeError("Expected usable value, not `"+e+"`")}function addPreset(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");addList(e.plugins),e.settings&&(r.settings=(0,i.default)(!0,r.settings,e.settings))}function addList(e){let t=-1;if(e!=null)if(Array.isArray(e))for(;++t<e.length;){let n=e[t];add(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}function addPlugin(e,t){let r=-1,a=-1;for(;++r<n.length;)if(n[r][0]===e){a=r;break}if(a===-1)n.push([e,...t]);else if(t.length>0){let[r,...o]=t,s=n[a][1];isPlainObject(s)&&isPlainObject(r)&&(r=(0,i.default)(!0,s,r)),n[a]=[e,r,...o]}}}}().freeze();function assertParser(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function assertCompiler(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function assertUnfrozen(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function assertNode(e){if(!isPlainObject(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function assertDone(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function vfile(e){return looksLikeAVFile(e)?e:new VFile(e)}function looksLikeAVFile(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function looksLikeAValue(e){return typeof e==`string`||isUint8Array(e)}function isUint8Array(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}export{l as t};
1
+ import{i as e,r as t,t as n}from"../rolldown-runtime.mjs";import{r}from"./mdast.mjs";function bail(e){if(e)throw e}var i=e(n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function isArray(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function isPlainObject(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function setProperty(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function getProperty(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function extend(){var e,t,n,r,i,a,u=arguments[0],d=1,f=arguments.length,p=!1;for(typeof u==`boolean`&&(p=u,u=arguments[1]||{},d=2),(u==null||typeof u!=`object`&&typeof u!=`function`)&&(u={});d<f;++d)if(e=arguments[d],e!=null)for(t in e)n=l(u,t),r=l(e,t),u!==r&&(p&&r&&(s(r)||(i=o(r)))?(i?(i=!1,a=n&&o(n)?n:[]):a=n&&s(n)?n:{},c(u,{name:t,newValue:extend(p,a,r)})):r!==void 0&&c(u,{name:t,newValue:r}));return u}}))(),1);function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function trough(){let e=[],t={run,use};return t;function run(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);next(null,...t);function next(i,...a){let o=e[++n],s=-1;if(i){r(i);return}for(;++s<t.length;)(a[s]===null||a[s]===void 0)&&(a[s]=t[s]);t=a,o?wrap(o,next)(...a):r(null,...a)}}function use(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function wrap(e,t){let n;return wrapped;function wrapped(...t){let r=e.length>t.length,i;r&&t.push(done);try{i=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return done(t)}r||(i&&i.then&&typeof i.then==`function`?i.then(then,done):i instanceof Error?done(i):then(i))}function done(e,...r){n||(n=!0,t(e,...r))}function then(e){done(null,e)}}var VFileMessage=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let i=``,a={},o=!1;if(t&&(a=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?i=e:!a.cause&&e&&(o=!0,i=e.message,a.cause=e),!a.ruleId&&!a.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?a.ruleId=n:(a.source=n.slice(0,e),a.ruleId=n.slice(e+1))}if(!a.place&&a.ancestors&&a.ancestors){let e=a.ancestors[a.ancestors.length-1];e&&(a.place=e.position)}let s=a.place&&`start`in a.place?a.place.start:a.place;this.ancestors=a.ancestors||void 0,this.cause=a.cause||void 0,this.column=s?s.column:void 0,this.fatal=void 0,this.file,this.message=i,this.line=s?s.line:void 0,this.name=r(a.place)||`1:1`,this.place=a.place||void 0,this.reason=this.message,this.ruleId=a.ruleId||void 0,this.source=a.source||void 0,this.stack=o&&a.cause&&typeof a.cause.stack==`string`?a.cause.stack:``,this.actual,this.expected,this.note,this.url}};VFileMessage.prototype.file=``,VFileMessage.prototype.name=``,VFileMessage.prototype.reason=``,VFileMessage.prototype.message=``,VFileMessage.prototype.stack=``,VFileMessage.prototype.column=void 0,VFileMessage.prototype.line=void 0,VFileMessage.prototype.ancestors=void 0,VFileMessage.prototype.cause=void 0,VFileMessage.prototype.fatal=void 0,VFileMessage.prototype.place=void 0,VFileMessage.prototype.ruleId=void 0,VFileMessage.prototype.source=void 0;const a={basename,dirname,extname,join,sep:`/`};function basename(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);assertPath$1(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function dirname(e){if(assertPath$1(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function extname(e){assertPath$1(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function join(...e){let t=-1,n;for(;++t<e.length;)assertPath$1(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:normalize(n)}function normalize(e){assertPath$1(e);let t=e.codePointAt(0)===47,n=normalizeString(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function normalizeString(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(i!==o-1&&a!==1){if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1}i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function assertPath$1(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}t(assertPath$1,`assertPath`);const o={cwd};function cwd(){return`/`}function isUrl(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function urlToPath(e){if(typeof e==`string`)e=new URL(e);else if(!isUrl(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return getPathFromURLPosix(e)}function getPathFromURLPosix(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}const s=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`];var VFile=class{constructor(e){let t;t=e?isUrl(e)?{path:e}:typeof e==`string`||isUint8Array$1(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:o.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<s.length;){let e=s[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)s.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?a.basename(this.path):void 0}set basename(e){assertNonEmpty(e,`basename`),assertPart(e,`basename`),this.path=a.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?a.dirname(this.path):void 0}set dirname(e){assertPath(this.basename,`dirname`),this.path=a.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?a.extname(this.path):void 0}set extname(e){if(assertPart(e,`extname`),assertPath(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=a.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){isUrl(e)&&(e=urlToPath(e)),assertNonEmpty(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?a.basename(this.path,this.extname):void 0}set stem(e){assertNonEmpty(e,`stem`),assertPart(e,`stem`),this.path=a.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new VFileMessage(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function assertPart(e,t){if(e&&e.includes(a.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+a.sep+"`")}function assertNonEmpty(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function assertPath(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function isUint8Array$1(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}t(isUint8Array$1,`isUint8Array`);const CallableInstance=(function(e){let t=this.constructor.prototype,n=t[e],apply=function(){return n.apply(apply,arguments)};return Object.setPrototypeOf(apply,t),apply}),c={}.hasOwnProperty,l=new class Processor extends CallableInstance{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=trough()}copy(){let e=new Processor,t=-1;for(;++t<this.attachers.length;){let n=this.attachers[t];e.use(...n)}return e.data((0,i.default)(!0,{},this.namespace)),e}data(e,t){return typeof e==`string`?arguments.length===2?(assertUnfrozen(`data`,this.frozen),this.namespace[e]=t,this):c.call(this.namespace,e)&&this.namespace[e]||void 0:e?(assertUnfrozen(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=vfile(e),n=this.parser||this.Parser;return assertParser(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),assertParser(`process`,this.parser||this.Parser),assertCompiler(`process`,this.compiler||this.Compiler),t?executor(void 0,t):new Promise(executor);function executor(r,i){let a=vfile(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return realDone(e);let i=t,a=n.stringify(i,r);looksLikeAValue(a)?r.value=a:r.result=a,realDone(e,r)});function realDone(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),assertParser(`processSync`,this.parser||this.Parser),assertCompiler(`processSync`,this.compiler||this.Compiler),this.process(e,realDone),assertDone(`processSync`,`process`,t),n;function realDone(e,r){t=!0,bail(e),n=r}}run(e,t,n){assertNode(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?executor(void 0,n):new Promise(executor);function executor(i,a){let o=vfile(t);r.run(e,o,realDone);function realDone(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,realDone),assertDone(`runSync`,`run`,n),r;function realDone(e,t){bail(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=vfile(t),r=this.compiler||this.Compiler;return assertCompiler(`stringify`,r),assertNode(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(assertUnfrozen(`use`,this.frozen),e!=null){if(typeof e==`function`)addPlugin(e,t);else if(typeof e==`object`)Array.isArray(e)?addList(e):addPreset(e);else throw TypeError("Expected usable value, not `"+e+"`")}return this;function add(e){if(typeof e==`function`)addPlugin(e,[]);else if(typeof e==`object`){if(Array.isArray(e)){let[t,...n]=e;addPlugin(t,n)}else addPreset(e)}else throw TypeError("Expected usable value, not `"+e+"`")}function addPreset(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");addList(e.plugins),e.settings&&(r.settings=(0,i.default)(!0,r.settings,e.settings))}function addList(e){let t=-1;if(e!=null){if(Array.isArray(e))for(;++t<e.length;){let n=e[t];add(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}}function addPlugin(e,t){let r=-1,a=-1;for(;++r<n.length;)if(n[r][0]===e){a=r;break}if(a===-1)n.push([e,...t]);else if(t.length>0){let[r,...o]=t,s=n[a][1];isPlainObject(s)&&isPlainObject(r)&&(r=(0,i.default)(!0,s,r)),n[a]=[e,r,...o]}}}}().freeze();function assertParser(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function assertCompiler(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function assertUnfrozen(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function assertNode(e){if(!isPlainObject(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function assertDone(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function vfile(e){return looksLikeAVFile(e)?e:new VFile(e)}function looksLikeAVFile(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function looksLikeAValue(e){return typeof e==`string`||isUint8Array(e)}function isUint8Array(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}export{l as t};
@@ -1,4 +1,4 @@
1
- import{n as e,r as t}from"./rolldown-runtime.mjs";import{An as n,Cn as r,Ct as i,Et as a,Fn as o,Ft as s,I as c,In as l,Jt as u,Ln as d,Lt as f,Mt as p,N as m,Pt as h,Sn as g,Tn as ee,Wt as _,Y as te,Zt as v,_n as y,_t as ne,bn as b,cn as re,dn as x,gn as S,hn as C,jn as w,ln as ie,nn as T,nt as E,ot as ae,t as D,tn as oe,un as O,vn as k,vt as se,wn as A,wt as j,xt as ce,yn as M,yt as le,zt as N}from"./types.mjs";import{E as P,F,O as I,P as L,Q as R,T as ue,Y as z,Z as B,c as de,i as V,j as fe,l as H,m as pe,r as U,s as W,w as G}from"./libs/remeda.mjs";import{t as K}from"./libs/mnemonist.mjs";import{n as me,t as he}from"./calcDriftsFromSnapshot.mjs";var ElementModel=class{$model;$element;Aux;id;_literalId;hierarchyLevel;imported;constructor(e,t){this.$model=e,this.$element=t,this.id=this.$element.id,this._literalId=this.$element.id;let[n,r]=ce(this.id);n?(this.imported={from:n,fqn:r},this.hierarchyLevel=C(r)):(this.imported=null,this.hierarchyLevel=C(this.id))}get name(){return M(this.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$element.kind}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get tags(){return _(this,Symbol.for(`tags`),()=>V([...this.$element.tags??[],...this.$model.specification.elements[this.$element.kind]?.tags??[]]))}get metadata(){return this.$element.metadata??{}}get title(){return this.$element.title}get hasSummary(){return!!this.$element.summary&&!!this.$element.description&&!I(this.$element.summary,this.$element.description)}get summary(){return D.memoize(this,`summary`,l(this.$element))}get description(){return D.memoize(this,`description`,o(this.$element))}get technology(){return this.$element.technology??null}get links(){return this.$element.links??[]}get defaultView(){return _(this,Symbol.for(`defaultView`),()=>v(this.scopedViews())??null)}get isRoot(){return this.parent===null}get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$element.style}))}get projectId(){return this.imported?.from??this.$model.projectId}isAncestorOf(e){return S(this,e)}isDescendantOf(e){return S(e,this)}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=x(this.id,e.id);return t?this.$model.element(t):null}children(){return this.$model.children(this)}descendants(e){return e?g([...this.$model.descendants(this)],e)[Symbol.iterator]():this.$model.descendants(this)}siblings(){return this.$model.siblings(this)}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}get allOutgoing(){return _(this,Symbol.for(`allOutgoing`),()=>new Set(this.outgoing()))}get allIncoming(){return _(this,Symbol.for(`allIncoming`),()=>new Set(this.incoming()))}views(){return _(this,Symbol.for(`views`),()=>{let e=new Set;for(let t of this.$model.views())t.includesElement(this.id)&&e.add(t);return e})}scopedViews(){return _(this,Symbol.for(`scopedViews`),()=>{let e=new Set;for(let t of this.$model.views())t.isScopedElementView()&&t.viewOf.id===this.id&&e.add(t);return e})}isDeployed(){return P(v(this.deployments()))}deployments(){return this.$model.deployment.instancesOf(this)}hasMetadata(){return!!this.$element.metadata&&!F(this.$element.metadata)}getMetadata(e){return e?this.$element.metadata?.[e]:this.$element.metadata??{}}isTagged(e){return this.tags.includes(e)}},AbstractDeploymentElementModel=class{Aux;get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$node.style}))}get name(){return M(this.id)}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get summary(){return D.memoize(this,`summary`,l(this.$node))}get description(){return D.memoize(this,`description`,o(this.$node))}get technology(){return this.$node.technology??null}get links(){return this.$node.links??[]}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=x(this.id,e.id);return t?this.$model.node(t):null}siblings(){return this.$model.siblings(this)}isSibling(e){return this.parent===e.parent}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}*views(){for(let e of this.$model.views())e._type===`deployment`&&e.includesDeployment(this.id)&&(yield e)}isDeploymentNode(){return!1}isInstance(){return!1}get allOutgoing(){return _(this,Symbol.for(`allOutgoing`),()=>q.from(new Set(this.outgoingModelRelationships()),new Set(this.outgoing())))}get allIncoming(){return _(this,Symbol.for(`allIncoming`),()=>q.from(new Set(this.incomingModelRelationships()),new Set(this.incoming())))}hasMetadata(){return!!this.$node.metadata&&!F(this.$node.metadata)}getMetadata(e){return e?this.$node.metadata?.[e]:this.$node.metadata??{}}isTagged(e){return this.tags.includes(e)}},DeploymentNodeModel=class extends AbstractDeploymentElementModel{$model;$node;id;_literalId;title;hierarchyLevel;constructor(e,t){super(),this.$model=e,this.$node=t,this.id=t.id,this._literalId=t.id,this.title=t.title,this.hierarchyLevel=C(t.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$node.kind}get metadata(){return this.$node.metadata??{}}get tags(){return _(this,Symbol.for(`tags`),()=>V([...this.$node.tags??[],...this.$model.$model.specification.deployments[this.kind]?.tags??[]]))}children(){return this.$model.children(this)}descendants(e=`desc`){return this.$model.descendants(this,e)}isDeploymentNode(){return!0}*instances(){for(let e of this.descendants(`desc`))e.isInstance()&&(yield e)}onlyOneInstance(){let e=this.children();if(e.size!==1)return null;let t=v(e);return t?t.isInstance()?t:t.onlyOneInstance():null}_relationshipsFromInstances=null;relationshipsFromInstances(){if(this._relationshipsFromInstances)return this._relationshipsFromInstances;let{outgoing:e,incoming:t}=this._relationshipsFromInstances={outgoing:new Set,incoming:new Set};for(let n of this.instances()){for(let t of n.element.outgoing())e.add(t);for(let e of n.element.incoming())t.add(e)}return this._relationshipsFromInstances}outgoingModelRelationships(){return this.relationshipsFromInstances().outgoing.values()}incomingModelRelationships(){return this.relationshipsFromInstances().incoming.values()}internalModelRelationships(){let{outgoing:e,incoming:t}=this.relationshipsFromInstances();return f(t,e)}},DeployedInstanceModel=class extends AbstractDeploymentElementModel{$model;$instance;element;id;_literalId;title;hierarchyLevel;constructor(e,t,n){super(),this.$model=e,this.$instance=t,this.element=n,this.id=t.id,this._literalId=t.id,this.title=t.title??n.title,this.hierarchyLevel=C(t.id)}get $node(){return this.$instance}get parent(){return w(this.$model.parent(this),`Parent of ${this.id} not found`)}get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.element.$element.style,...this.$instance.style}))}get tags(){return _(this,Symbol.for(`tags`),()=>V([...this.$instance.tags??[],...this.element.tags]))}get kind(){return this.element.kind}get metadata(){return this.$instance.metadata??this.element.metadata??{}}get summary(){return D.memoize(this,`summary`,l(this.$instance)??l(this.element.$element))}get description(){return D.memoize(this,`description`,o(this.$instance)??o(this.element.$element))}get technology(){return this.$instance.technology??this.element.technology??null}get links(){return this.$instance.links??this.element.links}isInstance(){return!0}outgoingModelRelationships(){return this.element.outgoing()}incomingModelRelationships(){return this.element.incoming()}*views(){for(let e of this.$model.views())if(e._type===`deployment`){if(e.includesDeployment(this.id)){yield e;continue}e.includesDeployment(this.parent.id)&&this.parent.onlyOneInstance()&&(yield e)}}},NestedElementOfDeployedInstanceModel=class{instance;element;constructor(e,t){this.instance=e,this.element=t}get id(){return this.instance.id}get _literalId(){return this.instance.id}get style(){return _(this,`style `,()=>({shape:this.element.shape,color:this.element.color,...this.element.$element.style}))}get shape(){return this.element.shape}get color(){return this.element.color}get title(){return this.element.title}get summary(){return this.element.summary}get description(){return this.element.description}get technology(){return this.element.technology}isDeploymentNode(){return!1}isInstance(){return!1}},DeploymentRelationModel=class{$model;$relationship;boundary;source;target;constructor(e,t){this.$model=e,this.$relationship=t,this.source=e.deploymentRef(t.source),this.target=e.deploymentRef(t.target);let n=x(this.source.id,this.target.id);this.boundary=n?this.$model.node(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return P(this.$relationship.title)?this.$relationship.title:null}get technology(){return L(this.$relationship.technology)?(this.kind&&this.$model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!I(this.$relationship.summary,this.$relationship.description)}get summary(){return D.memoize(this,`summary`,l(this.$relationship))}get description(){return D.memoize(this,`description`,o(this.$relationship))}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get navigateTo(){return this.$relationship.navigateTo?this.$model.$model.view(this.$relationship.navigateTo):null}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.$model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.$model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.$model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.$model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!0}isModelRelation(){return!1}hasMetadata(){return!!this.$relationship.metadata&&!F(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},q=class RelationshipsAccum{model;deployment;static empty(){return new RelationshipsAccum}static from(e,t){return new RelationshipsAccum(new Set(e),new Set(t))}constructor(e=new Set,t=new Set){this.model=e,this.deployment=t}get isEmpty(){return this.model.size===0&&this.deployment.size===0}get nonEmpty(){return this.model.size>0||this.deployment.size>0}get size(){return this.model.size+this.deployment.size}intersect(e){return RelationshipsAccum.from(f(this.model,e.model),f(this.deployment,e.deployment))}difference(e){return RelationshipsAccum.from(h(this.model,e.model),h(this.deployment,e.deployment))}union(e){return RelationshipsAccum.from(N(this.model,e.model),N(this.deployment,e.deployment))}};const getId=e=>typeof e==`string`?e:e.id,ge=`/`,splitViewTitle=e=>{if(n(!e.includes(`
2
- `),`View title cannot contain newlines`),e.includes(`/`)){let t=e.split(`/`).map(e=>e.trim()).filter(e=>e.length>0);return B(t,1)?t:[``]}return[e.trim()]},normalizeViewPath=e=>splitViewTitle(e).join(`/`),getViewFolderPath=e=>{let t=splitViewTitle(e);return B(t,2)?t.slice(0,-1).join(`/`):null},extractViewTitleFromPath=e=>e.includes(`/`)?splitViewTitle(e).at(-1)??e:e.trim();var LikeC4DeploymentModel=class{$model;#e=new Map;#t=new Map;#n=new K.default(()=>new Set);#r=new K.default(()=>new Set);#i=new Set;#a=new Map;#o=new K.default(()=>new Set);#s=new K.default(()=>new Set);#c=new K.default(()=>new Set);#l=new K.default(()=>new Set);#u=new Map;$deployments;constructor(e){this.$model=e;let t=this.$deployments=e.$data.deployments,n=U(t.elements);for(let e of r(n)){let t=this.addElement(e);for(let e of t.tags)this.#l.get(e).add(t);t.isInstance()&&this.#r.get(t.element.id).add(t)}for(let e of U(t.relations)){let t=this.addRelation(e);for(let e of t.tags)this.#l.get(e).add(t)}}get $styles(){return this.$model.$styles}get projectId(){return this.$model.projectId}get project(){return this.$model.project}get specification(){return this.$model.specification}element(e){if(e instanceof DeploymentNodeModel||e instanceof DeployedInstanceModel)return e;let t=getId(e);return w(this.#e.get(t),`Element ${t} not found`)}findElement(e){return this.#e.get(e)??null}node(e){let t=this.element(e);return n(t.isDeploymentNode(),`Element ${t.id} is not a deployment node`),t}findNode(e){let t=this.findElement(e);return t?(n(t.isDeploymentNode(),`Element ${t?.id} is not a deployment node`),t):null}instance(e){let t=this.element(e);return n(t.isInstance(),`Element ${t.id} is not a deployed instance`),t}findInstance(e){let t=this.findElement(e);return t?(n(t.isInstance(),`Element ${t?.id} is not a deployed instance`),t):null}roots(){return this.#i.values()}elements(){return this.#e.values()}*nodes(){for(let e of this.#e.values())e.isDeploymentNode()&&(yield e)}*nodesOfKind(e){for(let t of this.#e.values())t.isDeploymentNode()&&t.kind===e&&(yield t)}*instances(){for(let e of this.#e.values())e.isInstance()&&(yield e)}*instancesOf(e){let t=getId(e),n=this.#r.get(t);n&&(yield*n)}deploymentRef(e){if(E.isInsideInstanceRef(e)){let{deployment:t,element:n}=e;return ie(this.#u,`${t}@${n}`,()=>new NestedElementOfDeployedInstanceModel(this.instance(t),this.$model.element(n)))}return this.element(e.deployment)}relationships(){return this.#a.values()}relationship(e){let t=getId(e);return w(this.#a.get(t),`DeploymentRelationModel ${t} not found`)}findRelationship(e){return this.#a.get(e)??null}*views(){for(let e of this.$model.views())e.isDeploymentView()&&(yield e)}parent(e){let t=getId(e);return this.#t.get(t)||null}children(e){let t=getId(e);return this.#n.get(t)}*siblings(e){let t=getId(e),n=this.parent(e)?.children()??this.roots();for(let e of n)e.id!==t&&(yield e)}*ancestors(e){let t=getId(e),n;for(;n=this.#t.get(t);)yield n,t=n.id}*descendants(e,t=`desc`){for(let n of this.children(e))t===`asc`?(yield n,yield*this.descendants(n.id)):(yield*this.descendants(n.id),yield n)}*incoming(e,t=`all`){let n=getId(e);for(let e of this.#o.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=getId(e);for(let e of this.#s.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}addElement(e){if(this.#e.has(e.id))throw Error(`Element ${e.id} already exists`);let t=te(e)?new DeploymentNodeModel(this,Object.freeze(e)):new DeployedInstanceModel(this,Object.freeze(e),this.$model.element(e.element));this.#e.set(t.id,t);let r=b(t.id);return r?(n(this.#e.has(r),`Parent ${r} of ${t.id} not found`),this.#t.set(t.id,this.node(r)),this.#n.get(r).add(t)):(n(t.isDeploymentNode(),`Root element ${t.id} is not a deployment node`),this.#i.add(t)),t}addRelation(e){if(this.#a.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new DeploymentRelationModel(this,Object.freeze(e));this.#a.set(t.id,t),this.#o.get(t.target.id).add(t),this.#s.get(t.source.id).add(t);let n=t.boundary?.id??null;if(n)for(let e of[n,...O(n)])this.#c.get(e).add(t);for(let e of O(t.source.id)){if(e===n)break;this.#s.get(e).add(t)}for(let e of O(t.target.id)){if(e===n)break;this.#o.get(e).add(t)}return t}},RelationshipModel=class{model;$relationship;source;target;boundary;constructor(e,t){this.model=e,this.$relationship=t,this.source=e.element(E.flatten(t.source)),this.target=e.element(E.flatten(t.target));let n=x(this.source.id,this.target.id);this.boundary=n?this.model.element(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return L(this.$relationship.title)?null:this.$relationship.title}get technology(){return L(this.$relationship.technology)?(this.kind&&this.model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!I(this.$relationship.summary,this.$relationship.description)}get summary(){return D.memoize(this,`summary`,l(this.$relationship))}get description(){return D.memoize(this,`description`,o(this.$relationship))}get navigateTo(){return this.$relationship.navigateTo?this.model.view(this.$relationship.navigateTo):null}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!1}isModelRelation(){return!0}hasMetadata(){return!!this.$relationship.metadata&&!F(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},EdgeModel=class{source;target;Aux;$viewModel;$view;$edge;constructor(e,t,n,r){this.source=n,this.target=r,this.$viewModel=e,this.$view=e.$view,this.$edge=t}get id(){return this.$edge.id}get parent(){return this.$edge.parent?this.$viewModel.node(this.$edge.parent):null}get label(){return this.$edge.label??null}get description(){return D.memoize(this,`description`,this.$edge.description)}get technology(){return this.$edge.technology??null}hasParent(){return this.$edge.parent!==null}get tags(){return this.$edge.tags??[]}get navigateTo(){return this.$edge.navigateTo?this.$viewModel.$model.view(this.$edge.navigateTo):null}get color(){return this.$edge.color}get line(){return this.$edge.line??this.$viewModel.$styles.defaults.relationship.line}get head(){return this.$edge.head??this.$viewModel.$styles.defaults.relationship.arrow}get tail(){return this.$edge.tail}isStep(){return le(this.$edge.id)}*relationships(e){for(let t of this.$edge.relations)if(e){let n=this.$viewModel.$model.findRelationship(t,e);n&&(yield n)}else yield this.$viewModel.$model.relationship(t)}includesRelation(e){let t=typeof e==`string`?e:e.id;return this.$edge.relations.includes(t)}isTagged(e){return this.tags.includes(e)}},NodeModel=class{Aux;$viewModel;$view;$node;constructor(e,t){this.$viewModel=e,this.$view=e.$view,this.$node=t}get id(){return this.$node.id}get title(){return this.$node.title}get kind(){return this.$node.kind}get description(){return D.memoize(this,`description`,this.$node.description)}get technology(){return this.$node.technology??null}get notes(){return D.memoize(this,`notes`,this.$node.notes)}get parent(){return this.$node.parent?this.$viewModel.node(this.$node.parent):null}get element(){let e=this.$node.modelRef;return e?this.$viewModel.$model.element(e):null}get deployment(){let e=this.$node.deploymentRef;return e?this.$viewModel.$model.deployment.element(e):null}get shape(){return this.$node.shape}get color(){return this.$node.color}get icon(){return this.$node.icon??null}get tags(){return this.$node.tags}get links(){return this.$node.links??[]}get navigateTo(){return this.$node.navigateTo?this.$viewModel.$model.view(this.$node.navigateTo):null}get style(){return this.$node.style}get x(){return`x`in this.$node?this.$node.x:void 0}get y(){return`y`in this.$node?this.$node.y:void 0}get width(){return`width`in this.$node?this.$node.width:void 0}get height(){return`height`in this.$node?this.$node.height:void 0}children(){return _(this,`children`,()=>new Set(this.$node.children.map(e=>this.$viewModel.node(e))))}*ancestors(){let e=this.parent;for(;e;)yield e,e=e.parent}*siblings(){let e=this.parent?.children()??this.$viewModel.roots();for(let t of e)t.id!==this.id&&(yield t)}*incoming(e=`all`){for(let t of this.$node.inEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.target.id===this.id:case e===`to-descendants`&&n.target.id!==this.id:yield n;break}}}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoing(e=`all`){for(let t of this.$node.outEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.source.id===this.id:case e===`from-descendants`&&n.source.id!==this.id:yield n;break}}}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}isLayouted(){return`width`in this.$node&&`height`in this.$node}hasChildren(){return this.$node.children.length>0}hasParent(){return this.$node.parent!==null}hasElement(){return P(this.$node.modelRef)}hasDeployment(){return P(this.$node.deploymentRef)}hasDeployedInstance(){return this.hasElement()&&this.hasDeployment()}isGroup(){return se(this.$node)}isTagged(e){return this.tags.includes(e)}},LikeC4ViewModel=class{Aux;#e;#t=new Set;#n=new Map;#r=new Map;#i=new Set;#a=new Set;#o=new Set;#s=new K.default(e=>new Set);#c;id;$model;title;folder;viewPath;constructor(e,t,n,r){this.$model=e,this.#e=n,this.id=n.id,this.folder=t,this.#c=r;for(let e of this.#e.nodes){let t=new NodeModel(this,Object.freeze(e));this.#n.set(e.id,t),e.parent||this.#t.add(t),e.deploymentRef&&this.#a.add(e.deploymentRef),e.modelRef&&this.#i.add(e.modelRef);for(let e of t.tags)this.#s.get(e).add(t)}for(let e of this.#e.edges){let t=new EdgeModel(this,Object.freeze(e),this.node(e.source),this.node(e.target));for(let e of t.tags)this.#s.get(e).add(t);for(let t of e.relations)this.#o.add(t);this.#r.set(e.id,t)}this.title=n.title?extractViewTitleFromPath(n.title):null,this.viewPath=n.title?normalizeViewPath(n.title):n.id}get $styles(){return this.$model.$styles}get _type(){return this.#e[j]}get stage(){return this.#e[i]}get bounds(){if(`bounds`in this.#e)return this.#e.bounds;if(this.#c)return this.#c.bounds;throw Error(`View is not layouted`)}get titleOrId(){return this.title??this.viewOf?.title??this.id}get titleOrUntitled(){return this.title??`Untitled`}get breadcrumbs(){return _(this,`breadcrumbs`,()=>this.folder.isRoot?[this]:[...this.folder.breadcrumbs,this])}get description(){return D.memoize(this,`description`,this.#e.description)}get tags(){return this.#e.tags??[]}get links(){return this.#e.links??[]}get viewOf(){if(this.isElementView()){let e=this.#e.viewOf;return e?this.$model.element(e):null}return null}get mode(){return this.isDynamicView()?this.#e.variant??`diagram`:null}get includedTags(){return[...this.#s.keys()]}get $view(){if(!this.isLayouted()||`drifts`in this.#e)return this.#e;let e=this.#c;return e?_(this,`withDriftReasons`,()=>he(this.#e,e)):this.#e}get $layouted(){if(!this.isLayouted())throw Error(`View is not layouted`);return this.$manual??this.#e}get hasManualLayout(){return this.#c!==void 0}get hasLayoutDrifts(){if(!this.isLayouted())return!1;let e=this.$manual;return!!e?.drifts&&e.drifts.length>0}get $manual(){if(!this.isLayouted())return null;let e=this.#c;return e?this.#e._layout===`manual`?this.#e:_(this,`snapshotWithManualLayout`,()=>me(this.#e,e)):null}get projectId(){return this.$model.projectId}roots(){return this.#t.values()}*compounds(){for(let e of this.#n.values())e.hasChildren()&&(yield e)}node(e){let t=getId(e);return w(this.#n.get(t),`Node ${t} not found in view ${this.#e.id}`)}findNode(e){return this.#n.get(getId(e))??null}findNodeWithElement(e){let t=getId(e);return this.#i.has(t)?oe(this.#n.values(),e=>e.hasElement()&&e.element.id===t)??null:null}nodes(){return this.#n.values()}edge(e){let t=getId(e);return w(this.#r.get(t),`Edge ${t} not found in view ${this.#e.id}`)}findEdge(e){return this.#r.get(getId(e))??null}edges(){return this.#r.values()}*edgesWithRelation(e){for(let t of this.#r.values())t.includesRelation(e)&&(yield t)}*elements(){for(let e of this.#n.values())e.hasElement()&&(yield e)}isTagged(e){return this.tags.includes(e)}includesElement(e){return this.#i.has(getId(e))}includesDeployment(e){return this.#a.has(getId(e))}includesRelation(e){return this.#o.has(getId(e))}isComputed(){return this.#e[i]===`computed`}isLayouted(){return this.#e[i]===`layouted`}isDiagram(){return this.#e[i]===`layouted`}isElementView(){return this.#e[j]===`element`}isScopedElementView(){return this.#e._type===`element`&&P(this.#e.viewOf)}isDeploymentView(){return this.#e[j]===`deployment`}isDynamicView(){return this.#e[j]===`dynamic`}},J=class LikeC4ViewsFolder{$model;path;title;isRoot;parentPath;defaultViewId;constructor(e,t,n){this.$model=e,this.path=t.join(`/`),this.isRoot=this.path===``,this.title=ue(t),this.isRoot?this.parentPath=void 0:this.parentPath=t.slice(0,-1).join(`/`),this.defaultViewId=n}get defaultView(){return this.defaultViewId?this.$model.view(this.defaultViewId):null}get breadcrumbs(){return n(!this.isRoot,`Root view folder has no breadcrumbs`),_(this,`breadcrumbs`,()=>{let e=this.parent;return e?e.isRoot?[e,this]:[...e.breadcrumbs,this]:[this]})}get parent(){return n(!this.isRoot,`Root view folder has no parent`),L(this.parentPath)?null:this.$model.viewFolder(this.parentPath)}get children(){return this.$model.viewFolderItems(this.path)}get folders(){return _(this,`folders`,()=>{let e=[];for(let t of this.children)t instanceof LikeC4ViewsFolder&&e.push(t);return e})}get views(){return _(this,`views`,()=>{let e=[];for(let t of this.children)t instanceof LikeC4ViewModel&&e.push(t);return e})}},Y=class LikeC4Model{Aux;_elements=new Map;_parents=new Map;_children=new K.default(()=>new Set);_rootElements=new Set;_relations=new Map;_incoming=new K.default(()=>new Set);_outgoing=new K.default(()=>new Set);_internal=new K.default(()=>new Set);_views=new Map;_rootViewFolder;_viewFolders=new Map;_viewFolderItems=new K.default(()=>new Set);_allTags=new K.default(()=>new Set);static fromParsed(e){return new LikeC4Model(e)}static create(e){return new LikeC4Model(e)}static fromDump(e){let{_stage:t=`layouted`,projectId:n=`unknown`,project:r,globals:a,imports:o,deployments:s,views:c,relations:l,elements:u,specification:d}=e;return new LikeC4Model({[i]:t,projectId:n,project:r,globals:{predicates:a?.predicates??{},dynamicPredicates:a?.dynamicPredicates??{},styles:a?.styles??{}},imports:o??{},deployments:{elements:s?.elements??{},relations:s?.relations??{}},views:c??{},relations:l??{},elements:u??{},specification:d})}deployment;$data;constructor(e){this.$data=e;for(let[,t]of z(e.elements)){let e=this.addElement(t);for(let t of e.tags)this._allTags.get(t).add(e)}for(let[t,n]of z(e.imports??{}))for(let e of r(n)){let n=this.addImportedElement(t,e);for(let e of n.tags)this._allTags.get(e).add(n)}for(let t of U(e.relations)){let e=this.addRelation(t);for(let t of e.tags)this._allTags.get(t).add(e)}if(this.deployment=new LikeC4DeploymentModel(this),a(e,`computed`)||a(e,`layouted`)){let t=ee(`/`),r=R(U(e.views),G(e=>({view:e,path:normalizeViewPath(e.title??e.id),folderPath:e.title&&getViewFolderPath(e.title)||``})),H((e,n)=>t(e.folderPath,n.folderPath))),getOrCreateFolder=e=>{let t=this._viewFolders.get(e);if(!t){let i=W(e,`/`);n(B(i,1),`View group path "${e}" must have at least one element`);let a;a=e===``?r.find(e=>e.view.id===`index`):r.find(t=>t.path===e),t=new J(this,i,a?.view.id),this._viewFolders.set(e,t)}return t};this._rootViewFolder=getOrCreateFolder(``);for(let{folderPath:e}of r)this._viewFolders.has(e)||W(e,`/`).reduce((e,t)=>{let n=e.join(`/`),r=F(n)?t:n+`/`+t,i=getOrCreateFolder(r);return this._viewFolderItems.get(n).add(i),e.push(t),e},[]);for(let{view:t,folderPath:n}of r){let r=new LikeC4ViewModel(this,getOrCreateFolder(n),t,e.manualLayouts?.[t.id]);this._viewFolderItems.get(n).add(r),this._views.set(t.id,r);for(let e of r.tags)this._allTags.get(e).add(r)}}else this._rootViewFolder=new J(this,[``],void 0),this._viewFolders.set(this._rootViewFolder.path,this._rootViewFolder)}get asParsed(){return this}get asComputed(){return this}get asLayouted(){return this}get $styles(){return _(this,`styles`,()=>c.from(this.project.styles,this.specification.customColors))}isParsed(){return this.stage===`parsed`}isLayouted(){return this.stage===`layouted`}isComputed(){return this.stage===`computed`}get $model(){return this.$data}get stage(){return this.$data[i]}get projectId(){return this.$data.projectId??`default`}get project(){return this.$data.project??_(this,Symbol.for(`project`),()=>({id:this.projectId,styles:{},manualLayouts:{}}))}get specification(){return this.$data.specification}get globals(){return _(this,Symbol.for(`globals`),()=>({predicates:{...this.$data.globals?.predicates},dynamicPredicates:{...this.$data.globals?.dynamicPredicates},styles:{...this.$data.globals?.styles}}))}element(e){if(e instanceof ElementModel)return e;let t=getId(e);return w(this._elements.get(t),`Element ${t} not found`)}findElement(e){return this._elements.get(getId(e))??null}roots(){return this._rootElements.values()}elements(){return this._elements.values()}relationships(){return this._relations.values()}relationship(e,t){if(t===`deployment`)return this.deployment.relationship(e);let n=getId(e),r=this._relations.get(n)??null;return r||t===`model`?w(r,`Model relation ${n} not found`):w(this.deployment.findRelationship(n),`No model/deployment relation ${n} not found`)}findRelationship(e,t){if(t===`deployment`)return this.deployment.findRelationship(e);let n=this._relations.get(getId(e))??null;return n||t===`model`?n:this.deployment.findRelationship(e)}views(){return this._views.values()}view(e){let t=getId(e);return w(this._views.get(t),`View ${t} not found`)}findView(e){return this._views.get(e)??null}findManualLayout(e){return`manualLayouts`in this.$data?this.$data.manualLayouts?.[e]??null:null}viewFolder(e){return w(this._viewFolders.get(e),`View folder ${e} not found`)}get rootViewFolder(){return this._rootViewFolder}get hasViewFolders(){return this._viewFolders.size>1}viewFolderItems(e){return n(this._viewFolders.has(e),`View folder ${e} not found`),this._viewFolderItems.get(e)}parent(e){let t=getId(e);return this._parents.get(t)||null}children(e){let t=getId(e);return this._children.get(t)}*siblings(e){let t=getId(e),n=this._parents.get(t),r=n?this._children.get(n.id).values():this.roots();for(let e of r)e.id!==t&&(yield e)}*ancestors(e){let t=getId(e),n;for(;n=this._parents.get(t);)yield n,t=n.id}*descendants(e){for(let t of this.children(e))yield t,yield*this.descendants(t.id)}*incoming(e,t=`all`){let n=getId(e);for(let e of this._incoming.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e;break}}*outgoing(e,t=`all`){let n=getId(e);for(let e of this._outgoing.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e;break}}get tags(){return _(this,`tags`,()=>H([...this._allTags.keys()],A))}get tagsSortedByUsage(){return _(this,`tagsSortedByUsage`,()=>R([...this._allTags.entries()],G(([e,t])=>({tag:e,count:t.size,tagged:t})),H((e,t)=>A(e.tag,t.tag)),de([pe(`count`),`desc`])))}findByTag(e,t){return T(this._allTags.get(e),e=>t===`elements`?e instanceof ElementModel:t===`views`?e instanceof LikeC4ViewModel:t!==`relationships`||e instanceof RelationshipModel)}*elementsOfKind(e){for(let t of this._elements.values())t.kind===e&&(yield t)}*elementsWhere(e){let t=m(e);for(let e of this._elements.values())t(e)&&(yield e)}*relationshipsWhere(e){let t=m(e);for(let e of this._relations.values())t(e)&&(yield e)}addElement(e){if(this._elements.has(e.id))throw Error(`Element ${e.id} already exists`);let t=new ElementModel(this,Object.freeze(e));this._elements.set(t.id,t);let r=b(t.id);return r?(n(this._elements.has(r),`Parent ${r} of ${t.id} not found`),this._parents.set(t.id,this.element(r)),this._children.get(r).add(t)):this._rootElements.add(t),t}addImportedElement(e,t){n(!ne(t.id),`Imported element already has global FQN`);let r=ae(e,t.id);if(this._elements.has(r))throw Error(`Element ${r} already exists`);let i=new ElementModel(this,Object.freeze({...t,id:r}));this._elements.set(i.id,i);let a=b(i.id);for(;a;){if(a.includes(`.`)&&this._elements.has(a))return this._parents.set(i.id,this.element(a)),this._children.get(a).add(i),i;a=b(a)}return this._rootElements.add(i),i}addRelation(e){if(this._relations.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new RelationshipModel(this,Object.freeze(e)),{source:n,target:r}=t;this._relations.set(t.id,t),this._incoming.get(r.id).add(t),this._outgoing.get(n.id).add(t);let i=x(n.id,r.id);if(i)for(let e of[i,...O(i)])this._internal.get(e).add(t);for(let e of O(n.id)){if(e===i)break;this._outgoing.get(e).add(t)}for(let e of O(r.id)){if(e===i)break;this._incoming.get(e).add(t)}return t}};(function(e){e.EMPTY=Y.create({_stage:`computed`,projectId:`default`,project:{id:`default`},specification:{elements:{},relationships:{},deployments:{},tags:{}},globals:{predicates:{},dynamicPredicates:{},styles:{}},deployments:{elements:{},relations:{}},elements:{},relations:{},views:{},imports:{}})})(Y||={});let X;(function(e){e.isInside=e=>t=>S(e,t.source.id)&&S(e,t.target.id);let t=e.isDirectedBetween=(e,t)=>n=>(n.source.id===e||S(e,n.source.id))&&(n.target.id===t||S(t,n.target.id));e.isAnyBetween=(e,n)=>{let r=t(e,n),i=t(n,e);return e=>r(e)||i(e)};let n=e.isIncoming=e=>t=>(t.target.id===e||S(e,t.target.id))&&!S(e,t.source.id),r=e.isOutgoing=e=>t=>(t.source.id===e||S(e,t.source.id))&&!S(e,t.target.id);e.isAnyInOut=e=>{let t=n(e),i=r(e);return e=>t(e)||i(e)}})(X||={});const Z=Symbol.for(`nodejs.util.inspect.custom`);var Q=class DeploymentConnectionModel{source;target;relations;id;constructor(e,t,n){this.source=e,this.target=t,this.relations=n,this.id=p(`deployment:${e.id}:${t.id}`)}get expression(){return`${this.source.id} -> ${this.target.id}`}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target),this._boundary}nonEmpty(){return this.relations.nonEmpty}[Z](e,t,n){let r=this.toString();return Object.defineProperty(r,"constructor",{value:DeploymentConnectionModel,enumerable:!1}),r}toString(){let e=[...this.relations.model].map(e=>` `+e.expression);e.length?e.unshift(` model:`):e.unshift(` model: []`);let t=[...this.relations.deployment].map(e=>` `+e.expression);return t.length?t.unshift(` deployment:`):t.unshift(` deployment: []`),[this.expression,...e,...t].join(`
3
- `)}hasDirectDeploymentRelation(){for(let e of this.relations.deployment)if(e.source.id===this.source.id||e.target.id===this.target.id)return!0;return!1}*values(){yield*this.relations.model,yield*this.relations.deployment}mergeWith(e){return Array.isArray(e)?e.reduce((e,t)=>e.mergeWith(t),this):(n(this.source.id===e.source.id,`Cannot merge connections with different sources`),n(this.target.id===e.target.id,`Cannot merge connections with different targets`),new DeploymentConnectionModel(this.source,this.target,this.relations.union(e.relations)))}difference(e){return new DeploymentConnectionModel(this.source,this.target,this.relations.difference(e.relations))}intersect(e){return new DeploymentConnectionModel(this.source,this.target,this.relations.intersect(e.relations))}equals(e){return n(e instanceof DeploymentConnectionModel,`Other should ne DeploymentConnectionModel`),this.id===e.id&&this.source.id===e.source.id&&this.target.id===e.target.id&&s(this.relations.model,e.relations.model)&&s(this.relations.deployment,e.relations.deployment)}update(e){return e&&={model:this.relations.model,deployment:this.relations.deployment,...e},new DeploymentConnectionModel(this.source,this.target,e?new q(e.model??new Set,e.deployment??new Set):this.relations)}};function isNestedConnection(e,t){if(!t){let t=e;return e=>isNestedConnection(e,t)}let n=e.source===t.source,r=e.target===t.target;if(n&&r)return!1;let i=S(t.source.id,e.source.id),a=S(t.target.id,e.target.id);return i&&a||n&&a||r&&i}function findDeepestNestedConnection(e,t){let n=t;for(let t of e)isNestedConnection(t,n)&&(n=t);return n===t?null:n}function sortDeepestFirst(e){let t=[],n=e.slice(),r;for(;r=n.shift();){let e;for(;e=findDeepestNestedConnection(n,r);){let r=n.indexOf(e);t.push(n.splice(r,1)[0])}t.push(r)}return t}function boundaryHierarchy(e){return e.boundary?.id?`.${e.boundary.id}`:``}function sortConnectionsByBoundaryHierarchy(e,t){if(!e||re(e)){let t=e??`asc`;return e=>_sortByBoundary(e,t)}return _sortByBoundary(e,t??`asc`)}function _sortByBoundary(e,t){return R(e,G(e=>({id:boundaryHierarchy(e),conn:e})),g(t),G(e=>e.conn))}function findAscendingConnections(e,t){return e.filter(e=>isNestedConnection(t,e))}function findDescendantConnections(e,t){return e.filter(isNestedConnection(t))}function mergeConnections(e){let t=new Map;for(let n of e){let e=t.get(n.id);e?t.set(n.id,n.mergeWith(e)):t.set(n.id,n)}return[...t.values()]}function differenceConnections(e,t){let n=new Map([...t].map(e=>[e.id,e]));return[...e].reduce((e,t)=>{let r=n.get(t.id);if(!r)return e.push(t),e;let i=t.difference(r);return i.nonEmpty()&&e.push(i),e},[])}function hasSameSourceTarget(e,t){return t?e.source===t.source&&e.target===t.target:t=>e.source===t.source&&e.target===t.target}function hasSameSource(e,t){return t?e.source===t.source:t=>e.source===t.source}function hasSameTarget(e,t){return t?e.target===t.target:t=>e.target===t.target}function isOutgoing(e,t){if(!t){let t=e;return e=>isOutgoing(e,t)}let n=e;return y(n.source,t)&&!y(n.target,t)}function isIncoming(e,t){if(!t){let t=e;return e=>isIncoming(e,t)}let n=e;return y(n.target,t)&&!y(n.source,t)}function isAnyInOut(e,t){if(!t){let t=e;return e=>isAnyInOut(e,t)}let n=e;return y(n.source,t)!==y(n.target,t)}var $=class ConnectionModel{source;target;relations;id;constructor(e,t,n=new Set){this.source=e,this.target=t,this.relations=n,this.id=p(`model:${e.id}:${t.id}`)}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target)}get expression(){return`${this.source.id} -> ${this.target.id}`}get isDirect(){return this.nonEmpty()&&!this.isImplicit}get isImplicit(){return this.nonEmpty()&&u(this.relations,fe(hasSameSourceTarget(this)))}get directRelations(){return new Set(T(this.relations,hasSameSourceTarget(this)))}nonEmpty(){return this.relations.size>0}mergeWith(e){return n(this.source.id===e.source.id,`Cannot merge connections with different sources`),n(this.target.id===e.target.id,`Cannot merge connections with different targets`),new ConnectionModel(this.source,this.target,N(this.relations,e.relations))}difference(e){return new ConnectionModel(this.source,this.target,h(this.relations,e.relations))}intersect(e){return n(e instanceof ConnectionModel,`Cannot intersect connection with different type`),new ConnectionModel(this.source,this.target,f(this.relations,e.relations))}equals(e){n(e instanceof ConnectionModel,`Cannot merge connection with different type`);let t=e;return this.id===t.id&&this.source.id===t.source.id&&this.target.id===t.target.id&&s(this.relations,t.relations)}update(e){return new ConnectionModel(this.source,this.target,e)}[Z](e,t,n){let r=this.toString();return Object.defineProperty(r,"constructor",{value:ConnectionModel,enumerable:!1}),r}toString(){return[this.expression,this.relations.size?` relations:`:` relations: [ ]`,...[...this.relations].map(e=>` `+e.expression)].join(`
4
- `)}reversed(){return new ConnectionModel(this.target,this.source)}},_e=e({findConnection:()=>findConnection$1,findConnectionsBetween:()=>findConnectionsBetween$1,findConnectionsWithin:()=>findConnectionsWithin$1});function findConnection$1(e,t,n=`directed`){if(e===t||k(e,t))return[];let r=e.allOutgoing.intersect(t.allIncoming),i=r.nonEmpty?[new Q(e,t,r)]:[];return n===`directed`?i:[...i,...findConnection$1(t,e,`directed`)]}t(findConnection$1,`findConnection`);function findConnectionsBetween$1(e,t,n=`both`){if(e.allIncoming.isEmpty&&e.allOutgoing.isEmpty)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of findConnection$1(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}t(findConnectionsBetween$1,`findConnectionsBetween`);function findConnectionsWithin$1(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...findConnectionsBetween$1(t,r.slice(n+1),`both`)),e),[])}t(findConnectionsWithin$1,`findConnectionsWithin`);var ve=e({findConnection:()=>findConnection,findConnectionsBetween:()=>findConnectionsBetween,findConnectionsWithin:()=>findConnectionsWithin});function findConnection(e,t,n=`directed`){if(e===t||k(e,t))return[];let r=f(e.allOutgoing,t.allIncoming),i=r.size>0?new $(e,t,r):null;if(n===`directed`)return i?[i]:[];let a=f(e.allIncoming,t.allOutgoing),o=a.size>0?new $(t,e,a):null;return i&&o?[i,o]:i?[i]:o?[o]:[]}function findConnectionsBetween(e,t,n=`both`){if(e.allIncoming.size===0&&e.allOutgoing.size===0)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of findConnection(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}function findConnectionsWithin(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...findConnectionsBetween(t,r.slice(n+1),`both`)),e),[])}function isDeploymentNodeModel(e){return e instanceof DeploymentNodeModel}function isDeployedInstanceModel(e){return e instanceof DeployedInstanceModel}function isDeploymentElementModel(e){return isDeploymentNodeModel(e)||isDeployedInstanceModel(e)}function isNestedElementOfDeployedInstanceModel(e){return e instanceof NestedElementOfDeployedInstanceModel}function isDeploymentRelationModel(e){return e instanceof DeploymentRelationModel}function isRelationModel(e){return e instanceof RelationshipModel}function isElementModel(e){return e instanceof ElementModel}function isLikeC4ViewModel(e){return e instanceof LikeC4ViewModel}function isNodeModel(e){return e instanceof NodeModel}function isEdgeModel(e){return e instanceof EdgeModel}export{Q as A,ge as B,isAnyInOut as C,mergeConnections as D,isOutgoing as E,LikeC4ViewModel as F,DeploymentNodeModel as G,getViewFolderPath as H,NodeModel as I,ElementModel as J,DeploymentRelationModel as K,EdgeModel as L,X as M,Y as N,sortConnectionsByBoundaryHierarchy as O,J as P,RelationshipModel as R,hasSameTarget as S,isNestedConnection as T,normalizeViewPath as U,extractViewTitleFromPath as V,DeployedInstanceModel as W,findAscendingConnections as _,isEdgeModel as a,hasSameSource as b,isNestedElementOfDeployedInstanceModel as c,findConnection as d,findConnectionsBetween as f,differenceConnections as g,$ as h,isDeploymentRelationModel as i,Z as j,sortDeepestFirst as k,isNodeModel as l,_e as m,isDeploymentElementModel as n,isElementModel as o,ve as p,q,isDeploymentNodeModel as r,isLikeC4ViewModel as s,isDeployedInstanceModel as t,isRelationModel as u,findDeepestNestedConnection as v,isIncoming as w,hasSameSourceTarget as x,findDescendantConnections as y,LikeC4DeploymentModel as z};
1
+ import{n as e,r as t}from"./rolldown-runtime.mjs";import{An as n,Cn as r,Ct as i,Et as a,Fn as o,Ft as s,I as c,In as l,Jt as u,Ln as d,Lt as f,Mt as p,N as m,Pt as h,Sn as g,Tn as ee,Wt as _,Y as te,Zt as v,_n as y,_t as ne,bn as b,cn as re,dn as x,gn as S,hn as C,jn as w,ln as ie,nn as T,nt as E,ot as ae,t as D,tn as oe,un as O,vn as k,vt as se,wn as A,wt as j,xt as ce,yn as M,yt as le,zt as N}from"./types.mjs";import{A as ue,C as P,D as F,J as I,N as L,P as R,T as z,X as B,Z as V,c as H,i as U,p as de,r as W,s as fe,w as pe}from"./libs/remeda.mjs";import{t as G}from"./libs/mnemonist.mjs";import{n as me,t as he}from"./calcDriftsFromSnapshot.mjs";var ElementModel=class{$model;$element;Aux;id;_literalId;hierarchyLevel;imported;constructor(e,t){this.$model=e,this.$element=t,this.id=this.$element.id,this._literalId=this.$element.id;let[n,r]=ce(this.id);n?(this.imported={from:n,fqn:r},this.hierarchyLevel=C(r)):(this.imported=null,this.hierarchyLevel=C(this.id))}get name(){return M(this.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$element.kind}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get tags(){return _(this,Symbol.for(`tags`),()=>U([...this.$element.tags??[],...this.$model.specification.elements[this.$element.kind]?.tags??[]]))}get metadata(){return this.$element.metadata??{}}get title(){return this.$element.title}get hasSummary(){return!!this.$element.summary&&!!this.$element.description&&!F(this.$element.summary,this.$element.description)}get summary(){return D.memoize(this,`summary`,l(this.$element))}get description(){return D.memoize(this,`description`,o(this.$element))}get technology(){return this.$element.technology??null}get links(){return this.$element.links??[]}get defaultView(){return _(this,Symbol.for(`defaultView`),()=>v(this.scopedViews())??null)}get isRoot(){return this.parent===null}get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$element.style}))}get projectId(){return this.imported?.from??this.$model.projectId}isAncestorOf(e){return S(this,e)}isDescendantOf(e){return S(e,this)}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=x(this.id,e.id);return t?this.$model.element(t):null}children(){return this.$model.children(this)}descendants(e){return e?g([...this.$model.descendants(this)],e)[Symbol.iterator]():this.$model.descendants(this)}siblings(){return this.$model.siblings(this)}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}get allOutgoing(){return _(this,Symbol.for(`allOutgoing`),()=>new Set(this.outgoing()))}get allIncoming(){return _(this,Symbol.for(`allIncoming`),()=>new Set(this.incoming()))}views(){return _(this,Symbol.for(`views`),()=>{let e=new Set;for(let t of this.$model.views())t.includesElement(this.id)&&e.add(t);return e})}scopedViews(){return _(this,Symbol.for(`scopedViews`),()=>{let e=new Set;for(let t of this.$model.views())t.isScopedElementView()&&t.viewOf.id===this.id&&e.add(t);return e})}isDeployed(){return z(v(this.deployments()))}deployments(){return this.$model.deployment.instancesOf(this)}hasMetadata(){return!!this.$element.metadata&&!R(this.$element.metadata)}getMetadata(e){return e?this.$element.metadata?.[e]:this.$element.metadata??{}}isTagged(e){return this.tags.includes(e)}},AbstractDeploymentElementModel=class{Aux;get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.$node.style}))}get name(){return M(this.id)}get shape(){return this.style.shape}get color(){return this.style.color}get icon(){return this.style.icon??null}get summary(){return D.memoize(this,`summary`,l(this.$node))}get description(){return D.memoize(this,`description`,o(this.$node))}get technology(){return this.$node.technology??null}get links(){return this.$node.links??[]}ancestors(){return this.$model.ancestors(this)}commonAncestor(e){let t=x(this.id,e.id);return t?this.$model.node(t):null}siblings(){return this.$model.siblings(this)}isSibling(e){return this.parent===e.parent}*ascendingSiblings(){yield*this.siblings();for(let e of this.ancestors())yield*e.siblings()}*descendingSiblings(){for(let e of[...this.ancestors()].reverse())yield*e.siblings();yield*this.siblings()}incoming(e=`all`){return this.$model.incoming(this,e)}outgoing(e=`all`){return this.$model.outgoing(this,e)}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}*views(){for(let e of this.$model.views())e._type===`deployment`&&e.includesDeployment(this.id)&&(yield e)}isDeploymentNode(){return!1}isInstance(){return!1}get allOutgoing(){return _(this,Symbol.for(`allOutgoing`),()=>K.from(new Set(this.outgoingModelRelationships()),new Set(this.outgoing())))}get allIncoming(){return _(this,Symbol.for(`allIncoming`),()=>K.from(new Set(this.incomingModelRelationships()),new Set(this.incoming())))}hasMetadata(){return!!this.$node.metadata&&!R(this.$node.metadata)}getMetadata(e){return e?this.$node.metadata?.[e]:this.$node.metadata??{}}isTagged(e){return this.tags.includes(e)}},DeploymentNodeModel=class extends AbstractDeploymentElementModel{$model;$node;id;_literalId;title;hierarchyLevel;constructor(e,t){super(),this.$model=e,this.$node=t,this.id=t.id,this._literalId=t.id,this.title=t.title,this.hierarchyLevel=C(t.id)}get parent(){return this.$model.parent(this)}get kind(){return this.$node.kind}get metadata(){return this.$node.metadata??{}}get tags(){return _(this,Symbol.for(`tags`),()=>U([...this.$node.tags??[],...this.$model.$model.specification.deployments[this.kind]?.tags??[]]))}children(){return this.$model.children(this)}descendants(e=`desc`){return this.$model.descendants(this,e)}isDeploymentNode(){return!0}*instances(){for(let e of this.descendants(`desc`))e.isInstance()&&(yield e)}onlyOneInstance(){let e=this.children();if(e.size!==1)return null;let t=v(e);return t?t.isInstance()?t:t.onlyOneInstance():null}_relationshipsFromInstances=null;relationshipsFromInstances(){if(this._relationshipsFromInstances)return this._relationshipsFromInstances;let{outgoing:e,incoming:t}=this._relationshipsFromInstances={outgoing:new Set,incoming:new Set};for(let n of this.instances()){for(let t of n.element.outgoing())e.add(t);for(let e of n.element.incoming())t.add(e)}return this._relationshipsFromInstances}outgoingModelRelationships(){return this.relationshipsFromInstances().outgoing.values()}incomingModelRelationships(){return this.relationshipsFromInstances().incoming.values()}internalModelRelationships(){let{outgoing:e,incoming:t}=this.relationshipsFromInstances();return f(t,e)}},DeployedInstanceModel=class extends AbstractDeploymentElementModel{$model;$instance;element;id;_literalId;title;hierarchyLevel;constructor(e,t,n){super(),this.$model=e,this.$instance=t,this.element=n,this.id=t.id,this._literalId=t.id,this.title=t.title??n.title,this.hierarchyLevel=C(t.id)}get $node(){return this.$instance}get parent(){return w(this.$model.parent(this),`Parent of ${this.id} not found`)}get style(){return _(this,`style`,()=>d({shape:this.$model.$styles.defaults.shape,color:this.$model.$styles.defaults.color,border:this.$model.$styles.defaults.border,opacity:this.$model.$styles.defaults.opacity,size:this.$model.$styles.defaults.size,padding:this.$model.$styles.defaults.padding,textSize:this.$model.$styles.defaults.text,iconPosition:this.$model.$styles.defaults.iconPosition,...this.element.$element.style,...this.$instance.style}))}get tags(){return _(this,Symbol.for(`tags`),()=>U([...this.$instance.tags??[],...this.element.tags]))}get kind(){return this.element.kind}get metadata(){return this.$instance.metadata??this.element.metadata??{}}get summary(){return D.memoize(this,`summary`,l(this.$instance)??l(this.element.$element))}get description(){return D.memoize(this,`description`,o(this.$instance)??o(this.element.$element))}get technology(){return this.$instance.technology??this.element.technology??null}get links(){return this.$instance.links??this.element.links}isInstance(){return!0}outgoingModelRelationships(){return this.element.outgoing()}incomingModelRelationships(){return this.element.incoming()}*views(){for(let e of this.$model.views())if(e._type===`deployment`){if(e.includesDeployment(this.id)){yield e;continue}e.includesDeployment(this.parent.id)&&this.parent.onlyOneInstance()&&(yield e)}}},NestedElementOfDeployedInstanceModel=class{instance;element;constructor(e,t){this.instance=e,this.element=t}get id(){return this.instance.id}get _literalId(){return this.instance.id}get style(){return _(this,`style `,()=>({shape:this.element.shape,color:this.element.color,...this.element.$element.style}))}get shape(){return this.element.shape}get color(){return this.element.color}get title(){return this.element.title}get summary(){return this.element.summary}get description(){return this.element.description}get technology(){return this.element.technology}isDeploymentNode(){return!1}isInstance(){return!1}},DeploymentRelationModel=class{$model;$relationship;boundary;source;target;constructor(e,t){this.$model=e,this.$relationship=t,this.source=e.deploymentRef(t.source),this.target=e.deploymentRef(t.target);let n=x(this.source.id,this.target.id);this.boundary=n?this.$model.node(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return z(this.$relationship.title)?this.$relationship.title:null}get technology(){return L(this.$relationship.technology)?(this.kind&&this.$model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!F(this.$relationship.summary,this.$relationship.description)}get summary(){return D.memoize(this,`summary`,l(this.$relationship))}get description(){return D.memoize(this,`description`,o(this.$relationship))}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get navigateTo(){return this.$relationship.navigateTo?this.$model.$model.view(this.$relationship.navigateTo):null}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.$model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.$model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.$model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}*views(){for(let e of this.$model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!0}isModelRelation(){return!1}hasMetadata(){return!!this.$relationship.metadata&&!R(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},K=class RelationshipsAccum{model;deployment;static empty(){return new RelationshipsAccum}static from(e,t){return new RelationshipsAccum(new Set(e),new Set(t))}constructor(e=new Set,t=new Set){this.model=e,this.deployment=t}get isEmpty(){return this.model.size===0&&this.deployment.size===0}get nonEmpty(){return this.model.size>0||this.deployment.size>0}get size(){return this.model.size+this.deployment.size}intersect(e){return RelationshipsAccum.from(f(this.model,e.model),f(this.deployment,e.deployment))}difference(e){return RelationshipsAccum.from(h(this.model,e.model),h(this.deployment,e.deployment))}union(e){return RelationshipsAccum.from(N(this.model,e.model),N(this.deployment,e.deployment))}};const getId=e=>typeof e==`string`?e:e.id,ge=`/`,q=/(?<!\\)\//,_e=/\\\//g,unescapeViewPathSegment=e=>e.replace(_e,`/`),splitViewTitle=e=>{if(n(!e.includes(`
2
+ `),`View title cannot contain newlines`),q.test(e)){let t=e.split(q).map(e=>e.trim()).filter(e=>e.length>0);return B(t,1)?t:[``]}return[e.trim()]},splitViewFolderPath=e=>splitViewTitle(e),normalizeViewPath=e=>splitViewTitle(e).join(`/`),getViewFolderPath=e=>{let t=splitViewTitle(e);return B(t,2)?t.slice(0,-1).join(`/`):null},extractViewTitleFromPath=e=>q.test(e)?unescapeViewPathSegment(splitViewTitle(e).at(-1)??e):unescapeViewPathSegment(e.trim());var LikeC4DeploymentModel=class{$model;#e=new Map;#t=new Map;#n=new G.default(()=>new Set);#r=new G.default(()=>new Set);#i=new Set;#a=new Map;#o=new G.default(()=>new Set);#s=new G.default(()=>new Set);#c=new G.default(()=>new Set);#l=new G.default(()=>new Set);#u=new Map;$deployments;constructor(e){this.$model=e;let t=this.$deployments=e.$data.deployments,n=W(t.elements);for(let e of r(n)){let t=this.addElement(e);for(let e of t.tags)this.#l.get(e).add(t);t.isInstance()&&this.#r.get(t.element.id).add(t)}for(let e of W(t.relations)){let t=this.addRelation(e);for(let e of t.tags)this.#l.get(e).add(t)}}get $styles(){return this.$model.$styles}get projectId(){return this.$model.projectId}get project(){return this.$model.project}get specification(){return this.$model.specification}element(e){if(e instanceof DeploymentNodeModel||e instanceof DeployedInstanceModel)return e;let t=getId(e);return w(this.#e.get(t),`Element ${t} not found`)}findElement(e){return this.#e.get(e)??null}node(e){let t=this.element(e);return n(t.isDeploymentNode(),`Element ${t.id} is not a deployment node`),t}findNode(e){let t=this.findElement(e);return t?(n(t.isDeploymentNode(),`Element ${t?.id} is not a deployment node`),t):null}instance(e){let t=this.element(e);return n(t.isInstance(),`Element ${t.id} is not a deployed instance`),t}findInstance(e){let t=this.findElement(e);return t?(n(t.isInstance(),`Element ${t?.id} is not a deployed instance`),t):null}roots(){return this.#i.values()}elements(){return this.#e.values()}*nodes(){for(let e of this.#e.values())e.isDeploymentNode()&&(yield e)}*nodesOfKind(e){for(let t of this.#e.values())t.isDeploymentNode()&&t.kind===e&&(yield t)}*instances(){for(let e of this.#e.values())e.isInstance()&&(yield e)}*instancesOf(e){let t=getId(e),n=this.#r.get(t);n&&(yield*n)}deploymentRef(e){if(E.isInsideInstanceRef(e)){let{deployment:t,element:n}=e;return ie(this.#u,`${t}@${n}`,()=>new NestedElementOfDeployedInstanceModel(this.instance(t),this.$model.element(n)))}return this.element(e.deployment)}relationships(){return this.#a.values()}relationship(e){let t=getId(e);return w(this.#a.get(t),`DeploymentRelationModel ${t} not found`)}findRelationship(e){return this.#a.get(e)??null}*views(){for(let e of this.$model.views())e.isDeploymentView()&&(yield e)}parent(e){let t=getId(e);return this.#t.get(t)||null}children(e){let t=getId(e);return this.#n.get(t)}*siblings(e){let t=getId(e),n=this.parent(e)?.children()??this.roots();for(let e of n)e.id!==t&&(yield e)}*ancestors(e){let t=getId(e),n;for(;n=this.#t.get(t);)yield n,t=n.id}*descendants(e,t=`desc`){for(let n of this.children(e))t===`asc`?(yield n,yield*this.descendants(n.id)):(yield*this.descendants(n.id),yield n)}*incoming(e,t=`all`){let n=getId(e);for(let e of this.#o.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e}}*outgoing(e,t=`all`){let n=getId(e);for(let e of this.#s.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e}}addElement(e){if(this.#e.has(e.id))throw Error(`Element ${e.id} already exists`);let t=te(e)?new DeploymentNodeModel(this,Object.freeze(e)):new DeployedInstanceModel(this,Object.freeze(e),this.$model.element(e.element));this.#e.set(t.id,t);let r=b(t.id);return r?(n(this.#e.has(r),`Parent ${r} of ${t.id} not found`),this.#t.set(t.id,this.node(r)),this.#n.get(r).add(t)):(n(t.isDeploymentNode(),`Root element ${t.id} is not a deployment node`),this.#i.add(t)),t}addRelation(e){if(this.#a.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new DeploymentRelationModel(this,Object.freeze(e));this.#a.set(t.id,t),this.#o.get(t.target.id).add(t),this.#s.get(t.source.id).add(t);let n=t.boundary?.id??null;if(n)for(let e of[n,...O(n)])this.#c.get(e).add(t);for(let e of O(t.source.id)){if(e===n)break;this.#s.get(e).add(t)}for(let e of O(t.target.id)){if(e===n)break;this.#o.get(e).add(t)}return t}},RelationshipModel=class{model;$relationship;source;target;boundary;constructor(e,t){this.model=e,this.$relationship=t,this.source=e.element(E.flatten(t.source)),this.target=e.element(E.flatten(t.target));let n=x(this.source.id,this.target.id);this.boundary=n?this.model.element(n):null}get id(){return this.$relationship.id}get expression(){return`${this.source.id} -> ${this.target.id}`}get title(){return L(this.$relationship.title)?null:this.$relationship.title}get technology(){return L(this.$relationship.technology)?(this.kind&&this.model.specification.relationships[this.kind])?.technology??null:this.$relationship.technology}get hasSummary(){return!!this.$relationship.summary&&!!this.$relationship.description&&!F(this.$relationship.summary,this.$relationship.description)}get summary(){return D.memoize(this,`summary`,l(this.$relationship))}get description(){return D.memoize(this,`description`,o(this.$relationship))}get navigateTo(){return this.$relationship.navigateTo?this.model.view(this.$relationship.navigateTo):null}get tags(){return this.$relationship.tags??[]}get kind(){return this.$relationship.kind??null}get metadata(){return this.$relationship.metadata??{}}get links(){return this.$relationship.links??[]}get color(){return this.$relationship.color??this.model.$styles.defaults.relationship.color}get line(){return this.$relationship.line??this.model.$styles.defaults.relationship.line}get head(){return this.$relationship.head??this.model.$styles.defaults.relationship.arrow}get tail(){return this.$relationship.tail}get isBidirectional(){return this.$relationship.isBidirectional===!0}*views(){for(let e of this.model.views())e.includesRelation(this.id)&&(yield e)}isDeploymentRelation(){return!1}isModelRelation(){return!0}hasMetadata(){return!!this.$relationship.metadata&&!R(this.$relationship.metadata)}getMetadata(e){return e?this.$relationship.metadata?.[e]:this.$relationship.metadata??{}}isTagged(e){return this.tags.includes(e)}},EdgeModel=class{source;target;Aux;$viewModel;$view;$edge;constructor(e,t,n,r){this.source=n,this.target=r,this.$viewModel=e,this.$view=e.$view,this.$edge=t}get id(){return this.$edge.id}get parent(){return this.$edge.parent?this.$viewModel.node(this.$edge.parent):null}get label(){return this.$edge.label??null}get description(){return D.memoize(this,`description`,this.$edge.description)}get technology(){return this.$edge.technology??null}hasParent(){return this.$edge.parent!==null}get tags(){return this.$edge.tags??[]}get navigateTo(){return this.$edge.navigateTo?this.$viewModel.$model.view(this.$edge.navigateTo):null}get color(){return this.$edge.color}get line(){return this.$edge.line??this.$viewModel.$styles.defaults.relationship.line}get head(){return this.$edge.head??this.$viewModel.$styles.defaults.relationship.arrow}get tail(){return this.$edge.tail}isStep(){return le(this.$edge.id)}*relationships(e){for(let t of this.$edge.relations)if(e){let n=this.$viewModel.$model.findRelationship(t,e);n&&(yield n)}else yield this.$viewModel.$model.relationship(t)}includesRelation(e){let t=typeof e==`string`?e:e.id;return this.$edge.relations.includes(t)}isTagged(e){return this.tags.includes(e)}},NodeModel=class{Aux;$viewModel;$view;$node;constructor(e,t){this.$viewModel=e,this.$view=e.$view,this.$node=t}get id(){return this.$node.id}get title(){return this.$node.title}get kind(){return this.$node.kind}get description(){return D.memoize(this,`description`,this.$node.description)}get technology(){return this.$node.technology??null}get notes(){return D.memoize(this,`notes`,this.$node.notes)}get parent(){return this.$node.parent?this.$viewModel.node(this.$node.parent):null}get element(){let e=this.$node.modelRef;return e?this.$viewModel.$model.element(e):null}get deployment(){let e=this.$node.deploymentRef;return e?this.$viewModel.$model.deployment.element(e):null}get shape(){return this.$node.shape}get color(){return this.$node.color}get icon(){return this.$node.icon??null}get tags(){return this.$node.tags}get links(){return this.$node.links??[]}get navigateTo(){return this.$node.navigateTo?this.$viewModel.$model.view(this.$node.navigateTo):null}get style(){return this.$node.style}get x(){return`x`in this.$node?this.$node.x:void 0}get y(){return`y`in this.$node?this.$node.y:void 0}get width(){return`width`in this.$node?this.$node.width:void 0}get height(){return`height`in this.$node?this.$node.height:void 0}children(){return _(this,`children`,()=>new Set(this.$node.children.map(e=>this.$viewModel.node(e))))}*ancestors(){let e=this.parent;for(;e;)yield e,e=e.parent}*siblings(){let e=this.parent?.children()??this.$viewModel.roots();for(let t of e)t.id!==this.id&&(yield t)}*incoming(e=`all`){for(let t of this.$node.inEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.target.id===this.id:case e===`to-descendants`&&n.target.id!==this.id:yield n}}}*incomers(e=`all`){let t=new Set;for(let n of this.incoming(e))t.has(n.source.id)||(t.add(n.source.id),yield n.source)}*outgoing(e=`all`){for(let t of this.$node.outEdges){let n=this.$viewModel.edge(t);switch(!0){case e===`all`:case e===`direct`&&n.source.id===this.id:case e===`from-descendants`&&n.source.id!==this.id:yield n}}}*outgoers(e=`all`){let t=new Set;for(let n of this.outgoing(e))t.has(n.target.id)||(t.add(n.target.id),yield n.target)}isLayouted(){return`width`in this.$node&&`height`in this.$node}hasChildren(){return this.$node.children.length>0}hasParent(){return this.$node.parent!==null}hasElement(){return z(this.$node.modelRef)}hasDeployment(){return z(this.$node.deploymentRef)}hasDeployedInstance(){return this.hasElement()&&this.hasDeployment()}isGroup(){return se(this.$node)}isTagged(e){return this.tags.includes(e)}},LikeC4ViewModel=class{Aux;#e;#t=new Set;#n=new Map;#r=new Map;#i=new Set;#a=new Set;#o=new Set;#s=new G.default(e=>new Set);#c;id;$model;title;order;folder;viewPath;constructor(e,t,n,r){this.$model=e,this.#e=n,this.id=n.id,this.order=n.order,this.folder=t,this.#c=r;for(let e of this.#e.nodes){let t=new NodeModel(this,Object.freeze(e));this.#n.set(e.id,t),e.parent||this.#t.add(t),e.deploymentRef&&this.#a.add(e.deploymentRef),e.modelRef&&this.#i.add(e.modelRef);for(let e of t.tags)this.#s.get(e).add(t)}for(let e of this.#e.edges){let t=new EdgeModel(this,Object.freeze(e),this.node(e.source),this.node(e.target));for(let e of t.tags)this.#s.get(e).add(t);for(let t of e.relations)this.#o.add(t);this.#r.set(e.id,t)}this.title=n.title?extractViewTitleFromPath(n.title):null,this.viewPath=n.title?normalizeViewPath(n.title):n.id}get $styles(){return this.$model.$styles}get _type(){return this.#e[j]}get stage(){return this.#e[i]}get bounds(){if(`bounds`in this.#e)return this.#e.bounds;if(this.#c)return this.#c.bounds;throw Error(`View is not layouted`)}get titleOrId(){return this.title??this.viewOf?.title??this.id}get titleOrUntitled(){return this.title??`Untitled`}get breadcrumbs(){return _(this,`breadcrumbs`,()=>this.folder.isRoot?[this]:[...this.folder.breadcrumbs,this])}get description(){return D.memoize(this,`description`,this.#e.description)}get tags(){return this.#e.tags??[]}get links(){return this.#e.links??[]}get viewOf(){if(this.isElementView()){let e=this.#e.viewOf;return e?this.$model.element(e):null}return null}get mode(){return this.isDynamicView()?this.#e.variant??`diagram`:null}get includedTags(){return[...this.#s.keys()]}get $view(){if(!this.isLayouted()||`drifts`in this.#e)return this.#e;let e=this.#c;return e?_(this,`withDriftReasons`,()=>he(this.#e,e)):this.#e}get $layouted(){if(!this.isLayouted())throw Error(`View is not layouted`);return this.$manual??this.#e}get hasManualLayout(){return this.#c!==void 0}get hasLayoutDrifts(){if(!this.isLayouted())return!1;let e=this.$manual;return!!e?.drifts&&e.drifts.length>0}get $manual(){if(!this.isLayouted())return null;let e=this.#c;return e?this.#e._layout===`manual`?this.#e:_(this,`snapshotWithManualLayout`,()=>me(this.#e,e)):null}get projectId(){return this.$model.projectId}roots(){return this.#t.values()}*compounds(){for(let e of this.#n.values())e.hasChildren()&&(yield e)}node(e){let t=getId(e);return w(this.#n.get(t),`Node ${t} not found in view ${this.#e.id}`)}findNode(e){return this.#n.get(getId(e))??null}findNodeWithElement(e){let t=getId(e);return this.#i.has(t)?oe(this.#n.values(),e=>e.hasElement()&&e.element.id===t)??null:null}nodes(){return this.#n.values()}edge(e){let t=getId(e);return w(this.#r.get(t),`Edge ${t} not found in view ${this.#e.id}`)}findEdge(e){return this.#r.get(getId(e))??null}edges(){return this.#r.values()}*edgesWithRelation(e){for(let t of this.#r.values())t.includesRelation(e)&&(yield t)}*elements(){for(let e of this.#n.values())e.hasElement()&&(yield e)}isTagged(e){return this.tags.includes(e)}includesElement(e){return this.#i.has(getId(e))}includesDeployment(e){return this.#a.has(getId(e))}includesRelation(e){return this.#o.has(getId(e))}isComputed(){return this.#e[i]===`computed`}isLayouted(){return this.#e[i]===`layouted`}isDiagram(){return this.#e[i]===`layouted`}isElementView(){return this.#e[j]===`element`}isScopedElementView(){return this.#e._type===`element`&&z(this.#e.viewOf)}isDeploymentView(){return this.#e[j]===`deployment`}isDynamicView(){return this.#e[j]===`dynamic`}},J=class LikeC4ViewsFolder{$model;path;title;isRoot;parentPath;defaultViewId;constructor(e,t,n){this.$model=e,this.path=t.join(`/`),this.isRoot=this.path===``,this.title=unescapeViewPathSegment(pe(t)),this.parentPath=this.isRoot?void 0:t.slice(0,-1).join(`/`),this.defaultViewId=n}get defaultView(){return this.defaultViewId?this.$model.view(this.defaultViewId):null}get breadcrumbs(){return n(!this.isRoot,`Root view folder has no breadcrumbs`),_(this,`breadcrumbs`,()=>{let e=this.parent;return e?e.isRoot?[e,this]:[...e.breadcrumbs,this]:[this]})}get parent(){return n(!this.isRoot,`Root view folder has no parent`),L(this.parentPath)?null:this.$model.viewFolder(this.parentPath)}get children(){return this.$model.viewFolderItems(this.path)}get folders(){return _(this,`folders`,()=>{let e=[];for(let t of this.children)t instanceof LikeC4ViewsFolder&&e.push(t);return e})}get views(){return _(this,`views`,()=>{let e=[];for(let t of this.children)t instanceof LikeC4ViewModel&&e.push(t);return e})}},Y=class LikeC4Model{Aux;_elements=new Map;_parents=new Map;_children=new G.default(()=>new Set);_rootElements=new Set;_relations=new Map;_incoming=new G.default(()=>new Set);_outgoing=new G.default(()=>new Set);_internal=new G.default(()=>new Set);_views=new Map;_rootViewFolder;_viewFolders=new Map;_viewFolderItems=new G.default(()=>new Set);_allTags=new G.default(()=>new Set);static fromParsed(e){return new LikeC4Model(e)}static create(e){return new LikeC4Model(e)}static fromDump(e){let{_stage:t=`layouted`,projectId:n=`unknown`,project:r,globals:a,imports:o,deployments:s,views:c,relations:l,elements:u,specification:d}=e;return new LikeC4Model({[i]:t,projectId:n,project:r,globals:{predicates:a?.predicates??{},dynamicPredicates:a?.dynamicPredicates??{},styles:a?.styles??{}},imports:o??{},deployments:{elements:s?.elements??{},relations:s?.relations??{}},views:c??{},relations:l??{},elements:u??{},specification:d})}deployment;$data;constructor(e){this.$data=e;for(let[,t]of I(e.elements)){let e=this.addElement(t);for(let t of e.tags)this._allTags.get(t).add(e)}for(let[t,n]of I(e.imports??{}))for(let e of r(n)){let n=this.addImportedElement(t,e);for(let e of n.tags)this._allTags.get(e).add(n)}for(let t of W(e.relations)){let e=this.addRelation(t);for(let t of e.tags)this._allTags.get(t).add(e)}if(this.deployment=new LikeC4DeploymentModel(this),a(e,`computed`)||a(e,`layouted`)){let t=ee(`/`),compareViews=(e,n)=>{let r=t(e.folderPath,n.folderPath);if(r!==0)return r;let i=e.view.order,a=n.view.order;return i===a?0:i===void 0?1:a===void 0?-1:i-a},r=V(W(e.views),P(e=>({view:e,path:normalizeViewPath(e.title??e.id),folderPath:e.title&&getViewFolderPath(e.title)||``})),H(compareViews)),getOrCreateFolder=e=>{let t=this._viewFolders.get(e);if(!t){let i=splitViewFolderPath(e);n(B(i,1),`View group path "${e}" must have at least one element`);let a;a=e===``?r.find(e=>e.view.id===`index`):r.find(t=>t.path===e),t=new J(this,i,a?.view.id),this._viewFolders.set(e,t)}return t};this._rootViewFolder=getOrCreateFolder(``);for(let{folderPath:e}of r)this._viewFolders.has(e)||splitViewFolderPath(e).reduce((e,t)=>{let n=e.join(`/`),r=R(n)?t:n+`/`+t,i=getOrCreateFolder(r);return this._viewFolderItems.get(n).add(i),e.push(t),e},[]);for(let{view:t,folderPath:n}of r){let r=new LikeC4ViewModel(this,getOrCreateFolder(n),t,e.manualLayouts?.[t.id]);this._viewFolderItems.get(n).add(r),this._views.set(t.id,r);for(let e of r.tags)this._allTags.get(e).add(r)}}else this._rootViewFolder=new J(this,[``],void 0),this._viewFolders.set(this._rootViewFolder.path,this._rootViewFolder)}get asParsed(){return this}get asComputed(){return this}get asLayouted(){return this}get $styles(){return _(this,`styles`,()=>c.from(this.project.styles,this.specification.customColors))}isParsed(){return this.stage===`parsed`}isLayouted(){return this.stage===`layouted`}isComputed(){return this.stage===`computed`}get $model(){return this.$data}get stage(){return this.$data[i]}get projectId(){return this.$data.projectId??`default`}get project(){return this.$data.project??_(this,Symbol.for(`project`),()=>({id:this.projectId,styles:{},manualLayouts:{}}))}get specification(){return this.$data.specification}get globals(){return _(this,Symbol.for(`globals`),()=>({predicates:{...this.$data.globals?.predicates},dynamicPredicates:{...this.$data.globals?.dynamicPredicates},styles:{...this.$data.globals?.styles}}))}element(e){if(e instanceof ElementModel)return e;let t=getId(e);return w(this._elements.get(t),`Element ${t} not found`)}findElement(e){return this._elements.get(getId(e))??null}roots(){return this._rootElements.values()}elements(){return this._elements.values()}relationships(){return this._relations.values()}relationship(e,t){if(t===`deployment`)return this.deployment.relationship(e);let n=getId(e),r=this._relations.get(n)??null;return r||t===`model`?w(r,`Model relation ${n} not found`):w(this.deployment.findRelationship(n),`No model/deployment relation ${n} not found`)}findRelationship(e,t){if(t===`deployment`)return this.deployment.findRelationship(e);let n=this._relations.get(getId(e))??null;return n||t===`model`?n:this.deployment.findRelationship(e)}views(){return this._views.values()}view(e){let t=getId(e);return w(this._views.get(t),`View ${t} not found`)}findView(e){return this._views.get(e)??null}findManualLayout(e){return`manualLayouts`in this.$data?this.$data.manualLayouts?.[e]??null:null}viewFolder(e){return w(this._viewFolders.get(e),`View folder ${e} not found`)}get rootViewFolder(){return this._rootViewFolder}get hasViewFolders(){return this._viewFolders.size>1}viewFolderItems(e){return n(this._viewFolders.has(e),`View folder ${e} not found`),this._viewFolderItems.get(e)}parent(e){let t=getId(e);return this._parents.get(t)||null}children(e){let t=getId(e);return this._children.get(t)}*siblings(e){let t=getId(e),n=this._parents.get(t),r=n?this._children.get(n.id).values():this.roots();for(let e of r)e.id!==t&&(yield e)}*ancestors(e){let t=getId(e),n;for(;n=this._parents.get(t);)yield n,t=n.id}*descendants(e){for(let t of this.children(e))yield t,yield*this.descendants(t.id)}*incoming(e,t=`all`){let n=getId(e);for(let e of this._incoming.get(n))switch(!0){case t===`all`:case t===`direct`&&e.target.id===n:case t===`to-descendants`&&e.target.id!==n:yield e}}*outgoing(e,t=`all`){let n=getId(e);for(let e of this._outgoing.get(n))switch(!0){case t===`all`:case t===`direct`&&e.source.id===n:case t===`from-descendants`&&e.source.id!==n:yield e}}get tags(){return _(this,`tags`,()=>H([...this._allTags.keys()],A))}get tagsSortedByUsage(){return _(this,`tagsSortedByUsage`,()=>V([...this._allTags.entries()],P(([e,t])=>({tag:e,count:t.size,tagged:t})),H((e,t)=>A(e.tag,t.tag)),fe([de(`count`),`desc`])))}findByTag(e,t){return T(this._allTags.get(e),e=>t===`elements`?e instanceof ElementModel:t===`views`?e instanceof LikeC4ViewModel:t!==`relationships`||e instanceof RelationshipModel)}*elementsOfKind(e){for(let t of this._elements.values())t.kind===e&&(yield t)}*elementsWhere(e){let t=m(e);for(let e of this._elements.values())t(e)&&(yield e)}*relationshipsWhere(e){let t=m(e);for(let e of this._relations.values())t(e)&&(yield e)}addElement(e){if(this._elements.has(e.id))throw Error(`Element ${e.id} already exists`);let t=new ElementModel(this,Object.freeze(e));this._elements.set(t.id,t);let r=b(t.id);return r?(n(this._elements.has(r),`Parent ${r} of ${t.id} not found`),this._parents.set(t.id,this.element(r)),this._children.get(r).add(t)):this._rootElements.add(t),t}addImportedElement(e,t){n(!ne(t.id),`Imported element already has global FQN`);let r=ae(e,t.id);if(this._elements.has(r))throw Error(`Element ${r} already exists`);let i=new ElementModel(this,Object.freeze({...t,id:r}));this._elements.set(i.id,i);let a=b(i.id);for(;a;){if(a.includes(`.`)&&this._elements.has(a))return this._parents.set(i.id,this.element(a)),this._children.get(a).add(i),i;a=b(a)}return this._rootElements.add(i),i}addRelation(e){if(this._relations.has(e.id))throw Error(`Relation ${e.id} already exists`);let t=new RelationshipModel(this,Object.freeze(e)),{source:n,target:r}=t;this._relations.set(t.id,t),this._incoming.get(r.id).add(t),this._outgoing.get(n.id).add(t);let i=x(n.id,r.id);if(i)for(let e of[i,...O(i)])this._internal.get(e).add(t);for(let e of O(n.id)){if(e===i)break;this._outgoing.get(e).add(t)}for(let e of O(r.id)){if(e===i)break;this._incoming.get(e).add(t)}return t}};(function(e){e.EMPTY=Y.create({_stage:`computed`,projectId:`default`,project:{id:`default`},specification:{elements:{},relationships:{},deployments:{},tags:{}},globals:{predicates:{},dynamicPredicates:{},styles:{}},deployments:{elements:{},relations:{}},elements:{},relations:{},views:{},imports:{}})})(Y||={});let X;(function(e){e.isInside=e=>t=>S(e,t.source.id)&&S(e,t.target.id);let t=e.isDirectedBetween=(e,t)=>n=>(n.source.id===e||S(e,n.source.id))&&(n.target.id===t||S(t,n.target.id));e.isAnyBetween=(e,n)=>{let r=t(e,n),i=t(n,e);return e=>r(e)||i(e)};let n=e.isIncoming=e=>t=>(t.target.id===e||S(e,t.target.id))&&!S(e,t.source.id),r=e.isOutgoing=e=>t=>(t.source.id===e||S(e,t.source.id))&&!S(e,t.target.id);e.isAnyInOut=e=>{let t=n(e),i=r(e);return e=>t(e)||i(e)}})(X||={});const Z=Symbol.for(`nodejs.util.inspect.custom`);var Q=class DeploymentConnectionModel{source;target;relations;id;constructor(e,t,n){this.source=e,this.target=t,this.relations=n,this.id=p(`deployment:${e.id}:${t.id}`)}get expression(){return`${this.source.id} -> ${this.target.id}`}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target),this._boundary}nonEmpty(){return this.relations.nonEmpty}[Z](e,t,n){let r=this.toString();return Object.defineProperty(r,"constructor",{value:DeploymentConnectionModel,enumerable:!1}),r}toString(){let e=[...this.relations.model].map(e=>` `+e.expression);e.length?e.unshift(` model:`):e.unshift(` model: []`);let t=[...this.relations.deployment].map(e=>` `+e.expression);return t.length?t.unshift(` deployment:`):t.unshift(` deployment: []`),[this.expression,...e,...t].join(`
3
+ `)}hasDirectDeploymentRelation(){for(let e of this.relations.deployment)if(e.source.id===this.source.id||e.target.id===this.target.id)return!0;return!1}*values(){yield*this.relations.model,yield*this.relations.deployment}mergeWith(e){return Array.isArray(e)?e.reduce((e,t)=>e.mergeWith(t),this):(n(this.source.id===e.source.id,`Cannot merge connections with different sources`),n(this.target.id===e.target.id,`Cannot merge connections with different targets`),new DeploymentConnectionModel(this.source,this.target,this.relations.union(e.relations)))}difference(e){return new DeploymentConnectionModel(this.source,this.target,this.relations.difference(e.relations))}intersect(e){return new DeploymentConnectionModel(this.source,this.target,this.relations.intersect(e.relations))}equals(e){return n(e instanceof DeploymentConnectionModel,`Other should ne DeploymentConnectionModel`),this.id===e.id&&this.source.id===e.source.id&&this.target.id===e.target.id&&s(this.relations.model,e.relations.model)&&s(this.relations.deployment,e.relations.deployment)}update(e){return e&&={model:this.relations.model,deployment:this.relations.deployment,...e},new DeploymentConnectionModel(this.source,this.target,e?new K(e.model??new Set,e.deployment??new Set):this.relations)}};function isNestedConnection(e,t){if(!t){let t=e;return e=>isNestedConnection(e,t)}let n=e.source===t.source,r=e.target===t.target;if(n&&r)return!1;let i=S(t.source.id,e.source.id),a=S(t.target.id,e.target.id);return i&&a||n&&a||r&&i}function findDeepestNestedConnection(e,t){let n=t;for(let t of e)isNestedConnection(t,n)&&(n=t);return n===t?null:n}function sortDeepestFirst(e){let t=[],n=e.slice(),r;for(;r=n.shift();){let e;for(;e=findDeepestNestedConnection(n,r);){let r=n.indexOf(e);t.push(n.splice(r,1)[0])}t.push(r)}return t}function boundaryHierarchy(e){return e.boundary?.id?`.${e.boundary.id}`:``}function sortConnectionsByBoundaryHierarchy(e,t){if(!e||re(e)){let t=e??`asc`;return e=>_sortByBoundary(e,t)}return _sortByBoundary(e,t??`asc`)}function _sortByBoundary(e,t){return V(e,P(e=>({id:boundaryHierarchy(e),conn:e})),g(t),P(e=>e.conn))}function findAscendingConnections(e,t){return e.filter(e=>isNestedConnection(t,e))}function findDescendantConnections(e,t){return e.filter(isNestedConnection(t))}function mergeConnections(e){let t=new Map;for(let n of e){let e=t.get(n.id);e?t.set(n.id,n.mergeWith(e)):t.set(n.id,n)}return[...t.values()]}function differenceConnections(e,t){let n=new Map([...t].map(e=>[e.id,e]));return[...e].reduce((e,t)=>{let r=n.get(t.id);if(!r)return e.push(t),e;let i=t.difference(r);return i.nonEmpty()&&e.push(i),e},[])}function hasSameSourceTarget(e,t){return t?e.source===t.source&&e.target===t.target:t=>e.source===t.source&&e.target===t.target}function hasSameSource(e,t){return t?e.source===t.source:t=>e.source===t.source}function hasSameTarget(e,t){return t?e.target===t.target:t=>e.target===t.target}function isOutgoing(e,t){if(!t){let t=e;return e=>isOutgoing(e,t)}let n=e;return y(n.source,t)&&!y(n.target,t)}function isIncoming(e,t){if(!t){let t=e;return e=>isIncoming(e,t)}let n=e;return y(n.target,t)&&!y(n.source,t)}function isAnyInOut(e,t){if(!t){let t=e;return e=>isAnyInOut(e,t)}let n=e;return y(n.source,t)!==y(n.target,t)}var $=class ConnectionModel{source;target;relations;id;constructor(e,t,n=new Set){this.source=e,this.target=t,this.relations=n,this.id=p(`model:${e.id}:${t.id}`)}_boundary;get boundary(){return this._boundary??=this.source.commonAncestor(this.target)}get expression(){return`${this.source.id} -> ${this.target.id}`}get isDirect(){return this.nonEmpty()&&!this.isImplicit}get isImplicit(){return this.nonEmpty()&&u(this.relations,ue(hasSameSourceTarget(this)))}get directRelations(){return new Set(T(this.relations,hasSameSourceTarget(this)))}nonEmpty(){return this.relations.size>0}mergeWith(e){return n(this.source.id===e.source.id,`Cannot merge connections with different sources`),n(this.target.id===e.target.id,`Cannot merge connections with different targets`),new ConnectionModel(this.source,this.target,N(this.relations,e.relations))}difference(e){return new ConnectionModel(this.source,this.target,h(this.relations,e.relations))}intersect(e){return n(e instanceof ConnectionModel,`Cannot intersect connection with different type`),new ConnectionModel(this.source,this.target,f(this.relations,e.relations))}equals(e){n(e instanceof ConnectionModel,`Cannot merge connection with different type`);let t=e;return this.id===t.id&&this.source.id===t.source.id&&this.target.id===t.target.id&&s(this.relations,t.relations)}update(e){return new ConnectionModel(this.source,this.target,e)}[Z](e,t,n){let r=this.toString();return Object.defineProperty(r,"constructor",{value:ConnectionModel,enumerable:!1}),r}toString(){return[this.expression,this.relations.size?` relations:`:` relations: [ ]`,...[...this.relations].map(e=>` `+e.expression)].join(`
4
+ `)}reversed(){return new ConnectionModel(this.target,this.source)}},ve=e({findConnection:()=>findConnection$1,findConnectionsBetween:()=>findConnectionsBetween$1,findConnectionsWithin:()=>findConnectionsWithin$1});function findConnection$1(e,t,n=`directed`){if(e===t||k(e,t))return[];let r=e.allOutgoing.intersect(t.allIncoming),i=r.nonEmpty?[new Q(e,t,r)]:[];return n===`directed`?i:[...i,...findConnection$1(t,e,`directed`)]}t(findConnection$1,`findConnection`);function findConnectionsBetween$1(e,t,n=`both`){if(e.allIncoming.isEmpty&&e.allOutgoing.isEmpty)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of findConnection$1(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}t(findConnectionsBetween$1,`findConnectionsBetween`);function findConnectionsWithin$1(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...findConnectionsBetween$1(t,r.slice(n+1),`both`)),e),[])}t(findConnectionsWithin$1,`findConnectionsWithin`);var ye=e({findConnection:()=>findConnection,findConnectionsBetween:()=>findConnectionsBetween,findConnectionsWithin:()=>findConnectionsWithin});function findConnection(e,t,n=`directed`){if(e===t||k(e,t))return[];let r=f(e.allOutgoing,t.allIncoming),i=r.size>0?new $(e,t,r):null;if(n===`directed`)return i?[i]:[];let a=f(e.allIncoming,t.allOutgoing),o=a.size>0?new $(t,e,a):null;return i&&o?[i,o]:i?[i]:o?[o]:[]}function findConnectionsBetween(e,t,n=`both`){if(e.allIncoming.size===0&&e.allOutgoing.size===0)return[];let r=[],i=[];for(let a of t)if(e!==a)for(let t of findConnection(e,a,n))t.source===e?r.push(t):i.push(t);return[...r,...i]}function findConnectionsWithin(e){return[...e].reduce((e,t,n,r)=>(n===r.length-1||e.push(...findConnectionsBetween(t,r.slice(n+1),`both`)),e),[])}function isDeploymentNodeModel(e){return e instanceof DeploymentNodeModel}function isDeployedInstanceModel(e){return e instanceof DeployedInstanceModel}function isDeploymentElementModel(e){return isDeploymentNodeModel(e)||isDeployedInstanceModel(e)}function isNestedElementOfDeployedInstanceModel(e){return e instanceof NestedElementOfDeployedInstanceModel}function isDeploymentRelationModel(e){return e instanceof DeploymentRelationModel}function isRelationModel(e){return e instanceof RelationshipModel}function isElementModel(e){return e instanceof ElementModel}function isLikeC4ViewModel(e){return e instanceof LikeC4ViewModel}function isNodeModel(e){return e instanceof NodeModel}function isEdgeModel(e){return e instanceof EdgeModel}export{Q as A,ge as B,isAnyInOut as C,mergeConnections as D,isOutgoing as E,LikeC4ViewModel as F,DeploymentNodeModel as G,getViewFolderPath as H,NodeModel as I,ElementModel as J,DeploymentRelationModel as K,EdgeModel as L,X as M,Y as N,sortConnectionsByBoundaryHierarchy as O,J as P,RelationshipModel as R,hasSameTarget as S,isNestedConnection as T,normalizeViewPath as U,extractViewTitleFromPath as V,DeployedInstanceModel as W,findAscendingConnections as _,isEdgeModel as a,hasSameSource as b,isNestedElementOfDeployedInstanceModel as c,findConnection as d,findConnectionsBetween as f,differenceConnections as g,$ as h,isDeploymentRelationModel as i,Z as j,sortDeepestFirst as k,isNodeModel as l,ve as m,isDeploymentElementModel as n,isElementModel as o,ye as p,K as q,isDeploymentNodeModel as r,isLikeC4ViewModel as s,isDeployedInstanceModel as t,isRelationModel as u,findDeepestNestedConnection as v,isIncoming as w,hasSameSourceTarget as x,findDescendantConnections as y,LikeC4DeploymentModel as z};
@@ -1 +1 @@
1
- var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,configurable:!0}),n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,__commonJSMin=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),__exportAll=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},__copyProps=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},__toESM=(n,r,a)=>(a=n==null?{}:e(i(n)),__copyProps(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));export{__toESM as i,__exportAll as n,__name as r,__commonJSMin as t};
1
+ var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,configurable:!0}),n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,__commonJSMin=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),__exportAll=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},__copyProps=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},__toESM=(n,r,o)=>(o=n==null?{}:e(i(n)),__copyProps(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));export{__toESM as i,__exportAll as n,__name as r,__commonJSMin as t};
@@ -1,4 +1,4 @@
1
- import{i as e,n as t,t as n}from"./rolldown-runtime.mjs";import{A as r,B as i,D as a,E as o,I as s,J as c,L as l,M as u,N as d,P as f,Q as p,R as ee,W as m,Z as h,a as te,at as g,b as _,f as ne,it as re,j as ie,k as ae,l as oe,q as se,rt as ce,t as v,w as y}from"./libs/remeda.mjs";import{i as b,n as x,s as S,t as le}from"./libs/mnemonist.mjs";import{t as ue}from"./libs/ohash.mjs";import{d as de,n as fe}from"./libs/mdast.mjs";import{n as pe,t as me}from"./libs/hast-util-sanitize.mjs";import{t as he}from"./libs/hast-util-to-html.mjs";import{i as ge,n as _e,r as ve,t as ye}from"./libs/remark.mjs";import{t as be}from"./libs/unified.mjs";import{a as xe,c as Se,d as Ce,f as we,h as Te,i as Ee,l as De,m as Oe,n as ke,o as Ae,p as C,r as je,s as Me,t as Ne,u as Pe}from"./libs/@radix-ui/colors.mjs";import{t as w}from"./libs/chroma-js.mjs";function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function _defu(e,t,n=`.`,r){if(!isPlainObject(t))return _defu(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(Array.isArray(a)&&Array.isArray(i[t])?i[t]=[...a,...i[t]]:isPlainObject(a)&&isPlainObject(i[t])?i[t]=_defu(a,i[t],(n?`${n}.`:``)+t.toString(),r):i[t]=a))}return i}function createDefu(e){return(...t)=>t.reduce((t,n)=>_defu(t,n,``,e),{})}const T=createDefu();function exact(e){return _(e,e=>e===void 0)}function preferSummary(e){return e.summary??e.description}function preferDescription(e){return e.description??e.summary}function isPoint(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function convertPoint(e){return isPoint(e)?{x:e[0],y:e[1]}:[e.x,e.y]}function nonNullable(e,t){if(e===void 0||e==null){let n=typeof t==`function`?t():t;throw Error(n??`Expected defined value, but received ${e}`)}return e}function invariant(e,t){if(!e)throw Error(t??`Invariant failed`)}function nonexhaustive(e){throw Error(`NonExhaustive value: ${e}`)}const Fe={center({x:e,y:t,width:n,height:r}){return{x:e+n/2,y:t+r/2}},toPoints({x:e,y:t,width:n,height:r}){return[{x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r}]},fromPoints(e){let{x1:t,y1:n,x2:r,y2:i}=E.fromPoints(e);return{x:t,y:n,width:r-t,height:i-n}},merge(...e){if(invariant(h(e,1),`No boxes provided`),e.length===1)return e[0];let t=e[0].x,n=e[0].y,r=e[0].x+e[0].width,i=e[0].y+e[0].height;for(let a=1;a<e.length;a++){let o=e[a];t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),i=Math.max(i,o.y+o.height)}return{x:Math.floor(t),y:Math.floor(n),width:Math.round(r-t),height:Math.round(i-n)}},fromRectBox(e){return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}},toRectBox(e){return{x1:e.x,y1:e.y,x2:e.x+e.width,y2:e.y+e.height}},expand(e,t){return typeof t==`number`?t===0?e:{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}:{x:e.x-(t.left??0),y:e.y-(t.top??0),width:e.width+(t.left??0)+(t.right??0),height:e.height+(t.top??0)+(t.bottom??0)}},shrink(e,t){return t===0?e:{x:e.x+t,y:e.y+t,width:e.width-t*2,height:e.height-t*2}},includes(e,t){return e===t||e.x<=t.x&&e.y<=t.y&&e.x+e.width>=t.x+t.width&&e.y+e.height>=t.y+t.height}},E={center({x1:e,y1:t,x2:n,y2:r}){return{x:(e+n)/2,y:(t+r)/2}},fromPoints(e){invariant(e.length>0,`At least one point is required`);let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let[a,o]of e)t=Math.min(t,a),n=Math.min(n,o),r=Math.max(r,a),i=Math.max(i,o);return{x1:t,y1:n,x2:r,y2:i}},merge(...e){invariant(e.length>0,`No boxes provided`);let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x1),n=Math.min(n,a.y1),r=Math.max(r,a.x2),i=Math.max(i,a.y2);return{x1:t,y1:n,x2:r,y2:i}},toBBox(e){return{x:e.x1,y:e.y1,width:e.x2-e.x1,height:e.y2-e.y1}},includes(e,t){return e===t||e.x1<=t.x1&&e.y1<=t.y1&&e.x2>=t.x2&&e.y2>=t.y2}};function commonHead(e,t,n){return e.length===0||t.length===0?[]:(n??=Object.is,p(v(e,t),te(([e,t])=>n(e,t)),y(([e,t])=>e)))}
1
+ import{i as e,n as t,t as n}from"./rolldown-runtime.mjs";import{A as r,C as i,E as a,F as o,I as s,K as c,L as l,M as u,N as d,O as ee,T as f,U as p,X as m,Z as h,a as te,c as ne,d as re,it as g,j as ie,k as ae,nt as oe,q as _,rt as se,t as v,y as ce,z as y}from"./libs/remeda.mjs";import{i as b,n as x,s as S,t as le}from"./libs/mnemonist.mjs";import{t as ue}from"./libs/ohash.mjs";import{t as de}from"./libs/hast-util-to-html.mjs";import{d as fe,n as pe}from"./libs/mdast.mjs";import{t as me}from"./libs/rehype-prism-plus.mjs";import{n as he,t as ge}from"./libs/hast-util-sanitize.mjs";import{i as C,n as _e,r as ve,t as ye}from"./libs/remark.mjs";import{t as be}from"./libs/unified.mjs";import{a as xe,c as Se,d as Ce,f as we,h as Te,i as Ee,l as De,m as Oe,n as ke,o as Ae,p as je,r as Me,s as Ne,t as Pe,u as Fe}from"./libs/@radix-ui/colors.mjs";import{t as w}from"./libs/chroma-js.mjs";function isPlainObject(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function _defu(e,t,n=`.`,r){if(!isPlainObject(t))return _defu(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(i[t]=Array.isArray(a)&&Array.isArray(i[t])?[...a,...i[t]]:isPlainObject(a)&&isPlainObject(i[t])?_defu(a,i[t],(n?`${n}.`:``)+t.toString(),r):a))}return i}function createDefu(e){return(...t)=>t.reduce((t,n)=>_defu(t,n,``,e),{})}const T=createDefu();function exact(e){return ce(e,e=>e===void 0)}function preferSummary(e){return e.summary??e.description}function preferDescription(e){return e.description??e.summary}function isPoint(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function convertPoint(e){return isPoint(e)?{x:e[0],y:e[1]}:[e.x,e.y]}function nonNullable(e,t){if(e===void 0||e==null){let n=typeof t==`function`?t():t;throw Error(n??`Expected defined value, but received ${e}`)}return e}function invariant(e,t){if(!e)throw Error(t??`Invariant failed`)}function nonexhaustive(e){throw Error(`NonExhaustive value: ${e}`)}const Ie={center({x:e,y:t,width:n,height:r}){return{x:e+n/2,y:t+r/2}},toPoints({x:e,y:t,width:n,height:r}){return[{x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r}]},fromPoints(e){let{x1:t,y1:n,x2:r,y2:i}=E.fromPoints(e);return{x:t,y:n,width:r-t,height:i-n}},merge(...e){if(invariant(m(e,1),`No boxes provided`),e.length===1)return e[0];let t=e[0].x,n=e[0].y,r=e[0].x+e[0].width,i=e[0].y+e[0].height;for(let a=1;a<e.length;a++){let o=e[a];t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),i=Math.max(i,o.y+o.height)}return{x:Math.floor(t),y:Math.floor(n),width:Math.round(r-t),height:Math.round(i-n)}},fromRectBox(e){return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}},toRectBox(e){return{x1:e.x,y1:e.y,x2:e.x+e.width,y2:e.y+e.height}},expand(e,t){return typeof t==`number`?t===0?e:{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}:{x:e.x-(t.left??0),y:e.y-(t.top??0),width:e.width+(t.left??0)+(t.right??0),height:e.height+(t.top??0)+(t.bottom??0)}},shrink(e,t){return t===0?e:{x:e.x+t,y:e.y+t,width:e.width-t*2,height:e.height-t*2}},includes(e,t){return e===t||e.x<=t.x&&e.y<=t.y&&e.x+e.width>=t.x+t.width&&e.y+e.height>=t.y+t.height}},E={center({x1:e,y1:t,x2:n,y2:r}){return{x:(e+n)/2,y:(t+r)/2}},fromPoints(e){invariant(e.length>0,`At least one point is required`);let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let[a,o]of e)t=Math.min(t,a),n=Math.min(n,o),r=Math.max(r,a),i=Math.max(i,o);return{x1:t,y1:n,x2:r,y2:i}},merge(...e){invariant(e.length>0,`No boxes provided`);let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x1),n=Math.min(n,a.y1),r=Math.max(r,a.x2),i=Math.max(i,a.y2);return{x1:t,y1:n,x2:r,y2:i}},toBBox(e){return{x:e.x1,y:e.y1,width:e.x2-e.x1,height:e.y2-e.y1}},includes(e,t){return e===t||e.x1<=t.x1&&e.y1<=t.y1&&e.x2>=t.x2&&e.y2>=t.y2}};function commonHead(e,t,n){return e.length===0||t.length===0?[]:(n??=Object.is,h(v(e,t),te(([e,t])=>n(e,t)),i(([e,t])=>e)))}
2
2
  /*
3
3
  * @version 1.4.0
4
4
  * @date 2015-10-26
@@ -6,4 +6,4 @@ import{i as e,n as t,t as n}from"./rolldown-runtime.mjs";import{A as r,B as i,D
6
6
  * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
7
7
  * @license MIT License
8
8
  */
9
- var D=e(n(((e,t)=>{var naturalCompare=function(e,t){var n,r,i=1,a=0,o=0,s=String.alphabet;function getCode(e,t,r){if(r){for(n=t;r=getCode(e,n),r<76&&r>65;)++n;return+e.slice(t-1,n)}return r=s&&s.indexOf(e.charAt(t)),r>-1?r+76:(r=e.charCodeAt(t)||0,r<45||r>127?r:r<46?65:r<48?r-1:r<58?r+18:r<65?r-11:r<91?r+11:r<97?r-37:r<123?r+5:r-63)}if((e+=``)!=(t+=``)){for(;i;)if(r=getCode(e,a++),i=getCode(t,o++),r<76&&i<76&&r>66&&i>66&&(r=getCode(e,a,a),i=getCode(t,o,a=n),o=n),r!=i)return r<i?-1:1}return 0};try{t.exports=naturalCompare}catch{String.naturalCompare=naturalCompare}}))(),1);function compareNatural(e,t){return e===t?0:a(e)?a(t)?(0,D.default)(e,t):1:a(t)?-1:0}function _sortNatural(e){return oe(e,compareNatural)}function sortNatural(...e){return e.length===0?_sortNatural:_sortNatural(e[0])}function compareNaturalHierarchically(e=`.`,t=!1){return(n,r)=>{if(n===r)return 0;if(!n)return-1;if(!r)return 1;let i=n.split(e),a=r.split(e),o=Math.min(i.length,a.length);for(let e=0;e<o;e++){let t=i[e],n=a[e],r=(0,D.default)(t,n);if(r!==0)return r}let s=i.length-a.length;return t?-1*s:s}}function parentFqn(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):null}function nameFromFqn(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):e}const asString=e=>isString(e)?e:e.id;function isAncestor(e,t){let n=asString(e);return t?asString(t).startsWith(n+`.`):e=>{let t=asString(e);return n.startsWith(t+`.`)}}function isSameHierarchy(e,t){if(!t)return t=>isSameHierarchy(e,t);let n=asString(e),r=asString(t);return n===r||r.startsWith(n+`.`)||n.startsWith(r+`.`)}function isDescendantOf(e,t){return t?isAncestor(t,e):t=>isAncestor(e,t)}function hierarchyLevel(e){return(isString(e)?e:e.id).split(`.`).length}function hierarchyDistance(e,t){let n=isString(e)?e:e.id,r=isString(t)?t:t.id;if(n===r)return 0;let i=hierarchyLevel(n),a=hierarchyLevel(r);if(isSameHierarchy(n,r))return Math.abs(i-a);let o=commonAncestor(n,r),s=o?hierarchyLevel(o):0;return i+a-(2*s+1)}function commonAncestor(e,t){let n=e.split(`.`);if(n.length<2)return null;let r=t.split(`.`);if(r.length<2)return null;let i=[];for(let e=0;e<Math.min(n.length,r.length)-1&&n[e]===r[e];e++)i.push(n[e]);return i.length===0?null:i.join(`.`)}function ancestorsFqn(e){let t=e.split(`.`);if(t.pop(),!h(t,2))return t;for(let e=1;e<t.length;e++)t[e]=t[e-1]+`.`+t[e];return t.reverse()}function compareFqnHierarchically(e,t){let n=e.split(`.`).length,r=t.split(`.`).length;switch(!0){case n>r:return 1;case n<r:return-1;default:return 0}}function compareByFqnHierarchically(e,t){return compareFqnHierarchically(e.id,t.id)}function sortByFqnHierarchically(e){return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>e.fqn.length-t.fqn.length).map(({item:e})=>e)}function findTopAncestor(e,t){let n=t;for(let t of e)t!==n&&isAncestor(t,n)&&(n=t);return n===t?null:n}function sortParentsFirst(e){let t=[],n=[...e],r;for(;r=n.shift();){let e;for(;e=findTopAncestor(n,r);)t.push(...n.splice(n.indexOf(e),1));t.push(r)}return t}function sortNaturalByFqn(e,t){if(!e||isString(e)){let t=e??`asc`;return e=>sortNaturalByFqn(e,t)}let n=t===`desc`?-1:1;return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>{if(e.fqn.length!==t.fqn.length)return(e.fqn.length-t.fqn.length)*n;for(let n=0;n<e.fqn.length;n++){let r=compareNatural(e.fqn[n],t.fqn[n]);if(r!==0)return r}return 0}).map(({item:e})=>e)}function getOrCreate(e,t,n){let r=e.get(t);return r||(r=n(t),e.set(t,r)),r}function isString(e){return e!=null&&typeof e==`string`}function isNonEmptyArray(e){return!!e&&Array.isArray(e)&&e.length>0}function _hasProp(e,t){return invariant(typeof t==`string`,`Path must be string`),typeof e==`object`&&!!e&&e[t]!=null}function hasPropCurried(e){return t=>_hasProp(t,e)}function hasProp(...e){if(e.length===1&&typeof e[0]==`string`)return hasPropCurried(e[0]);let[t,n]=e;return _hasProp(t,n)}function isAnyOf(...e){return(t=>e.some(e=>e(t)))}function hasChildren(e){return e.children.length>0}function isIterable(e){return typeof e==`object`&&!!e&&Symbol.iterator in e}function ifilter(e,t){let n=t??e;invariant(d(n));function*_filter(e){for(let t of e)n(t)&&(yield t)}return t?_filter(e):_filter}function ifind(e,t){let n=t??e;invariant(d(n));function _find(e){for(let t of e)if(n(t))return t}return t?_find(e):_find}function ifirst(e,t){let n=t??e;invariant(typeof n==`number`&&n>=0,`Count must be a non-negative number`);function*_first(e){let t=0;for(let r of e){if(t>=n)break;yield r,t++}}return t===void 0?e=>_first(e):_first(e)}function iflat(e){return e?_iflat(e):_iflat}function*_iflat(e){for(let t of e)yield*t}function iflatMap(e,t){let n=t??e;invariant(d(n));function*_flatMap(e){for(let t of e)yield*n(t)}return t?_flatMap(e):_flatMap}function ihead(e){return e?_head(e):_head}function _head(e){let{value:t}=e[Symbol.iterator]().next();return t}function imap(e,t){let n=t??e;invariant(d(n));function*_map(e){for(let t of e)yield n(t)}return t?_map(e):_map}function ireduce(e,t,n){let r=s(n)?t:e,i=n??t;invariant(d(r));function _reduce(e){let t=i;for(let n of e)t=r(t,n);return t}return s(n)?_reduce(e):_reduce}function isome(e,t){let n=t??e;invariant(d(n));function _some(e){for(let t of e)if(n(t))return!0;return!1}return t?_some(e):_some}function toArray(e){return e?Array.from(e):e=>Array.from(e)}function toSet(e){return e?new Set(e):e=>new Set(e)}function iunique(e){return e?_iunique(e):_iunique}function*_iunique(e){let t=new Set;for(let n of e)t.has(n)||(t.add(n),yield n)}function memoizeProp(e,t,n){let r=typeof t==`symbol`?t:Symbol.for(t);return e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!1,writable:!1,value:n()}),e[r]}function delay(...e){let t=100;return e.length===2?t=ne(e[0],e[1]):e.length===1&&(t=e[0]),new Promise(e=>{setTimeout(()=>{e(`LIKEC4_DELAY`)},t??100)})}function promiseNextTick(){return Promise.resolve().then(()=>void 0)}function onNextTick(e){Promise.resolve().then(e)}const compareRelations=(e,t)=>{let n=commonAncestor(e.source.id,e.target.id),r=commonAncestor(t.source.id,t.target.id);if(n&&!r)return 1;if(!n&&r)return-1;let i=n&&r?compareFqnHierarchically(n,r):0;if(i!==0)return i;let a=compareFqnHierarchically(e.source.id,t.source.id);return a===0?compareFqnHierarchically(e.target.id,t.target.id):a},Ie=S.intersection,Le=S.symmetricDifference;function union(...e){let t=new Set;for(let n of e)for(let e of n)t.add(e);return t}function intersection(e,...t){let n=new Set;if(e.size===0)return n;let r=h(t,2)?Ie(...t):t[0];if(r.size===0)return n;for(let t of e)r.has(t)&&n.add(t);return n}function difference(e,t){if(e.size===0)return new Set;if(t.size===0)return new Set(e);let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function equals(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function symmetricDifference(e,t){return Le(e,t)}function hasIntersection(e,t){if(e.size===0||t.size===0)return!1;t.size<e.size&&([e,t]=[t,e]);for(let n of e)if(t.has(n))return!0;return!1}function objectHash(e){return invariant(typeof e==`object`&&u(e),`objectHash: value must be an object`),ue(e)}function stringHash(e){let t=5381,n=e.length;invariant(n>0,`stringHash: empty string`);for(let r=0;r<n;r++)t=t*33^e.charCodeAt(r);return(t>>>0).toString(36)}function rehypeSanitize(e){return function(t){return me(t,e)}}function rehypeStringify(e){let t=this,n={...t.data(`settings`),...e};t.compiler=compiler;function compiler(e){return he(e,n)}}function parser(){return be().use(_e).use(ge).use(ve).use(ye,{allowDangerousHtml:!0}).use(rehypeSanitize,T({attributes:{"*":[`className`],svg:[`width`,`height`,`viewBox`,`fill`,`ariaHidden`],path:[`d`,`fill`,`stroke`,`strokeWidth`,`strokeLinecap`,`strokeLinejoin`]},tagNames:[`svg`,`g`,`path`,`div`],protocols:{src:[`data`]}},pe)).use(rehypeStringify,{allowDangerousHtml:!0})}function markdownToHtml(e){return(``+parser().processSync(e)).trim()}function markdownToText(e){return de(fe(e),{includeHtml:!1,includeImageAlt:!1})}function unsafePartial(e){return e}var O=class Vector{x;y;constructor(e,t){this.x=e,this.y=t,invariant(typeof e==`number`&&!isNaN(e)&&isFinite(e)&&typeof t==`number`&&!isNaN(t)&&isFinite(t),`Invalid arguments for Vector: (${e}, ${t})`)}static create(...e){return e.length===2?new Vector(e[0],e[1]):new Vector(e[0].x,e[0].y)}static add(e,t){return{x:e.x+t.x,y:e.y+t.y}}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y}}static multiply(e,t){return{x:e.x*t,y:e.y*t}}static divide(e,t){return{x:e.x/t,y:e.y/t}}static dot(e,t){return e.x*t.x+e.y*t.y}add(e){return new Vector(this.x+e.x,this.y+e.y)}subtract(e){return new Vector(this.x-e.x,this.y-e.y)}multiply(e){return new Vector(this.x*e,this.y*e)}divide(e){return new Vector(this.x/e,this.y/e)}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}length(){return this.x===0&&this.y===0?0:Math.sqrt(this.x**2+this.y**2)}normalize(){let e=this.length();return e===0?new Vector(0,0):new Vector(this.x/e,this.y/e)}round(){return new Vector(Math.round(this.x),Math.round(this.y))}trunc(){return new Vector(Math.trunc(this.x),Math.trunc(this.y))}toObject(){return{x:this.x,y:this.y}}};function vector(...e){return e.length===1&&e[0]instanceof O?e[0]:e.length===2?new O(e[0],e[1]):new O(e[0].x,e[0].y)}function isOnStage(e,t){return e[k]===t}const k=`_stage`,Re=`_type`,ze=`_layout`,Be=`_v`;var Ve=t({DeploymentFqn:()=>DeploymentFqn,EdgeId:()=>EdgeId,Fqn:()=>Fqn,GlobalFqn:()=>GlobalFqn,GroupElementKind:()=>j,MarkdownOrString:()=>MarkdownOrString,NodeId:()=>NodeId,NoneIcon:()=>A,ProjectId:()=>ProjectId,RelationId:()=>RelationId,StepEdgeKind:()=>M,StepPath:()=>StepPath,ViewId:()=>ViewId,flattenMarkdownOrString:()=>flattenMarkdownOrString,isGlobalFqn:()=>isGlobalFqn,isGroupElementKind:()=>isGroupElementKind,isStepPath:()=>isStepPath,splitGlobalFqn:()=>splitGlobalFqn});function ProjectId(e){return e}function MarkdownOrString(e){return typeof e==`string`?{txt:e}:e}function flattenMarkdownOrString(e){if(f(e))return null;let t=a(e)?e:e.txt??e.md;return o(t?.trim())?t:null}const A=`none`;function Fqn(e,t){return t?t+`.`+e:e}const j=`@group`;function isGroupElementKind(e){return e.kind===j}function DeploymentFqn(e,t){return t?t+`.`+e:e}function ViewId(e){return e}function RelationId(e){return e}function GlobalFqn(e,t){return invariant(typeof e==`string`&&e!=``),`@`+e+`.`+t}function isGlobalFqn(e){return e.startsWith(`@`)}function splitGlobalFqn(e){if(!e.startsWith(`@`))return[null,e];let t=e.indexOf(`.`);if(t<2)throw Error(`Invalid global FQN`);return[e.slice(1,t),e.slice(t+1)]}function NodeId(e){return e}function EdgeId(e){return e}const M=`@step`;function isStepPath(e){return typeof e==`string`&&e.startsWith(`step-`)}function StepPath(...e){let t=e.filter(e=>e!==void 0&&e!==``).map((e,t)=>Array.isArray(e)&&e.length===2?(invariant(o(e[1]),`StepPath segment kind can not be empty "${e[0]}:${e[1]}"`),`${e[0].toString(10).padStart(2,`0`)}:${e[1]}`):ae(e)?e.toString(10).padStart(2,`0`):t>0&&e?.startsWith(`step-`)?e.substring(5):e);invariant(h(t,1),`StepPath must have at least one segment`);let n=t.join(`.`);return n.startsWith(`step-`)?n:`step-${n}`}let N;(function(e){function isElementRef(e){return`model`in e&&!(`project`in e)}e.isElementRef=isElementRef;function isImportRef(e){return`project`in e&&`model`in e}e.isImportRef=isImportRef;function flatten(e){if(a(e))throw Error(`Expected FqnRef, got: "${e}"`);if(isImportRef(e))return GlobalFqn(e.project,e.model);if(isElementRef(e))return e.model;throw Error(`Expected FqnRef.ModelRef or FqnRef.ImportRef`)}e.flatten=flatten;function isModelRef(e){return isElementRef(e)||isImportRef(e)}e.isModelRef=isModelRef;function isInsideInstanceRef(e){return`deployment`in e&&`element`in e}e.isInsideInstanceRef=isInsideInstanceRef;function isDeploymentElementRef(e){return`deployment`in e&&!(`element`in e)}e.isDeploymentElementRef=isDeploymentElementRef;function isDeploymentRef(e){return isDeploymentElementRef(e)||isInsideInstanceRef(e)}e.isDeploymentRef=isDeploymentRef})(N||={});let P;(function(e){function isWildcard(e){return`wildcard`in e&&e.wildcard===!0}e.isWildcard=isWildcard;function isModelRef(e){return`ref`in e&&N.isModelRef(e.ref)}e.isModelRef=isModelRef;function isDeploymentRef(e){return`ref`in e&&N.isDeploymentRef(e.ref)}e.isDeploymentRef=isDeploymentRef;function isElementKindExpr(e){return`elementKind`in e&&`isEqual`in e}e.isElementKindExpr=isElementKindExpr;function isElementTagExpr(e){return`elementTag`in e&&`isEqual`in e}e.isElementTagExpr=isElementTagExpr;function isWhere(e){return`where`in e&&is(e.where.expr)}e.isWhere=isWhere;function isCustom(e){return`custom`in e&&(is(e.custom.expr)||isWhere(e.custom.expr))}e.isCustom=isCustom;function is(e){return isWildcard(e)||isModelRef(e)||isDeploymentRef(e)||isElementKindExpr(e)||isElementTagExpr(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.custom.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(P||={});let F;(function(e){function isDirect(e){return`source`in e&&`target`in e}e.isDirect=isDirect;function isIncoming(e){return`incoming`in e}e.isIncoming=isIncoming;function isOutgoing(e){return`outgoing`in e}e.isOutgoing=isOutgoing;function isInOut(e){return`inout`in e}e.isInOut=isInOut;function isWhere(e){return`where`in e&&(isDirect(e.where.expr)||isIncoming(e.where.expr)||isOutgoing(e.where.expr)||isInOut(e.where.expr))}e.isWhere=isWhere;function isCustom(e){return`customRelation`in e}e.isCustom=isCustom;function is(e){return isDirect(e)||isIncoming(e)||isOutgoing(e)||isInOut(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.customRelation.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(F||={});let I;(function(e){function isWhere(e){return`where`in e}e.isWhere=isWhere;function isRelationWhere(e){return F.isWhere(e)}e.isRelationWhere=isRelationWhere;function isFqnExprWhere(e){return P.isWhere(e)}e.isFqnExprWhere=isFqnExprWhere;function isFqnExpr(e){return P.is(e)||P.isWhere(e)||P.isCustom(e)}e.isFqnExpr=isFqnExpr;function isRelation(e){return F.is(e)||F.isWhere(e)||F.isCustom(e)}e.isRelation=isRelation})(I||={});let L;(function(e){function isWildcard(e){return`wildcard`in e&&e.wildcard===!0}e.isWildcard=isWildcard;function isModelRef(e){return`ref`in e&&N.isModelRef(e.ref)}e.isModelRef=isModelRef;function isElementKindExpr(e){return`elementKind`in e&&`isEqual`in e}e.isElementKindExpr=isElementKindExpr;function isElementTagExpr(e){return`elementTag`in e&&`isEqual`in e}e.isElementTagExpr=isElementTagExpr;function isWhere(e){return`where`in e&&is(e.where.expr)}e.isWhere=isWhere;function isCustom(e){return`custom`in e&&(is(e.custom.expr)||isWhere(e.custom.expr))}e.isCustom=isCustom;function is(e){return isWildcard(e)||isModelRef(e)||isElementKindExpr(e)||isElementTagExpr(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.custom.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(L||={});let R;(function(e){function isDirect(e){return`source`in e&&`target`in e}e.isDirect=isDirect;function isIncoming(e){return`incoming`in e}e.isIncoming=isIncoming;function isOutgoing(e){return`outgoing`in e}e.isOutgoing=isOutgoing;function isInOut(e){return`inout`in e}e.isInOut=isInOut;function isWhere(e){return`where`in e&&(isDirect(e.where.expr)||isIncoming(e.where.expr)||isOutgoing(e.where.expr)||isInOut(e.where.expr))}e.isWhere=isWhere;function isCustom(e){return`customRelation`in e}e.isCustom=isCustom;function is(e){return isDirect(e)||isIncoming(e)||isOutgoing(e)||isInOut(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.customRelation.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(R||={});let z;(function(e){function isWhere(e){return`where`in e}e.isWhere=isWhere;function isRelationWhere(e){return R.isWhere(e)}e.isRelationWhere=isRelationWhere;function isFqnExprWhere(e){return L.isWhere(e)}e.isFqnExprWhere=isFqnExprWhere;function isFqnExpr(e){return L.is(e)||L.isWhere(e)||L.isCustom(e)}e.isFqnExpr=isFqnExpr;function isRelationExpr(e){return R.is(e)||R.isWhere(e)||R.isCustom(e)}e.isRelationExpr=isRelationExpr})(z||={});function isDeploymentNode(e){return o(e.kind)&&!o(e.element)}function isDeployedInstance(e){return o(e.element)&&!o(e.kind)}const B={fill:`#3b82f6`,stroke:`#2563eb`,hiContrast:`#eff6ff`,loContrast:`#bfdbfe`},V={fill:`#0284c7`,stroke:`#0369a1`,hiContrast:`#f0f9ff`,loContrast:`#B6ECF7`},H={fill:`#64748b`,stroke:`#475569`,hiContrast:`#f8fafc`,loContrast:`#cbd5e1`},He={primary:B,blue:B,secondary:V,sky:V,muted:H,slate:H,gray:{fill:`#737373`,stroke:`#525252`,hiContrast:`#fafafa`,loContrast:`#d4d4d4`},red:{fill:`#AC4D39`,stroke:`#853A2D`,hiContrast:`#FBD3CB`,loContrast:`#f5b2a3`},green:{fill:`#428a4f`,stroke:`#2d5d39`,hiContrast:`#f8fafc`,loContrast:`#c2f0c2`},amber:{fill:`#A35829`,stroke:`#7E451D`,hiContrast:`#FFE0C2`,loContrast:`#f9b27c`},indigo:{fill:`#6366f1`,stroke:`#4f46e5`,hiContrast:`#eef2ff`,loContrast:`#c7d2fe`}},Ue={line:`#8D8D8D`,labelBg:`#18191B`,label:`#C9C9C9`},U={line:`#64748b`,labelBg:`#0f172a`,label:`#cbd5e1`},W={line:`#3b82f6`,labelBg:`#172554`,label:`#eff5fd`},G={line:`#0ea5e9`,labelBg:`#082f49`,label:`#d4f2ff`},We={amber:{line:`#b45309`,labelBg:`#78350f`,label:`#FFE0C2`},blue:W,gray:Ue,green:{line:`#15803d`,labelBg:`#052e16`,label:`#bbfcd3`},indigo:{line:`#6366f1`,labelBg:`#1e1b4b`,label:`#cbd0fd`},muted:U,primary:W,red:{line:`#AC4D39`,labelBg:`#b91c1c`,label:`#fcd9d2`},secondary:G,sky:G,slate:U},Ge={sizes:{xs:{width:180,height:100},sm:{width:240,height:135},md:{width:320,height:180},lg:{width:420,height:234},xl:{width:520,height:290}},spacing:{xs:8,sm:10,md:16,lg:24,xl:32},textSizes:{xs:13.33,sm:16,md:19.2,lg:23.04,xl:27.65},iconSizes:{xs:24,sm:36,md:60,lg:82,xl:90}},Ke=[`xs`,`sm`,`md`,`lg`,`xl`],qe=[`left`,`right`,`top`,`bottom`],Je=[`solid`,`dashed`,`dotted`,`none`],Ye=[`rectangle`,`person`,`browser`,`mobile`,`cylinder`,`storage`,`queue`,`bucket`,`document`,`component`],K=[`amber`,`blue`,`gray`,`slate`,`green`,`indigo`,`muted`,`primary`,`red`,`secondary`,`sky`],Xe=[`tomato`,`grass`,`blue`,`ruby`,`orange`,`indigo`,`pink`,`teal`,`purple`,`amber`,`crimson`,`red`,`lime`,`yellow`,`violet`],q={tomato:C.tomato9,grass:Ee.grass9,blue:ke.blue9,ruby:Ce.ruby9,orange:Me.orange9,indigo:xe.indigo9,pink:Se.pink9,teal:we.teal9,purple:De.purple9,amber:Ne.amber9,crimson:je.crimson9,red:Pe.red9,lime:Ae.lime9,yellow:Te.yellow9,violet:Oe.violet9};function isDefaultTagColor(e){return typeof e==`string`&&e in q}const Ze={colors:K.reduce((e,t)=>(e[t]={elements:He[t],relationships:We[t]},e),{}),...Ge};function adjustToneRgb(e,t){return t=Math.max(-1,Math.min(1,t)),e.map(e=>{let n=t>0?e+(255-e)*t:e*(1+t);return Math.round(Math.max(0,Math.min(255,n)))})}function adjustToneHex(e,t){return w(adjustToneRgb(w(e).rgb(),t)).hex()}function isValidColor(e){return w.valid(e)}function computeColorValues(e){invariant(w.valid(e),`Invalid color: ${e}`);let t=e.trim(),n=getColorPalette(t.startsWith(`#`)?t:w(t).hex());return{elements:{fill:n.el_main,stroke:n.el_secondary,hiContrast:n.el_hiContrast,loContrast:n.el_loContrast},relationships:{line:n.rel_secondary,label:n.rel_hiContrast,labelBg:n.rel_main}}}function getColorPalette(e){let t=e,n=w(t).darken(.8).hex(),r=getContrastedColorsAPCA(t),i=r.hiContrast,a=r.loContrast,o=t;return{el_main:t,el_secondary:n,el_hiContrast:i,el_loContrast:a,rel_main:o,rel_secondary:adjustToneHex(t,-.25),rel_hiContrast:getContrastedColorsAPCA(o).hiContrast}}function getContrastedColorsAPCA(e){let t=w(e),n=t.brighten(2),r=t.darken(2),a,o,s,c;do a=n,o=r,n=n.brighten(1),r=r.darken(1),s=w.contrastAPCA(t,n),c=w.contrastAPCA(t,r);while(Math.abs(s)<60&&Math.abs(c)<60&&(!i(n,a)||!i(r,o)));return Math.abs(s)>Math.abs(c)?{hiContrast:w(n.brighten(.4)).hex(),loContrast:n.hex()}:{hiContrast:w(r.darken(.4)).hex(),loContrast:r.hex()}}function computeCompoundColorValues(e,t){let n=t??6,r=w(e.fill),i=w(e.stroke),a=r.luminance()>.8,o=p(v(w.scale(a?[r.darken(.02).desaturate(.05),r.darken(.1).desaturate(.1)]:[r.shade(.12,`lch`).desaturate(.05),r.shade(.35,`lch`).desaturate(.4)]).mode(`oklch`).correctLightness().colors(n,null),w.scale(a?[i.darken(.04).desaturate(.05),i.darken(.12).desaturate(.1)]:[i.shade(.15,`lch`).desaturate(.08),i.shade(.4,`lch`).desaturate(.4)]).mode(`oklch`).correctLightness().colors(n,null)),y(([t,n])=>({...e,fill:t.hex(),stroke:n.hex()})));return invariant(o.length===n,`Expected ${n} colors, got ${o.length}`),o}const J={color:`primary`,size:`md`,opacity:15,shape:`rectangle`,group:{opacity:15,border:`dashed`},relationship:{color:`gray`,line:`dashed`,arrow:`normal`}},Y=Ze,X={theme:Y,defaults:J};var Qe=class LikeC4Styles{config;customCss;theme;defaults;static DEFAULT=new LikeC4Styles(X);static from(e,t){if(!e&&!t)return this.DEFAULT;let{customCss:n,theme:r,defaults:a}={...e},o=T({theme:r},{defaults:{...a}},{theme:{colors:{...t}}},X);return f(n?.content)&&i(o,X)?this.DEFAULT:new LikeC4Styles(o,n)}constructor(e,t){this.config=e,this.customCss=t,this.theme=e.theme,this.defaults=e.defaults}get fingerprint(){return memoizeProp(this,`fingerprint`,()=>objectHash({config:this.config,customCss:this.customCss}))}get elementColors(){return this.theme.colors[this.defaults.color].elements}get relationshipColors(){return this.theme.colors[this.defaults.relationship.color].relationships}get groupColors(){let e=this.defaults.group?.color;if(!e)return this.elementColors;if(!this.isThemeColor(e))throw Error(`Default group color not found in theme: ${e}`);return memoizeProp(this,`defaultGroup`,()=>({...this.elementColors,...this.theme.colors[e].elements}))}isDefaultColor(e){return e===this.defaults.color}colors(e){return this.computeFrom(e??this.defaults.color)}compoundColorsCache=new x.default(e=>new le.default(t=>computeCompoundColorValues(e,t)));colorsForCompounds(e,t){return this.compoundColorsCache.get(e).get(t??6)}fontSize(e){return e??=this.defaults.text??this.defaults.size,this.theme.textSizes[e]}padding(e){return e??=this.defaults.padding??this.defaults.size,this.theme.spacing[e]}iconSize(e){return e??=this.defaults.size,this.theme.iconSizes[e]}isThemeColor(e){return e in this.theme.colors}nodeSizes(e){let t=ensureSizes(e,this.defaults.size);return{sizes:t,values:{sizes:this.theme.sizes[t.size],padding:this.padding(t.padding),textSize:this.fontSize(t.textSize),iconSize:this.iconSize(t.iconSize)}}}computeFrom(e){if(this.isThemeColor(e))return this.theme.colors[e];if(!w.valid(e))throw Error(`Invalid color value: "${e}" (not a theme color and not a valid CSS color)`);return computeColorValues(e)}equals(e){return e===this||this.constructor===e.constructor&&this.fingerprint===e.fingerprint}tagColor(e){return this.isThemeColor(e)?this.theme.colors[e].elements:isDefaultTagColor(e)?this.computeFrom(q[e]).elements:this.computeFrom(e).elements}};function ensureSizes({size:e,padding:t,textSize:n,iconSize:r,...i},a=X.defaults.size){return e??=a,n??=e,t??=e,r??=e,{...i,size:e,padding:t,textSize:n,iconSize:r}}function isTagColorSpecified(e){let t=typeof e==`string`?e:e.color;return t.startsWith(`#`)||t.startsWith(`rgb`)}function isTagEqual(e){return`tag`in e}function isKindEqual(e){return`kind`in e}function isMetadataEqual(e){return`metadata`in e}function isParticipantOperator(e){return`participant`in e}function isNotOperator(e){return`not`in e}function isAndOperator(e){return`and`in e}function isOrOperator(e){return`or`in e}function whereOperatorAsPredicate(e){switch(!0){case isParticipantOperator(e):{let t=e.participant;return participantIs(t,whereOperatorAsPredicate(e.operator))}case isTagEqual(e):{if(a(e.tag)||`eq`in e.tag){let t=a(e.tag)?e.tag:e.tag.eq;return e=>Array.isArray(e.tags)&&e.tags.includes(t)}let t=e.tag.neq;return e=>!Array.isArray(e.tags)||!e.tags.includes(t)}case isKindEqual(e):{if(a(e.kind)||`eq`in e.kind){let t=a(e.kind)?e.kind:e.kind.eq;return e=>e.kind===t}let t=e.kind.neq;return e=>r(e.kind)||e.kind!==t}case isMetadataEqual(e):{let{key:t,value:n}=e.metadata;if(n===void 0)return e=>e.metadata!=null&&t in e.metadata&&e.metadata[t]!=null;if(a(n)||`eq`in n){let e=a(n)?n:n.eq;return n=>{if(!n.metadata)return!1;let r=n.metadata[t];return Array.isArray(r)?r.includes(e):r===e}}let r=n.neq;return e=>{if(!e.metadata)return!0;let n=e.metadata[t];return n==null?!0:Array.isArray(n)?!n.includes(r):n!==r}}case isNotOperator(e):return ie(whereOperatorAsPredicate(e.not));case isAndOperator(e):return re(e.and.map(whereOperatorAsPredicate));case isOrOperator(e):return ce(e.or.map(whereOperatorAsPredicate));default:nonexhaustive(e)}}function participantIs(e,t){return n=>{if(!n.source||!n.target)return!1;switch(e){case`source`:return t(n.source);case`target`:return t(n.target)}}}function isViewRulePredicate(e){return`include`in e||`exclude`in e}function isViewRuleStyle(e){return`targets`in e&&`style`in e}function isComputedView(e){return e._stage===`computed`}function isDiagramView(e){return e._stage===`layouted`}function isElementView(e){return e._type===`element`}function isScopedElementView(e){return isElementView(e)&&o(e.viewOf)}function isExtendsElementView(e){return isElementView(e)&&o(e.extends)}function isDeploymentView(e){return e._type===`deployment`}function isDynamicView(e){return e._type===`dynamic`}function isViewRuleGlobalStyle(e){return`styleId`in e}function isViewRuleGlobalPredicateRef(e){return`predicateId`in e}function isAutoLayoutDirection(e){return e===`TB`||e===`BT`||e===`LR`||e===`RL`}function isViewRuleAutoLayout(e){return`direction`in e}function isSubFlow(e){return typeof e==`object`&&!!e&&isString(e.id)&&isString(e._type)}function asStepPath(e){return isString(e)?e:e.id}const Z={isStepPath,isSubFlow,isTry:e=>isSubFlow(e)&&e._type===`try`,isTryBlock:e=>isSubFlow(e)&&Z.type.isTryBlock(e._type),isAlt:e=>isSubFlow(e)&&e._type===`alt`,isAltBranch:e=>isSubFlow(e)&&Z.type.isAltBranch(e._type),isTryBranch:e=>isSubFlow(e)&&Z.type.isTryBranch(e._type),isAltOrTry:e=>isSubFlow(e)&&Z.type.isAltOrTry(e._type),isAltOrTryBranch:e=>isSubFlow(e)&&Z.type.isAltOrTryBranch(e._type),type:{isAltOrTry:e=>e===`alt`||e===`try`,isAltBranch:e=>isString(e)&&e.startsWith(`alt-`),isTryBlock:e=>e===`try-block`,isTryBranch:e=>isString(e)&&e.startsWith(`try-`),isAltOrTryBranch:e=>isString(e)&&(e.startsWith(`alt-`)||e.startsWith(`try-`))}};function _includesStep(e,t){let n=asStepPath(e);return asStepPath(t).startsWith(n)}function includes(...e){return g(_includesStep,e)}const $e=compareNaturalHierarchically();function _isBefore(e,t){let n=asStepPath(e),r=asStepPath(t);return $e(n,r)<=0}function isBefore(...e){return g(_isBefore,e)}const Q={unwindTry:e=>{let[t,n=null,r=null]=e.flow;return!r&&n?._type===`try-finally`&&(r=n,n=null),{tryBlock:t,catchBlock:n?._type===`try-catch`?n:null,finallyBlock:r}},firstStep:e=>{if(isStepPath(e))return e;if(ee(e)){for(let t of e){if(isStepPath(t))return t;let e=Q.firstStep(t);if(e)return e}return null}return Q.firstStep(e.flow)},hasSteps:e=>!!Q.firstStep(e),steps:e=>c(e.flow,Z.isStepPath),subflows:e=>c(e.flow,Z.isSubFlow),hasSubflows:e=>e.flow.some(Z.isSubFlow),isBefore,includes};function flowAncestors(e){if(!e.includes(`:`))return[];let t=e.split(`.`),n=[],r;for(let e=0;e<t.length-1;e++){let i=t.at(e);r=r?r+`.`+i:i,i.includes(`:`)&&n.push(r)}return n}function parentFlow(e){if(!e)return null;let t=e.lastIndexOf(`.`);if(t===-1)return null;let n=e.slice(0,t);return n.includes(`:`)?n:null}var StopError=class{result;constructor(e){this.result=e}};function walkthroughFlow(...e){if(e.length===1)return t=>walkthroughFlow(t,e[0]);let[t,n]=e;if(!t.flow)throw Error(`Dynamic view ${t.id} does not have a flow`);let r=1,i=new Map(t.edges.map(e=>[e.id,e])),a=new Map(t.nodes.map(e=>[e.id,e])),visitStep=(e,t,o,s)=>{let c=nonNullable(i.get(e)),l=nonNullable(a.get(c.source)),u=nonNullable(a.get(c.target));n.step?.({step:e,level:o,edge:c,source:l,target:u,stepnum:{index:s,global:r++},parent:t,stopAndReturn:t=>{throw new StopError(t??e)}})},callSubflow=e=>{if(!n.subflow)return;if(d(n.subflow))return n.subflow(e);let t=n.subflow[e.type]??n.subflow.default;return l(t)?t:d(t)?t(e):void 0},visitSubflow=(e,t,n,r=0)=>{let i={id:e.id,type:e._type,subflow:e,parent:t,previous:n,level:r,stopAndReturn:t=>{throw new StopError(t??e)}},a=callSubflow(i)??!0;if(a===!1)return!1;let s,l;a===!0?s=e.flow:d(a)?(l=a,s=e.flow):(s=a.next?p(Array.isArray(a.next)?a.next:[a.next],c(o),y(t=>(invariant(e.flow.includes(t),`Next step must be part of the subflow`),t))):e.flow,l=a.onLeave);let u=walk(s,i,r+1);return l?.(u),!0};function walk(e,t,n=0){let r=1,i=null,a=[];for(let o of e){if(Z.isStepPath(o)){a.push(o),i=o,visitStep(o,t,n,r++);continue}visitSubflow(o,t,i,n)&&(a.push(o),i=o)}return{visited:a,lastVisited:i}}try{walk(t.flow,null,0)}catch(e){if(e instanceof StopError)return e.result;throw e}}function onSubflows(e,t){return e=Array.isArray(e)?e:[e],Object.fromEntries(y(e,e=>[e,t]))}walkthroughFlow.onSubflows=onSubflows;function dynamicViewFlow(e){return $.from(e)}var $=class DynamicViewFlow{static cache=new x.default(e=>new DynamicViewFlow(e));static from(e){return this.cache.get(e)}static guards=Z;static helpers=Q;unwindTry=Q.unwindTry;isBefore=Q.isBefore;includes=Q.includes;onSubflows=onSubflows;guards=Z;helpers=Q;view;levelById=new Map;byId=new Map;stepsCount;constructor(e){if(!e.flow)throw Error(`Dynamic view "${e.id}" does not have a flow, probably it is a stale snapshot`);this.view=e;let t=0;walkthroughFlow(e,{step:({step:e,level:n})=>{this.levelById.set(e,n),t++},subflow:({subflow:e,level:t})=>{this.byId.set(e.id,e),this.levelById.set(e.id,t)}}),this.stepsCount=t}get paths(){return Array.from(this.levelById.keys())}level(e){return nonNullable(this.levelById.get(isString(e)?e:e.id))}parent(e){let t=parentFlow(isString(e)?e:e.id);return t?this.lookup(t):void 0}firstStep(e){if(!e)return nonNullable(Q.firstStep(this.view.flow),`No steps found in flow`);let t=asStepPath(e);return this.isStep(t)?t:Q.firstStep(this.lookup(t))}isStep(e){return!this.byId.has(e)&&this.levelById.has(e)}isSubflow(e){return this.byId.has(e)}steps(e){return c(e?this.lookup(asStepPath(e)).flow:this.view.flow,isStepPath)}prevAndNext(e,t){invariant(!this.isSubflow(e),`${e} is a subflow, not a step`);let n=null,r=null,i=null;return walkthroughFlow(this.view,{step:({step:t,stopAndReturn:a})=>{i===e&&(r=t,a()),t===e&&(n=i),i=t},subflow:({subflow:e})=>!t?.(e.id)}),{prev:n,next:r}}lookup(e,t){let n=nonNullable(this.byId.get(e),`SubFlow "${e}" not found`);if(t&&n._type!==t)throw Error(`SubFlow "${e}" is of type "${n._type}" (expected "${t}")`);return n}subflows(e){return e?(typeof e==`string`?this.lookup(e):e).flow.filter(Z.isSubFlow):this.view.flow.filter(Z.isSubFlow)}hasSubflows(e){return(typeof e==`string`?this.byId.get(e):e)?.flow.some(Z.isSubFlow)??!1}walk(e){return walkthroughFlow(this.view,e)}stepsBefore(e){return stepsBefore(this.view,e)}stepPathsBefore(e){return stepsBefore(this.view,e).map(asStepPath)}};function stepsBefore(e,t){let n=includes(t),r=[];return walkthroughFlow(e,{step:({step:e,stopAndReturn:n})=>{e===t&&n(),r.push(e)},subflow:({subflow:e,stopAndReturn:i})=>e.id===t?i():(r.push(e),e._type===`alt`?{next:n(e)?se(e.flow,n):m(e.flow,Q.hasSteps)}:e._type!==`try`||{next:n(e)?e.flow:m(e.flow,Z.type.isTryBlock)})}),r}const et={isStep:e=>!!e&&`source`in e&&`target`in e,isSeries:e=>!!e&&`_type`in e&&e._type===`series`,isParallel:e=>!!e&&`_type`in e&&e._type===`par`,isOpt:e=>!!e&&`_type`in e&&e._type===`opt`,isLoop:e=>!!e&&`_type`in e&&e._type===`loop`,isTry:e=>!!e&&`_type`in e&&e._type===`try`,isAlt:e=>!!e&&`_type`in e&&e._type===`alt`,isBreak:e=>!!e&&`_type`in e&&e._type===`break`};function isViewRuleGroup(e){return`title`in e&&`groupRules`in e&&Array.isArray(e.groupRules)}function isViewRuleRank(e){return`rank`in e&&Array.isArray(e.targets)}const tt=Symbol.for(`text`),nt=Symbol.for(`html`);var rt=class RichText{static mdcache=new b.default(500);static txtcache=new b.default(500);static getOrCreateFromText(e){if(e=e.trimEnd(),e===``)return RichText.EMPTY;let t=RichText.txtcache.get(e);return t||(t=new RichText({txt:e}),RichText.txtcache.set(e,t),t)}static getOrCreateFromMarkdown(e){if(e=e.trimEnd(),e===``)return RichText.EMPTY;let t=RichText.mdcache.get(e);return t||(t=new RichText({md:e}),RichText.mdcache.set(e,t),t)}static memoize(e,t,n){return memoizeProp(e,t,()=>RichText.from(n))}static from(e){return e==null||e===RichText.EMPTY?RichText.EMPTY:e instanceof RichText?e:typeof e==`string`?this.getOrCreateFromText(e):`isEmpty`in e&&e.isEmpty?RichText.EMPTY:`md`in e?this.getOrCreateFromMarkdown(e.md):this.getOrCreateFromText(e.txt)}static EMPTY=new class extends RichText{isEmpty=!0;nonEmpty=!1;isMarkdown=!1;$source=null;constructor(){super({txt:``})}get text(){return null}get md(){return null}get html(){return null}};$source;isEmpty;nonEmpty;isMarkdown;constructor(e){this.isMarkdown=!1,typeof e==`string`?(this.$source={txt:e},this.isEmpty=e.trim()===``):(this.$source=e,this.isEmpty=!0,`md`in e?(this.isEmpty=e.md===``,this.isMarkdown=!0):this.isEmpty=e.txt===``),this.nonEmpty=!this.isEmpty}get text(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;return`txt`in e?e.txt:memoizeProp(this,tt,()=>markdownToText(e.md))}get md(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;if(`md`in e)return e.md;if(`txt`in e)return e.txt;nonexhaustive(e)}get html(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;return`txt`in e?e.txt:memoizeProp(this,nt,()=>markdownToHtml(e.md))}equals(e){return this===e?!0:e instanceof RichText?this.isEmpty&&e.isEmpty?!0:this.isEmpty!==e.isEmpty||this.isMarkdown!==e.isMarkdown?!1:this.isMarkdown?this.$source?.md===e.$source?.md:this.$source?.txt===e.$source?.txt:!1}};export{I as $,iflat as $t,isOrOperator as A,invariant as An,markdownToText as At,getContrastedColorsAPCA as B,compareRelations as Bt,isScopedElementView as C,sortParentsFirst as Cn,k as Ct,isKindEqual as D,commonHead as Dn,O as Dt,isAndOperator as E,sortNatural as En,isOnStage as Et,ensureSizes as F,preferDescription as Fn,equals as Ft,qe as G,iunique as Gt,Je as H,onNextTick as Ht,Qe as I,preferSummary as In,hasIntersection as It,isDeployedInstance as J,isome as Jt,Ke as K,toArray as Kt,Y as L,exact as Ln,intersection as Lt,isTagEqual as M,nonexhaustive as Mn,stringHash as Mt,whereOperatorAsPredicate as N,convertPoint as Nn,objectHash as Nt,isMetadataEqual as O,Fe as On,vector as Ot,isTagColorSpecified as P,isPoint as Pn,difference as Pt,R as Q,iflatMap as Qt,J as R,T as Rn,symmetricDifference as Rt,isExtendsElementView as S,sortNaturalByFqn as Sn,ze as St,isViewRuleStyle as T,compareNaturalHierarchically as Tn,Be as Tt,Xe as U,promiseNextTick as Ut,isValidColor as V,delay as Vt,Ye as W,memoizeProp as Wt,z as X,imap as Xt,isDeploymentNode as Y,ireduce as Yt,L as Z,ihead as Zt,isComputedView as _,isDescendantOf as _n,isGlobalFqn as _t,$ as a,hasProp as an,Fqn as at,isDynamicView as b,parentFqn as bn,Ve as bt,Z as c,isString as cn,MarkdownOrString as ct,stepsBefore as d,commonAncestor as dn,ProjectId as dt,ifirst as en,P as et,walkthroughFlow as f,compareByFqnHierarchically as fn,RelationId as ft,isViewRuleGlobalStyle as g,isAncestor as gn,flattenMarkdownOrString as gt,isViewRuleGlobalPredicateRef as h,hierarchyLevel as hn,ViewId as ht,et as i,hasChildren as in,EdgeId as it,isParticipantOperator as j,nonNullable as jn,markdownToHtml as jt,isNotOperator as k,E as kn,unsafePartial as kt,Q as l,getOrCreate as ln,NodeId as lt,isViewRuleAutoLayout as m,hierarchyDistance as mn,StepPath as mt,isViewRuleGroup as n,ifilter as nn,N as nt,dynamicViewFlow as o,isAnyOf as on,GlobalFqn as ot,isAutoLayoutDirection as p,compareFqnHierarchically as pn,M as pt,K as q,toSet as qt,isViewRuleRank as r,isIterable as rn,DeploymentFqn as rt,flowAncestors as s,isNonEmptyArray as sn,j as st,rt as t,ifind as tn,F as tt,parentFlow as u,ancestorsFqn as un,A as ut,isDeploymentView as v,isSameHierarchy as vn,isGroupElementKind as vt,isViewRulePredicate as w,compareNatural as wn,Re as wt,isElementView as x,sortByFqnHierarchically as xn,splitGlobalFqn as xt,isDiagramView as y,nameFromFqn as yn,isStepPath as yt,computeColorValues as z,union as zt};
9
+ var D=e(n(((e,t)=>{var naturalCompare=function(e,t){var n,r,i=1,a=0,o=0,s=String.alphabet;function getCode(e,t,r){if(r){for(n=t;r=getCode(e,n),r<76&&r>65;)++n;return+e.slice(t-1,n)}return r=s&&s.indexOf(e.charAt(t)),r>-1?r+76:(r=e.charCodeAt(t)||0,r<45||r>127?r:r<46?65:r<48?r-1:r<58?r+18:r<65?r-11:r<91?r+11:r<97?r-37:r<123?r+5:r-63)}if((e+=``)!=(t+=``)){for(;i;)if(r=getCode(e,a++),i=getCode(t,o++),r<76&&i<76&&r>66&&i>66&&(r=getCode(e,a,a),i=getCode(t,o,a=n),o=n),r!=i)return r<i?-1:1}return 0};try{t.exports=naturalCompare}catch{String.naturalCompare=naturalCompare}}))(),1);function compareNatural(e,t){return e===t?0:a(e)?a(t)?(0,D.default)(e,t):1:a(t)?-1:0}function _sortNatural(e){return ne(e,compareNatural)}function sortNatural(...e){return e.length===0?_sortNatural:_sortNatural(e[0])}function compareNaturalHierarchically(e=`.`,t=!1){return(n,r)=>{if(n===r)return 0;if(!n)return-1;if(!r)return 1;let i=n.split(e),a=r.split(e),o=Math.min(i.length,a.length);for(let e=0;e<o;e++){let t=i[e],n=a[e],r=(0,D.default)(t,n);if(r!==0)return r}let s=i.length-a.length;return t?-1*s:s}}function parentFqn(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):null}function nameFromFqn(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):e}const asString=e=>isString(e)?e:e.id;function isAncestor(e,t){let n=asString(e);return t?asString(t).startsWith(n+`.`):e=>{let t=asString(e);return n.startsWith(t+`.`)}}function isSameHierarchy(e,t){if(!t)return t=>isSameHierarchy(e,t);let n=asString(e),r=asString(t);return n===r||r.startsWith(n+`.`)||n.startsWith(r+`.`)}function isDescendantOf(e,t){return t?isAncestor(t,e):t=>isAncestor(e,t)}function hierarchyLevel(e){return(isString(e)?e:e.id).split(`.`).length}function hierarchyDistance(e,t){let n=isString(e)?e:e.id,r=isString(t)?t:t.id;if(n===r)return 0;let i=hierarchyLevel(n),a=hierarchyLevel(r);if(isSameHierarchy(n,r))return Math.abs(i-a);let o=commonAncestor(n,r),s=o?hierarchyLevel(o):0;return i+a-(2*s+1)}function commonAncestor(e,t){let n=e.split(`.`);if(n.length<2)return null;let r=t.split(`.`);if(r.length<2)return null;let i=[];for(let e=0;e<Math.min(n.length,r.length)-1&&n[e]===r[e];e++)i.push(n[e]);return i.length===0?null:i.join(`.`)}function ancestorsFqn(e){let t=e.split(`.`);if(t.pop(),!m(t,2))return t;for(let e=1;e<t.length;e++)t[e]=t[e-1]+`.`+t[e];return t.reverse()}function compareFqnHierarchically(e,t){let n=e.split(`.`).length,r=t.split(`.`).length;switch(!0){case n>r:return 1;case n<r:return-1;default:return 0}}function compareByFqnHierarchically(e,t){return compareFqnHierarchically(e.id,t.id)}function sortByFqnHierarchically(e){return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>e.fqn.length-t.fqn.length).map(({item:e})=>e)}function findTopAncestor(e,t){let n=t;for(let t of e)t!==n&&isAncestor(t,n)&&(n=t);return n===t?null:n}function sortParentsFirst(e){let t=[],n=[...e],r;for(;r=n.shift();){let e;for(;e=findTopAncestor(n,r);)t.push(...n.splice(n.indexOf(e),1));t.push(r)}return t}function sortNaturalByFqn(e,t){if(!e||isString(e)){let t=e??`asc`;return e=>sortNaturalByFqn(e,t)}let n=t===`desc`?-1:1;return e.map(e=>({item:e,fqn:e.id.split(`.`)})).sort((e,t)=>{if(e.fqn.length!==t.fqn.length)return(e.fqn.length-t.fqn.length)*n;for(let n=0;n<e.fqn.length;n++){let r=compareNatural(e.fqn[n],t.fqn[n]);if(r!==0)return r}return 0}).map(({item:e})=>e)}function getOrCreate(e,t,n){let r=e.get(t);return r||(r=n(t),e.set(t,r)),r}function isString(e){return e!=null&&typeof e==`string`}function isNonEmptyArray(e){return!!e&&Array.isArray(e)&&e.length>0}function _hasProp(e,t){return invariant(typeof t==`string`,`Path must be string`),typeof e==`object`&&!!e&&e[t]!=null}function hasPropCurried(e){return t=>_hasProp(t,e)}function hasProp(...e){if(e.length===1&&typeof e[0]==`string`)return hasPropCurried(e[0]);let[t,n]=e;return _hasProp(t,n)}function isAnyOf(...e){return(t=>e.some(e=>e(t)))}function hasChildren(e){return e.children.length>0}function isIterable(e){return typeof e==`object`&&!!e&&Symbol.iterator in e}function ifilter(e,t){let n=t??e;invariant(u(n));function*_filter(e){for(let t of e)n(t)&&(yield t)}return t?_filter(e):_filter}function ifind(e,t){let n=t??e;invariant(u(n));function _find(e){for(let t of e)if(n(t))return t}return t?_find(e):_find}function ifirst(e,t){let n=t??e;invariant(typeof n==`number`&&n>=0,`Count must be a non-negative number`);function*_first(e){let t=0;for(let r of e){if(t>=n)break;yield r,t++}}return t===void 0?e=>_first(e):_first(e)}function iflat(e){return e?_iflat(e):_iflat}function*_iflat(e){for(let t of e)yield*t}function iflatMap(e,t){let n=t??e;invariant(u(n));function*_flatMap(e){for(let t of e)yield*n(t)}return t?_flatMap(e):_flatMap}function ihead(e){return e?_head(e):_head}function _head(e){let{value:t}=e[Symbol.iterator]().next();return t}function imap(e,t){let n=t??e;invariant(u(n));function*_map(e){for(let t of e)yield n(t)}return t?_map(e):_map}function ireduce(e,t,n){let r=o(n)?t:e,i=n??t;invariant(u(r));function _reduce(e){let t=i;for(let n of e)t=r(t,n);return t}return o(n)?_reduce(e):_reduce}function isome(e,t){let n=t??e;invariant(u(n));function _some(e){for(let t of e)if(n(t))return!0;return!1}return t?_some(e):_some}function toArray(e){return e?Array.from(e):e=>Array.from(e)}function toSet(e){return e?new Set(e):e=>new Set(e)}function iunique(e){return e?_iunique(e):_iunique}function*_iunique(e){let t=new Set;for(let n of e)t.has(n)||(t.add(n),yield n)}function memoizeProp(e,t,n){let r=typeof t==`symbol`?t:Symbol.for(t);return e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!1,writable:!1,value:n()}),e[r]}function delay(...e){let t=100;return e.length===2?t=re(e[0],e[1]):e.length===1&&(t=e[0]),new Promise(e=>{setTimeout(()=>{e(`LIKEC4_DELAY`)},t??100)})}function promiseNextTick(){return Promise.resolve().then(()=>void 0)}function onNextTick(e){Promise.resolve().then(e)}const compareRelations=(e,t)=>{let n=commonAncestor(e.source.id,e.target.id),r=commonAncestor(t.source.id,t.target.id);if(n&&!r)return 1;if(!n&&r)return-1;let i=n&&r?compareFqnHierarchically(n,r):0;if(i!==0)return i;let a=compareFqnHierarchically(e.source.id,t.source.id);return a===0?compareFqnHierarchically(e.target.id,t.target.id):a},Le=S.intersection,Re=S.symmetricDifference;function union(...e){let t=new Set;for(let n of e)for(let e of n)t.add(e);return t}function intersection(e,...t){let n=new Set;if(e.size===0)return n;let r=m(t,2)?Le(...t):t[0];if(r.size===0)return n;for(let t of e)r.has(t)&&n.add(t);return n}function difference(e,t){if(e.size===0)return new Set;if(t.size===0)return new Set(e);let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function equals(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function symmetricDifference(e,t){return Re(e,t)}function hasIntersection(e,t){if(e.size===0||t.size===0)return!1;t.size<e.size&&([e,t]=[t,e]);for(let n of e)if(t.has(n))return!0;return!1}function objectHash(e){return invariant(typeof e==`object`&&ie(e),`objectHash: value must be an object`),ue(e)}function stringHash(e){let t=5381,n=e.length;invariant(n>0,`stringHash: empty string`);for(let r=0;r<n;r++)t=t*33^e.charCodeAt(r);return(t>>>0).toString(36)}function rehypeSanitize(e){return function(t){return ge(t,e)}}function rehypeStringify(e){let t=this,n={...t.data(`settings`),...e};t.compiler=compiler;function compiler(e){return de(e,n)}}function parser(){return be().use(_e).use(C).use(ve).use(ye,{allowDangerousHtml:!0}).use(me,{ignoreMissing:!0}).use(rehypeSanitize,T({attributes:{"*":[`className`],svg:[`width`,`height`,`viewBox`,`fill`,`ariaHidden`],path:[`d`,`fill`,`stroke`,`strokeWidth`,`strokeLinecap`,`strokeLinejoin`]},tagNames:[`svg`,`g`,`path`,`div`],protocols:{src:[`data`]}},he)).use(rehypeStringify,{allowDangerousHtml:!0})}function markdownToHtml(e){return(``+parser().processSync(e)).trim()}function markdownToText(e){return fe(pe(e),{includeHtml:!1,includeImageAlt:!1})}function unsafePartial(e){return e}var O=class Vector{x;y;constructor(e,t){this.x=e,this.y=t,invariant(typeof e==`number`&&!isNaN(e)&&isFinite(e)&&typeof t==`number`&&!isNaN(t)&&isFinite(t),`Invalid arguments for Vector: (${e}, ${t})`)}static create(...e){return e.length===2?new Vector(e[0],e[1]):new Vector(e[0].x,e[0].y)}static add(e,t){return{x:e.x+t.x,y:e.y+t.y}}static subtract(e,t){return{x:e.x-t.x,y:e.y-t.y}}static multiply(e,t){return{x:e.x*t,y:e.y*t}}static divide(e,t){return{x:e.x/t,y:e.y/t}}static dot(e,t){return e.x*t.x+e.y*t.y}add(e){return new Vector(this.x+e.x,this.y+e.y)}subtract(e){return new Vector(this.x-e.x,this.y-e.y)}multiply(e){return new Vector(this.x*e,this.y*e)}divide(e){return new Vector(this.x/e,this.y/e)}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}length(){return this.x===0&&this.y===0?0:Math.sqrt(this.x**2+this.y**2)}normalize(){let e=this.length();return e===0?new Vector(0,0):new Vector(this.x/e,this.y/e)}round(){return new Vector(Math.round(this.x),Math.round(this.y))}trunc(){return new Vector(Math.trunc(this.x),Math.trunc(this.y))}toObject(){return{x:this.x,y:this.y}}};function vector(...e){return e.length===1&&e[0]instanceof O?e[0]:e.length===2?new O(e[0],e[1]):new O(e[0].x,e[0].y)}function isOnStage(e,t){return e[k]===t}const k=`_stage`,ze=`_type`,Be=`_layout`,Ve=`_v`;var He=t({DeploymentFqn:()=>DeploymentFqn,EdgeId:()=>EdgeId,Fqn:()=>Fqn,GlobalFqn:()=>GlobalFqn,GroupElementKind:()=>j,MarkdownOrString:()=>MarkdownOrString,NodeId:()=>NodeId,NoneIcon:()=>A,ProjectId:()=>ProjectId,RelationId:()=>RelationId,StepEdgeKind:()=>M,StepPath:()=>StepPath,ViewId:()=>ViewId,flattenMarkdownOrString:()=>flattenMarkdownOrString,isGlobalFqn:()=>isGlobalFqn,isGroupElementKind:()=>isGroupElementKind,isStepPath:()=>isStepPath,splitGlobalFqn:()=>splitGlobalFqn});function ProjectId(e){return e}function MarkdownOrString(e){return typeof e==`string`?{txt:e}:e}function flattenMarkdownOrString(e){if(d(e))return null;let t=a(e)?e:e.txt??e.md;return f(t?.trim())?t:null}const A=`none`;function Fqn(e,t){return t?t+`.`+e:e}const j=`@group`;function isGroupElementKind(e){return e.kind===j}function DeploymentFqn(e,t){return t?t+`.`+e:e}function ViewId(e){return e}function RelationId(e){return e}function GlobalFqn(e,t){return invariant(typeof e==`string`&&e!=``),`@`+e+`.`+t}function isGlobalFqn(e){return e.startsWith(`@`)}function splitGlobalFqn(e){if(!e.startsWith(`@`))return[null,e];let t=e.indexOf(`.`);if(t<2)throw Error(`Invalid global FQN`);return[e.slice(1,t),e.slice(t+1)]}function NodeId(e){return e}function EdgeId(e){return e}const M=`@step`;function isStepPath(e){return typeof e==`string`&&e.startsWith(`step-`)}function StepPath(...e){let t=e.filter(e=>e!==void 0&&e!==``).map((e,t)=>Array.isArray(e)&&e.length===2?(invariant(f(e[1]),`StepPath segment kind can not be empty "${e[0]}:${e[1]}"`),`${e[0].toString(10).padStart(2,`0`)}:${e[1]}`):ee(e)?e.toString(10).padStart(2,`0`):t>0&&e?.startsWith(`step-`)?e.substring(5):e);invariant(m(t,1),`StepPath must have at least one segment`);let n=t.join(`.`);return n.startsWith(`step-`)?n:`step-${n}`}let N;(function(e){function isElementRef(e){return`model`in e&&!(`project`in e)}e.isElementRef=isElementRef;function isImportRef(e){return`project`in e&&`model`in e}e.isImportRef=isImportRef;function flatten(e){if(a(e))throw Error(`Expected FqnRef, got: "${e}"`);if(isImportRef(e))return GlobalFqn(e.project,e.model);if(isElementRef(e))return e.model;throw Error(`Expected FqnRef.ModelRef or FqnRef.ImportRef`)}e.flatten=flatten;function isModelRef(e){return isElementRef(e)||isImportRef(e)}e.isModelRef=isModelRef;function isInsideInstanceRef(e){return`deployment`in e&&`element`in e}e.isInsideInstanceRef=isInsideInstanceRef;function isDeploymentElementRef(e){return`deployment`in e&&!(`element`in e)}e.isDeploymentElementRef=isDeploymentElementRef;function isDeploymentRef(e){return isDeploymentElementRef(e)||isInsideInstanceRef(e)}e.isDeploymentRef=isDeploymentRef})(N||={});let P;(function(e){function isWildcard(e){return`wildcard`in e&&e.wildcard===!0}e.isWildcard=isWildcard;function isModelRef(e){return`ref`in e&&N.isModelRef(e.ref)}e.isModelRef=isModelRef;function isDeploymentRef(e){return`ref`in e&&N.isDeploymentRef(e.ref)}e.isDeploymentRef=isDeploymentRef;function isElementKindExpr(e){return`elementKind`in e&&`isEqual`in e}e.isElementKindExpr=isElementKindExpr;function isElementTagExpr(e){return`elementTag`in e&&`isEqual`in e}e.isElementTagExpr=isElementTagExpr;function isWhere(e){return`where`in e&&is(e.where.expr)}e.isWhere=isWhere;function isCustom(e){return`custom`in e&&(is(e.custom.expr)||isWhere(e.custom.expr))}e.isCustom=isCustom;function is(e){return isWildcard(e)||isModelRef(e)||isDeploymentRef(e)||isElementKindExpr(e)||isElementTagExpr(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.custom.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(P||={});let F;(function(e){function isDirect(e){return`source`in e&&`target`in e}e.isDirect=isDirect;function isIncoming(e){return`incoming`in e}e.isIncoming=isIncoming;function isOutgoing(e){return`outgoing`in e}e.isOutgoing=isOutgoing;function isInOut(e){return`inout`in e}e.isInOut=isInOut;function isWhere(e){return`where`in e&&(isDirect(e.where.expr)||isIncoming(e.where.expr)||isOutgoing(e.where.expr)||isInOut(e.where.expr))}e.isWhere=isWhere;function isCustom(e){return`customRelation`in e}e.isCustom=isCustom;function is(e){return isDirect(e)||isIncoming(e)||isOutgoing(e)||isInOut(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.customRelation.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(F||={});let I;(function(e){function isWhere(e){return`where`in e}e.isWhere=isWhere;function isRelationWhere(e){return F.isWhere(e)}e.isRelationWhere=isRelationWhere;function isFqnExprWhere(e){return P.isWhere(e)}e.isFqnExprWhere=isFqnExprWhere;function isFqnExpr(e){return P.is(e)||P.isWhere(e)||P.isCustom(e)}e.isFqnExpr=isFqnExpr;function isRelation(e){return F.is(e)||F.isWhere(e)||F.isCustom(e)}e.isRelation=isRelation})(I||={});let L;(function(e){function isWildcard(e){return`wildcard`in e&&e.wildcard===!0}e.isWildcard=isWildcard;function isModelRef(e){return`ref`in e&&N.isModelRef(e.ref)}e.isModelRef=isModelRef;function isElementKindExpr(e){return`elementKind`in e&&`isEqual`in e}e.isElementKindExpr=isElementKindExpr;function isElementTagExpr(e){return`elementTag`in e&&`isEqual`in e}e.isElementTagExpr=isElementTagExpr;function isWhere(e){return`where`in e&&is(e.where.expr)}e.isWhere=isWhere;function isCustom(e){return`custom`in e&&(is(e.custom.expr)||isWhere(e.custom.expr))}e.isCustom=isCustom;function is(e){return isWildcard(e)||isModelRef(e)||isElementKindExpr(e)||isElementTagExpr(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.custom.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(L||={});let R;(function(e){function isDirect(e){return`source`in e&&`target`in e}e.isDirect=isDirect;function isIncoming(e){return`incoming`in e}e.isIncoming=isIncoming;function isOutgoing(e){return`outgoing`in e}e.isOutgoing=isOutgoing;function isInOut(e){return`inout`in e}e.isInOut=isInOut;function isWhere(e){return`where`in e&&(isDirect(e.where.expr)||isIncoming(e.where.expr)||isOutgoing(e.where.expr)||isInOut(e.where.expr))}e.isWhere=isWhere;function isCustom(e){return`customRelation`in e}e.isCustom=isCustom;function is(e){return isDirect(e)||isIncoming(e)||isOutgoing(e)||isInOut(e)}e.is=is;function unwrap(e){return isCustom(e)&&(e=e.customRelation.expr),isWhere(e)&&(e=e.where.expr),e}e.unwrap=unwrap})(R||={});let z;(function(e){function isWhere(e){return`where`in e}e.isWhere=isWhere;function isRelationWhere(e){return R.isWhere(e)}e.isRelationWhere=isRelationWhere;function isFqnExprWhere(e){return L.isWhere(e)}e.isFqnExprWhere=isFqnExprWhere;function isFqnExpr(e){return L.is(e)||L.isWhere(e)||L.isCustom(e)}e.isFqnExpr=isFqnExpr;function isRelationExpr(e){return R.is(e)||R.isWhere(e)||R.isCustom(e)}e.isRelationExpr=isRelationExpr})(z||={});function isDeploymentNode(e){return f(e.kind)&&!f(e.element)}function isDeployedInstance(e){return f(e.element)&&!f(e.kind)}const B={fill:`#3b82f6`,stroke:`#2563eb`,hiContrast:`#eff6ff`,loContrast:`#bfdbfe`},V={fill:`#0284c7`,stroke:`#0369a1`,hiContrast:`#f0f9ff`,loContrast:`#B6ECF7`},H={fill:`#64748b`,stroke:`#475569`,hiContrast:`#f8fafc`,loContrast:`#cbd5e1`},Ue={primary:B,blue:B,secondary:V,sky:V,muted:H,slate:H,gray:{fill:`#737373`,stroke:`#525252`,hiContrast:`#fafafa`,loContrast:`#d4d4d4`},red:{fill:`#AC4D39`,stroke:`#853A2D`,hiContrast:`#FBD3CB`,loContrast:`#f5b2a3`},green:{fill:`#428a4f`,stroke:`#2d5d39`,hiContrast:`#f8fafc`,loContrast:`#c2f0c2`},amber:{fill:`#A35829`,stroke:`#7E451D`,hiContrast:`#FFE0C2`,loContrast:`#f9b27c`},indigo:{fill:`#6366f1`,stroke:`#4f46e5`,hiContrast:`#eef2ff`,loContrast:`#c7d2fe`}},We={line:`#8D8D8D`,labelBg:`#18191B`,label:`#C9C9C9`},U={line:`#64748b`,labelBg:`#0f172a`,label:`#cbd5e1`},W={line:`#3b82f6`,labelBg:`#172554`,label:`#eff5fd`},G={line:`#0ea5e9`,labelBg:`#082f49`,label:`#d4f2ff`},Ge={amber:{line:`#b45309`,labelBg:`#78350f`,label:`#FFE0C2`},blue:W,gray:We,green:{line:`#15803d`,labelBg:`#052e16`,label:`#bbfcd3`},indigo:{line:`#6366f1`,labelBg:`#1e1b4b`,label:`#cbd0fd`},muted:U,primary:W,red:{line:`#AC4D39`,labelBg:`#b91c1c`,label:`#fcd9d2`},secondary:G,sky:G,slate:U},Ke={sizes:{xs:{width:180,height:100},sm:{width:240,height:135},md:{width:320,height:180},lg:{width:420,height:234},xl:{width:520,height:290}},spacing:{xs:8,sm:10,md:16,lg:24,xl:32},textSizes:{xs:13.33,sm:16,md:19.2,lg:23.04,xl:27.65},iconSizes:{xs:24,sm:36,md:60,lg:82,xl:90}},qe=[`xs`,`sm`,`md`,`lg`,`xl`],Je=[`left`,`right`,`top`,`bottom`],Ye=[`solid`,`dashed`,`dotted`,`none`],Xe=[`rectangle`,`person`,`browser`,`mobile`,`cylinder`,`storage`,`queue`,`bucket`,`document`,`component`],K=[`amber`,`blue`,`gray`,`slate`,`green`,`indigo`,`muted`,`primary`,`red`,`secondary`,`sky`],Ze=[`tomato`,`grass`,`blue`,`ruby`,`orange`,`indigo`,`pink`,`teal`,`purple`,`amber`,`crimson`,`red`,`lime`,`yellow`,`violet`],q={tomato:je.tomato9,grass:Ee.grass9,blue:ke.blue9,ruby:Ce.ruby9,orange:Ne.orange9,indigo:xe.indigo9,pink:Se.pink9,teal:we.teal9,purple:De.purple9,amber:Pe.amber9,crimson:Me.crimson9,red:Fe.red9,lime:Ae.lime9,yellow:Te.yellow9,violet:Oe.violet9};function isDefaultTagColor(e){return typeof e==`string`&&e in q}const Qe={colors:K.reduce((e,t)=>(e[t]={elements:Ue[t],relationships:Ge[t]},e),{}),...Ke};function adjustToneRgb(e,t){return t=Math.max(-1,Math.min(1,t)),e.map(e=>{let n=t>0?e+(255-e)*t:e*(1+t);return Math.round(Math.max(0,Math.min(255,n)))})}function adjustToneHex(e,t){return w(adjustToneRgb(w(e).rgb(),t)).hex()}function isValidColor(e){return w.valid(e)}function computeColorValues(e){invariant(w.valid(e),`Invalid color: ${e}`);let t=e.trim(),n=getColorPalette(t.startsWith(`#`)?t:w(t).hex());return{elements:{fill:n.el_main,stroke:n.el_secondary,hiContrast:n.el_hiContrast,loContrast:n.el_loContrast},relationships:{line:n.rel_secondary,label:n.rel_hiContrast,labelBg:n.rel_main}}}function getColorPalette(e){let t=e,n=w(t).darken(.8).hex(),r=getContrastedColorsAPCA(t),i=r.hiContrast,a=r.loContrast,o=t;return{el_main:t,el_secondary:n,el_hiContrast:i,el_loContrast:a,rel_main:o,rel_secondary:adjustToneHex(t,-.25),rel_hiContrast:getContrastedColorsAPCA(o).hiContrast}}function getContrastedColorsAPCA(e){let t=w(e),n=t.brighten(2),r=t.darken(2),i,a,o,s;do i=n,a=r,n=n.brighten(1),r=r.darken(1),o=w.contrastAPCA(t,n),s=w.contrastAPCA(t,r);while(Math.abs(o)<60&&Math.abs(s)<60&&(!y(n,i)||!y(r,a)));return Math.abs(o)>Math.abs(s)?{hiContrast:w(n.brighten(.4)).hex(),loContrast:n.hex()}:{hiContrast:w(r.darken(.4)).hex(),loContrast:r.hex()}}function computeCompoundColorValues(e,t){let n=t??6,r=w(e.fill),a=w(e.stroke),o=r.luminance()>.8,s=w.scale(o?[r.darken(.02).desaturate(.05),r.darken(.1).desaturate(.1)]:[r.shade(.12,`lch`).desaturate(.05),r.shade(.35,`lch`).desaturate(.4)]).mode(`oklch`).correctLightness().colors(n,null),c=w.scale(o?[a.darken(.04).desaturate(.05),a.darken(.12).desaturate(.1)]:[a.shade(.15,`lch`).desaturate(.08),a.shade(.4,`lch`).desaturate(.4)]).mode(`oklch`).correctLightness().colors(n,null),l=h(v(s,c),i(([t,n])=>({...e,fill:t.hex(),stroke:n.hex()})));return invariant(l.length===n,`Expected ${n} colors, got ${l.length}`),l}const J={color:`primary`,size:`md`,opacity:15,shape:`rectangle`,group:{opacity:15,border:`dashed`},relationship:{color:`gray`,line:`dashed`,arrow:`normal`}},Y=Qe,X={theme:Y,defaults:J};var $e=class LikeC4Styles{config;customCss;theme;defaults;static DEFAULT=new LikeC4Styles(X);static from(e,t){if(!e&&!t)return this.DEFAULT;let{customCss:n,theme:r,defaults:i}={...e},a=T({theme:r},{defaults:{...i}},{theme:{colors:{...t}}},X);return d(n?.content)&&y(a,X)?this.DEFAULT:new LikeC4Styles(a,n)}constructor(e,t){this.config=e,this.customCss=t,this.theme=e.theme,this.defaults=e.defaults}get fingerprint(){return memoizeProp(this,`fingerprint`,()=>objectHash({config:this.config,customCss:this.customCss}))}get elementColors(){return this.theme.colors[this.defaults.color].elements}get relationshipColors(){return this.theme.colors[this.defaults.relationship.color].relationships}get groupColors(){let e=this.defaults.group?.color;if(!e)return this.elementColors;if(!this.isThemeColor(e))throw Error(`Default group color not found in theme: ${e}`);return memoizeProp(this,`defaultGroup`,()=>({...this.elementColors,...this.theme.colors[e].elements}))}isDefaultColor(e){return e===this.defaults.color}colors(e){return this.computeFrom(e??this.defaults.color)}compoundColorsCache=new x.default(e=>new le.default(t=>computeCompoundColorValues(e,t)));colorsForCompounds(e,t){return this.compoundColorsCache.get(e).get(t??6)}fontSize(e){return e??=this.defaults.text??this.defaults.size,this.theme.textSizes[e]}padding(e){return e??=this.defaults.padding??this.defaults.size,this.theme.spacing[e]}iconSize(e){return e??=this.defaults.size,this.theme.iconSizes[e]}isThemeColor(e){return e in this.theme.colors}nodeSizes(e){let t=ensureSizes(e,this.defaults.size);return{sizes:t,values:{sizes:this.theme.sizes[t.size],padding:this.padding(t.padding),textSize:this.fontSize(t.textSize),iconSize:this.iconSize(t.iconSize)}}}computeFrom(e){if(this.isThemeColor(e))return this.theme.colors[e];if(!w.valid(e))throw Error(`Invalid color value: "${e}" (not a theme color and not a valid CSS color)`);return computeColorValues(e)}equals(e){return e===this||this.constructor===e.constructor&&this.fingerprint===e.fingerprint}tagColor(e){return this.isThemeColor(e)?this.theme.colors[e].elements:isDefaultTagColor(e)?this.computeFrom(q[e]).elements:this.computeFrom(e).elements}};function ensureSizes({size:e,padding:t,textSize:n,iconSize:r,...i},a=X.defaults.size){return e??=a,n??=e,t??=e,r??=e,{...i,size:e,padding:t,textSize:n,iconSize:r}}function isTagColorSpecified(e){let t=typeof e==`string`?e:e.color;return t.startsWith(`#`)||t.startsWith(`rgb`)}function isTagEqual(e){return`tag`in e}function isKindEqual(e){return`kind`in e}function isMetadataEqual(e){return`metadata`in e}function isParticipantOperator(e){return`participant`in e}function isNotOperator(e){return`not`in e}function isAndOperator(e){return`and`in e}function isOrOperator(e){return`or`in e}function whereOperatorAsPredicate(e){switch(!0){case isParticipantOperator(e):{let t=e.participant;return participantIs(t,whereOperatorAsPredicate(e.operator))}case isTagEqual(e):{if(a(e.tag)||`eq`in e.tag){let t=a(e.tag)?e.tag:e.tag.eq;return e=>Array.isArray(e.tags)&&e.tags.includes(t)}let t=e.tag.neq;return e=>!Array.isArray(e.tags)||!e.tags.includes(t)}case isKindEqual(e):{if(a(e.kind)||`eq`in e.kind){let t=a(e.kind)?e.kind:e.kind.eq;return e=>e.kind===t}let t=e.kind.neq;return e=>ae(e.kind)||e.kind!==t}case isMetadataEqual(e):{let{key:t,value:n}=e.metadata;if(n===void 0)return e=>e.metadata!=null&&t in e.metadata&&e.metadata[t]!=null;if(a(n)||`eq`in n){let e=a(n)?n:n.eq;return n=>{if(!n.metadata)return!1;let r=n.metadata[t];return Array.isArray(r)?r.includes(e):r===e}}let r=n.neq;return e=>{if(!e.metadata)return!0;let n=e.metadata[t];return n==null?!0:Array.isArray(n)?!n.includes(r):n!==r}}case isNotOperator(e):{let t=whereOperatorAsPredicate(e.not);return r(t)}case isAndOperator(e):{let t=e.and.map(whereOperatorAsPredicate);return se(t)}case isOrOperator(e):{let t=e.or.map(whereOperatorAsPredicate);return oe(t)}default:nonexhaustive(e)}}function participantIs(e,t){return n=>{if(!n.source||!n.target)return!1;switch(e){case`source`:return t(n.source);case`target`:return t(n.target)}}}function isViewRulePredicate(e){return`include`in e||`exclude`in e}function isViewRuleStyle(e){return`targets`in e&&`style`in e}function isComputedView(e){return e._stage===`computed`}function isDiagramView(e){return e._stage===`layouted`}function isElementView(e){return e._type===`element`}function isScopedElementView(e){return isElementView(e)&&f(e.viewOf)}function isExtendsElementView(e){return isElementView(e)&&f(e.extends)}function isDeploymentView(e){return e._type===`deployment`}function isDynamicView(e){return e._type===`dynamic`}function isViewRuleGlobalStyle(e){return`styleId`in e}function isViewRuleGlobalPredicateRef(e){return`predicateId`in e}function isAutoLayoutDirection(e){return e===`TB`||e===`BT`||e===`LR`||e===`RL`}function isViewRuleAutoLayout(e){return`direction`in e}function isSubFlow(e){return typeof e==`object`&&!!e&&isString(e.id)&&isString(e._type)}function asStepPath(e){return isString(e)?e:e.id}const Z={isStepPath,isSubFlow,isTry:e=>isSubFlow(e)&&e._type===`try`,isTryBlock:e=>isSubFlow(e)&&Z.type.isTryBlock(e._type),isAlt:e=>isSubFlow(e)&&e._type===`alt`,isAltBranch:e=>isSubFlow(e)&&Z.type.isAltBranch(e._type),isTryBranch:e=>isSubFlow(e)&&Z.type.isTryBranch(e._type),isAltOrTry:e=>isSubFlow(e)&&Z.type.isAltOrTry(e._type),isAltOrTryBranch:e=>isSubFlow(e)&&Z.type.isAltOrTryBranch(e._type),type:{isAltOrTry:e=>e===`alt`||e===`try`,isAltBranch:e=>isString(e)&&e.startsWith(`alt-`),isTryBlock:e=>e===`try-block`,isTryBranch:e=>isString(e)&&e.startsWith(`try-`),isAltOrTryBranch:e=>isString(e)&&(e.startsWith(`alt-`)||e.startsWith(`try-`))}};function _includesStep(e,t){let n=asStepPath(e);return asStepPath(t).startsWith(n)}function includes(...e){return g(_includesStep,e)}const et=compareNaturalHierarchically();function _isBefore(e,t){let n=asStepPath(e),r=asStepPath(t);return et(n,r)<=0}function isBefore(...e){return g(_isBefore,e)}const Q={unwindTry:e=>{let[t,n=null,r=null]=e.flow;return!r&&n?._type===`try-finally`&&(r=n,n=null),{tryBlock:t,catchBlock:n?._type===`try-catch`?n:null,finallyBlock:r}},firstStep:e=>{if(isStepPath(e))return e;if(l(e)){for(let t of e){if(isStepPath(t))return t;let e=Q.firstStep(t);if(e)return e}return null}return Q.firstStep(e.flow)},hasSteps:e=>!!Q.firstStep(e),steps:e=>_(e.flow,Z.isStepPath),subflows:e=>_(e.flow,Z.isSubFlow),hasSubflows:e=>e.flow.some(Z.isSubFlow),isBefore,includes};function flowAncestors(e){if(!e.includes(`:`))return[];let t=e.split(`.`),n=[],r;for(let e=0;e<t.length-1;e++){let i=t.at(e);r=r?r+`.`+i:i,i.includes(`:`)&&n.push(r)}return n}function parentFlow(e){if(!e)return null;let t=e.lastIndexOf(`.`);if(t===-1)return null;let n=e.slice(0,t);return n.includes(`:`)?n:null}var StopError=class{result;constructor(e){this.result=e}};function walkthroughFlow(...e){if(e.length===1)return t=>walkthroughFlow(t,e[0]);let[t,n]=e;if(!t.flow)throw Error(`Dynamic view ${t.id} does not have a flow`);let r=1,a=new Map(t.edges.map(e=>[e.id,e])),o=new Map(t.nodes.map(e=>[e.id,e])),visitStep=(e,t,i,s)=>{let c=nonNullable(a.get(e)),l=nonNullable(o.get(c.source)),u=nonNullable(o.get(c.target));n.step?.({step:e,level:i,edge:c,source:l,target:u,stepnum:{index:s,global:r++},parent:t,stopAndReturn:t=>{throw new StopError(t??e)}})},callSubflow=e=>{if(!n.subflow)return;if(u(n.subflow))return n.subflow(e);let t=n.subflow[e.type]??n.subflow.default;return s(t)?t:u(t)?t(e):void 0},visitSubflow=(e,t,n,r=0)=>{let a={id:e.id,type:e._type,subflow:e,parent:t,previous:n,level:r,stopAndReturn:t=>{throw new StopError(t??e)}},o=callSubflow(a)??!0;if(o===!1)return!1;let s,c;o===!0?s=e.flow:u(o)?(c=o,s=e.flow):(s=o.next?h(Array.isArray(o.next)?o.next:[o.next],_(f),i(t=>(invariant(e.flow.includes(t),`Next step must be part of the subflow`),t))):e.flow,c=o.onLeave);let l=walk(s,a,r+1);return c?.(l),!0};function walk(e,t,n=0){let r=1,i=null,a=[];for(let o of e){if(Z.isStepPath(o)){a.push(o),i=o,visitStep(o,t,n,r++);continue}visitSubflow(o,t,i,n)&&(a.push(o),i=o)}return{visited:a,lastVisited:i}}try{walk(t.flow,null,0)}catch(e){if(e instanceof StopError)return e.result;throw e}}function onSubflows(e,t){return e=Array.isArray(e)?e:[e],Object.fromEntries(i(e,e=>[e,t]))}walkthroughFlow.onSubflows=onSubflows;function dynamicViewFlow(e){return $.from(e)}var $=class DynamicViewFlow{static cache=new x.default(e=>new DynamicViewFlow(e));static from(e){return this.cache.get(e)}static guards=Z;static helpers=Q;unwindTry=Q.unwindTry;isBefore=Q.isBefore;includes=Q.includes;onSubflows=onSubflows;guards=Z;helpers=Q;view;levelById=new Map;byId=new Map;stepsCount;constructor(e){if(!e.flow)throw Error(`Dynamic view "${e.id}" does not have a flow, probably it is a stale snapshot`);this.view=e;let t=0;walkthroughFlow(e,{step:({step:e,level:n})=>{this.levelById.set(e,n),t++},subflow:({subflow:e,level:t})=>{this.byId.set(e.id,e),this.levelById.set(e.id,t)}}),this.stepsCount=t}get paths(){return Array.from(this.levelById.keys())}level(e){return nonNullable(this.levelById.get(isString(e)?e:e.id))}parent(e){let t=parentFlow(isString(e)?e:e.id);return t?this.lookup(t):void 0}firstStep(e){if(!e)return nonNullable(Q.firstStep(this.view.flow),`No steps found in flow`);let t=asStepPath(e);return this.isStep(t)?t:Q.firstStep(this.lookup(t))}isStep(e){return!this.byId.has(e)&&this.levelById.has(e)}isSubflow(e){return this.byId.has(e)}steps(e){let t=e?this.lookup(asStepPath(e)).flow:this.view.flow;return _(t,isStepPath)}prevAndNext(e,t){invariant(!this.isSubflow(e),`${e} is a subflow, not a step`);let n=null,r=null,i=null;return walkthroughFlow(this.view,{step:({step:t,stopAndReturn:a})=>{i===e&&(r=t,a()),t===e&&(n=i),i=t},subflow:({subflow:e})=>!t?.(e.id)}),{prev:n,next:r}}lookup(e,t){let n=nonNullable(this.byId.get(e),`SubFlow "${e}" not found`);if(t&&n._type!==t)throw Error(`SubFlow "${e}" is of type "${n._type}" (expected "${t}")`);return n}subflows(e){return e?(typeof e==`string`?this.lookup(e):e).flow.filter(Z.isSubFlow):this.view.flow.filter(Z.isSubFlow)}hasSubflows(e){return(typeof e==`string`?this.byId.get(e):e)?.flow.some(Z.isSubFlow)??!1}walk(e){return walkthroughFlow(this.view,e)}stepsBefore(e){return stepsBefore(this.view,e)}stepPathsBefore(e){return stepsBefore(this.view,e).map(asStepPath)}};function stepsBefore(e,t){let n=includes(t),r=[];return walkthroughFlow(e,{step:({step:e,stopAndReturn:n})=>{e===t&&n(),r.push(e)},subflow:({subflow:e,stopAndReturn:i})=>e.id===t?i():(r.push(e),e._type===`alt`?{next:n(e)?c(e.flow,n):p(e.flow,Q.hasSteps)}:e._type!==`try`||{next:n(e)?e.flow:p(e.flow,Z.type.isTryBlock)})}),r}const tt={isStep:e=>!!e&&`source`in e&&`target`in e,isSeries:e=>!!e&&`_type`in e&&e._type===`series`,isParallel:e=>!!e&&`_type`in e&&e._type===`par`,isOpt:e=>!!e&&`_type`in e&&e._type===`opt`,isLoop:e=>!!e&&`_type`in e&&e._type===`loop`,isTry:e=>!!e&&`_type`in e&&e._type===`try`,isAlt:e=>!!e&&`_type`in e&&e._type===`alt`,isBreak:e=>!!e&&`_type`in e&&e._type===`break`};function isViewRuleGroup(e){return`title`in e&&`groupRules`in e&&Array.isArray(e.groupRules)}function isViewRuleRank(e){return`rank`in e&&Array.isArray(e.targets)}const nt=Symbol.for(`text`),rt=Symbol.for(`html`);var it=class RichText{static mdcache=new b.default(500);static txtcache=new b.default(500);static getOrCreateFromText(e){if(e=e.trimEnd(),e===``)return RichText.EMPTY;let t=RichText.txtcache.get(e);return t||(t=new RichText({txt:e}),RichText.txtcache.set(e,t),t)}static getOrCreateFromMarkdown(e){if(e=e.trimEnd(),e===``)return RichText.EMPTY;let t=RichText.mdcache.get(e);return t||(t=new RichText({md:e}),RichText.mdcache.set(e,t),t)}static memoize(e,t,n){return memoizeProp(e,t,()=>RichText.from(n))}static from(e){return e==null||e===RichText.EMPTY?RichText.EMPTY:e instanceof RichText?e:typeof e==`string`?this.getOrCreateFromText(e):`isEmpty`in e&&e.isEmpty?RichText.EMPTY:`md`in e?this.getOrCreateFromMarkdown(e.md):this.getOrCreateFromText(e.txt)}static EMPTY=new class extends RichText{isEmpty=!0;nonEmpty=!1;isMarkdown=!1;$source=null;constructor(){super({txt:``})}get text(){return null}get md(){return null}get html(){return null}};$source;isEmpty;nonEmpty;isMarkdown;constructor(e){this.isMarkdown=!1,typeof e==`string`?(this.$source={txt:e},this.isEmpty=e.trim()===``):(this.$source=e,this.isEmpty=!0,`md`in e?(this.isEmpty=e.md===``,this.isMarkdown=!0):this.isEmpty=e.txt===``),this.nonEmpty=!this.isEmpty}get text(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;return`txt`in e?e.txt:memoizeProp(this,nt,()=>markdownToText(e.md))}get md(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;if(`md`in e)return e.md;if(`txt`in e)return e.txt;nonexhaustive(e)}get html(){if(this.isEmpty||this.$source===null)return``;let e=this.$source;return`txt`in e?e.txt:memoizeProp(this,rt,()=>markdownToHtml(e.md))}equals(e){return this===e?!0:e instanceof RichText?this.isEmpty&&e.isEmpty?!0:this.isEmpty!==e.isEmpty||this.isMarkdown!==e.isMarkdown?!1:this.isMarkdown?this.$source?.md===e.$source?.md:this.$source?.txt===e.$source?.txt:!1}};export{I as $,iflat as $t,isOrOperator as A,invariant as An,markdownToText as At,getContrastedColorsAPCA as B,compareRelations as Bt,isScopedElementView as C,sortParentsFirst as Cn,k as Ct,isKindEqual as D,commonHead as Dn,O as Dt,isAndOperator as E,sortNatural as En,isOnStage as Et,ensureSizes as F,preferDescription as Fn,equals as Ft,Je as G,iunique as Gt,Ye as H,onNextTick as Ht,$e as I,preferSummary as In,hasIntersection as It,isDeployedInstance as J,isome as Jt,qe as K,toArray as Kt,Y as L,exact as Ln,intersection as Lt,isTagEqual as M,nonexhaustive as Mn,stringHash as Mt,whereOperatorAsPredicate as N,convertPoint as Nn,objectHash as Nt,isMetadataEqual as O,Ie as On,vector as Ot,isTagColorSpecified as P,isPoint as Pn,difference as Pt,R as Q,iflatMap as Qt,J as R,T as Rn,symmetricDifference as Rt,isExtendsElementView as S,sortNaturalByFqn as Sn,Be as St,isViewRuleStyle as T,compareNaturalHierarchically as Tn,Ve as Tt,Ze as U,promiseNextTick as Ut,isValidColor as V,delay as Vt,Xe as W,memoizeProp as Wt,z as X,imap as Xt,isDeploymentNode as Y,ireduce as Yt,L as Z,ihead as Zt,isComputedView as _,isDescendantOf as _n,isGlobalFqn as _t,$ as a,hasProp as an,Fqn as at,isDynamicView as b,parentFqn as bn,He as bt,Z as c,isString as cn,MarkdownOrString as ct,stepsBefore as d,commonAncestor as dn,ProjectId as dt,ifirst as en,P as et,walkthroughFlow as f,compareByFqnHierarchically as fn,RelationId as ft,isViewRuleGlobalStyle as g,isAncestor as gn,flattenMarkdownOrString as gt,isViewRuleGlobalPredicateRef as h,hierarchyLevel as hn,ViewId as ht,tt as i,hasChildren as in,EdgeId as it,isParticipantOperator as j,nonNullable as jn,markdownToHtml as jt,isNotOperator as k,E as kn,unsafePartial as kt,Q as l,getOrCreate as ln,NodeId as lt,isViewRuleAutoLayout as m,hierarchyDistance as mn,StepPath as mt,isViewRuleGroup as n,ifilter as nn,N as nt,dynamicViewFlow as o,isAnyOf as on,GlobalFqn as ot,isAutoLayoutDirection as p,compareFqnHierarchically as pn,M as pt,K as q,toSet as qt,isViewRuleRank as r,isIterable as rn,DeploymentFqn as rt,flowAncestors as s,isNonEmptyArray as sn,j as st,it as t,ifind as tn,F as tt,parentFlow as u,ancestorsFqn as un,A as ut,isDeploymentView as v,isSameHierarchy as vn,isGroupElementKind as vt,isViewRulePredicate as w,compareNatural as wn,ze as wt,isElementView as x,sortByFqnHierarchically as xn,splitGlobalFqn as xt,isDiagramView as y,nameFromFqn as yn,isStepPath as yt,computeColorValues as z,union as zt};
@@ -1,7 +1,7 @@
1
1
  import { r as __name } from "../chunks/rolldown-runtime.mjs";
2
2
  import { $ as ComputedNode, C as ComputedView, Di as toComputed, Dn as ViewAutoLayout, E as ParsedView, Gr as Any, Jr as AnyParsed, Si as ViewId, X as ComputedDynamicView, Z as ComputedEdge, aa as _stage, bn as AnyIncludePredicate, ei as ElementId, oa as _type, qi as StepPath, v as ComputedLikeC4ModelData, vi as Unknown, vt as LayoutedDynamicView, wn as BaseViewProperties, x as ParsedLikeC4ModelData, ya as NonEmptyArray, yn as AnyExcludePredicate, zn as ModelExpression } from "../chunks/index.mjs";
3
3
  import { C as ElementModel, T as RelationshipModel, n as LikeC4Model } from "../chunks/LikeC4Model.mjs";
4
- import { U as ViewPredicate } from "../chunks/_types.mjs";
4
+ import { W as ViewPredicate } from "../chunks/_types.mjs";
5
5
  import "../chunks/index5.mjs";
6
6
  import { a as LayoutedProjectNode, i as LayoutedProjectEdge, n as ComputedProjectNode, o as LayoutedProjectsView, r as ComputedProjectsView, t as ComputedProjectEdge } from "../chunks/_types2.mjs";
7
7
  //#region src/compute-view/compute-view.d.ts
@@ -1,2 +1,2 @@
1
- import"../chunks/rolldown-runtime.mjs";import{An as n,Cn as o,Ct as s,In as c,Kt as l,Mt as u,S as d,Xt as f,_n as p,dt as m,gn as h,ht as g,jn as _,nn as v,ot as y,qt as b,sn as x,wt as S,x as C}from"../chunks/types.mjs";import{$ as w,C as T,D as E,F as D,J as O,Q as k,S as A,U as j,Y as M,Z as N,at as P,d as F,et as I,i as L,m as R,r as z,w as B,x as V,y as H}from"../chunks/libs/remeda.mjs";import{t as U}from"../chunks/libs/mnemonist.mjs";import{a as W,c as G,i as K,n as q,o as J,r as Y,s as X,t as Z}from"../chunks/Builder.view-element.mjs";import{t as Q}from"../chunks/libs/graphology.mjs";import{n as $,t as ee}from"../utils/graphology/index.mjs";function r(...n){return P(i,n,a)}const i=(n,o)=>o<0?[...n]:n.slice(o);function a(n){if(n<=0)return w;let o=n;return n=>o>0?(--o,I):{done:!1,hasNext:!0,next:n}}function t(...n){return P(Object.keys,n)}function e(n){let o=!1,s;return()=>(o||=(s=n(),!0),s)}function resolveRulesExtendedViews(n){let o=new Q({type:`directed`}),s=[];for(let c of z(n))o.addNode(c.id,{view:c}),d(c)&&s.push(c);if(s.length===0)return n;for(let n of s){if(!o.hasNode(n.extends)){console.warn(`View "${n.id}" extends from "${n.extends}" which does not exist`);continue}if((0,$.default)(o,n.id,n.extends)){console.warn(`View "${n.id}" extends from "${n.extends}" which creates a cycle`);continue}o.addDirectedEdge(n.id,n.extends)}return(0,ee.topologicalSort)(o).reverse().reduce((n,s)=>{let c=o.getNodeAttribute(s,`view`);if(!d(c))return n[c.id]=c,n;let l=n[c.extends];if(!l||!C(l))return n;let u=L([...l.tags??[],...c.tags??[]]),f=[...l.links??[],...c.links??[]];return n[c.id]={...l,...c,title:c.title??l.title??null,description:c.description??l.description??null,tags:u,links:x(f)?f:null,rules:[...l.rules,...c.rules]},n},{})}function withReadableEdges({edges:n,nodes:o,...s},c=`:`){let l=T(n,n=>[n.id,`${n.source}${c}${n.target}`]);return{...s,edges:n.map(n=>({...n,id:l[n.id]})),nodes:o.map(n=>({...n,inEdges:B(n.inEdges,n=>l[n]),outEdges:B(n.outEdges,n=>l[n])})),nodeIds:o.map(n=>n.id),edgeIds:n.map(n=>l[n.id])}}function viewsWithReadableEdges({views:n,...o}){return{...o,views:A(n,n=>V(withReadableEdges(n),[`nodeIds`,`edgeIds`]))}}const keysCount=n=>t(n).length,nodeId=n=>u(n);function computeProjectsView(o){let l=buildNodesForEachModel(o),key=(n,o)=>`${n}->${o}`,d=new U.default(n=>{let[o,s]=n.split(`->`);return{from:o,to:s,relationships:new Set}}),relationshipsFromTo=(n,o)=>d.get(key(n,o)).relationships,processImportedElement=(o,s)=>{let c=s.projectId;n(c!==o.projectId,`Imported element must have a different project id`);let l=relationshipsFromTo(o.projectId,c);for(let n of s.incoming(`direct`))n.source.projectId===o.projectId&&l.add(n);let u=relationshipsFromTo(c,o.projectId);for(let n of s.outgoing(`direct`))n.target.projectId===o.projectId&&u.add(n)};for(let n of o)if(!D(n.$data.imports))for(let[o,s]of M(n.$data.imports))for(let c of s){let s=y(o,c.id);processImportedElement(n,_(n.findElement(s),`Element ${c.id} from project ${o} not found in model ${n.projectId}`))}let f=Array.from(d.entries()).filter(([n,{relationships:o}])=>o.size>0).map(([o,{from:s,to:l,relationships:d}])=>{let f=[...d];n(N(f,1),`Relationships set must have at least one relationship`);let p={id:u(o),source:nodeId(s),target:nodeId(l),projectId:s,relations:B(f,R(`id`)),label:null,color:`gray`,parent:null,line:`solid`,tags:L(j(f,R(`tags`)))},m=H(f);return m&&(p.label=m.title,p.description=c(m.$relationship)??null,p.technology=m.technology,p.color=m.color,p.line=m.line,m.kind&&(p.kind=m.kind),m.$relationship.navigateTo&&(p.navigateTo=m.$relationship.navigateTo)),p});G(l,f);let p=X({nodes:l,edges:f});return{id:`projects-view`,[S]:`projects`,[s]:`computed`,title:`Projects`,description:{txt:`Overview of all projects and their relationships`},autoLayout:{direction:`TB`},...p}}function buildNodesForEachModel(n){let o=new Map;for(let s of n){let n=m(s.projectId),c={id:nodeId(n),kind:`@project`,parent:null,projectId:n,title:s.project.title??s.project.id,description:{txt:[`Elements: ${keysCount(s.$data.elements)}`,`Relationships: ${keysCount(s.$data.relations)}`,`Views: ${keysCount(s.$data.views)}`].join(`
2
- `)},shape:`rectangle`,children:[],inEdges:[],outEdges:[],color:`primary`,level:0,style:{},tags:[]};o.set(c.id,c)}return o}function treeFromElements(n){let s=o([...n]),c=new Set(s),l=new Map,u=new U.default(()=>null),d=s.reduce((n,o,s,d)=>(l.set(o.id,o),n.set(o.id,k(d,r(s+1),O(p(o)),F((n,s)=>(c.delete(s),n.some(h(s))||(n.push(s),u.set(s.id,o)),n),[]))),n),new U.default(()=>[]));return{sorted:s,byId:n=>_(l.get(n),`Element not found by id: ${n}`),root:c,parent:n=>u.get(typeof n==`string`?n:n.id),children:n=>d.get(typeof n==`string`?n:n.id),flatten:e(()=>new Set([...c,...s.reduce((n,o)=>{let s=d.get(o.id);if(s.length===0){n.push(o);let s=u.get(o.id);return s&&n.push(s),n}return s.length>1&&n.push(...s),n},[])]))}}const finalize=(n,s)=>n.size>2&&s.size!==n.size?new Set(o([...treeFromElements(n).flatten(),...s])):n.size>1?new Set(o([...n])):n;function computeRelationships(n,o,s){let isOther=n=>o.has(n),c=new Set([n]),l={incomers:new Set,subjects:new Set([n]),outgoers:new Set},u=new Set(s.incoming.flatMap(o=>{if(l.subjects.add(o.target),l.incomers.add(o.source),c.add(o.target),o.target!==n){let s=o.target.parent;for(;s&&s!==n;)c.add(s),s=s.parent}let s=o.source,u=[];for(;u.push(s),!(isOther(s)||!s.parent);)s=s.parent;return u})),d=new Set(s.outgoing.flatMap(o=>{if(l.subjects.add(o.source),l.outgoers.add(o.target),c.add(o.source),o.source!==n){let s=o.source.parent;for(;s&&s!==n;)c.add(s),s=s.parent}let s=o.target,u=[];for(;u.push(s),!(isOther(s)||!s.parent);)s=s.parent;return u}));return{incomers:finalize(u,l.incomers),incoming:new Set(s.incoming),subjects:finalize(c,l.subjects),outgoing:new Set(s.outgoing),outgoers:finalize(d,l.outgoers)}}function computeRelationshipsView(o,s,c,l=`global`){let u=c?s.findView(c):null;if(l===`view`)return n(u,`Scope view id is required when scope is "view"`),computeScopedRelationshipsView(o,u,s);let d=s.element(o);return computeRelationships(d,b(d.ascendingSiblings()),{incoming:[...d.incoming()],outgoing:[...d.outgoing()]})}function computeScopedRelationshipsView(n,o,s){let c=s.element(n),u={incoming:l(v(c.incoming(),n=>o.includesRelation(n.id))),outgoing:l(v(c.outgoing(),n=>o.includesRelation(n.id)))},d=p(c);return computeRelationships(c,new Set([...c.ascendingSiblings(),...k(o.elements(),f(n=>n.element),v(n=>n!==c&&d(n)))]),u)}function computeAdhocView(n,o){return{...J(n,{id:g(`adhoc`),_stage:`parsed`,_type:`element`,rules:o,title:null,description:null}),_type:`adhoc`,_stage:`computed`}}var te=class AdhocView{model;static use(n){return new AdhocView(n)}#e=[];constructor(n){this.model=n}Expr;include(...n){return this.#e.push({include:n.map(n=>Z(n))}),this}exclude(...n){return this.#e.push({exclude:n.map(n=>Z(n))}),this}compute(){return computeAdhocView(this.model,this.#e)}};function computeFlow(n){let{view:o,subflows:s=[]}=n;if(!o.flow)throw Error(`view '${o.id}' is outdated and has no flow. Please refresh the view.`);let c=new Set(s),l=new Set,hasRequestedDescendant=n=>{let o=`${n}.`;for(let n of c)if(n.startsWith(o))return!0;return!1},walk=n=>{for(let o of n){if(E(o)){l.add(o);continue}o._type===`alt`||o._type===`try`?walkBranches(o):walk(o.flow)}},walkBranches=n=>{let o=hasRequestedDescendant(n.id);for(let s of n.flow)(!o||c.has(s.id)||hasRequestedDescendant(s.id))&&walk(s.flow)};if(walk(o.flow),l.size===o.edges.length)return{edges:o.edges,nodes:o.nodes,subflows:s};let u=O(o.edges,n=>l.has(n.id)),d=new Set,f=new Set(B(u,n=>(d.add(n.source),d.add(n.target),n.id))),p=new Map(o.nodes.map(n=>[n.id,n])),m=new Set;for(let n of d){let o=n;for(;o&&!m.has(o);)m.add(o),o=p.get(o)?.parent??null}return{subflows:s,nodes:k(o.nodes,O(n=>m.has(n.id)),B(n=>({...n,children:n.children.filter(n=>m.has(n)),inEdges:n.inEdges.filter(n=>f.has(n)),outEdges:n.outEdges.filter(n=>f.has(n))}))),edges:u}}export{te as AdhocView,computeAdhocView,computeFlow,q as computeLikeC4Model,Y as computeParsedModelData,computeProjectsView,computeRelationshipsView,K as computeView,resolveRulesExtendedViews,treeFromElements,W as unsafeComputeView,viewsWithReadableEdges,withReadableEdges};
1
+ import"../chunks/rolldown-runtime.mjs";import{An as n,Cn as o,Ct as s,In as c,Kt as l,Mt as u,S as d,Xt as f,_n as p,dt as m,gn as h,ht as g,jn as _,nn as v,ot as y,qt as b,sn as x,wt as S,x as C}from"../chunks/types.mjs";import{$ as w,C as T,E,H as D,J as O,P as k,Q as A,S as j,X as M,Z as N,b as P,i as F,it as I,p as L,q as R,r as z,u as B,v as V,x as H}from"../chunks/libs/remeda.mjs";import{t as U}from"../chunks/libs/mnemonist.mjs";import{a as W,c as G,i as K,n as q,o as J,r as Y,s as X,t as Z}from"../chunks/Builder.view-element.mjs";import{t as Q}from"../chunks/libs/graphology.mjs";import{n as $,t as ee}from"../utils/graphology/index.mjs";function r(...n){return I(i,n,a)}const i=(n,o)=>o<0?[...n]:n.slice(o);function a(n){if(n<=0)return A;let o=n;return n=>o>0?(--o,w):{done:!1,hasNext:!0,next:n}}function t(...n){return I(Object.keys,n)}function e(n){let o=!1,s;return()=>(o||=(s=n(),!0),s)}function resolveRulesExtendedViews(n){let o=new Q({type:`directed`}),s=[];for(let c of z(n))o.addNode(c.id,{view:c}),d(c)&&s.push(c);if(s.length===0)return n;for(let n of s){if(!o.hasNode(n.extends)){console.warn(`View "${n.id}" extends from "${n.extends}" which does not exist`);continue}if((0,$.default)(o,n.id,n.extends)){console.warn(`View "${n.id}" extends from "${n.extends}" which creates a cycle`);continue}o.addDirectedEdge(n.id,n.extends)}return(0,ee.topologicalSort)(o).reverse().reduce((n,s)=>{let c=o.getNodeAttribute(s,`view`);if(!d(c))return n[c.id]=c,n;let l=n[c.extends];if(!l||!C(l))return n;let u=F([...l.tags??[],...c.tags??[]]),f=[...l.links??[],...c.links??[]],{order:p,...m}=l;return n[c.id]={...m,...c,title:c.title??l.title??null,description:c.description??l.description??null,tags:u,links:x(f)?f:null,rules:[...l.rules,...c.rules]},n},{})}function withReadableEdges({edges:n,nodes:o,...s},c=`:`){let l=j(n,n=>[n.id,`${n.source}${c}${n.target}`]);return{...s,edges:n.map(n=>({...n,id:l[n.id]})),nodes:o.map(n=>({...n,inEdges:T(n.inEdges,n=>l[n]),outEdges:T(n.outEdges,n=>l[n])})),nodeIds:o.map(n=>n.id),edgeIds:n.map(n=>l[n.id])}}function viewsWithReadableEdges({views:n,...o}){return{...o,views:H(n,n=>P(withReadableEdges(n),[`nodeIds`,`edgeIds`]))}}const keysCount=n=>t(n).length,nodeId=n=>u(n);function computeProjectsView(o){let l=buildNodesForEachModel(o),key=(n,o)=>`${n}->${o}`,d=new U.default(n=>{let[o,s]=n.split(`->`);return{from:o,to:s,relationships:new Set}}),relationshipsFromTo=(n,o)=>d.get(key(n,o)).relationships,processImportedElement=(o,s)=>{let c=s.projectId;n(c!==o.projectId,`Imported element must have a different project id`);let l=relationshipsFromTo(o.projectId,c);for(let n of s.incoming(`direct`))n.source.projectId===o.projectId&&l.add(n);let u=relationshipsFromTo(c,o.projectId);for(let n of s.outgoing(`direct`))n.target.projectId===o.projectId&&u.add(n)};for(let n of o)if(!k(n.$data.imports))for(let[o,s]of O(n.$data.imports))for(let c of s){let s=y(o,c.id);processImportedElement(n,_(n.findElement(s),`Element ${c.id} from project ${o} not found in model ${n.projectId}`))}let f=Array.from(d.entries()).filter(([n,{relationships:o}])=>o.size>0).map(([o,{from:s,to:l,relationships:d}])=>{let f=[...d];n(M(f,1),`Relationships set must have at least one relationship`);let p={id:u(o),source:nodeId(s),target:nodeId(l),projectId:s,relations:T(f,L(`id`)),label:null,color:`gray`,parent:null,line:`solid`,tags:F(D(f,L(`tags`)))},m=V(f);return m&&(p.label=m.title,p.description=c(m.$relationship)??null,p.technology=m.technology,p.color=m.color,p.line=m.line,m.kind&&(p.kind=m.kind),m.$relationship.navigateTo&&(p.navigateTo=m.$relationship.navigateTo)),p});G(l,f);let p=X({nodes:l,edges:f});return{id:`projects-view`,[S]:`projects`,[s]:`computed`,title:`Projects`,description:{txt:`Overview of all projects and their relationships`},autoLayout:{direction:`TB`},...p}}function buildNodesForEachModel(n){let o=new Map;for(let s of n){let n=m(s.projectId),c={id:nodeId(n),kind:`@project`,parent:null,projectId:n,title:s.project.title??s.project.id,description:{txt:[`Elements: ${keysCount(s.$data.elements)}`,`Relationships: ${keysCount(s.$data.relations)}`,`Views: ${keysCount(s.$data.views)}`].join(`
2
+ `)},shape:`rectangle`,children:[],inEdges:[],outEdges:[],color:`primary`,level:0,style:{},tags:[]};o.set(c.id,c)}return o}function treeFromElements(n){let s=o([...n]),c=new Set(s),l=new Map,u=new U.default(()=>null),d=s.reduce((n,o,s,d)=>(l.set(o.id,o),n.set(o.id,N(d,r(s+1),R(p(o)),B((n,s)=>(c.delete(s),n.some(h(s))||(n.push(s),u.set(s.id,o)),n),[]))),n),new U.default(()=>[]));return{sorted:s,byId:n=>_(l.get(n),`Element not found by id: ${n}`),root:c,parent:n=>u.get(typeof n==`string`?n:n.id),children:n=>d.get(typeof n==`string`?n:n.id),flatten:e(()=>new Set([...c,...s.reduce((n,o)=>{let s=d.get(o.id);if(s.length===0){n.push(o);let s=u.get(o.id);return s&&n.push(s),n}return s.length>1&&n.push(...s),n},[])]))}}const finalize=(n,s)=>n.size>2&&s.size!==n.size?new Set(o([...treeFromElements(n).flatten(),...s])):n.size>1?new Set(o([...n])):n;function computeRelationships(n,o,s){let isOther=n=>o.has(n),c=new Set([n]),l={incomers:new Set,subjects:new Set([n]),outgoers:new Set},u=new Set(s.incoming.flatMap(o=>{if(l.subjects.add(o.target),l.incomers.add(o.source),c.add(o.target),o.target!==n){let s=o.target.parent;for(;s&&s!==n;)c.add(s),s=s.parent}let s=o.source,u=[];for(;u.push(s),!(isOther(s)||!s.parent);)s=s.parent;return u})),d=new Set(s.outgoing.flatMap(o=>{if(l.subjects.add(o.source),l.outgoers.add(o.target),c.add(o.source),o.source!==n){let s=o.source.parent;for(;s&&s!==n;)c.add(s),s=s.parent}let s=o.target,u=[];for(;u.push(s),!(isOther(s)||!s.parent);)s=s.parent;return u}));return{incomers:finalize(u,l.incomers),incoming:new Set(s.incoming),subjects:finalize(c,l.subjects),outgoing:new Set(s.outgoing),outgoers:finalize(d,l.outgoers)}}function computeRelationshipsView(o,s,c,l=`global`){let u=c?s.findView(c):null;if(l===`view`)return n(u,`Scope view id is required when scope is "view"`),computeScopedRelationshipsView(o,u,s);let d=s.element(o);return computeRelationships(d,b(d.ascendingSiblings()),{incoming:[...d.incoming()],outgoing:[...d.outgoing()]})}function computeScopedRelationshipsView(n,o,s){let c=s.element(n),u={incoming:l(v(c.incoming(),n=>o.includesRelation(n.id))),outgoing:l(v(c.outgoing(),n=>o.includesRelation(n.id)))},d=p(c);return computeRelationships(c,new Set([...c.ascendingSiblings(),...N(o.elements(),f(n=>n.element),v(n=>n!==c&&d(n)))]),u)}function computeAdhocView(n,o){let s={id:g(`adhoc`),_stage:`parsed`,_type:`element`,rules:o,title:null,description:null};return{...J(n,s),_type:`adhoc`,_stage:`computed`}}var te=class AdhocView{model;static use(n){return new AdhocView(n)}#e=[];constructor(n){this.model=n}Expr;include(...n){return this.#e.push({include:n.map(n=>Z(n))}),this}exclude(...n){return this.#e.push({exclude:n.map(n=>Z(n))}),this}compute(){return computeAdhocView(this.model,this.#e)}};function computeFlow(n){let{view:o,subflows:s=[]}=n;if(!o.flow)throw Error(`view '${o.id}' is outdated and has no flow. Please refresh the view.`);let c=new Set(s),l=new Set,hasRequestedDescendant=n=>{let o=`${n}.`;for(let n of c)if(n.startsWith(o))return!0;return!1},walk=n=>{for(let o of n){if(E(o)){l.add(o);continue}o._type===`alt`||o._type===`try`?walkBranches(o):walk(o.flow)}},walkBranches=n=>{let o=hasRequestedDescendant(n.id);for(let s of n.flow)(!o||c.has(s.id)||hasRequestedDescendant(s.id))&&walk(s.flow)};if(walk(o.flow),l.size===o.edges.length)return{edges:o.edges,nodes:o.nodes,subflows:s};let u=R(o.edges,n=>l.has(n.id)),d=new Set,f=new Set(T(u,n=>(d.add(n.source),d.add(n.target),n.id))),p=new Map(o.nodes.map(n=>[n.id,n])),m=new Set;for(let n of d){let o=n;for(;o&&!m.has(o);)m.add(o),o=p.get(o)?.parent??null}return{subflows:s,nodes:N(o.nodes,R(n=>m.has(n.id)),T(n=>({...n,children:n.children.filter(n=>m.has(n)),inEdges:n.inEdges.filter(n=>f.has(n)),outEdges:n.outEdges.filter(n=>f.has(n))}))),edges:u}}export{te as AdhocView,computeAdhocView,computeFlow,q as computeLikeC4Model,Y as computeParsedModelData,computeProjectsView,computeRelationshipsView,K as computeView,resolveRulesExtendedViews,treeFromElements,W as unsafeComputeView,viewsWithReadableEdges,withReadableEdges};