@cypress-design/vue-icon 0.23.0 → 0.23.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.
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +15 -0
- package/Icon.ts +66 -15
- package/IconVue.cy.tsx +83 -1
- package/_TreeShakableIcons.ts +4943 -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 +660 -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 +3703 -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 +4 -4
package/compileProperties.ts
CHANGED
|
@@ -1,47 +1,131 @@
|
|
|
1
1
|
import type { OpenIconProps } from '@cypress-design/icon-registry'
|
|
2
2
|
import { ICON_COLOR_PROP_NAMES } from '@cypress-design/icon-registry'
|
|
3
|
+
import {
|
|
4
|
+
ComputedRef,
|
|
5
|
+
Ref,
|
|
6
|
+
computed,
|
|
7
|
+
onBeforeMount,
|
|
8
|
+
onUnmounted,
|
|
9
|
+
ref,
|
|
10
|
+
} from 'vue'
|
|
3
11
|
import type { SVGAttributes } from 'vue'
|
|
4
12
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Icon names of the SVGs whose defs already appear in the DOM
|
|
15
|
+
*/
|
|
16
|
+
const defsAlreadyLoaded = new Set<string>()
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* There is a bug in the chrome renderer
|
|
20
|
+
* If an svg containing defs is twice on the page
|
|
21
|
+
* AND
|
|
22
|
+
* the first instance is hidden (display:none)
|
|
23
|
+
*
|
|
24
|
+
* Then the defs are not rendered for the second instance
|
|
25
|
+
* @param iconName
|
|
26
|
+
* @param defs
|
|
27
|
+
*/
|
|
28
|
+
export const useShouldRenderDefs = (
|
|
29
|
+
iconName: string,
|
|
30
|
+
defs: ComputedRef<string | undefined>
|
|
31
|
+
) => {
|
|
32
|
+
const shouldRenderDefs = ref(false)
|
|
33
|
+
|
|
34
|
+
onBeforeMount(() => {
|
|
35
|
+
const hasDocMarker =
|
|
36
|
+
// on SSR, we always want the first instance to come with the defs
|
|
37
|
+
typeof document === 'undefined' ||
|
|
38
|
+
// in interactive mode, the defs can be loaded, then removed, then loaded again
|
|
39
|
+
// so we check that they are here before adding them again
|
|
40
|
+
!document.querySelector(`[data-cy-icon-unified-defs="${iconName}"]`)
|
|
41
|
+
shouldRenderDefs.value = !defsAlreadyLoaded.has(iconName) && hasDocMarker
|
|
42
|
+
if (hasDocMarker) {
|
|
43
|
+
defsAlreadyLoaded.add(iconName)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
onUnmounted(() => {
|
|
48
|
+
if (shouldRenderDefs.value && defs.value) {
|
|
49
|
+
// to avoid ssr mismatch errors and jank
|
|
50
|
+
// add the defs inside an extra SVG and append it to the end of the body only when unmounting
|
|
51
|
+
const newDefs = document.createElementNS(
|
|
52
|
+
'http://www.w3.org/2000/svg',
|
|
53
|
+
'svg'
|
|
54
|
+
)
|
|
55
|
+
newDefs.setAttribute('width', '0')
|
|
56
|
+
newDefs.setAttribute('height', '0')
|
|
57
|
+
newDefs.setAttribute('data-cy-icon-unified-defs', iconName)
|
|
58
|
+
newDefs.style.position = 'absolute'
|
|
59
|
+
newDefs.innerHTML = defs.value
|
|
60
|
+
document.body.appendChild(newDefs)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
return { shouldRenderDefs }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const compileVueIconProperties = (
|
|
67
|
+
opts: Ref<
|
|
68
|
+
OpenIconProps &
|
|
69
|
+
SVGAttributes & {
|
|
70
|
+
body: string
|
|
71
|
+
defs?: string
|
|
72
|
+
compiledClasses: string[]
|
|
73
|
+
size: string
|
|
74
|
+
interactiveColorsOnGroup?: boolean
|
|
28
75
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
>
|
|
77
|
+
) => {
|
|
78
|
+
const ret = computed(() => {
|
|
79
|
+
const {
|
|
80
|
+
name: iconName,
|
|
81
|
+
body,
|
|
82
|
+
defs,
|
|
83
|
+
compiledClasses,
|
|
84
|
+
size,
|
|
85
|
+
...attributes
|
|
86
|
+
} = opts.value
|
|
87
|
+
const filteredAttributes = Object.keys(attributes).reduce(
|
|
88
|
+
(newAttributes, attrName) => {
|
|
89
|
+
if (
|
|
90
|
+
!ICON_COLOR_PROP_NAMES.includes(
|
|
91
|
+
attrName as (typeof ICON_COLOR_PROP_NAMES)[number]
|
|
92
|
+
) &&
|
|
93
|
+
attrName !== 'name'
|
|
94
|
+
) {
|
|
95
|
+
// @ts-expect-error - TS doesn't know that attrName is a key of SVGAttributes
|
|
96
|
+
newAttributes[attrName] =
|
|
97
|
+
attributes[attrName as keyof typeof attributes]
|
|
98
|
+
}
|
|
99
|
+
return newAttributes
|
|
100
|
+
},
|
|
101
|
+
{} as Omit<SVGAttributes, 'name'>
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const iconFileId = `${iconName}_${size}`
|
|
105
|
+
|
|
106
|
+
const componentProps = {
|
|
107
|
+
width: size,
|
|
108
|
+
height: size,
|
|
109
|
+
viewBox: `0 0 ${size} ${size}`,
|
|
110
|
+
fill: 'none',
|
|
111
|
+
innerHTML: body,
|
|
112
|
+
class: undefined as string | undefined,
|
|
113
|
+
...filteredAttributes, // add all standard attributes back to the svg tag
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (compiledClasses.length) {
|
|
117
|
+
componentProps.class = compiledClasses.join(' ')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
componentProps,
|
|
122
|
+
iconFileId,
|
|
123
|
+
defs,
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
componentProps: computed(() => ret.value.componentProps),
|
|
129
|
+
defs: computed(() => ret.value.defs),
|
|
45
130
|
}
|
|
46
|
-
return componentProps
|
|
47
131
|
}
|
package/dist/Icon.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { OpenIconProps, IconProps } from '@cypress-design/icon-registry';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>;
|
|
2
|
+
declare const _default: (props: OpenIconProps & Pick<IconProps, "name"> & {
|
|
3
|
+
class?: string | undefined;
|
|
4
|
+
} & {}) => any;
|
|
6
5
|
export default _default;
|
|
7
6
|
//# sourceMappingURL=Icon.d.ts.map
|
package/dist/Icon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../Icon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../Icon.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;;;;AAQ7E,wBAwDC"}
|