@najemi-software/vitest-dom 0.33.1-alpha.41.1 → 0.34.0-alpha.42.1
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/CHANGELOG.md +7 -0
- package/esm/css-parse/at-rule-nodes.d.ts +54 -0
- package/esm/css-parse/at-rule-nodes.js +2 -0
- package/esm/css-parse/at-rule-nodes.js.map +1 -0
- package/esm/css-parse/comments.d.ts +10 -0
- package/esm/css-parse/comments.js +35 -0
- package/esm/css-parse/comments.js.map +1 -0
- package/esm/css-parse/css-parse.d.ts +3 -0
- package/esm/css-parse/css-parse.js +22 -0
- package/esm/css-parse/css-parse.js.map +1 -0
- package/esm/css-parse/declaration-block-at-rules.d.ts +10 -0
- package/esm/css-parse/declaration-block-at-rules.js +55 -0
- package/esm/css-parse/declaration-block-at-rules.js.map +1 -0
- package/esm/css-parse/declarations.d.ts +10 -0
- package/esm/css-parse/declarations.js +48 -0
- package/esm/css-parse/declarations.js.map +1 -0
- package/esm/css-parse/keyframes.d.ts +10 -0
- package/esm/css-parse/keyframes.js +53 -0
- package/esm/css-parse/keyframes.js.map +1 -0
- package/esm/css-parse/nested-rule-at-rules.d.ts +19 -0
- package/esm/css-parse/nested-rule-at-rules.js +85 -0
- package/esm/css-parse/nested-rule-at-rules.js.map +1 -0
- package/esm/css-parse/nodes.d.ts +34 -0
- package/esm/css-parse/nodes.js +2 -0
- package/esm/css-parse/nodes.js.map +1 -0
- package/esm/css-parse/options.d.ts +6 -0
- package/esm/css-parse/options.js +2 -0
- package/esm/css-parse/options.js.map +1 -0
- package/esm/css-parse/parent-references.d.ts +4 -0
- package/esm/css-parse/parent-references.js +29 -0
- package/esm/css-parse/parent-references.js.map +1 -0
- package/esm/css-parse/parse-error.d.ts +7 -0
- package/esm/css-parse/parse-error.js +2 -0
- package/esm/css-parse/parse-error.js.map +1 -0
- package/esm/css-parse/parser-context.d.ts +50 -0
- package/esm/css-parse/parser-context.js +88 -0
- package/esm/css-parse/parser-context.js.map +1 -0
- package/esm/css-parse/position.d.ts +24 -0
- package/esm/css-parse/position.js +18 -0
- package/esm/css-parse/position.js.map +1 -0
- package/esm/css-parse/rules.d.ts +6 -0
- package/esm/css-parse/rules.js +56 -0
- package/esm/css-parse/rules.js.map +1 -0
- package/esm/css-parse/selectors.d.ts +5 -0
- package/esm/css-parse/selectors.js +21 -0
- package/esm/css-parse/selectors.js.map +1 -0
- package/esm/css-parse/statement-at-rules.d.ts +18 -0
- package/esm/css-parse/statement-at-rules.js +44 -0
- package/esm/css-parse/statement-at-rules.js.map +1 -0
- package/esm/css-parse/trim.d.ts +4 -0
- package/esm/css-parse/trim.js +7 -0
- package/esm/css-parse/trim.js.map +1 -0
- package/esm/matchers/utils.js +1 -1
- package/esm/matchers/utils.js.map +1 -1
- package/package.json +1 -1
- package/esm/matchers/css-parse.d.ts +0 -112
- package/esm/matchers/css-parse.js +0 -508
- package/esm/matchers/css-parse.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.34.0] - 2026-09-27
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Split css-parse into smaller modules in src/css-parse/
|
|
13
|
+
|
|
8
14
|
## [0.33.1] - 2026-09-27
|
|
9
15
|
|
|
10
16
|
### Fixed
|
|
@@ -310,6 +316,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
310
316
|
|
|
311
317
|
- Initial release
|
|
312
318
|
|
|
319
|
+
[0.34.0]: https://github.com/Najemi-Software/vitest-dom/compare/v0.33.1...v0.34.0
|
|
313
320
|
[0.33.1]: https://github.com/Najemi-Software/vitest-dom/compare/v0.33.0...v0.33.1
|
|
314
321
|
[0.33.0]: https://github.com/Najemi-Software/vitest-dom/compare/v0.32.0...v0.33.0
|
|
315
322
|
[0.32.0]: https://github.com/Najemi-Software/vitest-dom/compare/v0.31.0...v0.32.0
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { IBaseNode, IComment, IDeclaration, StyleNode } from "./nodes.js";
|
|
2
|
+
export interface IKeyframe extends IBaseNode {
|
|
3
|
+
type: "keyframe";
|
|
4
|
+
values: string[];
|
|
5
|
+
declarations: Array<IDeclaration | IComment> | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface IKeyframes extends IBaseNode {
|
|
8
|
+
type: "keyframes";
|
|
9
|
+
name: string;
|
|
10
|
+
vendor: string | undefined;
|
|
11
|
+
keyframes: Array<IKeyframe | IComment>;
|
|
12
|
+
}
|
|
13
|
+
export interface ISupports extends IBaseNode {
|
|
14
|
+
type: "supports";
|
|
15
|
+
supports: string;
|
|
16
|
+
rules: StyleNode[];
|
|
17
|
+
}
|
|
18
|
+
export interface IHost extends IBaseNode {
|
|
19
|
+
type: "host";
|
|
20
|
+
rules: StyleNode[];
|
|
21
|
+
}
|
|
22
|
+
export interface IMedia extends IBaseNode {
|
|
23
|
+
type: "media";
|
|
24
|
+
media: string;
|
|
25
|
+
rules: StyleNode[];
|
|
26
|
+
}
|
|
27
|
+
export interface ICustomMedia extends IBaseNode {
|
|
28
|
+
type: "custom-media";
|
|
29
|
+
name: string;
|
|
30
|
+
media: string;
|
|
31
|
+
}
|
|
32
|
+
export interface IPage extends IBaseNode {
|
|
33
|
+
type: "page";
|
|
34
|
+
selectors: string[];
|
|
35
|
+
declarations: Array<IDeclaration | IComment>;
|
|
36
|
+
}
|
|
37
|
+
export interface IDocument extends IBaseNode {
|
|
38
|
+
type: "document";
|
|
39
|
+
document: string;
|
|
40
|
+
vendor: string;
|
|
41
|
+
rules: StyleNode[];
|
|
42
|
+
}
|
|
43
|
+
export interface IFontFace extends IBaseNode {
|
|
44
|
+
type: "font-face";
|
|
45
|
+
declarations: Array<IDeclaration | IComment>;
|
|
46
|
+
}
|
|
47
|
+
export type SimpleAtRuleName = "import" | "charset" | "namespace";
|
|
48
|
+
export interface ISimpleAtRule extends IBaseNode {
|
|
49
|
+
type: SimpleAtRuleName;
|
|
50
|
+
import?: string;
|
|
51
|
+
charset?: string;
|
|
52
|
+
namespace?: string;
|
|
53
|
+
}
|
|
54
|
+
export type AtRule = IKeyframes | IMedia | ICustomMedia | ISupports | ISimpleAtRule | IDocument | IPage | IHost | IFontFace;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"at-rule-nodes.js","sourceRoot":"","sources":["../../src/css-parse/at-rule-nodes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IComment } from "./nodes.js";
|
|
2
|
+
import type { ParserContext } from "./parser-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse comments;
|
|
5
|
+
*/
|
|
6
|
+
export declare function comments<T>(ctx: ParserContext, rules?: Array<T | IComment>): Array<T | IComment>;
|
|
7
|
+
/**
|
|
8
|
+
* Parse comment.
|
|
9
|
+
*/
|
|
10
|
+
export declare function comment(ctx: ParserContext): IComment | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse comments;
|
|
3
|
+
*/
|
|
4
|
+
export function comments(ctx, rules = []) {
|
|
5
|
+
let c;
|
|
6
|
+
while ((c = comment(ctx))) {
|
|
7
|
+
rules.push(c);
|
|
8
|
+
}
|
|
9
|
+
return rules;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse comment.
|
|
13
|
+
*/
|
|
14
|
+
export function comment(ctx) {
|
|
15
|
+
const pos = ctx.position();
|
|
16
|
+
if ("/" != ctx.css.charAt(0) || "*" != ctx.css.charAt(1))
|
|
17
|
+
return;
|
|
18
|
+
let i = 2;
|
|
19
|
+
while ("" != ctx.css.charAt(i) && ("*" != ctx.css.charAt(i) || "/" != ctx.css.charAt(i + 1)))
|
|
20
|
+
++i;
|
|
21
|
+
i += 2;
|
|
22
|
+
if ("" === ctx.css.charAt(i - 1)) {
|
|
23
|
+
return ctx.error("End of comment missing");
|
|
24
|
+
}
|
|
25
|
+
const str = ctx.css.slice(2, i - 2);
|
|
26
|
+
ctx.column += 2;
|
|
27
|
+
ctx.updatePosition(str);
|
|
28
|
+
ctx.css = ctx.css.slice(i);
|
|
29
|
+
ctx.column += 2;
|
|
30
|
+
return pos({
|
|
31
|
+
type: "comment",
|
|
32
|
+
comment: str,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/css-parse/comments.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,MAAM,UAAU,QAAQ,CAAI,GAAkB,EAAE,QAA6B,EAAE;IAC3E,IAAI,CAAuB,CAAC;IAC5B,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AAEH,MAAM,UAAU,OAAO,CAAC,GAAkB;IACtC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC3B,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAAE,OAAO;IAEjE,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAAE,EAAE,CAAC,CAAC;IAClG,CAAC,IAAI,CAAC,CAAC;IAEP,IAAI,EAAE,KAAK,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;IAChB,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;IAEhB,OAAO,GAAG,CAAC;QACP,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,GAAG;KACf,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { addParent } from "./parent-references.js";
|
|
2
|
+
import { ParserContext } from "./parser-context.js";
|
|
3
|
+
import { rules } from "./rules.js";
|
|
4
|
+
export function cssParse(css, options) {
|
|
5
|
+
const ctx = new ParserContext(css, options || {});
|
|
6
|
+
return addParent(stylesheet(ctx));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse stylesheet.
|
|
10
|
+
*/
|
|
11
|
+
function stylesheet(ctx) {
|
|
12
|
+
const rulesList = rules(ctx);
|
|
13
|
+
return {
|
|
14
|
+
type: "stylesheet",
|
|
15
|
+
stylesheet: {
|
|
16
|
+
source: ctx.options.source,
|
|
17
|
+
rules: rulesList,
|
|
18
|
+
parsingErrors: ctx.errorsList,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=css-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-parse.js","sourceRoot":"","sources":["../../src/css-parse/css-parse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,OAAwB;IAC1D,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAElD,OAAO,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AAEH,SAAS,UAAU,CAAC,GAAkB;IAClC,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAE7B,OAAO;QACH,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE;YACR,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM;YAC1B,KAAK,EAAE,SAAS;YAChB,aAAa,EAAE,GAAG,CAAC,UAAU;SAChC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IFontFace, IPage } from "./at-rule-nodes.js";
|
|
2
|
+
import type { ParserContext } from "./parser-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse paged media.
|
|
5
|
+
*/
|
|
6
|
+
export declare function atpage(ctx: ParserContext): IPage | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Parse font-face.
|
|
9
|
+
*/
|
|
10
|
+
export declare function atfontface(ctx: ParserContext): IFontFace | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { comments } from "./comments.js";
|
|
2
|
+
import { declaration } from "./declarations.js";
|
|
3
|
+
import { selector } from "./selectors.js";
|
|
4
|
+
// At-rules whose block contains declarations.
|
|
5
|
+
/**
|
|
6
|
+
* Parse paged media.
|
|
7
|
+
*/
|
|
8
|
+
export function atpage(ctx) {
|
|
9
|
+
const pos = ctx.position();
|
|
10
|
+
const m = ctx.match(/^@page */);
|
|
11
|
+
if (!m)
|
|
12
|
+
return;
|
|
13
|
+
const sel = selector(ctx) || [];
|
|
14
|
+
if (!ctx.open())
|
|
15
|
+
return ctx.error("@page missing '{'");
|
|
16
|
+
let decls = comments(ctx);
|
|
17
|
+
// declarations
|
|
18
|
+
let decl;
|
|
19
|
+
while ((decl = declaration(ctx))) {
|
|
20
|
+
decls.push(decl);
|
|
21
|
+
decls = decls.concat(comments(ctx));
|
|
22
|
+
}
|
|
23
|
+
if (!ctx.close())
|
|
24
|
+
return ctx.error("@page missing '}'");
|
|
25
|
+
return pos({
|
|
26
|
+
type: "page",
|
|
27
|
+
selectors: sel,
|
|
28
|
+
declarations: decls,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse font-face.
|
|
33
|
+
*/
|
|
34
|
+
export function atfontface(ctx) {
|
|
35
|
+
const pos = ctx.position();
|
|
36
|
+
const m = ctx.match(/^@font-face\s*/);
|
|
37
|
+
if (!m)
|
|
38
|
+
return;
|
|
39
|
+
if (!ctx.open())
|
|
40
|
+
return ctx.error("@font-face missing '{'");
|
|
41
|
+
let decls = comments(ctx);
|
|
42
|
+
// declarations
|
|
43
|
+
let decl;
|
|
44
|
+
while ((decl = declaration(ctx))) {
|
|
45
|
+
decls.push(decl);
|
|
46
|
+
decls = decls.concat(comments(ctx));
|
|
47
|
+
}
|
|
48
|
+
if (!ctx.close())
|
|
49
|
+
return ctx.error("@font-face missing '}'");
|
|
50
|
+
return pos({
|
|
51
|
+
type: "font-face",
|
|
52
|
+
declarations: decls,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=declaration-block-at-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtC,IAAI,CAAC,CAAC;QAAE,OAAO;IAEf,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5D,IAAI,KAAK,GAAG,QAAQ,CAAe,GAAG,CAAC,CAAC;IAExC,eAAe;IACf,IAAI,IAA8B,CAAC;IACnC,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAe,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAE7D,OAAO,GAAG,CAAC;QACP,IAAI,EAAE,WAAW;QACjB,YAAY,EAAE,KAAK;KACtB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IComment, IDeclaration } from "./nodes.js";
|
|
2
|
+
import type { ParserContext } from "./parser-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse declaration.
|
|
5
|
+
*/
|
|
6
|
+
export declare function declaration(ctx: ParserContext): IDeclaration | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Parse declarations.
|
|
9
|
+
*/
|
|
10
|
+
export declare function declarations(ctx: ParserContext): Array<IDeclaration | IComment> | undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { comments } from "./comments.js";
|
|
2
|
+
import { trim } from "./trim.js";
|
|
3
|
+
// http://www.w3.org/TR/CSS21/grammar.html
|
|
4
|
+
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
5
|
+
const commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
6
|
+
/**
|
|
7
|
+
* Parse declaration.
|
|
8
|
+
*/
|
|
9
|
+
export function declaration(ctx) {
|
|
10
|
+
const pos = ctx.position();
|
|
11
|
+
// prop
|
|
12
|
+
const propMatch = ctx.match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
|
|
13
|
+
if (!propMatch)
|
|
14
|
+
return;
|
|
15
|
+
const prop = trim(propMatch[0]);
|
|
16
|
+
// :
|
|
17
|
+
if (!ctx.match(/^:\s*/))
|
|
18
|
+
return ctx.error("property missing ':'");
|
|
19
|
+
// val
|
|
20
|
+
const val = ctx.match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
|
|
21
|
+
const ret = pos({
|
|
22
|
+
type: "declaration",
|
|
23
|
+
property: prop.replace(commentre, ""),
|
|
24
|
+
value: val ? trim(val[0]).replace(commentre, "") : "",
|
|
25
|
+
});
|
|
26
|
+
// ;
|
|
27
|
+
ctx.match(/^[;\s]*/);
|
|
28
|
+
return ret;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse declarations.
|
|
32
|
+
*/
|
|
33
|
+
export function declarations(ctx) {
|
|
34
|
+
const decls = [];
|
|
35
|
+
if (!ctx.open())
|
|
36
|
+
return ctx.error("missing '{'");
|
|
37
|
+
comments(ctx, decls);
|
|
38
|
+
// declarations
|
|
39
|
+
let decl;
|
|
40
|
+
while ((decl = declaration(ctx))) {
|
|
41
|
+
decls.push(decl);
|
|
42
|
+
comments(ctx, decls);
|
|
43
|
+
}
|
|
44
|
+
if (!ctx.close())
|
|
45
|
+
return ctx.error("missing '}'");
|
|
46
|
+
return decls;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../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,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACjD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAErB,eAAe;IACf,IAAI,IAA8B,CAAC;IACnC,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IKeyframe, IKeyframes } from "./at-rule-nodes.js";
|
|
2
|
+
import type { ParserContext } from "./parser-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse keyframe.
|
|
5
|
+
*/
|
|
6
|
+
export declare function keyframe(ctx: ParserContext): IKeyframe | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Parse keyframes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function atkeyframes(ctx: ParserContext): IKeyframes | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { comments } from "./comments.js";
|
|
2
|
+
import { declarations } from "./declarations.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse keyframe.
|
|
5
|
+
*/
|
|
6
|
+
export function keyframe(ctx) {
|
|
7
|
+
let m;
|
|
8
|
+
const vals = [];
|
|
9
|
+
const pos = ctx.position();
|
|
10
|
+
while ((m = ctx.match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
|
|
11
|
+
vals.push(m[1]);
|
|
12
|
+
ctx.match(/^,\s*/);
|
|
13
|
+
}
|
|
14
|
+
if (!vals.length)
|
|
15
|
+
return;
|
|
16
|
+
return pos({
|
|
17
|
+
type: "keyframe",
|
|
18
|
+
values: vals,
|
|
19
|
+
declarations: declarations(ctx),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse keyframes.
|
|
24
|
+
*/
|
|
25
|
+
export function atkeyframes(ctx) {
|
|
26
|
+
const pos = ctx.position();
|
|
27
|
+
let m = ctx.match(/^@([-\w]+)?keyframes\s*/);
|
|
28
|
+
if (!m)
|
|
29
|
+
return;
|
|
30
|
+
const vendor = m[1];
|
|
31
|
+
// identifier
|
|
32
|
+
m = ctx.match(/^([-\w]+)\s*/);
|
|
33
|
+
if (!m)
|
|
34
|
+
return ctx.error("@keyframes missing name");
|
|
35
|
+
const name = m[1];
|
|
36
|
+
if (!ctx.open())
|
|
37
|
+
return ctx.error("@keyframes missing '{'");
|
|
38
|
+
let frame;
|
|
39
|
+
let frames = comments(ctx);
|
|
40
|
+
while ((frame = keyframe(ctx))) {
|
|
41
|
+
frames.push(frame);
|
|
42
|
+
frames = frames.concat(comments(ctx));
|
|
43
|
+
}
|
|
44
|
+
if (!ctx.close())
|
|
45
|
+
return ctx.error("@keyframes missing '}'");
|
|
46
|
+
return pos({
|
|
47
|
+
type: "keyframes",
|
|
48
|
+
name: name,
|
|
49
|
+
vendor: vendor,
|
|
50
|
+
keyframes: frames,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=keyframes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyframes.js","sourceRoot":"","sources":["../../src/css-parse/keyframes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;GAEG;AAEH,MAAM,UAAU,QAAQ,CAAC,GAAkB;IACvC,IAAI,CAAC,CAAC;IACN,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC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,CAAY,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAE7D,OAAO,GAAG,CAAC;QACP,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,MAAM;KACpB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IDocument, IHost, IMedia, ISupports } from "./at-rule-nodes.js";
|
|
2
|
+
import type { StyleNode } from "./nodes.js";
|
|
3
|
+
import type { ParserContext } from "./parser-context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parse supports.
|
|
6
|
+
*/
|
|
7
|
+
export declare function atsupports(ctx: ParserContext, rules: () => StyleNode[]): ISupports | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Parse host.
|
|
10
|
+
*/
|
|
11
|
+
export declare function athost(ctx: ParserContext, rules: () => StyleNode[]): IHost | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Parse media.
|
|
14
|
+
*/
|
|
15
|
+
export declare function atmedia(ctx: ParserContext, rules: () => StyleNode[]): IMedia | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Parse document.
|
|
18
|
+
*/
|
|
19
|
+
export declare function atdocument(ctx: ParserContext, rules: () => StyleNode[]): IDocument | undefined;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { comments } from "./comments.js";
|
|
2
|
+
import { trim } from "./trim.js";
|
|
3
|
+
// At-rules whose block contains nested rules. The rules parser is passed in
|
|
4
|
+
// (rather than imported) because it in turn parses these at-rules.
|
|
5
|
+
/**
|
|
6
|
+
* Parse supports.
|
|
7
|
+
*/
|
|
8
|
+
export function atsupports(ctx, rules) {
|
|
9
|
+
const pos = ctx.position();
|
|
10
|
+
const m = ctx.match(/^@supports *([^{]+)/);
|
|
11
|
+
if (!m)
|
|
12
|
+
return;
|
|
13
|
+
const supports = trim(m[1]);
|
|
14
|
+
if (!ctx.open())
|
|
15
|
+
return ctx.error("@supports missing '{'");
|
|
16
|
+
const style = comments(ctx).concat(rules());
|
|
17
|
+
if (!ctx.close())
|
|
18
|
+
return ctx.error("@supports missing '}'");
|
|
19
|
+
return pos({
|
|
20
|
+
type: "supports",
|
|
21
|
+
supports: supports,
|
|
22
|
+
rules: style,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse host.
|
|
27
|
+
*/
|
|
28
|
+
export function athost(ctx, rules) {
|
|
29
|
+
const pos = ctx.position();
|
|
30
|
+
const m = ctx.match(/^@host\s*/);
|
|
31
|
+
if (!m)
|
|
32
|
+
return;
|
|
33
|
+
if (!ctx.open())
|
|
34
|
+
return ctx.error("@host missing '{'");
|
|
35
|
+
const style = comments(ctx).concat(rules());
|
|
36
|
+
if (!ctx.close())
|
|
37
|
+
return ctx.error("@host missing '}'");
|
|
38
|
+
return pos({
|
|
39
|
+
type: "host",
|
|
40
|
+
rules: style,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parse media.
|
|
45
|
+
*/
|
|
46
|
+
export function atmedia(ctx, rules) {
|
|
47
|
+
const pos = ctx.position();
|
|
48
|
+
const m = ctx.match(/^@media *([^{]+)/);
|
|
49
|
+
if (!m)
|
|
50
|
+
return;
|
|
51
|
+
const media = trim(m[1]);
|
|
52
|
+
if (!ctx.open())
|
|
53
|
+
return ctx.error("@media missing '{'");
|
|
54
|
+
const style = comments(ctx).concat(rules());
|
|
55
|
+
if (!ctx.close())
|
|
56
|
+
return ctx.error("@media missing '}'");
|
|
57
|
+
return pos({
|
|
58
|
+
type: "media",
|
|
59
|
+
media: media,
|
|
60
|
+
rules: style,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse document.
|
|
65
|
+
*/
|
|
66
|
+
export function atdocument(ctx, rules) {
|
|
67
|
+
const pos = ctx.position();
|
|
68
|
+
const m = ctx.match(/^@([-\w]+)?document *([^{]+)/);
|
|
69
|
+
if (!m)
|
|
70
|
+
return;
|
|
71
|
+
const vendor = trim(m[1]);
|
|
72
|
+
const doc = trim(m[2]);
|
|
73
|
+
if (!ctx.open())
|
|
74
|
+
return ctx.error("@document missing '{'");
|
|
75
|
+
const style = comments(ctx).concat(rules());
|
|
76
|
+
if (!ctx.close())
|
|
77
|
+
return ctx.error("@document missing '}'");
|
|
78
|
+
return pos({
|
|
79
|
+
type: "document",
|
|
80
|
+
document: doc,
|
|
81
|
+
vendor: vendor,
|
|
82
|
+
rules: style,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=nested-rule-at-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nested-rule-at-rules.js","sourceRoot":"","sources":["../../src/css-parse/nested-rule-at-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,4EAA4E;AAC5E,mEAAmE;AAEnE;;GAEG;AAEH,MAAM,UAAU,UAAU,CAAC,GAAkB,EAAE,KAAwB;IACnE,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAE3C,IAAI,CAAC,CAAC;QAAE,OAAO;IACf,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAE3D,MAAM,KAAK,GAAG,QAAQ,CAAY,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;I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3
|
+
import type { INodePosition } from "./position.js";
|
|
4
|
+
export interface IBaseNode {
|
|
5
|
+
/** The possible values are the ones listed in the Types section on https://github.com/reworkcss/css page. */
|
|
6
|
+
type: string;
|
|
7
|
+
position?: INodePosition;
|
|
8
|
+
/** A reference to the parent node, or null if the node has no parent. */
|
|
9
|
+
parent?: IBaseNode | null;
|
|
10
|
+
}
|
|
11
|
+
export interface IComment extends IBaseNode {
|
|
12
|
+
type: "comment";
|
|
13
|
+
comment: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IDeclaration extends IBaseNode {
|
|
16
|
+
type: "declaration";
|
|
17
|
+
property: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
export interface IRule extends IBaseNode {
|
|
21
|
+
type: "rule";
|
|
22
|
+
selectors: string[];
|
|
23
|
+
declarations: Array<IDeclaration | IComment> | undefined;
|
|
24
|
+
}
|
|
25
|
+
export type StyleNode = IRule | IComment | AtRule;
|
|
26
|
+
export interface IStyleRules {
|
|
27
|
+
source: string | undefined;
|
|
28
|
+
rules: StyleNode[];
|
|
29
|
+
parsingErrors: IParseError[];
|
|
30
|
+
}
|
|
31
|
+
export interface IStylesheet extends IBaseNode {
|
|
32
|
+
type: "stylesheet";
|
|
33
|
+
stylesheet: IStyleRules;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/css-parse/nodes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface IParserOptions {
|
|
2
|
+
/** Silently fail on parse errors */
|
|
3
|
+
silent?: boolean | undefined;
|
|
4
|
+
/** The path to the file containing css. Makes errors and source maps more helpful, by letting them know where code comes from. */
|
|
5
|
+
source?: string | undefined;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/css-parse/options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds non-enumerable parent node reference to each node.
|
|
3
|
+
*/
|
|
4
|
+
export function addParent(obj, parent) {
|
|
5
|
+
const record = obj;
|
|
6
|
+
const isNode = obj && typeof record.type === "string";
|
|
7
|
+
const childParent = isNode ? record : parent;
|
|
8
|
+
for (const k in record) {
|
|
9
|
+
const value = record[k];
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
value.forEach(function (v) {
|
|
12
|
+
addParent(v, childParent);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
else if (value && typeof value === "object") {
|
|
16
|
+
addParent(value, childParent);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (isNode) {
|
|
20
|
+
Object.defineProperty(obj, "parent", {
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
enumerable: false,
|
|
24
|
+
value: parent || null,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=parent-references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parent-references.js","sourceRoot":"","sources":["../../src/css-parse/parent-references.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,UAAU,SAAS,CAAI,GAAM,EAAE,MAAe;IAChD,MAAM,MAAM,GAAG,GAA8B,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;IACtD,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAE7C,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;gBACrB,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACP,CAAC;aAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5C,SAAS,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAClC,CAAC;IACL,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE;YACjC,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,MAAM,IAAI,IAAI;SACxB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error.js","sourceRoot":"","sources":["../../src/css-parse/parse-error.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { IBaseNode } from "./nodes.js";
|
|
2
|
+
import type { IParserOptions } from "./options.js";
|
|
3
|
+
import type { IParseError } from "./parse-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parser state (the remaining css and the current position in it) shared by
|
|
6
|
+
* all parsing functions, plus the low-level scanning primitives.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ParserContext {
|
|
9
|
+
/**
|
|
10
|
+
* The css that remains to be parsed.
|
|
11
|
+
*/
|
|
12
|
+
css: string;
|
|
13
|
+
readonly options: IParserOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Positional.
|
|
16
|
+
*/
|
|
17
|
+
lineno: number;
|
|
18
|
+
column: number;
|
|
19
|
+
readonly errorsList: IParseError[];
|
|
20
|
+
private readonly Position;
|
|
21
|
+
constructor(css: string, options: IParserOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Update lineno and column based on `str`.
|
|
24
|
+
*/
|
|
25
|
+
updatePosition(str: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Mark position and patch `node.position`.
|
|
28
|
+
*/
|
|
29
|
+
position(): <const T extends IBaseNode>(node: T) => T;
|
|
30
|
+
/**
|
|
31
|
+
* Error `msg`.
|
|
32
|
+
*/
|
|
33
|
+
error(msg: string): undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Match `re` and return captures.
|
|
36
|
+
*/
|
|
37
|
+
match(re: RegExp): RegExpExecArray | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Parse whitespace.
|
|
40
|
+
*/
|
|
41
|
+
whitespace(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Opening brace.
|
|
44
|
+
*/
|
|
45
|
+
open(): RegExpExecArray | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Closing brace.
|
|
48
|
+
*/
|
|
49
|
+
close(): RegExpExecArray | undefined;
|
|
50
|
+
}
|