@react-hive/honey-css 1.0.0 → 1.1.0

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.
@@ -0,0 +1,132 @@
1
+ import type { HoneyCssToken, HoneyCssTokenType } from '~/types';
2
+ /**
3
+ * A lightweight cursor abstraction over a token stream.
4
+ *
5
+ * This is the core navigation primitive used by the Honey CSS parser.
6
+ * It provides safe sequential reading, lookahead, backtracking,
7
+ * and small helper utilities for collecting selector/value text.
8
+ */
9
+ export interface HoneyTokenCursor {
10
+ /**
11
+ * Returns `true` when the cursor has consumed all tokens.
12
+ */
13
+ isEof: () => boolean;
14
+ /**
15
+ * Returns the current token without consuming it.
16
+ *
17
+ * This is primarily used for lookahead decisions in the parser:
18
+ *
19
+ * ```ts
20
+ * if (cursor.peek()?.type === 'braceOpen') {
21
+ * // parse rule block
22
+ * }
23
+ * ```
24
+ */
25
+ peek: () => HoneyCssToken | undefined;
26
+ /**
27
+ * Consumes and returns the current token, advancing the cursor forward.
28
+ *
29
+ * Returns `undefined` if the cursor is already at EOF.
30
+ *
31
+ * ```ts
32
+ * const token = cursor.next();
33
+ * ```
34
+ */
35
+ next: () => HoneyCssToken | undefined;
36
+ /**
37
+ * Creates a checkpoint of the current cursor position.
38
+ *
39
+ * Useful for speculative parsing or backtracking:
40
+ *
41
+ * ```ts
42
+ * const mark = cursor.mark();
43
+ *
44
+ * if (!tryParseSomething(cursor)) {
45
+ * cursor.reset(mark);
46
+ * }
47
+ * ```
48
+ */
49
+ mark: () => number;
50
+ /**
51
+ * Restores the cursor back to a previously created mark.
52
+ *
53
+ * @param mark - Index returned from {@link mark}.
54
+ */
55
+ reset: (mark: number) => void;
56
+ /**
57
+ * Consumes the next token and asserts that it matches the expected type.
58
+ *
59
+ * This is the parser's main safety mechanism and helps produce
60
+ * clear error messages during invalid input.
61
+ *
62
+ * Throws if:
63
+ * - the token stream ends unexpectedly
64
+ * - the next token has a different type
65
+ *
66
+ * ```ts
67
+ * cursor.expect('braceOpen'); // must be "{"
68
+ * ```
69
+ *
70
+ * @param type - Expected token type.
71
+ *
72
+ * @returns The consumed token, narrowed to the expected type.
73
+ */
74
+ expect: <T extends HoneyCssTokenType>(type: T) => Extract<HoneyCssToken, {
75
+ type: T;
76
+ }>;
77
+ /**
78
+ * Reads and concatenates consecutive token values until one of the stop token
79
+ * types is encountered.
80
+ *
81
+ * This helper is used to collect:
82
+ * - selectors (`.btn:hover`)
83
+ * - declaration values (`calc(100% - 1px)`)
84
+ * - at-rule names (`media`)
85
+ *
86
+ * Stops **before consuming** the stop token.
87
+ *
88
+ * Supported token types:
89
+ * - `text` → appended as-is
90
+ * - `string` → wrapped in quotes
91
+ * - `params` → appended verbatim including parentheses
92
+ *
93
+ * Example:
94
+ *
95
+ * Tokens:
96
+ * ```
97
+ * text("var")
98
+ * params("(--color)")
99
+ * ```
100
+ *
101
+ * Result:
102
+ * ```
103
+ * "var(--color)"
104
+ * ```
105
+ *
106
+ * @param stopTypes - Token types that terminate reading.
107
+ *
108
+ * @returns Combined string value.
109
+ */
110
+ readUntil: (stopTypes: HoneyCssTokenType[]) => string;
111
+ /**
112
+ * Advances the cursor until one of the stop token types is reached.
113
+ *
114
+ * This is useful for error recovery and safely skipping unknown syntax.
115
+ *
116
+ * Stops before consuming the stop token.
117
+ *
118
+ * @param stopTypes - Token types that terminate skipping.
119
+ */
120
+ skipUntil: (stopTypes: HoneyCssTokenType[]) => void;
121
+ }
122
+ /**
123
+ * Creates a cursor wrapper around a list of CSS tokens.
124
+ *
125
+ * The cursor provides a small API surface for building
126
+ * recursive-descent parsers without needing complex parser generators.
127
+ *
128
+ * @param tokens - Token list produced by the Honey tokenizer.
129
+ *
130
+ * @returns A reusable cursor instance.
131
+ */
132
+ export declare const createCssTokenCursor: (tokens: HoneyCssToken[]) => HoneyTokenCursor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-css",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A lightweight CSS tokenizer and parser that produces a simple AST for custom CSS processing.",
5
5
  "keywords": [
6
6
  "css",
@@ -47,20 +47,23 @@
47
47
  "engines": {
48
48
  "node": ">=18"
49
49
  },
50
+ "dependencies": {
51
+ "@react-hive/honey-utils": "3.23.0"
52
+ },
50
53
  "devDependencies": {
51
- "@eslint/js": "9.39.1",
54
+ "@eslint/js": "9.39.2",
52
55
  "@mdx-js/loader": "3.1.1",
53
56
  "@types/jest": "29.5.14",
54
- "@types/node": "22.19.1",
57
+ "@types/node": "22.19.11",
55
58
  "copy-webpack-plugin": "13.0.1",
56
- "eslint": "9.39.1",
59
+ "eslint": "9.39.2",
57
60
  "eslint-plugin-react": "7.37.5",
58
61
  "jest": "29.7.0",
59
- "prettier": "3.6.2",
60
- "ts-jest": "29.4.4",
62
+ "prettier": "3.8.1",
63
+ "ts-jest": "29.4.6",
61
64
  "ts-loader": "9.5.4",
62
65
  "typescript": "5.9.3",
63
- "typescript-eslint": "8.47.0",
66
+ "typescript-eslint": "8.55.0",
64
67
  "webpack": "5.105.2",
65
68
  "webpack-cli": "6.0.1"
66
69
  },