@osiris-smarttv/style-util 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OsirisTech SmartTV
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,80 @@
1
+ # @osiris-smarttv/style-util
2
+
3
+ Layered `className` composition utility for Smart TV UI codebases.
4
+
5
+ Combines:
6
+
7
+ - Tailwind utility classes
8
+ - design-token-aware atomic classes
9
+ - CSS module classes
10
+ - caller `className` overrides
11
+
12
+ with deterministic merge order and `tailwind-merge` conflict resolution.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm i @osiris-smarttv/style-util
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { cn } from '@osiris-smarttv/style-util'
24
+
25
+ const className = cn({
26
+ tw: ['flex', 'items-center', 'px-4'],
27
+ s: [styles.container, isActive && styles.active],
28
+ className: props.className,
29
+ })
30
+ ```
31
+
32
+ ## API
33
+
34
+ - `cn(input)` - default combiner
35
+ - `createCn()` - build custom combiner
36
+ - `createCnForTokens()` - token-typed combiner factory
37
+
38
+ Key exported types:
39
+
40
+ - `CnInput`
41
+ - `TwClass`
42
+ - `AtomicClass`
43
+ - `ModuleClass`
44
+ - `DesignToken`
45
+ - `DesignTokenValue`
46
+
47
+ ## Merge behavior
48
+
49
+ Layer precedence is explicit and stable:
50
+
51
+ 1. `tw`
52
+ 2. `atomic`
53
+ 3. `s`
54
+ 4. `className`
55
+
56
+ `tailwind-merge` runs on Tailwind-like layers to drop conflicting utilities.
57
+ Module classes are preserved.
58
+
59
+ ## Local development
60
+
61
+ ```bash
62
+ yarn install
63
+ yarn build
64
+ yarn typecheck
65
+ yarn test
66
+ ```
67
+
68
+ ## Manual publish (no GitHub Actions)
69
+
70
+ ```bash
71
+ yarn publish:check
72
+ yarn publish:dry-run
73
+ yarn publish:manual
74
+ ```
75
+
76
+ If publish returns `404` or permission errors for `@osiris-smarttv/*`, verify:
77
+
78
+ - your npm account has publish access to scope `@osiris-smarttv`
79
+ - package name is allowed by org policy
80
+ - you are authenticated against `https://registry.npmjs.org/`
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Augment in the host app to narrow default `atomic` tokens (when using `cn()` without a wrapper).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * declare module '@osiris-smarttv/style-util' {
7
+ * interface DesignTokenRegistry {
8
+ * 'ds-bg-surface': true
9
+ * }
10
+ * }
11
+ * ```
12
+ */
13
+ interface DesignTokenRegistry {
14
+ }
15
+ type RegistryTokenKey = keyof DesignTokenRegistry;
16
+ /** Resolved token id from {@link DesignTokenRegistry}. Falls back to `string` when empty. */
17
+ type RegisteredDesignToken = RegistryTokenKey extends never ? string : RegistryTokenKey & string;
18
+ /** One allowed value in the `atomic` array (token id + clsx falsy). */
19
+ type AtomicClass = string | false | null | undefined;
20
+ /** Tailwind utility class — structural frame. */
21
+ type TwClass = AtomicClass;
22
+ /** SCSS module resolved class name. */
23
+ type ModuleClass = AtomicClass;
24
+ /** Token id `T` plus optional falsy entries (for `atomic: [id, condition && id]`). */
25
+ type DesignTokenValue<T extends string = string> = T | false | null | undefined;
26
+ /** @deprecated Prefer {@link DesignTokenValue}. */
27
+ type DesignToken<T extends string = RegisteredDesignToken> = DesignTokenValue<T>;
28
+ /**
29
+ * `CnInput` generic = type of **each `atomic` entry**, not the token registry itself.
30
+ *
31
+ * @example App wrapper (wide open)
32
+ * ```ts
33
+ * type DesignToken = string | false | null | undefined
34
+ * const cn = (input: CnInput<DesignToken>) => cnLib(input)
35
+ * ```
36
+ *
37
+ * @example App wrapper (narrow ids)
38
+ * ```ts
39
+ * type FgnToken = DesignTokenValue<'ds-bg' | 'ds-text'>
40
+ * const cn = (input: CnInput<FgnToken>) => cnLib(input)
41
+ * ```
42
+ */
43
+ type CnInput<TAtomic extends AtomicClass = DesignTokenValue<RegisteredDesignToken>> = {
44
+ tw?: TwClass[];
45
+ atomic?: TAtomic[];
46
+ s?: ModuleClass[];
47
+ className?: string | string[];
48
+ };
49
+ declare function cn<TAtomic extends AtomicClass = DesignTokenValue<RegisteredDesignToken>>(input: CnInput<TAtomic>): string;
50
+ /** Pin the `atomic` element type (e.g. `DesignTokenValue<'lib-a' | 'lib-b'>`). */
51
+ declare function createCn<TAtomic extends AtomicClass = DesignTokenValue<RegisteredDesignToken>>(): (input: CnInput<TAtomic>) => string;
52
+ /** Pin allowed token **ids**; falsy entries still allowed in `atomic`. */
53
+ declare function createCnForTokens<TTokenId extends string>(): (input: CnInput<DesignTokenValue<TTokenId>>) => string;
54
+
55
+ export { type AtomicClass, type CnInput, type DesignToken, type DesignTokenRegistry, type DesignTokenValue, type ModuleClass, type RegisteredDesignToken, type TwClass, cn, createCn, createCnForTokens };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import e from'clsx';import {twMerge}from'tailwind-merge';function n(t){let{tw:o,atomic:i,s:r,className:g}=t;return twMerge(e(o),e(i),e(r),e(g))}function s(){return t=>n(t)}function p(){return s()}export{n as cn,s as createCn,p as createCnForTokens};
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@osiris-smarttv/style-util",
3
+ "version": "0.1.0",
4
+ "description": "Layered className merge (Tailwind + design tokens + SCSS modules) for Smart TV UI",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/OsirisTech-SmartTV/style-util.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/OsirisTech-SmartTV/style-util/issues"
13
+ },
14
+ "homepage": "https://github.com/OsirisTech-SmartTV/style-util#readme",
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "sideEffects": false,
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "dependencies": {
35
+ "clsx": "^2.1.1",
36
+ "tailwind-merge": "^3.6.0"
37
+ },
38
+ "devDependencies": {
39
+ "tsup": "^8.5.0",
40
+ "typescript": "~6.0.2",
41
+ "vitest": "^4.1.4"
42
+ },
43
+ "scripts": {
44
+ "clean": "node scripts/clean.mjs",
45
+ "build": "tsup",
46
+ "dev": "tsup --watch",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "verify": "yarn typecheck && yarn test",
51
+ "publish:check": "yarn clean && yarn build && yarn verify && npm pack --dry-run",
52
+ "publish:dry-run": "npm publish --dry-run --access public",
53
+ "publish:manual": "npm publish --access public",
54
+ "prepublishOnly": "yarn clean && yarn build && yarn verify"
55
+ }
56
+ }