@cssdoc/core 0.5.0 → 0.5.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.
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as CssState, B as ModifierMatcher, C as CssPart, D as CssReleaseStage, E as CssRelated, F as DEFAULT_STATE_PSEUDO_CLASSES, I as MODIFIER_PRESETS, L as ModifierConvention, M as ParseOptions, N as StructureNode, O as CssSlot, P as DEFAULT_MODIFIER_CONVENTION, R as ModifierConventionInput, S as CssParse, T as CssRecordKind, V as resolveModifierConvention, _ as CssCondition, a as DocModifier, b as CssLayer, c as parseDocComment, d as stripCommentFraming, f as CssDocConfiguration, g as CssAnimation, h as CssDocTagDefinitionOptions, i as DocCssProperty, j as CssTokenConsumed, k as CssSource, l as parseStructure, m as CssDocTagDefinition, n as toMermaid, o as ParsedDoc, p as CssDocSyntaxKind, r as DocCondition, s as RECORD_TAGS, t as toJson, u as recordNameOf, v as CssDocEntry, w as CssPropertyDeclared, x as CssModifier, y as CssFunction, z as ModifierHit } from "./lite-
|
|
1
|
+
import { A as CssState, B as ModifierMatcher, C as CssPart, D as CssReleaseStage, E as CssRelated, F as DEFAULT_STATE_PSEUDO_CLASSES, I as MODIFIER_PRESETS, L as ModifierConvention, M as ParseOptions, N as StructureNode, O as CssSlot, P as DEFAULT_MODIFIER_CONVENTION, R as ModifierConventionInput, S as CssParse, T as CssRecordKind, V as resolveModifierConvention, _ as CssCondition, a as DocModifier, b as CssLayer, c as parseDocComment, d as stripCommentFraming, f as CssDocConfiguration, g as CssAnimation, h as CssDocTagDefinitionOptions, i as DocCssProperty, j as CssTokenConsumed, k as CssSource, l as parseStructure, m as CssDocTagDefinition, n as toMermaid, o as ParsedDoc, p as CssDocSyntaxKind, r as DocCondition, s as RECORD_TAGS, t as toJson, u as recordNameOf, v as CssDocEntry, w as CssPropertyDeclared, x as CssModifier, y as CssFunction, z as ModifierHit } from "./lite-DtKEwRkS.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/parse.d.ts
|
|
4
4
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as parseStructure, c as CssDocConfiguration, d as DEFAULT_STATE_PSEUDO_CLASSES, f as MODIFIER_PRESETS, i as parseDocComment, l as CssDocTagDefinition, m as resolveModifierConvention, n as toMermaid, o as recordNameOf, p as ModifierMatcher, r as RECORD_TAGS, s as stripCommentFraming, t as toJson, u as DEFAULT_MODIFIER_CONVENTION } from "./lite-
|
|
1
|
+
import { a as parseStructure, c as CssDocConfiguration, d as DEFAULT_STATE_PSEUDO_CLASSES, f as MODIFIER_PRESETS, i as parseDocComment, l as CssDocTagDefinition, m as resolveModifierConvention, n as toMermaid, o as recordNameOf, p as ModifierMatcher, r as RECORD_TAGS, s as stripCommentFraming, t as toJson, u as DEFAULT_MODIFIER_CONVENTION } from "./lite-HEYG01Eo.mjs";
|
|
2
2
|
import postcss from "postcss";
|
|
3
3
|
//#region src/parse.ts
|
|
4
4
|
/**
|
|
@@ -715,26 +715,48 @@ declare function recordNameOf(commentText: string, configuration?: CssDocConfigu
|
|
|
715
715
|
declare function parseStructure(raw: string, parse?: CssParse): StructureNode[];
|
|
716
716
|
//#endregion
|
|
717
717
|
//#region src/mermaid.d.ts
|
|
718
|
+
/** Resolve a bare class name (no leading dot) to the sibling component it is the base class of. */
|
|
719
|
+
type ResolveStructureComponent = (className: string) => {
|
|
720
|
+
name: string;
|
|
721
|
+
href?: string;
|
|
722
|
+
} | undefined;
|
|
723
|
+
/** Options for {@link toMermaid}. */
|
|
724
|
+
interface MermaidOptions {
|
|
725
|
+
/** Flowchart orientation (default `"TD"`, top-down). */
|
|
726
|
+
direction?: "TD" | "LR";
|
|
727
|
+
/**
|
|
728
|
+
* The current record's base class, no leading dot (e.g. `alert`). Its top-level node renders as the
|
|
729
|
+
* diagram root; a descendant that references the same class stays a part, never a sibling component.
|
|
730
|
+
*/
|
|
731
|
+
self?: string;
|
|
732
|
+
/**
|
|
733
|
+
* Classify a bare class as a *sibling component* — a child that is itself a documented record. Such
|
|
734
|
+
* nodes get the stadium shape, are labelled by component name, and (when an `href` is returned) link
|
|
735
|
+
* to that component's page. Absent → every non-slot, non-root node is a plain part.
|
|
736
|
+
*/
|
|
737
|
+
resolveComponent?: ResolveStructureComponent;
|
|
738
|
+
}
|
|
718
739
|
/**
|
|
719
740
|
* Convert a structure tree to a Mermaid `flowchart` definition. Each node gets a stable id (`n0`, `n1`,
|
|
720
|
-
* …) in depth-first order;
|
|
741
|
+
* …) in depth-first order; a parent connects to each child with an edge carrying the child's
|
|
742
|
+
* cardinality. Nodes are shaped + classed by kind ({@link classify}); sibling components with an href
|
|
743
|
+
* get a `click` link.
|
|
721
744
|
*
|
|
722
745
|
* @param roots - Top-level {@link StructureNode}s (an authored `@structure`).
|
|
723
|
-
* @param options -
|
|
746
|
+
* @param options - {@link MermaidOptions}.
|
|
724
747
|
* @returns Mermaid source, or an empty string when there are no nodes.
|
|
725
748
|
*
|
|
726
749
|
* @example
|
|
727
750
|
* ```ts
|
|
728
|
-
* toMermaid([{ selector: ".tabs", children: [{ selector: ".panel", children: [] }] }]);
|
|
751
|
+
* toMermaid([{ selector: ".tabs", children: [{ selector: ".panel", cardinality: "many", children: [] }] }]);
|
|
729
752
|
* // flowchart TD
|
|
730
|
-
* // n0[".tabs"]
|
|
731
|
-
* // n1
|
|
732
|
-
* // n0
|
|
753
|
+
* // n0[".tabs"]:::cssdoc-root
|
|
754
|
+
* // n1(".panel"):::cssdoc-part
|
|
755
|
+
* // n0 -->|0..n| n1
|
|
756
|
+
* // classDef cssdoc-root …
|
|
733
757
|
* ```
|
|
734
758
|
*/
|
|
735
|
-
declare function toMermaid(roots: StructureNode[], options?:
|
|
736
|
-
direction?: "TD" | "LR";
|
|
737
|
-
}): string;
|
|
759
|
+
declare function toMermaid(roots: StructureNode[], options?: MermaidOptions): string;
|
|
738
760
|
//#endregion
|
|
739
761
|
//#region src/lite.d.ts
|
|
740
762
|
/**
|
|
@@ -819,50 +819,103 @@ function parseStructure(raw, parse) {
|
|
|
819
819
|
}
|
|
820
820
|
//#endregion
|
|
821
821
|
//#region src/mermaid.ts
|
|
822
|
-
|
|
823
|
-
optional: " (optional)",
|
|
824
|
-
many: " (0..n)",
|
|
825
|
-
"one-or-more": " (1..n)"
|
|
826
|
-
};
|
|
822
|
+
/** Match a `slot` / `slot[name="x"]` node (a light-DOM content region → the default/named slot). */
|
|
827
823
|
const SLOT_NODE = /^slot(?:\[\s*name\s*=\s*["']?([\w-]+)["']?\s*\])?$/u;
|
|
828
|
-
/**
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return `"${`${slot ? slot[1] ? `‹content: ${slot[1]}›` : "‹content›" : node.selector}${node.cardinality ? CARDINALITY_LABEL[node.cardinality] : ""}`.replace(/"/gu, """)}"`;
|
|
824
|
+
/** The child edge for each cardinality (dashed + `0..1` for optional; a count label for the ranges). */
|
|
825
|
+
const EDGE = {
|
|
826
|
+
required: "-->",
|
|
827
|
+
optional: "-.->|0..1|",
|
|
828
|
+
many: "-->|0..n|",
|
|
829
|
+
"one-or-more": "-->|1..n|"
|
|
835
830
|
};
|
|
831
|
+
/** Wrap a node's label in the shape mermaid draws for its class. */
|
|
832
|
+
const SHAPE = {
|
|
833
|
+
"cssdoc-root": (id, l) => `${id}["${l}"]`,
|
|
834
|
+
"cssdoc-part": (id, l) => `${id}("${l}")`,
|
|
835
|
+
"cssdoc-slot": (id, l) => `${id}[/"${l}"/]`,
|
|
836
|
+
"cssdoc-component": (id, l) => `${id}(["${l}"])`
|
|
837
|
+
};
|
|
838
|
+
/** The classDef palette — a readable standalone default; hosts restyle by class name. */
|
|
839
|
+
const CLASS_DEFS = [
|
|
840
|
+
"classDef cssdoc-root fill:#eef2ff,stroke:#6366f1,color:#1e1b4b;",
|
|
841
|
+
"classDef cssdoc-part fill:#f8fafc,stroke:#94a3b8,color:#0f172a;",
|
|
842
|
+
"classDef cssdoc-slot fill:#f0fdf4,stroke:#4ade80,color:#14532d;",
|
|
843
|
+
"classDef cssdoc-component fill:#fff7ed,stroke:#fb923c,color:#7c2d12;"
|
|
844
|
+
];
|
|
845
|
+
/** The leading bare class of a compound selector, e.g. `.item.-selected` → `item`. */
|
|
846
|
+
const firstClass = (selector) => selector.match(/\.([\w-]+)/u)?.[1];
|
|
847
|
+
/** Escape a label for a quoted Mermaid node body. */
|
|
848
|
+
const esc = (text) => text.replace(/"/gu, """);
|
|
849
|
+
/** Classify one node: slot → root → sibling component → plain part. */
|
|
850
|
+
function classify(node, isRoot, options) {
|
|
851
|
+
const slot = node.selector.match(SLOT_NODE);
|
|
852
|
+
if (slot) return {
|
|
853
|
+
klass: "cssdoc-slot",
|
|
854
|
+
label: slot[1] ? `‹content: ${slot[1]}›` : "‹content›"
|
|
855
|
+
};
|
|
856
|
+
if (isRoot) return {
|
|
857
|
+
klass: "cssdoc-root",
|
|
858
|
+
label: node.selector
|
|
859
|
+
};
|
|
860
|
+
const primary = firstClass(node.selector);
|
|
861
|
+
if (primary && primary !== options.self) {
|
|
862
|
+
const component = options.resolveComponent?.(primary);
|
|
863
|
+
if (component) return {
|
|
864
|
+
klass: "cssdoc-component",
|
|
865
|
+
label: component.name,
|
|
866
|
+
href: component.href
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
klass: "cssdoc-part",
|
|
871
|
+
label: node.selector
|
|
872
|
+
};
|
|
873
|
+
}
|
|
836
874
|
/**
|
|
837
875
|
* Convert a structure tree to a Mermaid `flowchart` definition. Each node gets a stable id (`n0`, `n1`,
|
|
838
|
-
* …) in depth-first order;
|
|
876
|
+
* …) in depth-first order; a parent connects to each child with an edge carrying the child's
|
|
877
|
+
* cardinality. Nodes are shaped + classed by kind ({@link classify}); sibling components with an href
|
|
878
|
+
* get a `click` link.
|
|
839
879
|
*
|
|
840
880
|
* @param roots - Top-level {@link StructureNode}s (an authored `@structure`).
|
|
841
|
-
* @param options -
|
|
881
|
+
* @param options - {@link MermaidOptions}.
|
|
842
882
|
* @returns Mermaid source, or an empty string when there are no nodes.
|
|
843
883
|
*
|
|
844
884
|
* @example
|
|
845
885
|
* ```ts
|
|
846
|
-
* toMermaid([{ selector: ".tabs", children: [{ selector: ".panel", children: [] }] }]);
|
|
886
|
+
* toMermaid([{ selector: ".tabs", children: [{ selector: ".panel", cardinality: "many", children: [] }] }]);
|
|
847
887
|
* // flowchart TD
|
|
848
|
-
* // n0[".tabs"]
|
|
849
|
-
* // n1
|
|
850
|
-
* // n0
|
|
888
|
+
* // n0[".tabs"]:::cssdoc-root
|
|
889
|
+
* // n1(".panel"):::cssdoc-part
|
|
890
|
+
* // n0 -->|0..n| n1
|
|
891
|
+
* // classDef cssdoc-root …
|
|
851
892
|
* ```
|
|
852
893
|
*/
|
|
853
894
|
function toMermaid(roots, options = {}) {
|
|
854
895
|
if (!roots.length) return "";
|
|
855
|
-
const
|
|
896
|
+
const nodes = [];
|
|
856
897
|
const edges = [];
|
|
898
|
+
const links = [];
|
|
857
899
|
let counter = 0;
|
|
858
|
-
const walk = (node) => {
|
|
900
|
+
const walk = (node, isRoot) => {
|
|
859
901
|
const id = `n${counter++}`;
|
|
860
|
-
|
|
861
|
-
|
|
902
|
+
const { klass, label, href } = classify(node, isRoot, options);
|
|
903
|
+
nodes.push(` ${SHAPE[klass](id, esc(label))}:::${klass}`);
|
|
904
|
+
if (href) links.push(` click ${id} "${href}"`);
|
|
905
|
+
for (const child of node.children) {
|
|
906
|
+
const childId = walk(child, false);
|
|
907
|
+
edges.push(` ${id} ${EDGE[child.cardinality ?? "required"]} ${childId}`);
|
|
908
|
+
}
|
|
862
909
|
return id;
|
|
863
910
|
};
|
|
864
|
-
for (const root of roots) walk(root);
|
|
865
|
-
return [
|
|
911
|
+
for (const root of roots) walk(root, true);
|
|
912
|
+
return [
|
|
913
|
+
`flowchart ${options.direction ?? "TD"}`,
|
|
914
|
+
...nodes,
|
|
915
|
+
...edges,
|
|
916
|
+
...links,
|
|
917
|
+
...CLASS_DEFS.map((d) => ` ${d}`)
|
|
918
|
+
].join("\n");
|
|
866
919
|
}
|
|
867
920
|
//#endregion
|
|
868
921
|
//#region src/lite.ts
|
package/dist/lite.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as CssState, B as ModifierMatcher, C as CssPart, D as CssReleaseStage, E as CssRelated, F as DEFAULT_STATE_PSEUDO_CLASSES, I as MODIFIER_PRESETS, L as ModifierConvention, M as ParseOptions, N as StructureNode, O as CssSlot, P as DEFAULT_MODIFIER_CONVENTION, R as ModifierConventionInput, S as CssParse, T as CssRecordKind, V as resolveModifierConvention, _ as CssCondition, a as DocModifier, b as CssLayer, c as parseDocComment, d as stripCommentFraming, f as CssDocConfiguration, g as CssAnimation, h as CssDocTagDefinitionOptions, i as DocCssProperty, j as CssTokenConsumed, k as CssSource, l as parseStructure, m as CssDocTagDefinition, n as toMermaid, o as ParsedDoc, p as CssDocSyntaxKind, r as DocCondition, s as RECORD_TAGS, t as toJson, u as recordNameOf, v as CssDocEntry, w as CssPropertyDeclared, x as CssModifier, y as CssFunction, z as ModifierHit } from "./lite-
|
|
1
|
+
import { A as CssState, B as ModifierMatcher, C as CssPart, D as CssReleaseStage, E as CssRelated, F as DEFAULT_STATE_PSEUDO_CLASSES, I as MODIFIER_PRESETS, L as ModifierConvention, M as ParseOptions, N as StructureNode, O as CssSlot, P as DEFAULT_MODIFIER_CONVENTION, R as ModifierConventionInput, S as CssParse, T as CssRecordKind, V as resolveModifierConvention, _ as CssCondition, a as DocModifier, b as CssLayer, c as parseDocComment, d as stripCommentFraming, f as CssDocConfiguration, g as CssAnimation, h as CssDocTagDefinitionOptions, i as DocCssProperty, j as CssTokenConsumed, k as CssSource, l as parseStructure, m as CssDocTagDefinition, n as toMermaid, o as ParsedDoc, p as CssDocSyntaxKind, r as DocCondition, s as RECORD_TAGS, t as toJson, u as recordNameOf, v as CssDocEntry, w as CssPropertyDeclared, x as CssModifier, y as CssFunction, z as ModifierHit } from "./lite-DtKEwRkS.mjs";
|
|
2
2
|
export { type CssAnimation, type CssCondition, CssDocConfiguration, type CssDocEntry, type CssDocSyntaxKind, CssDocTagDefinition, type CssDocTagDefinitionOptions, type CssFunction, type CssLayer, type CssModifier, type CssParse, type CssPart, type CssPropertyDeclared, type CssRecordKind, type CssRelated, type CssReleaseStage, type CssSlot, type CssSource, type CssState, type CssTokenConsumed, DEFAULT_MODIFIER_CONVENTION, DEFAULT_STATE_PSEUDO_CLASSES, type DocCondition, type DocCssProperty, type DocModifier, MODIFIER_PRESETS, type ModifierConvention, type ModifierConventionInput, type ModifierHit, ModifierMatcher, type ParseOptions, type ParsedDoc, RECORD_TAGS, type StructureNode, parseDocComment, parseStructure, recordNameOf, resolveModifierConvention, stripCommentFraming, toJson, toMermaid };
|
package/dist/lite.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as parseStructure, c as CssDocConfiguration, d as DEFAULT_STATE_PSEUDO_CLASSES, f as MODIFIER_PRESETS, i as parseDocComment, l as CssDocTagDefinition, m as resolveModifierConvention, n as toMermaid, o as recordNameOf, p as ModifierMatcher, r as RECORD_TAGS, s as stripCommentFraming, t as toJson, u as DEFAULT_MODIFIER_CONVENTION } from "./lite-
|
|
1
|
+
import { a as parseStructure, c as CssDocConfiguration, d as DEFAULT_STATE_PSEUDO_CLASSES, f as MODIFIER_PRESETS, i as parseDocComment, l as CssDocTagDefinition, m as resolveModifierConvention, n as toMermaid, o as recordNameOf, p as ModifierMatcher, r as RECORD_TAGS, s as stripCommentFraming, t as toJson, u as DEFAULT_MODIFIER_CONVENTION } from "./lite-HEYG01Eo.mjs";
|
|
2
2
|
export { CssDocConfiguration, CssDocTagDefinition, DEFAULT_MODIFIER_CONVENTION, DEFAULT_STATE_PSEUDO_CLASSES, MODIFIER_PRESETS, ModifierMatcher, RECORD_TAGS, parseDocComment, parseStructure, recordNameOf, resolveModifierConvention, stripCommentFraming, toJson, toMermaid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssdoc/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "A generic CSS documentation extractor: parse doc-comments + the CSS AST into a serializable model (TSDoc, for CSS).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"postcss": "^8.5.17",
|
|
36
|
-
"@cssdoc/spec": "0.5.
|
|
36
|
+
"@cssdoc/spec": "0.5.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^24.13.3",
|