summaryrefslogtreecommitdiff
path: root/node_modules/css-tokenize
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:50:21 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:50:21 +0800
commit0379526e20e1ff212df23e6326741aa9c06df204 (patch)
tree340143b0c4dc4280c88ba1591d137b53477005b3 /node_modules/css-tokenize
parent7aba14fb7c970c6e6af82c805db2aef6d70bfe2b (diff)
added doiuse plugin for postcss
Diffstat (limited to 'node_modules/css-tokenize')
-rw-r--r--node_modules/css-tokenize/.npmignore28
-rw-r--r--node_modules/css-tokenize/.travis.yml4
-rw-r--r--node_modules/css-tokenize/LICENSE22
-rw-r--r--node_modules/css-tokenize/README.md100
-rw-r--r--node_modules/css-tokenize/example.js13
-rw-r--r--node_modules/css-tokenize/index.js172
-rw-r--r--node_modules/css-tokenize/package.json34
-rw-r--r--node_modules/css-tokenize/test/base.js100
-rw-r--r--node_modules/css-tokenize/test/brackets.css7
-rw-r--r--node_modules/css-tokenize/test/gauntlet.css38
-rw-r--r--node_modules/css-tokenize/test/nested.css5
11 files changed, 523 insertions, 0 deletions
diff --git a/node_modules/css-tokenize/.npmignore b/node_modules/css-tokenize/.npmignore
new file mode 100644
index 00000000..59d842ba
--- /dev/null
+++ b/node_modules/css-tokenize/.npmignore
@@ -0,0 +1,28 @@
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# Commenting this out is preferred by some people, see
+# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
+node_modules
+
+# Users Environment Variables
+.lock-wscript
diff --git a/node_modules/css-tokenize/.travis.yml b/node_modules/css-tokenize/.travis.yml
new file mode 100644
index 00000000..2083806b
--- /dev/null
+++ b/node_modules/css-tokenize/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - "0.11"
+ - "0.10" \ No newline at end of file
diff --git a/node_modules/css-tokenize/LICENSE b/node_modules/css-tokenize/LICENSE
new file mode 100644
index 00000000..18ed0820
--- /dev/null
+++ b/node_modules/css-tokenize/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Anand Thakker
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/node_modules/css-tokenize/README.md b/node_modules/css-tokenize/README.md
new file mode 100644
index 00000000..df92e822
--- /dev/null
+++ b/node_modules/css-tokenize/README.md
@@ -0,0 +1,100 @@
+css-tokenize
+============
+
+Coarsely tokenize a stream of CSS, largely modeled after
+[substack/html-tokenize](/substack/html-tokenize).
+
+```javascript
+var tokenize = require('css-tokenize'),
+through = require('through2');
+
+process.stdin
+.pipe(tokenize())
+.pipe(through.obj(function(token, enc, next) {
+ token[1] = token[1].toString(); // it's a buffer slice
+ console.log('TOKEN', token);
+ next();
+}))
+```
+
+Input:
+```css
+
+div {
+ background: red;
+}
+
+.cls {
+ color: green;
+}
+
+#id {
+ font-size: 10px;
+}
+
+/* comment */
+
+@media screen and (min-width: 1000px) {
+ a {
+ text-decoration: underline;
+ }
+}
+
+a:hover {
+ font-weight: bold;
+}
+
+section
+
+
+{
+ margin: 0;
+ /* comment wthin a rule */
+ padding: 5px;
+}
+
+
+body > * {
+
+}
+```
+
+Output:
+```
+TOKEN [ 'root', '\n' ]
+TOKEN [ 'rule_start', 'div {' ]
+TOKEN [ 'rule', '\n background: red;\n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'root', '\n\n' ]
+TOKEN [ 'rule_start', '.cls {' ]
+TOKEN [ 'rule', '\n color: green;\n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'root', '\n\n' ]
+TOKEN [ 'rule_start', '#id {' ]
+TOKEN [ 'rule', '\n font-size: 10px;\n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'comment', '\n\n/* comment */' ]
+TOKEN [ 'space', '\n\n' ]
+TOKEN [ 'atrule_start', '@media screen and (min-width: 1000px) {' ]
+TOKEN [ 'atrule', '\n ' ]
+TOKEN [ 'rule_start', 'a {' ]
+TOKEN [ 'rule', '\n text-decoration: underline;\n ' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'atrule', '\n' ]
+TOKEN [ 'atrule_end', '}' ]
+TOKEN [ 'root', '\n\n' ]
+TOKEN [ 'rule_start', 'a:hover {' ]
+TOKEN [ 'rule', '\n font-weight: bold; \n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'root', '\n\n' ]
+TOKEN [ 'rule_start', 'section \n\n\n{' ]
+TOKEN [ 'rule', '\n margin: 0;\n ' ]
+TOKEN [ 'comment', '/* comment wthin a rule */' ]
+TOKEN [ 'rule', '\n padding: 5px;\n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'root', '\n\n\n' ]
+TOKEN [ 'rule_start', 'body > * {' ]
+TOKEN [ 'rule', '\n \n' ]
+TOKEN [ 'rule_end', '}' ]
+TOKEN [ 'root', '\n' ]
+```
diff --git a/node_modules/css-tokenize/example.js b/node_modules/css-tokenize/example.js
new file mode 100644
index 00000000..b0ff6534
--- /dev/null
+++ b/node_modules/css-tokenize/example.js
@@ -0,0 +1,13 @@
+
+var tokenize = require('./'),
+ through = require('through2'),
+ fs = require('fs');
+
+var input = process.argv[2] ? fs.createReadStream(process.argv[2]) : process.stdin;
+
+input.pipe(tokenize())
+ .pipe(through.obj(function(token, enc, next) {
+ token[1] = token[1].toString(); // it's a buffer slice
+ console.log('TOKEN', token);
+ next();
+ }))
diff --git a/node_modules/css-tokenize/index.js b/node_modules/css-tokenize/index.js
new file mode 100644
index 00000000..21d84470
--- /dev/null
+++ b/node_modules/css-tokenize/index.js
@@ -0,0 +1,172 @@
+
+/**
+ * The approach here owes a LOT to https://github.com/substack/html-tokenize.
+ */
+
+var Transform = require('readable-stream').Transform;
+var inherits = require('inherits');
+
+inherits(Tokenize, Transform);
+module.exports = Tokenize;
+
+var codes = {
+ fslash: '/'.charCodeAt(0),
+ bslash: '\\'.charCodeAt(0),
+ lparen: '('.charCodeAt(0),
+ rparen: ')'.charCodeAt(0),
+ lbrace: '{'.charCodeAt(0),
+ rbrace: '}'.charCodeAt(0),
+ lbrack: '['.charCodeAt(0),
+ rbrack: ']'.charCodeAt(0),
+ squote: '\''.charCodeAt(0),
+ dquote: '"'.charCodeAt(0),
+ at: '@'.charCodeAt(0),
+ semi: ';'.charCodeAt(0),
+ asterisk: '*'.charCodeAt(0)
+}
+
+var sequences = {
+ comment_start: '/*',
+ comment_end: '*/'
+}
+
+
+function charCodes(s) { return s.split('').map(function(c){return c.charCodeAt(0)}) }
+var sets = {
+ space: charCodes(' \t\n\r\f'),
+ open_brackets: [codes.lparen, codes.lbrace, codes.lbrack],
+ newline: charCodes('\n\r\f')
+}
+
+function Tokenize() {
+ if (!(this instanceof Tokenize)) return new Tokenize;
+ Transform.call(this);
+ this._readableState.objectMode = true;
+ this.state = [['root']];
+ this._input = null; // buffer the input for read-ahead
+ this._position = 0; // current position in this._input
+ this.buffers = []; // collect data for current token
+}
+
+
+Tokenize.prototype._transform = function(buf, enc, next) {
+ var input = this._input = this._input ? Buffer.concat([ this._input, buf ]) : buf;
+
+ for(var i = this._position; i < input.length; i++) {
+ var c = input[i];
+ var state = this.state[this.state.length - 1][0],
+ stateData = this.state[this.state.length - 1][1],
+ end = null;
+
+ // console.log(i, c, this.state);
+
+ /* comments */
+ if(i === input.length - 1
+ && (('comment' === state && c === codes.asterisk)
+ || c === codes.fslash)) {
+ // need more data: save unprocessed input and bail out.
+ this._input = this._input.slice(this._position);
+ break;
+ }
+ else if('comment' !== state
+ && c === codes.fslash && input[i+1] === codes.asterisk) {
+ if('root' !== state) end = [].concat(state);
+ i--; //backup to save the '/*' for the comment token.
+ this.state.push(['comment'])
+ }
+ else if('comment' === state
+ && c === codes.asterisk && input[i+1] === codes.fslash) {
+ i++;
+ end = this.state.pop();
+ }
+ /* strings */
+ else if('string' === state
+ && c === stateData) {
+ this.state.pop();
+ }
+ else if('string' !== state
+ && codes.squote === c || codes.dquote === c) {
+ this.state.push(['string', c]);
+ }
+ /* brackets */
+ // else if(codes.lparen === c) {
+ // this.state.push(['brackets', codes.rparen]);
+ // }
+ // else if(codes.lbrack === c) {
+ // this.state.push(['brackets', codes.rbrack]);
+ // }
+ // else if('brackets' === state
+ // && c === stateData) {
+ // this.state.pop();
+ // }
+ /* rules */
+ else if('rule_start' === state
+ && c === codes.lbrace) {
+ end = this.state.pop();
+ this.state.push(['rule']);
+ }
+ else if('atrule_start' === state
+ && c === codes.lbrace) {
+ end = this.state.pop();
+ this.state.push(['atrule']);
+ }
+ else if(('rule' === state || 'atrule' === state)
+ && c === codes.rbrace) {
+ end = this.state.pop();
+ i--; // backup to save the ending curly brace for the rule_end token.
+ this.state.push([ state + '_end' ]);
+ }
+ else if(('rule_end' === state || 'atrule_end' === state)
+ && c === codes.rbrace) {
+ end = this.state.pop();
+ }
+ else if('root' === state
+ && c === codes.at) {
+ end = ['space'];
+ i--;
+ this.state.push(['atrule_start'])
+ }
+ // rules can start from the root or nested within at-rules.
+ else if(sets.space.indexOf(c) < 0)
+ {
+ if('root' === state) {
+ end = ['root'];
+ i--;
+ this.state.push(['rule_start'])
+ }
+ else if('atrule' === state) {
+ end = ['atrule'];
+ i--;
+ this.state.push(['rule_start']);
+ }
+ }
+
+ if(end && i >= this._position) {
+ var out;
+ this.push(out = [end[0], input.slice(this._position, i+1)]);
+ this._position = i+1;
+ end = null;
+ }
+ }
+
+ if(this._position < this._input.length) {
+ this._input = this._input.slice(this._position);
+ this._position = 0;
+ }
+ else {
+ this._input = null;
+ this._position = 0;
+ }
+ next();
+}
+
+
+Tokenize.prototype._flush = function (next) {
+ if(this._input)
+ this.push([this.state.pop()[0], this._input.slice(this._position)]);
+ if(this.state.length !== 0) {
+ console.warn("[css-tokenize] unfinished business", this.state);
+ }
+ this.push(null);
+ next();
+};
diff --git a/node_modules/css-tokenize/package.json b/node_modules/css-tokenize/package.json
new file mode 100644
index 00000000..5d0bfa3b
--- /dev/null
+++ b/node_modules/css-tokenize/package.json
@@ -0,0 +1,34 @@
+{
+ "name": "css-tokenize",
+ "version": "1.0.1",
+ "description": "Transform stream that tokenizes CSS",
+ "main": "index.js",
+ "scripts": {
+ "test": "tape test/*.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/anandthakker/css-tokenize.git"
+ },
+ "keywords": [
+ "css",
+ "tokenize",
+ "parse",
+ "stream",
+ "streaming"
+ ],
+ "author": "Anand Thakker <vestibule@anandthakker.net> (http://anandthakker.net)",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/anandthakker/css-tokenize/issues"
+ },
+ "homepage": "https://github.com/anandthakker/css-tokenize",
+ "devDependencies": {
+ "tape": "^3.0.3",
+ "through2": "^0.6.3"
+ },
+ "dependencies": {
+ "inherits": "^2.0.1",
+ "readable-stream": "^1.0.33"
+ }
+}
diff --git a/node_modules/css-tokenize/test/base.js b/node_modules/css-tokenize/test/base.js
new file mode 100644
index 00000000..a42298b7
--- /dev/null
+++ b/node_modules/css-tokenize/test/base.js
@@ -0,0 +1,100 @@
+var fs = require('fs'),
+ test = require('tape'),
+ through = require('through2'),
+ tokenize = require('../')
+
+
+test('basic', function(t) {
+ var tok = tokenize();
+
+ var input = "html { font-size: 10px; }"
+ var expected = [
+ ['rule_start', 'html {'],
+ ['rule', ' font-size: 10px; '],
+ ['rule_end', '}']
+ ]
+
+ t.plan(expected.length);
+ tok.pipe(through.obj(function(token, enc, next) {
+ token[1] = token[1].toString();
+ if (expected.length > 0) t.same(token, expected.shift())
+ next();
+ }))
+
+ tok.end(input);
+})
+
+test('at-rule nesting', function(t) {
+ var tok = tokenize();
+ var expected = [
+ [ 'atrule_start', '@media screen and (min-width: 1000px) {' ],
+ [ 'atrule', '\n ' ],
+ [ 'rule_start', 'a {' ],
+ [ 'rule', '\n text-decoration: underline;\n ' ],
+ [ 'rule_end', '}' ],
+ [ 'atrule', '\n' ],
+ [ 'atrule_end', '}' ],
+ [ 'root', '\n' ]
+ ]
+
+ t.plan(expected.length);
+ tok.pipe(through.obj(function(token, enc, next) {
+ token[1] = token[1].toString();
+ if (expected.length > 0) t.same(token, expected.shift())
+ next();
+ }))
+
+ fs.createReadStream(__dirname + '/nested.css').pipe(tok);
+})
+
+test('gauntlet', function(t) {
+ var tok = tokenize();
+
+ var expected = [
+ ['root', '\n'],
+ ['rule_start', 'div {'],
+ ['rule', '\n background: red;\n'],
+ ['rule_end', '}'],
+ ['root', '\n\n'],
+ ['rule_start', '.cls {'],
+ ['rule', '\n color: green;\n'],
+ ['rule_end', '}'],
+ ['root', '\n\n'],
+ ['rule_start', '#id {'],
+ ['rule', '\n font-size: 10px;\n'],
+ ['rule_end', '}'],
+ ['comment', '\n\n/* comment */'],
+ ['space', '\n\n'],
+ ['atrule_start', '@media screen and (min-width: 1000px) {'],
+ ['atrule', '\n '],
+ ['rule_start', 'a {'],
+ ['rule', '\n text-decoration: underline;\n '],
+ ['rule_end', '}'],
+ ['atrule', '\n'],
+ ['atrule_end', '}'],
+ ['root', '\n\n'],
+ ['rule_start', 'a:hover {'],
+ ['rule', '\n font-weight: bold; \n'],
+ ['rule_end', '}'],
+ ['root', '\n\n'],
+ ['rule_start', 'section \n\n\n{'],
+ ['rule', '\n margin: 0;\n '],
+ ['comment', '/* comment wthin a rule */'],
+ ['rule', '\n padding: 5px;\n'],
+ ['rule_end', '}'],
+ ['root', '\n\n\n'],
+ ['rule_start', 'body > * {'],
+ ['rule', '\n \n'],
+ ['rule_end', '}'],
+ ['root', '\n']
+ ]
+
+ t.plan(expected.length);
+ tok.pipe(through.obj(function(token, enc, next) {
+ token[1] = token[1].toString();
+ if (expected.length > 0) t.same(token, expected.shift())
+ next();
+ }));
+
+ fs.createReadStream(__dirname + '/gauntlet.css').pipe(tok);
+})
diff --git a/node_modules/css-tokenize/test/brackets.css b/node_modules/css-tokenize/test/brackets.css
new file mode 100644
index 00000000..559ca209
--- /dev/null
+++ b/node_modules/css-tokenize/test/brackets.css
@@ -0,0 +1,7 @@
+
+.hello {
+ background: url(http://blahlbahlbah.com);
+}
+
+
+.explore-mail-tease{padding-top:20px;overflow:hidden;background:#202021 url(/assets/modules/home/octicons-bg-f51579234572c7286b1ead7a6408f2d43c7a0520dbb09f9d2b8b6b59024a01a0.png) center repeat;border-bottom:1px solid #ddd}.explore-mail-tease h3{color:#fff;text-align:center}.explore-mail-tease img{margin-bottom:-5px}
diff --git a/node_modules/css-tokenize/test/gauntlet.css b/node_modules/css-tokenize/test/gauntlet.css
new file mode 100644
index 00000000..833c8c9c
--- /dev/null
+++ b/node_modules/css-tokenize/test/gauntlet.css
@@ -0,0 +1,38 @@
+
+div {
+ background: red;
+}
+
+.cls {
+ color: green;
+}
+
+#id {
+ font-size: 10px;
+}
+
+/* comment */
+
+@media screen and (min-width: 1000px) {
+ a {
+ text-decoration: underline;
+ }
+}
+
+a:hover {
+ font-weight: bold;
+}
+
+section
+
+
+{
+ margin: 0;
+ /* comment wthin a rule */
+ padding: 5px;
+}
+
+
+body > * {
+
+}
diff --git a/node_modules/css-tokenize/test/nested.css b/node_modules/css-tokenize/test/nested.css
new file mode 100644
index 00000000..8922e61a
--- /dev/null
+++ b/node_modules/css-tokenize/test/nested.css
@@ -0,0 +1,5 @@
+@media screen and (min-width: 1000px) {
+ a {
+ text-decoration: underline;
+ }
+}