@tea-ui/utils 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.
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 landnevermore
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @tea-ui/utils
|
|
2
|
+
|
|
3
|
+
Shared types, class-name composition and small helpers.
|
|
4
|
+
|
|
5
|
+
Part of [TEA UI](https://landnevermore.github.io/TEAui/) — a design system built once and reused across
|
|
6
|
+
products. The whole system is documented at https://landnevermore.github.io/TEAui/docs/.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @tea-ui/utils
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
React 18.2 or 19 is expected as a peer dependency.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { tokens } from "@tea-ui/utils";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Licence
|
|
23
|
+
|
|
24
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
export { ClassValue, clsx } from 'clsx';
|
|
3
|
+
export { VariantProps, cva } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TEA UI — utilities.
|
|
7
|
+
*
|
|
8
|
+
* The smallest package in the system, and the one with the fewest opinions.
|
|
9
|
+
* Its job is to make the house style the path of least resistance: one class
|
|
10
|
+
* merge, one variant author, one prefix, one exhaustive check.
|
|
11
|
+
*
|
|
12
|
+
* It has no React dependency and no design opinions, so anything that needs
|
|
13
|
+
* either belongs elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
17
|
+
/** Alias for {@link cn}, for call sites where "compose" reads better. */
|
|
18
|
+
declare const cx: typeof cn;
|
|
19
|
+
|
|
20
|
+
/** Every TEA UI component prefixes its `data-slot` with this. */
|
|
21
|
+
declare const TEA_PREFIX = "tea";
|
|
22
|
+
/**
|
|
23
|
+
* Build a namespaced `data-slot` value, e.g. `slot("button", "icon")` ->
|
|
24
|
+
* `"tea-button-icon"`. One helper means one naming convention, and a
|
|
25
|
+
* convention that a test can assert.
|
|
26
|
+
*/
|
|
27
|
+
declare function slot(...parts: string[]): string;
|
|
28
|
+
/**
|
|
29
|
+
* Exhaustiveness check. The audit found five independent hand-written
|
|
30
|
+
* status-to-label tables per project, each disagreeing with the others; the
|
|
31
|
+
* type system catches the sixth version of that the moment a new variant
|
|
32
|
+
* appears without a label.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* function toneOf(t: Tone): string {
|
|
36
|
+
* switch (t) {
|
|
37
|
+
* case "positive": return "ok";
|
|
38
|
+
* // ...
|
|
39
|
+
* default: return assertNever(t);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function assertNever(value: never, message?: string): never;
|
|
45
|
+
/**
|
|
46
|
+
* Join class names and drop falsy entries, without merging. Useful when
|
|
47
|
+
* composing a class string that must NOT be deduplicated against a base
|
|
48
|
+
* (rare — prefer {@link cn} — but needed when a caller deliberately wants two
|
|
49
|
+
* `bg-*` classes to both reach the cascade).
|
|
50
|
+
*/
|
|
51
|
+
declare function joinClasses(...inputs: ClassValue[]): string;
|
|
52
|
+
|
|
53
|
+
export { TEA_PREFIX, assertNever, cn, cx, joinClasses, slot };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { clsx } from "clsx";
|
|
2
|
+
import { extendTailwindMerge } from "tailwind-merge";
|
|
3
|
+
const twMerge = extendTailwindMerge({
|
|
4
|
+
extend: {
|
|
5
|
+
classGroups: {
|
|
6
|
+
"font-size": [
|
|
7
|
+
{ text: ["label", "micro", "ui", "body", "lead", "title", "section", "display", "hero", "mono"] }
|
|
8
|
+
],
|
|
9
|
+
rounded: [{ rounded: ["none", "pill"] }],
|
|
10
|
+
shadow: [{ shadow: ["none", "raised", "overlay", "modal", "inset"] }]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const Z_UTILITIES = /* @__PURE__ */ new Set([
|
|
15
|
+
"z-base",
|
|
16
|
+
"z-raised",
|
|
17
|
+
"z-sticky",
|
|
18
|
+
"z-header",
|
|
19
|
+
"z-dropdown",
|
|
20
|
+
"z-overlay",
|
|
21
|
+
"z-modal",
|
|
22
|
+
"z-popover",
|
|
23
|
+
"z-toast",
|
|
24
|
+
"z-tooltip",
|
|
25
|
+
"z-max"
|
|
26
|
+
]);
|
|
27
|
+
function keepLastZUtilities(merged) {
|
|
28
|
+
const classes = merged.split(" ").filter(Boolean);
|
|
29
|
+
const lastIndex = /* @__PURE__ */ new Map();
|
|
30
|
+
classes.forEach((className, index) => {
|
|
31
|
+
if (Z_UTILITIES.has(className)) lastIndex.set(className, index);
|
|
32
|
+
});
|
|
33
|
+
if (lastIndex.size < 2) return merged;
|
|
34
|
+
return classes.filter((className, index) => !Z_UTILITIES.has(className) || lastIndex.get(className) === index).join(" ");
|
|
35
|
+
}
|
|
36
|
+
function cn(...inputs) {
|
|
37
|
+
return keepLastZUtilities(twMerge(clsx(inputs)));
|
|
38
|
+
}
|
|
39
|
+
const cx = cn;
|
|
40
|
+
import { cva } from "class-variance-authority";
|
|
41
|
+
const TEA_PREFIX = "tea";
|
|
42
|
+
function slot(...parts) {
|
|
43
|
+
return [TEA_PREFIX, ...parts].join("-");
|
|
44
|
+
}
|
|
45
|
+
function assertNever(value, message) {
|
|
46
|
+
throw new Error(message ?? `Unhandled variant: ${String(value)}`);
|
|
47
|
+
}
|
|
48
|
+
function joinClasses(...inputs) {
|
|
49
|
+
return clsx(inputs);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
TEA_PREFIX,
|
|
53
|
+
assertNever,
|
|
54
|
+
clsx,
|
|
55
|
+
cn,
|
|
56
|
+
cva,
|
|
57
|
+
cx,
|
|
58
|
+
joinClasses,
|
|
59
|
+
slot
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * TEA UI — utilities.\n *\n * The smallest package in the system, and the one with the fewest opinions.\n * Its job is to make the house style the path of least resistance: one class\n * merge, one variant author, one prefix, one exhaustive check.\n *\n * It has no React dependency and no design opinions, so anything that needs\n * either belongs elsewhere.\n */\n\nimport { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\n/**\n * The single class merge used by every TEA UI package.\n *\n * Both source projects had a `cn`, but they were not the same function: one\n * was a compiled `clsx + tailwind-merge` replacement, the other an explicit\n * composition, and HomeServerManager even had a second import path that\n * bypassed its own barrel. A component copied between projects therefore\n * changed behaviour silently. There is exactly one now, and there is exactly\n * one import path.\n *\n * TEA UI's colour, radius, shadow and type utilities come from a reset\n * Tailwind namespace, so they are not in tailwind-merge's default theme\n * vocabulary. They are registered explicitly below: without this, `bg-surface`\n * and `bg-canvas` would be treated as unrelated classes and both would reach\n * the DOM, leaving the winner to stylesheet order instead of the caller.\n */\nconst twMerge = extendTailwindMerge({\n extend: {\n classGroups: {\n \"font-size\": [\n { text: [\"label\", \"micro\", \"ui\", \"body\", \"lead\", \"title\", \"section\", \"display\", \"hero\", \"mono\"] },\n ],\n rounded: [{ rounded: [\"none\", \"pill\"] }],\n shadow: [{ shadow: [\"none\", \"raised\", \"overlay\", \"modal\", \"inset\"] }],\n },\n },\n});\n\n/**\n * The z-index scale TEA UI ships as custom utilities. Tailwind has no `z-*`\n * theme namespace, so tailwind-merge has no group to extend for it, and\n * `z-50 z-modal` would otherwise both reach the DOM with the winner decided by\n * stylesheet order. A five-line pass is cheaper than a fork of tailwind-merge.\n */\nconst Z_UTILITIES = new Set([\n \"z-base\",\n \"z-raised\",\n \"z-sticky\",\n \"z-header\",\n \"z-dropdown\",\n \"z-overlay\",\n \"z-modal\",\n \"z-popover\",\n \"z-toast\",\n \"z-tooltip\",\n \"z-max\",\n]);\n\n/** Keep only the last occurrence of each TEA z utility. */\nfunction keepLastZUtilities(merged: string): string {\n const classes = merged.split(\" \").filter(Boolean);\n const lastIndex = new Map<string, number>();\n classes.forEach((className, index) => {\n if (Z_UTILITIES.has(className)) lastIndex.set(className, index);\n });\n if (lastIndex.size < 2) return merged;\n return classes\n .filter((className, index) => !Z_UTILITIES.has(className) || lastIndex.get(className) === index)\n .join(\" \");\n}\n\nexport function cn(...inputs: ClassValue[]): string {\n return keepLastZUtilities(twMerge(clsx(inputs)));\n}\n\n/** Alias for {@link cn}, for call sites where \"compose\" reads better. */\nexport const cx = cn;\n\nexport type { ClassValue };\n\nexport { clsx };\n\n/**\n * `class-variance-authority`, re-exported from one place so variant authoring\n * is uniform across packages. cva is the only supported way to express a\n * variant surface: it keeps a component's variant space declarative and\n * greppable instead of spread across a `switch` in a render function.\n */\nexport { cva, type VariantProps } from \"class-variance-authority\";\n\n/** Every TEA UI component prefixes its `data-slot` with this. */\nexport const TEA_PREFIX = \"tea\";\n\n/**\n * Build a namespaced `data-slot` value, e.g. `slot(\"button\", \"icon\")` ->\n * `\"tea-button-icon\"`. One helper means one naming convention, and a\n * convention that a test can assert.\n */\nexport function slot(...parts: string[]): string {\n return [TEA_PREFIX, ...parts].join(\"-\");\n}\n\n/**\n * Exhaustiveness check. The audit found five independent hand-written\n * status-to-label tables per project, each disagreeing with the others; the\n * type system catches the sixth version of that the moment a new variant\n * appears without a label.\n *\n * ```ts\n * function toneOf(t: Tone): string {\n * switch (t) {\n * case \"positive\": return \"ok\";\n * // ...\n * default: return assertNever(t);\n * }\n * }\n * ```\n */\nexport function assertNever(value: never, message?: string): never {\n throw new Error(message ?? `Unhandled variant: ${String(value)}`);\n}\n\n/**\n * Join class names and drop falsy entries, without merging. Useful when\n * composing a class string that must NOT be deduplicated against a base\n * (rare — prefer {@link cn} — but needed when a caller deliberately wants two\n * `bg-*` classes to both reach the cascade).\n */\nexport function joinClasses(...inputs: ClassValue[]): string {\n return clsx(inputs);\n}\n"],"mappings":"AAWA,SAAS,YAA6B;AACtC,SAAS,2BAA2B;AAkBpC,MAAM,UAAU,oBAAoB;AAAA,E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;AAQO,SAAS,eAAe,QAA8B;AAC3D,SAAO,KAAK,MAAM;AACpB;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tea-ui/utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared types, class-name composition and small helpers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup && node ../../scripts/fix-esm-extensions.mjs utils",
|
|
28
|
+
"prepublishOnly": "node ../../scripts/prepublish-guard.mjs"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"class-variance-authority": "^0.7.1",
|
|
32
|
+
"clsx": "^2.1.1",
|
|
33
|
+
"tailwind-merge": "^3.3.1"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"react",
|
|
37
|
+
"typescript",
|
|
38
|
+
"cn",
|
|
39
|
+
"clsx",
|
|
40
|
+
"utility",
|
|
41
|
+
"tea-ui",
|
|
42
|
+
"design-system"
|
|
43
|
+
],
|
|
44
|
+
"author": "landnevermore",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/landnevermore/TEAui.git",
|
|
48
|
+
"directory": "packages/utils"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://landnevermore.github.io/TEAui/docs/",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/landnevermore/TEAui/issues"
|
|
53
|
+
}
|
|
54
|
+
}
|