@tuwaio/nova-core 0.0.1

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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 FOP Tkach Oleksandr
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # TUWA Nova Core
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@tuwaio/nova-core.svg)](https://www.npmjs.com/package/@tuwaio/nova-core)
4
+ [![License](https://img.shields.io/npm/l/@tuwaio/nova-core.svg)](./LICENSE)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/TuwaIO/nova-uikit/main.yml?branch=main)](https://github.com/TuwaIO/nova-uikit/actions)
6
+
7
+ The foundational package for the TUWA design system. Provides core styling primitives, theme variables, and common React hooks and utilities.
8
+
9
+ ## What is `@tuwaio/nova-core`?
10
+
11
+ `@tuwaio/nova-core` is the engine of the TUWA design system. It is **not** a component library. Instead, it provides the low-level tools necessary to build consistent, high-quality user interfaces across all TUWA products.
12
+
13
+ Use this package to:
14
+ - Ensure brand consistency with a centralized theme and styling.
15
+ - Speed up development with a set of battle-tested helper hooks and utilities.
16
+ - Provide a solid foundation for our component library, `@tuwaio/nova-react`.
17
+
18
+ ## Core Features
19
+
20
+ - **🎨 Styling Primitives:** A single CSS file containing all TUWA design tokens as CSS variables (e.g., `--tuwa-color-primary`).
21
+ - **🛠️ Helper Utilities:** A smart `cn` utility that combines `clsx` and `tailwind-merge` for building dynamic and conflict-free class names.
22
+ - **🎣 Common Hooks:** A collection of generic, reusable React hooks for common tasks.
23
+
24
+ ## Installation
25
+
26
+ 1. Install the package using your preferred package manager:
27
+
28
+ ```bash
29
+ pnpm add @tuwaio/nova-core
30
+ ```
31
+
32
+ 2. **Import the core styles** into the root of your application's main CSS file (e.g., `globals.css`). **This step is crucial.**
33
+
34
+ ```css
35
+ @import "tailwindcss";
36
+ @import '@tuwaio/nova-core/dist/index.css';
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ You can use the provided styles in two ways: directly with CSS variables (basic) or by integrating them into your theme (recommended).
42
+
43
+ ### Basic Usage (Without `tailwind.config.js`)
44
+
45
+ With Tailwind CSS v4, you can use the CSS variables from this package directly in your className as arbitrary values. A `tailwind.config.js` file is not required for this to work.
46
+
47
+ ```tsx
48
+ // You can use the variables directly
49
+ <button className="bg-[var(--tuwa-color-primary)] text-[var(--tuwa-color-foreground)] p-[var(--tuwa-spacing-md)]">
50
+ Click Me
51
+ </button>
52
+ ```
53
+
54
+ ### Recommended Usage (Theming with `tailwind.config.js`)
55
+
56
+ While a config file is optional in Tailwind v4, creating one to map our CSS variables to Tailwind's theme allows you to use clean, semantic class names. This is the recommended approach for building a consistent design system.
57
+
58
+ **1. Create or update your `tailwind.config.js`:**
59
+
60
+ ```js
61
+ // tailwind.config.js
62
+ /** @type {import('tailwindcss').Config} */
63
+ export default {
64
+ content: [
65
+ './src/**/*.{js,ts,jsx,tsx}',
66
+ ],
67
+ theme: {
68
+ extend: {
69
+ colors: {
70
+ primary: 'var(--tuwa-color-primary)',
71
+ secondary: 'var(--tuwa-color-secondary)',
72
+ background: 'var(--tuwa-color-background)',
73
+ foreground: 'var(--tuwa-color-foreground)',
74
+ },
75
+ // ... etc.
76
+ },
77
+ },
78
+ plugins: [],
79
+ };
80
+ ```
81
+
82
+ **2. Use semantic class names in your components:**
83
+
84
+ Now your code becomes much cleaner and easier to read.
85
+
86
+ ```tsx
87
+ import { cn } from '@tuwaio/nova-core';
88
+
89
+ export function Button({ intent, className, ...props }) {
90
+ const buttonClasses = cn(
91
+ 'px-4 py-2 rounded-md font-semibold transition-colors',
92
+ {
93
+ 'bg-primary text-white hover:opacity-90': intent === 'primary',
94
+ 'bg-secondary text-foreground hover:opacity-90': intent === 'secondary',
95
+ },
96
+ className,
97
+ );
98
+
99
+ return <button className={buttonClasses} {...props} />;
100
+ }
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
106
+
107
+ ## License
108
+
109
+ This project is licensed under the **Apache-2.0 License**.
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge');function g(r=2e3){let[o,e]=react.useState(false),[t,n]=react.useState(null),s=react.useCallback(async c=>{if(c)try{await navigator.clipboard.writeText(c),e(!0),n(null),setTimeout(()=>e(!1),r);}catch(l){let a=l instanceof Error?l:new Error("Failed to copy text.");console.error(a),n(a),setTimeout(()=>n(null),r);}},[r]);return {isCopied:o,copy:s,error:t}}function C(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var i=r=>r&&typeof r=="object"&&!Array.isArray(r);function y(r,o){let e={...r};return i(r)&&i(o)&&Object.keys(o).forEach(t=>{let n=r[t],s=o[t];i(n)&&i(s)?e[t]=y(n,s):e[t]=s;}),e}function j(r,o,e){if(!r)return "";if(r.length<=o+e)return r;let t=r.slice(0,o),n=r.slice(r.length-e);return `${t}...${n}`}exports.cn=C;exports.deepMerge=y;exports.textCenterEllipsis=j;exports.useCopyToClipboard=g;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useCopyToClipboard.ts","../src/utils/cn.ts","../src/utils/deepMerge.ts","../src/utils/textCenterEllipsis.ts"],"names":["useCopyToClipboard","timeout","isCopied","setIsCopied","useState","error","setError","copy","useCallback","text","e","copyError","cn","inputs","twMerge","clsx","isObject","item","deepMerge","target","source","output","key","targetValue","sourceValue","textCenterEllipsis","str","from","to","start","end"],"mappings":"qGA6BO,SAASA,CAAAA,CAAmBC,CAAAA,CAAU,GAAA,CAI3C,CACA,GAAM,CAACC,CAAAA,CAAUC,CAAW,CAAA,CAAIC,cAAAA,CAAS,KAAK,CAAA,CACxC,CAACC,CAAAA,CAAOC,CAAQ,CAAA,CAAIF,cAAAA,CAAuB,IAAI,CAAA,CAE/CG,EAAOC,iBAAAA,CACX,MAAOC,CAAAA,EAAiB,CACtB,GAAKA,CAAAA,CAEL,GAAI,CACF,MAAM,SAAA,CAAU,SAAA,CAAU,SAAA,CAAUA,CAAI,EACxCN,CAAAA,CAAY,CAAA,CAAI,CAAA,CAChBG,CAAAA,CAAS,IAAI,CAAA,CAEb,WAAW,IAAMH,CAAAA,CAAY,CAAA,CAAK,CAAA,CAAGF,CAAO,EAC9C,OAASS,CAAAA,CAAG,CACV,IAAMC,CAAAA,CAAYD,CAAAA,YAAa,KAAA,CAAQA,EAAI,IAAI,KAAA,CAAM,sBAAsB,CAAA,CAC3E,OAAA,CAAQ,KAAA,CAAMC,CAAS,CAAA,CACvBL,CAAAA,CAASK,CAAS,CAAA,CAGlB,UAAA,CAAW,IAAML,EAAS,IAAI,CAAA,CAAGL,CAAO,EAC1C,CACF,CAAA,CACA,CAACA,CAAO,CACV,CAAA,CAEA,OAAO,CAAE,QAAA,CAAAC,EAAU,IAAA,CAAAK,CAAAA,CAAM,KAAA,CAAAF,CAAM,CACjC,CCpCO,SAASO,CAAAA,CAAAA,GAAMC,CAAAA,CAA8B,CAClD,OAAOC,qBAAAA,CAAQC,UAAKF,CAAM,CAAC,CAC7B,CChBA,IAAMG,EAAYC,CAAAA,EACTA,CAAAA,EAAQ,OAAOA,CAAAA,EAAS,QAAA,EAAY,CAAC,MAAM,OAAA,CAAQA,CAAI,CAAA,CAkBzD,SAASC,CAAAA,CAA4BC,CAAAA,CAAWC,EAAuB,CAE5E,IAAMC,CAAAA,CAAS,CAAE,GAAGF,CAAO,EAE3B,OAAIH,CAAAA,CAASG,CAAM,CAAA,EAAKH,CAAAA,CAASI,CAAM,GAErC,MAAA,CAAO,IAAA,CAAKA,CAAM,CAAA,CAAE,OAAA,CAASE,CAAAA,EAAQ,CACnC,IAAMC,CAAAA,CAAcJ,CAAAA,CAAOG,CAAc,CAAA,CACnCE,CAAAA,CAAcJ,EAAOE,CAAc,CAAA,CAGrCN,CAAAA,CAASO,CAAW,CAAA,EAAKP,CAAAA,CAASQ,CAAW,CAAA,CAG9CH,CAAAA,CAA+BC,CAAG,CAAA,CAAIJ,CAAAA,CAAUK,CAAAA,CAAaC,CAAW,CAAA,CAGxEH,CAAAA,CAA+BC,CAAG,CAAA,CAAIE,EAE3C,CAAC,EAGIH,CACT,CCjCO,SAASI,CAAAA,CAAmBC,CAAAA,CAAgCC,CAAAA,CAAcC,EAAoB,CACnG,GAAI,CAACF,CAAAA,CACH,OAAO,EAAA,CAIT,GAAIA,CAAAA,CAAI,MAAA,EAAUC,CAAAA,CAAOC,CAAAA,CACvB,OAAOF,CAAAA,CAGT,IAAMG,CAAAA,CAAQH,CAAAA,CAAI,KAAA,CAAM,CAAA,CAAGC,CAAI,CAAA,CACzBG,EAAMJ,CAAAA,CAAI,KAAA,CAAMA,CAAAA,CAAI,MAAA,CAASE,CAAE,CAAA,CAErC,OAAO,CAAA,EAAGC,CAAK,CAAA,GAAA,EAAMC,CAAG,CAAA,CAC1B","file":"index.cjs","sourcesContent":["/**\n * @file This file contains a custom React hook for copying text to the clipboard.\n */\n\nimport { useCallback, useState } from 'react';\n\n/**\n * A custom React hook that provides functionality to copy text to the clipboard.\n * It also manages a \"copied\" state with a timeout for user feedback.\n *\n * @param {number} [timeout=2000] - The duration in milliseconds to keep the `isCopied` state as true.\n * @returns {{\n * isCopied: boolean;\n * copy: (text: string) => Promise<void>;\n * error: Error | null;\n * }} An object containing the `isCopied` state, the `copy` function, and any potential error.\n *\n * @example\n * const MyComponent = () => {\n * const { isCopied, copy } = useCopyToClipboard();\n * const textToCopy = '0x123...';\n *\n * return (\n * <button onClick={() => copy(textToCopy)}>\n * {isCopied ? 'Copied!' : 'Copy Address'}\n * </button>\n * );\n * }\n */\nexport function useCopyToClipboard(timeout = 2000): {\n isCopied: boolean;\n copy: (text: string) => Promise<void>;\n error: Error | null;\n} {\n const [isCopied, setIsCopied] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const copy = useCallback(\n async (text: string) => {\n if (!text) return;\n\n try {\n await navigator.clipboard.writeText(text);\n setIsCopied(true);\n setError(null);\n\n setTimeout(() => setIsCopied(false), timeout);\n } catch (e) {\n const copyError = e instanceof Error ? e : new Error('Failed to copy text.');\n console.error(copyError);\n setError(copyError);\n\n // Reset error state after timeout as well\n setTimeout(() => setError(null), timeout);\n }\n },\n [timeout],\n );\n\n return { isCopied, copy, error };\n}\n","/**\n * @file This file contains a utility function for conditionally merging Tailwind CSS classes.\n */\n\nimport { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function to conditionally join class names together and resolve\n * conflicting Tailwind CSS classes.\n *\n * It combines the functionality of `clsx` and `tailwind-merge`.\n *\n * @param {...ClassValue[]} inputs - A list of class values to be combined.\n * This can include strings, numbers, objects, arrays, and booleans.\n * @returns {string} The final, merged class name string.\n *\n * @example\n * cn('p-4', 'bg-red-500', { 'font-bold': true }); // => 'p-4 bg-red-500 font-bold'\n * cn('p-2', 'p-4'); // => 'p-4' (tailwind-merge resolves the conflict)\n *\n * @see https://github.com/dcastil/tailwind-merge\n * @see https://github.com/lukeed/clsx\n */\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","/**\n * @file This file contains a utility for performing a deep (recursive) merge of two objects.\n */\n\n/**\n * Checks if the provided item is a plain object (i.e., not null and not an array).\n *\n * @param {any} item - The item to check.\n * @returns {item is Record<string, any>} True if the item is a plain object, otherwise false.\n */\nconst isObject = (item: any): item is Record<string, any> => {\n return item && typeof item === 'object' && !Array.isArray(item);\n};\n\n/**\n * Recursively merges the properties of a source object into a target object.\n * This function creates a new object and does not mutate the original target.\n *\n * @template T - The type of the objects being merged.\n * @param {T} target - The base object.\n * @param {Partial<T>} source - The object with properties to merge into the target.\n * @returns {T} A new object representing the merged result.\n *\n * @example\n * const defaults = { a: 1, b: { c: 2, d: 3 } };\n * const custom = { b: { c: 99 } };\n * const result = deepMerge(defaults, custom);\n * // result will be { a: 1, b: { c: 99, d: 3 } }\n */\nexport function deepMerge<T extends object>(target: T, source: Partial<T>): T {\n // Start with a shallow copy of the target to avoid mutation.\n const output = { ...target };\n\n if (isObject(target) && isObject(source)) {\n // Iterate over the keys in the source object.\n Object.keys(source).forEach((key) => {\n const targetValue = target[key as keyof T];\n const sourceValue = source[key as keyof T];\n\n // If the value is an object in both target and source, merge them recursively.\n if (isObject(targetValue) && isObject(sourceValue)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n (output as Record<string, any>)[key] = deepMerge(targetValue, sourceValue);\n } else {\n // Otherwise, the source value overwrites the target value.\n (output as Record<string, any>)[key] = sourceValue;\n }\n });\n }\n\n return output;\n}\n","/**\n * @file This file contains a utility function for truncating a string with a center ellipsis.\n */\n\n/**\n * Truncates a string by showing a specified number of characters from the start and end,\n * with an ellipsis in the middle. If the string is too short to be truncated, it's returned as is.\n *\n * @param {string} str - The string to truncate.\n * @param {number} from - The number of characters to show from the beginning of the string.\n * @param {number} to - The number of characters to show from the end of the string.\n * @returns {string} The truncated string, or the original string if it's too short.\n *\n * @example\n * const hash = '0x1234567890abcdef1234567890abcdef';\n * textCenterEllipsis(hash, 6, 4); // => \"0x1234...cdef\"\n *\n * textCenterEllipsis('short', 6, 4); // => \"short\"\n */\nexport function textCenterEllipsis(str: string | undefined | null, from: number, to: number): string {\n if (!str) {\n return '';\n }\n\n // If the string is short enough, don't truncate it.\n if (str.length <= from + to) {\n return str;\n }\n\n const start = str.slice(0, from);\n const end = str.slice(str.length - to);\n\n return `${start}...${end}`;\n}\n"]}
package/dist/index.css ADDED
@@ -0,0 +1,309 @@
1
+ /*! tailwindcss v4.1.12 | MIT License | https://tailwindcss.com */
2
+ @layer properties;
3
+ @layer theme, base, components, utilities;
4
+ @layer theme {
5
+ :root, :host {
6
+ --font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
7
+ "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
8
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
9
+ "Courier New", monospace;
10
+ --color-red-500: oklch(63.7% 0.237 25.331);
11
+ --color-white: #fff;
12
+ --spacing: 0.25rem;
13
+ --font-weight-semibold: 600;
14
+ --font-weight-bold: 700;
15
+ --radius-md: 0.375rem;
16
+ --default-transition-duration: 150ms;
17
+ --default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
18
+ --default-font-family: var(--font-sans);
19
+ --default-mono-font-family: var(--font-mono);
20
+ }
21
+ }
22
+ @layer base {
23
+ *, ::after, ::before, ::backdrop, ::file-selector-button {
24
+ box-sizing: border-box;
25
+ margin: 0;
26
+ padding: 0;
27
+ border: 0 solid;
28
+ }
29
+ html, :host {
30
+ line-height: 1.5;
31
+ -webkit-text-size-adjust: 100%;
32
+ -moz-tab-size: 4;
33
+ -o-tab-size: 4;
34
+ tab-size: 4;
35
+ font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
36
+ font-feature-settings: var(--default-font-feature-settings, normal);
37
+ font-variation-settings: var(--default-font-variation-settings, normal);
38
+ -webkit-tap-highlight-color: transparent;
39
+ }
40
+ hr {
41
+ height: 0;
42
+ color: inherit;
43
+ border-top-width: 1px;
44
+ }
45
+ abbr:where([title]) {
46
+ -webkit-text-decoration: underline dotted;
47
+ text-decoration: underline dotted;
48
+ }
49
+ h1, h2, h3, h4, h5, h6 {
50
+ font-size: inherit;
51
+ font-weight: inherit;
52
+ }
53
+ a {
54
+ color: inherit;
55
+ -webkit-text-decoration: inherit;
56
+ text-decoration: inherit;
57
+ }
58
+ b, strong {
59
+ font-weight: bolder;
60
+ }
61
+ code, kbd, samp, pre {
62
+ font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
63
+ font-feature-settings: var(--default-mono-font-feature-settings, normal);
64
+ font-variation-settings: var(--default-mono-font-variation-settings, normal);
65
+ font-size: 1em;
66
+ }
67
+ small {
68
+ font-size: 80%;
69
+ }
70
+ sub, sup {
71
+ font-size: 75%;
72
+ line-height: 0;
73
+ position: relative;
74
+ vertical-align: baseline;
75
+ }
76
+ sub {
77
+ bottom: -0.25em;
78
+ }
79
+ sup {
80
+ top: -0.5em;
81
+ }
82
+ table {
83
+ text-indent: 0;
84
+ border-color: inherit;
85
+ border-collapse: collapse;
86
+ }
87
+ :-moz-focusring {
88
+ outline: auto;
89
+ }
90
+ progress {
91
+ vertical-align: baseline;
92
+ }
93
+ summary {
94
+ display: list-item;
95
+ }
96
+ ol, ul, menu {
97
+ list-style: none;
98
+ }
99
+ img, svg, video, canvas, audio, iframe, embed, object {
100
+ display: block;
101
+ vertical-align: middle;
102
+ }
103
+ img, video {
104
+ max-width: 100%;
105
+ height: auto;
106
+ }
107
+ button, input, select, optgroup, textarea, ::file-selector-button {
108
+ font: inherit;
109
+ font-feature-settings: inherit;
110
+ font-variation-settings: inherit;
111
+ letter-spacing: inherit;
112
+ color: inherit;
113
+ border-radius: 0;
114
+ background-color: transparent;
115
+ opacity: 1;
116
+ }
117
+ :where(select:is([multiple], [size])) optgroup {
118
+ font-weight: bolder;
119
+ }
120
+ :where(select:is([multiple], [size])) optgroup option {
121
+ padding-inline-start: 20px;
122
+ }
123
+ ::file-selector-button {
124
+ margin-inline-end: 4px;
125
+ }
126
+ ::-moz-placeholder {
127
+ opacity: 1;
128
+ }
129
+ ::placeholder {
130
+ opacity: 1;
131
+ }
132
+ @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
133
+ ::-moz-placeholder {
134
+ color: currentcolor;
135
+ @supports (color: color-mix(in lab, red, red)) {
136
+ color: color-mix(in oklab, currentcolor 50%, transparent);
137
+ }
138
+ }
139
+ ::placeholder {
140
+ color: currentcolor;
141
+ @supports (color: color-mix(in lab, red, red)) {
142
+ color: color-mix(in oklab, currentcolor 50%, transparent);
143
+ }
144
+ }
145
+ }
146
+ textarea {
147
+ resize: vertical;
148
+ }
149
+ ::-webkit-search-decoration {
150
+ -webkit-appearance: none;
151
+ }
152
+ ::-webkit-date-and-time-value {
153
+ min-height: 1lh;
154
+ text-align: inherit;
155
+ }
156
+ ::-webkit-datetime-edit {
157
+ display: inline-flex;
158
+ }
159
+ ::-webkit-datetime-edit-fields-wrapper {
160
+ padding: 0;
161
+ }
162
+ ::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
163
+ padding-block: 0;
164
+ }
165
+ ::-webkit-calendar-picker-indicator {
166
+ line-height: 1;
167
+ }
168
+ :-moz-ui-invalid {
169
+ box-shadow: none;
170
+ }
171
+ button, input:where([type="button"], [type="reset"], [type="submit"]), ::file-selector-button {
172
+ -webkit-appearance: button;
173
+ -moz-appearance: button;
174
+ appearance: button;
175
+ }
176
+ ::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
177
+ height: auto;
178
+ }
179
+ [hidden]:where(:not([hidden="until-found"])) {
180
+ display: none !important;
181
+ }
182
+ }
183
+ @layer utilities {
184
+ .contents {
185
+ display: contents;
186
+ }
187
+ .truncate {
188
+ overflow: hidden;
189
+ text-overflow: ellipsis;
190
+ white-space: nowrap;
191
+ }
192
+ .rounded-md {
193
+ border-radius: var(--radius-md);
194
+ }
195
+ .bg-\[var\(--tuwa-color-primary\)\] {
196
+ background-color: var(--tuwa-color-primary);
197
+ }
198
+ .bg-red-500 {
199
+ background-color: var(--color-red-500);
200
+ }
201
+ .p-2 {
202
+ padding: calc(var(--spacing) * 2);
203
+ }
204
+ .p-4 {
205
+ padding: calc(var(--spacing) * 4);
206
+ }
207
+ .p-\[var\(--tuwa-spacing-md\)\] {
208
+ padding: var(--tuwa-spacing-md);
209
+ }
210
+ .px-4 {
211
+ padding-inline: calc(var(--spacing) * 4);
212
+ }
213
+ .py-2 {
214
+ padding-block: calc(var(--spacing) * 2);
215
+ }
216
+ .font-bold {
217
+ --tw-font-weight: var(--font-weight-bold);
218
+ font-weight: var(--font-weight-bold);
219
+ }
220
+ .font-semibold {
221
+ --tw-font-weight: var(--font-weight-semibold);
222
+ font-weight: var(--font-weight-semibold);
223
+ }
224
+ .text-\[var\(--tuwa-color-foreground\)\] {
225
+ color: var(--tuwa-color-foreground);
226
+ }
227
+ .text-white {
228
+ color: var(--color-white);
229
+ }
230
+ .transition-colors {
231
+ transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to;
232
+ transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
233
+ transition-duration: var(--tw-duration, var(--default-transition-duration));
234
+ }
235
+ .hover\:opacity-90 {
236
+ &:hover {
237
+ @media (hover: hover) {
238
+ opacity: 90%;
239
+ }
240
+ }
241
+ }
242
+ }
243
+ :root {
244
+ --tuwa-success-bg: oklch(96.2% 0.044 156.743);
245
+ --tuwa-success-text: oklch(52.7% 0.154 150.069);
246
+ --tuwa-success-icon: oklch(72.3% 0.219 149.579);
247
+ --tuwa-error-bg: oklch(93.6% 0.032 17.717);
248
+ --tuwa-error-text: oklch(50.5% 0.213 27.518);
249
+ --tuwa-error-icon: oklch(63.7% 0.237 25.331);
250
+ --tuwa-pending-bg: oklch(97.3% 0.071 103.193);
251
+ --tuwa-pending-text: oklch(47.6% 0.114 61.907);
252
+ --tuwa-pending-icon: oklch(68.1% 0.162 75.834);
253
+ --tuwa-info-bg: oklch(96.7% 0.003 264.542);
254
+ --tuwa-info-text: oklch(44.6% 0.03 256.802);
255
+ --tuwa-info-icon: oklch(55.1% 0.027 264.364);
256
+ --tuwa-text-primary: oklch(21% 0.034 264.665);
257
+ --tuwa-text-secondary: oklch(55.1% 0.027 264.364);
258
+ --tuwa-text-tertiary: oklch(70.7% 0.022 261.325);
259
+ --tuwa-text-accent: oklch(54.6% 0.245 262.881);
260
+ --tuwa-text-on-accent: #fff;
261
+ --tuwa-bg-primary: #fff;
262
+ --tuwa-bg-secondary: oklch(98.5% 0.002 247.839);
263
+ --tuwa-bg-muted: oklch(96.7% 0.003 264.542);
264
+ --tuwa-border-primary: oklch(92.8% 0.006 264.531);
265
+ --tuwa-border-secondary: oklch(96.7% 0.003 264.542);
266
+ --tuwa-button-gradient-from: oklch(54.6% 0.245 262.881);
267
+ --tuwa-button-gradient-to: oklch(55.8% 0.288 302.321);
268
+ --tuwa-button-gradient-from-hover: oklch(48.8% 0.243 264.376);
269
+ --tuwa-button-gradient-to-hover: oklch(49.6% 0.265 301.924);
270
+ }
271
+ .dark {
272
+ --tuwa-success-bg: oklch(39.3% 0.095 152.535);
273
+ --tuwa-success-text: oklch(87.1% 0.15 154.449);
274
+ --tuwa-success-icon: oklch(79.2% 0.209 151.711);
275
+ --tuwa-error-bg: oklch(39.6% 0.141 25.723);
276
+ --tuwa-error-text: oklch(80.8% 0.114 19.571);
277
+ --tuwa-error-icon: oklch(70.4% 0.191 22.216);
278
+ --tuwa-pending-bg: oklch(42.1% 0.095 57.708);
279
+ --tuwa-pending-text: oklch(90.5% 0.182 98.111);
280
+ --tuwa-pending-icon: oklch(85.2% 0.199 91.936);
281
+ --tuwa-info-bg: oklch(37.3% 0.034 259.733);
282
+ --tuwa-info-text: oklch(87.2% 0.01 258.338);
283
+ --tuwa-info-icon: oklch(70.7% 0.022 261.325);
284
+ --tuwa-text-primary: oklch(98.5% 0.002 247.839);
285
+ --tuwa-text-secondary: oklch(70.7% 0.022 261.325);
286
+ --tuwa-text-tertiary: oklch(55.1% 0.027 264.364);
287
+ --tuwa-text-accent: oklch(70.7% 0.165 254.624);
288
+ --tuwa-text-on-accent: #fff;
289
+ --tuwa-bg-primary: oklch(21% 0.034 264.665);
290
+ --tuwa-bg-secondary: oklch(27.8% 0.033 256.848);
291
+ --tuwa-bg-muted: oklch(37.3% 0.034 259.733);
292
+ --tuwa-border-primary: oklch(37.3% 0.034 259.733);
293
+ --tuwa-border-secondary: oklch(27.8% 0.033 256.848);
294
+ --tuwa-button-gradient-from: oklch(62.3% 0.214 259.815);
295
+ --tuwa-button-gradient-to: oklch(62.7% 0.265 303.9);
296
+ --tuwa-button-gradient-from-hover: oklch(54.6% 0.245 262.881);
297
+ --tuwa-button-gradient-to-hover: oklch(55.8% 0.288 302.321);
298
+ }
299
+ @property --tw-font-weight {
300
+ syntax: "*";
301
+ inherits: false;
302
+ }
303
+ @layer properties {
304
+ @supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
305
+ *, ::before, ::after, ::backdrop {
306
+ --tw-font-weight: initial;
307
+ }
308
+ }
309
+ }
@@ -0,0 +1,98 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ /**
4
+ * @file This file contains a custom React hook for copying text to the clipboard.
5
+ */
6
+ /**
7
+ * A custom React hook that provides functionality to copy text to the clipboard.
8
+ * It also manages a "copied" state with a timeout for user feedback.
9
+ *
10
+ * @param {number} [timeout=2000] - The duration in milliseconds to keep the `isCopied` state as true.
11
+ * @returns {{
12
+ * isCopied: boolean;
13
+ * copy: (text: string) => Promise<void>;
14
+ * error: Error | null;
15
+ * }} An object containing the `isCopied` state, the `copy` function, and any potential error.
16
+ *
17
+ * @example
18
+ * const MyComponent = () => {
19
+ * const { isCopied, copy } = useCopyToClipboard();
20
+ * const textToCopy = '0x123...';
21
+ *
22
+ * return (
23
+ * <button onClick={() => copy(textToCopy)}>
24
+ * {isCopied ? 'Copied!' : 'Copy Address'}
25
+ * </button>
26
+ * );
27
+ * }
28
+ */
29
+ declare function useCopyToClipboard(timeout?: number): {
30
+ isCopied: boolean;
31
+ copy: (text: string) => Promise<void>;
32
+ error: Error | null;
33
+ };
34
+
35
+ /**
36
+ * @file This file contains a utility function for conditionally merging Tailwind CSS classes.
37
+ */
38
+
39
+ /**
40
+ * A utility function to conditionally join class names together and resolve
41
+ * conflicting Tailwind CSS classes.
42
+ *
43
+ * It combines the functionality of `clsx` and `tailwind-merge`.
44
+ *
45
+ * @param {...ClassValue[]} inputs - A list of class values to be combined.
46
+ * This can include strings, numbers, objects, arrays, and booleans.
47
+ * @returns {string} The final, merged class name string.
48
+ *
49
+ * @example
50
+ * cn('p-4', 'bg-red-500', { 'font-bold': true }); // => 'p-4 bg-red-500 font-bold'
51
+ * cn('p-2', 'p-4'); // => 'p-4' (tailwind-merge resolves the conflict)
52
+ *
53
+ * @see https://github.com/dcastil/tailwind-merge
54
+ * @see https://github.com/lukeed/clsx
55
+ */
56
+ declare function cn(...inputs: ClassValue[]): string;
57
+
58
+ /**
59
+ * @file This file contains a utility for performing a deep (recursive) merge of two objects.
60
+ */
61
+ /**
62
+ * Recursively merges the properties of a source object into a target object.
63
+ * This function creates a new object and does not mutate the original target.
64
+ *
65
+ * @template T - The type of the objects being merged.
66
+ * @param {T} target - The base object.
67
+ * @param {Partial<T>} source - The object with properties to merge into the target.
68
+ * @returns {T} A new object representing the merged result.
69
+ *
70
+ * @example
71
+ * const defaults = { a: 1, b: { c: 2, d: 3 } };
72
+ * const custom = { b: { c: 99 } };
73
+ * const result = deepMerge(defaults, custom);
74
+ * // result will be { a: 1, b: { c: 99, d: 3 } }
75
+ */
76
+ declare function deepMerge<T extends object>(target: T, source: Partial<T>): T;
77
+
78
+ /**
79
+ * @file This file contains a utility function for truncating a string with a center ellipsis.
80
+ */
81
+ /**
82
+ * Truncates a string by showing a specified number of characters from the start and end,
83
+ * with an ellipsis in the middle. If the string is too short to be truncated, it's returned as is.
84
+ *
85
+ * @param {string} str - The string to truncate.
86
+ * @param {number} from - The number of characters to show from the beginning of the string.
87
+ * @param {number} to - The number of characters to show from the end of the string.
88
+ * @returns {string} The truncated string, or the original string if it's too short.
89
+ *
90
+ * @example
91
+ * const hash = '0x1234567890abcdef1234567890abcdef';
92
+ * textCenterEllipsis(hash, 6, 4); // => "0x1234...cdef"
93
+ *
94
+ * textCenterEllipsis('short', 6, 4); // => "short"
95
+ */
96
+ declare function textCenterEllipsis(str: string | undefined | null, from: number, to: number): string;
97
+
98
+ export { cn, deepMerge, textCenterEllipsis, useCopyToClipboard };
@@ -0,0 +1,98 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ /**
4
+ * @file This file contains a custom React hook for copying text to the clipboard.
5
+ */
6
+ /**
7
+ * A custom React hook that provides functionality to copy text to the clipboard.
8
+ * It also manages a "copied" state with a timeout for user feedback.
9
+ *
10
+ * @param {number} [timeout=2000] - The duration in milliseconds to keep the `isCopied` state as true.
11
+ * @returns {{
12
+ * isCopied: boolean;
13
+ * copy: (text: string) => Promise<void>;
14
+ * error: Error | null;
15
+ * }} An object containing the `isCopied` state, the `copy` function, and any potential error.
16
+ *
17
+ * @example
18
+ * const MyComponent = () => {
19
+ * const { isCopied, copy } = useCopyToClipboard();
20
+ * const textToCopy = '0x123...';
21
+ *
22
+ * return (
23
+ * <button onClick={() => copy(textToCopy)}>
24
+ * {isCopied ? 'Copied!' : 'Copy Address'}
25
+ * </button>
26
+ * );
27
+ * }
28
+ */
29
+ declare function useCopyToClipboard(timeout?: number): {
30
+ isCopied: boolean;
31
+ copy: (text: string) => Promise<void>;
32
+ error: Error | null;
33
+ };
34
+
35
+ /**
36
+ * @file This file contains a utility function for conditionally merging Tailwind CSS classes.
37
+ */
38
+
39
+ /**
40
+ * A utility function to conditionally join class names together and resolve
41
+ * conflicting Tailwind CSS classes.
42
+ *
43
+ * It combines the functionality of `clsx` and `tailwind-merge`.
44
+ *
45
+ * @param {...ClassValue[]} inputs - A list of class values to be combined.
46
+ * This can include strings, numbers, objects, arrays, and booleans.
47
+ * @returns {string} The final, merged class name string.
48
+ *
49
+ * @example
50
+ * cn('p-4', 'bg-red-500', { 'font-bold': true }); // => 'p-4 bg-red-500 font-bold'
51
+ * cn('p-2', 'p-4'); // => 'p-4' (tailwind-merge resolves the conflict)
52
+ *
53
+ * @see https://github.com/dcastil/tailwind-merge
54
+ * @see https://github.com/lukeed/clsx
55
+ */
56
+ declare function cn(...inputs: ClassValue[]): string;
57
+
58
+ /**
59
+ * @file This file contains a utility for performing a deep (recursive) merge of two objects.
60
+ */
61
+ /**
62
+ * Recursively merges the properties of a source object into a target object.
63
+ * This function creates a new object and does not mutate the original target.
64
+ *
65
+ * @template T - The type of the objects being merged.
66
+ * @param {T} target - The base object.
67
+ * @param {Partial<T>} source - The object with properties to merge into the target.
68
+ * @returns {T} A new object representing the merged result.
69
+ *
70
+ * @example
71
+ * const defaults = { a: 1, b: { c: 2, d: 3 } };
72
+ * const custom = { b: { c: 99 } };
73
+ * const result = deepMerge(defaults, custom);
74
+ * // result will be { a: 1, b: { c: 99, d: 3 } }
75
+ */
76
+ declare function deepMerge<T extends object>(target: T, source: Partial<T>): T;
77
+
78
+ /**
79
+ * @file This file contains a utility function for truncating a string with a center ellipsis.
80
+ */
81
+ /**
82
+ * Truncates a string by showing a specified number of characters from the start and end,
83
+ * with an ellipsis in the middle. If the string is too short to be truncated, it's returned as is.
84
+ *
85
+ * @param {string} str - The string to truncate.
86
+ * @param {number} from - The number of characters to show from the beginning of the string.
87
+ * @param {number} to - The number of characters to show from the end of the string.
88
+ * @returns {string} The truncated string, or the original string if it's too short.
89
+ *
90
+ * @example
91
+ * const hash = '0x1234567890abcdef1234567890abcdef';
92
+ * textCenterEllipsis(hash, 6, 4); // => "0x1234...cdef"
93
+ *
94
+ * textCenterEllipsis('short', 6, 4); // => "short"
95
+ */
96
+ declare function textCenterEllipsis(str: string | undefined | null, from: number, to: number): string;
97
+
98
+ export { cn, deepMerge, textCenterEllipsis, useCopyToClipboard };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {useState,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';function g(r=2e3){let[o,e]=useState(false),[t,n]=useState(null),s=useCallback(async c=>{if(c)try{await navigator.clipboard.writeText(c),e(!0),n(null),setTimeout(()=>e(!1),r);}catch(l){let a=l instanceof Error?l:new Error("Failed to copy text.");console.error(a),n(a),setTimeout(()=>n(null),r);}},[r]);return {isCopied:o,copy:s,error:t}}function C(...r){return twMerge(clsx(r))}var i=r=>r&&typeof r=="object"&&!Array.isArray(r);function y(r,o){let e={...r};return i(r)&&i(o)&&Object.keys(o).forEach(t=>{let n=r[t],s=o[t];i(n)&&i(s)?e[t]=y(n,s):e[t]=s;}),e}function j(r,o,e){if(!r)return "";if(r.length<=o+e)return r;let t=r.slice(0,o),n=r.slice(r.length-e);return `${t}...${n}`}export{C as cn,y as deepMerge,j as textCenterEllipsis,g as useCopyToClipboard};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useCopyToClipboard.ts","../src/utils/cn.ts","../src/utils/deepMerge.ts","../src/utils/textCenterEllipsis.ts"],"names":["useCopyToClipboard","timeout","isCopied","setIsCopied","useState","error","setError","copy","useCallback","text","e","copyError","cn","inputs","twMerge","clsx","isObject","item","deepMerge","target","source","output","key","targetValue","sourceValue","textCenterEllipsis","str","from","to","start","end"],"mappings":"sGA6BO,SAASA,CAAAA,CAAmBC,CAAAA,CAAU,GAAA,CAI3C,CACA,GAAM,CAACC,CAAAA,CAAUC,CAAW,CAAA,CAAIC,QAAAA,CAAS,KAAK,CAAA,CACxC,CAACC,CAAAA,CAAOC,CAAQ,CAAA,CAAIF,QAAAA,CAAuB,IAAI,CAAA,CAE/CG,EAAOC,WAAAA,CACX,MAAOC,CAAAA,EAAiB,CACtB,GAAKA,CAAAA,CAEL,GAAI,CACF,MAAM,SAAA,CAAU,SAAA,CAAU,SAAA,CAAUA,CAAI,EACxCN,CAAAA,CAAY,CAAA,CAAI,CAAA,CAChBG,CAAAA,CAAS,IAAI,CAAA,CAEb,WAAW,IAAMH,CAAAA,CAAY,CAAA,CAAK,CAAA,CAAGF,CAAO,EAC9C,OAASS,CAAAA,CAAG,CACV,IAAMC,CAAAA,CAAYD,CAAAA,YAAa,KAAA,CAAQA,EAAI,IAAI,KAAA,CAAM,sBAAsB,CAAA,CAC3E,OAAA,CAAQ,KAAA,CAAMC,CAAS,CAAA,CACvBL,CAAAA,CAASK,CAAS,CAAA,CAGlB,UAAA,CAAW,IAAML,EAAS,IAAI,CAAA,CAAGL,CAAO,EAC1C,CACF,CAAA,CACA,CAACA,CAAO,CACV,CAAA,CAEA,OAAO,CAAE,QAAA,CAAAC,EAAU,IAAA,CAAAK,CAAAA,CAAM,KAAA,CAAAF,CAAM,CACjC,CCpCO,SAASO,CAAAA,CAAAA,GAAMC,CAAAA,CAA8B,CAClD,OAAOC,OAAAA,CAAQC,KAAKF,CAAM,CAAC,CAC7B,CChBA,IAAMG,EAAYC,CAAAA,EACTA,CAAAA,EAAQ,OAAOA,CAAAA,EAAS,QAAA,EAAY,CAAC,MAAM,OAAA,CAAQA,CAAI,CAAA,CAkBzD,SAASC,CAAAA,CAA4BC,CAAAA,CAAWC,EAAuB,CAE5E,IAAMC,CAAAA,CAAS,CAAE,GAAGF,CAAO,EAE3B,OAAIH,CAAAA,CAASG,CAAM,CAAA,EAAKH,CAAAA,CAASI,CAAM,GAErC,MAAA,CAAO,IAAA,CAAKA,CAAM,CAAA,CAAE,OAAA,CAASE,CAAAA,EAAQ,CACnC,IAAMC,CAAAA,CAAcJ,CAAAA,CAAOG,CAAc,CAAA,CACnCE,CAAAA,CAAcJ,EAAOE,CAAc,CAAA,CAGrCN,CAAAA,CAASO,CAAW,CAAA,EAAKP,CAAAA,CAASQ,CAAW,CAAA,CAG9CH,CAAAA,CAA+BC,CAAG,CAAA,CAAIJ,CAAAA,CAAUK,CAAAA,CAAaC,CAAW,CAAA,CAGxEH,CAAAA,CAA+BC,CAAG,CAAA,CAAIE,EAE3C,CAAC,EAGIH,CACT,CCjCO,SAASI,CAAAA,CAAmBC,CAAAA,CAAgCC,CAAAA,CAAcC,EAAoB,CACnG,GAAI,CAACF,CAAAA,CACH,OAAO,EAAA,CAIT,GAAIA,CAAAA,CAAI,MAAA,EAAUC,CAAAA,CAAOC,CAAAA,CACvB,OAAOF,CAAAA,CAGT,IAAMG,CAAAA,CAAQH,CAAAA,CAAI,KAAA,CAAM,CAAA,CAAGC,CAAI,CAAA,CACzBG,EAAMJ,CAAAA,CAAI,KAAA,CAAMA,CAAAA,CAAI,MAAA,CAASE,CAAE,CAAA,CAErC,OAAO,CAAA,EAAGC,CAAK,CAAA,GAAA,EAAMC,CAAG,CAAA,CAC1B","file":"index.js","sourcesContent":["/**\n * @file This file contains a custom React hook for copying text to the clipboard.\n */\n\nimport { useCallback, useState } from 'react';\n\n/**\n * A custom React hook that provides functionality to copy text to the clipboard.\n * It also manages a \"copied\" state with a timeout for user feedback.\n *\n * @param {number} [timeout=2000] - The duration in milliseconds to keep the `isCopied` state as true.\n * @returns {{\n * isCopied: boolean;\n * copy: (text: string) => Promise<void>;\n * error: Error | null;\n * }} An object containing the `isCopied` state, the `copy` function, and any potential error.\n *\n * @example\n * const MyComponent = () => {\n * const { isCopied, copy } = useCopyToClipboard();\n * const textToCopy = '0x123...';\n *\n * return (\n * <button onClick={() => copy(textToCopy)}>\n * {isCopied ? 'Copied!' : 'Copy Address'}\n * </button>\n * );\n * }\n */\nexport function useCopyToClipboard(timeout = 2000): {\n isCopied: boolean;\n copy: (text: string) => Promise<void>;\n error: Error | null;\n} {\n const [isCopied, setIsCopied] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const copy = useCallback(\n async (text: string) => {\n if (!text) return;\n\n try {\n await navigator.clipboard.writeText(text);\n setIsCopied(true);\n setError(null);\n\n setTimeout(() => setIsCopied(false), timeout);\n } catch (e) {\n const copyError = e instanceof Error ? e : new Error('Failed to copy text.');\n console.error(copyError);\n setError(copyError);\n\n // Reset error state after timeout as well\n setTimeout(() => setError(null), timeout);\n }\n },\n [timeout],\n );\n\n return { isCopied, copy, error };\n}\n","/**\n * @file This file contains a utility function for conditionally merging Tailwind CSS classes.\n */\n\nimport { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function to conditionally join class names together and resolve\n * conflicting Tailwind CSS classes.\n *\n * It combines the functionality of `clsx` and `tailwind-merge`.\n *\n * @param {...ClassValue[]} inputs - A list of class values to be combined.\n * This can include strings, numbers, objects, arrays, and booleans.\n * @returns {string} The final, merged class name string.\n *\n * @example\n * cn('p-4', 'bg-red-500', { 'font-bold': true }); // => 'p-4 bg-red-500 font-bold'\n * cn('p-2', 'p-4'); // => 'p-4' (tailwind-merge resolves the conflict)\n *\n * @see https://github.com/dcastil/tailwind-merge\n * @see https://github.com/lukeed/clsx\n */\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","/**\n * @file This file contains a utility for performing a deep (recursive) merge of two objects.\n */\n\n/**\n * Checks if the provided item is a plain object (i.e., not null and not an array).\n *\n * @param {any} item - The item to check.\n * @returns {item is Record<string, any>} True if the item is a plain object, otherwise false.\n */\nconst isObject = (item: any): item is Record<string, any> => {\n return item && typeof item === 'object' && !Array.isArray(item);\n};\n\n/**\n * Recursively merges the properties of a source object into a target object.\n * This function creates a new object and does not mutate the original target.\n *\n * @template T - The type of the objects being merged.\n * @param {T} target - The base object.\n * @param {Partial<T>} source - The object with properties to merge into the target.\n * @returns {T} A new object representing the merged result.\n *\n * @example\n * const defaults = { a: 1, b: { c: 2, d: 3 } };\n * const custom = { b: { c: 99 } };\n * const result = deepMerge(defaults, custom);\n * // result will be { a: 1, b: { c: 99, d: 3 } }\n */\nexport function deepMerge<T extends object>(target: T, source: Partial<T>): T {\n // Start with a shallow copy of the target to avoid mutation.\n const output = { ...target };\n\n if (isObject(target) && isObject(source)) {\n // Iterate over the keys in the source object.\n Object.keys(source).forEach((key) => {\n const targetValue = target[key as keyof T];\n const sourceValue = source[key as keyof T];\n\n // If the value is an object in both target and source, merge them recursively.\n if (isObject(targetValue) && isObject(sourceValue)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n (output as Record<string, any>)[key] = deepMerge(targetValue, sourceValue);\n } else {\n // Otherwise, the source value overwrites the target value.\n (output as Record<string, any>)[key] = sourceValue;\n }\n });\n }\n\n return output;\n}\n","/**\n * @file This file contains a utility function for truncating a string with a center ellipsis.\n */\n\n/**\n * Truncates a string by showing a specified number of characters from the start and end,\n * with an ellipsis in the middle. If the string is too short to be truncated, it's returned as is.\n *\n * @param {string} str - The string to truncate.\n * @param {number} from - The number of characters to show from the beginning of the string.\n * @param {number} to - The number of characters to show from the end of the string.\n * @returns {string} The truncated string, or the original string if it's too short.\n *\n * @example\n * const hash = '0x1234567890abcdef1234567890abcdef';\n * textCenterEllipsis(hash, 6, 4); // => \"0x1234...cdef\"\n *\n * textCenterEllipsis('short', 6, 4); // => \"short\"\n */\nexport function textCenterEllipsis(str: string | undefined | null, from: number, to: number): string {\n if (!str) {\n return '';\n }\n\n // If the string is short enough, don't truncate it.\n if (str.length <= from + to) {\n return str;\n }\n\n const start = str.slice(0, from);\n const end = str.slice(str.length - to);\n\n return `${start}...${end}`;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@tuwaio/nova-core",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "author": "Oleksandr Tkach",
6
+ "license": "Apache-2.0",
7
+ "description": "The foundational package for the TUWA design system. Provides core styling primitives, theme variables, and common React hooks and utilities.",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "type": "module",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "react",
20
+ "tailwindcss",
21
+ "design-system",
22
+ "ui-kit",
23
+ "hooks",
24
+ "utils",
25
+ "tuwa"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/TuwaIO/nova-uikit.git",
30
+ "directory": "packages/nova-core"
31
+ },
32
+ "homepage": "https://github.com/TuwaIO/nova-uikit",
33
+ "bugs": {
34
+ "url": "https://github.com/TuwaIO/nova-uikit/issues"
35
+ },
36
+ "contributors": [
37
+ {
38
+ "name": "Oleksandr Tkach",
39
+ "url": "https://github.com/Argeare5"
40
+ }
41
+ ],
42
+ "peerDependencies": {
43
+ "react": ">=19",
44
+ "react-dom": ">=19",
45
+ "tailwindcss": ">=4"
46
+ },
47
+ "dependencies": {
48
+ "clsx": "^2.1.1",
49
+ "tailwind-merge": "^3.3.1"
50
+ },
51
+ "devDependencies": {
52
+ "@tailwindcss/postcss": "^4.1.11",
53
+ "@tailwindcss/vite": "^4.1.11",
54
+ "@types/react": "^19.1.10",
55
+ "@types/react-dom": "^19.1.7",
56
+ "autoprefixer": "^10.4.21",
57
+ "postcss": "^8.5.6",
58
+ "postcss-cli": "^11.0.1",
59
+ "react": "^19.1.1",
60
+ "react-dom": "^19.1.1",
61
+ "tailwindcss": "^4.1.11",
62
+ "tsup": "^8.5.0",
63
+ "typescript": "~5.9.2"
64
+ },
65
+ "scripts": {
66
+ "build": "tsup && pnpm exec postcss ./src/styles/variables.css -o ./dist/index.css"
67
+ }
68
+ }