praxis-kit 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/dist/_shared/diagnostics.d.ts +312 -0
  4. package/dist/_shared/diagnostics.js +360 -0
  5. package/dist/build-runtime-CJ_nQEaZ.js +5065 -0
  6. package/dist/codemod/index.d.ts +2 -0
  7. package/dist/codemod/index.js +176520 -0
  8. package/dist/contract/index.d.ts +677 -0
  9. package/dist/contract/index.js +341 -0
  10. package/dist/eslint/index.d.ts +90 -0
  11. package/dist/eslint/index.js +1047 -0
  12. package/dist/guards/index.d.ts +78 -0
  13. package/dist/guards/index.js +118 -0
  14. package/dist/html/index.d.ts +151 -0
  15. package/dist/html/index.js +1244 -0
  16. package/dist/index-BIBd_iPD.d.ts +951 -0
  17. package/dist/lit/index.d.ts +862 -0
  18. package/dist/lit/index.js +4893 -0
  19. package/dist/preact/index.d.ts +796 -0
  20. package/dist/preact/index.js +5043 -0
  21. package/dist/react/index.d.ts +28 -0
  22. package/dist/react/index.js +205 -0
  23. package/dist/react/legacy.d.ts +29 -0
  24. package/dist/react/legacy.js +80 -0
  25. package/dist/solid/index.d.ts +728 -0
  26. package/dist/solid/index.js +4821 -0
  27. package/dist/svelte/Polymorphic.svelte +190 -0
  28. package/dist/svelte/_polymorphic-runtime.d.ts +102 -0
  29. package/dist/svelte/_polymorphic-runtime.js +371 -0
  30. package/dist/svelte/index.d.ts +994 -0
  31. package/dist/svelte/index.js +4482 -0
  32. package/dist/tailwind/index.d.ts +197 -0
  33. package/dist/tailwind/index.js +767 -0
  34. package/dist/tailwind/safelist.css +20 -0
  35. package/dist/ts-plugin/index.cjs +166 -0
  36. package/dist/ts-plugin/index.d.cts +9 -0
  37. package/dist/utils/index.d.ts +19 -0
  38. package/dist/utils/index.js +21 -0
  39. package/dist/vite-plugin/index.d.ts +200 -0
  40. package/dist/vite-plugin/index.js +2106 -0
  41. package/dist/vue/index.d.ts +729 -0
  42. package/dist/vue/index.js +4945 -0
  43. package/dist/web/index.d.ts +832 -0
  44. package/dist/web/index.js +4868 -0
  45. package/package.json +258 -0
@@ -0,0 +1,360 @@
1
+ //#region ../../lib/diagnostics/src/category.ts
2
+ /** The kind of rule a diagnostic reports. The load-bearing distinction:
3
+ *
4
+ * - `HTML` / `ARIA` — **spec compliance**. The markup or ARIA usage is invalid
5
+ * per the HTML standard or the ARIA spec. A fact, not a judgement.
6
+ * - `Accessibility` — **best-practice guidance**. The usage is spec-valid but
7
+ * inadvisable (e.g. a placeholder standing in for a label). Advisory.
8
+ *
9
+ * Keep that split deliberate: a rule belongs in `Accessibility` only when it is
10
+ * *not* an `HTML`/`ARIA` validity fact. The code ranges mirror it — `ARIA2xxx`
11
+ * and `HTML3xxx` are validity, `A11Y8xxx` is guidance (see `codes.ts`). */
12
+ let DiagnosticCategory = /* @__PURE__ */ function(DiagnosticCategory) {
13
+ DiagnosticCategory[DiagnosticCategory["Contract"] = 0] = "Contract";
14
+ DiagnosticCategory[DiagnosticCategory["HTML"] = 1] = "HTML";
15
+ DiagnosticCategory[DiagnosticCategory["ARIA"] = 2] = "ARIA";
16
+ DiagnosticCategory[DiagnosticCategory["Composition"] = 3] = "Composition";
17
+ DiagnosticCategory[DiagnosticCategory["Rendering"] = 4] = "Rendering";
18
+ DiagnosticCategory[DiagnosticCategory["Accessibility"] = 5] = "Accessibility";
19
+ DiagnosticCategory[DiagnosticCategory["Performance"] = 6] = "Performance";
20
+ DiagnosticCategory[DiagnosticCategory["Internal"] = 7] = "Internal";
21
+ DiagnosticCategory[DiagnosticCategory["Deprecation"] = 8] = "Deprecation";
22
+ DiagnosticCategory[DiagnosticCategory["Lint"] = 9] = "Lint";
23
+ return DiagnosticCategory;
24
+ }({});
25
+ //#endregion
26
+ //#region ../../lib/diagnostics/src/codes.ts
27
+ let DiagnosticCode = /* @__PURE__ */ function(DiagnosticCode) {
28
+ DiagnosticCode["MissingRequiredChild"] = "COMP1001";
29
+ DiagnosticCode["InvalidParent"] = "COMP1002";
30
+ DiagnosticCode["InvalidChild"] = "COMP1003";
31
+ DiagnosticCode["UnexpectedChild"] = "COMP1004";
32
+ DiagnosticCode["AmbiguousChild"] = "COMP1005";
33
+ DiagnosticCode["CardinalityMin"] = "COMP1006";
34
+ DiagnosticCode["CardinalityMax"] = "COMP1007";
35
+ DiagnosticCode["PositionViolation"] = "COMP1008";
36
+ DiagnosticCode["AllowedAsViolation"] = "COMP1009";
37
+ DiagnosticCode["SlotExclusive"] = "SLOT1001";
38
+ DiagnosticCode["SlotSingleChild"] = "SLOT1002";
39
+ DiagnosticCode["SlotDiscardedChildren"] = "SLOT1003";
40
+ DiagnosticCode["SlotRenderFn"] = "SLOT1004";
41
+ DiagnosticCode["MissingAriaRelationship"] = "ARIA2001";
42
+ DiagnosticCode["AriaViolation"] = "ARIA2002";
43
+ DiagnosticCode["AriaAttributeInvalid"] = "ARIA2003";
44
+ DiagnosticCode["AriaMissingLiveRegion"] = "ARIA2004";
45
+ DiagnosticCode["AriaMissingAtomic"] = "ARIA2005";
46
+ DiagnosticCode["AriaRelevantInvalidToken"] = "ARIA2006";
47
+ DiagnosticCode["AriaRelevantSuperseded"] = "ARIA2007";
48
+ DiagnosticCode["AriaInvalidRole"] = "ARIA2008";
49
+ DiagnosticCode["AriaMissingAccessibleName"] = "ARIA2009";
50
+ DiagnosticCode["AriaAttributeOnPresentational"] = "ARIA2010";
51
+ DiagnosticCode["AriaHiddenOnFocusable"] = "ARIA2011";
52
+ DiagnosticCode["AriaRequiredProperty"] = "ARIA2012";
53
+ DiagnosticCode["AriaInvalidAttributeValue"] = "ARIA2013";
54
+ DiagnosticCode["AriaRedundantLevelAttribute"] = "ARIA2014";
55
+ DiagnosticCode["AriaNameProhibited"] = "ARIA2015";
56
+ DiagnosticCode["InvalidHeadingHierarchy"] = "HTML3001";
57
+ DiagnosticCode["HtmlEmptyRole"] = "HTML3002";
58
+ DiagnosticCode["HtmlImplicitRoleRedundant"] = "HTML3003";
59
+ DiagnosticCode["HtmlImplicitRoleOverride"] = "HTML3004";
60
+ DiagnosticCode["HtmlStandaloneRegionOverride"] = "HTML3005";
61
+ DiagnosticCode["HtmlLandmarkRoleOverride"] = "HTML3006";
62
+ DiagnosticCode["HtmlInvalidChild"] = "HTML3007";
63
+ DiagnosticCode["HtmlRoleNotPermitted"] = "HTML3008";
64
+ DiagnosticCode["HtmlInputUnsupportedType"] = "HTML3101";
65
+ DiagnosticCode["HtmlInputCheckedIgnoredForType"] = "HTML3102";
66
+ DiagnosticCode["HtmlInputMultipleIgnoredForType"] = "HTML3103";
67
+ DiagnosticCode["HtmlInputMaxLengthIgnoredForType"] = "HTML3104";
68
+ DiagnosticCode["HtmlInputMinLengthIgnoredForType"] = "HTML3105";
69
+ DiagnosticCode["HtmlInputPatternIgnoredForType"] = "HTML3106";
70
+ DiagnosticCode["HtmlInputMinIgnoredForType"] = "HTML3107";
71
+ DiagnosticCode["HtmlInputMaxIgnoredForType"] = "HTML3108";
72
+ DiagnosticCode["HtmlInputStepIgnoredForType"] = "HTML3109";
73
+ DiagnosticCode["HtmlInputAcceptIgnoredForType"] = "HTML3110";
74
+ DiagnosticCode["HtmlInputCaptureIgnoredForType"] = "HTML3111";
75
+ DiagnosticCode["HtmlInputSizeIgnoredForType"] = "HTML3112";
76
+ DiagnosticCode["HtmlInputAltIgnoredForType"] = "HTML3113";
77
+ DiagnosticCode["HtmlInputHeightIgnoredForType"] = "HTML3114";
78
+ DiagnosticCode["HtmlInputWidthIgnoredForType"] = "HTML3115";
79
+ DiagnosticCode["HtmlAnchorDangerousHref"] = "HTML3201";
80
+ DiagnosticCode["A11yInputMissingAccessibleName"] = "A11Y8100";
81
+ DiagnosticCode["A11yInputPlaceholderNotLabel"] = "A11Y8101";
82
+ DiagnosticCode["A11yInputPasswordAutocomplete"] = "A11Y8102";
83
+ DiagnosticCode["A11yInputRequiredReadOnlyConflict"] = "A11Y8103";
84
+ DiagnosticCode["A11yAnchorRoleButtonWithHref"] = "A11Y8200";
85
+ DiagnosticCode["A11yAnchorAriaDisabledInert"] = "A11Y8201";
86
+ DiagnosticCode["InvalidRenderingTarget"] = "RENDER4001";
87
+ DiagnosticCode["LintDeadCompoundKey"] = "LINT5001";
88
+ DiagnosticCode["LintDeadCompoundValue"] = "LINT5002";
89
+ DiagnosticCode["LintDeadCompoundNonLiteral"] = "LINT5003";
90
+ DiagnosticCode["LintMissingStrict"] = "LINT5004";
91
+ DiagnosticCode["LintInvalidDefaultKey"] = "LINT5005";
92
+ DiagnosticCode["LintInvalidDefaultValue"] = "LINT5006";
93
+ DiagnosticCode["LintInvalidDefaultNonLiteral"] = "LINT5007";
94
+ DiagnosticCode["LintNegativeMin"] = "LINT5008";
95
+ DiagnosticCode["LintNegativeMax"] = "LINT5009";
96
+ DiagnosticCode["LintMaxLessThanMin"] = "LINT5010";
97
+ DiagnosticCode["LintZeroMax"] = "LINT5011";
98
+ DiagnosticCode["LintMultipleFirst"] = "LINT5012";
99
+ DiagnosticCode["LintMultipleLast"] = "LINT5013";
100
+ DiagnosticCode["LintMinSumExceedsCapacity"] = "LINT5014";
101
+ DiagnosticCode["LintCardinalityViolation"] = "LINT5015";
102
+ DiagnosticCode["LintAriaTagOverride"] = "LINT5016";
103
+ DiagnosticCode["ContractUnknownVariantDim"] = "COMP1010";
104
+ DiagnosticCode["ContractUnknownVariantValue"] = "COMP1011";
105
+ DiagnosticCode["ContractUnknownRecipeKey"] = "COMP1012";
106
+ DiagnosticCode["ContractInvalidVariantValue"] = "COMP1013";
107
+ DiagnosticCode["TailwindMultipleDisplayProps"] = "CSS6001";
108
+ DiagnosticCode["TailwindReservedLayoutLiteral"] = "CSS6002";
109
+ DiagnosticCode["TailwindDeadVariantClass"] = "CSS6003";
110
+ DiagnosticCode["TailwindLayoutOnVoidTag"] = "CSS6004";
111
+ DiagnosticCode["PluginInvalidShape"] = "PLUGIN7001";
112
+ DiagnosticCode["PluginPipelineReturnType"] = "PLUGIN7002";
113
+ DiagnosticCode["InternalError"] = "INTERNAL9000";
114
+ return DiagnosticCode;
115
+ }({});
116
+ //#endregion
117
+ //#region ../../lib/diagnostics/src/error.ts
118
+ var PraxisError = class extends Error {
119
+ diagnostic;
120
+ constructor(diagnostic) {
121
+ super(diagnostic.message);
122
+ this.name = "PraxisError";
123
+ this.diagnostic = diagnostic;
124
+ }
125
+ };
126
+ //#endregion
127
+ //#region ../../lib/diagnostics/src/severity.ts
128
+ let Severity = /* @__PURE__ */ function(Severity) {
129
+ Severity[Severity["Debug"] = 0] = "Debug";
130
+ Severity[Severity["Info"] = 1] = "Info";
131
+ Severity[Severity["Warning"] = 2] = "Warning";
132
+ Severity[Severity["Error"] = 3] = "Error";
133
+ Severity[Severity["Fatal"] = 4] = "Fatal";
134
+ return Severity;
135
+ }({});
136
+ function isAtLeast(s, threshold) {
137
+ return s >= threshold;
138
+ }
139
+ //#endregion
140
+ //#region ../../lib/diagnostics/src/policy.ts
141
+ let Enforcement = /* @__PURE__ */ function(Enforcement) {
142
+ Enforcement[Enforcement["Ignore"] = 0] = "Ignore";
143
+ Enforcement[Enforcement["Report"] = 1] = "Report";
144
+ Enforcement[Enforcement["Throw"] = 2] = "Throw";
145
+ return Enforcement;
146
+ }({});
147
+ var DefaultPolicy = class {
148
+ reportThreshold;
149
+ throwThreshold;
150
+ constructor({ reportThreshold = 1, throwThreshold = 4 } = {}) {
151
+ if (throwThreshold < reportThreshold) throw new RangeError(`DefaultPolicy: throwThreshold (${Severity[throwThreshold]}) must be >= reportThreshold (${Severity[reportThreshold]})`);
152
+ this.reportThreshold = reportThreshold;
153
+ this.throwThreshold = throwThreshold;
154
+ }
155
+ resolve(diagnostic) {
156
+ if (diagnostic.severity >= this.throwThreshold) return 2;
157
+ if (diagnostic.severity >= this.reportThreshold) return 1;
158
+ return 0;
159
+ }
160
+ };
161
+ //#endregion
162
+ //#region ../../lib/diagnostics/src/diagnostics.ts
163
+ var Diagnostics = class {
164
+ reporter;
165
+ policy;
166
+ /** Cheap gate for callers: `false` means a `Severity.Warning` diagnostic would
167
+ * be ignored by the policy, so warning-level validation work (often the
168
+ * expensive kind) can be skipped entirely. Precomputed at construction.
169
+ *
170
+ * Scoped to Warning deliberately — it is **not** a general "diagnostics on"
171
+ * flag. A policy that ignores Warning but reports Info or throws on Error
172
+ * still reads `false` here; check the policy directly for other severities. */
173
+ warnActive;
174
+ constructor(reporter, policy = new DefaultPolicy()) {
175
+ this.reporter = reporter;
176
+ this.policy = policy;
177
+ this.warnActive = policy.resolve({ severity: 2 }) !== 0;
178
+ }
179
+ report(diagnostic) {
180
+ const enforcement = this.policy.resolve(diagnostic);
181
+ if (enforcement === 0) return diagnostic;
182
+ if (enforcement === 2) throw new PraxisError(diagnostic);
183
+ this.reporter.report(diagnostic);
184
+ return diagnostic;
185
+ }
186
+ debug(input) {
187
+ return this.report({
188
+ ...input,
189
+ severity: 0
190
+ });
191
+ }
192
+ info(input) {
193
+ return this.report({
194
+ ...input,
195
+ severity: 1
196
+ });
197
+ }
198
+ warn(input) {
199
+ return this.report({
200
+ ...input,
201
+ severity: 2
202
+ });
203
+ }
204
+ error(input) {
205
+ return this.report({
206
+ ...input,
207
+ severity: 3
208
+ });
209
+ }
210
+ fatal(input) {
211
+ return this.report({
212
+ ...input,
213
+ severity: 4
214
+ });
215
+ }
216
+ };
217
+ //#endregion
218
+ //#region ../../lib/foundation/src/type-guards.ts
219
+ function isString(value) {
220
+ return typeof value === "string";
221
+ }
222
+ function isDefined(value) {
223
+ return value !== void 0;
224
+ }
225
+ function isUndefined(value) {
226
+ return value === void 0;
227
+ }
228
+ //#endregion
229
+ //#region ../../lib/diagnostics/src/formatter.ts
230
+ function formatDiagnostic(diagnostic) {
231
+ const level = Severity[diagnostic.severity];
232
+ const category = DiagnosticCategory[diagnostic.category];
233
+ const prefix = isDefined(category) ? `[${category}] ` : "";
234
+ return `${level} ${diagnostic.code}: ${prefix}${diagnostic.message}`;
235
+ }
236
+ //#endregion
237
+ //#region ../../lib/diagnostics/src/result.ts
238
+ function ok(value) {
239
+ return {
240
+ ok: true,
241
+ value
242
+ };
243
+ }
244
+ function err(error) {
245
+ return {
246
+ ok: false,
247
+ error
248
+ };
249
+ }
250
+ //#endregion
251
+ //#region ../../lib/diagnostics/src/async-console-reporter.ts
252
+ /** A console reporter that batches a microtask's worth of diagnostics into one
253
+ * flush and drops duplicates within that window.
254
+ *
255
+ * Dedup key is the **formatted string**, on purpose: this reporter's job is
256
+ * console UX — don't print the same line twice. Two distinct diagnostics that
257
+ * format identically (same code + message, different file/location) collapse to
258
+ * one printed line. If you need every distinct diagnostic preserved, use
259
+ * `CollectingReporter`; this one is not a lossless channel. (A
260
+ * location-aware key is a possible future refinement if `formatDiagnostic`
261
+ * stops including enough identity.) */
262
+ var AsyncConsoleReporter = class {
263
+ pending = /* @__PURE__ */ new Set();
264
+ scheduled = false;
265
+ report(diagnostic) {
266
+ const message = formatDiagnostic(diagnostic);
267
+ if (this.pending.has(message)) return;
268
+ this.pending.add(message);
269
+ if (!this.scheduled) {
270
+ this.scheduled = true;
271
+ queueMicrotask(() => {
272
+ this.scheduled = false;
273
+ for (const msg of this.pending) console.warn(msg);
274
+ this.pending.clear();
275
+ });
276
+ }
277
+ }
278
+ /** Clears pending messages. Exposed for test isolation only. */
279
+ reset() {
280
+ this.pending.clear();
281
+ this.scheduled = false;
282
+ }
283
+ };
284
+ //#endregion
285
+ //#region ../../lib/diagnostics/src/collecting-reporter.ts
286
+ var CollectingReporter = class {
287
+ collected = [];
288
+ report(diagnostic) {
289
+ this.collected.push(diagnostic);
290
+ }
291
+ get diagnostics() {
292
+ return this.collected;
293
+ }
294
+ clear() {
295
+ this.collected.length = 0;
296
+ }
297
+ };
298
+ //#endregion
299
+ //#region ../../lib/diagnostics/src/console-reporter.ts
300
+ var ConsoleReporter = class {
301
+ report(diagnostic) {
302
+ const message = formatDiagnostic(diagnostic);
303
+ switch (diagnostic.severity) {
304
+ case 0:
305
+ console.debug(message);
306
+ break;
307
+ case 1:
308
+ console.info(message);
309
+ break;
310
+ case 2:
311
+ console.warn(message);
312
+ break;
313
+ case 3:
314
+ case 4: console.error(message);
315
+ }
316
+ }
317
+ };
318
+ //#endregion
319
+ //#region ../../lib/diagnostics/src/null-reporter.ts
320
+ const nullReporter = { report() {} };
321
+ //#endregion
322
+ //#region ../../lib/diagnostics/src/presets.ts
323
+ const ignoreAllPolicy = { resolve(_) {
324
+ return 0;
325
+ } };
326
+ const warnOnlyReporter = { report(diagnostic) {
327
+ console.warn(formatDiagnostic(diagnostic));
328
+ } };
329
+ /** `'silent'` mode — every diagnostic is ignored. */
330
+ const silentDiagnostics = new Diagnostics(nullReporter, ignoreAllPolicy);
331
+ /** `'warn'` mode — Warning and above print to the console; only `Fatal` throws. */
332
+ const warnDiagnostics = new Diagnostics(warnOnlyReporter, new DefaultPolicy({
333
+ reportThreshold: 2,
334
+ throwThreshold: 4
335
+ }));
336
+ /** `'throw'` mode — Warning prints, **`Error` and above throw**. Note this is
337
+ * "errors throw", not "everything throws"; a Warning is still just logged. */
338
+ const throwDiagnostics = new Diagnostics(new ConsoleReporter(), new DefaultPolicy({
339
+ reportThreshold: 2,
340
+ throwThreshold: 3
341
+ }));
342
+ //#endregion
343
+ //#region ../../lib/diagnostics/src/resolve-diagnostics.ts
344
+ const PRESETS_BY_MODE = {
345
+ warn: warnDiagnostics,
346
+ throw: throwDiagnostics,
347
+ silent: silentDiagnostics
348
+ };
349
+ /**
350
+ * Resolves an `enforcement.diagnostics` value — a preset name, a full `Diagnostics`
351
+ * instance, or `undefined` — to a concrete `Diagnostics` instance. Lets authors write
352
+ * `enforcement: { diagnostics: 'warn' }` without importing `Diagnostics` or the presets
353
+ * themselves.
354
+ */
355
+ function resolveDiagnostics(value, fallback) {
356
+ if (isUndefined(value)) return fallback;
357
+ return isString(value) ? PRESETS_BY_MODE[value] : value;
358
+ }
359
+ //#endregion
360
+ export { AsyncConsoleReporter, CollectingReporter, ConsoleReporter, DefaultPolicy, DiagnosticCategory, DiagnosticCode, Diagnostics, Enforcement, PraxisError, Severity, err, formatDiagnostic, isAtLeast, nullReporter, ok, resolveDiagnostics, silentDiagnostics, throwDiagnostics, warnDiagnostics };