import * as happy_dom_without_node from 'happy-dom-without-node'; import { Document as Document$1, DocumentFragment, HTMLElement as HTMLElement$1, Comment, Text, Node } from 'happy-dom-without-node'; import { Narrowable, IsStringLiteral, Contains, AsString } from 'inferred-types'; import { Events } from 'vue'; /** * Use the self-reported numeric type that a node presents * to identify what type it is. */ declare const nodeTypeLookup: (type: number) => NodeType | undefined; /** * Determines the "content-type" of a given node */ declare const getNodeType: (node: Container | HTML) => NodeType; /** * A helper utility to help convert DOM nodes or HTML to common type. * * Start by providing the _exclusions_ you want to make for input. By default, all * `Container` types are allowed along with `HTML` */ declare const solveForNodeType: NodeSolver; /** * Ensures any Container, array of Containers, or even HTML or HTML[] are all * normalized down to just HTML. */ declare function toHtml(node: D): HTML; /** * Clones most DOM types */ declare function clone(container: T): T; /** * ensures that a given string doesn't have any HTML inside of it */ declare function safeString(str: string): string; type InspectionTuple = [msg: string, item: unknown]; type HTML = string; type GetAttribute = (node: N) => string; type NodeTypeInput> = T extends "html" ? string : T extends "text" ? IText : T extends "element" ? IElement : T extends "document" ? HappyDoc : T; /** The distinct types of Nodes we may encounter */ type NodeType = "html" | "text" | "element" | "comment" | "node" | "document" | "fragment"; type NodeSolverInput = T extends "html" ? HTML : T extends "comment" ? IComment : T extends "text" ? IText : T extends "element" ? IElement : T extends "node" ? INode : T extends "document" ? HappyDoc : T extends "fragment" ? IFragment : unknown; type DocRoot = HappyDoc | IFragment; type DomNode = IElement | IText | IComment | INode; type Container = DocRoot | DomNode; type ContainerOrHtml = Container | HTML; /** * The select.update/updateAll methods not only receive the _element_ * which is being mutated but also the _index_ and _total count_ of selection * results. */ type UpdateSignature = [el: IElement, idx: number, total: number] | [el: IElement, idx: number] | [el: IElement]; interface ToHtmlOptions { pretty?: boolean; indent?: number; } interface TreeSummary { node: string; children: TreeSummary[]; } interface Tree { node: Container; type: string; level: number; summary: () => TreeSummary; toString: () => string; children: Tree[]; } /** * A callback which receives a node type `C` and allows side-effects and/or * mutation. It expects the same container structure -- mutation or not -- to * be passed back as a return value. The one exception is that if you pass back * a `false` value then the element will be removed. */ type UpdateCallback_Native = (el: IElement, idx: number, total: number) => IElement | false; type UpdateCallback = (el: IElement, idx: number, total: number) => IElement | false; type MapCallback = (input: I) => O; interface NodeSolverDict { html: (input: HTML) => O extends "mirror" ? HTML : O; text: (input: IText) => O extends "mirror" ? IText : O; element: (input: IElement, parent?: IElement | DocRoot) => O extends "mirror" ? IElement : O; comment: (input: IComment) => O extends "mirror" ? IComment : O; node: (input: INode) => O extends "mirror" ? INode : O; document: (input: HappyDoc) => O extends "mirror" ? HappyDoc : O; fragment: (input: IFragment) => O extends "mirror" ? IFragment : O; } /** * A fully configured solver which is ready to convert a node into type `O`; if `O` is never * then it will mirror the input type as the output type */ type NodeSolverReady = >(node: N, parent?: IElement | DocRoot) => O extends "mirror" ? N : O; interface NodeSolverReceiver { /** provide a solver dictionary */ solver: (solver: Omit, E>) => NodeSolverReady; } interface NodeSolverWithExclusions { /** provide a type which all solvers will convert to */ outputType: () => NodeSolverReceiver; /** the input type should be maintained as the output type */ mirror: () => NodeSolverReceiver; } /** * Allows you to setup a type-string utility which receives DOM containers * and returns either the same container type or a specific type. * * This uses a builder API, of which this is the first step. */ type NodeSolver = (...exclude: E[]) => NodeSolverWithExclusions; /** * A selector API provided by using the `select()` utility */ interface NodeSelector { /** * The _type_ of the root node */ type: () => NodeType; /** * Find the first `IElement` found using the selector string. * * Note: _by default the return type includes `null` if no results were found but if you * prefer to throw an error you can state the error text and an error will be thrown_ */ findFirst: (sel: string, errorMsg?: E) => undefined extends E ? IElement | null : IElement; /** * Find _all_ `IElement` results returned from the Selection query */ findAll: (sel: S) => IElement[]; /** * Appends one or more elements to the root selected node */ append: (content?: (IText | IElement | HTML | undefined) | (IText | IElement | HTML | undefined)[]) => NodeSelector; /** * Allows the injection of a callback which will be used to mutate on the first `IElement` node * which matches the first */ update: (sel?: string, errorMsg?: E) => (cb: CB) => NodeSelector; /** * Provides a way to inject an update callback which will be applied to all IElement nodes * which meet the selector query. If no query is provided, then this will be all `IElement` * children of the root node. */ updateAll: (sel?: S) => (cb: CB) => NodeSelector; /** * Map over all selected items and transform them as needed; results are returned to * caller (exiting the selection API) and operation does not mutate the parent * selected DOM tree. */ mapAll: (selection?: S) => (mutate: MapCallback) => O[]; /** * Filters out all nodes which match the DOM query selector and returns the * selector API */ filterAll: (selection: S) => NodeSelector; /** * Wraps the current _selection_ with an Element or Fragment. * * You may optionally add a prefix to the error message thrown if the * wrapper does not represent a valid block/wrapper element. */ wrap: (wrapper: C, errMsg?: string) => NodeSelector; /** * Returns the root node with all mutations included */ toContainer: () => undefined extends T ? IFragment : T extends "html" ? string : T; } type SetAttribute = (value: string) => (node: N) => N; type SetAttributeTo<_T extends string, _V extends string> = (node: N) => N; declare const setAttribute: (attr: T) => SetAttribute; declare const getAttribute: (attr: T) => GetAttribute; /** * Provides the classes defined on a given container's top level * element as an array of strings */ declare const getClassList: (container: Container | HTML | null) => string[]; type RemoveClass = (container: C) => C; /** * Removes a class from the top level node of a container's body. * * Note: if the class wasn't present then no change is performed */ declare const removeClass: (remove: R) => RemoveClass; type AddClass = (container: C) => C; /** * Adds a class to the top level node of a document's body. */ declare const addClass: (...add: A) => AddClass; declare const addVueEvent: (event: keyof Events, value: string) => (el: T) => T; type Filter = string | RegExp; type FilterCallback = (removed: string[]) => void; type FiltersWithCallback = [FilterCallback, ...Filter[]]; /** * Filters classes out from a given element using _filters_, where a filter: * * - string - when a string it will compare for a direct match * - RegExp - will run the RegExp's `test(class)` method * * Optionally you may pass in a callback function as the first parameter in the * the list and this callback will be then called with all filtered properties * passed to it. This is useful for creating desirable side-effects like _moving_ * the classes to some other DOM element (for instance). */ declare const filterClasses: (...args: A) => (doc: D) => D; /** * Checks whether a given node has a parent reference */ declare const hasParentElement: (node: ContainerOrHtml) => boolean; /** * Get's the parent element of a given node or returns `null` if not * present. */ declare const getParent: (node: ContainerOrHtml) => happy_dom_without_node.Element | null; /** * Converts an HTML string into a Happy DOM document tree */ declare function createDocument(body: string, head?: string): HappyDoc; type FragmentFrom<_T extends Container | "html"> = IFragment; declare function createFragment(content?: C): FragmentFrom; /** * Creates a DOM Node which will be either an `IElement` or `IText` node * based on the content passed in. */ declare const createNode: (node: Container | string) => IElement | IText; /** * Creates a IText Node */ declare function createTextNode(text?: string): IText; declare function createCommentNode(comment?: string): IComment; /** * Creates an element node and can preserve parent relationship if known */ declare const createElement: (el: Container | HTML, parent?: IElement) => IElement; interface CssVariable { prop: string; value: string | number | boolean; } type ClassDefn = Record; type MultiClassDefn = [selector: string, keyValues: ClassDefn][]; interface ClassApi { /** add a child selector */ addChild: (selector: string, defn: ClassDefn) => ClassApi; /** add CSS prop/values */ addProps: (defn: ClassDefn) => ClassApi; } interface InlineStyle { /** add a single CSS variable (at a time); the CSS scope will ':root' unless specified */ addCssVariable: (prop: string, value: string | number | boolean, scope?: string) => InlineStyle; addClassDefinition: (selection: string, cb: (api: ClassApi) => void) => InlineStyle; addCssVariables: (dictionary: Record, scope?: string) => InlineStyle; convertToVueStyleBlock: (lang: "css" | "scss", scoped: boolean) => InlineStyle; finish: () => IElement; } /** * Creates a new `` node and provides a simple API surface to allow * populating the contents with inline CSS content */ declare const createInlineStyle: (type?: T) => InlineStyle; declare const describeNode: (node: Container | HTML | null | UpdateSignature | any[]) => string; declare const inspect: (item?: unknown, toJSON?: T) => false extends T ? Record : string; declare const tree: (node: Container | HTML) => Tree; /** * Allows various content-types to be wrapped into a single * Fragment which contains each element as a sibling */ declare const siblings: (...content: C) => [...C] extends infer T ? T extends [...C] ? T extends UpdateSignature ? false | IElement : happy_dom_without_node.DocumentFragment : never : never; interface StackLine { fn: string | undefined; line: number | undefined; file: string | undefined; } declare class HappyMishap extends Error { name: string; readonly kind: "HappyWrapper"; trace: string[]; readonly line: number | null; readonly fn: string; readonly file: string; readonly structuredStack: StackLine[]; toJSON(): { name: string; message: string; }; toString(): { name: string; message: string; }; constructor(message: string, options?: { error?: unknown; inspect?: unknown; name?: string; }); } /** * converts a IHTMLCollection or a INodeList to an array */ declare const getChildren: (el: Container) => (IElement | IText)[]; declare const getChildElements: (el: Container) => IElement[]; /** * Extracts a node from a DOM tree; is designed to be used with `update/updateAll()` * and the `updateChildren()` utilities. It can remove a set of elements as well as retain the extracted elements in * an array of nodes. * ``` * const memory = [] * domTree = select(domTree) * .updateAll('.bad-juju')(extract(memory)) * .toContainer() * ``` */ declare const extract: (memory?: M[]) => (node: T) => false; /** * **placeholder** * * Very similar to the `extract()` utility where it allows certain elements to be * removed from the DOM tree and stored in a separate variable but in this case * rather then leaving _nothing_ in it's place we can instead leave a _placeholder_ node. * * If you want to define what this placeholder node should look like you may -- * by setting the optional `placeholder` element -- but by default you will get: * * ```html * * ``` * * But all classes on removed element will be retained. */ declare const placeholder: (memory?: M[], placeholder?: IElement) => (node: T) => IElement; /** * Replaces an existing element with a brand new one while preserving the element's * relationship to the parent node (if one exists). */ declare const replaceElement: (newElement: IElement | HTML) => (oldElement: IElement) => IElement; /** * Appends one or more nodes to a parent container */ declare const append: (...nodes: N | N[]) =>

(parent: P) => P extends Array ? IElement : P; /** * A _partially applied_ instance of the `into()` utility; currently waiting * for child/children nodes. * * Note: the return type of this function is the Parent node (in whatever) * container type was passed in. However, child element(s) being wrapped which * had reference to a parent node, will have their parent node updated to * point now to the new parent node instead. This is important for proper * mutation when using the update/updateAll() utilities. */ type IntoChildren

= (...args: A) => A extends UpdateSignature ? IElement | false : undefined extends P ? IFragment : P; /** * A higher order function which starts by receiving a _wrapper_ component * and then is fully applied when the child nodes are passed in. * * This is the _inverse_ of the **wrap()** utility. * * ```ts * const sandwich = into(bread)(peanut, butter, jelly) * ``` */ declare const into:

(parent?: P) => IntoChildren

; type ChangeTagNameTo = (...el: E) => E extends UpdateSignature ? IElement : E; /** * Changes the tag name for the top level container element passed in * while preserving the parent node relationship. * ```ts * //

* const html = changeTagName('div')(`hi(tagName: T) => ChangeTagNameTo; /** * Prepends an `IElement` as the first child element of a host element. * * Note: you can use a string representation of an element * ```ts * const startWith = prepend('

just do it

') * const message: IElement = startWith(body) * ``` */ declare const prepend: (prepend: IElement | IText | HTML) => (el: IElement) => IElement; type Before<_T extends ContainerOrHtml> =
(...afterNode: A) => A extends UpdateSignature ? IElement : A extends string ? string : A; /** * Inserts a set of Node or string objects in the children list of this Element's * parent, just before this Element. String objects are inserted as equivalent Text nodes. * * Note: you can use a string representation of an element * ```ts * const startWith = before('

just do it

') * const message: IElement = startWith(body) * ``` */ declare const before: (beforeNode: B) => Before; declare const after: (afterNode: IElement | IText | HTML) => (beforeNode: B) => B; /** * A payload which is a partial application of the `wrap()` method and expects * to no w receive the parent element. */ type ReadyForWrapper<_C extends UpdateSignature | ContainerOrHtml[]> =

(parent: P) => undefined extends P ? IFragment : P; /** * **wrap** * * A higher order function which receives child elements which will need * to be wrapped and then fully applied when it receives the singular _wrapper_ * container. * * This is the _inverse_ of the **into()** utility. * * ```ts * const sandwich = wrap(peanut, butter, jelly)(bread) * ``` */ declare const wrap: (...children: C) => ReadyForWrapper; /** * Allows the _selection_ of HTML or a container type which is * then wrapped and a helpful query and mutation API is provided * to work with this DOM element. */ declare const select: (node: D) => NodeSelector; declare function isHappyWrapperError(err: unknown): err is HappyMishap; declare const isInspectionTuple: (thing: unknown) => thing is InspectionTuple; declare function isDocument(dom: unknown): dom is HappyDoc; declare function isFragment(dom: unknown): dom is IFragment; declare const nodeStartsWithElement: (node: D) => boolean; declare const nodeEndsWithElement: (node: D) => boolean; declare const nodeBoundedByElements: (node: D) => boolean; /** * tests whether a given node has a singular Element as a child * of the given node */ declare const hasSingularElement: (node: N) => boolean; declare function isElement(el: unknown): el is IElement; /** * **isHtmlElement** * * Tests whether the value passed in is an `HTMLElement` */ declare const isHtmlElement: (val: T) => val is T & HTMLElement; /** * determines if a Doc/DocFragment is a wrapper for only a singular * `IElement` node */ declare const isElementLike: (container: unknown) => boolean; /** * Tests whether a doc type is wrapping only a text node */ declare function isTextNodeLike(node: unknown): boolean; /** * Type guard which detects that the incoming calling signature matches * that of the `select()` utilities update/updateAll operation. */ declare const isUpdateSignature: (args: unknown) => args is UpdateSignature; declare function isTextNode(node: unknown): node is IText; declare const isContainer: (thing: unknown) => thing is Container; /** * detects whether _all_ children of a give node are Elements */ declare const nodeChildrenAllElements: (node: D) => boolean; /** * **isNodeList**`(val)` * * Type guards which validates that _val_ is a `NodeList` */ declare const isNodeList: (val: T) => val is T & NodeList; /** * **hasSelector**`(source, sel)` * * Tests whether a given DOM selector is found in the DOM source passed in. */ declare const hasSelector: (source: T, sel: string) => boolean; /** * **traverseUpward**`(el, sel)` * * Traverses up the DOM until it _matches_ the selector. If no match is found * a `DomError` will be thrown and the `element` property will have the element * this traversal from, the `selector` property will have the selector. */ declare const traverseUpward: (node: T, sel: string) => IElement; /** * **peers**`(el, sel)` * * Searches the elements peers using the passed in selector. If no match is found * a `DomError` will be thrown and the `element` property will have the element * this traversal from, the `selector` property will have the selector. */ declare const peers: (input: T, sel: string) => IElement; type HandlingApproach = "empty" | "throw" | "undefined" | (() => Narrowable); type DomSource = string | HappyDoc | Document | IFragment | IElement | HTMLElement; type MapContainerType = T extends string ? IsStringLiteral extends true ? Contains, ""> extends true ? HappyDoc : IFragment : HappyDoc | IFragment : T extends HTMLElement ? IElement : T extends Document ? IElement : never; type MapContainerTypeName = T extends string ? IsStringLiteral extends true ? Contains, ""> extends true ? "HappyDoc" : "IFragment" : "HappyDoc | IFragment" : T extends HTMLElement ? "IElement" : T extends Document ? "IElement" : never; /** * ***query***`(node,sel,[throwIfMissing])` * * A DOM query helper which takes an _input node_ and then uses querySelector() * to return the element if it's found. * * If it is not found you can choose from the following behaviors: * * - `empty` - by default if nothing is found then an empty object is returned * which allows you to _assume_ success using a syntax like `result?.textContent` * - `throw` - will throw a **DomError** * - `undefined` - returns an undefined value */ declare const query: (node: T, sel: string, handling?: H) => H extends "throw" ? IElement : H extends "empty" ? IElement | Record : H extends "undefined" ? IElement | undefined : H extends () => unknown ? ReturnType : never; /** * **queryAll** */ declare const queryAll: (dom: T, sel: string) => IElement[]; type TextCriteria = [ criteria: "contains" | "startsWith" | "endsWith" | "doesNotContain", comparator: string ] | [ criteria: "regex", comparator: RegExp ] | [ criteria: "callback", comparator: (el: IElement) => boolean ]; /** * **findWhere**`(source, sel, handling, condition)` * * Finds a single selection -- where possible -- that * meets the `sel` _selector_ criteria AND the text * criteria. * * Note: because there is a callback option, this can classify on * more than text content but that is the primary driver. * * **Related:** `findAllWhere()` */ declare const findWhere: (source: TSource, selector: TSelect, handling: THandle, ...text: TText) => THandle extends "throw" ? IElement : THandle extends "empty" ? IElement | Record : THandle extends "undefined" ? IElement | undefined : THandle extends () => unknown ? IElement | ReturnType : never; /** * **findAllWhere**`(source, selector, criteria, comparator)` * * Finds all elements which meet both the _selector_ criteria * as well as `criteria/comparator` condition. */ declare const findAllWhere: (source: TSource, selector: TSelect, ...text: TText) => IElement[]; /** * A DOM document originated from Happy DOM and renamed from * `Document` so as to avoid possible conflicts with Typescript's * built in `Document` type. */ interface HappyDoc extends Document$1 { } /** a document in happy-dom */ type IDocument = Document; /** a document fragment [happy-dom] */ type IDocumentFragment = DocumentFragment; /** a document fragment [happy-dom] */ type IFragment = DocumentFragment; /** An element in the DOM [happy-dom] */ type IElement = HTMLElement$1 & HTMLElement; /** a comment node in happy-dom */ type IComment = Comment; /** A text node in happy-dom */ type IText = Text; type INode = Node; export { type AddClass, type Before, type ChangeTagNameTo, type ClassApi, type ClassDefn, type Container, type ContainerOrHtml, type CssVariable, type DocRoot, type DomNode, type DomSource, type Filter, type FilterCallback, type FiltersWithCallback, type FragmentFrom, type GetAttribute, type HTML, type HandlingApproach, type HappyDoc, HappyMishap, type IComment, type IDocument, type IDocumentFragment, type IElement, type IFragment, type INode, type IText, type InlineStyle, type InspectionTuple, type IntoChildren, type MapCallback, type MapContainerType, type MapContainerTypeName, type MultiClassDefn, type NodeSelector, type NodeSolver, type NodeSolverDict, type NodeSolverInput, type NodeSolverReady, type NodeSolverReceiver, type NodeSolverWithExclusions, type NodeType, type NodeTypeInput, type ReadyForWrapper, type RemoveClass, type SetAttribute, type SetAttributeTo, type StackLine, type TextCriteria, type ToHtmlOptions, type Tree, type TreeSummary, type UpdateCallback, type UpdateCallback_Native, type UpdateSignature, addClass, addVueEvent, after, append, before, changeTagName, clone, createCommentNode, createDocument, createElement, createFragment, createInlineStyle, createNode, createTextNode, describeNode, extract, filterClasses, findAllWhere, findWhere, getAttribute, getChildElements, getChildren, getClassList, getNodeType, getParent, hasParentElement, hasSelector, hasSingularElement, inspect, into, isContainer, isDocument, isElement, isElementLike, isFragment, isHappyWrapperError, isHtmlElement, isInspectionTuple, isNodeList, isTextNode, isTextNodeLike, isUpdateSignature, nodeBoundedByElements, nodeChildrenAllElements, nodeEndsWithElement, nodeStartsWithElement, nodeTypeLookup, peers, placeholder, prepend, query, queryAll, removeClass, replaceElement, safeString, select, setAttribute, siblings, solveForNodeType, toHtml, traverseUpward, tree, wrap };