@istar-ts/core 0.13.4 → 0.13.6

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.d.cts CHANGED
@@ -159,6 +159,12 @@ export interface KindShape {
159
159
  readonly dash?: string;
160
160
  /** Outline width, when it differs from the renderer's default. */
161
161
  readonly strokeWidth?: number;
162
+ /**
163
+ * Default fill (any CSS colour) of the kind's elements and palette icon, when the element has
164
+ * no `display.backgroundColor`; absent: the renderer's node fill (DSM3's KAOS is grey, its
165
+ * NFR white).
166
+ */
167
+ readonly fill?: string;
162
168
  }
163
169
  export interface KindTextBox {
164
170
  readonly top: number;
package/dist/index.d.ts CHANGED
@@ -159,6 +159,12 @@ export interface KindShape {
159
159
  readonly dash?: string;
160
160
  /** Outline width, when it differs from the renderer's default. */
161
161
  readonly strokeWidth?: number;
162
+ /**
163
+ * Default fill (any CSS colour) of the kind's elements and palette icon, when the element has
164
+ * no `display.backgroundColor`; absent: the renderer's node fill (DSM3's KAOS is grey, its
165
+ * NFR white).
166
+ */
167
+ readonly fill?: string;
162
168
  }
163
169
  export interface KindTextBox {
164
170
  readonly top: number;
package/dist/index.js CHANGED
@@ -550,6 +550,26 @@ function elementBehavesLike(metamodel, kind, ancestor) {
550
550
  return false;
551
551
  }
552
552
  //#endregion
553
+ //#region src/shared.ts
554
+ /**
555
+ * Registries the library keeps beside models (their metamodel, their file's layout) are
556
+ * shared across every copy of `@istar-ts/core` loaded in a process. A bundle may load the
557
+ * package twice, once as ESM and once as CommonJS (an application parsing with the ESM build
558
+ * while a CommonJS dependency reads the model with the CJS build): a module-level WeakMap in
559
+ * each copy would make a model parsed by one copy unknown to the other, so `metamodelOf`
560
+ * would fall back to iStar 2.0 there. The registries live on `globalThis` under one symbol
561
+ * instead, keyed by name, and every copy finds the same ones.
562
+ */
563
+ const REGISTRIES = Symbol.for("@istar-ts/core/registries");
564
+ /** The WeakMap named `name`, the same object in every copy of the library in this process. */
565
+ function sharedWeakMap(name) {
566
+ const host = globalThis;
567
+ const registries = host[REGISTRIES] ??= /* @__PURE__ */ new Map();
568
+ let map = registries.get(name);
569
+ if (!map) registries.set(name, map = /* @__PURE__ */ new WeakMap());
570
+ return map;
571
+ }
572
+ //#endregion
553
573
  //#region src/model.ts
554
574
  /** Tool identifier written by piStar 2.1.0, whose file format this library emulates. */
555
575
  const PISTAR_TOOL = "pistar.2.1.0";
@@ -580,7 +600,7 @@ const DEFAULT_DIAGRAM = {
580
600
  * so a model's shape (and `JSON.stringify`, deep equality, snapshots) is the same as before
581
601
  * metamodels existed. Operations and the store carry it to every model they derive.
582
602
  */
583
- const metamodels = /* @__PURE__ */ new WeakMap();
603
+ const metamodels = sharedWeakMap("metamodels");
584
604
  /**
585
605
  * Associates `metamodel` with `model` and returns the same model, typed for it. Use when a
586
606
  * model was built without the library's operations (e.g. with an object spread), which loses
@@ -595,7 +615,7 @@ function withMetamodel(model, metamodel) {
595
615
  * For models whose file declares part of their metamodel (see `withFileMetamodel`): the
596
616
  * metamodel the host supplied, without the file's kinds.
597
617
  */
598
- const hostMetamodels = /* @__PURE__ */ new WeakMap();
618
+ const hostMetamodels = sharedWeakMap("hostMetamodels");
599
619
  /** @internal Records the host part of a model's metamodel (used by serialization). */
600
620
  function setHostMetamodel(model, metamodel) {
601
621
  if (metamodel) hostMetamodels.set(model, metamodel);
@@ -1240,7 +1260,7 @@ function hubEntryLayoutKey(hubId) {
1240
1260
  }
1241
1261
  /** The `objects` key of the diagram in a `SourceLayout`. */
1242
1262
  const DIAGRAM_LAYOUT_KEY = "\0diagram";
1243
- const layouts = /* @__PURE__ */ new WeakMap();
1263
+ const layouts = sharedWeakMap("layouts");
1244
1264
  /** The key order recorded when `model` was parsed, if it came from `parsePistar`. */
1245
1265
  function getSourceLayout(model) {
1246
1266
  return layouts.get(model);