add hw2
This commit is contained in:
17
node_modules/@iconify/utils/lib/css/common.d.ts
generated
vendored
Normal file
17
node_modules/@iconify/utils/lib/css/common.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { IconCSSCommonCodeOptions, IconCSSItemOptions, IconContentItemOptions } from "./types.js";
|
||||
import { IconifyIcon } from "@iconify/types";
|
||||
/**
|
||||
* Generates common CSS rules for multiple icons, rendered as background/mask
|
||||
*/
|
||||
declare function getCommonCSSRules(options: IconCSSCommonCodeOptions): Record<string, string>;
|
||||
/**
|
||||
* Generate CSS rules for one icon, rendered as background/mask
|
||||
*
|
||||
* This function excludes common rules
|
||||
*/
|
||||
declare function generateItemCSSRules(icon: Required<IconifyIcon>, options: IconCSSItemOptions): Record<string, string>;
|
||||
/**
|
||||
* Generate content for one icon, rendered as content of pseudo-selector
|
||||
*/
|
||||
declare function generateItemContent(icon: Required<IconifyIcon>, options: IconContentItemOptions): string;
|
||||
export { generateItemCSSRules, generateItemContent, getCommonCSSRules };
|
||||
78
node_modules/@iconify/utils/lib/css/common.js
generated
vendored
Normal file
78
node_modules/@iconify/utils/lib/css/common.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import { makeViewBoxSquare } from "../icon/square.js";
|
||||
import { calculateSize } from "../svg/size.js";
|
||||
import { iconToSVG } from "../svg/build.js";
|
||||
import { svgToURL } from "../svg/url.js";
|
||||
import { iconToHTML } from "../svg/html.js";
|
||||
|
||||
/**
|
||||
* Generates common CSS rules for multiple icons, rendered as background/mask
|
||||
*/
|
||||
function getCommonCSSRules(options) {
|
||||
const result = {
|
||||
display: "inline-block",
|
||||
width: "1em",
|
||||
height: "1em"
|
||||
};
|
||||
const varName = options.varName;
|
||||
if (options.pseudoSelector) result["content"] = "''";
|
||||
switch (options.mode) {
|
||||
case "background":
|
||||
if (varName) result["background-image"] = "var(--" + varName + ")";
|
||||
result["background-repeat"] = "no-repeat";
|
||||
result["background-size"] = "100% 100%";
|
||||
break;
|
||||
case "mask":
|
||||
result["background-color"] = "currentColor";
|
||||
if (varName) result["mask-image"] = result["-webkit-mask-image"] = "var(--" + varName + ")";
|
||||
result["mask-repeat"] = result["-webkit-mask-repeat"] = "no-repeat";
|
||||
result["mask-size"] = result["-webkit-mask-size"] = "100% 100%";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Generate CSS rules for one icon, rendered as background/mask
|
||||
*
|
||||
* This function excludes common rules
|
||||
*/
|
||||
function generateItemCSSRules(icon, options) {
|
||||
const result = {};
|
||||
const varName = options.varName;
|
||||
const buildResult = iconToSVG(icon);
|
||||
let viewBox = buildResult.viewBox;
|
||||
if (viewBox[2] !== viewBox[3]) if (options.forceSquare) viewBox = makeViewBoxSquare(viewBox);
|
||||
else result["width"] = calculateSize("1em", viewBox[2] / viewBox[3]);
|
||||
const svg = iconToHTML(buildResult.body.replace(/currentColor/g, options.color || "black"), {
|
||||
viewBox: `${viewBox[0]} ${viewBox[1]} ${viewBox[2]} ${viewBox[3]}`,
|
||||
width: `${viewBox[2]}`,
|
||||
height: `${viewBox[3]}`
|
||||
});
|
||||
const url = svgToURL(svg);
|
||||
if (varName) result["--" + varName] = url;
|
||||
else switch (options.mode) {
|
||||
case "background":
|
||||
result["background-image"] = url;
|
||||
break;
|
||||
case "mask":
|
||||
result["mask-image"] = result["-webkit-mask-image"] = url;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Generate content for one icon, rendered as content of pseudo-selector
|
||||
*/
|
||||
function generateItemContent(icon, options) {
|
||||
const buildResult = iconToSVG(icon);
|
||||
const viewBox = buildResult.viewBox;
|
||||
const height = options.height;
|
||||
const width = options.width ?? calculateSize(height, viewBox[2] / viewBox[3]);
|
||||
const svg = iconToHTML(buildResult.body.replace(/currentColor/g, options.color || "black"), {
|
||||
viewBox: `${viewBox[0]} ${viewBox[1]} ${viewBox[2]} ${viewBox[3]}`,
|
||||
width: width.toString(),
|
||||
height: height.toString()
|
||||
});
|
||||
return svgToURL(svg);
|
||||
}
|
||||
|
||||
export { generateItemCSSRules, generateItemContent, getCommonCSSRules };
|
||||
8
node_modules/@iconify/utils/lib/css/format.d.ts
generated
vendored
Normal file
8
node_modules/@iconify/utils/lib/css/format.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { CSSFormatMode, CSSUnformattedItem } from "./types.js";
|
||||
/**
|
||||
* Format data
|
||||
*
|
||||
* Key is selector, value is list of rules
|
||||
*/
|
||||
declare function formatCSS(data: CSSUnformattedItem[], mode?: CSSFormatMode): string;
|
||||
export { formatCSS };
|
||||
41
node_modules/@iconify/utils/lib/css/format.js
generated
vendored
Normal file
41
node_modules/@iconify/utils/lib/css/format.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
const format = {
|
||||
selectorStart: {
|
||||
compressed: "{",
|
||||
compact: " {",
|
||||
expanded: " {"
|
||||
},
|
||||
selectorEnd: {
|
||||
compressed: "}",
|
||||
compact: "; }\n",
|
||||
expanded: ";\n}\n"
|
||||
},
|
||||
rule: {
|
||||
compressed: "{key}:",
|
||||
compact: " {key}: ",
|
||||
expanded: "\n {key}: "
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Format data
|
||||
*
|
||||
* Key is selector, value is list of rules
|
||||
*/
|
||||
function formatCSS(data, mode = "expanded") {
|
||||
const results = [];
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const { selector, rules } = data[i];
|
||||
const fullSelector = selector instanceof Array ? selector.join(mode === "compressed" ? "," : ", ") : selector;
|
||||
let entry = fullSelector + format.selectorStart[mode];
|
||||
let firstRule = true;
|
||||
for (const key in rules) {
|
||||
if (!firstRule) entry += ";";
|
||||
entry += format.rule[mode].replace("{key}", key) + rules[key];
|
||||
firstRule = false;
|
||||
}
|
||||
entry += format.selectorEnd[mode];
|
||||
results.push(entry);
|
||||
}
|
||||
return results.join(mode === "compressed" ? "" : "\n");
|
||||
}
|
||||
|
||||
export { formatCSS };
|
||||
11
node_modules/@iconify/utils/lib/css/icon.d.ts
generated
vendored
Normal file
11
node_modules/@iconify/utils/lib/css/icon.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { IconCSSIconOptions, IconContentIconOptions } from "./types.js";
|
||||
import { IconifyIcon } from "@iconify/types";
|
||||
/**
|
||||
* Get CSS for icon, rendered as background or mask
|
||||
*/
|
||||
declare function getIconCSS(icon: IconifyIcon, options?: IconCSSIconOptions): string;
|
||||
/**
|
||||
* Get CSS for icon, rendered as content
|
||||
*/
|
||||
declare function getIconContentCSS(icon: IconifyIcon, options: IconContentIconOptions): string;
|
||||
export { getIconCSS, getIconContentCSS };
|
||||
54
node_modules/@iconify/utils/lib/css/icon.js
generated
vendored
Normal file
54
node_modules/@iconify/utils/lib/css/icon.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { defaultIconProps } from "../icon/defaults.js";
|
||||
import { generateItemCSSRules, generateItemContent, getCommonCSSRules } from "./common.js";
|
||||
import { formatCSS } from "./format.js";
|
||||
|
||||
/**
|
||||
* Get CSS for icon, rendered as background or mask
|
||||
*/
|
||||
function getIconCSS(icon, options = {}) {
|
||||
const body = options.customise ? options.customise(icon.body) : icon.body;
|
||||
const mode = options.mode || (options.color || !body.includes("currentColor") ? "background" : "mask");
|
||||
let varName = options.varName;
|
||||
if (varName === void 0 && mode === "mask") varName = "svg";
|
||||
const newOptions = {
|
||||
...options,
|
||||
mode,
|
||||
varName
|
||||
};
|
||||
if (mode === "background") delete newOptions.varName;
|
||||
const rules = {
|
||||
...options.rules,
|
||||
...getCommonCSSRules(newOptions),
|
||||
...generateItemCSSRules({
|
||||
...defaultIconProps,
|
||||
...icon,
|
||||
body
|
||||
}, newOptions)
|
||||
};
|
||||
const selector = options.iconSelector || ".icon";
|
||||
return formatCSS([{
|
||||
selector,
|
||||
rules
|
||||
}], newOptions.format);
|
||||
}
|
||||
/**
|
||||
* Get CSS for icon, rendered as content
|
||||
*/
|
||||
function getIconContentCSS(icon, options) {
|
||||
const body = options.customise ? options.customise(icon.body) : icon.body;
|
||||
const content = generateItemContent({
|
||||
...defaultIconProps,
|
||||
...icon,
|
||||
body
|
||||
}, options);
|
||||
const selector = options.iconSelector || ".icon::after";
|
||||
return formatCSS([{
|
||||
selector,
|
||||
rules: {
|
||||
...options.rules,
|
||||
content
|
||||
}
|
||||
}], options.format);
|
||||
}
|
||||
|
||||
export { getIconCSS, getIconContentCSS };
|
||||
20
node_modules/@iconify/utils/lib/css/icons.d.ts
generated
vendored
Normal file
20
node_modules/@iconify/utils/lib/css/icons.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { CSSUnformattedItem, IconCSSIconSetOptions, IconContentIconSetOptions } from "./types.js";
|
||||
import { IconifyJSON } from "@iconify/types";
|
||||
interface CSSData {
|
||||
common?: CSSUnformattedItem;
|
||||
css: CSSUnformattedItem[];
|
||||
errors: string[];
|
||||
}
|
||||
/**
|
||||
* Get data for getIconsCSS()
|
||||
*/
|
||||
declare function getIconsCSSData(iconSet: IconifyJSON, names: string[], options?: IconCSSIconSetOptions): CSSData;
|
||||
/**
|
||||
* Get CSS for icons as background/mask
|
||||
*/
|
||||
declare function getIconsCSS(iconSet: IconifyJSON, names: string[], options?: IconCSSIconSetOptions): string;
|
||||
/**
|
||||
* Get CSS for icons as content
|
||||
*/
|
||||
declare function getIconsContentCSS(iconSet: IconifyJSON, names: string[], options: IconContentIconSetOptions): string;
|
||||
export { getIconsCSS, getIconsCSSData, getIconsContentCSS };
|
||||
137
node_modules/@iconify/utils/lib/css/icons.js
generated
vendored
Normal file
137
node_modules/@iconify/utils/lib/css/icons.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
import { defaultIconProps } from "../icon/defaults.js";
|
||||
import { getIconData } from "../icon-set/get-icon.js";
|
||||
import { generateItemCSSRules, generateItemContent, getCommonCSSRules } from "./common.js";
|
||||
import { formatCSS } from "./format.js";
|
||||
|
||||
const commonSelector = ".icon--{prefix}";
|
||||
const iconSelector = ".icon--{prefix}--{name}";
|
||||
const contentSelector = ".icon--{prefix}--{name}::after";
|
||||
const defaultSelectors = {
|
||||
commonSelector,
|
||||
iconSelector,
|
||||
overrideSelector: commonSelector + iconSelector
|
||||
};
|
||||
/**
|
||||
* Get data for getIconsCSS()
|
||||
*/
|
||||
function getIconsCSSData(iconSet, names, options = {}) {
|
||||
const css = [];
|
||||
const errors = [];
|
||||
const palette = options.color ? true : void 0;
|
||||
let mode = options.mode || typeof palette === "boolean" && (palette ? "background" : "mask");
|
||||
if (!mode) {
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
const icon = getIconData(iconSet, name);
|
||||
if (icon) {
|
||||
const body = options.customise ? options.customise(icon.body, name) : icon.body;
|
||||
mode = 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 + " */");
|
||||
}
|
||||
}
|
||||
let varName = options.varName;
|
||||
if (varName === void 0 && mode === "mask") varName = "svg";
|
||||
const newOptions = {
|
||||
...options,
|
||||
mode,
|
||||
varName
|
||||
};
|
||||
const { commonSelector: commonSelector$1, iconSelector: iconSelector$1, overrideSelector } = newOptions.iconSelector ? newOptions : defaultSelectors;
|
||||
const iconSelectorWithPrefix = iconSelector$1.replace(/{prefix}/g, iconSet.prefix);
|
||||
const commonRules = {
|
||||
...options.rules,
|
||||
...getCommonCSSRules(newOptions)
|
||||
};
|
||||
const hasCommonRules = commonSelector$1 && commonSelector$1 !== iconSelector$1;
|
||||
const commonSelectors = /* @__PURE__ */ new Set();
|
||||
if (hasCommonRules) css.push({
|
||||
selector: commonSelector$1.replace(/{prefix}/g, iconSet.prefix),
|
||||
rules: commonRules
|
||||
});
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
const iconData = getIconData(iconSet, name);
|
||||
if (!iconData) {
|
||||
errors.push("/* Could not find icon: " + name + " */");
|
||||
continue;
|
||||
}
|
||||
const body = options.customise ? options.customise(iconData.body, name) : iconData.body;
|
||||
const rules = generateItemCSSRules({
|
||||
...defaultIconProps,
|
||||
...iconData,
|
||||
body
|
||||
}, newOptions);
|
||||
let requiresOverride = false;
|
||||
if (hasCommonRules && overrideSelector) {
|
||||
for (const key in rules) if (key in commonRules) requiresOverride = true;
|
||||
}
|
||||
const selector = (requiresOverride && overrideSelector ? overrideSelector.replace(/{prefix}/g, iconSet.prefix) : iconSelectorWithPrefix).replace(/{name}/g, name);
|
||||
css.push({
|
||||
selector,
|
||||
rules
|
||||
});
|
||||
if (!hasCommonRules) commonSelectors.add(selector);
|
||||
}
|
||||
const result = {
|
||||
css,
|
||||
errors
|
||||
};
|
||||
if (!hasCommonRules && commonSelectors.size) {
|
||||
const selector = Array.from(commonSelectors).join(newOptions.format === "compressed" ? "," : ", ");
|
||||
result.common = {
|
||||
selector,
|
||||
rules: commonRules
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Get CSS for icons as background/mask
|
||||
*/
|
||||
function getIconsCSS(iconSet, names, options = {}) {
|
||||
const { css, errors, common } = getIconsCSSData(iconSet, names, options);
|
||||
if (common) if (css.length === 1 && css[0].selector === common.selector) css[0].rules = {
|
||||
...common.rules,
|
||||
...css[0].rules
|
||||
};
|
||||
else css.unshift(common);
|
||||
return formatCSS(css, options.format) + (errors.length ? "\n" + errors.join("\n") + "\n" : "");
|
||||
}
|
||||
/**
|
||||
* Get CSS for icons as content
|
||||
*/
|
||||
function getIconsContentCSS(iconSet, names, options) {
|
||||
const errors = [];
|
||||
const css = [];
|
||||
const iconSelectorWithPrefix = (options.iconSelector ?? contentSelector).replace(/{prefix}/g, iconSet.prefix);
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
const iconData = getIconData(iconSet, name);
|
||||
if (!iconData) {
|
||||
errors.push("/* Could not find icon: " + name + " */");
|
||||
continue;
|
||||
}
|
||||
const body = options.customise ? options.customise(iconData.body, name) : iconData.body;
|
||||
const content = generateItemContent({
|
||||
...defaultIconProps,
|
||||
...iconData,
|
||||
body
|
||||
}, options);
|
||||
const selector = iconSelectorWithPrefix.replace(/{name}/g, name);
|
||||
css.push({
|
||||
selector,
|
||||
rules: {
|
||||
...options.rules,
|
||||
content
|
||||
}
|
||||
});
|
||||
}
|
||||
return formatCSS(css, options.format) + (errors.length ? "\n" + errors.join("\n") + "\n" : "");
|
||||
}
|
||||
|
||||
export { getIconsCSS, getIconsCSSData, getIconsContentCSS };
|
||||
104
node_modules/@iconify/utils/lib/css/types.d.ts
generated
vendored
Normal file
104
node_modules/@iconify/utils/lib/css/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Icon mode
|
||||
*/
|
||||
type IconCSSMode = 'mask' | 'background';
|
||||
/**
|
||||
* Selector for icon
|
||||
*/
|
||||
interface IconCSSIconSelectorOptions {
|
||||
pseudoSelector?: boolean;
|
||||
iconSelector?: string;
|
||||
}
|
||||
/**
|
||||
* Selector for icon when generating data from icon set
|
||||
*/
|
||||
interface IconCSSSelectorOptions extends IconCSSIconSelectorOptions {
|
||||
commonSelector?: string;
|
||||
overrideSelector?: string;
|
||||
}
|
||||
/**
|
||||
* Options common for both multiple icons and single icon
|
||||
*/
|
||||
interface IconCSSSharedOptions {
|
||||
varName?: string | null;
|
||||
forceSquare?: boolean;
|
||||
color?: string;
|
||||
rules?: Record<string, string>;
|
||||
}
|
||||
/**
|
||||
* Mode
|
||||
*/
|
||||
interface IconCSSModeOptions {
|
||||
mode?: IconCSSMode;
|
||||
}
|
||||
/**
|
||||
* Options for generating common code
|
||||
*
|
||||
* Requires mode
|
||||
*/
|
||||
interface IconCSSCommonCodeOptions extends IconCSSSharedOptions, IconCSSIconSelectorOptions, Required<IconCSSModeOptions> {}
|
||||
/**
|
||||
* Options for generating data for one icon
|
||||
*/
|
||||
interface IconCSSItemOptions extends IconCSSSharedOptions, Required<IconCSSModeOptions> {}
|
||||
/**
|
||||
* Selector for icon
|
||||
*/
|
||||
interface IconContentIconSelectorOptions {
|
||||
iconSelector?: string;
|
||||
}
|
||||
/**
|
||||
* Options common for both multiple icons and single icon
|
||||
*/
|
||||
interface IconContentSharedOptions {
|
||||
height: number;
|
||||
width?: number;
|
||||
color?: string;
|
||||
rules?: Record<string, string>;
|
||||
}
|
||||
/**
|
||||
* Options for generating data for one icon
|
||||
*/
|
||||
type IconContentItemOptions = IconContentSharedOptions;
|
||||
/**
|
||||
* Formatting modes. Same as in SASS
|
||||
*/
|
||||
type CSSFormatMode = 'expanded' | 'compact' | 'compressed';
|
||||
/**
|
||||
* Item to format
|
||||
*/
|
||||
interface CSSUnformattedItem {
|
||||
selector: string | string[];
|
||||
rules: Record<string, string>;
|
||||
}
|
||||
/**
|
||||
* Formatting options
|
||||
*/
|
||||
interface IconCSSFormatOptions {
|
||||
format?: CSSFormatMode;
|
||||
}
|
||||
/**
|
||||
* Options for generating data for one icon as background/mask
|
||||
*/
|
||||
interface IconCSSIconOptions extends IconCSSSharedOptions, IconCSSIconSelectorOptions, IconCSSModeOptions, IconCSSFormatOptions {
|
||||
customise?: (content: string) => string;
|
||||
}
|
||||
/**
|
||||
* Options for generating data for one icon as content
|
||||
*/
|
||||
interface IconContentIconOptions extends IconContentSharedOptions, IconContentIconSelectorOptions, IconCSSFormatOptions {
|
||||
customise?: (content: string) => string;
|
||||
}
|
||||
/**
|
||||
* Options for generating multiple icons as background/mask
|
||||
*/
|
||||
interface IconCSSIconSetOptions extends IconCSSSharedOptions, IconCSSSelectorOptions, IconCSSModeOptions, IconCSSFormatOptions {
|
||||
customise?: (content: string, name: string) => string;
|
||||
}
|
||||
/**
|
||||
* Options for generating multiple icons as content
|
||||
*/
|
||||
interface IconContentIconSetOptions extends IconContentSharedOptions, IconContentIconSelectorOptions, IconCSSFormatOptions {
|
||||
customise?: (content: string, name: string) => string;
|
||||
}
|
||||
export { CSSFormatMode, CSSUnformattedItem, IconCSSCommonCodeOptions, IconCSSFormatOptions, IconCSSIconOptions, IconCSSIconSelectorOptions, IconCSSIconSetOptions, IconCSSItemOptions, IconCSSMode, IconCSSModeOptions, IconCSSSelectorOptions, IconCSSSharedOptions, IconContentIconOptions, IconContentIconSelectorOptions, IconContentIconSetOptions, IconContentItemOptions, IconContentSharedOptions };
|
||||
0
node_modules/@iconify/utils/lib/css/types.js
generated
vendored
Normal file
0
node_modules/@iconify/utils/lib/css/types.js
generated
vendored
Normal file
Reference in New Issue
Block a user