@cyberalien/svg-utils 0.1.2 → 0.1.3
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/css/hash.d.ts +2 -2
- package/lib/css/hash.js +3 -2
- package/lib/css/types.d.ts +6 -1
- package/lib/index.d.ts +1 -1
- package/lib/svg-css/content.js +1 -1
- package/lib/svg-css/root.d.ts +2 -2
- package/lib/svg-css/root.js +2 -2
- package/lib/svg-css/types.d.ts +2 -1
- package/package.json +1 -1
package/lib/css/hash.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CSSRules } from "./types.js";
|
|
1
|
+
import { CSSHashOptions, CSSRules } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Get class name for CSS rules
|
|
4
4
|
*/
|
|
5
|
-
declare function createCSSClassName(rules: CSSRules, prefix?: string): string;
|
|
5
|
+
declare function createCSSClassName(rules: CSSRules, prefix?: string, options?: CSSHashOptions): string;
|
|
6
6
|
export { createCSSClassName };
|
package/lib/css/hash.js
CHANGED
|
@@ -5,12 +5,13 @@ const length = 6;
|
|
|
5
5
|
/**
|
|
6
6
|
* Get class name for CSS rules
|
|
7
7
|
*/
|
|
8
|
-
function createCSSClassName(rules, prefix = "") {
|
|
8
|
+
function createCSSClassName(rules, prefix = "", options) {
|
|
9
9
|
const sorted = sortObject(rules);
|
|
10
10
|
return getUniqueHash(sorted, {
|
|
11
11
|
css: true,
|
|
12
12
|
length,
|
|
13
|
-
prefix
|
|
13
|
+
prefix,
|
|
14
|
+
...options
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
|
package/lib/css/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UniqueHashOptions } from "../helpers/hash/types.js";
|
|
1
2
|
/**
|
|
2
3
|
* CSS rules
|
|
3
4
|
*/
|
|
@@ -13,4 +14,8 @@ interface CSSKeyframes {
|
|
|
13
14
|
prop: string;
|
|
14
15
|
frames: CSSKeyframe[];
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Hash options
|
|
19
|
+
*/
|
|
20
|
+
type CSSHashOptions = Partial<Pick<UniqueHashOptions, 'length' | 'lengths' | 'throwOnCollision'>>;
|
|
21
|
+
export { CSSHashOptions, CSSKeyframe, CSSKeyframes, CSSRules };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
|
|
2
2
|
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
3
|
+
import { UniqueHashOptions } from "./helpers/hash/types.js";
|
|
3
4
|
import { ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions } from "./xml/types.js";
|
|
4
5
|
import { ConvertSVGContentOptions, ConvertedSVGContent } from "./svg-css/types.js";
|
|
5
6
|
import { createCSSClassName } from "./css/hash.js";
|
|
6
7
|
import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
7
8
|
import { hashString } from "./helpers/hash/hash.js";
|
|
8
9
|
import { hashToString } from "./helpers/hash/stringify.js";
|
|
9
|
-
import { UniqueHashOptions } from "./helpers/hash/types.js";
|
|
10
10
|
import { getUniqueHash } from "./helpers/hash/unique.js";
|
|
11
11
|
import { cloneObject } from "./helpers/misc/clone.js";
|
|
12
12
|
import { compareSets, compareValues } from "./helpers/misc/compare.js";
|
package/lib/svg-css/content.js
CHANGED
|
@@ -8,7 +8,7 @@ import { convertSVGRootToCSS } from "./root.js";
|
|
|
8
8
|
function convertSVGContentToCSSRules(content, options) {
|
|
9
9
|
const root = parseXMLContent(content);
|
|
10
10
|
if (!root) return { content };
|
|
11
|
-
const classes = convertSVGRootToCSS(root, options?.classNamePrefix);
|
|
11
|
+
const classes = convertSVGRootToCSS(root, options?.classNamePrefix, options?.hashOptions);
|
|
12
12
|
if (classes) {
|
|
13
13
|
const newContent = stringifyXMLContent(root, options);
|
|
14
14
|
if (newContent) return {
|
package/lib/svg-css/root.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CSSRules } from "../css/types.js";
|
|
1
|
+
import { CSSHashOptions, CSSRules } from "../css/types.js";
|
|
2
2
|
import { ParsedXMLTagElement } from "../xml/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Convert SVG tags tree to SVG+CSS
|
|
5
5
|
*
|
|
6
6
|
* Returns used CSS class names with rules
|
|
7
7
|
*/
|
|
8
|
-
declare function convertSVGRootToCSS(root: ParsedXMLTagElement[], classNamePrefix?: string): Record<string, CSSRules>;
|
|
8
|
+
declare function convertSVGRootToCSS(root: ParsedXMLTagElement[], classNamePrefix?: string, hashOptions?: CSSHashOptions): Record<string, CSSRules>;
|
|
9
9
|
export { convertSVGRootToCSS };
|
package/lib/svg-css/root.js
CHANGED
|
@@ -8,13 +8,13 @@ import { extractSVGTagPropertiesForCSS } from "./props/props.js";
|
|
|
8
8
|
*
|
|
9
9
|
* Returns used CSS class names with rules
|
|
10
10
|
*/
|
|
11
|
-
function convertSVGRootToCSS(root, classNamePrefix = "") {
|
|
11
|
+
function convertSVGRootToCSS(root, classNamePrefix = "", hashOptions) {
|
|
12
12
|
const rules = Object.create(null);
|
|
13
13
|
iterateXMLContent(root, (node) => {
|
|
14
14
|
if (node.type === "tag") {
|
|
15
15
|
const props = extractSVGTagPropertiesForCSS(node);
|
|
16
16
|
if (props) {
|
|
17
|
-
const className = createCSSClassName(props.rules, classNamePrefix);
|
|
17
|
+
const className = createCSSClassName(props.rules, classNamePrefix, hashOptions);
|
|
18
18
|
toggleClassName(node.attribs, className, true);
|
|
19
19
|
rules[className] = props.rules;
|
|
20
20
|
}
|
package/lib/svg-css/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { CSSKeyframes, CSSRules } from "../css/types.js";
|
|
1
|
+
import { CSSHashOptions, CSSKeyframes, CSSRules } from "../css/types.js";
|
|
2
2
|
import { StringifyXMLOptions } from "../xml/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Options for converting SVG content to SVG+CSS
|
|
5
5
|
*/
|
|
6
6
|
interface ConvertSVGContentOptions extends StringifyXMLOptions {
|
|
7
7
|
classNamePrefix?: string;
|
|
8
|
+
hashOptions?: CSSHashOptions;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Result of converting SVG content to SVG+CSS
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Common functions for working with SVG used by various packages.",
|
|
5
5
|
"author": "Vjacheslav Trushkin",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.3",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|