@salty-css/core 0.0.1-alpha.20 → 0.0.1-alpha.201

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 (88) hide show
  1. package/.saltyrc.schema.json +48 -0
  2. package/README.md +143 -26
  3. package/bin/index.cjs +1 -8
  4. package/bin/index.js +2 -128
  5. package/bin/logger.d.ts +1 -0
  6. package/bin/main.cjs +11 -0
  7. package/bin/main.d.ts +1 -0
  8. package/bin/main.js +260 -0
  9. package/compiler/get-files.d.ts +3 -0
  10. package/compiler/index.cjs +1 -11
  11. package/compiler/index.d.ts +11 -6
  12. package/compiler/index.js +17 -172
  13. package/config/define-config.d.ts +1 -1
  14. package/config/index.cjs +1 -1
  15. package/config/index.d.ts +2 -1
  16. package/config/index.js +10 -2
  17. package/css/index.cjs +1 -1
  18. package/css/index.d.ts +4 -1
  19. package/css/index.js +9 -2
  20. package/css/keyframes.cjs +1 -0
  21. package/css/keyframes.d.ts +22 -0
  22. package/css/keyframes.js +34 -0
  23. package/css/media.cjs +1 -0
  24. package/css/media.d.ts +87 -0
  25. package/css/media.js +88 -0
  26. package/css/merge.cjs +1 -0
  27. package/css/merge.d.ts +6 -0
  28. package/css/merge.js +4 -0
  29. package/css/token.cjs +1 -0
  30. package/css/token.d.ts +1 -0
  31. package/css/token.js +4 -0
  32. package/{dash-case-DKzpenwY.cjs → dash-case-BJEkFEGQ.cjs} +1 -1
  33. package/{dash-case-DMQMcCO6.js → dash-case-DBThphLm.js} +2 -2
  34. package/factories/define-global-styles.d.ts +7 -0
  35. package/factories/define-media-query.d.ts +8 -0
  36. package/factories/define-templates.d.ts +10 -0
  37. package/factories/define-variables.d.ts +12 -0
  38. package/factories/index.d.ts +4 -0
  39. package/generators/class-name-generator.d.ts +6 -0
  40. package/generators/index.cjs +1 -0
  41. package/generators/index.d.ts +2 -0
  42. package/generators/index.js +75 -0
  43. package/generators/styled-generator.d.ts +19 -0
  44. package/generators/styles-generator.d.ts +18 -0
  45. package/helpers/color.d.ts +18 -0
  46. package/helpers/index.cjs +1 -0
  47. package/helpers/index.d.ts +1 -0
  48. package/helpers/index.js +1152 -0
  49. package/index-BtsgjRXm.cjs +38 -0
  50. package/index-DVzNO1Qt.js +486 -0
  51. package/package.json +34 -2
  52. package/parse-styles-Bjxh8lZv.js +107 -0
  53. package/parse-styles-D_gL6efj.cjs +7 -0
  54. package/parsers/index.cjs +1 -0
  55. package/parsers/index.d.ts +5 -0
  56. package/parsers/index.js +37 -0
  57. package/{generator → parsers}/parse-modifiers.d.ts +1 -1
  58. package/parsers/parse-styles.d.ts +2 -0
  59. package/parsers/parse-templates.d.ts +4 -0
  60. package/{generator → parsers}/parser-types.d.ts +1 -1
  61. package/parsers/property-name-check.d.ts +1 -0
  62. package/parsers/unit-check.d.ts +7 -0
  63. package/react-vanilla-file-CCXbsjIb.js +18 -0
  64. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  65. package/{salty.config-D9ANEDiH.js → salty.config-BhBY_oOk.js} +1 -0
  66. package/{salty.config-BupieCfE.cjs → salty.config-Dk6ZcCxI.cjs} +3 -2
  67. package/server/index.cjs +1 -0
  68. package/server/index.d.ts +1 -0
  69. package/server/index.js +12 -0
  70. package/server/should-restart.d.ts +1 -0
  71. package/templates/salty-reset.d.ts +2 -0
  72. package/types/cli-types.d.ts +10 -0
  73. package/types/config-types.d.ts +77 -0
  74. package/types/index.d.ts +52 -22
  75. package/util/dot-case.d.ts +1 -0
  76. package/util/index.cjs +1 -1
  77. package/util/index.js +1 -1
  78. package/util/module-type.d.ts +1 -0
  79. package/config/config-types.d.ts +0 -59
  80. package/generator/index.cjs +0 -1
  81. package/generator/index.d.ts +0 -1
  82. package/generator/index.js +0 -61
  83. package/generator/parse-styles.d.ts +0 -2
  84. package/generator/parse-templates.d.ts +0 -2
  85. package/generator/style-generator.d.ts +0 -28
  86. package/parse-templates-D4p3pgQR.js +0 -92
  87. package/parse-templates-W0YfTmOT.cjs +0 -8
  88. /package/{generator → parsers}/parse-tokens.d.ts +0 -0
@@ -0,0 +1,107 @@
1
+ import { d as y } from "./dash-case-DBThphLm.js";
2
+ const T = (r, e) => {
3
+ if (typeof r != "string") return { result: r };
4
+ if (!e) return { result: r };
5
+ const s = [];
6
+ return Object.values(e).forEach((p) => {
7
+ const { pattern: i, transform: w } = p;
8
+ r = r.replace(i, (n) => {
9
+ const { value: a, css: t } = w(n);
10
+ return t && s.push(t), a;
11
+ });
12
+ }), { result: r, additionalCss: s };
13
+ }, z = (r) => typeof r != "string" ? { result: r } : /\{[^{}]+\}/g.test(r) ? { result: r.replace(/\{([^{}]+)\}/g, (...p) => `var(--${y(p[1].replaceAll(".", "-"))})`) } : { result: r }, U = [
14
+ "top",
15
+ "right",
16
+ "bottom",
17
+ "left",
18
+ "min-width",
19
+ /.*width.*/,
20
+ /^[^line]*height.*/,
21
+ // Exclude line-height
22
+ /padding.*/,
23
+ /margin.*/,
24
+ /border.*/,
25
+ /inset.*/,
26
+ /.*radius.*/,
27
+ /.*spacing.*/,
28
+ /.*gap.*/,
29
+ /.*indent.*/,
30
+ /.*offset.*/,
31
+ /.*size.*/,
32
+ /.*thickness.*/,
33
+ /.*font-size.*/
34
+ ], M = (r, e, s) => {
35
+ if (U.some((i) => typeof i == "string" ? i === r : i.test(r))) {
36
+ const i = (s == null ? void 0 : s.defaultUnit) || "px";
37
+ return `${e}${i}`;
38
+ }
39
+ return `${e}`;
40
+ }, N = ["Webkit", "Moz", "ms", "O"], Q = (r) => r.startsWith("-") ? r : N.some((e) => r.startsWith(e)) ? `-${y(r)}` : y(r), c = (r, e, s) => {
41
+ if (!r) return "";
42
+ const p = [], i = Object.entries(r).reduce((n, [a, t]) => {
43
+ var S;
44
+ const o = a.trim(), O = Q(o), P = (f, h = ";") => n = `${n}${f}${h}`, b = (f) => P(`${O}:${f}`);
45
+ if (typeof t == "function" && (t = t()), typeof t == "object") {
46
+ if (!t) return n;
47
+ if (t.isColor)
48
+ return b(t.toString()), n;
49
+ if (o === "variants")
50
+ return Object.entries(t).forEach(([u, d]) => {
51
+ d && Object.entries(d).forEach(([$, m]) => {
52
+ if (!m) return;
53
+ const l = `${e}.${u}-${$}`, j = c(m, l, s);
54
+ p.push(j);
55
+ });
56
+ }), n;
57
+ if (o === "defaultVariants")
58
+ return n;
59
+ if (o === "compoundVariants")
60
+ return t.forEach((u) => {
61
+ const { css: d, ...$ } = u, m = Object.entries($).reduce((j, [W, x]) => `${j}.${W}-${x}`, e), l = c(d, m, s);
62
+ p.push(l);
63
+ }), n;
64
+ if (o.startsWith("@")) {
65
+ const u = ((S = s == null ? void 0 : s.mediaQueries) == null ? void 0 : S[o]) || o, d = c(t, e, s), $ = `${u} {
66
+ ${d.replace(`
67
+ `, `
68
+ `)}
69
+ }`;
70
+ return p.push($), n;
71
+ }
72
+ const f = a.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, h = c(t, f, s);
73
+ return p.push(h), n;
74
+ }
75
+ if (s != null && s.templates && s.templates[o]) {
76
+ const h = t.split(".").reduce((u, d) => u[d], s.templates[o]);
77
+ if (h) {
78
+ const u = c(h, "");
79
+ return `${n}${u}`;
80
+ }
81
+ return console.warn(`Template "${o}" with path of "${t}" was not found in config!`), n;
82
+ }
83
+ if (typeof t == "number") {
84
+ const f = M(O, t, s);
85
+ return b(f);
86
+ }
87
+ if (typeof t != "string")
88
+ if ("toString" in t) t = t.toString();
89
+ else return n;
90
+ const { modifiers: E } = s || {}, V = function* () {
91
+ yield z(t), yield T(t, E);
92
+ }();
93
+ for (const { result: f, additionalCss: h = [] } of V)
94
+ t = f, h.forEach((u) => {
95
+ const d = c(u, "");
96
+ P(d, "");
97
+ });
98
+ return b(t);
99
+ }, "");
100
+ return i ? e ? [`${e} { ${i} }`, ...p].join(`
101
+ `) : i : p.join(`
102
+ `);
103
+ };
104
+ export {
105
+ z as a,
106
+ c as p
107
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";const j=require("./dash-case-BJEkFEGQ.cjs"),z=(r,e)=>{if(typeof r!="string")return{result:r};if(!e)return{result:r};const s=[];return Object.values(e).forEach(p=>{const{pattern:i,transform:S}=p;r=r.replace(i,n=>{const{value:$,css:t}=S(n);return t&&s.push(t),$})}),{result:r,additionalCss:s}},V=r=>typeof r!="string"?{result:r}:/\{[^{}]+\}/g.test(r)?{result:r.replace(/\{([^{}]+)\}/g,(...p)=>`var(--${j.dashCase(p[1].replaceAll(".","-"))})`)}:{result:r},U=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],k=(r,e,s)=>{if(U.some(i=>typeof i=="string"?i===r:i.test(r))){const i=(s==null?void 0:s.defaultUnit)||"px";return`${e}${i}`}return`${e}`},q=["Webkit","Moz","ms","O"],M=r=>r.startsWith("-")?r:q.some(e=>r.startsWith(e))?`-${j.dashCase(r)}`:j.dashCase(r),a=(r,e,s)=>{if(!r)return"";const p=[],i=Object.entries(r).reduce((n,[$,t])=>{var P;const o=$.trim(),w=M(o),O=(f,h=";")=>n=`${n}${f}${h}`,b=f=>O(`${w}:${f}`);if(typeof t=="function"&&(t=t()),typeof t=="object"){if(!t)return n;if(t.isColor)return b(t.toString()),n;if(o==="variants")return Object.entries(t).forEach(([u,d])=>{d&&Object.entries(d).forEach(([c,m])=>{if(!m)return;const l=`${e}.${u}-${c}`,y=a(m,l,s);p.push(y)})}),n;if(o==="defaultVariants")return n;if(o==="compoundVariants")return t.forEach(u=>{const{css:d,...c}=u,m=Object.entries(c).reduce((y,[W,x])=>`${y}.${W}-${x}`,e),l=a(d,m,s);p.push(l)}),n;if(o.startsWith("@")){const u=((P=s==null?void 0:s.mediaQueries)==null?void 0:P[o])||o,d=a(t,e,s),c=`${u} {
2
+ ${d.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return p.push(c),n}const f=$.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,h=a(t,f,s);return p.push(h),n}if(s!=null&&s.templates&&s.templates[o]){const h=t.split(".").reduce((u,d)=>u[d],s.templates[o]);if(h){const u=a(h,"");return`${n}${u}`}return console.warn(`Template "${o}" with path of "${t}" was not found in config!`),n}if(typeof t=="number"){const f=k(w,t,s);return b(f)}if(typeof t!="string")if("toString"in t)t=t.toString();else return n;const{modifiers:E}=s||{},T=function*(){yield V(t),yield z(t,E)}();for(const{result:f,additionalCss:h=[]}of T)t=f,h.forEach(u=>{const d=a(u,"");O(d,"")});return b(t)},"");return i?e?[`${e} { ${i} }`,...p].join(`
6
+ `):i:p.join(`
7
+ `)};exports.parseStyles=a;exports.parseValueTokens=V;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../css/media.cjs");class r{constructor(t){this._current=t}get isGlobalDefine(){return!0}}const i=e=>new r(e),l=e=>e(n.media);class s{constructor(t){this._current=t}get isDefineVariables(){return!0}}const c=e=>new s(e);class a{constructor(t){this._current=t}get isDefineTemplates(){return!0}}const o=e=>new a(e);exports.GlobalStylesFactory=r;exports.TemplatesFactory=a;exports.VariablesFactory=s;exports.defineGlobalStyles=i;exports.defineMediaQuery=l;exports.defineTemplates=o;exports.defineVariables=c;
@@ -0,0 +1,5 @@
1
+ export * from './parse-modifiers';
2
+ export * from './parse-styles';
3
+ export * from './parse-templates';
4
+ export * from './parse-tokens';
5
+ export * from './parser-types';
@@ -0,0 +1,37 @@
1
+ import { media as t } from "../css/media.js";
2
+ class n {
3
+ constructor(r) {
4
+ this._current = r;
5
+ }
6
+ get isGlobalDefine() {
7
+ return !0;
8
+ }
9
+ }
10
+ const i = (e) => new n(e), o = (e) => e(t);
11
+ class s {
12
+ constructor(r) {
13
+ this._current = r;
14
+ }
15
+ get isDefineVariables() {
16
+ return !0;
17
+ }
18
+ }
19
+ const l = (e) => new s(e);
20
+ class a {
21
+ constructor(r) {
22
+ this._current = r;
23
+ }
24
+ get isDefineTemplates() {
25
+ return !0;
26
+ }
27
+ }
28
+ const u = (e) => new a(e);
29
+ export {
30
+ n as GlobalStylesFactory,
31
+ a as TemplatesFactory,
32
+ s as VariablesFactory,
33
+ i as defineGlobalStyles,
34
+ o as defineMediaQuery,
35
+ u as defineTemplates,
36
+ l as defineVariables
37
+ };
@@ -1,3 +1,3 @@
1
- import { CssModifiers } from '../config/config-types';
1
+ import { CssModifiers } from '../types/config-types';
2
2
  import { ValueParserReturnValue } from './parser-types';
3
3
  export declare const parseValueModifiers: (value: string, modifiers?: CssModifiers) => ValueParserReturnValue;
@@ -0,0 +1,2 @@
1
+ import { CachedConfig, SaltyConfig } from '../types/config-types';
2
+ export declare const parseStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined) => string;
@@ -0,0 +1,4 @@
1
+ export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => 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[];
@@ -1,4 +1,4 @@
1
1
  export interface ValueParserReturnValue {
2
2
  result: string;
3
- additionalCss?: Object[];
3
+ additionalCss?: object[];
4
4
  }
@@ -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,18 @@
1
+ const n = `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
+ n as default
18
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`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 %>;`;exports.default=e;
@@ -2,6 +2,7 @@ const n = `import { defineConfig } from '@salty-css/core/config';
2
2
 
3
3
  export const config = defineConfig({
4
4
  // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
5
6
  });
6
7
  `;
7
8
  export {
@@ -1,6 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=`import { defineConfig } from '@salty-css/core/config';
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { defineConfig } from '@salty-css/core/config';
2
2
 
3
3
  export const config = defineConfig({
4
4
  // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
5
6
  });
6
- `;exports.default=o;
7
+ `;exports.default=e;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-BtsgjRXm.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
@@ -0,0 +1 @@
1
+ export * from './should-restart';
@@ -0,0 +1,12 @@
1
+ import { readFile as r } from "fs/promises";
2
+ import { i as e } from "../index-DVzNO1Qt.js";
3
+ const f = async (t) => {
4
+ if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
5
+ if (t.includes("salty.config")) return !0;
6
+ if (!e(t)) return !1;
7
+ const s = await r(t, "utf-8");
8
+ return !!/.+define[A-Z]\w+/.test(s);
9
+ };
10
+ export {
11
+ f as checkShouldRestart
12
+ };
@@ -0,0 +1 @@
1
+ export declare const checkShouldRestart: (filename: string) => Promise<boolean>;
@@ -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,77 @@
1
+ import { CssProperties, CssStyles } from '../types';
2
+ import { OrString } from '../types/util-types';
3
+ export type GlobalStyles = Record<string, CssProperties>;
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 = CssStyles | {
19
+ [key: PropertyKey]: CssTemplate;
20
+ };
21
+ export interface CssTemplates {
22
+ [key: PropertyKey]: {
23
+ [key: PropertyKey]: CssTemplate;
24
+ };
25
+ }
26
+ export interface CssModifier {
27
+ pattern: RegExp;
28
+ transform: (regexMatch: string) => {
29
+ css?: CssStyles;
30
+ value: string;
31
+ };
32
+ }
33
+ export type CssModifiers = Record<string, CssModifier>;
34
+ export interface SaltyConfig {
35
+ /**
36
+ * The import strategy to use when importing css files.
37
+ * - `root` will import the css file from the root of the project.
38
+ * - `component` will import the css file from the component's directory.
39
+ */
40
+ importStrategy?: 'root' | 'component';
41
+ /**
42
+ * Base level variables that can be used in all styles as they are applied globally to :root.
43
+ @param responsive Variables that are defined for different media queries.
44
+ @param conditional Variables that are defined for different parent selectors (classes or data attributes).
45
+ */
46
+ variables?: SaltyVariables;
47
+ /**
48
+ * The global styles that are imported in the root of the project.
49
+ */
50
+ reset?: 'default' | 'none' | GlobalStyles;
51
+ /**
52
+ * The global styles that are imported in the root of the project.
53
+ */
54
+ global?: GlobalStyles;
55
+ /**
56
+ * The templates that can be used in styles to create reusable css.
57
+ */
58
+ templates?: CssTemplates;
59
+ /**
60
+ * The modifiers that can transform css values.
61
+ */
62
+ modifiers?: CssModifiers;
63
+ /**
64
+ * 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.
65
+ */
66
+ externalModules?: ('react' | 'react-dom' | OrString)[];
67
+ /**
68
+ * default unit for px based properties when providing a number value. Default is 'px'.
69
+ */
70
+ defaultUnit?: 'px' | 'rem' | 'em' | 'vh' | 'vw' | 'vmin' | 'vmax' | 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'ch' | 'ex' | 'fr' | 'percent' | OrString;
71
+ }
72
+ export interface CachedConfig {
73
+ templates: CssTemplates;
74
+ staticVariables: Record<string, any>;
75
+ mediaQueries: Record<string, string>;
76
+ }
77
+ export {};
package/types/index.d.ts CHANGED
@@ -1,36 +1,44 @@
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 CompoundVariant = {
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?: {
@@ -38,26 +46,48 @@ type Variants = {
38
46
  };
39
47
  compoundVariants?: CompoundVariant[];
40
48
  };
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]> | '';
49
+ type BooleanVariantValue = 'true' | 'false' | boolean;
50
+ type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T extends boolean ? BooleanVariantValue : T | '';
51
+ type PickType<T, K extends AllKeys<T>> = T extends {
52
+ [k in K]?: any;
53
+ } ? T[K] : undefined;
54
+ type AllKeys<T> = T extends any ? keyof T : never;
55
+ export type Merge<T> = {
56
+ [k in AllKeys<T>]?: PickType<T, k>;
44
57
  };
58
+ export type VariantProps<STYLES extends StyledParams, B = STYLES['variants'] extends undefined ? object : STYLES['variants'], C = STYLES['compoundVariants'] extends CompoundVariant[] ? Merge<STYLES['compoundVariants'][number]> : object> = Merge<{
59
+ [K in keyof B]?: K extends 'css' ? never : VariantPropValue<keyof B[K]>;
60
+ } | {
61
+ [K in keyof C]?: K extends 'css' ? never : VariantPropValue<C[K]>;
62
+ }>;
45
63
  type CssValuePropKey = `props-${string}`;
46
64
  export type ValueProps = {
47
65
  [key: CssValuePropKey]: string;
48
66
  };
49
- export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : unknown;
67
+ export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : object;
50
68
  type StylePropertyValue = Record<never, never> & unknown;
69
+ export type CSSinJS = CssProperties | StylePropertyValue | TemplateTokens | CssPseudos;
51
70
  export type CssStyles = {
52
- [key in StyleKeys | OrString]?: StyleValue<key> | StylePropertyValue | PropertyValueToken | CssStyles;
71
+ [key in OrString]?: CSSinJS | CssStyles;
53
72
  };
54
73
  export type Styles = CssStyles & Variants;
74
+ export type MediaQueryStyles = {
75
+ [key in MediaQueryKeys]?: CssProperties | CssStyles | CssPseudos | TemplateTokens | MediaQueryStyles;
76
+ };
55
77
  export interface GeneratorOptions {
56
- className?: string;
78
+ className?: string | string[];
57
79
  displayName?: string;
58
80
  element?: string;
81
+ passProps?: boolean | string | string[];
82
+ defaultProps?: Record<PropertyKey, unknown>;
59
83
  }
84
+ interface Base extends CssProperties, CssStyles, CssPseudos, TemplateTokens, MediaQueryStyles {
85
+ }
86
+ type Pseudos = CSS.Pseudos | `&${CSS.Pseudos}`;
87
+ type CssPseudos = {
88
+ [P in Pseudos]?: CssStyles;
89
+ };
60
90
  export interface StyledParams extends GeneratorOptions, Variants {
61
- base?: CssStyles;
91
+ base?: Base;
62
92
  }
63
93
  export {};
@@ -0,0 +1 @@
1
+ export declare function dotCase(str: PropertyKey): string;
package/util/index.cjs CHANGED
@@ -1 +1 @@
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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../dash-case-BJEkFEGQ.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;
package/util/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as o, t as s } from "../dash-case-DMQMcCO6.js";
1
+ import { d as o, t as s } from "../dash-case-DBThphLm.js";
2
2
  import { p as f } from "../pascal-case-BQpR5PdN.js";
3
3
  function r(e) {
4
4
  return e ? typeof e != "string" ? r(String(e)) : e.replace(/\s/g, "-").replace(/-([a-z])/g, (a) => a[1].toUpperCase()) : "";
@@ -0,0 +1 @@
1
+ export declare const detectCurrentModuleType: (dirname: string) => Promise<"esm" | "cjs">;
@@ -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";var m=Object.defineProperty;var l=(a,t,s)=>t in a?m(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var c=(a,t,s)=>l(a,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../dash-case-DKzpenwY.cjs"),p=require("../parse-templates-W0YfTmOT.cjs");class g{constructor(t,s){c(this,"_callerName");c(this,"_context");this.tagName=t,this.params=s}get hash(){return u.toHash(this.params.base||this.params)}get priority(){var t;return typeof this.tagName=="function"||typeof this.tagName=="object"?(((t=this.tagName.generator)==null?void 0:t.priority)||0)+1:0}get classNames(){const t=[this.hash],{className:s}=this.params;return s&&t.push(s),t.join(" ")}get cssClassName(){return this.hash}get cssDisplayNameVar(){return`--${this.hash}-display-name: ${this._callerName};`}get templateKeys(){var t;return(t=this._context)!=null&&t.config.templates?p.getTemplateKeys(this._context.config.templates):[]}get css(){var e;const{base:t={},variants:s={},compoundVariants:r=[]}=this.params,i={...t,variants:s,compoundVariants:r};return p.parseStyles(i,`.${this.cssClassName}`,this.priority,(e=this._context)==null?void 0:e.config)}get props(){const{element:t}=this.params,s=this.params.variants?Object.keys(this.params.variants).map(e=>{var n;const o=(n=this.params.defaultVariants)==null?void 0:n[e];return o!==void 0?`${e}=${String(o)}`:e}):void 0,r=new Set([]),i=/\{props\.([\w\d]+)\}/gi.exec(JSON.stringify(this.params.base));return i&&i.forEach((e,o,n)=>{const h=n.at(1);h&&r.add(h)}),{element:t,variantKeys:s,propValueKeys:[...r]}}_withBuildContext(t){this._context=t;const{name:s,config:r}=t;return this._callerName=s,this}}exports.StyleComponentGenerator=g;
@@ -1 +0,0 @@
1
- export * from './style-generator';
@@ -1,61 +0,0 @@
1
- var h = Object.defineProperty;
2
- var m = (e, t, s) => t in e ? h(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var c = (e, t, s) => m(e, typeof t != "symbol" ? t + "" : t, s);
4
- import { t as l } from "../dash-case-DMQMcCO6.js";
5
- import { g, p as u } from "../parse-templates-D4p3pgQR.js";
6
- class d {
7
- constructor(t, s) {
8
- c(this, "_callerName");
9
- c(this, "_context");
10
- this.tagName = t, this.params = s;
11
- }
12
- get hash() {
13
- return l(this.params.base || this.params);
14
- }
15
- get priority() {
16
- var t;
17
- return typeof this.tagName == "function" || typeof this.tagName == "object" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
18
- }
19
- get classNames() {
20
- const t = [this.hash], { className: s } = this.params;
21
- return s && t.push(s), t.join(" ");
22
- }
23
- get cssClassName() {
24
- return this.hash;
25
- }
26
- get cssDisplayNameVar() {
27
- return `--${this.hash}-display-name: ${this._callerName};`;
28
- }
29
- get templateKeys() {
30
- var t;
31
- return (t = this._context) != null && t.config.templates ? g(this._context.config.templates) : [];
32
- }
33
- get css() {
34
- var a;
35
- const { base: t = {}, variants: s = {}, compoundVariants: r = [] } = this.params, i = { ...t, variants: s, compoundVariants: r };
36
- return u(i, `.${this.cssClassName}`, this.priority, (a = this._context) == null ? void 0 : a.config);
37
- }
38
- get props() {
39
- const { element: t } = this.params, s = this.params.variants ? Object.keys(this.params.variants).map((a) => {
40
- var n;
41
- const o = (n = this.params.defaultVariants) == null ? void 0 : n[a];
42
- return o !== void 0 ? `${a}=${String(o)}` : a;
43
- }) : void 0, r = /* @__PURE__ */ new Set([]), i = /\{props\.([\w\d]+)\}/gi.exec(JSON.stringify(this.params.base));
44
- return i && i.forEach((a, o, n) => {
45
- const p = n.at(1);
46
- p && r.add(p);
47
- }), {
48
- element: t,
49
- variantKeys: s,
50
- propValueKeys: [...r]
51
- };
52
- }
53
- _withBuildContext(t) {
54
- this._context = t;
55
- const { name: s, config: r } = t;
56
- return this._callerName = s, this;
57
- }
58
- }
59
- export {
60
- d as StyleComponentGenerator
61
- };
@@ -1,2 +0,0 @@
1
- import { SaltyConfig } from '../config/config-types';
2
- export declare const parseStyles: <T extends object>(styles: T, currentClass: string, layer?: number, config?: SaltyConfig | undefined) => string;
@@ -1,2 +0,0 @@
1
- export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => string;
2
- export declare const getTemplateKeys: <T extends object>(templates: T) => string[];