mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 05:32:18 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
26
web/node_modules/postcss-values-parser/lib/atword.js
generated
vendored
Normal file
26
web/node_modules/postcss-values-parser/lib/atword.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
|
||||
class AtWord extends Container {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'atword';
|
||||
}
|
||||
|
||||
toString () {
|
||||
let quote = this.quoted ? this.raws.quote : '';
|
||||
return [
|
||||
this.raws.before,
|
||||
'@',
|
||||
// we can't use String() here because it'll try using itself
|
||||
// as the constructor
|
||||
String.prototype.toString.call(this.value),
|
||||
this.raws.after
|
||||
].join('');
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(AtWord);
|
||||
|
||||
module.exports = AtWord;
|
15
web/node_modules/postcss-values-parser/lib/colon.js
generated
vendored
Normal file
15
web/node_modules/postcss-values-parser/lib/colon.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Colon extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'colon';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(Colon);
|
||||
|
||||
module.exports = Colon;
|
15
web/node_modules/postcss-values-parser/lib/comma.js
generated
vendored
Normal file
15
web/node_modules/postcss-values-parser/lib/comma.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Comma extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'comma';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(Comma);
|
||||
|
||||
module.exports = Comma;
|
26
web/node_modules/postcss-values-parser/lib/comment.js
generated
vendored
Normal file
26
web/node_modules/postcss-values-parser/lib/comment.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Comment extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'comment';
|
||||
this.inline = Object(opts).inline || false;
|
||||
}
|
||||
|
||||
toString () {
|
||||
return [
|
||||
this.raws.before,
|
||||
this.inline ? '//' : '/*',
|
||||
String(this.value),
|
||||
this.inline ? '' : '*/',
|
||||
this.raws.after
|
||||
].join('');
|
||||
}
|
||||
};
|
||||
|
||||
Container.registerWalker(Comment);
|
||||
|
||||
module.exports = Comment;
|
210
web/node_modules/postcss-values-parser/lib/container.js
generated
vendored
Normal file
210
web/node_modules/postcss-values-parser/lib/container.js
generated
vendored
Normal file
|
@ -0,0 +1,210 @@
|
|||
'use strict';
|
||||
|
||||
const Node = require('./node');
|
||||
|
||||
class Container extends Node {
|
||||
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
|
||||
if (!this.nodes) {
|
||||
this.nodes = [];
|
||||
}
|
||||
}
|
||||
|
||||
push (child) {
|
||||
child.parent = this;
|
||||
this.nodes.push(child);
|
||||
return this;
|
||||
}
|
||||
|
||||
each (callback) {
|
||||
if (!this.lastEach) this.lastEach = 0;
|
||||
if (!this.indexes) this.indexes = { };
|
||||
|
||||
this.lastEach += 1;
|
||||
|
||||
let id = this.lastEach,
|
||||
index,
|
||||
result;
|
||||
|
||||
this.indexes[id] = 0;
|
||||
|
||||
if (!this.nodes) return undefined;
|
||||
|
||||
while (this.indexes[id] < this.nodes.length) {
|
||||
index = this.indexes[id];
|
||||
result = callback(this.nodes[index], index);
|
||||
if (result === false) break;
|
||||
|
||||
this.indexes[id] += 1;
|
||||
}
|
||||
|
||||
delete this.indexes[id];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
walk (callback) {
|
||||
return this.each((child, i) => {
|
||||
let result = callback(child, i);
|
||||
if (result !== false && child.walk) {
|
||||
result = child.walk(callback);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
walkType (type, callback) {
|
||||
if (!type || !callback) {
|
||||
throw new Error('Parameters {type} and {callback} are required.');
|
||||
}
|
||||
|
||||
// allow users to pass a constructor, or node type string; eg. Word.
|
||||
const isTypeCallable = typeof type === 'function';
|
||||
|
||||
return this.walk((node, index) => {
|
||||
if (isTypeCallable && node instanceof type || !isTypeCallable && node.type === type) {
|
||||
return callback.call(this, node, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
append (node) {
|
||||
node.parent = this;
|
||||
this.nodes.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
prepend (node) {
|
||||
node.parent = this;
|
||||
this.nodes.unshift(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
cleanRaws (keepBetween) {
|
||||
super.cleanRaws(keepBetween);
|
||||
if (this.nodes) {
|
||||
for (let node of this.nodes) node.cleanRaws(keepBetween);
|
||||
}
|
||||
}
|
||||
|
||||
insertAfter (oldNode, newNode) {
|
||||
let oldIndex = this.index(oldNode),
|
||||
index;
|
||||
|
||||
this.nodes.splice(oldIndex + 1, 0, newNode);
|
||||
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id];
|
||||
if (oldIndex <= index) {
|
||||
this.indexes[id] = index + this.nodes.length;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
insertBefore (oldNode, newNode) {
|
||||
let oldIndex = this.index(oldNode),
|
||||
index;
|
||||
|
||||
this.nodes.splice(oldIndex, 0, newNode);
|
||||
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id];
|
||||
if (oldIndex <= index) {
|
||||
this.indexes[id] = index + this.nodes.length;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
removeChild (child) {
|
||||
child = this.index(child);
|
||||
this.nodes[child].parent = undefined;
|
||||
this.nodes.splice(child, 1);
|
||||
|
||||
let index;
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id];
|
||||
if (index >= child) {
|
||||
this.indexes[id] = index - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
removeAll () {
|
||||
for (let node of this.nodes) node.parent = undefined;
|
||||
this.nodes = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
every (condition) {
|
||||
return this.nodes.every(condition);
|
||||
}
|
||||
|
||||
some (condition) {
|
||||
return this.nodes.some(condition);
|
||||
}
|
||||
|
||||
index (child) {
|
||||
if (typeof child === 'number') {
|
||||
return child;
|
||||
}
|
||||
else {
|
||||
return this.nodes.indexOf(child);
|
||||
}
|
||||
}
|
||||
|
||||
get first () {
|
||||
if (!this.nodes) return undefined;
|
||||
return this.nodes[0];
|
||||
}
|
||||
|
||||
get last () {
|
||||
if (!this.nodes) return undefined;
|
||||
return this.nodes[this.nodes.length - 1];
|
||||
}
|
||||
|
||||
toString () {
|
||||
let result = this.nodes.map(String).join('');
|
||||
|
||||
if (this.value) {
|
||||
result = this.value + result;
|
||||
}
|
||||
|
||||
if (this.raws.before) {
|
||||
result = this.raws.before + result;
|
||||
}
|
||||
|
||||
if (this.raws.after) {
|
||||
result += this.raws.after;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker = (constructor) => {
|
||||
let walkerName = 'walk' + constructor.name;
|
||||
|
||||
// plural sugar
|
||||
if (walkerName.lastIndexOf('s') !== walkerName.length - 1) {
|
||||
walkerName += 's';
|
||||
}
|
||||
|
||||
if (Container.prototype[walkerName]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we need access to `this` so we can't use an arrow function
|
||||
Container.prototype[walkerName] = function (callback) {
|
||||
return this.walkType(constructor, callback);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Container;
|
19
web/node_modules/postcss-values-parser/lib/errors/ParserError.js
generated
vendored
Normal file
19
web/node_modules/postcss-values-parser/lib/errors/ParserError.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
class ParserError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
|
||||
this.name = this.constructor.name;
|
||||
this.message = message || 'An error ocurred while parsing.';
|
||||
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
else {
|
||||
this.stack = (new Error(message)).stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ParserError;
|
19
web/node_modules/postcss-values-parser/lib/errors/TokenizeError.js
generated
vendored
Normal file
19
web/node_modules/postcss-values-parser/lib/errors/TokenizeError.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
class TokenizeError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
|
||||
this.name = this.constructor.name;
|
||||
this.message = message || 'An error ocurred while tokzenizing.';
|
||||
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
else {
|
||||
this.stack = (new Error(message)).stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TokenizeError;
|
16
web/node_modules/postcss-values-parser/lib/function.js
generated
vendored
Normal file
16
web/node_modules/postcss-values-parser/lib/function.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
|
||||
class FunctionNode extends Container {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'func';
|
||||
// start off at -1 so we know there haven't been any parens added
|
||||
this.unbalanced = -1;
|
||||
}
|
||||
};
|
||||
|
||||
Container.registerWalker(FunctionNode);
|
||||
|
||||
module.exports = FunctionNode;
|
69
web/node_modules/postcss-values-parser/lib/index.js
generated
vendored
Normal file
69
web/node_modules/postcss-values-parser/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
|
||||
const Parser = require('./parser');
|
||||
const AtWord = require('./atword');
|
||||
const Colon = require('./colon');
|
||||
const Comma = require('./comma');
|
||||
const Comment = require('./comment');
|
||||
const Func = require('./function');
|
||||
const Num = require('./number');
|
||||
const Operator = require('./operator');
|
||||
const Paren = require('./paren');
|
||||
const Str = require('./string');
|
||||
const UnicodeRange = require('./unicode-range');
|
||||
const Value = require('./value');
|
||||
const Word = require('./word');
|
||||
|
||||
let parser = function (source, options) {
|
||||
return new Parser(source, options);
|
||||
};
|
||||
|
||||
parser.atword = function (opts) {
|
||||
return new AtWord(opts);
|
||||
};
|
||||
|
||||
parser.colon = function (opts) {
|
||||
return new Colon(Object.assign({ value: ':' }, opts));
|
||||
};
|
||||
|
||||
parser.comma = function (opts) {
|
||||
return new Comma(Object.assign({ value: ',' }, opts));
|
||||
};
|
||||
|
||||
parser.comment = function (opts) {
|
||||
return new Comment(opts);
|
||||
};
|
||||
|
||||
parser.func = function (opts) {
|
||||
return new Func(opts);
|
||||
};
|
||||
|
||||
parser.number = function (opts) {
|
||||
return new Num(opts);
|
||||
};
|
||||
|
||||
parser.operator = function (opts) {
|
||||
return new Operator(opts);
|
||||
};
|
||||
|
||||
parser.paren = function (opts) {
|
||||
return new Paren(Object.assign({ value: '(' }, opts));
|
||||
};
|
||||
|
||||
parser.string = function (opts) {
|
||||
return new Str(Object.assign({ quote: '\'' }, opts));
|
||||
};
|
||||
|
||||
parser.value = function (opts) {
|
||||
return new Value(opts);
|
||||
};
|
||||
|
||||
parser.word = function (opts) {
|
||||
return new Word(opts);
|
||||
};
|
||||
|
||||
parser.unicodeRange = function (opts) {
|
||||
return new UnicodeRange(opts);
|
||||
};
|
||||
|
||||
module.exports = parser;
|
214
web/node_modules/postcss-values-parser/lib/node.js
generated
vendored
Normal file
214
web/node_modules/postcss-values-parser/lib/node.js
generated
vendored
Normal file
|
@ -0,0 +1,214 @@
|
|||
'use strict';
|
||||
|
||||
let cloneNode = function (obj, parent) {
|
||||
let cloned = new obj.constructor();
|
||||
|
||||
for (let i in obj) {
|
||||
if (!obj.hasOwnProperty(i)) continue;
|
||||
|
||||
let value = obj[i],
|
||||
type = typeof value;
|
||||
|
||||
if (i === 'parent' && type === 'object') {
|
||||
if (parent) cloned[i] = parent;
|
||||
}
|
||||
else if (i === 'source') {
|
||||
cloned[i] = value;
|
||||
}
|
||||
else if (value instanceof Array) {
|
||||
cloned[i] = value.map(j => cloneNode(j, cloned));
|
||||
}
|
||||
else if (i !== 'before' && i !== 'after' && i !== 'between' && i !== 'semicolon') {
|
||||
if (type === 'object' && value !== null) value = cloneNode(value);
|
||||
cloned[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return cloned;
|
||||
};
|
||||
|
||||
module.exports = class Node {
|
||||
|
||||
constructor (defaults) {
|
||||
defaults = defaults || {};
|
||||
this.raws = { before: '', after: '' };
|
||||
|
||||
for (let name in defaults) {
|
||||
this[name] = defaults[name];
|
||||
}
|
||||
}
|
||||
|
||||
remove () {
|
||||
if (this.parent) {
|
||||
this.parent.removeChild(this);
|
||||
}
|
||||
|
||||
this.parent = undefined;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
toString () {
|
||||
return [
|
||||
this.raws.before,
|
||||
String(this.value),
|
||||
this.raws.after
|
||||
].join('');
|
||||
}
|
||||
|
||||
clone (overrides) {
|
||||
overrides = overrides || {};
|
||||
|
||||
let cloned = cloneNode(this);
|
||||
|
||||
for (let name in overrides) {
|
||||
cloned[name] = overrides[name];
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
cloneBefore (overrides) {
|
||||
overrides = overrides || {};
|
||||
|
||||
let cloned = this.clone(overrides);
|
||||
|
||||
this.parent.insertBefore(this, cloned);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
cloneAfter (overrides) {
|
||||
overrides = overrides || {};
|
||||
|
||||
let cloned = this.clone(overrides);
|
||||
|
||||
this.parent.insertAfter(this, cloned);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
replaceWith () {
|
||||
let nodes = Array.prototype.slice.call(arguments);
|
||||
|
||||
if (this.parent) {
|
||||
for (let node of nodes) {
|
||||
this.parent.insertBefore(this, node);
|
||||
}
|
||||
|
||||
this.remove();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
moveTo (container) {
|
||||
this.cleanRaws(this.root() === container.root());
|
||||
this.remove();
|
||||
|
||||
container.append(this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
moveBefore (node) {
|
||||
this.cleanRaws(this.root() === node.root());
|
||||
this.remove();
|
||||
|
||||
node.parent.insertBefore(node, this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
moveAfter (node) {
|
||||
this.cleanRaws(this.root() === node.root());
|
||||
this.remove();
|
||||
node.parent.insertAfter(node, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
next () {
|
||||
let index = this.parent.index(this);
|
||||
|
||||
return this.parent.nodes[index + 1];
|
||||
}
|
||||
|
||||
prev () {
|
||||
let index = this.parent.index(this);
|
||||
|
||||
return this.parent.nodes[index - 1];
|
||||
}
|
||||
|
||||
toJSON () {
|
||||
let fixed = { };
|
||||
|
||||
for (let name in this) {
|
||||
if (!this.hasOwnProperty(name)) continue;
|
||||
if (name === 'parent') continue;
|
||||
let value = this[name];
|
||||
|
||||
if (value instanceof Array) {
|
||||
fixed[name] = value.map(i => {
|
||||
if (typeof i === 'object' && i.toJSON) {
|
||||
return i.toJSON();
|
||||
}
|
||||
else {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (typeof value === 'object' && value.toJSON) {
|
||||
fixed[name] = value.toJSON();
|
||||
}
|
||||
else {
|
||||
fixed[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return fixed;
|
||||
}
|
||||
|
||||
root () {
|
||||
let result = this;
|
||||
|
||||
while (result.parent) result = result.parent;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
cleanRaws (keepBetween) {
|
||||
delete this.raws.before;
|
||||
delete this.raws.after;
|
||||
if (!keepBetween) delete this.raws.between;
|
||||
}
|
||||
|
||||
positionInside (index) {
|
||||
let string = this.toString(),
|
||||
column = this.source.start.column,
|
||||
line = this.source.start.line;
|
||||
|
||||
for (let i = 0; i < index; i++) {
|
||||
if (string[i] === '\n') {
|
||||
column = 1;
|
||||
line += 1;
|
||||
}
|
||||
else {
|
||||
column += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return { line, column };
|
||||
}
|
||||
|
||||
positionBy (opts) {
|
||||
let pos = this.source.start;
|
||||
|
||||
if (Object(opts).index) {
|
||||
pos = this.positionInside(opts.index);
|
||||
}
|
||||
else if (Object(opts).word) {
|
||||
let index = this.toString().indexOf(opts.word);
|
||||
if (index !== -1) pos = this.positionInside(index);
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
};
|
25
web/node_modules/postcss-values-parser/lib/number.js
generated
vendored
Normal file
25
web/node_modules/postcss-values-parser/lib/number.js
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class NumberNode extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'number';
|
||||
this.unit = Object(opts).unit || '';
|
||||
}
|
||||
|
||||
toString () {
|
||||
return [
|
||||
this.raws.before,
|
||||
String(this.value),
|
||||
this.unit,
|
||||
this.raws.after
|
||||
].join('');
|
||||
}
|
||||
};
|
||||
|
||||
Container.registerWalker(NumberNode);
|
||||
|
||||
module.exports = NumberNode;
|
15
web/node_modules/postcss-values-parser/lib/operator.js
generated
vendored
Normal file
15
web/node_modules/postcss-values-parser/lib/operator.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Operator extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'operator';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(Operator);
|
||||
|
||||
module.exports = Operator;
|
16
web/node_modules/postcss-values-parser/lib/paren.js
generated
vendored
Normal file
16
web/node_modules/postcss-values-parser/lib/paren.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Parenthesis extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'paren';
|
||||
this.parenType = '';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(Parenthesis);
|
||||
|
||||
module.exports = Parenthesis;
|
576
web/node_modules/postcss-values-parser/lib/parser.js
generated
vendored
Normal file
576
web/node_modules/postcss-values-parser/lib/parser.js
generated
vendored
Normal file
|
@ -0,0 +1,576 @@
|
|||
'use strict';
|
||||
|
||||
const Root = require('./root');
|
||||
const Value = require('./value');
|
||||
|
||||
const AtWord = require('./atword');
|
||||
const Colon = require('./colon');
|
||||
const Comma = require('./comma');
|
||||
const Comment = require('./comment');
|
||||
const Func = require('./function');
|
||||
const Numbr = require('./number');
|
||||
const Operator = require('./operator');
|
||||
const Paren = require('./paren');
|
||||
const Str = require('./string');
|
||||
const Word = require('./word');
|
||||
const UnicodeRange = require('./unicode-range');
|
||||
|
||||
const tokenize = require('./tokenize');
|
||||
|
||||
const flatten = require('flatten');
|
||||
const indexesOf = require('indexes-of');
|
||||
const uniq = require('uniq');
|
||||
const ParserError = require('./errors/ParserError');
|
||||
|
||||
function sortAscending (list) {
|
||||
return list.sort((a, b) => a - b);
|
||||
}
|
||||
|
||||
module.exports = class Parser {
|
||||
constructor (input, options) {
|
||||
const defaults = { loose: false };
|
||||
|
||||
// cache needs to be an array for values with more than 1 level of function nesting
|
||||
this.cache = [];
|
||||
this.input = input;
|
||||
this.options = Object.assign({}, defaults, options);
|
||||
this.position = 0;
|
||||
// we'll use this to keep track of the paren balance
|
||||
this.unbalanced = 0;
|
||||
this.root = new Root();
|
||||
|
||||
let value = new Value();
|
||||
|
||||
this.root.append(value);
|
||||
|
||||
this.current = value;
|
||||
this.tokens = tokenize(input, this.options);
|
||||
}
|
||||
|
||||
parse () {
|
||||
return this.loop();
|
||||
}
|
||||
|
||||
colon () {
|
||||
let token = this.currToken;
|
||||
|
||||
this.newNode(new Colon({
|
||||
value: token[1],
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6]
|
||||
}));
|
||||
|
||||
this.position ++;
|
||||
}
|
||||
|
||||
comma () {
|
||||
let token = this.currToken;
|
||||
|
||||
this.newNode(new Comma({
|
||||
value: token[1],
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6]
|
||||
}));
|
||||
|
||||
this.position ++;
|
||||
}
|
||||
|
||||
comment () {
|
||||
let inline = false,
|
||||
value = this.currToken[1].replace(/\/\*|\*\//g, ''),
|
||||
node;
|
||||
|
||||
if (this.options.loose && value.startsWith("//")) {
|
||||
value = value.substring(2);
|
||||
inline = true;
|
||||
}
|
||||
|
||||
node = new Comment({
|
||||
value: value,
|
||||
inline: inline,
|
||||
source: {
|
||||
start: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3]
|
||||
},
|
||||
end: {
|
||||
line: this.currToken[4],
|
||||
column: this.currToken[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[6]
|
||||
});
|
||||
|
||||
this.newNode(node);
|
||||
this.position++;
|
||||
}
|
||||
|
||||
error (message, token) {
|
||||
throw new ParserError(message + ` at line: ${token[2]}, column ${token[3]}`);
|
||||
}
|
||||
|
||||
loop () {
|
||||
while (this.position < this.tokens.length) {
|
||||
this.parseTokens();
|
||||
}
|
||||
|
||||
if (!this.current.last && this.spaces) {
|
||||
this.current.raws.before += this.spaces;
|
||||
}
|
||||
else if (this.spaces) {
|
||||
this.current.last.raws.after += this.spaces;
|
||||
}
|
||||
|
||||
this.spaces = '';
|
||||
|
||||
return this.root;
|
||||
}
|
||||
|
||||
operator () {
|
||||
|
||||
// if a +|- operator is followed by a non-word character (. is allowed) and
|
||||
// is preceded by a non-word character. (5+5)
|
||||
let char = this.currToken[1],
|
||||
node;
|
||||
|
||||
if (char === '+' || char === '-') {
|
||||
// only inspect if the operator is not the first token, and we're only
|
||||
// within a calc() function: the only spec-valid place for math expressions
|
||||
if (!this.options.loose) {
|
||||
if (this.position > 0) {
|
||||
if (this.current.type === 'func' && this.current.value === 'calc') {
|
||||
// allow operators to be proceeded by spaces and opening parens
|
||||
if (this.prevToken[0] !== 'space' && this.prevToken[0] !== '(') {
|
||||
this.error('Syntax Error', this.currToken);
|
||||
}
|
||||
// valid: calc(1 - +2)
|
||||
// invalid: calc(1 -+2)
|
||||
else if (this.nextToken[0] !== 'space' && this.nextToken[0] !== 'word') {
|
||||
this.error('Syntax Error', this.currToken);
|
||||
}
|
||||
// valid: calc(1 - +2)
|
||||
// valid: calc(-0.5 + 2)
|
||||
// invalid: calc(1 -2)
|
||||
else if (this.nextToken[0] === 'word' && this.current.last.type !== 'operator' &&
|
||||
this.current.last.value !== '(') {
|
||||
this.error('Syntax Error', this.currToken);
|
||||
}
|
||||
}
|
||||
// if we're not in a function and someone has doubled up on operators,
|
||||
// or they're trying to perform a calc outside of a calc
|
||||
// eg. +-4px or 5+ 5, throw an error
|
||||
else if (this.nextToken[0] === 'space'
|
||||
|| this.nextToken[0] === 'operator'
|
||||
|| this.prevToken[0] === 'operator') {
|
||||
this.error('Syntax Error', this.currToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.options.loose) {
|
||||
if (this.nextToken[0] === 'word') {
|
||||
return this.word();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((!this.current.nodes.length || (this.current.last && this.current.last.type === 'operator')) && this.nextToken[0] === 'word') {
|
||||
return this.word();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node = new Operator({
|
||||
value: this.currToken[1],
|
||||
source: {
|
||||
start: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3]
|
||||
},
|
||||
end: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3]
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[4]
|
||||
});
|
||||
|
||||
this.position ++;
|
||||
|
||||
return this.newNode(node);
|
||||
}
|
||||
|
||||
parseTokens () {
|
||||
switch (this.currToken[0]) {
|
||||
case 'space':
|
||||
this.space();
|
||||
break;
|
||||
case 'colon':
|
||||
this.colon();
|
||||
break;
|
||||
case 'comma':
|
||||
this.comma();
|
||||
break;
|
||||
case 'comment':
|
||||
this.comment();
|
||||
break;
|
||||
case '(':
|
||||
this.parenOpen();
|
||||
break;
|
||||
case ')':
|
||||
this.parenClose();
|
||||
break;
|
||||
case 'atword':
|
||||
case 'word':
|
||||
this.word();
|
||||
break;
|
||||
case 'operator':
|
||||
this.operator();
|
||||
break;
|
||||
case 'string':
|
||||
this.string();
|
||||
break;
|
||||
case 'unicoderange':
|
||||
this.unicodeRange();
|
||||
break;
|
||||
default:
|
||||
this.word();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parenOpen () {
|
||||
let unbalanced = 1,
|
||||
pos = this.position + 1,
|
||||
token = this.currToken,
|
||||
last;
|
||||
|
||||
// check for balanced parens
|
||||
while (pos < this.tokens.length && unbalanced) {
|
||||
let tkn = this.tokens[pos];
|
||||
|
||||
if (tkn[0] === '(') {
|
||||
unbalanced++;
|
||||
}
|
||||
if (tkn[0] === ')') {
|
||||
unbalanced--;
|
||||
}
|
||||
pos ++;
|
||||
}
|
||||
|
||||
if (unbalanced) {
|
||||
this.error('Expected closing parenthesis', token);
|
||||
}
|
||||
|
||||
// ok, all parens are balanced. continue on
|
||||
|
||||
last = this.current.last;
|
||||
|
||||
if (last && last.type === 'func' && last.unbalanced < 0) {
|
||||
last.unbalanced = 0; // ok we're ready to add parens now
|
||||
this.current = last;
|
||||
}
|
||||
|
||||
this.current.unbalanced ++;
|
||||
|
||||
this.newNode(new Paren({
|
||||
value: token[1],
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6]
|
||||
}));
|
||||
|
||||
this.position ++;
|
||||
|
||||
// url functions get special treatment, and anything between the function
|
||||
// parens get treated as one word, if the contents aren't not a string.
|
||||
if (this.current.type === 'func' && this.current.unbalanced &&
|
||||
this.current.value === 'url' && this.currToken[0] !== 'string' &&
|
||||
this.currToken[0] !== ')' && !this.options.loose) {
|
||||
|
||||
let nextToken = this.nextToken,
|
||||
value = this.currToken[1],
|
||||
start = {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3]
|
||||
};
|
||||
|
||||
while (nextToken && nextToken[0] !== ')' && this.current.unbalanced) {
|
||||
this.position ++;
|
||||
value += this.currToken[1];
|
||||
nextToken = this.nextToken;
|
||||
}
|
||||
|
||||
if (this.position !== this.tokens.length - 1) {
|
||||
// skip the following word definition, or it'll be a duplicate
|
||||
this.position ++;
|
||||
|
||||
this.newNode(new Word({
|
||||
value,
|
||||
source: {
|
||||
start,
|
||||
end: {
|
||||
line: this.currToken[4],
|
||||
column: this.currToken[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[6]
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parenClose () {
|
||||
let token = this.currToken;
|
||||
|
||||
this.newNode(new Paren({
|
||||
value: token[1],
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6]
|
||||
}));
|
||||
|
||||
this.position ++;
|
||||
|
||||
if (this.position >= this.tokens.length - 1 && !this.current.unbalanced) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.current.unbalanced --;
|
||||
|
||||
if (this.current.unbalanced < 0) {
|
||||
this.error('Expected opening parenthesis', token);
|
||||
}
|
||||
|
||||
if (!this.current.unbalanced && this.cache.length) {
|
||||
this.current = this.cache.pop();
|
||||
}
|
||||
}
|
||||
|
||||
space () {
|
||||
let token = this.currToken;
|
||||
// Handle space before and after the selector
|
||||
if (this.position === (this.tokens.length - 1) || this.nextToken[0] === ',' || this.nextToken[0] === ')') {
|
||||
this.current.last.raws.after += token[1];
|
||||
this.position ++;
|
||||
}
|
||||
else {
|
||||
this.spaces = token[1];
|
||||
this.position ++;
|
||||
}
|
||||
}
|
||||
|
||||
unicodeRange () {
|
||||
let token = this.currToken;
|
||||
|
||||
this.newNode(new UnicodeRange({
|
||||
value: token[1],
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6]
|
||||
}));
|
||||
|
||||
this.position ++;
|
||||
}
|
||||
|
||||
splitWord () {
|
||||
let nextToken = this.nextToken,
|
||||
word = this.currToken[1],
|
||||
rNumber = /^[\+\-]?((\d+(\.\d*)?)|(\.\d+))([eE][\+\-]?\d+)?/,
|
||||
|
||||
// treat css-like groupings differently so they can be inspected,
|
||||
// but don't address them as anything but a word, but allow hex values
|
||||
// to pass through.
|
||||
rNoFollow = /^(?!\#([a-z0-9]+))[\#\{\}]/gi,
|
||||
|
||||
hasAt, indices;
|
||||
|
||||
if (!rNoFollow.test(word)) {
|
||||
while (nextToken && nextToken[0] === 'word') {
|
||||
this.position ++;
|
||||
|
||||
let current = this.currToken[1];
|
||||
word += current;
|
||||
|
||||
nextToken = this.nextToken;
|
||||
}
|
||||
}
|
||||
|
||||
hasAt = indexesOf(word, '@');
|
||||
indices = sortAscending(uniq(flatten([[0], hasAt])));
|
||||
|
||||
indices.forEach((ind, i) => {
|
||||
let index = indices[i + 1] || word.length,
|
||||
value = word.slice(ind, index),
|
||||
node;
|
||||
|
||||
if (~hasAt.indexOf(ind)) {
|
||||
node = new AtWord({
|
||||
value: value.slice(1),
|
||||
source: {
|
||||
start: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3] + ind
|
||||
},
|
||||
end: {
|
||||
line: this.currToken[4],
|
||||
column: this.currToken[3] + (index - 1)
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[6] + indices[i]
|
||||
});
|
||||
}
|
||||
else if (rNumber.test(this.currToken[1])) {
|
||||
let unit = value.replace(rNumber, '');
|
||||
|
||||
node = new Numbr({
|
||||
value: value.replace(unit, ''),
|
||||
source: {
|
||||
start: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3] + ind
|
||||
},
|
||||
end: {
|
||||
line: this.currToken[4],
|
||||
column: this.currToken[3] + (index - 1)
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[6] + indices[i],
|
||||
unit
|
||||
});
|
||||
}
|
||||
else {
|
||||
node = new (nextToken && nextToken[0] === '(' ? Func : Word)({
|
||||
value,
|
||||
source: {
|
||||
start: {
|
||||
line: this.currToken[2],
|
||||
column: this.currToken[3] + ind
|
||||
},
|
||||
end: {
|
||||
line: this.currToken[4],
|
||||
column: this.currToken[3] + (index - 1)
|
||||
}
|
||||
},
|
||||
sourceIndex: this.currToken[6] + indices[i]
|
||||
});
|
||||
|
||||
if (node.constructor.name === 'Word') {
|
||||
node.isHex = /^#(.+)/.test(value);
|
||||
node.isColor = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value);
|
||||
}
|
||||
else {
|
||||
this.cache.push(this.current);
|
||||
}
|
||||
}
|
||||
|
||||
this.newNode(node);
|
||||
|
||||
});
|
||||
|
||||
this.position ++;
|
||||
}
|
||||
|
||||
string () {
|
||||
let token = this.currToken,
|
||||
value = this.currToken[1],
|
||||
rQuote = /^(\"|\')/,
|
||||
quoted = rQuote.test(value),
|
||||
quote = '',
|
||||
node;
|
||||
|
||||
if (quoted) {
|
||||
quote = value.match(rQuote)[0];
|
||||
// set value to the string within the quotes
|
||||
// quotes are stored in raws
|
||||
value = value.slice(1, value.length - 1);
|
||||
}
|
||||
|
||||
node = new Str({
|
||||
value,
|
||||
source: {
|
||||
start: {
|
||||
line: token[2],
|
||||
column: token[3]
|
||||
},
|
||||
end: {
|
||||
line: token[4],
|
||||
column: token[5]
|
||||
}
|
||||
},
|
||||
sourceIndex: token[6],
|
||||
quoted
|
||||
});
|
||||
|
||||
node.raws.quote = quote;
|
||||
|
||||
this.newNode(node);
|
||||
this.position++;
|
||||
}
|
||||
|
||||
word () {
|
||||
return this.splitWord();
|
||||
}
|
||||
|
||||
newNode (node) {
|
||||
if (this.spaces) {
|
||||
node.raws.before += this.spaces;
|
||||
this.spaces = '';
|
||||
}
|
||||
|
||||
return this.current.append(node);
|
||||
}
|
||||
|
||||
get currToken () {
|
||||
return this.tokens[this.position];
|
||||
}
|
||||
|
||||
get nextToken () {
|
||||
return this.tokens[this.position + 1];
|
||||
}
|
||||
|
||||
get prevToken () {
|
||||
return this.tokens[this.position - 1];
|
||||
}
|
||||
};
|
10
web/node_modules/postcss-values-parser/lib/root.js
generated
vendored
Normal file
10
web/node_modules/postcss-values-parser/lib/root.js
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
|
||||
module.exports = class Root extends Container {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'root';
|
||||
}
|
||||
};
|
28
web/node_modules/postcss-values-parser/lib/string.js
generated
vendored
Normal file
28
web/node_modules/postcss-values-parser/lib/string.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class StringNode extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'string';
|
||||
}
|
||||
|
||||
toString () {
|
||||
let quote = this.quoted ? this.raws.quote : '';
|
||||
return [
|
||||
this.raws.before,
|
||||
quote,
|
||||
// we can't use String() here because it'll try using itself
|
||||
// as the constructor
|
||||
this.value + '',
|
||||
quote,
|
||||
this.raws.after
|
||||
].join('');
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(StringNode);
|
||||
|
||||
module.exports = StringNode;
|
394
web/node_modules/postcss-values-parser/lib/tokenize.js
generated
vendored
Normal file
394
web/node_modules/postcss-values-parser/lib/tokenize.js
generated
vendored
Normal file
|
@ -0,0 +1,394 @@
|
|||
'use strict';
|
||||
|
||||
const openBracket = '{'.charCodeAt(0);
|
||||
const closeBracket = '}'.charCodeAt(0);
|
||||
const openParen = '('.charCodeAt(0);
|
||||
const closeParen = ')'.charCodeAt(0);
|
||||
const singleQuote = '\''.charCodeAt(0);
|
||||
const doubleQuote = '"'.charCodeAt(0);
|
||||
const backslash = '\\'.charCodeAt(0);
|
||||
const slash = '/'.charCodeAt(0);
|
||||
const period = '.'.charCodeAt(0);
|
||||
const comma = ','.charCodeAt(0);
|
||||
const colon = ':'.charCodeAt(0);
|
||||
const asterisk = '*'.charCodeAt(0);
|
||||
const minus = '-'.charCodeAt(0);
|
||||
const plus = '+'.charCodeAt(0);
|
||||
const pound = '#'.charCodeAt(0);
|
||||
const newline = '\n'.charCodeAt(0);
|
||||
const space = ' '.charCodeAt(0);
|
||||
const feed = '\f'.charCodeAt(0);
|
||||
const tab = '\t'.charCodeAt(0);
|
||||
const cr = '\r'.charCodeAt(0);
|
||||
const at = '@'.charCodeAt(0);
|
||||
const lowerE = 'e'.charCodeAt(0);
|
||||
const upperE = 'E'.charCodeAt(0);
|
||||
const digit0 = '0'.charCodeAt(0);
|
||||
const digit9 = '9'.charCodeAt(0);
|
||||
const lowerU = 'u'.charCodeAt(0);
|
||||
const upperU = 'U'.charCodeAt(0);
|
||||
const atEnd = /[ \n\t\r\{\(\)'"\\;,/]/g;
|
||||
const wordEnd = /[ \n\t\r\(\)\{\}\*:;@!&'"\+\|~>,\[\]\\]|\/(?=\*)/g;
|
||||
const wordEndNum = /[ \n\t\r\(\)\{\}\*:;@!&'"\-\+\|~>,\[\]\\]|\//g;
|
||||
const alphaNum = /^[a-z0-9]/i;
|
||||
const unicodeRange = /^[a-f0-9?\-]/i;
|
||||
|
||||
const util = require('util');
|
||||
const TokenizeError = require('./errors/TokenizeError');
|
||||
|
||||
module.exports = function tokenize (input, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
let tokens = [],
|
||||
css = input.valueOf(),
|
||||
length = css.length,
|
||||
offset = -1,
|
||||
line = 1,
|
||||
pos = 0,
|
||||
parentCount = 0,
|
||||
isURLArg = null,
|
||||
|
||||
code, next, quote, lines, last, content, escape, nextLine, nextOffset,
|
||||
escaped, escapePos, nextChar;
|
||||
|
||||
function unclosed (what) {
|
||||
let message = util.format('Unclosed %s at line: %d, column: %d, token: %d', what, line, pos - offset, pos);
|
||||
throw new TokenizeError(message);
|
||||
}
|
||||
|
||||
function tokenizeError () {
|
||||
let message = util.format('Syntax error at line: %d, column: %d, token: %d', line, pos - offset, pos);
|
||||
throw new TokenizeError(message);
|
||||
}
|
||||
|
||||
while (pos < length) {
|
||||
code = css.charCodeAt(pos);
|
||||
|
||||
if (code === newline) {
|
||||
offset = pos;
|
||||
line += 1;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case newline:
|
||||
case space:
|
||||
case tab:
|
||||
case cr:
|
||||
case feed:
|
||||
next = pos;
|
||||
do {
|
||||
next += 1;
|
||||
code = css.charCodeAt(next);
|
||||
if (code === newline) {
|
||||
offset = next;
|
||||
line += 1;
|
||||
}
|
||||
} while (code === space ||
|
||||
code === newline ||
|
||||
code === tab ||
|
||||
code === cr ||
|
||||
code === feed);
|
||||
|
||||
tokens.push(['space', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
break;
|
||||
|
||||
case colon:
|
||||
next = pos + 1;
|
||||
tokens.push(['colon', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
break;
|
||||
|
||||
case comma:
|
||||
next = pos + 1;
|
||||
tokens.push(['comma', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
break;
|
||||
|
||||
case openBracket:
|
||||
tokens.push(['{', '{',
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
break;
|
||||
|
||||
case closeBracket:
|
||||
tokens.push(['}', '}',
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
break;
|
||||
|
||||
case openParen:
|
||||
parentCount++;
|
||||
isURLArg = !isURLArg && parentCount === 1 &&
|
||||
tokens.length > 0 &&
|
||||
tokens[tokens.length - 1][0] === "word" &&
|
||||
tokens[tokens.length - 1][1] === "url";
|
||||
tokens.push(['(', '(',
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
break;
|
||||
|
||||
case closeParen:
|
||||
parentCount--;
|
||||
isURLArg = isURLArg && parentCount > 0;
|
||||
tokens.push([')', ')',
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
break;
|
||||
|
||||
case singleQuote:
|
||||
case doubleQuote:
|
||||
quote = code === singleQuote ? '\'' : '"';
|
||||
next = pos;
|
||||
do {
|
||||
escaped = false;
|
||||
next = css.indexOf(quote, next + 1);
|
||||
if (next === -1) {
|
||||
unclosed('quote', quote);
|
||||
}
|
||||
escapePos = next;
|
||||
while (css.charCodeAt(escapePos - 1) === backslash) {
|
||||
escapePos -= 1;
|
||||
escaped = !escaped;
|
||||
}
|
||||
} while (escaped);
|
||||
|
||||
tokens.push(['string', css.slice(pos, next + 1),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
pos = next;
|
||||
break;
|
||||
|
||||
case at:
|
||||
atEnd.lastIndex = pos + 1;
|
||||
atEnd.test(css);
|
||||
|
||||
if (atEnd.lastIndex === 0) {
|
||||
next = css.length - 1;
|
||||
}
|
||||
else {
|
||||
next = atEnd.lastIndex - 2;
|
||||
}
|
||||
|
||||
tokens.push(['atword', css.slice(pos, next + 1),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
pos = next;
|
||||
break;
|
||||
|
||||
case backslash:
|
||||
next = pos;
|
||||
code = css.charCodeAt(next + 1);
|
||||
|
||||
if (escape && (code !== slash && code !== space &&
|
||||
code !== newline && code !== tab &&
|
||||
code !== cr && code !== feed)) {
|
||||
next += 1;
|
||||
}
|
||||
|
||||
tokens.push(['word', css.slice(pos, next + 1),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next;
|
||||
break;
|
||||
|
||||
case plus:
|
||||
case minus:
|
||||
case asterisk:
|
||||
next = pos + 1;
|
||||
nextChar = css.slice(pos + 1, next + 1);
|
||||
|
||||
let prevChar = css.slice(pos - 1, pos);
|
||||
|
||||
// if the operator is immediately followed by a word character, then we
|
||||
// have a prefix of some kind, and should fall-through. eg. -webkit
|
||||
|
||||
// look for --* for custom variables
|
||||
if (code === minus && nextChar.charCodeAt(0) === minus) {
|
||||
next++;
|
||||
|
||||
tokens.push(['word', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
tokens.push(['operator', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (code === slash && (css.charCodeAt(pos + 1) === asterisk || (options.loose && !isURLArg && css.charCodeAt(pos + 1) === slash))) {
|
||||
const isStandardComment = css.charCodeAt(pos + 1) === asterisk;
|
||||
|
||||
if (isStandardComment) {
|
||||
next = css.indexOf('*/', pos + 2) + 1;
|
||||
if (next === 0) {
|
||||
unclosed('comment', '*/');
|
||||
}
|
||||
}
|
||||
else {
|
||||
const newlinePos = css.indexOf('\n', pos + 2);
|
||||
|
||||
next = newlinePos !== -1 ? newlinePos - 1 : length;
|
||||
}
|
||||
|
||||
content = css.slice(pos, next + 1);
|
||||
lines = content.split('\n');
|
||||
last = lines.length - 1;
|
||||
|
||||
if (last > 0) {
|
||||
nextLine = line + last;
|
||||
nextOffset = next - lines[last].length;
|
||||
}
|
||||
else {
|
||||
nextLine = line;
|
||||
nextOffset = offset;
|
||||
}
|
||||
|
||||
tokens.push(['comment', content,
|
||||
line, pos - offset,
|
||||
nextLine, next - nextOffset,
|
||||
pos
|
||||
]);
|
||||
|
||||
offset = nextOffset;
|
||||
line = nextLine;
|
||||
pos = next;
|
||||
|
||||
}
|
||||
else if (code === pound && !alphaNum.test(css.slice(pos + 1, pos + 2))) {
|
||||
next = pos + 1;
|
||||
|
||||
tokens.push(['#', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
}
|
||||
else if ((code === lowerU || code === upperU) && css.charCodeAt(pos + 1) === plus) {
|
||||
next = pos + 2;
|
||||
|
||||
do {
|
||||
next += 1;
|
||||
code = css.charCodeAt(next);
|
||||
} while (next < length && unicodeRange.test(css.slice(next, next + 1)));
|
||||
|
||||
tokens.push(['unicoderange', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
pos = next - 1;
|
||||
}
|
||||
// catch a regular slash, that isn't a comment
|
||||
else if (code === slash) {
|
||||
next = pos + 1;
|
||||
|
||||
tokens.push(['operator', css.slice(pos, next),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
|
||||
pos = next - 1;
|
||||
}
|
||||
else {
|
||||
let regex = wordEnd;
|
||||
|
||||
// we're dealing with a word that starts with a number
|
||||
// those get treated differently
|
||||
if (code >= digit0 && code <= digit9) {
|
||||
regex = wordEndNum;
|
||||
}
|
||||
|
||||
regex.lastIndex = pos + 1;
|
||||
regex.test(css);
|
||||
|
||||
if (regex.lastIndex === 0) {
|
||||
next = css.length - 1;
|
||||
}
|
||||
else {
|
||||
next = regex.lastIndex - 2;
|
||||
}
|
||||
|
||||
// Exponential number notation with minus or plus: 1e-10, 1e+10
|
||||
if (regex === wordEndNum || code === period) {
|
||||
let ncode = css.charCodeAt(next),
|
||||
ncode1 = css.charCodeAt(next + 1),
|
||||
ncode2 = css.charCodeAt(next + 2);
|
||||
|
||||
if (
|
||||
(ncode === lowerE || ncode === upperE) &&
|
||||
(ncode1 === minus || ncode1 === plus) &&
|
||||
(ncode2 >= digit0 && ncode2 <= digit9)
|
||||
) {
|
||||
wordEndNum.lastIndex = next + 2;
|
||||
wordEndNum.test(css);
|
||||
|
||||
if (wordEndNum.lastIndex === 0) {
|
||||
next = css.length - 1;
|
||||
}
|
||||
else {
|
||||
next = wordEndNum.lastIndex - 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tokens.push(['word', css.slice(pos, next + 1),
|
||||
line, pos - offset,
|
||||
line, next - offset,
|
||||
pos
|
||||
]);
|
||||
pos = next;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pos ++;
|
||||
}
|
||||
|
||||
return tokens;
|
||||
};
|
15
web/node_modules/postcss-values-parser/lib/unicode-range.js
generated
vendored
Normal file
15
web/node_modules/postcss-values-parser/lib/unicode-range.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class UnicodeRange extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'unicode-range';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(UnicodeRange);
|
||||
|
||||
module.exports = UnicodeRange;
|
11
web/node_modules/postcss-values-parser/lib/value.js
generated
vendored
Normal file
11
web/node_modules/postcss-values-parser/lib/value.js
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
|
||||
module.exports = class Value extends Container {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'value';
|
||||
this.unbalanced = 0;
|
||||
}
|
||||
};
|
15
web/node_modules/postcss-values-parser/lib/word.js
generated
vendored
Normal file
15
web/node_modules/postcss-values-parser/lib/word.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Container = require('./container');
|
||||
const Node = require('./node');
|
||||
|
||||
class Word extends Node {
|
||||
constructor (opts) {
|
||||
super(opts);
|
||||
this.type = 'word';
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerWalker(Word);
|
||||
|
||||
module.exports = Word;
|
Loading…
Add table
Add a link
Reference in a new issue