diff --git a/src/stylis-rtl.ts b/src/stylis-rtl.ts index 581bf93..658cc6c 100644 --- a/src/stylis-rtl.ts +++ b/src/stylis-rtl.ts @@ -1,4 +1,4 @@ -import cssjanus from 'cssjanus'; +import cssjanus from "cssjanus"; import { COMMENT, compile, @@ -7,26 +7,22 @@ import { RULESET, serialize, strlen, - Middleware, KEYFRAMES, MEDIA, SUPPORTS, -} from 'stylis'; + Element, +} from "stylis"; -type MiddlewareParams = Parameters; - -function stringifyPreserveComments( - element: MiddlewareParams[0], - index: MiddlewareParams[1], - children: MiddlewareParams[2] -): string { +function stringifyPreserveComments(element: Element): string { switch (element.type) { case IMPORT: case DECLARATION: case COMMENT: return (element.return = element.return || element.value); case RULESET: { - element.value = Array.isArray(element.props) ? element.props.join(',') : element.props; + element.value = Array.isArray(element.props) + ? element.props.join(",") + : element.props; if (Array.isArray(element.children)) { element.children.forEach((x) => { @@ -36,32 +32,35 @@ function stringifyPreserveComments( } } - const serializedChildren = serialize(Array.prototype.concat(element.children), stringifyPreserveComments); + const serializedChildren = serialize( + Array.prototype.concat(element.children), + stringifyPreserveComments + ); - return strlen(serializedChildren) ? (element.return = element.value + '{' + serializedChildren + '}') : ''; + return strlen(serializedChildren) + ? (element.return = element.value + "{" + serializedChildren + "}") + : ""; } -function stylisRTLPlugin( - element: MiddlewareParams[0], - index: MiddlewareParams[1], - children: MiddlewareParams[2], - callback: MiddlewareParams[3] -): string | void { +function stylisRTLPlugin(element: Element): string | void { if ( element.type === KEYFRAMES || element.type === SUPPORTS || - (element.type === RULESET && (!element.parent || element.parent.type === MEDIA || element.parent.type === RULESET)) + (element.type === RULESET && + (!element.parent || + element.parent.type === MEDIA || + element.parent.type === RULESET)) ) { - const stringified = cssjanus.transform(stringifyPreserveComments(element, index, children)); + const stringified = cssjanus.transform(stringifyPreserveComments(element)); element.children = stringified ? compile(stringified)[0].children : []; - element.return = ''; + element.return = ""; } } // stable identifier that will not be dropped by minification unless the whole module // is unused -Object.defineProperty(stylisRTLPlugin, 'name', { value: 'stylisRTLPlugin' }); +Object.defineProperty(stylisRTLPlugin, "name", { value: "stylisRTLPlugin" }); export default stylisRTLPlugin;