@projectwallace/css-parser 0.7.0 → 0.7.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.
@@ -1,6 +1,44 @@
1
1
  import type { CSSDataArena } from './arena';
2
2
  import { STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, SELECTOR_LIST, TYPE_SELECTOR, CLASS_SELECTOR, ID_SELECTOR, ATTRIBUTE_SELECTOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, COMBINATOR, UNIVERSAL_SELECTOR, NESTING_SELECTOR, NTH_SELECTOR, NTH_OF_SELECTOR, LANG_SELECTOR, MEDIA_QUERY, MEDIA_FEATURE, MEDIA_TYPE, CONTAINER_QUERY, SUPPORTS_QUERY, LAYER_NAME, PRELUDE_OPERATOR } from './arena';
3
- export declare const TYPE_NAMES: Record<number, string>;
3
+ export declare const TYPE_NAMES: {
4
+ readonly 1: "StyleSheet";
5
+ readonly 2: "Rule";
6
+ readonly 3: "Atrule";
7
+ readonly 4: "Declaration";
8
+ readonly 5: "Selector";
9
+ readonly 6: "Comment";
10
+ readonly 7: "Block";
11
+ readonly 10: "Identifier";
12
+ readonly 11: "Number";
13
+ readonly 12: "Dimension";
14
+ readonly 13: "String";
15
+ readonly 14: "Hash";
16
+ readonly 15: "Function";
17
+ readonly 16: "Operator";
18
+ readonly 17: "Parentheses";
19
+ readonly 18: "Url";
20
+ readonly 20: "SelectorList";
21
+ readonly 21: "TypeSelector";
22
+ readonly 22: "ClassSelector";
23
+ readonly 23: "IdSelector";
24
+ readonly 24: "AttributeSelector";
25
+ readonly 25: "PseudoClassSelector";
26
+ readonly 26: "PseudoElementSelector";
27
+ readonly 27: "Combinator";
28
+ readonly 28: "UniversalSelector";
29
+ readonly 29: "NestingSelector";
30
+ readonly 30: "Nth";
31
+ readonly 31: "NthOf";
32
+ readonly 56: "Lang";
33
+ readonly 32: "MediaQuery";
34
+ readonly 33: "Feature";
35
+ readonly 34: "MediaType";
36
+ readonly 35: "ContainerQuery";
37
+ readonly 36: "SupportsQuery";
38
+ readonly 37: "Layer";
39
+ readonly 38: "Operator";
40
+ };
41
+ export type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown';
4
42
  export type CSSNodeType = typeof STYLESHEET | typeof STYLE_RULE | typeof AT_RULE | typeof DECLARATION | typeof SELECTOR | typeof COMMENT | typeof BLOCK | typeof IDENTIFIER | typeof NUMBER | typeof DIMENSION | typeof STRING | typeof HASH | typeof FUNCTION | typeof OPERATOR | typeof PARENTHESIS | typeof URL | typeof SELECTOR_LIST | typeof TYPE_SELECTOR | typeof CLASS_SELECTOR | typeof ID_SELECTOR | typeof ATTRIBUTE_SELECTOR | typeof PSEUDO_CLASS_SELECTOR | typeof PSEUDO_ELEMENT_SELECTOR | typeof COMBINATOR | typeof UNIVERSAL_SELECTOR | typeof NESTING_SELECTOR | typeof NTH_SELECTOR | typeof NTH_OF_SELECTOR | typeof LANG_SELECTOR | typeof MEDIA_QUERY | typeof MEDIA_FEATURE | typeof MEDIA_TYPE | typeof CONTAINER_QUERY | typeof SUPPORTS_QUERY | typeof LAYER_NAME | typeof PRELUDE_OPERATOR;
5
43
  export interface CloneOptions {
6
44
  /**
@@ -16,7 +54,7 @@ export interface CloneOptions {
16
54
  }
17
55
  export type PlainCSSNode = {
18
56
  type: number;
19
- type_name: string;
57
+ type_name: TypeName;
20
58
  text: string;
21
59
  children: PlainCSSNode[];
22
60
  name?: string;
@@ -43,7 +81,7 @@ export declare class CSSNode {
43
81
  constructor(arena: CSSDataArena, source: string, index: number);
44
82
  get_index(): number;
45
83
  get type(): CSSNodeType;
46
- get type_name(): string;
84
+ get type_name(): TypeName;
47
85
  get text(): string;
48
86
  get name(): string;
49
87
  get property(): string;
package/dist/css-node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DIMENSION, NUMBER, DECLARATION, FLAG_IMPORTANT, FLAG_VENDOR_PREFIXED, FLAG_HAS_ERROR, FLAG_HAS_BLOCK, FLAG_HAS_DECLARATIONS, STYLE_RULE, BLOCK, AT_RULE, COMMENT, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, FLAG_HAS_PARENS, NTH_SELECTOR, NTH_OF_SELECTOR, SELECTOR_LIST, SELECTOR, COMBINATOR, ATTRIBUTE_SELECTOR, PRELUDE_OPERATOR, LAYER_NAME, SUPPORTS_QUERY, CONTAINER_QUERY, MEDIA_TYPE, MEDIA_FEATURE, MEDIA_QUERY, LANG_SELECTOR, NESTING_SELECTOR, UNIVERSAL_SELECTOR, ID_SELECTOR, CLASS_SELECTOR, TYPE_SELECTOR, URL, PARENTHESIS, OPERATOR, FUNCTION, HASH, STRING, IDENTIFIER, STYLESHEET } from './arena.js';
1
+ import { URL, STRING, DIMENSION, NUMBER, DECLARATION, FLAG_IMPORTANT, FLAG_VENDOR_PREFIXED, FLAG_HAS_ERROR, FLAG_HAS_BLOCK, FLAG_HAS_DECLARATIONS, STYLE_RULE, BLOCK, AT_RULE, COMMENT, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, FLAG_HAS_PARENS, NTH_SELECTOR, NTH_OF_SELECTOR, SELECTOR_LIST, SELECTOR, COMBINATOR, ATTRIBUTE_SELECTOR, PRELUDE_OPERATOR, LAYER_NAME, SUPPORTS_QUERY, CONTAINER_QUERY, MEDIA_TYPE, MEDIA_FEATURE, MEDIA_QUERY, LANG_SELECTOR, NESTING_SELECTOR, UNIVERSAL_SELECTOR, ID_SELECTOR, CLASS_SELECTOR, TYPE_SELECTOR, PARENTHESIS, OPERATOR, FUNCTION, HASH, IDENTIFIER, STYLESHEET } from './arena.js';
2
2
  import { is_whitespace, CHAR_MINUS_HYPHEN, CHAR_PLUS } from './string-utils.js';
3
3
  import { parse_dimension } from './parse-utils.js';
4
4
 
@@ -82,7 +82,26 @@ class CSSNode {
82
82
  // Get the value text (for declarations: "blue" in "color: blue")
83
83
  // For dimension/number nodes: returns the numeric value as a number
84
84
  // For string nodes: returns the string content without quotes
85
+ // For URL nodes with quoted string: returns the string with quotes (consistent with STRING node)
86
+ // For URL nodes with unquoted URL: returns the URL content without quotes
85
87
  get value() {
88
+ if (this.type === URL) {
89
+ const firstChild = this.first_child;
90
+ if (firstChild && firstChild.type === STRING) {
91
+ return firstChild.text;
92
+ }
93
+ const text = this.text;
94
+ if (text.startsWith("url(")) {
95
+ const openParen = text.indexOf("(");
96
+ const closeParen = text.lastIndexOf(")");
97
+ if (openParen !== -1 && closeParen !== -1 && closeParen > openParen) {
98
+ let content = text.substring(openParen + 1, closeParen).trim();
99
+ return content;
100
+ }
101
+ } else if (text.startsWith('"') || text.startsWith("'")) {
102
+ return text;
103
+ }
104
+ }
86
105
  if (this.type === DIMENSION || this.type === NUMBER) {
87
106
  return parse_dimension(this.text).value;
88
107
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
5
  "author": "Bart Veneman <bat@projectwallace.com>",
6
6
  "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/projectwallace/css-parser.git"
10
- },
11
- "issues": "https://github.com/projectwallace/css-parser/issues",
12
- "homepage": "https://github.com/projectwallace/css-parser",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/projectwallace/css-parser.git"
10
+ },
11
+ "issues": "https://github.com/projectwallace/css-parser/issues",
12
+ "homepage": "https://github.com/projectwallace/css-parser",
13
13
  "type": "module",
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.js",
@@ -56,8 +56,7 @@
56
56
  "benchmark:memory": "npm run build && node --expose-gc benchmark/memory.ts",
57
57
  "lint": "oxlint --config .oxlintrc.json",
58
58
  "lint-package": "publint",
59
- "check": "tsc --noEmit",
60
- "knip": "knip"
59
+ "check": "tsc --noEmit"
61
60
  },
62
61
  "keywords": [
63
62
  "css",
@@ -72,7 +71,6 @@
72
71
  "@vitest/coverage-v8": "^4.0.8",
73
72
  "bootstrap": "^5.3.8",
74
73
  "css-tree": "^3.1.0",
75
- "knip": "^5.69.1",
76
74
  "oxlint": "^1.28.0",
77
75
  "postcss": "^8.5.6",
78
76
  "prettier": "^3.6.2",