@@ -133,13 +133,6 @@ function createStyleElement(options) {
133
133
return styleElement ;
134
134
}
135
135
136
- function createLinkElement ( options ) {
137
- var linkElement = document . createElement ( "link" ) ;
138
- linkElement . rel = "stylesheet" ;
139
- insertStyleElement ( options , linkElement ) ;
140
- return linkElement ;
141
- }
142
-
143
136
function addStyle ( obj , options ) {
144
137
var styleElement , update , remove ;
145
138
@@ -148,19 +141,6 @@ function addStyle(obj, options) {
148
141
styleElement = singletonElement || ( singletonElement = createStyleElement ( options ) ) ;
149
142
update = applyToSingletonTag . bind ( null , styleElement , styleIndex , false ) ;
150
143
remove = applyToSingletonTag . bind ( null , styleElement , styleIndex , true ) ;
151
- } else if ( obj . sourceMap &&
152
- typeof URL === "function" &&
153
- typeof URL . createObjectURL === "function" &&
154
- typeof URL . revokeObjectURL === "function" &&
155
- typeof Blob === "function" &&
156
- typeof btoa === "function" ) {
157
- styleElement = createLinkElement ( options ) ;
158
- update = updateLink . bind ( null , styleElement ) ;
159
- remove = function ( ) {
160
- removeStyleElement ( styleElement ) ;
161
- if ( styleElement . href )
162
- URL . revokeObjectURL ( styleElement . href ) ;
163
- } ;
164
144
} else {
165
145
styleElement = createStyleElement ( options ) ;
166
146
update = applyToTag . bind ( null , styleElement ) ;
@@ -212,11 +192,19 @@ function applyToTag(styleElement, obj) {
212
192
var css = obj . css ;
213
193
var media = obj . media ;
214
194
215
- if ( media ) {
216
- styleElement . setAttribute ( "media" , media )
195
+ if ( media ) {
196
+ styleElement . setAttribute ( "media" , media ) ;
217
197
}
218
198
219
- if ( styleElement . styleSheet ) {
199
+ if ( sourceMap ) {
200
+ // https://developer.chrome.com/devtools/docs/javascript-debugging
201
+ // this makes source maps inside style tags work properly in Chrome
202
+ css += '\n/*# sourceURL=' + sourceMap . sources [ 0 ] + ' */' ;
203
+ // http://stackoverflow.com/a/26603875
204
+ css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa ( unescape ( encodeURIComponent ( JSON . stringify ( sourceMap ) ) ) ) + " */" ;
205
+ }
206
+
207
+ if ( styleElement . styleSheet ) {
220
208
styleElement . styleSheet . cssText = css ;
221
209
} else {
222
210
while ( styleElement . firstChild ) {
@@ -225,22 +213,3 @@ function applyToTag(styleElement, obj) {
225
213
styleElement . appendChild ( document . createTextNode ( css ) ) ;
226
214
}
227
215
}
228
-
229
- function updateLink ( linkElement , obj ) {
230
- var css = obj . css ;
231
- var sourceMap = obj . sourceMap ;
232
-
233
- if ( sourceMap ) {
234
- // http://stackoverflow.com/a/26603875
235
- css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa ( unescape ( encodeURIComponent ( JSON . stringify ( sourceMap ) ) ) ) + " */" ;
236
- }
237
-
238
- var blob = new Blob ( [ css ] , { type : "text/css" } ) ;
239
-
240
- var oldSrc = linkElement . href ;
241
-
242
- linkElement . href = URL . createObjectURL ( blob ) ;
243
-
244
- if ( oldSrc )
245
- URL . revokeObjectURL ( oldSrc ) ;
246
- }
0 commit comments