@cypress-design/vue-icon 0.23.1 → 0.24.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.
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +20 -0
- package/Icon.ts +66 -15
- package/IconVue.cy.tsx +83 -1
- package/_TreeShakableIcons.ts +4964 -5144
- package/compileProperties.ts +124 -40
- package/dist/Icon.d.ts +3 -4
- package/dist/Icon.d.ts.map +1 -1
- package/dist/_TreeShakableIcons.d.ts +663 -661
- package/dist/_TreeShakableIcons.d.ts.map +1 -1
- package/dist/compileProperties.d.ts +403 -385
- package/dist/compileProperties.d.ts.map +1 -1
- package/dist/index.es.mjs +3718 -3856
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/generate-icons.js +87 -22
- package/package.json +3 -3
package/generate-icons.js
CHANGED
|
@@ -16,42 +16,107 @@ const iconsComponents = Object.keys(iconsMetadata).map((name) => {
|
|
|
16
16
|
const iconBodies = iconSet.reduce((acc, icon) => {
|
|
17
17
|
const sizeIndex = availableIds.indexOf(icon.name)
|
|
18
18
|
if (sizeIndex > -1) {
|
|
19
|
-
|
|
19
|
+
const indexOfDefs = icon.data.indexOf('<defs>')
|
|
20
|
+
acc[iconMetadata.availableSizes[sizeIndex]] = {
|
|
21
|
+
body: indexOfDefs >= 0 ? icon.data.slice(0, indexOfDefs) : icon.data,
|
|
22
|
+
// avoid defs: undefined in final exported code
|
|
23
|
+
...(indexOfDefs >= 0 ? { defs: icon.data.slice(indexOfDefs) } : {}),
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
return acc
|
|
22
27
|
}, {})
|
|
28
|
+
|
|
23
29
|
return dedent`
|
|
24
|
-
export const Icon${pascalCaseName} = (props:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
availableSizes: ${JSON.stringify(iconMetadata.availableSizes)},
|
|
29
|
-
interactiveColorsOnGroup
|
|
30
|
-
})
|
|
31
|
-
const iconBodies: Record<string, string> = ${JSON.stringify(
|
|
30
|
+
export const Icon${pascalCaseName} = defineComponent((props: Omit<iconsRegistry.Icon${pascalCaseName}Props, 'name'> & {
|
|
31
|
+
class?: string
|
|
32
|
+
}, { attrs }: { attrs: Omit<SVGAttributes, 'name' | 'class'> }) => {
|
|
33
|
+
const iconPropsStep = useIconProps(props, ${JSON.stringify(
|
|
32
34
|
iconBodies,
|
|
33
35
|
null,
|
|
34
36
|
2
|
|
35
|
-
)}
|
|
36
|
-
|
|
37
|
+
)}, ${JSON.stringify(iconMetadata.availableSizes)}, ${JSON.stringify(name)})
|
|
38
|
+
|
|
39
|
+
const { componentProps, defs } = compileVueIconProperties(iconPropsStep)
|
|
40
|
+
|
|
41
|
+
const { shouldRenderDefs } = useShouldRenderDefs(
|
|
42
|
+
${JSON.stringify(name)},
|
|
43
|
+
defs)
|
|
44
|
+
|
|
45
|
+
return () => hyperSVG(componentProps, defs, shouldRenderDefs, attrs, props.class)
|
|
46
|
+
},
|
|
47
|
+
// @ts-expect-error - vue types need an update
|
|
48
|
+
__iconComponentOpts__)
|
|
49
|
+
`
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
writeFile(`
|
|
53
|
+
import { h, defineComponent, computed } from 'vue'
|
|
54
|
+
import type { ComputedRef, SVGAttributes, Ref } from 'vue'
|
|
55
|
+
import * as iconsRegistry from '@cypress-design/icon-registry'
|
|
56
|
+
import { compileVueIconProperties, useShouldRenderDefs } from './compileProperties'
|
|
57
|
+
|
|
58
|
+
const __iconComponentOpts__ = {
|
|
59
|
+
props: [...iconsRegistry.ICON_COLOR_PROP_NAMES, 'interactiveColorsOnGroup', 'size', 'class'],
|
|
60
|
+
} as const
|
|
61
|
+
|
|
62
|
+
function useIconProps(props: SVGAttributes & Omit<iconsRegistry.IconProps, 'name'>, iconBodiesAndDefs: Record<string, {body: string, defs?: string}>, availableSizes: string[], name: string) {
|
|
63
|
+
return computed(() => {
|
|
64
|
+
const { interactiveColorsOnGroup, ...cleanProps } = props
|
|
65
|
+
|
|
66
|
+
const { sizeWithDefault: size, compiledClasses } = iconsRegistry.getComponentAttributes({
|
|
67
|
+
...cleanProps,
|
|
68
|
+
availableSizes,
|
|
69
|
+
interactiveColorsOnGroup,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const { body, defs } = iconBodiesAndDefs[size] || {}
|
|
37
73
|
if(!body){
|
|
38
|
-
throw Error(\`Icon "${name}" is not available in size ${'$'}{size}\`)
|
|
74
|
+
throw Error(\`Icon "${'$'}{name}" is not available in size ${'$'}{size}\`)
|
|
39
75
|
}
|
|
40
|
-
|
|
76
|
+
|
|
77
|
+
return {
|
|
41
78
|
...cleanProps,
|
|
79
|
+
name,
|
|
42
80
|
size,
|
|
43
81
|
body,
|
|
82
|
+
defs,
|
|
44
83
|
compiledClasses
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
})
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
}
|
|
49
87
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
88
|
+
function hyperSVG(
|
|
89
|
+
componentProps: ComputedRef<SVGAttributes>,
|
|
90
|
+
defs: ComputedRef<string | undefined>,
|
|
91
|
+
shouldRenderDefs: Ref<boolean>,
|
|
92
|
+
attrs: SVGAttributes,
|
|
93
|
+
className?: string,
|
|
94
|
+
) {
|
|
95
|
+
|
|
96
|
+
return shouldRenderDefs.value && defs.value
|
|
97
|
+
? [
|
|
98
|
+
h('svg', {
|
|
99
|
+
innerHTML: defs.value,
|
|
100
|
+
height: 0,
|
|
101
|
+
width: 0,
|
|
102
|
+
style: 'position:absolute',
|
|
103
|
+
class: [
|
|
104
|
+
'pointer-events-none',
|
|
105
|
+
'opacity-0',
|
|
106
|
+
],
|
|
107
|
+
}),
|
|
108
|
+
h('svg', {
|
|
109
|
+
...attrs,
|
|
110
|
+
...componentProps.value,
|
|
111
|
+
class: [className, componentProps.value.class],
|
|
112
|
+
}),
|
|
113
|
+
]
|
|
114
|
+
: h('svg', {
|
|
115
|
+
...attrs,
|
|
116
|
+
...componentProps.value,
|
|
117
|
+
class: [className, componentProps.value.class],
|
|
118
|
+
})
|
|
119
|
+
}
|
|
55
120
|
|
|
56
121
|
${iconsComponents.join('\n\n\n')}
|
|
57
122
|
`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cypress-design/vue-icon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"*"
|
|
6
6
|
],
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"build:types": "yarn tsc --project ./tsconfig.build.json"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cypress-design/icon-registry": "^0.
|
|
24
|
+
"@cypress-design/icon-registry": "^0.25.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@cypress-design/rollup-plugin-tailwind-keep": "*",
|
|
28
28
|
"@types/lodash": "^4.14.195",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"dedent": "^
|
|
30
|
+
"dedent": "^1.2.0"
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT"
|
|
33
33
|
}
|