@stillwind/host 0.10.1 → 0.12.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.
@@ -767,29 +767,49 @@ var CompilationFailure = class extends Error {
767
767
  * @param cause - Optional preparation or checker failure that produced these reports.
768
768
  */
769
769
  constructor(batches, cause) {
770
- super(batches.flatMap((batch) => batch.reports).map(formatReport).join("\n"), { cause });
770
+ super(batches.flatMap((batch) => batch.reports).map((report) => formatReport(report)).join("\n"), { cause });
771
771
  this.batches = batches;
772
772
  }
773
773
  };
774
774
  /**
775
+ * Converts a `file://` URI to a readable filesystem path without requiring Node built-ins.
776
+ *
777
+ * @param uri - Source document URI or filesystem path.
778
+ * @returns Decoded filesystem path for `file://` URIs, or the original string otherwise.
779
+ */
780
+ function displayUri(uri) {
781
+ if (!uri.startsWith("file://")) return uri;
782
+ try {
783
+ const pathname = decodeURIComponent(new URL(uri).pathname);
784
+ return /^\/[A-Za-z]:\//.test(pathname) ? pathname.slice(1) : pathname;
785
+ } catch {
786
+ return uri;
787
+ }
788
+ }
789
+ /**
775
790
  * Formats a compiler report for an Error message or terminal output.
776
791
  *
777
792
  * @param report - Structured report with a primary label, related labels, and notes.
793
+ * @param options - `primaryLocation: false` omits the primary path and range, for hosts that
794
+ * display the primary location separately, such as the Vite error overlay.
778
795
  * @returns Text with one-based line and column ranges for source labels, followed by related labels
779
- * and notes. Document-scoped primary labels use only the URI.
796
+ * and notes. Document-scoped primary labels use only the path.
780
797
  */
781
- function formatReport(report) {
798
+ function formatReport(report, options = {}) {
782
799
  const { location, scope } = report.primary;
783
- const at = scope === "document" ? location.uri : `${location.uri}:${location.startLine + 1}:${location.startColumn + 1}-${location.endLine + 1}:${location.endColumn + 1}`;
784
- const related = report.related.map((label) => {
785
- const loc = label.location;
786
- return ` ${label.scope === "document" ? loc.uri : `${loc.uri}:${loc.startLine + 1}:${loc.startColumn + 1}`}${label.message ? `: ${label.message}` : ""}`;
787
- });
788
- return [
789
- `${at}: ${report.code}: ${report.message}`,
790
- ...related,
791
- ...report.notes.map((note) => ` ${note}`)
792
- ].join("\n");
800
+ const primaryPath = displayUri(location.uri);
801
+ const at = scope === "document" ? primaryPath : `${primaryPath}:${location.startLine + 1}:${location.startColumn + 1}-${location.endLine + 1}:${location.endColumn + 1}`;
802
+ const details = [
803
+ ...report.primary.message ? [` note: ${report.primary.message}`] : [],
804
+ ...report.related.map((label) => {
805
+ const loc = label.location;
806
+ const relatedPath = displayUri(loc.uri);
807
+ return ` related: ${label.scope === "document" ? relatedPath : `${relatedPath}:${loc.startLine + 1}:${loc.startColumn + 1}`}${label.message ? `: ${label.message}` : ""}`;
808
+ }),
809
+ ...report.notes.map((note) => ` note: ${note}`)
810
+ ];
811
+ const heading = `${report.code}: ${report.message}`;
812
+ return [options.primaryLocation === false ? heading : `${at}: ${heading}`, ...details].join("\n");
793
813
  }
794
814
  /** Collects prepared sources and semantic facts for one entry's demanded dependency graph. */
795
815
  var ModuleGraph = class {
@@ -1610,7 +1630,7 @@ function warnRejectedNames(rejected, warn) {
1610
1630
  function reportLintWarnings(output, host) {
1611
1631
  for (const finding of output.lintFindings ?? []) {
1612
1632
  if ((output.lintSettings?.[finding.rule] ?? "off") === "off") continue;
1613
- host.warn(`${finding.rule}: ${finding.message} (${finding.uri}:${finding.start})`);
1633
+ host.warn(`stillwind: ${finding.rule}: ${finding.message} (${displayUri(finding.uri)}:${finding.startLine + 1}:${finding.startColumn + 1})`);
1614
1634
  }
1615
1635
  }
1616
1636
  /**
@@ -2677,9 +2697,10 @@ function patternExpression(target) {
2677
2697
  * @returns Tokens that match, or every token for an empty target list, and unmatched targets.
2678
2698
  */
2679
2699
  function theme(context, request) {
2680
- const tokens = context.query.themeTokens().map(({ name, value, fallback, inline }) => ({
2700
+ const tokens = context.query.themeTokens().map(({ name, value, resolvedValue, fallback, inline }) => ({
2681
2701
  name,
2682
2702
  value,
2703
+ ...resolvedValue ? { resolvedValue } : {},
2683
2704
  source: fallback ? "default" : "project",
2684
2705
  inline
2685
2706
  })).filter(({ source }) => !request.source || source === request.source);
@@ -2704,14 +2725,14 @@ function theme(context, request) {
2704
2725
  * @returns The candidate, with a suggestion when it is invalid.
2705
2726
  * @throws If a matching utility definition is malformed.
2706
2727
  */
2707
- function describe(query, candidates, annotations, name, kind) {
2728
+ function describe(query, candidates, annotations, name, kind, namesOnly) {
2708
2729
  const css = kind === "variants" ? candidates.variant(name, "utility") : candidates.preview(name);
2709
2730
  const marker = kind === "utilities" ? candidates.marker(name) : null;
2710
2731
  if (css || marker) return {
2711
2732
  name,
2712
2733
  kind: kind === "variants" ? "variant" : marker ? "marker" : "utility",
2713
2734
  valid: true,
2714
- css: css ? query.formatCss(css, annotations) : ""
2735
+ css: !namesOnly && css ? query.formatCss(css, annotations) : ""
2715
2736
  };
2716
2737
  const suggestion = kind === "variants" ? query.suggestCandidate(`${name}:flex`)?.replace(/:flex$/, "") : query.suggestCandidate(name);
2717
2738
  return {
@@ -2744,7 +2765,7 @@ function canonicalSpelling(query, name, kind) {
2744
2765
  * @throws If a plugin fails or a matching utility definition is malformed.
2745
2766
  */
2746
2767
  async function candidates(context, request) {
2747
- const { kind } = request;
2768
+ const { kind, namesOnly = false } = request;
2748
2769
  const catalog = new CandidateQueries(context.query);
2749
2770
  const targets = request.targets.length ? request.targets : ["*"];
2750
2771
  const exact = targets.filter((target) => !isPattern(target));
@@ -2757,9 +2778,11 @@ async function candidates(context, request) {
2757
2778
  const name = variant ? label.slice(0, -1) : label;
2758
2779
  return variant === (kind === "variants") && !name.endsWith("-") && expression.test(name) ? [name] : [];
2759
2780
  });
2781
+ const shapes = kind === "utilities" ? context.query.functionalUtilityPatterns(prefix).filter((shape) => expression.test(shape)) : [];
2760
2782
  patterns.push({
2761
2783
  target,
2762
- names: [...new Set(names)].sort()
2784
+ names: [...new Set(names)].sort(),
2785
+ shapes: [...new Set(shapes)].sort()
2763
2786
  });
2764
2787
  }
2765
2788
  const dynamic = [...exact, ...patterns.flatMap(({ names }) => names)].map((name) => kind === "variants" ? `${name}:` : name).filter((text) => context.query.dynamicCandidates(text).length > 0);
@@ -2768,26 +2791,43 @@ async function candidates(context, request) {
2768
2791
  const seen = new Set(exact);
2769
2792
  const listed = [];
2770
2793
  const unmatched = [];
2771
- for (const { target, names } of patterns) {
2794
+ for (const { target, names, shapes } of patterns) {
2772
2795
  let matched = false;
2796
+ const entries = [];
2773
2797
  for (const name of names) {
2774
2798
  if (seen.has(name)) {
2775
2799
  matched = true;
2776
2800
  continue;
2777
2801
  }
2778
- const candidate = describe(query, queries, context.annotations, name, kind);
2802
+ const candidate = describe(query, queries, context.annotations, name, kind, namesOnly);
2779
2803
  if (candidate.valid) {
2780
2804
  matched = true;
2781
2805
  seen.add(name);
2782
- listed.push(candidate);
2806
+ entries.push(candidate);
2783
2807
  }
2784
2808
  }
2809
+ for (const shape of shapes) {
2810
+ if (seen.has(shape)) {
2811
+ matched = true;
2812
+ continue;
2813
+ }
2814
+ matched = true;
2815
+ seen.add(shape);
2816
+ entries.push({
2817
+ name: shape,
2818
+ kind: "pattern",
2819
+ valid: true,
2820
+ css: ""
2821
+ });
2822
+ }
2823
+ entries.sort((a, b) => a.name.localeCompare(b.name));
2824
+ listed.push(...entries);
2785
2825
  if (!matched) unmatched.push(target);
2786
2826
  }
2787
2827
  return {
2788
2828
  tokens: [],
2789
2829
  candidates: [...exact.map((name) => {
2790
- const candidate = describe(query, queries, context.annotations, name, kind);
2830
+ const candidate = describe(query, queries, context.annotations, name, kind, namesOnly);
2791
2831
  const canonical = candidate.valid ? canonicalSpelling(query, name, kind) : void 0;
2792
2832
  return canonical ? {
2793
2833
  ...candidate,
@@ -2950,7 +2990,7 @@ function sortSource(source, index, candidates, options, seed = [], allows) {
2950
2990
  let edits = [...seed];
2951
2991
  const permits = allows ?? (() => true);
2952
2992
  if (options.stringLiterals !== false) {
2953
- const literals = index.literals.filter((literal) => literal.source === source && literal.context === "utility" && permits(literal.boundaries[0], literal.boundaries.at(-1))).map((literal) => {
2993
+ const literals = index.literals.filter((literal) => literal.source === source && literal.context === "utility" && !literal.key && permits(literal.boundaries[0], literal.boundaries.at(-1))).map((literal) => {
2954
2994
  const matches = [...literal.text.matchAll(/\S+/gu)];
2955
2995
  const original = matches.map((match) => match[0]);
2956
2996
  const spellings = matches.map((match) => {
@@ -3954,7 +3994,16 @@ var SourceIndex = class {
3954
3994
  this.#bindings = new SourceBindings(graph, session);
3955
3995
  for (const { source, ast } of this.#bindings.files.values()) {
3956
3996
  walk(ast, (node) => {
3997
+ if (ts.isTaggedTemplateExpression(node) && ts.isNoSubstitutionTemplateLiteral(node.template) && this.asset(source, node.tag)?.identity.kind === "ref") {
3998
+ this.#literal(source, node.template, "", "elementVariants");
3999
+ return;
4000
+ }
3957
4001
  if (!ts.isCallExpression(node)) return;
4002
+ if (this.asset(source, node.expression)?.identity.kind === "ref") {
4003
+ const [argument] = node.arguments;
4004
+ if (node.arguments.length === 1 && ts.isStringLiteralLike(argument)) this.#literal(source, argument, "", "elementVariants");
4005
+ return;
4006
+ }
3958
4007
  const asset = this.asset(source, node);
3959
4008
  if (asset?.identity.kind === "style" || this.#bindings.styleImport(node.expression)) {
3960
4009
  if (node.arguments.length > 1) this.#containers.push({
@@ -3997,6 +4046,14 @@ var SourceIndex = class {
3997
4046
  for (const argument of node.arguments) if (ts.isStringLiteralLike(argument)) this.#literal(source, argument, "", "mediaVariants");
3998
4047
  return;
3999
4048
  }
4049
+ if (this.#bindings.producer(node.expression, "when")) {
4050
+ for (const argument of node.arguments) if (ts.isStringLiteralLike(argument)) this.#literal(source, argument, "", "elementVariants");
4051
+ return;
4052
+ }
4053
+ if (this.#bindings.producer(node.expression, "cva")) {
4054
+ this.#cva(source, node);
4055
+ return;
4056
+ }
4000
4057
  if (this.asset(source, node.expression)?.identity.kind === "keyframes") {
4001
4058
  const options = node.arguments[0];
4002
4059
  if (options && ts.isStringLiteralLike(options)) this.#literal(source, options, "", "animationOptions");
@@ -4070,6 +4127,16 @@ var SourceIndex = class {
4070
4127
  return this.#bindings.asset(source, node);
4071
4128
  }
4072
4129
  /**
4130
+ * Recognizes a call of an imported Stillwind style producer or of one of its methods,
4131
+ * such as `style()` or `style.when()`.
4132
+ *
4133
+ * @param node - Call in one of this index's checker ASTs.
4134
+ * @returns Whether the callee is a supported `style` import or a method of one.
4135
+ */
4136
+ styleCall(node) {
4137
+ return this.#bindings.styleImport(node.expression) || ts.isPropertyAccessExpression(node.expression) && this.#bindings.styleImport(node.expression.expression);
4138
+ }
4139
+ /**
4073
4140
  * Returns the comments that contain `swlint-*` directives in `source`'s original buffer.
4074
4141
  *
4075
4142
  * @param source - Prepared source of this index.
@@ -4112,7 +4179,8 @@ var SourceIndex = class {
4112
4179
  }
4113
4180
  /**
4114
4181
  * Indexes the static utility literals of one `style.css()` input with their group keys.
4115
- * Runtime values and computed keys add no literals.
4182
+ * String-literal keys are recorded as variant keys. Runtime values and computed keys add
4183
+ * no literals.
4116
4184
  *
4117
4185
  * @param source - Prepared source stored in this index.
4118
4186
  * @param node - Input in that source's checker AST.
@@ -4135,6 +4203,7 @@ var SourceIndex = class {
4135
4203
  }
4136
4204
  if (ts.isObjectLiteralExpression(node)) for (const property of node.properties) {
4137
4205
  if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4206
+ this.#key(source, property, prefix, context);
4138
4207
  const name = propertyName(property);
4139
4208
  if (name === "" || name.endsWith(":")) this.#cssInput(source, property.initializer, name === ":" ? prefix : prefix + name, context);
4140
4209
  }
@@ -4147,6 +4216,7 @@ var SourceIndex = class {
4147
4216
  * @param source - Prepared source whose checker AST contains `node`.
4148
4217
  * @param node - Input expression to inspect. Object properties ending in `:` contribute
4149
4218
  * their values under the accumulated group variants. The keys `""` and `":"` add no variants.
4219
+ * String-literal keys are recorded as variant keys.
4150
4220
  * @param prefix - Decoded enclosing variants, including trailing colons. Nested group
4151
4221
  * names are appended before their literals are recorded.
4152
4222
  */
@@ -4196,7 +4266,8 @@ var SourceIndex = class {
4196
4266
  });
4197
4267
  for (const property of node.properties) {
4198
4268
  if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4199
- const name = ts.isStringLiteralLike(property.name) ? property.name.text : property.name.getText();
4269
+ this.#key(source, property, prefix, "utility");
4270
+ const name = propertyName(property);
4200
4271
  if (name !== "" && !name.endsWith(":")) continue;
4201
4272
  this.#input(source, property.initializer, name === ":" ? prefix : prefix + name);
4202
4273
  }
@@ -4222,6 +4293,71 @@ var SourceIndex = class {
4222
4293
  else if (ts.isStringLiteralLike(value)) this.#literal(source, value, prefix);
4223
4294
  }
4224
4295
  /**
4296
+ * Records a string-literal object key as a variant key. A key that is complete, incomplete,
4297
+ * empty, or `":"` is recorded, so completion can suggest variants while the key is written.
4298
+ * `class`, `className`, and custom-property keys are not variant keys.
4299
+ *
4300
+ * @param source - Prepared source whose checker AST contains `property`.
4301
+ * @param property - Property of an object written directly in a style input.
4302
+ * @param prefix - Decoded variants of the enclosing keys, each ending in `:`.
4303
+ * @param context - Input role of the values that the key applies to.
4304
+ */
4305
+ #key(source, property, prefix, context) {
4306
+ const name = property.name;
4307
+ if (!ts.isStringLiteralLike(name) || name.text === "class" || name.text === "className" || name.text.startsWith("--")) return;
4308
+ const literal = this.#literal(source, name, prefix, context);
4309
+ if (literal) literal.key = true;
4310
+ }
4311
+ /**
4312
+ * Records the variant keys of a `style.cva()` call. The compiler captures the utility
4313
+ * literals of the call, so this method adds only keys.
4314
+ *
4315
+ * @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.
4319
+ */
4320
+ #cva(source, call) {
4321
+ const [base, config] = call.arguments;
4322
+ this.#cvaInput(source, base, "");
4323
+ if (!config || !ts.isObjectLiteralExpression(config)) return;
4324
+ for (const property of config.properties) {
4325
+ if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4326
+ const name = propertyName(property);
4327
+ const value = property.initializer;
4328
+ if (name === "variants" && ts.isObjectLiteralExpression(value)) {
4329
+ 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, "");
4331
+ }
4332
+ } else if (name === "compoundVariants" && ts.isArrayLiteralExpression(value)) for (const compound of value.elements) {
4333
+ 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, "");
4335
+ }
4336
+ }
4337
+ }
4338
+ /**
4339
+ * Records the variant keys in one CVA utility input, including keys in nested arrays and
4340
+ * variant groups.
4341
+ *
4342
+ * @param source - Prepared source whose checker AST contains `node`.
4343
+ * @param node - CVA input, or undefined for an omitted argument.
4344
+ * @param prefix - Decoded variants of the enclosing keys, each ending in `:`.
4345
+ */
4346
+ #cvaInput(source, node, prefix) {
4347
+ while (node && (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node))) node = node.expression;
4348
+ if (!node) return;
4349
+ if (ts.isArrayLiteralExpression(node)) {
4350
+ for (const element of node.elements) this.#cvaInput(source, element, prefix);
4351
+ return;
4352
+ }
4353
+ if (ts.isObjectLiteralExpression(node)) for (const property of node.properties) {
4354
+ if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name)) continue;
4355
+ this.#key(source, property, prefix, "utility");
4356
+ const name = propertyName(property);
4357
+ if (name === "" || name.endsWith(":")) this.#cvaInput(source, property.initializer, name === ":" ? prefix : prefix + name);
4358
+ }
4359
+ }
4360
+ /**
4225
4361
  * Records decoded content and original UTF-16 boundaries for a literal in `source`'s AST.
4226
4362
  * A captured `site` overrides an existing entry's context and plan at the same content start.
4227
4363
  * Unmapped ranges or decoding that disagrees with the AST add nothing.
@@ -4232,6 +4368,8 @@ var SourceIndex = class {
4232
4368
  * @param context - Input role stored with a new entry. Defaults to ordinary utilities.
4233
4369
  * @param site - Optional captured input. An existing entry keeps its prefix and boundaries
4234
4370
  * when this site replaces its context and plan.
4371
+ * @returns The new entry, or undefined when the literal is unmapped, cannot be decoded, or
4372
+ * already has an entry.
4235
4373
  */
4236
4374
  #literal(source, node, prefix, context = "utility", site) {
4237
4375
  const range = this.range(source, node);
@@ -4248,14 +4386,16 @@ var SourceIndex = class {
4248
4386
  }
4249
4387
  return;
4250
4388
  }
4251
- this.#literals.push({
4389
+ const literal = {
4252
4390
  source,
4253
4391
  node,
4254
4392
  prefix,
4255
4393
  context,
4256
4394
  site,
4257
4395
  ...decoded
4258
- });
4396
+ };
4397
+ this.#literals.push(literal);
4398
+ return literal;
4259
4399
  }
4260
4400
  }
4261
4401
  };
@@ -4475,7 +4615,7 @@ var SourceQueries = class {
4475
4615
  return result;
4476
4616
  }
4477
4617
  if (request.kind === "previews") {
4478
- result.previews = this.#index.previews.sites(source).filter((site) => site.native.kind !== "input").flatMap((site) => {
4618
+ result.previews = this.#index.previews.sites(source).filter((site) => site.native.kind !== "input" && site.native.kind !== "variant").flatMap((site) => {
4479
4619
  const preview = this.#index.previews.assemble(site.native);
4480
4620
  const range = {
4481
4621
  start: site.start,
@@ -4504,7 +4644,7 @@ var SourceQueries = class {
4504
4644
  const tokens = this.#sourceTokens(source);
4505
4645
  if (request.kind === "colors") {
4506
4646
  result.colors = tokens.flatMap((token) => {
4507
- if (!this.#colorInput(token.literal) || !this.#preview(token.literal, token.text)) return [];
4647
+ if (!this.#colorInput(token.literal) || !this.#preview(token.literal, token.text, token.site)) return [];
4508
4648
  return this.#candidates.colors(token.literal.prefix + token.text).map(({ scheme, ...color }) => ({
4509
4649
  start: token.start,
4510
4650
  end: token.end,
@@ -4518,7 +4658,7 @@ var SourceQueries = class {
4518
4658
  const token = tokens.find((token) => token.start === request.start && token.end === request.end);
4519
4659
  if (!token || !this.#colorInput(token.literal)) return result;
4520
4660
  const candidate = colorReplacement(token.text, token.literal.prefix, request.color, this.#candidates);
4521
- if (candidate && this.#preview(token.literal, candidate)) result.edits = [{
4661
+ if (candidate && this.#preview(token.literal, candidate, token.site)) result.edits = [{
4522
4662
  start: token.start,
4523
4663
  end: token.end,
4524
4664
  newText: escapeContent(candidate, token.literal)
@@ -4527,9 +4667,15 @@ var SourceQueries = class {
4527
4667
  }
4528
4668
  const token = tokens.find((token) => token.start <= request.offset && request.offset <= token.end);
4529
4669
  if (request.kind === "hover") {
4670
+ const variant = this.#variantPreview(source, request.offset);
4671
+ if (variant !== false) {
4672
+ result.hover = variant;
4673
+ return result;
4674
+ }
4530
4675
  if (token) {
4531
- const css = this.#preview(token.literal, token.text);
4532
- const marker = this.#candidates.marker(token.literal.prefix + token.text, token.literal.context);
4676
+ const candidate = token.literal.prefix + token.text;
4677
+ 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);
4533
4679
  if (css || marker) result.hover = {
4534
4680
  start: token.start,
4535
4681
  end: token.end,
@@ -4542,14 +4688,20 @@ var SourceQueries = class {
4542
4688
  const input = this.#completionInput(source, request.offset);
4543
4689
  if (!input) return result;
4544
4690
  const { literal, start, end, prefix } = input;
4545
- const native = this.#candidates.complete(literal.prefix + prefix, literal.context, request.snippets === true).filter(({ label, marker }) => marker || label.endsWith(":") || !literal.site || this.#preview(literal, label.slice(literal.prefix.length)));
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)));
4546
4692
  const known = new Set(native.map(({ label }) => label));
4547
- result.completions = [...native, ...this.#catalogCompletions(literal.prefix + prefix, literal.context).filter((candidate) => !known.has(candidate)).map((label) => ({
4693
+ const { names: catalog, incomplete } = literal.key ? {
4694
+ names: [],
4695
+ incomplete: false
4696
+ } : this.#catalogCompletions(literal.prefix + prefix, literal.context);
4697
+ if (incomplete) result.completionsIncomplete = true;
4698
+ result.completions = [...native, ...catalog.filter((candidate) => !known.has(candidate)).map((label) => ({
4548
4699
  label,
4549
4700
  marker: false
4550
4701
  }))].map(({ label: candidate, marker }) => {
4551
4702
  const label = candidate.slice(literal.prefix.length);
4552
4703
  const source = (text) => escapeContent(text, literal);
4704
+ const color = marker || candidate.endsWith(":") ? void 0 : this.#color(candidate);
4553
4705
  return {
4554
4706
  label,
4555
4707
  candidate,
@@ -4559,6 +4711,7 @@ var SourceQueries = class {
4559
4711
  end,
4560
4712
  newText: escapeContent(label, literal),
4561
4713
  ...marker ? { marker } : {},
4714
+ ...color ? { color } : {},
4562
4715
  snippet: !request.snippets ? void 0 : marker && candidate.endsWith("/") ? markerModifierSnippet(label, source) : candidate.endsWith(":") ? completionSnippet(label, source) : void 0,
4563
4716
  retrigger: candidate.endsWith(":") || candidate.endsWith("-")
4564
4717
  };
@@ -4618,11 +4771,13 @@ var SourceQueries = class {
4618
4771
  *
4619
4772
  * @param literal - Indexed literal that supplies the input role, enclosing variants, and plan.
4620
4773
  * @param candidate - Decoded text without the literal's enclosing group prefix.
4774
+ * @param site - Captured input whose plan is rendered. Defaults to the literal's capture.
4775
+ * A template token can have its own capture.
4621
4776
  * @returns CSS for the replacement, or undefined for failed or unavailable emission.
4622
4777
  * @throws If a matching ordinary utility requirement is malformed in a standalone query.
4623
4778
  */
4624
- #preview(literal, candidate) {
4625
- if (literal.site) return this.#index.previews.previewInput(literal.source, literal.site.native.start, candidate);
4779
+ #preview(literal, candidate, site = literal.site) {
4780
+ if (site) return this.#index.previews.previewInput(literal.source, site.native.start, candidate);
4626
4781
  return this.#candidates.preview(literal.prefix + candidate, literal.context) ?? void 0;
4627
4782
  }
4628
4783
  /**
@@ -4630,16 +4785,41 @@ var SourceQueries = class {
4630
4785
  *
4631
4786
  * @param text - Decoded partial candidate, including enclosing and written variants.
4632
4787
  * @param context - Input role of the literal. Only utility roles complete catalog names.
4633
- * @returns Candidates with the written variants, for names that start with the partial
4634
- * utility, at most {@link CATALOG_COMPLETIONS} of them in catalog order.
4788
+ * @returns `names`: candidates with the written variants, for names that start with the
4789
+ * partial utility, at most {@link CATALOG_COMPLETIONS} of them in catalog order. `incomplete`:
4790
+ * whether more names matched than `names` lists.
4635
4791
  */
4636
4792
  #catalogCompletions(text, context) {
4637
- if (!this.#catalogContext(context)) return [];
4793
+ if (!this.#catalogContext(context)) return {
4794
+ names: [],
4795
+ incomplete: false
4796
+ };
4638
4797
  const parts = segments(text, ":");
4639
4798
  const partial = parts.pop();
4640
- if (!partial) return [];
4799
+ if (!partial) return {
4800
+ names: [],
4801
+ incomplete: false
4802
+ };
4641
4803
  const variants = parts.map((part) => `${part}:`).join("");
4642
- return [.../* @__PURE__ */ new Set([...this.#catalog, ...this.#inputCatalogs.get(partial) ?? []])].filter((name) => name.startsWith(partial)).slice(0, CATALOG_COMPLETIONS).map((name) => variants + name);
4804
+ const matches = [.../* @__PURE__ */ new Set([...this.#catalog, ...this.#inputCatalogs.get(partial) ?? []])].filter((name) => name.startsWith(partial));
4805
+ return {
4806
+ names: matches.slice(0, CATALOG_COMPLETIONS).map((name) => variants + name),
4807
+ incomplete: matches.length > CATALOG_COMPLETIONS
4808
+ };
4809
+ }
4810
+ /**
4811
+ * Formats the concrete color of a color utility for a completion swatch.
4812
+ *
4813
+ * @param candidate - Full decoded candidate, including enclosing and written variants.
4814
+ * @returns `#rrggbb`, or `#rrggbbaa` below full opacity. Undefined for other candidates and for
4815
+ * colors that depend on the color scheme.
4816
+ * @throws If a matching utility definition has a malformed requirement.
4817
+ */
4818
+ #color(candidate) {
4819
+ const components = this.#candidates.color(candidate);
4820
+ if (!components) return;
4821
+ const [red, green, blue, alpha] = components.map((value) => Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, "0"));
4822
+ return `#${red}${green}${blue}${alpha === "ff" ? "" : alpha}`;
4643
4823
  }
4644
4824
  /**
4645
4825
  * Reports whether an input role completes plugin catalog names.
@@ -4663,7 +4843,8 @@ var SourceQueries = class {
4663
4843
  #sourceTokens(source) {
4664
4844
  return this.#index.literals.filter((literal) => literal.source === source).flatMap((literal) => this.#tokens(literal).map((token) => ({
4665
4845
  ...token,
4666
- literal
4846
+ literal,
4847
+ site: literal.site ?? (ts.isTemplateLiteralToken(literal.node) ? this.#index.previews.input(source, token.start, token.end) : void 0)
4667
4848
  })));
4668
4849
  }
4669
4850
  /**
@@ -4692,13 +4873,14 @@ var SourceQueries = class {
4692
4873
  }
4693
4874
  /**
4694
4875
  * Allows color operations only for input roles that emit utility declarations.
4695
- * Option and definition-prefix inputs use different value contracts.
4876
+ * Option and definition-prefix inputs use different value contracts, and variant keys
4877
+ * emit no declarations.
4696
4878
  *
4697
4879
  * @param literal - Indexed literal whose context supplies the input role.
4698
4880
  * @returns Whether its role supports a utility candidate's concrete color and replacement.
4699
4881
  */
4700
4882
  #colorInput(literal) {
4701
- return [
4883
+ return !literal.key && [
4702
4884
  "utility",
4703
4885
  "keyframesFrame",
4704
4886
  "viewTransitionUtilities"
@@ -4712,11 +4894,50 @@ var SourceQueries = class {
4712
4894
  * @returns Tokens in source order, without trimming or decoding them again.
4713
4895
  */
4714
4896
  #tokens(literal) {
4715
- return [...literal.text.matchAll(/\S+/gu)].map((match) => ({
4716
- text: match[0],
4717
- start: literal.boundaries[match.index],
4718
- end: literal.boundaries[match.index + match[0].length]
4719
- }));
4897
+ const continued = ts.isTemplateMiddle(literal.node) || ts.isTemplateTail(literal.node);
4898
+ return [...literal.text.matchAll(/\S+/gu)].flatMap((match) => {
4899
+ const skip = continued && match.index === 0 && match[0].startsWith(":") ? 1 : 0;
4900
+ const text = match[0].slice(skip);
4901
+ return text ? [{
4902
+ text,
4903
+ start: literal.boundaries[match.index + skip],
4904
+ end: literal.boundaries[match.index + match[0].length]
4905
+ }] : [];
4906
+ });
4907
+ }
4908
+ /**
4909
+ * Finds the ref or container variant expression at `offset`, such as `trigger("hover:")`,
4910
+ * ``trigger`hover:` ``, `trigger.at("width >= 40rem")`, or `trigger().in(card)`, and its
4911
+ * captured variant preview. The expression extends from the cursor through enclosing
4912
+ * property accesses, calls, and tags, and ends before a call of a style producer.
4913
+ *
4914
+ * @param source - Prepared source stored in this snapshot's index.
4915
+ * @param offset - Cursor offset in the original document's UTF-16 coordinates.
4916
+ * @returns The formatted selectors and conditions of the first captured variant in that
4917
+ * expression, with the expression's original range; undefined when the expression is a ref
4918
+ * variant without a valid capture, such as one whose stored variant has no use; or false when
4919
+ * the cursor is not in a ref variant expression.
4920
+ * @throws If the native formatter rejects the captured CSS.
4921
+ */
4922
+ #variantPreview(source, offset) {
4923
+ let node = this.#index.nodeAt(source, offset);
4924
+ let expression;
4925
+ let reference = false;
4926
+ 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
+ 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;
4929
+ expression = node;
4930
+ node = node.parent;
4931
+ }
4932
+ const range = expression && this.#index.range(source, expression);
4933
+ if (!reference || !range) return false;
4934
+ const site = this.#index.previews.sites(source).find((site) => site.native.kind === "variant" && range[0] <= site.start && site.end <= range[1]);
4935
+ const preview = site && this.#index.previews.preview(site.native);
4936
+ return preview ? {
4937
+ start: range[0],
4938
+ end: range[1],
4939
+ css: this.#query.formatCss(preview.css, this.#annotations)
4940
+ } : void 0;
4720
4941
  }
4721
4942
  };
4722
4943
  // src/editor/snapshot.ts
@@ -5366,6 +5587,6 @@ function compilerOptions(config) {
5366
5587
  rootFontSize: resolved.rootFontSize
5367
5588
  };
5368
5589
  }
5369
- export { fileSourceKind as A, CompilationFailure as C, ResolutionMismatchError as D, CompilationProject as E, prepareSourcePlugins as F, attachPlugins as M, compileWithPlugins as N, sourceKey as O, pluginLoader as P, warnRejectedNames as S, tracePhase 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, TypeFactsError as j, cleanModuleId 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, startPhase as w, compileModule as x, finalizeCss as y };
5590
+ 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 };
5370
5591
 
5371
- //# sourceMappingURL=options-CHkqG1Gc.js.map
5592
+ //# sourceMappingURL=options-Cc-SlJed.js.map