diff --git a/README.md b/README.md index b8c8b2b..1bceaa7 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ## Updated! -Feb. 9, 2020 +Feb. 17, 2020
-Be sure to check out the new features (and bug fixes!) that Facebook added to [v3.3.1](https://github.com/facebook/create-react-app/releases/tag/v3.3.1) of `Create-React-App`. +Be sure to check out the new features (and bug fixes!) that Facebook added to [v3.4.0](https://github.com/facebook/create-react-app/releases/tag/v3.4.0) of `Create-React-App`. ## Good to Know! -[Create-React-App](https://create-react-app.dev/) is **more than** just **React.** `Create-React-App` is a full stack of tested and battle-hardened tools, guaranteed to be configured correctly to work together to make your job easier. +[Create-React-App](https://create-react-app.dev/) is **more than** just **React.** `Create-React-App` is a suite of battle-hardened tools, guaranteed to be configured correctly to work together to make your job easier. **No need for weird CORS setups** or server proxies. **Why in the world** would you want to **maintain two servers** anyway? No need for that, just use `Create-React-WPTheme` instead. The biggest difference between `Create-React-WPTheme` and `Create-React-App` is that this project here **uses your WordPress server as the development server instead of the Webpack Dev Server.** diff --git a/packages/cra-template-wptheme-typescript/package.json b/packages/cra-template-wptheme-typescript/package.json index 06e66f5..65d6a02 100644 --- a/packages/cra-template-wptheme-typescript/package.json +++ b/packages/cra-template-wptheme-typescript/package.json @@ -1,6 +1,6 @@ { "name": "cra-template-wptheme-typescript", - "version": "3.3.1-wp.1", + "version": "3.4.0-wp.3", "keywords": [ "react", "create-react-app", diff --git a/packages/cra-template-wptheme-typescript/template/README.md b/packages/cra-template-wptheme-typescript/template/README.md index a31481c..74735dc 100644 --- a/packages/cra-template-wptheme-typescript/template/README.md +++ b/packages/cra-template-wptheme-typescript/template/README.md @@ -33,7 +33,7 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. diff --git a/packages/cra-template-wptheme-typescript/template/src/App.tsx b/packages/cra-template-wptheme-typescript/template/src/App.tsx index 3cd5ee2..4bf8d55 100644 --- a/packages/cra-template-wptheme-typescript/template/src/App.tsx +++ b/packages/cra-template-wptheme-typescript/template/src/App.tsx @@ -1,26 +1,21 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React from "react"; +import logo from "./logo.svg"; +import "./App.css"; -const App = () => { - return ( -
-
- logo -

- Edit react-src/src/App.tsx and save to reload. -

- - Learn React - -
-
- ); +function App() { + return ( +
+
+ logo +

+ Edit react-src/src/App.tsx and save to reload. +

+ + Learn React + +
+
+ ); } export default App; diff --git a/packages/cra-template-wptheme-typescript/template/src/index.tsx b/packages/cra-template-wptheme-typescript/template/src/index.tsx index 825db58..48da9f6 100644 --- a/packages/cra-template-wptheme-typescript/template/src/index.tsx +++ b/packages/cra-template-wptheme-typescript/template/src/index.tsx @@ -1,12 +1,12 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -// import * as serviceWorker from './serviceWorker'; +import React from "react"; +import ReactDOM from "react-dom"; +import "./index.css"; +import App from "./App"; +import * as serviceWorker from "./serviceWorker"; -ReactDOM.render(, document.getElementById('root')); +ReactDOM.render(, document.getElementById("root")); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA -// serviceWorker.unregister(); +serviceWorker.unregister(); diff --git a/packages/cra-template-wptheme-typescript/template/src/serviceWorker.ts b/packages/cra-template-wptheme-typescript/template/src/serviceWorker.ts index d5f0275..b09523f 100644 --- a/packages/cra-template-wptheme-typescript/template/src/serviceWorker.ts +++ b/packages/cra-template-wptheme-typescript/template/src/serviceWorker.ts @@ -138,8 +138,12 @@ function checkValidServiceWorker(swUrl: string, config?: Config) { export function unregister() { if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then(registration => { - registration.unregister(); - }); + navigator.serviceWorker.ready + .then(registration => { + registration.unregister(); + }) + .catch(error => { + console.error(error.message); + }); } } diff --git a/packages/cra-template-wptheme/package.json b/packages/cra-template-wptheme/package.json index cdd8f1f..34d1e5a 100644 --- a/packages/cra-template-wptheme/package.json +++ b/packages/cra-template-wptheme/package.json @@ -1,6 +1,6 @@ { "name": "cra-template-wptheme", - "version": "3.3.1-wp.1", + "version": "3.4.0-wp.2", "keywords": [ "wordpress", "create-react-app", diff --git a/packages/cra-template-wptheme/template/README.md b/packages/cra-template-wptheme/template/README.md index 859d27a..54ef094 100644 --- a/packages/cra-template-wptheme/template/README.md +++ b/packages/cra-template-wptheme/template/README.md @@ -33,7 +33,7 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. diff --git a/packages/cra-template-wptheme/template/src/App.js b/packages/cra-template-wptheme/template/src/App.js index e55c89f..f31200d 100644 --- a/packages/cra-template-wptheme/template/src/App.js +++ b/packages/cra-template-wptheme/template/src/App.js @@ -1,26 +1,21 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React from "react"; +import logo from "./logo.svg"; +import "./App.css"; function App() { - return ( -
-
- logo -

- Edit react-src/src/App.js and save to reload. -

- - Learn React - -
-
- ); + return ( +
+
+ logo +

+ Edit react-src/src/App.js and save to reload. +

+ + Learn React + +
+
+ ); } export default App; diff --git a/packages/cra-template-wptheme/template/src/index.js b/packages/cra-template-wptheme/template/src/index.js index 825db58..48da9f6 100644 --- a/packages/cra-template-wptheme/template/src/index.js +++ b/packages/cra-template-wptheme/template/src/index.js @@ -1,12 +1,12 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -// import * as serviceWorker from './serviceWorker'; +import React from "react"; +import ReactDOM from "react-dom"; +import "./index.css"; +import App from "./App"; +import * as serviceWorker from "./serviceWorker"; -ReactDOM.render(, document.getElementById('root')); +ReactDOM.render(, document.getElementById("root")); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA -// serviceWorker.unregister(); +serviceWorker.unregister(); diff --git a/packages/cra-template-wptheme/template/src/serviceWorker.js b/packages/cra-template-wptheme/template/src/serviceWorker.js index 8703ddb..c4838eb 100644 --- a/packages/cra-template-wptheme/template/src/serviceWorker.js +++ b/packages/cra-template-wptheme/template/src/serviceWorker.js @@ -130,8 +130,12 @@ function checkValidServiceWorker(swUrl, config) { export function unregister() { if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then(registration => { - registration.unregister(); - }); + navigator.serviceWorker.ready + .then(registration => { + registration.unregister(); + }) + .catch(error => { + console.error(error.message); + }); } } diff --git a/packages/create-react-wptheme-utils/create-react-wptheme-error-overlay/package.json b/packages/create-react-wptheme-utils/create-react-wptheme-error-overlay/package.json index 45fa2d6..6f13991 100644 --- a/packages/create-react-wptheme-utils/create-react-wptheme-error-overlay/package.json +++ b/packages/create-react-wptheme-utils/create-react-wptheme-error-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@devloco/create-react-wptheme-error-overlay", - "version": "3.3.1-wp.1", + "version": "3.4.0-wp.1", "description": "create-react-wptheme client with error overlay", "main": "wptheme-error-overlay.js", "scripts": { @@ -17,15 +17,15 @@ "wpThemeErrorOverlay.js" ], "dependencies": { - "react-dev-utils": "^10.1.0", - "react-error-overlay": "^6.0.5" + "react-dev-utils": "^10.2.0", + "react-error-overlay": "^6.0.6" }, "devDependencies": { "@babel/code-frame": "^7.8.3", "@babel/core": "^7.8.4", "@webpack-cli/info": "^0.2.0", "babel-loader": "^8.0.6", - "webpack": "^4.41.5", - "webpack-cli": "^3.3.10" + "webpack": "^4.41.6", + "webpack-cli": "^3.3.11" } } diff --git a/packages/create-react-wptheme-utils/getPublicUrlOrPath.js b/packages/create-react-wptheme-utils/getPublicUrlOrPath.js new file mode 100644 index 0000000..e6036d9 --- /dev/null +++ b/packages/create-react-wptheme-utils/getPublicUrlOrPath.js @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +"use strict"; + +const { URL } = require("url"); + +module.exports = getPublicUrlOrPath; + +/** + * Returns a URL or a path with slash at the end + * In production can be URL, abolute path, relative path + * In development always will be an absolute path + * In development can use `path` module functions for operations + * + * @param {boolean} craIsEnvDevelopment; unused + * @param {(string|undefined)} homepage a valid url or pathname + * @param {(string|undefined)} envPublicUrl a valid url or pathname + * @returns {string} + */ +function getPublicUrlOrPath(craIsEnvDevelopment, homepage, envPublicUrl) { + const isEnvDevelopment = false; // create-react-wptheme always uses PROD paths. + const stubDomain = "https://create-react-wptheme.dev"; + + if (envPublicUrl) { + // ensure last slash exists + envPublicUrl = envPublicUrl.endsWith("/") ? envPublicUrl : envPublicUrl + "/"; + + // validate if `envPublicUrl` is a URL or path like + // `stubDomain` is ignored if `envPublicUrl` contains a domain + const validPublicUrl = new URL(envPublicUrl, stubDomain); + + return isEnvDevelopment + ? envPublicUrl.startsWith(".") + ? "/" + : validPublicUrl.pathname + : // Some apps do not use client-side routing with pushState. + // For these, "homepage" can be set to "." to enable relative asset paths. + envPublicUrl; + } + + if (homepage) { + // strip last slash if exists + homepage = homepage.endsWith("/") ? homepage : homepage + "/"; + + // validate if `homepage` is a URL or path like and use just pathname + const validHomepagePathname = new URL(homepage, stubDomain).pathname; + return isEnvDevelopment + ? homepage.startsWith(".") + ? "/" + : validHomepagePathname + : // Some apps do not use client-side routing with pushState. + // For these, "homepage" can be set to "." to enable relative asset paths. + homepage.startsWith(".") + ? homepage + : validHomepagePathname; + } + + return "/"; +} diff --git a/packages/create-react-wptheme-utils/package.json b/packages/create-react-wptheme-utils/package.json index 1bf9f33..56cfd90 100644 --- a/packages/create-react-wptheme-utils/package.json +++ b/packages/create-react-wptheme-utils/package.json @@ -1,6 +1,6 @@ { "name": "@devloco/create-react-wptheme-utils", - "version": "3.3.1-wp.1", + "version": "3.4.0-wp.1", "description": "Utilities used by create-react-wptheme.", "engines": { "node": ">=8" @@ -20,6 +20,7 @@ "files": [ "fileFunctions.js", "fileWatcherPlugin.js", + "getPublicUrlOrPath.js", "getUserConfig.js", "postInstallerInfo.js", "shell-js.js", @@ -28,7 +29,7 @@ "wpThemeServer.js" ], "dependencies": { - "chalk": "^3.0.0", + "chalk": "2.4.2", "chokidar": "^3.3.1", "shelljs": "^0.8.3", "fs-extra": "^8.1.0", diff --git a/packages/create-react-wptheme-utils/wpThemeErrorOverlay.js b/packages/create-react-wptheme-utils/wpThemeErrorOverlay.js index 6be5f5f..dd36060 100644 --- a/packages/create-react-wptheme-utils/wpThemeErrorOverlay.js +++ b/packages/create-react-wptheme-utils/wpThemeErrorOverlay.js @@ -204,11 +204,12 @@ function handleErrors(errors) { "use strict"; -var ansiRegex = __webpack_require__(2)(); +const ansiRegex = __webpack_require__(2); -module.exports = function (str) { - return typeof str === 'string' ? str.replace(ansiRegex, '') : str; -}; +const stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string; + +module.exports = stripAnsi; +module.exports.default = stripAnsi; /***/ }), @@ -217,8 +218,18 @@ module.exports = function (str) { "use strict"; -module.exports = function () { - return /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g; + +module.exports = options => { + options = Object.assign({ + onlyFirst: false + }, options); + + const pattern = [ + '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', + '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' + ].join('|'); + + return new RegExp(pattern, options.onlyFirst ? undefined : 'g'); }; @@ -444,7 +455,7 @@ function isLikelyASyntaxError(message) { function formatMessage(message) { let lines = message.split('\n'); - // Strip Webpack-added headers off errors/warnings + // Strip webpack-added headers off errors/warnings // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line)); @@ -511,7 +522,7 @@ function formatMessage(message) { message = lines.join('\n'); // Internal stacks are generally useless so we strip them... with the // exception of stacks containing `webpack:` because they're normally - // from user code generated by Webpack. For more information see + // from user code generated by webpack. For more information see // https://github.com/facebook/create-react-app/pull/1050 message = message.replace( /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, @@ -554,304 +565,276 @@ module.exports = formatWebpackMessages; /***/ (function(module, exports, __webpack_require__) { "use strict"; +/* WEBPACK VAR INJECTION */(function(process) { +const escapeStringRegexp = __webpack_require__(7); +const ansiStyles = __webpack_require__(8); +const stdoutColor = __webpack_require__(14).stdout; -const ansiStyles = __webpack_require__(7); -const {stdout: stdoutColor, stderr: stderrColor} = __webpack_require__(13); -const { - stringReplaceAll, - stringEncaseCRLFWithFirstIndex -} = __webpack_require__(14); +const template = __webpack_require__(15); + +const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping -const levelMapping = [ - 'ansi', - 'ansi', - 'ansi256', - 'ansi16m' -]; +const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; + +// `color-convert` models to exclude from the Chalk API due to conflicts and such +const skipModels = new Set(['gray']); const styles = Object.create(null); -const applyOptions = (object, options = {}) => { - if (options.level > 3 || options.level < 0) { - throw new Error('The `level` option should be an integer from 0 to 3'); - } +function applyOptions(obj, options) { + options = options || {}; // Detect level if not set manually - const colorLevel = stdoutColor ? stdoutColor.level : 0; - object.level = options.level === undefined ? colorLevel : options.level; -}; - -class ChalkClass { - constructor(options) { - return chalkFactory(options); - } + const scLevel = stdoutColor ? stdoutColor.level : 0; + obj.level = options.level === undefined ? scLevel : options.level; + obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0; } -const chalkFactory = options => { - const chalk = {}; - applyOptions(chalk, options); - - chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_); +function Chalk(options) { + // We check for this.template here since calling `chalk.constructor()` + // by itself will have a `this` of a previously constructed chalk object + if (!this || !(this instanceof Chalk) || this.template) { + const chalk = {}; + applyOptions(chalk, options); + + chalk.template = function () { + const args = [].slice.call(arguments); + return chalkTag.apply(null, [chalk.template].concat(args)); + }; - Object.setPrototypeOf(chalk, Chalk.prototype); - Object.setPrototypeOf(chalk.template, chalk); + Object.setPrototypeOf(chalk, Chalk.prototype); + Object.setPrototypeOf(chalk.template, chalk); - chalk.template.constructor = () => { - throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.'); - }; + chalk.template.constructor = Chalk; - chalk.template.Instance = ChalkClass; + return chalk.template; + } - return chalk.template; -}; + applyOptions(this, options); +} -function Chalk(options) { - return chalkFactory(options); +// Use bright blue on Windows as the normal blue color is illegible +if (isSimpleWindowsTerm) { + ansiStyles.blue.open = '\u001B[94m'; } -for (const [styleName, style] of Object.entries(ansiStyles)) { - styles[styleName] = { +for (const key of Object.keys(ansiStyles)) { + ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); + + styles[key] = { get() { - const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty); - Object.defineProperty(this, styleName, {value: builder}); - return builder; + const codes = ansiStyles[key]; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key); } }; } styles.visible = { get() { - const builder = createBuilder(this, this._styler, true); - Object.defineProperty(this, 'visible', {value: builder}); - return builder; + return build.call(this, this._styles || [], true, 'visible'); } }; -const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256']; +ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g'); +for (const model of Object.keys(ansiStyles.color.ansi)) { + if (skipModels.has(model)) { + continue; + } -for (const model of usedModels) { styles[model] = { get() { - const {level} = this; - return function (...arguments_) { - const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler); - return createBuilder(this, styler, this._isEmpty); + const level = this.level; + return function () { + const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.color.close, + closeRe: ansiStyles.color.closeRe + }; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); }; } }; } -for (const model of usedModels) { +ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g'); +for (const model of Object.keys(ansiStyles.bgColor.ansi)) { + if (skipModels.has(model)) { + continue; + } + const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); styles[bgModel] = { get() { - const {level} = this; - return function (...arguments_) { - const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler); - return createBuilder(this, styler, this._isEmpty); + const level = this.level; + return function () { + const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.bgColor.close, + closeRe: ansiStyles.bgColor.closeRe + }; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); }; } }; } -const proto = Object.defineProperties(() => {}, { - ...styles, - level: { +const proto = Object.defineProperties(() => {}, styles); + +function build(_styles, _empty, key) { + const builder = function () { + return applyStyle.apply(builder, arguments); + }; + + builder._styles = _styles; + builder._empty = _empty; + + const self = this; + + Object.defineProperty(builder, 'level', { enumerable: true, get() { - return this._generator.level; + return self.level; }, set(level) { - this._generator.level = level; + self.level = level; } - } -}); - -const createStyler = (open, close, parent) => { - let openAll; - let closeAll; - if (parent === undefined) { - openAll = open; - closeAll = close; - } else { - openAll = parent.openAll + open; - closeAll = close + parent.closeAll; - } + }); - return { - open, - close, - openAll, - closeAll, - parent - }; -}; + Object.defineProperty(builder, 'enabled', { + enumerable: true, + get() { + return self.enabled; + }, + set(enabled) { + self.enabled = enabled; + } + }); -const createBuilder = (self, _styler, _isEmpty) => { - const builder = (...arguments_) => { - // Single argument is hot path, implicit coercion is faster than anything - // eslint-disable-next-line no-implicit-coercion - return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' ')); - }; + // See below for fix regarding invisible grey/dim combination on Windows + builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is // no way to create a function with a different prototype builder.__proto__ = proto; // eslint-disable-line no-proto - builder._generator = self; - builder._styler = _styler; - builder._isEmpty = _isEmpty; - return builder; -}; +} -const applyStyle = (self, string) => { - if (self.level <= 0 || !string) { - return self._isEmpty ? '' : string; - } +function applyStyle() { + // Support varags, but simply cast to string in case there's only one arg + const args = arguments; + const argsLen = args.length; + let str = String(arguments[0]); - let styler = self._styler; + if (argsLen === 0) { + return ''; + } - if (styler === undefined) { - return string; + if (argsLen > 1) { + // Don't slice `arguments`, it prevents V8 optimizations + for (let a = 1; a < argsLen; a++) { + str += ' ' + args[a]; + } } - const {openAll, closeAll} = styler; - if (string.indexOf('\u001B') !== -1) { - while (styler !== undefined) { - // Replace any instances already present with a re-opening code - // otherwise only the part of the string until said closing code - // will be colored, and the rest will simply be 'plain'. - string = stringReplaceAll(string, styler.close, styler.open); + if (!this.enabled || this.level <= 0 || !str) { + return this._empty ? '' : str; + } - styler = styler.parent; - } + // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe, + // see https://github.com/chalk/chalk/issues/58 + // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop. + const originalDim = ansiStyles.dim.open; + if (isSimpleWindowsTerm && this.hasGrey) { + ansiStyles.dim.open = ''; } - // We can move both next actions out of loop, because remaining actions in loop won't have - // any/visible effect on parts we add here. Close the styling before a linebreak and reopen - // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92 - const lfIndex = string.indexOf('\n'); - if (lfIndex !== -1) { - string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex); + for (const code of this._styles.slice().reverse()) { + // Replace any instances already present with a re-opening code + // otherwise only the part of the string until said closing code + // will be colored, and the rest will simply be 'plain'. + str = code.open + str.replace(code.closeRe, code.open) + code.close; + + // Close the styling before a linebreak and reopen + // after next line to fix a bleed issue on macOS + // https://github.com/chalk/chalk/pull/92 + str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); } - return openAll + string + closeAll; -}; + // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue + ansiStyles.dim.open = originalDim; -let template; -const chalkTag = (chalk, ...strings) => { - const [firstString] = strings; + return str; +} - if (!Array.isArray(firstString)) { +function chalkTag(chalk, strings) { + if (!Array.isArray(strings)) { // If chalk() was called by itself or with a string, // return the string itself as a string. - return strings.join(' '); + return [].slice.call(arguments, 1).join(' '); } - const arguments_ = strings.slice(1); - const parts = [firstString.raw[0]]; - - for (let i = 1; i < firstString.length; i++) { - parts.push( - String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), - String(firstString.raw[i]) - ); - } + const args = [].slice.call(arguments, 2); + const parts = [strings.raw[0]]; - if (template === undefined) { - template = __webpack_require__(15); + for (let i = 1; i < strings.length; i++) { + parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&')); + parts.push(String(strings.raw[i])); } return template(chalk, parts.join('')); -}; +} Object.defineProperties(Chalk.prototype, styles); -const chalk = Chalk(); // eslint-disable-line new-cap -chalk.supportsColor = stdoutColor; -chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap -chalk.stderr.supportsColor = stderrColor; - -// For TypeScript -chalk.Level = { - None: 0, - Basic: 1, - Ansi256: 2, - TrueColor: 3, - 0: 'None', - 1: 'Basic', - 2: 'Ansi256', - 3: 'TrueColor' -}; - -module.exports = chalk; +module.exports = Chalk(); // eslint-disable-line new-cap +module.exports.supportsColor = stdoutColor; +module.exports.default = module.exports; // For TypeScript +/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(4))) /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(module) { -const wrapAnsi16 = (fn, offset) => (...args) => { - const code = fn(...args); - return `\u001B[${code + offset}m`; -}; -const wrapAnsi256 = (fn, offset) => (...args) => { - const code = fn(...args); - return `\u001B[${38 + offset};5;${code}m`; -}; +var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; -const wrapAnsi16m = (fn, offset) => (...args) => { - const rgb = fn(...args); - return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; +module.exports = function (str) { + if (typeof str !== 'string') { + throw new TypeError('Expected a string'); + } + + return str.replace(matchOperatorsRe, '\\$&'); }; -const ansi2ansi = n => n; -const rgb2rgb = (r, g, b) => [r, g, b]; -const setLazyProperty = (object, property, get) => { - Object.defineProperty(object, property, { - get: () => { - const value = get(); +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { - Object.defineProperty(object, property, { - value, - enumerable: true, - configurable: true - }); +"use strict"; +/* WEBPACK VAR INJECTION */(function(module) { +const colorConvert = __webpack_require__(10); - return value; - }, - enumerable: true, - configurable: true - }); +const wrapAnsi16 = (fn, offset) => function () { + const code = fn.apply(colorConvert, arguments); + return `\u001B[${code + offset}m`; }; -/** @type {typeof import('color-convert')} */ -let colorConvert; -const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => { - if (colorConvert === undefined) { - colorConvert = __webpack_require__(9); - } - - const offset = isBackground ? 10 : 0; - const styles = {}; - - for (const [sourceSpace, suite] of Object.entries(colorConvert)) { - const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace; - if (sourceSpace === targetSpace) { - styles[name] = wrap(identity, offset); - } else if (typeof suite === 'object') { - styles[name] = wrap(suite[targetSpace], offset); - } - } +const wrapAnsi256 = (fn, offset) => function () { + const code = fn.apply(colorConvert, arguments); + return `\u001B[${38 + offset};5;${code}m`; +}; - return styles; +const wrapAnsi16m = (fn, offset) => function () { + const rgb = fn.apply(colorConvert, arguments); + return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; }; function assembleStyles() { @@ -877,9 +860,9 @@ function assembleStyles() { magenta: [35, 39], cyan: [36, 39], white: [37, 39], + gray: [90, 39], // Bright color - blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], @@ -910,14 +893,15 @@ function assembleStyles() { } }; - // Alias bright black as gray (and grey) - styles.color.gray = styles.color.blackBright; - styles.bgColor.bgGray = styles.bgColor.bgBlackBright; - styles.color.grey = styles.color.blackBright; - styles.bgColor.bgGrey = styles.bgColor.bgBlackBright; + // Fix humans + styles.color.grey = styles.color.gray; + + for (const groupName of Object.keys(styles)) { + const group = styles[groupName]; + + for (const styleName of Object.keys(group)) { + const style = group[styleName]; - for (const [groupName, group] of Object.entries(styles)) { - for (const [styleName, style] of Object.entries(group)) { styles[styleName] = { open: `\u001B[${style[0]}m`, close: `\u001B[${style[1]}m` @@ -932,22 +916,65 @@ function assembleStyles() { value: group, enumerable: false }); + + Object.defineProperty(styles, 'codes', { + value: codes, + enumerable: false + }); } - Object.defineProperty(styles, 'codes', { - value: codes, - enumerable: false - }); + const ansi2ansi = n => n; + const rgb2rgb = (r, g, b) => [r, g, b]; styles.color.close = '\u001B[39m'; styles.bgColor.close = '\u001B[49m'; - setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false)); - setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false)); - setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false)); - setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true)); - setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true)); - setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true)); + styles.color.ansi = { + ansi: wrapAnsi16(ansi2ansi, 0) + }; + styles.color.ansi256 = { + ansi256: wrapAnsi256(ansi2ansi, 0) + }; + styles.color.ansi16m = { + rgb: wrapAnsi16m(rgb2rgb, 0) + }; + + styles.bgColor.ansi = { + ansi: wrapAnsi16(ansi2ansi, 10) + }; + styles.bgColor.ansi256 = { + ansi256: wrapAnsi256(ansi2ansi, 10) + }; + styles.bgColor.ansi16m = { + rgb: wrapAnsi16m(rgb2rgb, 10) + }; + + for (let key of Object.keys(colorConvert)) { + if (typeof colorConvert[key] !== 'object') { + continue; + } + + const suite = colorConvert[key]; + + if (key === 'ansi16') { + key = 'ansi'; + } + + if ('ansi16' in suite) { + styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0); + styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10); + } + + if ('ansi256' in suite) { + styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0); + styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10); + } + + if ('rgb' in suite) { + styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0); + styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10); + } + } return styles; } @@ -958,10 +985,10 @@ Object.defineProperty(module, 'exports', { get: assembleStyles }); -/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(8)(module))) +/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(9)(module))) /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, exports) { module.exports = function(module) { @@ -989,31 +1016,30 @@ module.exports = function(module) { /***/ }), -/* 9 */ +/* 10 */ /***/ (function(module, exports, __webpack_require__) { -const conversions = __webpack_require__(10); -const route = __webpack_require__(12); +var conversions = __webpack_require__(11); +var route = __webpack_require__(13); -const convert = {}; +var convert = {}; -const models = Object.keys(conversions); +var models = Object.keys(conversions); function wrapRaw(fn) { - const wrappedFn = function (...args) { - const arg0 = args[0]; - if (arg0 === undefined || arg0 === null) { - return arg0; + var wrappedFn = function (args) { + if (args === undefined || args === null) { + return args; } - if (arg0.length > 1) { - args = arg0; + if (arguments.length > 1) { + args = Array.prototype.slice.call(arguments); } return fn(args); }; - // Preserve .conversion property if there is one + // preserve .conversion property if there is one if ('conversion' in fn) { wrappedFn.conversion = fn.conversion; } @@ -1022,24 +1048,22 @@ function wrapRaw(fn) { } function wrapRounded(fn) { - const wrappedFn = function (...args) { - const arg0 = args[0]; - - if (arg0 === undefined || arg0 === null) { - return arg0; + var wrappedFn = function (args) { + if (args === undefined || args === null) { + return args; } - if (arg0.length > 1) { - args = arg0; + if (arguments.length > 1) { + args = Array.prototype.slice.call(arguments); } - const result = fn(args); + var result = fn(args); - // We're assuming the result is an array here. + // we're assuming the result is an array here. // see notice in conversions.js; don't use box types // in conversion functions. if (typeof result === 'object') { - for (let len = result.length, i = 0; i < len; i++) { + for (var len = result.length, i = 0; i < len; i++) { result[i] = Math.round(result[i]); } } @@ -1047,7 +1071,7 @@ function wrapRounded(fn) { return result; }; - // Preserve .conversion property if there is one + // preserve .conversion property if there is one if ('conversion' in fn) { wrappedFn.conversion = fn.conversion; } @@ -1055,17 +1079,17 @@ function wrapRounded(fn) { return wrappedFn; } -models.forEach(fromModel => { +models.forEach(function (fromModel) { convert[fromModel] = {}; Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels}); Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels}); - const routes = route(fromModel); - const routeModels = Object.keys(routes); + var routes = route(fromModel); + var routeModels = Object.keys(routes); - routeModels.forEach(toModel => { - const fn = routes[toModel]; + routeModels.forEach(function (toModel) { + var fn = routes[toModel]; convert[fromModel][toModel] = wrapRounded(fn); convert[fromModel][toModel].raw = wrapRaw(fn); @@ -1076,23 +1100,24 @@ module.exports = convert; /***/ }), -/* 10 */ +/* 11 */ /***/ (function(module, exports, __webpack_require__) { /* MIT license */ -/* eslint-disable no-mixed-operators */ -const cssKeywords = __webpack_require__(11); +var cssKeywords = __webpack_require__(12); // NOTE: conversions should only return primitive values (i.e. arrays, or // values that give correct `typeof` results). // do not use box values types (i.e. Number(), String(), etc.) -const reverseKeywords = {}; -for (const key of Object.keys(cssKeywords)) { - reverseKeywords[cssKeywords[key]] = key; +var reverseKeywords = {}; +for (var key in cssKeywords) { + if (cssKeywords.hasOwnProperty(key)) { + reverseKeywords[cssKeywords[key]] = key; + } } -const convert = { +var convert = module.exports = { rgb: {channels: 3, labels: 'rgb'}, hsl: {channels: 3, labels: 'hsl'}, hsv: {channels: 3, labels: 'hsv'}, @@ -1110,38 +1135,40 @@ const convert = { gray: {channels: 1, labels: ['gray']} }; -module.exports = convert; +// hide .channels and .labels properties +for (var model in convert) { + if (convert.hasOwnProperty(model)) { + if (!('channels' in convert[model])) { + throw new Error('missing channels property: ' + model); + } -// Hide .channels and .labels properties -for (const model of Object.keys(convert)) { - if (!('channels' in convert[model])) { - throw new Error('missing channels property: ' + model); - } + if (!('labels' in convert[model])) { + throw new Error('missing channel labels property: ' + model); + } - if (!('labels' in convert[model])) { - throw new Error('missing channel labels property: ' + model); - } + if (convert[model].labels.length !== convert[model].channels) { + throw new Error('channel and label counts mismatch: ' + model); + } - if (convert[model].labels.length !== convert[model].channels) { - throw new Error('channel and label counts mismatch: ' + model); + var channels = convert[model].channels; + var labels = convert[model].labels; + delete convert[model].channels; + delete convert[model].labels; + Object.defineProperty(convert[model], 'channels', {value: channels}); + Object.defineProperty(convert[model], 'labels', {value: labels}); } - - const {channels, labels} = convert[model]; - delete convert[model].channels; - delete convert[model].labels; - Object.defineProperty(convert[model], 'channels', {value: channels}); - Object.defineProperty(convert[model], 'labels', {value: labels}); } convert.rgb.hsl = function (rgb) { - const r = rgb[0] / 255; - const g = rgb[1] / 255; - const b = rgb[2] / 255; - const min = Math.min(r, g, b); - const max = Math.max(r, g, b); - const delta = max - min; - let h; - let s; + var r = rgb[0] / 255; + var g = rgb[1] / 255; + var b = rgb[2] / 255; + var min = Math.min(r, g, b); + var max = Math.max(r, g, b); + var delta = max - min; + var h; + var s; + var l; if (max === min) { h = 0; @@ -1159,7 +1186,7 @@ convert.rgb.hsl = function (rgb) { h += 360; } - const l = (min + max) / 2; + l = (min + max) / 2; if (max === min) { s = 0; @@ -1173,24 +1200,23 @@ convert.rgb.hsl = function (rgb) { }; convert.rgb.hsv = function (rgb) { - let rdif; - let gdif; - let bdif; - let h; - let s; - - const r = rgb[0] / 255; - const g = rgb[1] / 255; - const b = rgb[2] / 255; - const v = Math.max(r, g, b); - const diff = v - Math.min(r, g, b); - const diffc = function (c) { + var rdif; + var gdif; + var bdif; + var h; + var s; + + var r = rgb[0] / 255; + var g = rgb[1] / 255; + var b = rgb[2] / 255; + var v = Math.max(r, g, b); + var diff = v - Math.min(r, g, b); + var diffc = function (c) { return (v - c) / 6 / diff + 1 / 2; }; if (diff === 0) { - h = 0; - s = 0; + h = s = 0; } else { s = diff / v; rdif = diffc(r); @@ -1204,7 +1230,6 @@ convert.rgb.hsv = function (rgb) { } else if (b === v) { h = (2 / 3) + gdif - rdif; } - if (h < 0) { h += 1; } else if (h > 1) { @@ -1220,11 +1245,11 @@ convert.rgb.hsv = function (rgb) { }; convert.rgb.hwb = function (rgb) { - const r = rgb[0]; - const g = rgb[1]; - let b = rgb[2]; - const h = convert.rgb.hsl(rgb)[0]; - const w = 1 / 255 * Math.min(r, Math.min(g, b)); + var r = rgb[0]; + var g = rgb[1]; + var b = rgb[2]; + var h = convert.rgb.hsl(rgb)[0]; + var w = 1 / 255 * Math.min(r, Math.min(g, b)); b = 1 - 1 / 255 * Math.max(r, Math.max(g, b)); @@ -1232,48 +1257,54 @@ convert.rgb.hwb = function (rgb) { }; convert.rgb.cmyk = function (rgb) { - const r = rgb[0] / 255; - const g = rgb[1] / 255; - const b = rgb[2] / 255; - - const k = Math.min(1 - r, 1 - g, 1 - b); - const c = (1 - r - k) / (1 - k) || 0; - const m = (1 - g - k) / (1 - k) || 0; - const y = (1 - b - k) / (1 - k) || 0; + var r = rgb[0] / 255; + var g = rgb[1] / 255; + var b = rgb[2] / 255; + var c; + var m; + var y; + var k; + + k = Math.min(1 - r, 1 - g, 1 - b); + c = (1 - r - k) / (1 - k) || 0; + m = (1 - g - k) / (1 - k) || 0; + y = (1 - b - k) / (1 - k) || 0; return [c * 100, m * 100, y * 100, k * 100]; }; +/** + * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance + * */ function comparativeDistance(x, y) { - /* - See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance - */ return ( - ((x[0] - y[0]) ** 2) + - ((x[1] - y[1]) ** 2) + - ((x[2] - y[2]) ** 2) + Math.pow(x[0] - y[0], 2) + + Math.pow(x[1] - y[1], 2) + + Math.pow(x[2] - y[2], 2) ); } convert.rgb.keyword = function (rgb) { - const reversed = reverseKeywords[rgb]; + var reversed = reverseKeywords[rgb]; if (reversed) { return reversed; } - let currentClosestDistance = Infinity; - let currentClosestKeyword; + var currentClosestDistance = Infinity; + var currentClosestKeyword; - for (const keyword of Object.keys(cssKeywords)) { - const value = cssKeywords[keyword]; + for (var keyword in cssKeywords) { + if (cssKeywords.hasOwnProperty(keyword)) { + var value = cssKeywords[keyword]; - // Compute comparative distance - const distance = comparativeDistance(rgb, value); + // Compute comparative distance + var distance = comparativeDistance(rgb, value); - // Check if its less, if so set as closest - if (distance < currentClosestDistance) { - currentClosestDistance = distance; - currentClosestKeyword = keyword; + // Check if its less, if so set as closest + if (distance < currentClosestDistance) { + currentClosestDistance = distance; + currentClosestKeyword = keyword; + } } } @@ -1285,50 +1316,55 @@ convert.keyword.rgb = function (keyword) { }; convert.rgb.xyz = function (rgb) { - let r = rgb[0] / 255; - let g = rgb[1] / 255; - let b = rgb[2] / 255; + var r = rgb[0] / 255; + var g = rgb[1] / 255; + var b = rgb[2] / 255; - // Assume sRGB - r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92); - g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92); - b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92); + // assume sRGB + r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92); + g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92); + b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92); - const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); - const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); - const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); + var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); + var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); + var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); return [x * 100, y * 100, z * 100]; }; convert.rgb.lab = function (rgb) { - const xyz = convert.rgb.xyz(rgb); - let x = xyz[0]; - let y = xyz[1]; - let z = xyz[2]; + var xyz = convert.rgb.xyz(rgb); + var x = xyz[0]; + var y = xyz[1]; + var z = xyz[2]; + var l; + var a; + var b; x /= 95.047; y /= 100; z /= 108.883; - x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); - y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); - z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); + x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); + y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); + z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); - const l = (116 * y) - 16; - const a = 500 * (x - y); - const b = 200 * (y - z); + l = (116 * y) - 16; + a = 500 * (x - y); + b = 200 * (y - z); return [l, a, b]; }; convert.hsl.rgb = function (hsl) { - const h = hsl[0] / 360; - const s = hsl[1] / 100; - const l = hsl[2] / 100; - let t2; - let t3; - let val; + var h = hsl[0] / 360; + var s = hsl[1] / 100; + var l = hsl[2] / 100; + var t1; + var t2; + var t3; + var rgb; + var val; if (s === 0) { val = l * 255; @@ -1341,15 +1377,14 @@ convert.hsl.rgb = function (hsl) { t2 = l + s - l * s; } - const t1 = 2 * l - t2; + t1 = 2 * l - t2; - const rgb = [0, 0, 0]; - for (let i = 0; i < 3; i++) { + rgb = [0, 0, 0]; + for (var i = 0; i < 3; i++) { t3 = h + 1 / 3 * -(i - 1); if (t3 < 0) { t3++; } - if (t3 > 1) { t3--; } @@ -1371,31 +1406,33 @@ convert.hsl.rgb = function (hsl) { }; convert.hsl.hsv = function (hsl) { - const h = hsl[0]; - let s = hsl[1] / 100; - let l = hsl[2] / 100; - let smin = s; - const lmin = Math.max(l, 0.01); + var h = hsl[0]; + var s = hsl[1] / 100; + var l = hsl[2] / 100; + var smin = s; + var lmin = Math.max(l, 0.01); + var sv; + var v; l *= 2; s *= (l <= 1) ? l : 2 - l; smin *= lmin <= 1 ? lmin : 2 - lmin; - const v = (l + s) / 2; - const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s); + v = (l + s) / 2; + sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s); return [h, sv * 100, v * 100]; }; convert.hsv.rgb = function (hsv) { - const h = hsv[0] / 60; - const s = hsv[1] / 100; - let v = hsv[2] / 100; - const hi = Math.floor(h) % 6; - - const f = h - Math.floor(h); - const p = 255 * v * (1 - s); - const q = 255 * v * (1 - (s * f)); - const t = 255 * v * (1 - (s * (1 - f))); + var h = hsv[0] / 60; + var s = hsv[1] / 100; + var v = hsv[2] / 100; + var hi = Math.floor(h) % 6; + + var f = h - Math.floor(h); + var p = 255 * v * (1 - s); + var q = 255 * v * (1 - (s * f)); + var t = 255 * v * (1 - (s * (1 - f))); v *= 255; switch (hi) { @@ -1415,15 +1452,16 @@ convert.hsv.rgb = function (hsv) { }; convert.hsv.hsl = function (hsv) { - const h = hsv[0]; - const s = hsv[1] / 100; - const v = hsv[2] / 100; - const vmin = Math.max(v, 0.01); - let sl; - let l; + var h = hsv[0]; + var s = hsv[1] / 100; + var v = hsv[2] / 100; + var vmin = Math.max(v, 0.01); + var lmin; + var sl; + var l; l = (2 - s) * v; - const lmin = (2 - s) * vmin; + lmin = (2 - s) * vmin; sl = s * vmin; sl /= (lmin <= 1) ? lmin : 2 - lmin; sl = sl || 0; @@ -1434,83 +1472,87 @@ convert.hsv.hsl = function (hsv) { // http://dev.w3.org/csswg/css-color/#hwb-to-rgb convert.hwb.rgb = function (hwb) { - const h = hwb[0] / 360; - let wh = hwb[1] / 100; - let bl = hwb[2] / 100; - const ratio = wh + bl; - let f; - - // Wh + bl cant be > 1 + var h = hwb[0] / 360; + var wh = hwb[1] / 100; + var bl = hwb[2] / 100; + var ratio = wh + bl; + var i; + var v; + var f; + var n; + + // wh + bl cant be > 1 if (ratio > 1) { wh /= ratio; bl /= ratio; } - const i = Math.floor(6 * h); - const v = 1 - bl; + i = Math.floor(6 * h); + v = 1 - bl; f = 6 * h - i; if ((i & 0x01) !== 0) { f = 1 - f; } - const n = wh + f * (v - wh); // Linear interpolation + n = wh + f * (v - wh); // linear interpolation - let r; - let g; - let b; - /* eslint-disable max-statements-per-line,no-multi-spaces */ + var r; + var g; + var b; switch (i) { default: case 6: - case 0: r = v; g = n; b = wh; break; - case 1: r = n; g = v; b = wh; break; - case 2: r = wh; g = v; b = n; break; - case 3: r = wh; g = n; b = v; break; - case 4: r = n; g = wh; b = v; break; - case 5: r = v; g = wh; b = n; break; + case 0: r = v; g = n; b = wh; break; + case 1: r = n; g = v; b = wh; break; + case 2: r = wh; g = v; b = n; break; + case 3: r = wh; g = n; b = v; break; + case 4: r = n; g = wh; b = v; break; + case 5: r = v; g = wh; b = n; break; } - /* eslint-enable max-statements-per-line,no-multi-spaces */ return [r * 255, g * 255, b * 255]; }; convert.cmyk.rgb = function (cmyk) { - const c = cmyk[0] / 100; - const m = cmyk[1] / 100; - const y = cmyk[2] / 100; - const k = cmyk[3] / 100; - - const r = 1 - Math.min(1, c * (1 - k) + k); - const g = 1 - Math.min(1, m * (1 - k) + k); - const b = 1 - Math.min(1, y * (1 - k) + k); + var c = cmyk[0] / 100; + var m = cmyk[1] / 100; + var y = cmyk[2] / 100; + var k = cmyk[3] / 100; + var r; + var g; + var b; + + r = 1 - Math.min(1, c * (1 - k) + k); + g = 1 - Math.min(1, m * (1 - k) + k); + b = 1 - Math.min(1, y * (1 - k) + k); return [r * 255, g * 255, b * 255]; }; convert.xyz.rgb = function (xyz) { - const x = xyz[0] / 100; - const y = xyz[1] / 100; - const z = xyz[2] / 100; - let r; - let g; - let b; + var x = xyz[0] / 100; + var y = xyz[1] / 100; + var z = xyz[2] / 100; + var r; + var g; + var b; r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); - // Assume sRGB + // assume sRGB r = r > 0.0031308 - ? ((1.055 * (r ** (1.0 / 2.4))) - 0.055) + ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055) : r * 12.92; g = g > 0.0031308 - ? ((1.055 * (g ** (1.0 / 2.4))) - 0.055) + ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055) : g * 12.92; b = b > 0.0031308 - ? ((1.055 * (b ** (1.0 / 2.4))) - 0.055) + ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055) : b * 12.92; r = Math.min(Math.max(0, r), 1); @@ -1521,40 +1563,43 @@ convert.xyz.rgb = function (xyz) { }; convert.xyz.lab = function (xyz) { - let x = xyz[0]; - let y = xyz[1]; - let z = xyz[2]; + var x = xyz[0]; + var y = xyz[1]; + var z = xyz[2]; + var l; + var a; + var b; x /= 95.047; y /= 100; z /= 108.883; - x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); - y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); - z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); + x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); + y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); + z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); - const l = (116 * y) - 16; - const a = 500 * (x - y); - const b = 200 * (y - z); + l = (116 * y) - 16; + a = 500 * (x - y); + b = 200 * (y - z); return [l, a, b]; }; convert.lab.xyz = function (lab) { - const l = lab[0]; - const a = lab[1]; - const b = lab[2]; - let x; - let y; - let z; + var l = lab[0]; + var a = lab[1]; + var b = lab[2]; + var x; + var y; + var z; y = (l + 16) / 116; x = a / 500 + y; z = y - b / 200; - const y2 = y ** 3; - const x2 = x ** 3; - const z2 = z ** 3; + var y2 = Math.pow(y, 3); + var x2 = Math.pow(x, 3); + var z2 = Math.pow(z, 3); y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787; x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787; z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787; @@ -1567,38 +1612,45 @@ convert.lab.xyz = function (lab) { }; convert.lab.lch = function (lab) { - const l = lab[0]; - const a = lab[1]; - const b = lab[2]; - let h; - - const hr = Math.atan2(b, a); + var l = lab[0]; + var a = lab[1]; + var b = lab[2]; + var hr; + var h; + var c; + + hr = Math.atan2(b, a); h = hr * 360 / 2 / Math.PI; if (h < 0) { h += 360; } - const c = Math.sqrt(a * a + b * b); + c = Math.sqrt(a * a + b * b); return [l, c, h]; }; convert.lch.lab = function (lch) { - const l = lch[0]; - const c = lch[1]; - const h = lch[2]; + var l = lch[0]; + var c = lch[1]; + var h = lch[2]; + var a; + var b; + var hr; - const hr = h / 360 * 2 * Math.PI; - const a = c * Math.cos(hr); - const b = c * Math.sin(hr); + hr = h / 360 * 2 * Math.PI; + a = c * Math.cos(hr); + b = c * Math.sin(hr); return [l, a, b]; }; -convert.rgb.ansi16 = function (args, saturation = null) { - const [r, g, b] = args; - let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization +convert.rgb.ansi16 = function (args) { + var r = args[0]; + var g = args[1]; + var b = args[2]; + var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization value = Math.round(value / 50); @@ -1606,7 +1658,7 @@ convert.rgb.ansi16 = function (args, saturation = null) { return 30; } - let ansi = 30 + var ansi = 30 + ((Math.round(b / 255) << 2) | (Math.round(g / 255) << 1) | Math.round(r / 255)); @@ -1619,17 +1671,17 @@ convert.rgb.ansi16 = function (args, saturation = null) { }; convert.hsv.ansi16 = function (args) { - // Optimization here; we already know the value and don't need to get + // optimization here; we already know the value and don't need to get // it converted for us. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]); }; convert.rgb.ansi256 = function (args) { - const r = args[0]; - const g = args[1]; - const b = args[2]; + var r = args[0]; + var g = args[1]; + var b = args[2]; - // We use the extended greyscale palette here, with the exception of + // we use the extended greyscale palette here, with the exception of // black and white. normal palette only has 4 greyscale shades. if (r === g && g === b) { if (r < 8) { @@ -1643,7 +1695,7 @@ convert.rgb.ansi256 = function (args) { return Math.round(((r - 8) / 247) * 24) + 232; } - const ansi = 16 + var ansi = 16 + (36 * Math.round(r / 255 * 5)) + (6 * Math.round(g / 255 * 5)) + Math.round(b / 255 * 5); @@ -1652,9 +1704,9 @@ convert.rgb.ansi256 = function (args) { }; convert.ansi16.rgb = function (args) { - let color = args % 10; + var color = args % 10; - // Handle greyscale + // handle greyscale if (color === 0 || color === 7) { if (args > 50) { color += 3.5; @@ -1665,71 +1717,71 @@ convert.ansi16.rgb = function (args) { return [color, color, color]; } - const mult = (~~(args > 50) + 1) * 0.5; - const r = ((color & 1) * mult) * 255; - const g = (((color >> 1) & 1) * mult) * 255; - const b = (((color >> 2) & 1) * mult) * 255; + var mult = (~~(args > 50) + 1) * 0.5; + var r = ((color & 1) * mult) * 255; + var g = (((color >> 1) & 1) * mult) * 255; + var b = (((color >> 2) & 1) * mult) * 255; return [r, g, b]; }; convert.ansi256.rgb = function (args) { - // Handle greyscale + // handle greyscale if (args >= 232) { - const c = (args - 232) * 10 + 8; + var c = (args - 232) * 10 + 8; return [c, c, c]; } args -= 16; - let rem; - const r = Math.floor(args / 36) / 5 * 255; - const g = Math.floor((rem = args % 36) / 6) / 5 * 255; - const b = (rem % 6) / 5 * 255; + var rem; + var r = Math.floor(args / 36) / 5 * 255; + var g = Math.floor((rem = args % 36) / 6) / 5 * 255; + var b = (rem % 6) / 5 * 255; return [r, g, b]; }; convert.rgb.hex = function (args) { - const integer = ((Math.round(args[0]) & 0xFF) << 16) + var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF); - const string = integer.toString(16).toUpperCase(); + var string = integer.toString(16).toUpperCase(); return '000000'.substring(string.length) + string; }; convert.hex.rgb = function (args) { - const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); + var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); if (!match) { return [0, 0, 0]; } - let colorString = match[0]; + var colorString = match[0]; if (match[0].length === 3) { - colorString = colorString.split('').map(char => { + colorString = colorString.split('').map(function (char) { return char + char; }).join(''); } - const integer = parseInt(colorString, 16); - const r = (integer >> 16) & 0xFF; - const g = (integer >> 8) & 0xFF; - const b = integer & 0xFF; + var integer = parseInt(colorString, 16); + var r = (integer >> 16) & 0xFF; + var g = (integer >> 8) & 0xFF; + var b = integer & 0xFF; return [r, g, b]; }; convert.rgb.hcg = function (rgb) { - const r = rgb[0] / 255; - const g = rgb[1] / 255; - const b = rgb[2] / 255; - const max = Math.max(Math.max(r, g), b); - const min = Math.min(Math.min(r, g), b); - const chroma = (max - min); - let grayscale; - let hue; + var r = rgb[0] / 255; + var g = rgb[1] / 255; + var b = rgb[2] / 255; + var max = Math.max(Math.max(r, g), b); + var min = Math.min(Math.min(r, g), b); + var chroma = (max - min); + var grayscale; + var hue; if (chroma < 1) { grayscale = min / (1 - chroma); @@ -1746,7 +1798,7 @@ convert.rgb.hcg = function (rgb) { if (max === g) { hue = 2 + (b - r) / chroma; } else { - hue = 4 + (r - g) / chroma; + hue = 4 + (r - g) / chroma + 4; } hue /= 6; @@ -1756,12 +1808,17 @@ convert.rgb.hcg = function (rgb) { }; convert.hsl.hcg = function (hsl) { - const s = hsl[1] / 100; - const l = hsl[2] / 100; + var s = hsl[1] / 100; + var l = hsl[2] / 100; + var c = 1; + var f = 0; - const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l)); + if (l < 0.5) { + c = 2.0 * s * l; + } else { + c = 2.0 * s * (1.0 - l); + } - let f = 0; if (c < 1.0) { f = (l - 0.5 * c) / (1.0 - c); } @@ -1770,11 +1827,11 @@ convert.hsl.hcg = function (hsl) { }; convert.hsv.hcg = function (hsv) { - const s = hsv[1] / 100; - const v = hsv[2] / 100; + var s = hsv[1] / 100; + var v = hsv[2] / 100; - const c = s * v; - let f = 0; + var c = s * v; + var f = 0; if (c < 1.0) { f = (v - c) / (1 - c); @@ -1784,21 +1841,20 @@ convert.hsv.hcg = function (hsv) { }; convert.hcg.rgb = function (hcg) { - const h = hcg[0] / 360; - const c = hcg[1] / 100; - const g = hcg[2] / 100; + var h = hcg[0] / 360; + var c = hcg[1] / 100; + var g = hcg[2] / 100; if (c === 0.0) { return [g * 255, g * 255, g * 255]; } - const pure = [0, 0, 0]; - const hi = (h % 1) * 6; - const v = hi % 1; - const w = 1 - v; - let mg = 0; + var pure = [0, 0, 0]; + var hi = (h % 1) * 6; + var v = hi % 1; + var w = 1 - v; + var mg = 0; - /* eslint-disable max-statements-per-line */ switch (Math.floor(hi)) { case 0: pure[0] = 1; pure[1] = v; pure[2] = 0; break; @@ -1813,7 +1869,6 @@ convert.hcg.rgb = function (hcg) { default: pure[0] = 1; pure[1] = 0; pure[2] = w; } - /* eslint-enable max-statements-per-line */ mg = (1.0 - c) * g; @@ -1825,11 +1880,11 @@ convert.hcg.rgb = function (hcg) { }; convert.hcg.hsv = function (hcg) { - const c = hcg[1] / 100; - const g = hcg[2] / 100; + var c = hcg[1] / 100; + var g = hcg[2] / 100; - const v = c + g * (1.0 - c); - let f = 0; + var v = c + g * (1.0 - c); + var f = 0; if (v > 0.0) { f = c / v; @@ -1839,11 +1894,11 @@ convert.hcg.hsv = function (hcg) { }; convert.hcg.hsl = function (hcg) { - const c = hcg[1] / 100; - const g = hcg[2] / 100; + var c = hcg[1] / 100; + var g = hcg[2] / 100; - const l = g * (1.0 - c) + 0.5 * c; - let s = 0; + var l = g * (1.0 - c) + 0.5 * c; + var s = 0; if (l > 0.0 && l < 0.5) { s = c / (2 * l); @@ -1856,18 +1911,18 @@ convert.hcg.hsl = function (hcg) { }; convert.hcg.hwb = function (hcg) { - const c = hcg[1] / 100; - const g = hcg[2] / 100; - const v = c + g * (1.0 - c); + var c = hcg[1] / 100; + var g = hcg[2] / 100; + var v = c + g * (1.0 - c); return [hcg[0], (v - c) * 100, (1 - v) * 100]; }; convert.hwb.hcg = function (hwb) { - const w = hwb[1] / 100; - const b = hwb[2] / 100; - const v = 1 - b; - const c = v - w; - let g = 0; + var w = hwb[1] / 100; + var b = hwb[2] / 100; + var v = 1 - b; + var c = v - w; + var g = 0; if (c < 1) { g = (v - c) / (1 - c); @@ -1888,12 +1943,10 @@ convert.gray.rgb = function (args) { return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255]; }; -convert.gray.hsl = function (args) { +convert.gray.hsl = convert.gray.hsv = function (args) { return [0, 0, args[0]]; }; -convert.gray.hsv = convert.gray.hsl; - convert.gray.hwb = function (gray) { return [0, 100, gray[0]]; }; @@ -1907,21 +1960,21 @@ convert.gray.lab = function (gray) { }; convert.gray.hex = function (gray) { - const val = Math.round(gray[0] / 100 * 255) & 0xFF; - const integer = (val << 16) + (val << 8) + val; + var val = Math.round(gray[0] / 100 * 255) & 0xFF; + var integer = (val << 16) + (val << 8) + val; - const string = integer.toString(16).toUpperCase(); + var string = integer.toString(16).toUpperCase(); return '000000'.substring(string.length) + string; }; convert.rgb.gray = function (rgb) { - const val = (rgb[0] + rgb[1] + rgb[2]) / 3; + var val = (rgb[0] + rgb[1] + rgb[2]) / 3; return [val / 255 * 100]; }; /***/ }), -/* 11 */ +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -2080,13 +2133,13 @@ module.exports = { /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, exports, __webpack_require__) { -const conversions = __webpack_require__(10); +var conversions = __webpack_require__(11); /* - This function routes a model to all other models. + this function routes a model to all other models. all functions that are routed have a property `.conversion` attached to the returned synthetic function. This property is an array @@ -2097,11 +2150,11 @@ const conversions = __webpack_require__(10); */ function buildGraph() { - const graph = {}; + var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3 - const models = Object.keys(conversions); + var models = Object.keys(conversions); - for (let len = models.length, i = 0; i < len; i++) { + for (var len = models.length, i = 0; i < len; i++) { graph[models[i]] = { // http://jsperf.com/1-vs-infinity // micro-opt, but this is simple. @@ -2115,18 +2168,18 @@ function buildGraph() { // https://en.wikipedia.org/wiki/Breadth-first_search function deriveBFS(fromModel) { - const graph = buildGraph(); - const queue = [fromModel]; // Unshift -> queue -> pop + var graph = buildGraph(); + var queue = [fromModel]; // unshift -> queue -> pop graph[fromModel].distance = 0; while (queue.length) { - const current = queue.pop(); - const adjacents = Object.keys(conversions[current]); + var current = queue.pop(); + var adjacents = Object.keys(conversions[current]); - for (let len = adjacents.length, i = 0; i < len; i++) { - const adjacent = adjacents[i]; - const node = graph[adjacent]; + for (var len = adjacents.length, i = 0; i < len; i++) { + var adjacent = adjacents[i]; + var node = graph[adjacent]; if (node.distance === -1) { node.distance = graph[current].distance + 1; @@ -2146,10 +2199,10 @@ function link(from, to) { } function wrapConversion(toModel, graph) { - const path = [graph[toModel].parent, toModel]; - let fn = conversions[graph[toModel].parent][toModel]; + var path = [graph[toModel].parent, toModel]; + var fn = conversions[graph[toModel].parent][toModel]; - let cur = graph[toModel].parent; + var cur = graph[toModel].parent; while (graph[cur].parent) { path.unshift(graph[cur].parent); fn = link(conversions[graph[cur].parent][cur], fn); @@ -2161,16 +2214,16 @@ function wrapConversion(toModel, graph) { } module.exports = function (fromModel) { - const graph = deriveBFS(fromModel); - const conversion = {}; + var graph = deriveBFS(fromModel); + var conversion = {}; - const models = Object.keys(graph); - for (let len = models.length, i = 0; i < len; i++) { - const toModel = models[i]; - const node = graph[toModel]; + var models = Object.keys(graph); + for (var len = models.length, i = 0; i < len; i++) { + var toModel = models[i]; + var node = graph[toModel]; if (node.parent === null) { - // No possible conversion, or this node is the source model. + // no possible conversion, or this node is the source model. continue; } @@ -2183,7 +2236,7 @@ module.exports = function (fromModel) { /***/ }), -/* 13 */ +/* 14 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -2194,62 +2247,16 @@ module.exports = { }; -/***/ }), -/* 14 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -const stringReplaceAll = (string, substring, replacer) => { - let index = string.indexOf(substring); - if (index === -1) { - return string; - } - - const substringLength = substring.length; - let endIndex = 0; - let returnValue = ''; - do { - returnValue += string.substr(endIndex, index - endIndex) + substring + replacer; - endIndex = index + substringLength; - index = string.indexOf(substring, endIndex); - } while (index !== -1); - - returnValue += string.substr(endIndex); - return returnValue; -}; - -const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => { - let endIndex = 0; - let returnValue = ''; - do { - const gotCR = string[index - 1] === '\r'; - returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix; - endIndex = index + 1; - index = string.indexOf('\n', endIndex); - } while (index !== -1); - - returnValue += string.substr(endIndex); - return returnValue; -}; - -module.exports = { - stringReplaceAll, - stringEncaseCRLFWithFirstIndex -}; - - /***/ }), /* 15 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi; +const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi; const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g; const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/; -const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi; +const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi; const ESCAPES = new Map([ ['n', '\n'], @@ -2265,31 +2272,23 @@ const ESCAPES = new Map([ ]); function unescape(c) { - const u = c[0] === 'u'; - const bracket = c[1] === '{'; - - if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) { + if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) { return String.fromCharCode(parseInt(c.slice(1), 16)); } - if (u && bracket) { - return String.fromCodePoint(parseInt(c.slice(2, -1), 16)); - } - return ESCAPES.get(c) || c; } -function parseArguments(name, arguments_) { +function parseArguments(name, args) { const results = []; - const chunks = arguments_.trim().split(/\s*,\s*/g); + const chunks = args.trim().split(/\s*,\s*/g); let matches; for (const chunk of chunks) { - const number = Number(chunk); - if (!Number.isNaN(number)) { - results.push(number); + if (!isNaN(chunk)) { + results.push(Number(chunk)); } else if ((matches = chunk.match(STRING_REGEX))) { - results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character)); + results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr)); } else { throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`); } @@ -2328,34 +2327,36 @@ function buildStyle(chalk, styles) { } let current = chalk; - for (const [styleName, styles] of Object.entries(enabled)) { - if (!Array.isArray(styles)) { - continue; - } + for (const styleName of Object.keys(enabled)) { + if (Array.isArray(enabled[styleName])) { + if (!(styleName in current)) { + throw new Error(`Unknown Chalk style: ${styleName}`); + } - if (!(styleName in current)) { - throw new Error(`Unknown Chalk style: ${styleName}`); + if (enabled[styleName].length > 0) { + current = current[styleName].apply(current, enabled[styleName]); + } else { + current = current[styleName]; + } } - - current = styles.length > 0 ? current[styleName](...styles) : current[styleName]; } return current; } -module.exports = (chalk, temporary) => { +module.exports = (chalk, tmp) => { const styles = []; const chunks = []; let chunk = []; // eslint-disable-next-line max-params - temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => { - if (escapeCharacter) { - chunk.push(unescape(escapeCharacter)); + tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => { + if (escapeChar) { + chunk.push(unescape(escapeChar)); } else if (style) { - const string = chunk.join(''); + const str = chunk.join(''); chunk = []; - chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string)); + chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str)); styles.push({inverse, styles: parseStyle(style)}); } else if (close) { if (styles.length === 0) { @@ -2366,7 +2367,7 @@ module.exports = (chalk, temporary) => { chunk = []; styles.pop(); } else { - chunk.push(character); + chunk.push(chr); } }); diff --git a/packages/create-react-wptheme/README.md b/packages/create-react-wptheme/README.md index 3879ee7..ddbf475 100644 --- a/packages/create-react-wptheme/README.md +++ b/packages/create-react-wptheme/README.md @@ -2,17 +2,17 @@ ## Updated! -Be sure to check out the new features (and bug fixes!) that Facebook added to [v3.3.1](https://github.com/facebook/create-react-app/releases/tag/v3.3.1) of `Create-React-App`. +Be sure to check out the new features (and bug fixes!) that Facebook added to [v3.4.0](https://github.com/facebook/create-react-app/releases/tag/v3.4.0) of `Create-React-App`. ## Good to Know! -[Create-React-App](https://create-react-app.dev/) is **more than** just **React.** `Create-React-App` is a stack of well tested and battle-hardened tools, guaranteed to be configured correctly to work together to make your job easier. +[Create-React-App](https://create-react-app.dev/) is **more than** just **React.** `Create-React-App` is a suite of battle-hardened tools, guaranteed to be configured correctly to work together to make your job easier. **No need for weird CORS setups** or server proxies. **Why in the world** would you want to **maintain two servers** anyway? No need for that, just use `Create-React-WPTheme` instead. The biggest difference between `Create-React-WPTheme` and `Create-React-App` is that this project here **uses your WordPress server as the development server instead of the Webpack Dev Server.** ## Don't Forget! -If you used an earlier version of `create-react-wptheme` to create a theme, you can easily update it as well. See the [Updating Existing Themes](#updating-existing-themes) section of the README below. +If you used an earlier version of `create-react-wptheme` to create a theme, you can easily update it as well. See the [Updating Existing Themes](https://github.com/devloco/create-react-wptheme#updating-existing-themes) section of the README below. --- diff --git a/packages/create-react-wptheme/createReactWpTheme.js b/packages/create-react-wptheme/createReactWpTheme.js index 0f3b991..e7a75a1 100644 --- a/packages/create-react-wptheme/createReactWpTheme.js +++ b/packages/create-react-wptheme/createReactWpTheme.js @@ -43,7 +43,7 @@ const _wpThemeVersion = packageJson.version; const _createReactAppVersion = _wpThemeVersion.split("-wp.")[0]; // Check these!!!! -const _reactScriptsWpThemeVersion = "^3.3.1-wp.2"; +const _reactScriptsWpThemeVersion = "^3.4.0-wp.1"; const _getScriptsPath = function() { return scriptsFromNpm(); }; diff --git a/packages/create-react-wptheme/package.json b/packages/create-react-wptheme/package.json index 380ae83..02257bb 100644 --- a/packages/create-react-wptheme/package.json +++ b/packages/create-react-wptheme/package.json @@ -1,6 +1,6 @@ { "name": "@devloco/create-react-wptheme", - "version": "3.3.1-wp.4", + "version": "3.4.0-wp.2", "description": "Create React-enabled WP themes.", "main": "index.js", "scripts": { @@ -42,7 +42,7 @@ "create-react-wptheme": "./index.js" }, "dependencies": { - "chalk": "2.4.2", + "chalk": "3.0.0", "commander": "2.20.0", "cross-spawn": "6.0.5", "envinfo": "7.3.1",