@@ -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 ) ;
@@ -213,11 +193,19 @@ function applyToTag(styleElement, obj) {
213
193
var media = obj . media ;
214
194
var sourceMap = obj . sourceMap ;
215
195
216
- if ( media ) {
217
- styleElement . setAttribute ( "media" , media )
196
+ if ( media ) {
197
+ styleElement . setAttribute ( "media" , media ) ;
198
+ }
199
+
200
+ if ( sourceMap ) {
201
+ // https://developer.chrome.com/devtools/docs/javascript-debugging
202
+ // this makes source maps inside style tags work properly in Chrome
203
+ css += '\n/*# sourceURL=' + sourceMap . sources [ 0 ] + ' */' ;
204
+ // http://stackoverflow.com/a/26603875
205
+ css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa ( unescape ( encodeURIComponent ( JSON . stringify ( sourceMap ) ) ) ) + " */" ;
218
206
}
219
207
220
- if ( styleElement . styleSheet ) {
208
+ if ( styleElement . styleSheet ) {
221
209
styleElement . styleSheet . cssText = css ;
222
210
} else {
223
211
while ( styleElement . firstChild ) {
@@ -226,23 +214,3 @@ function applyToTag(styleElement, obj) {
226
214
styleElement . appendChild ( document . createTextNode ( css ) ) ;
227
215
}
228
216
}
229
-
230
- function updateLink ( linkElement , obj ) {
231
- var css = obj . css ;
232
- var media = obj . media ;
233
- var sourceMap = obj . sourceMap ;
234
-
235
- if ( sourceMap ) {
236
- // http://stackoverflow.com/a/26603875
237
- css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa ( unescape ( encodeURIComponent ( JSON . stringify ( sourceMap ) ) ) ) + " */" ;
238
- }
239
-
240
- var blob = new Blob ( [ css ] , { type : "text/css" } ) ;
241
-
242
- var oldSrc = linkElement . href ;
243
-
244
- linkElement . href = URL . createObjectURL ( blob ) ;
245
-
246
- if ( oldSrc )
247
- URL . revokeObjectURL ( oldSrc ) ;
248
- }
0 commit comments