@purestack/ts-format 0.0.0-stage → 1.1.24

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.
@@ -0,0 +1,178 @@
1
+ /*! @purestack/ts-format v1.1.24 | (c) 2026 Ahmed Yasin Koculu | MIT License */
2
+
3
+ import * as TypeScript from "typescript-parser";
4
+ //#region packages/ts-format/src/html.d.ts
5
+ export interface HtmlFormattingOptions {
6
+ printWidth: number;
7
+ tabSize: number;
8
+ useTabs: boolean;
9
+ }
10
+ export declare function formatHtmlFragment(source: string, options: HtmlFormattingOptions): Promise<string>;
11
+ /** Keep closing tags readable without inserting whitespace into inline content. */
12
+ export declare function normalizeClosingTagSpacing(source: string): string;
13
+ export declare function getLineIndent(line: string): string;
14
+ export declare function normalizeSelfClosingTagSpacing(formatted: string): string;
15
+ //#endregion
16
+ //#region packages/ts-format/src/source.d.ts
17
+ export interface SourceRange {
18
+ start: number;
19
+ end: number;
20
+ }
21
+ export interface SourceEdit extends SourceRange {
22
+ newText: string;
23
+ }
24
+ export interface FormatDiagnostic extends SourceRange {
25
+ message: string;
26
+ }
27
+ export interface FormatOptions extends Partial<HtmlFormattingOptions> {
28
+ filePath?: string;
29
+ language?: 'mdx' | 'typescript';
30
+ onlyWithinRange?: SourceRange;
31
+ }
32
+ export declare function intersects(left: SourceRange, right: SourceRange): boolean;
33
+ /** Immutable source snapshot. All edit offsets refer to this text. */
34
+ export declare class SourceText {
35
+ readonly text: string;
36
+ readonly filePath: string;
37
+ readonly options: HtmlFormattingOptions;
38
+ readonly diagnostics: FormatDiagnostic[];
39
+ private readonly lines;
40
+ private readonly eol;
41
+ constructor(text: string, options?: FormatOptions);
42
+ get lineCount(): number;
43
+ lineAt(line: number): {
44
+ text: string;
45
+ range: SourceRange;
46
+ };
47
+ positionAt(offset: number): {
48
+ line: number;
49
+ character: number;
50
+ };
51
+ offsetAt(position: {
52
+ line: number;
53
+ character: number;
54
+ }): number;
55
+ preserveEol(text: string): string;
56
+ report(range: SourceRange, error: unknown): void;
57
+ }
58
+ /** Apply non-overlapping edits against their original snapshot. */
59
+ export declare function applySourceEdits(source: string, edits: readonly SourceEdit[]): string;
60
+ //#endregion
61
+ //#region packages/ts-format/src/expressions.d.ts
62
+ interface RegorExpressionPlaceholder {
63
+ placeholder: string;
64
+ source: string;
65
+ }
66
+ /**
67
+ * Protects Regor {{ ... }} expressions while the surrounding markup is
68
+ * formatted as HTML. The expression source is restored byte-for-byte.
69
+ */
70
+ export declare function maskRegorExpressions(source: string): {
71
+ expressions: RegorExpressionPlaceholder[];
72
+ placeholderContent: string;
73
+ };
74
+ export declare function restoreRegorExpressions(formatted: string, expressions: RegorExpressionPlaceholder[]): string;
75
+ //#endregion
76
+ //#region packages/ts-format/src/fences.d.ts
77
+ export interface MdxFencePlaceholder {
78
+ placeholder: string;
79
+ source: string;
80
+ }
81
+ export interface MdxFence {
82
+ length: number;
83
+ marker: '`' | '~';
84
+ }
85
+ export interface MdxFenceDelimiter extends MdxFence {
86
+ suffix: string;
87
+ }
88
+ export interface MdxFenceDelimiterEditOptions {
89
+ onlyWithinRange?: SourceRange;
90
+ }
91
+ export declare function buildMdxFenceDelimiterEdits(document: SourceText, excludedRanges: SourceRange[], options?: MdxFenceDelimiterEditOptions): {
92
+ start: number;
93
+ end: number;
94
+ newText: string;
95
+ }[];
96
+ export declare function maskMdxFencedRegions(source: string): {
97
+ fences: MdxFencePlaceholder[];
98
+ placeholderContent: string;
99
+ };
100
+ export declare function restoreMdxFencedRegions(formatted: string, fences: MdxFencePlaceholder[]): string;
101
+ export declare function parseMdxFenceDelimiter(trimmed: string): MdxFenceDelimiter | undefined;
102
+ export declare function parseInlineMdxFenceOpener(trimmed: string): MdxFenceDelimiter | undefined;
103
+ export declare function parseInlineMdxFenceCloser(trimmed: string, activeFence: MdxFence): MdxFenceDelimiter | undefined;
104
+ export declare function isMdxFenceClosingDelimiter(delimiter: MdxFenceDelimiter, activeFence: MdxFence): boolean;
105
+ //#endregion
106
+ //#region packages/ts-format/src/markup.d.ts
107
+ export declare const VOID_HTML_TAG_NAMES: Set<string>;
108
+ export interface TagToken {
109
+ end: number;
110
+ kind: 'closing' | 'opening';
111
+ name: string;
112
+ nameEnd: number;
113
+ nameStart: number;
114
+ selfClosing: boolean;
115
+ start: number;
116
+ }
117
+ export declare function scanTagTokens(markup: string): TagToken[];
118
+ export declare function isMdxExpressionStart(source: string, index: number): boolean;
119
+ export declare function findMdxExpressionEnd(source: string, startIndex: number): number;
120
+ export declare function findTagEnd(markup: string, startIndex: number): number;
121
+ //#endregion
122
+ //#region packages/ts-format/src/mdx.d.ts
123
+ export interface MdxMarkupBlock {
124
+ content: string;
125
+ range: SourceRange;
126
+ }
127
+ interface MdxExpressionPlaceholder {
128
+ placeholder: string;
129
+ source: string;
130
+ }
131
+ interface MdxFormattingRequest {
132
+ onlyWithinRange?: SourceRange;
133
+ }
134
+ interface MdxMarkupBlockOptions {
135
+ includeIncomplete?: boolean;
136
+ }
137
+ export declare function buildMdxFormattingEdits(document: SourceText, request?: MdxFormattingRequest): Promise<SourceEdit[]>;
138
+ export declare function getMdxMarkupBlocks(document: SourceText, options?: MdxMarkupBlockOptions): MdxMarkupBlock[];
139
+ export declare function maskMdxExpressions(source: string): {
140
+ expressions: MdxExpressionPlaceholder[];
141
+ placeholderContent: string;
142
+ };
143
+ //#endregion
144
+ //#region packages/ts-format/src/templates.d.ts
145
+ export type SupportedTemplateTagName = 'html' | 'svg';
146
+ export interface SupportedTaggedTemplate {
147
+ content: string;
148
+ contentRange: SourceRange;
149
+ expressions: TemplateExpressionPlaceholder[];
150
+ interpolationRanges: Array<{
151
+ start: number;
152
+ end: number;
153
+ }>;
154
+ placeholderContent: string;
155
+ tagName: SupportedTemplateTagName;
156
+ }
157
+ interface TemplateExpressionPlaceholder {
158
+ placeholder: string;
159
+ source: string;
160
+ }
161
+ interface TemplateFormattingRequest {
162
+ onlyWithinRange?: SourceRange;
163
+ }
164
+ export declare function buildTemplateFormattingEdits(document: SourceText, request?: TemplateFormattingRequest): Promise<SourceEdit[]>;
165
+ export declare function getSupportedTaggedTemplates(document: SourceText): SupportedTaggedTemplate[];
166
+ export declare function isOffsetInsideSupportedTaggedTemplate(sourceFile: TypeScript.SourceFile, offset: number): boolean;
167
+ //#endregion
168
+ //#region packages/ts-format/src/index.d.ts
169
+ /** Formats only component markup and html/svg tagged template contents. */
170
+ export declare function formatSource(text: string, options?: FormatOptions): Promise<{
171
+ code: string;
172
+ edits: SourceEdit[];
173
+ diagnostics: FormatDiagnostic[];
174
+ changed: boolean;
175
+ }>;
176
+ //#endregion
177
+ export type { RegorExpressionPlaceholder };
178
+ //# sourceMappingURL=ts-format.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-format.d.mts","names":["_$__source0.SourceEdit","_$__source0.FormatDiagnostic"],"sources":["../src/html.ts","../src/source.ts","../src/expressions.ts","../src/fences.ts","../src/markup.ts","../src/mdx.ts","../src/templates.ts","../src/index.ts"],"mappings":";;iBAsBiB;EACf;EACA;EACA;;wBAGoB,mBACpB,gBACA,SAAS,wBAAqB;;wBAchB,2BAA2B;wBAQ3B,cAAc;wBAKd,+BAA+B;;;iBCvD9B;EACf;EACA;;iBAGe,mBAAmB;EAClC;;iBAGe,yBAAyB;EACxC;;iBAGe,sBAAsB,QAAQ;EAC7C;EACA;EACA,kBAAkB;;wBAGJ,WAAW,MAAM,aAAa,OAAO;;qBAKxC;WAQA;WAPF;WACA,SAAS;WACT,aAAa;mBACL;mBACA;EAEjB,YACW,cACT,UAAS;MAwBP;EAIJ,OAAO;IAjC+B;IAAe,OAAA;;EAqCrD,WAAW;IAWP;IACA;;EAIJ,SAAS;IAAY;IAAc;;EASnC,YAAY;EAIZ,OAAO,OAAO,aAAa;;;wBASb,iBAAiB,gBAAgB,gBAAgB;;;UCvGhD;EACf;EACA;;;;;;wBAOc,qBAAqB;eAArB;;;wBA8BA,wBACd,mBACA,aAAa;;;iBCnCE;EACf;EACA;;i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