sveld 0.35.1 → 0.36.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.
Files changed (74) hide show
  1. package/README.md +33 -10
  2. package/cli.js +1 -1
  3. package/lib/browser.d.ts +660 -39
  4. package/lib/browser.js +205 -227
  5. package/lib/chunk-0fqdg2xa.js +20 -0
  6. package/lib/chunk-2vwf7nck.js +1 -0
  7. package/lib/chunk-8myyzjb1.js +4 -0
  8. package/lib/chunk-as5hgj7e.js +62 -0
  9. package/lib/chunk-denfbw92.js +13 -0
  10. package/lib/chunk-h1r040pg.js +6 -0
  11. package/lib/chunk-m538qnhp.js +230 -0
  12. package/lib/chunk-r4rrncmd.js +1 -0
  13. package/lib/chunk-t9d5k3p7.js +2 -0
  14. package/lib/chunk-tmj7vnjr.js +10 -0
  15. package/lib/chunk-xryt7ad2.js +3 -0
  16. package/lib/cli-entry.js +1 -0
  17. package/lib/index.d.ts +767 -10
  18. package/lib/index.js +1 -343
  19. package/package.json +1 -1
  20. package/lib/ComponentParser.d.ts +0 -822
  21. package/lib/ast-guards.d.ts +0 -18
  22. package/lib/brands.d.ts +0 -11
  23. package/lib/bundle.d.ts +0 -176
  24. package/lib/check.d.ts +0 -43
  25. package/lib/cli.d.ts +0 -28
  26. package/lib/create-exports.d.ts +0 -32
  27. package/lib/dependency-graph.d.ts +0 -20
  28. package/lib/diagnostics.d.ts +0 -34
  29. package/lib/element-tag-map.d.ts +0 -146
  30. package/lib/example-check.d.ts +0 -24
  31. package/lib/get-svelte-entry.d.ts +0 -4
  32. package/lib/load-config.d.ts +0 -62
  33. package/lib/parse-cache.d.ts +0 -28
  34. package/lib/parse-entry-exports.d.ts +0 -30
  35. package/lib/parse-exports.d.ts +0 -25
  36. package/lib/parser/bindings.d.ts +0 -6
  37. package/lib/parser/context.d.ts +0 -114
  38. package/lib/parser/contexts.d.ts +0 -19
  39. package/lib/parser/diagnostics.d.ts +0 -8
  40. package/lib/parser/events.d.ts +0 -23
  41. package/lib/parser/generics.d.ts +0 -24
  42. package/lib/parser/jsdoc.d.ts +0 -59
  43. package/lib/parser/props.d.ts +0 -73
  44. package/lib/parser/rest-props.d.ts +0 -6
  45. package/lib/parser/runes-detection.d.ts +0 -16
  46. package/lib/parser/runes-props.d.ts +0 -18
  47. package/lib/parser/scopes.d.ts +0 -58
  48. package/lib/parser/slots.d.ts +0 -29
  49. package/lib/parser/source-position.d.ts +0 -30
  50. package/lib/parser/type-resolution.d.ts +0 -32
  51. package/lib/parser/typescript-casts.d.ts +0 -2
  52. package/lib/path.d.ts +0 -3
  53. package/lib/plugin.d.ts +0 -85
  54. package/lib/resolve-alias.d.ts +0 -30
  55. package/lib/resolve-types.d.ts +0 -52
  56. package/lib/sveld.d.ts +0 -29
  57. package/lib/validate.d.ts +0 -13
  58. package/lib/watch.d.ts +0 -34
  59. package/lib/writer/MarkdownWriterBase.d.ts +0 -26
  60. package/lib/writer/Writer.d.ts +0 -53
  61. package/lib/writer/WriterMarkdown.d.ts +0 -33
  62. package/lib/writer/built-in-writers.d.ts +0 -1
  63. package/lib/writer/document-model.d.ts +0 -34
  64. package/lib/writer/format-generated-ts.d.ts +0 -8
  65. package/lib/writer/markdown-format-utils.d.ts +0 -104
  66. package/lib/writer/markdown-render-utils.d.ts +0 -10
  67. package/lib/writer/registry.d.ts +0 -17
  68. package/lib/writer/writer-custom-elements-core.d.ts +0 -86
  69. package/lib/writer/writer-custom-elements.d.ts +0 -15
  70. package/lib/writer/writer-json.d.ts +0 -37
  71. package/lib/writer/writer-markdown-core.d.ts +0 -32
  72. package/lib/writer/writer-markdown.d.ts +0 -25
  73. package/lib/writer/writer-ts-definitions-core.d.ts +0 -38
  74. package/lib/writer/writer-ts-definitions.d.ts +0 -70
package/lib/browser.d.ts CHANGED
@@ -1,39 +1,660 @@
1
- /**
2
- * Browser-safe entry point.
3
- *
4
- * Everything exported here avoids Node built-ins (`node:fs`, `node:path`, ...),
5
- * so it bundles for the browser (Vite, esbuild, webpack, Rollup) without a
6
- * polyfill. It covers parsing a single component's source and rendering that
7
- * result to JSON, Markdown, TypeScript definitions, or a Custom Elements
8
- * Manifest — everything except the filesystem-driven project scanning
9
- * (`sveld()`/`pluginSveld()`) and CLI, which only make sense in Node.
10
- *
11
- * @example
12
- * ```ts
13
- * import { asNormalizedPath, ComponentParser, buildComponentApiDocument } from "sveld/browser";
14
- *
15
- * const parser = new ComponentParser();
16
- * const diagnostics = { moduleName: "Button", filePath: "Button.svelte" };
17
- * const parsed = parser.parseSvelteComponent(source, diagnostics);
18
- *
19
- * // `parseSvelteComponent` returns component metadata only; add the fields
20
- * // `ComponentDocApi` needs (`moduleName`, `filePath`) yourself.
21
- * const component = {
22
- * ...parsed,
23
- * moduleName: diagnostics.moduleName,
24
- * filePath: asNormalizedPath(diagnostics.filePath),
25
- * };
26
- *
27
- * const doc = buildComponentApiDocument(new Map([[component.moduleName, component]]));
28
- * ```
29
- */
30
- export { asNormalizedPath, type NormalizedPath } from "./brands";
31
- export { default as ComponentParser, type SerializedComponentEvent } from "./ComponentParser";
32
- export type { SveldDiagnostic, SveldDiagnosticKind } from "./diagnostics";
33
- export type { ComponentDocApi, ComponentDocs } from "./plugin";
34
- export { type BuildComponentApiDocumentOptions, buildComponentApiDocument, COMPONENT_API_SCHEMA_VERSION, type ComponentApiDocument, } from "./writer/document-model";
35
- export type { AppendType, MarkdownWriterBase, TocLine } from "./writer/MarkdownWriterBase";
36
- export { renderComponentsToMarkdown } from "./writer/markdown-render-utils";
37
- export { type BuildCustomElementsManifestOptions, buildCustomElementsManifest, type CemAttribute, type CemClassDeclaration, type CemClassField, type CemCustomElementExport, type CemEvent, type CemExport, type CemJavaScriptExport, type CemModule, type CemSlot, type CemType, type CustomElementsManifest, } from "./writer/writer-custom-elements-core";
38
- export { BrowserWriterMarkdown, type WriteMarkdownCoreOptions, writeMarkdownCore, } from "./writer/writer-markdown-core";
39
- export { formatTsProps, getContextDefs, getTypeDefs, type WriteTsDefinitionOptions, writeTsDefinition, } from "./writer/writer-ts-definitions-core";
1
+ import type { Property } from "estree";
2
+
3
+ import type { Node } from "estree-walker";
4
+
5
+ declare const brand: unique symbol;
6
+
7
+ type Brand<TBase extends string, TBrand extends string> = TBase & {
8
+ readonly [brand]: TBrand;
9
+ };
10
+
11
+ export type NormalizedPath = Brand<string, "NormalizedPath">;
12
+
13
+ export declare function asNormalizedPath(path: string): NormalizedPath;
14
+
15
+ interface JsDocPassthroughTag {
16
+ name: string;
17
+ body: string;
18
+ }
19
+
20
+ type DeprecatedValue = string | true;
21
+
22
+ interface SourcePosition {
23
+ /** 1-based source line number */
24
+ line: number;
25
+ /** 0-based source column number */
26
+ column: number;
27
+ }
28
+
29
+ interface SourceRange {
30
+ start: SourcePosition;
31
+ end: SourcePosition;
32
+ }
33
+
34
+ interface ParsedComponentTypeScriptMetadata {
35
+ canonicalPropsType?: string;
36
+ canonicalPropNames: string[];
37
+ localTypeDeclarations: string[];
38
+ typeImportStatements: string[];
39
+ /**
40
+ * Whether `canonicalPropsType` mentions one of the component's own
41
+ * `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
42
+ * resolver has no binding for `T`, so `resolveTypes` must leave this
43
+ * component's props as their AST-derived text rather than expand them.
44
+ */
45
+ referencesComponentGenerics?: boolean;
46
+ }
47
+
48
+ type SyntaxMode = "legacy" | "runes";
49
+
50
+ type ScriptLanguage = "js" | "ts";
51
+
52
+ type ComponentPropTypeSource = "typescript" | "jsdoc" | "default" | "inferred" | "unknown";
53
+
54
+ type ComponentPropDefaultValueKind = "literal" | "array" | "object" | "expression" | "function" | "unknown";
55
+
56
+ interface ComponentPropDefaultValue {
57
+ raw: string;
58
+ kind: ComponentPropDefaultValueKind;
59
+ value?: unknown;
60
+ }
61
+
62
+ type ModernScriptAttribute = {
63
+ name?: string;
64
+ value?: Array<{
65
+ data?: string;
66
+ raw?: string;
67
+ }> | boolean;
68
+ start?: number;
69
+ end?: number;
70
+ };
71
+
72
+ type ModernScriptNode = {
73
+ attributes?: ModernScriptAttribute[];
74
+ };
75
+
76
+ interface ComponentParserDiagnostics {
77
+ moduleName: string;
78
+ filePath: string;
79
+ }
80
+
81
+ type ComponentPropBinding = "readonly" | "writable";
82
+
83
+ interface ComponentPropParam {
84
+ /** Parameter name. */
85
+ name: string;
86
+ /** Parameter type (e.g. `"string"`, `"CustomType"`). */
87
+ type: string;
88
+ /** From JSDoc `@param`. */
89
+ description?: string;
90
+ /** True when optional. */
91
+ optional?: boolean;
92
+ }
93
+
94
+ interface ComponentProp {
95
+ /** Public prop name. */
96
+ name: string;
97
+ /** `"let"` (required), `"const"` (default), or `"function"`. */
98
+ kind: "let" | "const" | "function";
99
+ /** True when declared with `const`. */
100
+ constant: boolean;
101
+ /** TypeScript type text. */
102
+ type?: string;
103
+ /** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
104
+ typeSource?: ComponentPropTypeSource;
105
+ /** Local binding when it differs from the public name. */
106
+ localName?: string;
107
+ /** Default value as source text; unset when the prop has no initializer/default. */
108
+ value?: string;
109
+ /** Structured default value metadata for docs UIs; set alongside `value` from the same initializer. */
110
+ defaultValue?: ComponentPropDefaultValue;
111
+ /** From JSDoc, or a matching `@typedef`'s own description (legacy only; see {@link ComponentProp}). */
112
+ description?: string;
113
+ /** From JSDoc `@param` on function props. */
114
+ params?: ComponentPropParam[];
115
+ /** From JSDoc `@returns` on function props. */
116
+ returnType?: string;
117
+ /**
118
+ * True for arrow/function-expression initializers and bare `function`
119
+ * declarations in every mode; additionally true for a function-shaped
120
+ * type/JSDoc signature in runes only (see {@link ComponentProp}).
121
+ */
122
+ isFunction: boolean;
123
+ /** True for `function` declarations. */
124
+ isFunctionDeclaration: boolean;
125
+ /** True when declared with `let` and no default. */
126
+ isRequired: boolean;
127
+ /**
128
+ * True when the prop is mutated locally (legacy, inferred from assignment/
129
+ * binding targets) or declared with `$bindable()` (runes).
130
+ */
131
+ reactive: boolean;
132
+ /** Binding direction from `@bindable` JSDoc. */
133
+ binding?: ComponentPropBinding;
134
+ /** True when declared with Svelte 5 `$bindable()` (runes only). */
135
+ bindable?: true;
136
+ /** From `@deprecated` JSDoc. */
137
+ deprecated?: DeprecatedValue;
138
+ /** `@since` / `@example` tags in source order. */
139
+ tags?: JsDocPassthroughTag[];
140
+ /** Source range when available. */
141
+ source?: SourceRange;
142
+ }
143
+
144
+ interface ComponentSlot {
145
+ /** Slot name (`null` for the default slot). */
146
+ name?: string | null;
147
+ /** True for the default slot. */
148
+ default: boolean;
149
+ /** Fallback content when the slot is empty. */
150
+ fallback?: string;
151
+ /** Slot props as TypeScript type text. */
152
+ slot_props?: string;
153
+ /** From JSDoc `@slot` or `@snippet`. */
154
+ description?: string;
155
+ /** From `@deprecated` JSDoc. */
156
+ deprecated?: DeprecatedValue;
157
+ /** Tags between the description and `@slot`/`@snippet` (e.g. `@example`), in source order. */
158
+ tags?: JsDocPassthroughTag[];
159
+ /** Source range when available. */
160
+ source?: SourceRange;
161
+ }
162
+
163
+ interface DispatchedEvent {
164
+ /** Discriminator: `"dispatched"`. */
165
+ type: "dispatched";
166
+ /** Event name. */
167
+ name: string;
168
+ /** Detail type text. */
169
+ detail?: string;
170
+ /** From JSDoc `@event`. */
171
+ description?: string;
172
+ /** From `@deprecated` JSDoc. */
173
+ deprecated?: DeprecatedValue;
174
+ /** `@since` / `@example` tags in source order. */
175
+ tags?: JsDocPassthroughTag[];
176
+ /** Source range when available. */
177
+ source?: SourceRange;
178
+ }
179
+
180
+ interface SerializedForwardedEvent {
181
+ /** Discriminator: `"forwarded"`. */
182
+ type: "forwarded";
183
+ /** Event name. */
184
+ name: string;
185
+ /** Element name as a string for JSON output. */
186
+ element: string;
187
+ /** From JSDoc `@event`. */
188
+ description?: string;
189
+ /** From `@deprecated` JSDoc. */
190
+ deprecated?: DeprecatedValue;
191
+ /** Detail type from `@event`. */
192
+ detail?: string;
193
+ /** `@since` / `@example` tags in source order. */
194
+ tags?: JsDocPassthroughTag[];
195
+ /** Source range when available. */
196
+ source?: SourceRange;
197
+ }
198
+
199
+ export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
200
+
201
+ interface TypeDef {
202
+ /** Type text (e.g. `"{ x: number; y: number }"`). */
203
+ type: string;
204
+ /** Type name. */
205
+ name: string;
206
+ /** From JSDoc. */
207
+ description?: string;
208
+ /** Full `type` alias declaration text. */
209
+ ts: string;
210
+ }
211
+
212
+ type ComponentGenerics = [name: string, type: string] | null;
213
+
214
+ interface ComponentInlineElement {
215
+ /** Discriminator: `"InlineComponent"`. */
216
+ type: "InlineComponent";
217
+ /** Component name. */
218
+ name: string;
219
+ }
220
+
221
+ interface ComponentElement {
222
+ type: "Element";
223
+ name: string;
224
+ /**
225
+ * Static tag for `svelte:element this="div"`. Undefined when `this` is dynamic.
226
+ *
227
+ * @example
228
+ * ```svelte
229
+ * <!-- Static tag -->
230
+ * <svelte:element this="div" bind:this={elementRef} />
231
+ * // thisValue: "div"
232
+ *
233
+ * <!-- Dynamic tag -->
234
+ * <svelte:element this={tagName} bind:this={elementRef} />
235
+ * // thisValue: undefined
236
+ * ```
237
+ */
238
+ thisValue?: string;
239
+ /** From `@restProps` JSDoc. */
240
+ description?: string;
241
+ }
242
+
243
+ type RestProps = undefined | ComponentInlineElement | ComponentElement;
244
+
245
+ interface Extends {
246
+ /** Interface name (e.g. `"ButtonProps"`). */
247
+ interface: string;
248
+ /** Import path (e.g. `"./types"`). */
249
+ import: string;
250
+ }
251
+
252
+ interface ComponentContextProp {
253
+ /** Property name. */
254
+ name: string;
255
+ /** Property type text. */
256
+ type: string;
257
+ /** From JSDoc. */
258
+ description?: string;
259
+ /** True when optional. */
260
+ optional: boolean;
261
+ }
262
+
263
+ interface ComponentContext {
264
+ /** Context key from `setContext`. */
265
+ key: string;
266
+ /** Generated type name (e.g. `"ModalContext"`). */
267
+ typeName: string;
268
+ /** From JSDoc. */
269
+ description?: string;
270
+ /** Context object properties. */
271
+ properties: ComponentContextProp[];
272
+ }
273
+
274
+ interface ParsedComponent {
275
+ /** Source range of the parsed file. */
276
+ source?: SourceRange;
277
+ syntaxMode: SyntaxMode;
278
+ scriptLanguage?: ScriptLanguage;
279
+ /** Instance-level props (`export let`/`export function`, or runes `$props()`). See {@link ComponentProp} for the shared IR these are built from. */
280
+ props: ComponentProp[];
281
+ /** Exports from `<script context="module">`. Same {@link ComponentProp} shape as `props`, resolved through the same shared decisions. */
282
+ moduleExports: ComponentProp[];
283
+ slots: ComponentSlot[];
284
+ /** Serialized events for JSON/API output. */
285
+ events: SerializedComponentEvent[];
286
+ typedefs: TypeDef[];
287
+ generics: null | ComponentGenerics;
288
+ rest_props: RestProps;
289
+ extends?: Extends;
290
+ /** From `@component` HTML comment. */
291
+ componentComment?: string;
292
+ componentCommentSource?: SourceRange;
293
+ contexts?: ComponentContext[];
294
+ customElementTag?: string;
295
+ /**
296
+ * Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
297
+ */
298
+ diagnostics?: SveldDiagnostic[];
299
+ /** Writer-only TypeScript metadata. Not serialized to JSON. */
300
+ [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
301
+ }
302
+
303
+ export class ComponentParser {
304
+ /**
305
+ * All per-parse mutable state (props, slots, events, scopes, source, etc.).
306
+ * See {@link ParserContext} for field-by-field documentation. Replaced
307
+ * wholesale by `cleanup()` between parses.
308
+ */
309
+ private ctx;
310
+ private static mapToArray;
311
+ private static getStaticAttributeValue;
312
+ resolveScriptLanguage(parsed: {
313
+ instance?: ModernScriptNode;
314
+ module?: ModernScriptNode;
315
+ }): ScriptLanguage | undefined;
316
+ /**
317
+ * Reads the `generics` attribute off the instance script (Svelte only allows
318
+ * it there, and only alongside `lang="ts"`). Returns the raw value for later
319
+ * precedence resolution against `@generics`/`@template` JSDoc tags, or
320
+ * `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
321
+ * `undefined` if the attribute is present without `lang="ts"`, since sveld
322
+ * can't safely guess how to parse it as plain JavaScript.
323
+ */
324
+ resolveScriptGenericsAttribute(parsed: {
325
+ instance?: ModernScriptNode;
326
+ }): {
327
+ value: string;
328
+ source?: SourceRange;
329
+ } | undefined;
330
+ private resolvePublicPropName;
331
+ trackPropLocalName(propName: string, localName?: string): void;
332
+ private getPropByLocalOrPublic;
333
+ getPropTypeByLocalOrPublic(name: string): string | undefined;
334
+ getExplicitPropType(name: string): string | undefined;
335
+ getPropertyName(node: Property["key"]): string | undefined;
336
+ isNumericConstant(memberExpr: unknown): boolean;
337
+ resolveLocalVarJSDoc(name: string): {
338
+ type?: string;
339
+ params?: ComponentPropParam[];
340
+ returnType?: string;
341
+ description?: string;
342
+ binding?: ComponentPropBinding;
343
+ deprecated?: DeprecatedValue;
344
+ tags?: JsDocPassthroughTag[];
345
+ } | undefined;
346
+ private addModuleExport;
347
+ /**
348
+ * @example
349
+ * ```ts
350
+ * aliasType("*"); // "any"
351
+ * aliasType(" string "); // "string"
352
+ * ```
353
+ */
354
+ aliasType(type: string): string;
355
+ /**
356
+ * @example
357
+ * ```ts
358
+ * // Given:
359
+ * // /**
360
+ * // * @type {number}
361
+ * // * The count value
362
+ * // *\/
363
+ * // const count = 0;
364
+ *
365
+ * findVariableTypeAndDescription("count");
366
+ * // { type: "number", description: "The count value" }
367
+ * ```
368
+ */
369
+ findVariableTypeAndDescription(varName: string): {
370
+ type: string;
371
+ description?: string;
372
+ } | null;
373
+ accumulateGeneric(name: string, constraint: string): void;
374
+ /**
375
+ * Resets parser state for reuse between parses.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * parser.parseSvelteComponent(source1, diagnostics1);
380
+ * parser.cleanup();
381
+ * parser.parseSvelteComponent(source2, diagnostics2);
382
+ * ```
383
+ */
384
+ cleanup(): void;
385
+ private static readonly SCRIPT_BLOCK_REGEX;
386
+ private static readonly TS_DIRECTIVE_REGEX;
387
+ private static stripTypeScriptDirectivesFromScripts;
388
+ /**
389
+ * @example
390
+ * ```ts
391
+ * const parser = new ComponentParser();
392
+ * const result = parser.parseSvelteComponent(source, {
393
+ * moduleName: "Button",
394
+ * filePath: "./Button.svelte"
395
+ * });
396
+ * // { props, slots, events, typedefs, ... }
397
+ * ```
398
+ */
399
+ parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
400
+ }
401
+
402
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "event-no-source" | "example-compile-error" | "syntax-skipped";
403
+
404
+ export interface SveldDiagnostic {
405
+ /** File this came from, e.g. `"./Button.svelte"`. */
406
+ component: string;
407
+ kind: SveldDiagnosticKind;
408
+ /** Prop, context field, or event name. */
409
+ name: string;
410
+ /** What went wrong and what type sveld used. */
411
+ message: string;
412
+ /** Where in the component source this diagnostic points, when the parser holds a stable position. */
413
+ source?: SourceRange;
414
+ }
415
+
416
+ declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
417
+
418
+ export interface ComponentDocApi extends ParsedComponent {
419
+ filePath: NormalizedPath;
420
+ moduleName: string;
421
+ }
422
+
423
+ export type ComponentDocs = Map<string, ComponentDocApi>;
424
+
425
+ interface EntryExport {
426
+ name: string;
427
+ kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
428
+ /** Type text from the source, when present. */
429
+ type?: string;
430
+ /** Initializer text for simple constants. */
431
+ value?: string;
432
+ description?: string;
433
+ /** Declaring module, relative to the entry file. */
434
+ source?: string;
435
+ isTypeOnly: boolean;
436
+ }
437
+
438
+ type EntryExports = EntryExport[];
439
+
440
+ export interface CemType {
441
+ text: string;
442
+ }
443
+
444
+ export interface CemClassField {
445
+ kind: "field";
446
+ name: string;
447
+ type?: CemType;
448
+ default?: string;
449
+ description?: string;
450
+ deprecated?: DeprecatedValue;
451
+ }
452
+
453
+ export interface CemAttribute {
454
+ name: string;
455
+ fieldName: string;
456
+ type?: CemType;
457
+ default?: string;
458
+ description?: string;
459
+ }
460
+
461
+ export interface CemEvent {
462
+ name: string;
463
+ type: CemType;
464
+ description?: string;
465
+ deprecated?: DeprecatedValue;
466
+ }
467
+
468
+ export interface CemSlot {
469
+ name: string;
470
+ description?: string;
471
+ deprecated?: DeprecatedValue;
472
+ }
473
+
474
+ export interface CemClassDeclaration {
475
+ kind: "class";
476
+ name: string;
477
+ description?: string;
478
+ members: CemClassField[];
479
+ attributes: CemAttribute[];
480
+ events: CemEvent[];
481
+ slots: CemSlot[];
482
+ /** Only present when the source component sets `<svelte:options customElement="..." />`. */
483
+ tagName?: string;
484
+ /** Only present when the source component sets `<svelte:options customElement="..." />`. */
485
+ customElement?: true;
486
+ }
487
+
488
+ export interface CemJavaScriptExport {
489
+ kind: "js";
490
+ name: string;
491
+ declaration: {
492
+ name: string;
493
+ module: string;
494
+ };
495
+ }
496
+
497
+ export interface CemCustomElementExport {
498
+ kind: "custom-element-definition";
499
+ name: string;
500
+ declaration: {
501
+ name: string;
502
+ module: string;
503
+ };
504
+ }
505
+
506
+ export type CemExport = CemJavaScriptExport | CemCustomElementExport;
507
+
508
+ export interface CemModule {
509
+ kind: "javascript-module";
510
+ path: string;
511
+ declarations: CemClassDeclaration[];
512
+ exports: CemExport[];
513
+ }
514
+
515
+ export interface CustomElementsManifest {
516
+ schemaVersion: "1.0.0";
517
+ modules: CemModule[];
518
+ }
519
+
520
+ export interface BuildCustomElementsManifestOptions {
521
+ /** Resolves each component's manifest `path`. Defaults to the component's `filePath` as-is. */
522
+ resolveModulePath?: (component: ComponentDocApi) => string;
523
+ }
524
+
525
+ export declare function buildCustomElementsManifest(components: ComponentDocs, options?: BuildCustomElementsManifestOptions): CustomElementsManifest;
526
+
527
+ type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
528
+
529
+ interface MarkdownOptions {
530
+ onAppend?: OnAppend;
531
+ }
532
+
533
+ declare class WriterMarkdown extends Writer {
534
+ onAppend?: OnAppend;
535
+ private markdownBase;
536
+ constructor(options: MarkdownOptions);
537
+ get source(): string;
538
+ get hasToC(): boolean;
539
+ get toc(): TocLine[];
540
+ appendLineBreaks(): this;
541
+ append(type: AppendType, raw?: string): this;
542
+ tableOfContents(): this;
543
+ end(): string;
544
+ }
545
+
546
+ export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
547
+
548
+ export interface TocLine {
549
+ /** Leading space count; 0 for the top-level (`h2`) entries the TOC currently lists. */
550
+ indent: number;
551
+ raw: string;
552
+ }
553
+
554
+ export interface MarkdownWriterBase {
555
+ sourceParts: string[];
556
+ hasToC: boolean;
557
+ toc: TocLine[];
558
+ appendLineBreaks(): this;
559
+ append(type: AppendType, raw?: string): this;
560
+ tableOfContents(): this;
561
+ end(): string;
562
+ get source(): string;
563
+ }
564
+
565
+ declare class MarkdownWriterBaseImpl implements MarkdownWriterBase {
566
+ sourceParts: string[];
567
+ hasToC: boolean;
568
+ toc: TocLine[];
569
+ get source(): string;
570
+ appendLineBreaks(): this;
571
+ append(type: AppendType, raw?: string): this;
572
+ tableOfContents(): this;
573
+ end(): string;
574
+ }
575
+
576
+ interface WriterOptions {
577
+ /** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
578
+ dryRun?: boolean;
579
+ }
580
+
581
+ declare class Writer {
582
+ private readonly dryRun;
583
+ constructor(options?: WriterOptions);
584
+ /**
585
+ * Skips the write when `filePath` already contains `raw`, so repeated runs
586
+ * over unchanged sources don't touch the file (or its mtime). In dry-run
587
+ * mode, prints `would write "<path>"` to stdout and touches nothing.
588
+ *
589
+ * @returns `true` if the file was written, `false` if it was already up to date.
590
+ *
591
+ * @example
592
+ * ```ts
593
+ * const writer = new Writer();
594
+ * await writer.write("./dist/index.d.ts", "export type Props = {};");
595
+ * ```
596
+ */
597
+ write(filePath: string, raw: string): Promise<boolean>;
598
+ }
599
+
600
+ export declare function formatTsProps(props?: string): string;
601
+
602
+ export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
603
+
604
+ export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
605
+
606
+ export interface WriteTsDefinitionOptions {
607
+ /**
608
+ * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
609
+ * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
610
+ * instead, for Svelte 5+ consumers. Generic components get a per-component
611
+ * interface with a generic call signature instead of `Component<...>`
612
+ * directly, since a `declare const` can't itself carry a generic type
613
+ * parameter (see `genGenericComponentDeclaration`).
614
+ */
615
+ format?: "class" | "component";
616
+ }
617
+
618
+ export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
619
+
620
+ export declare const COMPONENT_API_SCHEMA_VERSION = 1;
621
+
622
+ export interface ComponentApiDocument {
623
+ schemaVersion: 1;
624
+ generator: {
625
+ name: string;
626
+ version: string;
627
+ svelteVersion: string;
628
+ };
629
+ total: number;
630
+ components: ComponentDocApi[];
631
+ /** Only when `documentExports` is on. */
632
+ totalExports?: number;
633
+ exports?: EntryExports;
634
+ }
635
+
636
+ export interface BuildComponentApiDocumentOptions {
637
+ /** Entry-barrel exports when `documentExports` is on. */
638
+ entryExports?: EntryExports;
639
+ }
640
+
641
+ export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
642
+
643
+ interface MarkdownDocument {
644
+ append(type: AppendType, raw?: string): MarkdownDocument;
645
+ tableOfContents(): MarkdownDocument;
646
+ }
647
+
648
+ export declare function renderComponentsToMarkdown(document: MarkdownDocument, components: ComponentDocs, entryExports?: EntryExports): void;
649
+
650
+ export declare class BrowserWriterMarkdown extends MarkdownWriterBaseImpl {
651
+ onAppend?: OnAppend;
652
+ constructor(options: MarkdownOptions);
653
+ append(type: AppendType, raw?: string): this;
654
+ }
655
+
656
+ export interface WriteMarkdownCoreOptions {
657
+ onAppend?: (type: AppendType, document: BrowserWriterMarkdown, components: ComponentDocs) => void;
658
+ }
659
+
660
+ export declare function writeMarkdownCore(components: ComponentDocs, options?: WriteMarkdownCoreOptions): string;