@team-monolith/cds 1.78.1 → 1.78.2
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.
|
@@ -9,22 +9,25 @@ const URL_PATTERN = /(url\(#\w+)(\))/;
|
|
|
9
9
|
function modifySVGElementsRecursive(element) {
|
|
10
10
|
let useUniqueId = false;
|
|
11
11
|
const elementAttributes = element.openingElement.attributes;
|
|
12
|
-
// uniqueId 적용
|
|
12
|
+
// svg 컴포넌트가 여러 번 렌더링되는 경우 같은 id로 인식되어 style 공유를 막기 위한 uniqueId 적용
|
|
13
13
|
elementAttributes.forEach(attr => {
|
|
14
14
|
if (attr.value.value) {
|
|
15
15
|
// id attribute에 uniqueId 적용
|
|
16
|
+
// id="paint0_linear_4029_17033" -> id="paint0_linear_4029_17033_${uniqueId}"
|
|
16
17
|
if (attr.name.name === 'id') {
|
|
17
18
|
attr.value.value = `${attr.value.value}_\${uniqueId}`;
|
|
18
19
|
useUniqueId = true;
|
|
19
20
|
}
|
|
20
21
|
// url 패턴에 매칭되는 attribute에 uniqueId 적용
|
|
22
|
+
// fill="url(#paint0_linear_4029_17033)" => fill="url(#paint0_linear_4029_17033_${uniqueId})"
|
|
21
23
|
if (attr.value.value.match(URL_PATTERN)) {
|
|
22
24
|
attr.value.value = attr.value.value.replace(URL_PATTERN, "$1_${uniqueId}$2");
|
|
23
25
|
useUniqueId = true;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
|
-
// 중복 스타일 제거
|
|
29
|
+
// 중복 스타일 제거 (객체 리터럴의 중복 속성 타입 오류 방지)
|
|
30
|
+
// style="fill:#363636;fill:color(display-p3 0.2118 0.2118 0.2118);" => style="fill:color(display-p3 0.2118 0.2118 0.2118);"
|
|
28
31
|
const styleAttribute = elementAttributes.find(attr => attr.name.name === 'style');
|
|
29
32
|
if (styleAttribute) {
|
|
30
33
|
const styleMap = new Map();
|
|
@@ -41,11 +44,9 @@ function modifySVGElementsRecursive(element) {
|
|
|
41
44
|
});
|
|
42
45
|
styleAttribute.value.expression.properties = Array.from(styleMap.values());
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
}
|
|
47
|
+
element.children.forEach(child => {
|
|
48
|
+
useUniqueId = modifySVGElementsRecursive(child) || useUniqueId;
|
|
49
|
+
});
|
|
49
50
|
return useUniqueId;
|
|
50
51
|
}
|
|
51
52
|
const template = (variables, { tpl }) => {
|
|
@@ -7,37 +7,38 @@ const URL_PATTERN = /(url\(#\w+)(\))/;
|
|
|
7
7
|
* svg의 하위 엘리먼트에 대한 재귀 호출
|
|
8
8
|
* @returns {boolean} useUniqueId
|
|
9
9
|
*/
|
|
10
|
-
function modifySVGElementsRecursive(element
|
|
10
|
+
function modifySVGElementsRecursive(element) {
|
|
11
11
|
let useUniqueId = false;
|
|
12
12
|
const elementAttributes = element.openingElement.attributes;
|
|
13
|
-
// uniqueId 적용
|
|
13
|
+
// svg 컴포넌트가 여러 번 렌더링되는 경우 같은 id로 인식되어 style 공유를 막기 위한 uniqueId 적용
|
|
14
14
|
elementAttributes.forEach(attr => {
|
|
15
15
|
if (attr.value.value) {
|
|
16
16
|
// id attribute에 uniqueId 적용
|
|
17
|
+
// id="paint0_linear_4029_17033" -> id="paint0_linear_4029_17033_${uniqueId}"
|
|
17
18
|
if (attr.name.name === 'id') {
|
|
18
19
|
attr.value.value = `${attr.value.value}_\${uniqueId}`;
|
|
19
20
|
useUniqueId = true;
|
|
20
21
|
}
|
|
21
22
|
// url 패턴에 매칭되는 attribute에 uniqueId 적용
|
|
23
|
+
// fill="url(#paint0_linear_4029_17033)" => fill="url(#paint0_linear_4029_17033_${uniqueId})"
|
|
22
24
|
if (attr.value.value.match(URL_PATTERN)) {
|
|
23
25
|
attr.value.value = attr.value.value.replace(URL_PATTERN, "$1_${uniqueId}$2");
|
|
24
26
|
useUniqueId = true;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
|
-
// currentColor 변환
|
|
29
|
-
//
|
|
30
|
+
// 단색 컬러 #363636(remixicon 컬러값)에 대해서 color prop을 적용하기 위한 currentColor로 변환
|
|
31
|
+
// fill="#363636" => fill="currentColor"
|
|
32
|
+
// 배경색인 white 또는 foreground값은 유지
|
|
30
33
|
const fillAttribute = elementAttributes.find(attr => attr.name.name === 'fill');
|
|
31
34
|
if (fillAttribute && fillAttribute.value.value === BASE_COLOR) {
|
|
32
35
|
fillAttribute.value.value = 'currentColor';
|
|
33
36
|
}
|
|
34
37
|
// color prop이 있는 단색 svg의 경우 스타일 속성 제거
|
|
35
38
|
element.openingElement.attributes = elementAttributes.filter(attr => attr.name.name !== 'style');
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
}
|
|
39
|
+
element.children.forEach(child => {
|
|
40
|
+
useUniqueId = modifySVGElementsRecursive(child) || useUniqueId;
|
|
41
|
+
});
|
|
41
42
|
return useUniqueId;
|
|
42
43
|
}
|
|
43
44
|
const template = (variables, { tpl }) => {
|