@carbon/icon-helpers 10.73.0 → 10.74.0-rc.0

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 (4) hide show
  1. package/es/index.js +75 -160
  2. package/lib/index.js +76 -161
  3. package/package.json +4 -4
  4. package/umd/index.js +98 -183
package/es/index.js CHANGED
@@ -1,177 +1,92 @@
1
- function _defineProperty(e, r, t) {
2
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
3
- value: t,
4
- enumerable: true,
5
- configurable: true,
6
- writable: true
7
- }) : e[r] = t, e;
8
- }
9
- function ownKeys(e, r) {
10
- var t = Object.keys(e);
11
- if (Object.getOwnPropertySymbols) {
12
- var o = Object.getOwnPropertySymbols(e);
13
- r && (o = o.filter(function (r) {
14
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
15
- })), t.push.apply(t, o);
16
- }
17
- return t;
18
- }
19
- function _objectSpread2(e) {
20
- for (var r = 1; r < arguments.length; r++) {
21
- var t = null != arguments[r] ? arguments[r] : {};
22
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
23
- _defineProperty(e, r, t[r]);
24
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
25
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
26
- });
27
- }
28
- return e;
29
- }
30
- function _objectWithoutProperties(e, t) {
31
- if (null == e) return {};
32
- var o,
33
- r,
34
- i = _objectWithoutPropertiesLoose(e, t);
35
- if (Object.getOwnPropertySymbols) {
36
- var n = Object.getOwnPropertySymbols(e);
37
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
38
- }
39
- return i;
40
- }
41
- function _objectWithoutPropertiesLoose(r, e) {
42
- if (null == r) return {};
43
- var t = {};
44
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
45
- if (-1 !== e.indexOf(n)) continue;
46
- t[n] = r[n];
47
- }
48
- return t;
49
- }
50
- function _toPrimitive(t, r) {
51
- if ("object" != typeof t || !t) return t;
52
- var e = t[Symbol.toPrimitive];
53
- if (void 0 !== e) {
54
- var i = e.call(t, r);
55
- if ("object" != typeof i) return i;
56
- throw new TypeError("@@toPrimitive must return a primitive value.");
57
- }
58
- return ("string" === r ? String : Number)(t);
59
- }
60
- function _toPropertyKey(t) {
61
- var i = _toPrimitive(t, "string");
62
- return "symbol" == typeof i ? i : i + "";
63
- }
64
-
65
- var _excluded = ["width", "height", "viewBox"],
66
- _excluded2 = ["tabindex"];
1
+ //#region src/getAttributes.ts
67
2
  /**
68
- * Copyright IBM Corp. 2018, 2026
69
- *
70
- * This source code is licensed under the Apache-2.0 license found in the
71
- * LICENSE file in the root directory of this source tree.
72
- */
73
-
74
- var defaultAttributes = {
75
- // Reference:
76
- // https://github.com/IBM/carbon-components-react/issues/1392
77
- // https://github.com/PolymerElements/iron-iconset-svg/pull/47
78
- // `focusable` is a string attribute which is why we do not use a boolean here
79
- focusable: 'false',
80
- preserveAspectRatio: 'xMidYMid meet'
3
+ * Copyright IBM Corp. 2018, 2026
4
+ *
5
+ * This source code is licensed under the Apache-2.0 license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ const defaultAttributes = {
9
+ focusable: "false",
10
+ preserveAspectRatio: "xMidYMid meet"
81
11
  };
82
-
83
12
  /**
84
- * Get supplementary HTML attributes for a given <svg> element based on existing
85
- * attributes.
86
- */
87
- function getAttributes() {
88
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
89
- width = _ref.width,
90
- height = _ref.height,
91
- _ref$viewBox = _ref.viewBox,
92
- viewBox = _ref$viewBox === void 0 ? "0 0 ".concat(width, " ").concat(height) : _ref$viewBox,
93
- attributes = _objectWithoutProperties(_ref, _excluded);
94
- var tabindex = attributes.tabindex,
95
- rest = _objectWithoutProperties(attributes, _excluded2);
96
- var iconAttributes = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultAttributes), rest), {}, {
97
- width: width,
98
- height: height,
99
- viewBox: viewBox
100
- });
101
- if (iconAttributes['aria-label'] || iconAttributes['aria-labelledby']) {
102
- iconAttributes.role = 'img';
103
-
104
- // Reference:
105
- // https://allyjs.io/tutorials/focusing-in-svg.html
106
- if (tabindex !== undefined && tabindex !== null) {
107
- iconAttributes.focusable = 'true';
108
- iconAttributes.tabindex = tabindex;
109
- }
110
- } else {
111
- iconAttributes['aria-hidden'] = true;
112
- }
113
- return iconAttributes;
13
+ * Get supplementary HTML attributes for a given <svg> element based on existing
14
+ * attributes.
15
+ */
16
+ function getAttributes({ width, height, viewBox = `0 0 ${width} ${height}`, ...attributes } = {}) {
17
+ const { tabindex, ...rest } = attributes;
18
+ const iconAttributes = {
19
+ ...defaultAttributes,
20
+ ...rest,
21
+ width,
22
+ height,
23
+ viewBox
24
+ };
25
+ if (iconAttributes["aria-label"] || iconAttributes["aria-labelledby"]) {
26
+ iconAttributes.role = "img";
27
+ if (tabindex !== void 0 && tabindex !== null) {
28
+ iconAttributes.focusable = "true";
29
+ iconAttributes.tabindex = tabindex;
30
+ }
31
+ } else iconAttributes["aria-hidden"] = true;
32
+ return iconAttributes;
114
33
  }
115
34
 
35
+ //#endregion
36
+ //#region src/toString.ts
116
37
  /**
117
- * Copyright IBM Corp. 2018, 2024
118
- *
119
- * This source code is licensed under the Apache-2.0 license found in the
120
- * LICENSE file in the root directory of this source tree.
121
- */
122
-
38
+ * Copyright IBM Corp. 2018, 2024
39
+ *
40
+ * This source code is licensed under the Apache-2.0 license found in the
41
+ * LICENSE file in the root directory of this source tree.
42
+ */
123
43
  /**
124
- * Convert an icon descriptor to a String
125
- */
44
+ * Convert an icon descriptor to a String
45
+ */
126
46
  function toString(descriptor) {
127
- var _descriptor$elem = descriptor.elem,
128
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
129
- _descriptor$attrs = descriptor.attrs,
130
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
131
- _descriptor$content = descriptor.content,
132
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
133
- var children = content.map(toString).join('');
134
- if (elem !== 'svg') {
135
- return "<".concat(elem, " ").concat(formatAttributes(attrs), ">").concat(children, "</").concat(elem, ">");
136
- }
137
- return "<".concat(elem, " ").concat(formatAttributes(getAttributes(attrs)), ">").concat(children, "</").concat(elem, ">");
47
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
48
+ const children = content.map(toString).join("");
49
+ if (elem !== "svg") return `<${elem} ${formatAttributes(attrs)}>${children}</${elem}>`;
50
+ return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}</${elem}>`;
138
51
  }
139
52
  function formatAttributes(attrs) {
140
- return Object.keys(attrs).reduce(function (acc, key, index) {
141
- var attribute = "".concat(key, "=\"").concat(attrs[key], "\"");
142
- if (index === 0) {
143
- return attribute;
144
- }
145
- return acc + ' ' + attribute;
146
- }, '');
53
+ return Object.keys(attrs).reduce((acc, key, index) => {
54
+ const attribute = `${key}="${attrs[key]}"`;
55
+ if (index === 0) return attribute;
56
+ return acc + " " + attribute;
57
+ }, "");
147
58
  }
148
59
 
60
+ //#endregion
61
+ //#region src/toSVG.ts
149
62
  /**
150
- * Copyright IBM Corp. 2018, 2024
151
- *
152
- * This source code is licensed under the Apache-2.0 license found in the
153
- * LICENSE file in the root directory of this source tree.
154
- */
155
-
63
+ * Copyright IBM Corp. 2018, 2024
64
+ *
65
+ * This source code is licensed under the Apache-2.0 license found in the
66
+ * LICENSE file in the root directory of this source tree.
67
+ */
156
68
  /**
157
- * Convert an icon descriptor to a DOM node.
158
- */
69
+ * Convert an icon descriptor to a DOM node.
70
+ */
159
71
  function toSVG(descriptor) {
160
- var _descriptor$elem = descriptor.elem,
161
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
162
- _descriptor$attrs = descriptor.attrs,
163
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
164
- _descriptor$content = descriptor.content,
165
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
166
- var node = document.createElementNS('http://www.w3.org/2000/svg', elem);
167
- var attributes = elem !== 'svg' ? attrs : getAttributes(attrs);
168
- Object.keys(attributes).forEach(function (key) {
169
- node.setAttribute(key, attrs[key]);
170
- });
171
- for (var i = 0; i < content.length; i++) {
172
- node.appendChild(toSVG(content[i]));
173
- }
174
- return node;
72
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
73
+ const node = document.createElementNS("http://www.w3.org/2000/svg", elem);
74
+ const attributes = elem !== "svg" ? attrs : getAttributes(attrs);
75
+ Object.keys(attributes).forEach((key) => {
76
+ node.setAttribute(key, attrs[key]);
77
+ });
78
+ for (let i = 0; i < content.length; i++) node.appendChild(toSVG(content[i]));
79
+ return node;
175
80
  }
176
81
 
177
- export { defaultAttributes, formatAttributes, getAttributes, toSVG, toString };
82
+ //#endregion
83
+ //#region src/index.ts
84
+ /**
85
+ * Copyright IBM Corp. 2018, 2023
86
+ *
87
+ * This source code is licensed under the Apache-2.0 license found in the
88
+ * LICENSE file in the root directory of this source tree.
89
+ */
90
+
91
+ //#endregion
92
+ export { defaultAttributes, formatAttributes, getAttributes, toSVG, toString };
package/lib/index.js CHANGED
@@ -1,183 +1,98 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- function _defineProperty(e, r, t) {
4
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
5
- value: t,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- }) : e[r] = t, e;
10
- }
11
- function ownKeys(e, r) {
12
- var t = Object.keys(e);
13
- if (Object.getOwnPropertySymbols) {
14
- var o = Object.getOwnPropertySymbols(e);
15
- r && (o = o.filter(function (r) {
16
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
17
- })), t.push.apply(t, o);
18
- }
19
- return t;
20
- }
21
- function _objectSpread2(e) {
22
- for (var r = 1; r < arguments.length; r++) {
23
- var t = null != arguments[r] ? arguments[r] : {};
24
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
25
- _defineProperty(e, r, t[r]);
26
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
27
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
28
- });
29
- }
30
- return e;
31
- }
32
- function _objectWithoutProperties(e, t) {
33
- if (null == e) return {};
34
- var o,
35
- r,
36
- i = _objectWithoutPropertiesLoose(e, t);
37
- if (Object.getOwnPropertySymbols) {
38
- var n = Object.getOwnPropertySymbols(e);
39
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
40
- }
41
- return i;
42
- }
43
- function _objectWithoutPropertiesLoose(r, e) {
44
- if (null == r) return {};
45
- var t = {};
46
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
47
- if (-1 !== e.indexOf(n)) continue;
48
- t[n] = r[n];
49
- }
50
- return t;
51
- }
52
- function _toPrimitive(t, r) {
53
- if ("object" != typeof t || !t) return t;
54
- var e = t[Symbol.toPrimitive];
55
- if (void 0 !== e) {
56
- var i = e.call(t, r);
57
- if ("object" != typeof i) return i;
58
- throw new TypeError("@@toPrimitive must return a primitive value.");
59
- }
60
- return ("string" === r ? String : Number)(t);
61
- }
62
- function _toPropertyKey(t) {
63
- var i = _toPrimitive(t, "string");
64
- return "symbol" == typeof i ? i : i + "";
65
- }
66
-
67
- var _excluded = ["width", "height", "viewBox"],
68
- _excluded2 = ["tabindex"];
3
+ //#region src/getAttributes.ts
69
4
  /**
70
- * Copyright IBM Corp. 2018, 2026
71
- *
72
- * This source code is licensed under the Apache-2.0 license found in the
73
- * LICENSE file in the root directory of this source tree.
74
- */
75
-
76
- var defaultAttributes = {
77
- // Reference:
78
- // https://github.com/IBM/carbon-components-react/issues/1392
79
- // https://github.com/PolymerElements/iron-iconset-svg/pull/47
80
- // `focusable` is a string attribute which is why we do not use a boolean here
81
- focusable: 'false',
82
- preserveAspectRatio: 'xMidYMid meet'
5
+ * Copyright IBM Corp. 2018, 2026
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ const defaultAttributes = {
11
+ focusable: "false",
12
+ preserveAspectRatio: "xMidYMid meet"
83
13
  };
84
-
85
14
  /**
86
- * Get supplementary HTML attributes for a given <svg> element based on existing
87
- * attributes.
88
- */
89
- function getAttributes() {
90
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
91
- width = _ref.width,
92
- height = _ref.height,
93
- _ref$viewBox = _ref.viewBox,
94
- viewBox = _ref$viewBox === void 0 ? "0 0 ".concat(width, " ").concat(height) : _ref$viewBox,
95
- attributes = _objectWithoutProperties(_ref, _excluded);
96
- var tabindex = attributes.tabindex,
97
- rest = _objectWithoutProperties(attributes, _excluded2);
98
- var iconAttributes = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultAttributes), rest), {}, {
99
- width: width,
100
- height: height,
101
- viewBox: viewBox
102
- });
103
- if (iconAttributes['aria-label'] || iconAttributes['aria-labelledby']) {
104
- iconAttributes.role = 'img';
105
-
106
- // Reference:
107
- // https://allyjs.io/tutorials/focusing-in-svg.html
108
- if (tabindex !== undefined && tabindex !== null) {
109
- iconAttributes.focusable = 'true';
110
- iconAttributes.tabindex = tabindex;
111
- }
112
- } else {
113
- iconAttributes['aria-hidden'] = true;
114
- }
115
- return iconAttributes;
15
+ * Get supplementary HTML attributes for a given <svg> element based on existing
16
+ * attributes.
17
+ */
18
+ function getAttributes({ width, height, viewBox = `0 0 ${width} ${height}`, ...attributes } = {}) {
19
+ const { tabindex, ...rest } = attributes;
20
+ const iconAttributes = {
21
+ ...defaultAttributes,
22
+ ...rest,
23
+ width,
24
+ height,
25
+ viewBox
26
+ };
27
+ if (iconAttributes["aria-label"] || iconAttributes["aria-labelledby"]) {
28
+ iconAttributes.role = "img";
29
+ if (tabindex !== void 0 && tabindex !== null) {
30
+ iconAttributes.focusable = "true";
31
+ iconAttributes.tabindex = tabindex;
32
+ }
33
+ } else iconAttributes["aria-hidden"] = true;
34
+ return iconAttributes;
116
35
  }
117
36
 
37
+ //#endregion
38
+ //#region src/toString.ts
118
39
  /**
119
- * Copyright IBM Corp. 2018, 2024
120
- *
121
- * This source code is licensed under the Apache-2.0 license found in the
122
- * LICENSE file in the root directory of this source tree.
123
- */
124
-
40
+ * Copyright IBM Corp. 2018, 2024
41
+ *
42
+ * This source code is licensed under the Apache-2.0 license found in the
43
+ * LICENSE file in the root directory of this source tree.
44
+ */
125
45
  /**
126
- * Convert an icon descriptor to a String
127
- */
46
+ * Convert an icon descriptor to a String
47
+ */
128
48
  function toString(descriptor) {
129
- var _descriptor$elem = descriptor.elem,
130
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
131
- _descriptor$attrs = descriptor.attrs,
132
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
133
- _descriptor$content = descriptor.content,
134
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
135
- var children = content.map(toString).join('');
136
- if (elem !== 'svg') {
137
- return "<".concat(elem, " ").concat(formatAttributes(attrs), ">").concat(children, "</").concat(elem, ">");
138
- }
139
- return "<".concat(elem, " ").concat(formatAttributes(getAttributes(attrs)), ">").concat(children, "</").concat(elem, ">");
49
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
50
+ const children = content.map(toString).join("");
51
+ if (elem !== "svg") return `<${elem} ${formatAttributes(attrs)}>${children}</${elem}>`;
52
+ return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}</${elem}>`;
140
53
  }
141
54
  function formatAttributes(attrs) {
142
- return Object.keys(attrs).reduce(function (acc, key, index) {
143
- var attribute = "".concat(key, "=\"").concat(attrs[key], "\"");
144
- if (index === 0) {
145
- return attribute;
146
- }
147
- return acc + ' ' + attribute;
148
- }, '');
55
+ return Object.keys(attrs).reduce((acc, key, index) => {
56
+ const attribute = `${key}="${attrs[key]}"`;
57
+ if (index === 0) return attribute;
58
+ return acc + " " + attribute;
59
+ }, "");
149
60
  }
150
61
 
62
+ //#endregion
63
+ //#region src/toSVG.ts
151
64
  /**
152
- * Copyright IBM Corp. 2018, 2024
153
- *
154
- * This source code is licensed under the Apache-2.0 license found in the
155
- * LICENSE file in the root directory of this source tree.
156
- */
157
-
65
+ * Copyright IBM Corp. 2018, 2024
66
+ *
67
+ * This source code is licensed under the Apache-2.0 license found in the
68
+ * LICENSE file in the root directory of this source tree.
69
+ */
158
70
  /**
159
- * Convert an icon descriptor to a DOM node.
160
- */
71
+ * Convert an icon descriptor to a DOM node.
72
+ */
161
73
  function toSVG(descriptor) {
162
- var _descriptor$elem = descriptor.elem,
163
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
164
- _descriptor$attrs = descriptor.attrs,
165
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
166
- _descriptor$content = descriptor.content,
167
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
168
- var node = document.createElementNS('http://www.w3.org/2000/svg', elem);
169
- var attributes = elem !== 'svg' ? attrs : getAttributes(attrs);
170
- Object.keys(attributes).forEach(function (key) {
171
- node.setAttribute(key, attrs[key]);
172
- });
173
- for (var i = 0; i < content.length; i++) {
174
- node.appendChild(toSVG(content[i]));
175
- }
176
- return node;
74
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
75
+ const node = document.createElementNS("http://www.w3.org/2000/svg", elem);
76
+ const attributes = elem !== "svg" ? attrs : getAttributes(attrs);
77
+ Object.keys(attributes).forEach((key) => {
78
+ node.setAttribute(key, attrs[key]);
79
+ });
80
+ for (let i = 0; i < content.length; i++) node.appendChild(toSVG(content[i]));
81
+ return node;
177
82
  }
178
83
 
84
+ //#endregion
85
+ //#region src/index.ts
86
+ /**
87
+ * Copyright IBM Corp. 2018, 2023
88
+ *
89
+ * This source code is licensed under the Apache-2.0 license found in the
90
+ * LICENSE file in the root directory of this source tree.
91
+ */
92
+
93
+ //#endregion
179
94
  exports.defaultAttributes = defaultAttributes;
180
95
  exports.formatAttributes = formatAttributes;
181
96
  exports.getAttributes = getAttributes;
182
97
  exports.toSVG = toSVG;
183
- exports.toString = toString;
98
+ exports.toString = toString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/icon-helpers",
3
3
  "description": "Helpers used alongside icons for digital and software products using the Carbon Design System",
4
- "version": "10.73.0",
4
+ "version": "10.74.0-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -32,12 +32,12 @@
32
32
  "provenance": true
33
33
  },
34
34
  "scripts": {
35
- "build": "yarn clean && carbon-cli bundle src/index.ts --name CarbonIconHelpers",
35
+ "build": "yarn clean && carbon-cli bundle src/index.ts --name CarbonIconHelpers --dts",
36
36
  "clean": "rimraf es lib umd",
37
37
  "postinstall": "ibmtelemetry --config=telemetry.yml"
38
38
  },
39
39
  "devDependencies": {
40
- "@carbon/cli": "^11.41.0",
40
+ "@carbon/cli": "^11.42.0-rc.0",
41
41
  "rimraf": "^6.0.1",
42
42
  "typescript-config-carbon": "^0.9.0"
43
43
  },
@@ -45,5 +45,5 @@
45
45
  "dependencies": {
46
46
  "@ibm/telemetry-js": "^1.5.0"
47
47
  },
48
- "gitHead": "4f48ac426be7302a57460b1c81d74dd5d6071ad6"
48
+ "gitHead": "d901529b78f5b70b49309ad45604fa5ec99a2e69"
49
49
  }
package/umd/index.js CHANGED
@@ -1,189 +1,104 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
1
+ (function(global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CarbonIconHelpers = {}));
5
- })(this, (function (exports) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CarbonIconHelpers = {})));
5
+ })(this, function(exports) {
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6
7
 
7
- function _defineProperty(e, r, t) {
8
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
9
- value: t,
10
- enumerable: true,
11
- configurable: true,
12
- writable: true
13
- }) : e[r] = t, e;
14
- }
15
- function ownKeys(e, r) {
16
- var t = Object.keys(e);
17
- if (Object.getOwnPropertySymbols) {
18
- var o = Object.getOwnPropertySymbols(e);
19
- r && (o = o.filter(function (r) {
20
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
21
- })), t.push.apply(t, o);
22
- }
23
- return t;
24
- }
25
- function _objectSpread2(e) {
26
- for (var r = 1; r < arguments.length; r++) {
27
- var t = null != arguments[r] ? arguments[r] : {};
28
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
29
- _defineProperty(e, r, t[r]);
30
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
31
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
32
- });
33
- }
34
- return e;
35
- }
36
- function _objectWithoutProperties(e, t) {
37
- if (null == e) return {};
38
- var o,
39
- r,
40
- i = _objectWithoutPropertiesLoose(e, t);
41
- if (Object.getOwnPropertySymbols) {
42
- var n = Object.getOwnPropertySymbols(e);
43
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
44
- }
45
- return i;
46
- }
47
- function _objectWithoutPropertiesLoose(r, e) {
48
- if (null == r) return {};
49
- var t = {};
50
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
51
- if (-1 !== e.indexOf(n)) continue;
52
- t[n] = r[n];
53
- }
54
- return t;
55
- }
56
- function _toPrimitive(t, r) {
57
- if ("object" != typeof t || !t) return t;
58
- var e = t[Symbol.toPrimitive];
59
- if (void 0 !== e) {
60
- var i = e.call(t, r);
61
- if ("object" != typeof i) return i;
62
- throw new TypeError("@@toPrimitive must return a primitive value.");
63
- }
64
- return ("string" === r ? String : Number)(t);
65
- }
66
- function _toPropertyKey(t) {
67
- var i = _toPrimitive(t, "string");
68
- return "symbol" == typeof i ? i : i + "";
69
- }
8
+ //#region src/getAttributes.ts
9
+ /**
10
+ * Copyright IBM Corp. 2018, 2026
11
+ *
12
+ * This source code is licensed under the Apache-2.0 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ const defaultAttributes = {
16
+ focusable: "false",
17
+ preserveAspectRatio: "xMidYMid meet"
18
+ };
19
+ /**
20
+ * Get supplementary HTML attributes for a given <svg> element based on existing
21
+ * attributes.
22
+ */
23
+ function getAttributes({ width, height, viewBox = `0 0 ${width} ${height}`, ...attributes } = {}) {
24
+ const { tabindex, ...rest } = attributes;
25
+ const iconAttributes = {
26
+ ...defaultAttributes,
27
+ ...rest,
28
+ width,
29
+ height,
30
+ viewBox
31
+ };
32
+ if (iconAttributes["aria-label"] || iconAttributes["aria-labelledby"]) {
33
+ iconAttributes.role = "img";
34
+ if (tabindex !== void 0 && tabindex !== null) {
35
+ iconAttributes.focusable = "true";
36
+ iconAttributes.tabindex = tabindex;
37
+ }
38
+ } else iconAttributes["aria-hidden"] = true;
39
+ return iconAttributes;
40
+ }
70
41
 
71
- var _excluded = ["width", "height", "viewBox"],
72
- _excluded2 = ["tabindex"];
73
- /**
74
- * Copyright IBM Corp. 2018, 2026
75
- *
76
- * This source code is licensed under the Apache-2.0 license found in the
77
- * LICENSE file in the root directory of this source tree.
78
- */
42
+ //#endregion
43
+ //#region src/toString.ts
44
+ /**
45
+ * Copyright IBM Corp. 2018, 2024
46
+ *
47
+ * This source code is licensed under the Apache-2.0 license found in the
48
+ * LICENSE file in the root directory of this source tree.
49
+ */
50
+ /**
51
+ * Convert an icon descriptor to a String
52
+ */
53
+ function toString(descriptor) {
54
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
55
+ const children = content.map(toString).join("");
56
+ if (elem !== "svg") return `<${elem} ${formatAttributes(attrs)}>${children}</${elem}>`;
57
+ return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}</${elem}>`;
58
+ }
59
+ function formatAttributes(attrs) {
60
+ return Object.keys(attrs).reduce((acc, key, index) => {
61
+ const attribute = `${key}="${attrs[key]}"`;
62
+ if (index === 0) return attribute;
63
+ return acc + " " + attribute;
64
+ }, "");
65
+ }
79
66
 
80
- var defaultAttributes = {
81
- // Reference:
82
- // https://github.com/IBM/carbon-components-react/issues/1392
83
- // https://github.com/PolymerElements/iron-iconset-svg/pull/47
84
- // `focusable` is a string attribute which is why we do not use a boolean here
85
- focusable: 'false',
86
- preserveAspectRatio: 'xMidYMid meet'
87
- };
67
+ //#endregion
68
+ //#region src/toSVG.ts
69
+ /**
70
+ * Copyright IBM Corp. 2018, 2024
71
+ *
72
+ * This source code is licensed under the Apache-2.0 license found in the
73
+ * LICENSE file in the root directory of this source tree.
74
+ */
75
+ /**
76
+ * Convert an icon descriptor to a DOM node.
77
+ */
78
+ function toSVG(descriptor) {
79
+ const { elem = "svg", attrs = {}, content = [] } = descriptor;
80
+ const node = document.createElementNS("http://www.w3.org/2000/svg", elem);
81
+ const attributes = elem !== "svg" ? attrs : getAttributes(attrs);
82
+ Object.keys(attributes).forEach((key) => {
83
+ node.setAttribute(key, attrs[key]);
84
+ });
85
+ for (let i = 0; i < content.length; i++) node.appendChild(toSVG(content[i]));
86
+ return node;
87
+ }
88
88
 
89
- /**
90
- * Get supplementary HTML attributes for a given <svg> element based on existing
91
- * attributes.
92
- */
93
- function getAttributes() {
94
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
95
- width = _ref.width,
96
- height = _ref.height,
97
- _ref$viewBox = _ref.viewBox,
98
- viewBox = _ref$viewBox === void 0 ? "0 0 ".concat(width, " ").concat(height) : _ref$viewBox,
99
- attributes = _objectWithoutProperties(_ref, _excluded);
100
- var tabindex = attributes.tabindex,
101
- rest = _objectWithoutProperties(attributes, _excluded2);
102
- var iconAttributes = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultAttributes), rest), {}, {
103
- width: width,
104
- height: height,
105
- viewBox: viewBox
106
- });
107
- if (iconAttributes['aria-label'] || iconAttributes['aria-labelledby']) {
108
- iconAttributes.role = 'img';
89
+ //#endregion
90
+ //#region src/index.ts
91
+ /**
92
+ * Copyright IBM Corp. 2018, 2023
93
+ *
94
+ * This source code is licensed under the Apache-2.0 license found in the
95
+ * LICENSE file in the root directory of this source tree.
96
+ */
109
97
 
110
- // Reference:
111
- // https://allyjs.io/tutorials/focusing-in-svg.html
112
- if (tabindex !== undefined && tabindex !== null) {
113
- iconAttributes.focusable = 'true';
114
- iconAttributes.tabindex = tabindex;
115
- }
116
- } else {
117
- iconAttributes['aria-hidden'] = true;
118
- }
119
- return iconAttributes;
120
- }
121
-
122
- /**
123
- * Copyright IBM Corp. 2018, 2024
124
- *
125
- * This source code is licensed under the Apache-2.0 license found in the
126
- * LICENSE file in the root directory of this source tree.
127
- */
128
-
129
- /**
130
- * Convert an icon descriptor to a String
131
- */
132
- function toString(descriptor) {
133
- var _descriptor$elem = descriptor.elem,
134
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
135
- _descriptor$attrs = descriptor.attrs,
136
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
137
- _descriptor$content = descriptor.content,
138
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
139
- var children = content.map(toString).join('');
140
- if (elem !== 'svg') {
141
- return "<".concat(elem, " ").concat(formatAttributes(attrs), ">").concat(children, "</").concat(elem, ">");
142
- }
143
- return "<".concat(elem, " ").concat(formatAttributes(getAttributes(attrs)), ">").concat(children, "</").concat(elem, ">");
144
- }
145
- function formatAttributes(attrs) {
146
- return Object.keys(attrs).reduce(function (acc, key, index) {
147
- var attribute = "".concat(key, "=\"").concat(attrs[key], "\"");
148
- if (index === 0) {
149
- return attribute;
150
- }
151
- return acc + ' ' + attribute;
152
- }, '');
153
- }
154
-
155
- /**
156
- * Copyright IBM Corp. 2018, 2024
157
- *
158
- * This source code is licensed under the Apache-2.0 license found in the
159
- * LICENSE file in the root directory of this source tree.
160
- */
161
-
162
- /**
163
- * Convert an icon descriptor to a DOM node.
164
- */
165
- function toSVG(descriptor) {
166
- var _descriptor$elem = descriptor.elem,
167
- elem = _descriptor$elem === void 0 ? 'svg' : _descriptor$elem,
168
- _descriptor$attrs = descriptor.attrs,
169
- attrs = _descriptor$attrs === void 0 ? {} : _descriptor$attrs,
170
- _descriptor$content = descriptor.content,
171
- content = _descriptor$content === void 0 ? [] : _descriptor$content;
172
- var node = document.createElementNS('http://www.w3.org/2000/svg', elem);
173
- var attributes = elem !== 'svg' ? attrs : getAttributes(attrs);
174
- Object.keys(attributes).forEach(function (key) {
175
- node.setAttribute(key, attrs[key]);
176
- });
177
- for (var i = 0; i < content.length; i++) {
178
- node.appendChild(toSVG(content[i]));
179
- }
180
- return node;
181
- }
182
-
183
- exports.defaultAttributes = defaultAttributes;
184
- exports.formatAttributes = formatAttributes;
185
- exports.getAttributes = getAttributes;
186
- exports.toSVG = toSVG;
187
- exports.toString = toString;
188
-
189
- }));
98
+ //#endregion
99
+ exports.defaultAttributes = defaultAttributes;
100
+ exports.formatAttributes = formatAttributes;
101
+ exports.getAttributes = getAttributes;
102
+ exports.toSVG = toSVG;
103
+ exports.toString = toString;
104
+ });