@kutur-kit/oxc 0.1.0-alpha.4 → 0.1.0-alpha.5

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 (66) hide show
  1. package/README.md +45 -7
  2. package/dist/effect.d.ts.map +1 -1
  3. package/dist/effect.js +6 -0
  4. package/dist/effect.js.map +1 -1
  5. package/dist/foldkit-stylex/attributes.d.ts +2 -0
  6. package/dist/foldkit-stylex/attributes.d.ts.map +1 -0
  7. package/dist/foldkit-stylex/attributes.js +191 -0
  8. package/dist/foldkit-stylex/attributes.js.map +1 -0
  9. package/dist/foldkit-stylex/components.d.ts +12 -0
  10. package/dist/foldkit-stylex/components.d.ts.map +1 -0
  11. package/dist/foldkit-stylex/components.js +41 -0
  12. package/dist/foldkit-stylex/components.js.map +1 -0
  13. package/dist/foldkit-stylex/condition-key.d.ts +2 -0
  14. package/dist/foldkit-stylex/condition-key.d.ts.map +1 -0
  15. package/dist/foldkit-stylex/condition-key.js +255 -0
  16. package/dist/foldkit-stylex/condition-key.js.map +1 -0
  17. package/dist/foldkit-stylex/styles.d.ts +2 -0
  18. package/dist/foldkit-stylex/styles.d.ts.map +1 -0
  19. package/dist/foldkit-stylex/styles.js +131 -0
  20. package/dist/foldkit-stylex/styles.js.map +1 -0
  21. package/dist/foldkit-stylex/unstyled-view.d.ts +2 -0
  22. package/dist/foldkit-stylex/unstyled-view.d.ts.map +1 -0
  23. package/dist/foldkit-stylex/unstyled-view.js +89 -0
  24. package/dist/foldkit-stylex/unstyled-view.js.map +1 -0
  25. package/dist/foldkit-stylex/vite.d.ts +2 -0
  26. package/dist/foldkit-stylex/vite.d.ts.map +1 -0
  27. package/dist/foldkit-stylex/vite.js +26 -0
  28. package/dist/foldkit-stylex/vite.js.map +1 -0
  29. package/dist/foldkit-stylex.d.ts +21 -0
  30. package/dist/foldkit-stylex.d.ts.map +1 -0
  31. package/dist/foldkit-stylex.js +25 -0
  32. package/dist/foldkit-stylex.js.map +1 -0
  33. package/dist/foldkit-stylex.json +25 -0
  34. package/dist/plugin.d.ts.map +1 -1
  35. package/dist/plugin.js +12 -0
  36. package/dist/plugin.js.map +1 -1
  37. package/dist/rules/imports.d.ts +37 -0
  38. package/dist/rules/imports.d.ts.map +1 -0
  39. package/dist/rules/imports.js +72 -0
  40. package/dist/rules/imports.js.map +1 -0
  41. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts +2 -0
  42. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts.map +1 -0
  43. package/dist/rules/no-manual-effect-runtime-in-tests.js +74 -0
  44. package/dist/rules/no-manual-effect-runtime-in-tests.js.map +1 -0
  45. package/dist/rules/scope.d.ts +9 -0
  46. package/dist/rules/scope.d.ts.map +1 -0
  47. package/dist/rules/scope.js +15 -0
  48. package/dist/rules/scope.js.map +1 -0
  49. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts.map +1 -1
  50. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +17 -1
  51. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js.map +1 -1
  52. package/package.json +14 -4
  53. package/src/effect.ts +6 -0
  54. package/src/foldkit-stylex/attributes.ts +282 -0
  55. package/src/foldkit-stylex/components.ts +41 -0
  56. package/src/foldkit-stylex/condition-key.ts +321 -0
  57. package/src/foldkit-stylex/styles.ts +170 -0
  58. package/src/foldkit-stylex/unstyled-view.ts +116 -0
  59. package/src/foldkit-stylex/vite.ts +29 -0
  60. package/src/foldkit-stylex.ts +29 -0
  61. package/src/plugin.ts +12 -0
  62. package/src/rules/imports.ts +99 -0
  63. package/src/rules/no-manual-effect-runtime-in-tests.ts +99 -0
  64. package/src/rules/scope.ts +24 -0
  65. package/src/vendor/anti-slop/UPSTREAM.md +2 -0
  66. package/src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts +22 -1
package/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # @kutur-kit/oxc
2
2
 
3
- Oxlint and Oxfmt presets for TypeScript, with optional Effect rules.
3
+ Oxlint and Oxfmt presets for TypeScript, with optional Effect and `@kutur-kit/foldkit-stylex` rules.
4
4
 
5
- | Export | Required tools |
6
- | ------------ | ---------------------------------------------- |
7
- | `/base` | `oxlint`, a type-aware backend |
8
- | `/effect` | `oxlint`, `@effect/tsgo`, a type-aware backend |
9
- | `/format` | `oxfmt` |
10
- | `/anti-slop` | `oxlint` |
5
+ | Export | Required tools |
6
+ | ----------------- | ---------------------------------------------- |
7
+ | `/base` | `oxlint`, a type-aware backend |
8
+ | `/effect` | `oxlint`, `@effect/tsgo`, a type-aware backend |
9
+ | `/format` | `oxfmt` |
10
+ | `/anti-slop` | `oxlint` |
11
+ | `/foldkit-stylex` | `oxlint`, `@stylexjs/eslint-plugin` |
11
12
 
12
13
  The type-aware backend is [tsrs](https://github.com/oxc-project/tsrs) or `oxlint-tsgolint`.
13
14
 
@@ -37,8 +38,45 @@ Install the required tools in `devDependencies` and include linted files in your
37
38
 
38
39
  `/effect` also warns where code uses a runtime global that has an Effect service, such as `console`, `Date` or `process.env`. Its rules warn, so set `maxWarnings: 0` to fail on them. Turn a rule off with `overrides` only for files where the global is the point, such as a script that prints its result.
39
40
 
41
+ In test files (`*.test.*`, `*.spec.*`, `test/**` and `tests/**`), `/effect` also reports manual Effect runners: `Effect.runPromise`, `Effect.runSync` and the other `run*` functions, their `*With` forms and the runners of a `ManagedRuntime` made in the same file. Run effects in tests with `it.effect` from `@effect/vitest`, which provides `TestClock`, and provide services with Layers. The rule also reports runners at module scope: compute a value that a test file needs before its tests run, such as an environment flag, in `vitest.config.ts` and read it with Vitest's `provide` and `inject`.
42
+
40
43
  `/anti-slop` is optional and includes the generic and Effect rules from [anti-slop](https://github.com/dmmulroy/anti-slop), and `kit/comment-prose` (see [Prose](#prose)).
41
44
 
45
+ ### @kutur-kit/foldkit-stylex
46
+
47
+ `/foldkit-stylex` checks what the types of `@kutur-kit/foldkit-stylex` cannot see:
48
+
49
+ - a second Class on an element, or a Class or Style that replaces a @foldkit/ui part's, on a bundle `toView` hands out or `DragAndDropStyle.draggable` returns, or in a `*Attributes` view input;
50
+ - a @foldkit/ui view used without its `XStyle.view` wrapper;
51
+ - StyleX condition keys that never match or that rank differently than written, such as `:focus-visible` or `:has(:focus-visible)` next to `:hover` or `:user-invalid`;
52
+ - `createTheme`, `--fks-*` tokens set on an element, theme overrides without `satisfies ThemeOverrides`, styles objects annotated or cast with `as`, and arrays of them annotated, cast or typed as a parameter;
53
+ - StyleX's own Vite plugin.
54
+
55
+ It also turns on StyleX's ESLint rules. Each message names the fix. Add `@stylexjs/eslint-plugin` to your `devDependencies` beside Oxlint, then extend the preset in `oxlint.config.ts`:
56
+
57
+ ```ts
58
+ import effect from "@kutur-kit/oxc/effect";
59
+ import foldkitStylex from "@kutur-kit/oxc/foldkit-stylex";
60
+ import { defineConfig } from "oxlint";
61
+
62
+ export default defineConfig({
63
+ extends: [effect, foldkitStylex],
64
+ options: { typeAware: true, maxWarnings: 0 },
65
+ });
66
+ ```
67
+
68
+ Or in `.oxlintrc.json`, which extends configs by path:
69
+
70
+ ```json
71
+ {
72
+ "extends": ["./node_modules/@kutur-kit/oxc/dist/foldkit-stylex.json"]
73
+ }
74
+ ```
75
+
76
+ The rules recognise `sx`, the `XStyle` namespaces, StyleX, Effect and @foldkit/ui by their imports, named, aliased or as a namespace, and read each file on its own. They recognise @foldkit/ui parts by the names `toView`, `entryToView`, `toCalendarView` and `*Attributes`, so an app's own Submodel that uses those names is checked as a @foldkit/ui part. They follow bundles through `map`, `flatMap` and `filter` written in place, as array methods, Effect `Array` functions or `pipe` steps.
77
+
78
+ They miss a @foldkit/ui view, a `create()` result or a styled draggable that reaches the file through another module, a bundle kept in a variable or iterated another way, a Class that a helper adds to a bundle passed to it, and a `*Attributes` input whose `childAttributes([...])` call is not written in place.
79
+
42
80
  ### Suppression comments
43
81
 
44
82
  `kit/no-suppression-directives` reports comments that suppress Oxlint rules or Effect diagnostics, reading `oxlint-disable`, `eslint-disable` and `@effect-diagnostics` as Oxlint and tsgo read them. With `{ allowWithReason: true }`, as `/base` sets it, a comment passes when it names each rule and gives a reason after `--`:
@@ -1 +1 @@
1
- {"version":3,"file":"effect.d.ts","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,MAAM,EAAE,YAsBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"effect.d.ts","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,MAAM,EAAE,YA4Bb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/effect.js CHANGED
@@ -21,6 +21,12 @@ const effect = {
21
21
  // Effect's documented form for a service is a class that extends `Context.Service`.
22
22
  "effecttsgo/service-not-as-class": "warn",
23
23
  },
24
+ overrides: [
25
+ {
26
+ files: ["**/*.test.*", "**/*.spec.*", "**/test/**", "**/tests/**"],
27
+ rules: { "kit/no-manual-effect-runtime-in-tests": "error" },
28
+ },
29
+ ],
24
30
  options: { typeAware: true },
25
31
  };
26
32
  export default effect;
@@ -1 +1 @@
1
- {"version":3,"file":"effect.js","sources":["../src/effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,MAAM,GAAiB;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC;IAC5B,KAAK,EAAE;QACL,kFAAkF;QAClF,+BAA+B,EAAE,MAAM;QACvC,yCAAyC,EAAE,MAAM;QACjD,2BAA2B,EAAE,MAAM;QACnC,qCAAqC,EAAE,MAAM;QAC7C,wBAAwB,EAAE,MAAM;QAChC,kCAAkC,EAAE,MAAM;QAC1C,yBAAyB,EAAE,MAAM;QACjC,mCAAmC,EAAE,M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,2 @@
1
+ export declare const attributes: import("@oxlint/plugins").Rule;
2
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sources":["../../src/foldkit-stylex/attributes.ts"],"names":[],"mappings":"AA2DA,eAAO,MAAM,UAAU,gCA8NrB,CAAC"}
@@ -0,0 +1,191 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { effectMemberOf, exportOf, importsOf, isMethodCall, keyOf, resolve, rootOf, } from "../rules/imports.js";
3
+ import { variableOf } from "../rules/scope.js";
4
+ const kit = "@kutur-kit/foldkit-stylex";
5
+ // Callbacks through which @foldkit/ui hands the app attribute bundles for its parts.
6
+ const bundleCallbacks = new Set(["toView", "entryToView", "toCalendarView"]);
7
+ // View inputs whose attributes @foldkit/ui applies to a part after the part's class, such as
8
+ // `buttonAttributes`.
9
+ const attributesInput = /^(attributes|\w+Attributes)$/;
10
+ // Array methods and Effect Array functions that call a callback with each item of an array.
11
+ const iterators = new Set(["map", "flatMap"]);
12
+ // Array methods and Effect Array functions that return some items of an array.
13
+ const filters = new Set(["filter"]);
14
+ // The value of a `toView`-like property, as in `toView: (attributes) => ...` or `toView: view`.
15
+ const isBundleCallback = (node) => node.parent?.type === "Property" &&
16
+ node.parent.value === node &&
17
+ bundleCallbacks.has(keyOf(node.parent) ?? "");
18
+ const isSx = (node, imports) => node.type === "CallExpression" && exportOf(node.callee, imports, kit) === "sx";
19
+ // Whether `node` writes an element's class or its style, of which Foldkit keeps one each, and
20
+ // whether it writes it raw, as `h.Attribute("class", ...)`.
21
+ const writtenBy = (node, imports) => {
22
+ if (isMethodCall(node, "Attribute")) {
23
+ const [name] = node.arguments;
24
+ return name?.type === "Literal" && (name.value === "class" || name.value === "style")
25
+ ? { attribute: name.value, raw: true }
26
+ : undefined;
27
+ }
28
+ if (isSx(node, imports) || isMethodCall(node, "Class"))
29
+ return { attribute: "class", raw: false };
30
+ return isMethodCall(node, "Style") ? { attribute: "style", raw: false } : undefined;
31
+ };
32
+ export const attributes = defineRule({
33
+ meta: {
34
+ type: "problem",
35
+ docs: {
36
+ description: "Keep one Class per element: styles in one sx(...) call, after every spread, and never on a @foldkit/ui part.",
37
+ },
38
+ schema: [],
39
+ messages: {
40
+ partClass: "This element is a @foldkit/ui part, whose Class its XStyle wrapper sets. Put these styles in that part's entry of its styles: Foldkit keeps one Class per element, so this replaces the part's styles and the functional ones.",
41
+ partStyle: "This element is a @foldkit/ui part, whose inline style @foldkit/ui owns, and Foldkit keeps one Style per element, so this replaces it. Put static styles in that part's entry of its styles. For a runtime value, set a custom property with h.Style on your own element around the part and read it with var() in the part's styles; a portaled panel inherits from none of your elements, so set it on an element you render inside the panel and style that element.",
42
+ oneCall: "Pass every style of this element to one sx(...) call, conditions included. Foldkit keeps one Class per element, and StyleX resolves conflicting properties only within one call.",
43
+ oneClass: "Join these class names into one Class. Foldkit keeps one Class per element, so this one replaces the ones before it.",
44
+ last: "Put sx(...) last in the attribute list. Foldkit keeps the last Class, so a bundle spread after it replaces these styles.",
45
+ rawClass: "Use sx(...) for StyleX styles or h.Class(...) for class names. Scene's toHaveClass cannot see a raw class attribute.",
46
+ rawStyle: "Use h.Style(...). A raw style attribute throws when the element also gets a Style, as @foldkit/ui panels do.",
47
+ stylexRuntime: "Use sx(...). stylex.props returns numbers that h.Style rejects and omits className when no style applies; stylex.attrs kebab-cases custom properties and returns a raw attribute Scene cannot see.",
48
+ notInElement: "Write sx(...) directly in the attribute list of the element it styles, so this rule sees every Class that element gets. Put conditions inside the call: sx(isOpen ? styles.open : styles.closed).",
49
+ },
50
+ },
51
+ createOnce(context) {
52
+ let imports = new Map();
53
+ // A binding made by `DragAndDropStyle.draggable(...)`, which returns the draggable's attributes
54
+ // with its Class.
55
+ const isStyledDraggable = (callee) => callee.type === "Identifier" &&
56
+ (variableOf(context.sourceCode, callee)?.defs.some(({ node }) => node.type === "VariableDeclarator" &&
57
+ node.init?.type === "CallExpression" &&
58
+ exportOf(node.init.callee, imports, kit) === "DragAndDropStyle.draggable") ??
59
+ false);
60
+ // The Effect Array function `callee` names, such as `map` for `Array.map`.
61
+ const arrayFunctionOf = (callee) => effectMemberOf(resolve(callee, imports), "Array");
62
+ // Effect's `pipe`, from effect or effect/Function.
63
+ const isPipe = (callee) => {
64
+ const imported = resolve(callee, imports);
65
+ return ((imported?.source === "effect" && imported.path === "pipe") ||
66
+ effectMemberOf(imported, "Function") === "pipe");
67
+ };
68
+ // The array a call of one of `names` reads: the receiver of `tabs.map(...)`, or the first
69
+ // argument of Effect's `Array.map(tabs, ...)`.
70
+ const arrayOf = (call, names) => {
71
+ const { callee } = call;
72
+ const effect = arrayFunctionOf(callee);
73
+ if (effect !== undefined)
74
+ return names.has(effect) ? call.arguments[0] : undefined;
75
+ return callee.type === "MemberExpression" &&
76
+ !callee.computed &&
77
+ callee.property.type === "Identifier" &&
78
+ names.has(callee.property.name)
79
+ ? callee.object
80
+ : undefined;
81
+ };
82
+ // A part's bundle: a parameter of a function @foldkit/ui calls with bundles, a member of one
83
+ // such as `tab.tab`, bundles filtered as in `tabs.filter(...)` or `Array.filter(tabs, ...)`, or
84
+ // the result of a styled draggable.
85
+ const isBundle = (node) => {
86
+ if (node === undefined || node.type === "SpreadElement")
87
+ return false;
88
+ if (node.type === "CallExpression") {
89
+ return isBundle(arrayOf(node, filters)) || isStyledDraggable(node.callee);
90
+ }
91
+ const root = rootOf(node);
92
+ const variable = root === undefined ? undefined : variableOf(context.sourceCode, root);
93
+ return (variable?.defs.some((def) => def.type === "Parameter" && takesBundles(def.node)) ?? false);
94
+ };
95
+ // The `const` or `function` declaration that names `fn`.
96
+ const declarationOf = (fn) => {
97
+ if (fn.type === "FunctionDeclaration")
98
+ return fn;
99
+ return fn.parent?.type === "VariableDeclarator" && fn.parent.init === fn
100
+ ? fn.parent
101
+ : undefined;
102
+ };
103
+ // A function @foldkit/ui calls with bundles: one written as a `toView`-like property, one
104
+ // declared by name and passed as one, as in `toView: checkboxView`, or a callback that iterates
105
+ // bundles, as in `tabs.map(cb)`, `Array.map(tabs, cb)` or `pipe(tabs, Array.map(cb))`.
106
+ const takesBundles = (fn) => {
107
+ if (isBundleCallback(fn))
108
+ return true;
109
+ const declaration = declarationOf(fn);
110
+ if (declaration !== undefined) {
111
+ return context.sourceCode
112
+ .getDeclaredVariables(declaration)
113
+ .some(({ defs, references }) => defs.some(({ type }) => type !== "Parameter") &&
114
+ references.some(({ identifier }) => isBundleCallback(identifier)));
115
+ }
116
+ const { parent } = fn;
117
+ if (parent?.type !== "CallExpression")
118
+ return false;
119
+ const pipeline = parent.parent;
120
+ // A data-last step of a pipe gets what flows from the pipe's first argument.
121
+ if (pipeline.type === "CallExpression" &&
122
+ isPipe(pipeline.callee) &&
123
+ parent.arguments.length === 1 &&
124
+ iterators.has(arrayFunctionOf(parent.callee) ?? "")) {
125
+ return isBundle(pipeline.arguments[0]);
126
+ }
127
+ return isBundle(arrayOf(parent, iterators));
128
+ };
129
+ // An attribute list that ends up on a part: one that spreads a part's bundle, or the
130
+ // `childAttributes([...])` of a view input such as `buttonAttributes`.
131
+ const isPartList = (list) => {
132
+ const { parent } = list;
133
+ if (parent.type === "CallExpression" &&
134
+ exportOf(parent.callee, imports, "foldkit/html") === "childAttributes") {
135
+ return (parent.parent.type === "Property" && attributesInput.test(keyOf(parent.parent) ?? ""));
136
+ }
137
+ return list.elements.some((item) => item?.type === "SpreadElement" && isBundle(item.argument));
138
+ };
139
+ return {
140
+ Program(program) {
141
+ imports = importsOf(program);
142
+ },
143
+ CallExpression(node) {
144
+ const runtime = exportOf(node.callee, imports, "@stylexjs/stylex");
145
+ // A result the code throws away, as in a compile guard, reaches no element.
146
+ if ((runtime === "props" || runtime === "attrs") &&
147
+ node.parent.type !== "ExpressionStatement") {
148
+ context.report({ node, messageId: "stylexRuntime" });
149
+ }
150
+ if (isSx(node, imports) && node.parent.type !== "ArrayExpression") {
151
+ context.report({ node, messageId: "notInElement" });
152
+ }
153
+ },
154
+ ArrayExpression(node) {
155
+ const written = node.elements.flatMap((item) => {
156
+ if (item === null)
157
+ return [];
158
+ const writes = writtenBy(item, imports);
159
+ return writes === undefined ? [] : [{ item, ...writes }];
160
+ });
161
+ if (isPartList(node)) {
162
+ for (const { item, attribute } of written) {
163
+ context.report({
164
+ node: item,
165
+ messageId: attribute === "class" ? "partClass" : "partStyle",
166
+ });
167
+ }
168
+ return;
169
+ }
170
+ for (const { item, attribute } of written.filter(({ raw }) => raw)) {
171
+ context.report({
172
+ node: item,
173
+ messageId: attribute === "class" ? "rawClass" : "rawStyle",
174
+ });
175
+ }
176
+ const classWriters = written.flatMap(({ item, attribute, raw }) => attribute === "class" && !raw ? [item] : []);
177
+ const oneCall = classWriters.some((item) => isSx(item, imports)) ? "oneCall" : "oneClass";
178
+ for (const item of classWriters.slice(1)) {
179
+ context.report({ node: item, messageId: oneCall });
180
+ }
181
+ const items = node.elements.filter((item) => item !== null);
182
+ const lastSpread = items.map((item) => item.type).lastIndexOf("SpreadElement");
183
+ for (const item of items.slice(0, Math.max(lastSpread, 0))) {
184
+ if (isSx(item, imports))
185
+ context.report({ node: item, messageId: "last" });
186
+ }
187
+ },
188
+ };
189
+ },
190
+ });
191
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sources":["../../src/foldkit-stylex/attributes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EACL,cAAc,EACd,QAAQ,EAER,SAAS,EACT,YAAY,EACZ,KAAK,EACL,OAAO,EACP,MAAM,GACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,GAAG,GAAG,2BAA2B,CAAC;AAExC,qFAAqF;AACrF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE7E,6FAA6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I,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBACrD,CAAC;gBAED,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;gBAE5D,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;gBAE/E,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC3D,IAAI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;wBAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC7E,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The @foldkit/ui namespaces that @kutur-kit/foldkit-stylex wraps, as `<Name>Style` namespaces.
3
+ * `foldkit-stylex-unstyled-view` asks for a wrapper only for these. A test compares the list with
4
+ * the core's `src/index.ts`, so add a name in the change that adds its namespace to the core.
5
+ */
6
+ export declare const components: ReadonlySet<string>;
7
+ /**
8
+ * The view each `<Name>Style` namespace wraps under the same name. DragAndDrop has no `view`: its
9
+ * styled part is the bundle `draggable` returns.
10
+ */
11
+ export declare const viewOf: (component: string) => "draggable" | "view";
12
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sources":["../../src/foldkit-stylex/components.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,MAAM,CA6BzC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,MAAM,cAAe,MAAM,yBAAyD,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The @foldkit/ui namespaces that @kutur-kit/foldkit-stylex wraps, as `<Name>Style` namespaces.
3
+ * `foldkit-stylex-unstyled-view` asks for a wrapper only for these. A test compares the list with
4
+ * the core's `src/index.ts`, so add a name in the change that adds its namespace to the core.
5
+ */
6
+ export const components = new Set([
7
+ "Animation",
8
+ "Button",
9
+ "Calendar",
10
+ "Checkbox",
11
+ "Combobox",
12
+ "DatePicker",
13
+ "Dialog",
14
+ "Disclosure",
15
+ "DragAndDrop",
16
+ "Fieldset",
17
+ "FileDrop",
18
+ "HoverIntent",
19
+ "Input",
20
+ "Listbox",
21
+ "Menu",
22
+ "Meter",
23
+ "Nav",
24
+ "Popover",
25
+ "Progress",
26
+ "RadioGroup",
27
+ "Select",
28
+ "Slider",
29
+ "Switch",
30
+ "Tabs",
31
+ "Textarea",
32
+ "Toast",
33
+ "Tooltip",
34
+ "VirtualList",
35
+ ]);
36
+ /**
37
+ * The view each `<Name>Style` namespace wraps under the same name. DragAndDrop has no `view`: its
38
+ * styled part is the bundle `draggable` returns.
39
+ */
40
+ export const viewOf = (component) => (component === "DragAndDrop" ? "draggable" : "view");
41
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sources":["../../src/foldkit-stylex/components.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IACrD,WAAW;IACX,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,UAAU;IACV,UAAU;IACV,aAAa;IACb,OAAO;IACP,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,SAAS;IACT,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,UAAU;IACV,OAAO;IACP,SAAS;IACT,aAAa;CACd,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,SAAS,KAAK,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const conditionKey: import("@oxlint/plugins").Rule;
2
+ //# sourceMappingURL=condition-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-key.d.ts","sources":["../../src/foldkit-stylex/condition-key.ts"],"names":[],"mappings":"AAsKA,eAAO,MAAM,YAAY,gCA0JvB,CAAC"}
@@ -0,0 +1,255 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { exportOf, importsOf, keyOf } from "../rules/imports.js";
3
+ // Hooks @foldkit/ui derives from state that the kit exposes as flags, native states that
4
+ // @foldkit/ui's aria-disabled controls never enter, and ARIA attributes.
5
+ const stateHook = /data-(checked|indeterminate|open|active|selected|disabled|readonly|invalid|focused|current|drag-over|dragging|today|outside-month|state|variant|closed|swipe)\b|:(disabled|enabled|checked|indeterminate|read-only|read-write|invalid|open)\b|\[aria-/;
6
+ // Every Toast entry shares one class, which cannot take state, so its animation and swipe key on
7
+ // these hooks.
8
+ const toastEntryHooks = /data-(closed|swipe)\b/g;
9
+ const unbounded = {
10
+ min: { value: -Infinity, inclusive: true },
11
+ max: { value: Infinity, inclusive: true },
12
+ };
13
+ const length = String.raw `(\d*\.?\d+)(px|rem|em)`;
14
+ const feature = new RegExp(String.raw `^\((min|max)-width:\s*${length}\)$`);
15
+ const comparison = new RegExp(String.raw `^\(width\s*(<=?|>=?)\s*${length}\)$`);
16
+ const narrow = (range, side, bound) => ({
17
+ ...range,
18
+ [side]: bound,
19
+ });
20
+ // rem and em resolve against the browser's default font size in media queries.
21
+ const toPixels = (value, unit) => Number(value) * (unit === "px" ? 1 : 16);
22
+ // Parses `@media (min-width: 40rem) and (prefers-reduced-motion: reduce)`, with widths also in the
23
+ // `(width >= 640px)` form. Returns `undefined` for a query with a media type, `or`, `not` or a
24
+ // comma.
25
+ const mediaQueryOf = (key) => {
26
+ if (!key.startsWith("@media "))
27
+ return undefined;
28
+ let range = unbounded;
29
+ const features = new Set();
30
+ for (const condition of key
31
+ .slice("@media ".length)
32
+ .trim()
33
+ .split(/\s+and\s+/)) {
34
+ const minMax = feature.exec(condition);
35
+ const compared = comparison.exec(condition);
36
+ if (minMax !== null) {
37
+ const [, side = "", value = "", unit = ""] = minMax;
38
+ range = narrow(range, side === "min" ? "min" : "max", {
39
+ value: toPixels(value, unit),
40
+ inclusive: true,
41
+ });
42
+ }
43
+ else if (compared !== null) {
44
+ const [, operator = "", value = "", unit = ""] = compared;
45
+ range = narrow(range, operator.startsWith(">") ? "min" : "max", {
46
+ value: toPixels(value, unit),
47
+ inclusive: operator.endsWith("="),
48
+ });
49
+ }
50
+ else if (/^\([^()]*\)$/.test(condition)) {
51
+ features.add(condition.replaceAll(/\s/g, ""));
52
+ }
53
+ else {
54
+ return undefined;
55
+ }
56
+ }
57
+ return { range, features };
58
+ };
59
+ const atOrBelow = (a, b) => a.value < b.value || (a.value === b.value && (b.inclusive || !a.inclusive));
60
+ const atOrAbove = (a, b) => a.value > b.value || (a.value === b.value && (b.inclusive || !a.inclusive));
61
+ // Whether `outer` matches wherever `inner` does: it needs no feature `inner` lacks, and its widths
62
+ // include all of `inner`'s.
63
+ const covers = (outer, inner) => [...outer.features].every((name) => inner.features.has(name)) &&
64
+ atOrAbove(inner.range.min, outer.range.min) &&
65
+ atOrBelow(inner.range.max, outer.range.max);
66
+ // PSEUDO_CLASS_PRIORITIES of @stylexjs/babel-plugin 0.19.1, less its entries of 40 and its focus
67
+ // entries. StyleX ranks a key by the name before its first '(', and an unlisted name, such as ':is',
68
+ // 40. It ranks a chain without '(', such as ':hover:active', by the sum of its parts; this rule
69
+ // reads a chain as unlisted, so it never reports one.
70
+ const pseudoClassRank = new Map([
71
+ [":has", 45],
72
+ [":dir", 50],
73
+ [":lang", 51],
74
+ [":first-child", 52],
75
+ [":first-of-type", 53],
76
+ [":last-child", 54],
77
+ [":last-of-type", 55],
78
+ [":only-child", 56],
79
+ [":only-of-type", 57],
80
+ [":nth-child", 60],
81
+ [":nth-last-child", 61],
82
+ [":nth-of-type", 62],
83
+ [":nth-last-of-type", 63],
84
+ [":empty", 70],
85
+ [":link", 80],
86
+ [":any-link", 81],
87
+ [":local-link", 82],
88
+ [":target-within", 83],
89
+ [":target", 84],
90
+ [":visited", 85],
91
+ [":enabled", 91],
92
+ [":disabled", 92],
93
+ [":required", 93],
94
+ [":optional", 94],
95
+ [":read-only", 95],
96
+ [":read-write", 96],
97
+ [":placeholder-shown", 97],
98
+ [":in-range", 98],
99
+ [":out-of-range", 99],
100
+ [":default", 100],
101
+ [":checked", 101],
102
+ [":indeterminate", 101],
103
+ [":blank", 102],
104
+ [":valid", 103],
105
+ [":invalid", 104],
106
+ [":user-invalid", 105],
107
+ [":autofill", 110],
108
+ [":picture-in-picture", 120],
109
+ [":modal", 121],
110
+ [":fullscreen", 122],
111
+ [":paused", 123],
112
+ [":playing", 124],
113
+ [":current", 125],
114
+ [":past", 126],
115
+ [":future", 127],
116
+ [":hover", 130],
117
+ [":focus", 150],
118
+ [":active", 170],
119
+ ]);
120
+ // The ranks StyleX's table means focus keys to have. It lists ':focus-visible' and ':focus-within'
121
+ // as ':focusVisible' and ':focusWithin', so they rank 40, below every listed pseudo-class.
122
+ // ':has(:focus-visible)', which styles focus on an element whose input is hidden, ranks 45 as a
123
+ // ':has' key and takes the rank of ':focus-visible' here.
124
+ const intendedRank = new Map([
125
+ [":focus-visible", 160],
126
+ [":focus-within", 140],
127
+ [":has(:focus-visible)", 160],
128
+ ]);
129
+ const rankOf = (key) => pseudoClassRank.get(key.replace(/\(.*/, "")) ?? 40;
130
+ export const conditionKey = defineRule({
131
+ meta: {
132
+ type: "problem",
133
+ docs: {
134
+ description: "Disallow StyleX condition keys that never match or that rank differently than written.",
135
+ },
136
+ hasSuggestions: true,
137
+ schema: [],
138
+ messages: {
139
+ stateAttribute: "Style '{{key}}' from state: (state) => [styles.base, state.isChecked && styles.checked] in a part's styles, or sx(styles.base, isChecked && styles.checked) on your own element. @foldkit/ui's hooks differ across components (Checkbox, Switch, Button and Listbox use aria-disabled, so :disabled never matches them), and StyleX ranks ':is()' keys of one property equally.",
140
+ bareAttribute: "Write ':is({{key}})' instead of '{{key}}'. StyleX adds 3000 to a bare attribute condition's priority, above :hover (+130) and media queries (+200), and types its value as unknown, which typed style props reject. The :is() form ranks with pseudo-classes, so check which condition wins where they overlap.",
141
+ mediaOrder: "'{{earlier}}' never matches: StyleX rewrites each media query to exclude the ones after it in the same property, and '{{later}}' matches wherever it does. Put the query that covers the other first: min-width queries from narrow to wide, max-width queries from wide to narrow.",
142
+ focusRank: "StyleX 0.19 ranks '{{key}}' below '{{above}}', so '{{above}}' wins wherever both match and hides the focus style. Style focus on a property that '{{above}}' does not set, or write '{{above}}:not({{key}})' so the two never match together.",
143
+ wrapInIs: "Wrap the key in :is().",
144
+ },
145
+ },
146
+ createOnce(context) {
147
+ let imports = new Map();
148
+ // State hook keys, reported at the end of the file once every Toast entry is known.
149
+ let candidates = [];
150
+ // Style keys passed as a Toast `entry`, such as `entry` in `entry: styles.entry`.
151
+ let toastEntries = new Set();
152
+ const checkMediaOrder = (properties) => {
153
+ const queries = properties.flatMap((property) => {
154
+ const key = keyOf(property);
155
+ const query = key === undefined ? undefined : mediaQueryOf(key);
156
+ return key === undefined || query === undefined ? [] : [{ key, query, property }];
157
+ });
158
+ for (const [index, earlier] of queries.entries()) {
159
+ const later = queries.slice(index + 1).find(({ query }) => covers(query, earlier.query));
160
+ if (later !== undefined) {
161
+ context.report({
162
+ node: earlier.property.key,
163
+ messageId: "mediaOrder",
164
+ data: { earlier: earlier.key, later: later.key },
165
+ });
166
+ }
167
+ }
168
+ };
169
+ // A focus key next to a key that StyleX ranks above it but its table puts below it. Keys of
170
+ // one rank, such as ':focus-visible' and ':is()', tie and are not reported.
171
+ const checkFocusRank = (properties) => {
172
+ const keys = properties.flatMap((property) => keyOf(property) ?? []);
173
+ for (const property of properties) {
174
+ const key = keyOf(property) ?? "";
175
+ const intended = intendedRank.get(key);
176
+ const above = intended === undefined
177
+ ? undefined
178
+ : keys.find((other) => rankOf(other) > rankOf(key) && rankOf(other) < intended);
179
+ if (above !== undefined) {
180
+ context.report({ node: property.key, messageId: "focusRank", data: { key, above } });
181
+ }
182
+ }
183
+ };
184
+ const checkKey = (entry, key, property) => {
185
+ if (stateHook.test(key)) {
186
+ candidates.push({ entry, key, node: property.key });
187
+ }
188
+ else if (key.startsWith("[")) {
189
+ context.report({
190
+ node: property.key,
191
+ messageId: "bareAttribute",
192
+ data: { key },
193
+ suggest: [
194
+ {
195
+ messageId: "wrapInIs",
196
+ fix: (fixer) => fixer.replaceText(property.key, JSON.stringify(`:is(${key})`)),
197
+ },
198
+ ],
199
+ });
200
+ }
201
+ };
202
+ const checkStyle = (entry, style) => {
203
+ // A dynamic style's conditions are in the object its function returns.
204
+ const object = style.type === "ArrowFunctionExpression" ? style.body : style;
205
+ if (object.type !== "ObjectExpression")
206
+ return;
207
+ const properties = object.properties.filter((property) => property.type === "Property");
208
+ checkMediaOrder(properties);
209
+ checkFocusRank(properties);
210
+ for (const property of properties) {
211
+ const key = keyOf(property);
212
+ if (key !== undefined)
213
+ checkKey(entry, key, property);
214
+ checkStyle(entry, property.value);
215
+ }
216
+ };
217
+ return {
218
+ Program(program) {
219
+ imports = importsOf(program);
220
+ candidates = [];
221
+ toastEntries = new Set();
222
+ },
223
+ CallExpression(node) {
224
+ const [styles] = node.arguments;
225
+ if (exportOf(node.callee, imports, "@stylexjs/stylex") !== "create" ||
226
+ styles?.type !== "ObjectExpression") {
227
+ return;
228
+ }
229
+ for (const entry of styles.properties) {
230
+ const name = entry.type === "Property" ? keyOf(entry) : undefined;
231
+ if (entry.type === "Property" && name !== undefined)
232
+ checkStyle(name, entry.value);
233
+ }
234
+ },
235
+ MemberExpression(node) {
236
+ if (node.computed || node.property.type !== "Identifier")
237
+ return;
238
+ for (let parent = node.parent; parent !== null; parent = parent.parent) {
239
+ if (parent.type === "Property" && keyOf(parent) === "entry") {
240
+ toastEntries.add(node.property.name);
241
+ return;
242
+ }
243
+ }
244
+ },
245
+ "Program:exit"() {
246
+ for (const { entry, key, node } of candidates) {
247
+ const entryOnly = toastEntries.has(entry) && !stateHook.test(key.replaceAll(toastEntryHooks, ""));
248
+ if (!entryOnly)
249
+ context.report({ node, messageId: "stateAttribute", data: { key } });
250
+ }
251
+ },
252
+ };
253
+ },
254
+ });
255
+ //# sourceMappingURL=condition-key.js.map