123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- var isHexDigit = require('../tokenizer').isHexDigit;
- var cmpChar = require('../tokenizer').cmpChar;
- var TYPE = require('../tokenizer').TYPE;
- var IDENT = TYPE.Ident;
- var DELIM = TYPE.Delim;
- var NUMBER = TYPE.Number;
- var DIMENSION = TYPE.Dimension;
- var PLUSSIGN = 0x002B;
- var HYPHENMINUS = 0x002D;
- var QUESTIONMARK = 0x003F;
- var U = 0x0075;
- function isDelim(token, code) {
- return token !== null && token.type === DELIM && token.value.charCodeAt(0) === code;
- }
- function startsWith(token, code) {
- return token.value.charCodeAt(0) === code;
- }
- function hexSequence(token, offset, allowDash) {
- for (var pos = offset, hexlen = 0; pos < token.value.length; pos++) {
- var code = token.value.charCodeAt(pos);
- if (code === HYPHENMINUS && allowDash && hexlen !== 0) {
- if (hexSequence(token, offset + hexlen + 1, false) > 0) {
- return 6;
- }
- return 0;
- }
- if (!isHexDigit(code)) {
- return 0;
- }
- if (++hexlen > 6) {
- return 0;
- };
- }
- return hexlen;
- }
- function withQuestionMarkSequence(consumed, length, getNextToken) {
- if (!consumed) {
- return 0;
- }
- while (isDelim(getNextToken(length), QUESTIONMARK)) {
- if (++consumed > 6) {
- return 0;
- }
- length++;
- }
- return length;
- }
- module.exports = function urange(token, getNextToken) {
- var length = 0;
-
- if (token === null || token.type !== IDENT || !cmpChar(token.value, 0, U)) {
- return 0;
- }
- token = getNextToken(++length);
- if (token === null) {
- return 0;
- }
-
-
- if (isDelim(token, PLUSSIGN)) {
- token = getNextToken(++length);
- if (token === null) {
- return 0;
- }
- if (token.type === IDENT) {
-
- return withQuestionMarkSequence(hexSequence(token, 0, true), ++length, getNextToken);
- }
- if (isDelim(token, QUESTIONMARK)) {
-
- return withQuestionMarkSequence(1, ++length, getNextToken);
- }
-
- return 0;
- }
-
-
-
- if (token.type === NUMBER) {
- if (!startsWith(token, PLUSSIGN)) {
- return 0;
- }
- var consumedHexLength = hexSequence(token, 1, true);
- if (consumedHexLength === 0) {
- return 0;
- }
- token = getNextToken(++length);
- if (token === null) {
-
- return length;
- }
- if (token.type === DIMENSION || token.type === NUMBER) {
-
-
- if (!startsWith(token, HYPHENMINUS) || !hexSequence(token, 1, false)) {
- return 0;
- }
- return length + 1;
- }
-
- return withQuestionMarkSequence(consumedHexLength, length, getNextToken);
- }
-
- if (token.type === DIMENSION) {
- if (!startsWith(token, PLUSSIGN)) {
- return 0;
- }
- return withQuestionMarkSequence(hexSequence(token, 1, true), ++length, getNextToken);
- }
- return 0;
- };
|