@cssdoc/index 0.2.0 → 0.3.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/dist/index.d.mts +11 -4
- package/dist/index.mjs +18 -4
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CssAnimation, CssCondition, CssDocConfiguration, CssDocEntry, CssFunction, CssModifier, CssPart, CssPropertyDeclared, CssState, ModifierConventionInput, ModifierMatcher, StructureNode } from "@cssdoc/core";
|
|
2
|
+
import postcss from "postcss";
|
|
2
3
|
|
|
3
4
|
//#region src/index.d.ts
|
|
4
5
|
/** A 1-based line/column position (matching PostCSS). */
|
|
@@ -52,7 +53,7 @@ interface CssValueSites {
|
|
|
52
53
|
usages: PropertyUsage[];
|
|
53
54
|
}
|
|
54
55
|
/** The kinds of record member a span can be keyed to. */
|
|
55
|
-
type MemberKind = "record" | "modifier" | "part" | "property" | "function" | "animation" | "layer" | "state" | "condition";
|
|
56
|
+
type MemberKind = "record" | "modifier" | "part" | "shadow-part" | "property" | "function" | "animation" | "layer" | "state" | "condition";
|
|
56
57
|
/** Build a stable span key for a member. */
|
|
57
58
|
declare function memberKey(kind: MemberKind, id?: string): string;
|
|
58
59
|
/** One record in the index: its model entry plus source spans and the facts drift checks need. */
|
|
@@ -64,8 +65,10 @@ interface RecordInfo {
|
|
|
64
65
|
memberSpans: Map<string, SourceSpan>;
|
|
65
66
|
/** Modifier names authored via `@modifier` (used for drift detection). */
|
|
66
67
|
authoredModifiers: Set<string>;
|
|
67
|
-
/** Part names authored via `@part
|
|
68
|
+
/** Part names authored via `@part` (used for drift detection). */
|
|
68
69
|
authoredParts: Set<string>;
|
|
70
|
+
/** Shadow-part names authored via `@csspart` (used for drift detection). */
|
|
71
|
+
authoredShadowParts: Set<string>;
|
|
69
72
|
/** The concatenated selector text of the record's rules (used for drift detection). */
|
|
70
73
|
selectorText: string;
|
|
71
74
|
}
|
|
@@ -92,6 +95,7 @@ declare class CssDocIndex {
|
|
|
92
95
|
recordInfo(name: string): RecordInfo | undefined;
|
|
93
96
|
modifiersFor(name: string): CssModifier[];
|
|
94
97
|
partsFor(name: string): CssPart[];
|
|
98
|
+
shadowPartsFor(name: string): CssPart[];
|
|
95
99
|
customPropertiesFor(name: string): CssPropertyDeclared[];
|
|
96
100
|
functionsFor(name: string): CssFunction[];
|
|
97
101
|
statesFor(name: string): CssState[];
|
|
@@ -133,7 +137,8 @@ declare function indexFromEntries(entries: CssDocEntry[], file?: string): CssDoc
|
|
|
133
137
|
declare function createIndex(css: string, options?: {
|
|
134
138
|
file?: string;
|
|
135
139
|
configuration?: CssDocConfiguration;
|
|
136
|
-
modifierConvention?: ModifierConventionInput;
|
|
140
|
+
modifierConvention?: ModifierConventionInput; /** The PostCSS parser (inject a dialect parser for `.scss`/`.less`; default `postcss.parse`). */
|
|
141
|
+
parse?: (css: string) => ReturnType<typeof postcss.parse>;
|
|
137
142
|
}): CssDocIndex;
|
|
138
143
|
/**
|
|
139
144
|
* Extract custom-property assignments (`--name: value`) and `var(--name, fallback)` references from
|
|
@@ -143,6 +148,8 @@ declare function createIndex(css: string, options?: {
|
|
|
143
148
|
* @param css - The CSS source.
|
|
144
149
|
* @returns The assignments and `var(…)` usages found.
|
|
145
150
|
*/
|
|
146
|
-
declare function cssValueSites(css: string
|
|
151
|
+
declare function cssValueSites(css: string, options?: {
|
|
152
|
+
parse?: (css: string) => ReturnType<typeof postcss.parse>;
|
|
153
|
+
}): CssValueSites;
|
|
147
154
|
//#endregion
|
|
148
155
|
export { ClassUsage, CssDocIndex, CssDocManifest, CssValueSites, Location, MemberKind, Position, PropertyAssignment, PropertyUsage, RecordInfo, SourceSpan, createIndex, cssValueSites, indexFromEntries, memberKey };
|
package/dist/index.mjs
CHANGED
|
@@ -69,6 +69,9 @@ var CssDocIndex = class {
|
|
|
69
69
|
partsFor(name) {
|
|
70
70
|
return this.byName.get(name)?.entry.parts ?? [];
|
|
71
71
|
}
|
|
72
|
+
shadowPartsFor(name) {
|
|
73
|
+
return this.byName.get(name)?.entry.shadowParts ?? [];
|
|
74
|
+
}
|
|
72
75
|
customPropertiesFor(name) {
|
|
73
76
|
return this.byName.get(name)?.entry.cssPropertiesDeclared ?? [];
|
|
74
77
|
}
|
|
@@ -137,6 +140,7 @@ function indexFromEntries(entries, file) {
|
|
|
137
140
|
memberSpans: /* @__PURE__ */ new Map(),
|
|
138
141
|
authoredModifiers: /* @__PURE__ */ new Set(),
|
|
139
142
|
authoredParts: /* @__PURE__ */ new Set(),
|
|
143
|
+
authoredShadowParts: /* @__PURE__ */ new Set(),
|
|
140
144
|
selectorText: ""
|
|
141
145
|
})), file);
|
|
142
146
|
}
|
|
@@ -152,12 +156,19 @@ function scanNodes(nodes, build, base, matcher) {
|
|
|
152
156
|
if (`.${stripDot(node.selector.trim())}` === base && !build.span) build.span = spanOf(node);
|
|
153
157
|
for (const selector of node.selector.split(",")) {
|
|
154
158
|
for (const s of selector.matchAll(/:state\(\s*([\w-]+)\s*\)/gu)) set(memberKey("state", s[1]), node);
|
|
159
|
+
for (const ps of matcher.pseudoStatesIn(selector)) set(memberKey("state", ps.name), node);
|
|
160
|
+
for (const sp of selector.matchAll(/::part\(\s*([\w-]+)\s*\)/gu)) set(memberKey("shadow-part", sp[1]), node);
|
|
155
161
|
const bare = selector.replace(/::?[\w-]+(\([^)]*\))?/gu, "");
|
|
156
162
|
const modNames = /* @__PURE__ */ new Set();
|
|
157
163
|
for (const mod of matcher.modifiersIn(bare, baseNoDot)) {
|
|
158
164
|
modNames.add(mod.name);
|
|
159
165
|
set(memberKey("modifier", mod.name), node);
|
|
160
166
|
}
|
|
167
|
+
for (const el of matcher.elementsIn(bare, baseNoDot)) {
|
|
168
|
+
set(memberKey("part", el.name), node);
|
|
169
|
+
for (const m of el.modifiers) set(memberKey("modifier", m.name), node);
|
|
170
|
+
}
|
|
171
|
+
for (const st of matcher.statesIn(bare, baseNoDot)) set(memberKey("state", st.name), node);
|
|
161
172
|
for (const p of bare.matchAll(/\.([a-z][\w-]*)/gu)) {
|
|
162
173
|
if (modNames.has(p[1])) continue;
|
|
163
174
|
set(memberKey("part", p[1]), node);
|
|
@@ -189,11 +200,12 @@ function createIndex(css, options = {}) {
|
|
|
189
200
|
const matcher = new ModifierMatcher(resolveModifierConvention(options.modifierConvention ?? options.configuration?.modifierConvention));
|
|
190
201
|
const entries = parseCssDocs(css, {
|
|
191
202
|
configuration: options.configuration,
|
|
192
|
-
modifierConvention: options.modifierConvention
|
|
203
|
+
modifierConvention: options.modifierConvention,
|
|
204
|
+
parse: options.parse
|
|
193
205
|
});
|
|
194
206
|
const byName = new Map(entries.map((e) => [e.name, e]));
|
|
195
207
|
const builds = /* @__PURE__ */ new Map();
|
|
196
|
-
const root = postcss.parse(css);
|
|
208
|
+
const root = (options.parse ?? postcss.parse)(css);
|
|
197
209
|
let current;
|
|
198
210
|
for (const node of root.nodes) {
|
|
199
211
|
if (node.type === "comment") {
|
|
@@ -207,6 +219,7 @@ function createIndex(css, options = {}) {
|
|
|
207
219
|
memberSpans: /* @__PURE__ */ new Map(),
|
|
208
220
|
authoredModifiers: new Set(doc.modifiers.keys()),
|
|
209
221
|
authoredParts: new Set(doc.parts.keys()),
|
|
222
|
+
authoredShadowParts: new Set(doc.cssParts.keys()),
|
|
210
223
|
selectorText: ""
|
|
211
224
|
};
|
|
212
225
|
builds.set(name, current);
|
|
@@ -220,6 +233,7 @@ function createIndex(css, options = {}) {
|
|
|
220
233
|
memberSpans: /* @__PURE__ */ new Map(),
|
|
221
234
|
authoredModifiers: /* @__PURE__ */ new Set(),
|
|
222
235
|
authoredParts: /* @__PURE__ */ new Set(),
|
|
236
|
+
authoredShadowParts: /* @__PURE__ */ new Set(),
|
|
223
237
|
selectorText: ""
|
|
224
238
|
}), options.file, matcher);
|
|
225
239
|
}
|
|
@@ -231,10 +245,10 @@ function createIndex(css, options = {}) {
|
|
|
231
245
|
* @param css - The CSS source.
|
|
232
246
|
* @returns The assignments and `var(…)` usages found.
|
|
233
247
|
*/
|
|
234
|
-
function cssValueSites(css) {
|
|
248
|
+
function cssValueSites(css, options = {}) {
|
|
235
249
|
const assignments = [];
|
|
236
250
|
const usages = [];
|
|
237
|
-
postcss.parse(css).walkDecls((decl) => {
|
|
251
|
+
(options.parse ?? postcss.parse)(css).walkDecls((decl) => {
|
|
238
252
|
const loc = spanOf(decl);
|
|
239
253
|
if (decl.prop.startsWith("--")) assignments.push({
|
|
240
254
|
name: decl.prop,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssdoc/index",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A queryable semantic index over the @cssdoc/core model, plus a host-agnostic Usage abstraction and source spans — the shared data layer for cssdoc's linters and language server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"postcss": "^8.5.16",
|
|
32
32
|
"postcss-value-parser": "^4.2.0",
|
|
33
|
-
"@cssdoc/core": "0.
|
|
33
|
+
"@cssdoc/core": "0.3.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^24.13.3",
|