sveld 0.37.9 → 0.38.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.
@@ -1,7 +1,3 @@
1
- import type { Node, Property } from "estree";
2
-
3
- import type { FunctionDeclaration, VariableDeclaration } from "estree";
4
-
5
1
  declare const brand: unique symbol;
6
2
 
7
3
  type Brand<TBase extends string, TBrand extends string> = TBase & {
@@ -12,6 +8,49 @@ export type NormalizedPath = Brand<string, "NormalizedPath">;
12
8
 
13
9
  export declare function asNormalizedPath(path: string): NormalizedPath;
14
10
 
11
+ interface ComponentParserDiagnostics {
12
+ moduleName: string;
13
+ filePath: string;
14
+ }
15
+
16
+ export class ComponentParser {
17
+ /**
18
+ * All per-parse mutable state (props, slots, events, scopes, source, etc.).
19
+ * See {@link ParserContext} for field-by-field documentation. Replaced
20
+ * wholesale by `cleanup()` between parses.
21
+ */
22
+ private ctx;
23
+ /**
24
+ * Resets parser state for reuse between parses.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * parser.parseSvelteComponent(source1, diagnostics1);
29
+ * parser.cleanup();
30
+ * parser.parseSvelteComponent(source2, diagnostics2);
31
+ * ```
32
+ */
33
+ cleanup(): void;
34
+ /**
35
+ * @example
36
+ * ```ts
37
+ * const parser = new ComponentParser();
38
+ * const result = parser.parseSvelteComponent(source, {
39
+ * moduleName: "Button",
40
+ * filePath: "./Button.svelte"
41
+ * });
42
+ * // { props, slots, events, typedefs, ... }
43
+ * ```
44
+ */
45
+ parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
46
+ /**
47
+ * Like {@link parseSvelteComponent}, but returns the candidates only a
48
+ * pass with file access can resolve beside the component rather than
49
+ * inside its metadata.
50
+ */
51
+ parse(source: string, diagnostics: ComponentParserDiagnostics): ComponentParseResult;
52
+ }
53
+
15
54
  interface JsDocPassthroughTag {
16
55
  name: string;
17
56
  body: string;
@@ -84,31 +123,18 @@ interface PendingDispatchEscapeCandidate {
84
123
  ignored?: boolean;
85
124
  }
86
125
 
87
- interface ParsedComponentTypeScriptMetadata {
88
- canonicalPropsType?: string;
89
- canonicalPropNames: string[];
90
- localTypeDeclarations: string[];
91
- /** Types the module script exports (`export interface Item`), emitted with `export`. */
92
- moduleTypeDeclarations?: string[];
93
- typeImportStatements: string[];
94
- /**
95
- * Whether `canonicalPropsType` mentions one of the component's own
96
- * `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
97
- * resolver has no binding for `T`, so `resolveTypes` must leave this
98
- * component's props as their AST-derived text rather than expand them.
99
- */
100
- referencesComponentGenerics?: boolean;
101
- /** Unresolved CallExpression defaults for the cross-file pass in `generateBundle`. */
126
+ interface PendingCrossFileCandidates {
127
+ /** Unresolved CallExpression defaults. */
102
128
  pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
103
- /** Imported-identifier defaults for the cross-file pass in `generateBundle`. */
129
+ /** Imported-identifier defaults. */
104
130
  pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
105
- /** Unresolved `setContext` import keys for the cross-file pass in `generateBundle`. */
131
+ /** Unresolved `setContext` import keys. */
106
132
  pendingContextKeyCandidates?: PendingContextKeyCandidate[];
107
- /** Dispatchers passed to imported functions, for the cross-file pass in `generateBundle`. */
133
+ /** Dispatchers passed to imported functions. */
108
134
  pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
109
135
  /**
110
136
  * `event-no-source` diagnostics held back while the dispatcher escapes to
111
- * imported functions: `generateBundle` keeps those the functions don't dispatch.
137
+ * imported functions: the cross-file pass keeps those the functions don't dispatch.
112
138
  */
113
139
  deferredEventNoSourceDiagnostics?: SveldDiagnostic[];
114
140
  /**
@@ -118,6 +144,21 @@ interface ParsedComponentTypeScriptMetadata {
118
144
  untypedJsDocEventNames?: string[];
119
145
  }
120
146
 
147
+ interface ParsedComponentTypeScriptMetadata extends PendingCrossFileCandidates {
148
+ canonicalPropsType?: string;
149
+ canonicalPropNames: string[];
150
+ localTypeDeclarations: string[];
151
+ /** Types the module script exports (`export interface Item`), emitted with `export`. */
152
+ moduleTypeDeclarations?: string[];
153
+ typeImportStatements: string[];
154
+ }
155
+
156
+ interface ComponentParseResult {
157
+ component: ParsedComponent;
158
+ /** Undefined when the component depends on no other file's contents. */
159
+ pending?: PendingCrossFileCandidates;
160
+ }
161
+
121
162
  type SyntaxMode = "legacy" | "runes";
122
163
 
123
164
  type ScriptLanguage = "js" | "ts";
@@ -132,25 +173,6 @@ interface ComponentPropDefaultValue {
132
173
  value?: unknown;
133
174
  }
134
175
 
135
- type ModernScriptAttribute = {
136
- name?: string;
137
- value?: Array<{
138
- data?: string;
139
- raw?: string;
140
- }> | boolean;
141
- start?: number;
142
- end?: number;
143
- };
144
-
145
- type ModernScriptNode = {
146
- attributes?: ModernScriptAttribute[];
147
- };
148
-
149
- interface ComponentParserDiagnostics {
150
- moduleName: string;
151
- filePath: string;
152
- }
153
-
154
176
  type ComponentPropBinding = "readonly" | "writable";
155
177
 
156
178
  interface ComponentPropParam {
@@ -489,154 +511,7 @@ interface ParsedComponent {
489
511
  [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
490
512
  }
491
513
 
492
- export class ComponentParser {
493
- /**
494
- * All per-parse mutable state (props, slots, events, scopes, source, etc.).
495
- * See {@link ParserContext} for field-by-field documentation. Replaced
496
- * wholesale by `cleanup()` between parses.
497
- */
498
- private ctx;
499
- private static mapToArray;
500
- private static getStaticAttributeValue;
501
- resolveScriptLanguage(parsed: {
502
- instance?: ModernScriptNode;
503
- module?: ModernScriptNode;
504
- }): ScriptLanguage | undefined;
505
- /**
506
- * Reads the `generics` attribute off the instance script (Svelte only allows
507
- * it there, and only alongside `lang="ts"`). Returns the raw value for later
508
- * precedence resolution against `@generics`/`@template` JSDoc tags, or
509
- * `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
510
- * `undefined` if the attribute is present without `lang="ts"`, since sveld
511
- * can't safely guess how to parse it as plain JavaScript.
512
- */
513
- resolveScriptGenericsAttribute(parsed: {
514
- instance?: ModernScriptNode;
515
- }): {
516
- value: string;
517
- source?: SourceRange;
518
- } | undefined;
519
- private resolvePublicPropName;
520
- trackPropLocalName(propName: string, localName?: string): void;
521
- private getPropByLocalOrPublic;
522
- getPropTypeByLocalOrPublic(name: string): string | undefined;
523
- getExplicitPropType(name: string): string | undefined;
524
- getPropertyName(node: Property["key"]): string | undefined;
525
- isNumericConstant(memberExpr: unknown): boolean;
526
- resolveLocalVarJSDoc(name: string): {
527
- type?: string;
528
- params?: ComponentPropParam[];
529
- returnType?: string;
530
- description?: string;
531
- binding?: ComponentPropBinding;
532
- deprecated?: DeprecatedValue;
533
- tags?: JsDocPassthroughTag[];
534
- sveldIgnore?: string[];
535
- internal: boolean;
536
- typeParameters?: string;
537
- } | undefined;
538
- private addModuleExport;
539
- /**
540
- * Resolves one `export { local as exported }` specifier to the top-level
541
- * function, class, or variable declarator (including one destructured
542
- * from a pattern) it names. Each specifier resolves on its own, so
543
- * `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
544
- * exports `b`'s declarator rather than the first one in the declaration.
545
- *
546
- * `program` is the script the export sits in: only its top-level
547
- * declarations count, not a same-named variable inside a function. An
548
- * instance-script export can also name a module-script declaration, or a
549
- * variable that a `$: local = ...` reactive declaration declares implicitly.
550
- */
551
- private resolveExportSpecifier;
552
- private recordUnresolvedExportSpecifier;
553
- /**
554
- * Doc comment for a declaration exported by `node`. A specifier uses the
555
- * comment on the declaration it names. An `export { ... }` list's own
556
- * comment documents it too, but only when the list has a single specifier;
557
- * its tags and description then override the declaration's.
558
- */
559
- private exportJSDoc;
560
- /** An instance-script `export class Foo {}` or `export { Foo }` of a class: neither a prop nor a documented accessor. */
561
- private recordClassExport;
562
- /**
563
- * The `.d.ts` can only say `extends Base` when `Base` is in scope there:
564
- * imported, or another exported class. A class extending anything else
565
- * (a local class, a call like `mixin(Base)`) is declared without it, and
566
- * flagged, since consumers won't see its inherited members.
567
- */
568
- private dropUndeclaredClassBases;
569
- /** A module-script `export class Foo {}` or `export { Foo }` of a class, with its public members. */
570
- private addModuleClassExport;
571
- /**
572
- * @example
573
- * ```ts
574
- * aliasType("*"); // "any"
575
- * aliasType(" string "); // "string"
576
- * ```
577
- */
578
- aliasType(type: string): string;
579
- /**
580
- * @example
581
- * ```ts
582
- * // Given:
583
- * // /**
584
- * // * @type {number}
585
- * // * The count value
586
- * // *\/
587
- * // const count = 0;
588
- *
589
- * findVariableTypeAndDescription("count");
590
- * // { type: "number", description: "The count value" }
591
- * ```
592
- */
593
- findVariableTypeAndDescription(varName: string): {
594
- type: string;
595
- description?: string;
596
- internal?: boolean;
597
- } | null;
598
- /**
599
- * The description and `@internal` flag of the JSDoc above `varName`,
600
- * whether or not it has a `@type`. For a variable typed some other way,
601
- * such as from its initializer.
602
- */
603
- findVariableJsDoc(varName: string): {
604
- description?: string;
605
- internal?: boolean;
606
- };
607
- /** The JSDoc table entry for `varName`, building the table on first use. */
608
- private variableJsDocEntry;
609
- accumulateGeneric(name: string, constraint: string): void;
610
- /**
611
- * Resets parser state for reuse between parses.
612
- *
613
- * @example
614
- * ```ts
615
- * parser.parseSvelteComponent(source1, diagnostics1);
616
- * parser.cleanup();
617
- * parser.parseSvelteComponent(source2, diagnostics2);
618
- * ```
619
- */
620
- cleanup(): void;
621
- private static readonly SCRIPT_BLOCK_REGEX;
622
- /** A `// @ts-...` comment, but not one on a `*` line of a JSDoc block (e.g. in an `@example`). */
623
- private static readonly TS_DIRECTIVE_REGEX;
624
- private static stripTypeScriptDirectivesFromScripts;
625
- /**
626
- * @example
627
- * ```ts
628
- * const parser = new ComponentParser();
629
- * const result = parser.parseSvelteComponent(source, {
630
- * moduleName: "Button",
631
- * filePath: "./Button.svelte"
632
- * });
633
- * // { props, slots, events, typedefs, ... }
634
- * ```
635
- */
636
- parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
637
- }
638
-
639
- export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "types-inline-unresolved" | "cross-file-unresolved" | "export-ambiguous";
514
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "type-syntax-error" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "cross-file-unresolved" | "export-ambiguous";
640
515
 
641
516
  type SveldDiagnosticSeverity = "error" | "warning";
642
517
 
@@ -680,95 +555,6 @@ export interface ComponentDocApi extends ParsedComponent {
680
555
 
681
556
  export type ComponentDocs = Map<string, ComponentDocApi>;
682
557
 
683
- interface InlinedTypes {
684
- /** Exact `typeImportStatements` entries the writer must drop. */
685
- droppedImportStatements: string[];
686
- /** Declarations to emit (already stripped of `export`), in dependency order. */
687
- declarations: string[];
688
- /** Absolute paths of every file read, for watch-mode invalidation. */
689
- dependencies: string[];
690
- }
691
-
692
- type CommentLevel = "all" | "descriptions" | "none";
693
-
694
- export declare function formatTsProps(props?: string): string;
695
-
696
- export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">, emit?: {
697
- export: boolean;
698
- }, commentLevel?: CommentLevel): string;
699
-
700
- export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">, emit?: {
701
- export: boolean;
702
- }, commentLevel?: CommentLevel): string;
703
-
704
- export interface WriteTsDefinitionOptions {
705
- /**
706
- * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
707
- * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
708
- * instead, for Svelte 5+ consumers. Generic components get a per-component
709
- * interface with a generic call signature instead of `Component<...>`
710
- * directly, since a `declare const` can't itself carry a generic type
711
- * parameter (see `genGenericComponentDeclaration`).
712
- */
713
- format?: "class" | "component";
714
- /**
715
- * Which generated type declarations get an `export` keyword. `true`
716
- * (default) exports all; `false` exports none; an object picks per kind.
717
- * Module-script exports (`export declare const/function`) are runtime
718
- * exports and are always emitted as exports.
719
- */
720
- exportTypes?: boolean | {
721
- props?: boolean;
722
- exports?: boolean;
723
- typedefs?: boolean;
724
- contexts?: boolean;
725
- };
726
- /** @internal Set by `writeTsDefinitions` for `@extends` targets; overrides `exportTypes.props`. */
727
- forceExportProps?: boolean;
728
- /**
729
- * Templates for generated type names. `{name}` is replaced with the
730
- * component's module name. Defaults: `"{name}Props"`, `"{name}Exports"`.
731
- */
732
- typeNames?: {
733
- props?: string;
734
- exports?: string;
735
- };
736
- /**
737
- * How much JSDoc to emit. `"all"` (default) keeps descriptions,
738
- * `@deprecated`, `@default`, and passthrough tags (`@since`, `@see`,
739
- * `@example`, `@link`). `"descriptions"` keeps descriptions and
740
- * `@deprecated` only. `"none"` emits no comments at all.
741
- */
742
- comments?: "all" | "descriptions" | "none";
743
- /**
744
- * `"type"` (default) emits the props type as a type alias.
745
- * `"interface"` emits `interface <Name>Props { ... }` when the props are a
746
- * plain object (no `@restProps`, no `@extendProps`, no whole-object
747
- * `$props()` type); other shapes are intersections and stay aliases.
748
- */
749
- propsDeclaration?: "type" | "interface";
750
- /**
751
- * Copies `type`/`interface` declarations imported from a relative source (or a
752
- * tsconfig/jsconfig path alias) directly into the `.d.ts`, dropping the import. `"local"`
753
- * follows relative sources, path aliases, re-exports, and same-file dependencies; bare package
754
- * imports, `.svelte` sources, and unsupported exports (enums, classes, functions, consts,
755
- * namespaces) stay imports and get a `types-inline-unresolved` warning. `"all"` additionally
756
- * inlines bare/package imports (e.g. `import type { Foo } from "some-lib"`) using the real
757
- * TypeScript checker - same unsupported-export/collision rules, same warning on failure - with
758
- * two exceptions kept as plain imports regardless: `svelte`/`svelte/elements` (a hard-coded
759
- * allow-list; copying framework types would freeze a Svelte version into consumer output) and
760
- * `@extendProps`/`@extends` targets (deferred; unrelated mechanism). `"all"` needs `typescript`
761
- * 7+ and a `tsconfig.json`, same hard requirement as `resolveTypes`. `false` (default)
762
- * preserves every import as-is.
763
- * @default false
764
- */
765
- inline?: false | "local" | "all";
766
- /** @internal Set by `writeTsDefinitions` from `GenerateBundleResult.inlinedTypesByFilePath` when `inline` resolved something for this component. */
767
- inlined?: InlinedTypes;
768
- }
769
-
770
- export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
771
-
772
558
  interface EntryExport {
773
559
  name: string;
774
560
  kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
@@ -794,151 +580,28 @@ interface EntryExport {
794
580
 
795
581
  type EntryExports = EntryExport[];
796
582
 
797
- export interface CemType {
798
- text: string;
799
- }
800
-
801
- export interface CemClassField {
802
- kind: "field";
803
- name: string;
804
- type?: CemType;
805
- default?: string;
806
- description?: string;
807
- deprecated?: DeprecatedValue;
808
- /** Present, and `true`, for an `export const` prop. */
809
- readonly?: true;
810
- }
811
-
812
- interface CemParameter {
813
- name: string;
814
- type?: CemType;
815
- optional?: true;
816
- rest?: true;
817
- }
818
-
819
- interface CemClassMethod {
820
- kind: "method";
821
- name: string;
822
- static: boolean;
823
- parameters?: CemParameter[];
824
- return?: {
825
- type: CemType;
826
- };
827
- description?: string;
828
- deprecated?: DeprecatedValue;
829
- }
830
-
831
- export interface CemAttribute {
832
- name: string;
833
- fieldName: string;
834
- type?: CemType;
835
- default?: string;
836
- description?: string;
837
- /** Present, and `true`, when the prop's `customElement` config sets `reflect: true`. */
838
- reflects?: true;
839
- }
840
-
841
- interface CemCssPart {
842
- name: string;
843
- description?: string;
844
- }
845
-
846
- interface CemCssCustomProperty {
847
- /** Includes the leading `--`. */
848
- name: string;
849
- type?: CemType;
850
- default?: string;
851
- description?: string;
852
- }
853
-
854
- export interface CemEvent {
855
- name: string;
856
- type: CemType;
857
- description?: string;
858
- deprecated?: DeprecatedValue;
859
- }
860
-
861
- export interface CemSlot {
862
- name: string;
863
- description?: string;
864
- deprecated?: DeprecatedValue;
865
- }
866
-
867
- export interface CemClassDeclaration {
868
- kind: "class";
869
- name: string;
870
- description?: string;
871
- members: Array<CemClassField | CemClassMethod>;
872
- attributes: CemAttribute[];
873
- events: CemEvent[];
874
- slots: CemSlot[];
875
- /** From component-level `@csspart` JSDoc tags. */
876
- cssParts?: CemCssPart[];
877
- /** From component-level `@cssprop`/`@cssproperty` JSDoc tags. */
878
- cssProperties?: CemCssCustomProperty[];
879
- /** Only present when the source component sets `<svelte:options customElement="..." />`. */
880
- tagName?: string;
881
- /** Only present when the source component sets `<svelte:options customElement="..." />`. */
882
- customElement?: true;
883
- }
884
-
885
- export interface CemJavaScriptExport {
886
- kind: "js";
887
- name: string;
888
- declaration: {
889
- name: string;
890
- module: string;
891
- };
892
- }
583
+ export declare const COMPONENT_API_SCHEMA_VERSION = 1;
893
584
 
894
- export interface CemCustomElementExport {
895
- kind: "custom-element-definition";
896
- name: string;
897
- declaration: {
585
+ export interface ComponentApiDocument {
586
+ schemaVersion: 1;
587
+ generator: {
898
588
  name: string;
899
- module: string;
589
+ version: string;
590
+ svelteVersion: string;
900
591
  };
592
+ total: number;
593
+ components: ComponentDocApi[];
594
+ /** Only when `documentExports` is on. */
595
+ totalExports?: number;
596
+ exports?: EntryExports;
901
597
  }
902
598
 
903
- export type CemExport = CemJavaScriptExport | CemCustomElementExport;
904
-
905
- export interface CemModule {
906
- kind: "javascript-module";
907
- path: string;
908
- declarations: CemClassDeclaration[];
909
- exports: CemExport[];
910
- }
911
-
912
- export interface CustomElementsManifest {
913
- schemaVersion: "1.0.0";
914
- modules: CemModule[];
915
- }
916
-
917
- export interface BuildCustomElementsManifestOptions {
918
- /** Resolves each component's manifest `path`. Defaults to the component's `filePath` as-is. */
919
- resolveModulePath?: (component: ComponentDocApi) => string;
920
- }
921
-
922
- export declare function buildCustomElementsManifest(components: ComponentDocs, options?: BuildCustomElementsManifestOptions): CustomElementsManifest;
923
-
924
- type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
925
-
926
- interface MarkdownOptions {
927
- onAppend?: OnAppend;
599
+ export interface BuildComponentApiDocumentOptions {
600
+ /** Entry-barrel exports when `documentExports` is on. */
601
+ entryExports?: EntryExports;
928
602
  }
929
603
 
930
- declare class WriterMarkdown extends Writer {
931
- onAppend?: OnAppend;
932
- private markdownBase;
933
- constructor(options: MarkdownOptions);
934
- get source(): string;
935
- get hasToC(): boolean;
936
- get toc(): TocLine[];
937
- appendLineBreaks(): this;
938
- append(type: AppendType, raw?: string): this;
939
- tableOfContents(): this;
940
- end(): string;
941
- }
604
+ export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
942
605
 
943
606
  export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
944
607
 
@@ -948,21 +611,18 @@ export interface TocLine {
948
611
  raw: string;
949
612
  }
950
613
 
951
- export interface MarkdownWriterBase {
952
- sourceParts: string[];
953
- hasToC: boolean;
954
- toc: TocLine[];
955
- appendLineBreaks(): this;
956
- append(type: AppendType, raw?: string): this;
957
- tableOfContents(): this;
958
- end(): string;
959
- get source(): string;
614
+ type MarkdownAppendCallback = (type: AppendType, document: MarkdownDocument) => void;
615
+
616
+ interface MarkdownDocumentOptions {
617
+ onAppend?: MarkdownAppendCallback;
960
618
  }
961
619
 
962
- declare class MarkdownWriterBaseImpl implements MarkdownWriterBase {
620
+ export declare class MarkdownDocument {
963
621
  sourceParts: string[];
964
622
  hasToC: boolean;
965
623
  toc: TocLine[];
624
+ onAppend?: MarkdownAppendCallback;
625
+ constructor(options?: MarkdownDocumentOptions);
966
626
  get source(): string;
967
627
  appendLineBreaks(): this;
968
628
  append(type: AppendType, raw?: string): this;
@@ -970,70 +630,40 @@ declare class MarkdownWriterBaseImpl implements MarkdownWriterBase {
970
630
  end(): string;
971
631
  }
972
632
 
973
- interface WriterOptions {
974
- /** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
975
- dryRun?: boolean;
633
+ export declare class BrowserWriterMarkdown extends MarkdownDocument {
976
634
  }
977
635
 
978
- declare class Writer {
979
- private readonly dryRun;
980
- /** Directories already created by this writer, so sibling files skip the `mkdir` round trip. */
981
- private readonly ensuredDirs;
982
- constructor(options?: WriterOptions);
983
- /**
984
- * Skips the write when `filePath` already contains `raw`, so repeated runs
985
- * over unchanged sources don't touch the file (or its mtime). In dry-run
986
- * mode, prints `would write "<path>"` to stdout and touches nothing.
987
- *
988
- * @returns `true` if the file was written, `false` if it was already up to date.
989
- *
990
- * @example
991
- * ```ts
992
- * const writer = new Writer();
993
- * await writer.write("./dist/index.d.ts", "export type Props = {};");
994
- * ```
995
- */
996
- write(filePath: string, raw: string): Promise<boolean>;
997
- }
636
+ export type MarkdownWriterBase = MarkdownDocument;
998
637
 
999
- export declare const COMPONENT_API_SCHEMA_VERSION = 1;
1000
-
1001
- export interface ComponentApiDocument {
1002
- schemaVersion: 1;
1003
- generator: {
1004
- name: string;
1005
- version: string;
1006
- svelteVersion: string;
1007
- };
1008
- total: number;
1009
- components: ComponentDocApi[];
1010
- /** Only when `documentExports` is on. */
1011
- totalExports?: number;
1012
- exports?: EntryExports;
1013
- }
638
+ export declare function formatTsProps(props?: string): string;
1014
639
 
1015
- export interface BuildComponentApiDocumentOptions {
1016
- /** Entry-barrel exports when `documentExports` is on. */
1017
- entryExports?: EntryExports;
1018
- }
640
+ export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
1019
641
 
1020
- export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
642
+ export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
1021
643
 
1022
- interface MarkdownDocument {
1023
- append(type: AppendType, raw?: string): MarkdownDocument;
1024
- tableOfContents(): MarkdownDocument;
644
+ export interface WriteTsDefinitionOptions {
645
+ /**
646
+ * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
647
+ * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
648
+ * instead, for Svelte 5+ consumers. Generic components get a per-component
649
+ * interface with a generic call signature instead of `Component<...>`
650
+ * directly, since a `declare const` can't itself carry a generic type
651
+ * parameter (see `genGenericComponentDeclaration`).
652
+ */
653
+ format?: "class" | "component";
1025
654
  }
1026
655
 
1027
- export declare function renderComponentsToMarkdown(document: MarkdownDocument, components: ComponentDocs, entryExports?: EntryExports): void;
656
+ export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
1028
657
 
1029
- export declare class BrowserWriterMarkdown extends MarkdownWriterBaseImpl {
1030
- onAppend?: OnAppend;
1031
- constructor(options: MarkdownOptions);
1032
- append(type: AppendType, raw?: string): this;
658
+ interface MarkdownRenderTarget {
659
+ append(type: AppendType, raw?: string): MarkdownRenderTarget;
660
+ tableOfContents(): MarkdownRenderTarget;
1033
661
  }
1034
662
 
663
+ export declare function renderComponentsToMarkdown(document: MarkdownRenderTarget, components: ComponentDocs, entryExports?: EntryExports): void;
664
+
1035
665
  export interface WriteMarkdownCoreOptions {
1036
- onAppend?: (type: AppendType, document: BrowserWriterMarkdown, components: ComponentDocs) => void;
666
+ onAppend?: (type: AppendType, document: MarkdownDocument, components: ComponentDocs) => void;
1037
667
  }
1038
668
 
1039
669
  export declare function writeMarkdownCore(components: ComponentDocs, options?: WriteMarkdownCoreOptions): string;