bruce-cesium 7.7.9 → 7.8.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.
@@ -7621,6 +7621,36 @@
7621
7621
  * Prefer declared semantics; only infers from recognisable glyphs and filename tokens, never image pixels.
7622
7622
  */
7623
7623
  EntityLabel.IconPriority = GetClusterIconPriority;
7624
+ /*
7625
+ * The glyph and chip colours an icon draws with: each given one as is, a missing one inferred from the other.
7626
+ */
7627
+ function IconColors(options) {
7628
+ var _a;
7629
+ const icon = typeof options.iconColor === "string" && options.iconColor ? options.iconColor : undefined;
7630
+ const background = typeof options.iconBackground === "string" && options.iconBackground.trim() ? options.iconBackground : undefined;
7631
+ if (background) {
7632
+ return { icon: icon !== null && icon !== void 0 ? icon : contrasting(background, 1), background };
7633
+ }
7634
+ if (options.iconBackground === true) {
7635
+ return { icon, background: (_a = contrasting(icon, ICON_BACKGROUND_ALPHA)) !== null && _a !== void 0 ? _a : contrasting("white", ICON_BACKGROUND_ALPHA) };
7636
+ }
7637
+ return { icon };
7638
+ }
7639
+ EntityLabel.IconColors = IconColors;
7640
+ /*
7641
+ * A light colour darkened, or a dark one brightened, far enough to read against it.
7642
+ */
7643
+ function contrasting(css, alpha) {
7644
+ const color = css ? Cesium.Color.fromCssColorString(css) : undefined;
7645
+ if (!color) {
7646
+ return undefined;
7647
+ }
7648
+ const luminance = 0.2126 * color.red + 0.7152 * color.green + 0.0722 * color.blue;
7649
+ const shade = luminance > 0.5 ?
7650
+ color.darken(ICON_BACKGROUND_BLEND, new Cesium.Color()) :
7651
+ color.brighten(ICON_BACKGROUND_BLEND, new Cesium.Color());
7652
+ return shade.withAlpha(alpha).toCssColorString();
7653
+ }
7624
7654
  function iconLook(options) {
7625
7655
  return {
7626
7656
  icon: options.icon || undefined,
@@ -10302,8 +10332,10 @@
10302
10332
  }
10303
10333
  icon.style.cssText = `font-size:${(options.iconSize || 24) * ((_a = options.iconScale) !== null && _a !== void 0 ? _a : 1)}px;line-height:1;`;
10304
10334
  icon.style.textShadow = "0 1px 2px rgba(0, 0, 0, 0.25)";
10305
- const iconColor = typeof options.iconColor === "string" ? options.iconColor : undefined;
10306
- const iconBackground = options.iconBackground && options.iconScale !== 0;
10335
+ const colors = IconColors(options);
10336
+ // A file keeps its own colours unless one was given; only a glyph takes an inferred one.
10337
+ const iconColor = options.iconUrl ? (typeof options.iconColor === "string" ? options.iconColor : undefined) : colors.icon;
10338
+ const iconBackground = options.iconScale !== 0 ? colors.background : undefined;
10307
10339
  if (iconColor) {
10308
10340
  icon.style.color = iconColor;
10309
10341
  }
@@ -10368,12 +10400,8 @@
10368
10400
  icon.textContent = options.icon || "●";
10369
10401
  }
10370
10402
  if (iconBackground) {
10371
- const color = Cesium.Color.fromCssColorString(iconColor || "white") || Cesium.Color.WHITE;
10372
- const luminance = 0.2126 * color.red + 0.7152 * color.green + 0.0722 * color.blue;
10373
- const background = (luminance > 0.5 ? color.darken(ICON_BACKGROUND_BLEND, new Cesium.Color()) :
10374
- color.brighten(ICON_BACKGROUND_BLEND, new Cesium.Color()));
10375
10403
  const size = (options.iconSize || 24) * ((_c = options.iconScale) !== null && _c !== void 0 ? _c : 1);
10376
- icon.style.backgroundColor = background.withAlpha(ICON_BACKGROUND_ALPHA).toCssColorString();
10404
+ icon.style.backgroundColor = iconBackground;
10377
10405
  icon.style.borderRadius = "50%";
10378
10406
  icon.style.padding = `${size / 3}px`;
10379
10407
  icon.style.display = "inline-flex";
@@ -10747,7 +10775,7 @@
10747
10775
  }
10748
10776
  return [
10749
10777
  options.text, options.icon, options.iconUrl, options.iconClass,
10750
- options.iconColor, options.iconStatus, options.iconPriority, options.iconScale
10778
+ options.iconColor, options.iconBackground, options.iconStatus, options.iconPriority, options.iconScale
10751
10779
  ].some(Array.isArray);
10752
10780
  }
10753
10781
  EntityLabelGroup.NeedsEntityData = NeedsEntityData;
@@ -10875,6 +10903,12 @@
10875
10903
  return null;
10876
10904
  }
10877
10905
  }
10906
+ /*
10907
+ * A calculated chip colour that finds nothing for an entity draws no chip, as an unset one would.
10908
+ */
10909
+ function resolveBackground(value, entity) {
10910
+ return typeof value === "boolean" ? value : resolveIcon(value, entity) || undefined;
10911
+ }
10878
10912
  // How many entities one attachment read asks for.
10879
10913
  const IMAGES_AT_ONCE = 100;
10880
10914
  // How long on-screen requests gather before they are read together.
@@ -11112,7 +11146,7 @@
11112
11146
  iconUrl: resolveIcon((_h = group.definition.options) === null || _h === void 0 ? void 0 : _h.iconUrl, entity),
11113
11147
  iconClass: resolveIcon((_j = group.definition.options) === null || _j === void 0 ? void 0 : _j.iconClass, entity),
11114
11148
  iconColor: resolveIcon((_k = group.definition.options) === null || _k === void 0 ? void 0 : _k.iconColor, entity),
11115
- iconBackground: (_l = group.definition.options) === null || _l === void 0 ? void 0 : _l.iconBackground,
11149
+ iconBackground: resolveBackground((_l = group.definition.options) === null || _l === void 0 ? void 0 : _l.iconBackground, entity),
11116
11150
  iconPriority: Number.isFinite(iconPriority) ? iconPriority : item.iconPriority,
11117
11151
  iconStatus: (_o = resolveIcon((_m = group.definition.options) === null || _m === void 0 ? void 0 : _m.iconStatus, entity)) !== null && _o !== void 0 ? _o : item.iconStatus
11118
11152
  };
@@ -11367,8 +11401,11 @@
11367
11401
  if (!options) {
11368
11402
  return;
11369
11403
  }
11370
- if (options.iconBackground != null && typeof options.iconBackground !== "boolean") {
11371
- throw new Error("Label iconBackground must be a boolean");
11404
+ if (options.iconBackground != null &&
11405
+ typeof options.iconBackground !== "boolean" &&
11406
+ typeof options.iconBackground !== "string" &&
11407
+ !Array.isArray(options.iconBackground)) {
11408
+ throw new Error("Label iconBackground must be a boolean, a colour or a Calculator field array");
11372
11409
  }
11373
11410
  for (const value of [options.icon, options.iconUrl, options.iconClass, options.iconColor, options.text]) {
11374
11411
  if (value != null && typeof value !== "string" && !Array.isArray(value)) {
@@ -60158,7 +60195,7 @@ void main() {
60158
60195
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
60159
60196
  })(exports.StyleUtils || (exports.StyleUtils = {}));
60160
60197
 
60161
- const VERSION = "7.7.9";
60198
+ const VERSION = "7.8.0";
60162
60199
  /**
60163
60200
  * Updates the environment instance used by bruce-cesium to one specified.
60164
60201
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.