@contember/utilities 1.2.0-rc.0 → 1.2.0-rc.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/dist/development/assert-types/Predicates.js.map +1 -1
- package/dist/development/class-name/colorSchemeClassName.js +16 -0
- package/dist/development/class-name/colorSchemeClassName.js.map +1 -0
- package/dist/development/class-name/constants.js +7 -0
- package/dist/development/class-name/constants.js.map +1 -0
- package/dist/development/class-name/deduplicateClassName.js.map +1 -0
- package/dist/development/class-name/filterThemedClassName.js +68 -0
- package/dist/development/class-name/filterThemedClassName.js.map +1 -0
- package/dist/development/class-name/{Internal/flatClassNameList.js → flatClassNameList.js} +1 -1
- package/dist/development/class-name/flatClassNameList.js.map +1 -0
- package/dist/development/class-name/listClassName.js +2 -2
- package/dist/development/class-name/listClassName.js.map +1 -1
- package/dist/development/class-name/stateClassName.js.map +1 -1
- package/dist/development/class-name/themeClassName.js +18 -0
- package/dist/development/class-name/themeClassName.js.map +1 -0
- package/dist/development/deprecate/currentOrDeprecated.js +20 -0
- package/dist/development/deprecate/currentOrDeprecated.js.map +1 -0
- package/dist/development/deprecate/deprecate.js +6 -0
- package/dist/development/deprecate/deprecate.js.map +1 -0
- package/dist/development/index.js +21 -7
- package/dist/development/index.js.map +1 -1
- package/dist/production/assert-types/Predicates.js.map +1 -1
- package/dist/production/class-name/colorSchemeClassName.js +16 -0
- package/dist/production/class-name/colorSchemeClassName.js.map +1 -0
- package/dist/production/class-name/constants.js +7 -0
- package/dist/production/class-name/constants.js.map +1 -0
- package/dist/production/class-name/deduplicateClassName.js.map +1 -0
- package/dist/production/class-name/filterThemedClassName.js +68 -0
- package/dist/production/class-name/filterThemedClassName.js.map +1 -0
- package/dist/production/class-name/{Internal/flatClassNameList.js → flatClassNameList.js} +1 -1
- package/dist/production/class-name/flatClassNameList.js.map +1 -0
- package/dist/production/class-name/listClassName.js +2 -2
- package/dist/production/class-name/listClassName.js.map +1 -1
- package/dist/production/class-name/stateClassName.js.map +1 -1
- package/dist/production/class-name/themeClassName.js +18 -0
- package/dist/production/class-name/themeClassName.js.map +1 -0
- package/dist/production/deprecate/currentOrDeprecated.js +20 -0
- package/dist/production/deprecate/currentOrDeprecated.js.map +1 -0
- package/dist/production/deprecate/deprecate.js +6 -0
- package/dist/production/deprecate/deprecate.js.map +1 -0
- package/dist/production/index.js +21 -7
- package/dist/production/index.js.map +1 -1
- package/dist/types/assert-types/Predicates.d.ts +1 -1
- package/dist/types/assert-types/Predicates.d.ts.map +1 -1
- package/dist/types/class-name/colorSchemeClassName.d.ts +35 -0
- package/dist/types/class-name/colorSchemeClassName.d.ts.map +1 -0
- package/dist/types/class-name/constants.d.ts +42 -0
- package/dist/types/class-name/constants.d.ts.map +1 -0
- package/dist/types/class-name/deduplicateClassName.d.ts.map +1 -0
- package/dist/types/class-name/filterThemedClassName.d.ts +7 -0
- package/dist/types/class-name/filterThemedClassName.d.ts.map +1 -0
- package/dist/types/class-name/flatClassNameList.d.ts +3 -0
- package/dist/types/class-name/flatClassNameList.d.ts.map +1 -0
- package/dist/types/class-name/index.d.ts +7 -4
- package/dist/types/class-name/index.d.ts.map +1 -1
- package/dist/types/class-name/stateClassName.d.ts +1 -1
- package/dist/types/class-name/themeClassName.d.ts +87 -0
- package/dist/types/class-name/themeClassName.d.ts.map +1 -0
- package/dist/types/class-name/types.d.ts +14 -0
- package/dist/types/class-name/types.d.ts.map +1 -0
- package/dist/types/deprecate/currentOrDeprecated.d.ts +35 -0
- package/dist/types/deprecate/currentOrDeprecated.d.ts.map +1 -0
- package/dist/types/deprecate/deprecate.d.ts +19 -0
- package/dist/types/deprecate/deprecate.d.ts.map +1 -0
- package/dist/types/deprecate/index.d.ts +4 -0
- package/dist/types/deprecate/index.d.ts.map +1 -0
- package/dist/types/deprecate/types.d.ts +2 -0
- package/dist/types/deprecate/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/assert-types/Predicates.ts +1 -1
- package/src/class-name/colorSchemeClassName.ts +46 -0
- package/src/class-name/constants.ts +43 -0
- package/src/class-name/filterThemedClassName.ts +86 -0
- package/src/class-name/{Internal/flatClassNameList.ts → flatClassNameList.ts} +2 -2
- package/src/class-name/index.ts +7 -4
- package/src/class-name/listClassName.ts +2 -2
- package/src/class-name/stateClassName.ts +1 -1
- package/src/class-name/themeClassName.ts +117 -0
- package/src/class-name/types.ts +18 -0
- package/src/deprecate/currentOrDeprecated.ts +51 -0
- package/src/deprecate/deprecate.ts +31 -0
- package/src/deprecate/index.ts +3 -0
- package/src/deprecate/types.ts +2 -0
- package/src/index.ts +1 -0
- package/src/types/index.ts +2 -0
- package/dist/development/class-name/GlobalClassNamePrefixContext.js +0 -6
- package/dist/development/class-name/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/development/class-name/Internal/deduplicateClassName.js.map +0 -1
- package/dist/development/class-name/Internal/flatClassNameList.js.map +0 -1
- package/dist/development/class-name/useClassName.js +0 -18
- package/dist/development/class-name/useClassName.js.map +0 -1
- package/dist/development/class-name/useClassNameFactory.js +0 -21
- package/dist/development/class-name/useClassNameFactory.js.map +0 -1
- package/dist/production/class-name/GlobalClassNamePrefixContext.js +0 -6
- package/dist/production/class-name/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/production/class-name/Internal/deduplicateClassName.js.map +0 -1
- package/dist/production/class-name/Internal/flatClassNameList.js.map +0 -1
- package/dist/production/class-name/useClassName.js +0 -18
- package/dist/production/class-name/useClassName.js.map +0 -1
- package/dist/production/class-name/useClassNameFactory.js +0 -21
- package/dist/production/class-name/useClassNameFactory.js.map +0 -1
- package/dist/types/class-name/GlobalClassNamePrefixContext.d.ts +0 -2
- package/dist/types/class-name/GlobalClassNamePrefixContext.d.ts.map +0 -1
- package/dist/types/class-name/Internal/deduplicateClassName.d.ts.map +0 -1
- package/dist/types/class-name/Internal/flatClassNameList.d.ts +0 -3
- package/dist/types/class-name/Internal/flatClassNameList.d.ts.map +0 -1
- package/dist/types/class-name/Types.d.ts +0 -10
- package/dist/types/class-name/Types.d.ts.map +0 -1
- package/dist/types/class-name/useClassName.d.ts +0 -10
- package/dist/types/class-name/useClassName.d.ts.map +0 -1
- package/dist/types/class-name/useClassNameFactory.d.ts +0 -3
- package/dist/types/class-name/useClassNameFactory.d.ts.map +0 -1
- package/src/class-name/GlobalClassNamePrefixContext.ts +0 -3
- package/src/class-name/Types.ts +0 -9
- package/src/class-name/useClassName.ts +0 -29
- package/src/class-name/useClassNameFactory.ts +0 -31
- /package/dist/development/class-name/{Internal/deduplicateClassName.js → deduplicateClassName.js} +0 -0
- /package/dist/production/class-name/{Internal/deduplicateClassName.js → deduplicateClassName.js} +0 -0
- /package/dist/types/class-name/{Internal/deduplicateClassName.d.ts → deduplicateClassName.d.ts} +0 -0
- /package/src/class-name/{Internal/deduplicateClassName.ts → deduplicateClassName.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Predicates.js","sources":["../../../src/assert-types/Predicates.ts"],"sourcesContent":["import { Predicate, SlugString, UnionOfPredicateTypes } from './types'\n\nexport function isNull(value: unknown): value is null {\n return value === null\n}\nexport function isNotNull<T>(value: unknown): value is T {\n return value !== null\n}\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined\n}\nexport function isDefined<T>(value: unknown): value is T {\n return value !== undefined\n}\nexport function isNotNullish<T>(value: T): value is Exclude<T, null | undefined> {\n return value != null\n}\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean'\n}\nexport function isTrue(value: unknown): value is true {\n return value === true\n}\nexport function isFalse(value: unknown): value is false {\n return value === false\n}\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\nexport function isSlugString(value: unknown): value is SlugString {\n\treturn isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value)\n}\nexport function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value.length > 0\n}\nfunction isNonEmptyTrimmedStringFactory(trim: 'trim' | 'trimStart' | 'trimEnd' = 'trim') {\n return function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value[trim]().length > 0\n }\n}\nexport const isNonEmptyTrimmedString = isNonEmptyTrimmedStringFactory()\nexport const isNonEmptyTrimmedStartString = isNonEmptyTrimmedStringFactory('trimStart')\nexport const isNonEmptyTrimmedEndString = isNonEmptyTrimmedStringFactory('trimEnd')\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && value === value\n}\nexport function isNonNegativeNumber(value: unknown): value is number {\n return isNumber(value) && value >= 0\n}\nexport function isNumericString(value: string): value is string {\n return isString(value) && !isNaN(parseFloat(value))\n}\nexport function isOneOfFactory<U, T = any>(\n\tmembers: T extends Array<U> | ReadonlyArray<U> ? T : never,\n): (value: unknown) => value is U {\n\treturn function isOneOfFactoryProduct(value: unknown): value is U {\n\t\treturn members.includes(value as U)\n\t}\n}\nexport function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(\n\t...predicates: T\n): Predicate<unknown, UnionOfPredicateTypes<T>> {\n\treturn (value: any): value is UnionOfPredicateTypes<T> => {\n\t\treturn predicates.some(predicate => predicate(value))\n\t}\n}\nexport function isArrayOfMembersSatisfyingFactory<T>(\n\tpredicate: (value: unknown) => value is T,\n): (value: unknown) => value is Array<T> {\n\treturn function isArrayOfMembersSatisfyingProduct(value: unknown): value is Array<T> {\n\t\treturn Array.isArray(value) && value.every(predicate)\n\t}\n}\nexport function isHTMLElement(value: unknown): value is HTMLElement {\n return value instanceof HTMLElement\n}\nexport function isObject(value: unknown): value is Object {\n return typeof value === 'object' && value !== null\n}\nexport function isPlainObject<T extends Record<string, unknown>>(value: unknown): value is T {\n return isObject(value) && value.constructor === Object\n}\n"],"names":["isNonEmptyString"],"mappings":"AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAA4B;AACvD,SAAO,UAAU;AACnB;AACO,SAAS,YAAY,OAAoC;AAC9D,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,
|
|
1
|
+
{"version":3,"file":"Predicates.js","sources":["../../../src/assert-types/Predicates.ts"],"sourcesContent":["import { Predicate, SlugString, UnionOfPredicateTypes } from './types'\n\nexport function isNull(value: unknown): value is null {\n return value === null\n}\nexport function isNotNull<T>(value: unknown): value is T {\n return value !== null\n}\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined\n}\nexport function isDefined<T>(value: unknown): value is Exclude<T, undefined> {\n return value !== undefined\n}\nexport function isNotNullish<T>(value: T): value is Exclude<T, null | undefined> {\n return value != null\n}\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean'\n}\nexport function isTrue(value: unknown): value is true {\n return value === true\n}\nexport function isFalse(value: unknown): value is false {\n return value === false\n}\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\nexport function isSlugString(value: unknown): value is SlugString {\n\treturn isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value)\n}\nexport function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value.length > 0\n}\nfunction isNonEmptyTrimmedStringFactory(trim: 'trim' | 'trimStart' | 'trimEnd' = 'trim') {\n return function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value[trim]().length > 0\n }\n}\nexport const isNonEmptyTrimmedString = isNonEmptyTrimmedStringFactory()\nexport const isNonEmptyTrimmedStartString = isNonEmptyTrimmedStringFactory('trimStart')\nexport const isNonEmptyTrimmedEndString = isNonEmptyTrimmedStringFactory('trimEnd')\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && value === value\n}\nexport function isNonNegativeNumber(value: unknown): value is number {\n return isNumber(value) && value >= 0\n}\nexport function isNumericString(value: string): value is string {\n return isString(value) && !isNaN(parseFloat(value))\n}\nexport function isOneOfFactory<U, T = any>(\n\tmembers: T extends Array<U> | ReadonlyArray<U> ? T : never,\n): (value: unknown) => value is U {\n\treturn function isOneOfFactoryProduct(value: unknown): value is U {\n\t\treturn members.includes(value as U)\n\t}\n}\nexport function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(\n\t...predicates: T\n): Predicate<unknown, UnionOfPredicateTypes<T>> {\n\treturn (value: any): value is UnionOfPredicateTypes<T> => {\n\t\treturn predicates.some(predicate => predicate(value))\n\t}\n}\nexport function isArrayOfMembersSatisfyingFactory<T>(\n\tpredicate: (value: unknown) => value is T,\n): (value: unknown) => value is Array<T> {\n\treturn function isArrayOfMembersSatisfyingProduct(value: unknown): value is Array<T> {\n\t\treturn Array.isArray(value) && value.every(predicate)\n\t}\n}\nexport function isHTMLElement(value: unknown): value is HTMLElement {\n return value instanceof HTMLElement\n}\nexport function isObject(value: unknown): value is Object {\n return typeof value === 'object' && value !== null\n}\nexport function isPlainObject<T extends Record<string, unknown>>(value: unknown): value is T {\n return isObject(value) && value.constructor === Object\n}\n"],"names":["isNonEmptyString"],"mappings":"AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAA4B;AACvD,SAAO,UAAU;AACnB;AACO,SAAS,YAAY,OAAoC;AAC9D,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAAgD;AAC3E,SAAO,UAAU;AACnB;AACO,SAAS,aAAgB,OAAiD;AAC/E,SAAO,SAAS;AAClB;AACO,SAAS,UAAU,OAAkC;AAC1D,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,QAAQ,OAAgC;AACtD,SAAO,UAAU;AACnB;AACO,SAAS,SAAS,OAAiC;AACxD,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,aAAa,OAAqC;AACjE,SAAO,iBAAiB,KAAK,KAAK,gBAAgB,KAAK,KAAK;AAC7D;AACO,SAAS,iBAAiB,OAAiC;AAChE,SAAO,SAAS,KAAK,KAAK,MAAM,SAAS;AAC3C;AACA,SAAS,+BAA+B,OAAyC,QAAQ;AAChF,SAAA,SAASA,kBAAiB,OAAiC;AAChE,WAAO,SAAS,KAAK,KAAK,MAAM,IAAI,IAAI,SAAS;AAAA,EAAA;AAErD;AACO,MAAM,0BAA0B,+BAA+B;AACzD,MAAA,+BAA+B,+BAA+B,WAAW;AACzE,MAAA,6BAA6B,+BAA+B,SAAS;AAC3E,SAAS,SAAS,OAAiC;AACjD,SAAA,OAAO,UAAU,YAAY,UAAU;AAChD;AACO,SAAS,oBAAoB,OAAiC;AAC5D,SAAA,SAAS,KAAK,KAAK,SAAS;AACrC;AACO,SAAS,gBAAgB,OAAgC;AAC9D,SAAO,SAAS,KAAK,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC;AACpD;AACO,SAAS,eACf,SACiC;AAC1B,SAAA,SAAS,sBAAsB,OAA4B;AAC1D,WAAA,QAAQ,SAAS,KAAU;AAAA,EAAA;AAEpC;AACO,SAAS,yBACZ,YAC4C;AAC/C,SAAO,CAAC,UAAkD;AACzD,WAAO,WAAW,KAAK,CAAa,cAAA,UAAU,KAAK,CAAC;AAAA,EAAA;AAEtD;AACO,SAAS,kCACf,WACwC;AACjC,SAAA,SAAS,kCAAkC,OAAmC;AACpF,WAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,SAAS;AAAA,EAAA;AAEtD;AACO,SAAS,cAAc,OAAsC;AAClE,SAAO,iBAAiB;AAC1B;AACO,SAAS,SAAS,OAAiC;AACjD,SAAA,OAAO,UAAU,YAAY,UAAU;AAChD;AACO,SAAS,cAAiD,OAA4B;AAC3F,SAAO,SAAS,KAAK,KAAK,MAAM,gBAAgB;AAClD;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { COLOR_SCHEME_CLASS_NAME_REG_EXP } from "./constants.js";
|
|
2
|
+
function colorSchemeClassName(scheme) {
|
|
3
|
+
if (typeof scheme === "string") {
|
|
4
|
+
return `scheme-${scheme}`;
|
|
5
|
+
} else {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function isColorSchemeClassName(value) {
|
|
10
|
+
return COLOR_SCHEME_CLASS_NAME_REG_EXP.test(value);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
colorSchemeClassName,
|
|
14
|
+
isColorSchemeClassName
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=colorSchemeClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorSchemeClassName.js","sources":["../../../src/class-name/colorSchemeClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { COLOR_SCHEME_CLASS_NAME_REG_EXP } from './constants'\nimport { ColorSchemeClassName } from './types'\n\n/**\n * Returns a string with a color scheme class name, prefixed with `scheme-`\n *\n * @param scheme - Color scheme name\n * @returns A color scheme class name\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n *\n * return (\n * \t<div className={colorScheme}>\n * \t\t<button className={controlsThemeClassName}>Click me</button>\n * \t</div>\n *\n * // renders:\n * // <div class=\"scheme-system\">\n * // \t<button class=\"scheme-system theme-default-controls theme-danger-controls:hover\">Click me</button>\n * // </div>\n * ```\n */\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S): ColorSchemeClassName<S>;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: null | undefined): undefined;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S | null | undefined): ColorSchemeClassName<S> | undefined;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S | null | undefined): ColorSchemeClassName<S> | undefined {\n\tif (typeof scheme === 'string') {\n\t\treturn `scheme-${scheme}`\n\t} else {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Tests if a string is a color scheme CSS class\n * @param value - String to test\n * @returns `true` if the string is a color scheme CSS class\n * @internal\n */\nexport function isColorSchemeClassName<T extends string>(value: string): value is ColorSchemeClassName<T> {\n\treturn COLOR_SCHEME_CLASS_NAME_REG_EXP.test(value)\n}\n"],"names":[],"mappings":";AA6BO,SAAS,qBAAsE,QAAmE;AACpJ,MAAA,OAAO,WAAW,UAAU;AAC/B,WAAO,UAAU;AAAA,EAAA,OACX;AACC,WAAA;AAAA,EACR;AACD;AAQO,SAAS,uBAAyC,OAAiD;AAClG,SAAA,gCAAgC,KAAK,KAAK;AAClD;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const THEME_CLASS_NAME_REG_EXP = /^theme-(?<name>[\w-]+?)(?:-(?<scope>content|controls))?(?<state>:[\w]+(?:[\w-]+)?)?$/;
|
|
2
|
+
const COLOR_SCHEME_CLASS_NAME_REG_EXP = /^scheme-(?<colorScheme>[a-z0-9]|[a-z0-9]+[a-z-]+[a-z])$/;
|
|
3
|
+
export {
|
|
4
|
+
COLOR_SCHEME_CLASS_NAME_REG_EXP,
|
|
5
|
+
THEME_CLASS_NAME_REG_EXP
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/class-name/constants.ts"],"sourcesContent":["/**\n * RegExp that matches theme class names\n *\n * @internal\n *\n * If theme is `default` then it will match:\n *\n * - theme-default\n * - theme-default:hover\n * - theme-default:active\n * - theme-default:focus\n * - theme-default-content\n * - theme-default-content:hover\n * - theme-default-content:active\n * - theme-default-content:focus\n * - theme-default-controls\n * - theme-default-controls:hover\n * - theme-default-controls:active\n * - theme-default-controls:focus\n *\n * If theme is `brand-color` then it will match:\n *\n * - theme-brand-color\n * - theme-brand-color:hover\n * - theme-brand-color:active\n * - theme-brand-color:focus\n * - theme-brand-color-content\n * - theme-brand-color-content:hover\n * - theme-brand-color-content:active\n * - theme-brand-color-content:focus\n * - theme-brand-color-controls\n * - theme-brand-color-controls:hover\n * - theme-brand-color-controls:active\n * - theme-brand-color-controls:focus\n */\n\nexport const THEME_CLASS_NAME_REG_EXP = /^theme-(?<name>[\\w-]+?)(?:-(?<scope>content|controls))?(?<state>:[\\w]+(?:[\\w-]+)?)?$/\n\n/**\n * Regular expression for testing if a string is a color scheme CSS class\n * @internal\n */\nexport const COLOR_SCHEME_CLASS_NAME_REG_EXP = /^scheme-(?<colorScheme>[a-z0-9]|[a-z0-9]+[a-z-]+[a-z])$/\n"],"names":[],"mappings":"AAoCO,MAAM,2BAA2B;AAMjC,MAAM,kCAAkC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduplicateClassName.js","sources":["../../../src/class-name/deduplicateClassName.ts"],"sourcesContent":["export function deduplicateClassName(classNameArray: string[]): string[] {\n\treturn [...new Set(classNameArray)]\n}\n"],"names":[],"mappings":"AAAO,SAAS,qBAAqB,gBAAoC;AACxE,SAAO,CAAC,GAAG,IAAI,IAAI,cAAc,CAAC;AACnC;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isColorSchemeClassName } from "./colorSchemeClassName.js";
|
|
2
|
+
import { THEME_CLASS_NAME_REG_EXP } from "./constants.js";
|
|
3
|
+
import { flatClassNameList } from "./flatClassNameList.js";
|
|
4
|
+
import { contentThemeClassName, controlsThemeClassName } from "./themeClassName.js";
|
|
5
|
+
function filterThemedClassName(nestedClassName, defaultColorSchemeContext) {
|
|
6
|
+
const theme = { content: void 0, controls: void 0 };
|
|
7
|
+
const stateThemes = {};
|
|
8
|
+
let colorScheme = void 0;
|
|
9
|
+
const flatClassName = flatClassNameList(nestedClassName).map((className) => {
|
|
10
|
+
if (isColorSchemeClassName(className)) {
|
|
11
|
+
colorScheme = className;
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
const match = className.match(THEME_CLASS_NAME_REG_EXP);
|
|
15
|
+
if (match) {
|
|
16
|
+
const name = match.groups.name;
|
|
17
|
+
const scope = match.groups.scope;
|
|
18
|
+
const state = match.groups.state;
|
|
19
|
+
if (state) {
|
|
20
|
+
stateThemes[state] = stateThemes[state] ?? { content: void 0, controls: void 0 };
|
|
21
|
+
if (!scope) {
|
|
22
|
+
stateThemes[state].content = name;
|
|
23
|
+
stateThemes[state].controls = name;
|
|
24
|
+
} else if (scope === "content") {
|
|
25
|
+
stateThemes[state].content = name;
|
|
26
|
+
} else if (scope === "controls") {
|
|
27
|
+
stateThemes[state].controls = name;
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error(`Unknown theme scope: ${scope}`);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
if (!scope) {
|
|
33
|
+
theme.content = name;
|
|
34
|
+
theme.controls = name;
|
|
35
|
+
} else if (scope === "content") {
|
|
36
|
+
theme.content = name;
|
|
37
|
+
} else if (scope === "controls") {
|
|
38
|
+
theme.controls = name;
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error(`Unknown theme scope: ${scope}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
} else {
|
|
45
|
+
return className;
|
|
46
|
+
}
|
|
47
|
+
}).filter(Boolean);
|
|
48
|
+
const themeClassNames = [];
|
|
49
|
+
const content = contentThemeClassName(theme.content);
|
|
50
|
+
const controls = controlsThemeClassName(theme.controls);
|
|
51
|
+
themeClassNames.push(content, controls);
|
|
52
|
+
for (const state in stateThemes) {
|
|
53
|
+
const { content: content2, controls: controls2 } = stateThemes[state];
|
|
54
|
+
const contentClassName = contentThemeClassName(content2, state);
|
|
55
|
+
const controlsClassName = controlsThemeClassName(controls2, state);
|
|
56
|
+
themeClassNames.push(contentClassName, controlsClassName);
|
|
57
|
+
}
|
|
58
|
+
const flatThemedClassName = flatClassNameList(themeClassNames);
|
|
59
|
+
if (flatThemedClassName.length > 0 || colorScheme) {
|
|
60
|
+
return [colorScheme ?? defaultColorSchemeContext, ...flatThemedClassName, ...flatClassName];
|
|
61
|
+
} else {
|
|
62
|
+
return flatClassName;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
filterThemedClassName
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=filterThemedClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterThemedClassName.js","sources":["../../../src/class-name/filterThemedClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { isColorSchemeClassName } from './colorSchemeClassName'\nimport { THEME_CLASS_NAME_REG_EXP } from './constants'\nimport { flatClassNameList } from './flatClassNameList'\nimport { contentThemeClassName, controlsThemeClassName } from './themeClassName'\nimport { ColorSchemeClassName, NestedClassName } from './types'\n\nexport type ThemeConfig = { content: string | undefined, controls: string | undefined }\n\nexport function filterThemedClassName(\n\tnestedClassName: NestedClassName,\n\tdefaultColorSchemeContext: ColorSchemeClassName,\n) {\n\tconst theme: ThemeConfig = { content: undefined, controls: undefined }\n\tconst stateThemes: Record<string, ThemeConfig> = {}\n\tlet colorScheme: ColorSchemeClassName | undefined = undefined\n\n\tconst flatClassName = flatClassNameList(nestedClassName).map(className => {\n\t\tif (isColorSchemeClassName(className)) {\n\t\t\tcolorScheme = className\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst match = className.match(THEME_CLASS_NAME_REG_EXP)\n\n\t\tif (match) {\n\t\t\tconst name = match.groups!.name as KebabCase<string>\n\t\t\tconst scope = match.groups!.scope as KebabCase<string>\n\t\t\tconst state = match.groups!.state as `:${KebabCase<string>}`\n\n\t\t\tif (state) {\n\t\t\t\tstateThemes[state] = stateThemes[state] ?? { content: undefined, controls: undefined }\n\n\t\t\t\tif (!scope) {\n\t\t\t\t\tstateThemes[state].content = name\n\t\t\t\t\tstateThemes[state].controls = name\n\t\t\t\t} else if (scope === 'content') {\n\t\t\t\t\tstateThemes[state].content = name\n\t\t\t\t} else if (scope === 'controls') {\n\t\t\t\t\tstateThemes[state].controls = name\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Unknown theme scope: ${scope}`)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!scope) {\n\t\t\t\t\ttheme.content = name\n\t\t\t\t\ttheme.controls = name\n\t\t\t\t} else if (scope === 'content') {\n\t\t\t\t\ttheme.content = name\n\t\t\t\t} else if (scope === 'controls') {\n\t\t\t\t\ttheme.controls = name\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Unknown theme scope: ${scope}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn undefined\n\t\t} else {\n\t\t\treturn className\n\t\t}\n\t}).filter(Boolean) as string[]\n\n\tconst themeClassNames: (string | undefined)[] = []\n\n\tconst content = contentThemeClassName(theme.content)\n\tconst controls = controlsThemeClassName(theme.controls)\n\n\tthemeClassNames.push(content, controls)\n\n\tfor (const state in stateThemes) {\n\t\tconst { content, controls } = stateThemes[state]\n\n\t\tconst contentClassName = contentThemeClassName(content, state as `:${KebabCase<string>}`)\n\t\tconst controlsClassName = controlsThemeClassName(controls, state as `:${KebabCase<string>}`)\n\n\t\tthemeClassNames.push(contentClassName, controlsClassName)\n\t}\n\n\tconst flatThemedClassName = flatClassNameList(themeClassNames)\n\n\tif (flatThemedClassName.length > 0 || colorScheme) {\n\t\treturn [colorScheme ?? defaultColorSchemeContext, ...flatThemedClassName, ...flatClassName]\n\t} else {\n\t\treturn flatClassName\n\t}\n}\n"],"names":["content","controls"],"mappings":";;;;AASgB,SAAA,sBACf,iBACA,2BACC;AACD,QAAM,QAAqB,EAAE,SAAS,QAAW,UAAU;AAC3D,QAAM,cAA2C,CAAA;AACjD,MAAI,cAAgD;AAEpD,QAAM,gBAAgB,kBAAkB,eAAe,EAAE,IAAI,CAAa,cAAA;AACrE,QAAA,uBAAuB,SAAS,GAAG;AACxB,oBAAA;AACP,aAAA;AAAA,IACR;AAEM,UAAA,QAAQ,UAAU,MAAM,wBAAwB;AAEtD,QAAI,OAAO;AACJ,YAAA,OAAO,MAAM,OAAQ;AACrB,YAAA,QAAQ,MAAM,OAAQ;AACtB,YAAA,QAAQ,MAAM,OAAQ;AAE5B,UAAI,OAAO;AACE,oBAAA,KAAK,IAAI,YAAY,KAAK,KAAK,EAAE,SAAS,QAAW,UAAU,OAAU;AAErF,YAAI,CAAC,OAAO;AACC,sBAAA,KAAK,EAAE,UAAU;AACjB,sBAAA,KAAK,EAAE,WAAW;AAAA,QAAA,WACpB,UAAU,WAAW;AACnB,sBAAA,KAAK,EAAE,UAAU;AAAA,QAAA,WACnB,UAAU,YAAY;AACpB,sBAAA,KAAK,EAAE,WAAW;AAAA,QAAA,OACxB;AACA,gBAAA,IAAI,MAAM,wBAAwB,OAAO;AAAA,QAChD;AAAA,MAAA,OACM;AACN,YAAI,CAAC,OAAO;AACX,gBAAM,UAAU;AAChB,gBAAM,WAAW;AAAA,QAAA,WACP,UAAU,WAAW;AAC/B,gBAAM,UAAU;AAAA,QAAA,WACN,UAAU,YAAY;AAChC,gBAAM,WAAW;AAAA,QAAA,OACX;AACA,gBAAA,IAAI,MAAM,wBAAwB,OAAO;AAAA,QAChD;AAAA,MACD;AAEO,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IACR;AAAA,EAAA,CACA,EAAE,OAAO,OAAO;AAEjB,QAAM,kBAA0C,CAAA;AAE1C,QAAA,UAAU,sBAAsB,MAAM,OAAO;AAC7C,QAAA,WAAW,uBAAuB,MAAM,QAAQ;AAEtC,kBAAA,KAAK,SAAS,QAAQ;AAEtC,aAAW,SAAS,aAAa;AAChC,UAAM,EAAE,SAAAA,UAAS,UAAAC,cAAa,YAAY,KAAK;AAEzC,UAAA,mBAAmB,sBAAsBD,UAAS,KAAgC;AAClF,UAAA,oBAAoB,uBAAuBC,WAAU,KAAgC;AAE3E,oBAAA,KAAK,kBAAkB,iBAAiB;AAAA,EACzD;AAEM,QAAA,sBAAsB,kBAAkB,eAAe;AAEzD,MAAA,oBAAoB,SAAS,KAAK,aAAa;AAClD,WAAO,CAAC,eAAe,2BAA2B,GAAG,qBAAqB,GAAG,aAAa;AAAA,EAAA,OACpF;AACC,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatClassNameList.js","sources":["../../../src/class-name/flatClassNameList.ts"],"sourcesContent":["import { assertNever } from '../assert-types'\nimport { NestedClassName } from './types'\n\nexport function flatClassNameList(className: NestedClassName): string[] {\n\tif (!className) {\n\t\treturn []\n\t} else if (typeof className === 'string') {\n\t\treturn className.split(' ').filter(Boolean)\n\t} else if (Array.isArray(className)) {\n\t\treturn className.flatMap(flatClassNameList)\n\t} else {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconsole.error(`Unexpected className: ${JSON.stringify(className)}`)\n\t\t}\n\n\t\tassertNever(className)\n\t}\n}\n"],"names":[],"mappings":";AAGO,SAAS,kBAAkB,WAAsC;AACvE,MAAI,CAAC,WAAW;AACf,WAAO;EAAC,WACE,OAAO,cAAc,UAAU;AACzC,WAAO,UAAU,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAChC,WAAA,MAAM,QAAQ,SAAS,GAAG;AAC7B,WAAA,UAAU,QAAQ,iBAAiB;AAAA,EAAA,OACpC;AAKN,gBAAqB;AAAA,EACtB;AACD;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { deduplicateClassName } from "./
|
|
2
|
-
import { flatClassNameList } from "./
|
|
1
|
+
import { deduplicateClassName } from "./deduplicateClassName.js";
|
|
2
|
+
import { flatClassNameList } from "./flatClassNameList.js";
|
|
3
3
|
function listClassName(list) {
|
|
4
4
|
return deduplicateClassName(flatClassNameList(list)).join(" ");
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listClassName.js","sources":["../../../src/class-name/listClassName.ts"],"sourcesContent":["import { deduplicateClassName } from './
|
|
1
|
+
{"version":3,"file":"listClassName.js","sources":["../../../src/class-name/listClassName.ts"],"sourcesContent":["import { deduplicateClassName } from './deduplicateClassName'\nimport { flatClassNameList } from './flatClassNameList'\n\n/**\n * Combines a list of class names into a single string, even nested\n *\n * @param list - List of class names\n * @returns Combined class names as string\n */\nexport function listClassName(list: (string | false | null | undefined)[]) {\n\treturn deduplicateClassName(flatClassNameList(list)).join(' ')\n}\n"],"names":[],"mappings":";;AASO,SAAS,cAAc,MAA6C;AAC1E,SAAO,qBAAqB,kBAAkB,IAAI,CAAC,EAAE,KAAK,GAAG;AAC9D;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateClassName.js","sources":["../../../src/class-name/stateClassName.ts"],"sourcesContent":["import { toKebabCase } from '../string-utilities'\nimport { ClassNameStateMap } from './
|
|
1
|
+
{"version":3,"file":"stateClassName.js","sources":["../../../src/class-name/stateClassName.ts"],"sourcesContent":["import { toKebabCase } from '../string-utilities'\nimport { ClassNameStateMap } from './types'\n\nexport interface StateClassNameOptions {\n\tglue?: string;\n\tremoveFalsy?: boolean;\n}\n\n/**\n * Combines a state map of class names into a single string\n *\n * @example\n * stateClassName({ foo: true, bar: false, baz: 1 }) // => 'foo baz-1'\n *\n * @param state - State map object with class names as keys and literals as values.\n * @param options - Options object\n * @param options.glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.\n * @param options.removeFalsy - Whether to remove falsy class names, default is true.\n * @returns Combined class names as string\n */\nexport function stateClassName(\n\tstate: ClassNameStateMap | null = null,\n\t{ glue = '-', removeFalsy = true }: StateClassNameOptions = {},\n): string[] {\n\tconst entries = Object.entries(state ?? []).map(\n\t\t([className, value]) => value || value === 0 || !removeFalsy\n\t\t\t? (value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}`)\n\t\t\t: '',\n\t).filter(Boolean)\n\n\treturn entries\n}\n"],"names":[],"mappings":";AAoBgB,SAAA,eACf,QAAkC,MAClC,EAAE,OAAO,KAAK,cAAc,KAAgC,IAAA,IACjD;AACX,QAAM,UAAU,OAAO,QAAQ,SAAS,CAAA,CAAE,EAAE;AAAA,IAC3C,CAAC,CAAC,WAAW,KAAK,MAAM,SAAS,UAAU,KAAK,CAAC,cAC7C,UAAU,OAAO,YAAY,SAAS,IAAI,GAAG,YAAY,SAAS,IAAI,OAAO,UAC9E;AAAA,EAAA,EACF,OAAO,OAAO;AAET,SAAA;AACR;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function contentThemeClassName(theme, state) {
|
|
2
|
+
return theme ? `theme-${theme}-content${state ?? ""}` : void 0;
|
|
3
|
+
}
|
|
4
|
+
function controlsThemeClassName(theme, state) {
|
|
5
|
+
return theme ? `theme-${theme}-controls${state ?? ""}` : void 0;
|
|
6
|
+
}
|
|
7
|
+
function themeClassName(theme, state) {
|
|
8
|
+
return [
|
|
9
|
+
contentThemeClassName(theme, state),
|
|
10
|
+
controlsThemeClassName(theme, state)
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
contentThemeClassName,
|
|
15
|
+
controlsThemeClassName,
|
|
16
|
+
themeClassName
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=themeClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeClassName.js","sources":["../../../src/class-name/themeClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { colorSchemeClassName } from './colorSchemeClassName'\nimport { ThemeContentClassName, ThemeControlsClassName } from './types'\n\n/**\n * Returns a string with a content theme class name, prefixed with `theme-` and suffixed with `-content`\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param contentTheme - Theme name basis for content\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A content theme class name\n *\n * @see {@link controlsThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const contentThemeClassName = contentThemeClassName('default')\n * // ^ 'theme-default-content:hover'\n * const dangerOnMouseOverTheme = controlsThemeClassName('danger', ':hover')\n * // ^ 'theme-danger-controls:hover'\n *\n * return (\n * \t<div className={`${colorScheme} ${contentThemeClassName}`}>\n * \t\t<button className={`${colorScheme} ${dangerOnMouseOverTheme}`}>Delete</button>\n * \t</div>\n * )\n * ```\n */\nexport function contentThemeClassName<\n\tContentTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\ttheme: ContentTheme | null | undefined,\n\tstate?: State | null | undefined,\n) {\n\treturn theme ? `theme-${theme}-content${state ?? ''}` as ThemeContentClassName<ContentTheme, State> : undefined\n}\n\n/**\n * Returns a string with a controls theme class name, prefixed with `theme-` and suffixed with `-controls`\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param theme - Theme name basis for controls\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A controls theme class name\n *\n * @see {@link contentThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const contentThemeClassName = contentThemeClassName('default')\n * // ^ 'theme-default-content:hover'\n * const dangerOnMouseOverTheme = controlsThemeClassName('danger', ':hover')\n * // ^ 'theme-danger-controls:hover'\n *\n * return (\n * \t<div className={`${colorScheme} ${contentThemeClassName}`}>\n * \t\t<button className={`${colorScheme} ${dangerOnMouseOverTheme}`}>Delete</button>\n * \t</div>\n * )\n * ```\n */\nexport function controlsThemeClassName<\n\tControlsTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\ttheme: ControlsTheme | null | undefined,\n\tstate?: State | null | undefined,\n) {\n\treturn theme ? `theme-${theme}-controls${state ?? ''}` as ThemeControlsClassName<ControlsTheme, State> : undefined\n}\n\n/**\n * Returns a tuple with a content theme class name and a controls theme class name, prefixed with `theme-` and suffixed with `-content` and `-controls` respectively\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param theme - Theme name basis for content and controls\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A tuple with a content theme class name and a controls theme class name\n *\n * @see {@link contentThemeClassName}\n * @see {@link controlsThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const errorTheme = themeClassName('danger').join(' ')\n * // ^ 'theme-danger-content theme-danger-controls'\n *\n * return (\n * \t<div className={`${colorScheme} ${errorTheme}`}>File not found</div>\n * )\n * ```\n */\nexport function themeClassName<\n\tTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\t\ttheme: Theme | null | undefined,\n\t\tstate?: State | null | undefined,\n) {\n\treturn [\n\t\tcontentThemeClassName(theme, state),\n\t\tcontrolsThemeClassName(theme, state),\n\t] as const\n}\n"],"names":[],"mappings":"AAgCgB,SAAA,sBAIf,OACA,OACC;AACD,SAAO,QAAQ,SAAS,gBAAgB,SAAS,OAAqD;AACvG;AA8BgB,SAAA,uBAIf,OACA,OACC;AACD,SAAO,QAAQ,SAAS,iBAAiB,SAAS,OAAuD;AAC1G;AA2BgB,SAAA,eAId,OACA,OACA;AACM,SAAA;AAAA,IACN,sBAAsB,OAAO,KAAK;AAAA,IAClC,uBAAuB,OAAO,KAAK;AAAA,EAAA;AAErC;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function currentOrDeprecated(current, deprecated, shouldThrow = false) {
|
|
2
|
+
if (deprecated !== void 0) {
|
|
3
|
+
if (current !== void 0 && false) {
|
|
4
|
+
console.error("Current value:", current);
|
|
5
|
+
console.error("Deprecated value:", deprecated);
|
|
6
|
+
if (shouldThrow) {
|
|
7
|
+
throw new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
|
|
8
|
+
} else {
|
|
9
|
+
console.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return deprecated;
|
|
13
|
+
} else {
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
currentOrDeprecated
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=currentOrDeprecated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currentOrDeprecated.js","sources":["../../../src/deprecate/currentOrDeprecated.ts"],"sourcesContent":["/**\n * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.\n *\n * @internal\n *\n * Errors are thrown only in development mode. In production mode, the deprecated value is returned.\n *\n * @param current - Current value that replaces deprecated value\n * @param deprecated - Deprecated value that will be removed in the next release\n * @param shouldThrow - Whether to throw an error if both current and deprecated are defined\n * @returns Deprecated value if it is defined, otherwise current value\n * @throws Error if both current and deprecated are defined\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = 'deprecated'\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'deprecated'\n * ```\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = undefined\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'current'\n * ```\n */\nexport function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow: boolean = false): R | D {\n\tif (deprecated !== undefined) {\n\t\tif (current !== undefined && import.meta.env.DEV) {\n\t\t\tconsole.error('Current value:', current)\n\t\t\tconsole.error('Deprecated value:', deprecated)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t} else {\n\t\t\t\tconsole.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t}\n\t\t}\n\n\t\treturn deprecated\n\t} else {\n\t\treturn current\n\t}\n}\n"],"names":[],"mappings":"AAiCO,SAAS,oBAA0B,SAAY,YAAe,cAAuB,OAAc;AACzG,MAAI,eAAe,QAAW;AAC7B,QAAI,YAAY,UAAa,OAAqB;AACzC,cAAA,MAAM,kBAAkB,OAAO;AAC/B,cAAA,MAAM,qBAAqB,UAAU;AAE7C,UAAI,aAAa;AACV,cAAA,IAAI,MAAM,yGAAyG;AAAA,MAAA,OACnH;AACN,gBAAQ,MAAM,yGAAyG;AAAA,MACxH;AAAA,IACD;AAEO,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate.js","sources":["../../../src/deprecate/deprecate.ts"],"sourcesContent":["import { SemverString } from './types'\n\n/**\n * Logs a deprecation warning if the assertion is `false`.\n * @internal\n *\n * @param removal - Version when the deprecated feature will be removed\n * @param assertion - Condition that must be true to avoid the deprecation warning\n * @param deprecated - Name of the deprecated feature\n * @param replacement - Name of the feature that replaces the deprecated feature\n *\n * @example\n * ```ts\n * const { visible } = props\n * deprecate(visible !== 'default', '1.3.0', '\"default\"', '\"hidden\"')\n * // Logs: Use of \"default\" is deprecated and might be removed in the next release. Use \"hidden\" instead.\n * ```\n */\nexport function deprecate(removal: SemverString, assertion: boolean, deprecated: string, replacement: string): void {\n\tif (assertion === false) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst shouldThrow = Boolean(import.meta.env.VITE_CONTEMBER_ADMIN_STRICT_DEPRECATIONS)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`Support for ${deprecated} was planned to be removed in the ${removal} release. Replace it with ${replacement} instead.`)\n\t\t\t} else {\n\t\t\t\tconsole.warn(`Use of ${deprecated} is deprecated and might be removed in the next release. Use ${replacement} instead.`)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAkBO,SAAS,UAAU,SAAuB,WAAoB,YAAoB,aAA2B;AAYpH;"}
|
|
@@ -2,12 +2,17 @@ import { AssertionError } from "./assert-types/AssertionError.js";
|
|
|
2
2
|
import { isArrayOfMembersSatisfyingFactory, isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isSlugString, isString, isTrue, isUndefined, satisfiesOneOfFactory } from "./assert-types/Predicates.js";
|
|
3
3
|
import { assert } from "./assert-types/assert.js";
|
|
4
4
|
import { assertNever } from "./assert-types/assertNever.js";
|
|
5
|
-
import {
|
|
5
|
+
import { colorSchemeClassName, isColorSchemeClassName } from "./class-name/colorSchemeClassName.js";
|
|
6
|
+
import { COLOR_SCHEME_CLASS_NAME_REG_EXP, THEME_CLASS_NAME_REG_EXP } from "./class-name/constants.js";
|
|
7
|
+
import { deduplicateClassName } from "./class-name/deduplicateClassName.js";
|
|
8
|
+
import { filterThemedClassName } from "./class-name/filterThemedClassName.js";
|
|
9
|
+
import { flatClassNameList } from "./class-name/flatClassNameList.js";
|
|
6
10
|
import { listClassName } from "./class-name/listClassName.js";
|
|
7
11
|
import { stateClassName } from "./class-name/stateClassName.js";
|
|
8
|
-
import {
|
|
9
|
-
import { useClassNameFactory } from "./class-name/useClassNameFactory.js";
|
|
12
|
+
import { contentThemeClassName, controlsThemeClassName, themeClassName } from "./class-name/themeClassName.js";
|
|
10
13
|
import { px } from "./css-utilities/px.js";
|
|
14
|
+
import { currentOrDeprecated } from "./deprecate/currentOrDeprecated.js";
|
|
15
|
+
import { deprecate } from "./deprecate/deprecate.js";
|
|
11
16
|
import { dataAttribute } from "./dom/dataAttribute.js";
|
|
12
17
|
import { getMatchingParentElement } from "./dom/getMatchingParentElement.js";
|
|
13
18
|
import { getSizeFromResizeObserverEntryFactory } from "./dom/getSizeFromResizeObserverEntry.js";
|
|
@@ -23,15 +28,25 @@ import { toKebabCase } from "./string-utilities/kebabCase.js";
|
|
|
23
28
|
import { trimString } from "./string-utilities/trimString.js";
|
|
24
29
|
export {
|
|
25
30
|
AssertionError,
|
|
26
|
-
|
|
31
|
+
COLOR_SCHEME_CLASS_NAME_REG_EXP,
|
|
32
|
+
THEME_CLASS_NAME_REG_EXP,
|
|
27
33
|
assert,
|
|
28
34
|
assertNever,
|
|
29
35
|
capitalize,
|
|
36
|
+
colorSchemeClassName,
|
|
37
|
+
contentThemeClassName,
|
|
38
|
+
controlsThemeClassName,
|
|
39
|
+
currentOrDeprecated,
|
|
30
40
|
dataAttribute,
|
|
41
|
+
deduplicateClassName,
|
|
42
|
+
deprecate,
|
|
43
|
+
filterThemedClassName,
|
|
44
|
+
flatClassNameList,
|
|
31
45
|
getMatchingParentElement,
|
|
32
46
|
getSizeFromResizeObserverEntryFactory,
|
|
33
47
|
isArrayOfMembersSatisfyingFactory,
|
|
34
48
|
isBoolean,
|
|
49
|
+
isColorSchemeClassName,
|
|
35
50
|
isDefined,
|
|
36
51
|
isFalse,
|
|
37
52
|
isHTMLElement,
|
|
@@ -63,9 +78,8 @@ export {
|
|
|
63
78
|
stateClassName,
|
|
64
79
|
stateDataAttributes,
|
|
65
80
|
svgSizeProps,
|
|
81
|
+
themeClassName,
|
|
66
82
|
toKebabCase,
|
|
67
|
-
trimString
|
|
68
|
-
useClassName,
|
|
69
|
-
useClassNameFactory
|
|
83
|
+
trimString
|
|
70
84
|
};
|
|
71
85
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Predicates.js","sources":["../../../src/assert-types/Predicates.ts"],"sourcesContent":["import { Predicate, SlugString, UnionOfPredicateTypes } from './types'\n\nexport function isNull(value: unknown): value is null {\n return value === null\n}\nexport function isNotNull<T>(value: unknown): value is T {\n return value !== null\n}\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined\n}\nexport function isDefined<T>(value: unknown): value is T {\n return value !== undefined\n}\nexport function isNotNullish<T>(value: T): value is Exclude<T, null | undefined> {\n return value != null\n}\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean'\n}\nexport function isTrue(value: unknown): value is true {\n return value === true\n}\nexport function isFalse(value: unknown): value is false {\n return value === false\n}\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\nexport function isSlugString(value: unknown): value is SlugString {\n\treturn isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value)\n}\nexport function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value.length > 0\n}\nfunction isNonEmptyTrimmedStringFactory(trim: 'trim' | 'trimStart' | 'trimEnd' = 'trim') {\n return function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value[trim]().length > 0\n }\n}\nexport const isNonEmptyTrimmedString = isNonEmptyTrimmedStringFactory()\nexport const isNonEmptyTrimmedStartString = isNonEmptyTrimmedStringFactory('trimStart')\nexport const isNonEmptyTrimmedEndString = isNonEmptyTrimmedStringFactory('trimEnd')\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && value === value\n}\nexport function isNonNegativeNumber(value: unknown): value is number {\n return isNumber(value) && value >= 0\n}\nexport function isNumericString(value: string): value is string {\n return isString(value) && !isNaN(parseFloat(value))\n}\nexport function isOneOfFactory<U, T = any>(\n\tmembers: T extends Array<U> | ReadonlyArray<U> ? T : never,\n): (value: unknown) => value is U {\n\treturn function isOneOfFactoryProduct(value: unknown): value is U {\n\t\treturn members.includes(value as U)\n\t}\n}\nexport function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(\n\t...predicates: T\n): Predicate<unknown, UnionOfPredicateTypes<T>> {\n\treturn (value: any): value is UnionOfPredicateTypes<T> => {\n\t\treturn predicates.some(predicate => predicate(value))\n\t}\n}\nexport function isArrayOfMembersSatisfyingFactory<T>(\n\tpredicate: (value: unknown) => value is T,\n): (value: unknown) => value is Array<T> {\n\treturn function isArrayOfMembersSatisfyingProduct(value: unknown): value is Array<T> {\n\t\treturn Array.isArray(value) && value.every(predicate)\n\t}\n}\nexport function isHTMLElement(value: unknown): value is HTMLElement {\n return value instanceof HTMLElement\n}\nexport function isObject(value: unknown): value is Object {\n return typeof value === 'object' && value !== null\n}\nexport function isPlainObject<T extends Record<string, unknown>>(value: unknown): value is T {\n return isObject(value) && value.constructor === Object\n}\n"],"names":["isNonEmptyString"],"mappings":"AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAA4B;AACvD,SAAO,UAAU;AACnB;AACO,SAAS,YAAY,OAAoC;AAC9D,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,
|
|
1
|
+
{"version":3,"file":"Predicates.js","sources":["../../../src/assert-types/Predicates.ts"],"sourcesContent":["import { Predicate, SlugString, UnionOfPredicateTypes } from './types'\n\nexport function isNull(value: unknown): value is null {\n return value === null\n}\nexport function isNotNull<T>(value: unknown): value is T {\n return value !== null\n}\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined\n}\nexport function isDefined<T>(value: unknown): value is Exclude<T, undefined> {\n return value !== undefined\n}\nexport function isNotNullish<T>(value: T): value is Exclude<T, null | undefined> {\n return value != null\n}\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean'\n}\nexport function isTrue(value: unknown): value is true {\n return value === true\n}\nexport function isFalse(value: unknown): value is false {\n return value === false\n}\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\nexport function isSlugString(value: unknown): value is SlugString {\n\treturn isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value)\n}\nexport function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value.length > 0\n}\nfunction isNonEmptyTrimmedStringFactory(trim: 'trim' | 'trimStart' | 'trimEnd' = 'trim') {\n return function isNonEmptyString(value: unknown): value is string {\n return isString(value) && value[trim]().length > 0\n }\n}\nexport const isNonEmptyTrimmedString = isNonEmptyTrimmedStringFactory()\nexport const isNonEmptyTrimmedStartString = isNonEmptyTrimmedStringFactory('trimStart')\nexport const isNonEmptyTrimmedEndString = isNonEmptyTrimmedStringFactory('trimEnd')\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && value === value\n}\nexport function isNonNegativeNumber(value: unknown): value is number {\n return isNumber(value) && value >= 0\n}\nexport function isNumericString(value: string): value is string {\n return isString(value) && !isNaN(parseFloat(value))\n}\nexport function isOneOfFactory<U, T = any>(\n\tmembers: T extends Array<U> | ReadonlyArray<U> ? T : never,\n): (value: unknown) => value is U {\n\treturn function isOneOfFactoryProduct(value: unknown): value is U {\n\t\treturn members.includes(value as U)\n\t}\n}\nexport function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(\n\t...predicates: T\n): Predicate<unknown, UnionOfPredicateTypes<T>> {\n\treturn (value: any): value is UnionOfPredicateTypes<T> => {\n\t\treturn predicates.some(predicate => predicate(value))\n\t}\n}\nexport function isArrayOfMembersSatisfyingFactory<T>(\n\tpredicate: (value: unknown) => value is T,\n): (value: unknown) => value is Array<T> {\n\treturn function isArrayOfMembersSatisfyingProduct(value: unknown): value is Array<T> {\n\t\treturn Array.isArray(value) && value.every(predicate)\n\t}\n}\nexport function isHTMLElement(value: unknown): value is HTMLElement {\n return value instanceof HTMLElement\n}\nexport function isObject(value: unknown): value is Object {\n return typeof value === 'object' && value !== null\n}\nexport function isPlainObject<T extends Record<string, unknown>>(value: unknown): value is T {\n return isObject(value) && value.constructor === Object\n}\n"],"names":["isNonEmptyString"],"mappings":"AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAA4B;AACvD,SAAO,UAAU;AACnB;AACO,SAAS,YAAY,OAAoC;AAC9D,SAAO,UAAU;AACnB;AACO,SAAS,UAAa,OAAgD;AAC3E,SAAO,UAAU;AACnB;AACO,SAAS,aAAgB,OAAiD;AAC/E,SAAO,SAAS;AAClB;AACO,SAAS,UAAU,OAAkC;AAC1D,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,OAAO,OAA+B;AACpD,SAAO,UAAU;AACnB;AACO,SAAS,QAAQ,OAAgC;AACtD,SAAO,UAAU;AACnB;AACO,SAAS,SAAS,OAAiC;AACxD,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,aAAa,OAAqC;AACjE,SAAO,iBAAiB,KAAK,KAAK,gBAAgB,KAAK,KAAK;AAC7D;AACO,SAAS,iBAAiB,OAAiC;AAChE,SAAO,SAAS,KAAK,KAAK,MAAM,SAAS;AAC3C;AACA,SAAS,+BAA+B,OAAyC,QAAQ;AAChF,SAAA,SAASA,kBAAiB,OAAiC;AAChE,WAAO,SAAS,KAAK,KAAK,MAAM,IAAI,IAAI,SAAS;AAAA,EAAA;AAErD;AACO,MAAM,0BAA0B,+BAA+B;AACzD,MAAA,+BAA+B,+BAA+B,WAAW;AACzE,MAAA,6BAA6B,+BAA+B,SAAS;AAC3E,SAAS,SAAS,OAAiC;AACjD,SAAA,OAAO,UAAU,YAAY,UAAU;AAChD;AACO,SAAS,oBAAoB,OAAiC;AAC5D,SAAA,SAAS,KAAK,KAAK,SAAS;AACrC;AACO,SAAS,gBAAgB,OAAgC;AAC9D,SAAO,SAAS,KAAK,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC;AACpD;AACO,SAAS,eACf,SACiC;AAC1B,SAAA,SAAS,sBAAsB,OAA4B;AAC1D,WAAA,QAAQ,SAAS,KAAU;AAAA,EAAA;AAEpC;AACO,SAAS,yBACZ,YAC4C;AAC/C,SAAO,CAAC,UAAkD;AACzD,WAAO,WAAW,KAAK,CAAa,cAAA,UAAU,KAAK,CAAC;AAAA,EAAA;AAEtD;AACO,SAAS,kCACf,WACwC;AACjC,SAAA,SAAS,kCAAkC,OAAmC;AACpF,WAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,SAAS;AAAA,EAAA;AAEtD;AACO,SAAS,cAAc,OAAsC;AAClE,SAAO,iBAAiB;AAC1B;AACO,SAAS,SAAS,OAAiC;AACjD,SAAA,OAAO,UAAU,YAAY,UAAU;AAChD;AACO,SAAS,cAAiD,OAA4B;AAC3F,SAAO,SAAS,KAAK,KAAK,MAAM,gBAAgB;AAClD;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { COLOR_SCHEME_CLASS_NAME_REG_EXP } from "./constants.js";
|
|
2
|
+
function colorSchemeClassName(scheme) {
|
|
3
|
+
if (typeof scheme === "string") {
|
|
4
|
+
return `scheme-${scheme}`;
|
|
5
|
+
} else {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function isColorSchemeClassName(value) {
|
|
10
|
+
return COLOR_SCHEME_CLASS_NAME_REG_EXP.test(value);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
colorSchemeClassName,
|
|
14
|
+
isColorSchemeClassName
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=colorSchemeClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorSchemeClassName.js","sources":["../../../src/class-name/colorSchemeClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { COLOR_SCHEME_CLASS_NAME_REG_EXP } from './constants'\nimport { ColorSchemeClassName } from './types'\n\n/**\n * Returns a string with a color scheme class name, prefixed with `scheme-`\n *\n * @param scheme - Color scheme name\n * @returns A color scheme class name\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n *\n * return (\n * \t<div className={colorScheme}>\n * \t\t<button className={controlsThemeClassName}>Click me</button>\n * \t</div>\n *\n * // renders:\n * // <div class=\"scheme-system\">\n * // \t<button class=\"scheme-system theme-default-controls theme-danger-controls:hover\">Click me</button>\n * // </div>\n * ```\n */\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S): ColorSchemeClassName<S>;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: null | undefined): undefined;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S | null | undefined): ColorSchemeClassName<S> | undefined;\nexport function colorSchemeClassName<S extends KebabCase<string> = KebabCase<string>>(scheme: S | null | undefined): ColorSchemeClassName<S> | undefined {\n\tif (typeof scheme === 'string') {\n\t\treturn `scheme-${scheme}`\n\t} else {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Tests if a string is a color scheme CSS class\n * @param value - String to test\n * @returns `true` if the string is a color scheme CSS class\n * @internal\n */\nexport function isColorSchemeClassName<T extends string>(value: string): value is ColorSchemeClassName<T> {\n\treturn COLOR_SCHEME_CLASS_NAME_REG_EXP.test(value)\n}\n"],"names":[],"mappings":";AA6BO,SAAS,qBAAsE,QAAmE;AACpJ,MAAA,OAAO,WAAW,UAAU;AAC/B,WAAO,UAAU;AAAA,EAAA,OACX;AACC,WAAA;AAAA,EACR;AACD;AAQO,SAAS,uBAAyC,OAAiD;AAClG,SAAA,gCAAgC,KAAK,KAAK;AAClD;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const THEME_CLASS_NAME_REG_EXP = /^theme-(?<name>[\w-]+?)(?:-(?<scope>content|controls))?(?<state>:[\w]+(?:[\w-]+)?)?$/;
|
|
2
|
+
const COLOR_SCHEME_CLASS_NAME_REG_EXP = /^scheme-(?<colorScheme>[a-z0-9]|[a-z0-9]+[a-z-]+[a-z])$/;
|
|
3
|
+
export {
|
|
4
|
+
COLOR_SCHEME_CLASS_NAME_REG_EXP,
|
|
5
|
+
THEME_CLASS_NAME_REG_EXP
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/class-name/constants.ts"],"sourcesContent":["/**\n * RegExp that matches theme class names\n *\n * @internal\n *\n * If theme is `default` then it will match:\n *\n * - theme-default\n * - theme-default:hover\n * - theme-default:active\n * - theme-default:focus\n * - theme-default-content\n * - theme-default-content:hover\n * - theme-default-content:active\n * - theme-default-content:focus\n * - theme-default-controls\n * - theme-default-controls:hover\n * - theme-default-controls:active\n * - theme-default-controls:focus\n *\n * If theme is `brand-color` then it will match:\n *\n * - theme-brand-color\n * - theme-brand-color:hover\n * - theme-brand-color:active\n * - theme-brand-color:focus\n * - theme-brand-color-content\n * - theme-brand-color-content:hover\n * - theme-brand-color-content:active\n * - theme-brand-color-content:focus\n * - theme-brand-color-controls\n * - theme-brand-color-controls:hover\n * - theme-brand-color-controls:active\n * - theme-brand-color-controls:focus\n */\n\nexport const THEME_CLASS_NAME_REG_EXP = /^theme-(?<name>[\\w-]+?)(?:-(?<scope>content|controls))?(?<state>:[\\w]+(?:[\\w-]+)?)?$/\n\n/**\n * Regular expression for testing if a string is a color scheme CSS class\n * @internal\n */\nexport const COLOR_SCHEME_CLASS_NAME_REG_EXP = /^scheme-(?<colorScheme>[a-z0-9]|[a-z0-9]+[a-z-]+[a-z])$/\n"],"names":[],"mappings":"AAoCO,MAAM,2BAA2B;AAMjC,MAAM,kCAAkC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduplicateClassName.js","sources":["../../../src/class-name/deduplicateClassName.ts"],"sourcesContent":["export function deduplicateClassName(classNameArray: string[]): string[] {\n\treturn [...new Set(classNameArray)]\n}\n"],"names":[],"mappings":"AAAO,SAAS,qBAAqB,gBAAoC;AACxE,SAAO,CAAC,GAAG,IAAI,IAAI,cAAc,CAAC;AACnC;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isColorSchemeClassName } from "./colorSchemeClassName.js";
|
|
2
|
+
import { THEME_CLASS_NAME_REG_EXP } from "./constants.js";
|
|
3
|
+
import { flatClassNameList } from "./flatClassNameList.js";
|
|
4
|
+
import { contentThemeClassName, controlsThemeClassName } from "./themeClassName.js";
|
|
5
|
+
function filterThemedClassName(nestedClassName, defaultColorSchemeContext) {
|
|
6
|
+
const theme = { content: void 0, controls: void 0 };
|
|
7
|
+
const stateThemes = {};
|
|
8
|
+
let colorScheme = void 0;
|
|
9
|
+
const flatClassName = flatClassNameList(nestedClassName).map((className) => {
|
|
10
|
+
if (isColorSchemeClassName(className)) {
|
|
11
|
+
colorScheme = className;
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
const match = className.match(THEME_CLASS_NAME_REG_EXP);
|
|
15
|
+
if (match) {
|
|
16
|
+
const name = match.groups.name;
|
|
17
|
+
const scope = match.groups.scope;
|
|
18
|
+
const state = match.groups.state;
|
|
19
|
+
if (state) {
|
|
20
|
+
stateThemes[state] = stateThemes[state] ?? { content: void 0, controls: void 0 };
|
|
21
|
+
if (!scope) {
|
|
22
|
+
stateThemes[state].content = name;
|
|
23
|
+
stateThemes[state].controls = name;
|
|
24
|
+
} else if (scope === "content") {
|
|
25
|
+
stateThemes[state].content = name;
|
|
26
|
+
} else if (scope === "controls") {
|
|
27
|
+
stateThemes[state].controls = name;
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error(`Unknown theme scope: ${scope}`);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
if (!scope) {
|
|
33
|
+
theme.content = name;
|
|
34
|
+
theme.controls = name;
|
|
35
|
+
} else if (scope === "content") {
|
|
36
|
+
theme.content = name;
|
|
37
|
+
} else if (scope === "controls") {
|
|
38
|
+
theme.controls = name;
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error(`Unknown theme scope: ${scope}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
} else {
|
|
45
|
+
return className;
|
|
46
|
+
}
|
|
47
|
+
}).filter(Boolean);
|
|
48
|
+
const themeClassNames = [];
|
|
49
|
+
const content = contentThemeClassName(theme.content);
|
|
50
|
+
const controls = controlsThemeClassName(theme.controls);
|
|
51
|
+
themeClassNames.push(content, controls);
|
|
52
|
+
for (const state in stateThemes) {
|
|
53
|
+
const { content: content2, controls: controls2 } = stateThemes[state];
|
|
54
|
+
const contentClassName = contentThemeClassName(content2, state);
|
|
55
|
+
const controlsClassName = controlsThemeClassName(controls2, state);
|
|
56
|
+
themeClassNames.push(contentClassName, controlsClassName);
|
|
57
|
+
}
|
|
58
|
+
const flatThemedClassName = flatClassNameList(themeClassNames);
|
|
59
|
+
if (flatThemedClassName.length > 0 || colorScheme) {
|
|
60
|
+
return [colorScheme ?? defaultColorSchemeContext, ...flatThemedClassName, ...flatClassName];
|
|
61
|
+
} else {
|
|
62
|
+
return flatClassName;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
filterThemedClassName
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=filterThemedClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterThemedClassName.js","sources":["../../../src/class-name/filterThemedClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { isColorSchemeClassName } from './colorSchemeClassName'\nimport { THEME_CLASS_NAME_REG_EXP } from './constants'\nimport { flatClassNameList } from './flatClassNameList'\nimport { contentThemeClassName, controlsThemeClassName } from './themeClassName'\nimport { ColorSchemeClassName, NestedClassName } from './types'\n\nexport type ThemeConfig = { content: string | undefined, controls: string | undefined }\n\nexport function filterThemedClassName(\n\tnestedClassName: NestedClassName,\n\tdefaultColorSchemeContext: ColorSchemeClassName,\n) {\n\tconst theme: ThemeConfig = { content: undefined, controls: undefined }\n\tconst stateThemes: Record<string, ThemeConfig> = {}\n\tlet colorScheme: ColorSchemeClassName | undefined = undefined\n\n\tconst flatClassName = flatClassNameList(nestedClassName).map(className => {\n\t\tif (isColorSchemeClassName(className)) {\n\t\t\tcolorScheme = className\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst match = className.match(THEME_CLASS_NAME_REG_EXP)\n\n\t\tif (match) {\n\t\t\tconst name = match.groups!.name as KebabCase<string>\n\t\t\tconst scope = match.groups!.scope as KebabCase<string>\n\t\t\tconst state = match.groups!.state as `:${KebabCase<string>}`\n\n\t\t\tif (state) {\n\t\t\t\tstateThemes[state] = stateThemes[state] ?? { content: undefined, controls: undefined }\n\n\t\t\t\tif (!scope) {\n\t\t\t\t\tstateThemes[state].content = name\n\t\t\t\t\tstateThemes[state].controls = name\n\t\t\t\t} else if (scope === 'content') {\n\t\t\t\t\tstateThemes[state].content = name\n\t\t\t\t} else if (scope === 'controls') {\n\t\t\t\t\tstateThemes[state].controls = name\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Unknown theme scope: ${scope}`)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!scope) {\n\t\t\t\t\ttheme.content = name\n\t\t\t\t\ttheme.controls = name\n\t\t\t\t} else if (scope === 'content') {\n\t\t\t\t\ttheme.content = name\n\t\t\t\t} else if (scope === 'controls') {\n\t\t\t\t\ttheme.controls = name\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Unknown theme scope: ${scope}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn undefined\n\t\t} else {\n\t\t\treturn className\n\t\t}\n\t}).filter(Boolean) as string[]\n\n\tconst themeClassNames: (string | undefined)[] = []\n\n\tconst content = contentThemeClassName(theme.content)\n\tconst controls = controlsThemeClassName(theme.controls)\n\n\tthemeClassNames.push(content, controls)\n\n\tfor (const state in stateThemes) {\n\t\tconst { content, controls } = stateThemes[state]\n\n\t\tconst contentClassName = contentThemeClassName(content, state as `:${KebabCase<string>}`)\n\t\tconst controlsClassName = controlsThemeClassName(controls, state as `:${KebabCase<string>}`)\n\n\t\tthemeClassNames.push(contentClassName, controlsClassName)\n\t}\n\n\tconst flatThemedClassName = flatClassNameList(themeClassNames)\n\n\tif (flatThemedClassName.length > 0 || colorScheme) {\n\t\treturn [colorScheme ?? defaultColorSchemeContext, ...flatThemedClassName, ...flatClassName]\n\t} else {\n\t\treturn flatClassName\n\t}\n}\n"],"names":["content","controls"],"mappings":";;;;AASgB,SAAA,sBACf,iBACA,2BACC;AACD,QAAM,QAAqB,EAAE,SAAS,QAAW,UAAU;AAC3D,QAAM,cAA2C,CAAA;AACjD,MAAI,cAAgD;AAEpD,QAAM,gBAAgB,kBAAkB,eAAe,EAAE,IAAI,CAAa,cAAA;AACrE,QAAA,uBAAuB,SAAS,GAAG;AACxB,oBAAA;AACP,aAAA;AAAA,IACR;AAEM,UAAA,QAAQ,UAAU,MAAM,wBAAwB;AAEtD,QAAI,OAAO;AACJ,YAAA,OAAO,MAAM,OAAQ;AACrB,YAAA,QAAQ,MAAM,OAAQ;AACtB,YAAA,QAAQ,MAAM,OAAQ;AAE5B,UAAI,OAAO;AACE,oBAAA,KAAK,IAAI,YAAY,KAAK,KAAK,EAAE,SAAS,QAAW,UAAU,OAAU;AAErF,YAAI,CAAC,OAAO;AACC,sBAAA,KAAK,EAAE,UAAU;AACjB,sBAAA,KAAK,EAAE,WAAW;AAAA,QAAA,WACpB,UAAU,WAAW;AACnB,sBAAA,KAAK,EAAE,UAAU;AAAA,QAAA,WACnB,UAAU,YAAY;AACpB,sBAAA,KAAK,EAAE,WAAW;AAAA,QAAA,OACxB;AACA,gBAAA,IAAI,MAAM,wBAAwB,OAAO;AAAA,QAChD;AAAA,MAAA,OACM;AACN,YAAI,CAAC,OAAO;AACX,gBAAM,UAAU;AAChB,gBAAM,WAAW;AAAA,QAAA,WACP,UAAU,WAAW;AAC/B,gBAAM,UAAU;AAAA,QAAA,WACN,UAAU,YAAY;AAChC,gBAAM,WAAW;AAAA,QAAA,OACX;AACA,gBAAA,IAAI,MAAM,wBAAwB,OAAO;AAAA,QAChD;AAAA,MACD;AAEO,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IACR;AAAA,EAAA,CACA,EAAE,OAAO,OAAO;AAEjB,QAAM,kBAA0C,CAAA;AAE1C,QAAA,UAAU,sBAAsB,MAAM,OAAO;AAC7C,QAAA,WAAW,uBAAuB,MAAM,QAAQ;AAEtC,kBAAA,KAAK,SAAS,QAAQ;AAEtC,aAAW,SAAS,aAAa;AAChC,UAAM,EAAE,SAAAA,UAAS,UAAAC,cAAa,YAAY,KAAK;AAEzC,UAAA,mBAAmB,sBAAsBD,UAAS,KAAgC;AAClF,UAAA,oBAAoB,uBAAuBC,WAAU,KAAgC;AAE3E,oBAAA,KAAK,kBAAkB,iBAAiB;AAAA,EACzD;AAEM,QAAA,sBAAsB,kBAAkB,eAAe;AAEzD,MAAA,oBAAoB,SAAS,KAAK,aAAa;AAClD,WAAO,CAAC,eAAe,2BAA2B,GAAG,qBAAqB,GAAG,aAAa;AAAA,EAAA,OACpF;AACC,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatClassNameList.js","sources":["../../../src/class-name/flatClassNameList.ts"],"sourcesContent":["import { assertNever } from '../assert-types'\nimport { NestedClassName } from './types'\n\nexport function flatClassNameList(className: NestedClassName): string[] {\n\tif (!className) {\n\t\treturn []\n\t} else if (typeof className === 'string') {\n\t\treturn className.split(' ').filter(Boolean)\n\t} else if (Array.isArray(className)) {\n\t\treturn className.flatMap(flatClassNameList)\n\t} else {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconsole.error(`Unexpected className: ${JSON.stringify(className)}`)\n\t\t}\n\n\t\tassertNever(className)\n\t}\n}\n"],"names":[],"mappings":";AAGO,SAAS,kBAAkB,WAAsC;AACvE,MAAI,CAAC,WAAW;AACf,WAAO;EAAC,WACE,OAAO,cAAc,UAAU;AACzC,WAAO,UAAU,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAChC,WAAA,MAAM,QAAQ,SAAS,GAAG;AAC7B,WAAA,UAAU,QAAQ,iBAAiB;AAAA,EAAA,OACpC;AAKN,gBAAqB;AAAA,EACtB;AACD;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { deduplicateClassName } from "./
|
|
2
|
-
import { flatClassNameList } from "./
|
|
1
|
+
import { deduplicateClassName } from "./deduplicateClassName.js";
|
|
2
|
+
import { flatClassNameList } from "./flatClassNameList.js";
|
|
3
3
|
function listClassName(list) {
|
|
4
4
|
return deduplicateClassName(flatClassNameList(list)).join(" ");
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listClassName.js","sources":["../../../src/class-name/listClassName.ts"],"sourcesContent":["import { deduplicateClassName } from './
|
|
1
|
+
{"version":3,"file":"listClassName.js","sources":["../../../src/class-name/listClassName.ts"],"sourcesContent":["import { deduplicateClassName } from './deduplicateClassName'\nimport { flatClassNameList } from './flatClassNameList'\n\n/**\n * Combines a list of class names into a single string, even nested\n *\n * @param list - List of class names\n * @returns Combined class names as string\n */\nexport function listClassName(list: (string | false | null | undefined)[]) {\n\treturn deduplicateClassName(flatClassNameList(list)).join(' ')\n}\n"],"names":[],"mappings":";;AASO,SAAS,cAAc,MAA6C;AAC1E,SAAO,qBAAqB,kBAAkB,IAAI,CAAC,EAAE,KAAK,GAAG;AAC9D;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateClassName.js","sources":["../../../src/class-name/stateClassName.ts"],"sourcesContent":["import { toKebabCase } from '../string-utilities'\nimport { ClassNameStateMap } from './
|
|
1
|
+
{"version":3,"file":"stateClassName.js","sources":["../../../src/class-name/stateClassName.ts"],"sourcesContent":["import { toKebabCase } from '../string-utilities'\nimport { ClassNameStateMap } from './types'\n\nexport interface StateClassNameOptions {\n\tglue?: string;\n\tremoveFalsy?: boolean;\n}\n\n/**\n * Combines a state map of class names into a single string\n *\n * @example\n * stateClassName({ foo: true, bar: false, baz: 1 }) // => 'foo baz-1'\n *\n * @param state - State map object with class names as keys and literals as values.\n * @param options - Options object\n * @param options.glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.\n * @param options.removeFalsy - Whether to remove falsy class names, default is true.\n * @returns Combined class names as string\n */\nexport function stateClassName(\n\tstate: ClassNameStateMap | null = null,\n\t{ glue = '-', removeFalsy = true }: StateClassNameOptions = {},\n): string[] {\n\tconst entries = Object.entries(state ?? []).map(\n\t\t([className, value]) => value || value === 0 || !removeFalsy\n\t\t\t? (value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}`)\n\t\t\t: '',\n\t).filter(Boolean)\n\n\treturn entries\n}\n"],"names":[],"mappings":";AAoBgB,SAAA,eACf,QAAkC,MAClC,EAAE,OAAO,KAAK,cAAc,KAAgC,IAAA,IACjD;AACX,QAAM,UAAU,OAAO,QAAQ,SAAS,CAAA,CAAE,EAAE;AAAA,IAC3C,CAAC,CAAC,WAAW,KAAK,MAAM,SAAS,UAAU,KAAK,CAAC,cAC7C,UAAU,OAAO,YAAY,SAAS,IAAI,GAAG,YAAY,SAAS,IAAI,OAAO,UAC9E;AAAA,EAAA,EACF,OAAO,OAAO;AAET,SAAA;AACR;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function contentThemeClassName(theme, state) {
|
|
2
|
+
return theme ? `theme-${theme}-content${state ?? ""}` : void 0;
|
|
3
|
+
}
|
|
4
|
+
function controlsThemeClassName(theme, state) {
|
|
5
|
+
return theme ? `theme-${theme}-controls${state ?? ""}` : void 0;
|
|
6
|
+
}
|
|
7
|
+
function themeClassName(theme, state) {
|
|
8
|
+
return [
|
|
9
|
+
contentThemeClassName(theme, state),
|
|
10
|
+
controlsThemeClassName(theme, state)
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
contentThemeClassName,
|
|
15
|
+
controlsThemeClassName,
|
|
16
|
+
themeClassName
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=themeClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeClassName.js","sources":["../../../src/class-name/themeClassName.ts"],"sourcesContent":["import { KebabCase } from 'type-fest'\nimport { colorSchemeClassName } from './colorSchemeClassName'\nimport { ThemeContentClassName, ThemeControlsClassName } from './types'\n\n/**\n * Returns a string with a content theme class name, prefixed with `theme-` and suffixed with `-content`\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param contentTheme - Theme name basis for content\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A content theme class name\n *\n * @see {@link controlsThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const contentThemeClassName = contentThemeClassName('default')\n * // ^ 'theme-default-content:hover'\n * const dangerOnMouseOverTheme = controlsThemeClassName('danger', ':hover')\n * // ^ 'theme-danger-controls:hover'\n *\n * return (\n * \t<div className={`${colorScheme} ${contentThemeClassName}`}>\n * \t\t<button className={`${colorScheme} ${dangerOnMouseOverTheme}`}>Delete</button>\n * \t</div>\n * )\n * ```\n */\nexport function contentThemeClassName<\n\tContentTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\ttheme: ContentTheme | null | undefined,\n\tstate?: State | null | undefined,\n) {\n\treturn theme ? `theme-${theme}-content${state ?? ''}` as ThemeContentClassName<ContentTheme, State> : undefined\n}\n\n/**\n * Returns a string with a controls theme class name, prefixed with `theme-` and suffixed with `-controls`\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param theme - Theme name basis for controls\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A controls theme class name\n *\n * @see {@link contentThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const contentThemeClassName = contentThemeClassName('default')\n * // ^ 'theme-default-content:hover'\n * const dangerOnMouseOverTheme = controlsThemeClassName('danger', ':hover')\n * // ^ 'theme-danger-controls:hover'\n *\n * return (\n * \t<div className={`${colorScheme} ${contentThemeClassName}`}>\n * \t\t<button className={`${colorScheme} ${dangerOnMouseOverTheme}`}>Delete</button>\n * \t</div>\n * )\n * ```\n */\nexport function controlsThemeClassName<\n\tControlsTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\ttheme: ControlsTheme | null | undefined,\n\tstate?: State | null | undefined,\n) {\n\treturn theme ? `theme-${theme}-controls${state ?? ''}` as ThemeControlsClassName<ControlsTheme, State> : undefined\n}\n\n/**\n * Returns a tuple with a content theme class name and a controls theme class name, prefixed with `theme-` and suffixed with `-content` and `-controls` respectively\n *\n * IMPORTANT: Make sure to use color scheme class in combination with theme class names.\n *\n * @param theme - Theme name basis for content and controls\n * @param state - State of the theme starting with a \":\", e.g. `\":hover\"`, `\":focus\"`, `\":active\"`, `\":focus-visible\"`\n * @returns A tuple with a content theme class name and a controls theme class name\n *\n * @see {@link contentThemeClassName}\n * @see {@link controlsThemeClassName}\n * @see {@link (colorSchemeClassName:3)}\n *\n * @example\n * ```tsx\n * const colorScheme = colorSchemeClassName('system')\n * // ^ 'scheme-system'\n * const errorTheme = themeClassName('danger').join(' ')\n * // ^ 'theme-danger-content theme-danger-controls'\n *\n * return (\n * \t<div className={`${colorScheme} ${errorTheme}`}>File not found</div>\n * )\n * ```\n */\nexport function themeClassName<\n\tTheme extends KebabCase<string> = KebabCase<string>,\n\tState extends `:${KebabCase<string>}` | null | undefined = undefined,\n>(\n\t\ttheme: Theme | null | undefined,\n\t\tstate?: State | null | undefined,\n) {\n\treturn [\n\t\tcontentThemeClassName(theme, state),\n\t\tcontrolsThemeClassName(theme, state),\n\t] as const\n}\n"],"names":[],"mappings":"AAgCgB,SAAA,sBAIf,OACA,OACC;AACD,SAAO,QAAQ,SAAS,gBAAgB,SAAS,OAAqD;AACvG;AA8BgB,SAAA,uBAIf,OACA,OACC;AACD,SAAO,QAAQ,SAAS,iBAAiB,SAAS,OAAuD;AAC1G;AA2BgB,SAAA,eAId,OACA,OACA;AACM,SAAA;AAAA,IACN,sBAAsB,OAAO,KAAK;AAAA,IAClC,uBAAuB,OAAO,KAAK;AAAA,EAAA;AAErC;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function currentOrDeprecated(current, deprecated, shouldThrow = false) {
|
|
2
|
+
if (deprecated !== void 0) {
|
|
3
|
+
if (current !== void 0 && false) {
|
|
4
|
+
console.error("Current value:", current);
|
|
5
|
+
console.error("Deprecated value:", deprecated);
|
|
6
|
+
if (shouldThrow) {
|
|
7
|
+
throw new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
|
|
8
|
+
} else {
|
|
9
|
+
console.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return deprecated;
|
|
13
|
+
} else {
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
currentOrDeprecated
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=currentOrDeprecated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currentOrDeprecated.js","sources":["../../../src/deprecate/currentOrDeprecated.ts"],"sourcesContent":["/**\n * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.\n *\n * @internal\n *\n * Errors are thrown only in development mode. In production mode, the deprecated value is returned.\n *\n * @param current - Current value that replaces deprecated value\n * @param deprecated - Deprecated value that will be removed in the next release\n * @param shouldThrow - Whether to throw an error if both current and deprecated are defined\n * @returns Deprecated value if it is defined, otherwise current value\n * @throws Error if both current and deprecated are defined\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = 'deprecated'\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'deprecated'\n * ```\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = undefined\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'current'\n * ```\n */\nexport function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow: boolean = false): R | D {\n\tif (deprecated !== undefined) {\n\t\tif (current !== undefined && import.meta.env.DEV) {\n\t\t\tconsole.error('Current value:', current)\n\t\t\tconsole.error('Deprecated value:', deprecated)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t} else {\n\t\t\t\tconsole.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t}\n\t\t}\n\n\t\treturn deprecated\n\t} else {\n\t\treturn current\n\t}\n}\n"],"names":[],"mappings":"AAiCO,SAAS,oBAA0B,SAAY,YAAe,cAAuB,OAAc;AACzG,MAAI,eAAe,QAAW;AAC7B,QAAI,YAAY,UAAa,OAAqB;AACzC,cAAA,MAAM,kBAAkB,OAAO;AAC/B,cAAA,MAAM,qBAAqB,UAAU;AAE7C,UAAI,aAAa;AACV,cAAA,IAAI,MAAM,yGAAyG;AAAA,MAAA,OACnH;AACN,gBAAQ,MAAM,yGAAyG;AAAA,MACxH;AAAA,IACD;AAEO,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate.js","sources":["../../../src/deprecate/deprecate.ts"],"sourcesContent":["import { SemverString } from './types'\n\n/**\n * Logs a deprecation warning if the assertion is `false`.\n * @internal\n *\n * @param removal - Version when the deprecated feature will be removed\n * @param assertion - Condition that must be true to avoid the deprecation warning\n * @param deprecated - Name of the deprecated feature\n * @param replacement - Name of the feature that replaces the deprecated feature\n *\n * @example\n * ```ts\n * const { visible } = props\n * deprecate(visible !== 'default', '1.3.0', '\"default\"', '\"hidden\"')\n * // Logs: Use of \"default\" is deprecated and might be removed in the next release. Use \"hidden\" instead.\n * ```\n */\nexport function deprecate(removal: SemverString, assertion: boolean, deprecated: string, replacement: string): void {\n\tif (assertion === false) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst shouldThrow = Boolean(import.meta.env.VITE_CONTEMBER_ADMIN_STRICT_DEPRECATIONS)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`Support for ${deprecated} was planned to be removed in the ${removal} release. Replace it with ${replacement} instead.`)\n\t\t\t} else {\n\t\t\t\tconsole.warn(`Use of ${deprecated} is deprecated and might be removed in the next release. Use ${replacement} instead.`)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAkBO,SAAS,UAAU,SAAuB,WAAoB,YAAoB,aAA2B;AAYpH;"}
|