@cyberalien/svg-utils 1.0.9 → 1.0.11
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/index.d.ts +2 -2
- package/lib/svg-css/animations/attribute.d.ts +11 -0
- package/lib/svg-css/animations/attribute.js +19 -0
- package/lib/svg-css/animations/common.d.ts +8 -0
- package/lib/svg-css/animations/common.js +16 -0
- package/lib/svg-css/animations/find.d.ts +9 -0
- package/lib/svg-css/animations/find.js +48 -0
- package/lib/svg-css/animations/tags.d.ts +7 -3
- package/lib/svg-css/animations/tags.js +9 -8
- package/lib/svg-css/animations/types.d.ts +19 -0
- package/lib/svg-css/animations/types.js +1 -0
- package/lib/svg-css/content.js +1 -1
- package/lib/svg-css/props/prop.d.ts +11 -2
- package/lib/svg-css/props/prop.js +6 -4
- package/lib/svg-css/props/props.d.ts +1 -1
- package/lib/svg-css/props/props.js +10 -6
- package/lib/svg-css/root.d.ts +3 -2
- package/lib/svg-css/root.js +4 -2
- package/lib/svg-css/types.d.ts +8 -3
- package/lib/xml/stringify.d.ts +2 -2
- package/lib/xml/stringify.js +5 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
|
|
|
2
2
|
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
3
3
|
import { UniqueHashOptions } from "./helpers/hash/types.js";
|
|
4
4
|
import { ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions } from "./xml/types.js";
|
|
5
|
-
import { ConvertSVGContentOptions, ConvertedSVGContent } from "./svg-css/types.js";
|
|
5
|
+
import { BaseConvertSVGContentOptions, ConvertSVGContentOptions, ConvertedSVGContent } from "./svg-css/types.js";
|
|
6
6
|
import { createCSSClassName } from "./css/hash.js";
|
|
7
7
|
import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
8
8
|
import { hashString } from "./helpers/hash/hash.js";
|
|
@@ -24,4 +24,4 @@ import { changeSVGIDs } from "./svg/ids/change.js";
|
|
|
24
24
|
import { createUniqueIDs } from "./svg/ids/unique.js";
|
|
25
25
|
import { convertSVGRootToCSS } from "./svg-css/root.js";
|
|
26
26
|
import { convertSVGContentToCSSRules } from "./svg-css/content.js";
|
|
27
|
-
export { ChangeIDResult, ClassProp, ComparisonKey, ConvertSVGContentOptions, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareKeys, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName, uniquePromise };
|
|
27
|
+
export { BaseConvertSVGContentOptions, ChangeIDResult, ClassProp, ComparisonKey, ConvertSVGContentOptions, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareKeys, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName, uniquePromise };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ParsedXMLTagElement } from "../../xml/types.js";
|
|
2
|
+
import { getSVGPropertyType } from "../props/prop.js";
|
|
3
|
+
interface CheckResult {
|
|
4
|
+
attributeName: string;
|
|
5
|
+
type: ReturnType<typeof getSVGPropertyType>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get animated attribute name and type
|
|
9
|
+
*/
|
|
10
|
+
declare function getAnimatedAttributeData(node: ParsedXMLTagElement, stack: ParsedXMLTagElement[], supportLegacyBrowsers?: boolean): undefined | CheckResult;
|
|
11
|
+
export { getAnimatedAttributeData };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getSVGPropertyType } from "../props/prop.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get animated attribute name and type
|
|
5
|
+
*/
|
|
6
|
+
function getAnimatedAttributeData(node, stack, supportLegacyBrowsers) {
|
|
7
|
+
const parentNode = stack[stack.length - 1];
|
|
8
|
+
if (!parentNode) return;
|
|
9
|
+
const parentTag = parentNode.tag;
|
|
10
|
+
const attributeName = node.attribs.attributeName;
|
|
11
|
+
if (typeof attributeName !== "string") return;
|
|
12
|
+
const type = getSVGPropertyType(parentTag, attributeName, supportLegacyBrowsers);
|
|
13
|
+
return type ? {
|
|
14
|
+
attributeName,
|
|
15
|
+
type
|
|
16
|
+
} : void 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { getAnimatedAttributeData };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsedXMLTagElement } from "../../xml/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check for common failures
|
|
4
|
+
*
|
|
5
|
+
* Returns true on success
|
|
6
|
+
*/
|
|
7
|
+
declare function checkAnimationTagForCompatibility(node: ParsedXMLTagElement): boolean | undefined;
|
|
8
|
+
export { checkAnimationTagForCompatibility };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const supportedValues = {
|
|
2
|
+
additive: "replace",
|
|
3
|
+
accumulate: "none"
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Check for common failures
|
|
7
|
+
*
|
|
8
|
+
* Returns true on success
|
|
9
|
+
*/
|
|
10
|
+
function checkAnimationTagForCompatibility(node) {
|
|
11
|
+
if (node.children.length) return;
|
|
12
|
+
const attribs = node.attribs;
|
|
13
|
+
for (const attr in supportedValues) if (attribs[attr] && attribs[attr] !== supportedValues[attr]) return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { checkAnimationTagForCompatibility };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedXMLTagElement } from "../../xml/types.js";
|
|
2
|
+
import { FindSVGAnimationsOptions, SVGAnimationsContext } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Find all animations in SVG tree
|
|
5
|
+
*
|
|
6
|
+
* @todo Implement this
|
|
7
|
+
*/
|
|
8
|
+
declare function findAnimationsInSVGTree(root: ParsedXMLTagElement[], options: FindSVGAnimationsOptions): SVGAnimationsContext;
|
|
9
|
+
export { findAnimationsInSVGTree };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { iterateXMLContent } from "../../xml/iterate.js";
|
|
2
|
+
import { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTag, svgSetTag } from "./tags.js";
|
|
3
|
+
import { getAnimatedAttributeData } from "./attribute.js";
|
|
4
|
+
import { checkAnimationTagForCompatibility } from "./common.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Find all animations in SVG tree
|
|
8
|
+
*
|
|
9
|
+
* @todo Implement this
|
|
10
|
+
*/
|
|
11
|
+
function findAnimationsInSVGTree(root, options) {
|
|
12
|
+
const animatedProperties = /* @__PURE__ */ new Map();
|
|
13
|
+
let failed = false;
|
|
14
|
+
const context = {
|
|
15
|
+
failed,
|
|
16
|
+
animatedProperties
|
|
17
|
+
};
|
|
18
|
+
iterateXMLContent(root, (node, stack) => {
|
|
19
|
+
if (context.failed || node.type !== "tag") return;
|
|
20
|
+
switch (node.tag) {
|
|
21
|
+
case svgAnimateMotionTag:
|
|
22
|
+
failed = true;
|
|
23
|
+
return "abort";
|
|
24
|
+
case svgAnimateTransformTag:
|
|
25
|
+
if (!checkAnimationTagForCompatibility(node)) {
|
|
26
|
+
failed = true;
|
|
27
|
+
return "abort";
|
|
28
|
+
}
|
|
29
|
+
failed = true;
|
|
30
|
+
return "abort";
|
|
31
|
+
case svgSetTag:
|
|
32
|
+
case svgAnimationTag:
|
|
33
|
+
if (!checkAnimationTagForCompatibility(node)) {
|
|
34
|
+
failed = true;
|
|
35
|
+
return "abort";
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
default: return;
|
|
39
|
+
}
|
|
40
|
+
if (!getAnimatedAttributeData(node, stack, options.supportLegacyBrowsers)) {
|
|
41
|
+
failed = true;
|
|
42
|
+
return "abort";
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return failed ? { failed: true } : context;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { findAnimationsInSVGTree };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Tag used to set attribute value without animation duration
|
|
3
3
|
*/
|
|
4
|
-
declare const
|
|
4
|
+
declare const svgSetTag = "set";
|
|
5
|
+
/**
|
|
6
|
+
* Attribute animation tag
|
|
7
|
+
*/
|
|
8
|
+
declare const svgAnimationTag = "animate";
|
|
5
9
|
/**
|
|
6
10
|
* Tag for animating transformations in SVG
|
|
7
11
|
*/
|
|
@@ -14,4 +18,4 @@ declare const svgAnimateMotionTag = "animateMotion";
|
|
|
14
18
|
* All tags for animating SVG
|
|
15
19
|
*/
|
|
16
20
|
declare const svgAnimationTags: string[];
|
|
17
|
-
export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTags,
|
|
21
|
+
export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTag, svgAnimationTags, svgSetTag };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Tag used to set attribute value without animation duration
|
|
3
3
|
*/
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const svgSetTag = "set";
|
|
5
|
+
/**
|
|
6
|
+
* Attribute animation tag
|
|
7
|
+
*/
|
|
8
|
+
const svgAnimationTag = "animate";
|
|
9
9
|
/**
|
|
10
10
|
* Tag for animating transformations in SVG
|
|
11
11
|
*/
|
|
@@ -18,9 +18,10 @@ const svgAnimateMotionTag = "animateMotion";
|
|
|
18
18
|
* All tags for animating SVG
|
|
19
19
|
*/
|
|
20
20
|
const svgAnimationTags = [
|
|
21
|
-
|
|
21
|
+
svgSetTag,
|
|
22
|
+
svgAnimationTag,
|
|
22
23
|
svgAnimateTransformTag,
|
|
23
24
|
svgAnimateMotionTag
|
|
24
25
|
];
|
|
25
26
|
|
|
26
|
-
export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTags,
|
|
27
|
+
export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTag, svgAnimationTags, svgSetTag };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ParsedXMLTagElement } from "../../xml/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* SVG animations context
|
|
4
|
+
*/
|
|
5
|
+
interface FailedSVGAnimationsContext {
|
|
6
|
+
failed: true;
|
|
7
|
+
}
|
|
8
|
+
interface SuccessfulSVGAnimationsContext {
|
|
9
|
+
failed: false;
|
|
10
|
+
animatedProperties: Map<ParsedXMLTagElement, Set<string>>;
|
|
11
|
+
}
|
|
12
|
+
type SVGAnimationsContext = FailedSVGAnimationsContext | SuccessfulSVGAnimationsContext;
|
|
13
|
+
/**
|
|
14
|
+
* Options for finding animations in SVG tree
|
|
15
|
+
*/
|
|
16
|
+
interface FindSVGAnimationsOptions {
|
|
17
|
+
supportLegacyBrowsers?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export { FindSVGAnimationsOptions, SVGAnimationsContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
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
|
|
11
|
+
const classes = convertSVGRootToCSS(root, options);
|
|
12
12
|
if (classes) {
|
|
13
13
|
const newContent = stringifyXMLContent(root, options);
|
|
14
14
|
if (newContent) return {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG property types
|
|
3
|
+
*/
|
|
4
|
+
declare const propTypes: readonly ["path", "px", "raw"];
|
|
5
|
+
type SVGPropertyType = (typeof propTypes)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Get property type
|
|
8
|
+
*/
|
|
9
|
+
declare function getSVGPropertyType(tag: string, prop: string, supportLegacyBrowsers?: boolean): SVGPropertyType | undefined;
|
|
1
10
|
/**
|
|
2
11
|
* Convert property to CSS
|
|
3
12
|
*/
|
|
4
|
-
declare function convertSVGPropertyToCSS(tag: string, prop: string, value: string | number): [string, string] | undefined;
|
|
5
|
-
export { convertSVGPropertyToCSS };
|
|
13
|
+
declare function convertSVGPropertyToCSS(tag: string, prop: string, value: string | number, supportLegacyBrowsers?: boolean): [string, string] | undefined;
|
|
14
|
+
export { convertSVGPropertyToCSS, getSVGPropertyType };
|
|
@@ -46,19 +46,21 @@ const skipTags = [
|
|
|
46
46
|
"set",
|
|
47
47
|
"discard"
|
|
48
48
|
];
|
|
49
|
+
const legacyProps = ["d"];
|
|
49
50
|
/**
|
|
50
51
|
* Get property type
|
|
51
52
|
*/
|
|
52
|
-
function getSVGPropertyType(tag, prop) {
|
|
53
|
+
function getSVGPropertyType(tag, prop, supportLegacyBrowsers = false) {
|
|
53
54
|
if (skipTags.includes(tag)) return;
|
|
55
|
+
if (supportLegacyBrowsers && legacyProps.includes(prop)) return;
|
|
54
56
|
for (const type of propTypes) if (props[tag]?.[type]?.includes(prop) || props["*"]?.[type]?.includes(prop)) return type;
|
|
55
57
|
if (prop.startsWith("stroke") || prop.startsWith("fill")) return "raw";
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* Convert property to CSS
|
|
59
61
|
*/
|
|
60
|
-
function convertSVGPropertyToCSS(tag, prop, value) {
|
|
61
|
-
switch (getSVGPropertyType(tag, prop)) {
|
|
62
|
+
function convertSVGPropertyToCSS(tag, prop, value, supportLegacyBrowsers = false) {
|
|
63
|
+
switch (getSVGPropertyType(tag, prop, supportLegacyBrowsers)) {
|
|
62
64
|
case "path":
|
|
63
65
|
if (typeof value !== "string") return;
|
|
64
66
|
return [prop, `path("${value.replace(/\s+/g, " ")}")`];
|
|
@@ -71,4 +73,4 @@ function convertSVGPropertyToCSS(tag, prop, value) {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
export { convertSVGPropertyToCSS };
|
|
76
|
+
export { convertSVGPropertyToCSS, getSVGPropertyType };
|
|
@@ -5,5 +5,5 @@ import { SVGConvertedToCSSProperties } from "./types.js";
|
|
|
5
5
|
*
|
|
6
6
|
* Returns CSS rules, does not add a class to tag, but does remove properties from tag
|
|
7
7
|
*/
|
|
8
|
-
declare function extractSVGTagPropertiesForCSS(tag: ParsedXMLTagElement): SVGConvertedToCSSProperties | undefined;
|
|
8
|
+
declare function extractSVGTagPropertiesForCSS(tag: ParsedXMLTagElement, supportLegacyBrowsers?: boolean): SVGConvertedToCSSProperties | undefined;
|
|
9
9
|
export { extractSVGTagPropertiesForCSS };
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import { iterateXMLContent } from "../../xml/iterate.js";
|
|
2
2
|
import { convertSVGPropertyToCSS } from "./prop.js";
|
|
3
|
-
import { svgAnimateTransformTag,
|
|
3
|
+
import { svgAnimateTransformTag, svgAnimationTag, svgSetTag } from "../animations/tags.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Extract SVG tag properties that can be converted to CSS
|
|
7
7
|
*
|
|
8
8
|
* Returns CSS rules, does not add a class to tag, but does remove properties from tag
|
|
9
9
|
*/
|
|
10
|
-
function extractSVGTagPropertiesForCSS(tag) {
|
|
10
|
+
function extractSVGTagPropertiesForCSS(tag, supportLegacyBrowsers = false) {
|
|
11
11
|
const result = {
|
|
12
12
|
props: [],
|
|
13
13
|
rules: Object.create(null)
|
|
14
14
|
};
|
|
15
15
|
const animatedProps = /* @__PURE__ */ new Set();
|
|
16
16
|
iterateXMLContent(tag.children, (node) => {
|
|
17
|
-
if (node.type === "tag") {
|
|
18
|
-
|
|
17
|
+
if (node.type === "tag") switch (node.tag) {
|
|
18
|
+
case svgSetTag:
|
|
19
|
+
case svgAnimationTag: {
|
|
19
20
|
const prop = node.attribs.attributeName;
|
|
20
21
|
if (typeof prop === "string") animatedProps.add(prop);
|
|
22
|
+
break;
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
case svgAnimateTransformTag:
|
|
25
|
+
animatedProps.add("transform");
|
|
26
|
+
break;
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
29
|
for (const prop in tag.attribs) if (!animatedProps.has(prop)) {
|
|
26
30
|
const value = tag.attribs[prop];
|
|
27
|
-
const converted = convertSVGPropertyToCSS(tag.tag, prop, value);
|
|
31
|
+
const converted = convertSVGPropertyToCSS(tag.tag, prop, value, supportLegacyBrowsers);
|
|
28
32
|
if (converted) {
|
|
29
33
|
const [propName, propValue] = converted;
|
|
30
34
|
result.props.push(propName);
|
package/lib/svg-css/root.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CSSRules } from "../css/types.js";
|
|
2
2
|
import { ParsedXMLTagElement } from "../xml/types.js";
|
|
3
|
+
import { BaseConvertSVGContentOptions } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Convert SVG tags tree to SVG+CSS
|
|
5
6
|
*
|
|
6
7
|
* Returns used CSS class names with rules
|
|
7
8
|
*/
|
|
8
|
-
declare function convertSVGRootToCSS(root: ParsedXMLTagElement[],
|
|
9
|
+
declare function convertSVGRootToCSS(root: ParsedXMLTagElement[], options?: BaseConvertSVGContentOptions): Record<string, CSSRules>;
|
|
9
10
|
export { convertSVGRootToCSS };
|
package/lib/svg-css/root.js
CHANGED
|
@@ -8,11 +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,
|
|
11
|
+
function convertSVGRootToCSS(root, options = {}) {
|
|
12
12
|
const rules = Object.create(null);
|
|
13
|
+
const hashOptions = options.hashOptions || {};
|
|
14
|
+
const classNamePrefix = options.classNamePrefix || "";
|
|
13
15
|
iterateXMLContent(root, (node) => {
|
|
14
16
|
if (node.type === "tag") {
|
|
15
|
-
const props = extractSVGTagPropertiesForCSS(node);
|
|
17
|
+
const props = extractSVGTagPropertiesForCSS(node, options.legacy);
|
|
16
18
|
if (props) {
|
|
17
19
|
const className = createCSSClassName(props.rules, classNamePrefix, hashOptions);
|
|
18
20
|
toggleClassName(node.attribs, className, true);
|
package/lib/svg-css/types.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { CSSHashOptions, CSSKeyframes, CSSRules } from "../css/types.js";
|
|
2
2
|
import { StringifyXMLOptions } from "../xml/types.js";
|
|
3
3
|
/**
|
|
4
|
-
* Options for converting SVG
|
|
4
|
+
* Options for converting SVG tags to SVG+CSS
|
|
5
5
|
*/
|
|
6
|
-
interface
|
|
6
|
+
interface BaseConvertSVGContentOptions {
|
|
7
7
|
classNamePrefix?: string;
|
|
8
8
|
hashOptions?: CSSHashOptions;
|
|
9
|
+
legacy?: boolean;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for converting SVG content to SVG+CSS
|
|
13
|
+
*/
|
|
14
|
+
interface ConvertSVGContentOptions extends StringifyXMLOptions, BaseConvertSVGContentOptions {}
|
|
10
15
|
/**
|
|
11
16
|
* Result of converting SVG content to SVG+CSS
|
|
12
17
|
*/
|
|
@@ -15,4 +20,4 @@ interface ConvertedSVGContent {
|
|
|
15
20
|
classes?: Record<string, CSSRules>;
|
|
16
21
|
keyframes?: Record<string, CSSKeyframes>;
|
|
17
22
|
}
|
|
18
|
-
export { ConvertSVGContentOptions, ConvertedSVGContent };
|
|
23
|
+
export { BaseConvertSVGContentOptions, ConvertSVGContentOptions, ConvertedSVGContent };
|
package/lib/xml/stringify.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParsedXMLNode, StringifyXMLOptions } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Convert parsed XML content to string
|
|
4
4
|
*/
|
|
5
|
-
declare function stringifyXMLContent(root:
|
|
5
|
+
declare function stringifyXMLContent(root: ParsedXMLNode[], options?: StringifyXMLOptions): string | null;
|
|
6
6
|
export { stringifyXMLContent };
|
package/lib/xml/stringify.js
CHANGED
|
@@ -18,6 +18,10 @@ function stringifyXMLContent(root, options) {
|
|
|
18
18
|
const tabs = (length) => tab.repeat(length);
|
|
19
19
|
const nl = prettyPrint === false ? "" : "\n";
|
|
20
20
|
const add = (node, depth) => {
|
|
21
|
+
if (node.type !== "tag") {
|
|
22
|
+
output += node.content;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
21
25
|
output += tabs(depth) + "<" + node.tag;
|
|
22
26
|
for (const key in node.attribs) {
|
|
23
27
|
const value = node.attribs[key];
|
|
@@ -31,7 +35,7 @@ function stringifyXMLContent(root, options) {
|
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
if (!node.children.length) {
|
|
34
|
-
if (fullOptions.useSelfClosing) output += " />" + nl;
|
|
38
|
+
if (fullOptions.useSelfClosing) output += (prettyPrint ? " " : "") + "/>" + nl;
|
|
35
39
|
else output += "></" + node.tag + ">" + nl;
|
|
36
40
|
return true;
|
|
37
41
|
}
|
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": "1.0.
|
|
6
|
+
"version": "1.0.11",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|