@xtreat/solid-iconify
Version:
A reactive and first class native Solid Iconify icon component
92 lines (78 loc) • 2.8 kB
TypeScript
import * as solid_js from 'solid-js';
import { JSX } from 'solid-js';
import { IFilterXSSOptions } from 'xss';
type LRUOptions = {
strategy: "static";
limit: number;
} | {
strategy: "grow";
initial?: number;
} | {
strategy: "unlimited";
};
declare class LRUCache<K, V> implements Iterable<[K, V]> {
private cache;
private readonly strategy;
capacity: number;
constructor(cap: number | LRUOptions, entries?: Iterable<[K, V]>);
get size(): number;
get(key: K): V | undefined;
set(key: K, value: V): this;
delete(key: K): V | undefined;
entries(): IterableIterator<[K, V]>;
[Symbol.iterator](): IterableIterator<[K, V]>;
}
/* ───────── helpers ───────── */
type NonEmptyArray<T> = readonly [T, ...T[]];
type SanitizeToggle =
| {
readonly SANITIZE: true;
readonly SANITIZE_OPTIONS?: Partial<IFilterXSSOptions>;
}
| {
readonly SANITIZE?: false;
readonly SANITIZE_OPTIONS?: never;
};
/* ───────── types ───────── */
type IconifySpecifier = string;
type IconifyFlip = "horizontal" | "vertical" | "horizontal,vertical";
type IconifyRotate = "90deg" | "180deg" | "270deg";
/* ───────── shapes ───────── */
interface IconifyMockParams {
flip?: IconifyFlip;
rotate?: IconifyRotate;
box?: boolean;
}
interface IconifyVisibility {
showLoading?: boolean;
showError?: boolean;
}
interface IconifyIconProps
extends JSX.SvgSVGAttributes<SVGSVGElement>,
IconifyVisibility,
IconifyMockParams {
icon: IconifySpecifier;
}
/* ───────── data structures ───────── */
interface IconifyData {
vBox: number[];
body: string;
}
type IconifyCollectionCache = Map<string, IconifyIconCache>;
type IconifyIconCache = LRUCache<string, Promise<IconifyData>>;
type IconifyCacheConfiguration =
| { strategy: "no-cache" }
| { strategy: "unlimited" }
| { strategy: "grow"; initial: number }
| { strategy: "static"; limit: number }
| number; // infer to be static
/* ───────── configuration ───────── */
type IconifyConfig = Readonly<{
ICONIFY_API: string | URL | NonEmptyArray<string | URL>;
REQUEST_OPTIONS: RequestInit;
CACHE: IconifyCacheConfiguration;
}> &
SanitizeToggle;
declare function configureIconify(patch: Partial<IconifyConfig>): void;
declare function Icon(props: IconifyIconProps): solid_js.JSX.Element;
export { type IconifyCacheConfiguration, type IconifyCollectionCache, type IconifyConfig, type IconifyData, type IconifyFlip, type IconifyIconCache, type IconifyIconProps, type IconifyMockParams, type IconifyRotate, type IconifySpecifier, type IconifyVisibility, type SanitizeToggle, configureIconify, Icon as default };