@iconify/tailwind
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -8,3 +8,3 @@ import { Config } from 'tailwindcss/types/config'; | ||
*/ | ||
export declare function addCleanIconSelectors(icons?: string[] | string, options?: CleanIconifyPluginOptions): { | ||
export declare function addCleanIconSelectors(icons: string[] | string, options?: CleanIconifyPluginOptions): { | ||
handler: PluginCreator; | ||
@@ -106,6 +106,5 @@ config?: Partial<Config>; | ||
declare interface IconifyPluginLoaderOptions { | ||
files?: Record<string, string>; | ||
iconSets?: Record<string, IconifyJSON | IconifyJSONLoaderCallback>; | ||
iconSets?: Record<string, IconifyJSON | string | IconifyJSONLoaderCallback>; | ||
} | ||
export { } |
@@ -10,3 +10,3 @@ /** | ||
* @license MIT | ||
* @version 0.1.1 | ||
* @version 0.1.2 | ||
*/ | ||
@@ -240,6 +240,15 @@ 'use strict'; | ||
if (!mode) { | ||
mode = "mask"; | ||
errors.push( | ||
"/* cannot detect icon mode: not set in options and icon set is missing info, rendering as " + mode + " */" | ||
); | ||
for (let i = 0; i < names.length; i++) { | ||
const icon = getIconData(iconSet, names[i]); | ||
if (icon) { | ||
mode = icon.body.includes("currentColor") ? "mask" : "background"; | ||
break; | ||
} | ||
} | ||
if (!mode) { | ||
mode = "mask"; | ||
errors.push( | ||
"/* cannot detect icon mode: not set in options and icon set is missing info, rendering as " + mode + " */" | ||
); | ||
} | ||
} | ||
@@ -252,2 +261,3 @@ let varName = options.varName; | ||
...options, | ||
// Override mode and varName | ||
mode, | ||
@@ -314,8 +324,3 @@ varName | ||
function locateIconSet(prefix, options) { | ||
if (options.files?.[prefix]) { | ||
return { | ||
main: options.files?.[prefix], | ||
}; | ||
} | ||
function locateIconSet(prefix) { | ||
try { | ||
@@ -351,14 +356,28 @@ const main = require.resolve(`@iconify-json/${prefix}/icons.json`); | ||
function loadIconSet(prefix, options) { | ||
let filename; | ||
// Check for custom icon set | ||
const customIconSet = options.iconSets?.[prefix]; | ||
if (customIconSet) { | ||
if (typeof customIconSet === 'function') { | ||
// Callback. Store result in options to avoid loading it again | ||
const result = customIconSet(); | ||
options.iconSets[prefix] = result; | ||
return result; | ||
switch (typeof customIconSet) { | ||
case 'function': { | ||
// Callback. Store result in options to avoid loading it again | ||
const result = customIconSet(); | ||
options.iconSets[prefix] = result; | ||
return result; | ||
} | ||
case 'string': { | ||
// Filename to load it from | ||
filename = { | ||
main: customIconSet, | ||
}; | ||
break; | ||
} | ||
default: | ||
return customIconSet; | ||
} | ||
return customIconSet; | ||
} | ||
const filename = options.files?.[prefix] || locateIconSet(prefix, options); | ||
else { | ||
// Find icon set | ||
filename = locateIconSet(prefix); | ||
} | ||
if (!filename) { | ||
@@ -462,3 +481,3 @@ return; | ||
if (!iconSet) { | ||
throw new Error(`Cannot load icon set for "${prefix}"`); | ||
throw new Error(`Cannot load icon set for "${prefix}". Install "@iconify-json/${prefix}" as dev dependency?`); | ||
} | ||
@@ -493,3 +512,3 @@ const generated = getIconsCSSData(iconSet, Array.from(prefixes[prefix]), options); | ||
if (!iconSet) { | ||
throw new Error(`Cannot load icon set for "${prefix}"`); | ||
throw new Error(`Cannot load icon set for "${prefix}". Install "@iconify-json/${prefix}" as dev dependency?`); | ||
} | ||
@@ -500,3 +519,3 @@ const generated = getIconsCSSData(iconSet, [name], { | ||
if (generated.css.length !== 1) { | ||
throw new Error(`Something went wrong generating "${icon}"`); | ||
throw new Error(`Cannot find "${icon}". Bad icon name?`); | ||
} | ||
@@ -528,11 +547,4 @@ return { | ||
function addCleanIconSelectors(icons, options) { | ||
const passedOptions = typeof icons === 'object' && !(icons instanceof Array) | ||
? icons | ||
: options || {}; | ||
const passedIcons = typeof icons !== 'object' || icons instanceof Array ? icons : void 0; | ||
// Get hardcoded list of icons | ||
const rules = passedIcons | ||
? getCSSRulesForIcons(passedIcons, passedOptions) | ||
: void 0; | ||
return plugin(({ addUtilities, matchComponents }) => { | ||
const rules = getCSSRulesForIcons(icons, options); | ||
return plugin(({ addUtilities }) => { | ||
addUtilities(rules); | ||
@@ -539,0 +551,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Vjacheslav Trushkin <cyberalien@gmail.com> (https://iconify.design)", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "main": "./dist/plugin.js", | ||
"typescript": "^4.9.4", | ||
"@iconify/utils": "^2.1.0" | ||
"@iconify/utils": "^2.1.4" | ||
}, | ||
@@ -41,0 +41,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25307
660