@stillwind/host 0.12.0 → 0.14.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.
@@ -1,4 +1,4 @@
1
- import { NativeDesignSystemLoader, completionDetail, editorCssSource, fingerprint, stylesheetPluginPaths } from "@stillwind/native";
1
+ import { NativeDesignSystemLoader, candidateSegments, completionDetail, editorCssSource, fingerprint, stylesheetCatalogInput, stylesheetPluginPaths } from "@stillwind/native";
2
2
  import { PreparationError, checkerEnvironment, prepareSource } from "@stillwind/projection";
3
3
  import { TraceMap, decodedMappings } from "@jridgewell/trace-mapping";
4
4
  import ts from "typescript-6";
@@ -70,19 +70,19 @@ function pluginLoader(session) {
70
70
  return sessions.get(session)?.loader;
71
71
  }
72
72
  /**
73
- * Finds plugin candidates across source texts before individual modules are compiled.
73
+ * Defines the plugin candidates of several sources before individual modules are compiled.
74
74
  *
75
75
  * @param session - Session attached to the project's plugin runtime.
76
76
  * @param loader - Initial loader of the same session.
77
- * @param texts - Original source documents, including templates and embedded scripts.
77
+ * @param candidates - Candidates and variant prefixes that the scans of the sources found, as
78
+ * `NativeModuleSummary.candidates` lists them.
78
79
  * @returns Completion of candidate resolution and any required CSS reload, without publishing modules.
79
80
  * @throws If a plugin or CSS reload fails. Discard this runtime before retrying individual modules.
80
81
  */
81
- async function prepareSourcePlugins(session, loader, texts) {
82
+ async function prepareSourcePlugins(session, loader, candidates) {
82
83
  if (!sessions.has(session)) return;
83
84
  await compileWithPlugins(session, () => {
84
- const query = (pluginLoader(session) ?? loader).editorQuery();
85
- return { modules: [{ dynamicCandidates: [...new Set(texts.flatMap((text) => query.dynamicCandidates(text)))] }] };
85
+ return { modules: [{ dynamicCandidates: (pluginLoader(session) ?? loader).editorQuery().dynamicCandidates([...new Set(candidates)].join(" ")) }] };
86
86
  }, 1);
87
87
  }
88
88
  // src/compilation/host.ts
@@ -263,6 +263,16 @@ var CompilationProject = class {
263
263
  #revision = 0;
264
264
  /** Advances when sources or import links change so checker inputs are installed again. */
265
265
  #generation = 0;
266
+ /**
267
+ * Normalized identities, as {@link sourceKey} defines them, of files that CSS order traversals
268
+ * scanned without retaining them as sources. They are not checker inputs.
269
+ */
270
+ #orderingReads = /* @__PURE__ */ new Set();
271
+ /** Maps that CSS order traversals share, and the revision that they belong to. */
272
+ #ordering = {
273
+ revision: 0,
274
+ maps: /* @__PURE__ */ new Map()
275
+ };
266
276
  /** Last backend and inputs installed by this project. */
267
277
  #installed;
268
278
  /**
@@ -282,6 +292,24 @@ var CompilationProject = class {
282
292
  return this.#revision;
283
293
  }
284
294
  /**
295
+ * Returns a map that CSS order traversals share until the next invalidation. Every change to a
296
+ * file advances the revision, so an entry never outlives the text that it was derived from.
297
+ *
298
+ * @param name - Name of the map. Include the resolver domain when the entries depend on import
299
+ * resolution.
300
+ * @returns The map for the current revision. Callers store only values derived from module text
301
+ * and import resolution.
302
+ */
303
+ orderingCache(name) {
304
+ if (this.#ordering.revision !== this.#revision) this.#ordering = {
305
+ revision: this.#revision,
306
+ maps: /* @__PURE__ */ new Map()
307
+ };
308
+ let map = this.#ordering.maps.get(name);
309
+ if (!map) this.#ordering.maps.set(name, map = /* @__PURE__ */ new Map());
310
+ return map;
311
+ }
312
+ /**
285
313
  * Finds a source prepared since its last invalidation.
286
314
  *
287
315
  * @param id - Full resolver ID. Windows path spelling may differ in case or slashes.
@@ -294,9 +322,29 @@ var CompilationProject = class {
294
322
  sourceKeys() {
295
323
  return [...this.#sources.keys()];
296
324
  }
297
- /** Returns the prepared documents' original text so plugins can find candidates together. */
298
- texts() {
299
- return [...this.#sources.values()].map((record) => record.source.document.code);
325
+ /**
326
+ * Records a file that a CSS order traversal read without retaining it as a source.
327
+ *
328
+ * @param id - Full resolver ID of the file.
329
+ */
330
+ recordOrderingRead(id) {
331
+ this.#orderingReads.add(sourceKey(id));
332
+ }
333
+ /**
334
+ * Returns the normalized identities of files that only CSS order traversals read, as
335
+ * {@link sourceKey} defines them. A full {@link invalidate} clears them.
336
+ */
337
+ orderingReadKeys() {
338
+ return [...this.#orderingReads];
339
+ }
340
+ /**
341
+ * Returns the candidates that the local scans of the prepared sources found, so that plugins
342
+ * can define them together.
343
+ *
344
+ * @returns Candidates and variant prefixes, possibly repeated.
345
+ */
346
+ candidates() {
347
+ return [...this.#sources.values()].flatMap((record) => record.summary.candidates);
300
348
  }
301
349
  /**
302
350
  * Finds the scan results for a prepared source.
@@ -449,6 +497,7 @@ var CompilationProject = class {
449
497
  if (ids === void 0) {
450
498
  this.#sources.clear();
451
499
  this.#reload.clear();
500
+ this.#orderingReads.clear();
452
501
  } else for (const id of typeof ids === "string" ? [ids] : ids) this.#sources.delete(sourceKey(id));
453
502
  for (const record of this.#sources.values()) {
454
503
  record.resolutions = [];
@@ -823,6 +872,16 @@ var ModuleGraph = class {
823
872
  #attempted = /* @__PURE__ */ new Map();
824
873
  /** Successful scanner summaries keyed by compiler identity. */
825
874
  #summaries = /* @__PURE__ */ new Map();
875
+ /**
876
+ * Summaries of modules that only ordering imports reached, keyed by compiler identity, for a
877
+ * graph without a project.
878
+ */
879
+ #orderingSummaries = /* @__PURE__ */ new Map();
880
+ /**
881
+ * Complete ordering traversals keyed by resolved module and imported name, for a graph without a
882
+ * project.
883
+ */
884
+ #orderingReach = /* @__PURE__ */ new Map();
826
885
  /** Sources retained for compilation, keyed by full host identity. */
827
886
  #sources = /* @__PURE__ */ new Map();
828
887
  /** Correspondence from compiler identities to full host resolver identities. */
@@ -1198,6 +1257,162 @@ var ModuleGraph = class {
1198
1257
  }
1199
1258
  }
1200
1259
  /**
1260
+ * Returns the complete ordering traversals that this graph may reuse. A project shares them with
1261
+ * the other graphs of its current revision, separately for each resolver domain.
1262
+ *
1263
+ * @returns Traversals keyed by resolved module and imported name.
1264
+ */
1265
+ #orderingReaches() {
1266
+ return this.project?.orderingCache(`reach:${this.host.resolverDomain ?? ""}`) ?? this.#orderingReach;
1267
+ }
1268
+ /**
1269
+ * Returns the summaries of modules that only ordering imports reached. A project shares them
1270
+ * with the other graphs of its current revision.
1271
+ *
1272
+ * @returns Summaries keyed by compiler identity.
1273
+ */
1274
+ #orderingScans() {
1275
+ return this.project?.orderingCache("summaries") ?? this.#orderingSummaries;
1276
+ }
1277
+ /**
1278
+ * Resolves the ordering imports of a source to the modules whose CSS comes first.
1279
+ *
1280
+ * Each import resolves to the module that declares the imported value, after named and
1281
+ * `export *` re-exports. When that module does not import a Stillwind macro module, its own
1282
+ * value imports are followed instead, so a module that reaches a component through a module
1283
+ * without styles still comes after the component. Imports that do not resolve, or resolve to
1284
+ * an external or unsupported module, produce no entry. Every module that the traversal reads
1285
+ * is passed to the host's `watch`, so a change to it compiles the importer again.
1286
+ *
1287
+ * @param source - Importer whose ordering imports are resolved.
1288
+ * @param summary - Scan result of that importer.
1289
+ * @returns Ordering modules for the prepared source. Each entry keeps the authored import that
1290
+ * leads to it, in the order of the summary's imports.
1291
+ */
1292
+ async orderingModules(source, summary) {
1293
+ const modules = [];
1294
+ for (const ordering of summary.orderingImports) {
1295
+ const reached = await this.#orderingTargets(source.resolverId, ordering.source, ordering.imported, /* @__PURE__ */ new Set());
1296
+ for (const id of reached.reads) this.host.watch(id);
1297
+ for (const moduleId of reached.targets) if (moduleId !== source.moduleId) modules.push({
1298
+ source: ordering.source,
1299
+ imported: ordering.imported,
1300
+ moduleId
1301
+ });
1302
+ }
1303
+ return modules;
1304
+ }
1305
+ /**
1306
+ * Returns the modules with styles that one import reaches, and the modules that the traversal
1307
+ * reads to find them.
1308
+ *
1309
+ * A complete result is kept, keyed by the resolved module and the imported name, because the
1310
+ * imports of many sources reach the same shared modules. A result that stopped at a request in
1311
+ * `visited` is not kept. That request was followed earlier in the same traversal, so the importer
1312
+ * at the top of the traversal receives its targets through the earlier path, but this result can
1313
+ * miss them.
1314
+ *
1315
+ * @param importer - Full resolver identity of the importing module.
1316
+ * @param specifier - Authored module request.
1317
+ * @param imported - Imported name, or `*` for a namespace import.
1318
+ * @param visited - Requests that the traversal of one import of a source has followed. Each
1319
+ * request is followed once, which also stops re-export and import cycles.
1320
+ * @returns Compiler identities of the modules with styles, resolver identities of the modules
1321
+ * read, and whether the result is complete.
1322
+ */
1323
+ async #orderingTargets(importer, specifier, imported, visited) {
1324
+ const resolved = await this.#resolveOrdering(importer, specifier);
1325
+ if (!resolved) return {
1326
+ targets: /* @__PURE__ */ new Set(),
1327
+ reads: /* @__PURE__ */ new Set(),
1328
+ complete: true
1329
+ };
1330
+ const key = JSON.stringify([resolved.id, imported]);
1331
+ const kept = this.#orderingReaches().get(key);
1332
+ if (kept) return kept;
1333
+ if (visited.has(key)) return {
1334
+ targets: /* @__PURE__ */ new Set(),
1335
+ reads: /* @__PURE__ */ new Set(),
1336
+ complete: false
1337
+ };
1338
+ visited.add(key);
1339
+ const reach = {
1340
+ targets: /* @__PURE__ */ new Set(),
1341
+ reads: /* @__PURE__ */ new Set([resolved.id]),
1342
+ complete: true
1343
+ };
1344
+ const follow = async (next, name) => {
1345
+ const inner = await this.#orderingTargets(resolved.id, next, name, visited);
1346
+ for (const target of inner.targets) reach.targets.add(target);
1347
+ for (const id of inner.reads) reach.reads.add(id);
1348
+ reach.complete &&= inner.complete;
1349
+ };
1350
+ const summary = await this.#orderingSummary(resolved.id, resolved.moduleId);
1351
+ if (!summary) reach.targets.add(resolved.moduleId);
1352
+ else {
1353
+ const named = imported === "*" ? void 0 : summary.reExports.find((entry) => entry.exported === imported);
1354
+ const stars = summary.reExports.filter((entry) => entry.exported === "*");
1355
+ if (named) await follow(named.source, named.imported);
1356
+ else {
1357
+ if (imported === "*" || summary.localExports.includes(imported) || summary.localExports.length === 0 && summary.reExports.length === 0) {
1358
+ if (summary.macroImports > 0) reach.targets.add(resolved.moduleId);
1359
+ else for (const next of summary.orderingImports) await follow(next.source, next.imported);
1360
+ }
1361
+ for (const entry of imported === "*" ? summary.reExports : stars) await follow(entry.source, imported === "*" ? entry.imported : imported);
1362
+ }
1363
+ }
1364
+ if (reach.complete) this.#orderingReaches().set(key, reach);
1365
+ return reach;
1366
+ }
1367
+ /**
1368
+ * Returns the summary of a module that an ordering import reaches, scanning it when no
1369
+ * summary is retained.
1370
+ *
1371
+ * @param id - Full resolver identity of the module.
1372
+ * @param moduleId - Compiler identity of the module.
1373
+ * @returns The summary, or undefined when the module cannot be loaded or scanned.
1374
+ */
1375
+ async #orderingSummary(id, moduleId) {
1376
+ const retained = this.#summaries.get(moduleId) ?? this.#orderingScans().get(moduleId);
1377
+ if (retained) return retained;
1378
+ const target = this.project?.source(id);
1379
+ const projected = target && this.project?.summary(target);
1380
+ if (projected) return projected;
1381
+ try {
1382
+ const input = await this.#load(id);
1383
+ this.project?.recordOrderingRead(id);
1384
+ const prepared = "kind" in input ? input : await prepareSource(input);
1385
+ const result = tracePhase("scan", 1, () => this.session.scanSource(prepared));
1386
+ if (result.kind === "failed") return;
1387
+ this.#orderingScans().set(moduleId, result.summary);
1388
+ return result.summary;
1389
+ } catch {
1390
+ return;
1391
+ }
1392
+ }
1393
+ /**
1394
+ * Resolves one ordering specifier without loading the target.
1395
+ *
1396
+ * @param importer - Full resolver identity of the importing module.
1397
+ * @param specifier - Authored module request.
1398
+ * @returns The resolver identity and compiler identity of the target, or undefined when the
1399
+ * request does not resolve to a local source.
1400
+ */
1401
+ async #resolveOrdering(importer, specifier) {
1402
+ try {
1403
+ const resolved = await (this.host.resolveOrdering ? this.host.resolveOrdering(specifier, importer) : this.project ? this.project.resolveImport(this.host, specifier, importer) : this.host.resolve(specifier, importer, { skipSelf: true }));
1404
+ if (!resolved || resolved.external) return;
1405
+ const id = this.project?.source(resolved.id)?.resolverId ?? resolved.id;
1406
+ if (sourceSupport(this.host, id) !== "source") return;
1407
+ return {
1408
+ id,
1409
+ moduleId: this.project?.source(id)?.moduleId ?? this.host.describe(id).moduleId
1410
+ };
1411
+ } catch {
1412
+ return;
1413
+ }
1414
+ }
1415
+ /**
1201
1416
  * Uses host resolution first and a checker identity only when the host returns null.
1202
1417
  *
1203
1418
  * @param source - Importer whose full resolver identity is passed to the host.
@@ -1454,7 +1669,13 @@ async function compileGraph(session, factsService, code, id, host, options, anal
1454
1669
  if (entrySummary.macroImports > 0) entrySource.stylesheetImports = options.stylesheetImports;
1455
1670
  entrySource.moduleCssImport = hasModuleCssImport ? options.moduleCssImport : "stillwind/module-css";
1456
1671
  await graph.collectDependencies(entrySource, entrySummary);
1457
- const typedSources = await graph.collectTypedSources(entrySource);
1672
+ const typedSources = await Promise.all((await graph.collectTypedSources(entrySource)).map(async (source) => {
1673
+ const summary = source.moduleId === entrySource.moduleId ? entrySummary : graph.summary(source.moduleId);
1674
+ return summary && summary.orderingImports.length > 0 ? {
1675
+ ...source,
1676
+ orderingModules: await tracePhase("ordering", 1, () => graph.orderingModules(source, summary))
1677
+ } : source;
1678
+ }));
1458
1679
  const producer = analysis ? void 0 : entrySource.moduleId;
1459
1680
  const projectOutput = await tracePhase("native-compile", typedSources.length, () => compileWithPlugins(session, () => session.compile(typedSources, producer), PLUGIN_ROUNDS));
1460
1681
  if (analysis) recordAnalysis(analysis, projectOutput.modules, session, typedSources, graph);
@@ -1741,24 +1962,6 @@ function defaultPluginExport(module, specifier) {
1741
1962
  return plugin;
1742
1963
  }
1743
1964
  /**
1744
- * Returns the utility text before the cursor for plugin catalog lookup.
1745
- *
1746
- * @param text - Text before the cursor. The candidate ends at the cursor and starts after the
1747
- * last whitespace, quote, backtick, `;`, `{`, or `}`.
1748
- * @returns The candidate without its variants, such as `icon-mdi--cl` for `hover:icon-mdi--cl`.
1749
- */
1750
- function catalogInput(text) {
1751
- const candidate = /[^\s"'`;{}]*$/.exec(text)[0];
1752
- let depth = 0;
1753
- for (let index = candidate.length - 1; index >= 0; index--) {
1754
- const character = candidate[index];
1755
- if (character === "]" || character === ")") depth++;
1756
- else if ((character === "[" || character === "(") && depth > 0) depth--;
1757
- else if (character === ":" && depth === 0) return candidate.slice(index + 1);
1758
- }
1759
- return candidate;
1760
- }
1761
- /**
1762
1965
  * Identifies one `@plugin` statement independently of its request ID.
1763
1966
  *
1764
1967
  * @param request - Plugin request.
@@ -1936,7 +2139,7 @@ var PluginRuntime = class {
1936
2139
  kind: "plugin",
1937
2140
  name: request.specifier
1938
2141
  },
1939
- tailwind: nativePlugin(plugin) ? void 0 : (await import("./configuration-MQZe6ufN.js")).configurePlugin(plugin, request.pluginOptions ?? [])
2142
+ tailwind: nativePlugin(plugin) ? void 0 : (await import("./configuration-BckWlAj2.js")).configurePlugin(plugin, request.pluginOptions ?? [])
1940
2143
  };
1941
2144
  this.#instances.set(key, instance);
1942
2145
  }
@@ -1969,7 +2172,7 @@ var PluginRuntime = class {
1969
2172
  let current = loader;
1970
2173
  if (instances.length || project) {
1971
2174
  this.#tailwindInstances = instances;
1972
- const { TailwindRuntime } = await import("./plugin-CNOsrkrd.js");
2175
+ const { TailwindRuntime } = await import("./plugin-BG0VOzNB.js");
1973
2176
  const editor = loader.editorQuery();
1974
2177
  this.#tailwind = new TailwindRuntime(instances.map((instance) => instance.tailwind), editor.themeTokens(), editor.legacyThemeKeys(), project);
1975
2178
  if (this.previous) await this.resolve(this.previous.#requested);
@@ -2600,45 +2803,18 @@ var CandidateQueries = class {
2600
2803
  }
2601
2804
  };
2602
2805
  /**
2603
- * Splits at delimiters outside brackets, parentheses, single or double quotes, and escapes.
2604
- * The operation preserves source spelling and does not validate nesting syntax.
2806
+ * Splits at delimiters outside brackets, parentheses, single or double quotes, and escapes,
2807
+ * with the grouping rules of the native candidate parser.
2605
2808
  *
2606
- * @param text - Candidate text whose backslashes escape the following UTF-16 code unit.
2607
- * @param delimiter - One UTF-16 code unit, such as `:` or `/`, that is not a bracket,
2608
- * parenthesis, quote, or backslash.
2609
- * @returns Segments in their original order, including empty segments. Nothing is trimmed
2610
- * or unescaped, and an empty input returns one empty segment.
2809
+ * @param text - Candidate text whose backslashes escape the following character.
2810
+ * @param delimiter - One character, such as `:` or `/`, that is not a bracket, parenthesis,
2811
+ * quote, or backslash.
2812
+ * @returns Segments in their original order, including empty segments. Nothing is trimmed or
2813
+ * unescaped, and an empty input returns one empty segment. After a closing bracket without a
2814
+ * matching opener, the rest of the text stays in the last segment.
2611
2815
  */
2612
2816
  function segments(text, delimiter) {
2613
- const result = [];
2614
- let start = 0;
2615
- let depth = 0;
2616
- let quote = "";
2617
- let escaped = false;
2618
- for (let index = 0; index < text.length; index++) {
2619
- const character = text[index];
2620
- if (escaped) {
2621
- escaped = false;
2622
- continue;
2623
- }
2624
- if (character === "\\") {
2625
- escaped = true;
2626
- continue;
2627
- }
2628
- if (quote) {
2629
- if (character === quote) quote = "";
2630
- continue;
2631
- }
2632
- if (character === "'" || character === "\"") quote = character;
2633
- else if (character === "[" || character === "(") depth++;
2634
- else if (character === "]" || character === ")") depth--;
2635
- else if (character === delimiter && depth === 0) {
2636
- result.push(text.slice(start, index));
2637
- start = index + 1;
2638
- }
2639
- }
2640
- result.push(text.slice(start));
2641
- return result;
2817
+ return candidateSegments(text, delimiter);
2642
2818
  }
2643
2819
  /**
2644
2820
  * Describes an added marker class and the definitions that make it a marker.
@@ -3267,7 +3443,8 @@ var CheckerSource = class {
3267
3443
  * @param ids - Resolved source identities mapped to their main checker filenames for import
3268
3444
  * rewriting.
3269
3445
  * @throws If a byte boundary is invalid, producer identities conflict, a mapped producer does not
3270
- * end with a closing parenthesis, edits overlap, or projection decoding fails.
3446
+ * end with a closing parenthesis or does not parse as a call, edits overlap, or projection
3447
+ * decoding fails.
3271
3448
  */
3272
3449
  constructor(source, buffer, index, assets, ids) {
3273
3450
  this.source = source;
@@ -3295,9 +3472,9 @@ var CheckerSource = class {
3295
3472
  });
3296
3473
  const call = buffer.source.slice(start, end);
3297
3474
  if (!call.endsWith(")")) throw new Error(`Cannot locate producer in ${source.moduleId}`);
3298
- const separator = [...call.matchAll(/[,(]/g)].some((match) => skipTrivia(call, match.index + 1) === call.length - 1) ? "" : ",";
3299
- const identity = `{readonly __stillwindDeclarationIdentity:${JSON.stringify(key)}}`;
3300
3475
  const syntax = source.kind === "direct" ? source.syntax : source.projection.syntax;
3476
+ const separator = endsArgumentList(call, scriptKinds[syntax.language]) ? "" : ",";
3477
+ const identity = `{readonly __stillwindDeclarationIdentity:${JSON.stringify(key)}}`;
3301
3478
  const argument = syntax.language === "js" || syntax.language === "jsx" ? `/** @type {${identity}} */ (/** @type {unknown} */ (undefined))` : `undefined as unknown as ${identity}`;
3302
3479
  this.#edits.push({
3303
3480
  at: end - 1,
@@ -3488,19 +3665,29 @@ function projectionPoints(source) {
3488
3665
  function base64url(text) {
3489
3666
  return btoa(String.fromCharCode(...new TextEncoder().encode(text))).replaceAll("+", "-").replaceAll("/", "_").replace(/=+/, "");
3490
3667
  }
3668
+ /** Script kinds of the checker buffer languages. */
3669
+ const scriptKinds = {
3670
+ js: ts.ScriptKind.JS,
3671
+ jsx: ts.ScriptKind.JSX,
3672
+ ts: ts.ScriptKind.TS,
3673
+ tsx: ts.ScriptKind.TSX,
3674
+ dts: ts.ScriptKind.TS
3675
+ };
3491
3676
  /**
3492
- * Finds the next token start after whitespace and comments.
3677
+ * Reports whether a new argument can follow the existing arguments of a call without a comma.
3493
3678
  *
3494
- * @param text - Checker call text to scan.
3495
- * @param offset - UTF-16 position at which scanning starts.
3496
- * @returns UTF-16 start of the next token, or text.length at end of input.
3679
+ * @param call - Text of one call expression, ending with its closing parenthesis.
3680
+ * @param kind - Script kind of the checker buffer that contains the call.
3681
+ * @returns Whether the call has no arguments or ends them with a trailing comma, as in `f()` or
3682
+ * `f(a,)`.
3683
+ * @throws If the text does not parse as a single call expression.
3497
3684
  */
3498
- function skipTrivia(text, offset) {
3499
- const scanner = ts.createScanner(ts.ScriptTarget.Latest, true);
3500
- scanner.setText(text);
3501
- scanner.resetTokenState(offset);
3502
- scanner.scan();
3503
- return scanner.getTokenStart();
3685
+ function endsArgumentList(call, kind) {
3686
+ const file = ts.createSourceFile("call.ts", call, ts.ScriptTarget.Latest, false, kind);
3687
+ const statement = file.statements.length === 1 ? file.statements[0] : void 0;
3688
+ const expression = statement && ts.isExpressionStatement(statement) ? statement.expression : void 0;
3689
+ if (!expression || !ts.isCallExpression(expression) || expression.end !== call.length) throw new Error("Cannot parse producer call");
3690
+ return expression.arguments.length === 0 || expression.arguments.hasTrailingComma === true;
3504
3691
  }
3505
3692
  // src/editor/previews.ts
3506
3693
  /** Captures compiler input plans and assembles their required declaration previews. */
@@ -3591,6 +3778,29 @@ var GeneratedPreviews = class {
3591
3778
  return site ? this.preview(site) : void 0;
3592
3779
  }
3593
3780
  /**
3781
+ * Assembles previews for a sequence of declaration identities in their supplied order,
3782
+ * deduplicating CSS parts and runtime expressions.
3783
+ *
3784
+ * @param identities - Declaration identities to combine.
3785
+ * @returns Combined preview, or undefined if no identity produces CSS.
3786
+ */
3787
+ previewIdentities(identities) {
3788
+ const parts = [];
3789
+ const runtimeNames = /* @__PURE__ */ new Set();
3790
+ for (const identity of identities) {
3791
+ const preview = this.previewIdentity(identity);
3792
+ if (!preview) continue;
3793
+ if (preview.css) parts.push(preview.css);
3794
+ for (const name of preview.runtimeNames) runtimeNames.add(name);
3795
+ }
3796
+ const css = [...new Set(parts)].join("\n");
3797
+ if (!css) return;
3798
+ return {
3799
+ css,
3800
+ runtimeNames: [...runtimeNames]
3801
+ };
3802
+ }
3803
+ /**
3594
3804
  * Assembles `site` and its dependencies from this capture batch. Composed styles precede
3595
3805
  * the site's CSS, and global definitions follow it. Each dependency identity is visited once.
3596
3806
  * Identical CSS parts and runtime expression text are deduplicated in traversal order.
@@ -3602,7 +3812,7 @@ var GeneratedPreviews = class {
3602
3812
  */
3603
3813
  preview(site) {
3604
3814
  const preview = this.assemble(site);
3605
- return preview?.css ? preview : void 0;
3815
+ return preview && (preview.css || preview.js || preview.documentation) ? preview : void 0;
3606
3816
  }
3607
3817
  /**
3608
3818
  * Assembles `site` as {@link preview} does and keeps a successful empty result.
@@ -3612,6 +3822,16 @@ var GeneratedPreviews = class {
3612
3822
  * or undefined if any required site is missing or invalid.
3613
3823
  */
3614
3824
  assemble(site) {
3825
+ if (site.kind === "media") return site.valid && site.css ? {
3826
+ css: "",
3827
+ js: site.css,
3828
+ runtimeNames: []
3829
+ } : void 0;
3830
+ if (site.kind === "ref") return site.valid ? {
3831
+ css: "",
3832
+ documentation: "Adds a generated marker class to the element for ref selectors and queries.",
3833
+ runtimeNames: []
3834
+ } : void 0;
3615
3835
  const parts = [];
3616
3836
  const runtimeNames = /* @__PURE__ */ new Set();
3617
3837
  const seen = /* @__PURE__ */ new Set();
@@ -3800,6 +4020,46 @@ var SourceBindings = class {
3800
4020
  return this.#nodeAssets.get(node);
3801
4021
  }
3802
4022
  /**
4023
+ * Follows a stable identifier or namespace-import reference to its final initializer
4024
+ * expression across the captured source graph. Mutated bindings and cyclic aliases stop
4025
+ * resolution.
4026
+ *
4027
+ * @param source - Prepared source whose checker AST contains `node`.
4028
+ * @param node - Reference expression to resolve.
4029
+ * @returns The declaring source and initializer expression, or undefined when `node` does
4030
+ * not reference a stable variable initializer.
4031
+ */
4032
+ initializer(source, node) {
4033
+ const seen = /* @__PURE__ */ new Set();
4034
+ let currentSource = source;
4035
+ let current = node;
4036
+ let resolved;
4037
+ for (;;) {
4038
+ while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current) || ts.isNonNullExpression(current)) current = current.expression;
4039
+ if (ts.isPropertyAccessExpression(current) && ts.isIdentifier(current.expression)) {
4040
+ if (!this.#checker.getSymbolAtLocation(current.expression)?.declarations?.some(ts.isNamespaceImport)) return resolved;
4041
+ } else if (!ts.isIdentifier(current)) return resolved;
4042
+ let symbol = this.#checker.getSymbolAtLocation(current);
4043
+ if (!symbol || this.#mutated.has(symbol) || seen.has(symbol)) return resolved;
4044
+ seen.add(symbol);
4045
+ if (symbol.flags & ts.SymbolFlags.Alias) {
4046
+ symbol = this.#checker.getAliasedSymbol(symbol);
4047
+ if (this.#mutated.has(symbol) || seen.has(symbol)) return resolved;
4048
+ seen.add(symbol);
4049
+ }
4050
+ const declaration = symbol.valueDeclaration;
4051
+ if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer) return resolved;
4052
+ const owner = this.files.get(declaration.getSourceFile().fileName)?.source;
4053
+ if (!owner) return resolved;
4054
+ currentSource = owner;
4055
+ current = declaration.initializer;
4056
+ resolved = {
4057
+ source: currentSource,
4058
+ node: declaration.initializer
4059
+ };
4060
+ }
4061
+ }
4062
+ /**
3803
4063
  * Returns the comments that contain `swlint-*` directives in `source`'s original buffer.
3804
4064
  *
3805
4065
  * @param source - Prepared source of this index.
@@ -4050,8 +4310,8 @@ var SourceIndex = class {
4050
4310
  for (const argument of node.arguments) if (ts.isStringLiteralLike(argument)) this.#literal(source, argument, "", "elementVariants");
4051
4311
  return;
4052
4312
  }
4053
- if (this.#bindings.producer(node.expression, "cva")) {
4054
- this.#cva(source, node);
4313
+ if (this.#bindings.producer(node.expression, "recipe")) {
4314
+ this.#recipe(source, node);
4055
4315
  return;
4056
4316
  }
4057
4317
  if (this.asset(source, node.expression)?.identity.kind === "keyframes") {
@@ -4127,6 +4387,16 @@ var SourceIndex = class {
4127
4387
  return this.#bindings.asset(source, node);
4128
4388
  }
4129
4389
  /**
4390
+ * Follows a stable variable or import reference to its initializer expression.
4391
+ *
4392
+ * @param source - Prepared source whose checker AST contains `node`.
4393
+ * @param node - Reference expression to resolve.
4394
+ * @returns The declaring source and initializer expression, or undefined when unresolved.
4395
+ */
4396
+ initializer(source, node) {
4397
+ return this.#bindings.initializer(source, node);
4398
+ }
4399
+ /**
4130
4400
  * Recognizes a call of an imported Stillwind style producer or of one of its methods,
4131
4401
  * such as `style()` or `style.when()`.
4132
4402
  *
@@ -4309,52 +4579,76 @@ var SourceIndex = class {
4309
4579
  if (literal) literal.key = true;
4310
4580
  }
4311
4581
  /**
4312
- * Records the variant keys of a `style.cva()` call. The compiler captures the utility
4582
+ * Records the variant keys of a `style.recipe()` call. The compiler captures the utility
4313
4583
  * literals of the call, so this method adds only keys.
4314
4584
  *
4315
4585
  * @param source - Prepared source whose checker AST contains `call`.
4316
- * @param call - Call whose callee is the `cva` method of a Stillwind style import.
4317
- * Keys are read from the base input, from each option of `variants`, and from the
4318
- * `class` and `className` inputs of `compoundVariants`. Other syntax adds nothing.
4586
+ * @param call - Call whose callee is the `recipe` method of a Stillwind style import.
4587
+ * Keys are read from the base input, from each value of `slots`, from each option of
4588
+ * `variants`, and from the `class` and `className` inputs of `compoundVariants` and
4589
+ * `compoundSlots`. With `slots`, an object whose keys all name slots is read slot by slot.
4590
+ * Other syntax adds nothing.
4319
4591
  */
4320
- #cva(source, call) {
4592
+ #recipe(source, call) {
4321
4593
  const [base, config] = call.arguments;
4322
- this.#cvaInput(source, base, "");
4594
+ this.#recipeInput(source, base, "");
4323
4595
  if (!config || !ts.isObjectLiteralExpression(config)) return;
4324
- for (const property of config.properties) {
4325
- if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4596
+ const entries = config.properties.filter((property) => ts.isPropertyAssignment(property) && !ts.isComputedPropertyName(property.name));
4597
+ const slots = /* @__PURE__ */ new Set();
4598
+ for (const property of entries) if (propertyName(property) === "slots" && ts.isObjectLiteralExpression(property.initializer)) {
4599
+ slots.add("base");
4600
+ for (const slot of property.initializer.properties) if (ts.isPropertyAssignment(slot) && !ts.isComputedPropertyName(slot.name)) {
4601
+ slots.add(propertyName(slot));
4602
+ this.#recipeInput(source, slot.initializer, "");
4603
+ }
4604
+ }
4605
+ for (const property of entries) {
4326
4606
  const name = propertyName(property);
4327
4607
  const value = property.initializer;
4328
4608
  if (name === "variants" && ts.isObjectLiteralExpression(value)) {
4329
4609
  for (const axis of value.properties) if (ts.isPropertyAssignment(axis) && ts.isObjectLiteralExpression(axis.initializer)) {
4330
- for (const option of axis.initializer.properties) if (ts.isPropertyAssignment(option)) this.#cvaInput(source, option.initializer, "");
4610
+ for (const option of axis.initializer.properties) if (ts.isPropertyAssignment(option)) this.#recipeSlotInput(source, option.initializer, slots);
4331
4611
  }
4332
- } else if (name === "compoundVariants" && ts.isArrayLiteralExpression(value)) for (const compound of value.elements) {
4612
+ } else if ((name === "compoundVariants" || name === "compoundSlots") && ts.isArrayLiteralExpression(value)) for (const compound of value.elements) {
4333
4613
  if (!ts.isObjectLiteralExpression(compound)) continue;
4334
- for (const entry of compound.properties) if (ts.isPropertyAssignment(entry) && !ts.isComputedPropertyName(entry.name) && ["class", "className"].includes(propertyName(entry))) this.#cvaInput(source, entry.initializer, "");
4614
+ for (const entry of compound.properties) if (ts.isPropertyAssignment(entry) && !ts.isComputedPropertyName(entry.name) && ["class", "className"].includes(propertyName(entry))) this.#recipeSlotInput(source, entry.initializer, name === "compoundVariants" ? slots : /* @__PURE__ */ new Set());
4335
4615
  }
4336
4616
  }
4337
4617
  }
4338
4618
  /**
4339
- * Records the variant keys in one CVA utility input, including keys in nested arrays and
4619
+ * Records the variant keys in a recipe input that may select inputs by slot.
4620
+ *
4621
+ * @param source - Prepared source whose checker AST contains `node`.
4622
+ * @param node - An input for the `base` slot, or an object whose keys all name slots.
4623
+ * @param slots - Declared slot names including `base`, or an empty set without slots.
4624
+ */
4625
+ #recipeSlotInput(source, node, slots) {
4626
+ if (slots.size > 0 && ts.isObjectLiteralExpression(node) && node.properties.length > 0 && node.properties.every((property) => ts.isPropertyAssignment(property) && !ts.isComputedPropertyName(property.name) && slots.has(propertyName(property)))) {
4627
+ for (const property of node.properties) this.#recipeInput(source, property.initializer, "");
4628
+ return;
4629
+ }
4630
+ this.#recipeInput(source, node, "");
4631
+ }
4632
+ /**
4633
+ * Records the variant keys in one recipe utility input, including keys in nested arrays and
4340
4634
  * variant groups.
4341
4635
  *
4342
4636
  * @param source - Prepared source whose checker AST contains `node`.
4343
- * @param node - CVA input, or undefined for an omitted argument.
4637
+ * @param node - recipe input, or undefined for an omitted argument.
4344
4638
  * @param prefix - Decoded variants of the enclosing keys, each ending in `:`.
4345
4639
  */
4346
- #cvaInput(source, node, prefix) {
4640
+ #recipeInput(source, node, prefix) {
4347
4641
  while (node && (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node))) node = node.expression;
4348
4642
  if (!node) return;
4349
4643
  if (ts.isArrayLiteralExpression(node)) {
4350
- for (const element of node.elements) this.#cvaInput(source, element, prefix);
4644
+ for (const element of node.elements) this.#recipeInput(source, element, prefix);
4351
4645
  return;
4352
4646
  }
4353
4647
  if (ts.isObjectLiteralExpression(node)) for (const property of node.properties) {
4354
4648
  if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4355
4649
  this.#key(source, property, prefix, "utility");
4356
4650
  const name = propertyName(property);
4357
- if (name === "" || name.endsWith(":")) this.#cvaInput(source, property.initializer, name === ":" ? prefix : prefix + name);
4651
+ if (name === "" || name.endsWith(":")) this.#recipeInput(source, property.initializer, name === ":" ? prefix : prefix + name);
4358
4652
  }
4359
4653
  }
4360
4654
  /**
@@ -4601,7 +4895,7 @@ var SourceQueries = class {
4601
4895
  const candidates = this.#resolved.get(request.candidate) ?? this.#candidates;
4602
4896
  const current = literal && request.snapshot === this.#revision;
4603
4897
  const css = current ? request.candidate.endsWith(":") ? candidates.variant(request.candidate, literal.context) : this.#preview(literal, request.candidate.slice(literal.prefix.length)) ?? candidates.preview(request.candidate, literal.context) : void 0;
4604
- const marker = current ? candidates.marker(request.candidate, literal.context) : null;
4898
+ const marker = current && !literal.site?.native.enclosingVariant ? candidates.marker(request.candidate, literal.context) : null;
4605
4899
  if (css || marker) {
4606
4900
  const formatted = css ? this.#query.formatCss(css, this.#annotations) : "";
4607
4901
  result.hover = {
@@ -4615,7 +4909,7 @@ var SourceQueries = class {
4615
4909
  return result;
4616
4910
  }
4617
4911
  if (request.kind === "previews") {
4618
- result.previews = this.#index.previews.sites(source).filter((site) => site.native.kind !== "input" && site.native.kind !== "variant").flatMap((site) => {
4912
+ result.previews = this.#index.previews.sites(source).filter((site) => site.native.kind !== "input" && site.native.kind !== "variant" && site.native.kind !== "media" && site.native.kind !== "ref").flatMap((site) => {
4619
4913
  const preview = this.#index.previews.assemble(site.native);
4620
4914
  const range = {
4621
4915
  start: site.start,
@@ -4675,7 +4969,7 @@ var SourceQueries = class {
4675
4969
  if (token) {
4676
4970
  const candidate = token.literal.prefix + token.text;
4677
4971
  const css = token.literal.key ? this.#candidates.variant(candidate, token.literal.context) : this.#preview(token.literal, token.text, token.site);
4678
- const marker = token.literal.key ? null : this.#candidates.marker(candidate, token.literal.context);
4972
+ const marker = token.literal.key || token.site?.native.enclosingVariant ? null : this.#candidates.marker(candidate, token.literal.context);
4679
4973
  if (css || marker) result.hover = {
4680
4974
  start: token.start,
4681
4975
  end: token.end,
@@ -4688,7 +4982,7 @@ var SourceQueries = class {
4688
4982
  const input = this.#completionInput(source, request.offset);
4689
4983
  if (!input) return result;
4690
4984
  const { literal, start, end, prefix } = input;
4691
- const native = this.#candidates.complete(literal.prefix + prefix, literal.context, request.snippets === true).filter(({ label, marker }) => literal.key ? !marker && label.endsWith(":") : marker || label.endsWith(":") || !literal.site || this.#preview(literal, label.slice(literal.prefix.length)));
4985
+ const native = this.#candidates.complete(literal.prefix + prefix, literal.context, request.snippets === true).filter(({ label, marker }) => literal.key ? !marker && label.endsWith(":") : marker && !literal.site?.native.enclosingVariant || label.endsWith(":") || !literal.site || this.#preview(literal, label.slice(literal.prefix.length)));
4692
4986
  const known = new Set(native.map(({ label }) => label));
4693
4987
  const { names: catalog, incomplete } = literal.key ? {
4694
4988
  names: [],
@@ -4735,34 +5029,169 @@ var SourceQueries = class {
4735
5029
  let reference;
4736
5030
  while (node) {
4737
5031
  const site = this.#index.previewSite(source, node);
4738
- if (site) {
5032
+ if (site && (!reference || site.native.kind === "use")) {
4739
5033
  const preview = this.#index.previews.preview(site.native);
4740
5034
  const range = this.#index.range(source, node);
4741
- return preview && range ? {
4742
- start: range[0],
4743
- end: range[1],
4744
- css: this.#query.formatCss(preview.css, this.#annotations),
4745
- ...preview.runtimeNames.length ? { runtimeNames: preview.runtimeNames } : {}
4746
- } : void 0;
5035
+ return preview && range ? this.#formatExpressionPreview(preview, range) : void 0;
5036
+ }
5037
+ if (ts.isCallExpression(node)) {
5038
+ const recipeCall = this.#recipeCallPreview(source, node);
5039
+ const range = this.#index.range(source, node);
5040
+ if (recipeCall && range) return this.#formatExpressionPreview(recipeCall, range);
5041
+ break;
4747
5042
  }
4748
5043
  if (!reference) {
4749
5044
  const asset = this.#index.asset(source, node);
4750
- const preview = asset && this.#index.previews.previewIdentity(asset.identity);
5045
+ let preview = asset && this.#index.previews.previewIdentity(asset.identity);
5046
+ if (!preview) {
5047
+ const init = this.#index.initializer(source, node);
5048
+ if (init) {
5049
+ if (ts.isCallExpression(init.node)) preview = this.#recipeCallPreview(init.source, init.node);
5050
+ if (!preview) {
5051
+ const initSite = this.#index.previewSite(init.source, init.node);
5052
+ if (initSite) preview = this.#index.previews.preview(initSite.native);
5053
+ else {
5054
+ const initRange = this.#index.range(init.source, init.node);
5055
+ const variantSite = initRange && this.#index.previews.sites(init.source).find((site) => site.native.kind === "variant" && initRange[0] <= site.start && site.end <= initRange[1]);
5056
+ preview = variantSite && this.#index.previews.preview(variantSite.native);
5057
+ }
5058
+ }
5059
+ }
5060
+ }
5061
+ if (!preview) {
5062
+ const subtree = this.#subtreePreview(source, node);
5063
+ if (subtree) return this.#formatExpressionPreview(subtree.preview, subtree.range);
5064
+ }
4751
5065
  const range = this.#index.range(source, node);
4752
5066
  if (preview && range) reference = {
4753
5067
  preview,
4754
5068
  range
4755
5069
  };
4756
5070
  }
4757
- if (ts.isCallExpression(node)) break;
4758
5071
  node = node.parent;
4759
5072
  }
4760
- return reference ? {
4761
- start: reference.range[0],
4762
- end: reference.range[1],
4763
- css: this.#query.formatCss(reference.preview.css, this.#annotations),
4764
- ...reference.preview.runtimeNames.length ? { runtimeNames: reference.preview.runtimeNames } : {}
4765
- } : void 0;
5073
+ return reference ? this.#formatExpressionPreview(reference.preview, reference.range) : void 0;
5074
+ }
5075
+ /**
5076
+ * Filters a `recipe({ ... })` call to the values selected by its static arguments and
5077
+ * `defaultVariants`. Dynamic axes retain all their options; a spread or non-literal
5078
+ * argument falls back to the complete recipe preview.
5079
+ *
5080
+ * @param source - Prepared source containing `node`.
5081
+ * @param node - Call expression that may invoke a `style.recipe()` factory.
5082
+ * @returns Assembled preview for matching recipe values, or undefined if `node` is not a
5083
+ * recipe call.
5084
+ */
5085
+ #recipeCallPreview(source, node) {
5086
+ const init = this.#index.initializer(source, node.expression);
5087
+ const initSite = init && this.#index.previewSite(init.source, init.node);
5088
+ const recipe = initSite?.native.recipe;
5089
+ if (!recipe) return;
5090
+ const arg = node.arguments[0];
5091
+ const selected = /* @__PURE__ */ new Map();
5092
+ const dynamic = /* @__PURE__ */ new Set();
5093
+ if (arg && !(ts.isIdentifier(arg) && arg.text === "undefined")) {
5094
+ if (!ts.isObjectLiteralExpression(arg)) return this.#index.previews.preview(initSite.native);
5095
+ for (const property of arg.properties) {
5096
+ if (ts.isSpreadAssignment(property)) return this.#index.previews.preview(initSite.native);
5097
+ if (ts.isShorthandPropertyAssignment(property)) {
5098
+ dynamic.add(property.name.text);
5099
+ continue;
5100
+ }
5101
+ if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) return this.#index.previews.preview(initSite.native);
5102
+ const axis = ts.isStringLiteralLike(property.name) ? property.name.text : ts.isNumericLiteral(property.name) || ts.isIdentifier(property.name) ? property.name.text : void 0;
5103
+ if (!axis) return this.#index.previews.preview(initSite.native);
5104
+ const option = this.#staticRecipeOption(property.initializer);
5105
+ if (!option) dynamic.add(axis);
5106
+ else selected.set(axis, option.value);
5107
+ }
5108
+ }
5109
+ for (const { axis, value } of recipe.defaultVariants) if (!selected.has(axis) && !dynamic.has(axis)) selected.set(axis, value);
5110
+ const matching = recipe.values.filter((entry) => entry.conditions.every(({ axis, values }) => {
5111
+ if (dynamic.has(axis)) return true;
5112
+ const chosen = selected.get(axis);
5113
+ return chosen !== void 0 && values.includes(chosen);
5114
+ })).map((entry) => entry.identity);
5115
+ return this.#index.previews.previewIdentities(matching);
5116
+ }
5117
+ /**
5118
+ * Decodes a static recipe option literal (`string`, `boolean`, `number`, `null`, or
5119
+ * `undefined`), or returns `undefined` for runtime expressions.
5120
+ *
5121
+ * @param expr - Initializer expression of a recipe call option.
5122
+ * @returns Normalized option key wrapped in an object (`value: undefined` for nullish
5123
+ * literals), or `undefined` when the expression is dynamic.
5124
+ */
5125
+ #staticRecipeOption(expr) {
5126
+ const inner = ts.isParenthesizedExpression(expr) ? expr.expression : expr;
5127
+ if (ts.isStringLiteralLike(inner)) return { value: inner.text };
5128
+ if (ts.isNumericLiteral(inner)) return { value: String(Number(inner.text)) };
5129
+ if (inner.kind === ts.SyntaxKind.TrueKeyword) return { value: "true" };
5130
+ if (inner.kind === ts.SyntaxKind.FalseKeyword) return { value: "false" };
5131
+ if (inner.kind === ts.SyntaxKind.NullKeyword || ts.isIdentifier(inner) && inner.text === "undefined") return { value: void 0 };
5132
+ }
5133
+ /**
5134
+ * Assembles a scoped preview for a compound sub-expression inside a style or keyframes
5135
+ * call (such as `active && [...]`, `active ? a : b`, `{ "hover:": [...] }`, or a
5136
+ * keyframe frame property) by combining the captured input and use sites it contains.
5137
+ *
5138
+ * @param source - Prepared source containing `node`.
5139
+ * @param node - Candidate AST node during ancestor traversal.
5140
+ * @returns Combined preview and original UTF-16 range, or undefined when `node` is not a
5141
+ * compound sub-expression with captured inner sites.
5142
+ */
5143
+ #subtreePreview(source, node) {
5144
+ if (!(ts.isBinaryExpression(node) || ts.isConditionalExpression(node) || ts.isElementAccessExpression(node) || ts.isArrayLiteralExpression(node) || ts.isObjectLiteralExpression(node) || ts.isPropertyAssignment(node))) return;
5145
+ if (ts.isCallExpression(node.parent) && node.parent.arguments.length === 1 && node.parent.arguments[0] === node && this.#index.previewSite(source, node.parent)) return;
5146
+ const range = this.#index.range(source, node);
5147
+ if (!range) return;
5148
+ const inner = this.#index.previews.sites(source).filter((site) => (site.native.kind === "input" || site.native.kind === "use") && range[0] <= site.start && site.end <= range[1]).sort((a, b) => a.start - b.start || a.end - b.end);
5149
+ if (!inner.length) return;
5150
+ const parts = [];
5151
+ const runtimeNames = /* @__PURE__ */ new Set();
5152
+ for (const site of inner) {
5153
+ const preview = this.#index.previews.preview(site.native);
5154
+ if (!preview) continue;
5155
+ if (preview.css) parts.push(preview.css);
5156
+ for (const name of preview.runtimeNames) runtimeNames.add(name);
5157
+ }
5158
+ const css = [...new Set(parts)].join("\n");
5159
+ if (!css) return;
5160
+ return {
5161
+ preview: {
5162
+ css,
5163
+ runtimeNames: [...runtimeNames]
5164
+ },
5165
+ range
5166
+ };
5167
+ }
5168
+ /**
5169
+ * Formats a resolved expression preview into an editor hover payload.
5170
+ *
5171
+ * @param preview - Assembled CSS or lowered JavaScript preview.
5172
+ * @param range - Inclusive start and exclusive end in original UTF-16 coordinates.
5173
+ * @returns Hover payload for CSS or JavaScript output.
5174
+ * @throws If the native formatter rejects the CSS preview.
5175
+ */
5176
+ #formatExpressionPreview(preview, range) {
5177
+ if (preview.js) return {
5178
+ start: range[0],
5179
+ end: range[1],
5180
+ css: "",
5181
+ documentation: `\`\`\`js\n${preview.js}\n\`\`\``
5182
+ };
5183
+ if (preview.documentation) return {
5184
+ start: range[0],
5185
+ end: range[1],
5186
+ css: "",
5187
+ documentation: preview.documentation
5188
+ };
5189
+ return {
5190
+ start: range[0],
5191
+ end: range[1],
5192
+ css: this.#query.formatCss(preview.css, this.#annotations),
5193
+ ...preview.runtimeNames.length ? { runtimeNames: preview.runtimeNames } : {}
5194
+ };
4766
5195
  }
4767
5196
  /**
4768
5197
  * Renders candidate text in a captured input plan or the standalone input registry.
@@ -4925,7 +5354,7 @@ var SourceQueries = class {
4925
5354
  let reference = false;
4926
5355
  while (node && (ts.isIdentifier(node) || ts.isStringLiteralLike(node) || ts.isPropertyAccessExpression(node) || ts.isParenthesizedExpression(node) || ts.isTaggedTemplateExpression(node) || ts.isCallExpression(node) && !this.#index.styleCall(node))) {
4927
5356
  const callee = ts.isCallExpression(node) ? node.expression : ts.isTaggedTemplateExpression(node) ? node.tag : void 0;
4928
- if (callee && (this.#index.asset(source, callee)?.identity.kind === "ref" || ts.isPropertyAccessExpression(callee) && ["at", "in"].includes(callee.name.text))) reference = true;
5357
+ if (callee && this.#refCallee(source, callee)) reference = true;
4929
5358
  expression = node;
4930
5359
  node = node.parent;
4931
5360
  }
@@ -4939,6 +5368,25 @@ var SourceQueries = class {
4939
5368
  css: this.#query.formatCss(preview.css, this.#annotations)
4940
5369
  } : void 0;
4941
5370
  }
5371
+ /**
5372
+ * Reports whether `callee` calls a ref asset directly or through `.at()` / `.in()` chains.
5373
+ *
5374
+ * @param source - Prepared source stored in this snapshot's index.
5375
+ * @param callee - Call target or template tag to inspect.
5376
+ * @returns Whether the root receiver resolves to a `ref` asset.
5377
+ */
5378
+ #refCallee(source, callee) {
5379
+ while (ts.isParenthesizedExpression(callee)) callee = callee.expression;
5380
+ if (this.#index.asset(source, callee)?.identity.kind === "ref") return true;
5381
+ if (ts.isPropertyAccessExpression(callee) && ["at", "in"].includes(callee.name.text)) {
5382
+ let receiver = callee.expression;
5383
+ while (ts.isParenthesizedExpression(receiver)) receiver = receiver.expression;
5384
+ if (ts.isCallExpression(receiver)) return this.#refCallee(source, receiver.expression);
5385
+ if (ts.isTaggedTemplateExpression(receiver)) return this.#refCallee(source, receiver.tag);
5386
+ return this.#index.asset(source, receiver)?.identity.kind === "ref";
5387
+ }
5388
+ return false;
5389
+ }
4942
5390
  };
4943
5391
  // src/editor/snapshot.ts
4944
5392
  /**
@@ -5345,7 +5793,7 @@ var StylesheetEditor = class {
5345
5793
  async prepare(id, request) {
5346
5794
  if (id !== this.#id) return;
5347
5795
  if (this.#plugins && (request.kind === "completion" || request.kind === "resolve" && request.snapshot === this.#completionSnapshot(request.registryDirectives, request.snippets))) {
5348
- const input = catalogInput(this.#text.slice(0, request.kind === "completion" ? request.offset : request.input));
5796
+ const input = this.#catalogInput(request.kind === "completion" ? request.offset : request.input);
5349
5797
  if (input && !this.#inputCatalogs.has(input)) this.#inputCatalogs.set(input, await this.#plugins.catalog(input));
5350
5798
  }
5351
5799
  if (request.kind === "resolve" && request.snapshot === this.#completionSnapshot(request.registryDirectives, request.snippets) && this.#plugins && !this.#resolved.has(request.candidate)) {
@@ -5498,10 +5946,20 @@ var StylesheetEditor = class {
5498
5946
  * for the candidate's input, without duplicates.
5499
5947
  */
5500
5948
  #catalogAt(offset) {
5501
- const input = catalogInput(this.#text.slice(0, offset));
5949
+ const input = this.#catalogInput(offset);
5502
5950
  return [.../* @__PURE__ */ new Set([...this.#catalog, ...this.#inputCatalogs.get(input) ?? []])];
5503
5951
  }
5504
5952
  /**
5953
+ * Returns the text that a plugin catalog completes at a cursor.
5954
+ *
5955
+ * @param offset - UTF-16 character boundary within the captured text.
5956
+ * @returns The `@apply` candidate or applied `@variant` sequence before the cursor without its
5957
+ * variants, or an empty string at other positions.
5958
+ */
5959
+ #catalogInput(offset) {
5960
+ return stylesheetCatalogInput(this.#text, this.#byteOffset(offset)) ?? "";
5961
+ }
5962
+ /**
5505
5963
  * Converts a cursor in the original buffer to the native query's byte coordinates.
5506
5964
  *
5507
5965
  * @param offset - UTF-16 character boundary within the captured text.
@@ -5533,7 +5991,7 @@ var StylesheetEditor = class {
5533
5991
  const bytes = encoder.encode(text);
5534
5992
  const hover = query.hoverStylesheet(text, encoder.encode(text.slice(0, offset)).length);
5535
5993
  if (!hover) return;
5536
- const css = hover.css.startsWith("--") ? hover.css : hover.css ? this.#query.formatCss(hover.css, this.#preview) : "";
5994
+ const css = hover.css.startsWith("--") ? this.#query.annotatePreview(hover.css, this.#preview) : hover.css ? this.#query.formatCss(hover.css, this.#preview) : "";
5537
5995
  const decoder = new TextDecoder();
5538
5996
  return {
5539
5997
  start: decoder.decode(bytes.subarray(0, hover.start)).length,
@@ -5589,4 +6047,4 @@ function compilerOptions(config) {
5589
6047
  }
5590
6048
  export { cleanModuleId as A, CompilationFailure as C, CompilationProject as D, tracePhase as E, pluginLoader as F, prepareSourcePlugins as I, TypeFactsError as M, attachPlugins as N, ResolutionMismatchError as O, compileWithPlugins as P, warnRejectedNames as S, startPhase as T, defaultPluginExport as _, pluginDirectory as a, analyzeModule as b, CheckerSource as c, queryDesignSystem as d, isStylesheet as f, PluginRuntime as g, loadEditorCssGraph as h, completePluginPaths as i, fileSourceKind as j, sourceKey as k, checkerId as l, loadCssGraph as m, cssEntrypoint as n, queryPluginPaths as o, lintsStylesheet as p, StylesheetEditor as r, EditorSnapshot as s, compilerOptions as t, withRequestedProbes as u, cssBannerPrefix as v, formatReport as w, compileModule as x, finalizeCss as y };
5591
6049
 
5592
- //# sourceMappingURL=options-Cc-SlJed.js.map
6050
+ //# sourceMappingURL=options-B0m3Ajj9.js.map