@salty-css/core 0.0.1-alpha.30 → 0.0.1-alpha.301

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.
Files changed (118) hide show
  1. package/.saltyrc.schema.json +48 -0
  2. package/README.md +469 -26
  3. package/bin/index.cjs +3 -1
  4. package/bin/index.js +2 -2
  5. package/bin/main.cjs +445 -8
  6. package/bin/main.js +424 -121
  7. package/cache/resolve-dynamic-config-cache.cjs +13 -0
  8. package/cache/resolve-dynamic-config-cache.d.ts +1 -0
  9. package/cache/resolve-dynamic-config-cache.js +13 -0
  10. package/compiler/get-files.d.ts +3 -0
  11. package/compiler/get-function-range.d.ts +1 -0
  12. package/compiler/helpers.d.ts +2 -0
  13. package/compiler/index.cjs +774 -11
  14. package/compiler/index.d.ts +22 -11
  15. package/compiler/index.js +735 -153
  16. package/config/define-config.d.ts +1 -1
  17. package/config/index.cjs +16 -1
  18. package/config/index.d.ts +2 -1
  19. package/config/index.js +14 -2
  20. package/css/index.cjs +12 -1
  21. package/css/index.d.ts +4 -1
  22. package/css/index.js +10 -2
  23. package/css/keyframes.cjs +49 -0
  24. package/css/keyframes.d.ts +22 -0
  25. package/css/keyframes.js +49 -0
  26. package/css/media.cjs +93 -0
  27. package/css/media.d.ts +87 -0
  28. package/css/media.js +93 -0
  29. package/css/merge.cjs +15 -0
  30. package/css/merge.d.ts +7 -0
  31. package/css/merge.js +15 -0
  32. package/css/token.cjs +4 -0
  33. package/css/token.d.ts +1 -0
  34. package/css/token.js +4 -0
  35. package/dash-case-Cz8wwE9a.cjs +32 -0
  36. package/dash-case-NMk0mXyT.js +33 -0
  37. package/define-templates-CVhhgPnd.js +60 -0
  38. package/define-templates-Deq1aCbN.cjs +59 -0
  39. package/factories/define-global-styles.d.ts +7 -0
  40. package/factories/define-media-query.d.ts +8 -0
  41. package/factories/define-templates.d.ts +27 -0
  42. package/factories/define-variables.d.ts +12 -0
  43. package/factories/index.cjs +37 -0
  44. package/factories/index.d.ts +4 -0
  45. package/factories/index.js +37 -0
  46. package/generators/class-name-generator.d.ts +6 -0
  47. package/generators/index.cjs +121 -0
  48. package/generators/index.d.ts +2 -0
  49. package/generators/index.js +121 -0
  50. package/generators/styled-generator.d.ts +20 -0
  51. package/generators/styles-generator.d.ts +22 -0
  52. package/helpers/color.d.ts +18 -0
  53. package/helpers/index.cjs +53 -0
  54. package/helpers/index.d.ts +2 -0
  55. package/helpers/index.js +53 -0
  56. package/helpers/viewport-clamp.d.ts +9 -0
  57. package/helpers-DM2fbDDz.js +18 -0
  58. package/helpers-wv74jTRI.cjs +18 -0
  59. package/index-ByR0nfaf.cjs +4 -0
  60. package/index-DKz1QXqs.js +4 -0
  61. package/package.json +54 -6
  62. package/parse-styles-CqBQc3eQ.js +232 -0
  63. package/parse-styles-D-p_guRO.cjs +231 -0
  64. package/parsers/index.cjs +57 -0
  65. package/parsers/index.d.ts +5 -0
  66. package/parsers/index.js +58 -0
  67. package/parsers/parse-modifiers.d.ts +3 -0
  68. package/parsers/parse-styles.d.ts +13 -0
  69. package/parsers/parse-templates.d.ts +4 -0
  70. package/parsers/parse-tokens.d.ts +3 -0
  71. package/parsers/parser-types.d.ts +8 -0
  72. package/parsers/property-name-check.d.ts +1 -0
  73. package/parsers/unit-check.d.ts +7 -0
  74. package/pascal-case-By_l58S-.cjs +7 -0
  75. package/pascal-case-F3Usi5Wf.js +8 -0
  76. package/{react-styled-file-CGVf5n1B.js → react-styled-file-B99mwk0w.js} +2 -2
  77. package/react-styled-file-U02jek-B.cjs +11 -0
  78. package/react-vanilla-file-Bj6XC8GS.cjs +18 -0
  79. package/react-vanilla-file-D9px70iK.js +18 -0
  80. package/salty.config-DjosWdPw.js +4 -0
  81. package/salty.config-cqavVm2t.cjs +4 -0
  82. package/server/index.cjs +4 -0
  83. package/server/index.d.ts +1 -0
  84. package/server/index.js +4 -0
  85. package/server/should-restart.d.ts +1 -0
  86. package/should-restart-5jI-bzz0.js +18 -0
  87. package/should-restart-DoaGoD5T.cjs +17 -0
  88. package/templates/salty-reset.d.ts +2 -0
  89. package/types/cli-types.d.ts +10 -0
  90. package/types/config-types.d.ts +85 -0
  91. package/types/index.d.ts +57 -23
  92. package/util/dot-case.d.ts +1 -0
  93. package/util/index.cjs +13 -1
  94. package/util/index.js +10 -8
  95. package/util/module-type.d.ts +1 -0
  96. package/viewport-clamp-CEmzmcSj.cjs +10 -0
  97. package/viewport-clamp-K553uXu3.js +11 -0
  98. package/config/config-types.d.ts +0 -59
  99. package/dash-case-DKzpenwY.cjs +0 -1
  100. package/dash-case-DMQMcCO6.js +0 -19
  101. package/generator/index.cjs +0 -1
  102. package/generator/index.d.ts +0 -1
  103. package/generator/index.js +0 -61
  104. package/generator/parse-modifiers.d.ts +0 -3
  105. package/generator/parse-styles.d.ts +0 -2
  106. package/generator/parse-templates.d.ts +0 -2
  107. package/generator/parse-tokens.d.ts +0 -2
  108. package/generator/parser-types.d.ts +0 -4
  109. package/generator/style-generator.d.ts +0 -28
  110. package/index-84Wroia-.cjs +0 -1
  111. package/index-D_732b92.js +0 -4
  112. package/parse-templates-D4p3pgQR.js +0 -92
  113. package/parse-templates-W0YfTmOT.cjs +0 -8
  114. package/pascal-case-BQpR5PdN.js +0 -6
  115. package/pascal-case-iWoaJWwT.cjs +0 -1
  116. package/react-styled-file-Dkubsz-U.cjs +0 -8
  117. package/salty.config-BupieCfE.cjs +0 -6
  118. package/salty.config-D9ANEDiH.js +0 -9
@@ -0,0 +1,58 @@
1
+ import { p as parseAndJoinStyles } from "../parse-styles-CqBQc3eQ.js";
2
+ import { c, b, d, a } from "../parse-styles-CqBQc3eQ.js";
3
+ import { d as dashCase, t as toHash } from "../dash-case-NMk0mXyT.js";
4
+ const parseTemplates = async (obj, path = []) => {
5
+ if (!obj) return "";
6
+ const classes = [];
7
+ const levelStyles = {};
8
+ for (const [key, value] of Object.entries(obj)) {
9
+ if (typeof value === "function") ;
10
+ else if (value && typeof value === "object") {
11
+ const _key = key.trim();
12
+ const result = await parseTemplates(value, [...path, _key]);
13
+ classes.push(result);
14
+ } else {
15
+ levelStyles[key] = value;
16
+ }
17
+ }
18
+ if (Object.keys(levelStyles).length) {
19
+ const className = path.map(dashCase).join("-");
20
+ const hashClass = "t_" + toHash(className, 4);
21
+ const result = await parseAndJoinStyles(levelStyles, `.${className}, .${hashClass}`);
22
+ classes.push(result);
23
+ }
24
+ return classes.join("\n");
25
+ };
26
+ const getTemplateKeys = (templates) => {
27
+ return Object.keys(templates);
28
+ };
29
+ const getTemplateTypes = (templates) => {
30
+ if (!templates) return {};
31
+ return Object.entries(templates).reduce((acc, [key, value]) => {
32
+ if (typeof value === "function") {
33
+ acc[key] = "any";
34
+ } else if (typeof value === "object")
35
+ acc[key] = getTemplateTokens(value).map((val) => `"${val}"`).join(" | ");
36
+ return acc;
37
+ }, {});
38
+ };
39
+ const getTemplateTokens = (templates, parent = "", templateTokens = /* @__PURE__ */ new Set()) => {
40
+ if (!templates) return [];
41
+ Object.entries(templates).forEach(([key, value]) => {
42
+ const keyValue = parent ? `${parent}.${key}` : key;
43
+ if (typeof value === "object") return getTemplateTokens(value, keyValue, templateTokens);
44
+ return templateTokens.add(parent);
45
+ });
46
+ return [...templateTokens];
47
+ };
48
+ export {
49
+ getTemplateKeys,
50
+ getTemplateTokens,
51
+ getTemplateTypes,
52
+ parseAndJoinStyles,
53
+ c as parseStyles,
54
+ parseTemplates,
55
+ b as parseValueModifiers,
56
+ d as parseValueTokens,
57
+ a as parseVariableTokens
58
+ };
@@ -0,0 +1,3 @@
1
+ import { CssModifiers } from '../types/config-types';
2
+ import { StyleValueModifierFunction } from './parser-types';
3
+ export declare const parseValueModifiers: (modifiers?: CssModifiers) => StyleValueModifierFunction;
@@ -0,0 +1,13 @@
1
+ import { CachedConfig, SaltyConfig } from '../types/config-types';
2
+ /**
3
+ * Transform styles object to css string with or without scope
4
+ * @param styles CSS as JS object
5
+ * @param currentScope Scope of the styles, for class names full path with dot separator is required
6
+ * @param config Salty config object to allow use of templates and media queries etc.
7
+ * @param omitTemplates If true, static templates will be ignored
8
+ * @returns CSS strings that can be injected to the .css file or used inside of styles tag
9
+ * - First item is the main class with all the styles
10
+ * - Rest of the items are child selectors or media queries etc.
11
+ */
12
+ export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | CachedConfig | undefined, omitTemplates?: boolean) => Promise<string[]>;
13
+ export declare const parseAndJoinStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<string>;
@@ -0,0 +1,4 @@
1
+ export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => Promise<string>;
2
+ export declare const getTemplateKeys: <T extends object>(templates: T) => string[];
3
+ export declare const getTemplateTypes: <T extends object>(templates: T) => Record<string, string>;
4
+ export declare const getTemplateTokens: <T extends object>(templates: T, parent?: string, templateTokens?: Set<string>) => string[];
@@ -0,0 +1,3 @@
1
+ import { SyncronousStyleValueModifierFunction } from './parser-types';
2
+ export declare const parseValueTokens: (tokenNames?: string[]) => SyncronousStyleValueModifierFunction;
3
+ export declare const parseVariableTokens: SyncronousStyleValueModifierFunction;
@@ -0,0 +1,8 @@
1
+ export interface ValueParserReturnValue {
2
+ transformed: string;
3
+ additionalCss?: object[];
4
+ }
5
+ type StyleValueModifierFunctionReturnValue = undefined | ValueParserReturnValue;
6
+ export type SyncronousStyleValueModifierFunction = (current: unknown) => StyleValueModifierFunctionReturnValue;
7
+ export type StyleValueModifierFunction = (current: string) => Promise<StyleValueModifierFunctionReturnValue> | StyleValueModifierFunctionReturnValue;
8
+ export {};
@@ -0,0 +1 @@
1
+ export declare const propertyNameCheck: (key: string) => string;
@@ -0,0 +1,7 @@
1
+ import { SaltyConfig } from '../config';
2
+ /**
3
+ * Add unit to a number value based on property name
4
+ * @param key - The property name
5
+ * @param value - The value to add unit to
6
+ */
7
+ export declare const addUnit: (key: string, value: string | number, config?: SaltyConfig) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ function pascalCase(str) {
3
+ if (!str) return "";
4
+ if (typeof str !== "string") return pascalCase(String(str));
5
+ return str.replace(/\s/g, "-").replace(/[-_]([a-z0-9])/g, (g) => g[1].toUpperCase()).replace(/^[a-z]/, (g) => g.toUpperCase());
6
+ }
7
+ exports.pascalCase = pascalCase;
@@ -0,0 +1,8 @@
1
+ function pascalCase(str) {
2
+ if (!str) return "";
3
+ if (typeof str !== "string") return pascalCase(String(str));
4
+ return str.replace(/\s/g, "-").replace(/[-_]([a-z0-9])/g, (g) => g[1].toUpperCase()).replace(/^[a-z]/, (g) => g.toUpperCase());
5
+ }
6
+ export {
7
+ pascalCase as p
8
+ };
@@ -1,4 +1,4 @@
1
- const e = `import { styled } from "@salty-css/react/styled";
1
+ const reactStyledFile = `import { styled } from "@salty-css/react/styled";
2
2
 
3
3
  export const <%- name %> = styled('<%- tag %>', {
4
4
  <% if(className) { %>className: '<%- className %>',<% } %>
@@ -7,5 +7,5 @@ export const <%- name %> = styled('<%- tag %>', {
7
7
  }
8
8
  })`;
9
9
  export {
10
- e as default
10
+ reactStyledFile as default
11
11
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const reactStyledFile = `import { styled } from "@salty-css/react/styled";
4
+
5
+ export const <%- name %> = styled('<%- tag %>', {
6
+ <% if(className) { %>className: '<%- className %>',<% } %>
7
+ base: {
8
+ // Add your styles here
9
+ }
10
+ })`;
11
+ exports.default = reactStyledFile;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const reactVanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
4
+
5
+ interface <%- componentName %>Props {
6
+ text?: string;
7
+ }
8
+
9
+ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
10
+ return (
11
+ <<%- styledComponentName %>>
12
+ {text}
13
+ </<%- styledComponentName %>>
14
+ );
15
+ };
16
+
17
+ export default <%- componentName %>;`;
18
+ exports.default = reactVanillaFile;
@@ -0,0 +1,18 @@
1
+ const reactVanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
2
+
3
+ interface <%- componentName %>Props {
4
+ text?: string;
5
+ }
6
+
7
+ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
8
+ return (
9
+ <<%- styledComponentName %>>
10
+ {text}
11
+ </<%- styledComponentName %>>
12
+ );
13
+ };
14
+
15
+ export default <%- componentName %>;`;
16
+ export {
17
+ reactVanillaFile as default
18
+ };
@@ -0,0 +1,4 @@
1
+ const salty_config = "import { defineConfig } from '@salty-css/core/config';\n\nexport const config = defineConfig({\n // Add your custom config here\n externalModules: ['react', 'react-dom']\n});\n";
2
+ export {
3
+ salty_config as default
4
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const salty_config = "import { defineConfig } from '@salty-css/core/config';\n\nexport const config = defineConfig({\n // Add your custom config here\n externalModules: ['react', 'react-dom']\n});\n";
4
+ exports.default = salty_config;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const shouldRestart = require("../should-restart-DoaGoD5T.cjs");
4
+ exports.checkShouldRestart = shouldRestart.checkShouldRestart;
@@ -0,0 +1 @@
1
+ export * from './should-restart';
@@ -0,0 +1,4 @@
1
+ import { c } from "../should-restart-5jI-bzz0.js";
2
+ export {
3
+ c as checkShouldRestart
4
+ };
@@ -0,0 +1 @@
1
+ export declare const checkShouldRestart: (filename: string) => Promise<boolean>;
@@ -0,0 +1,18 @@
1
+ import { readFile } from "fs/promises";
2
+ import { isSaltyFile } from "./compiler/index.js";
3
+ const checkShouldRestart = async (filename) => {
4
+ if (!filename) return false;
5
+ if (filename.includes("node_modules")) return false;
6
+ if (filename.includes("saltygen")) return false;
7
+ const isConfig = filename.includes("salty.config");
8
+ if (isConfig) return true;
9
+ const isSalty = isSaltyFile(filename);
10
+ if (!isSalty) return false;
11
+ const contents = await readFile(filename, "utf-8");
12
+ if (/.+define[A-Z]\w+/.test(contents)) return true;
13
+ if (/.+keyframes\(.+/.test(contents)) return true;
14
+ return false;
15
+ };
16
+ export {
17
+ checkShouldRestart as c
18
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ const promises = require("fs/promises");
3
+ const compiler_index = require("./compiler/index.cjs");
4
+ const checkShouldRestart = async (filename) => {
5
+ if (!filename) return false;
6
+ if (filename.includes("node_modules")) return false;
7
+ if (filename.includes("saltygen")) return false;
8
+ const isConfig = filename.includes("salty.config");
9
+ if (isConfig) return true;
10
+ const isSalty = compiler_index.isSaltyFile(filename);
11
+ if (!isSalty) return false;
12
+ const contents = await promises.readFile(filename, "utf-8");
13
+ if (/.+define[A-Z]\w+/.test(contents)) return true;
14
+ if (/.+keyframes\(.+/.test(contents)) return true;
15
+ return false;
16
+ };
17
+ exports.checkShouldRestart = checkShouldRestart;
@@ -0,0 +1,2 @@
1
+ import { GlobalStyles } from '../types/config-types';
2
+ export declare const saltyReset: GlobalStyles;
@@ -0,0 +1,10 @@
1
+ export interface RCFile {
2
+ defaultProject?: string;
3
+ projects?: {
4
+ dir?: string;
5
+ framework?: string;
6
+ components?: string;
7
+ configDir?: string;
8
+ saltygenDir?: string;
9
+ }[];
10
+ }
@@ -0,0 +1,85 @@
1
+ import { BaseStyles, CssStyles, MediaQueryStyles } from '../types';
2
+ import { OrString } from '../types/util-types';
3
+ export type GlobalStyles = Record<string, BaseStyles>;
4
+ export type CssVariableTokensObject = Record<string, unknown>;
5
+ export interface CssResponsiveVariables {
6
+ [key: string]: CssVariableTokensObject;
7
+ }
8
+ export interface CssConditionalVariables {
9
+ [key: PropertyKey]: {
10
+ [key: PropertyKey]: CssVariableTokensObject;
11
+ };
12
+ }
13
+ export interface SaltyVariables {
14
+ responsive?: CssResponsiveVariables;
15
+ conditional?: CssConditionalVariables;
16
+ [key: string]: undefined | string | number | CssVariableTokensObject;
17
+ }
18
+ type CssTemplate = MediaQueryStyles | CssStyles | {
19
+ [key: PropertyKey]: CssTemplate;
20
+ };
21
+ export interface CssTemplateObject {
22
+ [key: PropertyKey]: CssTemplate;
23
+ }
24
+ export interface CssTemplateFunction {
25
+ (value: any): CssTemplate;
26
+ }
27
+ export interface CssTemplates {
28
+ [key: PropertyKey]: CssTemplateObject | CssTemplateFunction;
29
+ }
30
+ export interface CssModifier {
31
+ pattern: RegExp;
32
+ transform: (regexMatch: string) => {
33
+ css?: CssStyles;
34
+ value: string;
35
+ };
36
+ }
37
+ export type CssModifiers = Record<string, CssModifier>;
38
+ export interface SaltyConfig {
39
+ /**
40
+ * The import strategy to use when importing css files.
41
+ * - `root` will import the css file from the root of the project.
42
+ * - `component` will import the css file from the component's directory.
43
+ */
44
+ importStrategy?: 'root' | 'component';
45
+ /**
46
+ * Base level variables that can be used in all styles as they are applied globally to :root.
47
+ @param responsive Variables that are defined for different media queries.
48
+ @param conditional Variables that are defined for different parent selectors (classes or data attributes).
49
+ */
50
+ variables?: SaltyVariables;
51
+ /**
52
+ * The global styles that are imported in the root of the project.
53
+ */
54
+ reset?: 'default' | 'none' | GlobalStyles;
55
+ /**
56
+ * The global styles that are imported in the root of the project.
57
+ */
58
+ global?: GlobalStyles;
59
+ /**
60
+ * The templates that can be used in styles to create reusable css.
61
+ */
62
+ templates?: CssTemplates;
63
+ /**
64
+ * The modifiers that can transform css values.
65
+ */
66
+ modifiers?: CssModifiers;
67
+ /**
68
+ * Define modules that should not be bundled when generating the css file. This improves the performance of the css generation and can help with issues relared to external packages being imported in an environment that does not support them.
69
+ */
70
+ externalModules?: ('react' | 'react-dom' | OrString)[];
71
+ /**
72
+ * default unit for px based properties when providing a number value. Default is 'px'.
73
+ */
74
+ defaultUnit?: 'px' | 'rem' | 'em' | 'vh' | 'vw' | 'vmin' | 'vmax' | 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'ch' | 'ex' | 'fr' | 'percent' | `viewport-clamp:${number}` | OrString;
75
+ }
76
+ export interface CachedConfig {
77
+ templates: CssTemplates;
78
+ staticVariables: Record<string, any>;
79
+ mediaQueries: Record<string, string>;
80
+ modifiers?: CssModifiers;
81
+ templatePaths: {
82
+ [key: string]: string;
83
+ };
84
+ }
85
+ export {};
package/types/index.d.ts CHANGED
@@ -1,63 +1,97 @@
1
- import { AllHTMLAttributes, ReactDOM, ReactNode } from 'react';
2
- import { StyleComponentGenerator } from '../generator';
3
- import { OrString } from './util-types';
1
+ import { ReactNode } from 'react';
2
+ import { NeverObj, OrAny, OrString } from './util-types';
3
+ import { StyledGenerator } from '../generators';
4
+ import type * as CSS from 'csstype';
4
5
  export type CreateElementProps = {
5
6
  extend?: Tag<any>;
6
7
  children?: ReactNode;
7
8
  className?: string;
8
9
  element?: string;
9
- passVariantProps?: boolean;
10
- style?: any;
10
+ passProps?: boolean | string | string[];
11
+ style?: CssProperties | {
12
+ [key: string]: PropertyValueToken | NeverObj;
13
+ };
11
14
  /** vks = Variant key set */
12
15
  _vks?: Set<string>;
13
16
  };
14
17
  export type StyledComponentProps = Record<string, unknown> & CreateElementProps;
15
18
  type FnComponent<PROPS extends StyledComponentProps> = {
16
- (props: PROPS): ReactNode;
17
- generator?: StyleComponentGenerator;
19
+ (props: OrAny | PROPS): ReactNode;
20
+ generator?: StyledGenerator;
18
21
  };
19
- export type Tag<PROPS extends StyledComponentProps> = OrString | keyof ReactDOM | FnComponent<PROPS>;
20
- export type CompoundVariant = {
21
- [key: PropertyKey]: any;
22
- css: CssStyles;
22
+ export type Tag<PROPS extends StyledComponentProps> = OrString | keyof HTMLElementTagNameMap | FnComponent<PROPS>;
23
+ type CSSPropertyValueFunction = (params?: any) => any;
24
+ export type CssProperties = {
25
+ [key in keyof CSS.Properties]: CSS.Properties[key] | PropertyValueToken | CSSPropertyValueFunction | NeverObj;
23
26
  };
24
- type InvalidVariantKeys = keyof AllHTMLAttributes<HTMLElement>;
25
- type StyleKeys = keyof Required<AllHTMLAttributes<HTMLElement>>['style'];
26
- export type StyleValue<K extends string> = K extends StyleKeys ? Required<AllHTMLAttributes<HTMLElement>>['style'][K] : never;
27
+ type CssPropertyKeys = keyof CssProperties;
28
+ export type StyleValue<K extends string> = K extends CssPropertyKeys ? CssProperties[K] : never;
29
+ type InvalidVariantKeys = '' | 'css';
27
30
  type VariantOptions = {
28
31
  [key in InvalidVariantKeys]?: never;
29
32
  };
33
+ export type MultiVariant = {
34
+ [key: PropertyKey]: string | boolean | undefined;
35
+ } | {
36
+ css: CSSinJS;
37
+ };
30
38
  type Variants = {
31
39
  variants?: VariantOptions & {
32
40
  [key: PropertyKey]: {
33
- [key: string]: Styles;
41
+ [key: PropertyKey]: CSSinJS;
34
42
  };
35
43
  };
36
44
  defaultVariants?: {
37
45
  [key: PropertyKey]: any;
38
46
  };
39
- compoundVariants?: CompoundVariant[];
47
+ compoundVariants?: MultiVariant[];
48
+ anyOfVariants?: MultiVariant[];
40
49
  };
41
- type VariantPropValue<T> = T extends 'true' ? 'true' | true : T;
42
- export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? object : {
43
- [K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
50
+ type BooleanVariantValue = 'true' | 'false' | boolean;
51
+ type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T extends boolean ? BooleanVariantValue : T | '';
52
+ type PickType<T, K extends AllKeys<T>> = T extends {
53
+ [k in K]?: any;
54
+ } ? T[K] : undefined;
55
+ type AllKeys<T> = T extends any ? keyof T : never;
56
+ export type Merge<T> = {
57
+ [k in AllKeys<T>]?: PickType<T, k>;
44
58
  };
59
+ export type VariantProps<STYLES extends StyledParams, B = STYLES['variants'] extends undefined ? object : STYLES['variants'], C = STYLES['compoundVariants'] extends MultiVariant[] ? Merge<STYLES['compoundVariants'][number]> : object, U = STYLES['anyOfVariants'] extends MultiVariant[] ? Merge<STYLES['anyOfVariants'][number]> : object> = Merge<{
60
+ [K in keyof B]?: K extends 'css' ? never : VariantPropValue<keyof B[K]>;
61
+ } | {
62
+ [K in keyof C]?: K extends 'css' ? never : VariantPropValue<C[K]>;
63
+ } | {
64
+ [K in keyof U]?: K extends 'css' ? never : VariantPropValue<U[K]>;
65
+ }>;
45
66
  type CssValuePropKey = `props-${string}`;
46
67
  export type ValueProps = {
47
68
  [key: CssValuePropKey]: string;
48
69
  };
49
- export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : unknown;
70
+ export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : object;
50
71
  type StylePropertyValue = Record<never, never> & unknown;
72
+ export type CSSinJS = CssProperties | StylePropertyValue | TemplateTokens | CssPseudos;
51
73
  export type CssStyles = {
52
- [key in StyleKeys | OrString]?: StyleValue<key> | StylePropertyValue | PropertyValueToken | CssStyles;
74
+ [key in OrString]?: CSSinJS | CssStyles;
53
75
  };
54
76
  export type Styles = CssStyles & Variants;
77
+ export type MediaQueryStyles = {
78
+ [key in MediaQueryKeys]?: CssProperties | CssStyles | CssPseudos | TemplateTokens | MediaQueryStyles;
79
+ };
55
80
  export interface GeneratorOptions {
56
- className?: string;
81
+ className?: string | string[];
57
82
  displayName?: string;
58
83
  element?: string;
84
+ passProps?: boolean | string | string[];
85
+ defaultProps?: Record<PropertyKey, unknown>;
86
+ priority?: number;
87
+ }
88
+ export interface BaseStyles extends CssProperties, CssStyles, CssPseudos, TemplateTokens, MediaQueryStyles {
59
89
  }
90
+ type Pseudos = CSS.Pseudos | `&${CSS.Pseudos}`;
91
+ type CssPseudos = {
92
+ [P in Pseudos]?: CssStyles;
93
+ };
60
94
  export interface StyledParams extends GeneratorOptions, Variants {
61
- base?: CssStyles;
95
+ base?: BaseStyles;
62
96
  }
63
97
  export {};
@@ -0,0 +1 @@
1
+ export declare function dotCase(str: PropertyKey): string;
package/util/index.cjs CHANGED
@@ -1 +1,13 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../dash-case-DKzpenwY.cjs"),t=require("../pascal-case-iWoaJWwT.cjs");function s(e){return e?typeof e!="string"?s(String(e)):e.replace(/\s/g,"-").replace(/-([a-z])/g,r=>r[1].toUpperCase()):""}exports.dashCase=a.dashCase;exports.toHash=a.toHash;exports.pascalCase=t.pascalCase;exports.camelCase=s;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const dashCase = require("../dash-case-Cz8wwE9a.cjs");
4
+ const pascalCase = require("../pascal-case-By_l58S-.cjs");
5
+ function camelCase(str) {
6
+ if (!str) return "";
7
+ if (typeof str !== "string") return camelCase(String(str));
8
+ return str.replace(/\s/g, "-").replace(/-([a-z])/g, (g) => g[1].toUpperCase());
9
+ }
10
+ exports.dashCase = dashCase.dashCase;
11
+ exports.toHash = dashCase.toHash;
12
+ exports.pascalCase = pascalCase.pascalCase;
13
+ exports.camelCase = camelCase;
package/util/index.js CHANGED
@@ -1,11 +1,13 @@
1
- import { d as o, t as s } from "../dash-case-DMQMcCO6.js";
2
- import { p as f } from "../pascal-case-BQpR5PdN.js";
3
- function r(e) {
4
- return e ? typeof e != "string" ? r(String(e)) : e.replace(/\s/g, "-").replace(/-([a-z])/g, (a) => a[1].toUpperCase()) : "";
1
+ import { d, t } from "../dash-case-NMk0mXyT.js";
2
+ import { p } from "../pascal-case-F3Usi5Wf.js";
3
+ function camelCase(str) {
4
+ if (!str) return "";
5
+ if (typeof str !== "string") return camelCase(String(str));
6
+ return str.replace(/\s/g, "-").replace(/-([a-z])/g, (g) => g[1].toUpperCase());
5
7
  }
6
8
  export {
7
- r as camelCase,
8
- o as dashCase,
9
- f as pascalCase,
10
- s as toHash
9
+ camelCase,
10
+ d as dashCase,
11
+ p as pascalCase,
12
+ t as toHash
11
13
  };
@@ -0,0 +1 @@
1
+ export declare const detectCurrentModuleType: (dirname: string) => Promise<"esm" | "cjs">;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ const defineViewportClamp = (config) => (value, min, max) => {
3
+ const { screenSize, axis = "horizontal", minMultiplier = 0.5, maxMultiplier = 1.5, minMaxUnit = "px" } = config;
4
+ const relativeValue = Math.round(value / screenSize * 1e4) / 100;
5
+ const relativeUnit = axis === "vertical" ? "vh" : "vw";
6
+ const minValue = min || Math.round(minMultiplier * value);
7
+ const maxValue = max || Math.round(maxMultiplier * value);
8
+ return `clamp(${minValue}${minMaxUnit}, ${relativeValue}${relativeUnit}, ${maxValue}${minMaxUnit})`;
9
+ };
10
+ exports.defineViewportClamp = defineViewportClamp;
@@ -0,0 +1,11 @@
1
+ const defineViewportClamp = (config) => (value, min, max) => {
2
+ const { screenSize, axis = "horizontal", minMultiplier = 0.5, maxMultiplier = 1.5, minMaxUnit = "px" } = config;
3
+ const relativeValue = Math.round(value / screenSize * 1e4) / 100;
4
+ const relativeUnit = axis === "vertical" ? "vh" : "vw";
5
+ const minValue = min || Math.round(minMultiplier * value);
6
+ const maxValue = max || Math.round(maxMultiplier * value);
7
+ return `clamp(${minValue}${minMaxUnit}, ${relativeValue}${relativeUnit}, ${maxValue}${minMaxUnit})`;
8
+ };
9
+ export {
10
+ defineViewportClamp as d
11
+ };
@@ -1,59 +0,0 @@
1
- import { CssStyles } from '../types';
2
- type CssTemplate = CssStyles | {
3
- [key: PropertyKey]: CssTemplate;
4
- };
5
- export type CssVariables = Record<string, unknown>;
6
- export interface CssResponsiveVariables {
7
- [key: string]: CssVariables;
8
- }
9
- export interface CssConditionalVariables {
10
- [key: PropertyKey]: {
11
- [key: PropertyKey]: CssVariables;
12
- };
13
- }
14
- export interface CssTemplates {
15
- [key: PropertyKey]: {
16
- [key: PropertyKey]: CssTemplate;
17
- };
18
- }
19
- export interface CssModifier {
20
- pattern: RegExp;
21
- transform: (regexMatch: string) => {
22
- css?: CssStyles;
23
- value: string;
24
- };
25
- }
26
- export type CssModifiers = Record<string, CssModifier>;
27
- export interface SaltyConfig {
28
- /**
29
- * The import strategy to use when importing css files.
30
- * - `root` will import the css file from the root of the project.
31
- * - `component` will import the css file from the component's directory.
32
- */
33
- importStrategy?: 'root' | 'component';
34
- /**
35
- * Base variables that can be used in all styles as they are applied globally to :root.
36
- */
37
- variables?: CssVariables;
38
- /**
39
- * Variables that are defined for different media queries.
40
- */
41
- responsiveVariables?: CssResponsiveVariables;
42
- /**
43
- * Variables that are defined for different parent selectors (classes or data attributes).
44
- */
45
- conditionalVariables?: CssConditionalVariables;
46
- /**
47
- * The global styles that are imported in the root of the project.
48
- */
49
- global?: CssStyles;
50
- /**
51
- * The templates that can be used in styles to create reusable css.
52
- */
53
- templates?: CssTemplates;
54
- /**
55
- * The modifiers that can transform css values.
56
- */
57
- modifiers?: CssModifiers;
58
- }
59
- export {};
@@ -1 +0,0 @@
1
- "use strict";const n=e=>String.fromCharCode(e+(e>25?39:97)),i=(e,r)=>{let t="",a;for(a=Math.abs(e);a>52;a=a/52|0)t=n(a%52)+t;return t=n(a%52)+t,t.length<r?t=t.padStart(r,"a"):t.length>r&&(t=t.slice(-r)),t},o=(e,r)=>{let t=r.length;for(;t;)e=e*33^r.charCodeAt(--t);return e},c=(e,r=3)=>{const t=o(5381,JSON.stringify(e))>>>0;return i(t,r)};function s(e){return e?typeof e!="string"?s(String(e)):e.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(r,t)=>(t>0?"-":"")+r.toLowerCase()):""}exports.dashCase=s;exports.toHash=c;
@@ -1,19 +0,0 @@
1
- const n = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), o = (e, r) => {
2
- let t = "", a;
3
- for (a = Math.abs(e); a > 52; a = a / 52 | 0) t = n(a % 52) + t;
4
- return t = n(a % 52) + t, t.length < r ? t = t.padStart(r, "a") : t.length > r && (t = t.slice(-r)), t;
5
- }, i = (e, r) => {
6
- let t = r.length;
7
- for (; t; ) e = e * 33 ^ r.charCodeAt(--t);
8
- return e;
9
- }, c = (e, r = 3) => {
10
- const t = i(5381, JSON.stringify(e)) >>> 0;
11
- return o(t, r);
12
- };
13
- function s(e) {
14
- return e ? typeof e != "string" ? s(String(e)) : e.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (r, t) => (t > 0 ? "-" : "") + r.toLowerCase()) : "";
15
- }
16
- export {
17
- s as d,
18
- c as t
19
- };