From 7be3b4893a16e40786d114d8853aa9d3105e8fd6 Mon Sep 17 00:00:00 2001 From: ChristianMayer Date: Sun, 18 Oct 2015 17:54:26 +0200 Subject: [PATCH] Remove files out of this directory as they moved to the main repository --- css-builder.js | 200 ------------------------------------------------- normalize.js | 141 ---------------------------------- 2 files changed, 341 deletions(-) delete mode 100644 css-builder.js delete mode 100644 normalize.js diff --git a/css-builder.js b/css-builder.js deleted file mode 100644 index e2bd36a..0000000 --- a/css-builder.js +++ /dev/null @@ -1,200 +0,0 @@ -define(['require', './normalize'], function(req, normalize) { - var cssAPI = {}; - - var isWindows = !!process.platform.match(/^win/); - - function compress(css) { - if (config.optimizeCss == 'none') { - return css; - } - if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) { - try { - var csso = require.nodeRequire('csso'); - } - catch(e) { - console.log('Compression module not installed. Use "npm install csso -g" to enable.'); - return css; - } - var csslen = css.length; - try { - css = csso.justDoIt(css); - } - catch(e) { - console.log('Compression failed due to a CSS syntax error.'); - return css; - } - console.log('Compressed CSS output to ' + Math.round(css.length / csslen * 100) + '%.'); - return css; - } - console.log('Compression not supported outside of nodejs environments.'); - return css; - } - - //load file code - stolen from text plugin - function loadFile(path) { - if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) { - var fs = require.nodeRequire('fs'); - var file = fs.readFileSync(path, 'utf8'); - if (file.indexOf('\uFEFF') === 0) - return file.substring(1); - return file; - } - else { - var file = new java.io.File(path), - lineSeparator = java.lang.System.getProperty("line.separator"), - input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), 'utf-8')), - stringBuffer, line; - try { - stringBuffer = new java.lang.StringBuffer(); - line = input.readLine(); - if (line && line.length() && line.charAt(0) === 0xfeff) - line = line.substring(1); - stringBuffer.append(line); - while ((line = input.readLine()) !== null) { - stringBuffer.append(lineSeparator).append(line); - } - return String(stringBuffer.toString()); - } - finally { - input.close(); - } - } - } - - - function saveFile(path, data) { - if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) { - var fs = require.nodeRequire('fs'); - fs.writeFileSync(path, data, 'utf8'); - } - else { - var content = new java.lang.String(data); - var output = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new java.io.FileOutputStream(path), 'utf-8')); - - try { - output.write(content, 0, content.length()); - output.flush(); - } - finally { - output.close(); - } - } - } - - //when adding to the link buffer, paths are normalised to the baseUrl - //when removing from the link buffer, paths are normalised to the output file path - function escape(content) { - return content.replace(/(["'\\])/g, '\\$1') - .replace(/[\f]/g, "\\f") - .replace(/[\b]/g, "\\b") - .replace(/[\n]/g, "\\n") - .replace(/[\t]/g, "\\t") - .replace(/[\r]/g, "\\r"); - } - - // NB add @media query support for media imports - var importRegEx = /@import\s*(url)?\s*(('([^']*)'|"([^"]*)")|\(('([^']*)'|"([^"]*)"|([^\)]*))\))\s*;?/g; - var absUrlRegEx = /^([^\:\/]+:\/)?\//; - - - var siteRoot; - - var baseParts = req.toUrl('base_url').split('/'); - baseParts[baseParts.length - 1] = ''; - var baseUrl = baseParts.join('/'); - - var curModule = 0; - var config; - - var layerBuffer = []; - var cssBuffer = {}; - - cssAPI.load = function(name, req, load, _config) { - - //store config - config = config || _config; - - if (!siteRoot) { - siteRoot = path.resolve(config.dir || path.dirname(config.out), config.siteRoot || '.') + '/'; - if (isWindows) - siteRoot = siteRoot.replace(/\\/g, '/'); - } - - //external URLS don't get added (just like JS requires) - if (name.match(absUrlRegEx)) - return load(); - - var fileUrl = req.toUrl(name + '.css'); - if (isWindows) - fileUrl = fileUrl.replace(/\\/g, '/'); - - // rebase to the output directory if based on the source directory; - // baseUrl points always to the output directory, fileUrl only if - // it is not prefixed by a computed path (relative too) - var fileSiteUrl = fileUrl; - if (fileSiteUrl.indexOf(baseUrl) < 0) { - var appRoot = req.toUrl(config.appDir); - if (isWindows) - appRoot = appRoot.replace(/\\/g, '/'); - if (fileSiteUrl.indexOf(appRoot) == 0) - fileSiteUrl = siteRoot + fileSiteUrl.substring(appRoot.length); - } - - //add to the buffer - cssBuffer[name] = normalize(loadFile(fileUrl), fileSiteUrl, siteRoot); - - load(); - } - - cssAPI.normalize = function(name, normalize) { - if (name.substr(name.length - 4, 4) == '.css') - name = name.substr(0, name.length - 4); - return normalize(name); - } - - cssAPI.write = function(pluginName, moduleName, write, parse) { - //external URLS don't get added (just like JS requires) - if (moduleName.match(absUrlRegEx)) - return; - - layerBuffer.push(cssBuffer[moduleName]); - - if (config.buildCSS != false) - write.asModule(pluginName + '!' + moduleName, 'define(function(){})'); - } - - cssAPI.onLayerEnd = function(write, data) { - if (config.separateCSS && config.IESelectorLimit) - throw 'RequireCSS: separateCSS option is not compatible with ensuring the IE selector limit'; - - if (config.separateCSS) { - var outPath = data.path.replace(/(\.js)?$/, '.css'); - console.log('Writing CSS! file: ' + outPath + '\n'); - - var css = layerBuffer.join(''); - - process.nextTick(function() { - if (fs.existsSync(outPath)) { - css = css + fs.readFileSync(outPath, {encoding: 'utf8'}); - } - saveFile(outPath, compress(css)); - }); - - } - else if (config.buildCSS != false) { - var styles = config.IESelectorLimit ? layerBuffer : [layerBuffer.join('')]; - for (var i = 0; i < styles.length; i++) { - if (styles[i] == '') - return; - write( - "(function(c){var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})\n" - + "('" + escape(compress(styles[i])) + "');\n" - ); - } - } - //clear layer buffer for next layer - layerBuffer = []; - } - - return cssAPI; -}); diff --git a/normalize.js b/normalize.js deleted file mode 100644 index bca1394..0000000 --- a/normalize.js +++ /dev/null @@ -1,141 +0,0 @@ -//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss) -/* - * css.normalize.js - * - * CSS Normalization - * - * CSS paths are normalized based on an optional basePath and the RequireJS config - * - * Usage: - * normalize(css, fromBasePath, toBasePath); - * - * css: the stylesheet content to normalize - * fromBasePath: the absolute base path of the css relative to any root (but without ../ backtracking) - * toBasePath: the absolute new base path of the css relative to the same root - * - * Absolute dependencies are left untouched. - * - * Urls in the CSS are picked up by regular expressions. - * These will catch all statements of the form: - * - * url(*) - * url('*') - * url("*") - * - * @import '*' - * @import "*" - * - * (and so also @import url(*) variations) - * - * For urls needing normalization - * - */ - -define(function() { - - // regular expression for removing double slashes - // eg http://www.example.com//my///url/here -> http://www.example.com/my/url/here - var slashes = /([^:])\/+/g - var removeDoubleSlashes = function(uri) { - return uri.replace(slashes, '$1/'); - } - - // given a relative URI, and two absolute base URIs, convert it from one base to another - var protocolRegEx = /[^\:\/]*:\/\/([^\/])*/; - var absUrlRegEx = /^(\/|data:)/; - function convertURIBase(uri, fromBase, toBase) { - if (uri.match(absUrlRegEx) || uri.match(protocolRegEx)) - return uri; - uri = removeDoubleSlashes(uri); - // if toBase specifies a protocol path, ensure this is the same protocol as fromBase, if not - // use absolute path at fromBase - var toBaseProtocol = toBase.match(protocolRegEx); - var fromBaseProtocol = fromBase.match(protocolRegEx); - if (fromBaseProtocol && (!toBaseProtocol || toBaseProtocol[1] != fromBaseProtocol[1] || toBaseProtocol[2] != fromBaseProtocol[2])) - return absoluteURI(uri, fromBase); - - else { - return relativeURI(absoluteURI(uri, fromBase), toBase); - } - }; - - // given a relative URI, calculate the absolute URI - function absoluteURI(uri, base) { - if (uri.substr(0, 2) == './') - uri = uri.substr(2); - - // absolute urls are left in tact - if (uri.match(absUrlRegEx) || uri.match(protocolRegEx)) - return uri; - - var baseParts = base.split('/'); - var uriParts = uri.split('/'); - - baseParts.pop(); - - while (curPart = uriParts.shift()) - if (curPart == '..') - baseParts.pop(); - else - baseParts.push(curPart); - - return baseParts.join('/'); - }; - - - // given an absolute URI, calculate the relative URI - function relativeURI(uri, base) { - - // reduce base and uri strings to just their difference string - var baseParts = base.split('/'); - baseParts.pop(); - base = baseParts.join('/') + '/'; - i = 0; - while (base.substr(i, 1) == uri.substr(i, 1)) - i++; - while (base.substr(i, 1) != '/') - i--; - base = base.substr(i + 1); - uri = uri.substr(i + 1); - - // each base folder difference is thus a backtrack - baseParts = base.split('/'); - var uriParts = uri.split('/'); - out = ''; - while (baseParts.shift()) - out += '../'; - - // finally add uri parts - while (curPart = uriParts.shift()) - out += curPart + '/'; - - return out.substr(0, out.length - 1); - }; - - var normalizeCSS = function(source, fromBase, toBase) { - - fromBase = removeDoubleSlashes(fromBase); - toBase = removeDoubleSlashes(toBase); - - var urlRegEx = /@import\s*("([^"]*)"|'([^']*)')|url\s*\((?!#)\s*(\s*"([^"]*)"|'([^']*)'|[^\)]*\s*)\s*\)/ig; - var result, url, source; - - while (result = urlRegEx.exec(source)) { - url = result[3] || result[2] || result[5] || result[6] || result[4]; - var newUrl; - newUrl = convertURIBase(url, fromBase, toBase); - var quoteLen = result[5] || result[6] ? 1 : 0; - source = source.substr(0, urlRegEx.lastIndex - url.length - quoteLen - 1) + newUrl + source.substr(urlRegEx.lastIndex - quoteLen - 1); - urlRegEx.lastIndex = urlRegEx.lastIndex + (newUrl.length - url.length); - } - - return source; - }; - - normalizeCSS.convertURIBase = convertURIBase; - normalizeCSS.absoluteURI = absoluteURI; - normalizeCSS.relativeURI = relativeURI; - - return normalizeCSS; -}); -//>>excludeEnd('excludeRequireCss')