first commit
This commit is contained in:
249
app_vue/node_modules/css-tree/lib/tokenizer/char-code-definitions.js
generated
vendored
Normal file
249
app_vue/node_modules/css-tree/lib/tokenizer/char-code-definitions.js
generated
vendored
Normal file
@ -0,0 +1,249 @@
|
||||
var 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 <control>.
|
||||
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
|
||||
//
|
||||
// https://drafts.csswg.org/css-syntax/#tokenizer-definitions
|
||||
// > non-ASCII code point
|
||||
// > A code point with a value equal to or greater than U+0080 <control>
|
||||
// > name-start code point
|
||||
// > A letter, a non-ASCII code point, or U+005F LOW LINE (_).
|
||||
// > name code point
|
||||
// > A name-start code point, a digit, or U+002D HYPHEN-MINUS (-)
|
||||
// That means only ASCII code points has a special meaning and we define a maps for 0..127 codes only
|
||||
var CATEGORY = new Array(0x80);
|
||||
charCodeCategory.Eof = 0x80;
|
||||
charCodeCategory.WhiteSpace = 0x82;
|
||||
charCodeCategory.Digit = 0x83;
|
||||
charCodeCategory.NameStart = 0x84;
|
||||
charCodeCategory.NonPrintable = 0x85;
|
||||
|
||||
for (var i = 0; i < CATEGORY.length; i++) {
|
||||
switch (true) {
|
||||
case isWhiteSpace(i):
|
||||
CATEGORY[i] = charCodeCategory.WhiteSpace;
|
||||
break;
|
||||
|
||||
case isDigit(i):
|
||||
CATEGORY[i] = charCodeCategory.Digit;
|
||||
break;
|
||||
|
||||
case isNameStart(i):
|
||||
CATEGORY[i] = charCodeCategory.NameStart;
|
||||
break;
|
||||
|
||||
case isNonPrintable(i):
|
||||
CATEGORY[i] = charCodeCategory.NonPrintable;
|
||||
break;
|
||||
|
||||
default:
|
||||
CATEGORY[i] = i || charCodeCategory.Eof;
|
||||
}
|
||||
}
|
||||
|
||||
function charCodeCategory(code) {
|
||||
return code < 0x80 ? CATEGORY[code] : charCodeCategory.NameStart;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isDigit: isDigit,
|
||||
isHexDigit: isHexDigit,
|
||||
isUppercaseLetter: isUppercaseLetter,
|
||||
isLowercaseLetter: isLowercaseLetter,
|
||||
isLetter: isLetter,
|
||||
isNonAscii: isNonAscii,
|
||||
isNameStart: isNameStart,
|
||||
isName: isName,
|
||||
isNonPrintable: isNonPrintable,
|
||||
isNewline: isNewline,
|
||||
isWhiteSpace: isWhiteSpace,
|
||||
isValidEscape: isValidEscape,
|
||||
isIdentifierStart: isIdentifierStart,
|
||||
isNumberStart: isNumberStart,
|
||||
|
||||
isBOM: isBOM,
|
||||
charCodeCategory: charCodeCategory
|
||||
};
|
40
app_vue/node_modules/css-tree/lib/tokenizer/const.js
generated
vendored
Normal file
40
app_vue/node_modules/css-tree/lib/tokenizer/const.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// CSS Syntax Module Level 3
|
||||
// https://www.w3.org/TR/css-syntax-3/
|
||||
var TYPE = {
|
||||
EOF: 0, // <EOF-token>
|
||||
Ident: 1, // <ident-token>
|
||||
Function: 2, // <function-token>
|
||||
AtKeyword: 3, // <at-keyword-token>
|
||||
Hash: 4, // <hash-token>
|
||||
String: 5, // <string-token>
|
||||
BadString: 6, // <bad-string-token>
|
||||
Url: 7, // <url-token>
|
||||
BadUrl: 8, // <bad-url-token>
|
||||
Delim: 9, // <delim-token>
|
||||
Number: 10, // <number-token>
|
||||
Percentage: 11, // <percentage-token>
|
||||
Dimension: 12, // <dimension-token>
|
||||
WhiteSpace: 13, // <whitespace-token>
|
||||
CDO: 14, // <CDO-token>
|
||||
CDC: 15, // <CDC-token>
|
||||
Colon: 16, // <colon-token> :
|
||||
Semicolon: 17, // <semicolon-token> ;
|
||||
Comma: 18, // <comma-token> ,
|
||||
LeftSquareBracket: 19, // <[-token>
|
||||
RightSquareBracket: 20, // <]-token>
|
||||
LeftParenthesis: 21, // <(-token>
|
||||
RightParenthesis: 22, // <)-token>
|
||||
LeftCurlyBracket: 23, // <{-token>
|
||||
RightCurlyBracket: 24, // <}-token>
|
||||
Comment: 25
|
||||
};
|
||||
|
||||
var NAME = Object.keys(TYPE).reduce(function(result, key) {
|
||||
result[TYPE[key]] = key;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
module.exports = {
|
||||
TYPE: TYPE,
|
||||
NAME: NAME
|
||||
};
|
591
app_vue/node_modules/css-tree/lib/tokenizer/index.js
generated
vendored
Normal file
591
app_vue/node_modules/css-tree/lib/tokenizer/index.js
generated
vendored
Normal file
@ -0,0 +1,591 @@
|
||||
var TokenStream = require('../common/TokenStream');
|
||||
var adoptBuffer = require('../common/adopt-buffer');
|
||||
|
||||
var constants = require('./const');
|
||||
var TYPE = constants.TYPE;
|
||||
|
||||
var charCodeDefinitions = require('./char-code-definitions');
|
||||
var isNewline = charCodeDefinitions.isNewline;
|
||||
var isName = charCodeDefinitions.isName;
|
||||
var isValidEscape = charCodeDefinitions.isValidEscape;
|
||||
var isNumberStart = charCodeDefinitions.isNumberStart;
|
||||
var isIdentifierStart = charCodeDefinitions.isIdentifierStart;
|
||||
var charCodeCategory = charCodeDefinitions.charCodeCategory;
|
||||
var isBOM = charCodeDefinitions.isBOM;
|
||||
|
||||
var utils = require('./utils');
|
||||
var cmpStr = utils.cmpStr;
|
||||
var getNewlineLength = utils.getNewlineLength;
|
||||
var findWhiteSpaceEnd = utils.findWhiteSpaceEnd;
|
||||
var consumeEscaped = utils.consumeEscaped;
|
||||
var consumeName = utils.consumeName;
|
||||
var consumeNumber = utils.consumeNumber;
|
||||
var consumeBadUrlRemnants = utils.consumeBadUrlRemnants;
|
||||
|
||||
var OFFSET_MASK = 0x00FFFFFF;
|
||||
var TYPE_SHIFT = 24;
|
||||
|
||||
function tokenize(source, stream) {
|
||||
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(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 <dimension-token> with the same value and type flag as number, and a unit set initially to the empty string.
|
||||
// Consume a name. Set the <dimension-token>’s unit to the returned value.
|
||||
// Return the <dimension-token>.
|
||||
type = TYPE.Dimension;
|
||||
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 <percentage-token> with the same value as number, and return it.
|
||||
type = TYPE.Percentage;
|
||||
offset++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, create a <number-token> with the same value and type flag as number, and return it.
|
||||
type = TYPE.Number;
|
||||
}
|
||||
|
||||
// § 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 <function-token> with its value set to string and return it.
|
||||
if (getCharCode(offset) === 0x0022 ||
|
||||
getCharCode(offset) === 0x0027) {
|
||||
type = TYPE.Function;
|
||||
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 <function-token> with its value set to string and return it.
|
||||
if (getCharCode(offset) === 0x0028) {
|
||||
type = TYPE.Function;
|
||||
offset++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, create an <ident-token> with its value set to string and return it.
|
||||
type = 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 <string-token> with its value set to the empty string.
|
||||
type = TYPE.String;
|
||||
|
||||
// Repeatedly consume the next input code point from the stream:
|
||||
for (; offset < source.length; offset++) {
|
||||
var code = source.charCodeAt(offset);
|
||||
|
||||
switch (charCodeCategory(code)) {
|
||||
// ending code point
|
||||
case endingCodePoint:
|
||||
// Return the <string-token>.
|
||||
offset++;
|
||||
return;
|
||||
|
||||
// EOF
|
||||
case charCodeCategory.Eof:
|
||||
// This is a parse error. Return the <string-token>.
|
||||
return;
|
||||
|
||||
// newline
|
||||
case charCodeCategory.WhiteSpace:
|
||||
if (isNewline(code)) {
|
||||
// This is a parse error. Reconsume the current input code point,
|
||||
// create a <bad-string-token>, and return it.
|
||||
offset += getNewlineLength(source, offset, code);
|
||||
type = 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;
|
||||
}
|
||||
|
||||
var 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 <string-token>’s value.
|
||||
offset = consumeEscaped(source, offset) - 1;
|
||||
}
|
||||
break;
|
||||
|
||||
// anything else
|
||||
// Append the current input code point to the <string-token>’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 <function-token>. Consume an ident-like token
|
||||
// automatically handles this distinction; this algorithm shouldn’t be called directly otherwise.
|
||||
function consumeUrlToken() {
|
||||
// Initially create a <url-token> with its value set to the empty string.
|
||||
type = TYPE.Url;
|
||||
|
||||
// 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++) {
|
||||
var code = source.charCodeAt(offset);
|
||||
|
||||
switch (charCodeCategory(code)) {
|
||||
// U+0029 RIGHT PARENTHESIS ())
|
||||
case 0x0029:
|
||||
// Return the <url-token>.
|
||||
offset++;
|
||||
return;
|
||||
|
||||
// EOF
|
||||
case charCodeCategory.Eof:
|
||||
// This is a parse error. Return the <url-token>.
|
||||
return;
|
||||
|
||||
// whitespace
|
||||
case charCodeCategory.WhiteSpace:
|
||||
// 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 <url-token>
|
||||
// (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 <bad-url-token>,
|
||||
// and return it.
|
||||
offset = consumeBadUrlRemnants(source, offset);
|
||||
type = 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 charCodeCategory.NonPrintable:
|
||||
// This is a parse error. Consume the remnants of a bad url,
|
||||
// create a <bad-url-token>, and return it.
|
||||
offset = consumeBadUrlRemnants(source, offset);
|
||||
type = 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 <url-token>’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 <bad-url-token>, and return it.
|
||||
offset = consumeBadUrlRemnants(source, offset);
|
||||
type = TYPE.BadUrl;
|
||||
return;
|
||||
|
||||
// anything else
|
||||
// Append the current input code point to the <url-token>’s value.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!stream) {
|
||||
stream = new TokenStream();
|
||||
}
|
||||
|
||||
// ensure source is a string
|
||||
source = String(source || '');
|
||||
|
||||
var sourceLength = source.length;
|
||||
var offsetAndType = adoptBuffer(stream.offsetAndType, sourceLength + 1); // +1 because of eof-token
|
||||
var balance = adoptBuffer(stream.balance, sourceLength + 1);
|
||||
var tokenCount = 0;
|
||||
var start = isBOM(getCharCode(0));
|
||||
var offset = start;
|
||||
var balanceCloseType = 0;
|
||||
var balanceStart = 0;
|
||||
var balancePrev = 0;
|
||||
|
||||
// https://drafts.csswg.org/css-syntax-3/#consume-token
|
||||
// § 4.3.1. Consume a token
|
||||
while (offset < sourceLength) {
|
||||
var code = source.charCodeAt(offset);
|
||||
var type = 0;
|
||||
|
||||
balance[tokenCount] = sourceLength;
|
||||
|
||||
switch (charCodeCategory(code)) {
|
||||
// whitespace
|
||||
case charCodeCategory.WhiteSpace:
|
||||
// Consume as much whitespace as possible. Return a <whitespace-token>.
|
||||
type = TYPE.WhiteSpace;
|
||||
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 <hash-token>.
|
||||
type = TYPE.Hash;
|
||||
|
||||
// If the next 3 input code points would start an identifier, set the <hash-token>’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 <hash-token>’s value to the returned string.
|
||||
offset = consumeName(source, offset + 1);
|
||||
|
||||
// Return the <hash-token>.
|
||||
} else {
|
||||
// Otherwise, return a <delim-token> with its value set to the current input code point.
|
||||
type = 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 = TYPE.LeftParenthesis;
|
||||
offset++;
|
||||
break;
|
||||
|
||||
// U+0029 RIGHT PARENTHESIS ())
|
||||
case 0x0029:
|
||||
// Return a <)-token>.
|
||||
type = 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 <delim-token> with its value set to the current input code point.
|
||||
type = TYPE.Delim;
|
||||
offset++;
|
||||
}
|
||||
break;
|
||||
|
||||
// U+002C COMMA (,)
|
||||
case 0x002C:
|
||||
// Return a <comma-token>.
|
||||
type = 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 <CDC-token>.
|
||||
if (getCharCode(offset + 1) === 0x002D &&
|
||||
getCharCode(offset + 2) === 0x003E) {
|
||||
type = TYPE.CDC;
|
||||
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 <delim-token> with its value set to the current input code point.
|
||||
type = 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 <delim-token> with its value set to the current input code point.
|
||||
type = 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 = TYPE.Comment;
|
||||
offset = source.indexOf('*/', offset + 2) + 2;
|
||||
if (offset === 1) {
|
||||
offset = source.length;
|
||||
}
|
||||
} else {
|
||||
type = TYPE.Delim;
|
||||
offset++;
|
||||
}
|
||||
break;
|
||||
|
||||
// U+003A COLON (:)
|
||||
case 0x003A:
|
||||
// Return a <colon-token>.
|
||||
type = TYPE.Colon;
|
||||
offset++;
|
||||
break;
|
||||
|
||||
// U+003B SEMICOLON (;)
|
||||
case 0x003B:
|
||||
// Return a <semicolon-token>.
|
||||
type = 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 <CDO-token>.
|
||||
type = TYPE.CDO;
|
||||
offset = offset + 4;
|
||||
} else {
|
||||
// Otherwise, return a <delim-token> with its value set to the current input code point.
|
||||
type = 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 <at-keyword-token> with its value set to the returned value, and return it.
|
||||
type = TYPE.AtKeyword;
|
||||
offset = consumeName(source, offset + 1);
|
||||
} else {
|
||||
// Otherwise, return a <delim-token> with its value set to the current input code point.
|
||||
type = TYPE.Delim;
|
||||
offset++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// U+005B LEFT SQUARE BRACKET ([)
|
||||
case 0x005B:
|
||||
// Return a <[-token>.
|
||||
type = 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 <delim-token> with its value set to the current input code point.
|
||||
type = TYPE.Delim;
|
||||
offset++;
|
||||
}
|
||||
break;
|
||||
|
||||
// U+005D RIGHT SQUARE BRACKET (])
|
||||
case 0x005D:
|
||||
// Return a <]-token>.
|
||||
type = TYPE.RightSquareBracket;
|
||||
offset++;
|
||||
break;
|
||||
|
||||
// U+007B LEFT CURLY BRACKET ({)
|
||||
case 0x007B:
|
||||
// Return a <{-token>.
|
||||
type = TYPE.LeftCurlyBracket;
|
||||
offset++;
|
||||
break;
|
||||
|
||||
// U+007D RIGHT CURLY BRACKET (})
|
||||
case 0x007D:
|
||||
// Return a <}-token>.
|
||||
type = TYPE.RightCurlyBracket;
|
||||
offset++;
|
||||
break;
|
||||
|
||||
// digit
|
||||
case charCodeCategory.Digit:
|
||||
// Reconsume the current input code point, consume a numeric token, and return it.
|
||||
consumeNumericToken();
|
||||
break;
|
||||
|
||||
// name-start code point
|
||||
case charCodeCategory.NameStart:
|
||||
// Reconsume the current input code point, consume an ident-like token, and return it.
|
||||
consumeIdentLikeToken();
|
||||
break;
|
||||
|
||||
// EOF
|
||||
case charCodeCategory.Eof:
|
||||
// Return an <EOF-token>.
|
||||
break;
|
||||
|
||||
// anything else
|
||||
default:
|
||||
// Return a <delim-token> with its value set to the current input code point.
|
||||
type = TYPE.Delim;
|
||||
offset++;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case balanceCloseType:
|
||||
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 TYPE.LeftParenthesis:
|
||||
case TYPE.Function:
|
||||
balance[tokenCount] = balanceStart;
|
||||
balanceCloseType = TYPE.RightParenthesis;
|
||||
balanceStart = (balanceCloseType << TYPE_SHIFT) | tokenCount;
|
||||
break;
|
||||
|
||||
case TYPE.LeftSquareBracket:
|
||||
balance[tokenCount] = balanceStart;
|
||||
balanceCloseType = TYPE.RightSquareBracket;
|
||||
balanceStart = (balanceCloseType << TYPE_SHIFT) | tokenCount;
|
||||
break;
|
||||
|
||||
case TYPE.LeftCurlyBracket:
|
||||
balance[tokenCount] = balanceStart;
|
||||
balanceCloseType = TYPE.RightCurlyBracket;
|
||||
balanceStart = (balanceCloseType << TYPE_SHIFT) | tokenCount;
|
||||
break;
|
||||
}
|
||||
|
||||
offsetAndType[tokenCount++] = (type << TYPE_SHIFT) | offset;
|
||||
}
|
||||
|
||||
// finalize buffers
|
||||
offsetAndType[tokenCount] = (TYPE.EOF << TYPE_SHIFT) | offset; // <EOF-token>
|
||||
balance[tokenCount] = sourceLength;
|
||||
balance[sourceLength] = sourceLength; // prevents false positive balance match with any token
|
||||
while (balanceStart !== 0) {
|
||||
balancePrev = balanceStart & OFFSET_MASK;
|
||||
balanceStart = balance[balancePrev];
|
||||
balance[balancePrev] = sourceLength;
|
||||
}
|
||||
|
||||
// update stream
|
||||
stream.source = source;
|
||||
stream.firstCharOffset = start;
|
||||
stream.offsetAndType = offsetAndType;
|
||||
stream.tokenCount = tokenCount;
|
||||
stream.balance = balance;
|
||||
stream.reset();
|
||||
stream.next();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
// extend tokenizer with constants
|
||||
Object.keys(constants).forEach(function(key) {
|
||||
tokenize[key] = constants[key];
|
||||
});
|
||||
|
||||
// extend tokenizer with static methods from utils
|
||||
Object.keys(charCodeDefinitions).forEach(function(key) {
|
||||
tokenize[key] = charCodeDefinitions[key];
|
||||
});
|
||||
Object.keys(utils).forEach(function(key) {
|
||||
tokenize[key] = utils[key];
|
||||
});
|
||||
|
||||
module.exports = tokenize;
|
243
app_vue/node_modules/css-tree/lib/tokenizer/utils.js
generated
vendored
Normal file
243
app_vue/node_modules/css-tree/lib/tokenizer/utils.js
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
var charCodeDef = require('./char-code-definitions');
|
||||
var isDigit = charCodeDef.isDigit;
|
||||
var isHexDigit = charCodeDef.isHexDigit;
|
||||
var isUppercaseLetter = charCodeDef.isUppercaseLetter;
|
||||
var isName = charCodeDef.isName;
|
||||
var isWhiteSpace = charCodeDef.isWhiteSpace;
|
||||
var isValidEscape = charCodeDef.isValidEscape;
|
||||
|
||||
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) {
|
||||
var 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 (var i = start; i < end; i++) {
|
||||
var testCode = testStr.charCodeAt(i);
|
||||
var referenceCode = referenceStr.charCodeAt(i - start);
|
||||
|
||||
// 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 (var 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.
|
||||
var 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 <ident-token>. 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++) {
|
||||
var 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(source, offset) {
|
||||
var 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.
|
||||
code = source.charCodeAt(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 */)) {
|
||||
var 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++) {
|
||||
var 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 <bad-url-token>. This is otherwise identical to
|
||||
// the "anything else" clause.
|
||||
offset = consumeEscaped(source, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
consumeEscaped: consumeEscaped,
|
||||
consumeName: consumeName,
|
||||
consumeNumber: consumeNumber,
|
||||
consumeBadUrlRemnants: consumeBadUrlRemnants,
|
||||
|
||||
cmpChar: cmpChar,
|
||||
cmpStr: cmpStr,
|
||||
|
||||
getNewlineLength: getNewlineLength,
|
||||
findWhiteSpaceStart: findWhiteSpaceStart,
|
||||
findWhiteSpaceEnd: findWhiteSpaceEnd
|
||||
};
|
Reference in New Issue
Block a user