/*! temmejs v1.0.9 | MIT | https://github.com/eoussama/temmejs#readme */ /** * @description * The hierarchy models that map the HTML skeleton. */ /** * @description * The labels of the options that can be inherited through the `from` option. */ type InheritableOption = "name" | "id" | "classes" | "attributes" | "dataset" | "content" | "childNodes"; /** * @description * The shape of the `from` referencing sub-object inside a sanitized hierarchy. */ type From = { /** The reference key of the element to inherit from, or `@selector` for an outer element. */ ref: string; /** The inheritance mode. */ mode: "append" | "override"; /** The option keys to include during inheritance. */ include: Array; /** The option keys to exclude during inheritance. */ exclude: Array; /** Child-node inheritance settings. */ children: { /** Whether child nodes should be inherited. */ allow: boolean; /** Where to place the inherited children. */ placement: "before" | "after"; }; }; /** * @description * The shape of the `content` sub-object inside a sanitized hierarchy. */ type Content = { /** The content type. */ type: "text" | "html"; /** The actual content string. */ value: string; }; /** * @description * A sanitized hierarchy object, as handed to the parse callbacks and returned by `parse`. * Templates share this shape, minus the `name`, `childNodes` and `templates` options. */ type Hierarchy = { /** The hierarchy's reference key. */ ref: string; /** The HTML element's tag name. */ name: string; /** The HTML element's id. */ id: string; /** The hierarchy object's temmeIds trail. */ temmeIds: Array; /** The HTML element's classes. */ classes: Array; /** The hierarchy object's templates. */ templates: Array; /** The hierarchy object's children. */ childNodes: Array; /** The HTML element's content. */ content: Content; /** The hierarchy object's referencing configuration. */ from: From; /** The HTML element's attributes. */ attributes: Record; /** The HTML element's dataset entries. */ dataset: Record; /** Index signature for dynamic key access during sanitization and validation. */ [key: string]: unknown; }; /** * @description * The scalar values accepted for attributes and dataset entries; they are stringified by the DOM. */ type AttributeValue = string | number | boolean; /** * @description * A template object as written by the user: a reusable, render-less set of options. */ type TemplateInput = { ref: string; id?: string; classes?: Array; content?: { type?: Content["type"]; value?: string; }; attributes?: Record; dataset?: Record; from?: FromInput; }; /** * @description * The `from` option as written by the user; only `ref` is required. */ type FromInput = { ref: string; mode?: From["mode"]; include?: Array; exclude?: Array; children?: { allow?: boolean; placement?: From["children"]["placement"]; }; }; /** * @description * A hierarchy object as written by the user, every option is optional. */ type HierarchyInput = Omit & { ref?: string; name?: string; childNodes?: Array; templates?: Array; }; /** * @description * The base class of every error Temme throws. */ declare class TemmyError extends Error { /** The name of the error. */ override readonly name: string; /** * @description * Constructs a Temme error. * * @param message The message of the error; when empty, `fallback` is used instead. * @param fallback The generic message describing this kind of error. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, fallback?: string, options?: ErrorOptions); } /** * @description * The error thrown when hierarchies (indirectly) inherit from themselves. */ declare class CircularReferenceError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param reference The offending reference. */ constructor(reference: string); } /** * @description * The error thrown when a hierarchy is not a valid plain object. */ declare class InvalidHierarchyError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * The error thrown when an option is not recognised. */ declare class InvalidOptionNameError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param option The offending option name. */ constructor(option: string); } /** * @description * The error thrown when an option's value has the wrong type. */ declare class InvalidOptionTypeError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param option The offending option name. * @param type The offending value type. */ constructor(option: string, type: string); } /** * @description * The error thrown when an option's value is not allowed. */ declare class InvalidOptionValueError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param option The offending option name. * @param value The offending value. */ constructor(option: string, value: string); } /** * @description * The error thrown when a reference points to nothing. */ declare class InvalidReferenceError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param reference The offending reference. */ constructor(reference: string); } /** * @description * The error thrown when a reference value is not valid. */ declare class InvalidReferenceOptionValueError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * The error thrown when a `from` option is not valid. */ declare class InvalidReferencingOptionError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * The error thrown when a sub-option is not recognised. */ declare class InvalidSubOptionNameError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param option The offending option name. * @param subOption The offending sub-option name. */ constructor(option: string, subOption: string); } /** * @description * The error thrown when a sub-option's value has the wrong type. */ declare class InvalidSubOptionTypeError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param subOption The offending sub-option name. * @param type The offending value type. */ constructor(subOption: string, type: string); } /** * @description * The error thrown when a sub-option's value is not allowed. */ declare class InvalidSubOptionValueError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param subOption The offending sub-option name. * @param value The offending value. */ constructor(subOption: string, value: string); } /** * @description * The error thrown when a target is not a valid HTML element. */ declare class InvalidTargetError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * The error thrown when a template does not have a `ref` option. */ declare class InvalidTemplateError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * The error thrown when a template uses an option templates can't have. */ declare class InvalidTemplateOptionError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param option The offending option name. */ constructor(option: string); } /** * @description * The error thrown when a template references a non-template object. */ declare class InvalidTemplateReferencingError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param ref The template reference. * @param target The referenced key. */ constructor(ref: string, target: string); } /** * @description * The error thrown when a hierarchy references an element out of its scope. */ declare class ReferenceOutOfScopeError extends TemmyError { /** The name of the error. */ override readonly name: string; /** * @description * Constructs the error. * * @param message The message of the error; a generic one is used when empty. * @param options The standard error options, e.g. the `cause`. */ constructor(message: string, options?: ErrorOptions); } /** * @description * Called once the whole tree has been rendered. May be async: a rejected promise is * reported with `console.warn` and never affects the caller. */ export type ParseEndCallback = (resultedHierarchy: Hierarchy) => void | Promise; /** * @description * Called right after each element is rendered (the root first, then depth-first). */ export type ParseNodeCallback = (temmeId: string, currentHierarchy: Hierarchy) => void; /** * @description * The outcome of `validate`. */ export type ValidationResult = { /** `true` when the hierarchy can be parsed. */ valid: boolean; /** The error `parse` would throw, or `null` when valid. */ error: unknown; }; /** * @description * The entry point of Temme — validates, sanitizes, resolves the references of and renders * a hierarchy object into a live HTML tree. * * The hierarchy object is completed in place (defaults, inherited values, temmeIds) and * returned. Parsing the returned object again renders the same tree. * * @param hierarchy The hierarchy object that maps the HTML skeleton. * @param target The HTML element that will host the rendered skeleton. * @param endCallback The function that executes when the skeleton has been fully rendered. * @param nodeCallback The function that executes whenever an individual element is rendered. * @returns {Hierarchy} The completed hierarchy object. * @throws {TemmyError} When the target or the hierarchy is invalid; the message is prefixed * with "[Temme]: ". Errors thrown by the callbacks are re-thrown untouched. */ export declare function parse(hierarchy: object, target: HTMLElement, endCallback?: ParseEndCallback, nodeCallback?: ParseNodeCallback): Hierarchy; /** * @description * Validates a hierarchy object without rendering or modifying it: runs every check `parse` * runs (options, templates, references, scopes and cycles) on a copy. * * @param hierarchy The hierarchy object to validate. * @returns {ValidationResult} `valid` is `true` when the hierarchy is well-formed, * otherwise `error` holds the error `parse` would throw. */ export declare function validate(hierarchy: object): ValidationResult; export { type AttributeValue, CircularReferenceError, type Content, type From, type FromInput, type Hierarchy, type HierarchyInput, type InheritableOption, InvalidHierarchyError, InvalidOptionNameError, InvalidOptionTypeError, InvalidOptionValueError, InvalidReferenceError, InvalidReferenceOptionValueError, InvalidReferencingOptionError, InvalidSubOptionNameError, InvalidSubOptionTypeError, InvalidSubOptionValueError, InvalidTargetError, InvalidTemplateError, InvalidTemplateOptionError, InvalidTemplateReferencingError, ReferenceOutOfScopeError, TemmyError, type TemplateInput }; //# sourceMappingURL=temme.d.mts.map