UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

142 lines 4.3 kB
export default TinyCookieConsent; export type Category = { /** * - Category label displayed to the user */ label: string; /** * - If true, cannot be disabled */ required: boolean; /** * - Default state (true = enabled, false = disabled) */ default: boolean; }; export type Config = { /** * - Consent message */ message: string; /** * - Text for "Accept All" button */ acceptText: string; /** * - Text for "Reject All" button */ rejectText: string; /** * - Text for "Manage Settings" button */ settingsText: string; /** * - List of cookie categories */ categories: Category[]; /** * - Key used to store preferences */ storageKey: string; /** * - Callback when preferences are saved */ onSave: (preferences: Object) => void; /** * - Animation duration in ms */ animationDuration?: number | undefined; /** * - Optional custom HTML renderer for consent bar */ renderBar?: ((config: Config) => string) | null | undefined; /** * - Optional custom HTML renderer for modal */ renderModal?: ((config: Config) => string) | null | undefined; }; /** * @typedef {Object} Category * @property {string} label - Category label displayed to the user * @property {boolean} required - If true, cannot be disabled * @property {boolean} default - Default state (true = enabled, false = disabled) */ /** * @typedef {Object} Config * @property {string} message - Consent message * @property {string} acceptText - Text for "Accept All" button * @property {string} rejectText - Text for "Reject All" button * @property {string} settingsText - Text for "Manage Settings" button * @property {Category[]} categories - List of cookie categories * @property {string} storageKey - Key used to store preferences * @property {(preferences: Object) => void} onSave - Callback when preferences are saved * @property {number} [animationDuration=400] - Animation duration in ms * @property {((config: Config) => string)|null} [renderBar] - Optional custom HTML renderer for consent bar * @property {((config: Config) => string)|null} [renderModal] - Optional custom HTML renderer for modal */ /** * CookieConsent * * A flexible and customizable cookie consent manager. * Features: * - Displays a consent bar with customizable text and buttons. * - Allows defining multiple cookie categories (required, analytics, ads, etc.). * - Stores user preferences in localStorage. * - Provides callbacks for when user accepts or denies categories. * - Fully customizable via configuration. */ declare class TinyCookieConsent { /** * @param {Config} config */ constructor(config: Config); /** @type {Record<string, boolean>} */ get preferences(): Record<string, boolean>; /** @param {Config} value */ set config(value: Config); /** @type {Config} */ get config(): Config; /** * Validates config object against jsDoc typedefs * @param {Partial<Config>} config */ validateConfig(config: Partial<Config>): void; /** * Validates a single category object * @param {Category} cat * @param {number} index */ validateCategory(cat: Category, index: number): void; /** * Loads saved preferences from localStorage * @returns {Record<string, boolean>|null} */ loadPreferences(): Record<string, boolean> | null; /** * Smoothly removes an element with fade-out/slide-out animation * @param {HTMLElement} el */ removeWithAnimation(el: HTMLElement): void; /** * Saves preferences to localStorage * * @param {Record<string, boolean>} prefs */ savePreferences(prefs: Record<string, boolean>): void; /** Shows the initial consent bar */ showConsentBar(): void; /** * Shows settings modal for fine-grained control * * @param {HTMLElement} bar */ showSettingsModal(bar: HTMLElement): void; /** * Checks if a category is allowed * @param {string} category * @returns {boolean} */ isAllowed(category: string): boolean; #private; } //# sourceMappingURL=TinyCookieConsent.d.mts.map