1
- import clsx from 'clsx'
2
- import { mergeProps , SetupContext , h , Fragment } from 'vue'
3
- import { CSSInterpolation , serializeStyles } from '@emotion/serialize'
4
- import { extractStyleAttrs } from '@chakra-ui/vue-utils'
5
- import { getRegisteredStyles , insertStyles , SerializedStyles } from '@emotion/utils'
6
- import camelCase from 'lodash.camelcase'
7
- import { CreateStyled , PrivateStyledComponent , StyledOptions } from './types'
8
- import { defaultCache , __unusafe_useEmotionCache } from './cache'
9
- import { useEmotionTheme } from './theming'
10
- import memoize from 'lodash.memoize'
1
+ import clsx from "clsx"
2
+ import { mergeProps , SetupContext , h , Fragment } from "vue"
3
+ import { CSSInterpolation , serializeStyles } from "@emotion/serialize"
4
+ import { extractStyleAttrs } from "@chakra-ui/vue-utils"
5
+ import {
6
+ getRegisteredStyles ,
7
+ insertStyles ,
8
+ SerializedStyles ,
9
+ } from "@emotion/utils"
10
+ import camelCase from "lodash.camelcase"
11
+ import { CreateStyled , PrivateStyledComponent , StyledOptions } from "./types"
12
+ import { defaultCache , __unusafe_useEmotionCache } from "./cache"
13
+ import { useEmotionTheme } from "./theming"
14
+ import memoize from "lodash.memoize"
11
15
12
16
const ILLEGAL_ESCAPE_SEQUENCE_ERROR = `You have illegal escape sequence in your template literal, most likely inside content's property value.
13
17
Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';".
14
18
You can read more about this here:
15
19
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences`
16
20
17
- let isBrowser = typeof document !== ' undefined'
21
+ let isBrowser = typeof document !== " undefined"
18
22
19
23
const Noop = ( ) => null
20
24
const camelCaseCache : any = { }
21
25
22
26
const _camelCase = memoize ( ( key ) => camelCase ( key ) )
23
27
24
28
// @ts -ignore
25
- export const createStyled : CreateStyled = ( tag : any , options ?: StyledOptions ) => {
26
- if ( process . env . NODE_ENV !== 'production' ) {
29
+ export const createStyled : CreateStyled = (
30
+ tag : any ,
31
+ options ?: StyledOptions
32
+ ) => {
33
+ if ( process . env . NODE_ENV !== "production" ) {
27
34
if ( tag === undefined ) {
28
35
throw new Error (
29
- ' You are trying to create a styled element with an undefined component.\nYou may have forgotten to import it.'
36
+ " You are trying to create a styled element with an undefined component.\nYou may have forgotten to import it."
30
37
)
31
38
}
32
39
}
@@ -42,7 +49,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
42
49
}
43
50
44
51
// Extract arguments from template literals
45
- return function < Props > ( ) : PrivateStyledComponent < Props > {
52
+ return function < Props > ( ) : PrivateStyledComponent < Props > {
46
53
let args = arguments
47
54
let styles =
48
55
isReal && tag . __emotion_styles !== undefined
@@ -55,27 +62,34 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
55
62
if ( args [ 0 ] == null || args [ 0 ] . raw === undefined ) {
56
63
styles . push . apply ( styles , args )
57
64
} else {
58
- if ( process . env . NODE_ENV !== ' production' && args [ 0 ] [ 0 ] === undefined ) {
65
+ if ( process . env . NODE_ENV !== " production" && args [ 0 ] [ 0 ] === undefined ) {
59
66
console . error ( ILLEGAL_ESCAPE_SEQUENCE_ERROR )
60
67
}
61
68
styles . push ( args [ 0 ] [ 0 ] )
62
69
let len = args . length
63
70
let i = 1
64
71
for ( ; i < len ; i ++ ) {
65
- if ( process . env . NODE_ENV !== ' production' && args [ 0 ] [ i ] === undefined ) {
72
+ if ( process . env . NODE_ENV !== " production" && args [ 0 ] [ i ] === undefined ) {
66
73
console . error ( ILLEGAL_ESCAPE_SEQUENCE_ERROR )
67
74
}
68
75
styles . push ( args [ i ] , args [ 0 ] [ i ] )
69
76
}
70
77
}
71
78
72
- function StyledComponent ( props : any , { attrs, expose, slots } : SetupContext ) {
79
+ function StyledComponent (
80
+ props : any ,
81
+ { attrs, expose, slots } : SetupContext
82
+ ) {
73
83
const cache = __unusafe_useEmotionCache ( defaultCache )
74
84
const { as, ...restAttrs } = attrs || { }
75
85
76
86
let mergedProps = { ...props , ...restAttrs }
77
87
78
- let className = options ?. __label ? `${ cache . key } -${ options ?. __label || typeof tag === 'string' ? tag : 'element' } ` : ``
88
+ let className = options ?. __label
89
+ ? `${ cache . key } -${
90
+ options ?. __label || typeof tag === "string" ? tag : "element"
91
+ } `
92
+ : ``
79
93
const FinalTag = as || baseTag
80
94
const classInterpolations = [ ] as string [ ]
81
95
@@ -98,7 +112,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
98
112
...attrs ,
99
113
...mergedProps ,
100
114
} )
101
-
115
+
102
116
if ( attrs . class ) {
103
117
className += getRegisteredStyles (
104
118
cache . registered ,
@@ -116,14 +130,13 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
116
130
const rules = insertStyles (
117
131
cache ,
118
132
serialized ,
119
- typeof FinalTag === ' string'
133
+ typeof FinalTag === " string"
120
134
)
121
135
122
136
className += `${ cache . key } -${ serialized . name } `
123
- if ( targetClassName !== undefined ) {
124
- className += ` ${ targetClassName } `
125
- }
126
-
137
+ if ( targetClassName !== undefined ) {
138
+ className += ` ${ targetClassName } `
139
+ }
127
140
128
141
const { attrs : htmlAttrs } = extractStyleAttrs ( mergedProps )
129
142
const vnodeProps = {
@@ -133,25 +146,21 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
133
146
// @ts -expect-error
134
147
delete vnodeProps ?. theme
135
148
136
- const StyledElement = (
137
- < FinalTag { ...vnodeProps } >
138
- { slots }
139
- </ FinalTag >
140
- )
141
-
149
+ const StyledElement = < FinalTag { ...vnodeProps } > { slots } </ FinalTag >
150
+
142
151
let possiblyStyleElement = < Noop />
143
152
if ( ! isBrowser && rules !== undefined ) {
144
153
let serializedNames = serialized . name
145
154
let next = serialized . next
146
155
while ( next !== undefined ) {
147
- serializedNames += ' ' + next . name
156
+ serializedNames += " " + next . name
148
157
next = next . next
149
158
}
150
159
possiblyStyleElement = (
151
160
< style
152
161
{ ...{
153
162
[ `data-emotion` ] : `${ cache . key } ${ serializedNames } ` ,
154
- nonce : cache . sheet . nonce
163
+ nonce : cache . sheet . nonce ,
155
164
} }
156
165
>
157
166
{ rules }
@@ -167,36 +176,39 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
167
176
}
168
177
169
178
StyledComponent . _name =
170
- identifierName === undefined ?
171
- `Styled${
172
- typeof baseTag === ' string' ? baseTag : baseTag . name || ' Component'
173
- } ` :
174
- identifierName
179
+ identifierName === undefined
180
+ ? `Styled${
181
+ typeof baseTag === " string" ? baseTag : baseTag . name || " Component"
182
+ } `
183
+ : identifierName
175
184
176
185
StyledComponent . __emotion_real = StyledComponent
177
186
StyledComponent . __emotion_base = baseTag
178
187
StyledComponent . __emotion_styles = styles
179
188
180
- Object . defineProperty ( StyledComponent , ' toString' , {
189
+ Object . defineProperty ( StyledComponent , " toString" , {
181
190
value ( ) {
182
191
if (
183
192
targetClassName === undefined &&
184
- process . env . NODE_ENV !== ' production'
193
+ process . env . NODE_ENV !== " production"
185
194
) {
186
- return ' NO_COMPONENT_SELECTOR'
195
+ return " NO_COMPONENT_SELECTOR"
187
196
}
188
197
189
198
return `.${ targetClassName } `
190
- }
199
+ } ,
191
200
} )
192
201
193
- StyledComponent . withComponent = ( nextTag : any , nextOptions : StyledOptions ) => {
202
+ StyledComponent . withComponent = (
203
+ nextTag : any ,
204
+ nextOptions : StyledOptions
205
+ ) => {
194
206
return createStyled (
195
207
nextTag ,
196
- nextOptions === undefined ?
197
- options :
198
- { ...( options || { } ) , ...nextOptions }
199
- // Here we use apply to make TypeScript happy. Otherwise we would use spread operator
208
+ nextOptions === undefined
209
+ ? options
210
+ : { ...( options || { } ) , ...nextOptions }
211
+ // Here we use apply to make TypeScript happy. Otherwise we would use spread operator
200
212
) . apply ( null , styles )
201
213
}
202
214
@@ -205,6 +217,8 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
205
217
}
206
218
}
207
219
208
- export function css ( ...args : Array < CSSInterpolation | TemplateStringsArray > ) : SerializedStyles {
220
+ export function css (
221
+ ...args : Array < CSSInterpolation | TemplateStringsArray >
222
+ ) : SerializedStyles {
209
223
return serializeStyles ( args , { } )
210
- }
224
+ }
0 commit comments