@mdsvex/language-core 0.1.0-next.0 → 0.1.0-next.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.js ADDED
@@ -0,0 +1,1253 @@
1
+ import { pfmToSvelte, template_value_at, yaml_keys } from "@mdsvex/source-map/pfm-to-svelte";
2
+ import { template_value_at as template_value_at2 } from "@mdsvex/source-map/pfm-to-svelte";
3
+ import { v3ToVolarMappings } from "@mdsvex/source-map/v3-to-volar";
4
+ import { composeMappings } from "@mdsvex/source-map/compose-mappings";
5
+ import { svelte2tsx } from "svelte2tsx";
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import temml from "temml";
10
+ import { manifest_resolver, read_json_config, CONFIG_FILE, read_exports, DIRECTIVES_EXPORT, MANIFEST_PATH, MANIFEST_VERSION } from "mdsvex/host";
11
+ import { CONFIG_FILE as CONFIG_FILE2 } from "mdsvex/host";
12
+ import { create_highlight } from "mdsvex/highlight";
13
+ import { default_languages } from "mdsvex/highlight/languages";
14
+ import { temml_math, source_math } from "mdsvex/math";
15
+ import { forEachEmbeddedCode } from "@volar/language-core";
16
+ const posix = (p) => p.replace(/\\/g, "/");
17
+ function create_config_loader(loader_options = {}) {
18
+ const ts = loader_options.typescript;
19
+ const parsed = /* @__PURE__ */ new Map();
20
+ function read(file, json) {
21
+ let stat;
22
+ try {
23
+ stat = fs.statSync(file);
24
+ } catch {
25
+ return null;
26
+ }
27
+ const hit = parsed.get(file);
28
+ if (hit !== void 0 && hit.mtime === stat.mtimeMs) return hit;
29
+ let manifest = null;
30
+ try {
31
+ const raw = JSON.parse(fs.readFileSync(file, "utf8"));
32
+ manifest = json ? from_json(raw, path.dirname(file), ts) : raw.version === MANIFEST_VERSION ? raw : null;
33
+ } catch {
34
+ manifest = null;
35
+ }
36
+ loader_options.on_read?.(file);
37
+ if (manifest === null) return null;
38
+ const loaded = {
39
+ file,
40
+ stamp: `${file}@${stat.mtimeMs}`,
41
+ manifest,
42
+ mtime: stat.mtimeMs
43
+ };
44
+ parsed.set(file, loaded);
45
+ return loaded;
46
+ }
47
+ function load(file) {
48
+ let dir = path.dirname(file);
49
+ for (; ; ) {
50
+ const found = read(path.join(dir, MANIFEST_PATH), false) ?? read(path.join(dir, CONFIG_FILE), true);
51
+ if (found !== null) return found;
52
+ const up = path.dirname(dir);
53
+ if (up === dir) return null;
54
+ dir = up;
55
+ }
56
+ }
57
+ return {
58
+ load,
59
+ options_for(file) {
60
+ const config = load(file);
61
+ if (config === null) return { stamp: "", options: {} };
62
+ return {
63
+ stamp: config.stamp,
64
+ options: document_options(config.manifest, file)
65
+ };
66
+ }
67
+ };
68
+ }
69
+ function specifier_from(doc, file) {
70
+ let rel = posix(path.relative(path.dirname(doc), file));
71
+ if (!rel.startsWith(".") && !path.isAbsolute(rel)) rel = "./" + rel;
72
+ return rel.replace(/\.([mc]?)ts$/, (_, m) => `.${m}js`);
73
+ }
74
+ function sources(modules) {
75
+ return modules.length === 0 ? void 0 : modules.map((m) => ({ specifier: m.id, names: m.names }));
76
+ }
77
+ function document_options(manifest, doc) {
78
+ const templates = {};
79
+ for (const [name, t] of Object.entries(manifest.templates)) {
80
+ const extra = t.extra;
81
+ const names = extra === null ? t.components : union(t.components, extra.names);
82
+ const entry = { specifier: t.id, components: names };
83
+ if (t.directives.length !== 0) entry.directives = sources(t.directives);
84
+ templates[name] = entry;
85
+ }
86
+ const file_of = manifest_resolver(manifest);
87
+ const components = [];
88
+ const directives = [];
89
+ for (const p of manifest.plugins ?? []) {
90
+ if (p.components) components.push(p.components);
91
+ if (p.directives) directives.push(p.directives);
92
+ }
93
+ components.push(...manifest.components);
94
+ directives.push(...manifest.directives);
95
+ const compile = {
96
+ component_mode: manifest.component_mode,
97
+ components: sources(components),
98
+ directives: sources(directives),
99
+ highlight: highlight_of(manifest)
100
+ };
101
+ if (Object.keys(templates).length !== 0) compile.templates = templates;
102
+ if (manifest.unwrap_images === true) compile.unwrap_images = true;
103
+ if (manifest.import_images === true) compile.import_images = true;
104
+ if (manifest.heading_ids === true) compile.heading_ids = true;
105
+ const smart = smart_from_json(manifest.smart_punctuation);
106
+ if (smart !== void 0) compile.smart_punctuation = smart;
107
+ const math = math_of(manifest);
108
+ if (math !== void 0) compile.math = math;
109
+ if (manifest.select_template) {
110
+ const picked = manifest.documents[posix(doc)];
111
+ compile.select_template = () => picked === null ? false : picked;
112
+ }
113
+ return {
114
+ compile,
115
+ resolve(id, name) {
116
+ const file = file_of(id, name);
117
+ return file === void 0 ? void 0 : specifier_from(doc, file);
118
+ },
119
+ // a parse plugin may handle a directive no component renders
120
+ report_directives: !manifest.directive_plugins,
121
+ lenient_frontmatter: manifest.frontmatter_parse,
122
+ declare_plugin_data: manifest.plugin_data === true,
123
+ report_missing_pre: true
124
+ };
125
+ }
126
+ let twinkleplop = null;
127
+ function highlight_of(manifest) {
128
+ if ((manifest.highlight ?? "twinkleplop") !== "twinkleplop") return void 0;
129
+ return twinkleplop ??= create_highlight({ languages: default_languages });
130
+ }
131
+ let temml_default = null;
132
+ function math_of(manifest) {
133
+ const math = manifest.math;
134
+ if (math === false) return void 0;
135
+ if (math === void 0) return temml_default ??= temml_math(temml);
136
+ const options = math.options;
137
+ if (math.renderer !== "temml" || options === null) return source_math;
138
+ return options === void 0 ? temml_default ??= temml_math(temml) : temml_math(temml, options);
139
+ }
140
+ function smart_from_json(smart) {
141
+ if (smart === true) return true;
142
+ if (typeof smart !== "object" || smart === null || Array.isArray(smart))
143
+ return void 0;
144
+ const { quotes, dashes, ellipses } = smart;
145
+ const flag = (v) => v === void 0 || typeof v === "boolean";
146
+ const four = Array.isArray(quotes) && quotes.length === 4 && quotes.every((q) => typeof q === "string");
147
+ if (!flag(dashes) || !flag(ellipses) || !(flag(quotes) || four))
148
+ return void 0;
149
+ if (quotes === false && dashes === false && ellipses === false)
150
+ return void 0;
151
+ return smart;
152
+ }
153
+ function union(a, b) {
154
+ const out = a.slice();
155
+ for (const n of b) if (!out.includes(n)) out.push(n);
156
+ return out;
157
+ }
158
+ function from_json(config, dir, ts) {
159
+ return read_json_config(config, path.join(dir, CONFIG_FILE), posix(dir), {
160
+ resolve: resolve_specifier,
161
+ scan: (file) => scan_exports(file, ts)
162
+ }).manifest;
163
+ }
164
+ function scan_exports(file, ts) {
165
+ const none = { names: [], directives: null };
166
+ if (ts === void 0) return none;
167
+ let code;
168
+ try {
169
+ code = fs.readFileSync(file, "utf8");
170
+ } catch {
171
+ return none;
172
+ }
173
+ const strip = (js) => ts.transpileModule(js, {
174
+ fileName: file + ".ts",
175
+ compilerOptions: {
176
+ target: ts.ScriptTarget.ESNext,
177
+ module: ts.ModuleKind.ESNext
178
+ }
179
+ }).outputText;
180
+ let scanned;
181
+ try {
182
+ scanned = read_exports(
183
+ code,
184
+ file.endsWith(".svelte") ? "svelte" : "js",
185
+ strip
186
+ );
187
+ } catch {
188
+ return none;
189
+ }
190
+ const directives = scanned.namespaces.find((n) => n.name === DIRECTIVES_EXPORT)?.specifier ?? null;
191
+ return {
192
+ names: scanned.names.filter((n) => n !== DIRECTIVES_EXPORT),
193
+ directives
194
+ };
195
+ }
196
+ const CONDITIONS = ["svelte", "import", "module", "default"];
197
+ function target_of(target) {
198
+ if (typeof target === "string") return target;
199
+ if (Array.isArray(target)) {
200
+ for (const t of target) {
201
+ const found = target_of(t);
202
+ if (found !== null) return found;
203
+ }
204
+ return null;
205
+ }
206
+ if (target !== null && typeof target === "object") {
207
+ const record = target;
208
+ for (const c of CONDITIONS)
209
+ if (c in record) {
210
+ const found = target_of(record[c]);
211
+ if (found !== null) return found;
212
+ }
213
+ }
214
+ return null;
215
+ }
216
+ function match_map(map, subpath) {
217
+ if (subpath in map) return target_of(map[subpath]);
218
+ for (const key of Object.keys(map)) {
219
+ const star = key.indexOf("*");
220
+ if (star < 0) continue;
221
+ const head = key.slice(0, star);
222
+ const tail = key.slice(star + 1);
223
+ if (subpath.startsWith(head) && subpath.endsWith(tail) && subpath.length >= key.length - 1) {
224
+ const target = target_of(map[key]);
225
+ if (target === null) return null;
226
+ return target.replace(
227
+ "*",
228
+ subpath.slice(head.length, subpath.length - tail.length)
229
+ );
230
+ }
231
+ }
232
+ return null;
233
+ }
234
+ function read_json(file) {
235
+ try {
236
+ return JSON.parse(fs.readFileSync(file, "utf8"));
237
+ } catch {
238
+ return null;
239
+ }
240
+ }
241
+ function nearest_package(dir) {
242
+ for (; ; ) {
243
+ const json = read_json(path.join(dir, "package.json"));
244
+ if (json !== null) return { dir, json };
245
+ const up = path.dirname(dir);
246
+ if (up === dir) return null;
247
+ dir = up;
248
+ }
249
+ }
250
+ function existing(file) {
251
+ try {
252
+ return fs.statSync(file).isFile() ? posix(file) : null;
253
+ } catch {
254
+ return null;
255
+ }
256
+ }
257
+ function resolve_specifier(spec, importer) {
258
+ const dir = path.dirname(importer);
259
+ if (spec.startsWith("file:")) return existing(fileURLToPath(spec));
260
+ if (spec.startsWith(".") || path.isAbsolute(spec))
261
+ return existing(path.resolve(dir, spec));
262
+ if (spec.startsWith("#")) {
263
+ const pkg = nearest_package(dir);
264
+ const imports = pkg?.json.imports;
265
+ if (pkg === null || typeof imports !== "object" || imports === null)
266
+ return null;
267
+ const target = match_map(imports, spec);
268
+ if (target === null) return null;
269
+ return target.startsWith(".") ? existing(path.resolve(pkg.dir, target)) : resolve_specifier(target, path.join(pkg.dir, "package.json"));
270
+ }
271
+ const parts = spec.split("/");
272
+ const name = spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
273
+ const subpath = "." + spec.slice(name.length);
274
+ for (let at = dir; ; ) {
275
+ const root = path.join(at, "node_modules", name);
276
+ const json = read_json(path.join(root, "package.json"));
277
+ if (json !== null) {
278
+ const exports = json.exports;
279
+ if (exports !== void 0 && exports !== null) {
280
+ const target = typeof exports === "object" && !Array.isArray(exports) && Object.keys(exports).some((k) => k.startsWith(".")) ? match_map(exports, subpath) : subpath === "." ? target_of(exports) : null;
281
+ return target === null ? null : existing(path.resolve(root, target));
282
+ }
283
+ return existing(
284
+ path.resolve(root, subpath === "." ? "index.js" : subpath)
285
+ );
286
+ }
287
+ const up = path.dirname(at);
288
+ if (up === at) return null;
289
+ at = up;
290
+ }
291
+ }
292
+ const SVELTE_SHIMS = `// Whenever a ambient declaration changes, its number should be increased
293
+ // This way, we avoid the situation where multiple ambient versions of svelte2tsx
294
+ // are loaded and their declarations conflict each other
295
+ // See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
296
+ // If you change anything in this file, think about whether or not it should be backported to svelte-shims.d.ts
297
+
298
+ type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
299
+
300
+ /** @internal PRIVATE API, DO NOT USE */
301
+ type SvelteActionReturnType = {
302
+ update?: (args: any) => void,
303
+ destroy?: () => void
304
+ } | void
305
+
306
+ /** @internal PRIVATE API, DO NOT USE */
307
+ type SvelteTransitionConfig = {
308
+ delay?: number,
309
+ duration?: number,
310
+ easing?: (t: number) => number,
311
+ css?: (t: number, u: number) => string,
312
+ tick?: (t: number, u: number) => void
313
+ }
314
+
315
+ /** @internal PRIVATE API, DO NOT USE */
316
+ type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
317
+
318
+ /** @internal PRIVATE API, DO NOT USE */
319
+ type SvelteAnimationReturnType = {
320
+ delay?: number,
321
+ duration?: number,
322
+ easing?: (t: number) => number,
323
+ css?: (t: number, u: number) => string,
324
+ tick?: (t: number, u: number) => void
325
+ }
326
+
327
+ /** @internal PRIVATE API, DO NOT USE */
328
+ type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
329
+ /** @internal PRIVATE API, DO NOT USE */
330
+ type SvelteAllProps = { [index: string]: any }
331
+ /** @internal PRIVATE API, DO NOT USE */
332
+ type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
333
+ /** @internal PRIVATE API, DO NOT USE */
334
+ type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
335
+ /** @internal PRIVATE API, DO NOT USE */
336
+ type SvelteRestProps = { [index: string]: any }
337
+ /** @internal PRIVATE API, DO NOT USE */
338
+ type SvelteSlots = { [index: string]: any }
339
+ /** @internal PRIVATE API, DO NOT USE */
340
+ type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
341
+
342
+ // Forces TypeScript to look into the type which results in a better representation of it
343
+ // which helps for error messages and is necessary for d.ts file transformation so that
344
+ // no ambient type references are left in the output
345
+ /** @internal PRIVATE API, DO NOT USE */
346
+ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
347
+
348
+ /** @internal PRIVATE API, DO NOT USE */
349
+ type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
350
+ /** @internal PRIVATE API, DO NOT USE */
351
+ declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
352
+
353
+ declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
354
+ declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
355
+ declare function __sveltets_2_allPropsType(): SvelteAllProps
356
+ declare function __sveltets_2_restPropsType(): SvelteRestProps
357
+ declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
358
+
359
+ // Overload of the following two functions is necessary.
360
+ // An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
361
+ // optionalProps need to be first or its type cannot be infered correctly.
362
+
363
+ declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
364
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
365
+ ): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
366
+ declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
367
+ optionalProps: OptionalProps[],
368
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
369
+ ): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
370
+
371
+ declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
372
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
373
+ ): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
374
+ declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
375
+ optionalProps: OptionalProps[],
376
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
377
+ ): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
378
+
379
+
380
+ declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
381
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
382
+ ): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
383
+
384
+ declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
385
+ render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
386
+ ): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots, exports?: Exports, bindings?: Bindings }
387
+
388
+ declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
389
+ declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
390
+ declare function __sveltets_2_any(dummy: any): any;
391
+ declare function __sveltets_2_invalidate<T>(getValue: () => T): T
392
+
393
+ declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
394
+ event: K
395
+ ): HTMLBodyElementEventMap[K];
396
+ declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
397
+ event: K
398
+ ): WindowEventMap[K];
399
+ declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
400
+ event: K
401
+ ): HTMLElementEventMap[K];
402
+
403
+ declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
404
+ events: Events, eventKey: K
405
+ ): Events[K];
406
+ declare function __sveltets_2_bubbleEventDef(
407
+ events: any, eventKey: string
408
+ ): any;
409
+
410
+ declare const __sveltets_2_customEvent: CustomEvent<any>;
411
+ declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
412
+
413
+ declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
414
+ declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
415
+ declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
416
+ declare function __sveltets_2_unionType(...types: any[]): any;
417
+
418
+ declare function __sveltets_2_createSvelte2TsxComponent<Props extends {}, Events extends {}, Slots extends {}>(
419
+ render: {props: Props, events: Events, slots: Slots }
420
+ ): typeof import("svelte").SvelteComponent<Props, Events, Slots>;
421
+
422
+ declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
423
+ declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
424
+
425
+ // v2
426
+ declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
427
+ declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponent<any, any, any>;
428
+
429
+ declare function __sveltets_2_any(...dummy: any[]): any;
430
+ declare function __sveltets_2_empty(...dummy: any[]): {};
431
+ declare function __sveltets_2_union<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(t1:T1,t2?:T2,t3?:T3,t4?:T4,t5?:T5,t6?:T6,t7?:T7,t8?:T8,t9?:T9,t10?:T10): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;
432
+ declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
433
+
434
+ declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
435
+
436
+ // @ts-ignore Svelte v3/v4 don't have this
437
+ declare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet> | undefined | null): any;
438
+
439
+ /** @internal PRIVATE API, DO NOT USE */
440
+ type __sveltets_2_SvelteAnimationReturnType = {
441
+ delay?: number,
442
+ duration?: number,
443
+ easing?: (t: number) => number,
444
+ css?: (t: number, u: number) => string,
445
+ tick?: (t: number, u: number) => void
446
+ }
447
+ declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
448
+ declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
449
+
450
+ /** @internal PRIVATE API, DO NOT USE */
451
+ type __sveltets_2_SvelteActionReturnType = {
452
+ update?: (args: any) => void,
453
+ destroy?: () => void,
454
+ $$_attributes?: Record<string, any>,
455
+ } | void
456
+ declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
457
+
458
+ /** @internal PRIVATE API, DO NOT USE */
459
+ type __sveltets_2_SvelteTransitionConfig = {
460
+ delay?: number,
461
+ duration?: number,
462
+ easing?: (t: number) => number,
463
+ css?: (t: number, u: number) => string,
464
+ tick?: (t: number, u: number) => void
465
+ }
466
+ /** @internal PRIVATE API, DO NOT USE */
467
+ type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
468
+ declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
469
+
470
+ // Includes undefined and null for all types as all usages also allow these
471
+ declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
472
+ declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
473
+
474
+ // The following is necessary because there are two clashing errors that can't be solved at the same time
475
+ // when using Svelte2TsxComponent, more precisely the event typings in
476
+ // __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
477
+ // If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
478
+ // If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
479
+ // If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
480
+ // Therefore introduce two more base classes just for this case.
481
+ /**
482
+ * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
483
+ */
484
+ declare type ATypedSvelteComponent = {
485
+ /**
486
+ * @internal This is for type checking capabilities only
487
+ * and does not exist at runtime. Don't use this property.
488
+ */
489
+ $$prop_def: any;
490
+ /**
491
+ * @internal This is for type checking capabilities only
492
+ * and does not exist at runtime. Don't use this property.
493
+ */
494
+ $$events_def: any;
495
+ /**
496
+ * @internal This is for type checking capabilities only
497
+ * and does not exist at runtime. Don't use this property.
498
+ */
499
+ $$slot_def: any;
500
+
501
+ $on(event: string, handler: any): () => void;
502
+ }
503
+ /**
504
+ * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
505
+ *
506
+ * If you're looking for the type of a Svelte Component, use \`SvelteComponent\` and \`ComponentType\` instead:
507
+ *
508
+ * \`\`\`ts
509
+ * import type { ComponentType, SvelteComponent } from "svelte";
510
+ * let myComponentConstructor: ComponentType<SvelteComponent> = ..;
511
+ * \`\`\`
512
+ */
513
+ declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
514
+ // Usage note: Cannot properly transform generic function components to class components due to TypeScript limitations
515
+ declare function __sveltets_2_ensureComponent<
516
+ T extends
517
+ | ConstructorOfATypedSvelteComponent
518
+ | (typeof import('svelte') extends { mount: any }
519
+ ? // @ts-ignore svelte.Component doesn't exist in Svelte 4
520
+ import('svelte').Component<any, any, any>
521
+ : never)
522
+ | null
523
+ | undefined
524
+ >(
525
+ type: T
526
+ ): NonNullable<
527
+ T extends ConstructorOfATypedSvelteComponent
528
+ ? T
529
+ : typeof import('svelte') extends { mount: any }
530
+ ? // @ts-ignore svelte.Component doesn't exist in Svelte 4
531
+ T extends import('svelte').Component<
532
+ infer Props extends Record<string, any>,
533
+ infer Exports extends Record<string, any>,
534
+ infer Bindings extends string
535
+ >
536
+ ? new (
537
+ options: import('svelte').ComponentConstructorOptions<Props>
538
+ ) => import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> &
539
+ Exports & { $$bindings: Bindings }
540
+ : never
541
+ : never
542
+ >;
543
+
544
+ declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(
545
+ // Svelte 5 allows undefined or null here, Svelte 4 doesn't
546
+ array: T | (typeof import('svelte') extends { mount: any } ? (undefined | null) : never)
547
+ ): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];
548
+
549
+ type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
550
+ (Slots extends { default: any }
551
+ // This is unfortunate because it means "accepts no props" turns into "accepts any prop"
552
+ // but the alternative is non-fixable type errors because of the way TypeScript index
553
+ // signatures work (they will always take precedence and make an impossible-to-satisfy children type).
554
+ ? Props extends Record<string, never>
555
+ ? any
556
+ : { children?: any }
557
+ : {});
558
+ declare function __sveltets_2_runes_constructor<Props extends {}>(render: {props: Props }): import("svelte").ComponentConstructorOptions<Props>;
559
+
560
+ declare function __sveltets_2_get_set_binding<T>(get: (() => T) | null | undefined, set: (t: T) => void): T;
561
+
562
+ declare function __sveltets_$$bindings<Bindings extends string[]>(...bindings: Bindings): Bindings[number];
563
+
564
+ declare function __sveltets_2_fn_component<
565
+ Props extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
566
+ // @ts-ignore Svelte 5 only
567
+ >(klass: {props: Props, exports?: Exports, bindings?: Bindings }): import('svelte').Component<Props, Exports, Bindings>;
568
+
569
+ interface __sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
570
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & { $$bindings?: Bindings } & Exports;
571
+ (internal: unknown, props: Props extends Record<string, never> ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any };
572
+ z_$$bindings?: Bindings;
573
+ }
574
+
575
+ declare function __sveltets_2_isomorphic_component<
576
+ Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
577
+ >(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<Props, Events, Slots, Exports, Bindings>;
578
+
579
+ declare function __sveltets_2_isomorphic_component_slots<
580
+ Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
581
+ >(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;
582
+ `;
583
+ const PFM_LANGUAGE_ID = "pfm";
584
+ const EXTENSIONS = [".pfm", ".svx"];
585
+ const DIRECTIVE_ARGS = /((?<![\w:]):{1,3}[A-Za-z_][\w-]*\[(?:[^[\]\n\\]|\\.|\[[^[\]\n]*\])*\])(\([^)\n]*\))/g;
586
+ const NOT_DOCUMENTS = /\.(?:[cm]?[jt]sx?|svelte|json|css|d\.ts|map)$/;
587
+ function inject_shims(tsx_code, raw_mappings) {
588
+ const prefix = SVELTE_SHIMS + "\n";
589
+ const prefixLen = prefix.length;
590
+ return {
591
+ code: prefix + tsx_code,
592
+ mappings: raw_mappings.map((m) => ({
593
+ ...m,
594
+ generatedOffsets: m.generatedOffsets.map((o) => o + prefixLen)
595
+ }))
596
+ };
597
+ }
598
+ function create_snapshot(text) {
599
+ return {
600
+ getText: (start, end) => text.slice(start, end),
601
+ getLength: () => text.length,
602
+ getChangeRange: () => void 0
603
+ };
604
+ }
605
+ function create_fallback_virtual_code(source) {
606
+ return {
607
+ id: "root",
608
+ languageId: PFM_LANGUAGE_ID,
609
+ snapshot: create_snapshot(source),
610
+ mappings: [
611
+ {
612
+ sourceOffsets: [0],
613
+ generatedOffsets: [0],
614
+ lengths: [source.length],
615
+ data: { structure: true }
616
+ }
617
+ ],
618
+ embeddedCodes: [],
619
+ diagnostics: [],
620
+ frontmatter: null,
621
+ templates: [],
622
+ probes: []
623
+ };
624
+ }
625
+ function template_choices(options) {
626
+ const templates = options.compile?.templates ?? {};
627
+ return Object.keys(templates).map((name) => {
628
+ const file = options.resolve?.(templates[name].specifier, "default");
629
+ return file === void 0 ? { name } : { name, file };
630
+ });
631
+ }
632
+ function merge_capabilities(a, b) {
633
+ if (!a.editor) return { ...b, format: false };
634
+ const out = { editor: true };
635
+ if (a.verification && b.verification)
636
+ out.verification = typeof a.verification === "object" ? a.verification : b.verification;
637
+ if (a.completion && b.completion) out.completion = b.completion;
638
+ if (a.semantic && b.semantic) out.semantic = b.semantic;
639
+ if (a.navigation && b.navigation) out.navigation = b.navigation;
640
+ if (a.structure && b.structure) out.structure = b.structure;
641
+ return out;
642
+ }
643
+ function create_virtual_code_from_source(source, script_id, options) {
644
+ let svelte;
645
+ try {
646
+ svelte = pfmToSvelte(source, options);
647
+ } catch {
648
+ return create_fallback_virtual_code(source);
649
+ }
650
+ let tsx;
651
+ try {
652
+ tsx = svelte2tsx(svelte.code, {
653
+ filename: script_id.replace(/\.[^./\\]+$/, ".svelte"),
654
+ isTsFile: false,
655
+ mode: "ts"
656
+ });
657
+ } catch {
658
+ return create_fallback_virtual_code(source);
659
+ }
660
+ const v3_map = tsx.map;
661
+ const raw_svelte_to_ts = v3ToVolarMappings(
662
+ v3_map,
663
+ tsx.code,
664
+ svelte.code
665
+ );
666
+ const { code: ts_code, mappings: svelte_to_ts_mappings } = inject_shims(
667
+ tsx.code,
668
+ raw_svelte_to_ts
669
+ );
670
+ const ALL_CAPS = {
671
+ verification: true,
672
+ completion: true,
673
+ semantic: true,
674
+ navigation: true,
675
+ structure: true
676
+ };
677
+ const markdown_props = [];
678
+ const filtered_mappings = svelte.mappings.filter((m) => m.data.role !== "node" && m.lengths[0] > 0).filter((m) => {
679
+ if (typeof m.data.verification !== "object") return true;
680
+ markdown_props.push(m);
681
+ return false;
682
+ }).map((m) => ({
683
+ sourceOffsets: m.sourceOffsets,
684
+ generatedOffsets: m.generatedOffsets,
685
+ lengths: m.lengths,
686
+ ...m.generatedLengths ? { generatedLengths: m.generatedLengths } : {},
687
+ // a mapping the converter added keeps its own capabilities
688
+ data: m.data.editor ? editor_caps(m.data) : ALL_CAPS
689
+ }));
690
+ const pfm_to_ts = composeMappings(
691
+ filtered_mappings,
692
+ svelte_to_ts_mappings,
693
+ merge_capabilities
694
+ ).filter((m) => !is_empty(m.data));
695
+ for (const m of markdown_props) {
696
+ const g = m.generatedOffsets[0];
697
+ const length = m.generatedLengths ? m.generatedLengths[0] : m.lengths[0];
698
+ const range = generated_span(svelte_to_ts_mappings, g, g + length);
699
+ if (range === null) continue;
700
+ pfm_to_ts.push({
701
+ sourceOffsets: [m.sourceOffsets[0]],
702
+ generatedOffsets: [range[0]],
703
+ lengths: [m.lengths[0]],
704
+ generatedLengths: [range[1] - range[0]],
705
+ data: editor_caps(m.data)
706
+ });
707
+ }
708
+ pfm_to_ts.sort((a, b) => a.sourceOffsets[0] - b.sourceOffsets[0]);
709
+ for (let i = pfm_to_ts.length - 2; i >= 0; i--) {
710
+ const m = pfm_to_ts[i];
711
+ if (m.lengths[0] !== 1) continue;
712
+ const gen_len = m.generatedLengths ? m.generatedLengths[0] : 1;
713
+ if (gen_len !== 1) continue;
714
+ const src_ch = source.charCodeAt(m.sourceOffsets[0]);
715
+ const gen_ch = ts_code.charCodeAt(m.generatedOffsets[0]);
716
+ if (src_ch === gen_ch) continue;
717
+ const next = pfm_to_ts[i + 1];
718
+ if (!m.data.editor !== !next.data.editor) continue;
719
+ const next_gen_len = next.generatedLengths ? next.generatedLengths[0] : next.lengths[0];
720
+ if (m.sourceOffsets[0] + 1 === next.sourceOffsets[0] && next.generatedOffsets[0] - (m.generatedOffsets[0] + 1) <= 1) {
721
+ const new_gen_start = m.generatedOffsets[0];
722
+ const new_gen_end = next.generatedOffsets[0] + next_gen_len;
723
+ next.sourceOffsets[0] = m.sourceOffsets[0];
724
+ next.lengths[0] += 1;
725
+ next.generatedOffsets[0] = new_gen_start;
726
+ const new_gen_len = new_gen_end - new_gen_start;
727
+ next.generatedLengths = new_gen_len !== next.lengths[0] ? [new_gen_len] : void 0;
728
+ pfm_to_ts.splice(i, 1);
729
+ }
730
+ }
731
+ for (const m of pfm_to_ts) {
732
+ if (!m.data.editor) continue;
733
+ const start = m.generatedOffsets[0];
734
+ const len = m.generatedLengths ? m.generatedLengths[0] : m.lengths[0];
735
+ if (ts_code[start] === '"' && ts_code[start + len] === '"' && len > 1)
736
+ m.generatedLengths = [len + 1];
737
+ }
738
+ const by_gen_offset = pfm_to_ts.slice().sort((a, b) => a.generatedOffsets[0] - b.generatedOffsets[0]);
739
+ for (let i = 0; i < by_gen_offset.length - 1; i++) {
740
+ const m = by_gen_offset[i];
741
+ const next = by_gen_offset[i + 1];
742
+ if (m.data.editor) continue;
743
+ const src_len = m.lengths[0];
744
+ const gen_len = m.generatedLengths ? m.generatedLengths[0] : src_len;
745
+ if (gen_len <= 1) continue;
746
+ const gen_end = m.generatedOffsets[0] + gen_len;
747
+ if (gen_end !== next.generatedOffsets[0]) continue;
748
+ const last_src = source.charCodeAt(m.sourceOffsets[0] + src_len - 1);
749
+ const last_gen = ts_code.charCodeAt(m.generatedOffsets[0] + gen_len - 1);
750
+ if (last_src !== last_gen) {
751
+ m.generatedLengths = [gen_len - 1];
752
+ }
753
+ }
754
+ {
755
+ const seen = /* @__PURE__ */ new Set();
756
+ let write = 0;
757
+ for (let read = 0; read < pfm_to_ts.length; read++) {
758
+ const m = pfm_to_ts[read];
759
+ if (typeof m.data.verification === "object") {
760
+ pfm_to_ts[write++] = m;
761
+ continue;
762
+ }
763
+ const key = m.sourceOffsets[0] + ":" + m.lengths[0] + ":" + caps_key(m.data);
764
+ if (seen.has(key)) continue;
765
+ seen.add(key);
766
+ pfm_to_ts[write++] = m;
767
+ }
768
+ pfm_to_ts.length = write;
769
+ }
770
+ const ts_virtual_code = {
771
+ id: "ts",
772
+ languageId: "typescript",
773
+ snapshot: create_snapshot(ts_code),
774
+ mappings: pfm_to_ts,
775
+ embeddedCodes: []
776
+ };
777
+ const embedded_codes = [ts_virtual_code];
778
+ const all_caps = {
779
+ verification: true,
780
+ completion: true,
781
+ semantic: true,
782
+ navigation: true,
783
+ structure: true,
784
+ format: true
785
+ };
786
+ for (let i = 0; i < svelte.styleBlocks.length; i++) {
787
+ const sb = svelte.styleBlocks[i];
788
+ const css_text = source.slice(sb.sourceStart, sb.sourceEnd);
789
+ embedded_codes.push({
790
+ id: "style_" + i,
791
+ languageId: "css",
792
+ snapshot: create_snapshot(css_text),
793
+ mappings: [
794
+ {
795
+ sourceOffsets: [sb.sourceStart],
796
+ generatedOffsets: [0],
797
+ lengths: [css_text.length],
798
+ data: all_caps
799
+ }
800
+ ],
801
+ embeddedCodes: []
802
+ });
803
+ }
804
+ let md_source = source;
805
+ for (const region of svelte.excludedRegions) {
806
+ const chunk = source.slice(region.start, region.end);
807
+ const blanked = chunk.replace(/[^\n]/g, " ");
808
+ md_source = md_source.slice(0, region.start) + blanked + md_source.slice(region.end);
809
+ }
810
+ md_source = md_source.replace(
811
+ DIRECTIVE_ARGS,
812
+ (_, head, args) => head + " ".repeat(args.length)
813
+ );
814
+ embedded_codes.push({
815
+ id: "md",
816
+ languageId: "markdown",
817
+ snapshot: create_snapshot(md_source),
818
+ mappings: [
819
+ {
820
+ sourceOffsets: [0],
821
+ generatedOffsets: [0],
822
+ lengths: [source.length],
823
+ data: {
824
+ structure: true,
825
+ navigation: true
826
+ }
827
+ }
828
+ ],
829
+ embeddedCodes: []
830
+ });
831
+ return {
832
+ id: "root",
833
+ languageId: PFM_LANGUAGE_ID,
834
+ snapshot: create_snapshot(source),
835
+ mappings: [
836
+ {
837
+ sourceOffsets: [0],
838
+ generatedOffsets: [0],
839
+ lengths: [source.length],
840
+ // so a service reports compile diagnostics and completes frontmatter on the root
841
+ data: { structure: true, verification: true, completion: true }
842
+ }
843
+ ],
844
+ embeddedCodes: embedded_codes,
845
+ diagnostics: svelte.diagnostics,
846
+ frontmatter: svelte.frontmatter,
847
+ templates: template_choices(options),
848
+ template: svelte.template,
849
+ probes: svelte.probes
850
+ };
851
+ }
852
+ function generated_span(mappings, start, end) {
853
+ let from = Infinity;
854
+ let to = -Infinity;
855
+ for (const m of mappings) {
856
+ const s = m.sourceOffsets[0];
857
+ const e = s + m.lengths[0];
858
+ if (s >= end || e <= start) continue;
859
+ const g = m.generatedOffsets[0];
860
+ const length = m.generatedLengths ? m.generatedLengths[0] : m.lengths[0];
861
+ from = Math.min(from, g + Math.min(Math.max(start - s, 0), length));
862
+ to = Math.max(to, g + Math.min(Math.min(end, e) - s, length));
863
+ }
864
+ return to > from ? [from, to] : null;
865
+ }
866
+ function editor_caps(data) {
867
+ const out = { editor: true };
868
+ if (data.verification) out.verification = data.verification;
869
+ if (data.completion) out.completion = true;
870
+ if (data.semantic) out.semantic = true;
871
+ if (data.navigation) out.navigation = true;
872
+ if (data.structure) out.structure = true;
873
+ return out;
874
+ }
875
+ function is_empty(data) {
876
+ return !data.verification && !data.completion && !data.semantic && !data.navigation && !data.structure && !data.format;
877
+ }
878
+ function caps_key(data) {
879
+ return (data.verification ? "v" : "") + (data.semantic ? "s" : "") + (data.navigation ? "n" : "") + (data.completion ? "c" : "");
880
+ }
881
+ function hash_string(s) {
882
+ let h = 0;
883
+ for (let i = 0; i < s.length; i++) {
884
+ h = (h << 5) - h + s.charCodeAt(i) | 0;
885
+ }
886
+ return h;
887
+ }
888
+ function create_pfm_language_plugin(plugin_options = {}) {
889
+ const cache = /* @__PURE__ */ new Map();
890
+ const config = plugin_options.config ?? create_config_loader({ typescript: plugin_options.typescript });
891
+ function virtual_code(scriptId, snapshot) {
892
+ const source = snapshot.getText(0, snapshot.getLength());
893
+ const hash = hash_string(source);
894
+ const { stamp, options } = config.options_for(scriptId);
895
+ const cached = cache.get(scriptId);
896
+ if (cached && cached.hash === hash && cached.stamp === stamp) {
897
+ return cached.result;
898
+ }
899
+ const result = create_virtual_code_from_source(source, scriptId, options);
900
+ cache.set(scriptId, { hash, stamp, result });
901
+ return result;
902
+ }
903
+ return {
904
+ getLanguageId(scriptId) {
905
+ return is_document(scriptId, config) ? PFM_LANGUAGE_ID : void 0;
906
+ },
907
+ createVirtualCode(scriptId, languageId, snapshot, _ctx) {
908
+ if (languageId !== PFM_LANGUAGE_ID) return void 0;
909
+ return virtual_code(scriptId, snapshot);
910
+ },
911
+ updateVirtualCode(scriptId, _virtualCode, newSnapshot, _ctx) {
912
+ return virtual_code(scriptId, newSnapshot);
913
+ },
914
+ disposeVirtualCode(scriptId) {
915
+ cache.delete(scriptId);
916
+ },
917
+ typescript: {
918
+ extraFileExtensions: [
919
+ ...EXTENSIONS.map((ext) => ({
920
+ extension: ext.slice(1),
921
+ isMixedContent: true,
922
+ scriptKind: 7
923
+ // ts.ScriptKind.Deferred
924
+ }))
925
+ ],
926
+ getServiceScript(root) {
927
+ const ts_code = root.embeddedCodes?.find(
928
+ (c) => c.languageId === "typescript"
929
+ );
930
+ if (ts_code) {
931
+ return {
932
+ code: ts_code,
933
+ extension: ".ts",
934
+ scriptKind: 3
935
+ // ts.ScriptKind.TS
936
+ };
937
+ }
938
+ return void 0;
939
+ }
940
+ }
941
+ };
942
+ }
943
+ function is_document(file, config) {
944
+ for (const ext of EXTENSIONS) if (file.endsWith(ext)) return true;
945
+ if (NOT_DOCUMENTS.test(file) || !/\.[^./\\]+$/.test(file)) return false;
946
+ const extensions = config.load(file)?.manifest.extensions;
947
+ return extensions !== void 0 && extensions.some((e) => file.endsWith(e));
948
+ }
949
+ const SVELTE_EXTENSION = ".svelte";
950
+ function createSnapshot(text) {
951
+ return {
952
+ getText: (start, end) => text.slice(start, end),
953
+ getLength: () => text.length,
954
+ getChangeRange: () => void 0
955
+ };
956
+ }
957
+ function createSvelteVirtualCode(source, scriptId) {
958
+ let tsx;
959
+ try {
960
+ tsx = svelte2tsx(source, {
961
+ filename: scriptId,
962
+ isTsFile: false,
963
+ mode: "ts"
964
+ });
965
+ } catch {
966
+ return void 0;
967
+ }
968
+ const v3Map = tsx.map;
969
+ const prefix = SVELTE_SHIMS + "\n";
970
+ const tsCode = prefix + tsx.code;
971
+ const prefixLen = prefix.length;
972
+ const rawMappings = v3ToVolarMappings(v3Map, tsx.code, source);
973
+ const mappings = rawMappings.map((m) => ({
974
+ ...m,
975
+ generatedOffsets: m.generatedOffsets.map((o) => o + prefixLen)
976
+ }));
977
+ const tsVirtualCode = {
978
+ id: "ts",
979
+ languageId: "typescript",
980
+ snapshot: createSnapshot(tsCode),
981
+ mappings,
982
+ embeddedCodes: []
983
+ };
984
+ return {
985
+ id: "root",
986
+ languageId: "svelte",
987
+ snapshot: createSnapshot(source),
988
+ mappings: [{
989
+ sourceOffsets: [0],
990
+ generatedOffsets: [0],
991
+ lengths: [source.length],
992
+ data: { structure: true }
993
+ }],
994
+ embeddedCodes: [tsVirtualCode]
995
+ };
996
+ }
997
+ function create_svelte_language_plugin() {
998
+ const cache = /* @__PURE__ */ new Map();
999
+ function hashString(s) {
1000
+ let h = 0;
1001
+ for (let i = 0; i < s.length; i++) {
1002
+ h = (h << 5) - h + s.charCodeAt(i) | 0;
1003
+ }
1004
+ return h;
1005
+ }
1006
+ return {
1007
+ getLanguageId(scriptId) {
1008
+ if (scriptId.endsWith(SVELTE_EXTENSION)) {
1009
+ return "svelte";
1010
+ }
1011
+ return void 0;
1012
+ },
1013
+ createVirtualCode(scriptId, languageId, snapshot) {
1014
+ if (languageId !== "svelte") return void 0;
1015
+ const source = snapshot.getText(0, snapshot.getLength());
1016
+ const hash = hashString(source);
1017
+ const cached = cache.get(scriptId);
1018
+ if (cached && cached.hash === hash) return cached.result;
1019
+ const result = createSvelteVirtualCode(source, scriptId);
1020
+ if (result) cache.set(scriptId, { hash, result });
1021
+ return result;
1022
+ },
1023
+ updateVirtualCode(scriptId, _virtualCode, newSnapshot) {
1024
+ const source = newSnapshot.getText(0, newSnapshot.getLength());
1025
+ const hash = hashString(source);
1026
+ const cached = cache.get(scriptId);
1027
+ if (cached && cached.hash === hash) return cached.result;
1028
+ const result = createSvelteVirtualCode(source, scriptId);
1029
+ if (result) cache.set(scriptId, { hash, result });
1030
+ return result;
1031
+ },
1032
+ disposeVirtualCode(scriptId) {
1033
+ cache.delete(scriptId);
1034
+ },
1035
+ typescript: {
1036
+ extraFileExtensions: [
1037
+ {
1038
+ extension: "svelte",
1039
+ isMixedContent: true,
1040
+ scriptKind: 7
1041
+ // ts.ScriptKind.Deferred
1042
+ }
1043
+ ],
1044
+ getServiceScript(root) {
1045
+ const tsCode = root.embeddedCodes?.find(
1046
+ (c) => c.languageId === "typescript"
1047
+ );
1048
+ if (tsCode) {
1049
+ return {
1050
+ code: tsCode,
1051
+ extension: ".ts",
1052
+ scriptKind: 3
1053
+ // ts.ScriptKind.TS
1054
+ };
1055
+ }
1056
+ return void 0;
1057
+ },
1058
+ getExtraServiceScripts(fileName, root) {
1059
+ const scripts = [];
1060
+ for (const code of forEachEmbeddedCode(root)) {
1061
+ if (code.languageId === "typescript") {
1062
+ scripts.push({
1063
+ fileName: fileName + "." + code.id + ".ts",
1064
+ code,
1065
+ extension: ".ts",
1066
+ scriptKind: 3
1067
+ });
1068
+ }
1069
+ }
1070
+ return scripts;
1071
+ }
1072
+ }
1073
+ };
1074
+ }
1075
+ const WORD = /[\w$-]/;
1076
+ function word_end(source, at) {
1077
+ while (at < source.length && WORD.test(source[at])) at++;
1078
+ return at;
1079
+ }
1080
+ function line_of(source, offset) {
1081
+ const start = source.lastIndexOf("\n", offset - 1) + 1;
1082
+ let end = source.indexOf("\n", offset);
1083
+ if (end < 0) end = source.length;
1084
+ return { start, end };
1085
+ }
1086
+ function value_end(source, start, stop) {
1087
+ let at = start;
1088
+ const q = source[at];
1089
+ if (q === '"' || q === "'") {
1090
+ const close = source.indexOf(q, at + 1);
1091
+ return close < 0 ? at + 1 : close + 1;
1092
+ }
1093
+ while (at < source.length && !stop.test(source[at])) at++;
1094
+ return at;
1095
+ }
1096
+ const DIRECTIVE = /(?<![\w:])(:{1,3})([A-Za-z_][\w-]*)(\[(?:[^[\]\n\\]|\\.|\[[^[\]\n]*\])*\])?\(/g;
1097
+ const BLOCK_PREFIX = /^[ \t]*(?:>[ \t]*|(?:[-*+]|\d+[.)])[ \t]+)*$/;
1098
+ function completion_context(source, offset, frontmatter) {
1099
+ if (frontmatter !== null && offset >= frontmatter.start && offset <= frontmatter.end) {
1100
+ const template = template_value_at(source, offset, frontmatter);
1101
+ if (template !== null) return { kind: "template", range: template };
1102
+ const line2 = line_of(source, offset);
1103
+ const before = source.slice(line2.start, offset);
1104
+ if (/^[A-Za-z_$][\w$-]*$|^$/.test(before)) {
1105
+ const end = word_end(source, offset);
1106
+ if (/^[ \t]*:/.test(source.slice(end, line2.end))) return null;
1107
+ const keys = yaml_keys(
1108
+ source.slice(frontmatter.start, frontmatter.end),
1109
+ frontmatter.start
1110
+ );
1111
+ const existing2 = [...keys.keys()].filter(
1112
+ (k) => keys.get(k).start !== line2.start
1113
+ );
1114
+ return {
1115
+ kind: "frontmatter_key",
1116
+ range: { start: line2.start, end },
1117
+ existing: existing2
1118
+ };
1119
+ }
1120
+ const pair = /^([A-Za-z_$][\w$-]*)[ \t]*:[ \t]*(\S*)$/.exec(before);
1121
+ if (pair === null) return null;
1122
+ const start = offset - pair[2].length;
1123
+ return {
1124
+ kind: "frontmatter_value",
1125
+ key: pair[1],
1126
+ range: {
1127
+ start,
1128
+ end: Math.max(offset, value_end(source, start, /[\s#]/))
1129
+ }
1130
+ };
1131
+ }
1132
+ const line = line_of(source, offset);
1133
+ const text = source.slice(line.start, line.end);
1134
+ DIRECTIVE.lastIndex = 0;
1135
+ let m;
1136
+ while ((m = DIRECTIVE.exec(text)) !== null) {
1137
+ if (m[3] === void 0 && (m[1].length === 1 || !BLOCK_PREFIX.test(text.slice(0, m.index))))
1138
+ continue;
1139
+ const args_start = line.start + m.index + m[0].length;
1140
+ const close = text.indexOf(")", args_start - line.start);
1141
+ const args_end = close < 0 ? line.end : line.start + close;
1142
+ if (offset < args_start || offset > args_end) continue;
1143
+ const args = source.slice(args_start, args_end);
1144
+ const before = source.slice(args_start, offset);
1145
+ const segment_start = args_start + before.lastIndexOf(",") + 1;
1146
+ const segment = source.slice(segment_start, offset);
1147
+ const eq = segment.indexOf("=");
1148
+ if (eq >= 0) {
1149
+ let start2 = segment_start + eq + 1;
1150
+ while (start2 < offset && /[ \t]/.test(source[start2])) start2++;
1151
+ return {
1152
+ kind: "arg_value",
1153
+ directive: m[2],
1154
+ key: segment.slice(0, eq).trim(),
1155
+ range: {
1156
+ start: start2,
1157
+ end: Math.max(offset, value_end(source, start2, /[\s,)]/))
1158
+ }
1159
+ };
1160
+ }
1161
+ let start = segment_start;
1162
+ while (start < offset && /[ \t]/.test(source[start])) start++;
1163
+ const existing2 = [];
1164
+ for (const k of args.matchAll(/([A-Za-z_][\w-]*)[ \t]*=/g))
1165
+ if (args_start + k.index !== start) existing2.push(k[1]);
1166
+ return {
1167
+ kind: "arg_key",
1168
+ directive: m[2],
1169
+ inline: m[1].length === 1,
1170
+ range: { start, end: word_end(source, offset) },
1171
+ existing: existing2
1172
+ };
1173
+ }
1174
+ return null;
1175
+ }
1176
+ function template_named(source, frontmatter) {
1177
+ if (frontmatter === null) return void 0;
1178
+ const m = /^(["']?)template\1[ \t]*:[ \t]*(["']?)([^"'#\n]*?)\2[ \t]*(?:#.*)?$/m.exec(
1179
+ source.slice(frontmatter.start, frontmatter.end)
1180
+ );
1181
+ if (m === null || m[3] === "") return void 0;
1182
+ return m[3] === "false" ? false : m[3];
1183
+ }
1184
+ function probe_for(probes, kind, name, template) {
1185
+ if (kind === "template")
1186
+ return probes.find((p) => p.kind === "template" && p.name === name);
1187
+ return probes.find(
1188
+ (p) => p.kind === "directive" && p.name === name && p.template === template
1189
+ ) ?? probes.find(
1190
+ (p) => p.kind === "directive" && p.name === name && p.template === void 0
1191
+ );
1192
+ }
1193
+ function props_of(ts, program, file, alias) {
1194
+ const sf = program.getSourceFile(file);
1195
+ if (sf === void 0) return null;
1196
+ let found;
1197
+ const visit = (node) => {
1198
+ if (found) return;
1199
+ if (ts.isTypeAliasDeclaration(node) && node.name.text === alias)
1200
+ found = node;
1201
+ else ts.forEachChild(node, visit);
1202
+ };
1203
+ visit(sf);
1204
+ if (found === void 0) return null;
1205
+ const checker = program.getTypeChecker();
1206
+ const type = checker.getTypeFromTypeNode(found.type);
1207
+ if (type.flags & ts.TypeFlags.Any) return null;
1208
+ const props = [];
1209
+ for (const symbol of checker.getPropertiesOfType(type)) {
1210
+ const prop_type = checker.getTypeOfSymbolAtLocation(symbol, found);
1211
+ props.push({
1212
+ name: symbol.name,
1213
+ type: checker.typeToString(
1214
+ checker.getNonNullableType(prop_type),
1215
+ found,
1216
+ ts.TypeFormatFlags.NoTruncation
1217
+ ),
1218
+ optional: (symbol.flags & ts.SymbolFlags.Optional) !== 0,
1219
+ documentation: ts.displayPartsToString(
1220
+ symbol.getDocumentationComment(checker)
1221
+ ),
1222
+ values: literal_values(ts, prop_type)
1223
+ });
1224
+ }
1225
+ return props;
1226
+ }
1227
+ function literal_values(ts, type) {
1228
+ const parts = type.isUnion() ? type.types : [type];
1229
+ const values = [];
1230
+ for (const t of parts) {
1231
+ if (t.isStringLiteral()) values.push(t.value);
1232
+ else if (t.isNumberLiteral()) values.push(String(t.value));
1233
+ else if (t.flags & ts.TypeFlags.BooleanLiteral)
1234
+ values.push(t.intrinsicName ?? "");
1235
+ }
1236
+ return values.filter((v) => v !== "");
1237
+ }
1238
+ export {
1239
+ CONFIG_FILE2 as CONFIG_FILE,
1240
+ completion_context,
1241
+ create_config_loader,
1242
+ create_pfm_language_plugin,
1243
+ create_svelte_language_plugin,
1244
+ document_options,
1245
+ from_json,
1246
+ is_document,
1247
+ probe_for,
1248
+ props_of,
1249
+ resolve_specifier,
1250
+ scan_exports,
1251
+ template_named,
1252
+ template_value_at2 as template_value_at
1253
+ };