{"version":3,"file":"temme.browser.mjs","names":["parse","Validator.isValidHTMLElement","toError","value","message","isObject","isPromise","toFailure","error","tryCatchSync","fn","TemmyError","fallback","options","InvalidTargetError","idfy","length","isTemplate","temmeId","generateTemmeId","used","temmeIds","hierarchy","child","template","getTemmeId","key","i","resolved","isResolved","markResolved","clone","copy","entry","uniqueSorted","list","Option","label","type","values","keys","defaultValue","option","AttributesOption","incoming","attributes","element","attr","name","ChildNodesOption","childNodes","allow","placement","ClassesOption","classes","ContentTypeSubOption","ValueSubOption","ContentOption","content","DatasetOption","dataset","RefOption","ChildrenAllowSubOption","PlacementSubOption","ChildrenSubOption","INHERITABLE","IncludeSubOption","ExcludeSubOption","ModeSubOption","FromOption","IdOption","id","NameOption","TemmeIdsOption","TemplatesOption","forbiddenOptions","registry","getOptions","findOption","parse$1","topParent","parent","nodeCallback","CircularReferenceError","reference","InvalidReferenceError","InvalidReferenceOptionValueError","InvalidTemplateReferencingError","ref","target","ReferenceOutOfScopeError","process","nodes","collect","root","context","node","pending","validateReference","validateTemplateReference","validateScope","resolve","depth","findReferenced","candidate","hasInnerReference","queryOuterElement","dom","selector","getInheritedLabels","include","exclude","inheritFromElement","inheritFromHierarchy","source","inheritChildNodes","descendant","copies","stripReferences","sanitize","sanitizeOption","subOption","InvalidHierarchyError","InvalidOptionNameError","InvalidOptionTypeError","InvalidReferencingOptionError","InvalidSubOptionNameError","InvalidSubOptionTypeError","InvalidSubOptionValueError","InvalidTemplateError","InvalidTemplateOptionError","isValidHierarchy","isValidHTMLElement","HTMLElementOfRealm","validateOptions","valid","validateSubOptions","validateFrom","validateTemplates","subValue","subOptions","optionName","from","InvalidOptionValueError","parse","prepare","result","endCallback","validate","completed"],"sources":["../node_modules/.pnpm/@eoussama+core@0.1.2/node_modules/@eoussama/core/dist/index.mjs","../src/modules/models/TemmyError.ts","../src/modules/errors/InvalidTargetError.ts","../src/modules/idfier.ts","../src/modules/utils.ts","../src/modules/models/Option.ts","../src/modules/options/AttributesOption.ts","../src/modules/options/ChildrenNodesOption.ts","../src/modules/options/ClassesOption.ts","../src/modules/options/sub-options/ContentTypeSubOption.ts","../src/modules/options/sub-options/ValueSubOption.ts","../src/modules/options/ContentOption.ts","../src/modules/options/DatasetOption.ts","../src/modules/options/RefOption.ts","../src/modules/options/sub-options/ChildrenAllowSubOption.ts","../src/modules/options/sub-options/PlacementSubOption.ts","../src/modules/options/sub-options/ChildrenSubOption.ts","../src/modules/options/sub-options/IncludeSubOption.ts","../src/modules/options/sub-options/ExcludeSubOption.ts","../src/modules/options/sub-options/ModeSubOption.ts","../src/modules/options/FromOption.ts","../src/modules/options/IdOption.ts","../src/modules/options/NameOption.ts","../src/modules/options/TemmeIdsOption.ts","../src/modules/options/TemplatesOption.ts","../src/modules/options.ts","../src/modules/parser.ts","../src/modules/errors/CircularReferenceError.ts","../src/modules/errors/InvalidReferenceError.ts","../src/modules/errors/InvalidReferenceOptionValueError.ts","../src/modules/errors/InvalidTemplateReferencingError.ts","../src/modules/errors/ReferenceOutOfScopeError.ts","../src/modules/referencer.ts","../src/modules/sanitizer.ts","../src/modules/errors/InvalidHierarchyError.ts","../src/modules/errors/InvalidOptionNameError.ts","../src/modules/errors/InvalidOptionTypeError.ts","../src/modules/errors/InvalidReferencingOptionError.ts","../src/modules/errors/InvalidSubOptionNameError.ts","../src/modules/errors/InvalidSubOptionTypeError.ts","../src/modules/errors/InvalidSubOptionValueError.ts","../src/modules/errors/InvalidTemplateError.ts","../src/modules/errors/InvalidTemplateOptionError.ts","../src/modules/validator.ts","../src/modules/errors/InvalidOptionValueError.ts","../src/temme.ts"],"sourcesContent":["//#region src/errors/timeout.error.ts\nvar TimeoutError = class extends Error {\n\tname = \"TimeoutError\";\n};\n//#endregion\n//#region src/helpers/error.helper.ts\nfunction toError(value) {\n\tif (value instanceof Error) return value;\n\tif (typeof value === \"string\") return new Error(value);\n\tlet message;\n\ttry {\n\t\tmessage = JSON.stringify(value) ?? String(value);\n\t} catch {\n\t\tmessage = String(value);\n\t}\n\treturn new Error(message, { cause: value });\n}\nfunction invariant(condition, message) {\n\tif (!condition) throw new Error(typeof message === \"function\" ? message() : message ?? \"Invariant failed\");\n}\n//#endregion\n//#region src/helpers/guard.helper.ts\nfunction isNil(value) {\n\treturn value === null || value === void 0;\n}\nfunction isDefined(value) {\n\treturn value !== null && value !== void 0;\n}\nfunction isPrimitive(value) {\n\treturn typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\";\n}\nfunction isFunction(value) {\n\treturn typeof value === \"function\";\n}\nfunction isObject(value) {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n//#endregion\n//#region src/helpers/promise.helper.ts\nfunction isPromise(value) {\n\treturn (typeof value === \"object\" && value !== null || typeof value === \"function\") && \"then\" in value && typeof value.then === \"function\";\n}\nfunction deferred() {\n\tlet resolve;\n\tlet reject;\n\treturn {\n\t\tpromise: new Promise((res, rej) => {\n\t\t\tresolve = res;\n\t\t\treject = rej;\n\t\t}),\n\t\tresolve,\n\t\treject\n\t};\n}\n//#endregion\n//#region src/helpers/timer.helper.ts\nconst MAX_DELAY = 2147483647;\nfunction toDelay(ms) {\n\treturn Number.isNaN(ms) ? 0 : Math.min(Math.max(ms, 0), MAX_DELAY);\n}\nfunction wait(ms, options = {}) {\n\tconst { signal } = options;\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(signal.reason);\n\t\t\treturn;\n\t\t}\n\t\tconst timer = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t}, toDelay(ms));\n\t\tfunction onAbort() {\n\t\t\tclearTimeout(timer);\n\t\t\treject(signal?.reason);\n\t\t}\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\nfunction withTimeout(promise, ms, options = {}) {\n\tconst { message = `Operation timed out after ${ms}ms` } = options;\n\treturn new Promise((resolve, reject) => {\n\t\tconst timer = setTimeout(() => reject(new TimeoutError(message)), toDelay(ms));\n\t\tpromise.then((value) => {\n\t\t\tclearTimeout(timer);\n\t\t\tresolve(value);\n\t\t}, (error) => {\n\t\t\tclearTimeout(timer);\n\t\t\treject(error);\n\t\t});\n\t});\n}\n//#endregion\n//#region src/helpers/retry.helper.ts\nasync function retry(fn, options = {}) {\n\tconst { retries = 3, delay = 0, signal, shouldRetry } = options;\n\tconst run = async (attempt) => {\n\t\tsignal?.throwIfAborted();\n\t\ttry {\n\t\t\treturn await fn(attempt);\n\t\t} catch (error) {\n\t\t\tif (attempt > retries || shouldRetry && !shouldRetry(error, attempt)) throw error;\n\t\t\tawait wait(typeof delay === \"function\" ? delay(attempt, error) : delay, { signal });\n\t\t\treturn run(attempt + 1);\n\t\t}\n\t};\n\treturn run(1);\n}\n//#endregion\n//#region src/helpers/try-catch.helper.ts\nfunction toFailure(error) {\n\treturn error ?? toError(error);\n}\nasync function tryCatch(fn) {\n\ttry {\n\t\treturn [null, await (typeof fn === \"function\" ? fn() : fn)];\n\t} catch (error) {\n\t\treturn [toFailure(error), null];\n\t}\n}\nfunction tryCatchSync(fn) {\n\ttry {\n\t\treturn [null, fn()];\n\t} catch (error) {\n\t\treturn [toFailure(error), null];\n\t}\n}\n//#endregion\nexport { TimeoutError, deferred, invariant, isDefined, isFunction, isNil, isObject, isPrimitive, isPromise, retry, toError, tryCatch, tryCatchSync, wait, withTimeout };\n","/**\n * @description\n * The base class of every error Temme throws.\n */\nexport default class TemmyError extends Error {\n  /** The name of the error. */\n  public override readonly name: string = \"TemmyError\";\n\n\n  /**\n   * @description\n   * Constructs a Temme error.\n   *\n   * @param message The message of the error; when empty, `fallback` is used instead.\n   * @param fallback The generic message describing this kind of error.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, fallback: string = \"Temme isn't feeling good\", options?: ErrorOptions) {\n    super(message.length > 0 ? message : fallback, options);\n  }\n}\n","/**\n * @description\n * The error thrown when a target is not a valid HTML element.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a target is not a valid HTML element.\n */\nexport default class InvalidTargetError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidTargetError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"The target is not a valid HTML element\", options);\n  }\n}\n","/**\n * @description\n * Everything related to assigning internal temmeId identifiers to hierarchy objects.\n */\n\n\nimport type { Hierarchy } from \"./models/Hierarchy\";\n\n\n\n/** The length of a hierarchy's temmeId. */\nexport const HIERARCHY_ID_LENGTH = 6;\n\n/** The length of a template's temmeId. */\nexport const TEMPLATE_ID_LENGTH = 4;\n\n/** The characters temmeIds are made of. */\nconst ALPHABET = \"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\n\n/**\n * @description\n * Assigns a temmeId trail to a hierarchy object and all of its descendants and templates.\n * Every temmeId is unique within the tree.\n *\n * @param hierarchy The hierarchy object to assign a temmeId to.\n * @param temmeIds The trail of temmeIds leading up to the current hierarchy object.\n * @param isTemplate Whether the object is a template (4-character id) or not (6-character id).\n * @param used The temmeIds already handed out in this tree.\n * @returns {void}\n */\nexport function idfy(\n  hierarchy: Hierarchy,\n  temmeIds: Array<string> = [],\n  isTemplate: boolean = false,\n  used: Set<string> = new Set(),\n): void {\n  const length = isTemplate ? TEMPLATE_ID_LENGTH : HIERARCHY_ID_LENGTH;\n  let temmeId = generateTemmeId(length);\n\n  while (used.has(temmeId)) {\n    temmeId = generateTemmeId(length);\n  }\n\n  used.add(temmeId);\n  hierarchy.temmeIds = [...temmeIds, temmeId];\n\n  hierarchy.childNodes?.forEach((child: Hierarchy) => idfy(child, hierarchy.temmeIds, false, used));\n  hierarchy.templates?.forEach((template: Hierarchy) => idfy(template, hierarchy.temmeIds, true, used));\n}\n\n\n/**\n * @description\n * Returns the last (innermost) temmeId of a hierarchy or template object.\n *\n * @param hierarchy The hierarchy or template to read the temmeId from.\n * @returns {string} The innermost temmeId.\n */\nexport function getTemmeId(hierarchy: Hierarchy): string {\n  return hierarchy.temmeIds[hierarchy.temmeIds.length - 1] as string;\n}\n\n\n/**\n * @description\n * Generates a random temmeId of the given length.\n *\n * @param length The number of characters.\n * @returns {string} The generated temmeId.\n */\nexport function generateTemmeId(length: number): string {\n  let key = \"\";\n\n  for (let i = 0; i < length; i++) {\n    key += ALPHABET[Math.floor(Math.random() * ALPHABET.length)];\n  }\n\n  return key;\n}\n","/**\n * @description\n * Small, dependency-free helpers shared by the hierarchy pipeline.\n */\n\n\nimport { isObject } from \"@eoussama/core\";\n\n\n\n/**\n * @description\n * The hierarchy objects whose inheritance has already been applied.\n * Re-parsing such an object renders it as-is instead of inheriting a second time.\n */\nconst resolved: WeakSet<object> = /* @__PURE__ */ new WeakSet();\n\n\n/**\n * @description\n * Checks whether a hierarchy object has already been through reference resolution.\n *\n * @param hierarchy The hierarchy object to check.\n * @returns {boolean} `true` when the hierarchy has been resolved before.\n */\nexport function isResolved(hierarchy: object): boolean {\n  return resolved.has(hierarchy);\n}\n\n\n/**\n * @description\n * Marks a hierarchy object as resolved.\n *\n * @param hierarchy The hierarchy object to mark.\n * @returns {void}\n */\nexport function markResolved(hierarchy: object): void {\n  resolved.add(hierarchy);\n}\n\n\n/**\n * @description\n * Deep-copies plain data (arrays and plain objects), leaving every other value as-is.\n * The resolved state of copied hierarchy objects is carried over to their copies.\n *\n * @param value The value to copy.\n * @returns {T} The copy.\n */\nexport function clone<T>(value: T): T {\n  if (Array.isArray(value)) {\n    return value.map(clone) as T;\n  }\n\n  if (isObject(value)) {\n    const copy: Record<string, unknown> = {};\n\n    for (const [key, entry] of Object.entries(value)) {\n      copy[key] = clone(entry);\n    }\n\n    if (isResolved(value)) {\n      markResolved(copy);\n    }\n\n    return copy as T;\n  }\n\n  return value;\n}\n\n\n/**\n * @description\n * Returns the distinct entries of a list, sorted.\n *\n * @param list The list to normalise.\n * @returns {Array<T>} A new sorted list without duplicates.\n */\nexport function uniqueSorted<T>(list: Array<T>): Array<T> {\n  return [...new Set(list)].sort();\n}\n","/**\n * @description\n * The hierarchy's option model — defines what a valid option looks like.\n */\n\n\nimport type { Hierarchy } from \"./Hierarchy\";\nimport { clone } from \"../utils\";\n\n\n\n/**\n * @description\n * The value types an option can be declared with.\n */\nexport type OptionType = \"string\" | \"boolean\" | \"array\" | \"object\";\n\n\n/**\n * @description\n * Base class for every hierarchy option and sub-option.\n * Options that need to inherit, read from outer elements or render override the matching methods.\n */\nexport default class Option {\n  /** The name / label of the option. */\n  public readonly label: string;\n\n  /** The expected data type of the option's value. */\n  public readonly type: OptionType;\n\n  /** The set of allowed values (or allowed array entries); empty means unrestricted. */\n  public readonly values: ReadonlyArray<unknown>;\n\n  /** The sub-options of an object option, keyed by label. */\n  public readonly keys: Readonly<Record<string, Option>> | undefined;\n\n  /** The default value, built from the sub-options' defaults when there are any. */\n  private readonly defaultValue: unknown;\n\n\n  /**\n   * @description\n   * Constructs an Option with the given metadata.\n   *\n   * @param label The name of the option.\n   * @param type The expected data type.\n   * @param values The set of allowed values.\n   * @param defaultValue The default value (ignored when `keys` are given).\n   * @param keys The sub-options of an object option.\n   */\n  constructor(\n    label: string,\n    type: OptionType,\n    values: ReadonlyArray<unknown> = [],\n    defaultValue: unknown = undefined,\n    keys?: Record<string, Option>,\n  ) {\n    this.label = label;\n    this.type = type;\n    this.values = values;\n    this.keys = keys;\n    this.defaultValue = defaultValue;\n  }\n\n\n  /**\n   * @description\n   * Builds a fresh copy of the default value, so that no two hierarchies ever share\n   * (and mutate) the same default object.\n   *\n   * @returns {unknown} A new default value.\n   */\n  public createDefault(): unknown {\n    if (this.keys !== undefined) {\n      return Object.fromEntries(\n        Object.values(this.keys).map((key: Option) => [key.label, key.createDefault()]),\n      );\n    }\n\n    return clone(this.defaultValue);\n  }\n\n\n  /**\n   * @description\n   * Performs the inheritance process for this option on a hierarchy.\n   * No-op unless overridden.\n   *\n   * @param _hierarchy The hierarchy object that is inheriting.\n   * @param _value The (already copied) value to inherit.\n   * @returns {void}\n   */\n  public inherit(_hierarchy: Hierarchy, _value: unknown): void {}\n\n\n  /**\n   * @description\n   * Extracts this option's value from an outer HTML element.\n   * Returns `null` (nothing to inherit) unless overridden.\n   *\n   * @param _element The HTML element to read from.\n   * @returns {unknown} The extracted value, or `null` if not applicable.\n   */\n  public getKeyFromElement(_element: Element): unknown {\n    return null;\n  }\n\n\n  /**\n   * @description\n   * Applies this option's value to a rendered HTML element. No-op unless overridden.\n   *\n   * @param _element The HTML element to apply values to.\n   * @param _hierarchy The hierarchy object supplying the values.\n   * @returns {void}\n   */\n  public parse(_element: HTMLElement, _hierarchy: Hierarchy): void {}\n\n\n  /**\n   * @description\n   * Returns the type name of a value, distinguishing arrays and `null` from objects.\n   *\n   * @param value The value to inspect.\n   * @returns {string} The detected type.\n   */\n  public static typeOf(value: unknown): string {\n    if (value === null) {\n      return \"null\";\n    }\n\n    return Array.isArray(value) ? \"array\" : typeof value;\n  }\n\n\n  /**\n   * @description\n   * Validates that a value has the option's expected data type.\n   *\n   * @param value The value to check.\n   * @param option The option the value belongs to.\n   * @returns {{ valid: boolean; type: string }} Validation result and the detected type.\n   */\n  public static validateOptionType(value: unknown, option: Option): { valid: boolean; type: string } {\n    const type = Option.typeOf(value);\n\n    return { valid: type === option.type, type };\n  }\n\n\n  /**\n   * @description\n   * Validates that a value is one of the option's allowed values.\n   * For array options, every entry must be allowed.\n   *\n   * @param value The value to check.\n   * @param option The option the value belongs to.\n   * @returns {boolean} `true` when the value is valid.\n   */\n  public static validateOptionValue(value: unknown, option: Option): boolean {\n    if (option.values.length === 0) {\n      return true;\n    }\n\n    const entries = option.type === \"array\" ? value as Array<unknown> : [value];\n\n    return entries.every((entry: unknown) => option.values.includes(entry));\n  }\n}\n","/**\n * @description\n * The \"attributes\" option model — manages the HTML attribute map of a hierarchy element.\n */\n\n\nimport type { AttributeValue, Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `attributes` option, which sets or inherits an element's HTML attributes.\n */\nexport default class AttributesOption extends Option {\n  /**\n   * @description\n   * Constructs an AttributesOption with its default metadata.\n   */\n  constructor() {\n    super(\"attributes\", \"object\", [], {});\n  }\n\n\n  /**\n   * @description\n   * Inherits attributes. In \"append\" mode existing attributes win; otherwise incoming ones do.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param attributes The attribute map to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, attributes: unknown): void {\n    const incoming = attributes as Record<string, string>;\n\n    hierarchy.attributes = hierarchy.from.mode === \"append\"\n      ? { ...incoming, ...hierarchy.attributes }\n      : { ...hierarchy.attributes, ...incoming };\n  }\n\n\n  /**\n   * @description\n   * Reads the attributes of an outer element, excluding `id`, `class` and `data-*`\n   * (those are covered by their own options).\n   *\n   * @param element The HTML element to read attributes from.\n   * @returns {Record<string, string>} A map of attribute names to values.\n   */\n  public override getKeyFromElement(element: Element): unknown {\n    return Object.fromEntries(\n      Array.from(element.attributes)\n        .filter((attr: Attr) => attr.name !== \"id\" && attr.name !== \"class\" && !attr.name.startsWith(\"data-\"))\n        .map((attr: Attr) => [attr.name, attr.value]),\n    );\n  }\n\n\n  /**\n   * @description\n   * Applies the attribute map to the target HTML element.\n   *\n   * @param element The HTML element to set attributes on.\n   * @param hierarchy The hierarchy object supplying the attributes.\n   * @returns {void}\n   */\n  public override parse(element: HTMLElement, hierarchy: Hierarchy): void {\n    for (const [name, value] of Object.entries(hierarchy.attributes as Record<string, AttributeValue>)) {\n      element.setAttribute(name, String(value));\n    }\n  }\n}\n","/**\n * @description\n * The \"childNodes\" option model — holds the child hierarchies of a hierarchy element.\n */\n\n\nimport type { Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `childNodes` option, which lists (and can inherit) an element's children.\n * Children are never read from outer elements, as DOM nodes do not map to hierarchies.\n */\nexport default class ChildNodesOption extends Option {\n  /**\n   * @description\n   * Constructs a ChildNodesOption with its default metadata.\n   */\n  constructor() {\n    super(\"childNodes\", \"array\", [], []);\n  }\n\n\n  /**\n   * @description\n   * Inherits child nodes when `from.children.allow` is set. In \"append\" mode they are placed\n   * before or after the existing children (`from.children.placement`); otherwise they replace them.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param childNodes The (already copied) child hierarchies to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, childNodes: unknown): void {\n    const incoming = childNodes as Array<Hierarchy>;\n    const { allow, placement } = hierarchy.from.children;\n\n    if (!allow) {\n      return;\n    }\n\n    if (hierarchy.from.mode === \"override\") {\n      hierarchy.childNodes = incoming;\n    }\n    else {\n      hierarchy.childNodes = placement === \"before\"\n        ? [...incoming, ...hierarchy.childNodes]\n        : [...hierarchy.childNodes, ...incoming];\n    }\n  }\n}\n","/**\n * @description\n * The \"classes\" option model — manages the CSS class list of a hierarchy element.\n */\n\n\nimport type { Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\nimport { uniqueSorted } from \"../utils\";\n\n\n\n/**\n * @description\n * Defines the `classes` option, which sets or inherits the element's CSS class list.\n */\nexport default class ClassesOption extends Option {\n  /**\n   * @description\n   * Constructs a ClassesOption with its default metadata.\n   */\n  constructor() {\n    super(\"classes\", \"array\", [], []);\n  }\n\n\n  /**\n   * @description\n   * Inherits CSS classes. In \"append\" mode they are merged with the existing ones,\n   * otherwise they replace them. The result is de-duplicated and sorted.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param classes The class list to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, classes: unknown): void {\n    const incoming = classes as Array<string>;\n    const merged = hierarchy.from.mode === \"append\" ? [...hierarchy.classes, ...incoming] : incoming;\n\n    hierarchy.classes = uniqueSorted(merged);\n  }\n\n\n  /**\n   * @description\n   * Reads the class list of an outer element.\n   *\n   * @param element The HTML element to read classes from.\n   * @returns {Array<string>} The element's class names.\n   */\n  public override getKeyFromElement(element: Element): unknown {\n    return [...element.classList];\n  }\n\n\n  /**\n   * @description\n   * Applies the class list to the target HTML element.\n   *\n   * @param element The HTML element to add classes to.\n   * @param hierarchy The hierarchy object supplying the class list.\n   * @returns {void}\n   */\n  public override parse(element: HTMLElement, hierarchy: Hierarchy): void {\n    // Some DOM implementations create an empty `class` attribute when adding no class.\n    if (hierarchy.classes.length > 0) {\n      element.classList.add(...hierarchy.classes);\n    }\n  }\n}\n","/**\n * @description\n * The \"type\" sub-option model for the `content` option.\n */\n\n\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * Defines the content type (\"text\" | \"html\") for an element's content option.\n */\nexport default class ContentTypeSubOption extends Option {\n  /**\n   * @description\n   * Constructs a ContentTypeSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"type\", \"string\", [\"text\", \"html\"], \"text\");\n  }\n}\n","/**\n * @description\n * The \"value\" sub-option model for the `content` option.\n */\n\n\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * Holds the actual content string value for an element's `content` option.\n */\nexport default class ValueSubOption extends Option {\n  /**\n   * @description\n   * Constructs a ValueSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"value\", \"string\", [], \"\");\n  }\n}\n","/**\n * @description\n * The \"content\" option model — manages the text or HTML content of a hierarchy element.\n */\n\n\nimport type { Content, Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\nimport ContentTypeSubOption from \"./sub-options/ContentTypeSubOption\";\nimport ValueSubOption from \"./sub-options/ValueSubOption\";\n\n\n\n/**\n * @description\n * Defines the `content` option, which controls the inner text or HTML of an element.\n */\nexport default class ContentOption extends Option {\n  /**\n   * @description\n   * Constructs a ContentOption with its `type` and `value` sub-options.\n   */\n  constructor() {\n    super(\"content\", \"object\", [], undefined, {\n      type: new ContentTypeSubOption(),\n      value: new ValueSubOption(),\n    });\n  }\n\n\n  /**\n   * @description\n   * Inherits non-empty content. In \"append\" mode the incoming value is appended after the\n   * existing one (separated by a space) and the existing type is kept; empty existing content\n   * simply takes the incoming content. Otherwise the incoming content replaces it.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param content The content object to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, content: unknown): void {\n    const incoming = content as Content;\n\n    if (incoming.value === \"\") {\n      return;\n    }\n\n    if (hierarchy.from.mode === \"append\" && hierarchy.content.value !== \"\") {\n      hierarchy.content = { ...hierarchy.content, value: `${hierarchy.content.value} ${incoming.value}` };\n    }\n    else {\n      hierarchy.content = { ...incoming };\n    }\n  }\n\n\n  /**\n   * @description\n   * Reads the content of an outer element as HTML.\n   *\n   * @param element The HTML element to read content from.\n   * @returns {Content} The element's inner HTML as a content object.\n   */\n  public override getKeyFromElement(element: Element): unknown {\n    return { type: \"html\", value: element.innerHTML };\n  }\n\n\n  /**\n   * @description\n   * Applies non-empty content to the target HTML element.\n   *\n   * @param element The HTML element to set content on.\n   * @param hierarchy The hierarchy object supplying the content.\n   * @returns {void}\n   */\n  public override parse(element: HTMLElement, hierarchy: Hierarchy): void {\n    if (hierarchy.content.value === \"\") {\n      return;\n    }\n\n    if (hierarchy.content.type === \"text\") {\n      element.textContent = hierarchy.content.value;\n    }\n    else {\n      element.innerHTML = hierarchy.content.value;\n    }\n  }\n}\n","/**\n * @description\n * The \"dataset\" option model — manages the `data-*` attributes of a hierarchy element.\n */\n\n\nimport type { AttributeValue, Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `dataset` option, which sets or inherits an element's `data-*` attributes.\n */\nexport default class DatasetOption extends Option {\n  /**\n   * @description\n   * Constructs a DatasetOption with its default metadata.\n   */\n  constructor() {\n    super(\"dataset\", \"object\", [], {});\n  }\n\n\n  /**\n   * @description\n   * Inherits dataset entries. In \"append\" mode existing entries win; otherwise incoming ones do.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param dataset The dataset map to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, dataset: unknown): void {\n    const incoming = dataset as Record<string, string>;\n\n    hierarchy.dataset = hierarchy.from.mode === \"append\"\n      ? { ...incoming, ...hierarchy.dataset }\n      : { ...hierarchy.dataset, ...incoming };\n  }\n\n\n  /**\n   * @description\n   * Reads the dataset of an outer element.\n   *\n   * @param element The HTML element to read from.\n   * @returns {Record<string, string>} The element's dataset entries.\n   */\n  public override getKeyFromElement(element: Element): unknown {\n    return Object.fromEntries(Object.entries((element as HTMLElement).dataset));\n  }\n\n\n  /**\n   * @description\n   * Applies the dataset entries to the target HTML element.\n   *\n   * @param element The HTML element to set dataset entries on.\n   * @param hierarchy The hierarchy object supplying the dataset.\n   * @returns {void}\n   */\n  public override parse(element: HTMLElement, hierarchy: Hierarchy): void {\n    for (const [key, value] of Object.entries(hierarchy.dataset as Record<string, AttributeValue>)) {\n      element.dataset[key] = String(value);\n    }\n  }\n}\n","/**\n * @description\n * The \"ref\" option model — stores the reference key of a hierarchy element.\n */\n\n\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `ref` option, which identifies a hierarchy element for later referencing.\n */\nexport default class RefOption extends Option {\n  /**\n   * @description\n   * Constructs a RefOption with its default metadata.\n   */\n  constructor() {\n    super(\"ref\", \"string\", [], \"\");\n  }\n}\n","/**\n * @description\n * The \"allow\" sub-option for the `children` sub-option of `from`.\n */\n\n\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * Defines whether child nodes are included when inheriting from a referenced hierarchy.\n */\nexport default class ChildrenAllowSubOption extends Option {\n  /**\n   * @description\n   * Constructs a ChildrenAllowSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"allow\", \"boolean\", [], false);\n  }\n}\n","/**\n * @description\n * The \"placement\" sub-option model for the `children` sub-option of `from`.\n */\n\n\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * Defines where inherited child nodes are placed (\"before\" | \"after\").\n */\nexport default class PlacementSubOption extends Option {\n  /**\n   * @description\n   * Constructs a PlacementSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"placement\", \"string\", [\"before\", \"after\"], \"after\");\n  }\n}\n","/**\n * @description\n * The \"children\" sub-option model for the `from` option.\n */\n\n\nimport Option from \"../../models/Option\";\nimport ChildrenAllowSubOption from \"./ChildrenAllowSubOption\";\nimport PlacementSubOption from \"./PlacementSubOption\";\n\n\n\n/**\n * @description\n * Defines the child-node inheritance behaviour inside the `from` option.\n */\nexport default class ChildrenSubOption extends Option {\n  /**\n   * @description\n   * Constructs a ChildrenSubOption with its `allow` and `placement` sub-options.\n   */\n  constructor() {\n    super(\"children\", \"object\", [], undefined, {\n      allow: new ChildrenAllowSubOption(),\n      placement: new PlacementSubOption(),\n    });\n  }\n}\n","/**\n * @description\n * The \"include\" sub-option model for the `from` option.\n */\n\n\nimport type { InheritableOption } from \"../../models/Hierarchy\";\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * The option labels that can participate in inheritance.\n */\nexport const INHERITABLE: ReadonlyArray<InheritableOption> = [\n  \"name\",\n  \"id\",\n  \"classes\",\n  \"attributes\",\n  \"dataset\",\n  \"content\",\n  \"childNodes\",\n];\n\n\n/**\n * @description\n * Specifies which option keys should be included during inheritance.\n */\nexport default class IncludeSubOption extends Option {\n  /**\n   * @description\n   * Constructs an IncludeSubOption with its default metadata.\n   */\n  constructor() {\n    // The default is sorted like user-provided lists, so sanitizing stays idempotent.\n    super(\"include\", \"array\", INHERITABLE, [...INHERITABLE].sort());\n  }\n}\n","/**\n * @description\n * The \"exclude\" sub-option model for the `from` option.\n */\n\n\nimport Option from \"../../models/Option\";\nimport { INHERITABLE } from \"./IncludeSubOption\";\n\n\n\n/**\n * @description\n * Specifies which option keys should be excluded from inheritance.\n */\nexport default class ExcludeSubOption extends Option {\n  /**\n   * @description\n   * Constructs an ExcludeSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"exclude\", \"array\", INHERITABLE, []);\n  }\n}\n","/**\n * @description\n * The \"mode\" sub-option model for the `from` option.\n */\n\n\nimport Option from \"../../models/Option\";\n\n\n\n/**\n * @description\n * Defines the inheritance mode (\"append\" | \"override\") for the `from` option.\n */\nexport default class ModeSubOption extends Option {\n  /**\n   * @description\n   * Constructs a ModeSubOption with its default metadata.\n   */\n  constructor() {\n    super(\"mode\", \"string\", [\"append\", \"override\"], \"append\");\n  }\n}\n","/**\n * @description\n * The \"from\" option model — defines the referencing and inheritance configuration.\n */\n\n\nimport Option from \"../models/Option\";\nimport RefOption from \"./RefOption\";\nimport ChildrenSubOption from \"./sub-options/ChildrenSubOption\";\nimport ExcludeSubOption from \"./sub-options/ExcludeSubOption\";\nimport IncludeSubOption from \"./sub-options/IncludeSubOption\";\nimport ModeSubOption from \"./sub-options/ModeSubOption\";\n\n\n\n/**\n * @description\n * Defines the `from` option, which controls how a hierarchy element inherits\n * properties from another referenced element.\n */\nexport default class FromOption extends Option {\n  /**\n   * @description\n   * Constructs a FromOption with its sub-options.\n   */\n  constructor() {\n    super(\"from\", \"object\", [], undefined, {\n      ref: new RefOption(),\n      mode: new ModeSubOption(),\n      children: new ChildrenSubOption(),\n      include: new IncludeSubOption(),\n      exclude: new ExcludeSubOption(),\n    });\n  }\n}\n","/**\n * @description\n * The \"id\" option model — manages the HTML element id attribute.\n */\n\n\nimport type { Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `id` option, which sets or inherits the HTML element's id attribute.\n */\nexport default class IdOption extends Option {\n  /**\n   * @description\n   * Constructs an IdOption with its default metadata.\n   */\n  constructor() {\n    super(\"id\", \"string\", [], \"\");\n  }\n\n\n  /**\n   * @description\n   * Inherits a non-empty id. In \"append\" mode an existing id is kept.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param id The id to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, id: unknown): void {\n    if (id !== \"\" && (hierarchy.from.mode === \"override\" || hierarchy.id === \"\")) {\n      hierarchy.id = id as string;\n    }\n  }\n\n\n  /**\n   * @description\n   * Reads the id of an outer element.\n   *\n   * @param element The HTML element to read from.\n   * @returns {string} The element's id.\n   */\n  public override getKeyFromElement(element: Element): unknown {\n    return element.id;\n  }\n\n\n  /**\n   * @description\n   * Applies a non-empty id to the target HTML element.\n   *\n   * @param element The HTML element to set the id on.\n   * @param hierarchy The hierarchy object supplying the id.\n   * @returns {void}\n   */\n  public override parse(element: HTMLElement, hierarchy: Hierarchy): void {\n    if (hierarchy.id !== \"\") {\n      element.id = hierarchy.id;\n    }\n  }\n}\n","/**\n * @description\n * The \"name\" option model — defines the HTML tag name of a hierarchy element.\n */\n\n\nimport type { Hierarchy } from \"../models/Hierarchy\";\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `name` option, which sets the HTML element tag (e.g. \"div\", \"span\").\n */\nexport default class NameOption extends Option {\n  /**\n   * @description\n   * Constructs a NameOption with its default metadata.\n   */\n  constructor() {\n    super(\"name\", \"string\", [], \"div\");\n  }\n\n\n  /**\n   * @description\n   * Inherits the tag name from a referenced hierarchy, in \"override\" mode only.\n   *\n   * @param hierarchy The hierarchy object that inherits.\n   * @param name The tag name to inherit.\n   * @returns {void}\n   */\n  public override inherit(hierarchy: Hierarchy, name: unknown): void {\n    if (hierarchy.from.mode === \"override\") {\n      hierarchy.name = name as string;\n    }\n  }\n}\n","/**\n * @description\n * The \"temmeIds\" option model — stores the internal path identifiers for a hierarchy element.\n */\n\n\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `temmeIds` option, which tracks the internal ID trail through the hierarchy tree.\n */\nexport default class TemmeIdsOption extends Option {\n  /**\n   * @description\n   * Constructs a TemmeIdsOption with its default metadata.\n   */\n  constructor() {\n    super(\"temmeIds\", \"array\", [], []);\n  }\n}\n","/**\n * @description\n * The \"templates\" option model — holds the template hierarchy objects for a hierarchy element.\n */\n\n\nimport Option from \"../models/Option\";\n\n\n\n/**\n * @description\n * Defines the `templates` option, which stores template sub-hierarchies used for inheritance.\n */\nexport default class TemplatesOption extends Option {\n  /**\n   * @description\n   * Constructs a TemplatesOption with its default metadata.\n   */\n  constructor() {\n    super(\"templates\", \"array\", [], []);\n  }\n}\n","/**\n * @description\n * The registry of all supported hierarchy options.\n */\n\n\nimport type Option from \"./models/Option\";\nimport AttributesOption from \"./options/AttributesOption\";\nimport ChildNodesOption from \"./options/ChildrenNodesOption\";\nimport ClassesOption from \"./options/ClassesOption\";\nimport ContentOption from \"./options/ContentOption\";\nimport DatasetOption from \"./options/DatasetOption\";\nimport FromOption from \"./options/FromOption\";\nimport IdOption from \"./options/IdOption\";\nimport NameOption from \"./options/NameOption\";\nimport RefOption from \"./options/RefOption\";\nimport TemmeIdsOption from \"./options/TemmeIdsOption\";\nimport TemplatesOption from \"./options/TemplatesOption\";\n\n\n\n/**\n * @description\n * The option labels that are not permitted inside template hierarchies.\n */\nexport const forbiddenOptions: ReadonlyArray<string> = [\"name\", \"childNodes\", \"templates\"];\n\n\n/**\n * @description\n * The lazily created option instances; built on first use so that importing\n * this module has no side effects.\n */\nlet registry: ReadonlyArray<Option> | undefined;\n\n\n/**\n * @description\n * Returns the ordered list of all recognised hierarchy options.\n * The order is the order in which options are sanitized and rendered.\n *\n * @returns {ReadonlyArray<Option>} The option instances.\n */\nexport function getOptions(): ReadonlyArray<Option> {\n  registry ??= [\n    new RefOption(),\n    new NameOption(),\n    new IdOption(),\n    new ContentOption(),\n    new TemmeIdsOption(),\n    new TemplatesOption(),\n    new ClassesOption(),\n    new ChildNodesOption(),\n    new AttributesOption(),\n    new DatasetOption(),\n    new FromOption(),\n  ];\n\n  return registry;\n}\n\n\n/**\n * @description\n * Finds a top-level option by its label.\n *\n * @param label The option label.\n * @returns {Option | undefined} The matching option, if any.\n */\nexport function findOption(label: string): Option | undefined {\n  return getOptions().find((option: Option) => option.label === label);\n}\n","/**\n * @description\n * Responsible for rendering hierarchy objects into live HTML trees.\n */\n\n\nimport type { Hierarchy } from \"./models/Hierarchy\";\nimport type Option from \"./models/Option\";\nimport { getTemmeId } from \"./idfier\";\nimport { getOptions } from \"./options\";\n\n\n\n/**\n * @description\n * Recursively renders a sanitized hierarchy into HTML elements, appending each one to its parent.\n *\n * @param hierarchy The hierarchy object to render.\n * @param parent The HTML element that will host the rendered element.\n * @param nodeCallback Invoked after each element is rendered, with its temmeId and hierarchy.\n * @param topParent When `true` the hierarchy maps to `parent` itself (no element is created).\n * @returns {void}\n */\nexport function parse(\n  hierarchy: Hierarchy,\n  parent: HTMLElement,\n  nodeCallback: (temmeId: string, currentHierarchy: Hierarchy) => void,\n  topParent: boolean = false,\n): void {\n  const element = topParent ? parent : parent.ownerDocument.createElement(hierarchy.name);\n\n  getOptions().forEach((option: Option) => option.parse(element, hierarchy));\n\n  if (!topParent) {\n    parent.appendChild(element);\n  }\n\n  nodeCallback(getTemmeId(hierarchy), hierarchy);\n\n  hierarchy.childNodes.forEach((child: Hierarchy) => parse(child, element, nodeCallback));\n}\n","/**\n * @description\n * The error thrown when hierarchies (indirectly) inherit from themselves.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when hierarchies (indirectly) inherit from themselves.\n */\nexport default class CircularReferenceError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"CircularReferenceError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param reference The offending reference.\n   */\n  constructor(reference: string) {\n    super(reference.length > 0 ? `The “${reference}” reference is part of a circular inheritance chain` : \"\", \"A reference is part of a circular inheritance chain\");\n  }\n}\n","/**\n * @description\n * The error thrown when a reference points to nothing.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a reference points to nothing.\n */\nexport default class InvalidReferenceError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidReferenceError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param reference The offending reference.\n   */\n  constructor(reference: string) {\n    super(reference.length > 0 ? `“${reference}” is an invalid reference` : \"\", \"A reference is invalid\");\n  }\n}\n","/**\n * @description\n * The error thrown when a reference value is not valid.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a reference value is not valid.\n */\nexport default class InvalidReferenceOptionValueError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidReferenceOptionValueError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"“ref” options must not begin with the “@” symbol\", options);\n  }\n}\n","/**\n * @description\n * The error thrown when a template references a non-template object.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a template references a non-template object.\n */\nexport default class InvalidTemplateReferencingError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidTemplateReferencingError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param ref The template reference.\n   * @param target The referenced key.\n   */\n  constructor(ref: string, target: string) {\n    super(ref.length > 0 ? `The template with the reference “${ref}” is trying to reference “${target}” a non-template object` : \"\", \"Templates can only reference other templates.\");\n  }\n}\n","/**\n * @description\n * The error thrown when a hierarchy references an element out of its scope.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a hierarchy references an element out of its scope.\n */\nexport default class ReferenceOutOfScopeError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"ReferenceOutOfScopeError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"An object is referencing an element out of its scope\", options);\n  }\n}\n","/**\n * @description\n * Responsible for validating references and applying template and hierarchy inheritance.\n */\n\n\nimport type { Hierarchy, InheritableOption } from \"./models/Hierarchy\";\nimport type Option from \"./models/Option\";\nimport CircularReferenceError from \"./errors/CircularReferenceError\";\nimport InvalidReferenceError from \"./errors/InvalidReferenceError\";\nimport InvalidReferenceOptionValueError from \"./errors/InvalidReferenceOptionValueError\";\nimport InvalidTemplateReferencingError from \"./errors/InvalidTemplateReferencingError\";\nimport ReferenceOutOfScopeError from \"./errors/ReferenceOutOfScopeError\";\nimport { findOption } from \"./options\";\nimport { clone, isResolved, markResolved } from \"./utils\";\n\n\n\n/**\n * @description\n * A hierarchy (or template) of the tree, along with its position.\n */\nexport type ReferenceNode = {\n\n  /** The hierarchy or template object. */\n  hierarchy: Hierarchy;\n\n  /** The nesting depth; templates share the depth of the hierarchy that declares them. */\n  depth: number;\n\n  /** Whether the object is a template. */\n  isTemplate: boolean;\n};\n\n\n/**\n * @description\n * The state shared while resolving one tree.\n */\ntype Context = {\n\n  /** Every node of the tree, in lookup order. */\n  nodes: Array<ReferenceNode>;\n\n  /** The node of every hierarchy object of the tree. */\n  byHierarchy: Map<Hierarchy, ReferenceNode>;\n\n  /** The hierarchies whose inheritance is being resolved (used to detect cycles). */\n  resolving: Set<Hierarchy>;\n\n  /** The document (or any root node) that `@selector` references are queried in, if any. */\n  dom: ParentNode | undefined;\n};\n\n\n/**\n * @description\n * Validates every reference of a sanitized hierarchy tree, then applies inheritance in\n * dependency order: a hierarchy inherits only once the one it references is fully resolved.\n * Hierarchies resolved by a previous call are left untouched.\n *\n * @param root The root hierarchy to process.\n * @param dom The document `@selector` references are looked up in; when absent (e.g. no DOM),\n *   outer-element references are neither checked nor inherited.\n * @returns {void}\n */\nexport function process(root: Hierarchy, dom: ParentNode | undefined): void {\n  const nodes = collect(root, 1, false);\n  const context: Context = {\n    nodes,\n    byHierarchy: new Map(nodes.map((node: ReferenceNode) => [node.hierarchy, node])),\n    resolving: new Set(),\n    dom,\n  };\n  const pending = nodes.filter((node: ReferenceNode) => !isResolved(node.hierarchy));\n\n  pending.forEach((node: ReferenceNode) => validateReference(node, context));\n  pending.forEach((node: ReferenceNode) => validateTemplateReference(node, context));\n  pending.forEach((node: ReferenceNode) => validateScope(node, context));\n  pending.forEach((node: ReferenceNode) => resolve(node, context));\n}\n\n\n/**\n * @description\n * Lists a hierarchy, its children (recursively) and its templates with their depth.\n *\n * @param hierarchy The hierarchy to collect from.\n * @param depth The hierarchy's depth.\n * @param isTemplate Whether the hierarchy is a template.\n * @returns {Array<ReferenceNode>} The nodes, the hierarchy first.\n */\nfunction collect(hierarchy: Hierarchy, depth: number, isTemplate: boolean): Array<ReferenceNode> {\n  return [\n    { hierarchy, depth, isTemplate },\n    ...(hierarchy.childNodes ?? []).flatMap((child: Hierarchy) => collect(child, depth + 1, false)),\n    ...(hierarchy.templates ?? []).flatMap((template: Hierarchy) => collect(template, depth, true)),\n  ];\n}\n\n\n/**\n * @description\n * Finds the node a hierarchy references by name (never the hierarchy itself).\n *\n * @param node The referencing node.\n * @param context The resolution context.\n * @returns {ReferenceNode | undefined} The first node with a matching `ref`, if any.\n */\nfunction findReferenced(node: ReferenceNode, context: Context): ReferenceNode | undefined {\n  return context.nodes.find(\n    (candidate: ReferenceNode) => candidate.hierarchy.ref === node.hierarchy.from.ref && candidate !== node,\n  );\n}\n\n\n/**\n * @description\n * Tells whether a node references another hierarchy of the tree (as opposed to nothing\n * or an outer element).\n *\n * @param node The node to inspect.\n * @returns {boolean} `true` for inner references.\n */\nfunction hasInnerReference(node: ReferenceNode): boolean {\n  const { ref } = node.hierarchy.from;\n\n  return ref !== \"\" && !ref.startsWith(\"@\");\n}\n\n\n/**\n * @description\n * Looks an outer element up, turning malformed selectors into Temme errors.\n *\n * @param dom The root to query.\n * @param selector The CSS selector.\n * @returns {Element | null} The matching element, if any.\n * @throws {InvalidReferenceOptionValueError} When the selector is malformed.\n */\nfunction queryOuterElement(dom: ParentNode, selector: string): Element | null {\n  try {\n    return dom.querySelector(selector);\n  }\n  catch (error) {\n    throw new InvalidReferenceOptionValueError(`\"${selector}\" is not a valid selector`, { cause: error });\n  }\n}\n\n\n/**\n * @description\n * Checks that a node's `from.ref` points to an existing hierarchy, or to an existing\n * outer element for `@selector` references.\n *\n * @param node The node to validate.\n * @param context The resolution context.\n * @returns {void}\n * @throws {InvalidReferenceOptionValueError} When no outer element matches a `@selector`.\n * @throws {InvalidReferenceError} When no hierarchy has the referenced `ref`.\n */\nfunction validateReference(node: ReferenceNode, context: Context): void {\n  const { ref } = node.hierarchy.from;\n\n  if (ref.startsWith(\"@\")) {\n    const selector = ref.substring(1);\n\n    if (context.dom !== undefined && queryOuterElement(context.dom, selector) === null) {\n      throw new InvalidReferenceOptionValueError(`No outer element corresponds to the selector \"${selector}\"`);\n    }\n  }\n  else if (ref !== \"\" && findReferenced(node, context) === undefined) {\n    throw new InvalidReferenceError(ref);\n  }\n}\n\n\n/**\n * @description\n * Checks that templates only reference other templates (or outer elements).\n *\n * @param node The node to validate.\n * @param context The resolution context.\n * @returns {void}\n * @throws {InvalidTemplateReferencingError} When a template references a plain hierarchy.\n */\nfunction validateTemplateReference(node: ReferenceNode, context: Context): void {\n  if (node.isTemplate && hasInnerReference(node) && !(findReferenced(node, context) as ReferenceNode).isTemplate) {\n    throw new InvalidTemplateReferencingError(node.hierarchy.ref, node.hierarchy.from.ref);\n  }\n}\n\n\n/**\n * @description\n * Checks that a node does not reference a hierarchy nested deeper than itself.\n *\n * @param node The node to validate.\n * @param context The resolution context.\n * @returns {void}\n * @throws {ReferenceOutOfScopeError} When the referenced hierarchy is out of scope.\n */\nfunction validateScope(node: ReferenceNode, context: Context): void {\n  if (hasInnerReference(node) && (findReferenced(node, context) as ReferenceNode).depth > node.depth) {\n    throw new ReferenceOutOfScopeError(\"\");\n  }\n}\n\n\n/**\n * @description\n * Returns the option labels a node inherits: `include` minus `exclude`.\n *\n * @param node The inheriting node.\n * @returns {Array<InheritableOption>} The labels to inherit.\n */\nfunction getInheritedLabels(node: ReferenceNode): Array<InheritableOption> {\n  const { include, exclude } = node.hierarchy.from;\n\n  return include.filter((label: InheritableOption) => !exclude.includes(label));\n}\n\n\n/**\n * @description\n * Applies a node's inheritance, after resolving whatever it depends on.\n *\n * @param node The node to resolve.\n * @param context The resolution context.\n * @returns {void}\n * @throws {CircularReferenceError} When the node (indirectly) depends on itself.\n */\nfunction resolve(node: ReferenceNode, context: Context): void {\n  const { hierarchy } = node;\n  const { ref } = hierarchy.from;\n\n  if (context.resolving.has(hierarchy)) {\n    throw new CircularReferenceError(ref);\n  }\n\n  if (isResolved(hierarchy)) {\n    return;\n  }\n\n  context.resolving.add(hierarchy);\n\n  if (ref.startsWith(\"@\")) {\n    inheritFromElement(node, context);\n  }\n  else if (ref !== \"\") {\n    inheritFromHierarchy(node, findReferenced(node, context) as ReferenceNode, context);\n  }\n\n  context.resolving.delete(hierarchy);\n  markResolved(hierarchy);\n}\n\n\n/**\n * @description\n * Applies inheritance from an outer element. Options that can't be read from the DOM\n * (the tag name and the child nodes) are skipped.\n *\n * @param node The inheriting node.\n * @param context The resolution context.\n * @returns {void}\n */\nfunction inheritFromElement(node: ReferenceNode, context: Context): void {\n  if (context.dom === undefined) {\n    return;\n  }\n\n  const element = queryOuterElement(context.dom, node.hierarchy.from.ref.substring(1)) as Element;\n\n  getInheritedLabels(node).forEach((label: InheritableOption) => {\n    const option = findOption(label) as Option;\n    const value = option.getKeyFromElement(element);\n\n    if (value !== null) {\n      option.inherit(node.hierarchy, value);\n    }\n  });\n}\n\n\n/**\n * @description\n * Applies inheritance from another hierarchy of the tree, resolving it first.\n * Inherited values are copied, so the two hierarchies never share mutable state.\n * Options the source doesn't hold (templates have no tag name and no children) are skipped,\n * and so are child nodes unless `from.children.allow` is set.\n *\n * @param node The inheriting node.\n * @param source The referenced node.\n * @param context The resolution context.\n * @returns {void}\n */\nfunction inheritFromHierarchy(node: ReferenceNode, source: ReferenceNode, context: Context): void {\n  resolve(source, context);\n\n  getInheritedLabels(node)\n    .filter((label: InheritableOption) => Object.hasOwn(source.hierarchy, label))\n    .filter((label: InheritableOption) => label !== \"childNodes\" || node.hierarchy.from.children.allow)\n    .forEach((label: InheritableOption) => {\n      const value = label === \"childNodes\"\n        ? inheritChildNodes(source, context)\n        : clone(source.hierarchy[label]);\n\n      (findOption(label) as Option).inherit(node.hierarchy, value);\n    });\n}\n\n\n/**\n * @description\n * Builds the child nodes a node inherits: fully resolved copies of the source's children,\n * stripped of their `ref` so that they never shadow the originals.\n *\n * @param source The referenced (and already resolved) node.\n * @param context The resolution context.\n * @returns {Array<Hierarchy>} The copied children.\n */\nfunction inheritChildNodes(source: ReferenceNode, context: Context): Array<Hierarchy> {\n  collect(source.hierarchy, source.depth, source.isTemplate)\n    .forEach((descendant: ReferenceNode) => resolve(context.byHierarchy.get(descendant.hierarchy) as ReferenceNode, context));\n\n  const copies = clone(source.hierarchy.childNodes);\n\n  copies.forEach(stripReferences);\n\n  return copies;\n}\n\n\n/**\n * @description\n * Clears the `ref` of a copied hierarchy and of everything it contains.\n *\n * @param hierarchy The copied hierarchy.\n * @returns {void}\n */\nfunction stripReferences(hierarchy: Hierarchy): void {\n  hierarchy.ref = \"\";\n  hierarchy.childNodes?.forEach(stripReferences);\n  hierarchy.templates?.forEach(stripReferences);\n}\n","/**\n * @description\n * Responsible for sanitizing hierarchy input and populating option defaults.\n */\n\n\nimport type { Hierarchy } from \"./models/Hierarchy\";\nimport type Option from \"./models/Option\";\nimport { forbiddenOptions, getOptions } from \"./options\";\nimport { uniqueSorted } from \"./utils\";\n\n\n\n/**\n * @description\n * Sanitizes a hierarchy object in place, recursively: missing options get a fresh default,\n * and list values (classes, include, exclude) are de-duplicated and sorted.\n * Sanitizing is idempotent.\n *\n * @param hierarchy The hierarchy object to sanitize.\n * @param isTemplate Whether the object is a template (forbidden options are left out).\n * @returns {void}\n */\nexport function sanitize(hierarchy: Hierarchy, isTemplate: boolean = false): void {\n  getOptions()\n    .filter((option: Option) => !isTemplate || !forbiddenOptions.includes(option.label))\n    .forEach((option: Option) => sanitizeOption(hierarchy, option));\n\n  hierarchy.classes = uniqueSorted(hierarchy.classes);\n\n  hierarchy.childNodes?.forEach((child: Hierarchy) => sanitize(child));\n  hierarchy.templates?.forEach((template: Hierarchy) => sanitize(template, true));\n}\n\n\n/**\n * @description\n * Sanitizes a single option entry on a (sub-)hierarchy object: populates a fresh default\n * when it is missing, normalises restricted list values, and recurses into sub-options.\n *\n * @param target The object holding the option.\n * @param option The option descriptor to apply.\n * @returns {void}\n */\nfunction sanitizeOption(target: Record<string, unknown>, option: Option): void {\n  if (!Object.hasOwn(target, option.label)) {\n    target[option.label] = option.createDefault();\n\n    return;\n  }\n\n  if (option.type === \"array\" && option.values.length > 0) {\n    target[option.label] = uniqueSorted(target[option.label] as Array<unknown>);\n  }\n\n  if (option.keys !== undefined) {\n    const value = target[option.label] as Record<string, unknown>;\n\n    Object.values(option.keys).forEach((subOption: Option) => sanitizeOption(value, subOption));\n  }\n}\n","/**\n * @description\n * The error thrown when a hierarchy is not a valid plain object.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a hierarchy is not a valid plain object.\n */\nexport default class InvalidHierarchyError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidHierarchyError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"The hierarchy object is not valid\", options);\n  }\n}\n","/**\n * @description\n * The error thrown when an option is not recognised.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when an option is not recognised.\n */\nexport default class InvalidOptionNameError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidOptionNameError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param option The offending option name.\n   */\n  constructor(option: string) {\n    super(option.length > 0 ? `“${option}” is not a valid option` : \"\", \"An option is not valid\");\n  }\n}\n","/**\n * @description\n * The error thrown when an option's value has the wrong type.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when an option's value has the wrong type.\n */\nexport default class InvalidOptionTypeError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidOptionTypeError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param option The offending option name.\n   * @param type The offending value type.\n   */\n  constructor(option: string, type: string) {\n    super(option.length > 0 ? `The \"${option}\" option doesn't accept values of type \"${type}\"` : \"\", \"An option doesn't have a valid value type\");\n  }\n}\n","/**\n * @description\n * The error thrown when a `from` option is not valid.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a `from` option is not valid.\n */\nexport default class InvalidReferencingOptionError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidReferencingOptionError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"A referencing option is not valid\", options);\n  }\n}\n","/**\n * @description\n * The error thrown when a sub-option is not recognised.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a sub-option is not recognised.\n */\nexport default class InvalidSubOptionNameError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidSubOptionNameError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param option The offending option name.\n   * @param subOption The offending sub-option name.\n   */\n  constructor(option: string, subOption: string) {\n    super(option.length > 0 || subOption.length > 0 ? `The “${option}” option doesn't recognize “${subOption}” as a valid sub-option` : \"\", \"A sub-option is not valid\");\n  }\n}\n","/**\n * @description\n * The error thrown when a sub-option's value has the wrong type.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a sub-option's value has the wrong type.\n */\nexport default class InvalidSubOptionTypeError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidSubOptionTypeError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param subOption The offending sub-option name.\n   * @param type The offending value type.\n   */\n  constructor(subOption: string, type: string) {\n    super(subOption.length > 0 || type.length > 0 ? `The \"${subOption}\" sub-option doesn't accept values of type \"${type}\"` : \"\", \"A sub-option doesn't have a valid value type\");\n  }\n}\n","/**\n * @description\n * The error thrown when a sub-option's value is not allowed.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a sub-option's value is not allowed.\n */\nexport default class InvalidSubOptionValueError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidSubOptionValueError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param subOption The offending sub-option name.\n   * @param value The offending value.\n   */\n  constructor(subOption: string, value: string) {\n    super(subOption.length > 0 || value.length > 0 ? `The “${subOption}” sub-option doesn't accept “${value}” as a value` : \"\", \"A sub-option doesn't have a valid value\");\n  }\n}\n","/**\n * @description\n * The error thrown when a template does not have a `ref` option.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a template does not have a `ref` option.\n */\nexport default class InvalidTemplateError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidTemplateError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param message The message of the error; a generic one is used when empty.\n   * @param options The standard error options, e.g. the `cause`.\n   */\n  constructor(message: string, options?: ErrorOptions) {\n    super(message, \"A template does not have a “ref” option\", options);\n  }\n}\n","/**\n * @description\n * The error thrown when a template uses an option templates can't have.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when a template uses an option templates can't have.\n */\nexport default class InvalidTemplateOptionError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidTemplateOptionError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param option The offending option name.\n   */\n  constructor(option: string) {\n    super(option.length > 0 ? `“${option}” is not a valid option to use in templates` : \"\", \"A template has an invalid option\");\n  }\n}\n","/**\n * @description\n * Responsible for validating hierarchy input — option names, types, values\n * and template constraints. Reference validation lives in the referencer.\n */\n\n\nimport { isObject } from \"@eoussama/core\";\nimport InvalidHierarchyError from \"./errors/InvalidHierarchyError\";\nimport InvalidOptionNameError from \"./errors/InvalidOptionNameError\";\nimport InvalidOptionTypeError from \"./errors/InvalidOptionTypeError\";\nimport InvalidReferenceOptionValueError from \"./errors/InvalidReferenceOptionValueError\";\nimport InvalidReferencingOptionError from \"./errors/InvalidReferencingOptionError\";\nimport InvalidSubOptionNameError from \"./errors/InvalidSubOptionNameError\";\nimport InvalidSubOptionTypeError from \"./errors/InvalidSubOptionTypeError\";\nimport InvalidSubOptionValueError from \"./errors/InvalidSubOptionValueError\";\nimport InvalidTemplateError from \"./errors/InvalidTemplateError\";\nimport InvalidTemplateOptionError from \"./errors/InvalidTemplateOptionError\";\nimport Option from \"./models/Option\";\nimport { findOption, forbiddenOptions } from \"./options\";\n\n\n\n/**\n * @description\n * Checks whether a value is a structurally valid hierarchy (a non-null, non-array object).\n *\n * @param hierarchy The value to check.\n * @returns {boolean} `true` when the value can be used as a hierarchy.\n */\nexport function isValidHierarchy(hierarchy: unknown): hierarchy is Record<string, unknown> {\n  return isObject(hierarchy);\n}\n\n\n/**\n * @description\n * Checks whether a value is an HTML element. Elements from other realms (iframes) are\n * recognised, and environments without a DOM simply get `false`.\n *\n * @param target The value to check.\n * @returns {boolean} `true` when the value is an HTMLElement.\n */\nexport function isValidHTMLElement(target: unknown): target is HTMLElement {\n  if (!isObject(target)) {\n    return false;\n  }\n\n  const HTMLElementOfRealm = (target as Partial<Node>).ownerDocument?.defaultView?.HTMLElement ?? globalThis.HTMLElement;\n\n  return typeof HTMLElementOfRealm === \"function\" && target instanceof HTMLElementOfRealm;\n}\n\n\n/**\n * @description\n * Recursively validates all option names, types, values and sub-options of a hierarchy,\n * its templates and its children.\n *\n * @param hierarchy The hierarchy object to validate.\n * @param isTemplate Whether the object is a template (forbidden options are rejected).\n * @returns {void}\n * @throws {InvalidHierarchyError} When the hierarchy is not a plain object.\n * @throws {InvalidOptionNameError} When an unrecognised option key is encountered.\n * @throws {InvalidTemplateOptionError} When a template contains a forbidden option.\n * @throws {InvalidOptionTypeError} When an option's value has the wrong type.\n * @throws {InvalidSubOptionNameError} When an unrecognised sub-option key is encountered.\n * @throws {InvalidSubOptionTypeError} When a sub-option's value has the wrong type.\n * @throws {InvalidSubOptionValueError} When a sub-option's value is not in the allowed set.\n * @throws {InvalidReferenceOptionValueError} When the `ref` option starts with \"@\".\n * @throws {InvalidReferencingOptionError} When `from` lacks `ref`, or uses both `include` and `exclude`.\n */\nexport function validateOptions(hierarchy: unknown, isTemplate: boolean = false): void {\n  if (!isValidHierarchy(hierarchy)) {\n    throw new InvalidHierarchyError(\"\");\n  }\n\n  for (const [label, value] of Object.entries(hierarchy)) {\n    const option = findOption(label);\n\n    if (option === undefined) {\n      throw new InvalidOptionNameError(label);\n    }\n\n    if (isTemplate && forbiddenOptions.includes(label)) {\n      throw new InvalidTemplateOptionError(label);\n    }\n\n    const { valid, type } = Option.validateOptionType(value, option);\n\n    if (!valid) {\n      throw new InvalidOptionTypeError(label, type);\n    }\n\n    // No top-level option restricts its values; only sub-options (e.g. `mode`) do.\n    if (option.keys !== undefined) {\n      validateSubOptions(label, value as Record<string, unknown>, option.keys);\n    }\n  }\n\n  if (typeof hierarchy.ref === \"string\" && hierarchy.ref.startsWith(\"@\")) {\n    throw new InvalidReferenceOptionValueError(\"\");\n  }\n\n  if (isObject(hierarchy.from)) {\n    validateFrom(hierarchy.from);\n  }\n\n  (hierarchy.templates as Array<unknown> | undefined)?.forEach((template: unknown) => validateTemplates(template));\n  (hierarchy.childNodes as Array<unknown> | undefined)?.forEach((child: unknown) => validateOptions(child));\n}\n\n\n/**\n * @description\n * Validates a template: it must be an object with a `ref` and only template-friendly options.\n *\n * @param template The template object to validate.\n * @returns {void}\n * @throws {InvalidHierarchyError} When the template is not a plain object.\n * @throws {InvalidTemplateError} When the template is missing a `ref` key.\n * @throws {InvalidTemplateOptionError} When the template contains a forbidden option.\n */\nexport function validateTemplates(template: unknown): void {\n  if (!isValidHierarchy(template)) {\n    throw new InvalidHierarchyError(\"\");\n  }\n\n  if (!Object.hasOwn(template, \"ref\")) {\n    throw new InvalidTemplateError(\"\");\n  }\n\n  validateOptions(template, true);\n}\n\n\n/**\n * @description\n * Validates the sub-options of an object option's value.\n *\n * @param optionName The name of the parent option being validated.\n * @param value The value object containing sub-option entries.\n * @param subOptions The expected sub-options, keyed by label.\n * @returns {void}\n * @throws {InvalidSubOptionNameError} When an unrecognised sub-option key is found.\n * @throws {InvalidSubOptionTypeError} When a sub-option has the wrong type.\n * @throws {InvalidSubOptionValueError} When a sub-option has a disallowed value.\n */\nfunction validateSubOptions(optionName: string, value: Record<string, unknown>, subOptions: Readonly<Record<string, Option>>): void {\n  for (const [label, subValue] of Object.entries(value)) {\n    const subOption = Object.hasOwn(subOptions, label) ? subOptions[label] : undefined;\n\n    if (subOption === undefined) {\n      throw new InvalidSubOptionNameError(optionName, label);\n    }\n\n    const { valid, type } = Option.validateOptionType(subValue, subOption);\n\n    if (!valid) {\n      throw new InvalidSubOptionTypeError(label, type);\n    }\n\n    if (!Option.validateOptionValue(subValue, subOption)) {\n      throw new InvalidSubOptionValueError(label, String(subValue));\n    }\n\n    if (subOption.keys !== undefined) {\n      validateSubOptions(label, subValue as Record<string, unknown>, subOption.keys);\n    }\n  }\n}\n\n\n/**\n * @description\n * Validates the referencing constraints of a `from` value: it needs a `ref`, and it\n * can't restrict inheritance with both a non-empty `include` and a non-empty `exclude`.\n *\n * @param from The `from` option value.\n * @returns {void}\n * @throws {InvalidReferencingOptionError} When a constraint is violated.\n */\nfunction validateFrom(from: Record<string, unknown>): void {\n  if (!Object.hasOwn(from, \"ref\")) {\n    throw new InvalidReferencingOptionError(\n      \"The “from” option must always have a “ref” sub-option\",\n    );\n  }\n\n  const include = from.include as Array<string> | undefined;\n  const exclude = from.exclude as Array<string> | undefined;\n\n  if ((include?.length ?? 0) > 0 && (exclude?.length ?? 0) > 0) {\n    throw new InvalidReferencingOptionError(\n      \"The “from” option can’t have both the “include” and “exclude” sub-options at the same time\",\n    );\n  }\n}\n","/**\n * @description\n * The error thrown when an option's value is not allowed.\n */\n\n\nimport TemmyError from \"../models/TemmyError\";\n\n\n\n/**\n * @description\n * The error thrown when an option's value is not allowed.\n */\nexport default class InvalidOptionValueError extends TemmyError {\n  /** The name of the error. */\n  public override readonly name: string = \"InvalidOptionValueError\";\n\n\n  /**\n   * @description\n   * Constructs the error.\n   *\n   * @param option The offending option name.\n   * @param value The offending value.\n   */\n  constructor(option: string, value: string) {\n    super(option.length > 0 ? `The “${option}” option doesn't accept “${value}” as a value` : \"\", \"An option doesn't have a valid value\");\n  }\n}\n","/**\n * Temme (or Emmet in reverse) is to javascript what Emmet is to HTML and CSS,\n * with no doubts, Emmet saved us from the headache of working with HTML and CSS,\n * and now, Temme is doing Javascript the same favour too.\n *\n * https://github.com/eoussama/temmejs\n */\n\n\nimport type { Hierarchy } from \"./modules/models/Hierarchy\";\nimport { isPromise, tryCatchSync } from \"@eoussama/core\";\nimport InvalidTargetError from \"./modules/errors/InvalidTargetError\";\nimport * as Idfier from \"./modules/idfier\";\nimport TemmyError from \"./modules/models/TemmyError\";\nimport * as Parser from \"./modules/parser\";\nimport * as Referencer from \"./modules/referencer\";\nimport * as Sanitizer from \"./modules/sanitizer\";\nimport { clone } from \"./modules/utils\";\nimport * as Validator from \"./modules/validator\";\n\n\n\nexport { default as CircularReferenceError } from \"./modules/errors/CircularReferenceError\";\nexport { default as InvalidHierarchyError } from \"./modules/errors/InvalidHierarchyError\";\nexport { default as InvalidOptionNameError } from \"./modules/errors/InvalidOptionNameError\";\nexport { default as InvalidOptionTypeError } from \"./modules/errors/InvalidOptionTypeError\";\nexport { default as InvalidOptionValueError } from \"./modules/errors/InvalidOptionValueError\";\nexport { default as InvalidReferenceError } from \"./modules/errors/InvalidReferenceError\";\nexport { default as InvalidReferenceOptionValueError } from \"./modules/errors/InvalidReferenceOptionValueError\";\nexport { default as InvalidReferencingOptionError } from \"./modules/errors/InvalidReferencingOptionError\";\nexport { default as InvalidSubOptionNameError } from \"./modules/errors/InvalidSubOptionNameError\";\nexport { default as InvalidSubOptionTypeError } from \"./modules/errors/InvalidSubOptionTypeError\";\nexport { default as InvalidSubOptionValueError } from \"./modules/errors/InvalidSubOptionValueError\";\nexport { default as InvalidTargetError } from \"./modules/errors/InvalidTargetError\";\nexport { default as InvalidTemplateError } from \"./modules/errors/InvalidTemplateError\";\nexport { default as InvalidTemplateOptionError } from \"./modules/errors/InvalidTemplateOptionError\";\nexport { default as InvalidTemplateReferencingError } from \"./modules/errors/InvalidTemplateReferencingError\";\nexport { default as ReferenceOutOfScopeError } from \"./modules/errors/ReferenceOutOfScopeError\";\nexport type { AttributeValue, Content, From, FromInput, Hierarchy, HierarchyInput, InheritableOption, TemplateInput } from \"./modules/models/Hierarchy\";\nexport { default as TemmyError } from \"./modules/models/TemmyError\";\n\n\n/**\n * @description\n * Called once the whole tree has been rendered. May be async: a rejected promise is\n * reported with `console.warn` and never affects the caller.\n */\nexport type ParseEndCallback = (resultedHierarchy: Hierarchy) => void | Promise<void>;\n\n\n/**\n * @description\n * Called right after each element is rendered (the root first, then depth-first).\n */\nexport type ParseNodeCallback = (temmeId: string, currentHierarchy: Hierarchy) => void;\n\n\n/**\n * @description\n * The outcome of `validate`.\n */\nexport type ValidationResult = {\n\n  /** `true` when the hierarchy can be parsed. */\n  valid: boolean;\n\n  /** The error `parse` would throw, or `null` when valid. */\n  error: unknown;\n};\n\n\n/**\n * @description\n * The entry point of Temme — validates, sanitizes, resolves the references of and renders\n * a hierarchy object into a live HTML tree.\n *\n * The hierarchy object is completed in place (defaults, inherited values, temmeIds) and\n * returned. Parsing the returned object again renders the same tree.\n *\n * @param hierarchy The hierarchy object that maps the HTML skeleton.\n * @param target The HTML element that will host the rendered skeleton.\n * @param endCallback The function that executes when the skeleton has been fully rendered.\n * @param nodeCallback The function that executes whenever an individual element is rendered.\n * @returns {Hierarchy} The completed hierarchy object.\n * @throws {TemmyError} When the target or the hierarchy is invalid; the message is prefixed\n *   with \"[Temme]: \". Errors thrown by the callbacks are re-thrown untouched.\n */\nexport function parse(\n  hierarchy: object,\n  target: HTMLElement,\n  endCallback: ParseEndCallback = () => {},\n  nodeCallback: ParseNodeCallback = () => {},\n): Hierarchy {\n  const resolved = prepare(hierarchy, target);\n\n  Parser.parse(resolved, target, nodeCallback, true);\n\n  const result = endCallback(resolved);\n\n  if (isPromise(result)) {\n    result.then(undefined, (error: unknown) => {\n      console.warn(\"[Temme]: async end-callback rejected:\", error);\n    });\n  }\n\n  return resolved;\n}\n\n\n/**\n * @description\n * Validates a hierarchy object without rendering or modifying it: runs every check `parse`\n * runs (options, templates, references, scopes and cycles) on a copy.\n *\n * @param hierarchy The hierarchy object to validate.\n * @returns {ValidationResult} `valid` is `true` when the hierarchy is well-formed,\n *   otherwise `error` holds the error `parse` would throw.\n */\nexport function validate(hierarchy: object): ValidationResult {\n  const [error] = tryCatchSync<Error, void>(() => {\n    Validator.validateOptions(hierarchy);\n\n    const copy = clone(hierarchy) as Hierarchy;\n\n    Sanitizer.sanitize(copy);\n    Referencer.process(copy, globalThis.document);\n  });\n\n  return { valid: error === null, error };\n}\n\n\n/**\n * @description\n * Validates and completes a hierarchy, prefixing Temme's own errors with \"[Temme]: \".\n *\n * @param hierarchy The hierarchy object.\n * @param target The host element.\n * @returns {Hierarchy} The completed hierarchy.\n */\nfunction prepare(hierarchy: object, target: HTMLElement): Hierarchy {\n  try {\n    if (!Validator.isValidHTMLElement(target)) {\n      throw new InvalidTargetError(\"\");\n    }\n\n    Validator.validateOptions(hierarchy);\n\n    const completed = hierarchy as Hierarchy;\n\n    Sanitizer.sanitize(completed);\n    Referencer.process(completed, target.ownerDocument);\n    Idfier.idfy(completed);\n\n    return completed;\n  }\n  catch (error) {\n    if (error instanceof TemmyError) {\n      error.message = `[Temme]: ${error.message}.`;\n    }\n\n    throw error;\n  }\n}\n"],"ignoreList":[0],"mappings":";AAMA,SAASE,EAAQ,EAAO,CACvB,GAAIC,aAAiB,MAAO,OAAOA,EACnC,GAAI,OAAOA,GAAU,SAAU,OAAW,MAAMA,CAAK,EACrD,IAAIC,EACJ,GAAI,CACH,EAAU,KAAK,UAAUD,CAAK,GAAK,OAAOA,CAAK,CAChD,MAAQ,CACP,EAAU,OAAOA,CAAK,CACvB,CACA,OAAW,MAAMC,EAAS,CAAE,MAAOD,CAAM,CAAC,CAC3C,CAkBA,SAASE,EAAS,EAAO,CACxB,OAAO,OAAOF,GAAU,YAAYA,GAAkB,CAAC,MAAM,QAAQA,CAAK,CAC3E,CAGA,SAASG,EAAU,EAAO,CACzB,OAAQ,OAAOH,GAAU,YAAYA,GAAkB,OAAOA,GAAU,aAAe,SAAUA,GAAS,OAAOA,EAAM,MAAS,UACjI,CAoEA,SAASI,EAAU,EAAO,CACzB,OAAOC,GAASN,EAAQM,CAAK,CAC9B,CAQA,SAASC,EAAa,EAAI,CACzB,GAAI,CACH,MAAO,CAAC,KAAMC,EAAG,CAAC,CACnB,OAASF,EAAO,CACf,MAAO,CAACD,EAAUC,CAAK,EAAG,IAAI,CAC/B,CACD,CCzHA,IAAqBG,EAArB,cAAwC,KAAM,CAE5C,KAAwC,aAWxC,YAAY,EAAiB,EAAmB,2BAA4B,EAAwB,CAClG,MAAMP,EAAQ,OAAS,EAAIA,EAAUQ,EAAUC,CAAO,CACxD,CACF,ECNqBC,EAArB,cAAgDH,CAAW,CAEzD,KAAwC,qBAUxC,YAAY,EAAiB,EAAwB,CACnD,MAAMP,EAAS,yCAA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