{"version":3,"file":"create.mjs","names":["_createPlugin"],"sources":["../src/create.ts"],"sourcesContent":["import type { CreatePluginOptions as _CreatePluginOptions } from \"@ammolite/unplugin/rspack/create\";\nimport type {\n    DistPathConfig,\n    RsbuildConfig,\n    RsbuildPlugin,\n    RsbuildPluginAPI,\n} from \"@rsbuild/core\";\n\nimport type { PluginOptions } from \"#/@types/options\";\n\nimport * as Path from \"node:path\";\n\nimport { createPlugin as _createPlugin } from \"@ammolite/unplugin/rspack/create\";\n\nimport { name } from \"../package.json\";\n\ntype CreatePluginOptions = _CreatePluginOptions;\n\nconst getFileName = (\n    rsbuildConfig: RsbuildConfig,\n    options?: PluginOptions,\n): string => {\n    const isDev: boolean = process.env.NODE_ENV === \"development\";\n\n    const parsedPath: Path.ParsedPath = Path.parse(\n        options?.output?.fileName ?? \"index\",\n    );\n\n    const ext: string = parsedPath.ext === \"\" ? \".css\" : parsedPath.ext;\n\n    let fileName: string = `${parsedPath.name}${ext}`;\n\n    if (isDev) return fileName;\n\n    const filenameHash: string | boolean | undefined =\n        rsbuildConfig.output?.filenameHash;\n\n    if (typeof filenameHash === \"boolean\" && filenameHash === true) {\n        fileName = `${parsedPath.name}.[contenthash:8]${ext}`;\n    } else if (typeof filenameHash === \"string\") {\n        fileName = `${parsedPath.name}.[${filenameHash}]${ext}`;\n    }\n\n    return fileName;\n};\n\nconst createPlugin = (createOptions?: CreatePluginOptions) => {\n    return (options?: PluginOptions): RsbuildPlugin => {\n        return {\n            name,\n            async setup(api: RsbuildPluginAPI): Promise<void> {\n                const Plugin = _createPlugin({\n                    name: createOptions?.name ?? name,\n                    runtime: createOptions?.runtime,\n                });\n\n                api.modifyRsbuildConfig(\n                    (\n                        userConfig: RsbuildConfig,\n                        { mergeRsbuildConfig },\n                    ): RsbuildConfig => {\n                        const distPath: string | DistPathConfig | undefined =\n                            userConfig.output?.distPath;\n\n                        const dir: string =\n                            typeof distPath === \"string\"\n                                ? distPath\n                                : (distPath?.css ?? \"./static/css\");\n\n                        const config: RsbuildConfig = {\n                            tools: {\n                                rspack: {\n                                    plugins: [\n                                        new Plugin({\n                                            ...options,\n                                            output: {\n                                                ...userConfig.output,\n                                                dir,\n                                                fileName: getFileName(\n                                                    userConfig,\n                                                    options,\n                                                ),\n                                            },\n                                        }),\n                                    ],\n                                },\n                            },\n                        };\n\n                        return mergeRsbuildConfig(userConfig, config);\n                    },\n                );\n            },\n        };\n    };\n};\n\ntype Plugin = ReturnType<typeof createPlugin>;\n\nexport type { CreatePluginOptions, Plugin };\nexport { createPlugin };\n"],"mappings":";;;;AAkBA,MAAM,eACF,eACA,YACS;CACT,MAAM,QAAiB,QAAQ,IAAI,aAAa;CAEhD,MAAM,aAA8B,KAAK,MACrC,SAAS,QAAQ,YAAY,OACjC;CAEA,MAAM,MAAc,WAAW,QAAQ,KAAK,SAAS,WAAW;CAEhE,IAAI,WAAmB,GAAG,WAAW,OAAO;CAE5C,IAAI,OAAO,OAAO;CAElB,MAAM,eACF,cAAc,QAAQ;CAE1B,IAAI,OAAO,iBAAiB,aAAa,iBAAiB,MACtD,WAAW,GAAG,WAAW,KAAK,kBAAkB;MAC7C,IAAI,OAAO,iBAAiB,UAC/B,WAAW,GAAG,WAAW,KAAK,IAAI,aAAa,GAAG;CAGtD,OAAO;AACX;AAEA,MAAM,gBAAgB,kBAAwC;CAC1D,QAAQ,YAA2C;EAC/C,OAAO;GACH;GACA,MAAM,MAAM,KAAsC;IAC9C,MAAM,SAASA,eAAc;KACzB,MAAM,eAAe,QAAQ;KAC7B,SAAS,eAAe;IAC5B,CAAC;IAED,IAAI,qBAEI,YACA,EAAE,yBACc;KAChB,MAAM,WACF,WAAW,QAAQ;KAEvB,MAAM,MACF,OAAO,aAAa,WACd,WACC,UAAU,OAAO;KAsB5B,OAAO,mBAAmB,YAAY,EAnBlC,OAAO,EACH,QAAQ,EACJ,SAAS,CACL,IAAI,OAAO;MACP,GAAG;MACH,QAAQ;OACJ,GAAG,WAAW;OACd;OACA,UAAU,YACN,YACA,OACJ;MACJ;KACJ,CAAC,CACL,EACJ,EACJ,EAGuC,CAAC;IAChD,CACJ;GACJ;EACJ;CACJ;AACJ"}