"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const event = require("../../../base/common/event.js");
const lifecycle = require("../../../base/common/lifecycle.js");
const rgba = require("../core/rgba.js");
const languages = require("../languages.js");
class MinimapTokensColorTracker extends lifecycle.Disposable {
  constructor() {
    super();
    this._onDidChange = new event.Emitter();
    this.onDidChange = this._onDidChange.event;
    this._updateColorMap();
    this._register(languages.TokenizationRegistry.onDidChange((e) => {
      if (e.changedColorMap) {
        this._updateColorMap();
      }
    }));
  }
  static getInstance() {
    if (!this._INSTANCE) {
      this._INSTANCE = lifecycle.markAsSingleton(new MinimapTokensColorTracker());
    }
    return this._INSTANCE;
  }
  _updateColorMap() {
    const colorMap = languages.TokenizationRegistry.getColorMap();
    if (!colorMap) {
      this._colors = [rgba.RGBA8.Empty];
      this._backgroundIsLight = true;
      return;
    }
    this._colors = [rgba.RGBA8.Empty];
    for (let colorId = 1; colorId < colorMap.length; colorId++) {
      const source = colorMap[colorId].rgba;
      this._colors[colorId] = new rgba.RGBA8(source.r, source.g, source.b, Math.round(source.a * 255));
    }
    const backgroundLuminosity = colorMap[
      2
      /* DefaultBackground */
    ].getRelativeLuminance();
    this._backgroundIsLight = backgroundLuminosity >= 0.5;
    this._onDidChange.fire(void 0);
  }
  getColor(colorId) {
    if (colorId < 1 || colorId >= this._colors.length) {
      colorId = 2;
    }
    return this._colors[colorId];
  }
  backgroundIsLight() {
    return this._backgroundIsLight;
  }
}
MinimapTokensColorTracker._INSTANCE = null;
exports.MinimapTokensColorTracker = MinimapTokensColorTracker;
