1
1
import {
2
- Component ,
3
2
ComponentOptionsMixin ,
4
3
ComponentOptionsWithArrayProps ,
5
4
ComponentOptionsWithObjectProps ,
@@ -18,7 +17,8 @@ import {
18
17
createVNode ,
19
18
defineComponent ,
20
19
nextTick ,
21
- warn
20
+ warn ,
21
+ ComponentOptions
22
22
} from '@vue/runtime-core'
23
23
import { camelize , extend , hyphenate , isArray , toNumber } from '@vue/shared'
24
24
import { hydrate , render } from '.'
@@ -60,7 +60,7 @@ export function defineCustomElement<
60
60
Extends ,
61
61
E ,
62
62
EE
63
- >
63
+ > & { styles ?: string [ ] }
64
64
) : VueElementConstructor < Props >
65
65
66
66
// overload 3: object format with array props declaration
@@ -85,7 +85,7 @@ export function defineCustomElement<
85
85
Extends ,
86
86
E ,
87
87
EE
88
- >
88
+ > & { styles ?: string [ ] }
89
89
) : VueElementConstructor < { [ K in PropNames ] : any } >
90
90
91
91
// overload 4: object format with object props declaration
@@ -110,7 +110,7 @@ export function defineCustomElement<
110
110
Extends ,
111
111
E ,
112
112
EE
113
- >
113
+ > & { styles ?: string [ ] }
114
114
) : VueElementConstructor < ExtractPropTypes < PropsOptions > >
115
115
116
116
// overload 5: defining a custom element from the returned value of
@@ -176,7 +176,7 @@ export class VueElement extends BaseClass {
176
176
_connected = false
177
177
178
178
constructor (
179
- private _def : Component ,
179
+ private _def : ComponentOptions & { styles ?: string [ ] } ,
180
180
private _attrKeys : string [ ] ,
181
181
private _propKeys : string [ ] ,
182
182
hydrate ?: RootHydrateFunction
@@ -192,6 +192,13 @@ export class VueElement extends BaseClass {
192
192
)
193
193
}
194
194
this . attachShadow ( { mode : 'open' } )
195
+ if ( _def . styles ) {
196
+ _def . styles . forEach ( css => {
197
+ const s = document . createElement ( 'style' )
198
+ s . textContent = css
199
+ this . shadowRoot ! . appendChild ( s )
200
+ } )
201
+ }
195
202
}
196
203
}
197
204
0 commit comments