@team-monolith/cds 1.78.0 → 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.
@@ -1,30 +1,33 @@
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 modifySVGElements(element) {
9
+ function modifySVGElementsRecursive(element) {
9
10
  let useUniqueId = false;
10
11
  const elementAttributes = element.openingElement.attributes;
11
- // uniqueId 적용
12
- const urlPattern = /(url\(#\w+)(\))/;
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 적용
21
- if (attr.value.value.match(urlPattern)) {
22
- attr.value.value = attr.value.value.replace(urlPattern, "$1_${uniqueId}$2");
22
+ // fill="url(#paint0_linear_4029_17033)" => fill="url(#paint0_linear_4029_17033_${uniqueId})"
23
+ if (attr.value.value.match(URL_PATTERN)) {
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 modifySVGElements(element) {
41
44
  });
42
45
  styleAttribute.value.expression.properties = Array.from(styleMap.values());
43
46
  }
44
- if (element.children.length > 0) {
45
- element.children.forEach(child => {
46
- useUniqueId = modifySVGElements(child) || useUniqueId;
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 }) => {
@@ -58,8 +59,7 @@ const template = (variables, { tpl }) => {
58
59
  // variables.jsx는 prop이 포함된 jsx 정보를 가지고 있기 때문에 원본 파일 경로에서 import 후 export 처리
59
60
  const _ = require("lodash");
60
61
  const originSvgFilePath = `./${_.kebabCase(originSvgFileName)}.svg`;
61
- /** svg파일의 하위 엘리먼트(재귀 호출)에 대한 전처리 작업 수행 */
62
- const useUniqueId = modifySVGElements(variables.jsx);
62
+ const useUniqueId = modifySVGElementsRecursive(variables.jsx);
63
63
  if (useUniqueId) {
64
64
  return tpl `
65
65
  import { uid } from "uid";
@@ -1,43 +1,44 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- const baseColor = "#363636";
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 modifySVGElements(element, uniqueIdSet) {
10
+ function modifySVGElementsRecursive(element) {
10
11
  let useUniqueId = false;
11
12
  const elementAttributes = element.openingElement.attributes;
12
- // uniqueId 적용
13
- const urlPattern = /(url\(#\w+)(\))/;
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 적용
22
- if (attr.value.value.match(urlPattern)) {
23
- attr.value.value = attr.value.value.replace(urlPattern, "$1_${uniqueId}$2");
23
+ // fill="url(#paint0_linear_4029_17033)" => fill="url(#paint0_linear_4029_17033_${uniqueId})"
24
+ if (attr.value.value.match(URL_PATTERN)) {
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
- // 단색 아이콘의 경우 #363636 컬러값 고정 (remixicon 컬러값 반영), 배경색의 경우 white 또는 foreground에서 수동 적용
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
- if (fillAttribute && fillAttribute.value.value === baseColor) {
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
- if (element.children.length > 0) {
37
- element.children.forEach(child => {
38
- useUniqueId = modifySVGElements(child) || useUniqueId;
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 }) => {
@@ -50,8 +51,7 @@ const template = (variables, { tpl }) => {
50
51
  // variables.jsx는 prop이 포함된 jsx 정보를 가지고 있기 때문에 원본 파일 경로에서 import 후 export 처리
51
52
  const _ = require("lodash");
52
53
  const originSvgFilePath = `./${_.kebabCase(originSvgFileName)}.svg`;
53
- /** svg파일의 하위 엘리먼트(재귀 호출)에 대한 전처리 작업 수행 */
54
- const useUniqueId = modifySVGElements(variables.jsx);
54
+ const useUniqueId = modifySVGElementsRecursive(variables.jsx);
55
55
  if (useUniqueId) {
56
56
  return tpl `
57
57
  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 ID_PATTERN = /("(\w+_\${uniqueId})")|("(url\(#\w+_\${uniqueId}\))")/g;
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(ID_PATTERN) !== null) {
16
+ if (content.match(UNIQUE_ID_PATTERN) !== null) {
17
17
  // uniqueId 템플릿 리터럴 replace 적용
18
- content = content.replaceAll(ID_PATTERN, (_, _idPattern, id, _urlPattern, url) => {
18
+ content = content.replaceAll(UNIQUE_ID_PATTERN, (_, _idPattern, id, _urlPattern, url) => {
19
19
  return `{\`${id || url}\`}`;
20
20
  });
21
21
  fs.writeFileSync(filePath, content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.78.0",
3
+ "version": "1.78.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,