@team-monolith/cds 1.78.0 → 1.78.1
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
const URL_PATTERN = /(url\(#\w+)(\))/;
|
|
3
4
|
/**
|
|
4
5
|
* svg에서 uniqueId 적용 및 중복 스타일 제거하는 함수
|
|
5
6
|
* svg의 하위 엘리먼트에 대한 재귀 호출
|
|
6
7
|
* @returns {boolean} useUniqueId
|
|
7
8
|
*/
|
|
8
|
-
function
|
|
9
|
+
function modifySVGElementsRecursive(element) {
|
|
9
10
|
let useUniqueId = false;
|
|
10
11
|
const elementAttributes = element.openingElement.attributes;
|
|
11
12
|
// uniqueId 적용
|
|
12
|
-
const urlPattern = /(url\(#\w+)(\))/;
|
|
13
13
|
elementAttributes.forEach(attr => {
|
|
14
14
|
if (attr.value.value) {
|
|
15
15
|
// id attribute에 uniqueId 적용
|
|
@@ -18,8 +18,8 @@ function modifySVGElements(element) {
|
|
|
18
18
|
useUniqueId = true;
|
|
19
19
|
}
|
|
20
20
|
// url 패턴에 매칭되는 attribute에 uniqueId 적용
|
|
21
|
-
if (attr.value.value.match(
|
|
22
|
-
attr.value.value = attr.value.value.replace(
|
|
21
|
+
if (attr.value.value.match(URL_PATTERN)) {
|
|
22
|
+
attr.value.value = attr.value.value.replace(URL_PATTERN, "$1_${uniqueId}$2");
|
|
23
23
|
useUniqueId = true;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -43,7 +43,7 @@ function modifySVGElements(element) {
|
|
|
43
43
|
}
|
|
44
44
|
if (element.children.length > 0) {
|
|
45
45
|
element.children.forEach(child => {
|
|
46
|
-
useUniqueId =
|
|
46
|
+
useUniqueId = modifySVGElementsRecursive(child) || useUniqueId;
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
return useUniqueId;
|
|
@@ -58,8 +58,7 @@ const template = (variables, { tpl }) => {
|
|
|
58
58
|
// variables.jsx는 prop이 포함된 jsx 정보를 가지고 있기 때문에 원본 파일 경로에서 import 후 export 처리
|
|
59
59
|
const _ = require("lodash");
|
|
60
60
|
const originSvgFilePath = `./${_.kebabCase(originSvgFileName)}.svg`;
|
|
61
|
-
|
|
62
|
-
const useUniqueId = modifySVGElements(variables.jsx);
|
|
61
|
+
const useUniqueId = modifySVGElementsRecursive(variables.jsx);
|
|
63
62
|
if (useUniqueId) {
|
|
64
63
|
return tpl `
|
|
65
64
|
import { uid } from "uid";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
const
|
|
3
|
+
const BASE_COLOR = "#363636";
|
|
4
|
+
const URL_PATTERN = /(url\(#\w+)(\))/;
|
|
4
5
|
/**
|
|
5
6
|
* svg에서 uniqueId 적용 및 스타일 속성 제거하는 함수
|
|
6
7
|
* svg의 하위 엘리먼트에 대한 재귀 호출
|
|
7
8
|
* @returns {boolean} useUniqueId
|
|
8
9
|
*/
|
|
9
|
-
function
|
|
10
|
+
function modifySVGElementsRecursive(element, uniqueIdSet) {
|
|
10
11
|
let useUniqueId = false;
|
|
11
12
|
const elementAttributes = element.openingElement.attributes;
|
|
12
13
|
// uniqueId 적용
|
|
13
|
-
const urlPattern = /(url\(#\w+)(\))/;
|
|
14
14
|
elementAttributes.forEach(attr => {
|
|
15
15
|
if (attr.value.value) {
|
|
16
16
|
// id attribute에 uniqueId 적용
|
|
@@ -19,8 +19,8 @@ function modifySVGElements(element, uniqueIdSet) {
|
|
|
19
19
|
useUniqueId = true;
|
|
20
20
|
}
|
|
21
21
|
// url 패턴에 매칭되는 attribute에 uniqueId 적용
|
|
22
|
-
if (attr.value.value.match(
|
|
23
|
-
attr.value.value = attr.value.value.replace(
|
|
22
|
+
if (attr.value.value.match(URL_PATTERN)) {
|
|
23
|
+
attr.value.value = attr.value.value.replace(URL_PATTERN, "$1_${uniqueId}$2");
|
|
24
24
|
useUniqueId = true;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -28,14 +28,14 @@ function modifySVGElements(element, uniqueIdSet) {
|
|
|
28
28
|
// currentColor 변환
|
|
29
29
|
// 단색 아이콘의 경우 #363636 컬러값 고정 (remixicon 컬러값 반영), 배경색의 경우 white 또는 foreground에서 수동 적용
|
|
30
30
|
const fillAttribute = elementAttributes.find(attr => attr.name.name === 'fill');
|
|
31
|
-
if (fillAttribute && fillAttribute.value.value ===
|
|
31
|
+
if (fillAttribute && fillAttribute.value.value === BASE_COLOR) {
|
|
32
32
|
fillAttribute.value.value = 'currentColor';
|
|
33
33
|
}
|
|
34
34
|
// color prop이 있는 단색 svg의 경우 스타일 속성 제거
|
|
35
35
|
element.openingElement.attributes = elementAttributes.filter(attr => attr.name.name !== 'style');
|
|
36
36
|
if (element.children.length > 0) {
|
|
37
37
|
element.children.forEach(child => {
|
|
38
|
-
useUniqueId =
|
|
38
|
+
useUniqueId = modifySVGElementsRecursive(child) || useUniqueId;
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
return useUniqueId;
|
|
@@ -50,8 +50,7 @@ const template = (variables, { tpl }) => {
|
|
|
50
50
|
// variables.jsx는 prop이 포함된 jsx 정보를 가지고 있기 때문에 원본 파일 경로에서 import 후 export 처리
|
|
51
51
|
const _ = require("lodash");
|
|
52
52
|
const originSvgFilePath = `./${_.kebabCase(originSvgFileName)}.svg`;
|
|
53
|
-
|
|
54
|
-
const useUniqueId = modifySVGElements(variables.jsx);
|
|
53
|
+
const useUniqueId = modifySVGElementsRecursive(variables.jsx);
|
|
55
54
|
if (useUniqueId) {
|
|
56
55
|
return tpl `
|
|
57
56
|
import { uid } from "uid";
|
|
@@ -3,7 +3,7 @@ import path from "path";
|
|
|
3
3
|
const DEFAILT_DIR_PATH = "src/cds/icons/custom/default";
|
|
4
4
|
const COLORED_DIR_PATH = "src/cds/icons/custom/colored";
|
|
5
5
|
// uniqueId 치환은 template 내부 로직에서 처리
|
|
6
|
-
const
|
|
6
|
+
const UNIQUE_ID_PATTERN = /("(\w+_\${uniqueId})")|("(url\(#\w+_\${uniqueId}\))")/g;
|
|
7
7
|
/** 경로 내 모든 tsx 파일에서 uniqueId를 replace하는 함수 */
|
|
8
8
|
function replaceUniqueIds(dirPath) {
|
|
9
9
|
const files = fs.readdirSync(dirPath);
|
|
@@ -13,9 +13,9 @@ function replaceUniqueIds(dirPath) {
|
|
|
13
13
|
const stat = fs.statSync(filePath);
|
|
14
14
|
if (stat.isFile()) {
|
|
15
15
|
let content = fs.readFileSync(filePath).toString();
|
|
16
|
-
if (content.match(
|
|
16
|
+
if (content.match(UNIQUE_ID_PATTERN) !== null) {
|
|
17
17
|
// uniqueId 템플릿 리터럴 replace 적용
|
|
18
|
-
content = content.replaceAll(
|
|
18
|
+
content = content.replaceAll(UNIQUE_ID_PATTERN, (_, _idPattern, id, _urlPattern, url) => {
|
|
19
19
|
return `{\`${id || url}\`}`;
|
|
20
20
|
});
|
|
21
21
|
fs.writeFileSync(filePath, content);
|