@cssdoc/providers 0.5.3 → 0.6.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.
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
  ];
@@ -262,6 +264,10 @@ const record = {
262
264
  ...info.entry.modifiers.map((m) => m.name),
263
265
  ...info.entry.slots.map((s) => s.name)
264
266
  ]);
267
+ const selfClass = stripDot(info.entry.className);
268
+ const classesOf = (sel) => [...sel.matchAll(/\.([\w-]+)/gu)].map((m) => m[1]);
269
+ const hasSelfBelow = (nodes) => nodes.some((n) => classesOf(n.selector).includes(selfClass) || hasSelfBelow(n.children));
270
+ for (const root of info.entry.structure) if (hasSelfBelow(root.children)) for (const c of classesOf(root.selector)) known.add(c);
265
271
  const own = stripDot(info.entry.className);
266
272
  const prefix = info.entry.name && own.endsWith(info.entry.name) ? own.slice(0, own.length - info.entry.name.length) : "";
267
273
  const isSibling = (cls) => prefix !== "" && cls.startsWith(prefix) && siblingNames.has(cls.slice(prefix.length));
@@ -317,6 +323,7 @@ const record = {
317
323
  entry.modifiers.length && `${entry.modifiers.length} modifiers`,
318
324
  entry.parts.length && `${entry.parts.length} parts`,
319
325
  entry.shadowParts.length && `${entry.shadowParts.length} shadow parts`,
326
+ entry.pseudoElements.length && `${entry.pseudoElements.length} pseudo-elements`,
320
327
  entry.states.length && `${entry.states.length} states`,
321
328
  entry.cssPropertiesDeclared.length && `${entry.cssPropertiesDeclared.length} custom properties`,
322
329
  entry.functions.length && `${entry.functions.length} functions`,
@@ -360,6 +367,7 @@ const record = {
360
367
  }));
361
368
  list("parts", "symbol-field", "Parts", entry.parts.map((p) => `- ${styled(`.${p.name}`, "field")}${dash(p.description)}`));
362
369
  list("shadowParts", "symbol-namespace", "Shadow parts", entry.shadowParts.map((p) => `- ${styled(`::part(${p.name})`, "field")}${dash(p.description)}`));
370
+ list("pseudoElements", "symbol-misc", "Pseudo-elements", entry.pseudoElements.map((p) => `- ${styled(`::${p.name}`, "field")}${dash(p.description)}`));
363
371
  list("states", "symbol-event", "States", entry.states.map((s) => `- ${styled(s.kind === "custom" ? `:state(${s.name})` : `:${s.name}`, "variable")}${dash(s.description)}`));
364
372
  list("customProperties", "symbol-variable", "Custom properties", entry.cssPropertiesDeclared.map((p) => {
365
373
  const syntax = p.syntax ? `: ${linkedSyntax(p.syntax)}` : "";
@@ -372,6 +380,7 @@ const record = {
372
380
  list("layers", "layers", "Layers", entry.layers.map((l) => `- ${styled(l.name, "class")}${dash(l.description)}`));
373
381
  list("conditions", "filter", "Conditions", entry.conditions.map((c) => `- \`@${c.type} ${c.query}\`${dash(c.description)}`));
374
382
  list("see", "references", "See also", entry.see.map((s) => `- ${s}`));
383
+ list("todos", "checklist", "To do", entry.todos.map((t) => `- ${t}`));
375
384
  {
376
385
  const w = want("structure", Boolean(entry.structure?.length));
377
386
  if (w !== "skip") {
@@ -389,7 +398,7 @@ const record = {
389
398
  const frag = ["", `**$(book) Example${entry.examples.length > 1 ? "s" : ""}**`];
390
399
  if (w === "content") for (const e of entry.examples) {
391
400
  const ex = e.trim();
392
- frag.push("", ex.startsWith("```") ? ex : `\`\`\`${ex.includes("<") ? "html" : "css"}\n${ex}\n\`\`\``);
401
+ frag.push("", /(^|\n)\s*```/u.test(ex) ? ex : `\`\`\`${ex.includes("<") ? "html" : "css"}\n${ex}\n\`\`\``);
393
402
  }
394
403
  else frag.push("", "_—_");
395
404
  fragments.examples = frag;
@@ -645,13 +654,16 @@ const customProperty = {
645
654
  documentation: property.description
646
655
  }));
647
656
  },
648
- hover(name, index) {
657
+ hover(name, index, valueIndex = index) {
649
658
  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);
659
+ const { declared, resolved } = valueIndex.resolveCustomProperty(name);
660
+ if (!found && declared === void 0) return void 0;
661
+ const p = found?.record.entry.cssPropertiesDeclared[found.index];
662
+ const lines = [`\`${name}\`${p?.syntax ? ` — ${linkedSyntax(p.syntax)}` : ""}`];
663
+ const value = declared ?? p?.defaultValue;
664
+ if (value) lines.push("", `Value: \`${value}\``);
665
+ if (resolved) lines.push("", `Resolves to: \`${resolved}\``);
666
+ if (p?.description) lines.push("", p.description);
655
667
  return { contents: lines.join("\n") };
656
668
  },
657
669
  definition(name, index) {
@@ -851,9 +863,12 @@ function completeFunctions(index) {
851
863
  function hoverForClass(base, token, index, detail = "full", sections, sectionOrder) {
852
864
  return modifier.hover(base, token, index) ?? record.hover(base, index, detail, sections, sectionOrder);
853
865
  }
854
- /** Hover for a `var(--…)` custom property. */
855
- function hoverForCustomProperty(name, index) {
856
- return customProperty.hover(name, index);
866
+ /**
867
+ * Hover for a `var(--…)` custom property. `valueIndex` (default `index`) supplies the value graph for
868
+ * `var()` resolution — pass a project-wide index so a chain that runs through other sheets resolves.
869
+ */
870
+ function hoverForCustomProperty(name, index, valueIndex = index) {
871
+ return customProperty.hover(name, index, valueIndex);
857
872
  }
858
873
  /** Hover for a custom function. */
859
874
  function hoverForFunction(name, index) {
@@ -872,4 +887,4 @@ function definitionForFunction(name, index) {
872
887
  return func.definition(name, index);
873
888
  }
874
889
  //#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 };
890
+ 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.3",
3
+ "version": "0.6.0",
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.3",
33
- "@cssdoc/index": "0.5.3"
32
+ "@cssdoc/index": "0.6.0",
33
+ "@cssdoc/core": "0.6.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/css-tree": "^2.3.11",