@opudoc/opicon-shared 0.1.5 → 0.1.7
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.
- package/dist/cjs/shared.js +54 -0
- package/dist/cjs/shared.js.map +1 -1
- package/dist/esm/getIconSvgPaintProps.mjs +26 -0
- package/dist/esm/getIconSvgPaintProps.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/isFillPrimaryIconName.mjs +5 -0
- package/dist/esm/isFillPrimaryIconName.mjs.map +1 -0
- package/dist/esm/sanitizeFilledPathAttrs.mjs +26 -0
- package/dist/esm/sanitizeFilledPathAttrs.mjs.map +1 -0
- package/dist/shared.d.ts +26 -2
- package/package.json +1 -1
package/dist/cjs/shared.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const isBoldIconName = (iconName) => iconName.includes("-bold-");
|
|
4
4
|
|
|
5
|
+
const isFillPrimaryIconName = (iconName) => /-(bold|bulk)-/.test(iconName);
|
|
6
|
+
const isStrokePrimaryIconName = (iconName) => /-(linear|outline|broken|twotone)-/.test(iconName);
|
|
7
|
+
|
|
5
8
|
const pathHasFill = (tag, attrs) => tag === "path" && Boolean(attrs.fill) && attrs.fill !== "none";
|
|
6
9
|
const nodeUsesFill = (node) => {
|
|
7
10
|
if (node.length === 3) {
|
|
@@ -14,15 +17,66 @@ const nodeUsesFill = (node) => {
|
|
|
14
17
|
};
|
|
15
18
|
const iconNodeUsesFill = (iconNode) => iconNode.some(nodeUsesFill);
|
|
16
19
|
|
|
20
|
+
const getIconSvgPaintProps = (iconNode, options = {}) => {
|
|
21
|
+
const iconColor = options.color ?? "currentColor";
|
|
22
|
+
const filled = iconNodeUsesFill(iconNode);
|
|
23
|
+
if (filled) {
|
|
24
|
+
return {
|
|
25
|
+
color: iconColor,
|
|
26
|
+
fill: iconColor,
|
|
27
|
+
stroke: "none",
|
|
28
|
+
filled: true
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const strokeWidth = options.strokeWidth ?? 2;
|
|
32
|
+
const calculatedStrokeWidth = options.absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(options.size ?? 24) : strokeWidth;
|
|
33
|
+
return {
|
|
34
|
+
color: iconColor,
|
|
35
|
+
fill: "none",
|
|
36
|
+
stroke: iconColor,
|
|
37
|
+
strokeWidth: calculatedStrokeWidth,
|
|
38
|
+
filled: false
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const STROKE_ATTR_NAMES = [
|
|
43
|
+
"stroke",
|
|
44
|
+
"stroke-width",
|
|
45
|
+
"stroke-linecap",
|
|
46
|
+
"stroke-linejoin",
|
|
47
|
+
"stroke-miterlimit",
|
|
48
|
+
"stroke-dasharray",
|
|
49
|
+
"stroke-dashoffset"
|
|
50
|
+
];
|
|
51
|
+
const sanitizeFilledPathAttrs = (tag, attrs, filled) => {
|
|
52
|
+
if (!filled || tag !== "path") return attrs;
|
|
53
|
+
const fill = attrs.fill;
|
|
54
|
+
if (!fill || fill === "none") return attrs;
|
|
55
|
+
const result = { ...attrs };
|
|
56
|
+
for (const name of STROKE_ATTR_NAMES) {
|
|
57
|
+
delete result[name];
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
const iconNodeElementAttrs = (tag, attrs, filled) => {
|
|
62
|
+
const { key: _key, ...rest } = attrs;
|
|
63
|
+
return sanitizeFilledPathAttrs(tag, rest, filled);
|
|
64
|
+
};
|
|
65
|
+
|
|
17
66
|
const toPascalCase = (str) => str.split(/[-_/]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
18
67
|
const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
19
68
|
const mergeClasses = (...classes) => classes.filter(Boolean).join(" ");
|
|
20
69
|
const hasA11yProp = (props) => "aria-label" in props || "aria-labelledby" in props || "title" in props;
|
|
21
70
|
|
|
71
|
+
exports.getIconSvgPaintProps = getIconSvgPaintProps;
|
|
22
72
|
exports.hasA11yProp = hasA11yProp;
|
|
73
|
+
exports.iconNodeElementAttrs = iconNodeElementAttrs;
|
|
23
74
|
exports.iconNodeUsesFill = iconNodeUsesFill;
|
|
24
75
|
exports.isBoldIconName = isBoldIconName;
|
|
76
|
+
exports.isFillPrimaryIconName = isFillPrimaryIconName;
|
|
77
|
+
exports.isStrokePrimaryIconName = isStrokePrimaryIconName;
|
|
25
78
|
exports.mergeClasses = mergeClasses;
|
|
79
|
+
exports.sanitizeFilledPathAttrs = sanitizeFilledPathAttrs;
|
|
26
80
|
exports.toKebabCase = toKebabCase;
|
|
27
81
|
exports.toPascalCase = toPascalCase;
|
|
28
82
|
//# sourceMappingURL=shared.js.map
|
package/dist/cjs/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sources":["../../src/isBoldIconName.ts","../../src/iconNodeUsesFill.ts","../../src/index.ts"],"sourcesContent":["/** Icon ids use `{category}-bold-{name}` (e.g. `settings-bold-menu`). */\nexport const isBoldIconName = (iconName: string): boolean => iconName.includes('-bold-');\n","type IconNodeEntry = [string, Record<string, string | number>, ...unknown[]];\n\nconst pathHasFill = (tag: string, attrs: Record<string, string | number>): boolean =>\n tag === 'path' && Boolean(attrs.fill) && attrs.fill !== 'none';\n\nconst nodeUsesFill = (node: IconNodeEntry): boolean => {\n if (node.length === 3) {\n const [tag, attrs, children] = node;\n if (pathHasFill(tag, attrs)) return true;\n return (children as IconNodeEntry[]).some(nodeUsesFill);\n }\n const [tag, attrs] = node;\n return pathHasFill(tag, attrs);\n};\n\nexport const iconNodeUsesFill = (iconNode: IconNodeEntry[]): boolean => iconNode.some(nodeUsesFill);\n","export const toPascalCase = (str: string): string =>\n str\n .split(/[-_/]/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\nexport const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const mergeClasses = (...classes: (string | undefined | false)[]): string =>\n classes.filter(Boolean).join(' ');\n\nexport const hasA11yProp = (props: Record<string, unknown>): boolean =>\n 'aria-label' in props || 'aria-labelledby' in props || 'title' in props;\n\nexport { isBoldIconName } from './isBoldIconName';\nexport { iconNodeUsesFill } from './iconNodeUsesFill';\n"],"names":["tag","attrs"],"mappings":";;AACO,MAAM,cAAA,GAAiB,CAAC,QAAA,KAA8B,QAAA,CAAS,SAAS,QAAQ;;
|
|
1
|
+
{"version":3,"file":"shared.js","sources":["../../src/isBoldIconName.ts","../../src/isFillPrimaryIconName.ts","../../src/iconNodeUsesFill.ts","../../src/getIconSvgPaintProps.ts","../../src/sanitizeFilledPathAttrs.ts","../../src/index.ts"],"sourcesContent":["/** Icon ids use `{category}-bold-{name}` (e.g. `settings-bold-menu`). */\nexport const isBoldIconName = (iconName: string): boolean => iconName.includes('-bold-');\n","/** Icon ids use `{category}-{style}-{name}` (e.g. `home-bold-Add-home`). */\nexport const isFillPrimaryIconName = (iconName: string): boolean => /-(bold|bulk)-/.test(iconName);\n\nexport const isStrokePrimaryIconName = (iconName: string): boolean =>\n /-(linear|outline|broken|twotone)-/.test(iconName);\n","type IconNodeEntry = [string, Record<string, string | number>, ...unknown[]];\n\nconst pathHasFill = (tag: string, attrs: Record<string, string | number>): boolean =>\n tag === 'path' && Boolean(attrs.fill) && attrs.fill !== 'none';\n\nconst nodeUsesFill = (node: IconNodeEntry): boolean => {\n if (node.length === 3) {\n const [tag, attrs, children] = node;\n if (pathHasFill(tag, attrs)) return true;\n return (children as IconNodeEntry[]).some(nodeUsesFill);\n }\n const [tag, attrs] = node;\n return pathHasFill(tag, attrs);\n};\n\nexport const iconNodeUsesFill = (iconNode: IconNodeEntry[]): boolean => iconNode.some(nodeUsesFill);\n","import { iconNodeUsesFill } from './iconNodeUsesFill';\n\ntype IconNodeEntry = [string, Record<string, string | number>, ...unknown[]];\n\nexport interface IconSvgPaintProps {\n color: string;\n fill: string;\n stroke: string;\n strokeWidth?: number | string;\n filled: boolean;\n}\n\nexport const getIconSvgPaintProps = (\n iconNode: IconNodeEntry[],\n options: {\n color?: string;\n strokeWidth?: number | string;\n absoluteStrokeWidth?: boolean;\n size?: number | string;\n } = {},\n): IconSvgPaintProps => {\n const iconColor = options.color ?? 'currentColor';\n const filled = iconNodeUsesFill(iconNode);\n\n if (filled) {\n return {\n color: iconColor,\n fill: iconColor,\n stroke: 'none',\n filled: true,\n };\n }\n\n const strokeWidth = options.strokeWidth ?? 2;\n const calculatedStrokeWidth = options.absoluteStrokeWidth\n ? (Number(strokeWidth) * 24) / Number(options.size ?? 24)\n : strokeWidth;\n\n return {\n color: iconColor,\n fill: 'none',\n stroke: iconColor,\n strokeWidth: calculatedStrokeWidth,\n filled: false,\n };\n};\n","const STROKE_ATTR_NAMES = [\n 'stroke',\n 'stroke-width',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n] as const;\n\n/** Remove per-path stroke attrs on fill-primary paths (legacy bold nodes from 0.1.5). */\nexport const sanitizeFilledPathAttrs = (\n tag: string,\n attrs: Record<string, string | number>,\n filled: boolean,\n): Record<string, string | number> => {\n if (!filled || tag !== 'path') return attrs;\n\n const fill = attrs.fill;\n if (!fill || fill === 'none') return attrs;\n\n const result = { ...attrs };\n for (const name of STROKE_ATTR_NAMES) {\n delete result[name];\n }\n return result;\n};\n\nexport const iconNodeElementAttrs = (\n tag: string,\n attrs: Record<string, string | number>,\n filled: boolean,\n): Record<string, string | number> => {\n const { key: _key, ...rest } = attrs;\n return sanitizeFilledPathAttrs(tag, rest, filled);\n};\n","export const toPascalCase = (str: string): string =>\n str\n .split(/[-_/]/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\nexport const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const mergeClasses = (...classes: (string | undefined | false)[]): string =>\n classes.filter(Boolean).join(' ');\n\nexport const hasA11yProp = (props: Record<string, unknown>): boolean =>\n 'aria-label' in props || 'aria-labelledby' in props || 'title' in props;\n\nexport { isBoldIconName } from './isBoldIconName';\nexport { isFillPrimaryIconName, isStrokePrimaryIconName } from './isFillPrimaryIconName';\nexport { iconNodeUsesFill } from './iconNodeUsesFill';\nexport { getIconSvgPaintProps } from './getIconSvgPaintProps';\nexport type { IconSvgPaintProps } from './getIconSvgPaintProps';\nexport { iconNodeElementAttrs, sanitizeFilledPathAttrs } from './sanitizeFilledPathAttrs';\n"],"names":["tag","attrs"],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { iconNodeUsesFill } from './iconNodeUsesFill.mjs';
|
|
2
|
+
|
|
3
|
+
const getIconSvgPaintProps = (iconNode, options = {}) => {
|
|
4
|
+
const iconColor = options.color ?? "currentColor";
|
|
5
|
+
const filled = iconNodeUsesFill(iconNode);
|
|
6
|
+
if (filled) {
|
|
7
|
+
return {
|
|
8
|
+
color: iconColor,
|
|
9
|
+
fill: iconColor,
|
|
10
|
+
stroke: "none",
|
|
11
|
+
filled: true
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const strokeWidth = options.strokeWidth ?? 2;
|
|
15
|
+
const calculatedStrokeWidth = options.absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(options.size ?? 24) : strokeWidth;
|
|
16
|
+
return {
|
|
17
|
+
color: iconColor,
|
|
18
|
+
fill: "none",
|
|
19
|
+
stroke: iconColor,
|
|
20
|
+
strokeWidth: calculatedStrokeWidth,
|
|
21
|
+
filled: false
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { getIconSvgPaintProps };
|
|
26
|
+
//# sourceMappingURL=getIconSvgPaintProps.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIconSvgPaintProps.mjs","sources":["../../src/getIconSvgPaintProps.ts"],"sourcesContent":["import { iconNodeUsesFill } from './iconNodeUsesFill';\n\ntype IconNodeEntry = [string, Record<string, string | number>, ...unknown[]];\n\nexport interface IconSvgPaintProps {\n color: string;\n fill: string;\n stroke: string;\n strokeWidth?: number | string;\n filled: boolean;\n}\n\nexport const getIconSvgPaintProps = (\n iconNode: IconNodeEntry[],\n options: {\n color?: string;\n strokeWidth?: number | string;\n absoluteStrokeWidth?: boolean;\n size?: number | string;\n } = {},\n): IconSvgPaintProps => {\n const iconColor = options.color ?? 'currentColor';\n const filled = iconNodeUsesFill(iconNode);\n\n if (filled) {\n return {\n color: iconColor,\n fill: iconColor,\n stroke: 'none',\n filled: true,\n };\n }\n\n const strokeWidth = options.strokeWidth ?? 2;\n const calculatedStrokeWidth = options.absoluteStrokeWidth\n ? (Number(strokeWidth) * 24) / Number(options.size ?? 24)\n : strokeWidth;\n\n return {\n color: iconColor,\n fill: 'none',\n stroke: iconColor,\n strokeWidth: calculatedStrokeWidth,\n filled: false,\n };\n};\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAA,GAAuB,CAClC,QAAA,EACA,OAAA,GAKI,EAAC,KACiB;AACtB,EAAA,MAAM,SAAA,GAAY,QAAQ,KAAA,IAAS,cAAA;AACnC,EAAA,MAAM,MAAA,GAAS,iBAAiB,QAAQ,CAAA;AAExC,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,SAAA;AAAA,MACP,IAAA,EAAM,SAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AAEA,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,CAAA;AAC3C,EAAA,MAAM,qBAAA,GAAwB,OAAA,CAAQ,mBAAA,GACjC,MAAA,CAAO,WAAW,CAAA,GAAI,EAAA,GAAM,MAAA,CAAO,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,GACtD,WAAA;AAEJ,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,SAAA;AAAA,IACP,IAAA,EAAM,MAAA;AAAA,IACN,MAAA,EAAQ,SAAA;AAAA,IACR,WAAA,EAAa,qBAAA;AAAA,IACb,MAAA,EAAQ;AAAA,GACV;AACF;;;;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { isBoldIconName } from './isBoldIconName.mjs';
|
|
2
|
+
export { isFillPrimaryIconName, isStrokePrimaryIconName } from './isFillPrimaryIconName.mjs';
|
|
2
3
|
export { iconNodeUsesFill } from './iconNodeUsesFill.mjs';
|
|
4
|
+
export { getIconSvgPaintProps } from './getIconSvgPaintProps.mjs';
|
|
5
|
+
export { iconNodeElementAttrs, sanitizeFilledPathAttrs } from './sanitizeFilledPathAttrs.mjs';
|
|
3
6
|
|
|
4
7
|
const toPascalCase = (str) => str.split(/[-_/]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
5
8
|
const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["export const toPascalCase = (str: string): string =>\n str\n .split(/[-_/]/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\nexport const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const mergeClasses = (...classes: (string | undefined | false)[]): string =>\n classes.filter(Boolean).join(' ');\n\nexport const hasA11yProp = (props: Record<string, unknown>): boolean =>\n 'aria-label' in props || 'aria-labelledby' in props || 'title' in props;\n\nexport { isBoldIconName } from './isBoldIconName';\nexport { iconNodeUsesFill } from './iconNodeUsesFill';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["export const toPascalCase = (str: string): string =>\n str\n .split(/[-_/]/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\nexport const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const mergeClasses = (...classes: (string | undefined | false)[]): string =>\n classes.filter(Boolean).join(' ');\n\nexport const hasA11yProp = (props: Record<string, unknown>): boolean =>\n 'aria-label' in props || 'aria-labelledby' in props || 'title' in props;\n\nexport { isBoldIconName } from './isBoldIconName';\nexport { isFillPrimaryIconName, isStrokePrimaryIconName } from './isFillPrimaryIconName';\nexport { iconNodeUsesFill } from './iconNodeUsesFill';\nexport { getIconSvgPaintProps } from './getIconSvgPaintProps';\nexport type { IconSvgPaintProps } from './getIconSvgPaintProps';\nexport { iconNodeElementAttrs, sanitizeFilledPathAttrs } from './sanitizeFilledPathAttrs';\n"],"names":[],"mappings":";;;;;;AAAO,MAAM,YAAA,GAAe,CAAC,GAAA,KAC3B,GAAA,CACG,MAAM,OAAO,CAAA,CACb,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,IAAA,CAAK,MAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,EAAE;AAEL,MAAM,WAAA,GAAc,CAAC,GAAA,KAC1B,GAAA,CAAI,QAAQ,oBAAA,EAAsB,OAAO,EAAE,WAAA;AAEtC,MAAM,YAAA,GAAe,IAAI,OAAA,KAC9B,OAAA,CAAQ,OAAO,OAAO,CAAA,CAAE,KAAK,GAAG;AAE3B,MAAM,cAAc,CAAC,KAAA,KAC1B,gBAAgB,KAAA,IAAS,iBAAA,IAAqB,SAAS,OAAA,IAAW;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const isFillPrimaryIconName = (iconName) => /-(bold|bulk)-/.test(iconName);
|
|
2
|
+
const isStrokePrimaryIconName = (iconName) => /-(linear|outline|broken|twotone)-/.test(iconName);
|
|
3
|
+
|
|
4
|
+
export { isFillPrimaryIconName, isStrokePrimaryIconName };
|
|
5
|
+
//# sourceMappingURL=isFillPrimaryIconName.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isFillPrimaryIconName.mjs","sources":["../../src/isFillPrimaryIconName.ts"],"sourcesContent":["/** Icon ids use `{category}-{style}-{name}` (e.g. `home-bold-Add-home`). */\nexport const isFillPrimaryIconName = (iconName: string): boolean => /-(bold|bulk)-/.test(iconName);\n\nexport const isStrokePrimaryIconName = (iconName: string): boolean =>\n /-(linear|outline|broken|twotone)-/.test(iconName);\n"],"names":[],"mappings":"AACO,MAAM,qBAAA,GAAwB,CAAC,QAAA,KAA8B,eAAA,CAAgB,KAAK,QAAQ;AAE1F,MAAM,uBAAA,GAA0B,CAAC,QAAA,KACtC,mCAAA,CAAoC,KAAK,QAAQ;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const STROKE_ATTR_NAMES = [
|
|
2
|
+
"stroke",
|
|
3
|
+
"stroke-width",
|
|
4
|
+
"stroke-linecap",
|
|
5
|
+
"stroke-linejoin",
|
|
6
|
+
"stroke-miterlimit",
|
|
7
|
+
"stroke-dasharray",
|
|
8
|
+
"stroke-dashoffset"
|
|
9
|
+
];
|
|
10
|
+
const sanitizeFilledPathAttrs = (tag, attrs, filled) => {
|
|
11
|
+
if (!filled || tag !== "path") return attrs;
|
|
12
|
+
const fill = attrs.fill;
|
|
13
|
+
if (!fill || fill === "none") return attrs;
|
|
14
|
+
const result = { ...attrs };
|
|
15
|
+
for (const name of STROKE_ATTR_NAMES) {
|
|
16
|
+
delete result[name];
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
const iconNodeElementAttrs = (tag, attrs, filled) => {
|
|
21
|
+
const { key: _key, ...rest } = attrs;
|
|
22
|
+
return sanitizeFilledPathAttrs(tag, rest, filled);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { iconNodeElementAttrs, sanitizeFilledPathAttrs };
|
|
26
|
+
//# sourceMappingURL=sanitizeFilledPathAttrs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeFilledPathAttrs.mjs","sources":["../../src/sanitizeFilledPathAttrs.ts"],"sourcesContent":["const STROKE_ATTR_NAMES = [\n 'stroke',\n 'stroke-width',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n] as const;\n\n/** Remove per-path stroke attrs on fill-primary paths (legacy bold nodes from 0.1.5). */\nexport const sanitizeFilledPathAttrs = (\n tag: string,\n attrs: Record<string, string | number>,\n filled: boolean,\n): Record<string, string | number> => {\n if (!filled || tag !== 'path') return attrs;\n\n const fill = attrs.fill;\n if (!fill || fill === 'none') return attrs;\n\n const result = { ...attrs };\n for (const name of STROKE_ATTR_NAMES) {\n delete result[name];\n }\n return result;\n};\n\nexport const iconNodeElementAttrs = (\n tag: string,\n attrs: Record<string, string | number>,\n filled: boolean,\n): Record<string, string | number> => {\n const { key: _key, ...rest } = attrs;\n return sanitizeFilledPathAttrs(tag, rest, filled);\n};\n"],"names":[],"mappings":"AAAA,MAAM,iBAAA,GAAoB;AAAA,EACxB,QAAA;AAAA,EACA,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,iBAAA;AAAA,EACA,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAGO,MAAM,uBAAA,GAA0B,CACrC,GAAA,EACA,KAAA,EACA,MAAA,KACoC;AACpC,EAAA,IAAI,CAAC,MAAA,IAAU,GAAA,KAAQ,MAAA,EAAQ,OAAO,KAAA;AAEtC,EAAA,MAAM,OAAO,KAAA,CAAM,IAAA;AACnB,EAAA,IAAI,CAAC,IAAA,IAAQ,IAAA,KAAS,MAAA,EAAQ,OAAO,KAAA;AAErC,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,KAAA,EAAM;AAC1B,EAAA,KAAA,MAAW,QAAQ,iBAAA,EAAmB;AACpC,IAAA,OAAO,OAAO,IAAI,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,MAAA;AACT;AAEO,MAAM,oBAAA,GAAuB,CAClC,GAAA,EACA,KAAA,EACA,MAAA,KACoC;AACpC,EAAA,MAAM,EAAE,GAAA,EAAK,IAAA,EAAM,GAAG,MAAK,GAAI,KAAA;AAC/B,EAAA,OAAO,uBAAA,CAAwB,GAAA,EAAK,IAAA,EAAM,MAAM,CAAA;AAClD;;;;"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
/** Icon ids use `{category}-bold-{name}` (e.g. `settings-bold-menu`). */
|
|
2
2
|
declare const isBoldIconName: (iconName: string) => boolean;
|
|
3
3
|
|
|
4
|
+
/** Icon ids use `{category}-{style}-{name}` (e.g. `home-bold-Add-home`). */
|
|
5
|
+
declare const isFillPrimaryIconName: (iconName: string) => boolean;
|
|
6
|
+
declare const isStrokePrimaryIconName: (iconName: string) => boolean;
|
|
7
|
+
|
|
8
|
+
type IconNodeEntry$1 = [string, Record<string, string | number>, ...unknown[]];
|
|
9
|
+
declare const iconNodeUsesFill: (iconNode: IconNodeEntry$1[]) => boolean;
|
|
10
|
+
|
|
4
11
|
type IconNodeEntry = [string, Record<string, string | number>, ...unknown[]];
|
|
5
|
-
|
|
12
|
+
interface IconSvgPaintProps {
|
|
13
|
+
color: string;
|
|
14
|
+
fill: string;
|
|
15
|
+
stroke: string;
|
|
16
|
+
strokeWidth?: number | string;
|
|
17
|
+
filled: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare const getIconSvgPaintProps: (iconNode: IconNodeEntry[], options?: {
|
|
20
|
+
color?: string;
|
|
21
|
+
strokeWidth?: number | string;
|
|
22
|
+
absoluteStrokeWidth?: boolean;
|
|
23
|
+
size?: number | string;
|
|
24
|
+
}) => IconSvgPaintProps;
|
|
25
|
+
|
|
26
|
+
/** Remove per-path stroke attrs on fill-primary paths (legacy bold nodes from 0.1.5). */
|
|
27
|
+
declare const sanitizeFilledPathAttrs: (tag: string, attrs: Record<string, string | number>, filled: boolean) => Record<string, string | number>;
|
|
28
|
+
declare const iconNodeElementAttrs: (tag: string, attrs: Record<string, string | number>, filled: boolean) => Record<string, string | number>;
|
|
6
29
|
|
|
7
30
|
declare const toPascalCase: (str: string) => string;
|
|
8
31
|
declare const toKebabCase: (str: string) => string;
|
|
9
32
|
declare const mergeClasses: (...classes: (string | undefined | false)[]) => string;
|
|
10
33
|
declare const hasA11yProp: (props: Record<string, unknown>) => boolean;
|
|
11
34
|
|
|
12
|
-
export { hasA11yProp, iconNodeUsesFill, isBoldIconName, mergeClasses, toKebabCase, toPascalCase };
|
|
35
|
+
export { getIconSvgPaintProps, hasA11yProp, iconNodeElementAttrs, iconNodeUsesFill, isBoldIconName, isFillPrimaryIconName, isStrokePrimaryIconName, mergeClasses, sanitizeFilledPathAttrs, toKebabCase, toPascalCase };
|
|
36
|
+
export type { IconSvgPaintProps };
|