@cyberalien/svg-utils 0.0.16 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{svg/css/css/class.d.ts → css/hash.d.ts} +1 -1
- package/lib/{svg/css/css/class.js → css/hash.js} +2 -2
- package/lib/css/stringify.d.ts +14 -0
- package/lib/css/stringify.js +46 -0
- package/lib/css/types.d.ts +16 -0
- package/lib/helpers/misc/strings.d.ts +17 -0
- package/lib/helpers/misc/strings.js +27 -0
- package/lib/iconify/icon/nornalise.d.ts +7 -0
- package/lib/iconify/icon/nornalise.js +63 -0
- package/lib/iconify/icon/types.d.ts +6 -0
- package/lib/iconify/icon/types.js +1 -0
- package/lib/iconify/icon-set/defaults.d.ts +6 -0
- package/lib/iconify/icon-set/defaults.js +19 -0
- package/lib/iconify/icon-set/icon.d.ts +6 -0
- package/lib/iconify/icon-set/icon.js +24 -0
- package/lib/iconify/icon-set/parse.d.ts +7 -0
- package/lib/iconify/icon-set/parse.js +31 -0
- package/lib/iconify/icon-set/types.d.ts +6 -0
- package/lib/iconify/icon-set/types.js +1 -0
- package/lib/index.d.ts +10 -10
- package/lib/index.js +9 -9
- package/lib/svg/content/defs.d.ts +20 -0
- package/lib/svg/content/defs.js +44 -0
- package/lib/svg/ids/duplicate.js +1 -4
- package/lib/svg/ids/unused.js +1 -2
- package/lib/svg/props/size.d.ts +8 -0
- package/lib/svg/props/size.js +34 -0
- package/lib/svg/props/stringify.d.ts +5 -0
- package/lib/svg/props/stringify.js +8 -0
- package/lib/svg/viewbox/minify.d.ts +6 -0
- package/lib/svg/viewbox/minify.js +15 -0
- package/lib/svg/viewbox/parse.d.ts +6 -0
- package/lib/svg/viewbox/parse.js +17 -0
- package/lib/svg/viewbox/square.d.ts +6 -0
- package/lib/svg/viewbox/square.js +24 -0
- package/lib/svg/viewbox/types.d.ts +11 -0
- package/lib/svg/viewbox/types.js +1 -0
- package/lib/svg/viewbox/value.d.ts +6 -0
- package/lib/svg/viewbox/value.js +8 -0
- package/lib/svg-css/convert/content.d.ts +7 -0
- package/lib/svg-css/convert/content.js +22 -0
- package/lib/{svg/css → svg-css}/convert/root.d.ts +2 -2
- package/lib/{svg/css → svg-css}/convert/root.js +3 -3
- package/lib/svg-css/convert/types.d.ts +5 -0
- package/lib/svg-css/convert/types.js +1 -0
- package/lib/svg-css/factory/code/iconify.d.ts +11 -0
- package/lib/svg-css/factory/code/iconify.js +20 -0
- package/lib/svg-css/factory/code/stringify.d.ts +5 -0
- package/lib/svg-css/factory/code/stringify.js +9 -0
- package/lib/svg-css/factory/code/template.d.ts +6 -0
- package/lib/svg-css/factory/code/template.js +15 -0
- package/lib/svg-css/factory/components/raw.d.ts +8 -0
- package/lib/svg-css/factory/components/raw.js +41 -0
- package/lib/svg-css/factory/components/shared/size.js +79 -0
- package/lib/svg-css/factory/components/vue/types.js +25 -0
- package/lib/svg-css/factory/components/vue.d.ts +8 -0
- package/lib/svg-css/factory/components/vue.js +103 -0
- package/lib/svg-css/factory/content/size.d.ts +11 -0
- package/lib/svg-css/factory/content/size.js +22 -0
- package/lib/svg-css/factory/content/stringify.d.ts +7 -0
- package/lib/svg-css/factory/content/stringify.js +17 -0
- package/lib/svg-css/factory/css/generate.d.ts +11 -0
- package/lib/svg-css/factory/css/generate.js +45 -0
- package/lib/svg-css/factory/css/name.d.ts +7 -0
- package/lib/svg-css/factory/css/name.js +12 -0
- package/lib/svg-css/factory/export/exports.d.ts +10 -0
- package/lib/svg-css/factory/export/exports.js +11 -0
- package/lib/svg-css/factory/export/file.d.ts +6 -0
- package/lib/svg-css/factory/export/file.js +12 -0
- package/lib/svg-css/factory/export/fs.d.ts +6 -0
- package/lib/svg-css/factory/export/fs.js +20 -0
- package/lib/svg-css/factory/export/merge.d.ts +7 -0
- package/lib/svg-css/factory/export/merge.js +23 -0
- package/lib/svg-css/factory/filenames/asset.d.ts +11 -0
- package/lib/svg-css/factory/filenames/asset.js +16 -0
- package/lib/svg-css/factory/filenames/component.d.ts +12 -0
- package/lib/svg-css/factory/filenames/component.js +14 -0
- package/lib/svg-css/factory/filenames/css.d.ts +7 -0
- package/lib/svg-css/factory/filenames/css.js +14 -0
- package/lib/svg-css/factory/filenames/options.d.ts +6 -0
- package/lib/svg-css/factory/filenames/options.js +27 -0
- package/lib/svg-css/factory/filenames/path.d.ts +11 -0
- package/lib/svg-css/factory/filenames/path.js +15 -0
- package/lib/svg-css/factory/filenames/types.d.ts +8 -0
- package/lib/svg-css/factory/filenames/types.js +14 -0
- package/lib/svg-css/factory/imports/add.d.ts +10 -0
- package/lib/svg-css/factory/imports/add.js +18 -0
- package/lib/svg-css/factory/imports/create.d.ts +6 -0
- package/lib/svg-css/factory/imports/create.js +15 -0
- package/lib/svg-css/factory/imports/stringify.d.ts +6 -0
- package/lib/svg-css/factory/imports/stringify.js +47 -0
- package/lib/svg-css/factory/props/object.d.ts +6 -0
- package/lib/svg-css/factory/props/object.js +10 -0
- package/lib/svg-css/factory/props/stringify.d.ts +10 -0
- package/lib/svg-css/factory/props/stringify.js +21 -0
- package/lib/svg-css/factory/props/types.d.ts +6 -0
- package/lib/svg-css/factory/props/types.js +16 -0
- package/lib/svg-css/factory/types/asset.d.ts +8 -0
- package/lib/svg-css/factory/types/asset.js +1 -0
- package/lib/svg-css/factory/types/component.d.ts +38 -0
- package/lib/svg-css/factory/types/component.js +1 -0
- package/lib/svg-css/factory/types/css.d.ts +5 -0
- package/lib/svg-css/factory/types/css.js +1 -0
- package/lib/svg-css/factory/types/data.d.ts +13 -0
- package/lib/svg-css/factory/types/data.js +1 -0
- package/lib/svg-css/factory/types/file.d.ts +14 -0
- package/lib/svg-css/factory/types/file.js +1 -0
- package/lib/svg-css/factory/types/options.d.ts +26 -0
- package/lib/svg-css/factory/types/options.js +1 -0
- package/lib/svg-css/factory/types/props.d.ts +14 -0
- package/lib/svg-css/factory/types/props.js +1 -0
- package/lib/svg-css/factory/types/source.d.ts +10 -0
- package/lib/svg-css/factory/types/source.js +1 -0
- package/lib/{svg/css → svg-css}/props/props.d.ts +1 -1
- package/lib/{svg/css → svg-css}/props/props.js +1 -1
- package/lib/{svg/css → svg-css}/types.d.ts +4 -6
- package/lib/svg-css/types.js +1 -0
- package/lib/xml/parse.js +2 -4
- package/package.json +11 -9
- package/lib/svg/css/convert/content.d.ts +0 -10
- package/lib/svg/css/convert/content.js +0 -27
- package/lib/svg/css/css/stringify.d.ts +0 -10
- package/lib/svg/css/css/stringify.js +0 -26
- /package/lib/{svg/css/css → classname}/const.d.ts +0 -0
- /package/lib/{svg/css/css → classname}/const.js +0 -0
- /package/lib/{svg/css/css → classname}/toggle.d.ts +0 -0
- /package/lib/{svg/css/css → classname}/toggle.js +0 -0
- /package/lib/{svg/css → css}/types.js +0 -0
- /package/lib/{svg/css → svg-css}/props/prop.d.ts +0 -0
- /package/lib/{svg/css → svg-css}/props/prop.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sortObject } from "
|
|
2
|
-
import { getUniqueHash } from "
|
|
1
|
+
import { sortObject } from "../helpers/misc/sort-object.js";
|
|
2
|
+
import { getUniqueHash } from "../helpers/hash/unique.js";
|
|
3
3
|
|
|
4
4
|
const length = 6;
|
|
5
5
|
/**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CSSKeyframes, CSSRules } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Stringify CSS rules
|
|
4
|
+
*/
|
|
5
|
+
declare function stringifyCSSRules(rules: CSSRules, depth?: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Stringify CSS selector with rules
|
|
8
|
+
*/
|
|
9
|
+
declare function stringifyCSSSelector(selector: string, rules: string | CSSRules, depth?: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Stringify CSS keyframes
|
|
12
|
+
*/
|
|
13
|
+
declare function stringifyCSSKeyframes(animationName: string, keyframes: CSSKeyframes, depth?: number): string;
|
|
14
|
+
export { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function indent(depth) {
|
|
2
|
+
return " ".repeat(depth);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Stringify CSS rules
|
|
6
|
+
*/
|
|
7
|
+
function stringifyCSSRules(rules, depth = 1) {
|
|
8
|
+
const tab = indent(depth);
|
|
9
|
+
const lines = [];
|
|
10
|
+
for (const key in rules) {
|
|
11
|
+
const value = rules[key];
|
|
12
|
+
lines.push(`${tab}${key}: ${value};\n`);
|
|
13
|
+
}
|
|
14
|
+
return lines.join("");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stringify CSS selector with rules
|
|
18
|
+
*/
|
|
19
|
+
function stringifyCSSSelector(selector, rules, depth = 0) {
|
|
20
|
+
const content = typeof rules === "string" ? rules : stringifyCSSRules(rules, depth + 1);
|
|
21
|
+
if (!content.length) return "";
|
|
22
|
+
const tab = indent(depth);
|
|
23
|
+
return `${tab}${selector} {\n${content}${tab}}\n`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Stringify CSS keyframes
|
|
27
|
+
*/
|
|
28
|
+
function stringifyCSSKeyframes(animationName, keyframes, depth = 0) {
|
|
29
|
+
const prop = keyframes.prop;
|
|
30
|
+
const values = /* @__PURE__ */ new Map();
|
|
31
|
+
keyframes.frames.forEach((frame) => {
|
|
32
|
+
const css = `${indent(depth + 2)}${prop}: ${frame.value};\n`;
|
|
33
|
+
const item = values.get(css);
|
|
34
|
+
if (item) item.push(frame.time);
|
|
35
|
+
else values.set(css, [frame.time]);
|
|
36
|
+
});
|
|
37
|
+
const lines = [];
|
|
38
|
+
lines.push(`${indent(depth)}@keyframes ${animationName} {\n`);
|
|
39
|
+
values.forEach((times, css) => {
|
|
40
|
+
lines.push(`${indent(depth + 1)}${times.map((time) => `${(time * 100).toFixed(2).replace(/\.?0+$/, "")}%`).join(", ")} {\n${css}${indent(depth + 1)}}\n`);
|
|
41
|
+
});
|
|
42
|
+
lines.push("}\n");
|
|
43
|
+
return lines.join("");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS rules
|
|
3
|
+
*/
|
|
4
|
+
type CSSRules = Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Animation keyframes
|
|
7
|
+
*/
|
|
8
|
+
interface CSSKeyframe {
|
|
9
|
+
time: number;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
interface CSSKeyframes {
|
|
13
|
+
prop: string;
|
|
14
|
+
frames: CSSKeyframe[];
|
|
15
|
+
}
|
|
16
|
+
export { CSSKeyframe, CSSKeyframes, CSSRules };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert string to camelCase
|
|
3
|
+
*/
|
|
4
|
+
declare function camelize(str: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Convert string to PascaleCase
|
|
7
|
+
*/
|
|
8
|
+
declare function pascalize(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert camelCase string to kebab-case
|
|
11
|
+
*/
|
|
12
|
+
declare function camelToKebab(key: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Convert camelCase string to snake-case
|
|
15
|
+
*/
|
|
16
|
+
declare function snakelize(str: string): string;
|
|
17
|
+
export { camelToKebab, camelize, pascalize, snakelize };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert string to camelCase
|
|
3
|
+
*/
|
|
4
|
+
function camelize(str) {
|
|
5
|
+
return str.replace(/-([a-z0-9])/g, (g) => g[1].toUpperCase());
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Convert string to PascaleCase
|
|
9
|
+
*/
|
|
10
|
+
function pascalize(str) {
|
|
11
|
+
const camel = camelize(str);
|
|
12
|
+
return camel.slice(0, 1).toUpperCase() + camel.slice(1);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert camelCase string to kebab-case
|
|
16
|
+
*/
|
|
17
|
+
function camelToKebab(key) {
|
|
18
|
+
return key.replace(/:/g, "-").replace(/([A-Z])/g, " $1").trim().split(/\s+/g).join("-").toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert camelCase string to snake-case
|
|
22
|
+
*/
|
|
23
|
+
function snakelize(str) {
|
|
24
|
+
return camelToKebab(str).replace(/-/g, "_");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { camelToKebab, camelize, pascalize, snakelize };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { wrapSVGContent } from "../../svg/content/defs.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalise icon: apply transformations
|
|
5
|
+
*/
|
|
6
|
+
function normaliseIconifyIcon(data) {
|
|
7
|
+
const viewBox = {
|
|
8
|
+
left: data.left ?? 0,
|
|
9
|
+
top: data.top ?? 0,
|
|
10
|
+
width: data.width ?? 16,
|
|
11
|
+
height: data.height ?? 16
|
|
12
|
+
};
|
|
13
|
+
let body = data.body;
|
|
14
|
+
const transformations = [];
|
|
15
|
+
let rotation = data.rotate ?? 0;
|
|
16
|
+
if (data.hFlip) if (data.vFlip) rotation += 2;
|
|
17
|
+
else {
|
|
18
|
+
transformations.push("translate(" + (viewBox.width + viewBox.left).toString() + " " + (0 - viewBox.top).toString() + ")");
|
|
19
|
+
transformations.push("scale(-1 1)");
|
|
20
|
+
viewBox.top = viewBox.left = 0;
|
|
21
|
+
}
|
|
22
|
+
else if (data.vFlip) {
|
|
23
|
+
transformations.push("translate(" + (0 - viewBox.left).toString() + " " + (viewBox.height + viewBox.top).toString() + ")");
|
|
24
|
+
transformations.push("scale(1 -1)");
|
|
25
|
+
viewBox.top = viewBox.left = 0;
|
|
26
|
+
}
|
|
27
|
+
if (rotation < 0) rotation -= Math.floor(rotation / 4) * 4;
|
|
28
|
+
rotation = rotation % 4;
|
|
29
|
+
switch (rotation) {
|
|
30
|
+
case 1: {
|
|
31
|
+
const value = viewBox.height / 2 + viewBox.top;
|
|
32
|
+
transformations.unshift(`rotate(90 ${value} ${value})`);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 2:
|
|
36
|
+
transformations.unshift(`rotate(180 ${viewBox.width / 2 + viewBox.left} ${viewBox.height / 2 + viewBox.top})`);
|
|
37
|
+
break;
|
|
38
|
+
case 3: {
|
|
39
|
+
const value = viewBox.width / 2 + viewBox.left;
|
|
40
|
+
transformations.unshift(`rotate(-90 ${value} ${value})`);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (rotation % 2 === 1) {
|
|
45
|
+
if (viewBox.left !== viewBox.top) {
|
|
46
|
+
const tempValue = viewBox.left;
|
|
47
|
+
viewBox.left = viewBox.top;
|
|
48
|
+
viewBox.top = tempValue;
|
|
49
|
+
}
|
|
50
|
+
if (viewBox.width !== viewBox.height) {
|
|
51
|
+
const tempValue = viewBox.width;
|
|
52
|
+
viewBox.width = viewBox.height;
|
|
53
|
+
viewBox.height = tempValue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (transformations.length) body = wrapSVGContent(body, "<g transform=\"" + transformations.join(" ") + "\">", "</g>");
|
|
57
|
+
return {
|
|
58
|
+
body,
|
|
59
|
+
viewBox
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { normaliseIconifyIcon };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const defaultProps = [
|
|
2
|
+
"width",
|
|
3
|
+
"height",
|
|
4
|
+
"left",
|
|
5
|
+
"top"
|
|
6
|
+
];
|
|
7
|
+
/**
|
|
8
|
+
* Get default properties from icon set
|
|
9
|
+
*/
|
|
10
|
+
function getIconifyIconSetDefaults(data) {
|
|
11
|
+
const defaultValues = {};
|
|
12
|
+
for (const prop of defaultProps) {
|
|
13
|
+
const defaultValue = data[prop];
|
|
14
|
+
if (defaultValue) defaultValues[prop] = defaultValue;
|
|
15
|
+
}
|
|
16
|
+
return defaultValues;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { getIconifyIconSetDefaults };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getIconifyIconSetDefaults } from "./defaults.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get icon data from Iconify icon set
|
|
5
|
+
*/
|
|
6
|
+
function getIconifyIconSetIcon(data, name) {
|
|
7
|
+
if (data.not_found?.includes(name)) return null;
|
|
8
|
+
const icon = data.icons[name];
|
|
9
|
+
if (icon) return {
|
|
10
|
+
...getIconifyIconSetDefaults(data),
|
|
11
|
+
...icon
|
|
12
|
+
};
|
|
13
|
+
const alias = data.aliases?.[name];
|
|
14
|
+
if (alias) {
|
|
15
|
+
const parentIcon = data.icons?.[alias.parent];
|
|
16
|
+
return parentIcon ? {
|
|
17
|
+
...getIconifyIconSetDefaults(data),
|
|
18
|
+
...parentIcon,
|
|
19
|
+
...alias
|
|
20
|
+
} : null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { getIconifyIconSetIcon };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParseIconifyIconSetCallback } from "./types.js";
|
|
2
|
+
import { IconifyJSON } from "@iconify/types";
|
|
3
|
+
/**
|
|
4
|
+
* Parse Iconify icon set and call callback for each icon
|
|
5
|
+
*/
|
|
6
|
+
declare function parseIconifyIconSet(data: IconifyJSON, callback: ParseIconifyIconSetCallback): void;
|
|
7
|
+
export { parseIconifyIconSet };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getIconifyIconSetDefaults } from "./defaults.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse Iconify icon set and call callback for each icon
|
|
5
|
+
*/
|
|
6
|
+
function parseIconifyIconSet(data, callback) {
|
|
7
|
+
const defaultValues = getIconifyIconSetDefaults(data);
|
|
8
|
+
for (const name in data.icons) {
|
|
9
|
+
const item = data.icons[name];
|
|
10
|
+
callback(name, {
|
|
11
|
+
...defaultValues,
|
|
12
|
+
...item
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (data.aliases) for (const name in data.aliases) {
|
|
16
|
+
const item = data.aliases[name];
|
|
17
|
+
const parentIcon = data.icons[item.parent];
|
|
18
|
+
if (!parentIcon) {
|
|
19
|
+
callback(name, null);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
callback(name, {
|
|
23
|
+
...defaultValues,
|
|
24
|
+
...parentIcon,
|
|
25
|
+
...item
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (data.not_found) for (const name of data.not_found) callback(name, null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { parseIconifyIconSet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
|
|
2
|
+
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
3
|
+
import { createCSSClassName } from "./css/hash.js";
|
|
4
|
+
import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
1
5
|
import { hashString } from "./helpers/hash/hash.js";
|
|
2
6
|
import { hashToString } from "./helpers/hash/stringify.js";
|
|
3
7
|
import { UniqueHashOptions } from "./helpers/hash/types.js";
|
|
@@ -15,13 +19,9 @@ import { removeDuplicateIDs } from "./svg/ids/duplicate.js";
|
|
|
15
19
|
import { removeUnusedIDs } from "./svg/ids/unused.js";
|
|
16
20
|
import { changeSVGIDs } from "./svg/ids/change.js";
|
|
17
21
|
import { createUniqueIDs } from "./svg/ids/unique.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
import { extractSVGTagPropertiesForCSS } from "./svg/css/props/props.js";
|
|
25
|
-
import { convertSVGRootToCSS } from "./svg/css/convert/root.js";
|
|
26
|
-
import { convertSVGContentToCSS } from "./svg/css/convert/content.js";
|
|
27
|
-
export { CSSRules, ChangeIDResult, ClassProp, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, SVGConvertedToCSSProperties, SVGPropertyType, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSS, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
|
|
22
|
+
import { ConvertedSVGContent, SVGConvertedToCSSProperties, SVGPropertyType } from "./svg-css/types.js";
|
|
23
|
+
import { convertSVGPropertyToCSS } from "./svg-css/props/prop.js";
|
|
24
|
+
import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
|
|
25
|
+
import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
|
|
26
|
+
import { convertSVGContentToCSSRules } from "./svg-css/convert/content.js";
|
|
27
|
+
export { ChangeIDResult, ClassProp, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, SVGConvertedToCSSProperties, SVGPropertyType, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
|
package/lib/index.js
CHANGED
|
@@ -7,18 +7,18 @@ import { getUniqueHash } from "./helpers/hash/unique.js";
|
|
|
7
7
|
import { iterateXMLContent } from "./xml/iterate.js";
|
|
8
8
|
import { parseXMLContent } from "./xml/parse.js";
|
|
9
9
|
import { stringifyXMLContent } from "./xml/stringify.js";
|
|
10
|
+
import { createCSSClassName } from "./css/hash.js";
|
|
11
|
+
import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
12
|
+
import { classProps, defaultClassProp } from "./classname/const.js";
|
|
13
|
+
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
10
14
|
import { changeIDInString } from "./svg/ids/string.js";
|
|
11
15
|
import { removeDuplicateIDs } from "./svg/ids/duplicate.js";
|
|
12
16
|
import { removeUnusedIDs } from "./svg/ids/unused.js";
|
|
13
17
|
import { changeSVGIDs } from "./svg/ids/change.js";
|
|
14
18
|
import { createUniqueIDs } from "./svg/ids/unique.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { convertSVGPropertyToCSS } from "./svg/css/props/prop.js";
|
|
20
|
-
import { extractSVGTagPropertiesForCSS } from "./svg/css/props/props.js";
|
|
21
|
-
import { convertSVGRootToCSS } from "./svg/css/convert/root.js";
|
|
22
|
-
import { convertSVGContentToCSS } from "./svg/css/convert/content.js";
|
|
19
|
+
import { convertSVGPropertyToCSS } from "./svg-css/props/prop.js";
|
|
20
|
+
import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
|
|
21
|
+
import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
|
|
22
|
+
import { convertSVGContentToCSSRules } from "./svg-css/convert/content.js";
|
|
23
23
|
|
|
24
|
-
export { changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues,
|
|
24
|
+
export { changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface SplitSVGDefsResult {
|
|
2
|
+
defs: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Extract definitions from SVG
|
|
7
|
+
*
|
|
8
|
+
* Can be used with other tags, but name kept for backwards compatibility.
|
|
9
|
+
* Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
|
|
10
|
+
*/
|
|
11
|
+
declare function splitSVGDefs(content: string, tag?: string): SplitSVGDefsResult;
|
|
12
|
+
/**
|
|
13
|
+
* Merge defs and content
|
|
14
|
+
*/
|
|
15
|
+
declare function mergeDefsAndContent(defs: string, content: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap SVG content, without wrapping definitions
|
|
18
|
+
*/
|
|
19
|
+
declare function wrapSVGContent(body: string, start: string, end: string): string;
|
|
20
|
+
export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract definitions from SVG
|
|
3
|
+
*
|
|
4
|
+
* Can be used with other tags, but name kept for backwards compatibility.
|
|
5
|
+
* Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
|
|
6
|
+
*/
|
|
7
|
+
function splitSVGDefs(content, tag = "defs") {
|
|
8
|
+
let defs = "";
|
|
9
|
+
let index;
|
|
10
|
+
while ((index = content.indexOf("<" + tag)) !== -1) {
|
|
11
|
+
const start = content.indexOf(">", index);
|
|
12
|
+
if (start === -1) break;
|
|
13
|
+
const prevContent = content.slice(0, index).trim();
|
|
14
|
+
if (content[start - 1] === "/") {
|
|
15
|
+
content = prevContent + content.slice(start + 1);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const end = content.indexOf("</" + tag);
|
|
19
|
+
if (end === -1) break;
|
|
20
|
+
const endEnd = content.indexOf(">", end);
|
|
21
|
+
if (endEnd === -1) break;
|
|
22
|
+
defs += content.slice(start + 1, end).trim();
|
|
23
|
+
content = prevContent + content.slice(endEnd + 1);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
defs,
|
|
27
|
+
content
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Merge defs and content
|
|
32
|
+
*/
|
|
33
|
+
function mergeDefsAndContent(defs, content) {
|
|
34
|
+
return defs ? `<defs>${defs}</defs>${content}` : content;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wrap SVG content, without wrapping definitions
|
|
38
|
+
*/
|
|
39
|
+
function wrapSVGContent(body, start, end) {
|
|
40
|
+
const split = splitSVGDefs(body);
|
|
41
|
+
return mergeDefsAndContent(split.defs, start + split.content + end);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
|
package/lib/svg/ids/duplicate.js
CHANGED
|
@@ -5,10 +5,7 @@ import { iterateXMLContent } from "../../xml/iterate.js";
|
|
|
5
5
|
*/
|
|
6
6
|
function removeDuplicateIDs(root, data) {
|
|
7
7
|
const remove = /* @__PURE__ */ new Set();
|
|
8
|
-
for (const id in data.map)
|
|
9
|
-
const nodes = data.map[id];
|
|
10
|
-
if (nodes.length > 1) remove.add(id);
|
|
11
|
-
}
|
|
8
|
+
for (const id in data.map) if (data.map[id].length > 1) remove.add(id);
|
|
12
9
|
if (remove.size) {
|
|
13
10
|
const removing = /* @__PURE__ */ new Set();
|
|
14
11
|
return iterateXMLContent(root, (node) => {
|
package/lib/svg/ids/unused.js
CHANGED
|
@@ -15,8 +15,7 @@ function removeUnusedIDs(root, data) {
|
|
|
15
15
|
case "clipPath":
|
|
16
16
|
case "symbol": return "remove";
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
if (parentNode?.tag === "defs") return "remove";
|
|
18
|
+
if (stack[stack.length - 1]?.tag === "defs") return "remove";
|
|
20
19
|
delete node.attribs.id;
|
|
21
20
|
});
|
|
22
21
|
return root;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate second dimension when only 1 dimension is set
|
|
3
|
+
*
|
|
4
|
+
* If you are calculating width, ratio should be width/height
|
|
5
|
+
* If you are calculating height, ratio should be height/width
|
|
6
|
+
*/
|
|
7
|
+
declare function calculateSize<T extends string | number>(size: T, ratio: number, precision?: number): T;
|
|
8
|
+
export { calculateSize };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regular expressions for calculating dimensions
|
|
3
|
+
*/
|
|
4
|
+
const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
|
|
5
|
+
const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
|
|
6
|
+
/**
|
|
7
|
+
* Calculate second dimension when only 1 dimension is set
|
|
8
|
+
*
|
|
9
|
+
* If you are calculating width, ratio should be width/height
|
|
10
|
+
* If you are calculating height, ratio should be height/width
|
|
11
|
+
*/
|
|
12
|
+
function calculateSize(size, ratio, precision) {
|
|
13
|
+
if (ratio === 1) return size;
|
|
14
|
+
precision = precision || 100;
|
|
15
|
+
if (typeof size === "number") return Math.ceil(size * ratio * precision) / precision;
|
|
16
|
+
if (typeof size !== "string") return size;
|
|
17
|
+
const oldParts = size.split(unitsSplit);
|
|
18
|
+
if (oldParts === null || !oldParts.length) return size;
|
|
19
|
+
const newParts = [];
|
|
20
|
+
let code = oldParts.shift();
|
|
21
|
+
let isNumber = unitsTest.test(code);
|
|
22
|
+
while (true) {
|
|
23
|
+
if (isNumber) {
|
|
24
|
+
const num = parseFloat(code);
|
|
25
|
+
if (isNaN(num)) newParts.push(code);
|
|
26
|
+
else newParts.push(Math.ceil(num * ratio * precision) / precision);
|
|
27
|
+
} else newParts.push(code);
|
|
28
|
+
code = oldParts.shift();
|
|
29
|
+
if (code === void 0) return newParts.join("");
|
|
30
|
+
isNumber = !isNumber;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { calculateSize };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minify viewBox by removing default values
|
|
3
|
+
*/
|
|
4
|
+
function minifyViewBox(viewBox) {
|
|
5
|
+
const result = {
|
|
6
|
+
width: viewBox.width,
|
|
7
|
+
height: viewBox.height
|
|
8
|
+
};
|
|
9
|
+
if (viewBox.left) result.left = viewBox.left;
|
|
10
|
+
if (viewBox.top) result.top = viewBox.top;
|
|
11
|
+
if (viewBox.cx && viewBox.cx * 2 !== viewBox.width) result.cx = viewBox.cx;
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { minifyViewBox };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse viewBox string to IconViewBox
|
|
3
|
+
*/
|
|
4
|
+
function parseViewBox(value) {
|
|
5
|
+
const parts = value.split(/[\s,]+/).map((item) => item.trim());
|
|
6
|
+
if (parts.length !== 4) return;
|
|
7
|
+
const nums = parts.map((part) => Number(part));
|
|
8
|
+
if (nums.some((num) => isNaN(num))) return;
|
|
9
|
+
return {
|
|
10
|
+
left: nums[0],
|
|
11
|
+
top: nums[1],
|
|
12
|
+
width: nums[2],
|
|
13
|
+
height: nums[3]
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { parseViewBox };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make viewBox square
|
|
3
|
+
*/
|
|
4
|
+
function makeSquareViewBox(viewBox) {
|
|
5
|
+
const { width, height } = viewBox;
|
|
6
|
+
if (width === height) return { ...viewBox };
|
|
7
|
+
if (width >= height) {
|
|
8
|
+
const diff = (width - height) / 2;
|
|
9
|
+
return {
|
|
10
|
+
left: viewBox.left,
|
|
11
|
+
top: (viewBox.top ?? 0) - diff,
|
|
12
|
+
width,
|
|
13
|
+
height: width
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
left: (viewBox.cx ?? width / 2 + (viewBox.left ?? 0)) - height / 2,
|
|
18
|
+
top: viewBox.top,
|
|
19
|
+
width: height,
|
|
20
|
+
height
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { makeSquareViewBox };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|