@cssdoc/providers 0.5.4 → 0.6.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 CHANGED
@@ -80,7 +80,7 @@ type HoverDetail = "compact" | "full" | "custom";
80
80
  type HoverSectionMode = "on" | "off" | "auto";
81
81
  type HoverSections = Record<string, HoverSectionMode>;
82
82
  /** The card's section keys, in default render order — the `custom` map is keyed by these. */
83
- declare const HOVER_SECTION_KEYS: readonly ["summary", "deprecated", "remarks", "accessibility", "modifiers", "parts", "shadowParts", "states", "customProperties", "functions", "slots", "animations", "layers", "conditions", "see", "structure", "examples"];
83
+ declare const HOVER_SECTION_KEYS: readonly ["summary", "deprecated", "remarks", "accessibility", "modifiers", "parts", "shadowParts", "pseudoElements", "states", "customProperties", "functions", "slots", "animations", "layers", "conditions", "see", "todos", "structure", "examples"];
84
84
  /** One hover-card section name. */
85
85
  type HoverSectionKey = (typeof HOVER_SECTION_KEYS)[number];
86
86
  /**
@@ -184,6 +184,15 @@ declare function parseDirectives(source: string): Directive[];
184
184
  declare function applyDirectives(diagnostics: Diagnostic[], source: string): Diagnostic[];
185
185
  //#endregion
186
186
  //#region src/aspects.d.ts
187
+ /**
188
+ * Whether `selectorText` (the record's concatenated selectors) defines the modifier/part `selector`
189
+ * (`.name`, where `name` may be a `*` glob for a family like `.-icon-*`; a name with no `*` is exact).
190
+ * Beyond a literal class token, `class` attribute selectors count with their real CSS operator
191
+ * semantics — `[class~=v]`/`[class=v]` (exact word), `[class*=v]` (substring), and `[class$=v]` (suffix)
192
+ * can define a chained modifier; `[class^=v]` cannot, since `^=` anchors to the start of the whole
193
+ * attribute (the base class), never a chained modifier.
194
+ */
195
+ declare const selectorDefines: (selectorText: string, selector: string) => boolean;
187
196
  declare const record: {
188
197
  model(index: CssDocIndex, naming?: ResolvedNaming, structureIgnore?: readonly string[], siblingIndex?: CssDocIndex): Diagnostic[];
189
198
  completions(index: CssDocIndex): Completion[];
@@ -212,7 +221,7 @@ declare const customProperty: {
212
221
  assignment(a: PropertyAssignment, index: CssDocIndex): Diagnostic[];
213
222
  propertyUsage(usage: PropertyUsage, index: CssDocIndex, options: UsageOptions): Diagnostic[];
214
223
  completions(index: CssDocIndex): Completion[];
215
- hover(name: string, index: CssDocIndex): Hover | undefined;
224
+ hover(name: string, index: CssDocIndex, valueIndex?: CssDocIndex): Hover | undefined;
216
225
  definition(name: string, index: CssDocIndex): Location$1 | undefined;
217
226
  };
218
227
  declare const func: {
@@ -243,8 +252,11 @@ declare function completeCustomProperties(index: CssDocIndex): Completion[];
243
252
  declare function completeFunctions(index: CssDocIndex): Completion[];
244
253
  /** Hover for a class token: the modifier's docs, else the component's card (at the given detail). */
245
254
  declare function hoverForClass(base: string, token: string, index: CssDocIndex, detail?: HoverDetail, sections?: HoverSections, sectionOrder?: HoverSectionOrder): Hover | undefined;
246
- /** Hover for a `var(--…)` custom property. */
247
- declare function hoverForCustomProperty(name: string, index: CssDocIndex): Hover | undefined;
255
+ /**
256
+ * Hover for a `var(--…)` custom property. `valueIndex` (default `index`) supplies the value graph for
257
+ * `var()` resolution — pass a project-wide index so a chain that runs through other sheets resolves.
258
+ */
259
+ declare function hoverForCustomProperty(name: string, index: CssDocIndex, valueIndex?: CssDocIndex): Hover | undefined;
248
260
  /** Hover for a custom function. */
249
261
  declare function hoverForFunction(name: string, index: CssDocIndex): Hover | undefined;
250
262
  /** Definition of a class token: the modifier's rule, else the component's. */
@@ -254,4 +266,4 @@ declare function definitionForCustomProperty(name: string, index: CssDocIndex):
254
266
  /** Definition of a custom function (its `@function` rule). */
255
267
  declare function definitionForFunction(name: string, index: CssDocIndex): Location$1 | undefined;
256
268
  //#endregion
257
- export { ASPECTS, Completion, CompletionKind, DEFAULT_RULE_SEVERITIES, Diagnostic, HOVER_SECTION_KEYS, Hover, HoverDetail, HoverSectionKey, HoverSectionMode, HoverSectionOrder, HoverSections, type Location, NAME_CASE_PRESETS, NameCase, NamingRules, ResolvedNaming, RuleId, RuleSeverities, RuleSeverity, Severity, type SourceSpan, SyntaxMatch, UsageOptions, applyDirectives, checkClassUsage, checkPropertyAssignments, checkPropertyUsage, completeClasses, completeCustomProperties, completeFunctions, cssPart, customProperty, definitionForClass, definitionForCustomProperty, definitionForFunction, func, hoverForClass, hoverForCustomProperty, hoverForFunction, linkSyntax, lintModel, matchesSyntax, mdnUrlForType, modifier, parseDirectives, part, partUsage, record, resolveNaming, resolveRuleSeverities, stateUsage };
269
+ export { ASPECTS, Completion, CompletionKind, DEFAULT_RULE_SEVERITIES, Diagnostic, HOVER_SECTION_KEYS, Hover, HoverDetail, HoverSectionKey, HoverSectionMode, HoverSectionOrder, HoverSections, type Location, NAME_CASE_PRESETS, NameCase, NamingRules, ResolvedNaming, RuleId, RuleSeverities, RuleSeverity, Severity, type SourceSpan, SyntaxMatch, UsageOptions, applyDirectives, checkClassUsage, checkPropertyAssignments, checkPropertyUsage, completeClasses, completeCustomProperties, completeFunctions, cssPart, customProperty, definitionForClass, definitionForCustomProperty, definitionForFunction, func, hoverForClass, hoverForCustomProperty, hoverForFunction, linkSyntax, lintModel, matchesSyntax, mdnUrlForType, modifier, parseDirectives, part, partUsage, record, resolveNaming, resolveRuleSeverities, selectorDefines, stateUsage };
package/dist/index.mjs CHANGED
@@ -131,6 +131,7 @@ const HOVER_SECTION_KEYS = [
131
131
  "modifiers",
132
132
  "parts",
133
133
  "shadowParts",
134
+ "pseudoElements",
134
135
  "states",
135
136
  "customProperties",
136
137
  "functions",
@@ -139,6 +140,7 @@ const HOVER_SECTION_KEYS = [
139
140
  "layers",
140
141
  "conditions",
141
142
  "see",
143
+ "todos",
142
144
  "structure",
143
145
  "examples"
144
146
  ];
@@ -220,15 +222,17 @@ const globMatch = (pattern, value) => {
220
222
  /**
221
223
  * Serialize an authored `@structure` tree back to nested CSS for a syntax-highlighted hover block. Leaf
222
224
  * selectors are left bare (no `{}`) — VS Code's CSS grammar still colours them, and it reads like the
223
- * authored `@structure` declaration; only nesting keeps braces.
225
+ * authored `@structure` declaration; only nesting keeps braces. A node's authored prose (`@wrapper`)
226
+ * trails its selector as a CSS comment.
224
227
  */
225
228
  const renderStructureTree = (nodes, depth = 0) => nodes.flatMap((n) => {
226
229
  const pad = " ".repeat(depth);
230
+ const note = n.description ? ` /* ${n.description} */` : "";
227
231
  return n.children.length ? [
228
- `${pad}${n.selector} {`,
232
+ `${pad}${n.selector} {${note}`,
229
233
  ...renderStructureTree(n.children, depth + 1),
230
234
  `${pad}}`
231
- ] : [`${pad}${n.selector}`];
235
+ ] : [`${pad}${n.selector}${note}`];
232
236
  });
233
237
  const record = {
234
238
  model(index, naming, structureIgnore = [], siblingIndex = index) {
@@ -262,6 +266,10 @@ const record = {
262
266
  ...info.entry.modifiers.map((m) => m.name),
263
267
  ...info.entry.slots.map((s) => s.name)
264
268
  ]);
269
+ const selfClass = stripDot(info.entry.className);
270
+ const classesOf = (sel) => [...sel.matchAll(/\.([\w-]+)/gu)].map((m) => m[1]);
271
+ const hasSelfBelow = (nodes) => nodes.some((n) => classesOf(n.selector).includes(selfClass) || hasSelfBelow(n.children));
272
+ for (const root of info.entry.structure) if (hasSelfBelow(root.children)) for (const c of classesOf(root.selector)) known.add(c);
265
273
  const own = stripDot(info.entry.className);
266
274
  const prefix = info.entry.name && own.endsWith(info.entry.name) ? own.slice(0, own.length - info.entry.name.length) : "";
267
275
  const isSibling = (cls) => prefix !== "" && cls.startsWith(prefix) && siblingNames.has(cls.slice(prefix.length));
@@ -317,6 +325,7 @@ const record = {
317
325
  entry.modifiers.length && `${entry.modifiers.length} modifiers`,
318
326
  entry.parts.length && `${entry.parts.length} parts`,
319
327
  entry.shadowParts.length && `${entry.shadowParts.length} shadow parts`,
328
+ entry.pseudoElements.length && `${entry.pseudoElements.length} pseudo-elements`,
320
329
  entry.states.length && `${entry.states.length} states`,
321
330
  entry.cssPropertiesDeclared.length && `${entry.cssPropertiesDeclared.length} custom properties`,
322
331
  entry.functions.length && `${entry.functions.length} functions`,
@@ -360,6 +369,7 @@ const record = {
360
369
  }));
361
370
  list("parts", "symbol-field", "Parts", entry.parts.map((p) => `- ${styled(`.${p.name}`, "field")}${dash(p.description)}`));
362
371
  list("shadowParts", "symbol-namespace", "Shadow parts", entry.shadowParts.map((p) => `- ${styled(`::part(${p.name})`, "field")}${dash(p.description)}`));
372
+ list("pseudoElements", "symbol-misc", "Pseudo-elements", entry.pseudoElements.map((p) => `- ${styled(`::${p.name}`, "field")}${dash(p.description)}`));
363
373
  list("states", "symbol-event", "States", entry.states.map((s) => `- ${styled(s.kind === "custom" ? `:state(${s.name})` : `:${s.name}`, "variable")}${dash(s.description)}`));
364
374
  list("customProperties", "symbol-variable", "Custom properties", entry.cssPropertiesDeclared.map((p) => {
365
375
  const syntax = p.syntax ? `: ${linkedSyntax(p.syntax)}` : "";
@@ -372,6 +382,7 @@ const record = {
372
382
  list("layers", "layers", "Layers", entry.layers.map((l) => `- ${styled(l.name, "class")}${dash(l.description)}`));
373
383
  list("conditions", "filter", "Conditions", entry.conditions.map((c) => `- \`@${c.type} ${c.query}\`${dash(c.description)}`));
374
384
  list("see", "references", "See also", entry.see.map((s) => `- ${s}`));
385
+ list("todos", "checklist", "To do", entry.todos.map((t) => `- ${t}`));
375
386
  {
376
387
  const w = want("structure", Boolean(entry.structure?.length));
377
388
  if (w !== "skip") {
@@ -645,13 +656,16 @@ const customProperty = {
645
656
  documentation: property.description
646
657
  }));
647
658
  },
648
- hover(name, index) {
659
+ hover(name, index, valueIndex = index) {
649
660
  const found = findProperty(index, name);
650
- if (!found) return void 0;
651
- const p = found.record.entry.cssPropertiesDeclared[found.index];
652
- const lines = [`\`${p.name}\`${p.syntax ? ` — ${linkedSyntax(p.syntax)}` : ""}`];
653
- if (p.defaultValue) lines.push("", `Default: \`${p.defaultValue}\``);
654
- if (p.description) lines.push("", p.description);
661
+ const { declared, resolved } = valueIndex.resolveCustomProperty(name);
662
+ if (!found && declared === void 0) return void 0;
663
+ const p = found?.record.entry.cssPropertiesDeclared[found.index];
664
+ const lines = [`\`${name}\`${p?.syntax ? ` — ${linkedSyntax(p.syntax)}` : ""}`];
665
+ const value = declared ?? p?.defaultValue;
666
+ if (value) lines.push("", `Value: \`${value}\``);
667
+ if (resolved) lines.push("", `Resolves to: \`${resolved}\``);
668
+ if (p?.description) lines.push("", p.description);
655
669
  return { contents: lines.join("\n") };
656
670
  },
657
671
  definition(name, index) {
@@ -851,9 +865,12 @@ function completeFunctions(index) {
851
865
  function hoverForClass(base, token, index, detail = "full", sections, sectionOrder) {
852
866
  return modifier.hover(base, token, index) ?? record.hover(base, index, detail, sections, sectionOrder);
853
867
  }
854
- /** Hover for a `var(--…)` custom property. */
855
- function hoverForCustomProperty(name, index) {
856
- return customProperty.hover(name, index);
868
+ /**
869
+ * Hover for a `var(--…)` custom property. `valueIndex` (default `index`) supplies the value graph for
870
+ * `var()` resolution — pass a project-wide index so a chain that runs through other sheets resolves.
871
+ */
872
+ function hoverForCustomProperty(name, index, valueIndex = index) {
873
+ return customProperty.hover(name, index, valueIndex);
857
874
  }
858
875
  /** Hover for a custom function. */
859
876
  function hoverForFunction(name, index) {
@@ -872,4 +889,4 @@ function definitionForFunction(name, index) {
872
889
  return func.definition(name, index);
873
890
  }
874
891
  //#endregion
875
- export { ASPECTS, DEFAULT_RULE_SEVERITIES, HOVER_SECTION_KEYS, NAME_CASE_PRESETS, applyDirectives, checkClassUsage, checkPropertyAssignments, checkPropertyUsage, completeClasses, completeCustomProperties, completeFunctions, cssPart, customProperty, definitionForClass, definitionForCustomProperty, definitionForFunction, func, hoverForClass, hoverForCustomProperty, hoverForFunction, linkSyntax, lintModel, matchesSyntax, mdnUrlForType, modifier, parseDirectives, part, partUsage, record, resolveNaming, resolveRuleSeverities, stateUsage };
892
+ export { ASPECTS, DEFAULT_RULE_SEVERITIES, HOVER_SECTION_KEYS, NAME_CASE_PRESETS, applyDirectives, checkClassUsage, checkPropertyAssignments, checkPropertyUsage, completeClasses, completeCustomProperties, completeFunctions, cssPart, customProperty, definitionForClass, definitionForCustomProperty, definitionForFunction, func, hoverForClass, hoverForCustomProperty, hoverForFunction, linkSyntax, lintModel, matchesSyntax, mdnUrlForType, modifier, parseDirectives, part, partUsage, record, resolveNaming, resolveRuleSeverities, selectorDefines, stateUsage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssdoc/providers",
3
- "version": "0.5.4",
3
+ "version": "0.6.1",
4
4
  "description": "Host-agnostic aspect providers over the @cssdoc/index — diagnostics, completions, hover, and definitions for modifiers, custom properties, structure, functions, states, and conditions.",
5
5
  "keywords": [
6
6
  "css",
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "css-tree": "^3.2.1",
32
- "@cssdoc/core": "0.5.4",
33
- "@cssdoc/index": "0.5.4"
32
+ "@cssdoc/core": "0.6.1",
33
+ "@cssdoc/index": "0.6.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/css-tree": "^2.3.11",