@rzl-zone/utils-js 3.12.1-beta.0 → 3.13.0-beta.2
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/README.md +15 -35
- package/dist/.references/index.d.cts +1 -3
- package/dist/.references/index.d.ts +1 -3
- package/dist/{assertIsArray-BfAbIUfa.js → assertIsArray-6BcSdNa-.js} +3 -3
- package/dist/{assertIsArray-BfAbIUfa.js.map → assertIsArray-6BcSdNa-.js.map} +1 -1
- package/dist/{assertIsArray-BChqwPiP.cjs → assertIsArray-BqjMoan3.cjs} +3 -3
- package/dist/{assertIsArray-BChqwPiP.cjs.map → assertIsArray-BqjMoan3.cjs.map} +1 -1
- package/dist/{assertIsBoolean-BlBct0Fc.js → assertIsBoolean-Bv6gL-xe.js} +8 -8
- package/dist/assertIsBoolean-Bv6gL-xe.js.map +1 -0
- package/dist/{assertIsBoolean-DozdtbNi.cjs → assertIsBoolean-amRiJHnh.cjs} +8 -8
- package/dist/assertIsBoolean-amRiJHnh.cjs.map +1 -0
- package/dist/{assertIsString-DqV9NwbI.js → assertIsString-1WiUjgqf.js} +3 -3
- package/dist/{assertIsString-DqV9NwbI.js.map → assertIsString-1WiUjgqf.js.map} +1 -1
- package/dist/{assertIsString-Bvk7bUL7.cjs → assertIsString-C0b28AU1.cjs} +3 -3
- package/dist/{assertIsString-Bvk7bUL7.cjs.map → assertIsString-C0b28AU1.cjs.map} +1 -1
- package/dist/assertions/index.cjs +5 -5
- package/dist/assertions/index.d.cts +2 -2
- package/dist/assertions/index.d.ts +2 -2
- package/dist/assertions/index.js +5 -5
- package/dist/conversions/index.cjs +6 -6
- package/dist/conversions/index.d.cts +2 -2
- package/dist/conversions/index.d.ts +2 -2
- package/dist/conversions/index.js +6 -6
- package/dist/{conversions-EMJa3g-D.js → conversions-BrI0GIOr.js} +16 -18
- package/dist/conversions-BrI0GIOr.js.map +1 -0
- package/dist/{conversions-CBs8-REq.cjs → conversions-lvvAYiZs.cjs} +16 -18
- package/dist/conversions-lvvAYiZs.cjs.map +1 -0
- package/dist/events/index.cjs +4 -4
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +153 -151
- package/dist/events/index.d.ts +153 -151
- package/dist/events/index.js +4 -4
- package/dist/events/index.js.map +1 -1
- package/dist/formatters/index.cjs +2 -2
- package/dist/formatters/index.d.cts +2 -2
- package/dist/formatters/index.d.ts +2 -2
- package/dist/formatters/index.js +2 -2
- package/dist/{formatters-lAYgA11L.cjs → formatters-DQr05EUA.cjs} +17 -15
- package/dist/formatters-DQr05EUA.cjs.map +1 -0
- package/dist/{formatters-QcZO_Cpx.js → formatters-zDzQvtb4.js} +17 -15
- package/dist/formatters-zDzQvtb4.js.map +1 -0
- package/dist/generators/index.cjs +12 -8
- package/dist/generators/index.cjs.map +1 -1
- package/dist/generators/index.d.cts +2 -2
- package/dist/generators/index.d.ts +2 -2
- package/dist/generators/index.js +12 -8
- package/dist/generators/index.js.map +1 -1
- package/dist/index-3jBnthag.d.cts +340 -0
- package/dist/index-BXwimNPA.d.cts +2361 -0
- package/dist/index-BlTCrSyc.d.cts +2158 -0
- package/dist/index-CEm8ZOvj.d.ts +2158 -0
- package/dist/index-CLq5kZmQ.d.cts +822 -0
- package/dist/index-Ckao53JY.d.ts +2361 -0
- package/dist/index-DHHrLc0B.d.ts +947 -0
- package/dist/index-DIeR8qa-.d.ts +340 -0
- package/dist/index-DxZlGbAH.d.ts +1716 -0
- package/dist/index-DyVWeYP3.d.cts +765 -0
- package/dist/index-GSUN6rjA.d.ts +822 -0
- package/dist/index-_dJhBl1h.d.ts +765 -0
- package/dist/index-bMa-0Yr4.d.cts +1716 -0
- package/dist/index-z_uCh5KW.d.cts +947 -0
- package/dist/{isBigInt-B1cijjqm.cjs → isBigInt-CIFRnsdx.cjs} +2 -2
- package/dist/{isBigInt-B1cijjqm.cjs.map → isBigInt-CIFRnsdx.cjs.map} +1 -1
- package/dist/{isBigInt-C0bN0Rhu.js → isBigInt-D-Pu9sxp.js} +2 -2
- package/dist/{isBigInt-C0bN0Rhu.js.map → isBigInt-D-Pu9sxp.js.map} +1 -1
- package/dist/{isEmptyObject-DI42NEo0.cjs → isEmptyObject-CEySmyHK.cjs} +3 -3
- package/dist/{isEmptyObject-DI42NEo0.cjs.map → isEmptyObject-CEySmyHK.cjs.map} +1 -1
- package/dist/{isEmptyObject-DeLVIJpl.js → isEmptyObject-CZ9DLi7R.js} +3 -3
- package/dist/{isEmptyObject-DeLVIJpl.js.map → isEmptyObject-CZ9DLi7R.js.map} +1 -1
- package/dist/{isEmptyString-BTUWYTbw.js → isEmptyString-DFDtBbNr.js} +3 -3
- package/dist/{isEmptyString-BTUWYTbw.js.map → isEmptyString-DFDtBbNr.js.map} +1 -1
- package/dist/{isEmptyString-CCK3bP74.cjs → isEmptyString-DI64RQCy.cjs} +3 -3
- package/dist/{isEmptyString-CCK3bP74.cjs.map → isEmptyString-DI64RQCy.cjs.map} +1 -1
- package/dist/{isEmptyValue-DMSMFTU8.cjs → isEmptyValue-Cw6ovu7z.cjs} +5 -5
- package/dist/{isEmptyValue-DMSMFTU8.cjs.map → isEmptyValue-Cw6ovu7z.cjs.map} +1 -1
- package/dist/{isEmptyValue-fjnfQnt5.js → isEmptyValue-aGyeClwA.js} +5 -5
- package/dist/{isEmptyValue-fjnfQnt5.js.map → isEmptyValue-aGyeClwA.js.map} +1 -1
- package/dist/{isEqual-DhyP8fB_.js → isEqual-Dtb2sXUv.js} +4 -4
- package/dist/{isEqual-DhyP8fB_.js.map → isEqual-Dtb2sXUv.js.map} +1 -1
- package/dist/{isEqual-B1fRgEuU.cjs → isEqual-UsvOwrlY.cjs} +4 -4
- package/dist/{isEqual-B1fRgEuU.cjs.map → isEqual-UsvOwrlY.cjs.map} +1 -1
- package/dist/{isFinite-BYMOo0os.js → isFinite-Cz_IFXuV.js} +3 -3
- package/dist/{isFinite-BYMOo0os.js.map → isFinite-Cz_IFXuV.js.map} +1 -1
- package/dist/{isFinite-sFkps2TY.cjs → isFinite-uukWvxJh.cjs} +3 -3
- package/dist/{isFinite-sFkps2TY.cjs.map → isFinite-uukWvxJh.cjs.map} +1 -1
- package/dist/{isInteger-FTCthMre.cjs → isInteger-DPYjliLZ.cjs} +2 -2
- package/dist/{isInteger-FTCthMre.cjs.map → isInteger-DPYjliLZ.cjs.map} +1 -1
- package/dist/{isInteger-DS9V7l_f.js → isInteger-DZ163OQg.js} +2 -2
- package/dist/{isInteger-DS9V7l_f.js.map → isInteger-DZ163OQg.js.map} +1 -1
- package/dist/isPlainObject-CBABRyEX.d.cts +339 -0
- package/dist/isPlainObject-Dr8gi89U.d.ts +339 -0
- package/dist/{isServer-D1TXfOs3.js → isServer-BDShLyVJ.js} +2 -2
- package/dist/{isServer-D1TXfOs3.js.map → isServer-BDShLyVJ.js.map} +1 -1
- package/dist/{isServer-q-QLFCqE.cjs → isServer-BzDeYuGg.cjs} +2 -2
- package/dist/{isServer-q-QLFCqE.cjs.map → isServer-BzDeYuGg.cjs.map} +1 -1
- package/dist/{isTypedArray-DiCoqffZ.cjs → isTypedArray-DaYAkyrt.cjs} +3 -3
- package/dist/{isTypedArray-DiCoqffZ.cjs.map → isTypedArray-DaYAkyrt.cjs.map} +1 -1
- package/dist/{isTypedArray-47R0wdrc.js → isTypedArray-DuUUA4CL.js} +3 -3
- package/dist/{isTypedArray-47R0wdrc.js.map → isTypedArray-DuUUA4CL.js.map} +1 -1
- package/dist/{isValidDomain-BSXshgkC.cjs → isValidDomain-BxyToAlh.cjs} +74 -8
- package/dist/isValidDomain-BxyToAlh.cjs.map +1 -0
- package/dist/{isValidDomain-DwA2EN79.js → isValidDomain-CTw5vZFY.js} +57 -9
- package/dist/isValidDomain-CTw5vZFY.js.map +1 -0
- package/dist/{noop-B2mTBhW-.cjs → noop-7KrqC9DC.cjs} +2 -2
- package/dist/{noop-B2mTBhW-.cjs.map → noop-7KrqC9DC.cjs.map} +1 -1
- package/dist/{noop-BzktGBVz.js → noop-DGg9vMSD.js} +2 -2
- package/dist/{noop-BzktGBVz.js.map → noop-DGg9vMSD.js.map} +1 -1
- package/dist/{normalizeSpaces-DQHR3Tlr.cjs → normalizeSpaces-B6ZQOZRX.cjs} +3 -3
- package/dist/{normalizeSpaces-DQHR3Tlr.cjs.map → normalizeSpaces-B6ZQOZRX.cjs.map} +1 -1
- package/dist/{normalizeSpaces-WS_iERJk.js → normalizeSpaces-C1eLwykD.js} +3 -3
- package/dist/{normalizeSpaces-WS_iERJk.js.map → normalizeSpaces-C1eLwykD.js.map} +1 -1
- package/dist/operations/index.cjs +10 -10
- package/dist/operations/index.cjs.map +1 -1
- package/dist/operations/index.d.cts +120 -120
- package/dist/operations/index.d.ts +120 -120
- package/dist/operations/index.js +10 -10
- package/dist/operations/index.js.map +1 -1
- package/dist/parsers/index.cjs +2 -2
- package/dist/parsers/index.d.cts +222 -222
- package/dist/parsers/index.d.ts +222 -222
- package/dist/parsers/index.js +2 -2
- package/dist/{parsers-DXtpsDyj.cjs → parsers-DEFpCYhw.cjs} +4 -4
- package/dist/{parsers-DXtpsDyj.cjs.map → parsers-DEFpCYhw.cjs.map} +1 -1
- package/dist/{parsers-Dpuq-V4u.js → parsers-bQQ9mStV.js} +4 -4
- package/dist/{parsers-Dpuq-V4u.js.map → parsers-bQQ9mStV.js.map} +1 -1
- package/dist/{parsing-B43x1sxn.js → parsing-BngARhmu.js} +3 -3
- package/dist/{parsing-B43x1sxn.js.map → parsing-BngARhmu.js.map} +1 -1
- package/dist/{parsing-lRoxn1Nz.cjs → parsing-lI5EN4LY.cjs} +3 -3
- package/dist/{parsing-lRoxn1Nz.cjs.map → parsing-lI5EN4LY.cjs.map} +1 -1
- package/dist/predicates/index.cjs +15 -16
- package/dist/predicates/index.d.cts +3 -3
- package/dist/predicates/index.d.ts +3 -3
- package/dist/predicates/index.js +14 -15
- package/dist/{predicates-DiaYA7Ps.cjs → predicates-CMmP3fPJ.cjs} +15 -16
- package/dist/{predicates-DiaYA7Ps.cjs.map → predicates-CMmP3fPJ.cjs.map} +1 -1
- package/dist/{predicates-gNepszvo.js → predicates-V87QD8hs.js} +13 -14
- package/dist/{predicates-gNepszvo.js.map → predicates-V87QD8hs.js.map} +1 -1
- package/dist/promises/index.cjs +4 -4
- package/dist/promises/index.d.cts +101 -101
- package/dist/promises/index.d.ts +101 -101
- package/dist/promises/index.js +4 -4
- package/dist/{punyCode-hmiFzLWT.js → punyCode-BeFYDjj0.js} +6 -6
- package/dist/punyCode-BeFYDjj0.js.map +1 -0
- package/dist/{punyCode-CTWXVVFo.cjs → punyCode-DmTsB7q_.cjs} +6 -6
- package/dist/punyCode-DmTsB7q_.cjs.map +1 -0
- package/dist/{removeSpaces-BE8lfh-4.js → removeSpaces-B96axxP6.js} +7 -4
- package/dist/removeSpaces-B96axxP6.js.map +1 -0
- package/dist/{removeSpaces-DRRxNWlb.cjs → removeSpaces-C8mu_yp3.cjs} +12 -3
- package/dist/removeSpaces-C8mu_yp3.cjs.map +1 -0
- package/dist/rzl-utils.global.js +21 -0
- package/dist/{safeJsonParse-BBnQElk8.cjs → safeJsonParse-BXbtX_j7.cjs} +9 -9
- package/dist/safeJsonParse-BXbtX_j7.cjs.map +1 -0
- package/dist/{safeJsonParse-CXruaP0p.js → safeJsonParse-DyCsTXlU.js} +9 -9
- package/dist/safeJsonParse-DyCsTXlU.js.map +1 -0
- package/dist/{safeStableStringify-BNh3D0K0.js → safeStableStringify-BrOcdX9n.js} +4 -4
- package/dist/{safeStableStringify-BNh3D0K0.js.map → safeStableStringify-BrOcdX9n.js.map} +1 -1
- package/dist/{safeStableStringify-Cc62pfRp.cjs → safeStableStringify-DRYQ56Dg.cjs} +4 -4
- package/dist/{safeStableStringify-Cc62pfRp.cjs.map → safeStableStringify-DRYQ56Dg.cjs.map} +1 -1
- package/dist/strings/index.cjs +12 -10
- package/dist/strings/index.cjs.map +1 -1
- package/dist/strings/index.d.cts +2 -2
- package/dist/strings/index.d.ts +2 -2
- package/dist/strings/index.js +11 -9
- package/dist/strings/index.js.map +1 -1
- package/dist/tailwind/index.cjs +6 -2
- package/dist/tailwind/index.d.cts +3 -3
- package/dist/tailwind/index.d.ts +3 -3
- package/dist/tailwind/index.js +3 -3
- package/dist/{tailwind-IJvOdkZp.js → tailwind-BZ2_MeNX.js} +18 -8
- package/dist/tailwind-BZ2_MeNX.js.map +1 -0
- package/dist/{tailwind-DJ4cmLUw.cjs → tailwind-C1YtxJ-K.cjs} +39 -5
- package/dist/tailwind-C1YtxJ-K.cjs.map +1 -0
- package/dist/{toStringArrayUnRecursive-xUaU8Ot9.cjs → toStringArrayUnRecursive-D1mPM4wg.cjs} +6 -6
- package/dist/{toStringArrayUnRecursive-xUaU8Ot9.cjs.map → toStringArrayUnRecursive-D1mPM4wg.cjs.map} +1 -1
- package/dist/{toStringArrayUnRecursive-CFs0jTEg.js → toStringArrayUnRecursive-tHp2a7KR.js} +6 -6
- package/dist/{toStringArrayUnRecursive-CFs0jTEg.js.map → toStringArrayUnRecursive-tHp2a7KR.js.map} +1 -1
- package/dist/urls/index.cjs +9 -119
- package/dist/urls/index.d.cts +656 -659
- package/dist/urls/index.d.ts +656 -659
- package/dist/urls/index.js +3 -113
- package/dist/urls-CoxDAoki.js +263 -0
- package/dist/urls-CoxDAoki.js.map +1 -0
- package/dist/urls-DCyx8Wpk.cjs +299 -0
- package/dist/urls-DCyx8Wpk.cjs.map +1 -0
- package/package.json +4 -25
- package/dist/assertIsBoolean-BlBct0Fc.js.map +0 -1
- package/dist/assertIsBoolean-DozdtbNi.cjs.map +0 -1
- package/dist/conversions-CBs8-REq.cjs.map +0 -1
- package/dist/conversions-EMJa3g-D.js.map +0 -1
- package/dist/formatEnvPort-DpIXzPAZ.js +0 -159
- package/dist/formatEnvPort-DpIXzPAZ.js.map +0 -1
- package/dist/formatEnvPort-hHNvOim-.cjs +0 -171
- package/dist/formatEnvPort-hHNvOim-.cjs.map +0 -1
- package/dist/formatters-QcZO_Cpx.js.map +0 -1
- package/dist/formatters-lAYgA11L.cjs.map +0 -1
- package/dist/index-26W7ItWx.d.ts +0 -760
- package/dist/index-BPPQjAfs.d.cts +0 -2359
- package/dist/index-BXjlgBLz.d.cts +0 -2139
- package/dist/index-B_Wwo91H.d.ts +0 -2359
- package/dist/index-CpufydcI.d.cts +0 -704
- package/dist/index-Czc4O526.d.ts +0 -333
- package/dist/index-DPs1_p5G.d.cts +0 -760
- package/dist/index-DRpOyBSC.d.ts +0 -1703
- package/dist/index-DWWvtHUn.d.cts +0 -822
- package/dist/index-DnM0LD0n.d.cts +0 -333
- package/dist/index-GUZ9fK6T.d.ts +0 -2139
- package/dist/index-I4fAzwXV.d.ts +0 -704
- package/dist/index-JDrOl_19.d.ts +0 -822
- package/dist/index-b66P49Qe.d.cts +0 -1703
- package/dist/isPlainObject-DcFGh3_5.d.ts +0 -530
- package/dist/isPlainObject-doTI11Ib.d.cts +0 -530
- package/dist/isURL-CQiowFq2.js +0 -14
- package/dist/isURL-CQiowFq2.js.map +0 -1
- package/dist/isURL-WZypXsax.cjs +0 -20
- package/dist/isURL-WZypXsax.cjs.map +0 -1
- package/dist/isValidDomain-BSXshgkC.cjs.map +0 -1
- package/dist/isValidDomain-DwA2EN79.js.map +0 -1
- package/dist/next/index.cjs +0 -129
- package/dist/next/index.cjs.map +0 -1
- package/dist/next/index.d.cts +0 -226
- package/dist/next/index.d.ts +0 -226
- package/dist/next/index.js +0 -124
- package/dist/next/index.js.map +0 -1
- package/dist/next/server/index.cjs +0 -28
- package/dist/next/server/index.cjs.map +0 -1
- package/dist/next/server/index.d.cts +0 -39
- package/dist/next/server/index.d.ts +0 -39
- package/dist/next/server/index.js +0 -26
- package/dist/next/server/index.js.map +0 -1
- package/dist/normalizeString-2WLth_Gj.js +0 -15
- package/dist/normalizeString-2WLth_Gj.js.map +0 -1
- package/dist/normalizeString-D8euBcRD.cjs +0 -21
- package/dist/normalizeString-D8euBcRD.cjs.map +0 -1
- package/dist/punyCode-CTWXVVFo.cjs.map +0 -1
- package/dist/punyCode-hmiFzLWT.js.map +0 -1
- package/dist/removeSpaces-BE8lfh-4.js.map +0 -1
- package/dist/removeSpaces-DRRxNWlb.cjs.map +0 -1
- package/dist/safeJsonParse-BBnQElk8.cjs.map +0 -1
- package/dist/safeJsonParse-CXruaP0p.js.map +0 -1
- package/dist/tailwind-DJ4cmLUw.cjs.map +0 -1
- package/dist/tailwind-IJvOdkZp.js.map +0 -1
- package/dist/urls/index.cjs.map +0 -1
- package/dist/urls/index.js.map +0 -1
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Stringify } from "@rzl-zone/ts-types-plus";
|
|
12
|
+
import { Config } from "tailwindcss";
|
|
13
|
+
import { ClassNameValue, ConfigExtension } from "tailwind-merge-v3";
|
|
14
|
+
import { ClassNameValue as ClassNameValue$1, ConfigExtension as ConfigExtension$1 } from "tailwind-merge-v4";
|
|
15
|
+
/** ----------------------------------------------------------
|
|
16
|
+
* * ***Type-Utility: `ClassValue`.***
|
|
17
|
+
* ----------------------------------------------------------
|
|
18
|
+
* **Represents a single valid value that can be converted to a CSS class string.**
|
|
19
|
+
* @description
|
|
20
|
+
* - Supports the following types:
|
|
21
|
+
* - `string` → literal class names (non-empty only)
|
|
22
|
+
* - `number | bigint` → numeric class names
|
|
23
|
+
* - `boolean` → only `true` is considered in objects/arrays
|
|
24
|
+
* - `null | undefined` → ignored
|
|
25
|
+
* - `ClassObject` → objects where **keys with truthy values** are included
|
|
26
|
+
* - `ClassValues` → arrays recursively flattened
|
|
27
|
+
* - Used internally by ***`cx` utility function*** to process mixed input values.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const val1: ClassValue = "button"; // ➔ string
|
|
31
|
+
* const val2: ClassValue = 0; // ➔ number
|
|
32
|
+
* const val3: ClassValue = ["a", { b: true }]; // ➔ array with object
|
|
33
|
+
* const val4: ClassValue = { d: true, e: false }; // ➔ object
|
|
34
|
+
* const val5: ClassValue = new String("foo"); // ➔ boxed string
|
|
35
|
+
* const val6: ClassValue = new Number("123"); // ➔ boxed number
|
|
36
|
+
* const val7: ClassValue = new Boolean("true"); // ➔ boxed boolean
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
type ClassValue = ClassValues | ClassObject | string | number | bigint | null | boolean | undefined;
|
|
40
|
+
/** ----------------------------------------------------------
|
|
41
|
+
* * ***Type-Utility: `ClassObject`.***
|
|
42
|
+
* ----------------------------------------------------------
|
|
43
|
+
* **Represents an object whose keys with truthy values are included in the final class string.**
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const obj: ClassObject = { "text-red": true, "hidden": false };
|
|
47
|
+
* // ➔ "text-red" when processed by cx
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
type ClassObject = Record<string, any>;
|
|
51
|
+
/** ----------------------------------------------------------
|
|
52
|
+
* * ***Type-Utility: `ClassValues`.***
|
|
53
|
+
* ----------------------------------------------------------
|
|
54
|
+
* **Represents an array of {@link ClassValue | `ClassValue's`}, potentially nested.**
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const arr: ClassValues = [
|
|
58
|
+
* "a",
|
|
59
|
+
* 1,
|
|
60
|
+
* ["b", { c: true, d: false }],
|
|
61
|
+
* { e: 2 }
|
|
62
|
+
* ];
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
type ClassValues = ClassValue[];
|
|
66
|
+
/** ----------------------------------------------------------
|
|
67
|
+
* * ***Utility: `cx`.***
|
|
68
|
+
* ----------------------------------------------------------
|
|
69
|
+
* **Merge multiple class values into a single, space-separated string suitable for CSS usage.**
|
|
70
|
+
* @description
|
|
71
|
+
* - Supports **nested combinations** of arrays and objects, recursively.
|
|
72
|
+
* - **Falsy values** are skipped:
|
|
73
|
+
* - `false`, `null`, `undefined`, empty strings `""` are ignored anywhere.
|
|
74
|
+
* - Numbers `0` are ignored inside nested arrays/objects.
|
|
75
|
+
* - **Boxed primitives** are correctly unwrapped to their primitive value.
|
|
76
|
+
* - **Inherited object keys** are included in the final class string.
|
|
77
|
+
* - Optimized for **CSS class merging** where conditional inclusion is common.
|
|
78
|
+
* @param {ClassValues} values
|
|
79
|
+
* A list of mixed class values, which can include:
|
|
80
|
+
* - **Strings** → literal class names.
|
|
81
|
+
* - **Numbers** → numeric class names.
|
|
82
|
+
* - **BigInt** → numeric class names larger than JS safe integer limit.
|
|
83
|
+
* - **Arrays** → recursively flattened, can contain nested arrays or objects.
|
|
84
|
+
* - **Objects** → include keys whose values are truthy. Inherited keys are also included.
|
|
85
|
+
* - **Boxed primitives** (`new String()`, `new Number()`, `new Boolean()`) → automatically unwrapped.
|
|
86
|
+
* - **Falsy values** (`false`, `null`, `undefined`, `""`, `0`) are ignored according to original behavior.
|
|
87
|
+
* @returns {string}
|
|
88
|
+
* A single space-separated string containing all valid class names.
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* // Basic string merge
|
|
92
|
+
* cx("btn", "btn-primary");
|
|
93
|
+
* // ➔ "btn btn-primary"
|
|
94
|
+
*
|
|
95
|
+
* // Mixed arrays and objects
|
|
96
|
+
* cx("a", ["b", { c: true, d: false }], { e: 1, f: 0 }, null, 2);
|
|
97
|
+
* // ➔ "a b c e 2"
|
|
98
|
+
*
|
|
99
|
+
* // Empty and falsy values are ignored
|
|
100
|
+
* cx("", null, undefined, false, 0);
|
|
101
|
+
* // ➔ ""
|
|
102
|
+
*
|
|
103
|
+
* // Nested arrays with objects
|
|
104
|
+
* cx(["a", ["b", { c: true, d: false }]]);
|
|
105
|
+
* // ➔ "a b c"
|
|
106
|
+
*
|
|
107
|
+
* // Boxed primitives are unwrapped
|
|
108
|
+
* cx(new String("foo"), new Number(42), new Boolean(true), new Number(0), new Boolean(false));
|
|
109
|
+
* // ➔ "foo 42 true"
|
|
110
|
+
*
|
|
111
|
+
* // Inherited keys from objects are included
|
|
112
|
+
* const proto = { inherited: true };
|
|
113
|
+
* const obj = Object.create(proto);
|
|
114
|
+
* obj.own = true;
|
|
115
|
+
* cx(obj);
|
|
116
|
+
* // ➔ "own inherited"
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function cx(...values: ClassValues): string;
|
|
120
|
+
/** -------------------------------------------------------------------
|
|
121
|
+
* * ***Combines and merges class utility values into a single normalized
|
|
122
|
+
* string with `Tailwind CSS v3` conflict resolution.***
|
|
123
|
+
* --------------------------------------------------------------------
|
|
124
|
+
*
|
|
125
|
+
* This utility composes {@link cx | `cx`} and {@link twMergeV3 | `twMerge`} version **2** for ***`tailwind version 3`***:
|
|
126
|
+
*
|
|
127
|
+
* - `cx` handles flexible class inputs (like `clsx`)
|
|
128
|
+
* - `twMerge` resolves Tailwind CSS utility conflicts
|
|
129
|
+
*
|
|
130
|
+
* This provides a complete solution for conditional class composition
|
|
131
|
+
* with deterministic Tailwind merging.
|
|
132
|
+
*
|
|
133
|
+
* - **Behavior:**
|
|
134
|
+
* - Accepts strings, numbers, arrays, and objects
|
|
135
|
+
* - Supports deeply nested class structures
|
|
136
|
+
* - Ignores falsy values (`false`, `null`, `undefined`, `""`, `0`)
|
|
137
|
+
* - Includes object keys with truthy values (including inherited keys)
|
|
138
|
+
* - Unwraps boxed primitives (`new String()`, etc.)
|
|
139
|
+
* - Resolves Tailwind utility conflicts deterministically
|
|
140
|
+
* - Keeps the last conflicting class based on input order
|
|
141
|
+
* - Produces a clean, space-normalized class string
|
|
142
|
+
*
|
|
143
|
+
* This utility is a drop-in replacement for `clsx` or `classnames`
|
|
144
|
+
* with built-in Tailwind conflict resolution.
|
|
145
|
+
*
|
|
146
|
+
* @param values - A list of mixed class values including strings,
|
|
147
|
+
* numbers, arrays, objects, and conditional expressions.
|
|
148
|
+
*
|
|
149
|
+
* @returns A merged and normalized CSS class string.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* cn(
|
|
154
|
+
* "p-2",
|
|
155
|
+
* isActive && "bg-blue-500",
|
|
156
|
+
* ["text-sm", { "font-bold": isBold }],
|
|
157
|
+
* null,
|
|
158
|
+
* 0
|
|
159
|
+
* );
|
|
160
|
+
* // => "p-2 bg-blue-500 text-sm font-bold"
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* cn("p-2 p-4", { "text-sm": true, "text-lg": true });
|
|
166
|
+
* // => "p-4 text-lg"
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare const cnVer3: (...values: ClassValues) => string;
|
|
170
|
+
/** -------------------------------------------------------------------
|
|
171
|
+
* * ***Combines and merges class utility values into a single normalized
|
|
172
|
+
* string with `Tailwind CSS v4` conflict resolution.***
|
|
173
|
+
* --------------------------------------------------------------------
|
|
174
|
+
*
|
|
175
|
+
* This utility composes {@link cx | `cx`} and {@link twMergeV4 | `twMerge`} version **3** for ***`tailwind version 4`***:
|
|
176
|
+
*
|
|
177
|
+
* - `cx` handles flexible class inputs (like `clsx`)
|
|
178
|
+
* - `twMerge` resolves Tailwind CSS utility conflicts
|
|
179
|
+
*
|
|
180
|
+
* This provides a complete solution for conditional class composition
|
|
181
|
+
* with deterministic Tailwind merging.
|
|
182
|
+
*
|
|
183
|
+
* - **Behavior:**
|
|
184
|
+
* - Accepts strings, numbers, arrays, and objects
|
|
185
|
+
* - Supports deeply nested class structures
|
|
186
|
+
* - Ignores falsy values (`false`, `null`, `undefined`, `""`, `0`)
|
|
187
|
+
* - Includes object keys with truthy values (including inherited keys)
|
|
188
|
+
* - Unwraps boxed primitives (`new String()`, etc.)
|
|
189
|
+
* - Resolves Tailwind utility conflicts deterministically
|
|
190
|
+
* - Keeps the last conflicting class based on input order
|
|
191
|
+
* - Produces a clean, space-normalized class string
|
|
192
|
+
*
|
|
193
|
+
* This utility is a drop-in replacement for `clsx` or `classnames`
|
|
194
|
+
* with built-in Tailwind conflict resolution.
|
|
195
|
+
*
|
|
196
|
+
* @param values - A list of mixed class values including strings,
|
|
197
|
+
* numbers, arrays, objects, and conditional expressions.
|
|
198
|
+
*
|
|
199
|
+
* @returns A merged and normalized CSS class string.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* cn(
|
|
204
|
+
* "p-2",
|
|
205
|
+
* isActive && "bg-blue-500",
|
|
206
|
+
* ["text-sm", { "font-bold": isBold }],
|
|
207
|
+
* null,
|
|
208
|
+
* 0
|
|
209
|
+
* );
|
|
210
|
+
* // => "p-2 bg-blue-500 text-sm font-bold"
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* cn("p-2 p-4", { "text-sm": true, "text-lg": true });
|
|
216
|
+
* // => "p-4 text-lg"
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
declare const cnVer4: (...values: ClassValues) => string;
|
|
220
|
+
/** -------------------------------------------------------------
|
|
221
|
+
* * ***Default `cnV3` utility (Tailwind v3).***
|
|
222
|
+
* -------------------------------------------------------------
|
|
223
|
+
*
|
|
224
|
+
* **Combines class-name values and then deduplicates/resolves
|
|
225
|
+
* conflicts using {@link twMergeDefaultV3 | `twMergeDefaultV3`}
|
|
226
|
+
* with **Tailwind v3 default config only**.**
|
|
227
|
+
* - ✅ **Use this when:**
|
|
228
|
+
* - Your project uses **Tailwind v3**.
|
|
229
|
+
* - You need a simple `cn` that works out of the box without a custom config.
|
|
230
|
+
* - ⚡ **Need custom rules?**
|
|
231
|
+
* - Create a project-wide helper using
|
|
232
|
+
* {@link twMergeDefaultV3 | `twMergeDefaultV3`} +
|
|
233
|
+
* {@link customCnV3 | `customCnV3`} (see Example 2).
|
|
234
|
+
*
|
|
235
|
+
* @deprecated ***Still supported, but significantly slower during hydration because it uses extended runtime merge logic, prefer {@link cnVer3 | `cnVer3`} for
|
|
236
|
+
* better performance, this utility may be removed in a future release.***
|
|
237
|
+
*
|
|
238
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
239
|
+
* @returns {string} Merged Tailwind class string.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* #### Example 1: ✅ Default usage (Tailwind v3).
|
|
243
|
+
* ```ts
|
|
244
|
+
* cnV3("p-2", "p-4");
|
|
245
|
+
* // ➔ "p-4"
|
|
246
|
+
*
|
|
247
|
+
* cnV3("text-red-500", { "text-blue-500": true });
|
|
248
|
+
* // ➔ "text-blue-500"
|
|
249
|
+
*
|
|
250
|
+
* cnV3(["m-2", ["m-4"]], "m-8");
|
|
251
|
+
* // ➔ "m-8"
|
|
252
|
+
* ```
|
|
253
|
+
* #### Example 2: ⚡ Custom project-wide usage with Tailwind config.
|
|
254
|
+
* ```ts
|
|
255
|
+
* import tailwindConfig from "../tailwind.config";
|
|
256
|
+
* import { twMergeDefaultV3, customCnV3, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
257
|
+
*
|
|
258
|
+
* const cnApp = (...classes: ClassValues) => {
|
|
259
|
+
* return customCnV3(
|
|
260
|
+
* twMergeDefaultV3({
|
|
261
|
+
* config: tailwindConfig,
|
|
262
|
+
* extend: {
|
|
263
|
+
* classGroups: {
|
|
264
|
+
* "text-shadow": [
|
|
265
|
+
* "text-shadow",
|
|
266
|
+
* "text-shadow-sm",
|
|
267
|
+
* "text-shadow-md",
|
|
268
|
+
* ],
|
|
269
|
+
* },
|
|
270
|
+
* },
|
|
271
|
+
* }),
|
|
272
|
+
* // ...other options classes,
|
|
273
|
+
* );
|
|
274
|
+
* };
|
|
275
|
+
*
|
|
276
|
+
* cnApp("p-2 p-4"); // ➔ "p-4"
|
|
277
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
278
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (resolved from config)
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
declare const cnV3: (...classes: ClassValues) => string;
|
|
282
|
+
/** -------------------------------------------------------------
|
|
283
|
+
* * ***Default `cnV4` utility (Tailwind v4).***
|
|
284
|
+
* -------------------------------------------------------------
|
|
285
|
+
*
|
|
286
|
+
* **Combines class-name values and then deduplicates/resolves
|
|
287
|
+
* conflicts using {@link twMergeDefaultV4 | `twMergeDefaultV4`}
|
|
288
|
+
* with **Tailwind v4 default config only**.**
|
|
289
|
+
* - ✅ **Use this when:**
|
|
290
|
+
* - Your project uses **Tailwind v4**.
|
|
291
|
+
* - You need a simple `cn` that works out of the box without a custom config.
|
|
292
|
+
* - ⚡ **Need custom rules?**
|
|
293
|
+
* - Create a project-wide helper using
|
|
294
|
+
* {@link twMergeDefaultV4 | `twMergeDefaultV4`} +
|
|
295
|
+
* {@link customCnV4 | `customCnV4`} (see Example 2).
|
|
296
|
+
*
|
|
297
|
+
* @deprecated ***Still supported, but significantly slower during hydration because it uses extended runtime merge logic, prefer {@link cnVer4 | `cnVer4`} for
|
|
298
|
+
* better performance, this utility may be removed in a future release.***
|
|
299
|
+
*
|
|
300
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
301
|
+
* @returns {string} Merged Tailwind class string.
|
|
302
|
+
* @example
|
|
303
|
+
* #### Example 1: ✅ Default usage (Tailwind v4).
|
|
304
|
+
* ```ts
|
|
305
|
+
* cnV4("p-2", "p-4");
|
|
306
|
+
* // ➔ "p-4"
|
|
307
|
+
*
|
|
308
|
+
* cnV4("text-red-500", { "text-blue-500": true });
|
|
309
|
+
* // ➔ "text-blue-500"
|
|
310
|
+
*
|
|
311
|
+
* cnV4(["m-2", ["m-4"]], "m-8");
|
|
312
|
+
* // ➔ "m-8"
|
|
313
|
+
* ```
|
|
314
|
+
* #### Example 2: ⚡ Custom project-wide usage with Tailwind config.
|
|
315
|
+
* ```ts
|
|
316
|
+
* import tailwindConfig from "../tailwind.config";
|
|
317
|
+
* import { twMergeDefaultV4, customCnV4, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
318
|
+
*
|
|
319
|
+
* const cnApp = (...classes: ClassValues) => {
|
|
320
|
+
* return customCnV4(
|
|
321
|
+
* twMergeDefaultV4({
|
|
322
|
+
* config: tailwindConfig,
|
|
323
|
+
* extend: {
|
|
324
|
+
* classGroups: {
|
|
325
|
+
* "text-shadow": [
|
|
326
|
+
* "text-shadow",
|
|
327
|
+
* "text-shadow-sm",
|
|
328
|
+
* "text-shadow-md",
|
|
329
|
+
* ],
|
|
330
|
+
* },
|
|
331
|
+
* },
|
|
332
|
+
* }),
|
|
333
|
+
* // ...other options classes,
|
|
334
|
+
* );
|
|
335
|
+
* };
|
|
336
|
+
*
|
|
337
|
+
* cnApp("p-2 p-4"); // ➔ "p-4"
|
|
338
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
339
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (resolved from config)
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
declare const cnV4: (...classes: ClassValues) => string;
|
|
343
|
+
type TailwindConfig = Config;
|
|
344
|
+
/**
|
|
345
|
+
* Tailwind Merge config extension type
|
|
346
|
+
*/
|
|
347
|
+
type TwMergeConfigExt$1 = ConfigExtension<string, string>;
|
|
348
|
+
/**
|
|
349
|
+
* * ***Extra options for customized Tailwind class merge.***
|
|
350
|
+
*/
|
|
351
|
+
type OptionsConfigMergeTwCn$1 = {
|
|
352
|
+
/** ----------------------------------------------------------
|
|
353
|
+
* * ***Optional Tailwind CSS configuration object.***
|
|
354
|
+
* ----------------------------------------------------------
|
|
355
|
+
* - **Pass your project’s `tailwind.config.ts` if you want to:**
|
|
356
|
+
* - Respect custom theme values (`colors`, `fontSize`, `spacing`, `etc`.)
|
|
357
|
+
* - Enable/disable `corePlugins`
|
|
358
|
+
* - Register `plugins`
|
|
359
|
+
* - Extend class groups (e.g., `text-shadow`)
|
|
360
|
+
* - **If omitted, the **default Tailwind config** is used.**
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* import tailwindConfig from "../tailwind.config";
|
|
364
|
+
* import { twMergeDefaultV3 } from "@rzl-zone/utils-js/tailwind";
|
|
365
|
+
*
|
|
366
|
+
* const myCustomTwCls = twMergeDefaultV3({
|
|
367
|
+
* config: tailwindConfig,
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
370
|
+
* myCustomTwCls("text-primary text-secondary");
|
|
371
|
+
* // => "text-secondary" (resolved from your theme config)
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
config?: TailwindConfig;
|
|
375
|
+
/** ----------------------------------------------------------
|
|
376
|
+
* * ***Prefix added to Tailwind-generated classes.***
|
|
377
|
+
* ----------------------------------------------------------
|
|
378
|
+
* - **Tailwind v3**:
|
|
379
|
+
* - Configure in `tailwind.config.js`, e.g. `prefix: 'tw-'`.
|
|
380
|
+
* - Variants first; negative utilities: `-mt-8` ➔ `-tw-mt-8`.
|
|
381
|
+
* - Reference:
|
|
382
|
+
* [**`Tailwind v3 using prefix docs`**](https://v3.tailwindcss.com/docs/configuration#prefix).
|
|
383
|
+
* - **Tailwind v4**:
|
|
384
|
+
* - Use {@link twMergeDefaultV4 | **`twMergeDefaultV4`**} instead.
|
|
385
|
+
* - Reference:
|
|
386
|
+
* [**`Tailwind v4 using prefix docs`**](https://tailwindcss.com/docs/upgrade-guide#using-a-prefix).
|
|
387
|
+
* - **ℹ️ Notes**:
|
|
388
|
+
* - Tailwind v3: use hyphenated prefix (`tw-`).
|
|
389
|
+
* - Fallback order:
|
|
390
|
+
* 1. `prefix` option
|
|
391
|
+
* 2. `config.prefix` (if defined)
|
|
392
|
+
* 3. `undefined`
|
|
393
|
+
* - Tailwind v4:
|
|
394
|
+
* - Use {@link twMergeDefaultV4 | **`twMergeDefaultV4`**} instead.
|
|
395
|
+
* @example
|
|
396
|
+
* - Tailwind version 3 (`tailwind.config.ts`):
|
|
397
|
+
* ```ts
|
|
398
|
+
* import type { Config } from "tailwindcss";
|
|
399
|
+
*
|
|
400
|
+
* const config: Config = {
|
|
401
|
+
* prefix: 'tw-',
|
|
402
|
+
* // ... other config
|
|
403
|
+
* };
|
|
404
|
+
*
|
|
405
|
+
* export default config;
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
prefix?: string;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* * ***Options type for Tailwind Merge v3 wrapper.***
|
|
412
|
+
*/
|
|
413
|
+
type OptionsMergeTwClsV3 = Omit<TwMergeConfigExt$1, "prefix"> & OptionsConfigMergeTwCn$1;
|
|
414
|
+
/**
|
|
415
|
+
* * ***Tailwind Merge function Version 3 signature (same as twMerge).***
|
|
416
|
+
*/
|
|
417
|
+
type TwMergeDefaultFnV3 = (...classLists: ClassNameValue[]) => string;
|
|
418
|
+
/**
|
|
419
|
+
* Tailwind Merge config extension type
|
|
420
|
+
*/
|
|
421
|
+
type TwMergeConfigExt = ConfigExtension$1<string, string>;
|
|
422
|
+
/**
|
|
423
|
+
* * ***Extra options for customized Tailwind class merge.***
|
|
424
|
+
*/
|
|
425
|
+
type OptionsConfigMergeTwCn = {
|
|
426
|
+
/** ----------------------------------------------------------
|
|
427
|
+
* * ***Optional Tailwind CSS configuration object.***
|
|
428
|
+
* ----------------------------------------------------------
|
|
429
|
+
* - **Pass your project’s `tailwind.config.ts` if you want to:**
|
|
430
|
+
* - Respect custom theme values (`colors`, `fontSize`, `spacing`, `etc`.)
|
|
431
|
+
* - Enable/disable `corePlugins`
|
|
432
|
+
* - Register `plugins`
|
|
433
|
+
* - Extend class groups (e.g., `text-shadow`)
|
|
434
|
+
* - **If omitted, the **default Tailwind config** is used.**
|
|
435
|
+
* @example
|
|
436
|
+
* ```ts
|
|
437
|
+
* import tailwindConfig from "../tailwind.config";
|
|
438
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
439
|
+
*
|
|
440
|
+
* const myCustomTwCls = twMergeDefaultV4({
|
|
441
|
+
* config: tailwindConfig,
|
|
442
|
+
* });
|
|
443
|
+
*
|
|
444
|
+
* myCustomTwCls("text-primary text-secondary");
|
|
445
|
+
* // => "text-secondary" (resolved from your theme config)
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
config?: TailwindConfig;
|
|
449
|
+
/** ----------------------------------------------------------
|
|
450
|
+
* * ***Prefix added to Tailwind-generated classes.***
|
|
451
|
+
* ----------------------------------------------------------
|
|
452
|
+
* - **Tailwind v3**:
|
|
453
|
+
* - Use {@link twMergeDefaultV3 | **`twMergeDefaultV3`**} instead.
|
|
454
|
+
* - Reference:
|
|
455
|
+
* [**`Tailwind v3 using prefix docs`**](https://v3.tailwindcss.com/docs/configuration#prefix).
|
|
456
|
+
*
|
|
457
|
+
* - **Tailwind v4**:
|
|
458
|
+
* - Configure in your CSS import, e.g. `@import "tailwindcss" prefix(tw);`
|
|
459
|
+
* - The prefix appears like a variant at the start of the class, e.g. `tw:flex`,
|
|
460
|
+
* `tw:bg-red-500`, `tw:hover:bg-red-600`.
|
|
461
|
+
* - Reference:
|
|
462
|
+
* [**`Tailwind v4 using prefix docs`**](https://tailwindcss.com/docs/upgrade-guide#using-a-prefix).
|
|
463
|
+
*
|
|
464
|
+
* - **ℹ️ Notes**:
|
|
465
|
+
* - Tailwind v3:
|
|
466
|
+
* - Use {@link twMergeDefaultV3 | **`twMergeDefaultV3`**} instead.
|
|
467
|
+
* - Tailwind v4: prefer identifier (e.g. `tw`) without `-`.
|
|
468
|
+
* - Fallback order:
|
|
469
|
+
* 1. `prefix` option
|
|
470
|
+
* 2. `config.prefix` (if defined)
|
|
471
|
+
* 3. `undefined`
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* - Tailwind version 4 (in CSS entry only):
|
|
475
|
+
* - CSS files:
|
|
476
|
+
* ```css
|
|
477
|
+
* `@import "tailwindcss" prefix(tw);`
|
|
478
|
+
* ```
|
|
479
|
+
* - Your custom TwMerge file:
|
|
480
|
+
* ```ts
|
|
481
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
482
|
+
*
|
|
483
|
+
* const twMergeV3 = twMergeDefaultV4({
|
|
484
|
+
* prefix: "tw",
|
|
485
|
+
* // ... other config
|
|
486
|
+
* });
|
|
487
|
+
* ```
|
|
488
|
+
* - Tailwind version 4 (with `tailwind.config.{js,ts,mjs,...etc}`):
|
|
489
|
+
* - Reference:
|
|
490
|
+
* [**`Tailwind v4 using @config docs`**](https://tailwindcss.com/docs/functions-and-directives#config-directive).
|
|
491
|
+
* - CSS files:
|
|
492
|
+
* ```css
|
|
493
|
+
* `@import "tailwindcss";`
|
|
494
|
+
* `@config "./tailwind.config.ts";`
|
|
495
|
+
* ```
|
|
496
|
+
* - Config files:
|
|
497
|
+
* ```ts
|
|
498
|
+
* import type { Config } from "tailwindcss";
|
|
499
|
+
*
|
|
500
|
+
* const config: Config = {
|
|
501
|
+
* prefix: 'tw-',
|
|
502
|
+
* // ... other config
|
|
503
|
+
* };
|
|
504
|
+
*
|
|
505
|
+
* export default config;
|
|
506
|
+
* ```
|
|
507
|
+
* - Your custom TwMerge file:
|
|
508
|
+
* ```ts
|
|
509
|
+
* import config from "../tailwind.config";
|
|
510
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
511
|
+
*
|
|
512
|
+
* const twMergeV4 = twMergeDefaultV4({ config });
|
|
513
|
+
* // now without passing `prefix` options, will use automatic from config.
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
prefix?: string;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* * ***Options type for Tailwind Merge v4 wrapper.***
|
|
520
|
+
*/
|
|
521
|
+
type OptionsMergeTwClsV4 = Omit<TwMergeConfigExt, "prefix"> & OptionsConfigMergeTwCn;
|
|
522
|
+
/**
|
|
523
|
+
* * ***Tailwind Merge function Version 4 signature (same as twMerge).***
|
|
524
|
+
*/
|
|
525
|
+
type TwMergeDefaultFnV4 = (...classLists: ClassNameValue$1[]) => string;
|
|
526
|
+
/** -------------------------------------------------------------
|
|
527
|
+
* * ***High-performance `cn` factory utility (Tailwind `v3`).***
|
|
528
|
+
* -------------------------------------------------------------
|
|
529
|
+
* **Combines class-name values and applies the provided Tailwind merge
|
|
530
|
+
* function using the native {@link twMergeV3 | `twMergeV3`} implementation
|
|
531
|
+
* from `tailwind-merge` version 2 for `tailwind version 3`.**
|
|
532
|
+
*
|
|
533
|
+
* This utility is the recommended replacement for deprecated extended
|
|
534
|
+
* runtime merge helpers because it provides significantly better hydration
|
|
535
|
+
* and runtime performance.
|
|
536
|
+
*
|
|
537
|
+
* - ✅ **Recommended when:**
|
|
538
|
+
* - Your project uses **Tailwind v3**.
|
|
539
|
+
* - You want the fastest possible `cn` utility.
|
|
540
|
+
* - You need reusable project-wide `cn*` helpers.
|
|
541
|
+
* - You want predictable Tailwind conflict resolution with minimal overhead.
|
|
542
|
+
*
|
|
543
|
+
* - ⚡ **Performance note**
|
|
544
|
+
* - Uses the native `twMergeV3` implementation directly.
|
|
545
|
+
* - Faster than deprecated extended merge utilities.
|
|
546
|
+
* - Better suited for SSR and hydration-heavy applications.
|
|
547
|
+
*
|
|
548
|
+
* @param {TwMergeDefaultFnV3} customTwMergeV3 - Merge function created via {@link twMergeV3 | `twMergeV3`}.
|
|
549
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
550
|
+
* @returns {string} Merged Tailwind class string.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* import { twMerge as twMergeV3 } from "tailwind-merge"; // tw-merge (v2) for tailwind version 3
|
|
555
|
+
* import { customCnVer3, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
556
|
+
*
|
|
557
|
+
* // 1. Create app-level helper
|
|
558
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
559
|
+
* return customCnVer3(twMergeV3, ...classes);
|
|
560
|
+
* };
|
|
561
|
+
*
|
|
562
|
+
* // ✅ Usage
|
|
563
|
+
* cnApp("p-2", "p-4"); // ➔ "p-4"
|
|
564
|
+
* cnApp("text-sm text-lg"); // ➔ "text-lg"
|
|
565
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
declare const customCnVer3: (customTwMergeV3?: TwMergeDefaultFnV3, ...classes: ClassValues) => string;
|
|
569
|
+
/** -------------------------------------------------------------
|
|
570
|
+
* * ***High-performance `cn` factory utility (Tailwind `v4`).***
|
|
571
|
+
* -------------------------------------------------------------
|
|
572
|
+
* **Combines class-name values and applies the provided Tailwind merge
|
|
573
|
+
* function using the native {@link twMergeV4 | `twMergeV4`} implementation
|
|
574
|
+
* from `tailwind-merge` version 3 for `tailwind version 4`.**
|
|
575
|
+
*
|
|
576
|
+
* This utility is the recommended replacement for deprecated extended
|
|
577
|
+
* runtime merge helpers because it provides significantly better hydration
|
|
578
|
+
* and runtime performance.
|
|
579
|
+
*
|
|
580
|
+
* - ✅ **Recommended when:**
|
|
581
|
+
* - Your project uses **Tailwind v4**.
|
|
582
|
+
* - You want the fastest possible `cn` utility.
|
|
583
|
+
* - You need reusable project-wide `cn*` helpers.
|
|
584
|
+
* - You want predictable Tailwind conflict resolution with minimal overhead.
|
|
585
|
+
*
|
|
586
|
+
* - ⚡ **Performance note**
|
|
587
|
+
* - Uses the native `twMergeV4` implementation directly.
|
|
588
|
+
* - Faster than deprecated extended merge utilities.
|
|
589
|
+
* - Better suited for SSR and hydration-heavy applications.
|
|
590
|
+
*
|
|
591
|
+
* @param {TwMergeDefaultFnV4} customTwMergeV4 - Merge function created via {@link twMergeV4 | `twMergeV4`}.
|
|
592
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
593
|
+
* @returns {string} Merged Tailwind class string.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* import { twMerge as twMergeV4 } from "tailwind-merge"; // tw-merge (v3) for tailwind version 4
|
|
598
|
+
* import { customCnVer4, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
599
|
+
*
|
|
600
|
+
* // 1. Create app-level helper
|
|
601
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
602
|
+
* return customCnVer4(twMergeV4, ...classes);
|
|
603
|
+
* };
|
|
604
|
+
*
|
|
605
|
+
* // ✅ Usage
|
|
606
|
+
* cnApp("p-2", "p-4"); // ➔ "p-4"
|
|
607
|
+
* cnApp("text-sm text-lg"); // ➔ "text-lg"
|
|
608
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
declare const customCnVer4: (customTwMergeV4?: TwMergeDefaultFnV4, ...classes: ClassValues) => string;
|
|
612
|
+
/** -------------------------------------------------------------
|
|
613
|
+
* * ***Factory utility for building a custom `cn` helper (Tailwind `v3`).***
|
|
614
|
+
* -------------------------------------------------------------
|
|
615
|
+
*
|
|
616
|
+
* **Wraps internally function to combines class-name values and applies the provided
|
|
617
|
+
* Tailwind merge function (from {@link twMergeDefaultV3 | `twMergeDefaultV3`}).**
|
|
618
|
+
*
|
|
619
|
+
* - 🔑 **When to use it?**
|
|
620
|
+
* - Your project uses **Tailwind v3**.
|
|
621
|
+
* - You extend Tailwind merge rules (`classGroups`, `tailwind.config`).
|
|
622
|
+
* - You need multiple `cn*` variants across apps/packages.
|
|
623
|
+
*
|
|
624
|
+
* @deprecated ***Still supported, but slower during SSR and hydration because it relies on extended runtime merge logic,
|
|
625
|
+
* prefer {@link customCnVer3 | `customCnVer3`}for better performance, this utility may be removed in a future release.***
|
|
626
|
+
*
|
|
627
|
+
* @param {TwMergeDefaultFnV3} customTwMergeV3 - Merge function created via {@link twMergeDefaultV3 | `twMergeDefaultV3`}.
|
|
628
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
629
|
+
*
|
|
630
|
+
* @returns {string} Merged Tailwind class string.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* import tailwindConfig from "../tailwind.config";
|
|
635
|
+
* import { twMergeDefaultV3, customCnV3, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
636
|
+
*
|
|
637
|
+
* // 1. Create a custom merge function
|
|
638
|
+
* const myCustomTwMerge = twMergeDefaultV3({
|
|
639
|
+
* config: tailwindConfig,
|
|
640
|
+
* extend: {
|
|
641
|
+
* classGroups: {
|
|
642
|
+
* "text-shadow": ["text-shadow", "text-shadow-sm", "text-shadow-md"],
|
|
643
|
+
* },
|
|
644
|
+
* },
|
|
645
|
+
* });
|
|
646
|
+
*
|
|
647
|
+
* // 2. Build your helper using `customCnV3`
|
|
648
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
649
|
+
* return customCnV3(myCustomTwMerge, ...classes);
|
|
650
|
+
* };
|
|
651
|
+
* // ✅ Usage
|
|
652
|
+
* cnApp("p-2", "p-4"); // ➔ "p-4"
|
|
653
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
654
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (resolved from config)
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
declare const customCnV3: (customTwMergeV3: TwMergeDefaultFnV3, ...classes: ClassValues) => string;
|
|
658
|
+
/** -------------------------------------------------------------
|
|
659
|
+
* * ***Factory utility for building a custom `cn` helper (Tailwind `v4`).***
|
|
660
|
+
* -------------------------------------------------------------
|
|
661
|
+
*
|
|
662
|
+
* **Wraps internally function to combines class-name values and applies the provided
|
|
663
|
+
* Tailwind merge function (from {@link twMergeDefaultV4 | `twMergeDefaultV4`}).**
|
|
664
|
+
*
|
|
665
|
+
* - 🔑 **When to use it?**
|
|
666
|
+
* - Your project uses **Tailwind v4**.
|
|
667
|
+
* - You extend Tailwind merge rules (`classGroups`, `tailwind.config`).
|
|
668
|
+
* - You need multiple `cn*` variants across apps/packages.
|
|
669
|
+
*
|
|
670
|
+
* @deprecated ***Still supported, but slower during SSR and hydration because it relies on extended runtime merge logic,
|
|
671
|
+
* prefer {@link customCnVer4 | `customCnVer4`}for better performance, this utility may be removed in a future release.***
|
|
672
|
+
*
|
|
673
|
+
* @param {TwMergeDefaultFnV4} customTwMergeV4 - Merge function created via {@link twMergeDefaultV4 | `twMergeDefaultV4`}.
|
|
674
|
+
* @param {ClassValues} classes - Class values (`string`, `array`, `object`, `etc`).
|
|
675
|
+
*
|
|
676
|
+
* @returns {string} Merged Tailwind class string.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* import tailwindConfig from "../tailwind.config";
|
|
681
|
+
* import { twMergeDefaultV4, customCnV4, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
682
|
+
*
|
|
683
|
+
* // 1. Create a custom merge function
|
|
684
|
+
* const myCustomTwMerge = twMergeDefaultV4({
|
|
685
|
+
* config: tailwindConfig,
|
|
686
|
+
* extend: {
|
|
687
|
+
* classGroups: {
|
|
688
|
+
* "text-shadow": ["text-shadow", "text-shadow-sm", "text-shadow-md"],
|
|
689
|
+
* },
|
|
690
|
+
* },
|
|
691
|
+
* });
|
|
692
|
+
*
|
|
693
|
+
* // 2. Build your helper using `customCnV4`
|
|
694
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
695
|
+
* return customCnV4(myCustomTwMerge, ...classes);
|
|
696
|
+
* };
|
|
697
|
+
*
|
|
698
|
+
* // ✅ Usage
|
|
699
|
+
* cnApp("p-2", "p-4"); // ➔ "p-4"
|
|
700
|
+
* cnApp("shadow-sm shadow-md"); // ➔ "shadow-md"
|
|
701
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (resolved from config)
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
declare const customCnV4: (customTwMergeV4: TwMergeDefaultFnV4, ...classes: ClassValues) => string;
|
|
705
|
+
/** ----------------------------------------------------------
|
|
706
|
+
* * ***Utility: `shouldForwardProp`.***
|
|
707
|
+
* ----------------------------------------------------------
|
|
708
|
+
* **Creates a helper for styled-components `shouldForwardProp`.**
|
|
709
|
+
*
|
|
710
|
+
* @description
|
|
711
|
+
* 1. Returns a **predicate function** that determines whether a given prop
|
|
712
|
+
* should be forwarded to the DOM.
|
|
713
|
+
* 2. Useful for filtering out internal props (e.g., `$size`, `$active`)
|
|
714
|
+
* so they don't become invalid HTML attributes.
|
|
715
|
+
*
|
|
716
|
+
* - **Behavior:**
|
|
717
|
+
* - Accepts a strict tuple of **string keys** to exclude from forwarding.
|
|
718
|
+
* - Every key is validated as a **non-empty string** at runtime.
|
|
719
|
+
* - Throws a `TypeError` if:
|
|
720
|
+
* - `props` is not an array, or
|
|
721
|
+
* - any item is not a non-empty string.
|
|
722
|
+
* - Automatically coerces the tested prop name to string for matching.
|
|
723
|
+
*
|
|
724
|
+
* @template CustomProps
|
|
725
|
+
* The component props type to validate against.
|
|
726
|
+
*
|
|
727
|
+
* @param {readonly Stringify<keyof CustomProps>[]}
|
|
728
|
+
* props
|
|
729
|
+
* The list of prop names (keys of `CustomProps`) to exclude from forwarding.
|
|
730
|
+
*
|
|
731
|
+
* @returns {(propName: keyof CustomProps | ({} & string)) => boolean}
|
|
732
|
+
* A function that receives a prop name and returns:
|
|
733
|
+
* - `true` ➔ the prop **will** be forwarded to the DOM.
|
|
734
|
+
* - `false` ➔ the prop **will not** be forwarded.
|
|
735
|
+
*
|
|
736
|
+
* @throws **{@link TypeError | `TypeError`}**
|
|
737
|
+
* when:
|
|
738
|
+
* - `props` is not an array, or
|
|
739
|
+
* - any item is not a non-empty string.
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
742
|
+
* // Basic usage
|
|
743
|
+
* type Props = { $size: string; color: string; visible: boolean };
|
|
744
|
+
* const filter = shouldForwardProp<Props>(["$size"]);
|
|
745
|
+
*
|
|
746
|
+
* filter("$size"); // ➔ false (blocked).
|
|
747
|
+
* filter("color"); // ➔ true (forwarded).
|
|
748
|
+
* filter("visible"); // ➔ true (forwarded).
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* // With styled-components
|
|
752
|
+
* type CustomProps = { $internal: boolean; public: string; another: boolean };
|
|
753
|
+
*
|
|
754
|
+
* styled.div.withConfig({
|
|
755
|
+
* shouldForwardProp: shouldForwardProp<CustomProps>(["$internal"])
|
|
756
|
+
* });
|
|
757
|
+
*/
|
|
758
|
+
declare const shouldForwardProp: <CustomProps extends Record<string, unknown>>(props: readonly Stringify<keyof CustomProps>[]) => ((propName: keyof CustomProps | ({} & string)) => boolean);
|
|
759
|
+
/** -------------------------------------------------------------
|
|
760
|
+
* * ***Customized Tailwind class merger Version 3 with extended rules.***
|
|
761
|
+
* -------------------------------------------------------------
|
|
762
|
+
*
|
|
763
|
+
* **Wraps ***`extendTailwindMerge` from tailwind-merge-v3*** with Tailwind’s default
|
|
764
|
+
* config (_*`getDefaultConfig()` from tailwind-merge-v3*_) to create a **project-ready `twMerge`**.**
|
|
765
|
+
* - 🔑 **When to use it?**
|
|
766
|
+
* - Your project uses **Tailwind v3**.
|
|
767
|
+
* - Extend **class groups** (e.g. add `text-shadow`).
|
|
768
|
+
* - Respect your own **`tailwind.config.ts`** (colors, spacing, fontSize, etc).
|
|
769
|
+
* - Override or fine-tune **merge behavior**.
|
|
770
|
+
* - Create a **project-wide `cn` helper** that replaces raw `twMerge`.
|
|
771
|
+
*
|
|
772
|
+
* @deprecated ***Still supported for advanced Tailwind merge customization, but significantly slower than native `twMerge` during SSR and hydration because merge rules are extended at runtime, prefer `twMerge` + {@link customCnVer3 | `customCnVer3`} for better performance, this utility may be removed in a future release.***
|
|
773
|
+
*
|
|
774
|
+
* @param {OptionsMergeTwClsV3} [options={}]
|
|
775
|
+
* ***Merge options:***
|
|
776
|
+
* - `config` – Your Tailwind config (from `tailwind.config.ts`).
|
|
777
|
+
* - `prefix` - Utility prefix (e.g. `tw-` or `tw`).
|
|
778
|
+
* - `extend` – Extra merge rules (classGroups, theme, etc).
|
|
779
|
+
* - `override` – Fully replace rules.
|
|
780
|
+
* - `cacheSize` – Parsed class cache size.
|
|
781
|
+
* - `experimentalParseClassName` – Custom classname parser.
|
|
782
|
+
*
|
|
783
|
+
* @returns {TwMergeDefaultFnV3}
|
|
784
|
+
* Customized Tailwind class merge function version 3 (same signature as `twMerge`).
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* #### Example 1: ***Default behavior (same as tailwind-merge).***
|
|
788
|
+
* ```ts
|
|
789
|
+
* import { twMergeDefaultV3 } from "@rzl-zone/utils-js/tailwind";
|
|
790
|
+
*
|
|
791
|
+
* const twMerge = twMergeDefaultV3();
|
|
792
|
+
* twMerge("p-2 p-4");
|
|
793
|
+
* // ➔ "p-4"
|
|
794
|
+
* ```
|
|
795
|
+
* #### Example 2: ***Extend class groups.***
|
|
796
|
+
* ```ts
|
|
797
|
+
* import { twMergeDefaultV3 } from "@rzl-zone/utils-js/tailwind";
|
|
798
|
+
*
|
|
799
|
+
* const twMerge2 = twMergeDefaultV3({
|
|
800
|
+
* extend: {
|
|
801
|
+
* classGroups: {
|
|
802
|
+
* shadow: ["shadow-soft", "shadow-hard"],
|
|
803
|
+
* },
|
|
804
|
+
* },
|
|
805
|
+
* });
|
|
806
|
+
* twMerge2("shadow-soft shadow-hard");
|
|
807
|
+
* // ➔ "shadow-hard"
|
|
808
|
+
* ```
|
|
809
|
+
* #### Example 3: ***Respect your Tailwind config.***
|
|
810
|
+
* ```ts
|
|
811
|
+
* import config from "../tailwind.config";
|
|
812
|
+
* import { twMergeDefaultV3 } from "@rzl-zone/utils-js/tailwind";
|
|
813
|
+
*
|
|
814
|
+
* const twMerge3 = twMergeDefaultV3({ config });
|
|
815
|
+
* twMerge3("text-base text-xxs");
|
|
816
|
+
* // ➔ "text-xxs" (resolved from config)
|
|
817
|
+
* ```
|
|
818
|
+
* #### Example 4: ***Project-wide helper (recommended).***
|
|
819
|
+
* ```ts
|
|
820
|
+
* import configTwCss from "../tailwind.config";
|
|
821
|
+
* import { customCnV3, twMergeDefaultV3, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
822
|
+
*
|
|
823
|
+
* const customTwMerge = twMergeDefaultV3({
|
|
824
|
+
* config: configTwCss,
|
|
825
|
+
* extend: {
|
|
826
|
+
* classGroups: { shadow: ["shadow-soft", "shadow-hard"] },
|
|
827
|
+
* },
|
|
828
|
+
* });
|
|
829
|
+
*
|
|
830
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
831
|
+
* return customCnV3(customTwMerge, ...classes);
|
|
832
|
+
* };
|
|
833
|
+
*
|
|
834
|
+
* // ✅ Usage
|
|
835
|
+
* cnApp("p-2 p-4"); // ➔ "p-4"
|
|
836
|
+
* cnApp("shadow-soft shadow-hard"); // ➔ "shadow-hard"
|
|
837
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (uses config)
|
|
838
|
+
*
|
|
839
|
+
* // ⚡ Difference with package-level `cn`
|
|
840
|
+
* import { cnV3, cnV4 } from "@rzl-zone/utils-js/tailwind";
|
|
841
|
+
*
|
|
842
|
+
* cnV3("text-base text-xxs");
|
|
843
|
+
* // or
|
|
844
|
+
* cnV4("text-base text-xxs");
|
|
845
|
+
* // ➔ "text-base" (❌ doesn't know about your config)
|
|
846
|
+
*
|
|
847
|
+
* cnApp("text-base text-xxs");
|
|
848
|
+
* // ➔ "text-xxs" (✅ respects config)
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
declare const twMergeDefaultV3: (options?: OptionsMergeTwClsV3) => TwMergeDefaultFnV3;
|
|
852
|
+
/** -------------------------------------------------------------
|
|
853
|
+
* * ***Customized Tailwind class merger Version 4 with extended rules.***
|
|
854
|
+
* -------------------------------------------------------------
|
|
855
|
+
*
|
|
856
|
+
* **Wraps ***`extendTailwindMerge` from tailwind-merge-v4*** with Tailwind’s default
|
|
857
|
+
* config (_*`getDefaultConfig()` from tailwind-merge-v4*_) to create a **project-ready `twMerge`**.**
|
|
858
|
+
* - 🔑 **When to use it?**
|
|
859
|
+
* - Your project uses **Tailwind v4**.
|
|
860
|
+
* - Extend **class groups** (e.g. add `text-shadow`).
|
|
861
|
+
* - Respect your own **`tailwind.config.ts`** (colors, spacing, fontSize, etc).
|
|
862
|
+
* - Override or fine-tune **merge behavior**.
|
|
863
|
+
* - Create a **project-wide `cn` helper** that replaces raw `twMerge`.
|
|
864
|
+
*
|
|
865
|
+
* @deprecated ***Still supported for advanced Tailwind merge customization, but significantly slower than native `twMerge` during SSR and hydration because merge rules are extended at runtime, prefer `twMerge` + {@link customCnVer4 | `customCnVer4`} for better performance, this utility may be removed in a future release.***
|
|
866
|
+
*
|
|
867
|
+
* @deprecated ***Slower than the default `twMerge`, but still safe to use when custom merge behavior is needed.***
|
|
868
|
+
*
|
|
869
|
+
* @param {OptionsMergeTwClsV4} [options={}]
|
|
870
|
+
* ***Merge options:***
|
|
871
|
+
* - `config` – Your Tailwind config (from `tailwind.config.ts`).
|
|
872
|
+
* - `prefix` - Utility prefix (e.g. `tw-` or `tw`).
|
|
873
|
+
* - `extend` – Extra merge rules (classGroups, theme, etc).
|
|
874
|
+
* - `override` – Fully replace rules.
|
|
875
|
+
* - `cacheSize` – Parsed class cache size.
|
|
876
|
+
* - `experimentalParseClassName` – Custom classname parser.
|
|
877
|
+
*
|
|
878
|
+
* @returns {TwMergeDefaultFnV4}
|
|
879
|
+
* Customized Tailwind class merge function version 4 (same signature as `twMerge`).
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* #### Example 1: ***Default behavior (same as tailwind-merge).***
|
|
883
|
+
* ```ts
|
|
884
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
885
|
+
*
|
|
886
|
+
* const twMerge = twMergeDefaultV4();
|
|
887
|
+
* twMerge("p-2 p-4");
|
|
888
|
+
* // ➔ "p-4"
|
|
889
|
+
* ```
|
|
890
|
+
* #### Example 2: ***Extend class groups.***
|
|
891
|
+
* ```ts
|
|
892
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
893
|
+
*
|
|
894
|
+
* const twMerge2 = twMergeDefaultV4({
|
|
895
|
+
* extend: {
|
|
896
|
+
* classGroups: {
|
|
897
|
+
* shadow: ["shadow-soft", "shadow-hard"],
|
|
898
|
+
* },
|
|
899
|
+
* },
|
|
900
|
+
* });
|
|
901
|
+
* twMerge2("shadow-soft shadow-hard");
|
|
902
|
+
* // ➔ "shadow-hard"
|
|
903
|
+
* ```
|
|
904
|
+
* #### Example 3: ***Respect your Tailwind config.***
|
|
905
|
+
* ```ts
|
|
906
|
+
* import config from "../tailwind.config";
|
|
907
|
+
* import { twMergeDefaultV4 } from "@rzl-zone/utils-js/tailwind";
|
|
908
|
+
*
|
|
909
|
+
* const twMerge3 = twMergeDefaultV4({ config });
|
|
910
|
+
* twMerge3("text-base text-xxs");
|
|
911
|
+
* // ➔ "text-xxs" (resolved from config)
|
|
912
|
+
* ```
|
|
913
|
+
* #### Example 4: ***Project-wide helper (recommended).***
|
|
914
|
+
* ```ts
|
|
915
|
+
* import configTwCss from "../tailwind.config";
|
|
916
|
+
* import { customCnV4, twMergeDefaultV4, type ClassValues } from "@rzl-zone/utils-js/tailwind";
|
|
917
|
+
*
|
|
918
|
+
* const customTwMerge = twMergeDefaultV4({
|
|
919
|
+
* config: configTwCss,
|
|
920
|
+
* extend: {
|
|
921
|
+
* classGroups: { shadow: ["shadow-soft", "shadow-hard"] },
|
|
922
|
+
* },
|
|
923
|
+
* });
|
|
924
|
+
*
|
|
925
|
+
* export const cnApp = (...classes: ClassValues) => {
|
|
926
|
+
* return customCnV4(customTwMerge, ...classes);
|
|
927
|
+
* };
|
|
928
|
+
*
|
|
929
|
+
* // ✅ Usage
|
|
930
|
+
* cnApp("p-2 p-4"); // ➔ "p-4"
|
|
931
|
+
* cnApp("shadow-soft shadow-hard"); // ➔ "shadow-hard"
|
|
932
|
+
* cnApp("text-base text-xxs"); // ➔ "text-xxs" (uses config)
|
|
933
|
+
*
|
|
934
|
+
* // ⚡ Difference with package-level `cn`
|
|
935
|
+
* import { cnV3, cnV4 } from "@rzl-zone/utils-js/tailwind";
|
|
936
|
+
*
|
|
937
|
+
* cnV3("text-base text-xxs");
|
|
938
|
+
* // or
|
|
939
|
+
* cnV4("text-base text-xxs");
|
|
940
|
+
* // ➔ "text-base" (❌ doesn't know about your config)
|
|
941
|
+
*
|
|
942
|
+
* cnApp("text-base text-xxs");
|
|
943
|
+
* // ➔ "text-xxs" (✅ respects config)
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
declare const twMergeDefaultV4: (options?: OptionsMergeTwClsV4) => TwMergeDefaultFnV4;
|
|
947
|
+
export { customCnV4 as a, cnV3 as c, cnVer4 as d, ClassObject as f, cx as h, customCnV3 as i, cnV4 as l, ClassValues as m, twMergeDefaultV3 as n, customCnVer3 as o, ClassValue as p, shouldForwardProp as r, customCnVer4 as s, twMergeDefaultV4 as t, cnVer3 as u };
|