/* Magic paths are convenient for hiding the real path of a file. Use only JS, CSS and SCSS assets.
501299
public function MagicAssets($fake=false, $real=false) {
		if ( $fake !== false && $real !== false ) {
			$_SESSION['MAGIC'][$fake] = $real;
			return true;
		}

		if ( !empty($_SESSION['MAGIC']) ) {
			foreach($_SESSION['MAGIC'] as $symbol=>$link) {
				Base::instance()->route('GET|POST '.$symbol, function($f3) use ($symbol, $link) {	
					$ext = pathinfo($link, PATHINFO_EXTENSION);
					$filename = basename($link);
					$directory = $f3->get("ROOT").dirname($link)."/";
					if ( $ext == "js" ) {
						$js =  Web::instance()->minify($filename, null, true, $directory);
						$js = preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/', '', $js);
						header("Content-type: application/x-javascript");
						echo Template::instance()->resolve(Template::instance()->parse($js));
						exit();
					} elseif( $ext == "css" ) {
						header("Content-type: text/css");
					} else {
						header("Content-type: text/css");
						echo "/* SCSS currently disabled */";
						exit;
						$css = file_get_contents($directory.$filename);
						$js = str_replace("{{uuid}}", $f3->get("SESSION.uuid"), $js);
						$scss = new Compiler();
						echo $scss->compile($css);
						exit;
					}
					echo Template::instance()->resolve(Template::instance()->parse(file_get_contents($f3->get("ROOT").'/'.$link)));
					exit;
				});
			}
			return true;
		}
		return false;
	}
875774
function makeSpritePath(options, groups) {
	var base = options.spritePath;
	var file;

	// If is svg, do st
	if (groups.indexOf('GROUP_SVG_FLAG') > -1) {
		groups = _.filter(groups, function (item) {
			return item !== 'GROUP_SVG_FLAG';
		});
		file = path.resolve(base, groups.join('.') + '.svg');
	} else {
		file = path.resolve(base, groups.join('.') + '.png');
	}

	return file.replace('.@', options.retinaInfix);
}
569026
function resolveSassPath(sassPath, loadPaths, extensions) {
  // trim sass file extensions
  var re = new RegExp('(\.('+extensions.join('|')+'))$', 'i');
  var sassPathName = sassPath.replace(re, '');
  // check all load paths
  var i, j, length = loadPaths.length, scssPath, partialPath;
  for (i = 0; i < length; i++) {
    for (j = 0; j < extensions.length; j++) {
      scssPath = path.normalize(loadPaths[i] + '/' + sassPathName + '.' + extensions[j]);
      try {
        if (fs.lstatSync(scssPath).isFile()) {
          return scssPath;
        }
      } catch (e) {}
    }

    // special case for _partials
    for (j = 0; j < extensions.length; j++) {
      scssPath = path.normalize(loadPaths[i] + '/' + sassPathName + '.' + extensions[j]);
      partialPath = path.join(path.dirname(scssPath), '_' + path.basename(scssPath));
      try {
        if (fs.lstatSync(partialPath).isFile()) {
          return partialPath;
        }
      } catch (e) {}
    }
  }

  // File to import not found or unreadable so we assume this is a custom import
  return false;
}
714424
function realpath(dir) {
    return new Promise((resolve, reject) => {
        fs.realpath(dir, (err, path) => err ? reject(err) : resolve(path || dir));
    });
}
82908
function(filepath){
      filepath = filepath.replace(pathSepExp,'/'); // Use unix paths regardless. Makes these checks easier
      if(filepath &&
        (
          ( // If filepath has the jsIncludeDir, but does not include the node_modules directory under them
            filepath.match(expressions.jsIncludeDir)
            && !filepath.match(expressions.jsExcludeDir)
          )
          // Or the filepath has nothing to do with node_modules, app_modules/vendor
          || !filepath.match(expressions.jsAlwaysIncludeDir)
          || filepath.match(/node_modules(\\|\/)@polymer|node_modules(\\|\/)@webcomponents(\\|\/)shadycss/)
        )
      ) {
        // console.log('===================================')
        // console.log(filepath)
        // console.log('### Transpiling: '+filepath);
        return true;
      }
    }
730827
function replaceFilePaths () {
    // handle docs.js
    const filePath = path.join(__dirname, '/dist/docs/docs.js');
    const file = fs.readFileSync(filePath);
    const contents = file.toString()
        .replace(/http:\/\/localhost:8080\/angular-material/g, 'https://gitcdn.xyz/cdn/angular/bower-material/v' + newVersion + '/angular-material')
        .replace(/http:\/\/localhost:8080\/docs.css/g, 'https://material.angularjs.org/' + newVersion + '/docs.css');
    fs.writeFileSync(filePath, contents);
  }
683093
function file_path_to_web_path( file_path, root ) {
    return slash( path.join( '/', path.relative( root, file_path ) ) );
  }
103507
function inlinePng(rootFolder, currentFile, $) {
    var currentDirectory = path.dirname(currentFile);

    return editHTMLElement($, 'img', function($img) {
        var src = $img.attr('src');
        if (!LocationUtils.isDataURI(src)) {
            return;
        }

        // We avoid generating twice the same PNG
        var hash = crc.crc32(src).toString(16);
        var fileName = hash + '.png';

        // Result file path
        var filePath = path.join(rootFolder, fileName);

        return fs.assertFile(filePath, function() {
            return imagesUtil.convertInlinePNG(src, filePath);
        })
        .then(function() {
            // Convert filename to a relative filename
            fileName = LocationUtils.relative(currentDirectory, fileName);

            // Replace src
            $img.attr('src', fileName);
        });
    });
}
95265
function View_resolve(toPath, fromPath) {
            var file = di.normalizePath(toPath),
                themes = this.config.themes.slice(),
                theme,
                re,
                filePath,
                normalizers = this.normalizers.slice(),
                isNormalized = false,
                path,
                pathRegex,
                pathReplace,
                trace = [];

            // file name normalizers
            while (normalizers.length) {
                path = di.normalizePath(normalizers.shift());
                pathReplace = path.replace(/\\/g, '\\\\');
                pathRegex = new RegExp(pathReplace);
                if (file.match(pathRegex)) {
                    file = file.replace(pathRegex, '').replace(this.suffix, '');
                    isNormalized = true;
                    break;
                }
            }
            // try normalize fromPath
            if (!isNormalized && !!fromPath) {
                normalizers = this.normalizers.slice();
                fromPath = di.normalizePath(fromPath);
                // file name normalizers
                while (normalizers.length) {
                    path = di.normalizePath(normalizers.shift());
                    pathReplace = path.replace(/\\/g, '\\\\');
                    pathRegex = new RegExp(pathReplace);
                    if (fromPath.match(pathRegex)) {
                        isNormalized = true;
                        break;
                    }
                }
            }

            // check themes
            if (isNormalized) {
                while (themes.length) {
                    theme = di.normalizePath(themes.shift() + '/');
                    pathReplace = theme.replace(/\\/g, '\\\\');
                    re = new RegExp('^' + pathReplace);
                    file = file.replace(re, '');

                    filePath = di.normalizePath(path + theme + '/' + file + this.config.suffix);
                    if (this.isFile(filePath)) {
                        return filePath;
                    }
                    trace.push({
                        theme: theme,
                        path: path,
                        filePath: filePath
                    });
                }
            }


            throw new error.HttpError(500, {
                from: fromPath,
                load: toPath,
                filePath: filePath,
                paths: this.paths,
                isNormalized: isNormalized,
                file: file,
                path: path,
                trace: trace,
                themes: this.config.themes
            }, "View.resolve: template don't exists");
        }
1210212
function (srcPath, options) {
        _.defaults(options || (options = {}), DEFAULT_OPTIONS);
        var separator = options.separator;
        var extname = path.extname(srcPath);
        var reg = new RegExp('^.+' + separator + '(.+)((' + separator + '.+)|(@\\d+x))\\' + extname + '$');
        if (extname === '.styl' || extname === '.css') {
            reg = new RegExp('^.+' + separator + '(.+)\\' + extname + '$');
        }
        var result = path.basename(srcPath).match(reg);
        return result && result[1];
    }
318216
function(file) {
    var path = fis.util.realpath(file);
    if (path && this.deps[path]) {
      delete this.deps[path];
    }
    return this;
  }
659155
function rPath (htmlyFile, sourceFilepath) {
  htmlyFile = pathResolve(__dirname, htmlyFile)
  htmlyFile = pathRelative(dirname(sourceFilepath), htmlyFile)
  htmlyFile = slash(htmlyFile)
  if (!/^(\.|\/)/.test(htmlyFile)) {
    return './' + htmlyFile
  } else {
    return htmlyFile
  }
}
305240
public static void minify(String absolutePath) {
        if (absolutePath == null || absolutePath.contains(MIN)) {
            return;
        }

        if (config == null) {
            System.setProperty(Key.APPLICATION_CONFIG.toString(), basePath + Default.CONFIG_PATH.toString());
            config = new Config(Mode.DEV.toString());
        }

        if (config.isApplicationMinifyCSS() && absolutePath.endsWith(JS)) {
            minifyJS(new File(absolutePath));
        } else if (config.isApplicationMinifyJS() && absolutePath.endsWith(CSS)) {
            minifyCSS(new File(absolutePath));
        }
    }
1277667
function (res, path) {
                let defaultSrc = "default-src 'self';";
                let styleSrc = "style-src 'self' fonts.googleapis.com;";
                let fontSrc = "font-src 'self' fonts.gstatic.com;";
                let imgSrc = "img-src 'self' www.gravatar.com;";
                res.setHeader('Content-Security-Policy', `${defaultSrc} ${styleSrc} ${fontSrc} ${imgSrc}`);
              }
1044618
function realpath(path) {
  // /a/b/./c/./d ==> /a/b/c/d
  path = path.replace(DOT_RE, "/")

  /*
    @author wh1100717
    a//b/c ==> a/b/c
    a///b/////c ==> a/b/c
    DOUBLE_DOT_RE matches a/b/c//../d path correctly only if replace // with / first
  */
  path = path.replace(MULTI_SLASH_RE, "$1/")

  // a/b/c/../../d  ==>  a/b/../d  ==>  a/d
  while (path.match(DOUBLE_DOT_RE)) {
    path = path.replace(DOUBLE_DOT_RE, "/")
  }

  return path
}
491877
function pathWithSymlinks(path) {
                    var withSymlinks = path;
                    for (var real in realToSym) {
                        if (withSymlinks.indexOf(real) === 0) {
                            var symlink = realToSym[real];
                            withSymlinks = withSymlinks.replace(real, symlink);
                        }
                    }
                    return withSymlinks;
                }
621319
function(csspath,imgpath,absolute) {
        var host
            , cssroot
            , fullpath
            , url_parsed
            , opt = this.opt;


        url_parsed = mod_url.parse(imgpath);
        hash = url_parsed.hash;
        if(url_parsed.protocol && !url_parsed.protocol.match(/^http/)){
            return false;
        }
        if(absolute){
            fullpath = url_parsed.pathname;
            host = url_parsed.host;
        }else{
            cssroot = mod_path.dirname(csspath);
            fullpath = mod_path.join(cssroot,url_parsed.pathname);
        }

        var ext = mod_path.extname(fullpath);


        var name = fullpath.split(ext)[0];
        var version_match = name.match(/([\w\/\.\-\_]+)(\.v\d+)/);
        var version;
        if(version_match){
            version = version_match[2];
            name = version_match[1];
        }



        var real_full_path = fullpath;
            real_full_path = real_full_path.replace(/^(.*)(\.v\d+)+(\.(png|jpg|gif))$/,"$1$3");


        var warn_message;

        if(absolute){
            return false;
        }
        if(!grunt.file.exists(real_full_path)){
            warn_message  = "image not exists " + csspath + " -> " + fullpath;
            if(opt.allow_image_miss){
                grunt.log.warn(warn_message);
            }else{
                grunt.fail.warn(warn_message);
            }
            return false;
        }else{
            var parsed = {
                hash:hash,
                csspath:csspath,
                search:url_parsed.search,
                absolute:absolute,
                ext:ext,
                md5:mod_md5(grunt.file.read(real_full_path, { encoding: null })),
                name:name
            };
            parsed.host = (host || this.calculateCDNHost(
                mod_url.parse(this.connector(parsed)).pathname
            ));
            return parsed;
        }

    }