@edux-design/utils

中文文档
0.1.2发布于 2026/11/01TypeScriptESM + CJS零依赖近 30 天下载 2295

Shared Edux class composition and React child helpers.

原始使用文档

@edux-design/utils

Shared Edux class composition and React child helpers.

import { cx, filterChildrenByDisplayName, getSlot } from "@edux-design/utils";

cx("p-8 text-sm", condition && "px-24", "text-fg-base");
// p-8 text-sm px-24 text-fg-base

cx("px-24 py-8", "p-16");
// p-16

cx(...inputs) retains the existing conditional input contract: strings, conditional objects, numbers and nested arrays; falsy inputs are omitted. It then applies an independently authored Edux input flattener and utility conflict resolver. Neither clsx nor tailwind-merge is a runtime or declaration dependency. The flattener uses an explicit stack for nested arrays, preserves inherited enumerable object keys, and ignores unsupported primitive inputs. Cyclic arrays are invalid inputs and throw instead of looping indefinitely; reusing an array in separate positions is supported. The declaration accepts unknown inputs, preserving readonly tuples and values that the existing normalisation ignores rather than introducing a type-only restriction.

The other exports are unchanged:

  • filterChildrenByDisplayName(children, displayName) selects matching direct React children, including named ref-forwarding components.
  • getSlot(children, slotComponent) returns the matched direct child's content.

The package root requires React and React DOM ^19.1.0 because it exports React child helpers. The class resolver itself imports no React or DOM APIs and runs during server rendering without browser globals. ESM, CJS and own strict public declarations are provided at the package root. Deep imports are not a supported API.

Conflict semantics

Within the same modifier and importance scope, the last utility wins for its declaration group. Shorthand replacement is directional: a later p-16 replaces earlier px-24 py-8, while a later px-24 retains the vertical part of p-16. Logical and physical edges remain independent where writing-mode differences matter. Width/height, font size/colour, border width/colour, shadow size/colour, gradient stops, filters and masks have separate declaration groups.

Normal pseudo-classes commute within a selector segment. Pseudo-elements, wildcard variants and arbitrary selector variants preserve their relative order. Both !p-4 and p-4! are supported; important and ordinary declarations are separate scopes. Arbitrary values, typed custom properties, arbitrary CSS properties, negative utilities and the existing Edux semantic colour classes are recognised. An arbitrary CSS property conflicts with the same property, without guessing that it overrides an unrelated ordinary utility.

Unknown application and custom theme classes are retained, including repeated classes. For example, custom animate-drawer-* and cursor-pagination-* classes are not inferred to override standard animation/cursor utilities. The resolver does not load a consumer's Tailwind configuration or inspect browser stylesheets. Consumers who introduce custom utility names retain the established default cx behaviour rather than getting speculative conflict removal. The established colour and font-family namespaces are deliberately open: a bg-custom name is still a colour utility, for example. Unknown-class retention does not override those existing default namespace rules.

Compatibility includes a historical important-prefix font/line-height quirk: !text-lg/8 and text-lg/8! remain distinct in the established conflict model. The suffix form follows normal font-size/line-height grouping. This preserves the accepted output of the previous public API; it is not a recommendation to mix important syntaxes.

Ownership and validation

The resolver was written from CSS property relationships, Edux requirements and independent public black-box observations. No third-party merge implementation, declaration or test code was read, copied or translated. Retained dependencies still carry their own licence terms.

The independent acceptance corpus covers 32,757 conditional, observed and extended Tailwind 4 cases plus large/deep adversarial inputs. Its portable repository pool and the separately recorded optional Payload snapshot are distinguished in the acceptance receipts. Native generated-CSS fixtures compare computed styles, pseudo-element paint and measured dimensions with the accepted public Utils implementation. See the coordinator's docs/original-drag-and-classes/class-acceptance/ evidence for exact candidate hashes and browser coverage; source diagnostics are not installed-artifact proof.

The owned conditional input layer also has colocated edge-case tests and an optional 50,000-case black-box comparison against an ordinary old consumer:

node packages/utils/test/compare-class-inputs.mjs /absolute/old-utils-consumer

That comparison executes only the old dependency's public function. The normal Utils test suite does not require clsx to be installed.

The resolver keeps bounded FIFO caches: at most 500 complete inputs of up to 16,384 characters and 2,000 classified base tokens of up to 1,024 characters. Larger values are resolved without caching. Parsing is iterative, with no DOM subscriptions, timers or recursive arbitrary-value traversal. Benchmarks are descriptive; extreme 10,000-token cases are not an interaction latency guarantee.

npm run test --workspace=@edux-design/utils
npm run lint --workspace=@edux-design/utils
npm run check-types --workspace=@edux-design/utils
npm run build --workspace=@edux-design/utils

版本与发布记录

@edux-design/utils 共发布 9 个版本,首次发布于 2025/09/10;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.1.2latest2026/11/0113 天前
0.1.12026/10/3114 天前
0.1.02026/01/0110 个月前
0.0.62025/12/2310 个月前
0.0.52025/12/0911 个月前
0.0.42025/12/0911 个月前

关于 @edux-design/utils 的常见问题

@edux-design/utils 是什么?

Shared Edux class composition and React child helpers.

如何安装 @edux-design/utils?

在项目目录运行 npm install @edux-design/utils,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.1.0)、react-dom(^19.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@edux-design/utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@edux-design/utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@edux-design/utils 可以商用吗?

@edux-design/utils 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@edux-design/utils 的下载量有多少?

根据 npm 官方下载统计,@edux-design/utils 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,295 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@edux-design/utils 还在维护吗?

最新版本 0.1.2 发布于 2026/11/01(13 天前);至今共发布 9 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。