inline-style-parser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -17
- package/dist/inline-style-parser.js +274 -0
- package/dist/inline-style-parser.js.map +1 -0
- package/dist/inline-style-parser.min.js +2 -0
- package/dist/inline-style-parser.min.js.map +1 -0
- package/index.js +2 -2
- package/package.json +21 -22
- package/CHANGELOG.md +0 -47
package/README.md
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://nodei.co/npm/inline-style-parser/)
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/inline-style-parser)
|
|
6
|
+
[](https://bundlephobia.com/package/inline-style-parser)
|
|
7
|
+
[](https://github.com/remarkablemark/inline-style-parser/actions/workflows/build.yml)
|
|
8
|
+
[](https://codecov.io/gh/remarkablemark/inline-style-parser)
|
|
9
|
+
[](https://www.npmjs.com/package/inline-style-parser)
|
|
8
10
|
|
|
9
11
|
An inline style parser copied from [`css/lib/parse/index.js`](https://github.com/reworkcss/css/blob/v2.2.4/lib/parse/index.js):
|
|
10
12
|
|
|
@@ -28,18 +30,22 @@ Output:
|
|
|
28
30
|
position: Position { start: [Object], end: [Object], source: undefined } } ]
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
[JSFiddle](https://jsfiddle.net/remarkablemark/hcxbpwq8/) | [Replit](https://replit.com/@remarkablemark/inline-style-parser)
|
|
34
|
+
|
|
35
|
+
See [usage](#usage) and [examples](https://github.com/remarkablemark/inline-style-parser/tree/master/examples).
|
|
36
|
+
|
|
31
37
|
## Installation
|
|
32
38
|
|
|
33
39
|
[NPM](https://www.npmjs.com/package/inline-style-parser):
|
|
34
40
|
|
|
35
41
|
```sh
|
|
36
|
-
|
|
42
|
+
npm install inline-style-parser --save
|
|
37
43
|
```
|
|
38
44
|
|
|
39
45
|
[Yarn](https://yarnpkg.com/package/inline-style-parser):
|
|
40
46
|
|
|
41
47
|
```sh
|
|
42
|
-
|
|
48
|
+
yarn add inline-style-parser
|
|
43
49
|
```
|
|
44
50
|
|
|
45
51
|
[CDN](https://unpkg.com/inline-style-parser/):
|
|
@@ -180,47 +186,42 @@ parse('/*'); // throws Error
|
|
|
180
186
|
Run tests:
|
|
181
187
|
|
|
182
188
|
```sh
|
|
183
|
-
|
|
189
|
+
npm test
|
|
184
190
|
```
|
|
185
191
|
|
|
186
192
|
Run tests in watch mode:
|
|
187
193
|
|
|
188
194
|
```sh
|
|
189
|
-
|
|
195
|
+
npm run test:watch
|
|
190
196
|
```
|
|
191
197
|
|
|
192
198
|
Run tests with coverage:
|
|
193
199
|
|
|
194
200
|
```sh
|
|
195
|
-
|
|
201
|
+
npm run test:coverage
|
|
196
202
|
```
|
|
197
203
|
|
|
198
204
|
Run tests in CI mode:
|
|
199
205
|
|
|
200
206
|
```sh
|
|
201
|
-
|
|
207
|
+
npm run test:ci
|
|
202
208
|
```
|
|
203
209
|
|
|
204
210
|
Lint files:
|
|
205
211
|
|
|
206
212
|
```sh
|
|
207
|
-
|
|
213
|
+
npm run lint
|
|
208
214
|
```
|
|
209
215
|
|
|
210
216
|
Fix lint errors:
|
|
211
217
|
|
|
212
218
|
```sh
|
|
213
|
-
|
|
219
|
+
npm run lint:fix
|
|
214
220
|
```
|
|
215
221
|
|
|
216
222
|
## Release
|
|
217
223
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
```sh
|
|
221
|
-
$ npm run release
|
|
222
|
-
$ git push --follow-tags && npm publish
|
|
223
|
-
```
|
|
224
|
+
Release and publish are automated by [Release Please](https://github.com/googleapis/release-please).
|
|
224
225
|
|
|
225
226
|
## License
|
|
226
227
|
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.InlineStyleParser = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// http://www.w3.org/TR/CSS21/grammar.html
|
|
12
|
+
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
13
|
+
var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
14
|
+
|
|
15
|
+
var NEWLINE_REGEX = /\n/g;
|
|
16
|
+
var WHITESPACE_REGEX = /^\s*/;
|
|
17
|
+
|
|
18
|
+
// declaration
|
|
19
|
+
var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
|
|
20
|
+
var COLON_REGEX = /^:\s*/;
|
|
21
|
+
var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
|
|
22
|
+
var SEMICOLON_REGEX = /^[;\s]*/;
|
|
23
|
+
|
|
24
|
+
// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
|
25
|
+
var TRIM_REGEX = /^\s+|\s+$/g;
|
|
26
|
+
|
|
27
|
+
// strings
|
|
28
|
+
var NEWLINE = '\n';
|
|
29
|
+
var FORWARD_SLASH = '/';
|
|
30
|
+
var ASTERISK = '*';
|
|
31
|
+
var EMPTY_STRING = '';
|
|
32
|
+
|
|
33
|
+
// types
|
|
34
|
+
var TYPE_COMMENT = 'comment';
|
|
35
|
+
var TYPE_DECLARATION = 'declaration';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {String} style
|
|
39
|
+
* @param {Object} [options]
|
|
40
|
+
* @return {Object[]}
|
|
41
|
+
* @throws {TypeError}
|
|
42
|
+
* @throws {Error}
|
|
43
|
+
*/
|
|
44
|
+
var inlineStyleParser = function (style, options) {
|
|
45
|
+
if (typeof style !== 'string') {
|
|
46
|
+
throw new TypeError('First argument must be a string');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!style) return [];
|
|
50
|
+
|
|
51
|
+
options = options || {};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Positional.
|
|
55
|
+
*/
|
|
56
|
+
var lineno = 1;
|
|
57
|
+
var column = 1;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Update lineno and column based on `str`.
|
|
61
|
+
*
|
|
62
|
+
* @param {String} str
|
|
63
|
+
*/
|
|
64
|
+
function updatePosition(str) {
|
|
65
|
+
var lines = str.match(NEWLINE_REGEX);
|
|
66
|
+
if (lines) lineno += lines.length;
|
|
67
|
+
var i = str.lastIndexOf(NEWLINE);
|
|
68
|
+
column = ~i ? str.length - i : column + str.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Mark position and patch `node.position`.
|
|
73
|
+
*
|
|
74
|
+
* @return {Function}
|
|
75
|
+
*/
|
|
76
|
+
function position() {
|
|
77
|
+
var start = { line: lineno, column: column };
|
|
78
|
+
return function (node) {
|
|
79
|
+
node.position = new Position(start);
|
|
80
|
+
whitespace();
|
|
81
|
+
return node;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Store position information for a node.
|
|
87
|
+
*
|
|
88
|
+
* @constructor
|
|
89
|
+
* @property {Object} start
|
|
90
|
+
* @property {Object} end
|
|
91
|
+
* @property {undefined|String} source
|
|
92
|
+
*/
|
|
93
|
+
function Position(start) {
|
|
94
|
+
this.start = start;
|
|
95
|
+
this.end = { line: lineno, column: column };
|
|
96
|
+
this.source = options.source;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Non-enumerable source string.
|
|
101
|
+
*/
|
|
102
|
+
Position.prototype.content = style;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Error `msg`.
|
|
106
|
+
*
|
|
107
|
+
* @param {String} msg
|
|
108
|
+
* @throws {Error}
|
|
109
|
+
*/
|
|
110
|
+
function error(msg) {
|
|
111
|
+
var err = new Error(
|
|
112
|
+
options.source + ':' + lineno + ':' + column + ': ' + msg
|
|
113
|
+
);
|
|
114
|
+
err.reason = msg;
|
|
115
|
+
err.filename = options.source;
|
|
116
|
+
err.line = lineno;
|
|
117
|
+
err.column = column;
|
|
118
|
+
err.source = style;
|
|
119
|
+
|
|
120
|
+
if (options.silent) ; else {
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Match `re` and return captures.
|
|
127
|
+
*
|
|
128
|
+
* @param {RegExp} re
|
|
129
|
+
* @return {undefined|Array}
|
|
130
|
+
*/
|
|
131
|
+
function match(re) {
|
|
132
|
+
var m = re.exec(style);
|
|
133
|
+
if (!m) return;
|
|
134
|
+
var str = m[0];
|
|
135
|
+
updatePosition(str);
|
|
136
|
+
style = style.slice(str.length);
|
|
137
|
+
return m;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Parse whitespace.
|
|
142
|
+
*/
|
|
143
|
+
function whitespace() {
|
|
144
|
+
match(WHITESPACE_REGEX);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Parse comments.
|
|
149
|
+
*
|
|
150
|
+
* @param {Object[]} [rules]
|
|
151
|
+
* @return {Object[]}
|
|
152
|
+
*/
|
|
153
|
+
function comments(rules) {
|
|
154
|
+
var c;
|
|
155
|
+
rules = rules || [];
|
|
156
|
+
while ((c = comment())) {
|
|
157
|
+
if (c !== false) {
|
|
158
|
+
rules.push(c);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return rules;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Parse comment.
|
|
166
|
+
*
|
|
167
|
+
* @return {Object}
|
|
168
|
+
* @throws {Error}
|
|
169
|
+
*/
|
|
170
|
+
function comment() {
|
|
171
|
+
var pos = position();
|
|
172
|
+
if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
|
|
173
|
+
|
|
174
|
+
var i = 2;
|
|
175
|
+
while (
|
|
176
|
+
EMPTY_STRING != style.charAt(i) &&
|
|
177
|
+
(ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
|
|
178
|
+
) {
|
|
179
|
+
++i;
|
|
180
|
+
}
|
|
181
|
+
i += 2;
|
|
182
|
+
|
|
183
|
+
if (EMPTY_STRING === style.charAt(i - 1)) {
|
|
184
|
+
return error('End of comment missing');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var str = style.slice(2, i - 2);
|
|
188
|
+
column += 2;
|
|
189
|
+
updatePosition(str);
|
|
190
|
+
style = style.slice(i);
|
|
191
|
+
column += 2;
|
|
192
|
+
|
|
193
|
+
return pos({
|
|
194
|
+
type: TYPE_COMMENT,
|
|
195
|
+
comment: str
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Parse declaration.
|
|
201
|
+
*
|
|
202
|
+
* @return {Object}
|
|
203
|
+
* @throws {Error}
|
|
204
|
+
*/
|
|
205
|
+
function declaration() {
|
|
206
|
+
var pos = position();
|
|
207
|
+
|
|
208
|
+
// prop
|
|
209
|
+
var prop = match(PROPERTY_REGEX);
|
|
210
|
+
if (!prop) return;
|
|
211
|
+
comment();
|
|
212
|
+
|
|
213
|
+
// :
|
|
214
|
+
if (!match(COLON_REGEX)) return error("property missing ':'");
|
|
215
|
+
|
|
216
|
+
// val
|
|
217
|
+
var val = match(VALUE_REGEX);
|
|
218
|
+
|
|
219
|
+
var ret = pos({
|
|
220
|
+
type: TYPE_DECLARATION,
|
|
221
|
+
property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
|
|
222
|
+
value: val
|
|
223
|
+
? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
|
|
224
|
+
: EMPTY_STRING
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ;
|
|
228
|
+
match(SEMICOLON_REGEX);
|
|
229
|
+
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Parse declarations.
|
|
235
|
+
*
|
|
236
|
+
* @return {Object[]}
|
|
237
|
+
*/
|
|
238
|
+
function declarations() {
|
|
239
|
+
var decls = [];
|
|
240
|
+
|
|
241
|
+
comments(decls);
|
|
242
|
+
|
|
243
|
+
// declarations
|
|
244
|
+
var decl;
|
|
245
|
+
while ((decl = declaration())) {
|
|
246
|
+
if (decl !== false) {
|
|
247
|
+
decls.push(decl);
|
|
248
|
+
comments(decls);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return decls;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
whitespace();
|
|
256
|
+
return declarations();
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Trim `str`.
|
|
261
|
+
*
|
|
262
|
+
* @param {String} str
|
|
263
|
+
* @return {String}
|
|
264
|
+
*/
|
|
265
|
+
function trim(str) {
|
|
266
|
+
return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(inlineStyleParser);
|
|
270
|
+
|
|
271
|
+
return index;
|
|
272
|
+
|
|
273
|
+
}));
|
|
274
|
+
//# sourceMappingURL=inline-style-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-style-parser.js","sources":["../index.js"],"sourcesContent":["// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nmodule.exports = function (style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function (node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n var errorsList = [];\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) {\n errorsList.push(err);\n } else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n *\n * @return {Object}\n * @throws {Error}\n */\n function comment() {\n var pos = position();\n if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;\n\n var i = 2;\n while (\n EMPTY_STRING != style.charAt(i) &&\n (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))\n ) {\n ++i;\n }\n i += 2;\n\n if (EMPTY_STRING === style.charAt(i - 1)) {\n return error('End of comment missing');\n }\n\n var str = style.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n style = style.slice(i);\n column += 2;\n\n return pos({\n type: TYPE_COMMENT,\n comment: str\n });\n }\n\n /**\n * Parse declaration.\n *\n * @return {Object}\n * @throws {Error}\n */\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(PROPERTY_REGEX);\n if (!prop) return;\n comment();\n\n // :\n if (!match(COLON_REGEX)) return error(\"property missing ':'\");\n\n // val\n var val = match(VALUE_REGEX);\n\n var ret = pos({\n type: TYPE_DECLARATION,\n property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),\n value: val\n ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))\n : EMPTY_STRING\n });\n\n // ;\n match(SEMICOLON_REGEX);\n\n return ret;\n }\n\n /**\n * Parse declarations.\n *\n * @return {Object[]}\n */\n function declarations() {\n var decls = [];\n\n comments(decls);\n\n // declarations\n var decl;\n while ((decl = declaration())) {\n if (decl !== false) {\n decls.push(decl);\n comments(decls);\n }\n }\n\n return decls;\n }\n\n whitespace();\n return declarations();\n};\n\n/**\n * Trim `str`.\n *\n * @param {String} str\n * @return {String}\n */\nfunction trim(str) {\n return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;\n}\n"],"names":[],"mappings":";;;;;;;;;;CAAA;CACA;CACA,IAAI,aAAa,GAAG,iCAAiC,CAAC;AACtD;CACA,IAAI,aAAa,GAAG,KAAK,CAAC;CAC1B,IAAI,gBAAgB,GAAG,MAAM,CAAC;AAC9B;CACA;CACA,IAAI,cAAc,GAAG,wCAAwC,CAAC;CAC9D,IAAI,WAAW,GAAG,OAAO,CAAC;CAC1B,IAAI,WAAW,GAAG,sDAAsD,CAAC;CACzE,IAAI,eAAe,GAAG,SAAS,CAAC;AAChC;CACA;CACA,IAAI,UAAU,GAAG,YAAY,CAAC;AAC9B;CACA;CACA,IAAI,OAAO,GAAG,IAAI,CAAC;CACnB,IAAI,aAAa,GAAG,GAAG,CAAC;CACxB,IAAI,QAAQ,GAAG,GAAG,CAAC;CACnB,IAAI,YAAY,GAAG,EAAE,CAAC;AACtB;CACA;CACA,IAAI,YAAY,GAAG,SAAS,CAAC;CAC7B,IAAI,gBAAgB,GAAG,aAAa,CAAC;AACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,IAAA,iBAAc,GAAG,UAAU,KAAK,EAAE,OAAO,EAAE;CAC3C,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;CACjC,IAAI,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;CAC3D,GAA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Y,GAAG;CAC1B,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;AACnB;CACA,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpB;CACA;CACA,IAAI,IAAI,IAAI,CAAC;CACb,IAAI,QAAQ,IAAI,GAAG,WAAW,EAAE,GAAG;CACnC,MAAM,IAAI,IAAI,KAAK,KAAK,EAAE;CAC1B,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CACzB,QAAQ,QAAQ,CAAC,KAAK,CAAC,CAAC;CACxB,OAAO;CACP,KAAK;AACL;CACA,IAAI,OAAO,KAAK,CAAC;CACjB,GAAG;AACH;CACA,EAAE,UAAU,EAAE,CAAC;CACf,EAAE,OAAO,YAAY,EAAE,CAAC;CACxB,CAAC,CAAC;AACF;CACA;CACA;CACA;CACA;CACA;CACA;CACA,SAAS,IAAI,CAAC,GAAG,EAAE;CACnB,EAAE,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,YAAY,CAAC;CACpE,CAAA;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).InlineStyleParser=n()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,t=/^\s*/,o=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,u=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,f=/^\s+|\s+$/g,a="";function s(e){return e?e.replace(f,a):a}return e((function(e,f){if("string"!=typeof e)throw new TypeError("First argument must be a string");if(!e)return[];f=f||{};var l=1,p=1;function h(e){var n=e.match(r);n&&(l+=n.length);var t=e.lastIndexOf("\n");p=~t?e.length-t:p+e.length}function m(){var e={line:l,column:p};return function(n){return n.position=new d(e),y(),n}}function d(e){this.start=e,this.end={line:l,column:p},this.source=f.source}function v(n){var r=new Error(f.source+":"+l+":"+p+": "+n);if(r.reason=n,r.filename=f.source,r.line=l,r.column=p,r.source=e,!f.silent)throw r}function g(n){var r=n.exec(e);if(r){var t=r[0];return h(t),e=e.slice(t.length),r}}function y(){g(t)}function w(e){var n;for(e=e||[];n=A();)!1!==n&&e.push(n);return e}function A(){var n=m();if("/"==e.charAt(0)&&"*"==e.charAt(1)){for(var r=2;a!=e.charAt(r)&&("*"!=e.charAt(r)||"/"!=e.charAt(r+1));)++r;if(r+=2,a===e.charAt(r-1))return v("End of comment missing");var t=e.slice(2,r-2);return p+=2,h(t),e=e.slice(r),p+=2,n({type:"comment",comment:t})}}function b(){var e=m(),r=g(o);if(r){if(A(),!g(i))return v("property missing ':'");var t=g(u),f=e({type:"declaration",property:s(r[0].replace(n,a)),value:t?s(t[0].replace(n,a)):a});return g(c),f}}return d.prototype.content=e,y(),function(){var e,n=[];for(w(n);e=b();)!1!==e&&(n.push(e),w(n));return n}()}))}));
|
|
2
|
+
//# sourceMappingURL=inline-style-parser.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-style-parser.min.js","sources":["../index.js"],"sourcesContent":["// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nmodule.exports = function (style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function (node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n var errorsList = [];\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) {\n errorsList.push(err);\n } else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n *\n * @return {Object}\n * @throws {Error}\n */\n function comment() {\n var pos = position();\n if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;\n\n var i = 2;\n while (\n EMPTY_STRING != style.charAt(i) &&\n (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))\n ) {\n ++i;\n }\n i += 2;\n\n if (EMPTY_STRING === style.charAt(i - 1)) {\n return error('End of comment missing');\n }\n\n var str = style.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n style = style.slice(i);\n column += 2;\n\n return pos({\n type: TYPE_COMMENT,\n comment: str\n });\n }\n\n /**\n * Parse declaration.\n *\n * @return {Object}\n * @throws {Error}\n */\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(PROPERTY_REGEX);\n if (!prop) return;\n comment();\n\n // :\n if (!match(COLON_REGEX)) return error(\"property missing ':'\");\n\n // val\n var val = match(VALUE_REGEX);\n\n var ret = pos({\n type: TYPE_DECLARATION,\n property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),\n value: val\n ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))\n : EMPTY_STRING\n });\n\n // ;\n match(SEMICOLON_REGEX);\n\n return ret;\n }\n\n /**\n * Parse declarations.\n *\n * @return {Object[]}\n */\n function declarations() {\n var decls = [];\n\n comments(decls);\n\n // declarations\n var decl;\n while ((decl = declaration())) {\n if (decl !== false) {\n decls.push(decl);\n comments(decls);\n }\n }\n\n return decls;\n }\n\n whitespace();\n return declarations();\n};\n\n/**\n * Trim `str`.\n *\n * @param {String} str\n * @return {String}\n */\nfunction trim(str) {\n return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;\n}\n"],"names":["COMMENT_REGEX","NEWLINE_REGEX","WHITESPACE_REGEX","PROPERTY_REGEX","COLON_REGEX","VALUE_REGEX","SEMICOLON_REGEX","TRIM_REGEX","EMPTY_STRING","trim","str","replace","style","options","TypeError","lineno","column","updatePosition","lines","match","length","i","lastIndexOf","position","start","line","node","Position","whitespace","this","end","source","error","msg","err","Error","reason","filename","silent","re","m","exec","slice","comments","rules","c","comment","push","pos","charAt","type","declaration","prop","val","ret","property","value","prototype","content","decl","decls","declarations"],"mappings":"sVAEA,IAAIA,EAAgB,kCAEhBC,EAAgB,MAChBC,EAAmB,OAGnBC,EAAiB,yCACjBC,EAAc,QACdC,EAAc,uDACdC,EAAkB,UAGlBC,EAAa,aAMbC,EAAe,GA8OnB,SAASC,EAAKC,GACZ,OAAOA,EAAMA,EAAIC,QAAQJ,EAAYC,GAAgBA,CACvD,WAnOiB,SAAUI,EAAOC,GAChC,GAAqB,iBAAVD,EACT,MAAM,IAAIE,UAAU,mCAGtB,IAAKF,EAAO,MAAO,GAEnBC,EAAUA,GAAW,GAKrB,IAAIE,EAAS,EACTC,EAAS,EAOb,SAASC,EAAeP,GACtB,IAAIQ,EAAQR,EAAIS,MAAMlB,GAClBiB,IAAOH,GAAUG,EAAME,QAC3B,IAAIC,EAAIX,EAAIY,YAvCF,MAwCVN,GAAUK,EAAIX,EAAIU,OAASC,EAAIL,EAASN,EAAIU,MAC7C,CAOD,SAASG,IACP,IAAIC,EAAQ,CAAEC,KAAMV,EAAQC,OAAQA,GACpC,OAAO,SAAUU,GAGf,OAFAA,EAAKH,SAAW,IAAII,EAASH,GAC7BI,IACOF,CACb,CACG,CAUD,SAASC,EAASH,GAChBK,KAAKL,MAAQA,EACbK,KAAKC,IAAM,CAAEL,KAAMV,EAAQC,OAA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A,GAHAN,KAGK3B,EAAMf,GAAc,OAAO4B,EAAM,wBAGtC,IAAIqB,EAAMlC,EAAMd,GAEZiD,EAAMN,EAAI,CACZE,KA7LiB,cA8LjBK,SAAU9C,EAAK2C,EAAK,GAAGzC,QAAQX,EAAeQ,IAC9CgD,MAAOH,EACH5C,EAAK4C,EAAI,GAAG1C,QAAQX,EAAeQ,IACnCA,IAMN,OAFAW,EAAMb,GAECgD,CApBW,CAqBnB,CAyBD,OA9JA3B,EAAS8B,UAAUC,QAAU9C,EA6J7BgB,IAjBA,WACE,IAKI+B,EALAC,EAAQ,GAMZ,IAJAjB,EAASiB,GAIDD,EAAOR,MACA,IAATQ,IACFC,EAAMb,KAAKY,GACXhB,EAASiB,IAIb,OAAOA,CACR,CAGMC,EACT"}
|
package/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var TYPE_DECLARATION = 'declaration';
|
|
|
31
31
|
* @throws {TypeError}
|
|
32
32
|
* @throws {Error}
|
|
33
33
|
*/
|
|
34
|
-
module.exports = function(style, options) {
|
|
34
|
+
module.exports = function (style, options) {
|
|
35
35
|
if (typeof style !== 'string') {
|
|
36
36
|
throw new TypeError('First argument must be a string');
|
|
37
37
|
}
|
|
@@ -65,7 +65,7 @@ module.exports = function(style, options) {
|
|
|
65
65
|
*/
|
|
66
66
|
function position() {
|
|
67
67
|
var start = { line: lineno, column: column };
|
|
68
|
-
return function(node) {
|
|
68
|
+
return function (node) {
|
|
69
69
|
node.position = new Position(start);
|
|
70
70
|
whitespace();
|
|
71
71
|
return node;
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inline-style-parser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "An inline style parser.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"build:min": "NODE_ENV=production rollup --config --output.file dist/inline-style-parser.min.js --sourcemap",
|
|
9
|
-
"build:unmin": "NODE_ENV=development rollup --config --file dist/inline-style-parser.js",
|
|
7
|
+
"build": "rollup --config --failAfterWarnings",
|
|
10
8
|
"clean": "rm -rf dist",
|
|
11
9
|
"coveralls": "cat coverage/lcov.info | coveralls",
|
|
12
10
|
"lint": "eslint --ignore-path .gitignore .",
|
|
13
11
|
"lint:fix": "npm run lint -- --fix",
|
|
14
|
-
"prepublishOnly": "npm run build",
|
|
15
|
-
"release": "standard-version --no-verify",
|
|
12
|
+
"prepublishOnly": "pinst --disable && npm run lint && npm test && npm run build",
|
|
16
13
|
"test": "jest",
|
|
17
14
|
"test:ci": "npm run test:coverage -- --ci",
|
|
18
15
|
"test:coverage": "jest --coverage --collectCoverageFrom=index.js",
|
|
19
|
-
"test:watch": "jest --watch"
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"_postinstall": "husky install",
|
|
18
|
+
"postpublish": "pinst --enable"
|
|
20
19
|
},
|
|
21
20
|
"repository": {
|
|
22
21
|
"type": "git",
|
|
@@ -33,23 +32,23 @@
|
|
|
33
32
|
"css"
|
|
34
33
|
],
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@commitlint/cli": "
|
|
37
|
-
"@commitlint/config-conventional": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
35
|
+
"@commitlint/cli": "17.8.0",
|
|
36
|
+
"@commitlint/config-conventional": "17.8.0",
|
|
37
|
+
"@rollup/plugin-commonjs": "25.0.5",
|
|
38
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
39
|
+
"coveralls": "3.1.1",
|
|
40
|
+
"css": "3.0.0",
|
|
41
|
+
"eslint": "8.51.0",
|
|
42
|
+
"eslint-plugin-prettier": "5.0.1",
|
|
43
|
+
"husky": "8.0.3",
|
|
44
|
+
"jest": "29.7.0",
|
|
45
|
+
"lint-staged": "14.0.0",
|
|
46
|
+
"pinst": "3.0.0",
|
|
47
|
+
"prettier": "3.0.3",
|
|
48
|
+
"rollup": "4.1.0"
|
|
50
49
|
},
|
|
51
50
|
"files": [
|
|
52
|
-
"
|
|
51
|
+
"/dist"
|
|
53
52
|
],
|
|
54
53
|
"license": "MIT"
|
|
55
54
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
## 0.1.0 (2019-06-19)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* **index:** do not throw an error if a comment precedes the colon ([7f962ee](https://github.com/remarkablemark/inline-style-parser/commit/7f962ee))
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Build System
|
|
14
|
-
|
|
15
|
-
* **package:** add `build` and `clean` scripts ([d27a653](https://github.com/remarkablemark/inline-style-parser/commit/d27a653))
|
|
16
|
-
* **package:** add script `prepublishOnly` and "files" field ([5fad9ff](https://github.com/remarkablemark/inline-style-parser/commit/5fad9ff))
|
|
17
|
-
* **package:** save `css@2.2.4` to devDependencies ([93ad729](https://github.com/remarkablemark/inline-style-parser/commit/93ad729))
|
|
18
|
-
* **package:** save devDependencies for `rollup` and its plugins ([872b1fa](https://github.com/remarkablemark/inline-style-parser/commit/872b1fa))
|
|
19
|
-
* **package:** set `NODE_ENV=development` in script `build:unmin` ([5a7877b](https://github.com/remarkablemark/inline-style-parser/commit/5a7877b))
|
|
20
|
-
* **package:** update `build:min` to generate sourcemap (external) ([c81d66a](https://github.com/remarkablemark/inline-style-parser/commit/c81d66a))
|
|
21
|
-
* **rollup:** add `rollup.config.js` ([ac60124](https://github.com/remarkablemark/inline-style-parser/commit/ac60124))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Features
|
|
25
|
-
|
|
26
|
-
* clone project from `npm-package-template` ([5976c6f](https://github.com/remarkablemark/inline-style-parser/commit/5976c6f))
|
|
27
|
-
* **index:** copy `parse` module from `css` package ([3bf4bee](https://github.com/remarkablemark/inline-style-parser/commit/3bf4bee))
|
|
28
|
-
* **index:** parse only declarations and remove all unused code ([a04d918](https://github.com/remarkablemark/inline-style-parser/commit/a04d918))
|
|
29
|
-
* **index:** throw error if first argument is not a string ([346ae28](https://github.com/remarkablemark/inline-style-parser/commit/346ae28))
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Tests
|
|
33
|
-
|
|
34
|
-
* add snapshot for the parsed output of a single declaration ([c2c774c](https://github.com/remarkablemark/inline-style-parser/commit/c2c774c))
|
|
35
|
-
* **data:** add more cases for 'content' and 'background-image' ([204c574](https://github.com/remarkablemark/inline-style-parser/commit/204c574))
|
|
36
|
-
* **index:** add more misc and one-off test cases ([a08f521](https://github.com/remarkablemark/inline-style-parser/commit/a08f521))
|
|
37
|
-
* **index:** check that a comment before colon is parsed correctly ([bf9518c](https://github.com/remarkablemark/inline-style-parser/commit/bf9518c))
|
|
38
|
-
* **index:** check that the error message matches ([9169525](https://github.com/remarkablemark/inline-style-parser/commit/9169525))
|
|
39
|
-
* add snapshots for the parsed output of multiple declarations ([8708031](https://github.com/remarkablemark/inline-style-parser/commit/8708031))
|
|
40
|
-
* **index:** disable placeholder test suite ([20bf8af](https://github.com/remarkablemark/inline-style-parser/commit/20bf8af))
|
|
41
|
-
* add cases and compare parser output with `css.parse` output ([361974b](https://github.com/remarkablemark/inline-style-parser/commit/361974b))
|
|
42
|
-
* **index:** refactor tests and use `expect` and `it.each` ([dbf2ef0](https://github.com/remarkablemark/inline-style-parser/commit/dbf2ef0))
|
|
43
|
-
* organize tests with describe blocks and tidy test names ([5c5fcd4](https://github.com/remarkablemark/inline-style-parser/commit/5c5fcd4))
|
|
44
|
-
* replace `mocha` and `nyc` with `jest` ([100311d](https://github.com/remarkablemark/inline-style-parser/commit/100311d))
|
|
45
|
-
* **index:** test "End of comment missing" error and silent option ([9f0c832](https://github.com/remarkablemark/inline-style-parser/commit/9f0c832))
|
|
46
|
-
* **index:** verify that expected errors are thrown ([d0ed3bd](https://github.com/remarkablemark/inline-style-parser/commit/d0ed3bd))
|
|
47
|
-
* **package:** collect coverage from `index.js` only ([bc503b7](https://github.com/remarkablemark/inline-style-parser/commit/bc503b7))
|