"use strict";var F=Object.create;var d=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var N=(n,t)=>{for(var e in t)d(n,e,{get:t[e],enumerable:!0})},D=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of z(t))!I.call(n,s)&&s!==e&&d(n,s,{get:()=>t[s],enumerable:!(i=O(t,s))||i.enumerable});return n};var S=(n,t,e)=>(e=n!=null?F(T(n)):{},D(t||!n||!n.__esModule?d(e,"default",{value:n,enumerable:!0}):e,n)),L=n=>D(d({},"__esModule",{value:!0}),n);var V={};N(V,{default:()=>R,unplugin:()=>$,unpluginFactory:()=>E});module.exports=L(V);var k=require("unplugin");var c=S(require("fs/promises"),1),l=require("path"),r=class n{static fullPath(t){return t=this.normalizePath(t),(0,l.join)(process.cwd(),t)}static rootPath(t){let e=process.cwd();return t?n.normalizePath((0,l.join)(e,t)):e}static convertOptions(t,e){let i=Object.assign({},t,e);return i.svgDir=n.fullPath(i.svgDir||t.svgDir),i.libraryDir=n.fullPath(i.libraryDir||t.libraryDir),i.cacheDir=n.fullPath(i.cacheDir||t.cacheDir),i}static async findNodeModules(){let t=process.cwd(),e=t;for(;e!=="/";){let i=(0,l.join)(e,"node_modules");if(await n.existsAsync(i))return i;e=(0,l.dirname)(e)}return`${t}/node_modules`}static async existsAsync(t){try{return await(0,c.access)(t),!0}catch{return!1}}static relativeToRoot(t){let e=process.cwd();return t=n.normalizePath(t),t.replace(e,"")}static async relativeToNodeModules(t){let e=await n.findNodeModules(),i="";for(let o=0;othis.normalizePath(i)).join("/");return e=e.replace(/\/\//g,"/"),e}static async ensureDirectoryExists(t){t=this.normalizePath(t);try{return(await c.default.stat(t)).isDirectory()}catch{try{return await c.default.mkdir(t,{recursive:!0}),!0}catch{return!1}}}static async deleteDirectory(t){if(t=this.normalizePath(t),!!await this.ensureDirectoryExists(t))try{await c.default.rm(t,{recursive:!0})}catch{}}static async ignorePath(t,e){!t||(t=this.normalizePath(t),e=this.normalizePath(e??".gitignore"),t=t.replace(process.cwd(),""),e=e?.replace(process.cwd(),""),e=(0,l.join)(process.cwd(),e),(await c.default.readFile(e,"utf-8")).includes(t))||await c.default.appendFile(e,` ${t}`)}static async appendLineIfNotExists(t,e){(await c.default.readFile(t,"utf-8")).includes(e)||await c.default.appendFile(t,`${e} `)}static async copyRecursive(t,e){if(t=this.normalizePath(t),e=this.normalizePath(e),(await c.default.stat(t)).isDirectory()){await c.default.mkdir(e,{recursive:!0});let s=await c.default.readdir(t);for(let a of s){let o=(0,l.join)(t,a),p=(0,l.join)(e,a);await n.copyRecursive(o,p)}}else await c.default.copyFile(t,e)}static async copy(t,e){t=this.normalizePath(t),e=this.normalizePath(e),await c.default.copyFile(t,e)}static async symLink(t,e){if(t=n.normalizePaths(t),e=n.normalizePaths(e),!await n.fileExists(e))try{await(0,c.symlink)(t,e)}catch{}}static relativePath(t,e){let i=(0,l.relative)((0,l.dirname)(t),e);return i.startsWith(".")?i:`./${i}`}};var f=class n{constructor(t,e="",i=!1){this.options=t;this.contents=e;this.useVue=i}static async make(t,e,i){let s=new n(t,e);await s.checkVue();let a="{ cacheDir?: string, global: boolean, libraryDir?: string, svgDir?: string, useTypes: boolean, isTesting: boolean, isNuxt: boolean, nuxtDir: string, fallback: string, svg: { classDefault?: string[], clearSize: 'all' | 'parent' | 'none', clearClass: 'all' | 'parent' | 'none', clearStyle: 'all' | 'parent' | 'none', currentColor: boolean, inlineStyleDefault?: string[], sizeInherit: boolean, title?: boolean }, warning: boolean }",o=["/* eslint-disable */","/* prettier-ignore */","// @ts-nocheck","// Generated by unplugin-svg-transformer","export {};","","declare global {",` ${e}`," interface Window {"," ust: {",` options: ${a}`," svgList: Record Promise<{ default: string }>>"," importSvg: (name: SvgName) => Promise"," }"," }","}",""];return s.useVue&&(o=[...o,"declare module 'vue' {"," export interface GlobalComponents {"," SvgIcon: typeof import('unplugin-svg-transformer/dist/vue')['SvgIcon']"," }","}",""]),i||(o=[...o,"window.ust = {"," options: options || {},"," svgList: svgList || {},"," importSvg: importSvg || function () {},","} || {}",""]),s.contents=o.join(` `),s}getContents(){return this.contents}async checkVue(){let t=r.rootPath("package.json");if(await r.fileExists(t)){let e=await r.read(t);/vue|nuxt/.test(e)&&(this.useVue=!0)}}async write(){let t=r.rootPath("icons.d.ts"),e=`${this.options.nuxtDir}/types/icons.d.ts`,i=r.packagePath({dist:!1,path:"client.d.ts"});await r.rm(i);let s=this.contents;s=s.replace("'unplugin-svg-transformer","'."),await r.write(i,s),await r.rm(t),this.options.global&&await r.write(t,this.contents);let a=r.rootPath("src/vite-env.d.ts");await r.fileExists(a)&&await r.appendLineIfNotExists(a,'/// '),await r.rm(e),this.options.isNuxt&&await r.write(e,this.contents)}};var x=require("path");var v=class n{constructor(t=[],e="",i=[],s={},a="ts"){this.items=t;this.library=e;this.types=i;this.options=s;this.extension=a}static async make(t,e){let i=new n(t.getItems());return i.extension=e.useTypes?"ts":"js",i.options=e,i.types=i.setTypes(),i.library=i.setLibrary(),i}getTypes(){return this.types}getTypesString(){return`export type SvgName = ${this.types.join(" | ")}`}setLibrary(t=!0){let e=["/* eslint-disable eslint-comments/no-unlimited-disable */","/* eslint-disable */","/* prettier-ignore */","// @ts-nocheck","// Generated by unplugin-svg-transformer"];(this.options.useTypes||this.options.isNuxt)&&(e=[...e,this.getTypesString()]);let i=JSON.stringify(this.parseOptions(),null,2);i=i.replace(/"([^(")"]+)":/g,"$1:"),e=[...e,`export const options = ${i}`,this.options.useTypes?"export const svgList: Record Promise<{ default: string }>> = {":"export const svgList = {"];let s=`${this.options.libraryDir}/icons.${this.extension}`;return this.items.forEach(a=>{let o=a.getPath().replace(".svg",`.${this.extension}`),p=r.normalizePaths([this.options.cacheDir,o]),g=r.relativePath(s,p);g=r.normalizePaths(g),this.options.isNuxt&&(g=`./icons${o}`),e.push(` '${a.getName()}': () => import('${g}'),`)}),e=[...e,"}","",this.options.useTypes?"export async function importSvg(name: SvgName): Promise {":"export async function importSvg(name) {"," if (!svgList[name] && options.warning)"," console.warn(`Icon ${name} not found`)",' const icon = svgList[name] || svgList["default"]'," const svg = await icon()",""," return svg.default","}"],t&&!this.options.isNuxt&&(e=[...e,"","if (typeof window !== 'undefined') {"," window.ust = window.ust || {}"," window.ust.options = options"," window.ust.svgList = svgList"," window.ust.importSvg = importSvg","}",""]),e.join(` `)}parseOptions(){return{fallback:this.options.fallback,svg:{classDefault:this.options.svg?.classDefault??void 0,clearSize:this.options.svg?.clearSize??"none",clearClass:this.options.svg?.clearClass??"none",clearStyle:this.options.svg?.clearStyle??"none",currentColor:this.options.svg?.currentColor??!1,inlineStyleDefault:this.options.svg?.inlineStyleDefault??void 0,sizeInherit:this.options.svg?.sizeInherit??!1,title:this.options.svg?.title??void 0},warning:this.options.warning??!1,cacheDir:this.parseOptionPath(this.options.cacheDir),global:this.options.global??!1,libraryDir:this.parseOptionPath(this.options.libraryDir),svgDir:this.parseOptionPath(this.options.svgDir),useTypes:this.options.useTypes??!1}}parseOptionPath(t){if(t)return t=t.replace(`${r.rootPath()}/`,""),`./${t}`}setTypes(){let t=[];return this.items.forEach(e=>{t.push(`'${e.getName()}'`)}),t}async writeFile(t){t=r.normalizePaths(t),await r.fileExists(t)&&await r.rm(t),await r.ensureDirectoryExists((0,x.dirname)(t)),await r.write(t,this.library)}async write(){if(this.options.isNuxt){let t=`${this.options.nuxtDir}/icons.${this.extension}`,e=`${r.packagePath({dist:!0})}/icons.${this.extension}`;await this.writeFile(t),await r.symLink(t,e)}else{let t=`${this.options.libraryDir}/icons.${this.extension}`,e=`${r.packagePath({dist:!0})}/icons.${this.extension}`;await this.writeFile(t),await r.symLink(t,e)}}};var b=S(require("fs/promises"),1),m=S(require("path"),1);var C=require("fs/promises"),h=class n{constructor(t,e,i,s="",a=[],o=[],p="",g="",A=""){this.options=t;this.path=e;this.title=i;this.contents=s;this.svgClass=a;this.svgStyle=o;this.parentStart=p;this.parentEnd=g;this.children=A}static make(t){return t||(t={classDefault:[],clearClass:"none",clearSize:"none",clearStyle:"none",currentColor:!1,inlineStyleDefault:[],sizeInherit:!1,title:!1}),new n(t)}setContents(t){return this.contents=t,this}setPath(t){return this.path=t,this}setTitle(t){return this.title=t,this}async get(){return await this.readFile(),this.contents=this.handleTitle(),this.parse(),this.options.classDefault&&(this.svgClass=[...this.svgClass,...this.options.classDefault]),this.options.inlineStyleDefault&&(this.svgStyle=[...this.svgStyle,...this.options.inlineStyleDefault]),this.options.clearSize==="all"&&(this.parentStart=this.removeWidthAndHeight(this.parentStart),this.children=this.removeWidthAndHeight(this.children)),this.options.clearSize==="parent"&&(this.parentStart=this.removeWidthAndHeight(this.parentStart)),this.options.clearClass==="all"&&(this.parentStart=this.removeClass(this.parentStart),this.children=this.removeClass(this.children)),this.options.clearClass==="parent"&&(this.parentStart=this.removeClass(this.parentStart)),this.options.clearStyle==="all"&&(this.parentStart=this.removeInlineStyle(this.parentStart),this.children=this.removeInlineStyle(this.children)),this.options.clearStyle==="parent"&&(this.parentStart=this.removeInlineStyle(this.parentStart)),this.options.currentColor&&this.addInlineCurrentColor(),this.contents=`${this.parentStart}${this.children}${this.parentEnd}`,this.options.sizeInherit&&this.addWidthAndHeightInherit(),this.contents=this.addInlineStyle(),this.contents=this.addClassDefault(),this.contents=this.removeTooLargeSpaces(),this}getContents(){return this.contents}async readFile(){if(this.path)try{this.contents=await(0,C.readFile)(this.path,"utf8")}catch{}}parse(){this.contents=this.removeBreakLines(),this.contents=this.removeTooLargeSpaces();let t=this.contents.match(/(<[^>]+>|[^<]+)/g),e=[];t?e=t.filter(i=>i!==" "):e=[this.contents],this.parentStart=e.shift()?.trim()??"",this.parentEnd=e.pop()?.trim()??"",this.children=e.join("").trim()??""}removeBreakLines(){return this.contents.replace(/\r?\n|\r/g,"")}removeTooLargeSpaces(){return this.contents.replace(/\s{2,}/g," ").replace(/>\s<").trim()}removeClass(t){return t.replace(/class=".*?"/g,"")}removeInlineStyle(t){return t.replace(/style=".*?"/g,"")}removeWidthAndHeight(t){return t.replace(/width=".*?"/g,"").replace(/height=".*?"/g,"")}addWidthAndHeightInherit(){this.svgStyle.some(t=>/width:.*?;/.test(t))||(this.svgStyle=[...this.svgStyle,"width: inherit;"]),this.svgStyle.some(t=>/height:.*?;/.test(t))||(this.svgStyle=[...this.svgStyle,"height: inherit;"])}addInlineStyle(){if(this.svgStyle.length===0)return this.contents;let t=this.svgStyle.join(" ");return/style=".*?"/.test(this.contents)?this.contents.replace(/style=".*?"/,`style="${t}"`):this.contents.replace(/.*?<\/title>/,"");if(/.*?<\/title>/.test(this.contents))return this.contents;let t=/]*)>/i,e=t.exec(this.contents);if(!e)return this.contents;let i=e[1],s=`${this.title}`;return this.contents.replace(t,`${s}`)}addInlineCurrentColor(){if(/stroke/.test(this.parentStart)&&!/stroke="none"/.test(this.parentStart)){if(/stroke="currentColor"/.test(this.parentStart))return;this.parentStart=this.parentStart.replace(/e.charAt(0).toUpperCase()+e.substring(1).toLowerCase()):""}};var y=class n{constructor(t,e,i,s){this.options=t;this.directoryPath=e;this.rootPath=i;this.items=s}static async make(t,e){let i=t.svgDir;e=e||i;let s=new n(t,i,e,[]);return s.items=await s.parse(i,e),s.items.push(await s.addDefaultSvg()),s}getItems(){return this.items}async parse(t,e){let i=[];e||(e=t);let s=await b.default.readdir(t);for(let a of s){let o=m.default.join(t,a);if((await b.default.stat(o)).isDirectory()){let g=await this.parse(o,e);i.push(...g)}else if(m.default.extname(a)===".svg"){let g=await u.make(o,e,this.options);i.push(g)}}return i}async print(){let t=[];return await Promise.all(this.items.map(async e=>{let i=e.getContents();i=`export default '${i}' `,t.push(i)})),t}async addDefaultSvg(){return u.getDefaultSvg(this.options,'')}async write(t){let e=t,i=this.items.map(async s=>{let a=s.getPath().replace(".svg",this.options.useTypes?".ts":".js");a=`${e}${a}`,await r.rm(a);let o=(0,m.dirname)(a);return await r.ensureDirectoryExists(o),await r.write(a,`export default '${s.getContents()}' `)});await Promise.all(i).then(()=>!0)}};var w=class n{constructor(t,e={contents:"",path:"",pathCJS:""},i={contents:"",path:"",pathCJS:""}){this.types=t;this.vue=e;this.react=i}static async make(t){let e=new n(t);return await e.replace("vue.d.ts","vue"),await e.replace("react.d.ts","react"),e}async replace(t,e){let i=r.componentsPath(t);if(!await r.fileExists(i))return"";let a=await r.read(i);return a.includes("type SvgName")?a=a.replace(/type SvgName = '(.*)'/g,this.types):a=a.replace("import React from 'react';",`import React from 'react'; ${this.types};`),a=a.replace(/type: PropType;/g,"type: PropType;"),a=a.replace(/name: string;/g,"name: SvgName;"),this[e]={contents:a,path:i,pathCJS:i.replace(/\.ts$/,".cts")},a}async write(){let t=[r.write(this.vue.path,this.vue.contents),r.write(this.vue.pathCJS,this.vue.contents),r.write(this.react.path,this.react.contents),r.write(this.react.pathCJS,this.react.contents)];await Promise.all(t)}getVue(){return this.vue}getReact(){return this.react}};var P=class n{constructor(t,e,i,s,a,o){this.options=t;this.cacheDir=e;this.collect=i;this.library=s;this.definition=a;this.componentDefinition=o}static async make(t){let e=t.cacheDir||r.packagePath({path:"cache"}),i=new n(t,e);return t.isNuxt&&(t.libraryDir=t.nuxtDir),await i.handleDirectories(),await i.parse(),await i.write(),i}async handleDirectories(){await r.deleteDirectory(this.cacheDir),await r.ensureDirectoryExists(this.options.svgDir),await r.ensureDirectoryExists(this.cacheDir),await r.ensureDirectoryExists(this.options.libraryDir)}async parse(){this.collect=await y.make(this.options),this.library=await v.make(this.collect,this.options),this.definition=await f.make(this.options,this.library.getTypesString(),this.options.isNuxt||!1),this.componentDefinition=await w.make(this.library.getTypesString())}async write(){let t=this.cacheDir;this.options.isNuxt&&(t=`${this.options.nuxtDir}/icons`,await r.deleteDirectory(t),await r.ensureDirectoryExists(t)),await this.collect?.write(t),await this.library?.write(),this.options.useTypes&&(await this.definition?.write(),await this.componentDefinition?.write()),await this.componentDefinition?.write()}};var j={svgDir:"./src/svg",libraryDir:"./src",useTypes:!0,global:!1,cacheDir:"./node_modules/unplugin-svg-transformer/cache",fallback:'',warning:!0},E=n=>({name:"unplugin-svg-transformer",async buildStart(){let t=r.convertOptions(j,n);t.isTesting=await W(),await P.make(t),process.on("warning",e=>console.warn(e.stack))},vite:{handleHotUpdate({file:t,server:e}){t.endsWith(".svg")&&e.restart()},configureServer(t){function e(i){i.endsWith(".svg")&&t.restart()}t.watcher.on("unlink",e)}}}),$=(0,k.createUnplugin)(E),R=$;async function W(){let n=r.packagePath({dist:!1}),t=`${n}/LICENSE`;if(!await r.fileExists(t)){let e=`${n}/package.json`,i="../../dist",s="../../package.json";if(!await r.fileExists(i))return!1;let a=`${n}/dist`;return await r.ensureDirectoryExists(a),await r.copyRecursive(i,a),await r.copy(s,e),!0}return!1}0&&(module.exports={unplugin,unpluginFactory}); exports.default = module.exports;