From fd282f61ba9735d43c74f25b1e4e1f63f579d8be Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Mon, 7 Oct 2024 10:43:08 -0600 Subject: [PATCH] Remove built files from critical-css-gen js-package --- .../build-browser/bundle.full.js | 37567 ---------------- .../build-browser/bundle.full.js.map | 1 - .../critical-css-gen/build-browser/bundle.js | 4 - .../build-browser/bundle.js.map | 1 - .../browser-interface-playwright.d.ts | 53 - .../browser-interface-playwright.js | 94 - .../browser-interface-playwright.js.map | 1 - .../build-node/browser-interface.d.ts | 77 - .../build-node/browser-interface.js | 124 - .../build-node/browser-interface.js.map | 1 - .../build-node/css-file-set.d.ts | 100 - .../build-node/css-file-set.js | 210 - .../build-node/css-file-set.js.map | 1 - .../critical-css-gen/build-node/errors.d.ts | 101 - .../critical-css-gen/build-node/errors.js | 103 - .../critical-css-gen/build-node/errors.js.map | 1 - .../build-node/generate-critical-css.d.ts | 24 - .../build-node/generate-critical-css.js | 162 - .../build-node/generate-critical-css.js.map | 1 - .../build-node/ignored-pseudo-elements.d.ts | 8 - .../build-node/ignored-pseudo-elements.js | 35 - .../build-node/ignored-pseudo-elements.js.map | 1 - .../build-node/minify-css.d.ts | 11 - .../critical-css-gen/build-node/minify-css.js | 19 - .../build-node/minify-css.js.map | 1 - .../critical-css-gen/build-node/node.d.ts | 5 - .../critical-css-gen/build-node/node.js | 6 - .../critical-css-gen/build-node/node.js.map | 1 - .../build-node/object-promise-all.d.ts | 12 - .../build-node/object-promise-all.js | 16 - .../build-node/object-promise-all.js.map | 1 - .../build-node/style-ast.d.ts | 164 - .../critical-css-gen/build-node/style-ast.js | 540 - .../build-node/style-ast.js.map | 1 - .../critical-css-gen/build-node/types.d.ts | 14 - .../critical-css-gen/build-node/types.js | 2 - .../critical-css-gen/build-node/types.js.map | 1 - ...update-protect-show-results-while-scanning | 4 - 38 files changed, 39468 deletions(-) delete mode 100644 projects/js-packages/critical-css-gen/build-browser/bundle.full.js delete mode 100644 projects/js-packages/critical-css-gen/build-browser/bundle.full.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-browser/bundle.js delete mode 100644 projects/js-packages/critical-css-gen/build-browser/bundle.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface-playwright.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface-playwright.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface-playwright.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/browser-interface.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/css-file-set.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/css-file-set.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/css-file-set.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/errors.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/errors.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/errors.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/generate-critical-css.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/generate-critical-css.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/generate-critical-css.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/ignored-pseudo-elements.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/ignored-pseudo-elements.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/ignored-pseudo-elements.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/minify-css.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/minify-css.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/minify-css.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/node.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/node.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/node.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/object-promise-all.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/object-promise-all.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/object-promise-all.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/style-ast.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/style-ast.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/style-ast.js.map delete mode 100644 projects/js-packages/critical-css-gen/build-node/types.d.ts delete mode 100644 projects/js-packages/critical-css-gen/build-node/types.js delete mode 100644 projects/js-packages/critical-css-gen/build-node/types.js.map delete mode 100644 projects/js-packages/critical-css-gen/changelog/update-protect-show-results-while-scanning diff --git a/projects/js-packages/critical-css-gen/build-browser/bundle.full.js b/projects/js-packages/critical-css-gen/build-browser/bundle.full.js deleted file mode 100644 index 7067826c27ecf..0000000000000 --- a/projects/js-packages/critical-css-gen/build-browser/bundle.full.js +++ /dev/null @@ -1,37567 +0,0 @@ -var CriticalCSSGenerator = (function (exports) { - 'use strict'; - - class BrowserInterface { - constructor() { - this.urlErrors = {}; - } - trackUrlError(url, error) { - this.urlErrors[url] = error; - } - filterValidUrls(urls) { - return urls.filter(url => !this.urlErrors[url]); - } - async runInPage(_pageUrl, _viewport, _method, ..._args) { - throw new Error('Undefined interface method: BrowserInterface.runInPage()'); - } - /** - * Context-specific wrapper for fetch; uses window.fetch in browsers, or a - * node library when using Puppeteer. - * - * @param {string} _url - The URL to fetch - * @param {FetchOptions} _options - Fetch options - * @param {'css' | 'html'} _role - Role of the fetch operation - */ - async fetch(_url, _options, _role) { - throw new Error('Undefined interface method: BrowserInterface.fetch()'); - } - async cleanup() { - // No-op. - } - async getCssIncludes(pageUrl) { - return await this.runInPage(pageUrl, null, BrowserInterface.innerGetCssIncludes); - } - static innerGetCssIncludes({ innerWindow }) { - innerWindow = null === innerWindow ? window : innerWindow; - return [...innerWindow.document.getElementsByTagName('link')] - .filter(link => link.rel === 'stylesheet') - .reduce((set, link) => { - set[link.href] = { - media: link.media || null, - }; - return set; - }, {}); - } - async getInternalStyles(pageUrl) { - return await this.runInPage(pageUrl, null, BrowserInterface.innerGetInternalStyles); - } - /** - * Get all internal styles as a combined string from the window. - * - * @param {object} wrappedArgs - Object containing the inner window. - * @param {Window} wrappedArgs.innerWindow - Window inside the browser interface. - * @return {string} Combined internal styles as a string. - */ - static innerGetInternalStyles({ innerWindow }) { - innerWindow = null === innerWindow ? window : innerWindow; - const styleElements = Array.from(innerWindow.document.getElementsByTagName('style')); - return styleElements.reduce((styles, style) => { - styles += style.innerText; - return styles; - }, ''); - } - /** - * Given a set of CSS selectors (as object keys), along with "simplified" versions - * for easy querySelector calling (values), return an array of selectors which match - * _any_ element on the page. - * - * @param {object} wrappedArgs - Object containing the inner window and arguments. - * @param {Window} wrappedArgs.innerWindow - Window inside the browser interface. - * @param {Object[]} wrappedArgs.args - Array of arguments. - * {Object} wrappedArgs.args[selectors] - Map containing selectors (object keys), and simplified versions for easy matching (values). - * @return {string[]} Array of selectors matching above-the-fold elements. - */ - static innerFindMatchingSelectors({ innerWindow, args: [selectors] }) { - innerWindow = null === innerWindow ? window : innerWindow; - return Object.keys(selectors).filter(selector => { - try { - return !!innerWindow.document.querySelector(selectors[selector]); - } - catch (err) { - // Ignore invalid selectors. - return false; - } - }); - } - /** - * Given a set of CSS selectors (as object keys), along with "simplified" versions - * for easy querySelector calling (values), return an array of selectors which match - * any above-the-fold element on the page. - * - * @param {object} wrappedArgs - Object containing the inner window and arguments. - * @param {Window} wrappedArgs.innerWindow - Window inside the browser interface. - * @param {Object[]} wrappedArgs.args - Array of arguments. - * {Object} wrappedArgs.args[selectors] - Map containing selectors (object keys), and simplified versions for easy matching (values). - * {string[]} wrappedArgs.args[pageSelectors] - String array containing selectors that appear anywhere on this page (as returned by innerFindMatchingSelectors) - should be a subset of keys in selectors. - * @return {string[]} Array of selectors matching above-the-fold elements. - */ - static innerFindAboveFoldSelectors({ innerWindow, args: [selectors, pageSelectors], }) { - /** - * Inner helper function used inside browser / iframe to check if the given - * element is "above the fold". - * - * @param {HTMLElement} element - Element to check. - */ - innerWindow = null === innerWindow ? window : innerWindow; - const isAboveFold = element => { - const originalClearStyle = element.style.clear || ''; - element.style.clear = 'none'; - const rect = element.getBoundingClientRect(); - element.style.clear = originalClearStyle; - return rect.top < innerWindow.innerHeight; - }; - return pageSelectors.filter(s => { - if ('*' === selectors[s]) { - return true; - } - const matches = innerWindow.document.querySelectorAll(selectors[s]); - for (const match of matches) { - if (isAboveFold(match)) { - return true; - } - } - return false; - }); - } - } - - /** - * SuccessTargetError - Indicates that insufficient pages loaded to meet - * a specified success target. Contains information about each error that caused - * problems and the URLs they affect. - */ - class SuccessTargetError extends Error { - constructor(urlErrors) { - super('Insufficient pages loaded to meet success target. Errors:\n' + - Object.values(urlErrors) - .map(e => e.message) - .join('\n')); - // Mark this as a SuccessTargetError in an easy way for other code to check. - this.isSuccessTargetError = true; - // Convert any Error object into reliable {message,type,meta} objects. - this.urlErrors = {}; - for (const [url, errorObject] of Object.entries(urlErrors)) { - this.urlErrors[url] = { - message: errorObject.message, - type: errorObject.type || 'UnknownError', - meta: errorObject.meta || {}, - }; - } - } - } - /** - * Base class for URL specific errors, which can be bundled inside a - * SuccessTargetError. - */ - class UrlError extends Error { - constructor(type, meta, message) { - super(message); - this.type = type; - this.meta = meta; - } - } - /** - * HttpError - Indicates an HTTP request has failed with a non-2xx status code. - */ - class HttpError extends UrlError { - constructor({ url, code }) { - super('HttpError', { url, code }, `HTTP error ${code} on URL ${url}`); - } - } - /** - * UnknownError - Indicates that fetch() threw an error with its own error string. - * Contains a raw (and difficult to translate) error message generated by fetch. - */ - class UnknownError extends UrlError { - constructor({ url, message }) { - super('UnknownError', { url, message }, `Error while loading ${url}: ${message}`); - } - } - /** - * CrossDomainError - Indicates that a requested URL failed due to CORS / security - * limitations imposed by the browser. - */ - class CrossDomainError extends UrlError { - constructor({ url }) { - super('CrossDomainError', { url }, `Failed to fetch cross-domain content at ${url}`); - } - } - /** - * LoadTimeoutError - Indicates that an HTTP request failed due to a timeout. - */ - class LoadTimeoutError extends UrlError { - constructor({ url }) { - super('LoadTimeoutError', { url }, `Timeout while reading ${url}`); - } - } - /** - * RedirectError - Indicates that a requested URL failed due to an HTTP redirection of that url. - */ - class RedirectError extends UrlError { - constructor({ url, redirectUrl }) { - super('RedirectError', { url, redirectUrl }, `Failed to process ${url} because it redirects to ${redirectUrl} which cannot be verified`); - } - } - /** - * UrlVerifyError - Indicates that a provided BrowserInterface verifyUrl - * callback returned false for a page which was otherwise loaded successfully. - */ - class UrlVerifyError extends UrlError { - constructor({ url }) { - super('UrlVerifyError', { url }, `Failed to verify page at ${url}`); - } - } - /** - * EmptyCSSError - Indicates that a requested URL does not have any CSS in its external style sheet(s) and therefore Critical CSS could not be generated. - */ - class EmptyCSSError extends UrlError { - constructor({ url }) { - super('EmptyCSSError', { url }, `The ${url} does not have any CSS in its external style sheet(s).`); - } - } - /** - * XFrameDenyError - Indicates that a requested URL failed due to x-frame-options deny configuration - */ - class XFrameDenyError extends UrlError { - constructor({ url }) { - super('XFrameDenyError', { url }, `Failed to load ${url} due to the "X-Frame-Options: DENY" header`); - } - } - - const defaultLoadTimeout = 60 * 1000; - class BrowserInterfaceIframe extends BrowserInterface { - constructor({ requestGetParameters, loadTimeout, verifyPage, allowScripts, }) { - super(); - this.requestGetParameters = requestGetParameters || {}; - this.loadTimeout = loadTimeout || defaultLoadTimeout; - this.verifyPage = verifyPage; - // Default 'allowScripts' to true if not specified. - allowScripts = allowScripts !== false; - this.currentUrl = null; - this.currentSize = { width: null, height: null }; - // Create a wrapper div to keep the iframe invisible. - this.wrapperDiv = document.createElement('div'); - this.wrapperDiv.setAttribute('style', 'position:fixed; z-index: -1000; opacity: 0; top: 50px;'); - document.body.append(this.wrapperDiv); - // Create iframe itself. - this.iframe = document.createElement('iframe'); - this.iframe.setAttribute('style', 'max-width: none; max-height: none; border: 0px;'); - this.iframe.setAttribute('aria-hidden', 'true'); - this.iframe.setAttribute('sandbox', 'allow-same-origin ' + (allowScripts ? 'allow-scripts' : '')); - this.wrapperDiv.append(this.iframe); - } - async cleanup() { - this.iframe.remove(); - this.wrapperDiv.remove(); - } - async fetch(url, options, _role) { - return window.fetch(url, options); - } - async runInPage(pageUrl, viewport, method, ...args) { - await this.loadPage(pageUrl); - if (viewport) { - await this.resize(viewport); - } - // The inner window in the iframe is separate from the main window object. - // Pass the iframe window object to the evaluating method. - return method({ innerWindow: this.iframe.contentWindow, args }); - } - addGetParameters(rawUrl) { - const urlObject = new URL(rawUrl); - for (const key of Object.keys(this.requestGetParameters)) { - urlObject.searchParams.append(key, this.requestGetParameters[key]); - } - return urlObject.toString(); - } - async diagnoseUrlError(url) { - try { - const response = await this.fetch(url, { redirect: 'manual' }, 'html'); - const headers = response.headers; - if (headers.get('x-frame-options') === 'DENY') { - return new XFrameDenyError({ url }); - } - if (response.type === 'opaqueredirect') { - return new RedirectError({ - url, - redirectUrl: response.url, - }); - } - if (response.status === 200) { - return null; - } - return new HttpError({ url, code: response.status }); - } - catch (err) { - return new UnknownError({ url, message: err.message }); - } - } - sameOrigin(url) { - return new URL(url).origin === window.location.origin; - } - async loadPage(rawUrl) { - if (rawUrl === this.currentUrl) { - return; - } - const fullUrl = this.addGetParameters(rawUrl); - return new Promise((resolve, rawReject) => { - // Track all URL errors. - const reject = err => { - this.trackUrlError(rawUrl, err); - rawReject(err); - }; - // Catch cross-domain errors before they occur. - if (!this.sameOrigin(fullUrl)) { - reject(new CrossDomainError({ url: fullUrl })); - return; - } - // Set a timeout. - const timeoutId = setTimeout(() => { - this.iframe.onload = null; - reject(new LoadTimeoutError({ url: fullUrl })); - }, this.loadTimeout); - // Catch load event. - this.iframe.onload = async () => { - try { - this.iframe.onload = null; - clearTimeout(timeoutId); - // Verify the inner document is readable. - if (!this.iframe.contentDocument || !this.iframe.contentWindow) { - throw ((await this.diagnoseUrlError(fullUrl)) || new CrossDomainError({ url: fullUrl })); - } - if (!this.verifyPage(rawUrl, this.iframe.contentWindow, this.iframe.contentDocument)) { - // Diagnose and throw an appropriate error. - throw ((await this.diagnoseUrlError(fullUrl)) || new UrlVerifyError({ url: fullUrl })); - } - this.currentUrl = rawUrl; - resolve(); - } - catch (err) { - reject(err); - } - }; - this.iframe.src = fullUrl; - }); - } - async resize({ width, height }) { - if (this.currentSize.width === width && this.currentSize.height === height) { - return; - } - return new Promise(resolve => { - // Set iframe size. - this.iframe.width = width.toString(); - this.iframe.height = height.toString(); - // Bounce to browser main loop to allow resize to complete. - setTimeout(resolve, 1); - }); - } - } - - // CSS Syntax Module Level 3 - // https://www.w3.org/TR/css-syntax-3/ - const EOF$1 = 0; // - const Ident = 1; // - const Function$1 = 2; // - const AtKeyword = 3; // - const Hash$1 = 4; // - const String$2 = 5; // - const BadString = 6; // - const Url$2 = 7; // - const BadUrl = 8; // - const Delim = 9; // - const Number$2 = 10; // - const Percentage$1 = 11; // - const Dimension$1 = 12; // - const WhiteSpace$1 = 13; // - const CDO$1 = 14; // - const CDC$1 = 15; // - const Colon = 16; // : - const Semicolon = 17; // ; - const Comma = 18; // , - const LeftSquareBracket = 19; // <[-token> - const RightSquareBracket = 20; // <]-token> - const LeftParenthesis = 21; // <(-token> - const RightParenthesis = 22; // <)-token> - const LeftCurlyBracket = 23; // <{-token> - const RightCurlyBracket = 24; // <}-token> - const Comment$1 = 25; - - const EOF = 0; - - // https://drafts.csswg.org/css-syntax-3/ - // § 4.2. Definitions - - // digit - // A code point between U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9). - function isDigit(code) { - return code >= 0x0030 && code <= 0x0039; - } - - // hex digit - // A digit, or a code point between U+0041 LATIN CAPITAL LETTER A (A) and U+0046 LATIN CAPITAL LETTER F (F), - // or a code point between U+0061 LATIN SMALL LETTER A (a) and U+0066 LATIN SMALL LETTER F (f). - function isHexDigit(code) { - return ( - isDigit(code) || // 0 .. 9 - (code >= 0x0041 && code <= 0x0046) || // A .. F - (code >= 0x0061 && code <= 0x0066) // a .. f - ); - } - - // uppercase letter - // A code point between U+0041 LATIN CAPITAL LETTER A (A) and U+005A LATIN CAPITAL LETTER Z (Z). - function isUppercaseLetter(code) { - return code >= 0x0041 && code <= 0x005A; - } - - // lowercase letter - // A code point between U+0061 LATIN SMALL LETTER A (a) and U+007A LATIN SMALL LETTER Z (z). - function isLowercaseLetter(code) { - return code >= 0x0061 && code <= 0x007A; - } - - // letter - // An uppercase letter or a lowercase letter. - function isLetter(code) { - return isUppercaseLetter(code) || isLowercaseLetter(code); - } - - // non-ASCII code point - // A code point with a value equal to or greater than U+0080 . - function isNonAscii(code) { - return code >= 0x0080; - } - - // name-start code point - // A letter, a non-ASCII code point, or U+005F LOW LINE (_). - function isNameStart(code) { - return isLetter(code) || isNonAscii(code) || code === 0x005F; - } - - // name code point - // A name-start code point, a digit, or U+002D HYPHEN-MINUS (-). - function isName(code) { - return isNameStart(code) || isDigit(code) || code === 0x002D; - } - - // non-printable code point - // A code point between U+0000 NULL and U+0008 BACKSPACE, or U+000B LINE TABULATION, - // or a code point between U+000E SHIFT OUT and U+001F INFORMATION SEPARATOR ONE, or U+007F DELETE. - function isNonPrintable(code) { - return ( - (code >= 0x0000 && code <= 0x0008) || - (code === 0x000B) || - (code >= 0x000E && code <= 0x001F) || - (code === 0x007F) - ); - } - - // newline - // U+000A LINE FEED. Note that U+000D CARRIAGE RETURN and U+000C FORM FEED are not included in this definition, - // as they are converted to U+000A LINE FEED during preprocessing. - // TODO: we doesn't do a preprocessing, so check a code point for U+000D CARRIAGE RETURN and U+000C FORM FEED - function isNewline(code) { - return code === 0x000A || code === 0x000D || code === 0x000C; - } - - // whitespace - // A newline, U+0009 CHARACTER TABULATION, or U+0020 SPACE. - function isWhiteSpace(code) { - return isNewline(code) || code === 0x0020 || code === 0x0009; - } - - // § 4.3.8. Check if two code points are a valid escape - function isValidEscape(first, second) { - // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. - if (first !== 0x005C) { - return false; - } - - // Otherwise, if the second code point is a newline or EOF, return false. - if (isNewline(second) || second === EOF) { - return false; - } - - // Otherwise, return true. - return true; - } - - // § 4.3.9. Check if three code points would start an identifier - function isIdentifierStart(first, second, third) { - // Look at the first code point: - - // U+002D HYPHEN-MINUS - if (first === 0x002D) { - // If the second code point is a name-start code point or a U+002D HYPHEN-MINUS, - // or the second and third code points are a valid escape, return true. Otherwise, return false. - return ( - isNameStart(second) || - second === 0x002D || - isValidEscape(second, third) - ); - } - - // name-start code point - if (isNameStart(first)) { - // Return true. - return true; - } - - // U+005C REVERSE SOLIDUS (\) - if (first === 0x005C) { - // If the first and second code points are a valid escape, return true. Otherwise, return false. - return isValidEscape(first, second); - } - - // anything else - // Return false. - return false; - } - - // § 4.3.10. Check if three code points would start a number - function isNumberStart(first, second, third) { - // Look at the first code point: - - // U+002B PLUS SIGN (+) - // U+002D HYPHEN-MINUS (-) - if (first === 0x002B || first === 0x002D) { - // If the second code point is a digit, return true. - if (isDigit(second)) { - return 2; - } - - // Otherwise, if the second code point is a U+002E FULL STOP (.) - // and the third code point is a digit, return true. - // Otherwise, return false. - return second === 0x002E && isDigit(third) ? 3 : 0; - } - - // U+002E FULL STOP (.) - if (first === 0x002E) { - // If the second code point is a digit, return true. Otherwise, return false. - return isDigit(second) ? 2 : 0; - } - - // digit - if (isDigit(first)) { - // Return true. - return 1; - } - - // anything else - // Return false. - return 0; - } - - // - // Misc - // - - // detect BOM (https://en.wikipedia.org/wiki/Byte_order_mark) - function isBOM(code) { - // UTF-16BE - if (code === 0xFEFF) { - return 1; - } - - // UTF-16LE - if (code === 0xFFFE) { - return 1; - } - - return 0; - } - - // Fast code category - // Only ASCII code points has a special meaning, that's why we define a maps for 0..127 codes only - const CATEGORY = new Array(0x80); - const EofCategory = 0x80; - const WhiteSpaceCategory = 0x82; - const DigitCategory = 0x83; - const NameStartCategory = 0x84; - const NonPrintableCategory = 0x85; - - for (let i = 0; i < CATEGORY.length; i++) { - CATEGORY[i] = - isWhiteSpace(i) && WhiteSpaceCategory || - isDigit(i) && DigitCategory || - isNameStart(i) && NameStartCategory || - isNonPrintable(i) && NonPrintableCategory || - i || EofCategory; - } - - function charCodeCategory(code) { - return code < 0x80 ? CATEGORY[code] : NameStartCategory; - } - - function getCharCode(source, offset) { - return offset < source.length ? source.charCodeAt(offset) : 0; - } - - function getNewlineLength(source, offset, code) { - if (code === 13 /* \r */ && getCharCode(source, offset + 1) === 10 /* \n */) { - return 2; - } - - return 1; - } - - function cmpChar(testStr, offset, referenceCode) { - let code = testStr.charCodeAt(offset); - - // code.toLowerCase() for A..Z - if (isUppercaseLetter(code)) { - code = code | 32; - } - - return code === referenceCode; - } - - function cmpStr(testStr, start, end, referenceStr) { - if (end - start !== referenceStr.length) { - return false; - } - - if (start < 0 || end > testStr.length) { - return false; - } - - for (let i = start; i < end; i++) { - const referenceCode = referenceStr.charCodeAt(i - start); - let testCode = testStr.charCodeAt(i); - - // testCode.toLowerCase() for A..Z - if (isUppercaseLetter(testCode)) { - testCode = testCode | 32; - } - - if (testCode !== referenceCode) { - return false; - } - } - - return true; - } - - function findWhiteSpaceStart(source, offset) { - for (; offset >= 0; offset--) { - if (!isWhiteSpace(source.charCodeAt(offset))) { - break; - } - } - - return offset + 1; - } - - function findWhiteSpaceEnd(source, offset) { - for (; offset < source.length; offset++) { - if (!isWhiteSpace(source.charCodeAt(offset))) { - break; - } - } - - return offset; - } - - function findDecimalNumberEnd(source, offset) { - for (; offset < source.length; offset++) { - if (!isDigit(source.charCodeAt(offset))) { - break; - } - } - - return offset; - } - - // § 4.3.7. Consume an escaped code point - function consumeEscaped(source, offset) { - // It assumes that the U+005C REVERSE SOLIDUS (\) has already been consumed and - // that the next input code point has already been verified to be part of a valid escape. - offset += 2; - - // hex digit - if (isHexDigit(getCharCode(source, offset - 1))) { - // Consume as many hex digits as possible, but no more than 5. - // Note that this means 1-6 hex digits have been consumed in total. - for (const maxOffset = Math.min(source.length, offset + 5); offset < maxOffset; offset++) { - if (!isHexDigit(getCharCode(source, offset))) { - break; - } - } - - // If the next input code point is whitespace, consume it as well. - const code = getCharCode(source, offset); - if (isWhiteSpace(code)) { - offset += getNewlineLength(source, offset, code); - } - } - - return offset; - } - - // §4.3.11. Consume a name - // Note: This algorithm does not do the verification of the first few code points that are necessary - // to ensure the returned code points would constitute an . If that is the intended use, - // ensure that the stream starts with an identifier before calling this algorithm. - function consumeName(source, offset) { - // Let result initially be an empty string. - // Repeatedly consume the next input code point from the stream: - for (; offset < source.length; offset++) { - const code = source.charCodeAt(offset); - - // name code point - if (isName(code)) { - // Append the code point to result. - continue; - } - - // the stream starts with a valid escape - if (isValidEscape(code, getCharCode(source, offset + 1))) { - // Consume an escaped code point. Append the returned code point to result. - offset = consumeEscaped(source, offset) - 1; - continue; - } - - // anything else - // Reconsume the current input code point. Return result. - break; - } - - return offset; - } - - // §4.3.12. Consume a number - function consumeNumber$1(source, offset) { - let code = source.charCodeAt(offset); - - // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), - // consume it and append it to repr. - if (code === 0x002B || code === 0x002D) { - code = source.charCodeAt(offset += 1); - } - - // 3. While the next input code point is a digit, consume it and append it to repr. - if (isDigit(code)) { - offset = findDecimalNumberEnd(source, offset + 1); - code = source.charCodeAt(offset); - } - - // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: - if (code === 0x002E && isDigit(source.charCodeAt(offset + 1))) { - // 4.1 Consume them. - // 4.2 Append them to repr. - offset += 2; - - // 4.3 Set type to "number". - // TODO - - // 4.4 While the next input code point is a digit, consume it and append it to repr. - - offset = findDecimalNumberEnd(source, offset); - } - - // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) - // or U+0065 LATIN SMALL LETTER E (e), ... , followed by a digit, then: - if (cmpChar(source, offset, 101 /* e */)) { - let sign = 0; - code = source.charCodeAt(offset + 1); - - // ... optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+) ... - if (code === 0x002D || code === 0x002B) { - sign = 1; - code = source.charCodeAt(offset + 2); - } - - // ... followed by a digit - if (isDigit(code)) { - // 5.1 Consume them. - // 5.2 Append them to repr. - - // 5.3 Set type to "number". - // TODO - - // 5.4 While the next input code point is a digit, consume it and append it to repr. - offset = findDecimalNumberEnd(source, offset + 1 + sign + 1); - } - } - - return offset; - } - - // § 4.3.14. Consume the remnants of a bad url - // ... its sole use is to consume enough of the input stream to reach a recovery point - // where normal tokenizing can resume. - function consumeBadUrlRemnants(source, offset) { - // Repeatedly consume the next input code point from the stream: - for (; offset < source.length; offset++) { - const code = source.charCodeAt(offset); - - // U+0029 RIGHT PARENTHESIS ()) - // EOF - if (code === 0x0029) { - // Return. - offset++; - break; - } - - if (isValidEscape(code, getCharCode(source, offset + 1))) { - // Consume an escaped code point. - // Note: This allows an escaped right parenthesis ("\)") to be encountered - // without ending the . This is otherwise identical to - // the "anything else" clause. - offset = consumeEscaped(source, offset); - } - } - - return offset; - } - - // § 4.3.7. Consume an escaped code point - // Note: This algorithm assumes that escaped is valid without leading U+005C REVERSE SOLIDUS (\) - function decodeEscaped(escaped) { - // Single char escaped that's not a hex digit - if (escaped.length === 1 && !isHexDigit(escaped.charCodeAt(0))) { - return escaped[0]; - } - - // Interpret the hex digits as a hexadecimal number. - let code = parseInt(escaped, 16); - - if ( - (code === 0) || // If this number is zero, - (code >= 0xD800 && code <= 0xDFFF) || // or is for a surrogate, - (code > 0x10FFFF) // or is greater than the maximum allowed code point - ) { - // ... return U+FFFD REPLACEMENT CHARACTER - code = 0xFFFD; - } - - // Otherwise, return the code point with that value. - return String.fromCodePoint(code); - } - - var tokenNames = [ - 'EOF-token', - 'ident-token', - 'function-token', - 'at-keyword-token', - 'hash-token', - 'string-token', - 'bad-string-token', - 'url-token', - 'bad-url-token', - 'delim-token', - 'number-token', - 'percentage-token', - 'dimension-token', - 'whitespace-token', - 'CDO-token', - 'CDC-token', - 'colon-token', - 'semicolon-token', - 'comma-token', - '[-token', - ']-token', - '(-token', - ')-token', - '{-token', - '}-token' - ]; - - const MIN_SIZE = 16 * 1024; - - function adoptBuffer(buffer = null, size) { - if (buffer === null || buffer.length < size) { - return new Uint32Array(Math.max(size + 1024, MIN_SIZE)); - } - - return buffer; - } - - const N$4 = 10; - const F$2 = 12; - const R$2 = 13; - - function computeLinesAndColumns(host) { - const source = host.source; - const sourceLength = source.length; - const startOffset = source.length > 0 ? isBOM(source.charCodeAt(0)) : 0; - const lines = adoptBuffer(host.lines, sourceLength); - const columns = adoptBuffer(host.columns, sourceLength); - let line = host.startLine; - let column = host.startColumn; - - for (let i = startOffset; i < sourceLength; i++) { - const code = source.charCodeAt(i); - - lines[i] = line; - columns[i] = column++; - - if (code === N$4 || code === R$2 || code === F$2) { - if (code === R$2 && i + 1 < sourceLength && source.charCodeAt(i + 1) === N$4) { - i++; - lines[i] = line; - columns[i] = column; - } - - line++; - column = 1; - } - } - - lines[sourceLength] = line; - columns[sourceLength] = column; - - host.lines = lines; - host.columns = columns; - host.computed = true; - } - - class OffsetToLocation { - constructor() { - this.lines = null; - this.columns = null; - this.computed = false; - } - setSource(source, startOffset = 0, startLine = 1, startColumn = 1) { - this.source = source; - this.startOffset = startOffset; - this.startLine = startLine; - this.startColumn = startColumn; - this.computed = false; - } - getLocation(offset, filename) { - if (!this.computed) { - computeLinesAndColumns(this); - } - - return { - source: filename, - offset: this.startOffset + offset, - line: this.lines[offset], - column: this.columns[offset] - }; - } - getLocationRange(start, end, filename) { - if (!this.computed) { - computeLinesAndColumns(this); - } - - return { - source: filename, - start: { - offset: this.startOffset + start, - line: this.lines[start], - column: this.columns[start] - }, - end: { - offset: this.startOffset + end, - line: this.lines[end], - column: this.columns[end] - } - }; - } - } - - const OFFSET_MASK = 0x00FFFFFF; - const TYPE_SHIFT = 24; - const balancePair$1 = new Map([ - [Function$1, RightParenthesis], - [LeftParenthesis, RightParenthesis], - [LeftSquareBracket, RightSquareBracket], - [LeftCurlyBracket, RightCurlyBracket] - ]); - - class TokenStream { - constructor(source, tokenize) { - this.setSource(source, tokenize); - } - reset() { - this.eof = false; - this.tokenIndex = -1; - this.tokenType = 0; - this.tokenStart = this.firstCharOffset; - this.tokenEnd = this.firstCharOffset; - } - setSource(source = '', tokenize = () => {}) { - source = String(source || ''); - - const sourceLength = source.length; - const offsetAndType = adoptBuffer(this.offsetAndType, source.length + 1); // +1 because of eof-token - const balance = adoptBuffer(this.balance, source.length + 1); - let tokenCount = 0; - let balanceCloseType = 0; - let balanceStart = 0; - let firstCharOffset = -1; - - // capture buffers - this.offsetAndType = null; - this.balance = null; - - tokenize(source, (type, start, end) => { - switch (type) { - default: - balance[tokenCount] = sourceLength; - break; - - case balanceCloseType: { - let balancePrev = balanceStart & OFFSET_MASK; - balanceStart = balance[balancePrev]; - balanceCloseType = balanceStart >> TYPE_SHIFT; - balance[tokenCount] = balancePrev; - balance[balancePrev++] = tokenCount; - for (; balancePrev < tokenCount; balancePrev++) { - if (balance[balancePrev] === sourceLength) { - balance[balancePrev] = tokenCount; - } - } - break; - } - - case LeftParenthesis: - case Function$1: - case LeftSquareBracket: - case LeftCurlyBracket: - balance[tokenCount] = balanceStart; - balanceCloseType = balancePair$1.get(type); - balanceStart = (balanceCloseType << TYPE_SHIFT) | tokenCount; - break; - } - - offsetAndType[tokenCount++] = (type << TYPE_SHIFT) | end; - if (firstCharOffset === -1) { - firstCharOffset = start; - } - }); - - // finalize buffers - offsetAndType[tokenCount] = (EOF$1 << TYPE_SHIFT) | sourceLength; // - balance[tokenCount] = sourceLength; - balance[sourceLength] = sourceLength; // prevents false positive balance match with any token - while (balanceStart !== 0) { - const balancePrev = balanceStart & OFFSET_MASK; - balanceStart = balance[balancePrev]; - balance[balancePrev] = sourceLength; - } - - this.source = source; - this.firstCharOffset = firstCharOffset === -1 ? 0 : firstCharOffset; - this.tokenCount = tokenCount; - this.offsetAndType = offsetAndType; - this.balance = balance; - - this.reset(); - this.next(); - } - - lookupType(offset) { - offset += this.tokenIndex; - - if (offset < this.tokenCount) { - return this.offsetAndType[offset] >> TYPE_SHIFT; - } - - return EOF$1; - } - lookupOffset(offset) { - offset += this.tokenIndex; - - if (offset < this.tokenCount) { - return this.offsetAndType[offset - 1] & OFFSET_MASK; - } - - return this.source.length; - } - lookupValue(offset, referenceStr) { - offset += this.tokenIndex; - - if (offset < this.tokenCount) { - return cmpStr( - this.source, - this.offsetAndType[offset - 1] & OFFSET_MASK, - this.offsetAndType[offset] & OFFSET_MASK, - referenceStr - ); - } - - return false; - } - getTokenStart(tokenIndex) { - if (tokenIndex === this.tokenIndex) { - return this.tokenStart; - } - - if (tokenIndex > 0) { - return tokenIndex < this.tokenCount - ? this.offsetAndType[tokenIndex - 1] & OFFSET_MASK - : this.offsetAndType[this.tokenCount] & OFFSET_MASK; - } - - return this.firstCharOffset; - } - substrToCursor(start) { - return this.source.substring(start, this.tokenStart); - } - - isBalanceEdge(pos) { - return this.balance[this.tokenIndex] < pos; - } - isDelim(code, offset) { - if (offset) { - return ( - this.lookupType(offset) === Delim && - this.source.charCodeAt(this.lookupOffset(offset)) === code - ); - } - - return ( - this.tokenType === Delim && - this.source.charCodeAt(this.tokenStart) === code - ); - } - - skip(tokenCount) { - let next = this.tokenIndex + tokenCount; - - if (next < this.tokenCount) { - this.tokenIndex = next; - this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK; - next = this.offsetAndType[next]; - this.tokenType = next >> TYPE_SHIFT; - this.tokenEnd = next & OFFSET_MASK; - } else { - this.tokenIndex = this.tokenCount; - this.next(); - } - } - next() { - let next = this.tokenIndex + 1; - - if (next < this.tokenCount) { - this.tokenIndex = next; - this.tokenStart = this.tokenEnd; - next = this.offsetAndType[next]; - this.tokenType = next >> TYPE_SHIFT; - this.tokenEnd = next & OFFSET_MASK; - } else { - this.eof = true; - this.tokenIndex = this.tokenCount; - this.tokenType = EOF$1; - this.tokenStart = this.tokenEnd = this.source.length; - } - } - skipSC() { - while (this.tokenType === WhiteSpace$1 || this.tokenType === Comment$1) { - this.next(); - } - } - skipUntilBalanced(startToken, stopConsume) { - let cursor = startToken; - let balanceEnd; - let offset; - - loop: - for (; cursor < this.tokenCount; cursor++) { - balanceEnd = this.balance[cursor]; - - // stop scanning on balance edge that points to offset before start token - if (balanceEnd < startToken) { - break loop; - } - - offset = cursor > 0 ? this.offsetAndType[cursor - 1] & OFFSET_MASK : this.firstCharOffset; - - // check stop condition - switch (stopConsume(this.source.charCodeAt(offset))) { - case 1: // just stop - break loop; - - case 2: // stop & included - cursor++; - break loop; - - default: - // fast forward to the end of balanced block - if (this.balance[balanceEnd] === cursor) { - cursor = balanceEnd; - } - } - } - - this.skip(cursor - this.tokenIndex); - } - - forEachToken(fn) { - for (let i = 0, offset = this.firstCharOffset; i < this.tokenCount; i++) { - const start = offset; - const item = this.offsetAndType[i]; - const end = item & OFFSET_MASK; - const type = item >> TYPE_SHIFT; - - offset = end; - - fn(type, start, end, i); - } - } - dump() { - const tokens = new Array(this.tokenCount); - - this.forEachToken((type, start, end, index) => { - tokens[index] = { - idx: index, - type: tokenNames[type], - chunk: this.source.substring(start, end), - balance: this.balance[index] - }; - }); - - return tokens; - } - } - - function tokenize$3(source, onToken) { - function getCharCode(offset) { - return offset < sourceLength ? source.charCodeAt(offset) : 0; - } - - // § 4.3.3. Consume a numeric token - function consumeNumericToken() { - // Consume a number and let number be the result. - offset = consumeNumber$1(source, offset); - - // If the next 3 input code points would start an identifier, then: - if (isIdentifierStart(getCharCode(offset), getCharCode(offset + 1), getCharCode(offset + 2))) { - // Create a with the same value and type flag as number, and a unit set initially to the empty string. - // Consume a name. Set the ’s unit to the returned value. - // Return the . - type = Dimension$1; - offset = consumeName(source, offset); - return; - } - - // Otherwise, if the next input code point is U+0025 PERCENTAGE SIGN (%), consume it. - if (getCharCode(offset) === 0x0025) { - // Create a with the same value as number, and return it. - type = Percentage$1; - offset++; - return; - } - - // Otherwise, create a with the same value and type flag as number, and return it. - type = Number$2; - } - - // § 4.3.4. Consume an ident-like token - function consumeIdentLikeToken() { - const nameStartOffset = offset; - - // Consume a name, and let string be the result. - offset = consumeName(source, offset); - - // If string’s value is an ASCII case-insensitive match for "url", - // and the next input code point is U+0028 LEFT PARENTHESIS ((), consume it. - if (cmpStr(source, nameStartOffset, offset, 'url') && getCharCode(offset) === 0x0028) { - // While the next two input code points are whitespace, consume the next input code point. - offset = findWhiteSpaceEnd(source, offset + 1); - - // If the next one or two input code points are U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), - // or whitespace followed by U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('), - // then create a with its value set to string and return it. - if (getCharCode(offset) === 0x0022 || - getCharCode(offset) === 0x0027) { - type = Function$1; - offset = nameStartOffset + 4; - return; - } - - // Otherwise, consume a url token, and return it. - consumeUrlToken(); - return; - } - - // Otherwise, if the next input code point is U+0028 LEFT PARENTHESIS ((), consume it. - // Create a with its value set to string and return it. - if (getCharCode(offset) === 0x0028) { - type = Function$1; - offset++; - return; - } - - // Otherwise, create an with its value set to string and return it. - type = Ident; - } - - // § 4.3.5. Consume a string token - function consumeStringToken(endingCodePoint) { - // This algorithm may be called with an ending code point, which denotes the code point - // that ends the string. If an ending code point is not specified, - // the current input code point is used. - if (!endingCodePoint) { - endingCodePoint = getCharCode(offset++); - } - - // Initially create a with its value set to the empty string. - type = String$2; - - // Repeatedly consume the next input code point from the stream: - for (; offset < source.length; offset++) { - const code = source.charCodeAt(offset); - - switch (charCodeCategory(code)) { - // ending code point - case endingCodePoint: - // Return the . - offset++; - return; - - // EOF - // case EofCategory: - // This is a parse error. Return the . - // return; - - // newline - case WhiteSpaceCategory: - if (isNewline(code)) { - // This is a parse error. Reconsume the current input code point, - // create a , and return it. - offset += getNewlineLength(source, offset, code); - type = BadString; - return; - } - break; - - // U+005C REVERSE SOLIDUS (\) - case 0x005C: - // If the next input code point is EOF, do nothing. - if (offset === source.length - 1) { - break; - } - - const nextCode = getCharCode(offset + 1); - - // Otherwise, if the next input code point is a newline, consume it. - if (isNewline(nextCode)) { - offset += getNewlineLength(source, offset + 1, nextCode); - } else if (isValidEscape(code, nextCode)) { - // Otherwise, (the stream starts with a valid escape) consume - // an escaped code point and append the returned code point to - // the ’s value. - offset = consumeEscaped(source, offset) - 1; - } - break; - - // anything else - // Append the current input code point to the ’s value. - } - } - } - - // § 4.3.6. Consume a url token - // Note: This algorithm assumes that the initial "url(" has already been consumed. - // This algorithm also assumes that it’s being called to consume an "unquoted" value, like url(foo). - // A quoted value, like url("foo"), is parsed as a . Consume an ident-like token - // automatically handles this distinction; this algorithm shouldn’t be called directly otherwise. - function consumeUrlToken() { - // Initially create a with its value set to the empty string. - type = Url$2; - - // Consume as much whitespace as possible. - offset = findWhiteSpaceEnd(source, offset); - - // Repeatedly consume the next input code point from the stream: - for (; offset < source.length; offset++) { - const code = source.charCodeAt(offset); - - switch (charCodeCategory(code)) { - // U+0029 RIGHT PARENTHESIS ()) - case 0x0029: - // Return the . - offset++; - return; - - // EOF - // case EofCategory: - // This is a parse error. Return the . - // return; - - // whitespace - case WhiteSpaceCategory: - // Consume as much whitespace as possible. - offset = findWhiteSpaceEnd(source, offset); - - // If the next input code point is U+0029 RIGHT PARENTHESIS ()) or EOF, - // consume it and return the - // (if EOF was encountered, this is a parse error); - if (getCharCode(offset) === 0x0029 || offset >= source.length) { - if (offset < source.length) { - offset++; - } - return; - } - - // otherwise, consume the remnants of a bad url, create a , - // and return it. - offset = consumeBadUrlRemnants(source, offset); - type = BadUrl; - return; - - // U+0022 QUOTATION MARK (") - // U+0027 APOSTROPHE (') - // U+0028 LEFT PARENTHESIS (() - // non-printable code point - case 0x0022: - case 0x0027: - case 0x0028: - case NonPrintableCategory: - // This is a parse error. Consume the remnants of a bad url, - // create a , and return it. - offset = consumeBadUrlRemnants(source, offset); - type = BadUrl; - return; - - // U+005C REVERSE SOLIDUS (\) - case 0x005C: - // If the stream starts with a valid escape, consume an escaped code point and - // append the returned code point to the ’s value. - if (isValidEscape(code, getCharCode(offset + 1))) { - offset = consumeEscaped(source, offset) - 1; - break; - } - - // Otherwise, this is a parse error. Consume the remnants of a bad url, - // create a , and return it. - offset = consumeBadUrlRemnants(source, offset); - type = BadUrl; - return; - - // anything else - // Append the current input code point to the ’s value. - } - } - } - - // ensure source is a string - source = String(source || ''); - - const sourceLength = source.length; - let start = isBOM(getCharCode(0)); - let offset = start; - let type; - - // https://drafts.csswg.org/css-syntax-3/#consume-token - // § 4.3.1. Consume a token - while (offset < sourceLength) { - const code = source.charCodeAt(offset); - - switch (charCodeCategory(code)) { - // whitespace - case WhiteSpaceCategory: - // Consume as much whitespace as possible. Return a . - type = WhiteSpace$1; - offset = findWhiteSpaceEnd(source, offset + 1); - break; - - // U+0022 QUOTATION MARK (") - case 0x0022: - // Consume a string token and return it. - consumeStringToken(); - break; - - // U+0023 NUMBER SIGN (#) - case 0x0023: - // If the next input code point is a name code point or the next two input code points are a valid escape, then: - if (isName(getCharCode(offset + 1)) || isValidEscape(getCharCode(offset + 1), getCharCode(offset + 2))) { - // Create a . - type = Hash$1; - - // If the next 3 input code points would start an identifier, set the ’s type flag to "id". - // if (isIdentifierStart(getCharCode(offset + 1), getCharCode(offset + 2), getCharCode(offset + 3))) { - // // TODO: set id flag - // } - - // Consume a name, and set the ’s value to the returned string. - offset = consumeName(source, offset + 1); - - // Return the . - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - - break; - - // U+0027 APOSTROPHE (') - case 0x0027: - // Consume a string token and return it. - consumeStringToken(); - break; - - // U+0028 LEFT PARENTHESIS (() - case 0x0028: - // Return a <(-token>. - type = LeftParenthesis; - offset++; - break; - - // U+0029 RIGHT PARENTHESIS ()) - case 0x0029: - // Return a <)-token>. - type = RightParenthesis; - offset++; - break; - - // U+002B PLUS SIGN (+) - case 0x002B: - // If the input stream starts with a number, ... - if (isNumberStart(code, getCharCode(offset + 1), getCharCode(offset + 2))) { - // ... reconsume the current input code point, consume a numeric token, and return it. - consumeNumericToken(); - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - break; - - // U+002C COMMA (,) - case 0x002C: - // Return a . - type = Comma; - offset++; - break; - - // U+002D HYPHEN-MINUS (-) - case 0x002D: - // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it. - if (isNumberStart(code, getCharCode(offset + 1), getCharCode(offset + 2))) { - consumeNumericToken(); - } else { - // Otherwise, if the next 2 input code points are U+002D HYPHEN-MINUS U+003E GREATER-THAN SIGN (->), consume them and return a . - if (getCharCode(offset + 1) === 0x002D && - getCharCode(offset + 2) === 0x003E) { - type = CDC$1; - offset = offset + 3; - } else { - // Otherwise, if the input stream starts with an identifier, ... - if (isIdentifierStart(code, getCharCode(offset + 1), getCharCode(offset + 2))) { - // ... reconsume the current input code point, consume an ident-like token, and return it. - consumeIdentLikeToken(); - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - } - } - break; - - // U+002E FULL STOP (.) - case 0x002E: - // If the input stream starts with a number, ... - if (isNumberStart(code, getCharCode(offset + 1), getCharCode(offset + 2))) { - // ... reconsume the current input code point, consume a numeric token, and return it. - consumeNumericToken(); - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - - break; - - // U+002F SOLIDUS (/) - case 0x002F: - // If the next two input code point are U+002F SOLIDUS (/) followed by a U+002A ASTERISK (*), - if (getCharCode(offset + 1) === 0x002A) { - // ... consume them and all following code points up to and including the first U+002A ASTERISK (*) - // followed by a U+002F SOLIDUS (/), or up to an EOF code point. - type = Comment$1; - offset = source.indexOf('*/', offset + 2); - offset = offset === -1 ? source.length : offset + 2; - } else { - type = Delim; - offset++; - } - break; - - // U+003A COLON (:) - case 0x003A: - // Return a . - type = Colon; - offset++; - break; - - // U+003B SEMICOLON (;) - case 0x003B: - // Return a . - type = Semicolon; - offset++; - break; - - // U+003C LESS-THAN SIGN (<) - case 0x003C: - // If the next 3 input code points are U+0021 EXCLAMATION MARK U+002D HYPHEN-MINUS U+002D HYPHEN-MINUS (!--), ... - if (getCharCode(offset + 1) === 0x0021 && - getCharCode(offset + 2) === 0x002D && - getCharCode(offset + 3) === 0x002D) { - // ... consume them and return a . - type = CDO$1; - offset = offset + 4; - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - - break; - - // U+0040 COMMERCIAL AT (@) - case 0x0040: - // If the next 3 input code points would start an identifier, ... - if (isIdentifierStart(getCharCode(offset + 1), getCharCode(offset + 2), getCharCode(offset + 3))) { - // ... consume a name, create an with its value set to the returned value, and return it. - type = AtKeyword; - offset = consumeName(source, offset + 1); - } else { - // Otherwise, return a with its value set to the current input code point. - type = Delim; - offset++; - } - - break; - - // U+005B LEFT SQUARE BRACKET ([) - case 0x005B: - // Return a <[-token>. - type = LeftSquareBracket; - offset++; - break; - - // U+005C REVERSE SOLIDUS (\) - case 0x005C: - // If the input stream starts with a valid escape, ... - if (isValidEscape(code, getCharCode(offset + 1))) { - // ... reconsume the current input code point, consume an ident-like token, and return it. - consumeIdentLikeToken(); - } else { - // Otherwise, this is a parse error. Return a with its value set to the current input code point. - type = Delim; - offset++; - } - break; - - // U+005D RIGHT SQUARE BRACKET (]) - case 0x005D: - // Return a <]-token>. - type = RightSquareBracket; - offset++; - break; - - // U+007B LEFT CURLY BRACKET ({) - case 0x007B: - // Return a <{-token>. - type = LeftCurlyBracket; - offset++; - break; - - // U+007D RIGHT CURLY BRACKET (}) - case 0x007D: - // Return a <}-token>. - type = RightCurlyBracket; - offset++; - break; - - // digit - case DigitCategory: - // Reconsume the current input code point, consume a numeric token, and return it. - consumeNumericToken(); - break; - - // name-start code point - case NameStartCategory: - // Reconsume the current input code point, consume an ident-like token, and return it. - consumeIdentLikeToken(); - break; - - // EOF - // case EofCategory: - // Return an . - // break; - - // anything else - default: - // Return a with its value set to the current input code point. - type = Delim; - offset++; - } - - // put token to stream - onToken(type, start, start = offset); - } - } - - // - // list - // ┌──────┐ - // ┌──────────────┼─head │ - // │ │ tail─┼──────────────┐ - // │ └──────┘ │ - // ▼ ▼ - // item item item item - // ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ - // null ◀──┼─prev │◀───┼─prev │◀───┼─prev │◀───┼─prev │ - // │ next─┼───▶│ next─┼───▶│ next─┼───▶│ next─┼──▶ null - // ├──────┤ ├──────┤ ├──────┤ ├──────┤ - // │ data │ │ data │ │ data │ │ data │ - // └──────┘ └──────┘ └──────┘ └──────┘ - // - - let releasedCursors = null; - - class List { - static createItem(data) { - return { - prev: null, - next: null, - data - }; - } - - constructor() { - this.head = null; - this.tail = null; - this.cursor = null; - } - createItem(data) { - return List.createItem(data); - } - - // cursor helpers - allocateCursor(prev, next) { - let cursor; - - if (releasedCursors !== null) { - cursor = releasedCursors; - releasedCursors = releasedCursors.cursor; - cursor.prev = prev; - cursor.next = next; - cursor.cursor = this.cursor; - } else { - cursor = { - prev, - next, - cursor: this.cursor - }; - } - - this.cursor = cursor; - - return cursor; - } - releaseCursor() { - const { cursor } = this; - - this.cursor = cursor.cursor; - cursor.prev = null; - cursor.next = null; - cursor.cursor = releasedCursors; - releasedCursors = cursor; - } - updateCursors(prevOld, prevNew, nextOld, nextNew) { - let { cursor } = this; - - while (cursor !== null) { - if (cursor.prev === prevOld) { - cursor.prev = prevNew; - } - - if (cursor.next === nextOld) { - cursor.next = nextNew; - } - - cursor = cursor.cursor; - } - } - *[Symbol.iterator]() { - for (let cursor = this.head; cursor !== null; cursor = cursor.next) { - yield cursor.data; - } - } - - // getters - get size() { - let size = 0; - - for (let cursor = this.head; cursor !== null; cursor = cursor.next) { - size++; - } - - return size; - } - get isEmpty() { - return this.head === null; - } - get first() { - return this.head && this.head.data; - } - get last() { - return this.tail && this.tail.data; - } - - // convertors - fromArray(array) { - let cursor = null; - this.head = null; - - for (let data of array) { - const item = List.createItem(data); - - if (cursor !== null) { - cursor.next = item; - } else { - this.head = item; - } - - item.prev = cursor; - cursor = item; - } - - this.tail = cursor; - return this; - } - toArray() { - return [...this]; - } - toJSON() { - return [...this]; - } - - // array-like methods - forEach(fn, thisArg = this) { - // push cursor - const cursor = this.allocateCursor(null, this.head); - - while (cursor.next !== null) { - const item = cursor.next; - cursor.next = item.next; - fn.call(thisArg, item.data, item, this); - } - - // pop cursor - this.releaseCursor(); - } - forEachRight(fn, thisArg = this) { - // push cursor - const cursor = this.allocateCursor(this.tail, null); - - while (cursor.prev !== null) { - const item = cursor.prev; - cursor.prev = item.prev; - fn.call(thisArg, item.data, item, this); - } - - // pop cursor - this.releaseCursor(); - } - reduce(fn, initialValue, thisArg = this) { - // push cursor - let cursor = this.allocateCursor(null, this.head); - let acc = initialValue; - let item; - - while (cursor.next !== null) { - item = cursor.next; - cursor.next = item.next; - - acc = fn.call(thisArg, acc, item.data, item, this); - } - - // pop cursor - this.releaseCursor(); - - return acc; - } - reduceRight(fn, initialValue, thisArg = this) { - // push cursor - let cursor = this.allocateCursor(this.tail, null); - let acc = initialValue; - let item; - - while (cursor.prev !== null) { - item = cursor.prev; - cursor.prev = item.prev; - - acc = fn.call(thisArg, acc, item.data, item, this); - } - - // pop cursor - this.releaseCursor(); - - return acc; - } - some(fn, thisArg = this) { - for (let cursor = this.head; cursor !== null; cursor = cursor.next) { - if (fn.call(thisArg, cursor.data, cursor, this)) { - return true; - } - } - - return false; - } - map(fn, thisArg = this) { - const result = new List(); - - for (let cursor = this.head; cursor !== null; cursor = cursor.next) { - result.appendData(fn.call(thisArg, cursor.data, cursor, this)); - } - - return result; - } - filter(fn, thisArg = this) { - const result = new List(); - - for (let cursor = this.head; cursor !== null; cursor = cursor.next) { - if (fn.call(thisArg, cursor.data, cursor, this)) { - result.appendData(cursor.data); - } - } - - return result; - } - - nextUntil(start, fn, thisArg = this) { - if (start === null) { - return; - } - - // push cursor - const cursor = this.allocateCursor(null, start); - - while (cursor.next !== null) { - const item = cursor.next; - cursor.next = item.next; - if (fn.call(thisArg, item.data, item, this)) { - break; - } - } - - // pop cursor - this.releaseCursor(); - } - prevUntil(start, fn, thisArg = this) { - if (start === null) { - return; - } - - // push cursor - const cursor = this.allocateCursor(start, null); - - while (cursor.prev !== null) { - const item = cursor.prev; - cursor.prev = item.prev; - if (fn.call(thisArg, item.data, item, this)) { - break; - } - } - - // pop cursor - this.releaseCursor(); - } - - // mutation - clear() { - this.head = null; - this.tail = null; - } - copy() { - const result = new List(); - - for (let data of this) { - result.appendData(data); - } - - return result; - } - prepend(item) { - // head - // ^ - // item - this.updateCursors(null, item, this.head, item); - - // insert to the beginning of the list - if (this.head !== null) { - // new item <- first item - this.head.prev = item; - // new item -> first item - item.next = this.head; - } else { - // if list has no head, then it also has no tail - // in this case tail points to the new item - this.tail = item; - } - - // head always points to new item - this.head = item; - return this; - } - prependData(data) { - return this.prepend(List.createItem(data)); - } - append(item) { - return this.insert(item); - } - appendData(data) { - return this.insert(List.createItem(data)); - } - insert(item, before = null) { - if (before !== null) { - // prev before - // ^ - // item - this.updateCursors(before.prev, item, before, item); - - if (before.prev === null) { - // insert to the beginning of list - if (this.head !== before) { - throw new Error('before doesn\'t belong to list'); - } - // since head points to before therefore list doesn't empty - // no need to check tail - this.head = item; - before.prev = item; - item.next = before; - this.updateCursors(null, item); - } else { - // insert between two items - before.prev.next = item; - item.prev = before.prev; - before.prev = item; - item.next = before; - } - } else { - // tail - // ^ - // item - this.updateCursors(this.tail, item, null, item); - - // insert to the ending of the list - if (this.tail !== null) { - // last item -> new item - this.tail.next = item; - // last item <- new item - item.prev = this.tail; - } else { - // if list has no tail, then it also has no head - // in this case head points to new item - this.head = item; - } - - // tail always points to new item - this.tail = item; - } - - return this; - } - insertData(data, before) { - return this.insert(List.createItem(data), before); - } - remove(item) { - // item - // ^ - // prev next - this.updateCursors(item, item.prev, item, item.next); - - if (item.prev !== null) { - item.prev.next = item.next; - } else { - if (this.head !== item) { - throw new Error('item doesn\'t belong to list'); - } - - this.head = item.next; - } - - if (item.next !== null) { - item.next.prev = item.prev; - } else { - if (this.tail !== item) { - throw new Error('item doesn\'t belong to list'); - } - - this.tail = item.prev; - } - - item.prev = null; - item.next = null; - - return item; - } - push(data) { - this.insert(List.createItem(data)); - } - pop() { - return this.tail !== null ? this.remove(this.tail) : null; - } - unshift(data) { - this.prepend(List.createItem(data)); - } - shift() { - return this.head !== null ? this.remove(this.head) : null; - } - prependList(list) { - return this.insertList(list, this.head); - } - appendList(list) { - return this.insertList(list); - } - insertList(list, before) { - // ignore empty lists - if (list.head === null) { - return this; - } - - if (before !== undefined && before !== null) { - this.updateCursors(before.prev, list.tail, before, list.head); - - // insert in the middle of dist list - if (before.prev !== null) { - // before.prev <-> list.head - before.prev.next = list.head; - list.head.prev = before.prev; - } else { - this.head = list.head; - } - - before.prev = list.tail; - list.tail.next = before; - } else { - this.updateCursors(this.tail, list.tail, null, list.head); - - // insert to end of the list - if (this.tail !== null) { - // if destination list has a tail, then it also has a head, - // but head doesn't change - // dest tail -> source head - this.tail.next = list.head; - // dest tail <- source head - list.head.prev = this.tail; - } else { - // if list has no a tail, then it also has no a head - // in this case points head to new item - this.head = list.head; - } - - // tail always start point to new item - this.tail = list.tail; - } - - list.head = null; - list.tail = null; - return this; - } - replace(oldItem, newItemOrList) { - if ('head' in newItemOrList) { - this.insertList(newItemOrList, oldItem); - } else { - this.insert(newItemOrList, oldItem); - } - - this.remove(oldItem); - } - } - - function createCustomError(name, message) { - // use Object.create(), because some VMs prevent setting line/column otherwise - // (iOS Safari 10 even throws an exception) - const error = Object.create(SyntaxError.prototype); - const errorStack = new Error(); - - return Object.assign(error, { - name, - message, - get stack() { - return (errorStack.stack || '').replace(/^(.+\n){1,3}/, `${name}: ${message}\n`); - } - }); - } - - const MAX_LINE_LENGTH = 100; - const OFFSET_CORRECTION = 60; - const TAB_REPLACEMENT = ' '; - - function sourceFragment({ source, line, column }, extraLines) { - function processLines(start, end) { - return lines - .slice(start, end) - .map((line, idx) => - String(start + idx + 1).padStart(maxNumLength) + ' |' + line - ).join('\n'); - } - - const lines = source.split(/\r\n?|\n|\f/); - const startLine = Math.max(1, line - extraLines) - 1; - const endLine = Math.min(line + extraLines, lines.length + 1); - const maxNumLength = Math.max(4, String(endLine).length) + 1; - let cutLeft = 0; - - // column correction according to replaced tab before column - column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length; - - if (column > MAX_LINE_LENGTH) { - cutLeft = column - OFFSET_CORRECTION + 3; - column = OFFSET_CORRECTION - 2; - } - - for (let i = startLine; i <= endLine; i++) { - if (i >= 0 && i < lines.length) { - lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT); - lines[i] = - (cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') + - lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) + - (lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : ''); - } - } - - return [ - processLines(startLine, line), - new Array(column + maxNumLength + 2).join('-') + '^', - processLines(line, endLine) - ].filter(Boolean).join('\n'); - } - - function SyntaxError$2(message, source, offset, line, column) { - const error = Object.assign(createCustomError('SyntaxError', message), { - source, - offset, - line, - column, - sourceFragment(extraLines) { - return sourceFragment({ source, line, column }, isNaN(extraLines) ? 0 : extraLines); - }, - get formattedMessage() { - return ( - `Parse error: ${message}\n` + - sourceFragment({ source, line, column }, 2) - ); - } - }); - - return error; - } - - function readSequence$1(recognizer) { - const children = this.createList(); - let space = false; - const context = { - recognizer - }; - - while (!this.eof) { - switch (this.tokenType) { - case Comment$1: - this.next(); - continue; - - case WhiteSpace$1: - space = true; - this.next(); - continue; - } - - let child = recognizer.getNode.call(this, context); - - if (child === undefined) { - break; - } - - if (space) { - if (recognizer.onWhiteSpace) { - recognizer.onWhiteSpace.call(this, child, children, context); - } - space = false; - } - - children.push(child); - } - - if (space && recognizer.onWhiteSpace) { - recognizer.onWhiteSpace.call(this, null, children, context); - } - - return children; - } - - const NOOP = () => {}; - const EXCLAMATIONMARK$3 = 0x0021; // U+0021 EXCLAMATION MARK (!) - const NUMBERSIGN$4 = 0x0023; // U+0023 NUMBER SIGN (#) - const SEMICOLON = 0x003B; // U+003B SEMICOLON (;) - const LEFTCURLYBRACKET$1 = 0x007B; // U+007B LEFT CURLY BRACKET ({) - const NULL = 0; - - function createParseContext(name) { - return function() { - return this[name](); - }; - } - - function fetchParseValues(dict) { - const result = Object.create(null); - - for (const name in dict) { - const item = dict[name]; - const fn = item.parse || item; - - if (fn) { - result[name] = fn; - } - } - - return result; - } - - function processConfig(config) { - const parseConfig = { - context: Object.create(null), - scope: Object.assign(Object.create(null), config.scope), - atrule: fetchParseValues(config.atrule), - pseudo: fetchParseValues(config.pseudo), - node: fetchParseValues(config.node) - }; - - for (const name in config.parseContext) { - switch (typeof config.parseContext[name]) { - case 'function': - parseConfig.context[name] = config.parseContext[name]; - break; - - case 'string': - parseConfig.context[name] = createParseContext(config.parseContext[name]); - break; - } - } - - return { - config: parseConfig, - ...parseConfig, - ...parseConfig.node - }; - } - - function createParser(config) { - let source = ''; - let filename = ''; - let needPositions = false; - let onParseError = NOOP; - let onParseErrorThrow = false; - - const locationMap = new OffsetToLocation(); - const parser = Object.assign(new TokenStream(), processConfig(config || {}), { - parseAtrulePrelude: true, - parseRulePrelude: true, - parseValue: true, - parseCustomProperty: false, - - readSequence: readSequence$1, - - consumeUntilBalanceEnd: () => 0, - consumeUntilLeftCurlyBracket(code) { - return code === LEFTCURLYBRACKET$1 ? 1 : 0; - }, - consumeUntilLeftCurlyBracketOrSemicolon(code) { - return code === LEFTCURLYBRACKET$1 || code === SEMICOLON ? 1 : 0; - }, - consumeUntilExclamationMarkOrSemicolon(code) { - return code === EXCLAMATIONMARK$3 || code === SEMICOLON ? 1 : 0; - }, - consumeUntilSemicolonIncluded(code) { - return code === SEMICOLON ? 2 : 0; - }, - - createList() { - return new List(); - }, - createSingleNodeList(node) { - return new List().appendData(node); - }, - getFirstListNode(list) { - return list && list.first; - }, - getLastListNode(list) { - return list && list.last; - }, - - parseWithFallback(consumer, fallback) { - const startToken = this.tokenIndex; - - try { - return consumer.call(this); - } catch (e) { - if (onParseErrorThrow) { - throw e; - } - - const fallbackNode = fallback.call(this, startToken); - - onParseErrorThrow = true; - onParseError(e, fallbackNode); - onParseErrorThrow = false; - - return fallbackNode; - } - }, - - lookupNonWSType(offset) { - let type; - - do { - type = this.lookupType(offset++); - if (type !== WhiteSpace$1) { - return type; - } - } while (type !== NULL); - - return NULL; - }, - - charCodeAt(offset) { - return offset >= 0 && offset < source.length ? source.charCodeAt(offset) : 0; - }, - substring(offsetStart, offsetEnd) { - return source.substring(offsetStart, offsetEnd); - }, - substrToCursor(start) { - return this.source.substring(start, this.tokenStart); - }, - - cmpChar(offset, charCode) { - return cmpChar(source, offset, charCode); - }, - cmpStr(offsetStart, offsetEnd, str) { - return cmpStr(source, offsetStart, offsetEnd, str); - }, - - consume(tokenType) { - const start = this.tokenStart; - - this.eat(tokenType); - - return this.substrToCursor(start); - }, - consumeFunctionName() { - const name = source.substring(this.tokenStart, this.tokenEnd - 1); - - this.eat(Function$1); - - return name; - }, - consumeNumber(type) { - const number = source.substring(this.tokenStart, consumeNumber$1(source, this.tokenStart)); - - this.eat(type); - - return number; - }, - - eat(tokenType) { - if (this.tokenType !== tokenType) { - const tokenName = tokenNames[tokenType].slice(0, -6).replace(/-/g, ' ').replace(/^./, m => m.toUpperCase()); - let message = `${/[[\](){}]/.test(tokenName) ? `"${tokenName}"` : tokenName} is expected`; - let offset = this.tokenStart; - - // tweak message and offset - switch (tokenType) { - case Ident: - // when identifier is expected but there is a function or url - if (this.tokenType === Function$1 || this.tokenType === Url$2) { - offset = this.tokenEnd - 1; - message = 'Identifier is expected but function found'; - } else { - message = 'Identifier is expected'; - } - break; - - case Hash$1: - if (this.isDelim(NUMBERSIGN$4)) { - this.next(); - offset++; - message = 'Name is expected'; - } - break; - - case Percentage$1: - if (this.tokenType === Number$2) { - offset = this.tokenEnd; - message = 'Percent sign is expected'; - } - break; - } - - this.error(message, offset); - } - - this.next(); - }, - eatIdent(name) { - if (this.tokenType !== Ident || this.lookupValue(0, name) === false) { - this.error(`Identifier "${name}" is expected`); - } - - this.next(); - }, - eatDelim(code) { - if (!this.isDelim(code)) { - this.error(`Delim "${String.fromCharCode(code)}" is expected`); - } - - this.next(); - }, - - getLocation(start, end) { - if (needPositions) { - return locationMap.getLocationRange( - start, - end, - filename - ); - } - - return null; - }, - getLocationFromList(list) { - if (needPositions) { - const head = this.getFirstListNode(list); - const tail = this.getLastListNode(list); - return locationMap.getLocationRange( - head !== null ? head.loc.start.offset - locationMap.startOffset : this.tokenStart, - tail !== null ? tail.loc.end.offset - locationMap.startOffset : this.tokenStart, - filename - ); - } - - return null; - }, - - error(message, offset) { - const location = typeof offset !== 'undefined' && offset < source.length - ? locationMap.getLocation(offset) - : this.eof - ? locationMap.getLocation(findWhiteSpaceStart(source, source.length - 1)) - : locationMap.getLocation(this.tokenStart); - - throw new SyntaxError$2( - message || 'Unexpected input', - source, - location.offset, - location.line, - location.column - ); - } - }); - - const parse = function(source_, options) { - source = source_; - options = options || {}; - - parser.setSource(source, tokenize$3); - locationMap.setSource( - source, - options.offset, - options.line, - options.column - ); - - filename = options.filename || ''; - needPositions = Boolean(options.positions); - onParseError = typeof options.onParseError === 'function' ? options.onParseError : NOOP; - onParseErrorThrow = false; - - parser.parseAtrulePrelude = 'parseAtrulePrelude' in options ? Boolean(options.parseAtrulePrelude) : true; - parser.parseRulePrelude = 'parseRulePrelude' in options ? Boolean(options.parseRulePrelude) : true; - parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true; - parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false; - - const { context = 'default', onComment } = options; - - if (context in parser.context === false) { - throw new Error('Unknown context `' + context + '`'); - } - - if (typeof onComment === 'function') { - parser.forEachToken((type, start, end) => { - if (type === Comment$1) { - const loc = parser.getLocation(start, end); - const value = cmpStr(source, end - 2, end, '*/') - ? source.slice(start + 2, end - 2) - : source.slice(start + 2, end); - - onComment(value, loc); - } - }); - } - - const ast = parser.context[context].call(parser, options); - - if (!parser.eof) { - parser.error(); - } - - return ast; - }; - - return Object.assign(parse, { - SyntaxError: SyntaxError$2, - config: parser.config - }); - } - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function getAugmentedNamespace(n) { - if (n.__esModule) return n; - var f = n.default; - if (typeof f == "function") { - var a = function a () { - if (this instanceof a) { - return Reflect.construct(f, arguments, this.constructor); - } - return f.apply(this, arguments); - }; - a.prototype = f.prototype; - } else a = {}; - Object.defineProperty(a, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; - } - - var base64Vlq$1 = {}; - - var base64$3 = {}; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - /* - * Copyright 2011 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - */ - - var intToCharMap$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); - - /** - * Encode an integer in the range of 0 to 63 to a single base 64 digit. - */ - base64$3.encode = function (number) { - if (0 <= number && number < intToCharMap$1.length) { - return intToCharMap$1[number]; - } - throw new TypeError("Must be between 0 and 63: " + number); - }; - - /** - * Decode a single base 64 character code digit to an integer. Returns -1 on - * failure. - */ - base64$3.decode = function (charCode) { - var bigA = 65; // 'A' - var bigZ = 90; // 'Z' - - var littleA = 97; // 'a' - var littleZ = 122; // 'z' - - var zero = 48; // '0' - var nine = 57; // '9' - - var plus = 43; // '+' - var slash = 47; // '/' - - var littleOffset = 26; - var numberOffset = 52; - - // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ - if (bigA <= charCode && charCode <= bigZ) { - return (charCode - bigA); - } - - // 26 - 51: abcdefghijklmnopqrstuvwxyz - if (littleA <= charCode && charCode <= littleZ) { - return (charCode - littleA + littleOffset); - } - - // 52 - 61: 0123456789 - if (zero <= charCode && charCode <= nine) { - return (charCode - zero + numberOffset); - } - - // 62: + - if (charCode == plus) { - return 62; - } - - // 63: / - if (charCode == slash) { - return 63; - } - - // Invalid base64 digit. - return -1; - }; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - /* - * Copyright 2011 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - * - * Based on the Base 64 VLQ implementation in Closure Compiler: - * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java - * - * Copyright 2011 The Closure Compiler Authors. All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - var base64$2 = base64$3; - - // A single base 64 digit can contain 6 bits of data. For the base 64 variable - // length quantities we use in the source map spec, the first bit is the sign, - // the next four bits are the actual value, and the 6th bit is the - // continuation bit. The continuation bit tells us whether there are more - // digits in this value following this digit. - // - // Continuation - // | Sign - // | | - // V V - // 101011 - - var VLQ_BASE_SHIFT$1 = 5; - - // binary: 100000 - var VLQ_BASE$1 = 1 << VLQ_BASE_SHIFT$1; - - // binary: 011111 - var VLQ_BASE_MASK$1 = VLQ_BASE$1 - 1; - - // binary: 100000 - var VLQ_CONTINUATION_BIT$1 = VLQ_BASE$1; - - /** - * Converts from a two-complement value to a value where the sign bit is - * placed in the least significant bit. For example, as decimals: - * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) - * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) - */ - function toVLQSigned$1(aValue) { - return aValue < 0 - ? ((-aValue) << 1) + 1 - : (aValue << 1) + 0; - } - - /** - * Converts to a two-complement value from a value where the sign bit is - * placed in the least significant bit. For example, as decimals: - * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 - * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 - */ - function fromVLQSigned(aValue) { - var isNegative = (aValue & 1) === 1; - var shifted = aValue >> 1; - return isNegative - ? -shifted - : shifted; - } - - /** - * Returns the base 64 VLQ encoded value. - */ - base64Vlq$1.encode = function base64VLQ_encode(aValue) { - var encoded = ""; - var digit; - - var vlq = toVLQSigned$1(aValue); - - do { - digit = vlq & VLQ_BASE_MASK$1; - vlq >>>= VLQ_BASE_SHIFT$1; - if (vlq > 0) { - // There are still more digits in this value, so we must make sure the - // continuation bit is marked. - digit |= VLQ_CONTINUATION_BIT$1; - } - encoded += base64$2.encode(digit); - } while (vlq > 0); - - return encoded; - }; - - /** - * Decodes the next base 64 VLQ value from the given string and returns the - * value and the rest of the string via the out parameter. - */ - base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { - var strLen = aStr.length; - var result = 0; - var shift = 0; - var continuation, digit; - - do { - if (aIndex >= strLen) { - throw new Error("Expected more digits in base 64 VLQ value."); - } - - digit = base64$2.decode(aStr.charCodeAt(aIndex++)); - if (digit === -1) { - throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); - } - - continuation = !!(digit & VLQ_CONTINUATION_BIT$1); - digit &= VLQ_BASE_MASK$1; - result = result + (digit << shift); - shift += VLQ_BASE_SHIFT$1; - } while (continuation); - - aOutParam.value = fromVLQSigned(result); - aOutParam.rest = aIndex; - }; - - var util$8 = {}; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - (function (exports) { - /* - * Copyright 2011 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - */ - - /** - * This is a helper function for getting values from parameter/options - * objects. - * - * @param args The object we are extracting values from - * @param name The name of the property we are getting. - * @param defaultValue An optional value to return if the property is missing - * from the object. If this is not specified and the property is missing, an - * error will be thrown. - */ - function getArg(aArgs, aName, aDefaultValue) { - if (aName in aArgs) { - return aArgs[aName]; - } else if (arguments.length === 3) { - return aDefaultValue; - } else { - throw new Error('"' + aName + '" is a required argument.'); - } - } - exports.getArg = getArg; - - var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; - var dataUrlRegexp = /^data:.+\,.+$/; - - function urlParse(aUrl) { - var match = aUrl.match(urlRegexp); - if (!match) { - return null; - } - return { - scheme: match[1], - auth: match[2], - host: match[3], - port: match[4], - path: match[5] - }; - } - exports.urlParse = urlParse; - - function urlGenerate(aParsedUrl) { - var url = ''; - if (aParsedUrl.scheme) { - url += aParsedUrl.scheme + ':'; - } - url += '//'; - if (aParsedUrl.auth) { - url += aParsedUrl.auth + '@'; - } - if (aParsedUrl.host) { - url += aParsedUrl.host; - } - if (aParsedUrl.port) { - url += ":" + aParsedUrl.port; - } - if (aParsedUrl.path) { - url += aParsedUrl.path; - } - return url; - } - exports.urlGenerate = urlGenerate; - - var MAX_CACHED_INPUTS = 32; - - /** - * Takes some function `f(input) -> result` and returns a memoized version of - * `f`. - * - * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The - * memoization is a dumb-simple, linear least-recently-used cache. - */ - function lruMemoize(f) { - var cache = []; - - return function(input) { - for (var i = 0; i < cache.length; i++) { - if (cache[i].input === input) { - var temp = cache[0]; - cache[0] = cache[i]; - cache[i] = temp; - return cache[0].result; - } - } - - var result = f(input); - - cache.unshift({ - input, - result, - }); - - if (cache.length > MAX_CACHED_INPUTS) { - cache.pop(); - } - - return result; - }; - } - - /** - * Normalizes a path, or the path portion of a URL: - * - * - Replaces consecutive slashes with one slash. - * - Removes unnecessary '.' parts. - * - Removes unnecessary '/..' parts. - * - * Based on code in the Node.js 'path' core module. - * - * @param aPath The path or url to normalize. - */ - var normalize = lruMemoize(function normalize(aPath) { - var path = aPath; - var url = urlParse(aPath); - if (url) { - if (!url.path) { - return aPath; - } - path = url.path; - } - var isAbsolute = exports.isAbsolute(path); - // Split the path into parts between `/` characters. This is much faster than - // using `.split(/\/+/g)`. - var parts = []; - var start = 0; - var i = 0; - while (true) { - start = i; - i = path.indexOf("/", start); - if (i === -1) { - parts.push(path.slice(start)); - break; - } else { - parts.push(path.slice(start, i)); - while (i < path.length && path[i] === "/") { - i++; - } - } - } - - for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { - part = parts[i]; - if (part === '.') { - parts.splice(i, 1); - } else if (part === '..') { - up++; - } else if (up > 0) { - if (part === '') { - // The first part is blank if the path is absolute. Trying to go - // above the root is a no-op. Therefore we can remove all '..' parts - // directly after the root. - parts.splice(i + 1, up); - up = 0; - } else { - parts.splice(i, 2); - up--; - } - } - } - path = parts.join('/'); - - if (path === '') { - path = isAbsolute ? '/' : '.'; - } - - if (url) { - url.path = path; - return urlGenerate(url); - } - return path; - }); - exports.normalize = normalize; - - /** - * Joins two paths/URLs. - * - * @param aRoot The root path or URL. - * @param aPath The path or URL to be joined with the root. - * - * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a - * scheme-relative URL: Then the scheme of aRoot, if any, is prepended - * first. - * - Otherwise aPath is a path. If aRoot is a URL, then its path portion - * is updated with the result and aRoot is returned. Otherwise the result - * is returned. - * - If aPath is absolute, the result is aPath. - * - Otherwise the two paths are joined with a slash. - * - Joining for example 'http://' and 'www.example.com' is also supported. - */ - function join(aRoot, aPath) { - if (aRoot === "") { - aRoot = "."; - } - if (aPath === "") { - aPath = "."; - } - var aPathUrl = urlParse(aPath); - var aRootUrl = urlParse(aRoot); - if (aRootUrl) { - aRoot = aRootUrl.path || '/'; - } - - // `join(foo, '//www.example.org')` - if (aPathUrl && !aPathUrl.scheme) { - if (aRootUrl) { - aPathUrl.scheme = aRootUrl.scheme; - } - return urlGenerate(aPathUrl); - } - - if (aPathUrl || aPath.match(dataUrlRegexp)) { - return aPath; - } - - // `join('http://', 'www.example.com')` - if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { - aRootUrl.host = aPath; - return urlGenerate(aRootUrl); - } - - var joined = aPath.charAt(0) === '/' - ? aPath - : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); - - if (aRootUrl) { - aRootUrl.path = joined; - return urlGenerate(aRootUrl); - } - return joined; - } - exports.join = join; - - exports.isAbsolute = function (aPath) { - return aPath.charAt(0) === '/' || urlRegexp.test(aPath); - }; - - /** - * Make a path relative to a URL or another path. - * - * @param aRoot The root path or URL. - * @param aPath The path or URL to be made relative to aRoot. - */ - function relative(aRoot, aPath) { - if (aRoot === "") { - aRoot = "."; - } - - aRoot = aRoot.replace(/\/$/, ''); - - // It is possible for the path to be above the root. In this case, simply - // checking whether the root is a prefix of the path won't work. Instead, we - // need to remove components from the root one by one, until either we find - // a prefix that fits, or we run out of components to remove. - var level = 0; - while (aPath.indexOf(aRoot + '/') !== 0) { - var index = aRoot.lastIndexOf("/"); - if (index < 0) { - return aPath; - } - - // If the only part of the root that is left is the scheme (i.e. http://, - // file:///, etc.), one or more slashes (/), or simply nothing at all, we - // have exhausted all components, so the path is not relative to the root. - aRoot = aRoot.slice(0, index); - if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { - return aPath; - } - - ++level; - } - - // Make sure we add a "../" for each component we removed from the root. - return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); - } - exports.relative = relative; - - var supportsNullProto = (function () { - var obj = Object.create(null); - return !('__proto__' in obj); - }()); - - function identity (s) { - return s; - } - - /** - * Because behavior goes wacky when you set `__proto__` on objects, we - * have to prefix all the strings in our set with an arbitrary character. - * - * See https://github.com/mozilla/source-map/pull/31 and - * https://github.com/mozilla/source-map/issues/30 - * - * @param String aStr - */ - function toSetString(aStr) { - if (isProtoString(aStr)) { - return '$' + aStr; - } - - return aStr; - } - exports.toSetString = supportsNullProto ? identity : toSetString; - - function fromSetString(aStr) { - if (isProtoString(aStr)) { - return aStr.slice(1); - } - - return aStr; - } - exports.fromSetString = supportsNullProto ? identity : fromSetString; - - function isProtoString(s) { - if (!s) { - return false; - } - - var length = s.length; - - if (length < 9 /* "__proto__".length */) { - return false; - } - - if (s.charCodeAt(length - 1) !== 95 /* '_' */ || - s.charCodeAt(length - 2) !== 95 /* '_' */ || - s.charCodeAt(length - 3) !== 111 /* 'o' */ || - s.charCodeAt(length - 4) !== 116 /* 't' */ || - s.charCodeAt(length - 5) !== 111 /* 'o' */ || - s.charCodeAt(length - 6) !== 114 /* 'r' */ || - s.charCodeAt(length - 7) !== 112 /* 'p' */ || - s.charCodeAt(length - 8) !== 95 /* '_' */ || - s.charCodeAt(length - 9) !== 95 /* '_' */) { - return false; - } - - for (var i = length - 10; i >= 0; i--) { - if (s.charCodeAt(i) !== 36 /* '$' */) { - return false; - } - } - - return true; - } - - /** - * Comparator between two mappings where the original positions are compared. - * - * Optionally pass in `true` as `onlyCompareGenerated` to consider two - * mappings with the same original source/line/column, but different generated - * line and column the same. Useful when searching for a mapping with a - * stubbed out mapping. - */ - function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { - var cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0 || onlyCompareOriginal) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); - } - exports.compareByOriginalPositions = compareByOriginalPositions; - - function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) { - var cmp; - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0 || onlyCompareOriginal) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); - } - exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource; - - /** - * Comparator between two mappings with deflated source and name indices where - * the generated positions are compared. - * - * Optionally pass in `true` as `onlyCompareGenerated` to consider two - * mappings with the same generated line and column, but different - * source/name/original line and column the same. Useful when searching for a - * mapping with a stubbed out mapping. - */ - function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { - var cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0 || onlyCompareGenerated) { - return cmp; - } - - cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); - } - exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; - - function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) { - var cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0 || onlyCompareGenerated) { - return cmp; - } - - cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); - } - exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine; - - function strcmp(aStr1, aStr2) { - if (aStr1 === aStr2) { - return 0; - } - - if (aStr1 === null) { - return 1; // aStr2 !== null - } - - if (aStr2 === null) { - return -1; // aStr1 !== null - } - - if (aStr1 > aStr2) { - return 1; - } - - return -1; - } - - /** - * Comparator between two mappings with inflated source and name strings where - * the generated positions are compared. - */ - function compareByGeneratedPositionsInflated(mappingA, mappingB) { - var cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0) { - return cmp; - } - - cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); - } - exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; - - /** - * Strip any JSON XSSI avoidance prefix from the string (as documented - * in the source maps specification), and then parse the string as - * JSON. - */ - function parseSourceMapInput(str) { - return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, '')); - } - exports.parseSourceMapInput = parseSourceMapInput; - - /** - * Compute the URL of a source given the the source root, the source's - * URL, and the source map's URL. - */ - function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { - sourceURL = sourceURL || ''; - - if (sourceRoot) { - // This follows what Chrome does. - if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { - sourceRoot += '/'; - } - // The spec says: - // Line 4: An optional source root, useful for relocating source - // files on a server or removing repeated values in the - // “sources” entry. This value is prepended to the individual - // entries in the “source” field. - sourceURL = sourceRoot + sourceURL; - } - - // Historically, SourceMapConsumer did not take the sourceMapURL as - // a parameter. This mode is still somewhat supported, which is why - // this code block is conditional. However, it's preferable to pass - // the source map URL to SourceMapConsumer, so that this function - // can implement the source URL resolution algorithm as outlined in - // the spec. This block is basically the equivalent of: - // new URL(sourceURL, sourceMapURL).toString() - // ... except it avoids using URL, which wasn't available in the - // older releases of node still supported by this library. - // - // The spec says: - // If the sources are not absolute URLs after prepending of the - // “sourceRoot”, the sources are resolved relative to the - // SourceMap (like resolving script src in a html document). - if (sourceMapURL) { - var parsed = urlParse(sourceMapURL); - if (!parsed) { - throw new Error("sourceMapURL could not be parsed"); - } - if (parsed.path) { - // Strip the last path component, but keep the "/". - var index = parsed.path.lastIndexOf('/'); - if (index >= 0) { - parsed.path = parsed.path.substring(0, index + 1); - } - } - sourceURL = join(urlGenerate(parsed), sourceURL); - } - - return normalize(sourceURL); - } - exports.computeSourceURL = computeSourceURL; - } (util$8)); - - var arraySet$1 = {}; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - /* - * Copyright 2011 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - */ - - var util$7 = util$8; - var has = Object.prototype.hasOwnProperty; - var hasNativeMap = typeof Map !== "undefined"; - - /** - * A data structure which is a combination of an array and a set. Adding a new - * member is O(1), testing for membership is O(1), and finding the index of an - * element is O(1). Removing elements from the set is not supported. Only - * strings are supported for membership. - */ - function ArraySet$4() { - this._array = []; - this._set = hasNativeMap ? new Map() : Object.create(null); - } - - /** - * Static method for creating ArraySet instances from an existing array. - */ - ArraySet$4.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { - var set = new ArraySet$4(); - for (var i = 0, len = aArray.length; i < len; i++) { - set.add(aArray[i], aAllowDuplicates); - } - return set; - }; - - /** - * Return how many unique items are in this ArraySet. If duplicates have been - * added, than those do not count towards the size. - * - * @returns Number - */ - ArraySet$4.prototype.size = function ArraySet_size() { - return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; - }; - - /** - * Add the given string to this set. - * - * @param String aStr - */ - ArraySet$4.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { - var sStr = hasNativeMap ? aStr : util$7.toSetString(aStr); - var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); - var idx = this._array.length; - if (!isDuplicate || aAllowDuplicates) { - this._array.push(aStr); - } - if (!isDuplicate) { - if (hasNativeMap) { - this._set.set(aStr, idx); - } else { - this._set[sStr] = idx; - } - } - }; - - /** - * Is the given string a member of this set? - * - * @param String aStr - */ - ArraySet$4.prototype.has = function ArraySet_has(aStr) { - if (hasNativeMap) { - return this._set.has(aStr); - } else { - var sStr = util$7.toSetString(aStr); - return has.call(this._set, sStr); - } - }; - - /** - * What is the index of the given string in the array? - * - * @param String aStr - */ - ArraySet$4.prototype.indexOf = function ArraySet_indexOf(aStr) { - if (hasNativeMap) { - var idx = this._set.get(aStr); - if (idx >= 0) { - return idx; - } - } else { - var sStr = util$7.toSetString(aStr); - if (has.call(this._set, sStr)) { - return this._set[sStr]; - } - } - - throw new Error('"' + aStr + '" is not in the set.'); - }; - - /** - * What is the element at the given index? - * - * @param Number aIdx - */ - ArraySet$4.prototype.at = function ArraySet_at(aIdx) { - if (aIdx >= 0 && aIdx < this._array.length) { - return this._array[aIdx]; - } - throw new Error('No element indexed by ' + aIdx); - }; - - /** - * Returns the array representation of this set (which has the proper indices - * indicated by indexOf). Note that this is a copy of the internal array used - * for storing the members so that no one can mess with internal state. - */ - ArraySet$4.prototype.toArray = function ArraySet_toArray() { - return this._array.slice(); - }; - - arraySet$1.ArraySet = ArraySet$4; - - var mappingList$1 = {}; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - /* - * Copyright 2014 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - */ - - var util$6 = util$8; - - /** - * Determine whether mappingB is after mappingA with respect to generated - * position. - */ - function generatedPositionAfter$1(mappingA, mappingB) { - // Optimized for most common case - var lineA = mappingA.generatedLine; - var lineB = mappingB.generatedLine; - var columnA = mappingA.generatedColumn; - var columnB = mappingB.generatedColumn; - return lineB > lineA || lineB == lineA && columnB >= columnA || - util$6.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; - } - - /** - * A data structure to provide a sorted view of accumulated mappings in a - * performance conscious manner. It trades a neglibable overhead in general - * case for a large speedup in case of mappings being added in order. - */ - function MappingList$3() { - this._array = []; - this._sorted = true; - // Serves as infimum - this._last = {generatedLine: -1, generatedColumn: 0}; - } - - /** - * Iterate through internal items. This method takes the same arguments that - * `Array.prototype.forEach` takes. - * - * NOTE: The order of the mappings is NOT guaranteed. - */ - MappingList$3.prototype.unsortedForEach = - function MappingList_forEach(aCallback, aThisArg) { - this._array.forEach(aCallback, aThisArg); - }; - - /** - * Add the given source mapping. - * - * @param Object aMapping - */ - MappingList$3.prototype.add = function MappingList_add(aMapping) { - if (generatedPositionAfter$1(this._last, aMapping)) { - this._last = aMapping; - this._array.push(aMapping); - } else { - this._sorted = false; - this._array.push(aMapping); - } - }; - - /** - * Returns the flat, sorted array of mappings. The mappings are sorted by - * generated position. - * - * WARNING: This method returns internal data without copying, for - * performance. The return value must NOT be mutated, and should be treated as - * an immutable borrow. If you want to take ownership, you must make your own - * copy. - */ - MappingList$3.prototype.toArray = function MappingList_toArray() { - if (!this._sorted) { - this._array.sort(util$6.compareByGeneratedPositionsInflated); - this._sorted = true; - } - return this._array; - }; - - mappingList$1.MappingList = MappingList$3; - - /* -*- Mode: js; js-indent-level: 2; -*- */ - - /* - * Copyright 2011 Mozilla Foundation and contributors - * Licensed under the New BSD license. See LICENSE or: - * http://opensource.org/licenses/BSD-3-Clause - */ - - var base64VLQ$1 = base64Vlq$1; - var util$5 = util$8; - var ArraySet$3 = arraySet$1.ArraySet; - var MappingList$2 = mappingList$1.MappingList; - - /** - * An instance of the SourceMapGenerator represents a source map which is - * being built incrementally. You may pass an object with the following - * properties: - * - * - file: The filename of the generated source. - * - sourceRoot: A root for all relative URLs in this source map. - */ - function SourceMapGenerator$3(aArgs) { - if (!aArgs) { - aArgs = {}; - } - this._file = util$5.getArg(aArgs, 'file', null); - this._sourceRoot = util$5.getArg(aArgs, 'sourceRoot', null); - this._skipValidation = util$5.getArg(aArgs, 'skipValidation', false); - this._ignoreInvalidMapping = util$5.getArg(aArgs, 'ignoreInvalidMapping', false); - this._sources = new ArraySet$3(); - this._names = new ArraySet$3(); - this._mappings = new MappingList$2(); - this._sourcesContents = null; - } - - SourceMapGenerator$3.prototype._version = 3; - - /** - * Creates a new SourceMapGenerator based on a SourceMapConsumer - * - * @param aSourceMapConsumer The SourceMap. - */ - SourceMapGenerator$3.fromSourceMap = - function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) { - var sourceRoot = aSourceMapConsumer.sourceRoot; - var generator = new SourceMapGenerator$3(Object.assign(generatorOps || {}, { - file: aSourceMapConsumer.file, - sourceRoot: sourceRoot - })); - aSourceMapConsumer.eachMapping(function (mapping) { - var newMapping = { - generated: { - line: mapping.generatedLine, - column: mapping.generatedColumn - } - }; - - if (mapping.source != null) { - newMapping.source = mapping.source; - if (sourceRoot != null) { - newMapping.source = util$5.relative(sourceRoot, newMapping.source); - } - - newMapping.original = { - line: mapping.originalLine, - column: mapping.originalColumn - }; - - if (mapping.name != null) { - newMapping.name = mapping.name; - } - } - - generator.addMapping(newMapping); - }); - aSourceMapConsumer.sources.forEach(function (sourceFile) { - var sourceRelative = sourceFile; - if (sourceRoot !== null) { - sourceRelative = util$5.relative(sourceRoot, sourceFile); - } - - if (!generator._sources.has(sourceRelative)) { - generator._sources.add(sourceRelative); - } - - var content = aSourceMapConsumer.sourceContentFor(sourceFile); - if (content != null) { - generator.setSourceContent(sourceFile, content); - } - }); - return generator; - }; - - /** - * Add a single mapping from original source line and column to the generated - * source's line and column for this source map being created. The mapping - * object should have the following properties: - * - * - generated: An object with the generated line and column positions. - * - original: An object with the original line and column positions. - * - source: The original source file (relative to the sourceRoot). - * - name: An optional original token name for this mapping. - */ - SourceMapGenerator$3.prototype.addMapping = - function SourceMapGenerator_addMapping(aArgs) { - var generated = util$5.getArg(aArgs, 'generated'); - var original = util$5.getArg(aArgs, 'original', null); - var source = util$5.getArg(aArgs, 'source', null); - var name = util$5.getArg(aArgs, 'name', null); - - if (!this._skipValidation) { - if (this._validateMapping(generated, original, source, name) === false) { - return; - } - } - - if (source != null) { - source = String(source); - if (!this._sources.has(source)) { - this._sources.add(source); - } - } - - if (name != null) { - name = String(name); - if (!this._names.has(name)) { - this._names.add(name); - } - } - - this._mappings.add({ - generatedLine: generated.line, - generatedColumn: generated.column, - originalLine: original != null && original.line, - originalColumn: original != null && original.column, - source: source, - name: name - }); - }; - - /** - * Set the source content for a source file. - */ - SourceMapGenerator$3.prototype.setSourceContent = - function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { - var source = aSourceFile; - if (this._sourceRoot != null) { - source = util$5.relative(this._sourceRoot, source); - } - - if (aSourceContent != null) { - // Add the source content to the _sourcesContents map. - // Create a new _sourcesContents map if the property is null. - if (!this._sourcesContents) { - this._sourcesContents = Object.create(null); - } - this._sourcesContents[util$5.toSetString(source)] = aSourceContent; - } else if (this._sourcesContents) { - // Remove the source file from the _sourcesContents map. - // If the _sourcesContents map is empty, set the property to null. - delete this._sourcesContents[util$5.toSetString(source)]; - if (Object.keys(this._sourcesContents).length === 0) { - this._sourcesContents = null; - } - } - }; - - /** - * Applies the mappings of a sub-source-map for a specific source file to the - * source map being generated. Each mapping to the supplied source file is - * rewritten using the supplied source map. Note: The resolution for the - * resulting mappings is the minimium of this map and the supplied map. - * - * @param aSourceMapConsumer The source map to be applied. - * @param aSourceFile Optional. The filename of the source file. - * If omitted, SourceMapConsumer's file property will be used. - * @param aSourceMapPath Optional. The dirname of the path to the source map - * to be applied. If relative, it is relative to the SourceMapConsumer. - * This parameter is needed when the two source maps aren't in the same - * directory, and the source map to be applied contains relative source - * paths. If so, those relative source paths need to be rewritten - * relative to the SourceMapGenerator. - */ - SourceMapGenerator$3.prototype.applySourceMap = - function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { - var sourceFile = aSourceFile; - // If aSourceFile is omitted, we will use the file property of the SourceMap - if (aSourceFile == null) { - if (aSourceMapConsumer.file == null) { - throw new Error( - 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + - 'or the source map\'s "file" property. Both were omitted.' - ); - } - sourceFile = aSourceMapConsumer.file; - } - var sourceRoot = this._sourceRoot; - // Make "sourceFile" relative if an absolute Url is passed. - if (sourceRoot != null) { - sourceFile = util$5.relative(sourceRoot, sourceFile); - } - // Applying the SourceMap can add and remove items from the sources and - // the names array. - var newSources = new ArraySet$3(); - var newNames = new ArraySet$3(); - - // Find mappings for the "sourceFile" - this._mappings.unsortedForEach(function (mapping) { - if (mapping.source === sourceFile && mapping.originalLine != null) { - // Check if it can be mapped by the source map, then update the mapping. - var original = aSourceMapConsumer.originalPositionFor({ - line: mapping.originalLine, - column: mapping.originalColumn - }); - if (original.source != null) { - // Copy mapping - mapping.source = original.source; - if (aSourceMapPath != null) { - mapping.source = util$5.join(aSourceMapPath, mapping.source); - } - if (sourceRoot != null) { - mapping.source = util$5.relative(sourceRoot, mapping.source); - } - mapping.originalLine = original.line; - mapping.originalColumn = original.column; - if (original.name != null) { - mapping.name = original.name; - } - } - } - - var source = mapping.source; - if (source != null && !newSources.has(source)) { - newSources.add(source); - } - - var name = mapping.name; - if (name != null && !newNames.has(name)) { - newNames.add(name); - } - - }, this); - this._sources = newSources; - this._names = newNames; - - // Copy sourcesContents of applied map. - aSourceMapConsumer.sources.forEach(function (sourceFile) { - var content = aSourceMapConsumer.sourceContentFor(sourceFile); - if (content != null) { - if (aSourceMapPath != null) { - sourceFile = util$5.join(aSourceMapPath, sourceFile); - } - if (sourceRoot != null) { - sourceFile = util$5.relative(sourceRoot, sourceFile); - } - this.setSourceContent(sourceFile, content); - } - }, this); - }; - - /** - * A mapping can have one of the three levels of data: - * - * 1. Just the generated position. - * 2. The Generated position, original position, and original source. - * 3. Generated and original position, original source, as well as a name - * token. - * - * To maintain consistency, we validate that any new mapping being added falls - * in to one of these categories. - */ - SourceMapGenerator$3.prototype._validateMapping = - function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, - aName) { - // When aOriginal is truthy but has empty values for .line and .column, - // it is most likely a programmer error. In this case we throw a very - // specific error message to try to guide them the right way. - // For example: https://github.com/Polymer/polymer-bundler/pull/519 - if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { - var message = 'original.line and original.column are not numbers -- you probably meant to omit ' + - 'the original mapping entirely and only map the generated position. If so, pass ' + - 'null for the original mapping instead of an object with empty or null values.'; - - if (this._ignoreInvalidMapping) { - if (typeof console !== 'undefined' && console.warn) { - console.warn(message); - } - return false; - } else { - throw new Error(message); - } - } - - if (aGenerated && 'line' in aGenerated && 'column' in aGenerated - && aGenerated.line > 0 && aGenerated.column >= 0 - && !aOriginal && !aSource && !aName) { - // Case 1. - return; - } - else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated - && aOriginal && 'line' in aOriginal && 'column' in aOriginal - && aGenerated.line > 0 && aGenerated.column >= 0 - && aOriginal.line > 0 && aOriginal.column >= 0 - && aSource) { - // Cases 2 and 3. - return; - } - else { - var message = 'Invalid mapping: ' + JSON.stringify({ - generated: aGenerated, - source: aSource, - original: aOriginal, - name: aName - }); - - if (this._ignoreInvalidMapping) { - if (typeof console !== 'undefined' && console.warn) { - console.warn(message); - } - return false; - } else { - throw new Error(message) - } - } - }; - - /** - * Serialize the accumulated mappings in to the stream of base 64 VLQs - * specified by the source map format. - */ - SourceMapGenerator$3.prototype._serializeMappings = - function SourceMapGenerator_serializeMappings() { - var previousGeneratedColumn = 0; - var previousGeneratedLine = 1; - var previousOriginalColumn = 0; - var previousOriginalLine = 0; - var previousName = 0; - var previousSource = 0; - var result = ''; - var next; - var mapping; - var nameIdx; - var sourceIdx; - - var mappings = this._mappings.toArray(); - for (var i = 0, len = mappings.length; i < len; i++) { - mapping = mappings[i]; - next = ''; - - if (mapping.generatedLine !== previousGeneratedLine) { - previousGeneratedColumn = 0; - while (mapping.generatedLine !== previousGeneratedLine) { - next += ';'; - previousGeneratedLine++; - } - } - else { - if (i > 0) { - if (!util$5.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { - continue; - } - next += ','; - } - } - - next += base64VLQ$1.encode(mapping.generatedColumn - - previousGeneratedColumn); - previousGeneratedColumn = mapping.generatedColumn; - - if (mapping.source != null) { - sourceIdx = this._sources.indexOf(mapping.source); - next += base64VLQ$1.encode(sourceIdx - previousSource); - previousSource = sourceIdx; - - // lines are stored 0-based in SourceMap spec version 3 - next += base64VLQ$1.encode(mapping.originalLine - 1 - - previousOriginalLine); - previousOriginalLine = mapping.originalLine - 1; - - next += base64VLQ$1.encode(mapping.originalColumn - - previousOriginalColumn); - previousOriginalColumn = mapping.originalColumn; - - if (mapping.name != null) { - nameIdx = this._names.indexOf(mapping.name); - next += base64VLQ$1.encode(nameIdx - previousName); - previousName = nameIdx; - } - } - - result += next; - } - - return result; - }; - - SourceMapGenerator$3.prototype._generateSourcesContent = - function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { - return aSources.map(function (source) { - if (!this._sourcesContents) { - return null; - } - if (aSourceRoot != null) { - source = util$5.relative(aSourceRoot, source); - } - var key = util$5.toSetString(source); - return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) - ? this._sourcesContents[key] - : null; - }, this); - }; - - /** - * Externalize the source map. - */ - SourceMapGenerator$3.prototype.toJSON = - function SourceMapGenerator_toJSON() { - var map = { - version: this._version, - sources: this._sources.toArray(), - names: this._names.toArray(), - mappings: this._serializeMappings() - }; - if (this._file != null) { - map.file = this._file; - } - if (this._sourceRoot != null) { - map.sourceRoot = this._sourceRoot; - } - if (this._sourcesContents) { - map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); - } - - return map; - }; - - /** - * Render the source map being generated to a string. - */ - SourceMapGenerator$3.prototype.toString = - function SourceMapGenerator_toString() { - return JSON.stringify(this.toJSON()); - }; - - var SourceMapGenerator_1 = SourceMapGenerator$3; - - const trackNodes = new Set(['Atrule', 'Selector', 'Declaration']); - - function generateSourceMap(handlers) { - const map = new SourceMapGenerator_1(); - const generated = { - line: 1, - column: 0 - }; - const original = { - line: 0, // should be zero to add first mapping - column: 0 - }; - const activatedGenerated = { - line: 1, - column: 0 - }; - const activatedMapping = { - generated: activatedGenerated - }; - let line = 1; - let column = 0; - let sourceMappingActive = false; - - const origHandlersNode = handlers.node; - handlers.node = function(node) { - if (node.loc && node.loc.start && trackNodes.has(node.type)) { - const nodeLine = node.loc.start.line; - const nodeColumn = node.loc.start.column - 1; - - if (original.line !== nodeLine || - original.column !== nodeColumn) { - original.line = nodeLine; - original.column = nodeColumn; - - generated.line = line; - generated.column = column; - - if (sourceMappingActive) { - sourceMappingActive = false; - if (generated.line !== activatedGenerated.line || - generated.column !== activatedGenerated.column) { - map.addMapping(activatedMapping); - } - } - - sourceMappingActive = true; - map.addMapping({ - source: node.loc.source, - original, - generated - }); - } - } - - origHandlersNode.call(this, node); - - if (sourceMappingActive && trackNodes.has(node.type)) { - activatedGenerated.line = line; - activatedGenerated.column = column; - } - }; - - const origHandlersEmit = handlers.emit; - handlers.emit = function(value, type, auto) { - for (let i = 0; i < value.length; i++) { - if (value.charCodeAt(i) === 10) { // \n - line++; - column = 0; - } else { - column++; - } - } - - origHandlersEmit(value, type, auto); - }; - - const origHandlersResult = handlers.result; - handlers.result = function() { - if (sourceMappingActive) { - map.addMapping(activatedMapping); - } - - return { - css: origHandlersResult(), - map - }; - }; - - return handlers; - } - - const PLUSSIGN$9 = 0x002B; // U+002B PLUS SIGN (+) - const HYPHENMINUS$6 = 0x002D; // U+002D HYPHEN-MINUS (-) - - const code = (type, value) => { - if (type === Delim) { - type = value; - } - - if (typeof type === 'string') { - const charCode = type.charCodeAt(0); - return charCode > 0x7F ? 0x8000 : charCode << 8; - } - - return type; - }; - - // https://www.w3.org/TR/css-syntax-3/#serialization - // The only requirement for serialization is that it must "round-trip" with parsing, - // that is, parsing the stylesheet must produce the same data structures as parsing, - // serializing, and parsing again, except for consecutive s, - // which may be collapsed into a single token. - - const specPairs = [ - [Ident, Ident], - [Ident, Function$1], - [Ident, Url$2], - [Ident, BadUrl], - [Ident, '-'], - [Ident, Number$2], - [Ident, Percentage$1], - [Ident, Dimension$1], - [Ident, CDC$1], - [Ident, LeftParenthesis], - - [AtKeyword, Ident], - [AtKeyword, Function$1], - [AtKeyword, Url$2], - [AtKeyword, BadUrl], - [AtKeyword, '-'], - [AtKeyword, Number$2], - [AtKeyword, Percentage$1], - [AtKeyword, Dimension$1], - [AtKeyword, CDC$1], - - [Hash$1, Ident], - [Hash$1, Function$1], - [Hash$1, Url$2], - [Hash$1, BadUrl], - [Hash$1, '-'], - [Hash$1, Number$2], - [Hash$1, Percentage$1], - [Hash$1, Dimension$1], - [Hash$1, CDC$1], - - [Dimension$1, Ident], - [Dimension$1, Function$1], - [Dimension$1, Url$2], - [Dimension$1, BadUrl], - [Dimension$1, '-'], - [Dimension$1, Number$2], - [Dimension$1, Percentage$1], - [Dimension$1, Dimension$1], - [Dimension$1, CDC$1], - - ['#', Ident], - ['#', Function$1], - ['#', Url$2], - ['#', BadUrl], - ['#', '-'], - ['#', Number$2], - ['#', Percentage$1], - ['#', Dimension$1], - ['#', CDC$1], // https://github.com/w3c/csswg-drafts/pull/6874 - - ['-', Ident], - ['-', Function$1], - ['-', Url$2], - ['-', BadUrl], - ['-', '-'], - ['-', Number$2], - ['-', Percentage$1], - ['-', Dimension$1], - ['-', CDC$1], // https://github.com/w3c/csswg-drafts/pull/6874 - - [Number$2, Ident], - [Number$2, Function$1], - [Number$2, Url$2], - [Number$2, BadUrl], - [Number$2, Number$2], - [Number$2, Percentage$1], - [Number$2, Dimension$1], - [Number$2, '%'], - [Number$2, CDC$1], // https://github.com/w3c/csswg-drafts/pull/6874 - - ['@', Ident], - ['@', Function$1], - ['@', Url$2], - ['@', BadUrl], - ['@', '-'], - ['@', CDC$1], // https://github.com/w3c/csswg-drafts/pull/6874 - - ['.', Number$2], - ['.', Percentage$1], - ['.', Dimension$1], - - ['+', Number$2], - ['+', Percentage$1], - ['+', Dimension$1], - - ['/', '*'] - ]; - // validate with scripts/generate-safe - const safePairs = specPairs.concat([ - [Ident, Hash$1], - - [Dimension$1, Hash$1], - - [Hash$1, Hash$1], - - [AtKeyword, LeftParenthesis], - [AtKeyword, String$2], - [AtKeyword, Colon], - - [Percentage$1, Percentage$1], - [Percentage$1, Dimension$1], - [Percentage$1, Function$1], - [Percentage$1, '-'], - - [RightParenthesis, Ident], - [RightParenthesis, Function$1], - [RightParenthesis, Percentage$1], - [RightParenthesis, Dimension$1], - [RightParenthesis, Hash$1], - [RightParenthesis, '-'] - ]); - - function createMap(pairs) { - const isWhiteSpaceRequired = new Set( - pairs.map(([prev, next]) => (code(prev) << 16 | code(next))) - ); - - return function(prevCode, type, value) { - const nextCode = code(type, value); - const nextCharCode = value.charCodeAt(0); - const emitWs = - (nextCharCode === HYPHENMINUS$6 && - type !== Ident && - type !== Function$1 && - type !== CDC$1) || - (nextCharCode === PLUSSIGN$9) - ? isWhiteSpaceRequired.has(prevCode << 16 | nextCharCode << 8) - : isWhiteSpaceRequired.has(prevCode << 16 | nextCode); - - if (emitWs) { - this.emit(' ', WhiteSpace$1, true); - } - - return nextCode; - }; - } - - const spec = createMap(specPairs); - const safe = createMap(safePairs); - - var tokenBefore = /*#__PURE__*/Object.freeze({ - __proto__: null, - spec: spec, - safe: safe - }); - - const REVERSESOLIDUS = 0x005c; // U+005C REVERSE SOLIDUS (\) - - function processChildren(node, delimeter) { - if (typeof delimeter === 'function') { - let prev = null; - - node.children.forEach(node => { - if (prev !== null) { - delimeter.call(this, prev); - } - - this.node(node); - prev = node; - }); - - return; - } - - node.children.forEach(this.node, this); - } - - function processChunk(chunk) { - tokenize$3(chunk, (type, start, end) => { - this.token(type, chunk.slice(start, end)); - }); - } - - function createGenerator(config) { - const types = new Map(); - - for (let name in config.node) { - const item = config.node[name]; - const fn = item.generate || item; - - if (typeof fn === 'function') { - types.set(name, item.generate || item); - } - } - - return function(node, options) { - let buffer = ''; - let prevCode = 0; - let handlers = { - node(node) { - if (types.has(node.type)) { - types.get(node.type).call(publicApi, node); - } else { - throw new Error('Unknown node type: ' + node.type); - } - }, - tokenBefore: safe, - token(type, value) { - prevCode = this.tokenBefore(prevCode, type, value); - - this.emit(value, type, false); - - if (type === Delim && value.charCodeAt(0) === REVERSESOLIDUS) { - this.emit('\n', WhiteSpace$1, true); - } - }, - emit(value) { - buffer += value; - }, - result() { - return buffer; - } - }; - - if (options) { - if (typeof options.decorator === 'function') { - handlers = options.decorator(handlers); - } - - if (options.sourceMap) { - handlers = generateSourceMap(handlers); - } - - if (options.mode in tokenBefore) { - handlers.tokenBefore = tokenBefore[options.mode]; - } - } - - const publicApi = { - node: (node) => handlers.node(node), - children: processChildren, - token: (type, value) => handlers.token(type, value), - tokenize: processChunk - }; - - handlers.node(node); - - return handlers.result(); - }; - } - - function createConvertor(walk) { - return { - fromPlainObject(ast) { - walk(ast, { - enter(node) { - if (node.children && node.children instanceof List === false) { - node.children = new List().fromArray(node.children); - } - } - }); - - return ast; - }, - toPlainObject(ast) { - walk(ast, { - leave(node) { - if (node.children && node.children instanceof List) { - node.children = node.children.toArray(); - } - } - }); - - return ast; - } - }; - } - - const { hasOwnProperty: hasOwnProperty$5 } = Object.prototype; - const noop$5 = function() {}; - - function ensureFunction$1(value) { - return typeof value === 'function' ? value : noop$5; - } - - function invokeForType(fn, type) { - return function(node, item, list) { - if (node.type === type) { - fn.call(this, node, item, list); - } - }; - } - - function getWalkersFromStructure(name, nodeType) { - const structure = nodeType.structure; - const walkers = []; - - for (const key in structure) { - if (hasOwnProperty$5.call(structure, key) === false) { - continue; - } - - let fieldTypes = structure[key]; - const walker = { - name: key, - type: false, - nullable: false - }; - - if (!Array.isArray(fieldTypes)) { - fieldTypes = [fieldTypes]; - } - - for (const fieldType of fieldTypes) { - if (fieldType === null) { - walker.nullable = true; - } else if (typeof fieldType === 'string') { - walker.type = 'node'; - } else if (Array.isArray(fieldType)) { - walker.type = 'list'; - } - } - - if (walker.type) { - walkers.push(walker); - } - } - - if (walkers.length) { - return { - context: nodeType.walkContext, - fields: walkers - }; - } - - return null; - } - - function getTypesFromConfig(config) { - const types = {}; - - for (const name in config.node) { - if (hasOwnProperty$5.call(config.node, name)) { - const nodeType = config.node[name]; - - if (!nodeType.structure) { - throw new Error('Missed `structure` field in `' + name + '` node type definition'); - } - - types[name] = getWalkersFromStructure(name, nodeType); - } - } - - return types; - } - - function createTypeIterator(config, reverse) { - const fields = config.fields.slice(); - const contextName = config.context; - const useContext = typeof contextName === 'string'; - - if (reverse) { - fields.reverse(); - } - - return function(node, context, walk, walkReducer) { - let prevContextValue; - - if (useContext) { - prevContextValue = context[contextName]; - context[contextName] = node; - } - - for (const field of fields) { - const ref = node[field.name]; - - if (!field.nullable || ref) { - if (field.type === 'list') { - const breakWalk = reverse - ? ref.reduceRight(walkReducer, false) - : ref.reduce(walkReducer, false); - - if (breakWalk) { - return true; - } - } else if (walk(ref)) { - return true; - } - } - } - - if (useContext) { - context[contextName] = prevContextValue; - } - }; - } - - function createFastTraveralMap({ - StyleSheet, - Atrule, - Rule, - Block, - DeclarationList - }) { - return { - Atrule: { - StyleSheet, - Atrule, - Rule, - Block - }, - Rule: { - StyleSheet, - Atrule, - Rule, - Block - }, - Declaration: { - StyleSheet, - Atrule, - Rule, - Block, - DeclarationList - } - }; - } - - function createWalker(config) { - const types = getTypesFromConfig(config); - const iteratorsNatural = {}; - const iteratorsReverse = {}; - const breakWalk = Symbol('break-walk'); - const skipNode = Symbol('skip-node'); - - for (const name in types) { - if (hasOwnProperty$5.call(types, name) && types[name] !== null) { - iteratorsNatural[name] = createTypeIterator(types[name], false); - iteratorsReverse[name] = createTypeIterator(types[name], true); - } - } - - const fastTraversalIteratorsNatural = createFastTraveralMap(iteratorsNatural); - const fastTraversalIteratorsReverse = createFastTraveralMap(iteratorsReverse); - - const walk = function(root, options) { - function walkNode(node, item, list) { - const enterRet = enter.call(context, node, item, list); - - if (enterRet === breakWalk) { - return true; - } - - if (enterRet === skipNode) { - return false; - } - - if (iterators.hasOwnProperty(node.type)) { - if (iterators[node.type](node, context, walkNode, walkReducer)) { - return true; - } - } - - if (leave.call(context, node, item, list) === breakWalk) { - return true; - } - - return false; - } - - let enter = noop$5; - let leave = noop$5; - let iterators = iteratorsNatural; - let walkReducer = (ret, data, item, list) => ret || walkNode(data, item, list); - const context = { - break: breakWalk, - skip: skipNode, - - root, - stylesheet: null, - atrule: null, - atrulePrelude: null, - rule: null, - selector: null, - block: null, - declaration: null, - function: null - }; - - if (typeof options === 'function') { - enter = options; - } else if (options) { - enter = ensureFunction$1(options.enter); - leave = ensureFunction$1(options.leave); - - if (options.reverse) { - iterators = iteratorsReverse; - } - - if (options.visit) { - if (fastTraversalIteratorsNatural.hasOwnProperty(options.visit)) { - iterators = options.reverse - ? fastTraversalIteratorsReverse[options.visit] - : fastTraversalIteratorsNatural[options.visit]; - } else if (!types.hasOwnProperty(options.visit)) { - throw new Error('Bad value `' + options.visit + '` for `visit` option (should be: ' + Object.keys(types).sort().join(', ') + ')'); - } - - enter = invokeForType(enter, options.visit); - leave = invokeForType(leave, options.visit); - } - } - - if (enter === noop$5 && leave === noop$5) { - throw new Error('Neither `enter` nor `leave` walker handler is set or both aren\'t a function'); - } - - walkNode(root); - }; - - walk.break = breakWalk; - walk.skip = skipNode; - - walk.find = function(ast, fn) { - let found = null; - - walk(ast, function(node, item, list) { - if (fn.call(this, node, item, list)) { - found = node; - return breakWalk; - } - }); - - return found; - }; - - walk.findLast = function(ast, fn) { - let found = null; - - walk(ast, { - reverse: true, - enter(node, item, list) { - if (fn.call(this, node, item, list)) { - found = node; - return breakWalk; - } - } - }); - - return found; - }; - - walk.findAll = function(ast, fn) { - const found = []; - - walk(ast, function(node, item, list) { - if (fn.call(this, node, item, list)) { - found.push(node); - } - }); - - return found; - }; - - return walk; - } - - function noop$4(value) { - return value; - } - - function generateMultiplier(multiplier) { - const { min, max, comma } = multiplier; - - if (min === 0 && max === 0) { - return comma ? '#?' : '*'; - } - - if (min === 0 && max === 1) { - return '?'; - } - - if (min === 1 && max === 0) { - return comma ? '#' : '+'; - } - - if (min === 1 && max === 1) { - return ''; - } - - return ( - (comma ? '#' : '') + - (min === max - ? '{' + min + '}' - : '{' + min + ',' + (max !== 0 ? max : '') + '}' - ) - ); - } - - function generateTypeOpts(node) { - switch (node.type) { - case 'Range': - return ( - ' [' + - (node.min === null ? '-∞' : node.min) + - ',' + - (node.max === null ? '∞' : node.max) + - ']' - ); - - default: - throw new Error('Unknown node type `' + node.type + '`'); - } - } - - function generateSequence(node, decorate, forceBraces, compact) { - const combinator = node.combinator === ' ' || compact ? node.combinator : ' ' + node.combinator + ' '; - const result = node.terms - .map(term => internalGenerate(term, decorate, forceBraces, compact)) - .join(combinator); - - if (node.explicit || forceBraces) { - return (compact || result[0] === ',' ? '[' : '[ ') + result + (compact ? ']' : ' ]'); - } - - return result; - } - - function internalGenerate(node, decorate, forceBraces, compact) { - let result; - - switch (node.type) { - case 'Group': - result = - generateSequence(node, decorate, forceBraces, compact) + - (node.disallowEmpty ? '!' : ''); - break; - - case 'Multiplier': - // return since node is a composition - return ( - internalGenerate(node.term, decorate, forceBraces, compact) + - decorate(generateMultiplier(node), node) - ); - - case 'Type': - result = '<' + node.name + (node.opts ? decorate(generateTypeOpts(node.opts), node.opts) : '') + '>'; - break; - - case 'Property': - result = '<\'' + node.name + '\'>'; - break; - - case 'Keyword': - result = node.name; - break; - - case 'AtKeyword': - result = '@' + node.name; - break; - - case 'Function': - result = node.name + '('; - break; - - case 'String': - case 'Token': - result = node.value; - break; - - case 'Comma': - result = ','; - break; - - default: - throw new Error('Unknown node type `' + node.type + '`'); - } - - return decorate(result, node); - } - - function generate$G(node, options) { - let decorate = noop$4; - let forceBraces = false; - let compact = false; - - if (typeof options === 'function') { - decorate = options; - } else if (options) { - forceBraces = Boolean(options.forceBraces); - compact = Boolean(options.compact); - if (typeof options.decorate === 'function') { - decorate = options.decorate; - } - } - - return internalGenerate(node, decorate, forceBraces, compact); - } - - const defaultLoc = { offset: 0, line: 1, column: 1 }; - - function locateMismatch(matchResult, node) { - const tokens = matchResult.tokens; - const longestMatch = matchResult.longestMatch; - const mismatchNode = longestMatch < tokens.length ? tokens[longestMatch].node || null : null; - const badNode = mismatchNode !== node ? mismatchNode : null; - let mismatchOffset = 0; - let mismatchLength = 0; - let entries = 0; - let css = ''; - let start; - let end; - - for (let i = 0; i < tokens.length; i++) { - const token = tokens[i].value; - - if (i === longestMatch) { - mismatchLength = token.length; - mismatchOffset = css.length; - } - - if (badNode !== null && tokens[i].node === badNode) { - if (i <= longestMatch) { - entries++; - } else { - entries = 0; - } - } - - css += token; - } - - if (longestMatch === tokens.length || entries > 1) { // last - start = fromLoc(badNode || node, 'end') || buildLoc(defaultLoc, css); - end = buildLoc(start); - } else { - start = fromLoc(badNode, 'start') || - buildLoc(fromLoc(node, 'start') || defaultLoc, css.slice(0, mismatchOffset)); - end = fromLoc(badNode, 'end') || - buildLoc(start, css.substr(mismatchOffset, mismatchLength)); - } - - return { - css, - mismatchOffset, - mismatchLength, - start, - end - }; - } - - function fromLoc(node, point) { - const value = node && node.loc && node.loc[point]; - - if (value) { - return 'line' in value ? buildLoc(value) : value; - } - - return null; - } - - function buildLoc({ offset, line, column }, extra) { - const loc = { - offset, - line, - column - }; - - if (extra) { - const lines = extra.split(/\n|\r\n?|\f/); - - loc.offset += extra.length; - loc.line += lines.length - 1; - loc.column = lines.length === 1 ? loc.column + extra.length : lines.pop().length + 1; - } - - return loc; - } - - const SyntaxReferenceError = function(type, referenceName) { - const error = createCustomError( - 'SyntaxReferenceError', - type + (referenceName ? ' `' + referenceName + '`' : '') - ); - - error.reference = referenceName; - - return error; - }; - - const SyntaxMatchError = function(message, syntax, node, matchResult) { - const error = createCustomError('SyntaxMatchError', message); - const { - css, - mismatchOffset, - mismatchLength, - start, - end - } = locateMismatch(matchResult, node); - - error.rawMessage = message; - error.syntax = syntax ? generate$G(syntax) : ''; - error.css = css; - error.mismatchOffset = mismatchOffset; - error.mismatchLength = mismatchLength; - error.message = message + '\n' + - ' syntax: ' + error.syntax + '\n' + - ' value: ' + (css || '') + '\n' + - ' --------' + new Array(error.mismatchOffset + 1).join('-') + '^'; - - Object.assign(error, start); - error.loc = { - source: (node && node.loc && node.loc.source) || '', - start, - end - }; - - return error; - }; - - const keywords = new Map(); - const properties = new Map(); - const HYPHENMINUS$5 = 45; // '-'.charCodeAt() - - const keyword$1 = getKeywordDescriptor; - const property$2 = getPropertyDescriptor; - function isCustomProperty(str, offset) { - offset = offset || 0; - - return str.length - offset >= 2 && - str.charCodeAt(offset) === HYPHENMINUS$5 && - str.charCodeAt(offset + 1) === HYPHENMINUS$5; - } - - function getVendorPrefix(str, offset) { - offset = offset || 0; - - // verdor prefix should be at least 3 chars length - if (str.length - offset >= 3) { - // vendor prefix starts with hyper minus following non-hyper minus - if (str.charCodeAt(offset) === HYPHENMINUS$5 && - str.charCodeAt(offset + 1) !== HYPHENMINUS$5) { - // vendor prefix should contain a hyper minus at the ending - const secondDashIndex = str.indexOf('-', offset + 2); - - if (secondDashIndex !== -1) { - return str.substring(offset, secondDashIndex + 1); - } - } - } - - return ''; - } - - function getKeywordDescriptor(keyword) { - if (keywords.has(keyword)) { - return keywords.get(keyword); - } - - const name = keyword.toLowerCase(); - let descriptor = keywords.get(name); - - if (descriptor === undefined) { - const custom = isCustomProperty(name, 0); - const vendor = !custom ? getVendorPrefix(name, 0) : ''; - descriptor = Object.freeze({ - basename: name.substr(vendor.length), - name, - prefix: vendor, - vendor, - custom - }); - } - - keywords.set(keyword, descriptor); - - return descriptor; - } - - function getPropertyDescriptor(property) { - if (properties.has(property)) { - return properties.get(property); - } - - let name = property; - let hack = property[0]; - - if (hack === '/') { - hack = property[1] === '/' ? '//' : '/'; - } else if (hack !== '_' && - hack !== '*' && - hack !== '$' && - hack !== '#' && - hack !== '+' && - hack !== '&') { - hack = ''; - } - - const custom = isCustomProperty(name, hack.length); - - // re-use result when possible (the same as for lower case) - if (!custom) { - name = name.toLowerCase(); - if (properties.has(name)) { - const descriptor = properties.get(name); - properties.set(property, descriptor); - return descriptor; - } - } - - const vendor = !custom ? getVendorPrefix(name, hack.length) : ''; - const prefix = name.substr(0, hack.length + vendor.length); - const descriptor = Object.freeze({ - basename: name.substr(prefix.length), - name: name.substr(hack.length), - hack, - vendor, - prefix, - custom - }); - - properties.set(property, descriptor); - - return descriptor; - } - - // https://drafts.csswg.org/css-cascade-5/ - const cssWideKeywords = [ - 'initial', - 'inherit', - 'unset', - 'revert', - 'revert-layer' - ]; - - const PLUSSIGN$8 = 0x002B; // U+002B PLUS SIGN (+) - const HYPHENMINUS$4 = 0x002D; // U+002D HYPHEN-MINUS (-) - const N$3 = 0x006E; // U+006E LATIN SMALL LETTER N (n) - const DISALLOW_SIGN$1 = true; - const ALLOW_SIGN$1 = false; - - function isDelim$1(token, code) { - return token !== null && token.type === Delim && token.value.charCodeAt(0) === code; - } - - function skipSC(token, offset, getNextToken) { - while (token !== null && (token.type === WhiteSpace$1 || token.type === Comment$1)) { - token = getNextToken(++offset); - } - - return offset; - } - - function checkInteger$1(token, valueOffset, disallowSign, offset) { - if (!token) { - return 0; - } - - const code = token.value.charCodeAt(valueOffset); - - if (code === PLUSSIGN$8 || code === HYPHENMINUS$4) { - if (disallowSign) { - // Number sign is not allowed - return 0; - } - valueOffset++; - } - - for (; valueOffset < token.value.length; valueOffset++) { - if (!isDigit(token.value.charCodeAt(valueOffset))) { - // Integer is expected - return 0; - } - } - - return offset + 1; - } - - // ... - // ... ['+' | '-'] - function consumeB$1(token, offset_, getNextToken) { - let sign = false; - let offset = skipSC(token, offset_, getNextToken); - - token = getNextToken(offset); - - if (token === null) { - return offset_; - } - - if (token.type !== Number$2) { - if (isDelim$1(token, PLUSSIGN$8) || isDelim$1(token, HYPHENMINUS$4)) { - sign = true; - offset = skipSC(getNextToken(++offset), offset, getNextToken); - token = getNextToken(offset); - - if (token === null || token.type !== Number$2) { - return 0; - } - } else { - return offset_; - } - } - - if (!sign) { - const code = token.value.charCodeAt(0); - if (code !== PLUSSIGN$8 && code !== HYPHENMINUS$4) { - // Number sign is expected - return 0; - } - } - - return checkInteger$1(token, sign ? 0 : 1, sign, offset); - } - - // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb - function anPlusB(token, getNextToken) { - /* eslint-disable brace-style*/ - let offset = 0; - - if (!token) { - return 0; - } - - // - if (token.type === Number$2) { - return checkInteger$1(token, 0, ALLOW_SIGN$1, offset); // b - } - - // -n - // -n - // -n ['+' | '-'] - // -n- - // - else if (token.type === Ident && token.value.charCodeAt(0) === HYPHENMINUS$4) { - // expect 1st char is N - if (!cmpChar(token.value, 1, N$3)) { - return 0; - } - - switch (token.value.length) { - // -n - // -n - // -n ['+' | '-'] - case 2: - return consumeB$1(getNextToken(++offset), offset, getNextToken); - - // -n- - case 3: - if (token.value.charCodeAt(2) !== HYPHENMINUS$4) { - return 0; - } - - offset = skipSC(getNextToken(++offset), offset, getNextToken); - token = getNextToken(offset); - - return checkInteger$1(token, 0, DISALLOW_SIGN$1, offset); - - // - default: - if (token.value.charCodeAt(2) !== HYPHENMINUS$4) { - return 0; - } - - return checkInteger$1(token, 3, DISALLOW_SIGN$1, offset); - } - } - - // '+'? n - // '+'? n - // '+'? n ['+' | '-'] - // '+'? n- - // '+'? - else if (token.type === Ident || (isDelim$1(token, PLUSSIGN$8) && getNextToken(offset + 1).type === Ident)) { - // just ignore a plus - if (token.type !== Ident) { - token = getNextToken(++offset); - } - - if (token === null || !cmpChar(token.value, 0, N$3)) { - return 0; - } - - switch (token.value.length) { - // '+'? n - // '+'? n - // '+'? n ['+' | '-'] - case 1: - return consumeB$1(getNextToken(++offset), offset, getNextToken); - - // '+'? n- - case 2: - if (token.value.charCodeAt(1) !== HYPHENMINUS$4) { - return 0; - } - - offset = skipSC(getNextToken(++offset), offset, getNextToken); - token = getNextToken(offset); - - return checkInteger$1(token, 0, DISALLOW_SIGN$1, offset); - - // '+'? - default: - if (token.value.charCodeAt(1) !== HYPHENMINUS$4) { - return 0; - } - - return checkInteger$1(token, 2, DISALLOW_SIGN$1, offset); - } - } - - // - // - // - // - // ['+' | '-'] - else if (token.type === Dimension$1) { - let code = token.value.charCodeAt(0); - let sign = code === PLUSSIGN$8 || code === HYPHENMINUS$4 ? 1 : 0; - let i = sign; - - for (; i < token.value.length; i++) { - if (!isDigit(token.value.charCodeAt(i))) { - break; - } - } - - if (i === sign) { - // Integer is expected - return 0; - } - - if (!cmpChar(token.value, i, N$3)) { - return 0; - } - - // - // - // ['+' | '-'] - if (i + 1 === token.value.length) { - return consumeB$1(getNextToken(++offset), offset, getNextToken); - } else { - if (token.value.charCodeAt(i + 1) !== HYPHENMINUS$4) { - return 0; - } - - // - if (i + 2 === token.value.length) { - offset = skipSC(getNextToken(++offset), offset, getNextToken); - token = getNextToken(offset); - - return checkInteger$1(token, 0, DISALLOW_SIGN$1, offset); - } - // - else { - return checkInteger$1(token, i + 2, DISALLOW_SIGN$1, offset); - } - } - } - - return 0; - } - - const PLUSSIGN$7 = 0x002B; // U+002B PLUS SIGN (+) - const HYPHENMINUS$3 = 0x002D; // U+002D HYPHEN-MINUS (-) - const QUESTIONMARK$2 = 0x003F; // U+003F QUESTION MARK (?) - const U$1 = 0x0075; // U+0075 LATIN SMALL LETTER U (u) - - function isDelim(token, code) { - return token !== null && token.type === Delim && token.value.charCodeAt(0) === code; - } - - function startsWith$1(token, code) { - return token.value.charCodeAt(0) === code; - } - - function hexSequence(token, offset, allowDash) { - let hexlen = 0; - - for (let pos = offset; pos < token.value.length; pos++) { - const code = token.value.charCodeAt(pos); - - if (code === HYPHENMINUS$3 && allowDash && hexlen !== 0) { - hexSequence(token, offset + hexlen + 1, false); - return 6; // dissallow following question marks - } - - if (!isHexDigit(code)) { - return 0; // not a hex digit - } - - if (++hexlen > 6) { - return 0; // too many hex digits - } } - - return hexlen; - } - - function withQuestionMarkSequence(consumed, length, getNextToken) { - if (!consumed) { - return 0; // nothing consumed - } - - while (isDelim(getNextToken(length), QUESTIONMARK$2)) { - if (++consumed > 6) { - return 0; // too many question marks - } - - length++; - } - - return length; - } - - // https://drafts.csswg.org/css-syntax/#urange - // Informally, the production has three forms: - // U+0001 - // Defines a range consisting of a single code point, in this case the code point "1". - // U+0001-00ff - // Defines a range of codepoints between the first and the second value, in this case - // the range between "1" and "ff" (255 in decimal) inclusive. - // U+00?? - // Defines a range of codepoints where the "?" characters range over all hex digits, - // in this case defining the same as the value U+0000-00ff. - // In each form, a maximum of 6 digits is allowed for each hexadecimal number (if you treat "?" as a hexadecimal digit). - // - // = - // u '+' '?'* | - // u '?'* | - // u '?'* | - // u | - // u | - // u '+' '?'+ - function urange(token, getNextToken) { - let length = 0; - - // should start with `u` or `U` - if (token === null || token.type !== Ident || !cmpChar(token.value, 0, U$1)) { - return 0; - } - - token = getNextToken(++length); - if (token === null) { - return 0; - } - - // u '+' '?'* - // u '+' '?'+ - if (isDelim(token, PLUSSIGN$7)) { - token = getNextToken(++length); - if (token === null) { - return 0; - } - - if (token.type === Ident) { - // u '+' '?'* - return withQuestionMarkSequence(hexSequence(token, 0, true), ++length, getNextToken); - } - - if (isDelim(token, QUESTIONMARK$2)) { - // u '+' '?'+ - return withQuestionMarkSequence(1, ++length, getNextToken); - } - - // Hex digit or question mark is expected - return 0; - } - - // u '?'* - // u - // u - if (token.type === Number$2) { - const consumedHexLength = hexSequence(token, 1, true); - if (consumedHexLength === 0) { - return 0; - } - - token = getNextToken(++length); - if (token === null) { - // u - return length; - } - - if (token.type === Dimension$1 || token.type === Number$2) { - // u - // u - if (!startsWith$1(token, HYPHENMINUS$3) || !hexSequence(token, 1, false)) { - return 0; - } - - return length + 1; - } - - // u '?'* - return withQuestionMarkSequence(consumedHexLength, length, getNextToken); - } - - // u '?'* - if (token.type === Dimension$1) { - return withQuestionMarkSequence(hexSequence(token, 1, true), ++length, getNextToken); - } - - return 0; - } - - const calcFunctionNames = ['calc(', '-moz-calc(', '-webkit-calc(']; - const balancePair = new Map([ - [Function$1, RightParenthesis], - [LeftParenthesis, RightParenthesis], - [LeftSquareBracket, RightSquareBracket], - [LeftCurlyBracket, RightCurlyBracket] - ]); - - // safe char code getter - function charCodeAt(str, index) { - return index < str.length ? str.charCodeAt(index) : 0; - } - - function eqStr(actual, expected) { - return cmpStr(actual, 0, actual.length, expected); - } - - function eqStrAny(actual, expected) { - for (let i = 0; i < expected.length; i++) { - if (eqStr(actual, expected[i])) { - return true; - } - } - - return false; - } - - // IE postfix hack, i.e. 123\0 or 123px\9 - function isPostfixIeHack(str, offset) { - if (offset !== str.length - 2) { - return false; - } - - return ( - charCodeAt(str, offset) === 0x005C && // U+005C REVERSE SOLIDUS (\) - isDigit(charCodeAt(str, offset + 1)) - ); - } - - function outOfRange(opts, value, numEnd) { - if (opts && opts.type === 'Range') { - const num = Number( - numEnd !== undefined && numEnd !== value.length - ? value.substr(0, numEnd) - : value - ); - - if (isNaN(num)) { - return true; - } - - // FIXME: when opts.min is a string it's a dimension, skip a range validation - // for now since it requires a type covertation which is not implmented yet - if (opts.min !== null && num < opts.min && typeof opts.min !== 'string') { - return true; - } - - // FIXME: when opts.max is a string it's a dimension, skip a range validation - // for now since it requires a type covertation which is not implmented yet - if (opts.max !== null && num > opts.max && typeof opts.max !== 'string') { - return true; - } - } - - return false; - } - - function consumeFunction(token, getNextToken) { - let balanceCloseType = 0; - let balanceStash = []; - let length = 0; - - // balanced token consuming - scan: - do { - switch (token.type) { - case RightCurlyBracket: - case RightParenthesis: - case RightSquareBracket: - if (token.type !== balanceCloseType) { - break scan; - } - - balanceCloseType = balanceStash.pop(); - - if (balanceStash.length === 0) { - length++; - break scan; - } - - break; - - case Function$1: - case LeftParenthesis: - case LeftSquareBracket: - case LeftCurlyBracket: - balanceStash.push(balanceCloseType); - balanceCloseType = balancePair.get(token.type); - break; - } - - length++; - } while (token = getNextToken(length)); - - return length; - } - - // TODO: implement - // can be used wherever , , ,