11/* globals document */
2- const cssUrlMatcher = / u r l \s * \( \s * (? ! [ ' " ] d a t a ) ( [ ^ ) ] + ) \s * \) / gi;
2+ // Alert: this file will be used in users' app for ext:css plugin,
3+ // use plain ES5 JavaScript Syntax.
4+ var cssUrlMatcher = / u r l \s * \( \s * (? ! [ ' " ] d a t a ) ( [ ^ ) ] + ) \s * \) / gi;
35
46// copied from aurelia-templating-resources css-resource
57// This behaves differently from webpack's style-loader.
@@ -8,16 +10,17 @@ const cssUrlMatcher = /url\s*\(\s*(?!['"]data)([^) ]+)\s*\)/gi;
810// We inject css into a style tag on html head, it means the 'foo/hello.png'
911// is related to current url (not css url on link tag), or <base> tag in html
1012// head (which is recommended setup of aurelia-router if not using hash).
11- export function fixupCSSUrls ( address , css ) {
13+ function fixupCSSUrls ( address , css ) {
1214 if ( typeof css !== 'string' ) {
1315 throw new Error ( `Failed loading required CSS file: ${ address } ` ) ;
1416 }
15- return css . replace ( cssUrlMatcher , ( match , p1 ) => {
16- const quote = p1 . charAt ( 0 ) ;
17+
18+ return css . replace ( cssUrlMatcher , function ( match , p1 ) {
19+ var quote = p1 . charAt ( 0 ) ;
1720 if ( quote === '\'' || quote === '"' ) {
1821 p1 = p1 . substr ( 1 , p1 . length - 2 ) ;
1922 }
20- const absolutePath = absoluteModuleId ( address , p1 ) ;
23+ var absolutePath = absoluteModuleId ( address , p1 ) ;
2124 if ( absolutePath === p1 ) {
2225 return match ;
2326 }
@@ -28,30 +31,33 @@ export function fixupCSSUrls(address, css) {
2831function absoluteModuleId ( baseId , moduleId ) {
2932 if ( moduleId [ 0 ] !== '.' ) return moduleId ;
3033
31- let parts = baseId . split ( '/' ) ;
34+ var parts = baseId . split ( '/' ) ;
3235 parts . pop ( ) ;
3336
34- moduleId . split ( '/' ) . forEach ( p => {
35- if ( p === '.' ) return ;
37+ var mParts = moduleId . split ( '/' ) ;
38+ var p ;
39+
40+ for ( p of mParts ) {
41+ if ( p === '.' ) continue ;
3642 if ( p === '..' ) {
3743 parts . pop ( ) ;
38- return ;
44+ continue ;
3945 }
4046 parts . push ( p ) ;
41- } ) ;
47+ }
4248
4349 return parts . join ( '/' ) ;
4450}
4551
4652// copied from aurelia-pal-browser DOM.injectStyles
47- export function injectCSS ( css , id ) {
53+ function injectCSS ( css , id ) {
4854 if ( typeof document === 'undefined' || ! css ) return ;
4955 css = fixupCSSUrls ( id , css ) ;
5056
5157 if ( id ) {
52- let oldStyle = document . getElementById ( id ) ;
58+ var oldStyle = document . getElementById ( id ) ;
5359 if ( oldStyle ) {
54- let isStyleTag = oldStyle . tagName . toLowerCase ( ) === 'style' ;
60+ var isStyleTag = oldStyle . tagName . toLowerCase ( ) === 'style' ;
5561
5662 if ( isStyleTag ) {
5763 oldStyle . innerHTML = css ;
@@ -62,7 +68,7 @@ export function injectCSS(css, id) {
6268 }
6369 }
6470
65- let node = document . createElement ( 'style' ) ;
71+ var node = document . createElement ( 'style' ) ;
6672 node . innerHTML = css ;
6773 node . type = 'text/css' ;
6874
@@ -74,9 +80,13 @@ export function injectCSS(css, id) {
7480}
7581
7682// dumber-module-loader plugin ext:css
77- export function load ( name , req , load ) {
78- req ( [ 'text!' + name ] , text => {
83+ function load ( name , req , load ) {
84+ req ( [ 'text!' + name ] , function ( text ) {
7985 injectCSS ( text , name ) ;
8086 load ( text ) ;
8187 } ) ;
82- }
88+ }
89+
90+ exports . fixupCSSUrls = fixupCSSUrls ;
91+ exports . injectCSS = injectCSS ;
92+ exports . load = load ;
0 commit comments