Enforce enum types

This commit is contained in:
Idrees Hassan
2026-03-28 11:29:35 -07:00
parent 7d16459a76
commit b7d6ca63c1
8 changed files with 144 additions and 45 deletions

BIN
dist/extension.zip vendored

Binary file not shown.

View File

@@ -542,11 +542,7 @@
} }
}; };
/** const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -578,11 +574,13 @@
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
const SPRITE_SHEET_COLOR_MAP = { const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -618,6 +616,28 @@
"#373737": PALETTE.FEATHER_SPINE, "#373737": PALETTE.FEATHER_SPINE,
}; };
/**
* @type {Partial<Record<PaletteColor, PaletteColor>>}
*/
({
[PALETTE.HOOD]: PALETTE.FACE,
[PALETTE.EYEBROW]: PALETTE.FACE,
[PALETTE.UPPER_EYELID]: PALETTE.EYEBROW,
[PALETTE.UPPER_CORNER_EYE]: PALETTE.EYEBROW,
[PALETTE.BEHIND_EYE]: PALETTE.FACE,
[PALETTE.CORNER_EYE]: PALETTE.FACE,
[PALETTE.TEMPLE]: PALETTE.FACE,
[PALETTE.LOWER_EYELID]: PALETTE.FACE,
[PALETTE.NOSE]: PALETTE.FACE,
[PALETTE.NOSE_TIP]: PALETTE.NOSE,
[PALETTE.CHEEK]: PALETTE.FACE,
[PALETTE.SCRUFF]: PALETTE.FACE,
[PALETTE.COLLAR]: PALETTE.FACE,
[PALETTE.COLLAR_SCRUFF]: PALETTE.COLLAR,
[PALETTE.WING_SPOTS]: PALETTE.WING,
});
const RARITY = Object.freeze(/** @type {const} */ ({ const RARITY = Object.freeze(/** @type {const} */ ({
FAMILIAR: "familiar", FAMILIAR: "familiar",
UNCOMMON: "uncommon" UNCOMMON: "uncommon"

34
dist/obsidian/main.js vendored
View File

@@ -547,11 +547,7 @@ module.exports = class PocketBird extends Plugin {
} }
}; };
/** const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -583,11 +579,13 @@ module.exports = class PocketBird extends Plugin {
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
const SPRITE_SHEET_COLOR_MAP = { const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -623,6 +621,28 @@ module.exports = class PocketBird extends Plugin {
"#373737": PALETTE.FEATHER_SPINE, "#373737": PALETTE.FEATHER_SPINE,
}; };
/**
* @type {Partial<Record<PaletteColor, PaletteColor>>}
*/
({
[PALETTE.HOOD]: PALETTE.FACE,
[PALETTE.EYEBROW]: PALETTE.FACE,
[PALETTE.UPPER_EYELID]: PALETTE.EYEBROW,
[PALETTE.UPPER_CORNER_EYE]: PALETTE.EYEBROW,
[PALETTE.BEHIND_EYE]: PALETTE.FACE,
[PALETTE.CORNER_EYE]: PALETTE.FACE,
[PALETTE.TEMPLE]: PALETTE.FACE,
[PALETTE.LOWER_EYELID]: PALETTE.FACE,
[PALETTE.NOSE]: PALETTE.FACE,
[PALETTE.NOSE_TIP]: PALETTE.NOSE,
[PALETTE.CHEEK]: PALETTE.FACE,
[PALETTE.SCRUFF]: PALETTE.FACE,
[PALETTE.COLLAR]: PALETTE.FACE,
[PALETTE.COLLAR_SCRUFF]: PALETTE.COLLAR,
[PALETTE.WING_SPOTS]: PALETTE.WING,
});
const RARITY = Object.freeze(/** @type {const} */ ({ const RARITY = Object.freeze(/** @type {const} */ ({
FAMILIAR: "familiar", FAMILIAR: "familiar",
UNCOMMON: "uncommon" UNCOMMON: "uncommon"

View File

@@ -556,11 +556,7 @@
} }
}; };
/** const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -592,11 +588,13 @@
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
const SPRITE_SHEET_COLOR_MAP = { const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -632,6 +630,28 @@
"#373737": PALETTE.FEATHER_SPINE, "#373737": PALETTE.FEATHER_SPINE,
}; };
/**
* @type {Partial<Record<PaletteColor, PaletteColor>>}
*/
({
[PALETTE.HOOD]: PALETTE.FACE,
[PALETTE.EYEBROW]: PALETTE.FACE,
[PALETTE.UPPER_EYELID]: PALETTE.EYEBROW,
[PALETTE.UPPER_CORNER_EYE]: PALETTE.EYEBROW,
[PALETTE.BEHIND_EYE]: PALETTE.FACE,
[PALETTE.CORNER_EYE]: PALETTE.FACE,
[PALETTE.TEMPLE]: PALETTE.FACE,
[PALETTE.LOWER_EYELID]: PALETTE.FACE,
[PALETTE.NOSE]: PALETTE.FACE,
[PALETTE.NOSE_TIP]: PALETTE.NOSE,
[PALETTE.CHEEK]: PALETTE.FACE,
[PALETTE.SCRUFF]: PALETTE.FACE,
[PALETTE.COLLAR]: PALETTE.FACE,
[PALETTE.COLLAR_SCRUFF]: PALETTE.COLLAR,
[PALETTE.WING_SPOTS]: PALETTE.WING,
});
const RARITY = Object.freeze(/** @type {const} */ ({ const RARITY = Object.freeze(/** @type {const} */ ({
FAMILIAR: "familiar", FAMILIAR: "familiar",
UNCOMMON: "uncommon" UNCOMMON: "uncommon"

View File

@@ -542,11 +542,7 @@
} }
}; };
/** const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -578,11 +574,13 @@
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
const SPRITE_SHEET_COLOR_MAP = { const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -618,6 +616,28 @@
"#373737": PALETTE.FEATHER_SPINE, "#373737": PALETTE.FEATHER_SPINE,
}; };
/**
* @type {Partial<Record<PaletteColor, PaletteColor>>}
*/
({
[PALETTE.HOOD]: PALETTE.FACE,
[PALETTE.EYEBROW]: PALETTE.FACE,
[PALETTE.UPPER_EYELID]: PALETTE.EYEBROW,
[PALETTE.UPPER_CORNER_EYE]: PALETTE.EYEBROW,
[PALETTE.BEHIND_EYE]: PALETTE.FACE,
[PALETTE.CORNER_EYE]: PALETTE.FACE,
[PALETTE.TEMPLE]: PALETTE.FACE,
[PALETTE.LOWER_EYELID]: PALETTE.FACE,
[PALETTE.NOSE]: PALETTE.FACE,
[PALETTE.NOSE_TIP]: PALETTE.NOSE,
[PALETTE.CHEEK]: PALETTE.FACE,
[PALETTE.SCRUFF]: PALETTE.FACE,
[PALETTE.COLLAR]: PALETTE.FACE,
[PALETTE.COLLAR_SCRUFF]: PALETTE.COLLAR,
[PALETTE.WING_SPOTS]: PALETTE.WING,
});
const RARITY = Object.freeze(/** @type {const} */ ({ const RARITY = Object.freeze(/** @type {const} */ ({
FAMILIAR: "familiar", FAMILIAR: "familiar",
UNCOMMON: "uncommon" UNCOMMON: "uncommon"

34
dist/web/birb.js vendored
View File

@@ -542,11 +542,7 @@
} }
}; };
/** const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -578,11 +574,13 @@
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
const SPRITE_SHEET_COLOR_MAP = { const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -618,6 +616,28 @@
"#373737": PALETTE.FEATHER_SPINE, "#373737": PALETTE.FEATHER_SPINE,
}; };
/**
* @type {Partial<Record<PaletteColor, PaletteColor>>}
*/
({
[PALETTE.HOOD]: PALETTE.FACE,
[PALETTE.EYEBROW]: PALETTE.FACE,
[PALETTE.UPPER_EYELID]: PALETTE.EYEBROW,
[PALETTE.UPPER_CORNER_EYE]: PALETTE.EYEBROW,
[PALETTE.BEHIND_EYE]: PALETTE.FACE,
[PALETTE.CORNER_EYE]: PALETTE.FACE,
[PALETTE.TEMPLE]: PALETTE.FACE,
[PALETTE.LOWER_EYELID]: PALETTE.FACE,
[PALETTE.NOSE]: PALETTE.FACE,
[PALETTE.NOSE_TIP]: PALETTE.NOSE,
[PALETTE.CHEEK]: PALETTE.FACE,
[PALETTE.SCRUFF]: PALETTE.FACE,
[PALETTE.COLLAR]: PALETTE.FACE,
[PALETTE.COLLAR_SCRUFF]: PALETTE.COLLAR,
[PALETTE.WING_SPOTS]: PALETTE.WING,
});
const RARITY = Object.freeze(/** @type {const} */ ({ const RARITY = Object.freeze(/** @type {const} */ ({
FAMILIAR: "familiar", FAMILIAR: "familiar",
UNCOMMON: "uncommon" UNCOMMON: "uncommon"

View File

@@ -152,8 +152,9 @@ function getColor(part) {
if (currentSpecies.colors[part]) { if (currentSpecies.colors[part]) {
return currentSpecies.colors[part]; return currentSpecies.colors[part];
} }
if (DEFAULT_COLOR_OVERRIDES[part]) { const override = DEFAULT_COLOR_OVERRIDES[/** @type {keyof typeof DEFAULT_COLOR_OVERRIDES} */ (part)];
return getColor(DEFAULT_COLOR_OVERRIDES[part]); if (override) {
return getColor(override);
} }
for (const [color, partName] of Object.entries(COLOR_MAP)) { for (const [color, partName] of Object.entries(COLOR_MAP)) {
if (partName === part) { if (partName === part) {

View File

@@ -1,10 +1,6 @@
import species from "../species.js" import species from "../species.js"
/** export const PALETTE = Object.freeze(/** @type {const} */ ({
* Palette color names
* @type {Record<string, string>}
*/
export const PALETTE = {
THEME_HIGHLIGHT: "theme-highlight", THEME_HIGHLIGHT: "theme-highlight",
TRANSPARENT: "transparent", TRANSPARENT: "transparent",
OUTLINE: "outline", OUTLINE: "outline",
@@ -36,11 +32,13 @@ export const PALETTE = {
HEART_BORDER: "heart-border", HEART_BORDER: "heart-border",
HEART_SHINE: "heart-shine", HEART_SHINE: "heart-shine",
FEATHER_SPINE: "feather-spine", FEATHER_SPINE: "feather-spine",
}; }));
/** @typedef {typeof PALETTE[keyof typeof PALETTE]} PaletteColor */
/** /**
* Mapping of sprite sheet colors to palette colors * Mapping of sprite sheet colors to palette colors
* @type {Record<string, string>} * @type {Record<string, PaletteColor>}
*/ */
export const SPRITE_SHEET_COLOR_MAP = { export const SPRITE_SHEET_COLOR_MAP = {
"transparent": PALETTE.TRANSPARENT, "transparent": PALETTE.TRANSPARENT,
@@ -78,7 +76,7 @@ export const SPRITE_SHEET_COLOR_MAP = {
/** /**
* @type {Record<string, string>} * @type {Partial<Record<PaletteColor, PaletteColor>>}
*/ */
export const DEFAULT_COLOR_OVERRIDES = { export const DEFAULT_COLOR_OVERRIDES = {
[PALETTE.HOOD]: PALETTE.FACE, [PALETTE.HOOD]: PALETTE.FACE,