feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+437
View File
@@ -0,0 +1,437 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _chunkORVFCRDGcjs = require('./chunk-ORVFCRDG.cjs');
// src/index.ts
var _unplugin = require('unplugin');
// src/core/loader.ts
var _nodeloader = require('@iconify/utils/lib/loader/node-loader');
// src/core/compilers/astro.ts
var AstroCompiler = (svg) => {
const svgWithProps = svg.replace("<svg", "<svg {...props}");
return `---
interface Props extends astroHTML.JSX.SVGAttributes {};
const props = Astro.props;
---
${svgWithProps}`;
};
// src/core/compilers/jsx.ts
var _strings = require('@iconify/utils/lib/misc/strings');
var _localpkg = require('local-pkg');
var JSXCompiler = async (svg, collection, icon, options) => {
var _a;
const svgrCore = await _localpkg.importModule.call(void 0, "@svgr/core");
const svgr = svgrCore.transform || (svgrCore.default ? (_a = svgrCore.default.transform) != null ? _a : svgrCore.default : svgrCore.default) || svgrCore;
let res = await svgr(
svg,
{
plugins: ["@svgr/plugin-jsx"],
ref: options.jsx === "react"
},
{ componentName: _strings.camelize.call(void 0, `${collection}-${icon}`) }
);
if (options.jsx !== "react")
res = res.replace('import * as React from "react";', "");
return res;
};
// src/core/compilers/marko.ts
var MarkoCompiler = (svg) => {
const openTagEnd = svg.indexOf(">", svg.indexOf("<svg "));
const closeTagStart = svg.lastIndexOf("</svg");
const openTag = `${svg.slice(0, openTagEnd)} ...input>`;
const content = `$!{\`${escapeTemplateLiteral(svg.slice(openTagEnd + 1, closeTagStart))}\`}`;
const closeTag = svg.slice(closeTagStart);
return `${openTag}${content}${closeTag}`;
};
function escapeTemplateLiteral(str) {
return str.replace(/\\.|[$`]/g, (m) => {
switch (m) {
case "$":
return "&#36";
case "`":
return "&#96;";
default:
return m;
}
});
}
// src/core/compilers/none.ts
var NoneCompiler = (svg) => {
return svg;
};
// src/core/compilers/qwik.ts
var QwikCompiler = async (svg, collection, icon, options) => {
const defaultOptions = {
importSource: "@builder.io/qwik",
runtime: "automatic",
componentName: _strings.camelize.call(void 0, `${collection}-${icon}`)
};
const mergedOptions = Object.assign({}, defaultOptions, options);
const svgx = await _localpkg.importModule.call(void 0, "@svgx/core");
const toJsxComponent = svgx.toJsxComponent;
const res = toJsxComponent(svg, _chunkORVFCRDGcjs.__spreadProps.call(void 0, _chunkORVFCRDGcjs.__spreadValues.call(void 0, {}, mergedOptions), {
defaultExport: true
}));
return res;
};
// src/core/compilers/raw.ts
var RawCompiler = (svg) => {
return `export default ${JSON.stringify(svg)}`;
};
// src/core/compilers/solid.ts
var SolidCompiler = (svg) => {
const svgWithProps = svg.replace(/([{}])/g, "{'$1'}").replace(new RegExp("(?<=<svg[\\s\\S]*?)(>)", "i"), "{...props}>");
return `export default (props = {}) => ${svgWithProps}`;
};
// src/core/compilers/svelte.ts
var svelteRunes;
var SvelteCompiler = async (svg) => {
if (svelteRunes == null) {
try {
const { VERSION } = await Promise.resolve().then(() => _interopRequireWildcard(require("svelte/compiler")));
svelteRunes = Number(VERSION.split(".")[0]) >= 5;
} catch (e) {
svelteRunes = false;
}
}
const openTagEnd = svg.indexOf(">", svg.indexOf("<svg "));
const closeTagStart = svg.lastIndexOf("</svg");
let sfc = `${svg.slice(0, openTagEnd)} {...${svelteRunes ? "p" : "$$props"}}>`;
if (svelteRunes)
sfc += svg.slice(openTagEnd + 1, closeTagStart);
else
sfc += `{@html \`${escapeSvelte(svg.slice(openTagEnd + 1, closeTagStart))}\`}`;
sfc += svg.slice(closeTagStart);
return svelteRunes ? `<script>const{...p}=$props()</script>${sfc}` : sfc;
};
function escapeSvelte(str) {
return str.replace(/\{/g, "&#123;").replace(/\}/g, "&#125;").replace(/`/g, "&#96;").replace(/\\([trn])/g, " ");
}
// src/core/compilers/vue2.ts
// src/core/svgId.ts
var randIdFn = "const __randId = () => Math.random().toString(36).substr(2, 10);";
function handleSVGId(svg) {
const hasID = /="url\(#/.test(svg);
const idMap = {};
let injectScripts = "";
if (hasID) {
svg = svg.replace(/\b([\w-]+)="url\(#(.+?)\)"/g, (_, s, id) => {
idMap[id] = `'${id}':'uicons-'+__randId()`;
return `:${s}="'url(#'+idMap['${id}']+')'"`;
}).replace(/\bid="(.+?)"/g, (full, id) => {
if (idMap[id])
return `:id="idMap['${id}']"`;
return full;
});
injectScripts = `${randIdFn}const idMap = {${Object.values(idMap).join(",")}};`;
}
return {
hasID,
svg,
injectScripts
};
}
// src/core/compilers/vue2.ts
var Vue2Compiler = async (svg, collection, icon) => {
const { compile } = await _localpkg.importModule.call(void 0, "vue-template-compiler");
const transpileMod = await _localpkg.importModule.call(void 0, "vue-template-es2015-compiler");
const transpile = transpileMod.default || transpileMod;
const { injectScripts, svg: handled } = handleSVGId(svg);
const { render } = compile(handled);
const toFunction = (code2) => {
return `function () {${code2}}`;
};
let code = transpile(`var __render__ = ${toFunction(render)}
`, {});
code = code.replace(/\s__(render|staticRenderFns)__\s/g, " $1 ");
code += `
/* vite-plugin-components disabled */
export default {
render: render,
${injectScripts ? `data() {${injectScripts};return { idMap }},` : ""}
name: '${collection}-${icon}',
}
`;
return code;
};
// src/core/compilers/vue3.ts
var Vue3Compiler = async (svg, collection, icon) => {
const { compileTemplate } = await _localpkg.importModule.call(void 0, "@vue/compiler-sfc");
const { injectScripts, svg: handled } = handleSVGId(svg);
let { code } = compileTemplate({
source: handled,
id: `${collection}:${icon}`,
filename: `${collection}-${icon}.vue`
});
code = `import { markRaw } from 'vue'
${code}`;
code = code.replace(/^export /gm, "");
code += `
export default markRaw({ name: '${collection}-${icon}', render${injectScripts ? `, setup() {${injectScripts};return { idMap }}` : ""} })`;
code += "\n/* vite-plugin-components disabled */";
return code;
};
// src/core/compilers/web-components.ts
var WebComponentsCompiler = (svg, collection, icon, { webComponents: options }) => {
let id = `${collection}-${icon}`;
if (options.iconPrefix)
id = `${options.iconPrefix}-${id}`;
const name = _strings.camelize.call(void 0, id);
let code = `export default class ${name} extends HTMLElement {`;
if (options.shadow) {
code += `constructor() {
super()
this.attachShadow({ mode: 'open' }).innerHTML = ${JSON.stringify(svg)}
}`;
} else {
code += `connectedCallback() { this.innerHTML = ${JSON.stringify(svg)} }`;
}
code += "}";
if (options.autoDefine)
code += `
customElements.define('${id}', ${name})`;
return code;
};
// src/core/compilers/index.ts
var compilers = {
"astro": AstroCompiler,
"jsx": JSXCompiler,
"marko": MarkoCompiler,
"none": NoneCompiler,
"raw": RawCompiler,
"solid": SolidCompiler,
"svelte": SvelteCompiler,
"vue2": Vue2Compiler,
"vue3": Vue3Compiler,
"web-components": WebComponentsCompiler,
"qwik": QwikCompiler
};
// src/core/loader.ts
var URL_PREFIXES = ["/~icons/", "~icons/", "virtual:icons/", "virtual/icons/"];
var iconPathRE = new RegExp(`${URL_PREFIXES.map((v) => `^${v}`).join("|")}`);
function isIconPath(path) {
return iconPathRE.test(path);
}
function normalizeIconPath(path) {
return path.replace(iconPathRE, URL_PREFIXES[0]);
}
function resolveIconsPath(path) {
if (!isIconPath(path))
return null;
path = path.replace(iconPathRE, "");
const query = {};
const queryIndex = path.indexOf("?");
if (queryIndex !== -1) {
const queryRaw = path.slice(queryIndex + 1);
path = path.slice(0, queryIndex);
new URLSearchParams(queryRaw).forEach((value, key) => {
if (key === "raw")
query.raw = value === "" || value === "true" ? "true" : "false";
else
query[key] = value;
});
}
path = path.replace(/\.\w+$/, "");
const [collection, icon] = path.split("/");
return {
collection,
icon,
query
};
}
async function generateComponent({ collection, icon, query }, options) {
const warn = `${collection}/${icon}`;
const {
scale,
defaultStyle,
defaultClass,
customCollections,
iconCustomizer: providedIconCustomizer,
transform,
autoInstall = false,
collectionsNodeResolvePath
} = options;
const iconifyLoaderOptions = {
addXmlNs: false,
scale,
customCollections,
autoInstall,
defaultClass,
defaultStyle,
cwd: collectionsNodeResolvePath,
// there is no need to warn since we throw an error below
warn: void 0,
customizations: {
transform,
async iconCustomizer(collection2, icon2, props) {
await (providedIconCustomizer == null ? void 0 : providedIconCustomizer(collection2, icon2, props));
Object.keys(query).forEach((p) => {
const v = query[p];
if (p !== "raw" && v !== void 0 && v !== null)
props[p] = v;
});
}
}
};
const svg = await _nodeloader.loadNodeIcon.call(void 0, collection, icon, iconifyLoaderOptions);
if (!svg)
throw new Error(`Icon \`${warn}\` not found`);
const _compiler = query.raw === "true" ? "raw" : options.compiler;
if (_compiler) {
const compiler = typeof _compiler === "string" ? compilers[_compiler] : await _compiler.compiler;
if (compiler)
return compiler(svg, collection, icon, options);
}
throw new Error(`Unknown compiler: ${_compiler}`);
}
async function generateComponentFromPath(path, options) {
const resolved = resolveIconsPath(path);
if (!resolved)
return null;
return generateComponent(resolved, options);
}
// src/core/options.ts
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
var debug = _debug2.default.call(void 0, "unplugin-icons:options");
async function resolveOptions(options) {
const {
scale = 1.2,
defaultStyle = "",
defaultClass = "",
compiler = await guessCompiler(),
jsx = guessJSX(),
customCollections = {},
iconCustomizer = () => {
},
transform,
autoInstall = false,
collectionsNodeResolvePath = _process2.default.cwd()
} = options;
const webComponents = Object.assign({
autoDefine: false,
iconPrefix: "icon"
}, options.webComponents);
debug("compiler", compiler);
return {
scale,
defaultStyle,
defaultClass,
customCollections,
iconCustomizer,
compiler,
jsx,
webComponents,
transform,
autoInstall,
collectionsNodeResolvePath
};
}
async function guessCompiler() {
return await getVueVersion() || (_localpkg.isPackageExists.call(void 0, "@svgr/core") ? "jsx" : "vue3");
}
function guessJSX() {
if (_localpkg.isPackageExists.call(void 0, "preact"))
return "preact";
return "react";
}
async function getVueVersion() {
var _a;
try {
const result = await _localpkg.getPackageInfo.call(void 0, "vue");
if (!result || !result.version)
return null;
return ((_a = result.version) == null ? void 0 : _a.startsWith("2.")) ? "vue2" : "vue3";
} catch (e) {
return null;
}
}
// src/index.ts
var unplugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
const resolved = resolveOptions(options);
return {
name: "unplugin-icons",
enforce: "pre",
resolveId(id) {
var _a;
if (isIconPath(id)) {
const normalizedId = normalizeIconPath(id);
const queryIndex = normalizedId.indexOf("?");
const res = `${(queryIndex > -1 ? normalizedId.slice(0, queryIndex) : normalizedId).replace(/\.\w+$/, "").replace(/^\//, "")}${queryIndex > -1 ? `?${normalizedId.slice(queryIndex + 1)}` : ""}`;
const resolved2 = resolveIconsPath(res);
const compiler = ((_a = resolved2 == null ? void 0 : resolved2.query) == null ? void 0 : _a.raw) === "true" ? "raw" : options.compiler;
if (compiler && typeof compiler !== "string") {
const ext = compiler.extension;
if (ext)
return `${res}.${ext.startsWith(".") ? ext.slice(1) : ext}`;
} else {
switch (compiler) {
case "astro":
return `${res}.astro`;
case "jsx":
return `${res}.jsx`;
case "qwik":
return `${res}.jsx`;
case "marko":
return `${res}.marko`;
case "svelte":
return `${res}.svelte`;
case "solid":
return `${res}.tsx`;
}
}
return res;
}
return null;
},
loadInclude(id) {
return isIconPath(id);
},
async load(id) {
const config = await resolved;
const code = await generateComponentFromPath(id, config) || null;
if (code) {
return {
code,
map: { version: 3, mappings: "", sources: [] }
};
}
},
rollup: {
api: {
config: options
}
}
};
});
var src_default = unplugin;
exports.src_default = src_default;
View File
+437
View File
@@ -0,0 +1,437 @@
import {
__spreadProps,
__spreadValues
} from "./chunk-N3ETBM74.js";
// src/index.ts
import { createUnplugin } from "unplugin";
// src/core/loader.ts
import { loadNodeIcon } from "@iconify/utils/lib/loader/node-loader";
// src/core/compilers/astro.ts
var AstroCompiler = (svg) => {
const svgWithProps = svg.replace("<svg", "<svg {...props}");
return `---
interface Props extends astroHTML.JSX.SVGAttributes {};
const props = Astro.props;
---
${svgWithProps}`;
};
// src/core/compilers/jsx.ts
import { camelize } from "@iconify/utils/lib/misc/strings";
import { importModule } from "local-pkg";
var JSXCompiler = async (svg, collection, icon, options) => {
var _a;
const svgrCore = await importModule("@svgr/core");
const svgr = svgrCore.transform || (svgrCore.default ? (_a = svgrCore.default.transform) != null ? _a : svgrCore.default : svgrCore.default) || svgrCore;
let res = await svgr(
svg,
{
plugins: ["@svgr/plugin-jsx"],
ref: options.jsx === "react"
},
{ componentName: camelize(`${collection}-${icon}`) }
);
if (options.jsx !== "react")
res = res.replace('import * as React from "react";', "");
return res;
};
// src/core/compilers/marko.ts
var MarkoCompiler = (svg) => {
const openTagEnd = svg.indexOf(">", svg.indexOf("<svg "));
const closeTagStart = svg.lastIndexOf("</svg");
const openTag = `${svg.slice(0, openTagEnd)} ...input>`;
const content = `$!{\`${escapeTemplateLiteral(svg.slice(openTagEnd + 1, closeTagStart))}\`}`;
const closeTag = svg.slice(closeTagStart);
return `${openTag}${content}${closeTag}`;
};
function escapeTemplateLiteral(str) {
return str.replace(/\\.|[$`]/g, (m) => {
switch (m) {
case "$":
return "&#36";
case "`":
return "&#96;";
default:
return m;
}
});
}
// src/core/compilers/none.ts
var NoneCompiler = (svg) => {
return svg;
};
// src/core/compilers/qwik.ts
import { camelize as camelize2 } from "@iconify/utils/lib/misc/strings";
import { importModule as importModule2 } from "local-pkg";
var QwikCompiler = async (svg, collection, icon, options) => {
const defaultOptions = {
importSource: "@builder.io/qwik",
runtime: "automatic",
componentName: camelize2(`${collection}-${icon}`)
};
const mergedOptions = Object.assign({}, defaultOptions, options);
const svgx = await importModule2("@svgx/core");
const toJsxComponent = svgx.toJsxComponent;
const res = toJsxComponent(svg, __spreadProps(__spreadValues({}, mergedOptions), {
defaultExport: true
}));
return res;
};
// src/core/compilers/raw.ts
var RawCompiler = (svg) => {
return `export default ${JSON.stringify(svg)}`;
};
// src/core/compilers/solid.ts
var SolidCompiler = (svg) => {
const svgWithProps = svg.replace(/([{}])/g, "{'$1'}").replace(new RegExp("(?<=<svg[\\s\\S]*?)(>)", "i"), "{...props}>");
return `export default (props = {}) => ${svgWithProps}`;
};
// src/core/compilers/svelte.ts
var svelteRunes;
var SvelteCompiler = async (svg) => {
if (svelteRunes == null) {
try {
const { VERSION } = await import("svelte/compiler");
svelteRunes = Number(VERSION.split(".")[0]) >= 5;
} catch (e) {
svelteRunes = false;
}
}
const openTagEnd = svg.indexOf(">", svg.indexOf("<svg "));
const closeTagStart = svg.lastIndexOf("</svg");
let sfc = `${svg.slice(0, openTagEnd)} {...${svelteRunes ? "p" : "$$props"}}>`;
if (svelteRunes)
sfc += svg.slice(openTagEnd + 1, closeTagStart);
else
sfc += `{@html \`${escapeSvelte(svg.slice(openTagEnd + 1, closeTagStart))}\`}`;
sfc += svg.slice(closeTagStart);
return svelteRunes ? `<script>const{...p}=$props()</script>${sfc}` : sfc;
};
function escapeSvelte(str) {
return str.replace(/\{/g, "&#123;").replace(/\}/g, "&#125;").replace(/`/g, "&#96;").replace(/\\([trn])/g, " ");
}
// src/core/compilers/vue2.ts
import { importModule as importModule3 } from "local-pkg";
// src/core/svgId.ts
var randIdFn = "const __randId = () => Math.random().toString(36).substr(2, 10);";
function handleSVGId(svg) {
const hasID = /="url\(#/.test(svg);
const idMap = {};
let injectScripts = "";
if (hasID) {
svg = svg.replace(/\b([\w-]+)="url\(#(.+?)\)"/g, (_, s, id) => {
idMap[id] = `'${id}':'uicons-'+__randId()`;
return `:${s}="'url(#'+idMap['${id}']+')'"`;
}).replace(/\bid="(.+?)"/g, (full, id) => {
if (idMap[id])
return `:id="idMap['${id}']"`;
return full;
});
injectScripts = `${randIdFn}const idMap = {${Object.values(idMap).join(",")}};`;
}
return {
hasID,
svg,
injectScripts
};
}
// src/core/compilers/vue2.ts
var Vue2Compiler = async (svg, collection, icon) => {
const { compile } = await importModule3("vue-template-compiler");
const transpileMod = await importModule3("vue-template-es2015-compiler");
const transpile = transpileMod.default || transpileMod;
const { injectScripts, svg: handled } = handleSVGId(svg);
const { render } = compile(handled);
const toFunction = (code2) => {
return `function () {${code2}}`;
};
let code = transpile(`var __render__ = ${toFunction(render)}
`, {});
code = code.replace(/\s__(render|staticRenderFns)__\s/g, " $1 ");
code += `
/* vite-plugin-components disabled */
export default {
render: render,
${injectScripts ? `data() {${injectScripts};return { idMap }},` : ""}
name: '${collection}-${icon}',
}
`;
return code;
};
// src/core/compilers/vue3.ts
import { importModule as importModule4 } from "local-pkg";
var Vue3Compiler = async (svg, collection, icon) => {
const { compileTemplate } = await importModule4("@vue/compiler-sfc");
const { injectScripts, svg: handled } = handleSVGId(svg);
let { code } = compileTemplate({
source: handled,
id: `${collection}:${icon}`,
filename: `${collection}-${icon}.vue`
});
code = `import { markRaw } from 'vue'
${code}`;
code = code.replace(/^export /gm, "");
code += `
export default markRaw({ name: '${collection}-${icon}', render${injectScripts ? `, setup() {${injectScripts};return { idMap }}` : ""} })`;
code += "\n/* vite-plugin-components disabled */";
return code;
};
// src/core/compilers/web-components.ts
import { camelize as camelize3 } from "@iconify/utils/lib/misc/strings";
var WebComponentsCompiler = (svg, collection, icon, { webComponents: options }) => {
let id = `${collection}-${icon}`;
if (options.iconPrefix)
id = `${options.iconPrefix}-${id}`;
const name = camelize3(id);
let code = `export default class ${name} extends HTMLElement {`;
if (options.shadow) {
code += `constructor() {
super()
this.attachShadow({ mode: 'open' }).innerHTML = ${JSON.stringify(svg)}
}`;
} else {
code += `connectedCallback() { this.innerHTML = ${JSON.stringify(svg)} }`;
}
code += "}";
if (options.autoDefine)
code += `
customElements.define('${id}', ${name})`;
return code;
};
// src/core/compilers/index.ts
var compilers = {
"astro": AstroCompiler,
"jsx": JSXCompiler,
"marko": MarkoCompiler,
"none": NoneCompiler,
"raw": RawCompiler,
"solid": SolidCompiler,
"svelte": SvelteCompiler,
"vue2": Vue2Compiler,
"vue3": Vue3Compiler,
"web-components": WebComponentsCompiler,
"qwik": QwikCompiler
};
// src/core/loader.ts
var URL_PREFIXES = ["/~icons/", "~icons/", "virtual:icons/", "virtual/icons/"];
var iconPathRE = new RegExp(`${URL_PREFIXES.map((v) => `^${v}`).join("|")}`);
function isIconPath(path) {
return iconPathRE.test(path);
}
function normalizeIconPath(path) {
return path.replace(iconPathRE, URL_PREFIXES[0]);
}
function resolveIconsPath(path) {
if (!isIconPath(path))
return null;
path = path.replace(iconPathRE, "");
const query = {};
const queryIndex = path.indexOf("?");
if (queryIndex !== -1) {
const queryRaw = path.slice(queryIndex + 1);
path = path.slice(0, queryIndex);
new URLSearchParams(queryRaw).forEach((value, key) => {
if (key === "raw")
query.raw = value === "" || value === "true" ? "true" : "false";
else
query[key] = value;
});
}
path = path.replace(/\.\w+$/, "");
const [collection, icon] = path.split("/");
return {
collection,
icon,
query
};
}
async function generateComponent({ collection, icon, query }, options) {
const warn = `${collection}/${icon}`;
const {
scale,
defaultStyle,
defaultClass,
customCollections,
iconCustomizer: providedIconCustomizer,
transform,
autoInstall = false,
collectionsNodeResolvePath
} = options;
const iconifyLoaderOptions = {
addXmlNs: false,
scale,
customCollections,
autoInstall,
defaultClass,
defaultStyle,
cwd: collectionsNodeResolvePath,
// there is no need to warn since we throw an error below
warn: void 0,
customizations: {
transform,
async iconCustomizer(collection2, icon2, props) {
await (providedIconCustomizer == null ? void 0 : providedIconCustomizer(collection2, icon2, props));
Object.keys(query).forEach((p) => {
const v = query[p];
if (p !== "raw" && v !== void 0 && v !== null)
props[p] = v;
});
}
}
};
const svg = await loadNodeIcon(collection, icon, iconifyLoaderOptions);
if (!svg)
throw new Error(`Icon \`${warn}\` not found`);
const _compiler = query.raw === "true" ? "raw" : options.compiler;
if (_compiler) {
const compiler = typeof _compiler === "string" ? compilers[_compiler] : await _compiler.compiler;
if (compiler)
return compiler(svg, collection, icon, options);
}
throw new Error(`Unknown compiler: ${_compiler}`);
}
async function generateComponentFromPath(path, options) {
const resolved = resolveIconsPath(path);
if (!resolved)
return null;
return generateComponent(resolved, options);
}
// src/core/options.ts
import process from "node:process";
import createDebugger from "debug";
import { getPackageInfo, isPackageExists } from "local-pkg";
var debug = createDebugger("unplugin-icons:options");
async function resolveOptions(options) {
const {
scale = 1.2,
defaultStyle = "",
defaultClass = "",
compiler = await guessCompiler(),
jsx = guessJSX(),
customCollections = {},
iconCustomizer = () => {
},
transform,
autoInstall = false,
collectionsNodeResolvePath = process.cwd()
} = options;
const webComponents = Object.assign({
autoDefine: false,
iconPrefix: "icon"
}, options.webComponents);
debug("compiler", compiler);
return {
scale,
defaultStyle,
defaultClass,
customCollections,
iconCustomizer,
compiler,
jsx,
webComponents,
transform,
autoInstall,
collectionsNodeResolvePath
};
}
async function guessCompiler() {
return await getVueVersion() || (isPackageExists("@svgr/core") ? "jsx" : "vue3");
}
function guessJSX() {
if (isPackageExists("preact"))
return "preact";
return "react";
}
async function getVueVersion() {
var _a;
try {
const result = await getPackageInfo("vue");
if (!result || !result.version)
return null;
return ((_a = result.version) == null ? void 0 : _a.startsWith("2.")) ? "vue2" : "vue3";
} catch (e) {
return null;
}
}
// src/index.ts
var unplugin = createUnplugin((options = {}) => {
const resolved = resolveOptions(options);
return {
name: "unplugin-icons",
enforce: "pre",
resolveId(id) {
var _a;
if (isIconPath(id)) {
const normalizedId = normalizeIconPath(id);
const queryIndex = normalizedId.indexOf("?");
const res = `${(queryIndex > -1 ? normalizedId.slice(0, queryIndex) : normalizedId).replace(/\.\w+$/, "").replace(/^\//, "")}${queryIndex > -1 ? `?${normalizedId.slice(queryIndex + 1)}` : ""}`;
const resolved2 = resolveIconsPath(res);
const compiler = ((_a = resolved2 == null ? void 0 : resolved2.query) == null ? void 0 : _a.raw) === "true" ? "raw" : options.compiler;
if (compiler && typeof compiler !== "string") {
const ext = compiler.extension;
if (ext)
return `${res}.${ext.startsWith(".") ? ext.slice(1) : ext}`;
} else {
switch (compiler) {
case "astro":
return `${res}.astro`;
case "jsx":
return `${res}.jsx`;
case "qwik":
return `${res}.jsx`;
case "marko":
return `${res}.marko`;
case "svelte":
return `${res}.svelte`;
case "solid":
return `${res}.tsx`;
}
}
return res;
}
return null;
},
loadInclude(id) {
return isIconPath(id);
},
async load(id) {
const config = await resolved;
const code = await generateComponentFromPath(id, config) || null;
if (code) {
return {
code,
map: { version: 3, mappings: "", sources: [] }
};
}
},
rollup: {
api: {
config: options
}
}
};
});
var src_default = unplugin;
export {
src_default
};
+24
View File
@@ -0,0 +1,24 @@
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
export {
__spreadValues,
__spreadProps
};
+24
View File
@@ -0,0 +1,24 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps;
+1
View File
@@ -0,0 +1 @@
"use strict";
+11
View File
@@ -0,0 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/esbuild.ts
var esbuild_default = _chunk2ZA4SHTDcjs.src_default.esbuild;
exports.default = esbuild_default;
+7
View File
@@ -0,0 +1,7 @@
import * as unplugin from 'unplugin';
import { Options } from './types.cjs';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin;
export { _default as default };
+7
View File
@@ -0,0 +1,7 @@
import * as unplugin from 'unplugin';
import { Options } from './types.js';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin;
export { _default as default };
+11
View File
@@ -0,0 +1,11 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/esbuild.ts
var esbuild_default = src_default.esbuild;
export {
esbuild_default as default
};
+8
View File
@@ -0,0 +1,8 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
exports.default = _chunk2ZA4SHTDcjs.src_default;
+8
View File
@@ -0,0 +1,8 @@
import * as unplugin$1 from 'unplugin';
import { Options } from './types.cjs';
export { CustomCompiler, CustomIconLoader, IconCustomizer, InlineCollection, ResolvedOptions } from './types.cjs';
import '@antfu/utils';
declare const unplugin: unplugin$1.UnpluginInstance<Options | undefined, boolean>;
export { Options, unplugin as default };
+8
View File
@@ -0,0 +1,8 @@
import * as unplugin$1 from 'unplugin';
import { Options } from './types.js';
export { CustomCompiler, CustomIconLoader, IconCustomizer, InlineCollection, ResolvedOptions } from './types.js';
import '@antfu/utils';
declare const unplugin: unplugin$1.UnpluginInstance<Options | undefined, boolean>;
export { Options, unplugin as default };
+8
View File
@@ -0,0 +1,8 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
export {
src_default as default
};
+15
View File
@@ -0,0 +1,15 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-ORVFCRDG.cjs');
// src/loaders.ts
var _externalpkg = require('@iconify/utils/lib/loader/external-pkg');
var _nodeloaders = require('@iconify/utils/lib/loader/node-loaders');
function FileSystemIconLoader(dir, transform) {
return _nodeloaders.FileSystemIconLoader.call(void 0, dir, transform);
}
function ExternalPackageIconLoader(packageName, autoInstall) {
return _externalpkg.createExternalPackageIconLoader.call(void 0, packageName, autoInstall);
}
exports.ExternalPackageIconLoader = ExternalPackageIconLoader; exports.FileSystemIconLoader = FileSystemIconLoader;
+8
View File
@@ -0,0 +1,8 @@
import { Awaitable } from '@antfu/utils';
import { ExternalPkgName, AutoInstall } from '@iconify/utils/lib/loader/types';
import { CustomIconLoader } from './types.cjs';
declare function FileSystemIconLoader(dir: string, transform?: (svg: string) => Awaitable<string>): CustomIconLoader;
declare function ExternalPackageIconLoader(packageName: ExternalPkgName, autoInstall?: AutoInstall): Record<string, CustomIconLoader>;
export { ExternalPackageIconLoader, FileSystemIconLoader };
+8
View File
@@ -0,0 +1,8 @@
import { Awaitable } from '@antfu/utils';
import { ExternalPkgName, AutoInstall } from '@iconify/utils/lib/loader/types';
import { CustomIconLoader } from './types.js';
declare function FileSystemIconLoader(dir: string, transform?: (svg: string) => Awaitable<string>): CustomIconLoader;
declare function ExternalPackageIconLoader(packageName: ExternalPkgName, autoInstall?: AutoInstall): Record<string, CustomIconLoader>;
export { ExternalPackageIconLoader, FileSystemIconLoader };
+15
View File
@@ -0,0 +1,15 @@
import "./chunk-N3ETBM74.js";
// src/loaders.ts
import { createExternalPackageIconLoader } from "@iconify/utils/lib/loader/external-pkg";
import { FileSystemIconLoader as IconifyFileSystemIconLoader } from "@iconify/utils/lib/loader/node-loaders";
function FileSystemIconLoader(dir, transform) {
return IconifyFileSystemIconLoader(dir, transform);
}
function ExternalPackageIconLoader(packageName, autoInstall) {
return createExternalPackageIconLoader(packageName, autoInstall);
}
export {
ExternalPackageIconLoader,
FileSystemIconLoader
};
+32
View File
@@ -0,0 +1,32 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/nuxt.ts
function nuxt_default(options = {}, nuxt) {
var _a, _b, _c, _d, _e;
const nuxtApp = (this == null ? void 0 : this.nuxt) || nuxt;
if ((_a = nuxtApp == null ? void 0 : nuxtApp._version) == null ? void 0 : _a.startsWith("3.")) {
options.compiler = "vue3";
(_b = nuxtApp.options).typescript || (_b.typescript = {});
(_c = nuxtApp.options.typescript).tsConfig || (_c.tsConfig = {});
(_d = nuxtApp.options.typescript.tsConfig).compilerOptions || (_d.compilerOptions = {});
(_e = nuxtApp.options.typescript.tsConfig.compilerOptions).types || (_e.types = []);
nuxtApp.options.typescript.tsConfig.compilerOptions.types.push("unplugin-icons/types/vue");
}
nuxtApp.hook("webpack:config", (configs) => {
configs.forEach((config) => {
config.plugins = config.plugins || [];
config.plugins.unshift(_chunk2ZA4SHTDcjs.src_default.webpack(options));
});
});
nuxtApp.hook("vite:extend", async (vite) => {
vite.config.plugins = vite.config.plugins || [];
vite.config.plugins.push(_chunk2ZA4SHTDcjs.src_default.vite(options));
});
}
exports.default = nuxt_default;
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.cjs';
import '@antfu/utils';
declare function export_default(this: any, options: Options | undefined, nuxt: any): void;
export { export_default as default };
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.js';
import '@antfu/utils';
declare function export_default(this: any, options: Options | undefined, nuxt: any): void;
export { export_default as default };
+32
View File
@@ -0,0 +1,32 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/nuxt.ts
function nuxt_default(options = {}, nuxt) {
var _a, _b, _c, _d, _e;
const nuxtApp = (this == null ? void 0 : this.nuxt) || nuxt;
if ((_a = nuxtApp == null ? void 0 : nuxtApp._version) == null ? void 0 : _a.startsWith("3.")) {
options.compiler = "vue3";
(_b = nuxtApp.options).typescript || (_b.typescript = {});
(_c = nuxtApp.options.typescript).tsConfig || (_c.tsConfig = {});
(_d = nuxtApp.options.typescript.tsConfig).compilerOptions || (_d.compilerOptions = {});
(_e = nuxtApp.options.typescript.tsConfig.compilerOptions).types || (_e.types = []);
nuxtApp.options.typescript.tsConfig.compilerOptions.types.push("unplugin-icons/types/vue");
}
nuxtApp.hook("webpack:config", (configs) => {
configs.forEach((config) => {
config.plugins = config.plugins || [];
config.plugins.unshift(src_default.webpack(options));
});
});
nuxtApp.hook("vite:extend", async (vite) => {
vite.config.plugins = vite.config.plugins || [];
vite.config.plugins.push(src_default.vite(options));
});
}
export {
nuxt_default as default
};
+255
View File
@@ -0,0 +1,255 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-ORVFCRDG.cjs');
// src/resolver.ts
var _utils = require('@antfu/utils');
var _strings = require('@iconify/utils/lib/misc/strings');
// src/core/icon-sets.json
var icon_sets_default = [
"academicons",
"akar-icons",
"ant-design",
"arcticons",
"basil",
"bi",
"bitcoin-icons",
"bpmn",
"brandico",
"bx",
"bxl",
"bxs",
"bytesize",
"carbon",
"catppuccin",
"cbi",
"charm",
"ci",
"cib",
"cif",
"cil",
"circle-flags",
"circum",
"clarity",
"codicon",
"covid",
"cryptocurrency",
"cryptocurrency-color",
"cuida",
"dashicons",
"devicon",
"devicon-plain",
"duo-icons",
"ei",
"el",
"emojione",
"emojione-monotone",
"emojione-v1",
"entypo",
"entypo-social",
"eos-icons",
"ep",
"et",
"eva",
"f7",
"fa",
"fa-brands",
"fa-regular",
"fa-solid",
"fa6-brands",
"fa6-regular",
"fa6-solid",
"fad",
"fe",
"feather",
"file-icons",
"flag",
"flagpack",
"flat-color-icons",
"flat-ui",
"flowbite",
"fluent",
"fluent-color",
"fluent-emoji",
"fluent-emoji-flat",
"fluent-emoji-high-contrast",
"fluent-mdl2",
"fontelico",
"fontisto",
"formkit",
"foundation",
"fxemoji",
"gala",
"game-icons",
"geo",
"gg",
"gis",
"gravity-ui",
"gridicons",
"grommet-icons",
"guidance",
"healthicons",
"heroicons",
"heroicons-outline",
"heroicons-solid",
"hugeicons",
"humbleicons",
"ic",
"icomoon-free",
"icon-park",
"icon-park-outline",
"icon-park-solid",
"icon-park-twotone",
"iconamoon",
"iconoir",
"icons8",
"il",
"ion",
"iwwa",
"ix",
"jam",
"la",
"lets-icons",
"line-md",
"lineicons",
"logos",
"ls",
"lsicon",
"lucide",
"lucide-lab",
"mage",
"majesticons",
"maki",
"map",
"marketeq",
"material-symbols",
"material-symbols-light",
"mdi",
"mdi-light",
"medical-icon",
"memory",
"meteocons",
"meteor-icons",
"mi",
"mingcute",
"mono-icons",
"mynaui",
"nimbus",
"nonicons",
"noto",
"noto-v1",
"nrk",
"octicon",
"oi",
"ooui",
"openmoji",
"oui",
"pajamas",
"pepicons",
"pepicons-pencil",
"pepicons-pop",
"pepicons-print",
"ph",
"pixelarticons",
"prime",
"proicons",
"ps",
"qlementine-icons",
"quill",
"radix-icons",
"raphael",
"ri",
"rivet-icons",
"si",
"si-glyph",
"simple-icons",
"simple-line-icons",
"skill-icons",
"solar",
"stash",
"streamline",
"streamline-emojis",
"subway",
"svg-spinners",
"system-uicons",
"tabler",
"tdesign",
"teenyicons",
"token",
"token-branded",
"topcoat",
"twemoji",
"typcn",
"uil",
"uim",
"uis",
"uit",
"uiw",
"unjs",
"vaadin",
"vs",
"vscode-icons",
"websymbol",
"weui",
"whh",
"wi",
"wpf",
"zmdi",
"zondicons"
];
// src/resolver.ts
function ComponentsResolver(options = {}) {
var _a;
const {
prefix: rawPrefix = (_a = options.componentPrefix) != null ? _a : "i",
enabledCollections = icon_sets_default,
alias = {},
customCollections = [],
extension,
strict = false
} = options;
const prefix = rawPrefix ? `${_strings.camelToKebab.call(void 0, rawPrefix)}-` : "";
const ext = extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
const collections = _utils.uniq.call(void 0, [
..._utils.toArray.call(void 0, enabledCollections),
..._utils.toArray.call(void 0, customCollections),
..._utils.toArray.call(void 0, Object.keys(alias))
]);
collections.sort((a, b) => b.length - a.length);
return (name) => {
let collection;
let icon;
if (name.includes(":")) {
const [iconPrefix, iconSuffix] = name.split(":");
collection = _strings.camelToKebab.call(void 0, iconPrefix);
if (!collection.startsWith(prefix))
return;
const slice = collection.slice(prefix.length);
const resolvedCollection2 = collections.find((i) => slice === i);
if (!resolvedCollection2)
return;
collection = resolvedCollection2;
icon = _strings.camelToKebab.call(void 0, iconSuffix);
} else {
const kebab = _strings.camelToKebab.call(void 0, name);
if (!kebab.startsWith(prefix))
return;
const slice = kebab.slice(prefix.length);
const resolvedCollection2 = collections.find((i) => slice.startsWith(`${i}-`)) || !strict && collections.find((i) => slice.startsWith(i));
if (!resolvedCollection2)
return;
collection = resolvedCollection2;
icon = slice.slice(resolvedCollection2.length);
}
if (icon[0] === "-")
icon = icon.slice(1);
if (!icon)
return;
const resolvedCollection = alias[collection] || collection;
if (collections.includes(resolvedCollection))
return `~icons/${resolvedCollection}/${icon}${ext}`;
};
}
exports.default = ComponentsResolver;
+53
View File
@@ -0,0 +1,53 @@
interface ComponentResolverOption {
/**
* Prefix for resolving components name.
* Set '' to disable prefix.
*
* @default 'i'
*/
prefix?: string | false;
/**
* Iconify collection names to that enable for resolving.
*
* @default [all collections]
*/
enabledCollections?: string | string[];
/**
* Icon collections aliases.
*
* The `aliases` keys are the `alias` and the values are the `name` for the collection.
*
* Instead using `<i-icon-park-abnormal />` we can use `<i-park-abnormal />` configuring:
* `alias: { park: 'icon-park' }`
*/
alias?: Record<string, string>;
/**
* Name for custom collections provide by loaders.
*/
customCollections?: string | string[];
/**
* Extension for the resolved id
* Set `jsx` for JSX components
*
* @default ''
*/
extension?: string;
/**
* @deprecated renamed to `prefix`
*/
componentPrefix?: string;
/**
* For collections strict matching.
* Default is `false`, not side effect.
* Set `true` to enable strict matching with `-` suffix for all collections.
*/
strict?: boolean;
}
/**
* Resolver for unplugin-vue-components and unplugin-auto-import
*
* @param options
*/
declare function ComponentsResolver(options?: ComponentResolverOption): (name: string) => string | undefined;
export { type ComponentResolverOption, ComponentsResolver as default };
+53
View File
@@ -0,0 +1,53 @@
interface ComponentResolverOption {
/**
* Prefix for resolving components name.
* Set '' to disable prefix.
*
* @default 'i'
*/
prefix?: string | false;
/**
* Iconify collection names to that enable for resolving.
*
* @default [all collections]
*/
enabledCollections?: string | string[];
/**
* Icon collections aliases.
*
* The `aliases` keys are the `alias` and the values are the `name` for the collection.
*
* Instead using `<i-icon-park-abnormal />` we can use `<i-park-abnormal />` configuring:
* `alias: { park: 'icon-park' }`
*/
alias?: Record<string, string>;
/**
* Name for custom collections provide by loaders.
*/
customCollections?: string | string[];
/**
* Extension for the resolved id
* Set `jsx` for JSX components
*
* @default ''
*/
extension?: string;
/**
* @deprecated renamed to `prefix`
*/
componentPrefix?: string;
/**
* For collections strict matching.
* Default is `false`, not side effect.
* Set `true` to enable strict matching with `-` suffix for all collections.
*/
strict?: boolean;
}
/**
* Resolver for unplugin-vue-components and unplugin-auto-import
*
* @param options
*/
declare function ComponentsResolver(options?: ComponentResolverOption): (name: string) => string | undefined;
export { type ComponentResolverOption, ComponentsResolver as default };
+255
View File
@@ -0,0 +1,255 @@
import "./chunk-N3ETBM74.js";
// src/resolver.ts
import { toArray, uniq } from "@antfu/utils";
import { camelToKebab } from "@iconify/utils/lib/misc/strings";
// src/core/icon-sets.json
var icon_sets_default = [
"academicons",
"akar-icons",
"ant-design",
"arcticons",
"basil",
"bi",
"bitcoin-icons",
"bpmn",
"brandico",
"bx",
"bxl",
"bxs",
"bytesize",
"carbon",
"catppuccin",
"cbi",
"charm",
"ci",
"cib",
"cif",
"cil",
"circle-flags",
"circum",
"clarity",
"codicon",
"covid",
"cryptocurrency",
"cryptocurrency-color",
"cuida",
"dashicons",
"devicon",
"devicon-plain",
"duo-icons",
"ei",
"el",
"emojione",
"emojione-monotone",
"emojione-v1",
"entypo",
"entypo-social",
"eos-icons",
"ep",
"et",
"eva",
"f7",
"fa",
"fa-brands",
"fa-regular",
"fa-solid",
"fa6-brands",
"fa6-regular",
"fa6-solid",
"fad",
"fe",
"feather",
"file-icons",
"flag",
"flagpack",
"flat-color-icons",
"flat-ui",
"flowbite",
"fluent",
"fluent-color",
"fluent-emoji",
"fluent-emoji-flat",
"fluent-emoji-high-contrast",
"fluent-mdl2",
"fontelico",
"fontisto",
"formkit",
"foundation",
"fxemoji",
"gala",
"game-icons",
"geo",
"gg",
"gis",
"gravity-ui",
"gridicons",
"grommet-icons",
"guidance",
"healthicons",
"heroicons",
"heroicons-outline",
"heroicons-solid",
"hugeicons",
"humbleicons",
"ic",
"icomoon-free",
"icon-park",
"icon-park-outline",
"icon-park-solid",
"icon-park-twotone",
"iconamoon",
"iconoir",
"icons8",
"il",
"ion",
"iwwa",
"ix",
"jam",
"la",
"lets-icons",
"line-md",
"lineicons",
"logos",
"ls",
"lsicon",
"lucide",
"lucide-lab",
"mage",
"majesticons",
"maki",
"map",
"marketeq",
"material-symbols",
"material-symbols-light",
"mdi",
"mdi-light",
"medical-icon",
"memory",
"meteocons",
"meteor-icons",
"mi",
"mingcute",
"mono-icons",
"mynaui",
"nimbus",
"nonicons",
"noto",
"noto-v1",
"nrk",
"octicon",
"oi",
"ooui",
"openmoji",
"oui",
"pajamas",
"pepicons",
"pepicons-pencil",
"pepicons-pop",
"pepicons-print",
"ph",
"pixelarticons",
"prime",
"proicons",
"ps",
"qlementine-icons",
"quill",
"radix-icons",
"raphael",
"ri",
"rivet-icons",
"si",
"si-glyph",
"simple-icons",
"simple-line-icons",
"skill-icons",
"solar",
"stash",
"streamline",
"streamline-emojis",
"subway",
"svg-spinners",
"system-uicons",
"tabler",
"tdesign",
"teenyicons",
"token",
"token-branded",
"topcoat",
"twemoji",
"typcn",
"uil",
"uim",
"uis",
"uit",
"uiw",
"unjs",
"vaadin",
"vs",
"vscode-icons",
"websymbol",
"weui",
"whh",
"wi",
"wpf",
"zmdi",
"zondicons"
];
// src/resolver.ts
function ComponentsResolver(options = {}) {
var _a;
const {
prefix: rawPrefix = (_a = options.componentPrefix) != null ? _a : "i",
enabledCollections = icon_sets_default,
alias = {},
customCollections = [],
extension,
strict = false
} = options;
const prefix = rawPrefix ? `${camelToKebab(rawPrefix)}-` : "";
const ext = extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
const collections = uniq([
...toArray(enabledCollections),
...toArray(customCollections),
...toArray(Object.keys(alias))
]);
collections.sort((a, b) => b.length - a.length);
return (name) => {
let collection;
let icon;
if (name.includes(":")) {
const [iconPrefix, iconSuffix] = name.split(":");
collection = camelToKebab(iconPrefix);
if (!collection.startsWith(prefix))
return;
const slice = collection.slice(prefix.length);
const resolvedCollection2 = collections.find((i) => slice === i);
if (!resolvedCollection2)
return;
collection = resolvedCollection2;
icon = camelToKebab(iconSuffix);
} else {
const kebab = camelToKebab(name);
if (!kebab.startsWith(prefix))
return;
const slice = kebab.slice(prefix.length);
const resolvedCollection2 = collections.find((i) => slice.startsWith(`${i}-`)) || !strict && collections.find((i) => slice.startsWith(i));
if (!resolvedCollection2)
return;
collection = resolvedCollection2;
icon = slice.slice(resolvedCollection2.length);
}
if (icon[0] === "-")
icon = icon.slice(1);
if (!icon)
return;
const resolvedCollection = alias[collection] || collection;
if (collections.includes(resolvedCollection))
return `~icons/${resolvedCollection}/${icon}${ext}`;
};
}
export {
ComponentsResolver as default
};
+11
View File
@@ -0,0 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/rollup.ts
var rollup_default = _chunk2ZA4SHTDcjs.src_default.rollup;
exports.default = rollup_default;
+7
View File
@@ -0,0 +1,7 @@
import * as rollup from 'rollup';
import { Options } from './types.cjs';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
export { _default as default };
+7
View File
@@ -0,0 +1,7 @@
import * as rollup from 'rollup';
import { Options } from './types.js';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
export { _default as default };
+11
View File
@@ -0,0 +1,11 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/rollup.ts
var rollup_default = src_default.rollup;
export {
rollup_default as default
};
+11
View File
@@ -0,0 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/rspack.ts
var rspack_default = _chunk2ZA4SHTDcjs.src_default.rspack;
exports.default = rspack_default;
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.cjs';
import '@antfu/utils';
declare const _default: (options?: Options) => any;
export { _default as default };
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.js';
import '@antfu/utils';
declare const _default: (options?: Options) => any;
export { _default as default };
+11
View File
@@ -0,0 +1,11 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/rspack.ts
var rspack_default = src_default.rspack;
export {
rspack_default as default
};
+1
View File
@@ -0,0 +1 @@
"use strict";require('./chunk-ZBPRDZS4.cjs');
+103
View File
@@ -0,0 +1,103 @@
import { Awaitable } from '@antfu/utils';
type Compiler = (svg: string, collection: string, icon: string, options: ResolvedOptions) => string | Promise<string>;
interface CustomCompiler {
compiler: Awaitable<Compiler>;
extension?: string;
}
type CustomIconLoader = (name: string) => Awaitable<string | undefined>;
type IconCustomizer = (collection: string, icon: string, props: Record<string, string>) => Awaitable<void>;
type InlineCollection = Record<string, string | (() => Awaitable<string | undefined>)>;
interface Options {
/**
* Scale of icons against 1em
*
* @default 1.2
*/
scale?: number;
/**
* Style apply to icons by default
*
* @default ''
*/
defaultStyle?: string;
/**
* Class names apply to icons by default
*
* @default ''
*/
defaultClass?: string;
/**
* Loader for custom loaders
*/
customCollections?: Record<string, CustomIconLoader | InlineCollection>;
/**
* Icon customizer
*/
iconCustomizer?: IconCustomizer;
/**
* Current working directory for resolving collections from node_modules
*/
collectionsNodeResolvePath?: string | string[];
/**
* Transform raw `svg`.
*
* **WARNING**: `transform` will be only applied when using `custom` icon collection.
*
* @param svg The loaded `svg`
* @param collection The name of the collection
* @param icon The name of the icon
* @return The transformed `svg`.
*/
transform?: (svg: string, collection: string, icon: string) => Awaitable<string>;
/**
* Auto install icon sources package when the usages is detected
*
* @default false
*/
autoInstall?: boolean;
/**
* Compiler
*
* - none: plain SVG content
* - raw: an ESM module with a default exported string of the SVG HTML
*
* @default (detect automatically, fallback to 'vue3')
*/
compiler?: 'astro' | 'jsx' | 'marko' | 'none' | 'solid' | 'svelte' | 'raw' | 'vue2' | 'vue3' | 'web-components' | 'qwik' | CustomCompiler;
/**
* JSX style, works only when compiler set to `jsx`
*
* @default (detect automatically, fallback to 'react')
*/
jsx?: 'react' | 'preact' | 'qwik';
/**
* Config for Web Components compiler
*/
webComponents?: {
/**
* Call `customElements.define` automatically on module importing
*/
autoDefine?: boolean;
/**
* Prefix for auto defining
*
* @default 'icon'
*/
iconPrefix?: string;
/**
* Use shadow DOM
* @default false
*/
shadow?: boolean;
};
/**
* @deprecated no longer needed
*/
iconSource?: 'legacy' | 'modern' | 'auto';
}
type ResolvedOptions = Omit<Required<Options>, 'iconSource' | 'transform'> & Pick<Options, 'transform'>;
export type { CustomCompiler, CustomIconLoader, IconCustomizer, InlineCollection, Options, ResolvedOptions };
+103
View File
@@ -0,0 +1,103 @@
import { Awaitable } from '@antfu/utils';
type Compiler = (svg: string, collection: string, icon: string, options: ResolvedOptions) => string | Promise<string>;
interface CustomCompiler {
compiler: Awaitable<Compiler>;
extension?: string;
}
type CustomIconLoader = (name: string) => Awaitable<string | undefined>;
type IconCustomizer = (collection: string, icon: string, props: Record<string, string>) => Awaitable<void>;
type InlineCollection = Record<string, string | (() => Awaitable<string | undefined>)>;
interface Options {
/**
* Scale of icons against 1em
*
* @default 1.2
*/
scale?: number;
/**
* Style apply to icons by default
*
* @default ''
*/
defaultStyle?: string;
/**
* Class names apply to icons by default
*
* @default ''
*/
defaultClass?: string;
/**
* Loader for custom loaders
*/
customCollections?: Record<string, CustomIconLoader | InlineCollection>;
/**
* Icon customizer
*/
iconCustomizer?: IconCustomizer;
/**
* Current working directory for resolving collections from node_modules
*/
collectionsNodeResolvePath?: string | string[];
/**
* Transform raw `svg`.
*
* **WARNING**: `transform` will be only applied when using `custom` icon collection.
*
* @param svg The loaded `svg`
* @param collection The name of the collection
* @param icon The name of the icon
* @return The transformed `svg`.
*/
transform?: (svg: string, collection: string, icon: string) => Awaitable<string>;
/**
* Auto install icon sources package when the usages is detected
*
* @default false
*/
autoInstall?: boolean;
/**
* Compiler
*
* - none: plain SVG content
* - raw: an ESM module with a default exported string of the SVG HTML
*
* @default (detect automatically, fallback to 'vue3')
*/
compiler?: 'astro' | 'jsx' | 'marko' | 'none' | 'solid' | 'svelte' | 'raw' | 'vue2' | 'vue3' | 'web-components' | 'qwik' | CustomCompiler;
/**
* JSX style, works only when compiler set to `jsx`
*
* @default (detect automatically, fallback to 'react')
*/
jsx?: 'react' | 'preact' | 'qwik';
/**
* Config for Web Components compiler
*/
webComponents?: {
/**
* Call `customElements.define` automatically on module importing
*/
autoDefine?: boolean;
/**
* Prefix for auto defining
*
* @default 'icon'
*/
iconPrefix?: string;
/**
* Use shadow DOM
* @default false
*/
shadow?: boolean;
};
/**
* @deprecated no longer needed
*/
iconSource?: 'legacy' | 'modern' | 'auto';
}
type ResolvedOptions = Omit<Required<Options>, 'iconSource' | 'transform'> & Pick<Options, 'transform'>;
export type { CustomCompiler, CustomIconLoader, IconCustomizer, InlineCollection, Options, ResolvedOptions };
+1
View File
@@ -0,0 +1 @@
import "./chunk-6F4PWJZI.js";
+11
View File
@@ -0,0 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/vite.ts
var vite_default = _chunk2ZA4SHTDcjs.src_default.vite;
exports.default = vite_default;
+7
View File
@@ -0,0 +1,7 @@
import * as vite from 'vite';
import { Options } from './types.cjs';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
export { _default as default };
+7
View File
@@ -0,0 +1,7 @@
import * as vite from 'vite';
import { Options } from './types.js';
import '@antfu/utils';
declare const _default: (options?: Options | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
export { _default as default };
+11
View File
@@ -0,0 +1,11 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/vite.ts
var vite_default = src_default.vite;
export {
vite_default as default
};
+11
View File
@@ -0,0 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk2ZA4SHTDcjs = require('./chunk-2ZA4SHTD.cjs');
require('./chunk-ORVFCRDG.cjs');
require('./chunk-ZBPRDZS4.cjs');
// src/webpack.ts
var webpack_default = _chunk2ZA4SHTDcjs.src_default.webpack;
exports.default = webpack_default;
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.cjs';
import '@antfu/utils';
declare const _default: (options?: Options) => any;
export { _default as default };
+6
View File
@@ -0,0 +1,6 @@
import { Options } from './types.js';
import '@antfu/utils';
declare const _default: (options?: Options) => any;
export { _default as default };
+11
View File
@@ -0,0 +1,11 @@
import {
src_default
} from "./chunk-F5V4FZDM.js";
import "./chunk-N3ETBM74.js";
import "./chunk-6F4PWJZI.js";
// src/webpack.ts
var webpack_default = src_default.webpack;
export {
webpack_default as default
};