@magicwenli/league-fan-assets
Version:
Typed League of Legends asset loaders (icons, emotes, wards, loot, champions, skins) for league-fan
202 lines (184 loc) • 8.83 kB
TypeScript
import { Patch, Lang, AssetCategory, CategoryDataMap, SummonerIcon, SummonerIconSet, SummonerEmote, WardSkin, WardSkinSet, LootItem, Champion, Skinline, Universe, Skins, Added, VersionInfo, Skin, RarityEnum } from './types/index.js';
export { Augment, Borders, CategoryData, Chroma, CosmeticsCategory, DataManifest, DescriptionInfo, Emblem, Layer, Overlay, QuestSkinInfo, RegionalDescription, RegionalRarity, Role, SkinAugments, SkinLineRef, SkinType, SkinsDomainCategory, Tier } from './types/index.js';
type DataSource = {
kind: "cdragon";
patch?: Patch;
} | {
kind: "release";
baseUrl?: string;
version?: string;
};
interface LoadOptions {
lang?: Lang;
source?: DataSource;
fetch?: typeof globalThis.fetch;
/** Override patch for transforms when source is release. */
patch?: Patch;
}
declare function loadCategory<C extends AssetCategory>(category: C, opts?: LoadOptions): Promise<CategoryDataMap[C]>;
interface ClientOptions {
lang?: Lang;
source?: DataSource;
fetch?: typeof globalThis.fetch;
/** Default patch override for CDragon loads / path rewriting. */
patch?: Patch;
}
interface LeagueFanAssetsClient {
readonly lang: Lang;
readonly source: DataSource;
load<C extends AssetCategory>(category: C): Promise<CategoryDataMap[C]>;
summonerIcons(): Promise<SummonerIcon[]>;
summonerIconSets(): Promise<SummonerIconSet[]>;
summonerEmotes(): Promise<SummonerEmote[]>;
wardSkins(): Promise<WardSkin[]>;
wardSkinSets(): Promise<WardSkinSet[]>;
loot(): Promise<LootItem[]>;
champions(): Promise<Champion[]>;
skinlines(): Promise<Skinline[]>;
universes(): Promise<Universe[]>;
skins(): Promise<Skins>;
added(): Promise<Added>;
version(): Promise<VersionInfo>;
}
declare function createClient(options?: ClientOptions): LeagueFanAssetsClient;
declare class FetchError extends Error {
readonly status: number;
readonly url: string;
constructor(url: string, status: number, statusText: string);
}
declare function fetchJson<T>(url: string, opts?: {
fetch?: typeof globalThis.fetch;
}): Promise<T>;
declare const ASSET_CATEGORIES: readonly ["summoner-icons", "summoner-icon-sets", "summoner-emotes", "ward-skins", "ward-skin-sets", "loot", "champions", "skinlines", "universes", "skins", "added", "version"];
declare const PUBLISHED_DATA_CATEGORIES: readonly ["summoner-icons", "summoner-icon-sets", "summoner-emotes", "ward-skins", "ward-skin-sets", "loot", "champions", "skinlines", "universes", "skins", "added"];
declare const DEFAULT_DATA_LANGUAGES: readonly ["default", "zh_cn"];
interface CategoryMeta {
id: AssetCategory;
domain: "cosmetics" | "champions" | "skins" | "meta";
description: string;
}
declare const CATEGORY_META: Record<AssetCategory, CategoryMeta>;
declare const CDRAGON = "https://raw.communitydragon.org";
declare const TENCENT_PROFILE_ICON_CDN = "https://dlied1.qq.com/lolapp/lol/summoner/profileicon/";
/** CDragon filename for a category (under global/{lang}/v1/). */
declare const CATEGORY_CDRAGON_FILE: Partial<Record<AssetCategory, string>>;
declare function dataRoot(opts?: {
patch?: Patch;
lang?: Lang;
}): string;
declare function cdragonDataUrl(opts: {
category: AssetCategory;
lang?: Lang;
patch?: Patch;
}): string;
/** Default patch preference by domain when using live CDragon. */
declare function defaultPatchForCategory(category: AssetCategory): Patch;
declare const DDRAGON_REALM_TENCENT = "https://ddragon.leagueoflegends.com/realms/tencent.json";
declare const DDRAGON_REALM_NA = "https://ddragon.leagueoflegends.com/realms/na.json";
declare function getGameVersion(opts?: {
fetch?: typeof globalThis.fetch;
realmUrl?: string;
}): Promise<string>;
declare function getVersionInfo(opts?: {
fetch?: typeof globalThis.fetch;
realmUrl?: string;
}): Promise<VersionInfo>;
/**
* Default GitHub Releases download base (latest data release).
* Assets are flat: `{lang}__{category}.json` e.g. `zh_cn__summoner-icons.json`.
*/
declare const DEFAULT_RELEASE_BASE = "https://github.com/league-fan/league-fan-assets/releases/latest/download";
declare function releaseBaseUrl(opts?: {
baseUrl?: string;
version?: string;
}): string;
/** Flatten path for GitHub Release asset names. */
declare function releaseAssetName(relPath: string): string;
declare function releaseDataUrl(opts: {
category: AssetCategory;
lang?: Lang;
version?: string;
baseUrl?: string;
}): string;
declare function releaseManifestUrl(opts?: {
baseUrl?: string;
version?: string;
}): string;
interface AssetUrlOptions {
patch?: Patch;
/** Text language; image binaries still resolve under global/default. */
lang?: Lang;
category?: AssetCategory;
}
/**
* Resolve a CDragon game-data path (or passthrough absolute URL) to HTTPS.
* Mirrors historical league-fan-assets + feat-nextjs behavior.
*/
declare function assetUrl(path: string | null | undefined, opts?: AssetUrlOptions): string;
/** Deep-walk object/array and rewrite string fields that look like game-data paths. */
declare function rewritePathsDeep<T>(value: T, opts?: AssetUrlOptions): T;
interface TransformOpts {
lang?: Lang;
patch?: Patch;
}
declare function transformSummonerIcons(raw: unknown[], opts?: TransformOpts): SummonerIcon[];
declare function transformSummonerIconSets(raw: unknown, opts?: TransformOpts): SummonerIconSet[];
declare function transformSummonerEmotes(raw: unknown[], opts?: TransformOpts): SummonerEmote[];
declare function transformWardSkins(raw: unknown[], opts?: TransformOpts): WardSkin[];
declare function transformWardSkinSets(raw: unknown, opts?: TransformOpts): WardSkinSet[];
declare function transformLoot(raw: unknown, opts?: TransformOpts): LootItem[];
declare function filterLootChests(raw: unknown, opts?: {
lang?: Lang;
patch?: Patch;
}): LootItem[];
declare function transformChampions(raw: unknown[], opts?: {
lang?: Lang;
patch?: Patch;
}): Champion[];
interface SkinTransformOpts {
lang?: Lang;
patch?: Patch;
/** Prefix base skins with "Original " (default true for default/en). */
originalPrefix?: boolean;
}
/**
* Expand quest skin tiers into individual skin entries and normalize paths.
* Port of feat-nextjs scraper getLatestSkins.
*/
declare function transformSkins(raw: Skins | Record<string, Skin>, opts?: SkinTransformOpts): Skins;
declare function transformSkinlines(raw: unknown[], _opts?: SkinTransformOpts): Skinline[];
declare function transformUniverses(raw: unknown[], opts?: SkinTransformOpts): Universe[];
declare function computeAdded(opts: {
current: {
champions: Champion[];
skinlines: Skinline[];
skins: Skins;
universes: Universe[];
};
previous: {
champions: Champion[];
skinlines: Skinline[];
skins: Skins;
universes: Universe[];
};
}): Added;
interface SplitSkinId {
champId: number;
skinIndex: number;
}
/** Skin id layout: champId * 1000 + skinIndex */
declare function splitSkinId(id: number): SplitSkinId;
/** Legacy tuple form used by some scrapers: [champId, skinIndex] */
declare function splitId(id: number): [number, number];
/** Champion alias substitutions used by community tools / wiki. */
declare const ALIAS_SUBSTITUTIONS: Record<string, string>;
declare function substitute(value: string, sets?: Record<string, string>): string;
declare const raritiesMap: Partial<Record<RarityEnum, [string, string]>>;
declare function getRarityUrl(rarity: string, opts?: {
patch?: Patch;
}): {
imgUrl: string;
name: string;
} | null;
declare function modelviewerUrl(skinId: number): string;
export { ALIAS_SUBSTITUTIONS, ASSET_CATEGORIES, Added, AssetCategory, CATEGORY_CDRAGON_FILE, CATEGORY_META, CDRAGON, CategoryDataMap, type CategoryMeta, Champion, type ClientOptions, DDRAGON_REALM_NA, DDRAGON_REALM_TENCENT, DEFAULT_DATA_LANGUAGES, DEFAULT_RELEASE_BASE, type DataSource, FetchError, Lang, type LeagueFanAssetsClient, type LoadOptions, LootItem, PUBLISHED_DATA_CATEGORIES, Patch, RarityEnum, Skin, Skinline, Skins, type SplitSkinId, SummonerEmote, SummonerIcon, SummonerIconSet, TENCENT_PROFILE_ICON_CDN, Universe, VersionInfo, WardSkin, WardSkinSet, assetUrl, cdragonDataUrl, computeAdded, createClient, dataRoot, defaultPatchForCategory, fetchJson, filterLootChests, getGameVersion, getRarityUrl, getVersionInfo, loadCategory, modelviewerUrl, raritiesMap, releaseAssetName, releaseBaseUrl, releaseDataUrl, releaseManifestUrl, rewritePathsDeep, splitId, splitSkinId, substitute, transformChampions, transformLoot, transformSkinlines, transformSkins, transformSummonerEmotes, transformSummonerIconSets, transformSummonerIcons, transformUniverses, transformWardSkinSets, transformWardSkins };