+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Get boolean customisation value from attribute
|
||||
*/
|
||||
declare function toBoolean(name: string, value: unknown, defaultValue: boolean): boolean;
|
||||
export { toBoolean };
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Get boolean customisation value from attribute
|
||||
*/
|
||||
function toBoolean(name, value, defaultValue) {
|
||||
switch (typeof value) {
|
||||
case "boolean": return value;
|
||||
case "number": return !!value;
|
||||
case "string": switch (value.toLowerCase()) {
|
||||
case "1":
|
||||
case "true":
|
||||
case name.toLowerCase(): return true;
|
||||
case "0":
|
||||
case "false":
|
||||
case "": return false;
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
export { toBoolean };
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { IconifyTransformations } from "@iconify/types";
|
||||
/**
|
||||
* Icon size
|
||||
*/
|
||||
type IconifyIconSize = null | string | number;
|
||||
/**
|
||||
* Dimensions
|
||||
*/
|
||||
interface IconifyIconSizeCustomisations {
|
||||
width?: IconifyIconSize;
|
||||
height?: IconifyIconSize;
|
||||
}
|
||||
/**
|
||||
* Icon customisations
|
||||
*/
|
||||
interface IconifyIconCustomisations extends IconifyTransformations, IconifyIconSizeCustomisations {}
|
||||
type FullIconCustomisations = Required<IconifyIconCustomisations>;
|
||||
/**
|
||||
* Default icon customisations values
|
||||
*/
|
||||
declare const defaultIconSizeCustomisations: Required<IconifyIconSizeCustomisations>;
|
||||
declare const defaultIconCustomisations: FullIconCustomisations;
|
||||
export { FullIconCustomisations, IconifyIconCustomisations, IconifyIconSize, IconifyIconSizeCustomisations, defaultIconCustomisations, defaultIconSizeCustomisations };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { defaultIconTransformations } from "../icon/defaults.js";
|
||||
/**
|
||||
* Default icon customisations values
|
||||
*/
|
||||
const defaultIconSizeCustomisations = Object.freeze({
|
||||
width: null,
|
||||
height: null
|
||||
});
|
||||
const defaultIconCustomisations = Object.freeze({
|
||||
...defaultIconSizeCustomisations,
|
||||
...defaultIconTransformations
|
||||
});
|
||||
export { defaultIconCustomisations, defaultIconSizeCustomisations };
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { IconifyIconCustomisations } from "./defaults.js";
|
||||
/**
|
||||
* Additional shorthand customisations
|
||||
*/
|
||||
interface ShorthandIconCustomisations {
|
||||
flip?: string;
|
||||
}
|
||||
/**
|
||||
* Apply "flip" string to icon customisations
|
||||
*/
|
||||
declare function flipFromString(custom: IconifyIconCustomisations, flip: string): void;
|
||||
export { ShorthandIconCustomisations, flipFromString };
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
const separator = /[\s,]+/;
|
||||
/**
|
||||
* Apply "flip" string to icon customisations
|
||||
*/
|
||||
function flipFromString(custom, flip) {
|
||||
flip.split(separator).forEach((str) => {
|
||||
switch (str.trim()) {
|
||||
case "horizontal":
|
||||
custom.hFlip = true;
|
||||
break;
|
||||
case "vertical":
|
||||
custom.vFlip = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
export { flipFromString };
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { FullIconCustomisations, IconifyIconCustomisations } from "./defaults.js";
|
||||
/**
|
||||
* Convert IconifyIconCustomisations to FullIconCustomisations, checking value types
|
||||
*/
|
||||
declare function mergeCustomisations<T extends FullIconCustomisations>(defaults: T, item: IconifyIconCustomisations): T;
|
||||
export { mergeCustomisations };
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { defaultIconSizeCustomisations } from "./defaults.js";
|
||||
/**
|
||||
* Convert IconifyIconCustomisations to FullIconCustomisations, checking value types
|
||||
*/
|
||||
function mergeCustomisations(defaults, item) {
|
||||
const result = { ...defaults };
|
||||
for (const key in item) {
|
||||
const value = item[key];
|
||||
const valueType = typeof value;
|
||||
if (key in defaultIconSizeCustomisations) {
|
||||
if (value === null || value && (valueType === "string" || valueType === "number")) result[key] = value;
|
||||
} else if (valueType === typeof result[key]) result[key] = key === "rotate" ? value % 4 : value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export { mergeCustomisations };
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Get rotation value
|
||||
*/
|
||||
declare function rotateFromString(value: string, defaultValue?: number): number;
|
||||
export { rotateFromString };
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Get rotation value
|
||||
*/
|
||||
function rotateFromString(value, defaultValue = 0) {
|
||||
const units = value.replace(/^-?[0-9.]*/, "");
|
||||
function cleanup(value) {
|
||||
while (value < 0) value += 4;
|
||||
return value % 4;
|
||||
}
|
||||
if (units === "") {
|
||||
const num = parseInt(value);
|
||||
return isNaN(num) ? 0 : cleanup(num);
|
||||
} else if (units !== value) {
|
||||
let split = 0;
|
||||
switch (units) {
|
||||
case "%":
|
||||
split = 25;
|
||||
break;
|
||||
case "deg": split = 90;
|
||||
}
|
||||
if (split) {
|
||||
let num = parseFloat(value.slice(0, value.length - units.length));
|
||||
if (isNaN(num)) return 0;
|
||||
num = num / split;
|
||||
return num % 1 === 0 ? cleanup(num) : 0;
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
export { rotateFromString };
|
||||
Reference in New Issue
Block a user