@stillwind/config 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1351 @@
1
+ import * as v from "valibot";
2
+ // src/lint-presets.ts
3
+ /** Default checks also inherited by the strict preset. The same object is shared by all consumers. */
4
+ const recommended = {
5
+ name: "stillwind/recommended",
6
+ rules: {
7
+ "invalid-lint-suppression": "warn",
8
+ "duplicate-utility": "warn",
9
+ "conflicting-utilities": "warn",
10
+ "mismatched-framework-import": "warn",
11
+ "mutating-macro-argument": "deny",
12
+ "suspending-macro-argument": "deny",
13
+ "invalid-rule-group-input": "deny",
14
+ "invalid-style-input": "deny",
15
+ "invalid-cva-config": "deny",
16
+ "invalid-cva-input": "deny",
17
+ "invalid-keyframes-use": "deny",
18
+ "invalid-keyframes-definition": "deny",
19
+ "invalid-keyframes-variant": "deny",
20
+ "invalid-view-transition-use": "deny",
21
+ "invalid-view-transition-definition": "deny",
22
+ "invalid-view-transition-variant": "deny",
23
+ "invalid-media-query": "deny",
24
+ "invalid-css-input": "deny",
25
+ "invalid-ref-input": "deny",
26
+ "invalid-animation-option": "deny",
27
+ "invalid-style-composition": "deny",
28
+ "runtime-condition-requires-css-if": "deny",
29
+ "unverified-style-base": "warn",
30
+ "ineffective-anchor-scope": "warn",
31
+ "missing-ref-attachment": "warn",
32
+ "conflicting-provider-properties": "warn",
33
+ "document-scoped-selector": "deny",
34
+ "repeated-nesting-selector": "warn",
35
+ "missing-view-transition-name": "warn",
36
+ "duplicate-view-transition-name": "warn",
37
+ "split-view-transition-class": "warn",
38
+ "ambiguous-style-base-order": "warn",
39
+ "interfering-imported-style-base": "warn",
40
+ "incompatible-property-value": "deny",
41
+ "invalid-utility": "deny",
42
+ "unknown-utility": "warn",
43
+ "invalid-marker-use": "warn",
44
+ "invalid-variant": "deny",
45
+ "unknown-variant": "warn",
46
+ "missing-document-target": "deny",
47
+ "prefer-canonical-utilities": "warn",
48
+ "redundant-variant": "warn",
49
+ "unsatisfiable-variants": "warn",
50
+ "clamped-value": "warn",
51
+ "invalid-theme-reference": "deny",
52
+ "invalid-css-import": "deny",
53
+ "invalid-css-directive": "deny",
54
+ "invalid-runtime-condition": "deny",
55
+ "duplicate-definition": "warn",
56
+ "bypassed-undefinition": "warn",
57
+ "ignored-definition-condition": "deny",
58
+ "incompatible-theme-value": "deny",
59
+ "ignored-tailwind-feature": "warn",
60
+ "prefer-explicit-nesting-selector": "warn"
61
+ }
62
+ };
63
+ /**
64
+ * Built-in lint policies for ordered preset composition. Treat their shared objects as readonly.
65
+ * Recommended supplies the omitted-lint default. Strict denies every recommended rule and adds
66
+ * further denied checks. Stylistic enables optional rewrites and utility sorting.
67
+ */
68
+ const lintPresets = {
69
+ recommended,
70
+ strict: {
71
+ name: "stillwind/strict",
72
+ extends: [recommended],
73
+ rules: {
74
+ "invalid-lint-suppression": "deny",
75
+ "duplicate-utility": "deny",
76
+ "conflicting-utilities": "deny",
77
+ "mismatched-framework-import": "deny",
78
+ "mutating-macro-argument": "deny",
79
+ "suspending-macro-argument": "deny",
80
+ "invalid-rule-group-input": "deny",
81
+ "invalid-style-input": "deny",
82
+ "invalid-cva-config": "deny",
83
+ "invalid-cva-input": "deny",
84
+ "invalid-keyframes-use": "deny",
85
+ "invalid-keyframes-definition": "deny",
86
+ "invalid-keyframes-variant": "deny",
87
+ "invalid-view-transition-use": "deny",
88
+ "invalid-view-transition-definition": "deny",
89
+ "invalid-view-transition-variant": "deny",
90
+ "invalid-media-query": "deny",
91
+ "invalid-css-input": "deny",
92
+ "invalid-ref-input": "deny",
93
+ "invalid-animation-option": "deny",
94
+ "invalid-style-composition": "deny",
95
+ "runtime-condition-requires-css-if": "deny",
96
+ "unverified-style-base": "deny",
97
+ "ineffective-anchor-scope": "deny",
98
+ "missing-ref-attachment": "deny",
99
+ "conflicting-provider-properties": "deny",
100
+ "document-scoped-selector": "deny",
101
+ "repeated-nesting-selector": "deny",
102
+ "missing-view-transition-name": "deny",
103
+ "duplicate-view-transition-name": "deny",
104
+ "split-view-transition-class": "deny",
105
+ "ambiguous-style-base-order": "deny",
106
+ "interfering-imported-style-base": "deny",
107
+ "incompatible-property-value": "deny",
108
+ "invalid-utility": "deny",
109
+ "unknown-utility": "deny",
110
+ "invalid-marker-use": "deny",
111
+ "invalid-variant": "deny",
112
+ "unknown-variant": "deny",
113
+ "missing-document-target": "deny",
114
+ "prefer-canonical-utilities": "deny",
115
+ "redundant-variant": "deny",
116
+ "unsatisfiable-variants": "deny",
117
+ "clamped-value": "deny",
118
+ "invalid-theme-reference": "deny",
119
+ "invalid-css-import": "deny",
120
+ "invalid-css-directive": "deny",
121
+ "invalid-runtime-condition": "deny",
122
+ "duplicate-definition": "deny",
123
+ "bypassed-undefinition": "deny",
124
+ "ignored-definition-condition": "deny",
125
+ "incompatible-theme-value": "deny",
126
+ "ignored-tailwind-feature": "deny",
127
+ "prefer-explicit-nesting-selector": "deny",
128
+ "unused-lint-suppression": "deny"
129
+ }
130
+ },
131
+ stylistic: {
132
+ name: "stillwind/stylistic",
133
+ rules: {
134
+ "prefer-direct-styling": "warn",
135
+ "prefer-logical-properties": "warn",
136
+ "prefer-typed-relationships": "warn",
137
+ "prefer-sorted-utilities": "warn",
138
+ "prefer-typed-variables": "warn",
139
+ "prefer-variant-directive": "warn"
140
+ }
141
+ }
142
+ };
143
+ // src/lint-rules.ts
144
+ /**
145
+ * Maps public rule IDs to categories, native option names, and default detection settings.
146
+ * Each entry's category names the kind of problem the rule reports, and its nativeName
147
+ * identifies its field in the compiler binding. Null options indicate
148
+ * a severity-only rule. Other entries list accepted fields in options and initial values in defaults.
149
+ * Treat these shared catalog entries as readonly.
150
+ */
151
+ const lintRules = {
152
+ "invalid-rule-group-input": {
153
+ category: "input",
154
+ nativeName: "invalidRuleGroupInput",
155
+ defaults: null,
156
+ options: null
157
+ },
158
+ "invalid-style-input": {
159
+ category: "input",
160
+ nativeName: "invalidStyleInput",
161
+ defaults: null,
162
+ options: null
163
+ },
164
+ "invalid-cva-config": {
165
+ category: "input",
166
+ nativeName: "invalidCvaConfig",
167
+ defaults: null,
168
+ options: null
169
+ },
170
+ "invalid-cva-input": {
171
+ category: "input",
172
+ nativeName: "invalidCvaInput",
173
+ defaults: null,
174
+ options: null
175
+ },
176
+ "invalid-keyframes-use": {
177
+ category: "input",
178
+ nativeName: "invalidKeyframesUse",
179
+ defaults: null,
180
+ options: null
181
+ },
182
+ "invalid-keyframes-definition": {
183
+ category: "input",
184
+ nativeName: "invalidKeyframesDefinition",
185
+ defaults: null,
186
+ options: null
187
+ },
188
+ "invalid-keyframes-variant": {
189
+ category: "input",
190
+ nativeName: "invalidKeyframesVariant",
191
+ defaults: null,
192
+ options: null
193
+ },
194
+ "invalid-view-transition-use": {
195
+ category: "input",
196
+ nativeName: "invalidViewTransitionUse",
197
+ defaults: null,
198
+ options: null
199
+ },
200
+ "invalid-view-transition-definition": {
201
+ category: "input",
202
+ nativeName: "invalidViewTransitionDefinition",
203
+ defaults: null,
204
+ options: null
205
+ },
206
+ "invalid-view-transition-variant": {
207
+ category: "input",
208
+ nativeName: "invalidViewTransitionVariant",
209
+ defaults: null,
210
+ options: null
211
+ },
212
+ "invalid-media-query": {
213
+ category: "input",
214
+ nativeName: "invalidMediaQuery",
215
+ defaults: null,
216
+ options: null
217
+ },
218
+ "invalid-css-input": {
219
+ category: "input",
220
+ nativeName: "invalidCssInput",
221
+ defaults: null,
222
+ options: null
223
+ },
224
+ "invalid-ref-input": {
225
+ category: "input",
226
+ nativeName: "invalidRefInput",
227
+ defaults: null,
228
+ options: null
229
+ },
230
+ "invalid-animation-option": {
231
+ category: "input",
232
+ nativeName: "invalidAnimationOption",
233
+ defaults: null,
234
+ options: null
235
+ },
236
+ "invalid-style-composition": {
237
+ category: "input",
238
+ nativeName: "invalidStyleComposition",
239
+ defaults: null,
240
+ options: null
241
+ },
242
+ "runtime-condition-requires-css-if": {
243
+ category: "input",
244
+ nativeName: "runtimeConditionRequiresCssIf",
245
+ defaults: null,
246
+ options: null
247
+ },
248
+ "invalid-utility": {
249
+ category: "input",
250
+ nativeName: "invalidUtility",
251
+ defaults: null,
252
+ options: null
253
+ },
254
+ "unknown-utility": {
255
+ category: "input",
256
+ nativeName: "unknownUtility",
257
+ defaults: null,
258
+ options: null
259
+ },
260
+ "invalid-marker-use": {
261
+ category: "input",
262
+ nativeName: "invalidMarkerUse",
263
+ defaults: {
264
+ severity: "warn",
265
+ ignoredClasses: []
266
+ },
267
+ options: ["severity", "ignoredClasses"]
268
+ },
269
+ "invalid-variant": {
270
+ category: "input",
271
+ nativeName: "invalidVariant",
272
+ defaults: null,
273
+ options: null
274
+ },
275
+ "unknown-variant": {
276
+ category: "input",
277
+ nativeName: "unknownVariant",
278
+ defaults: null,
279
+ options: null
280
+ },
281
+ "missing-document-target": {
282
+ category: "input",
283
+ nativeName: "missingDocumentTarget",
284
+ defaults: null,
285
+ options: null
286
+ },
287
+ "invalid-theme-reference": {
288
+ category: "input",
289
+ nativeName: "invalidThemeReference",
290
+ defaults: null,
291
+ options: null
292
+ },
293
+ "invalid-css-import": {
294
+ category: "input",
295
+ nativeName: "invalidCssImport",
296
+ defaults: null,
297
+ options: null
298
+ },
299
+ "invalid-css-directive": {
300
+ category: "input",
301
+ nativeName: "invalidCssDirective",
302
+ defaults: null,
303
+ options: null
304
+ },
305
+ "invalid-runtime-condition": {
306
+ category: "input",
307
+ nativeName: "invalidRuntimeCondition",
308
+ defaults: null,
309
+ options: null
310
+ },
311
+ "mutating-macro-argument": {
312
+ category: "contract",
313
+ nativeName: "mutatingMacroArgument",
314
+ defaults: null,
315
+ options: null
316
+ },
317
+ "suspending-macro-argument": {
318
+ category: "contract",
319
+ nativeName: "suspendingMacroArgument",
320
+ defaults: null,
321
+ options: null
322
+ },
323
+ "mismatched-framework-import": {
324
+ category: "contract",
325
+ nativeName: "mismatchedFrameworkImport",
326
+ defaults: null,
327
+ options: null
328
+ },
329
+ "duplicate-utility": {
330
+ category: "hazard",
331
+ nativeName: "duplicateUtility",
332
+ defaults: null,
333
+ options: null
334
+ },
335
+ "conflicting-utilities": {
336
+ category: "hazard",
337
+ nativeName: "conflictingUtilities",
338
+ defaults: {
339
+ severity: "warn",
340
+ allowShorthandOverrides: false
341
+ },
342
+ options: ["severity", "allowShorthandOverrides"]
343
+ },
344
+ "conflicting-provider-properties": {
345
+ category: "hazard",
346
+ nativeName: "conflictingProviderProperties",
347
+ defaults: null,
348
+ options: null
349
+ },
350
+ "unverified-style-base": {
351
+ category: "hazard",
352
+ nativeName: "unverifiedStyleBase",
353
+ defaults: null,
354
+ options: null
355
+ },
356
+ "ambiguous-style-base-order": {
357
+ category: "hazard",
358
+ nativeName: "ambiguousStyleBaseOrder",
359
+ defaults: null,
360
+ options: null
361
+ },
362
+ "interfering-imported-style-base": {
363
+ category: "hazard",
364
+ nativeName: "interferingImportedStyleBase",
365
+ defaults: null,
366
+ options: null
367
+ },
368
+ "missing-ref-attachment": {
369
+ category: "hazard",
370
+ nativeName: "missingRefAttachment",
371
+ defaults: null,
372
+ options: null
373
+ },
374
+ "document-scoped-selector": {
375
+ category: "hazard",
376
+ nativeName: "documentScopedSelector",
377
+ defaults: null,
378
+ options: null
379
+ },
380
+ "repeated-nesting-selector": {
381
+ category: "hazard",
382
+ nativeName: "repeatedNestingSelector",
383
+ defaults: null,
384
+ options: null
385
+ },
386
+ "missing-view-transition-name": {
387
+ category: "hazard",
388
+ nativeName: "missingViewTransitionName",
389
+ defaults: null,
390
+ options: null
391
+ },
392
+ "duplicate-view-transition-name": {
393
+ category: "hazard",
394
+ nativeName: "duplicateViewTransitionName",
395
+ defaults: null,
396
+ options: null
397
+ },
398
+ "split-view-transition-class": {
399
+ category: "hazard",
400
+ nativeName: "splitViewTransitionClass",
401
+ defaults: null,
402
+ options: null
403
+ },
404
+ "ineffective-anchor-scope": {
405
+ category: "hazard",
406
+ nativeName: "ineffectiveAnchorScope",
407
+ defaults: null,
408
+ options: null
409
+ },
410
+ "incompatible-property-value": {
411
+ category: "hazard",
412
+ nativeName: "incompatiblePropertyValue",
413
+ defaults: null,
414
+ options: null
415
+ },
416
+ "unsatisfiable-variants": {
417
+ category: "hazard",
418
+ nativeName: "unsatisfiableVariants",
419
+ defaults: null,
420
+ options: null
421
+ },
422
+ "clamped-value": {
423
+ category: "hazard",
424
+ nativeName: "clampedValue",
425
+ defaults: null,
426
+ options: null
427
+ },
428
+ "duplicate-definition": {
429
+ category: "hazard",
430
+ nativeName: "duplicateDefinition",
431
+ defaults: null,
432
+ options: null
433
+ },
434
+ "bypassed-undefinition": {
435
+ category: "hazard",
436
+ nativeName: "bypassedUndefinition",
437
+ defaults: null,
438
+ options: null
439
+ },
440
+ "ignored-definition-condition": {
441
+ category: "hazard",
442
+ nativeName: "ignoredDefinitionCondition",
443
+ defaults: null,
444
+ options: null
445
+ },
446
+ "incompatible-theme-value": {
447
+ category: "hazard",
448
+ nativeName: "incompatibleThemeValue",
449
+ defaults: null,
450
+ options: null
451
+ },
452
+ "ignored-tailwind-feature": {
453
+ category: "hazard",
454
+ nativeName: "ignoredTailwindFeature",
455
+ defaults: null,
456
+ options: null
457
+ },
458
+ "no-arbitrary-colors": {
459
+ category: "restriction",
460
+ nativeName: "noArbitraryColors",
461
+ defaults: null,
462
+ options: null
463
+ },
464
+ "no-arbitrary-spacing": {
465
+ category: "restriction",
466
+ nativeName: "noArbitrarySpacing",
467
+ defaults: {
468
+ severity: "warn",
469
+ properties: []
470
+ },
471
+ options: ["severity", "properties"]
472
+ },
473
+ "no-class-property": {
474
+ category: "restriction",
475
+ nativeName: "noClassProperty",
476
+ defaults: null,
477
+ options: null
478
+ },
479
+ "no-restricted-utilities": {
480
+ category: "restriction",
481
+ nativeName: "noRestrictedUtilities",
482
+ defaults: {
483
+ severity: "warn",
484
+ utilities: []
485
+ },
486
+ options: ["severity", "utilities"]
487
+ },
488
+ "no-restricted-declarations": {
489
+ category: "restriction",
490
+ nativeName: "noRestrictedDeclarations",
491
+ defaults: {
492
+ severity: "warn",
493
+ checkImplementation: true,
494
+ rules: []
495
+ },
496
+ options: [
497
+ "severity",
498
+ "checkImplementation",
499
+ "rules"
500
+ ]
501
+ },
502
+ "no-important": {
503
+ category: "restriction",
504
+ nativeName: "noImportant",
505
+ defaults: {
506
+ severity: "warn",
507
+ checkImplementation: true
508
+ },
509
+ options: ["severity", "checkImplementation"]
510
+ },
511
+ "no-restricted-length-units": {
512
+ category: "restriction",
513
+ nativeName: "noRestrictedLengthUnits",
514
+ defaults: {
515
+ severity: "warn",
516
+ checkImplementation: false,
517
+ rules: []
518
+ },
519
+ options: [
520
+ "severity",
521
+ "checkImplementation",
522
+ "rules"
523
+ ]
524
+ },
525
+ "no-restricted-theme-tokens": {
526
+ category: "restriction",
527
+ nativeName: "noRestrictedThemeTokens",
528
+ defaults: {
529
+ severity: "warn",
530
+ checkImplementation: true,
531
+ tokens: []
532
+ },
533
+ options: [
534
+ "severity",
535
+ "checkImplementation",
536
+ "tokens"
537
+ ]
538
+ },
539
+ "no-arbitrary-breakpoints": {
540
+ category: "restriction",
541
+ nativeName: "noArbitraryBreakpoints",
542
+ defaults: null,
543
+ options: null
544
+ },
545
+ "prefer-direct-styling": {
546
+ category: "style",
547
+ nativeName: "preferDirectStyling",
548
+ defaults: null,
549
+ options: null
550
+ },
551
+ "prefer-logical-properties": {
552
+ category: "style",
553
+ nativeName: "preferLogicalProperties",
554
+ defaults: {
555
+ severity: "warn",
556
+ checkImplementation: false
557
+ },
558
+ options: ["severity", "checkImplementation"]
559
+ },
560
+ "prefer-typed-relationships": {
561
+ category: "style",
562
+ nativeName: "preferTypedRelationships",
563
+ defaults: null,
564
+ options: null
565
+ },
566
+ "prefer-canonical-utilities": {
567
+ category: "style",
568
+ nativeName: "preferCanonicalUtilities",
569
+ defaults: {
570
+ severity: "warn",
571
+ pxToRem: true,
572
+ collapse: true,
573
+ logicalToPhysical: false,
574
+ preserveSpecificity: true
575
+ },
576
+ options: [
577
+ "severity",
578
+ "pxToRem",
579
+ "collapse",
580
+ "logicalToPhysical",
581
+ "preserveSpecificity"
582
+ ]
583
+ },
584
+ "prefer-sorted-utilities": {
585
+ category: "style",
586
+ nativeName: "preferSortedUtilities",
587
+ defaults: null,
588
+ options: null
589
+ },
590
+ "redundant-variant": {
591
+ category: "style",
592
+ nativeName: "redundantVariant",
593
+ defaults: null,
594
+ options: null
595
+ },
596
+ "prefer-typed-variables": {
597
+ category: "style",
598
+ nativeName: "preferTypedVariables",
599
+ defaults: null,
600
+ options: null
601
+ },
602
+ "prefer-explicit-nesting-selector": {
603
+ category: "style",
604
+ nativeName: "preferExplicitNestingSelector",
605
+ defaults: null,
606
+ options: null
607
+ },
608
+ "prefer-variant-directive": {
609
+ category: "style",
610
+ nativeName: "preferVariantDirective",
611
+ defaults: {
612
+ severity: "warn",
613
+ pxToRem: false
614
+ },
615
+ options: ["severity", "pxToRem"]
616
+ },
617
+ "invalid-lint-suppression": {
618
+ category: "suppression",
619
+ nativeName: "invalidLintSuppression",
620
+ defaults: null,
621
+ options: null
622
+ },
623
+ "unused-lint-suppression": {
624
+ category: "suppression",
625
+ nativeName: "unusedLintSuppression",
626
+ defaults: null,
627
+ options: null
628
+ }
629
+ };
630
+ /** Lowercase CSS length units accepted by lint validation, which also accepts case variations. */
631
+ const lengthUnits = [
632
+ "px",
633
+ "cm",
634
+ "mm",
635
+ "q",
636
+ "in",
637
+ "pt",
638
+ "pc",
639
+ "em",
640
+ "rem",
641
+ "ex",
642
+ "rex",
643
+ "cap",
644
+ "rcap",
645
+ "ch",
646
+ "rch",
647
+ "ic",
648
+ "ric",
649
+ "lh",
650
+ "rlh",
651
+ "vw",
652
+ "vh",
653
+ "vi",
654
+ "vb",
655
+ "vmin",
656
+ "vmax",
657
+ "svw",
658
+ "svh",
659
+ "svi",
660
+ "svb",
661
+ "svmin",
662
+ "svmax",
663
+ "lvw",
664
+ "lvh",
665
+ "lvi",
666
+ "lvb",
667
+ "lvmin",
668
+ "lvmax",
669
+ "dvw",
670
+ "dvh",
671
+ "dvi",
672
+ "dvb",
673
+ "dvmin",
674
+ "dvmax",
675
+ "cqw",
676
+ "cqh",
677
+ "cqi",
678
+ "cqb",
679
+ "cqmin",
680
+ "cqmax"
681
+ ];
682
+ // src/validation.ts
683
+ /** Schema validation that reports authored field paths and keeps supplied objects unchanged. */
684
+ /** Accepts strings with non-whitespace content while preserving all authored whitespace. */
685
+ const nonemptyText = v.pipe(v.string(), v.check((value) => Boolean(value.trim()), "must be a nonempty string"));
686
+ /** Accepts arrays of strings with non-whitespace content. Arrays can be empty, and entries are not trimmed. */
687
+ const nonemptyStrings = v.array(nonemptyText);
688
+ /** Requires at least one string with non-whitespace content, without trimming entries. */
689
+ const nonemptyStringList = v.pipe(nonemptyStrings, v.minLength(1, "must be an array of nonempty strings"));
690
+ /**
691
+ * Checks a schema and narrows the supplied value without replacing it with parsed output.
692
+ * @param schema - Synchronous schema whose output type describes the input's existing shape.
693
+ * Parsed replacements are discarded, so narrowing must not depend on a transformation.
694
+ * @param value - Value to validate. Objects, arrays, and callbacks retain their original identities.
695
+ * @param location - Root field path prepended to the first validation issue's property and array path.
696
+ * @throws If validation fails. The error includes the first issue's field path and message.
697
+ */
698
+ function validate(schema, value, location) {
699
+ const result = v.safeParse(schema, value, { abortEarly: true });
700
+ if (result.success) return;
701
+ const issue = result.issues[0];
702
+ const suffix = issue.path?.map(({ key }) => typeof key === "number" ? `[${key}]` : `.${String(key)}`).join("") ?? "";
703
+ throw new Error(`${location}${suffix}: ${issue.message}`);
704
+ }
705
+ /**
706
+ * Constructs a schema that requires an object and rejects undeclared keys.
707
+ * @param entries - Field names and synchronous schemas used to validate their values.
708
+ * @returns A schema that validates declared fields on non-null, non-array objects and rejects unknown keys.
709
+ */
710
+ function strictObject(entries) {
711
+ return v.pipe(v.custom(object, "must be an object"), v.strictObject(entries));
712
+ }
713
+ /**
714
+ * Checks whether a value can supply configuration fields.
715
+ * @param value - Any runtime value. Objects with custom prototypes are accepted.
716
+ * @returns Whether the value is a non-null object other than an array.
717
+ */
718
+ function object(value) {
719
+ return value !== null && typeof value === "object" && !Array.isArray(value);
720
+ }
721
+ // src/lint.ts
722
+ /** Ordered lint preset composition and validation for all configuration hosts. */
723
+ /**
724
+ * Applies an inline override to project lint settings without expanding presets.
725
+ * Omitted extends preserves the project's list; a supplied list replaces it.
726
+ * Omitted project settings select recommended. Rule fields merge and arrays replace.
727
+ * False replaces all settings. An object override of false enables only its own rules and presets.
728
+ * Neither input is modified.
729
+ *
730
+ * @param base - Project settings, or undefined to use recommended.
731
+ * @param override - Inline settings; undefined preserves the project settings.
732
+ * @returns False when lint remains disabled, or settings with inherited rule options preserved.
733
+ */
734
+ function mergeLintConfig(base, override) {
735
+ if (override === void 0) return base ?? { extends: [lintPresets.recommended] };
736
+ if (override === false) return false;
737
+ const previous = base === false ? {} : base ?? { extends: [lintPresets.recommended] };
738
+ return {
739
+ ...previous,
740
+ ...override.name === void 0 ? {} : { name: override.name },
741
+ ...override.extends === void 0 ? {} : { extends: override.extends },
742
+ ...override.checkLibraries === void 0 ? {} : { checkLibraries: override.checkLibraries },
743
+ ...override.checkPlugins === void 0 ? {} : { checkPlugins: override.checkPlugins },
744
+ rules: mergeRules(previous.rules ?? {}, override.rules ?? {})
745
+ };
746
+ }
747
+ /**
748
+ * Expands presets in order and applies rule defaults without modifying the input.
749
+ *
750
+ * @param config - Project lint settings. Undefined selects recommended; false or an empty object disables all rules.
751
+ * @param location - Field path used in configuration errors.
752
+ * @returns Every rule's severity and detection options, wrapped in rules for repeatable normalization.
753
+ * @throws If a preset has a cycle, an unknown field, or invalid effective rule options.
754
+ */
755
+ function resolveLintConfig(config, location = "config.lint") {
756
+ const value = config === false ? {} : config ?? { extends: [lintPresets.recommended] };
757
+ const preset = validateScope(value, location);
758
+ validatePreset(preset, location, /* @__PURE__ */ new Set());
759
+ const rules = resolvedRules(preset);
760
+ validateResolvedRules(rules, `${location}.rules`);
761
+ return {
762
+ rules,
763
+ checkLibraries: value.checkLibraries ?? false,
764
+ checkPlugins: value.checkPlugins ?? false
765
+ };
766
+ }
767
+ /**
768
+ * Validates the project-level scope fields of lint settings.
769
+ *
770
+ * @param value - Project lint settings object.
771
+ * @param location - Field path used in configuration errors.
772
+ * @returns The settings without the scope fields, for preset validation.
773
+ * @throws If a scope field is neither a boolean nor a list of name globs.
774
+ */
775
+ function validateScope(value, location) {
776
+ if (!object(value)) return value;
777
+ const { checkLibraries, checkPlugins, ...preset } = value;
778
+ validate(definitionScopeSchema, checkLibraries, `${location}.checkLibraries`);
779
+ validate(definitionScopeSchema, checkPlugins, `${location}.checkPlugins`);
780
+ return preset;
781
+ }
782
+ /**
783
+ * Validates lint settings and preset ancestry before or after composition.
784
+ *
785
+ * @param value - False to disable lint, or a preset object with optional parents and rules.
786
+ * @param location - Field path used to identify invalid values and cyclic extends lists.
787
+ * @param partial - Whether to defer required effective options until presets and overrides are composed.
788
+ * @throws If preset fields or rule options are invalid, ancestry has a cycle, or complete settings
789
+ * enable a theme restriction without token patterns.
790
+ */
791
+ function validateLintConfig(value, location, partial) {
792
+ if (value === false) return;
793
+ const preset = validateScope(value, location);
794
+ validatePreset(preset, location, /* @__PURE__ */ new Set());
795
+ if (!partial) validateResolvedRules(resolvedRules(preset), `${location}.rules`);
796
+ }
797
+ const severitySchema = v.picklist([
798
+ "warn",
799
+ "deny",
800
+ "off"
801
+ ]);
802
+ const glob = v.pipe(nonemptyText, v.regex(/^\S+$/, "must contain valid complete globs"));
803
+ const propertyGlobs = v.pipe(v.array(glob), v.minLength(1));
804
+ const definitionScopeSchema = v.optional(v.union([v.boolean(), v.array(glob)], "must be a boolean or an array of name globs"));
805
+ const tokenGlob = v.pipe(glob, v.check((value) => value.startsWith("--") && value.length > 2, "must contain custom-property patterns"));
806
+ const ruleOptions = {
807
+ "no-important": strictObject({
808
+ severity: v.optional(severitySchema),
809
+ checkImplementation: v.optional(v.boolean())
810
+ }),
811
+ "no-arbitrary-spacing": strictObject({
812
+ severity: v.optional(severitySchema),
813
+ properties: v.optional(v.array(glob))
814
+ }),
815
+ "no-restricted-utilities": strictObject({
816
+ severity: v.optional(severitySchema),
817
+ utilities: v.optional(v.array(strictObject({
818
+ pattern: glob,
819
+ message: v.optional(v.string())
820
+ })))
821
+ }),
822
+ "no-restricted-declarations": strictObject({
823
+ severity: v.optional(severitySchema),
824
+ checkImplementation: v.optional(v.boolean()),
825
+ rules: v.optional(v.array(strictObject({
826
+ properties: propertyGlobs,
827
+ values: nonemptyStringList,
828
+ message: v.optional(v.string())
829
+ })))
830
+ }),
831
+ "conflicting-utilities": strictObject({
832
+ severity: v.optional(severitySchema),
833
+ allowShorthandOverrides: v.optional(v.boolean())
834
+ }),
835
+ "invalid-marker-use": strictObject({
836
+ severity: v.optional(severitySchema),
837
+ ignoredClasses: v.optional(v.array(nonemptyText))
838
+ }),
839
+ "no-restricted-length-units": strictObject({
840
+ severity: v.optional(severitySchema),
841
+ checkImplementation: v.optional(v.boolean()),
842
+ rules: v.optional(v.array(strictObject({
843
+ properties: propertyGlobs,
844
+ disallow: v.array(v.pipe(nonemptyText, v.check((value) => lengthUnits.some((unit) => unit === value.toLowerCase()), "must contain CSS length unit names")))
845
+ })))
846
+ }),
847
+ "prefer-logical-properties": strictObject({
848
+ severity: v.optional(severitySchema),
849
+ checkImplementation: v.optional(v.boolean())
850
+ }),
851
+ "no-restricted-theme-tokens": strictObject({
852
+ severity: v.optional(severitySchema),
853
+ checkImplementation: v.optional(v.boolean()),
854
+ tokens: v.optional(v.array(tokenGlob))
855
+ }),
856
+ "prefer-canonical-utilities": strictObject({
857
+ severity: v.optional(severitySchema),
858
+ pxToRem: v.optional(v.boolean()),
859
+ collapse: v.optional(v.boolean()),
860
+ logicalToPhysical: v.optional(v.boolean()),
861
+ preserveSpecificity: v.optional(v.boolean())
862
+ }),
863
+ "prefer-variant-directive": strictObject({
864
+ severity: v.optional(severitySchema),
865
+ pxToRem: v.optional(v.boolean())
866
+ })
867
+ };
868
+ const lintRulesSchema = strictObject(Object.fromEntries(Object.keys(lintRules).map((name) => [name, v.optional(name in ruleOptions ? v.lazy((value) => typeof value === "string" ? severitySchema : ruleOptions[name]) : severitySchema)])));
869
+ const presetSchema = strictObject({
870
+ name: v.optional(nonemptyText),
871
+ extends: v.optional(v.array(v.unknown(), "must be an array of presets")),
872
+ rules: v.optional(lintRulesSchema)
873
+ });
874
+ /**
875
+ * Validates preset fields and rejects cycles along the current ancestry while allowing shared parents.
876
+ *
877
+ * @param value - Preset object to check without modifying it or invoking callbacks.
878
+ * @param location - Authored field path, extended with parent indexes and supplied display names.
879
+ * @param active - Objects on the current ancestry. Success restores the previous contents.
880
+ * A failure can leave objects from the failing ancestry in this set.
881
+ * @throws If fields are invalid or a preset already belongs to active.
882
+ */
883
+ function validatePreset(value, location, active) {
884
+ validate(presetSchema, value, location);
885
+ if (active.has(value)) throw new Error(`${location}: cyclic lint preset extends`);
886
+ active.add(value);
887
+ for (const [index, preset] of (value.extends ?? []).entries()) validatePreset(preset, `${location}.extends[${index}]${object(preset) && typeof preset.name === "string" && preset.name.trim() ? ` (${preset.name})` : ""}`, active);
888
+ active.delete(value);
889
+ }
890
+ /**
891
+ * Expands a validated preset and supplies reporting and detection defaults for every catalog rule.
892
+ *
893
+ * @param config - Validated preset with acyclic ancestry.
894
+ * @returns Complete rule settings. Detection options and their arrays are cloned, unconfigured
895
+ * rules are off, and configured option objects without a severity use warn.
896
+ * @throws If a detection option cannot be cloned.
897
+ */
898
+ function resolvedRules(config) {
899
+ const expanded = expand(config);
900
+ return Object.fromEntries(Object.entries(lintRules).map(([name, rule]) => {
901
+ const setting = expanded[name];
902
+ return [name, rule.defaults === null ? setting ?? "off" : {
903
+ ...structuredClone(rule.defaults),
904
+ ...typeof setting === "object" ? structuredClone(setting) : {},
905
+ severity: typeof setting === "string" ? setting : setting?.severity ?? (setting === void 0 ? "off" : "warn")
906
+ }];
907
+ }));
908
+ }
909
+ /**
910
+ * Composes parent presets from left to right before applying the preset's own rule overrides.
911
+ *
912
+ * @param config - Validated preset with acyclic ancestry. The input is not modified.
913
+ * @returns A new rule map whose option arrays can still share references with the presets.
914
+ */
915
+ function expand(config) {
916
+ let rules = {};
917
+ for (const preset of config.extends ?? []) rules = mergeRules(rules, expand(preset));
918
+ return mergeRules(rules, config.rules ?? {});
919
+ }
920
+ /**
921
+ * Merges rule overrides while retaining inherited options for severity-only settings.
922
+ *
923
+ * @param base - Rules using validated catalog names and option fields.
924
+ * @param overrides - Validated fields. Undefined values preserve prior values, and arrays replace them.
925
+ * @returns A new rule map without mutating either input. Retained or replacement arrays can share input references.
926
+ */
927
+ function mergeRules(base, overrides) {
928
+ const rules = { ...base };
929
+ for (const [name, setting] of Object.entries(overrides)) {
930
+ if (setting === void 0) continue;
931
+ const key = name;
932
+ const previous = base[key];
933
+ const merged = lintRules[key].defaults === null ? setting : {
934
+ ...typeof previous === "string" ? { severity: previous } : previous,
935
+ ...typeof setting === "string" ? { severity: setting } : Object.fromEntries(Object.entries(setting).filter(([, value]) => value !== void 0))
936
+ };
937
+ Object.assign(rules, { [key]: merged });
938
+ }
939
+ return rules;
940
+ }
941
+ /**
942
+ * Checks effective rule settings after all presets, overrides, and defaults have been applied.
943
+ *
944
+ * @param value - Complete rules whose required options can now be checked.
945
+ * @param location - Field path for the rules object in validation errors.
946
+ * @throws If rule settings are invalid or an active theme restriction has no token patterns.
947
+ */
948
+ function validateResolvedRules(value, location) {
949
+ validate(lintRulesSchema, value, location);
950
+ validate(v.pipe(ruleOptions["no-restricted-theme-tokens"], v.forward(v.check((setting) => setting.severity === "off" || Boolean(setting.tokens?.length), "must contain custom-property patterns when the rule is active"), ["tokens"])), value["no-restricted-theme-tokens"], `${location}.no-restricted-theme-tokens`);
951
+ }
952
+ // src/compiler.ts
953
+ const cssPath = v.pipe(v.string("must specify CSS as a nonempty path"), v.check((value) => Boolean(value.trim()), "must specify CSS as a nonempty path"));
954
+ const namespace = v.pipe(v.string(), v.regex(/^--\S+-$/, "must start with --, end with -, and contain no whitespace"));
955
+ const sortOptionsSchema = strictObject({
956
+ stringLiterals: v.optional(v.boolean()),
957
+ arrays: v.optional(v.boolean()),
958
+ applyUtilities: v.optional(v.boolean()),
959
+ applyStatements: v.optional(v.boolean()),
960
+ variantBlocks: v.optional(v.boolean())
961
+ });
962
+ const browserTarget = v.pipe(v.string(), v.regex(/^(?:android|chrome|edge|firefox|ie|ios|opera|safari|samsung)\d+(?:\.\d+){0,2}$/, "must name a browser followed by one to three decimal version components"), v.check((value) => value.replace(/^[a-z]+/, "").split(".").every((part) => Number(part) <= 65535), "version components must not exceed 65535"));
963
+ /** Shared schemas for compiler fields, excluding delivery options and analysis scope. Lint is validated separately. */
964
+ const compilerEntries = {
965
+ root: v.optional(v.string()),
966
+ css: v.optional(cssPath),
967
+ tsconfig: v.optional(v.union([nonemptyText, v.literal(false)])),
968
+ prefix: v.optional(namespace),
969
+ tailwindPrefix: v.optional(namespace),
970
+ themePrefix: v.optional(namespace),
971
+ classNamespace: v.optional(v.string()),
972
+ utilityOrder: v.optional(v.picklist(["authored", "tailwind"])),
973
+ target: v.optional(v.union([browserTarget, v.array(browserTarget)])),
974
+ useCssIf: v.optional(v.boolean()),
975
+ namingRevision: v.optional(v.string()),
976
+ hashLength: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(50))),
977
+ rootFontSize: v.optional(v.pipe(v.number(), v.finite(), v.check((value) => value > 0, "must be positive and finite"))),
978
+ sort: v.optional(v.lazy((value) => value === false ? v.literal(false) : sortOptionsSchema)),
979
+ naming: v.optional(strictObject({
980
+ utilityClass: v.optional(v.function()),
981
+ refMarker: v.optional(v.function()),
982
+ anchorName: v.optional(v.function()),
983
+ containerName: v.optional(v.function()),
984
+ keyframesName: v.optional(v.function()),
985
+ viewTransitionClass: v.optional(v.function()),
986
+ viewTransitionSlot: v.optional(v.function()),
987
+ conditionHelper: v.optional(v.function()),
988
+ layerName: v.optional(v.function())
989
+ })),
990
+ plugins: v.optional(v.array(v.object({
991
+ name: nonemptyText,
992
+ css: v.function(),
993
+ resolve: v.optional(v.function()),
994
+ catalog: v.optional(v.function())
995
+ }))),
996
+ tailwind: v.optional(v.custom(object, "must be a Tailwind configuration object or a promise for one")),
997
+ important: v.optional(v.union([v.literal(true), nonemptyText])),
998
+ lint: v.optional(v.unknown())
999
+ };
1000
+ const compilerSchema = strictObject(compilerEntries);
1001
+ /**
1002
+ * Rejects an `important` field together with `important` in a Tailwind configuration object.
1003
+ * A promised configuration is checked after the host awaits it.
1004
+ */
1005
+ const singleImportant = v.forward(v.check((value) => value.important === void 0 || !object(value.tailwind) || typeof value.tailwind.then === "function" || value.tailwind.important === void 0, "must not be set together with tailwind.important"), ["important"]);
1006
+ /**
1007
+ * Validates compiler fields and lint policies without resolving paths or invoking naming callbacks.
1008
+ * @param value - Compiler settings with no analysis or delivery fields. CSS is optional here.
1009
+ * @param location - Field path prepended to validation errors. Defaults to `config`.
1010
+ * @param partial - Whether incomplete overrides can defer namespace collisions and required lint
1011
+ * options until they are merged with project settings.
1012
+ * @throws If a field is unknown or invalid, namespaces collide, or lint presets or effective options are invalid.
1013
+ */
1014
+ function validateCompilerConfig(value, location = "config", partial = false) {
1015
+ validate(v.pipe(compilerSchema, singleImportant), value, location);
1016
+ if (value.lint !== void 0) validateLintConfig(value.lint, `${location}.lint`, partial);
1017
+ }
1018
+ /**
1019
+ * Validates compiler fields and applies defaults without resolving paths.
1020
+ * @param config - Compiler and delivery settings. Other fields are discarded before validation.
1021
+ * @returns A new object containing compiler and delivery settings with explicit sort flags and
1022
+ * expanded lint rules. Naming callbacks and other unchanged objects can retain input references.
1023
+ * @throws If compiler fields, delivery settings, namespace combinations, or effective lint policies are invalid.
1024
+ */
1025
+ function normalizeCompilerConfig(config) {
1026
+ const { automatic } = config;
1027
+ const compiler = Object.fromEntries(compilerKeys.map((key) => [key, config[key]]));
1028
+ validateCompilerConfig(compiler);
1029
+ if (automatic !== void 0) validate(v.boolean(), automatic, "config.automatic");
1030
+ const lint = resolveLintConfig(config.lint);
1031
+ return {
1032
+ ...compiler,
1033
+ prefix: config.prefix ?? "--sw-",
1034
+ tailwindPrefix: config.tailwindPrefix ?? "--tw-",
1035
+ ...config.themePrefix === void 0 ? {} : { themePrefix: config.themePrefix },
1036
+ classNamespace: config.classNamespace ?? "",
1037
+ utilityOrder: config.utilityOrder ?? "authored",
1038
+ target: typeof config.target === "string" ? [config.target] : [...config.target ?? []],
1039
+ useCssIf: config.useCssIf ?? false,
1040
+ namingRevision: config.namingRevision ?? "",
1041
+ hashLength: config.hashLength ?? 5,
1042
+ rootFontSize: config.rootFontSize ?? 16,
1043
+ automatic: automatic ?? true,
1044
+ sort: config.sort === false ? {
1045
+ stringLiterals: false,
1046
+ arrays: false,
1047
+ applyUtilities: false,
1048
+ applyStatements: false,
1049
+ variantBlocks: false
1050
+ } : {
1051
+ stringLiterals: config.sort?.stringLiterals ?? true,
1052
+ arrays: config.sort?.arrays ?? true,
1053
+ applyUtilities: config.sort?.applyUtilities ?? true,
1054
+ applyStatements: config.sort?.applyStatements ?? false,
1055
+ variantBlocks: config.sort?.variantBlocks ?? false
1056
+ },
1057
+ lint
1058
+ };
1059
+ }
1060
+ /** Compiler field names used to discard analysis and delivery fields before compiler validation. */
1061
+ const compilerKeys = Object.keys(compilerEntries);
1062
+ // src/configuration.ts
1063
+ const capturedProjects = /* @__PURE__ */ new WeakSet();
1064
+ /**
1065
+ * Captures configuration data and callback registries without changing the caller's objects.
1066
+ * @param config - Evaluated project settings. Provider methods retain their original receivers.
1067
+ * @returns Fixed settings. A previously captured configuration is shared without copying it again.
1068
+ */
1069
+ function captureProjectConfig(config) {
1070
+ if (capturedProjects.has(config)) return config;
1071
+ const { naming, sources, projection, plugins, tailwind, ...settings } = config;
1072
+ const data = structuredClone(settings);
1073
+ const capturedSources = sources?.kind === "custom" ? {
1074
+ kind: sources.kind,
1075
+ supports: sources.supports.bind(sources),
1076
+ load: sources.load.bind(sources),
1077
+ ...sources.resolve ? { resolve: sources.resolve.bind(sources) } : {}
1078
+ } : sources && { kind: sources.kind };
1079
+ const capturedProjection = projection?.kind === "custom" ? {
1080
+ kind: projection.kind,
1081
+ prepare: projection.prepare.bind(projection)
1082
+ } : projection && { kind: projection.kind };
1083
+ const captured = {
1084
+ ...data,
1085
+ ...plugins ? { plugins: [...plugins] } : {},
1086
+ ...tailwind ? { tailwind } : {},
1087
+ ...naming ? { naming: {
1088
+ utilityClass: naming.utilityClass,
1089
+ refMarker: naming.refMarker,
1090
+ anchorName: naming.anchorName,
1091
+ containerName: naming.containerName,
1092
+ keyframesName: naming.keyframesName,
1093
+ viewTransitionClass: naming.viewTransitionClass,
1094
+ viewTransitionSlot: naming.viewTransitionSlot,
1095
+ conditionHelper: naming.conditionHelper,
1096
+ layerName: naming.layerName
1097
+ } } : {},
1098
+ ...capturedSources ? { sources: capturedSources } : {},
1099
+ ...capturedProjection ? { projection: capturedProjection } : {}
1100
+ };
1101
+ capturedProjects.add(captured);
1102
+ return captured;
1103
+ }
1104
+ /**
1105
+ * Provides contextual types and returns the supplied export unchanged. Factories run and promises
1106
+ * are awaited when the consumer calls resolveConfig. Definition does not validate their results.
1107
+ *
1108
+ * @param config - Settings, a promise for settings, or a factory returning either form.
1109
+ * @returns The same object, promise, or function with its inferred type preserved.
1110
+ */
1111
+ function defineConfig(config) {
1112
+ return config;
1113
+ }
1114
+ /**
1115
+ * Awaits a configuration export, calls a factory once without arguments when supplied, and
1116
+ * validates the resulting settings. Factory exceptions and rejected promises propagate.
1117
+ *
1118
+ * @param value - Settings, a promise, or a factory from a configuration module's default export.
1119
+ * @returns The validated settings object without copying it.
1120
+ * @throws If evaluation fails or the resulting settings are invalid.
1121
+ */
1122
+ async function resolveConfig(value) {
1123
+ const config = await value;
1124
+ return validateConfig(typeof config === "function" ? await config() : config);
1125
+ }
1126
+ const projectSchema = strictObject({
1127
+ ...compilerEntries,
1128
+ css: v.nonOptional(compilerEntries.css, "must specify CSS as a nonempty path"),
1129
+ automatic: v.optional(v.boolean()),
1130
+ name: v.optional(nonemptyText),
1131
+ files: nonemptyStringList,
1132
+ exclude: v.optional(nonemptyStrings),
1133
+ typeFacts: v.optional(v.literal(false)),
1134
+ preview: v.optional(strictObject({
1135
+ themeValues: v.optional(v.boolean()),
1136
+ pixelEquivalents: v.optional(v.boolean()),
1137
+ colorEquivalents: v.optional(v.union([v.picklist(["approximate", "exact"]), v.literal(false)]))
1138
+ })),
1139
+ sources: v.optional(v.pipe(v.custom(object, "must be an object"), v.variant("kind", [v.strictObject({ kind: v.literal("filesystem") }), v.strictObject({
1140
+ kind: v.literal("custom"),
1141
+ supports: v.function(),
1142
+ load: v.function(),
1143
+ resolve: v.optional(v.function())
1144
+ })]))),
1145
+ projection: v.optional(v.pipe(v.custom(object, "must be an object"), v.variant("kind", [v.strictObject({ kind: v.literal("framework") }), v.strictObject({
1146
+ kind: v.literal("custom"),
1147
+ prepare: v.function()
1148
+ })])))
1149
+ });
1150
+ const configurationSchema = v.pipe(strictObject({ projects: v.pipe(v.array(projectSchema), v.minLength(1, "must be a nonempty projects array")) }), v.rawCheck(({ dataset, addIssue }) => {
1151
+ if (!dataset.typed) return;
1152
+ const names = /* @__PURE__ */ new Set();
1153
+ for (const [index, project] of dataset.value.projects.entries()) {
1154
+ if (project.name === void 0) continue;
1155
+ if (names.has(project.name)) addIssue({
1156
+ message: `Duplicate Stillwind project name: ${project.name}`,
1157
+ path: [
1158
+ {
1159
+ type: "object",
1160
+ origin: "value",
1161
+ input: dataset.value,
1162
+ key: "projects",
1163
+ value: dataset.value.projects
1164
+ },
1165
+ {
1166
+ type: "array",
1167
+ origin: "value",
1168
+ input: dataset.value.projects,
1169
+ key: index,
1170
+ value: project
1171
+ },
1172
+ {
1173
+ type: "object",
1174
+ origin: "value",
1175
+ input: project,
1176
+ key: "name",
1177
+ value: project.name
1178
+ }
1179
+ ]
1180
+ });
1181
+ names.add(project.name);
1182
+ }
1183
+ }));
1184
+ /**
1185
+ * Validates evaluated projects and their compiler settings without running providers or resolving paths.
1186
+ * @param value - Evaluated settings with a nonempty project list, required CSS paths and file globs,
1187
+ * and unique names when names are supplied.
1188
+ * @returns The supplied settings with object and callback identities preserved.
1189
+ * @throws If a field, project name, effective lint policy, or compiler namespace is invalid.
1190
+ * Validation errors include the authored field path.
1191
+ */
1192
+ function validateConfig(value) {
1193
+ validate(configurationSchema, value, "config");
1194
+ for (const [index, project] of value.projects.entries()) {
1195
+ const { automatic: _automatic, name: _name, files: _files, exclude: _exclude, sources: _sources, projection: _projection, typeFacts: _typeFacts, ...compiler } = project;
1196
+ validateCompilerConfig(compiler, `projects[${index}]`);
1197
+ }
1198
+ return value;
1199
+ }
1200
+ // src/merge.ts
1201
+ /**
1202
+ * Merges objects recursively. Undefined preserves previous values, arrays and promises are
1203
+ * replaced, and a changed provider kind replaces that provider's complete configuration.
1204
+ *
1205
+ * @param base - Settings to preserve where overrides omit a value.
1206
+ * @param overrides - Fields to merge or replace. Neither input is modified.
1207
+ * @returns Merged settings. Unchanged values and replacement arrays can share input references.
1208
+ */
1209
+ function mergeConfig(base, overrides) {
1210
+ return mergeValue(base, overrides);
1211
+ }
1212
+ /**
1213
+ * Merges object fields recursively while treating other values as replacements.
1214
+ * @param base - Existing value. It is retained when the override is undefined.
1215
+ * @param override - Replacement or fields to merge. A changed, defined `kind` replaces the whole object.
1216
+ * @returns The original value, replacement value, or a new merged object. Nested values may share
1217
+ * input references, and neither input is mutated.
1218
+ */
1219
+ function mergeValue(base, override) {
1220
+ if (override === void 0) return base;
1221
+ if (!object(base) || !object(override) || typeof base.then === "function" || typeof override.then === "function" || override.kind !== void 0 && base.kind !== override.kind) return override;
1222
+ const result = { ...base };
1223
+ for (const [key, value] of Object.entries(override)) if (value !== void 0) result[key] = mergeValue(base[key], value);
1224
+ return result;
1225
+ }
1226
+ // src/resolution.ts
1227
+ /** Selects projects and resolves compiler settings through host-supplied path operations, without reading files. */
1228
+ /** Filenames in precedence order within each searched directory. */
1229
+ const configurationFiles = [
1230
+ "ts",
1231
+ "mts",
1232
+ "cts",
1233
+ "js",
1234
+ "mjs",
1235
+ "cjs",
1236
+ "json"
1237
+ ].map((extension) => `stillwind.config.${extension}`);
1238
+ /**
1239
+ * Enumerates configuration candidates from the nearest directory to the host's root.
1240
+ * @param directory - Starting directory, normalized with the supplied resolve operation.
1241
+ * @param paths - Consistent host path operations. dirname must return the root unchanged.
1242
+ * @returns Absolute candidate paths in directory order, then configurationFiles order within each
1243
+ * directory. Existence is not checked.
1244
+ */
1245
+ function configurationCandidates(directory, paths) {
1246
+ const candidates = [];
1247
+ let current = paths.resolve(directory);
1248
+ for (;;) {
1249
+ candidates.push(...configurationFiles.map((file) => paths.resolve(current, file)));
1250
+ const parent = paths.dirname(current);
1251
+ if (parent === current) return candidates;
1252
+ current = parent;
1253
+ }
1254
+ }
1255
+ /**
1256
+ * Resolves project paths from their authored root without changing the supplied settings.
1257
+ * @param project - Validated project with a required CSS path and optional root and tsconfig paths.
1258
+ * @param directory - Absolute configuration directory used for a relative or omitted project root.
1259
+ * @param paths - Host operations used to resolve each path.
1260
+ * @returns A copied project with absolute root and CSS paths. A string tsconfig path is resolved
1261
+ * against that root, while false and omission are preserved. Other values retain input references.
1262
+ */
1263
+ function resolveProjectPaths(project, directory, paths) {
1264
+ const root = paths.resolve(directory, project.root ?? ".");
1265
+ return {
1266
+ ...project,
1267
+ root,
1268
+ css: paths.resolve(root, project.css),
1269
+ ...typeof project.tsconfig === "string" ? { tsconfig: paths.resolve(root, project.tsconfig) } : {}
1270
+ };
1271
+ }
1272
+ /**
1273
+ * Removes analysis scope and providers while preserving compiler and delivery settings.
1274
+ * @param project - Evaluated project whose names, file scopes, and providers are no longer needed.
1275
+ * @returns A shallow copy containing compiler fields and automatic CSS delivery settings. Paths
1276
+ * and retained nested objects are unchanged.
1277
+ */
1278
+ function compilerConfig(project) {
1279
+ const { name: _name, files: _files, exclude: _exclude, sources: _sources, projection: _projection, typeFacts: _typeFacts, ...config } = project;
1280
+ return config;
1281
+ }
1282
+ const inlineSchema = strictObject({
1283
+ ...compilerEntries,
1284
+ configFile: v.optional(v.union([nonemptyText, v.literal(false)])),
1285
+ project: v.optional(nonemptyText),
1286
+ automatic: v.optional(v.boolean())
1287
+ });
1288
+ /**
1289
+ * Validates inline selectors and compiler overrides before selection or path resolution.
1290
+ * @param inline - File and project selectors with compiler and delivery overrides.
1291
+ * @throws If a field is unknown or invalid, or a lint preset has a cycle. Namespace collisions
1292
+ * and required effective lint options can remain deferred until settings are merged.
1293
+ */
1294
+ function validateInlineConfig(inline) {
1295
+ validate(inlineSchema, inline, "config");
1296
+ const { configFile: _configFile, project: _project, automatic: _automatic, ...compiler } = inline;
1297
+ validateCompilerConfig(compiler, "config", true);
1298
+ }
1299
+ /**
1300
+ * Selects a named project, the sole project, or the unique deepest containing project root.
1301
+ * @param projects - Evaluated projects with normalized absolute roots. Entries are not modified.
1302
+ * @param applicationRoot - Absolute application directory used for containment when no name is supplied.
1303
+ * @param inline - Project name and optional root override. The override changes the directory tested for containment.
1304
+ * @param paths - Host operations used to resolve the target and compare it with project roots.
1305
+ * @returns The selected input project object. A sole project is selected regardless of containment.
1306
+ * @throws If the requested name or containing root does not identify exactly one project.
1307
+ */
1308
+ function selectProject(projects, applicationRoot, inline, paths) {
1309
+ let selected;
1310
+ if (inline.project !== void 0) selected = projects.filter((project) => project.name === inline.project);
1311
+ else if (projects.length === 1) selected = projects;
1312
+ else {
1313
+ const target = paths.resolve(applicationRoot, inline.root ?? ".");
1314
+ const matches = projects.filter((project) => {
1315
+ const relative = paths.relative(project.root, target).replaceAll("\\", "/");
1316
+ return relative === "" || !paths.isAbsolute(relative) && relative !== ".." && !relative.startsWith("../");
1317
+ });
1318
+ const depth = Math.max(...matches.map((project) => project.root.length));
1319
+ selected = matches.filter((project) => project.root.length === depth);
1320
+ }
1321
+ if (selected.length !== 1) throw new Error(inline.project !== void 0 ? `Cannot select Stillwind project ${JSON.stringify(inline.project)}: expected one matching project` : "Cannot select one Stillwind project; specify project by name or use a distinct project root");
1322
+ return selected[0];
1323
+ }
1324
+ /**
1325
+ * Applies overrides and defaults, then resolves inline paths from the resulting project root.
1326
+ * @param base - Project settings with file-authored root, CSS, and tsconfig paths already resolved.
1327
+ * @param inline - Validated selectors and compiler overrides. Selectors are discarded before merging.
1328
+ * @param applicationRoot - Absolute base directory for an inline root override or omitted project root.
1329
+ * @param paths - Host operations used to resolve paths without checking whether files exist.
1330
+ * @returns Normalized compiler and delivery settings with absolute root and CSS paths. Absolute
1331
+ * file-authored CSS and tsconfig paths retain their original locations when root is overridden.
1332
+ * @throws If effective compiler settings are invalid or no nonempty CSS path is supplied.
1333
+ */
1334
+ function resolveCompilerSettings(base, inline, applicationRoot, paths) {
1335
+ const { configFile: _file, project: _project, ...overrides } = inline;
1336
+ const root = overrides.root !== void 0 ? paths.resolve(applicationRoot, overrides.root) : base.root ?? applicationRoot;
1337
+ const config = normalizeCompilerConfig({
1338
+ ...mergeConfig(base, overrides),
1339
+ lint: mergeLintConfig(base.lint, overrides.lint)
1340
+ });
1341
+ if (!config.css) throw new Error("config.css: must specify CSS as a nonempty path");
1342
+ return {
1343
+ ...config,
1344
+ root,
1345
+ css: paths.resolve(root, config.css),
1346
+ ...typeof config.tsconfig === "string" ? { tsconfig: paths.resolve(root, config.tsconfig) } : {}
1347
+ };
1348
+ }
1349
+ export { lintRules as _, resolveProjectPaths as a, mergeConfig as c, resolveConfig as d, validateConfig as f, resolveLintConfig as g, mergeLintConfig as h, resolveCompilerSettings as i, captureProjectConfig as l, validateCompilerConfig as m, configurationCandidates as n, selectProject as o, normalizeCompilerConfig as p, configurationFiles as r, validateInlineConfig as s, compilerConfig as t, defineConfig as u, lintPresets as v };
1350
+
1351
+ //# sourceMappingURL=resolution-BK-NUhyh.js.map