Files
Folo/apps/desktop/plugins/vite/ast.ts
T
Innei d87be02384 fix: update imports and enhance toast styles
- Changed import path for Transformer in ast.ts to streamline dependencies.
- Refined toast styles in styles.ts for improved visual consistency and hover effects.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-27 01:09:35 +08:00

46 lines
1.3 KiB
TypeScript

import { isTaggedFunctionCallOf } from "ast-kit"
import type { Transformer } from "unplugin-ast"
import { RemoveWrapperFunction } from "unplugin-ast/transformers"
import AST from "unplugin-ast/vite"
// Custom transformer for tw function that compresses template strings
const TwTransformer: Transformer<any> = {
onNode: (node) => isTaggedFunctionCallOf(node, ["tw"]),
transform(node) {
if (node.type === "TaggedTemplateExpression") {
const { quasi } = node
// Process template literals
if (quasi.type === "TemplateLiteral") {
// Get the raw string content
const rawString = quasi.quasis[0]?.value?.raw || ""
// Compress the string: remove extra whitespace, newlines, and normalize spaces
const compressedString = rawString
.replaceAll(/\s+/g, " ") // Replace multiple whitespace with single space
.trim() // Remove leading and trailing whitespace
// Update the template literal
quasi.quasis[0].value.raw = compressedString
quasi.quasis[0].value.cooked = compressedString
}
return quasi
}
return node.arguments[0]
},
}
export const astPlugin = AST({
transformer: [
TwTransformer,
RemoveWrapperFunction([
"defineSettingPageData",
"t_",
"tShortcuts",
"tSettings",
"defineFollowCommand",
]),
],
})