@cyberalien/svg-utils 0.0.10 → 0.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.
Files changed (2) hide show
  1. package/lib/svg/ids.js +26 -1
  2. package/package.json +1 -1
package/lib/svg/ids.js CHANGED
@@ -94,7 +94,32 @@ function changeSVGIDs(root, callback) {
94
94
  const node = idNodes.get(id);
95
95
  const newNode = cloneObject(node);
96
96
  delete newNode.attribs.id;
97
- for (const usageItem of usage) if (usageItem.node === node && usageItem.id === id) delete newNode.attribs[usageItem.attrib];
97
+ for (const usageItem of usage) if (usageItem.node === node && usageItem.id === id) {
98
+ const attr = usageItem.attrib;
99
+ const value = newNode.attribs[attr];
100
+ if (value === id) newNode.attribs[attr] = "";
101
+ else {
102
+ const parts = value.split(id);
103
+ const newValue = [];
104
+ const total = parts.length;
105
+ for (let i = 0; i < total; i++) {
106
+ if (i > 0) {
107
+ newValue.push(parts[i - 1]);
108
+ if (parts[i - i].slice(-1) !== ";") {
109
+ newValue.push(id);
110
+ continue;
111
+ }
112
+ }
113
+ if (i < total - 1) {
114
+ if (parts[i].slice(0, 1) !== ".") {
115
+ newValue.push(parts[i]);
116
+ continue;
117
+ }
118
+ }
119
+ }
120
+ newNode.attribs[attr] = newValue.join("");
121
+ }
122
+ }
98
123
  const content = stringifyXMLContent([newNode]);
99
124
  if (!content) throw new Error(`Failed to stringify node with ID: ${id}`);
100
125
  const newID = callback(id, content, node.tag);
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.0.10",
6
+ "version": "0.0.11",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",