@salty-css/core 0.0.1-alpha.13 → 0.0.1-alpha.130

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 (48) hide show
  1. package/.saltyrc.schema.json +40 -0
  2. package/README.md +143 -26
  3. package/bin/bin-util.d.ts +2 -0
  4. package/bin/index.cjs +2 -0
  5. package/bin/index.d.ts +2 -0
  6. package/bin/index.js +3 -0
  7. package/bin/logger.d.ts +2 -0
  8. package/bin/main.cjs +11 -0
  9. package/bin/main.d.ts +1 -0
  10. package/bin/main.js +260 -0
  11. package/bin/prettier.d.ts +1 -0
  12. package/compiler/get-files.d.ts +3 -0
  13. package/compiler/index.cjs +1 -11
  14. package/compiler/index.d.ts +4 -6
  15. package/compiler/index.js +16 -180
  16. package/config/config-types.d.ts +15 -5
  17. package/dash-case-BJEkFEGQ.cjs +1 -0
  18. package/dash-case-DBThphLm.js +19 -0
  19. package/generator/index.cjs +1 -1
  20. package/generator/index.js +40 -17
  21. package/generator/parse-templates.d.ts +2 -0
  22. package/generator/style-generator.d.ts +14 -4
  23. package/index-84Wroia-.cjs +1 -0
  24. package/index-BrNi5uoh.cjs +21 -0
  25. package/index-D_732b92.js +4 -0
  26. package/index-XN7f6bdr.js +305 -0
  27. package/package.json +20 -2
  28. package/parse-templates-BuKrl3n7.js +100 -0
  29. package/parse-templates-DIOn-gO_.cjs +8 -0
  30. package/pascal-case-BQpR5PdN.js +6 -0
  31. package/pascal-case-iWoaJWwT.cjs +1 -0
  32. package/react-styled-file-CGVf5n1B.js +11 -0
  33. package/react-styled-file-Dkubsz-U.cjs +8 -0
  34. package/react-vanilla-file-CCXbsjIb.js +18 -0
  35. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  36. package/salty.config-BhBY_oOk.js +10 -0
  37. package/salty.config-Dk6ZcCxI.cjs +7 -0
  38. package/templates/salty-reset.d.ts +2 -0
  39. package/types/index.d.ts +48 -21
  40. package/util/camel-case.d.ts +1 -0
  41. package/util/dot-case.d.ts +1 -0
  42. package/util/index.cjs +1 -1
  43. package/util/index.d.ts +2 -0
  44. package/util/index.js +7 -15
  45. package/util/module-type.d.ts +1 -0
  46. package/util/pascal-case.d.ts +1 -0
  47. package/parse-templates-BOSK0Tb6.js +0 -90
  48. package/parse-templates-BY1Xai-_.cjs +0 -8
package/compiler/index.js CHANGED
@@ -1,182 +1,18 @@
1
- import * as M from "esbuild";
2
- import * as N from "winston";
3
- import { execSync as z } from "child_process";
4
- import { toHash as T, dashCase as I } from "../util/index.js";
5
- import { join as o } from "path";
6
- import { writeFileSync as $, existsSync as H, mkdirSync as v, statSync as J, readdirSync as G, readFileSync as _ } from "fs";
7
- import { writeFile as L } from "fs/promises";
8
- import { p as q, a as A, b as U } from "../parse-templates-BOSK0Tb6.js";
9
- const rt = N.createLogger({
10
- level: "info",
11
- format: N.format.combine(N.format.colorize(), N.format.cli()),
12
- transports: [new N.transports.Console({})]
13
- }), k = (s) => o(s, "./saltygen"), W = ["salty", "css", "styles", "styled"], X = (s = []) => new RegExp(`\\.(${[...W, ...s].join("|")})\\.`), O = (s, e = []) => X(e).test(s), Y = async (s) => {
14
- const e = k(s), n = o(s, "salty-config.ts"), t = o(e, "salty-config.js");
15
- await M.build({
16
- entryPoints: [n],
17
- minify: !0,
18
- treeShaking: !0,
19
- bundle: !0,
20
- outfile: t,
21
- format: "esm",
22
- external: ["react"]
23
- });
24
- const c = Date.now(), { config: j } = await import(`${t}?t=${c}`);
25
- return j;
26
- }, Z = async (s) => {
27
- const e = await Y(s), n = /* @__PURE__ */ new Set(), t = (m, l = []) => m ? Object.entries(m).flatMap(([p, i]) => {
28
- if (!i) return;
29
- if (typeof i == "object") return t(i, [...l, p]);
30
- const x = [...l, p].join(".");
31
- n.add(`"${x}"`);
32
- const D = [...l.map(I), I(p)].join("-"), { result: P } = U(i);
33
- return `--${D}: ${P};`;
34
- }) : [], c = (m) => m ? Object.entries(m).flatMap(([l, p]) => {
35
- const i = t(p);
36
- return l === "base" ? i.join("") : `${l} { ${i.join("")} }`;
37
- }) : [], j = (m) => m ? Object.entries(m).flatMap(([l, p]) => Object.entries(p).flatMap(([i, x]) => {
38
- const D = t(x, [l]), P = `.${l}-${i}, [data-${l}="${i}"]`, V = D.join("");
39
- return `${P} { ${V} }`;
40
- })) : [], d = t(e.variables), w = c(e.responsiveVariables), a = j(e.conditionalVariables), b = k(s), y = o(b, "css/variables.css"), r = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
41
- $(y, r);
42
- const f = o(b, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
43
- $(f, u);
44
- const g = o(b, "css/global.css"), F = q(e.global, "");
45
- $(g, F);
46
- const S = o(b, "css/templates.css"), C = A(e.templates);
47
- $(S, C);
48
- }, E = async (s, e) => {
49
- const n = T(s), t = o(e, "js", n + ".js");
50
- await M.build({
51
- entryPoints: [s],
52
- minify: !0,
53
- treeShaking: !0,
54
- bundle: !0,
55
- outfile: t,
56
- format: "esm",
57
- target: ["es2022"],
58
- keepNames: !0,
59
- external: ["react"]
60
- });
61
- const c = Date.now();
62
- return await import(`${t}?t=${c}`);
63
- }, R = async (s) => {
64
- const e = k(s), n = o(e, "salty-config.js"), { config: t } = await import(n);
65
- return t;
66
- }, it = async (s) => {
67
- try {
68
- const e = [], n = [], t = k(s), c = o(t, "index.css");
69
- (() => {
70
- H(t) && z("rm -rf " + t), v(t), v(o(t, "css")), v(o(t, "types"));
71
- })(), await Z(s);
72
- const d = await R(s);
73
- async function w(r, f) {
74
- const h = J(r);
75
- if (h.isDirectory()) {
76
- const u = G(r);
77
- await Promise.all(u.map((g) => w(o(r, g), o(f, g))));
78
- } else if (h.isFile() && O(r)) {
79
- const g = await E(r, t), F = [];
80
- Object.entries(g).forEach(([l, p]) => {
81
- if (p.isKeyframes && p.css) {
82
- const V = `${p.animationName}.css`, B = `css/${V}`, K = o(t, B);
83
- e.push(V), $(K, p.css);
84
- return;
85
- }
86
- if (!p.generator) return;
87
- const i = p.generator._withBuildContext({
88
- name: l,
89
- config: d
90
- }), x = `${i.hash}-${i.priority}.css`;
91
- n[i.priority] || (n[i.priority] = []), n[i.priority].push(x), F.push(x);
92
- const D = `css/${x}`, P = o(t, D);
93
- $(P, i.css);
94
- });
95
- const S = F.map((l) => `@import url('./${l}');`).join(`
96
- `), C = T(r, 6), m = o(t, `css/${C}.css`);
97
- $(m, S);
98
- }
99
- }
100
- await w(s, t);
101
- const a = e.map((r) => `@import url('./css/${r}');`).join(`
102
- `);
103
- let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
104
-
105
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
106
- `)}
107
- ${a}`;
108
- if (d.importStrategy !== "component") {
109
- const r = n.flat().map((f) => `@import url('./css/${f}');`).join(`
110
- `);
111
- y += r;
112
- }
113
- $(c, y);
114
- } catch (e) {
115
- console.error(e);
116
- }
117
- }, ct = async (s, e) => {
118
- try {
119
- const n = [], t = o(s, "./saltygen"), c = o(t, "index.css");
120
- if (O(e)) {
121
- const d = await R(s), w = await E(e, t);
122
- Object.entries(w).forEach(([f, h]) => {
123
- if (!h.generator) return;
124
- const u = h.generator._withBuildContext({
125
- name: f,
126
- config: d
127
- }), g = `${u.hash}-${u.priority}.css`, F = `css/${g}`, S = o(t, F);
128
- n.push(g), $(S, u.css);
129
- });
130
- const a = _(c, "utf8").split(`
131
- `), b = n.map((f) => `@import url('../saltygen/css/${f}');`), r = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
132
- `);
133
- $(c, r);
134
- }
135
- } catch (n) {
136
- console.error(n);
137
- }
138
- }, at = async (s, e) => {
139
- try {
140
- const n = o(s, "./saltygen");
141
- if (O(e)) {
142
- let c = _(e, "utf8");
143
- c.replace(/^(?!export\s)const\s.*/gm, (y) => `export ${y}`) !== c && await L(e, c);
144
- const d = await R(s), w = await E(e, n);
145
- let a = c;
146
- Object.entries(w).forEach(([y, r]) => {
147
- var m;
148
- if (r.isKeyframes) {
149
- console.log("value", r);
150
- return;
151
- }
152
- if (!r.generator) return;
153
- const f = r.generator._withBuildContext({
154
- name: y,
155
- config: d
156
- }), h = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
157
- if (!h)
158
- return console.error("Could not find the original declaration");
159
- const u = (m = h.at(1)) == null ? void 0 : m.trim(), { element: g, variantKeys: F } = f.props, S = `${y} = styled(${u}, "${f.classNames}", "${f._callerName}", ${JSON.stringify(g)}, ${JSON.stringify(
160
- F
161
- )});`, C = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
162
- a = a.replace(C, S);
163
- });
164
- const b = T(e, 6);
165
- return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
166
- ${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
167
- }
168
- } catch (n) {
169
- console.error(n);
170
- }
171
- };
1
+ import "esbuild";
2
+ import "child_process";
3
+ import "../dash-case-DBThphLm.js";
4
+ import "path";
5
+ import "fs";
6
+ import "fs/promises";
7
+ import "../parse-templates-BuKrl3n7.js";
8
+ import { d as p, c as n, g, e as F, i as y, m as x, s as S, b as c } from "../index-XN7f6bdr.js";
172
9
  export {
173
- E as compileSaltyFile,
174
- it as generateCss,
175
- ct as generateFile,
176
- Z as generateVariables,
177
- O as isSaltyFile,
178
- rt as logger,
179
- at as minimizeFile,
180
- W as saltyFileExtensions,
181
- X as saltyFileRegExp
10
+ p as compileSaltyFile,
11
+ n as generateConfigStyles,
12
+ g as generateCss,
13
+ F as generateFile,
14
+ y as isSaltyFile,
15
+ x as minimizeFile,
16
+ S as saltyFileExtensions,
17
+ c as saltyFileRegExp
182
18
  };
@@ -1,7 +1,6 @@
1
- import { CssStyles } from '../types';
2
- type CssTemplate = CssStyles | {
3
- [key: PropertyKey]: CssTemplate;
4
- };
1
+ import { CssProperties, CssStyles } from '../types';
2
+ import { OrString } from '../types/util-types';
3
+ export type GlobalStyles = Record<string, CssProperties>;
5
4
  export type CssVariables = Record<string, unknown>;
6
5
  export interface CssResponsiveVariables {
7
6
  [key: string]: CssVariables;
@@ -11,6 +10,9 @@ export interface CssConditionalVariables {
11
10
  [key: PropertyKey]: CssVariables;
12
11
  };
13
12
  }
13
+ type CssTemplate = CssStyles | {
14
+ [key: PropertyKey]: CssTemplate;
15
+ };
14
16
  export interface CssTemplates {
15
17
  [key: PropertyKey]: {
16
18
  [key: PropertyKey]: CssTemplate;
@@ -46,7 +48,11 @@ export interface SaltyConfig {
46
48
  /**
47
49
  * The global styles that are imported in the root of the project.
48
50
  */
49
- global?: CssStyles;
51
+ reset?: 'default' | 'none' | GlobalStyles;
52
+ /**
53
+ * The global styles that are imported in the root of the project.
54
+ */
55
+ global?: GlobalStyles;
50
56
  /**
51
57
  * The templates that can be used in styles to create reusable css.
52
58
  */
@@ -55,5 +61,9 @@ export interface SaltyConfig {
55
61
  * The modifiers that can transform css values.
56
62
  */
57
63
  modifiers?: CssModifiers;
64
+ /**
65
+ * 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.
66
+ */
67
+ externalModules?: ('react' | 'react-dom' | OrString)[];
58
68
  }
59
69
  export {};
@@ -0,0 +1 @@
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=5)=>{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;
@@ -0,0 +1,19 @@
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 = 5) => {
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
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../util/index.cjs"),i=require("../parse-templates-BY1Xai-_.cjs");class o{constructor(t,s){this.tagName=t,this.params=s}get hash(){return n.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?i.getTemplateKeys(this._context.config.templates):[]}get css(){var a;const{base:t={},variants:s={},compoundVariants:e=[]}=this.params,r={...t,variants:s,compoundVariants:e};return i.parseStyles(r,`.${this.cssClassName}`,this.priority,(a=this._context)==null?void 0:a.config)}get props(){const{element:t}=this.params,s=this.params.variants?Object.keys(this.params.variants).map(e=>{var a;const r=(a=this.params.defaultVariants)==null?void 0:a[e];return r!==void 0?`${e}=${String(r)}`:e}):void 0;return{element:t,variantKeys:s}}_withBuildContext(t){this._context=t;const{name:s,config:e}=t;return this._callerName=s,this}}exports.StyleComponentGenerator=o;
1
+ "use strict";var y=Object.defineProperty;var f=(a,t,s)=>t in a?y(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var c=(a,t,s)=>f(a,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../dash-case-BJEkFEGQ.cjs"),u=require("../parse-templates-DIOn-gO_.cjs");class N{constructor(t,s){c(this,"_isProd");c(this,"_callerName");c(this,"_context");this.tagName=t,this.params=s}get hash(){return d.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 cssFileName(){return this._callerName?`c_${d.dashCase(this._callerName)}-${this.hash}-${this.priority}.css`:`${this.hash}-${this.priority}.css`}get templateKeys(){var t;return(t=this._context)!=null&&t.config.templates?u.getTemplateKeys(this._context.config.templates):[]}get css(){var n;const{base:t={},variants:s={},compoundVariants:i=[]}=this.params,r={...t,variants:s,compoundVariants:i};return u.parseStyles(r,`.${this.cssClassName}`,this.priority,(n=this._context)==null?void 0:n.config)}get props(){const{element:t,variants:s={},compoundVariants:i=[],defaultVariants:r={},defaultProps:n={},passProps:g}=this.params,h=new Set([]),p=e=>{const o=r[e];o!==void 0?h.add(`${e}=${String(o)}`):h.add(e)};Object.keys(s).forEach(p),i.map(e=>Object.keys(e).forEach(p));const l=new Set([]);if(this.params.base){const e=JSON.stringify(this.params.base).match(/\{props\.([\w\d]+)\}/gi);e&&e.forEach(o=>{const m=o.replace(/\{props\.([\w\d]+)\}/gi,"$1");m&&l.add(m)})}return{element:t,variantKeys:[...h],propValueKeys:[...l],passProps:g,defaultProps:n,attr:{"data-component-name":this._isProd?void 0:this._callerName}}}_withBuildContext(t){this._context=t;const{name:s,config:i,prod:r}=t;return this._isProd=r,this._callerName=s,this}}exports.StyleComponentGenerator=N;
@@ -1,11 +1,17 @@
1
- import { toHash as i } from "../util/index.js";
2
- import { g as n, p as o } from "../parse-templates-BOSK0Tb6.js";
3
- class p {
1
+ var u = Object.defineProperty;
2
+ var f = (a, t, s) => t in a ? u(a, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[t] = s;
3
+ var c = (a, t, s) => f(a, typeof t != "symbol" ? t + "" : t, s);
4
+ import { t as g, d as y } from "../dash-case-DBThphLm.js";
5
+ import { g as N, p as _ } from "../parse-templates-BuKrl3n7.js";
6
+ class v {
4
7
  constructor(t, s) {
8
+ c(this, "_isProd");
9
+ c(this, "_callerName");
10
+ c(this, "_context");
5
11
  this.tagName = t, this.params = s;
6
12
  }
7
13
  get hash() {
8
- return i(this.params.base || this.params);
14
+ return g(this.params.base || this.params);
9
15
  }
10
16
  get priority() {
11
17
  var t;
@@ -21,32 +27,49 @@ class p {
21
27
  get cssDisplayNameVar() {
22
28
  return `--${this.hash}-display-name: ${this._callerName};`;
23
29
  }
30
+ get cssFileName() {
31
+ return this._callerName ? `c_${y(this._callerName)}-${this.hash}-${this.priority}.css` : `${this.hash}-${this.priority}.css`;
32
+ }
24
33
  get templateKeys() {
25
34
  var t;
26
- return (t = this._context) != null && t.config.templates ? n(this._context.config.templates) : [];
35
+ return (t = this._context) != null && t.config.templates ? N(this._context.config.templates) : [];
27
36
  }
28
37
  get css() {
29
- var e;
30
- const { base: t = {}, variants: s = {}, compoundVariants: a = [] } = this.params, r = { ...t, variants: s, compoundVariants: a };
31
- return o(r, `.${this.cssClassName}`, this.priority, (e = this._context) == null ? void 0 : e.config);
38
+ var n;
39
+ const { base: t = {}, variants: s = {}, compoundVariants: i = [] } = this.params, r = { ...t, variants: s, compoundVariants: i };
40
+ return _(r, `.${this.cssClassName}`, this.priority, (n = this._context) == null ? void 0 : n.config);
32
41
  }
33
42
  get props() {
34
- const { element: t } = this.params, s = this.params.variants ? Object.keys(this.params.variants).map((a) => {
35
- var e;
36
- const r = (e = this.params.defaultVariants) == null ? void 0 : e[a];
37
- return r !== void 0 ? `${a}=${String(r)}` : a;
38
- }) : void 0;
43
+ const { element: t, variants: s = {}, compoundVariants: i = [], defaultVariants: r = {}, defaultProps: n = {}, passProps: d } = this.params, h = /* @__PURE__ */ new Set([]), p = (e) => {
44
+ const o = r[e];
45
+ o !== void 0 ? h.add(`${e}=${String(o)}`) : h.add(e);
46
+ };
47
+ Object.keys(s).forEach(p), i.map((e) => Object.keys(e).forEach(p));
48
+ const m = /* @__PURE__ */ new Set([]);
49
+ if (this.params.base) {
50
+ const e = JSON.stringify(this.params.base).match(/\{props\.([\w\d]+)\}/gi);
51
+ e && e.forEach((o) => {
52
+ const l = o.replace(/\{props\.([\w\d]+)\}/gi, "$1");
53
+ l && m.add(l);
54
+ });
55
+ }
39
56
  return {
40
57
  element: t,
41
- variantKeys: s
58
+ variantKeys: [...h],
59
+ propValueKeys: [...m],
60
+ passProps: d,
61
+ defaultProps: n,
62
+ attr: {
63
+ "data-component-name": this._isProd ? void 0 : this._callerName
64
+ }
42
65
  };
43
66
  }
44
67
  _withBuildContext(t) {
45
68
  this._context = t;
46
- const { name: s, config: a } = t;
47
- return this._callerName = s, this;
69
+ const { name: s, config: i, prod: r } = t;
70
+ return this._isProd = r, this._callerName = s, this;
48
71
  }
49
72
  }
50
73
  export {
51
- p as StyleComponentGenerator
74
+ v as StyleComponentGenerator
52
75
  };
@@ -1,2 +1,4 @@
1
1
  export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => string;
2
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,7 +1,18 @@
1
1
  import { StyledParams, Tag } from '../types';
2
+ export interface GeneratorProps {
3
+ element?: string;
4
+ variantKeys?: string[];
5
+ propValueKeys?: string[];
6
+ passProps?: boolean | string | string[];
7
+ defaultProps?: Record<PropertyKey, unknown>;
8
+ attr: {
9
+ [key: string]: any;
10
+ };
11
+ }
2
12
  export declare class StyleComponentGenerator {
3
13
  tagName: Tag<any>;
4
14
  params: StyledParams;
15
+ _isProd: boolean | undefined;
5
16
  _callerName: string | undefined;
6
17
  _context: {
7
18
  name: string;
@@ -13,14 +24,13 @@ export declare class StyleComponentGenerator {
13
24
  get classNames(): string;
14
25
  get cssClassName(): string;
15
26
  get cssDisplayNameVar(): string;
27
+ get cssFileName(): string;
16
28
  get templateKeys(): string[];
17
29
  get css(): string;
18
- get props(): {
19
- element: string | undefined;
20
- variantKeys: string[] | undefined;
21
- };
30
+ get props(): GeneratorProps;
22
31
  _withBuildContext(context: {
23
32
  name: string;
24
33
  config: any;
34
+ prod: boolean;
25
35
  }): this;
26
36
  }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="/* Empty */";exports.default=e;
@@ -0,0 +1,21 @@
1
+ "use strict";const ae=require("esbuild"),ce=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),s=require("path"),a=require("fs"),G=require("fs/promises"),R=require("./parse-templates-DIOn-gO_.cjs"),z=require("winston");var I=typeof document<"u"?document.currentScript:null;function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const K=le(ae),L=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=s.join(e,"package.json");return a.existsSync(t)?t:L(s.join(e,".."))},pe=async e=>{const t=L(e);return await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ue=async e=>{const t=await pe(e);if(t)return t.type};let E;const U=async e=>{if(E)return E;const t=await ue(e);return t==="module"?E="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-BrNi5uoh.cjs",document.baseURI).href).endsWith(".cjs"))&&(E="cjs"),E||"esm"},J=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]}),de=e=>{J.error(e)};function X(e){return e?typeof e!="string"?X(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,n)=>(n>0?".":"")+t.toLowerCase()):""}const fe={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},button:{lineHeight:"1em"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},A={externalModules:[]},Y=e=>{if(A.externalModules.length>0)return A.externalModules;const t=s.join(e,"salty.config.ts"),o=a.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!o)return[];const p=o[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return A.externalModules=p,p},q=e=>s.join(e,"./saltygen"),Q=["salty","css","styles","styled"],ee=(e=[])=>new RegExp(`\\.(${[...Q,...e].join("|")})\\.`),W=(e,t=[])=>ee(t).test(e),ge=async e=>{const t=q(e),n=s.join(e,"salty.config.ts"),o=s.join(t,"salty.config.js"),p=await U(e),r=Y(e);await K.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:p,external:r});const y=Date.now(),{config:m}=await import(`${o}?t=${y}`);return m},te=async e=>{const t=await ge(e),n=new Set,o=(l,d=[])=>l?Object.entries(l).flatMap(([h,f])=>{if(!f)return;if(typeof f=="object")return o(f,[...d,h]);const O=X(h),V=D.dashCase(h),P=[...d,O].join(".");n.add(`"${P}"`);const $=[...d.map(D.dashCase),V].join("-"),{result:x}=R.parseValueTokens(f);return`--${$}: ${x};`}):[],p=l=>l?Object.entries(l).flatMap(([d,h])=>{const f=o(h);return d==="base"?f.join(""):`${d} { ${f.join("")} }`}):[],r=l=>l?Object.entries(l).flatMap(([d,h])=>Object.entries(h).flatMap(([f,O])=>{const V=o(O,[d]),P=`.${d}-${f}, [data-${d}="${f}"]`,$=V.join("");return`${P} { ${$} }`})):[],y=o(t.variables),m=p(t.responsiveVariables),F=r(t.conditionalVariables),i=q(e),u=s.join(i,"css/_variables.css"),S=`:root { ${y.join("")} ${m.join("")} } ${F.join("")}`;a.writeFileSync(u,S);const w=s.join(i,"css/_global.css"),C=R.parseStyles(t.global,"");a.writeFileSync(w,`@layer global { ${C} }`);const b=s.join(i,"css/_reset.css"),g=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:fe,k=R.parseStyles(g,"");a.writeFileSync(b,`@layer reset { ${k} }`);const c=s.join(i,"css/_templates.css"),j=R.parseTemplates(t.templates),N=R.getTemplateTypes(t.templates);a.writeFileSync(c,j);const T=s.join(i,"types/css-tokens.d.ts"),v=`
2
+ // Variable types
3
+ type VariableTokens = ${[...n].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(N).map(([l,d])=>`${l}?: ${d}`).join(`
9
+ `)}
10
+ }
11
+ `;a.writeFileSync(T,v)},H=async(e,t,n)=>{const o=D.toHash(t),p=s.join(n,"./temp");a.existsSync(p)||a.mkdirSync(p);const r=s.parse(t);let y=a.readFileSync(t,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const m=s.join(n,"js",o+".js"),F=Y(e),i=await U(e);await K.build({stdin:{contents:y,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:m,format:i,target:["node20"],keepNames:!0,external:F,packages:"external"});const u=Date.now();return await import(`${m}?t=${u}`)},B=async e=>{const t=q(e),n=s.join(t,"salty.config.js"),{config:o}=await import(n);return o},se=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ye=async(e,t=se())=>{try{const n=Date.now();t?J.info("Generating CSS in production mode! 🔥"):J.info("Generating CSS in development mode! 🚀");const o=[],p=[],r=q(e),y=s.join(r,"index.css");(()=>{a.existsSync(r)&&ce.execSync("rm -rf "+r),a.mkdirSync(r),a.mkdirSync(s.join(r,"css")),a.mkdirSync(s.join(r,"types"))})(),await te(e);const F=await B(e);async function i(c,j){const N=["node_modules","saltygen"],T=a.statSync(c);if(T.isDirectory()){const M=a.readdirSync(c);if(N.some(l=>c.includes(l)))return;await Promise.all(M.map(l=>i(s.join(c,l),s.join(j,l))))}else if(T.isFile()&&W(c)){const v=await H(e,c,r),l=[];Object.entries(v).forEach(([P,$])=>{if($.isKeyframes&&$.css){const Z=`a_${$.animationName}.css`,re=`css/${Z}`,ie=s.join(r,re);o.push(Z),a.writeFileSync(ie,$.css);return}if(!$.generator)return;const x=$.generator._withBuildContext({name:P,config:F,prod:t});p[x.priority]||(p[x.priority]=[]),p[x.priority].push(x.cssFileName),l.push(x.cssFileName);const ne=`css/${x.cssFileName}`,oe=s.join(r,ne);a.writeFileSync(oe,x.css)});const d=l.map(P=>`@import url('./${P}');`).join(`
12
+ `),h=D.toHash(c,6),f=s.parse(c),O=D.dashCase(f.name),V=s.join(r,`css/f_${O}-${h}.css`);a.writeFileSync(V,d)}}await i(e,r);const u=o.map(c=>`@import url('./css/${c}');`).join(`
13
+ `);let b=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
14
+
15
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return a.readFileSync(s.join(r,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
16
+ `)}
17
+ ${u}`;if(F.importStrategy!=="component"){const c=p.flat().map(j=>`@import url('./css/${j}');`).join(`
18
+ `);b+=c}a.writeFileSync(y,b);const g=Date.now()-n,k=g<200?"🔥":g<500?"🚀":g<1e3?"🎉":g<2e3?"🚗":g<5e3?"🤔":"🥴";J.info(`Generated CSS in ${g}ms! ${k}`)}catch(n){console.error(n)}},me=async(e,t)=>{try{const n=[],o=s.join(e,"./saltygen"),p=s.join(o,"index.css");if(W(t)){const y=await B(e),m=await H(e,t,o);Object.entries(m).forEach(([w,C])=>{if(!C.generator)return;const b=C.generator._withBuildContext({name:w,config:y}),_=`css/${b.cssFileName}`,g=s.join(o,_);n.push(b.cssFileName),a.writeFileSync(g,b.css)});const F=a.readFileSync(p,"utf8").split(`
19
+ `),i=n.map(w=>`@import url('../saltygen/css/${w}');`),S=[...new Set([...F,...i])].join(`
20
+ `);a.writeFileSync(p,S)}}catch(n){console.error(n)}},he=async(e,t,n=se())=>{try{const o=s.join(e,"./saltygen");if(W(t)){const r=a.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==r&&await G.writeFile(t,r);const m=await B(e),F=await H(e,t,o);let i=r;if(Object.entries(F).forEach(([u,S])=>{var h;if(S.isKeyframes||!S.generator)return;const w=S.generator._withBuildContext({name:u,config:m,prod:n}),C=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!C)return console.error("Could not find the original declaration");const b=(h=C.at(1))==null?void 0:h.trim(),_=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(i);if(!_)return console.error("Could not find the original declaration");const{index:g}=_;let k=!1;const c=setTimeout(()=>k=!0,5e3);let j=0,N=!1,T=0;for(;!N&&!k;){const f=i[g+j];f==="("&&T++,f===")"&&T--,T===0&&f===")"&&(N=!0),j>i.length&&(k=!0),j++}if(!k)clearTimeout(c);else throw new Error("Failed to find the end of the styled call and timed out");const M=g+j,v=i.slice(g,M),l=i,d=` ${u} = styled(${b}, "${w.classNames}", ${JSON.stringify(w.props)});`;i=i.replace(v,d),l===i&&console.error("Minimize file failed to change content",{name:u,tagName:b})}),m.importStrategy==="component"){const u=D.toHash(t,6),S=s.parse(t);i=`import '../../saltygen/css/${`f_${D.dashCase(S.name)}-${u}.css`}';
21
+ ${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(o){console.error("Error in minimizeFile:",o)}};exports.compileSaltyFile=H;exports.generateConfigStyles=te;exports.generateCss=ye;exports.generateFile=me;exports.isSaltyFile=W;exports.logError=de;exports.logger=J;exports.minimizeFile=he;exports.saltyFileExtensions=Q;exports.saltyFileRegExp=ee;
@@ -0,0 +1,4 @@
1
+ const t = "/* Empty */";
2
+ export {
3
+ t as default
4
+ };