First commit.

Signed-off-by: Chen Xiao <abigwc@gmail.com>
This commit is contained in:
Chen Xiao
2026-05-08 14:43:16 +08:00
commit 0b64e2de94
10989 changed files with 2253791 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { ExtendedIconifyIcon, IconifyDimenisons, IconifyIcon, IconifyOptional, IconifyTransformations } from "@iconify/types";
type FullIconifyIcon = Required<IconifyIcon>;
/** Partial and full extended icon */
type PartialExtendedIconifyIcon = Partial<ExtendedIconifyIcon>;
type IconifyIconExtraProps = Omit<ExtendedIconifyIcon, keyof IconifyIcon>;
type FullExtendedIconifyIcon = FullIconifyIcon & IconifyIconExtraProps;
/** Default values for dimensions */
declare const defaultIconDimensions: Required<IconifyDimenisons>;
/** Default values for transformations */
declare const defaultIconTransformations: Required<IconifyTransformations>;
/** Default values for all optional IconifyIcon properties */
declare const defaultIconProps: Required<IconifyOptional>;
/** Default values for all properties used in ExtendedIconifyIcon */
declare const defaultExtendedIconProps: Required<FullExtendedIconifyIcon>;
export { FullExtendedIconifyIcon, FullIconifyIcon, IconifyIcon, PartialExtendedIconifyIcon, defaultExtendedIconProps, defaultIconDimensions, defaultIconProps, defaultIconTransformations };
+25
View File
@@ -0,0 +1,25 @@
/** Default values for dimensions */
const defaultIconDimensions = Object.freeze({
left: 0,
top: 0,
width: 16,
height: 16
});
/** Default values for transformations */
const defaultIconTransformations = Object.freeze({
rotate: 0,
vFlip: false,
hFlip: false
});
/** Default values for all optional IconifyIcon properties */
const defaultIconProps = Object.freeze({
...defaultIconDimensions,
...defaultIconTransformations
});
/** Default values for all properties used in ExtendedIconifyIcon */
const defaultExtendedIconProps = Object.freeze({
...defaultIconProps,
body: "",
hidden: false
});
export { defaultExtendedIconProps, defaultIconDimensions, defaultIconProps, defaultIconTransformations };
+8
View File
@@ -0,0 +1,8 @@
import { PartialExtendedIconifyIcon } from "./defaults.js";
/**
* Merge icon and alias
*
* Can also be used to merge default values and icon
*/
declare function mergeIconData<T extends PartialExtendedIconifyIcon>(parent: T, child: PartialExtendedIconifyIcon): T;
export { mergeIconData };
+16
View File
@@ -0,0 +1,16 @@
import { defaultExtendedIconProps, defaultIconTransformations } from "./defaults.js";
import { mergeIconTransformations } from "./transformations.js";
/**
* Merge icon and alias
*
* Can also be used to merge default values and icon
*/
function mergeIconData(parent, child) {
const result = mergeIconTransformations(parent, child);
for (const key in defaultExtendedIconProps) if (key in defaultIconTransformations) {
if (key in parent && !(key in result)) result[key] = defaultIconTransformations[key];
} else if (key in child) result[key] = child[key];
else if (key in parent) result[key] = parent[key];
return result;
}
export { mergeIconData };
+30
View File
@@ -0,0 +1,30 @@
/**
* Icon name
*/
interface IconifyIconName {
readonly provider: string;
readonly prefix: string;
readonly name: string;
}
/**
* Icon source: icon object without name
*/
type IconifyIconSource = Omit<IconifyIconName, 'name'>;
/**
* Expression to test part of icon name.
*
* Used when loading icons from Iconify API due to project naming convension.
* Ignored when using custom icon sets - convension does not apply.
*/
declare const matchIconName: RegExp;
/**
* Convert string icon name to IconifyIconName object.
*/
declare const stringToIcon: (value: string, validate?: boolean, allowSimpleName?: boolean, provider?: string) => IconifyIconName | null;
/**
* Check if icon is valid.
*
* This function is not part of stringToIcon because validation is not needed for most code.
*/
declare const validateIconName: (icon: IconifyIconName | null, allowSimpleName?: boolean) => boolean;
export { IconifyIconName, IconifyIconSource, matchIconName, stringToIcon, validateIconName };
+57
View File
@@ -0,0 +1,57 @@
/**
* Expression to test part of icon name.
*
* Used when loading icons from Iconify API due to project naming convension.
* Ignored when using custom icon sets - convension does not apply.
*/
const matchIconName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
/**
* Convert string icon name to IconifyIconName object.
*/
const stringToIcon = (value, validate, allowSimpleName, provider = "") => {
const colonSeparated = value.split(":");
if (value.slice(0, 1) === "@") {
if (colonSeparated.length < 2 || colonSeparated.length > 3) return null;
provider = colonSeparated.shift().slice(1);
}
if (colonSeparated.length > 3 || !colonSeparated.length) return null;
if (colonSeparated.length > 1) {
const name = colonSeparated.pop();
const prefix = colonSeparated.pop();
const result = {
provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
prefix,
name
};
return validate && !validateIconName(result) ? null : result;
}
const name = colonSeparated[0];
const dashSeparated = name.split("-");
if (dashSeparated.length > 1) {
const result = {
provider,
prefix: dashSeparated.shift(),
name: dashSeparated.join("-")
};
return validate && !validateIconName(result) ? null : result;
}
if (allowSimpleName && provider === "") {
const result = {
provider,
prefix: "",
name
};
return validate && !validateIconName(result, allowSimpleName) ? null : result;
}
return null;
};
/**
* Check if icon is valid.
*
* This function is not part of stringToIcon because validation is not needed for most code.
*/
const validateIconName = (icon, allowSimpleName) => {
if (!icon) return false;
return !!((allowSimpleName && icon.prefix === "" || !!icon.prefix) && !!icon.name);
};
export { matchIconName, stringToIcon, validateIconName };
+11
View File
@@ -0,0 +1,11 @@
import { SVGViewBox } from "../svg/viewbox.js";
import { IconifyIcon } from "@iconify/types";
/**
* Make icon square
*/
declare function makeIconSquare(icon: Required<IconifyIcon>): Required<IconifyIcon>;
/**
* Make icon viewBox square
*/
declare function makeViewBoxSquare(viewBox: SVGViewBox): SVGViewBox;
export { makeIconSquare, makeViewBoxSquare };
+33
View File
@@ -0,0 +1,33 @@
/**
* Make icon square
*/
function makeIconSquare(icon) {
if (icon.width !== icon.height) {
const max = Math.max(icon.width, icon.height);
return {
...icon,
width: max,
height: max,
left: icon.left - (max - icon.width) / 2,
top: icon.top - (max - icon.height) / 2
};
}
return icon;
}
/**
* Make icon viewBox square
*/
function makeViewBoxSquare(viewBox) {
const [left, top, width, height] = viewBox;
if (width !== height) {
const max = Math.max(width, height);
return [
left - (max - width) / 2,
top - (max - height) / 2,
max,
max
];
}
return viewBox;
}
export { makeIconSquare, makeViewBoxSquare };
+6
View File
@@ -0,0 +1,6 @@
import { IconifyTransformations } from "@iconify/types";
/**
* Merge transformations
*/
declare function mergeIconTransformations<T extends IconifyTransformations>(obj1: T, obj2: IconifyTransformations): T;
export { mergeIconTransformations };
+12
View File
@@ -0,0 +1,12 @@
/**
* Merge transformations
*/
function mergeIconTransformations(obj1, obj2) {
const result = {};
if (!obj1.hFlip !== !obj2.hFlip) result.hFlip = true;
if (!obj1.vFlip !== !obj2.vFlip) result.vFlip = true;
const rotate = ((obj1.rotate || 0) + (obj2.rotate || 0)) % 4;
if (rotate) result.rotate = rotate;
return result;
}
export { mergeIconTransformations };