1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Add plugin types (#1527)

Covered following plugins
- addAttributesToSVGElement.js 
- addClassesToSVGElement.js 
- cleanupAttrs.js 
- convertEllipseToCircle.js 
- removeAttributesBySelector.js 
- removeAttrs.js 
- removeComments.js 
- removeDesc.js 
- removeDoctype.js 
- removeElementsByAttr.js 
- removeEmptyText.js 
- removeMetadata.js 
- removeRasterImages.js 
- removeScriptElement.js 
- removeStyleElement.js 
- removeTitle.js 
- removeXMLProcInst.js
This commit is contained in:
Bogdan Chadkin
2021-08-15 13:52:41 +03:00
committed by GitHub
parent 7ec255719c
commit 9b8f13e911
22 changed files with 188 additions and 50 deletions

74
lib/types.ts Normal file
View File

@ -0,0 +1,74 @@
type XastDoctype = {
type: 'doctype';
name: string;
data: {
doctype: string;
};
};
type XastInstruction = {
type: 'instruction';
name: string;
value: string;
};
type XastComment = {
type: 'comment';
value: string;
};
type XastCdata = {
type: 'cdata';
value: string;
};
type XastText = {
type: 'text';
value: string;
};
type XastElement = {
type: 'element';
name: string;
attributes: Record<string, string>;
children: Array<XastChild>;
};
export type XastChild =
| XastDoctype
| XastInstruction
| XastComment
| XastCdata
| XastText
| XastElement;
type XastRoot = {
type: 'root';
children: Array<XastChild>;
};
export type XastParent = XastRoot | XastElement;
export type XastNode = XastRoot | XastChild;
type VisitorNode<Node> = {
enter?: (node: Node, parentNode: XastParent) => void;
leave?: (node: Node, parentNode: XastParent) => void;
};
type VisitorRoot = {
enter?: (node: XastRoot, parentNode: null) => void;
leave?: (node: XastRoot, parentNode: null) => void;
};
export type Visitor = {
doctype?: VisitorNode<XastDoctype>;
instruction?: VisitorNode<XastInstruction>;
comment?: VisitorNode<XastComment>;
cdata?: VisitorNode<XastCdata>;
text?: VisitorNode<XastText>;
element?: VisitorNode<XastElement>;
root?: VisitorRoot;
};
export type Plugin<Params> = (root: XastRoot, params: Params) => null | Visitor;