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.
98 lines • 4.89 kB
text/typescript
export default TinyHtmlAnchor;
/**
* TinyHtmlAnchor is a helper class for managing <a> elements.
* It provides strongly-typed getters and setters for attributes like href,
* target, rel, hreflang, referrerpolicy, and more.
*
* @example
* const link = new TinyHtmlAnchor({
* href: 'https://example.com',
* label: 'Visit Example',
* target: '_blank',
* rel: 'noopener noreferrer'
* });
*
* @extends TinyHtmlTemplate<HTMLAnchorElement>
*/
declare class TinyHtmlAnchor extends TinyHtmlTemplate<HTMLAnchorElement> {
/**
* Creates a new TinyHtmlAnchor instance.
* @param {Object} config - Configuration object.
* @param {string} config.href - Link URL (required).
* @param {string|Element|TinyHtml<any>} [config.label] - Link text or HTML.
* @param {string} [config.target] - Target attribute.
* @param {string} [config.rel] - Relationship of the linked resource.
* @param {string} [config.hreflang] - Language of the linked resource.
* @param {string|string[]} [config.ping] - URLs to send pings to.
* @param {'no-referrer'|'no-referrer-when-downgrade'|'origin'|'origin-when-cross-origin'|'same-origin'|'strict-origin'|'strict-origin-when-cross-origin'|'unsafe-url'} [config.referrerpolicy] - Referrer policy.
* @param {string} [config.type] - MIME type of the linked resource.
* @param {boolean|string|string[]} [config.attributionsrc] - Enables Attribution Reporting.
* @param {string|boolean} [config.download] - Download filename (or boolean to enable).
* @param {boolean} [config.allowHtml=false] - Whether to allow HTML inside the link.
* @param {string|string[]|Set<string>} [config.tags=[]] - Initial CSS classes.
* @param {string} [config.mainClass=''] - Main CSS class.
* @throws {TypeError} If any attribute is invalid.
*/
constructor({ href, label, target, rel, hreflang, ping, referrerpolicy, type, attributionsrc, download, allowHtml, tags, mainClass, }: {
href: string;
label?: string | Element | TinyHtml<any> | undefined;
target?: string | undefined;
rel?: string | undefined;
hreflang?: string | undefined;
ping?: string | string[] | undefined;
referrerpolicy?: "origin" | "same-origin" | "no-referrer" | "no-referrer-when-downgrade" | "origin-when-cross-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | undefined;
type?: string | undefined;
attributionsrc?: string | boolean | string[] | undefined;
download?: string | boolean | undefined;
allowHtml?: boolean | undefined;
tags?: string | string[] | Set<string> | undefined;
mainClass?: string | undefined;
});
/** @param {string} href */
set href(href: string);
/** @returns {string|null} */
get href(): string | null;
/** @param {string} target */
set target(target: string);
/** @returns {string|null} */
get target(): string | null;
/** @param {string} rel */
set rel(rel: string);
/** @returns {string|null} */
get rel(): string | null;
/** @param {string} hreflang */
set hreflang(hreflang: string);
/** @returns {string|null} */
get hreflang(): string | null;
/** @param {string|string[]} ping */
set ping(ping: string | string[]);
/** @returns {string|null} */
get ping(): string | null;
/** @param {'no-referrer'|'no-referrer-when-downgrade'|'origin'|'origin-when-cross-origin'|'same-origin'|'strict-origin'|'strict-origin-when-cross-origin'|'unsafe-url'} referrerpolicy */
set referrerpolicy(referrerpolicy: "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url");
/** @returns {string|null} */
get referrerpolicy(): string | null;
/** @param {string} type */
set type(type: string);
/** @returns {string|null} */
get type(): string | null;
/** @param {boolean|string|string[]} attributionsrc */
set attributionsrc(attributionsrc: boolean | string | string[]);
/** @returns {string|null} */
get attributionsrc(): string | null;
/** @param {string|boolean} download */
set download(download: string | boolean);
/** @returns {string|boolean|null} */
get download(): string | boolean | null;
/**
* Updates the link label with text, HTML, or an element.
*
* @param {string|Element|TinyHtml<any>} label - The new label to set.
* @param {boolean} [allowHtml=false] - Whether to allow raw HTML or DOM elements instead of plain text.
* @returns {this}
*/
setLabel(label: string | Element | TinyHtml<any>, allowHtml?: boolean): this;
}
import TinyHtmlTemplate from './TinyHtmlTemplate.mjs';
import TinyHtml from '../TinyHtml.mjs';
//# sourceMappingURL=TinyHtmlAnchor.d.mts.map