@likec4/core 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
- import { u, e, n as nonNullable, D as DefaultElementShape, a as DefaultThemeColor } from './shared/core.DeifT5lC.mjs';
2
- export { A as AsFqn, B as BorderStyles, J as DefaultArrowType, I as DefaultLineStyle, K as DefaultRelationshipColor, E as ElementShapes, c as Expr, V as StepEdgeId, X as extractStep, $ as getBBoxCenter, Y as getParallelStepsPrefix, i as invariant, F as isAndOperator, Z as isComputedDynamicView, _ as isComputedElementView, g as isCustomElement, w as isCustomRelationExpr, R as isDynamicView, P as isDynamicViewIncludeRule, Q as isDynamicViewParallelSteps, l as isElement, j as isElementKindExpr, o as isElementPredicateExpr, d as isElementRef, k as isElementTagExpr, S as isElementView, m as isElementWhere, f as isExpandedElementExpr, T as isExtendsElementView, q as isInOut, r as isIncoming, z as isKindEqual, C as isNotOperator, G as isOrOperator, s as isOutgoing, p as isRelation, t as isRelationExpression, x as isRelationPredicateExpr, v as isRelationWhere, U as isScopedElementView, W as isStepEdgeId, y as isTagEqual, L as isThemeColor, O as isViewRuleAutoLayout, M as isViewRulePredicate, N as isViewRuleStyle, h as isWildcard, b as nonexhaustive, H as whereOperatorAsPredicate } from './shared/core.DeifT5lC.mjs';
1
+ import { u, e, n as nonNullable, D as DefaultRelationshipColor, a as DefaultElementShape, b as DefaultThemeColor } from './shared/core.CUlHblBQ.mjs';
2
+ export { A as AsFqn, B as BorderStyles, K as DefaultArrowType, J as DefaultLineStyle, E as ElementShapes, c as Expr, V as StepEdgeId, X as extractStep, $ as getBBoxCenter, Y as getParallelStepsPrefix, i as invariant, G as isAndOperator, Z as isComputedDynamicView, _ as isComputedElementView, h as isCustomElement, x as isCustomRelationExpr, R as isDynamicView, P as isDynamicViewIncludeRule, Q as isDynamicViewParallelSteps, m as isElement, k as isElementKindExpr, p as isElementPredicateExpr, f as isElementRef, l as isElementTagExpr, S as isElementView, o as isElementWhere, g as isExpandedElementExpr, T as isExtendsElementView, r as isInOut, s as isIncoming, C as isKindEqual, F as isNotOperator, H as isOrOperator, t as isOutgoing, q as isRelation, v as isRelationExpression, y as isRelationPredicateExpr, w as isRelationWhere, U as isScopedElementView, W as isStepEdgeId, z as isTagEqual, L as isThemeColor, O as isViewRuleAutoLayout, M as isViewRulePredicate, N as isViewRuleStyle, j as isWildcard, d as nonexhaustive, I as whereOperatorAsPredicate } from './shared/core.CUlHblBQ.mjs';
3
+
4
+ const { min: min$4, max: max$4 } = Math;
3
5
 
4
6
  const limit = (x, low = 0, high = 1) => {
5
- return min$3(max$3(low, x), high);
7
+ return min$4(max$4(low, x), high);
6
8
  };
7
9
 
8
10
  const clip_rgb = (rgb) => {
@@ -123,7 +125,7 @@ class Color {
123
125
  }
124
126
 
125
127
  // this gets updated automatically
126
- const version = '3.0.0';
128
+ const version = '3.1.1';
127
129
 
128
130
  const chroma = (...args) => {
129
131
  return new Color(...args);
@@ -2604,6 +2606,72 @@ const contrast = (a, b) => {
2604
2606
  return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05);
2605
2607
  };
2606
2608
 
2609
+ /**
2610
+ * @license
2611
+ *
2612
+ * The APCA contrast prediction algorithm is based of the formulas published
2613
+ * in the APCA-1.0.98G specification by Myndex. The specification is available at:
2614
+ * https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg
2615
+ *
2616
+ * Note that the APCA implementation is still beta, so please update to
2617
+ * future versions of chroma.js when they become available.
2618
+ *
2619
+ * You can read more about the APCA Readability Criterion at
2620
+ * https://readtech.org/ARC/
2621
+ */
2622
+
2623
+ // constants
2624
+ const W_offset = 0.027;
2625
+ const P_in = 0.0005;
2626
+ const P_out = 0.1;
2627
+ const R_scale = 1.14;
2628
+ const B_threshold = 0.022;
2629
+ const B_exp = 1.414;
2630
+
2631
+ const contrastAPCA = (text, bg) => {
2632
+ // parse input colors
2633
+ text = new Color(text);
2634
+ bg = new Color(bg);
2635
+ // if text color has alpha, blend against background
2636
+ if (text.alpha() < 1) {
2637
+ text = mix(bg, text, text.alpha(), 'rgb');
2638
+ }
2639
+ const l_text = lum(...text.rgb());
2640
+ const l_bg = lum(...bg.rgb());
2641
+
2642
+ // soft clamp black levels
2643
+ const Y_text =
2644
+ l_text >= B_threshold
2645
+ ? l_text
2646
+ : l_text + Math.pow(B_threshold - l_text, B_exp);
2647
+ const Y_bg =
2648
+ l_bg >= B_threshold ? l_bg : l_bg + Math.pow(B_threshold - l_bg, B_exp);
2649
+
2650
+ // normal polarity (dark text on light background)
2651
+ const S_norm = Math.pow(Y_bg, 0.56) - Math.pow(Y_text, 0.57);
2652
+ // reverse polarity (light text on dark background)
2653
+ const S_rev = Math.pow(Y_bg, 0.65) - Math.pow(Y_text, 0.62);
2654
+ // clamp noise then scale
2655
+ const C =
2656
+ Math.abs(Y_bg - Y_text) < P_in
2657
+ ? 0
2658
+ : Y_text < Y_bg
2659
+ ? S_norm * R_scale
2660
+ : S_rev * R_scale;
2661
+ // clamp minimum contrast then offset
2662
+ const S_apc = Math.abs(C) < P_out ? 0 : C > 0 ? C - W_offset : C + W_offset;
2663
+ // scale to 100
2664
+ return S_apc * 100;
2665
+ };
2666
+
2667
+ function lum(r, g, b) {
2668
+ return (
2669
+ 0.2126729 * Math.pow(r / 255, 2.4) +
2670
+ 0.7151522 * Math.pow(g / 255, 2.4) +
2671
+ 0.072175 * Math.pow(b / 255, 2.4)
2672
+ );
2673
+ }
2674
+
2607
2675
  const { sqrt, pow, min, max: max$1, atan2, abs, cos, sin, exp, PI } = Math;
2608
2676
 
2609
2677
  function deltaE (a, b, Kl = 1, Kc = 1, Kh = 1) {
@@ -2766,10 +2834,24 @@ const colorbrewer = {
2766
2834
  Pastel1: ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec', '#f2f2f2']
2767
2835
  };
2768
2836
 
2769
- // add lowercase aliases for case-insensitive matches
2770
- for (let key of Object.keys(colorbrewer)) {
2771
- colorbrewer[key.toLowerCase()] = colorbrewer[key];
2772
- }
2837
+ const colorbrewerTypes = Object.keys(colorbrewer);
2838
+ const typeMap = new Map(colorbrewerTypes.map((key) => [key.toLowerCase(), key]));
2839
+
2840
+ // use Proxy to allow case-insensitive access to palettes
2841
+ const colorbrewerProxy =
2842
+ typeof Proxy === 'function'
2843
+ ? new Proxy(colorbrewer, {
2844
+ get(target, prop) {
2845
+ const lower = prop.toLowerCase();
2846
+ if (typeMap.has(lower)) {
2847
+ return target[typeMap.get(lower)];
2848
+ }
2849
+ },
2850
+ getOwnPropertyNames() {
2851
+ return Object.getOwnPropertyNames(colorbrewerTypes);
2852
+ }
2853
+ })
2854
+ : colorbrewer;
2773
2855
 
2774
2856
  const cmyk2rgb = (...args) => {
2775
2857
  args = unpack(args, 'cmyk');
@@ -2874,7 +2956,7 @@ const lch2css = (...args) => {
2874
2956
  let mode = last(args) || 'lab';
2875
2957
  lcha[0] = rnd2(lcha[0]) + '%';
2876
2958
  lcha[1] = rnd2(lcha[1]);
2877
- lcha[2] = rnd2(lcha[2]) + 'deg'; // add deg unit to hue
2959
+ lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
2878
2960
  if (mode === 'lcha' || (lcha.length > 3 && lcha[3] < 1)) {
2879
2961
  lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
2880
2962
  } else {
@@ -2883,7 +2965,7 @@ const lch2css = (...args) => {
2883
2965
  return `lch(${lcha.join(' ')})`;
2884
2966
  };
2885
2967
 
2886
- const oklab2css$1 = (...args) => {
2968
+ const oklab2css = (...args) => {
2887
2969
  const laba = unpack(args, 'lab');
2888
2970
  laba[0] = rnd2(laba[0] * 100) + '%';
2889
2971
  laba[1] = rnd3(laba[1]);
@@ -2903,17 +2985,17 @@ const rgb2oklch = (...args) => {
2903
2985
  return [L, c, h, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
2904
2986
  };
2905
2987
 
2906
- const oklab2css = (...args) => {
2907
- const laba = unpack(args, 'lab');
2908
- laba[0] = rnd2(laba[0] * 100) + '%';
2909
- laba[1] = rnd3(laba[1]);
2910
- laba[2] = rnd2(laba[2]) + 'deg';
2911
- if (laba.length > 3 && laba[3] < 1) {
2912
- laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
2988
+ const oklch2css = (...args) => {
2989
+ const lcha = unpack(args, 'lch');
2990
+ lcha[0] = rnd2(lcha[0] * 100) + '%';
2991
+ lcha[1] = rnd3(lcha[1]);
2992
+ lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
2993
+ if (lcha.length > 3 && lcha[3] < 1) {
2994
+ lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
2913
2995
  } else {
2914
- laba.length = 3;
2996
+ lcha.length = 3;
2915
2997
  }
2916
- return `oklch(${laba.join(' ')})`;
2998
+ return `oklch(${lcha.join(' ')})`;
2917
2999
  };
2918
3000
 
2919
3001
  const { round: round$2 } = Math;
@@ -2949,10 +3031,10 @@ const rgb2css = (...args) => {
2949
3031
  return cssColor;
2950
3032
  }
2951
3033
  if (mode.substr(0, 5) === 'oklab') {
2952
- return oklab2css$1(rgb2oklab(rgba));
3034
+ return oklab2css(rgb2oklab(rgba));
2953
3035
  }
2954
3036
  if (mode.substr(0, 5) === 'oklch') {
2955
- return oklab2css(rgb2oklch(rgba));
3037
+ return oklch2css(rgb2oklch(rgba));
2956
3038
  }
2957
3039
  rgba[0] = round$2(rgba[0]);
2958
3040
  rgba[1] = round$2(rgba[1]);
@@ -2972,42 +3054,75 @@ const oklch2rgb = (...args) => {
2972
3054
  return [r, g, b, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
2973
3055
  };
2974
3056
 
2975
- const RE_RGB = /^rgb\(\s*(-?\d+) \s*(-?\d+)\s* \s*(-?\d+)\s*\)$/;
2976
- const RE_RGB_LEGACY = /^rgb\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*\)$/;
2977
-
2978
- const RE_RGBA =
2979
- /^rgba?\(\s*(-?\d+) \s*(-?\d+)\s* \s*(-?\d+)\s*\/\s*([01]|[01]?\.\d+)\)$/;
2980
- const RE_RGBA_LEGACY =
2981
- /^rgba\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*([01]|[01]?\.\d+)\)$/;
2982
-
2983
- const RE_RGB_PCT =
2984
- /^rgb\(\s*(-?\d+(?:\.\d+)?)% \s*(-?\d+(?:\.\d+)?)%\s* \s*(-?\d+(?:\.\d+)?)%\s*\)$/;
2985
- const RE_RGB_PCT_LEGACY =
2986
- /^rgb\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/;
2987
-
2988
- const RE_RGBA_PCT =
2989
- /^rgba?\(\s*(-?\d+(?:\.\d+)?)% \s*(-?\d+(?:\.\d+)?)%\s* \s*(-?\d+(?:\.\d+)?)%\s*\/\s*([01]|[01]?\.\d+)\)$/;
2990
- const RE_RGBA_PCT_LEGACY =
2991
- /^rgba\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/;
2992
-
2993
- const RE_HSL =
2994
- /^hsl\(\s*(-?\d+(?:\.\d+)?)deg \s*(-?\d+(?:\.\d+)?)%\s* \s*(-?\d+(?:\.\d+)?)%\s*\)$/;
2995
- const RE_HSL_LEGACY =
2996
- /^hsl\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/;
3057
+ const INT_OR_PCT = /((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source;
3058
+ const FLOAT_OR_PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source;
3059
+ const PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source;
3060
+ const RE_S = /\s*/.source;
3061
+ const SEP = /\s+/.source;
3062
+ const COMMA = /\s*,\s*/.source;
3063
+ const ANLGE = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source;
3064
+ const ALPHA = /\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source;
3065
+
3066
+ // e.g. rgb(250 20 0), rgb(100% 50% 20%), rgb(100% 50% 20% / 0.5)
3067
+ const RE_RGB = new RegExp(
3068
+ '^rgba?\\(' +
3069
+ RE_S +
3070
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(SEP) +
3071
+ ALPHA +
3072
+ '\\)$'
3073
+ );
3074
+ const RE_RGB_LEGACY = new RegExp(
3075
+ '^rgb\\(' +
3076
+ RE_S +
3077
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(COMMA) +
3078
+ RE_S +
3079
+ '\\)$'
3080
+ );
3081
+ const RE_RGBA_LEGACY = new RegExp(
3082
+ '^rgba\\(' +
3083
+ RE_S +
3084
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT, FLOAT_OR_PCT].join(COMMA) +
3085
+ RE_S +
3086
+ '\\)$'
3087
+ );
2997
3088
 
2998
- const RE_HSLA =
2999
- /^hsla?\(\s*(-?\d+(?:\.\d+)?)deg \s*(-?\d+(?:\.\d+)?)%\s* \s*(-?\d+(?:\.\d+)?)%\s*\/\s*([01]|[01]?\.\d+)\)$/;
3089
+ const RE_HSL = new RegExp(
3090
+ '^hsla?\\(' + RE_S + [ANLGE, PCT, PCT].join(SEP) + ALPHA + '\\)$'
3091
+ );
3092
+ const RE_HSL_LEGACY = new RegExp(
3093
+ '^hsl?\\(' + RE_S + [ANLGE, PCT, PCT].join(COMMA) + RE_S + '\\)$'
3094
+ );
3000
3095
  const RE_HSLA_LEGACY =
3001
3096
  /^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/;
3002
3097
 
3003
- const RE_LAB =
3004
- /^lab\(\s*(-?\d+(?:\.\d+)?%?) \s*(-?\d+(?:\.\d+)?%?) \s*(-?\d+(?:\.\d+)?%?)\s*(?:\/\s*(\d+(?:\.\d+)?))?\)?$/;
3005
- const RE_LCH =
3006
- /^lch\(\s*(-?\d+(?:\.\d+)?%?) \s*((?:-?\d+(?:\.\d+)?%?)|none) \s*(-?\d+(?:\.\d+)?(?:deg)?|none)\s*(?:\/\s*(\d+(?:\.\d+)?))?\)?$/;
3007
- const RE_OKLAB =
3008
- /^oklab\(\s*(-?\d+(?:\.\d+)?%?) \s*(-?\d+(?:\.\d+)?%?) \s*(-?\d+(?:\.\d+)?%?)\s*(?:\/\s*(\d+(?:\.\d+)?))?\)?$/;
3009
- const RE_OKLCH =
3010
- /^oklch\(\s*(-?\d+(?:\.\d+)?%?) \s*(?:(-?\d+(?:\.\d+)?%?)|none) \s*(-?\d+(?:\.\d+)?(?:deg)?|none)\s*(?:\/\s*(\d+(?:\.\d+)?))?\)?$/;
3098
+ const RE_LAB = new RegExp(
3099
+ '^lab\\(' +
3100
+ RE_S +
3101
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
3102
+ ALPHA +
3103
+ '\\)$'
3104
+ );
3105
+ const RE_LCH = new RegExp(
3106
+ '^lch\\(' +
3107
+ RE_S +
3108
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
3109
+ ALPHA +
3110
+ '\\)$'
3111
+ );
3112
+ const RE_OKLAB = new RegExp(
3113
+ '^oklab\\(' +
3114
+ RE_S +
3115
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
3116
+ ALPHA +
3117
+ '\\)$'
3118
+ );
3119
+ const RE_OKLCH = new RegExp(
3120
+ '^oklch\\(' +
3121
+ RE_S +
3122
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
3123
+ ALPHA +
3124
+ '\\)$'
3125
+ );
3011
3126
 
3012
3127
  const { round: round$1 } = Math;
3013
3128
 
@@ -3034,6 +3149,11 @@ const noneToValue = (v, noneValue) => {
3034
3149
 
3035
3150
  const css2rgb = (css) => {
3036
3151
  css = css.toLowerCase().trim();
3152
+
3153
+ if (css === 'transparent') {
3154
+ return [0, 0, 0, 0];
3155
+ }
3156
+
3037
3157
  let m;
3038
3158
 
3039
3159
  if (input.format.named) {
@@ -3045,58 +3165,39 @@ const css2rgb = (css) => {
3045
3165
 
3046
3166
  // rgb(250 20 0) or rgb(250,20,0)
3047
3167
  if ((m = css.match(RE_RGB)) || (m = css.match(RE_RGB_LEGACY))) {
3048
- const rgb = m.slice(1, 4);
3168
+ let rgb = m.slice(1, 4);
3049
3169
  for (let i = 0; i < 3; i++) {
3050
- rgb[i] = +rgb[i];
3170
+ rgb[i] = +percentToAbsolute(noneToValue(rgb[i], 0), 0, 255);
3051
3171
  }
3052
- rgb[3] = 1; // default alpha
3172
+ rgb = roundRGB(rgb);
3173
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3174
+ rgb[3] = alpha; // default alpha
3053
3175
  return rgb;
3054
3176
  }
3055
3177
 
3056
3178
  // rgba(250,20,0,0.4)
3057
- if ((m = css.match(RE_RGBA)) || (m = css.match(RE_RGBA_LEGACY))) {
3179
+ if ((m = css.match(RE_RGBA_LEGACY))) {
3058
3180
  const rgb = m.slice(1, 5);
3059
3181
  for (let i = 0; i < 4; i++) {
3060
- rgb[i] = +rgb[i];
3061
- }
3062
- return rgb;
3063
- }
3064
-
3065
- // rgb(100%,0%,0%)
3066
- if ((m = css.match(RE_RGB_PCT)) || (m = css.match(RE_RGB_PCT_LEGACY))) {
3067
- const rgb = m.slice(1, 4);
3068
- for (let i = 0; i < 3; i++) {
3069
- rgb[i] = round$1(rgb[i] * 2.55);
3070
- }
3071
- rgb[3] = 1; // default alpha
3072
- return rgb;
3073
- }
3074
-
3075
- // rgba(100%,0%,0%,0.4)
3076
- if ((m = css.match(RE_RGBA_PCT)) || (m = css.match(RE_RGBA_PCT_LEGACY))) {
3077
- const rgb = m.slice(1, 5);
3078
- for (let i = 0; i < 3; i++) {
3079
- rgb[i] = round$1(rgb[i] * 2.55);
3182
+ rgb[i] = +percentToAbsolute(rgb[i], 0, 255);
3080
3183
  }
3081
- rgb[3] = +rgb[3];
3082
3184
  return rgb;
3083
3185
  }
3084
3186
 
3085
3187
  // hsl(0,100%,50%)
3086
3188
  if ((m = css.match(RE_HSL)) || (m = css.match(RE_HSL_LEGACY))) {
3087
3189
  const hsl = m.slice(1, 4);
3088
- hsl[1] *= 0.01;
3089
- hsl[2] *= 0.01;
3090
- const rgb = hsl2rgb(hsl);
3091
- for (let i = 0; i < 3; i++) {
3092
- rgb[i] = round$1(rgb[i]);
3093
- }
3094
- rgb[3] = 1;
3190
+ hsl[0] = +noneToValue(hsl[0].replace('deg', ''), 0);
3191
+ hsl[1] = +percentToAbsolute(noneToValue(hsl[1], 0), 0, 100) * 0.01;
3192
+ hsl[2] = +percentToAbsolute(noneToValue(hsl[2], 0), 0, 100) * 0.01;
3193
+ const rgb = roundRGB(hsl2rgb(hsl));
3194
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3195
+ rgb[3] = alpha;
3095
3196
  return rgb;
3096
3197
  }
3097
3198
 
3098
3199
  // hsla(0,100%,50%,0.5)
3099
- if ((m = css.match(RE_HSLA)) || (m = css.match(RE_HSLA_LEGACY))) {
3200
+ if ((m = css.match(RE_HSLA_LEGACY))) {
3100
3201
  const hsl = m.slice(1, 4);
3101
3202
  hsl[1] *= 0.01;
3102
3203
  hsl[2] *= 0.01;
@@ -3110,16 +3211,17 @@ const css2rgb = (css) => {
3110
3211
 
3111
3212
  if ((m = css.match(RE_LAB))) {
3112
3213
  const lab = m.slice(1, 4);
3113
- lab[0] = percentToAbsolute(lab[0], 0, 100);
3114
- lab[1] = percentToAbsolute(lab[1], -125, 125, true);
3115
- lab[2] = percentToAbsolute(lab[2], -125, 125, true);
3214
+ lab[0] = percentToAbsolute(noneToValue(lab[0], 0), 0, 100);
3215
+ lab[1] = percentToAbsolute(noneToValue(lab[1], 0), -125, 125, true);
3216
+ lab[2] = percentToAbsolute(noneToValue(lab[2], 0), -125, 125, true);
3116
3217
  // convert to D50 Lab whitepoint
3117
3218
  const wp = getLabWhitePoint();
3118
3219
  setLabWhitePoint('d50');
3119
3220
  const rgb = roundRGB(lab2rgb(lab));
3120
3221
  // convert back to original Lab whitepoint
3121
3222
  setLabWhitePoint(wp);
3122
- rgb[3] = m[4] !== undefined ? +m[4] : 1;
3223
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3224
+ rgb[3] = alpha;
3123
3225
  return rgb;
3124
3226
  }
3125
3227
 
@@ -3134,27 +3236,30 @@ const css2rgb = (css) => {
3134
3236
  const rgb = roundRGB(lch2rgb(lch));
3135
3237
  // convert back to original Lab whitepoint
3136
3238
  setLabWhitePoint(wp);
3137
- rgb[3] = m[4] !== undefined ? +m[4] : 1;
3239
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3240
+ rgb[3] = alpha;
3138
3241
  return rgb;
3139
3242
  }
3140
3243
 
3141
3244
  if ((m = css.match(RE_OKLAB))) {
3142
3245
  const oklab = m.slice(1, 4);
3143
- oklab[0] = percentToAbsolute(oklab[0], 0, 1);
3144
- oklab[1] = percentToAbsolute(oklab[1], -0.4, 0.4, true);
3145
- oklab[2] = percentToAbsolute(oklab[2], -0.4, 0.4, true);
3246
+ oklab[0] = percentToAbsolute(noneToValue(oklab[0], 0), 0, 1);
3247
+ oklab[1] = percentToAbsolute(noneToValue(oklab[1], 0), -0.4, 0.4, true);
3248
+ oklab[2] = percentToAbsolute(noneToValue(oklab[2], 0), -0.4, 0.4, true);
3146
3249
  const rgb = roundRGB(oklab2rgb(oklab));
3147
- rgb[3] = m[4] !== undefined ? +m[4] : 1;
3250
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3251
+ rgb[3] = alpha;
3148
3252
  return rgb;
3149
3253
  }
3150
3254
 
3151
3255
  if ((m = css.match(RE_OKLCH))) {
3152
3256
  const oklch = m.slice(1, 4);
3153
- oklch[0] = percentToAbsolute(oklch[0], 0, 1);
3257
+ oklch[0] = percentToAbsolute(noneToValue(oklch[0], 0), 0, 1);
3154
3258
  oklch[1] = percentToAbsolute(noneToValue(oklch[1], 0), 0, 0.4, false);
3155
3259
  oklch[2] = +noneToValue(oklch[2].replace('deg', ''), 0);
3156
3260
  const rgb = roundRGB(oklch2rgb(oklch));
3157
- rgb[3] = m[4] !== undefined ? +m[4] : 1;
3261
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3262
+ rgb[3] = alpha;
3158
3263
  return rgb;
3159
3264
  }
3160
3265
  };
@@ -3163,11 +3268,7 @@ css2rgb.test = (s) => {
3163
3268
  return (
3164
3269
  // modern
3165
3270
  RE_RGB.test(s) ||
3166
- RE_RGBA.test(s) ||
3167
- RE_RGB_PCT.test(s) ||
3168
- RE_RGBA_PCT.test(s) ||
3169
3271
  RE_HSL.test(s) ||
3170
- RE_HSLA.test(s) ||
3171
3272
  RE_LAB.test(s) ||
3172
3273
  RE_LCH.test(s) ||
3173
3274
  RE_OKLAB.test(s) ||
@@ -3175,10 +3276,9 @@ css2rgb.test = (s) => {
3175
3276
  // legacy
3176
3277
  RE_RGB_LEGACY.test(s) ||
3177
3278
  RE_RGBA_LEGACY.test(s) ||
3178
- RE_RGB_PCT_LEGACY.test(s) ||
3179
- RE_RGBA_PCT_LEGACY.test(s) ||
3180
3279
  RE_HSL_LEGACY.test(s) ||
3181
- RE_HSLA_LEGACY.test(s)
3280
+ RE_HSLA_LEGACY.test(s) ||
3281
+ s === 'transparent'
3182
3282
  );
3183
3283
  };
3184
3284
 
@@ -3344,10 +3444,11 @@ Object.assign(chroma, {
3344
3444
  average,
3345
3445
  bezier: bezier$1,
3346
3446
  blend,
3347
- brewer: colorbrewer,
3447
+ brewer: colorbrewerProxy,
3348
3448
  Color,
3349
3449
  colors: w3cx11,
3350
3450
  contrast,
3451
+ contrastAPCA,
3351
3452
  cubehelix,
3352
3453
  deltaE,
3353
3454
  distance,
@@ -3554,14 +3655,256 @@ function computeColorValues(color) {
3554
3655
  }
3555
3656
  }
3556
3657
 
3557
- function r$1(...t){return u(Object.values,t)}
3658
+ function r$1(...n){return u(Object.values,n)}
3558
3659
 
3559
3660
  function i(...e){return u(r,e)}var r=(e,t)=>e.length>=t;
3560
3661
 
3662
+ function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
3663
+
3561
3664
  function t(r){return typeof r=="string"}
3562
3665
 
3563
3666
  function n(e){return !!e}
3564
3667
 
3668
+ function getId(element) {
3669
+ return t(element) ? element : element.id;
3670
+ }
3671
+
3672
+ class LikeC4DiagramModel {
3673
+ constructor(view, model) {
3674
+ this.view = view;
3675
+ this.model = model;
3676
+ for (const node of view.nodes) {
3677
+ const el = new LikeC4DiagramModel.Element(node, this);
3678
+ this._elements.set(node.id, el);
3679
+ if (e(node.parent)) {
3680
+ this._rootElements.add(el);
3681
+ }
3682
+ }
3683
+ this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4DiagramModel.Connection(e, this)]));
3684
+ }
3685
+ _rootElements = /* @__PURE__ */ new Set();
3686
+ _elements = /* @__PURE__ */ new Map();
3687
+ _connections;
3688
+ get isDynamic() {
3689
+ return this.view.__ === "dynamic";
3690
+ }
3691
+ get id() {
3692
+ return this.view.id;
3693
+ }
3694
+ get title() {
3695
+ return this.view.title;
3696
+ }
3697
+ get viewOf() {
3698
+ if (e(this.view.__) || this.view.__ === "element") {
3699
+ const computedView = this.view;
3700
+ return computedView.viewOf ? this.model.element(computedView.viewOf) : null;
3701
+ }
3702
+ return null;
3703
+ }
3704
+ get tags() {
3705
+ return this.view.tags ?? [];
3706
+ }
3707
+ roots() {
3708
+ return [...this._rootElements];
3709
+ }
3710
+ elements() {
3711
+ return [...this._elements.values()];
3712
+ }
3713
+ element(id) {
3714
+ return nonNullable(this._elements.get(id), `LikeC4DiagramModel.Element ${id} in view ${this.view.id} not found`);
3715
+ }
3716
+ hasElement(id) {
3717
+ return this._elements.has(id);
3718
+ }
3719
+ connections() {
3720
+ return [...this._connections.values()];
3721
+ }
3722
+ connection(id) {
3723
+ return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
3724
+ }
3725
+ findConnections(source, target, direction = "direct") {
3726
+ const sourceId = getId(source);
3727
+ const targetId = getId(target);
3728
+ return this.connections().filter(
3729
+ (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
3730
+ );
3731
+ }
3732
+ parent(element) {
3733
+ const el = this.element(getId(element));
3734
+ return el.node.parent ? this.element(el.node.parent) : null;
3735
+ }
3736
+ children(element) {
3737
+ const el = this.element(getId(element));
3738
+ return el.node.children.map((c) => this.element(c));
3739
+ }
3740
+ // Get all sibling (i.e. same parent)
3741
+ siblings(element) {
3742
+ const id = getId(element);
3743
+ const parent = this.parent(id);
3744
+ const siblings = parent ? this.children(parent) : this.roots();
3745
+ return siblings.filter((e) => e.id !== id);
3746
+ }
3747
+ /**
3748
+ * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
3749
+ * (from closest to root)
3750
+ */
3751
+ ancestors(element) {
3752
+ let id = getId(element);
3753
+ const result = [];
3754
+ let parent;
3755
+ while (parent = this.parent(id)) {
3756
+ result.push(parent);
3757
+ id = parent.id;
3758
+ }
3759
+ return result;
3760
+ }
3761
+ descendants(element) {
3762
+ const children = this.children(element);
3763
+ return children.flatMap((c) => [c, ...this.descendants(c.id)]);
3764
+ }
3765
+ incoming(element, filter = "all") {
3766
+ const el = this.element(getId(element));
3767
+ const edges = el.node.inEdges.map((e) => this.connection(e));
3768
+ if (filter === "all" || edges.length === 0) {
3769
+ return edges;
3770
+ }
3771
+ return edges.filter((rel) => {
3772
+ if (filter === "direct") {
3773
+ return rel.target.id === el.id;
3774
+ }
3775
+ return rel.target.id !== el.id;
3776
+ });
3777
+ }
3778
+ incomers(element, filter = "all") {
3779
+ return this.incoming(element, filter).map((r) => r.source);
3780
+ }
3781
+ /**
3782
+ * Outgoing relationships from the element and its descendants
3783
+ */
3784
+ outgoing(element, filter = "all") {
3785
+ const el = this.element(getId(element));
3786
+ const edges = el.node.outEdges.map((e) => this.connection(e));
3787
+ if (filter === "all" || edges.length === 0) {
3788
+ return edges;
3789
+ }
3790
+ return edges.filter((rel) => {
3791
+ if (filter === "direct") {
3792
+ return rel.source.id === el.id;
3793
+ }
3794
+ return rel.source.id !== el.id;
3795
+ });
3796
+ }
3797
+ outgoers(element, filter = "all") {
3798
+ return this.outgoing(element, filter).map((r) => r.target);
3799
+ }
3800
+ }
3801
+ ((LikeC4DiagramModel2) => {
3802
+ class Element {
3803
+ constructor(node, view) {
3804
+ this.node = node;
3805
+ this.view = view;
3806
+ }
3807
+ get id() {
3808
+ return this.node.id;
3809
+ }
3810
+ get title() {
3811
+ return this.node.title;
3812
+ }
3813
+ get kind() {
3814
+ return this.node.kind;
3815
+ }
3816
+ get isRoot() {
3817
+ return e(this.node.parent);
3818
+ }
3819
+ get hasNested() {
3820
+ return this.node.children.length > 0;
3821
+ }
3822
+ get shape() {
3823
+ return this.node.shape;
3824
+ }
3825
+ get color() {
3826
+ return this.node.color;
3827
+ }
3828
+ get tags() {
3829
+ return this.node.tags ?? [];
3830
+ }
3831
+ get level() {
3832
+ return this.node.level;
3833
+ }
3834
+ get depth() {
3835
+ return this.node.depth ?? 0;
3836
+ }
3837
+ model() {
3838
+ return this.view.model.element(this.id);
3839
+ }
3840
+ parent() {
3841
+ return this.node.parent ? this.view.element(this.node.parent) : null;
3842
+ }
3843
+ metadata(key, defaultValue) {
3844
+ return this.model().metadata(key) ?? defaultValue;
3845
+ }
3846
+ hasMetadata(key) {
3847
+ return this.model().hasMetadata(key);
3848
+ }
3849
+ ancestors() {
3850
+ return this.view.ancestors(this);
3851
+ }
3852
+ siblings() {
3853
+ return this.view.siblings(this);
3854
+ }
3855
+ descendants() {
3856
+ return this.view.descendants(this);
3857
+ }
3858
+ children() {
3859
+ return this.view.children(this);
3860
+ }
3861
+ incoming(filter = "all") {
3862
+ return this.view.incoming(this, filter);
3863
+ }
3864
+ incomers(filter = "all") {
3865
+ return this.view.incomers(this, filter);
3866
+ }
3867
+ outgoing(filter = "all") {
3868
+ return this.view.outgoing(this, filter);
3869
+ }
3870
+ outgoers(filter = "all") {
3871
+ return this.view.outgoers(this, filter);
3872
+ }
3873
+ connectionsTo(target) {
3874
+ return this.view.findConnections(this, target);
3875
+ }
3876
+ }
3877
+ LikeC4DiagramModel2.Element = Element;
3878
+ class Connection {
3879
+ constructor(edge, view) {
3880
+ this.edge = edge;
3881
+ this.view = view;
3882
+ }
3883
+ get id() {
3884
+ return this.edge.id;
3885
+ }
3886
+ get source() {
3887
+ return this.view.element(this.edge.source);
3888
+ }
3889
+ get target() {
3890
+ return this.view.element(this.edge.target);
3891
+ }
3892
+ get tags() {
3893
+ return this.edge.tags ?? [];
3894
+ }
3895
+ get color() {
3896
+ return this.edge.color ?? DefaultRelationshipColor;
3897
+ }
3898
+ /**
3899
+ * Model relationships
3900
+ */
3901
+ relationships() {
3902
+ return this.edge.relations.map((r) => nonNullable(this.view.model.relationship(r)));
3903
+ }
3904
+ }
3905
+ LikeC4DiagramModel2.Connection = Connection;
3906
+ })(LikeC4DiagramModel || (LikeC4DiagramModel = {}));
3907
+
3565
3908
  function getDefaultExportFromCjs (x) {
3566
3909
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3567
3910
  }
@@ -3759,16 +4102,16 @@ class LikeC4ViewModel {
3759
4102
  this.model = model;
3760
4103
  for (const node of view.nodes) {
3761
4104
  const el = new LikeC4ViewModel.Element(node, this);
3762
- this.#elements.set(node.id, el);
4105
+ this._elements.set(node.id, el);
3763
4106
  if (e(node.parent)) {
3764
- this.#rootElements.add(el);
4107
+ this._rootElements.add(el);
3765
4108
  }
3766
4109
  }
3767
- this.#connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
4110
+ this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
3768
4111
  }
3769
- #rootElements = /* @__PURE__ */ new Set();
3770
- #elements = /* @__PURE__ */ new Map();
3771
- #connections;
4112
+ _rootElements = /* @__PURE__ */ new Set();
4113
+ _elements = /* @__PURE__ */ new Map();
4114
+ _connections;
3772
4115
  get id() {
3773
4116
  return this.view.id;
3774
4117
  }
@@ -3785,41 +4128,41 @@ class LikeC4ViewModel {
3785
4128
  return this.view.tags ?? [];
3786
4129
  }
3787
4130
  roots() {
3788
- return [...this.#rootElements];
4131
+ return [...this._rootElements];
3789
4132
  }
3790
4133
  elements() {
3791
- return [...this.#elements.values()];
4134
+ return [...this._elements.values()];
3792
4135
  }
3793
4136
  element(id) {
3794
- return nonNullable(this.#elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.view.id} not found`);
4137
+ return nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`);
3795
4138
  }
3796
4139
  hasElement(id) {
3797
- return this.#elements.has(id);
4140
+ return this._elements.has(id);
3798
4141
  }
3799
4142
  connections() {
3800
- return [...this.#connections.values()];
4143
+ return [...this._connections.values()];
3801
4144
  }
3802
4145
  connection(id) {
3803
- return nonNullable(this.#connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
4146
+ return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`);
3804
4147
  }
3805
4148
  findConnections(source, target, direction = "direct") {
3806
- const sourceId = t(source) ? source : source.id;
3807
- const targetId = t(target) ? target : target.id;
4149
+ const sourceId = getId(source);
4150
+ const targetId = getId(target);
3808
4151
  return this.connections().filter(
3809
4152
  (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
3810
4153
  );
3811
4154
  }
3812
4155
  parent(element) {
3813
- const el = this.element(t(element) ? element : element.id);
4156
+ const el = this.element(getId(element));
3814
4157
  return el.node.parent ? this.element(el.node.parent) : null;
3815
4158
  }
3816
4159
  children(element) {
3817
- const el = this.element(t(element) ? element : element.id);
4160
+ const el = this.element(getId(element));
3818
4161
  return el.node.children.map((c) => this.element(c));
3819
4162
  }
3820
4163
  // Get all sibling (i.e. same parent)
3821
4164
  siblings(element) {
3822
- const id = t(element) ? element : element.id;
4165
+ const id = getId(element);
3823
4166
  const parent = this.parent(id);
3824
4167
  const siblings = parent ? this.children(parent) : this.roots();
3825
4168
  return siblings.filter((e) => e.id !== id);
@@ -3829,7 +4172,7 @@ class LikeC4ViewModel {
3829
4172
  * (from closest to root)
3830
4173
  */
3831
4174
  ancestors(element) {
3832
- let id = t(element) ? element : element.id;
4175
+ let id = getId(element);
3833
4176
  const result = [];
3834
4177
  let parent;
3835
4178
  while (parent = this.parent(id)) {
@@ -3843,8 +4186,8 @@ class LikeC4ViewModel {
3843
4186
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
3844
4187
  }
3845
4188
  incoming(element, filter = "all") {
3846
- const el = this.element(t(element) ? element : element.id);
3847
- const edges = el.node.inEdges.map((e) => nonNullable(this.#connections.get(e), `Edge ${e} not found`));
4189
+ const el = this.element(getId(element));
4190
+ const edges = el.node.inEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
3848
4191
  if (filter === "all" || edges.length === 0) {
3849
4192
  return edges;
3850
4193
  }
@@ -3862,8 +4205,8 @@ class LikeC4ViewModel {
3862
4205
  * Outgoing relationships from the element and its descendants
3863
4206
  */
3864
4207
  outgoing(element, filter = "all") {
3865
- const el = this.element(t(element) ? element : element.id);
3866
- const edges = el.node.outEdges.map((e) => nonNullable(this.#connections.get(e), `Edge ${e} not found`));
4208
+ const el = this.element(getId(element));
4209
+ const edges = el.node.outEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
3867
4210
  if (filter === "all" || edges.length === 0) {
3868
4211
  return edges;
3869
4212
  }
@@ -3976,103 +4319,126 @@ class LikeC4ViewModel {
3976
4319
  LikeC4ViewModel2.Connection = Connection;
3977
4320
  })(LikeC4ViewModel || (LikeC4ViewModel = {}));
3978
4321
 
3979
- const RelationsSet = Set;
3980
- const MapRelations = Map;
3981
4322
  class LikeC4Model {
3982
- constructor(computed) {
3983
- this.computed = computed;
3984
- for (const el of r$1(computed.elements)) {
4323
+ constructor(type, sourcemodel, elements, relations) {
4324
+ this.type = type;
4325
+ this.sourcemodel = sourcemodel;
4326
+ for (const el of elements) {
3985
4327
  this.addElement(el);
3986
4328
  }
3987
- for (const rel of r$1(computed.relations)) {
4329
+ for (const rel of relations) {
3988
4330
  this.addRelation(rel);
3989
4331
  }
3990
- this.#views = new Map(
3991
- r$1(computed.views).map((v) => [v.id, new LikeC4ViewModel(v, this)])
3992
- );
3993
4332
  }
3994
- #elements = /* @__PURE__ */ new Map();
4333
+ _elements = /* @__PURE__ */ new Map();
3995
4334
  // Parent element for given FQN
3996
- #parents = /* @__PURE__ */ new Map();
4335
+ _parents = /* @__PURE__ */ new Map();
3997
4336
  // Children elements for given FQN
3998
- #children = /* @__PURE__ */ new Map();
3999
- #rootElements = /* @__PURE__ */ new Set();
4000
- #relations = /* @__PURE__ */ new Map();
4337
+ _children = /* @__PURE__ */ new Map();
4338
+ _rootElements = /* @__PURE__ */ new Set();
4339
+ _relations = /* @__PURE__ */ new Map();
4001
4340
  // Incoming to an element or its descendants
4002
- #incoming = new MapRelations();
4341
+ _incoming = /* @__PURE__ */ new Map();
4003
4342
  // Outgoing from an element or its descendants
4004
- #outgoing = new MapRelations();
4343
+ _outgoing = /* @__PURE__ */ new Map();
4005
4344
  // Relationships inside the element, among descendants
4006
- #internal = new MapRelations();
4007
- #cacheAscendingSiblings = /* @__PURE__ */ new Map();
4008
- #views;
4009
- static from(computed) {
4010
- return new LikeC4Model(computed);
4345
+ _internal = /* @__PURE__ */ new Map();
4346
+ _cacheAscendingSiblings = /* @__PURE__ */ new Map();
4347
+ _views = /* @__PURE__ */ new Map();
4348
+ static create(source) {
4349
+ if (source.__ === "layouted") {
4350
+ return LikeC4Model.layouted(source);
4351
+ }
4352
+ return LikeC4Model.computed(source);
4353
+ }
4354
+ static computed(source) {
4355
+ const instance = new LikeC4Model(
4356
+ "computed",
4357
+ source,
4358
+ r$1(source.elements),
4359
+ r$1(source.relations)
4360
+ );
4361
+ for (const view of r$1(source.views)) {
4362
+ instance._views.set(view.id, new LikeC4ViewModel(view, instance));
4363
+ }
4364
+ return instance;
4365
+ }
4366
+ static layouted(source) {
4367
+ const instance = new LikeC4Model(
4368
+ "layouted",
4369
+ source,
4370
+ r$1(source.elements),
4371
+ r$1(source.relations)
4372
+ );
4373
+ for (const view of r$1(source.views)) {
4374
+ instance._views.set(view.id, new LikeC4DiagramModel(view, instance));
4375
+ }
4376
+ return instance;
4011
4377
  }
4012
4378
  /**
4013
4379
  * Returns the root elements of the model.
4014
4380
  */
4015
4381
  roots() {
4016
- return [...this.#rootElements];
4382
+ return [...this._rootElements];
4017
4383
  }
4018
4384
  /**
4019
4385
  * Returns all elements in the model.
4020
4386
  */
4021
4387
  elements() {
4022
- return [...this.#elements.values()];
4388
+ return [...this._elements.values()];
4023
4389
  }
4024
4390
  /**
4025
4391
  * Returns a specific element by its FQN.
4026
4392
  */
4027
4393
  element(id) {
4028
- return nonNullable(this.#elements.get(id), `Element ${id} not found`);
4394
+ return nonNullable(this._elements.get(id), `Element ${id} not found`);
4029
4395
  }
4030
4396
  /**
4031
4397
  * Returns all relationships in the model.
4032
4398
  */
4033
4399
  relationships() {
4034
- return [...this.#relations.values()];
4400
+ return [...this._relations.values()];
4035
4401
  }
4036
4402
  /**
4037
4403
  * Returns a specific relationship by its ID.
4038
4404
  */
4039
4405
  relationship(id) {
4040
- return nonNullable(this.#relations.get(id), `Relation ${id} not found`);
4406
+ return nonNullable(this._relations.get(id), `Relation ${id} not found`);
4041
4407
  }
4042
4408
  /**
4043
4409
  * Returns all views in the model.
4044
4410
  */
4045
4411
  views() {
4046
- return [...this.#views.values()];
4412
+ return [...this._views.values()];
4047
4413
  }
4048
4414
  /**
4049
4415
  * Returns a specific view by its ID.
4050
4416
  */
4051
4417
  view(viewId) {
4052
- return nonNullable(this.#views.get(viewId), `View ${viewId} not found`);
4418
+ return nonNullable(this._views.get(viewId), `View ${viewId} not found`);
4053
4419
  }
4054
4420
  /**
4055
4421
  * Returns the parent element of given element.
4056
4422
  * @see ancestors
4057
4423
  */
4058
4424
  parent(element) {
4059
- const id = t(element) ? element : element.id;
4060
- return this.#parents.get(id) || null;
4425
+ const id = getId(element);
4426
+ return this._parents.get(id) || null;
4061
4427
  }
4062
4428
  /**
4063
4429
  * Get all children of the element (only direct children),
4064
4430
  * @see descendants
4065
4431
  */
4066
4432
  children(element) {
4067
- const id = t(element) ? element : element.id;
4433
+ const id = getId(element);
4068
4434
  return this._childrenOf(id);
4069
4435
  }
4070
4436
  /**
4071
4437
  * Get all sibling (i.e. same parent)
4072
4438
  */
4073
4439
  siblings(element) {
4074
- const id = t(element) ? element : element.id;
4075
- const parent = this.#parents.get(id);
4440
+ const id = getId(element);
4441
+ const parent = this._parents.get(id);
4076
4442
  const siblings = parent ? this._childrenOf(parent.id) : this.roots();
4077
4443
  return siblings.filter((e) => e.id !== id);
4078
4444
  }
@@ -4084,7 +4450,7 @@ class LikeC4Model {
4084
4450
  let id = t(element) ? element : element.id;
4085
4451
  const result = [];
4086
4452
  let parent;
4087
- while (parent = this.#parents.get(id)) {
4453
+ while (parent = this._parents.get(id)) {
4088
4454
  result.push(parent);
4089
4455
  id = parent.id;
4090
4456
  }
@@ -4094,7 +4460,7 @@ class LikeC4Model {
4094
4460
  * Get all descendant elements (i.e. children, children’s children, etc.)
4095
4461
  */
4096
4462
  descendants(element) {
4097
- const id = t(element) ? element : element.id;
4463
+ const id = getId(element);
4098
4464
  const children = this._childrenOf(id);
4099
4465
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4100
4466
  }
@@ -4103,7 +4469,7 @@ class LikeC4Model {
4103
4469
  * @see incomers
4104
4470
  */
4105
4471
  incoming(element, filter = "all") {
4106
- const id = t(element) ? element : element.id;
4472
+ const id = getId(element);
4107
4473
  const incoming = Array.from(this._incomingTo(id));
4108
4474
  if (filter === "all" || incoming.length === 0) {
4109
4475
  return incoming;
@@ -4126,7 +4492,7 @@ class LikeC4Model {
4126
4492
  * @see outgoers
4127
4493
  */
4128
4494
  outgoing(element, filter = "all") {
4129
- const id = t(element) ? element : element.id;
4495
+ const id = getId(element);
4130
4496
  const outgoing = Array.from(this._outgoingFrom(id));
4131
4497
  if (filter === "all" || outgoing.length === 0) {
4132
4498
  return outgoing;
@@ -4148,7 +4514,7 @@ class LikeC4Model {
4148
4514
  * Relationships inside the element, among descendants
4149
4515
  */
4150
4516
  internal(element) {
4151
- const id = t(element) ? element : element.id;
4517
+ const id = getId(element);
4152
4518
  return Array.from(this._internalOf(id));
4153
4519
  }
4154
4520
  /**
@@ -4156,14 +4522,14 @@ class LikeC4Model {
4156
4522
  * (from closest to root)
4157
4523
  */
4158
4524
  ascendingSiblings(element) {
4159
- const id = t(element) ? element : element.id;
4160
- let siblings = this.#cacheAscendingSiblings.get(id);
4525
+ const id = getId(element);
4526
+ let siblings = this._cacheAscendingSiblings.get(id);
4161
4527
  if (!siblings) {
4162
4528
  siblings = [
4163
4529
  ...this.siblings(id),
4164
4530
  ...this.ancestors(id).flatMap((a) => this.siblings(a.id))
4165
4531
  ];
4166
- this.#cacheAscendingSiblings.set(id, siblings);
4532
+ this._cacheAscendingSiblings.set(id, siblings);
4167
4533
  }
4168
4534
  return siblings.slice();
4169
4535
  }
@@ -4171,29 +4537,29 @@ class LikeC4Model {
4171
4537
  * Resolve all views that contain the element
4172
4538
  */
4173
4539
  viewsWithElement(element) {
4174
- const id = t(element) ? element : element.id;
4175
- return [...this.#views.values()].filter((v) => v.hasElement(id));
4540
+ const id = getId(element);
4541
+ return [...this._views.values()].filter((v) => v.hasElement(id));
4176
4542
  }
4177
4543
  addElement(parsed) {
4178
- if (this.#elements.has(parsed.id)) {
4544
+ if (this._elements.has(parsed.id)) {
4179
4545
  throw new Error(`Element ${parsed.id} already exists`);
4180
4546
  }
4181
- const el = new LikeC4Model.Element(parsed, this);
4182
- this.#elements.set(el.id, el);
4547
+ const el = new LikeC4Model.ElementModel(parsed, this);
4548
+ this._elements.set(el.id, el);
4183
4549
  const parentId = parentFqn(el.id);
4184
4550
  if (parentId) {
4185
- this.#parents.set(el.id, this.element(parentId));
4551
+ this._parents.set(el.id, this.element(parentId));
4186
4552
  this._childrenOf(parentId).push(el);
4187
4553
  } else {
4188
- this.#rootElements.add(el);
4554
+ this._rootElements.add(el);
4189
4555
  }
4190
4556
  }
4191
4557
  addRelation(relation) {
4192
- if (this.#relations.has(relation.id)) {
4558
+ if (this._relations.has(relation.id)) {
4193
4559
  throw new Error(`Relation ${relation.id} already exists`);
4194
4560
  }
4195
4561
  const rel = new LikeC4Model.Relationship(relation, this);
4196
- this.#relations.set(rel.id, rel);
4562
+ this._relations.set(rel.id, rel);
4197
4563
  this._incomingTo(relation.target).add(rel);
4198
4564
  this._outgoingFrom(relation.source).add(rel);
4199
4565
  const relParent = commonAncestor(relation.source, relation.target);
@@ -4216,40 +4582,85 @@ class LikeC4Model {
4216
4582
  }
4217
4583
  }
4218
4584
  _childrenOf(id) {
4219
- let children = this.#children.get(id);
4585
+ let children = this._children.get(id);
4220
4586
  if (!children) {
4221
4587
  children = [];
4222
- this.#children.set(id, children);
4588
+ this._children.set(id, children);
4223
4589
  }
4224
4590
  return children;
4225
4591
  }
4226
4592
  _incomingTo(id) {
4227
- let incoming = this.#incoming.get(id);
4593
+ let incoming = this._incoming.get(id);
4228
4594
  if (!incoming) {
4229
- incoming = new RelationsSet();
4230
- this.#incoming.set(id, incoming);
4595
+ incoming = /* @__PURE__ */ new Set();
4596
+ this._incoming.set(id, incoming);
4231
4597
  }
4232
4598
  return incoming;
4233
4599
  }
4234
4600
  _outgoingFrom(id) {
4235
- let outgoing = this.#outgoing.get(id);
4601
+ let outgoing = this._outgoing.get(id);
4236
4602
  if (!outgoing) {
4237
- outgoing = new RelationsSet();
4238
- this.#outgoing.set(id, outgoing);
4603
+ outgoing = /* @__PURE__ */ new Set();
4604
+ this._outgoing.set(id, outgoing);
4239
4605
  }
4240
4606
  return outgoing;
4241
4607
  }
4242
4608
  _internalOf(id) {
4243
- let internal = this.#internal.get(id);
4609
+ let internal = this._internal.get(id);
4244
4610
  if (!internal) {
4245
- internal = new RelationsSet();
4246
- this.#internal.set(id, internal);
4611
+ internal = /* @__PURE__ */ new Set();
4612
+ this._internal.set(id, internal);
4247
4613
  }
4248
4614
  return internal;
4249
4615
  }
4250
4616
  }
4251
4617
  ((LikeC4Model2) => {
4252
- class Element {
4618
+ function isModel(model) {
4619
+ return model instanceof LikeC4Model2;
4620
+ }
4621
+ LikeC4Model2.isModel = isModel;
4622
+ ((ViewModel2) => {
4623
+ function isLayouted2(model) {
4624
+ return model instanceof LikeC4DiagramModel;
4625
+ }
4626
+ ViewModel2.isLayouted = isLayouted2;
4627
+ })(LikeC4Model2.ViewModel || (LikeC4Model2.ViewModel = {}));
4628
+ function isLayouted(model) {
4629
+ return model.type === "layouted";
4630
+ }
4631
+ LikeC4Model2.isLayouted = isLayouted;
4632
+ class Relationship {
4633
+ constructor(relationship, model) {
4634
+ this.relationship = relationship;
4635
+ this.model = model;
4636
+ }
4637
+ get id() {
4638
+ return this.relationship.id;
4639
+ }
4640
+ get title() {
4641
+ return this.relationship.title;
4642
+ }
4643
+ get kind() {
4644
+ return this.relationship.kind ?? null;
4645
+ }
4646
+ get tags() {
4647
+ return this.relationship.tags ?? [];
4648
+ }
4649
+ get source() {
4650
+ return this.model.element(this.relationship.source);
4651
+ }
4652
+ get target() {
4653
+ return this.model.element(this.relationship.target);
4654
+ }
4655
+ metadata(key, defaultValue) {
4656
+ return this.relationship.metadata?.[key] ?? defaultValue;
4657
+ }
4658
+ hasMetadata(key) {
4659
+ return n(this.relationship.metadata?.[key]);
4660
+ }
4661
+ }
4662
+ LikeC4Model2.Relationship = Relationship;
4663
+ class ElementModel {
4253
4664
  constructor(element, model) {
4254
4665
  this.element = element;
4255
4666
  this.model = model;
@@ -4324,46 +4735,21 @@ class LikeC4Model {
4324
4735
  // return
4325
4736
  // }
4326
4737
  }
4327
- LikeC4Model2.Element = Element;
4328
- class Relationship {
4329
- constructor(relationship, model) {
4330
- this.relationship = relationship;
4331
- this.model = model;
4332
- }
4333
- get id() {
4334
- return this.relationship.id;
4335
- }
4336
- get title() {
4337
- return this.relationship.title;
4338
- }
4339
- get kind() {
4340
- return this.relationship.kind ?? null;
4341
- }
4342
- get tags() {
4343
- return this.relationship.tags ?? [];
4344
- }
4345
- get source() {
4346
- return this.model.element(this.relationship.source);
4347
- }
4348
- get target() {
4349
- return this.model.element(this.relationship.target);
4350
- }
4351
- metadata(key, defaultValue) {
4352
- return this.relationship.metadata?.[key] ?? defaultValue;
4353
- }
4354
- hasMetadata(key) {
4355
- return n(this.relationship.metadata?.[key]);
4356
- }
4357
- }
4358
- LikeC4Model2.Relationship = Relationship;
4738
+ LikeC4Model2.ElementModel = ElementModel;
4359
4739
  })(LikeC4Model || (LikeC4Model = {}));
4360
4740
 
4361
4741
  const DELAY = "LIKEC4_DELAY";
4362
- function delay(ms = 100) {
4742
+ function delay(...args) {
4743
+ let ms = 100;
4744
+ if (args.length === 2) {
4745
+ ms = o(args[0], args[1]);
4746
+ } else if (args.length === 1) {
4747
+ ms = args[0];
4748
+ }
4363
4749
  return new Promise((resolve) => {
4364
4750
  setTimeout(() => {
4365
4751
  resolve(DELAY);
4366
- }, ms);
4752
+ }, ms ?? 100);
4367
4753
  });
4368
4754
  }
4369
4755
 
@@ -4387,4 +4773,4 @@ const compareRelations = (a, b) => {
4387
4773
  return compareFqnHierarchically(a.target, b.target);
4388
4774
  };
4389
4775
 
4390
- export { DefaultElementShape, DefaultThemeColor, ElementColors, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };
4776
+ export { DefaultElementShape, DefaultRelationshipColor, DefaultThemeColor, ElementColors, LikeC4DiagramModel, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };