dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
129 lines (128 loc) • 4.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TabGroupColorPalette = exports.DEFAULT_TAB_GROUP_COLORS = void 0;
exports.applyTabGroupAccent = applyTabGroupAccent;
exports.resolveTabGroupAccent = resolveTabGroupAccent;
exports.DEFAULT_TAB_GROUP_COLORS = [
{ id: 'grey', value: 'var(--dv-tab-group-color-grey)', label: 'Grey' },
{ id: 'blue', value: 'var(--dv-tab-group-color-blue)', label: 'Blue' },
{ id: 'red', value: 'var(--dv-tab-group-color-red)', label: 'Red' },
{
id: 'yellow',
value: 'var(--dv-tab-group-color-yellow)',
label: 'Yellow',
},
{ id: 'green', value: 'var(--dv-tab-group-color-green)', label: 'Green' },
{ id: 'pink', value: 'var(--dv-tab-group-color-pink)', label: 'Pink' },
{
id: 'purple',
value: 'var(--dv-tab-group-color-purple)',
label: 'Purple',
},
{ id: 'cyan', value: 'var(--dv-tab-group-color-cyan)', label: 'Cyan' },
{
id: 'orange',
value: 'var(--dv-tab-group-color-orange)',
label: 'Orange',
},
];
/**
* Runtime palette for tab-group color accents.
*
* Resolves a stored `color` string to a CSS color expression, with three
* fall-through modes:
* 1. `id` matches an entry → entry's `value`
* 2. `id` doesn't match → `id` itself (raw CSS literal pass-through)
* 3. `id` is empty or undefined → undefined (caller skips assignment)
*
* When `enabled` is false the palette returns undefined for everything; this
* is the `tabGroupAccent: 'off'` opt-out path.
*/
var TabGroupColorPalette = /** @class */ (function () {
function TabGroupColorPalette(entries, enabled) {
if (enabled === void 0) { enabled = true; }
this._entries = entries.slice();
this._byId = new Map(entries.map(function (e) { return [e.id, e]; }));
this._enabled = enabled;
}
Object.defineProperty(TabGroupColorPalette.prototype, "enabled", {
get: function () {
return this._enabled;
},
set: function (value) {
this._enabled = value;
},
enumerable: false,
configurable: true
});
/**
* Replace the entry list in place. Used by `updateOptions` so that
* existing palette references (held by chips, indicators, etc.) see
* the new palette without needing to be re-wired.
*/
TabGroupColorPalette.prototype.setEntries = function (entries) {
this._entries = entries.slice();
this._byId = new Map(entries.map(function (e) { return [e.id, e]; }));
};
TabGroupColorPalette.prototype.entries = function () {
return this._entries;
};
TabGroupColorPalette.prototype.has = function (id) {
return this._byId.has(id);
};
TabGroupColorPalette.prototype.get = function (id) {
return this._byId.get(id);
};
/** First entry's id; used as the default when a color is unset. */
TabGroupColorPalette.prototype.defaultId = function () {
var _a;
return (_a = this._entries[0]) === null || _a === void 0 ? void 0 : _a.id;
};
/**
* Resolve a stored color to its CSS value, or undefined if no value
* should be written (palette disabled, or color empty/undefined).
*/
TabGroupColorPalette.prototype.resolveValue = function (color) {
if (!this._enabled || !color) {
return undefined;
}
var entry = this._byId.get(color);
return entry ? entry.value : color;
};
return TabGroupColorPalette;
}());
exports.TabGroupColorPalette = TabGroupColorPalette;
var _fallbackPalette;
/**
* Lazy-built palette used when the accessor isn't available (test mocks,
* isolated chip construction). Production code paths always pass a real
* palette through.
*/
function getFallbackPalette() {
if (!_fallbackPalette) {
_fallbackPalette = new TabGroupColorPalette(exports.DEFAULT_TAB_GROUP_COLORS, true);
}
return _fallbackPalette;
}
/**
* Set the `--dv-tab-group-color` custom property on `el` to the resolved
* accent value, or remove it when the palette is disabled / color is unset.
*/
function applyTabGroupAccent(el, color, palette) {
var value = (palette !== null && palette !== void 0 ? palette : getFallbackPalette()).resolveValue(color);
if (value === undefined) {
el.style.removeProperty('--dv-tab-group-color');
}
else {
el.style.setProperty('--dv-tab-group-color', value);
}
}
/**
* Return the resolved CSS color for a tab group, or undefined when the
* palette is disabled or no color is set. Use this when you need the raw
* value to assign to a non-custom-property style (e.g. SVG stroke,
* backgroundColor on the indicator underline).
*/
function resolveTabGroupAccent(color, palette) {
return (palette !== null && palette !== void 0 ? palette : getFallbackPalette()).resolveValue(color);
}