summaryrefslogtreecommitdiff
path: root/node_modules/posthtml/types
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/posthtml/types
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/posthtml/types')
-rw-r--r--node_modules/posthtml/types/posthtml.d.ts108
1 files changed, 108 insertions, 0 deletions
diff --git a/node_modules/posthtml/types/posthtml.d.ts b/node_modules/posthtml/types/posthtml.d.ts
new file mode 100644
index 0000000..0088dd2
--- /dev/null
+++ b/node_modules/posthtml/types/posthtml.d.ts
@@ -0,0 +1,108 @@
+type Maybe<T> = void | T;
+type MaybeArray<T> = T | T[];
+
+declare namespace PostHTML {
+ type StringMatcher = string | RegExp;
+ type AttrMatcher = Record<string, StringMatcher>;
+ type ContentMatcher =
+ | StringMatcher[]
+ | {
+ tag?: StringMatcher;
+ attrs?: AttrMatcher;
+ content?: ContentMatcher[];
+ };
+
+ export type Matcher<
+ TTag extends StringMatcher,
+ TAttrs extends Maybe<AttrMatcher>
+ > =
+ | StringMatcher
+ | {
+ tag?: TTag;
+ attrs?: TAttrs;
+ content?: ContentMatcher[];
+ };
+
+ export type Expression<
+ TTag extends StringMatcher,
+ TAttrs extends Maybe<AttrMatcher>
+ > = MaybeArray<Matcher<TTag, TAttrs>>;
+
+ export type NodeCallback<
+ TTag extends Maybe<string> = Maybe<string>,
+ TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
+ > = (node: Node<TTag, TAttrs>) => MaybeArray<Node | RawNode>;
+
+ export type NodeAttributes = Record<string, Maybe<string>>;
+
+ interface NodeAPI {
+ walk: (cb: NodeCallback) => Node;
+ match: <
+ TTag extends StringMatcher,
+ TAttrs extends Maybe<AttrMatcher>,
+ TTagResult extends Maybe<string> = TTag extends string
+ ? TTag
+ : TTag extends void
+ ? Maybe<string>
+ : string,
+ TAttrResult extends Maybe<NodeAttributes> = TAttrs extends void
+ ? Maybe<NodeAttributes>
+ : {
+ [P in keyof TAttrs]: string;
+ } &
+ NodeAttributes
+ >(
+ expression: Expression<TTag, TAttrs>,
+ cb: NodeCallback<TTagResult, TAttrResult>
+ ) => Node<TTagResult, TAttrResult>[];
+ }
+
+ export interface RawNode<
+ TTag extends Maybe<string> = Maybe<string>,
+ TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
+ > {
+ tag: TTag;
+ attrs: TAttrs;
+ content?: Array<string | RawNode>;
+ }
+
+ export interface Node<
+ TTag extends Maybe<string> = Maybe<string>,
+ TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
+ > extends NodeAPI, RawNode<TTag, TAttrs> {
+ content?: Array<string | Node>;
+ options?: Options;
+ }
+
+ export interface Options {
+ sync?: boolean;
+ parser?: Function;
+ render?: Function;
+ skipParse?: boolean;
+ }
+
+ export type Plugin<TThis> = (
+ tree: Node
+ ) => void | Node | RawNode | ThisType<TThis>;
+
+ export interface Result<TMessage> {
+ html: string;
+ tree: Node;
+ messages: TMessage[];
+ }
+
+ export interface PostHTML<TThis, TMessage> {
+ version: string;
+ name: "";
+ plugins: Plugin<TThis>[];
+ messages: TMessage[];
+ use<TThis>(plugins: MaybeArray<Plugin<TThis>>): this;
+ process(html: string, options?: Options): Promise<Result<TMessage>>;
+ }
+}
+
+declare function PostHTML<TThis, TMessage>(
+ plugins?: PostHTML.Plugin<TThis>[]
+): PostHTML.PostHTML<TThis, TMessage>;
+
+export = PostHTML;