@salty-css/core 0.0.1-alpha.205 → 0.0.1-alpha.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/main.cjs +1 -1
- package/bin/main.js +1 -1
- package/compiler/index.cjs +1 -1
- package/compiler/index.d.ts +1 -1
- package/compiler/index.js +2 -2
- package/css/index.cjs +1 -1
- package/css/index.js +3 -3
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/css/merge.cjs +1 -1
- package/css/merge.d.ts +2 -3
- package/css/merge.js +1 -1
- package/generators/index.cjs +1 -1
- package/generators/index.js +51 -40
- package/generators/styled-generator.d.ts +1 -1
- package/generators/styles-generator.d.ts +4 -0
- package/index-BZxPdVzL.cjs +38 -0
- package/index-Djy7Z9Ft.js +498 -0
- package/package.json +1 -1
- package/parse-styles-CkaV3OGz.js +126 -0
- package/parse-styles-DKWtadpv.cjs +3 -0
- package/parsers/parse-styles.d.ts +3 -2
- package/parsers/parser-types.d.ts +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/index-BEJWepok.cjs +0 -38
- package/index-BsRtXRDr.js +0 -490
- package/parse-styles-B67L4oyf.cjs +0 -3
- package/parse-styles-DZbuVYRn.js +0 -125
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-BZxPdVzL.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
|
4
4
|
import { join as i, relative as z, parse as re, format as ee } from "path";
|
5
5
|
import { render as ce } from "ejs";
|
6
|
-
import { l as t, a as h, g as te } from "../index-
|
6
|
+
import { l as t, a as h, g as te } from "../index-Djy7Z9Ft.js";
|
7
7
|
import { p as le } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as de } from "child_process";
|
9
9
|
import fe from "ora";
|
package/compiler/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-DKWtadpv.cjs");const e=require("../index-BZxPdVzL.cjs");require("../css/merge.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.d.ts
CHANGED
@@ -20,5 +20,5 @@ export declare const compileSaltyFile: (dirname: string, sourceFilePath: string,
|
|
20
20
|
outputFilePath: string;
|
21
21
|
}>;
|
22
22
|
export declare const generateCss: (dirname: string, prod?: boolean, clean?: boolean) => Promise<void>;
|
23
|
-
export declare const generateFile: (dirname: string, file: string) => Promise<void>;
|
23
|
+
export declare const generateFile: (dirname: string, file: string, prod?: boolean) => Promise<void>;
|
24
24
|
export declare const minimizeFile: (dirname: string, file: string, prod?: boolean) => Promise<string | undefined>;
|
package/compiler/index.js
CHANGED
@@ -4,8 +4,8 @@ import "../dash-case-DBThphLm.js";
|
|
4
4
|
import "path";
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
|
-
import "../parse-styles-
|
8
|
-
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-
|
7
|
+
import "../parse-styles-CkaV3OGz.js";
|
8
|
+
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-Djy7Z9Ft.js";
|
9
9
|
import "../css/merge.js";
|
10
10
|
export {
|
11
11
|
n as compileSaltyFile,
|
package/css/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./keyframes.cjs"),e=require("./media.cjs"),t=require("./token.cjs"),r=require("./merge.cjs");exports.keyframes=s.keyframes;exports.MediaQueryFactory=e.MediaQueryFactory;exports.media=e.media;exports.token=t.token;exports.mergeFactories=r.mergeFactories;exports.
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./keyframes.cjs"),e=require("./media.cjs"),t=require("./token.cjs"),r=require("./merge.cjs");exports.keyframes=s.keyframes;exports.MediaQueryFactory=e.MediaQueryFactory;exports.media=e.media;exports.token=t.token;exports.mergeFactories=r.mergeFactories;exports.mergeObjects=r.mergeObjects;
|
package/css/index.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import { keyframes as o } from "./keyframes.js";
|
2
2
|
import { MediaQueryFactory as t, media as a } from "./media.js";
|
3
3
|
import { token as p } from "./token.js";
|
4
|
-
import { mergeFactories as
|
4
|
+
import { mergeFactories as c, mergeObjects as i } from "./merge.js";
|
5
5
|
export {
|
6
6
|
t as MediaQueryFactory,
|
7
7
|
o as keyframes,
|
8
8
|
a as media,
|
9
|
-
|
10
|
-
i as
|
9
|
+
c as mergeFactories,
|
10
|
+
i as mergeObjects,
|
11
11
|
p as token
|
12
12
|
};
|
package/css/keyframes.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../parse-styles-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../parse-styles-DKWtadpv.cjs"),w=require("../dash-case-BJEkFEGQ.cjs"),C=async({animationName:l,params:u,appendInitialStyles:y,...t})=>{const n=l||w.toHash(t),r=async(s={})=>{const{duration:e="500ms",easing:o="ease-in-out",delay:i="0s",iterationCount:S="1",direction:p="normal",fillMode:g="forwards",playState:b="running"}={...u,...s},a=`${n} ${e} ${o} ${i} ${S} ${p} ${g} ${b}`;if(!y)return a;const c=t.from||t["0%"];if(!c)return a;const j=await m.parseAndJoinStyles(c,"");return`${a};${j}`},$=Object.entries(t).map(async([s,e])=>{if(!e)return"";const o=await m.parseAndJoinStyles(e,"");return`${typeof s=="number"?`${s}%`:s}{${o}}`}),d=(await Promise.all($)).join(""),f=`@keyframes ${n} {${d}}`;return Object.assign(r,{toString:r,isKeyframes:!0,animationName:n,css:f,keyframes:t}),r};exports.keyframes=C;
|
package/css/keyframes.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { p as m } from "../parse-styles-
|
1
|
+
import { p as m } from "../parse-styles-CkaV3OGz.js";
|
2
2
|
import { t as j } from "../dash-case-DBThphLm.js";
|
3
3
|
const v = async ({ animationName: $, params: f, appendInitialStyles: l, ...t }) => {
|
4
4
|
const r = $ || j(t), o = async (n = {}) => {
|
package/css/merge.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=(...t)=>t.flat().reduce((e,r)=>r!=null&&r._current?{...e,...r._current}:{...e,...r},{}),u=(...t)=>t.flat().reduce((e,r)=>({...e,...r._children}),{});exports.mergeFactories=u;exports.
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=(...t)=>t.flat().reduce((e,r)=>r!=null&&r._current?{...e,...r._current}:{...e,...r},{}),u=(...t)=>t.flat().reduce((e,r)=>({...e,...r._children}),{});exports.mergeFactories=u;exports.mergeObjects=n;
|
package/css/merge.d.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import { CSSinJS } from '../types';
|
2
1
|
interface StyleFactory {
|
3
2
|
_current: Record<string, any>;
|
4
|
-
_children: Record<string, any
|
3
|
+
_children: Record<string, any>;
|
5
4
|
}
|
6
|
-
export declare const
|
5
|
+
export declare const mergeObjects: <T = any>(...styles: any[]) => T;
|
7
6
|
export declare const mergeFactories: <T extends StyleFactory>(...factories: T[][]) => T;
|
8
7
|
export {};
|
package/css/merge.js
CHANGED
package/generators/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
1
|
+
"use strict";var g=Object.defineProperty;var C=(a,t,s)=>t in a?g(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var m=(a,t,s)=>C(a,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("../parse-styles-DKWtadpv.cjs"),c=require("../dash-case-BJEkFEGQ.cjs");class f{constructor(t){m(this,"buildContext",{});this.params=t}get priority(){return 0}get isRoot(){return this.priority===0}get hash(){return c.toHash(this.params.base||this.params)}get cssClassName(){return this.hash}get classNames(){const t=new Set([this.cssClassName]),{className:s}=this.params;return typeof s=="string"&&t.add(s),typeof s=="object"&&s.forEach(e=>t.add(e)),this.getTemplateClasses().forEach(e=>t.add(e)),this.buildContext.classNames&&this.buildContext.classNames.forEach(e=>t.add(e)),[...t].join(" ")}get cssFileName(){const{callerName:t}=this.buildContext;return t?`cl_${c.dashCase(t)}-${this.hash}.css`:`${this.hash}.css`}get css(){const{base:t={},variants:s={},compoundVariants:e=[]}=this.params,{config:i}=this.buildContext,n={...t,variants:s,compoundVariants:e};return N.parseAndJoinStyles(n,`.${this.cssClassName}`,i,this.isRoot)}getTemplateClasses(t=this.buildContext.config){if(!(t!=null&&t.templates)||!this.params.base||this.priority>0)return[];const s=Object.keys(t.templates);return Object.entries(this.params.base).reduce((e,[i,n])=>(s.includes(i)&&e.push("t_"+c.toHash(c.dashCase(`${i}-${n}`),4)),e),[])}_withBuildContext(t){return this.buildContext=t,this}}class S extends f{constructor(t){super(t),this._params=t}}class x extends f{constructor(t,s){super(s),this.tagName=t,this._params=s}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 clientProps(){const{element:t,variants:s={},compoundVariants:e=[],defaultVariants:i={},defaultProps:n={},passProps:d}=this.params,{callerName:y,isProduction:b}=this.buildContext,h=new Set([]),l=r=>{const o=i[r];o!==void 0?h.add(`${r}=${String(o)}`):h.add(r)};Object.keys(s).forEach(l),e.map(r=>Object.keys(r).forEach(l));const p=new Set([]);if(this.params.base){const r=JSON.stringify(this.params.base).match(/\{props\.([\w\d]+)\}/gi);r&&r.forEach(o=>{const u=o.replace(/\{props\.([\w\d]+)\}/gi,"$1");u&&p.add(u)})}return{element:t,variantKeys:[...h],propValueKeys:[...p],passProps:d,defaultProps:n,attr:{"data-component-name":b?void 0:y}}}}exports.ClassNameGenerator=S;exports.StyledGenerator=x;
|
package/generators/index.js
CHANGED
@@ -1,75 +1,86 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var u = (
|
4
|
-
import { p as
|
5
|
-
import { t as
|
6
|
-
class
|
7
|
-
constructor(
|
1
|
+
var N = Object.defineProperty;
|
2
|
+
var C = (a, t, s) => t in a ? N(a, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[t] = s;
|
3
|
+
var u = (a, t, s) => C(a, typeof t != "symbol" ? t + "" : t, s);
|
4
|
+
import { p as x } from "../parse-styles-CkaV3OGz.js";
|
5
|
+
import { t as m, d as f } from "../dash-case-DBThphLm.js";
|
6
|
+
class y {
|
7
|
+
constructor(t) {
|
8
8
|
u(this, "buildContext", {});
|
9
|
-
this.params =
|
9
|
+
this.params = t;
|
10
|
+
}
|
11
|
+
get priority() {
|
12
|
+
return 0;
|
13
|
+
}
|
14
|
+
get isRoot() {
|
15
|
+
return this.priority === 0;
|
10
16
|
}
|
11
17
|
get hash() {
|
12
|
-
return
|
18
|
+
return m(this.params.base || this.params);
|
13
19
|
}
|
14
20
|
get cssClassName() {
|
15
21
|
return this.hash;
|
16
22
|
}
|
17
23
|
get classNames() {
|
18
|
-
const
|
19
|
-
return typeof
|
24
|
+
const t = /* @__PURE__ */ new Set([this.cssClassName]), { className: s } = this.params;
|
25
|
+
return typeof s == "string" && t.add(s), typeof s == "object" && s.forEach((e) => t.add(e)), this.getTemplateClasses().forEach((e) => t.add(e)), this.buildContext.classNames && this.buildContext.classNames.forEach((e) => t.add(e)), [...t].join(" ");
|
20
26
|
}
|
21
27
|
get cssFileName() {
|
22
|
-
const { callerName:
|
23
|
-
return
|
28
|
+
const { callerName: t } = this.buildContext;
|
29
|
+
return t ? `cl_${f(t)}-${this.hash}.css` : `${this.hash}.css`;
|
24
30
|
}
|
25
31
|
get css() {
|
26
|
-
const { base:
|
27
|
-
return
|
32
|
+
const { base: t = {}, variants: s = {}, compoundVariants: e = [] } = this.params, { config: i } = this.buildContext, n = { ...t, variants: s, compoundVariants: e };
|
33
|
+
return x(n, `.${this.cssClassName}`, i, this.isRoot);
|
34
|
+
}
|
35
|
+
getTemplateClasses(t = this.buildContext.config) {
|
36
|
+
if (!(t != null && t.templates) || !this.params.base || this.priority > 0) return [];
|
37
|
+
const s = Object.keys(t.templates);
|
38
|
+
return Object.entries(this.params.base).reduce((e, [i, n]) => (s.includes(i) && e.push("t_" + m(f(`${i}-${n}`), 4)), e), []);
|
28
39
|
}
|
29
|
-
_withBuildContext(
|
30
|
-
return this.buildContext =
|
40
|
+
_withBuildContext(t) {
|
41
|
+
return this.buildContext = t, this;
|
31
42
|
}
|
32
43
|
}
|
33
|
-
class
|
34
|
-
constructor(
|
35
|
-
super(
|
44
|
+
class v extends y {
|
45
|
+
constructor(t) {
|
46
|
+
super(t), this._params = t;
|
36
47
|
}
|
37
48
|
}
|
38
|
-
class
|
39
|
-
constructor(
|
40
|
-
super(
|
49
|
+
class V extends y {
|
50
|
+
constructor(t, s) {
|
51
|
+
super(s), this.tagName = t, this._params = s;
|
41
52
|
}
|
42
53
|
get priority() {
|
43
|
-
var
|
44
|
-
return typeof this.tagName == "function" || typeof this.tagName == "object" ? (((
|
54
|
+
var t;
|
55
|
+
return typeof this.tagName == "function" || typeof this.tagName == "object" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
|
45
56
|
}
|
46
57
|
get clientProps() {
|
47
|
-
const { element:
|
48
|
-
const
|
49
|
-
|
58
|
+
const { element: t, variants: s = {}, compoundVariants: e = [], defaultVariants: i = {}, defaultProps: n = {}, passProps: h } = this.params, { callerName: b, isProduction: g } = this.buildContext, c = /* @__PURE__ */ new Set([]), d = (r) => {
|
59
|
+
const o = i[r];
|
60
|
+
o !== void 0 ? c.add(`${r}=${String(o)}`) : c.add(r);
|
50
61
|
};
|
51
|
-
Object.keys(
|
52
|
-
const
|
62
|
+
Object.keys(s).forEach(d), e.map((r) => Object.keys(r).forEach(d));
|
63
|
+
const p = /* @__PURE__ */ new Set([]);
|
53
64
|
if (this.params.base) {
|
54
|
-
const
|
55
|
-
|
56
|
-
const l =
|
57
|
-
l &&
|
65
|
+
const r = JSON.stringify(this.params.base).match(/\{props\.([\w\d]+)\}/gi);
|
66
|
+
r && r.forEach((o) => {
|
67
|
+
const l = o.replace(/\{props\.([\w\d]+)\}/gi, "$1");
|
68
|
+
l && p.add(l);
|
58
69
|
});
|
59
70
|
}
|
60
71
|
return {
|
61
|
-
element:
|
72
|
+
element: t,
|
62
73
|
variantKeys: [...c],
|
63
|
-
propValueKeys: [...
|
74
|
+
propValueKeys: [...p],
|
64
75
|
passProps: h,
|
65
|
-
defaultProps:
|
76
|
+
defaultProps: n,
|
66
77
|
attr: {
|
67
|
-
"data-component-name": g ? void 0 :
|
78
|
+
"data-component-name": g ? void 0 : b
|
68
79
|
}
|
69
80
|
};
|
70
81
|
}
|
71
82
|
}
|
72
83
|
export {
|
73
|
-
|
74
|
-
|
84
|
+
v as ClassNameGenerator,
|
85
|
+
V as StyledGenerator
|
75
86
|
};
|
@@ -4,15 +4,19 @@ export interface StylesGeneratorBuildTimeProps {
|
|
4
4
|
callerName?: string;
|
5
5
|
isProduction?: boolean;
|
6
6
|
config?: SaltyConfig;
|
7
|
+
classNames?: string[];
|
7
8
|
}
|
8
9
|
export declare class StylesGenerator<const STYLE_PARAMS extends StyledParams = StyledParams> {
|
9
10
|
params: STYLE_PARAMS;
|
10
11
|
buildContext: StylesGeneratorBuildTimeProps;
|
11
12
|
constructor(params: STYLE_PARAMS);
|
13
|
+
get priority(): number;
|
14
|
+
get isRoot(): boolean;
|
12
15
|
get hash(): string;
|
13
16
|
get cssClassName(): string;
|
14
17
|
get classNames(): string;
|
15
18
|
get cssFileName(): string;
|
16
19
|
get css(): Promise<string>;
|
20
|
+
getTemplateClasses(config?: SaltyConfig | undefined): string[];
|
17
21
|
_withBuildContext(context: StylesGeneratorBuildTimeProps): this;
|
18
22
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";const Ce=require("esbuild"),xe=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-DKWtadpv.cjs"),B=require("winston"),M=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const pe=Ne(Ce),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[r,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const a=r.trim(),y=await ye(o,[...t,a]);s.push(y)}else n[r]=o;if(Object.keys(n).length){const r=t.map(D.dashCase).join("-"),o="t_"+D.toHash(r,4),a=await X.parseAndJoinStyles(n,`.${r}, .${o}`);s.push(a)}return s.join(`
|
2
|
+
`)},Pe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(r=>`"${r}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,r])=>{const o=t?`${t}.${n}`:n;return typeof r=="object"?me(r,o,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:ge(i.join(e,".."))},ke=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await ke(e);if(t)return t.type};let H;const he=async e=>{if(H)return H;const t=await De(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-BZxPdVzL.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};function Se(e){return e?typeof e!="string"?Se(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Oe={"*, *::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"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},V={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(V.externalModules.length>0)return V.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ie=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>we(t).test(e),be=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):be(i.join(e,".."))},re=async e=>{var n,r;const t=await be(e),s=(n=t.projects)==null?void 0:n.find(o=>e.endsWith(o.dir||""));return s||((r=t.projects)==null?void 0:r.find(o=>o.dir===t.defaultProject))},Te=async e=>{const t=await re(e),s=await v(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),o=await he(e),a=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:o,external:a});const y=Date.now(),{config:$}=await import(`${r}?t=${y}`);return $},Fe=async(e,t)=>{var le,fe;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async m=>{const{contents:b,outputFilePath:R}=await K(e,m,s);Object.entries(b).forEach(([k,O])=>{O.isMedia?n.mediaQueries.push([k,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(R))})}));const r=await Te(e),o={...r},a=new Set,y=(m,b=[])=>m?Object.entries(m).flatMap(([R,k])=>{if(!k)return;if(typeof k=="object")return y(k,[...b,R]);const O=Se(R),te=D.dashCase(R),se=[...b,O].join(".");a.add(`"${se}"`);const U=[...b.map(D.dashCase),te].join("-"),ue=X.parseVariableTokens(k);return ue?`--${U}: ${ue.transformed};`:`--${U}: ${k};`}):[],$=m=>m?Object.entries(m).flatMap(([b,R])=>{const k=y(R);return b==="base"?k.join(""):`${b} { ${k.join("")} }`}):[],l=m=>m?Object.entries(m).flatMap(([b,R])=>Object.entries(R).flatMap(([k,O])=>{const te=y(O,[b]),se=`.${b}-${k}, [data-${b}="${k}"]`,U=te.join("");return`${se} { ${U} }`})):[],d=m=>({...m,responsive:void 0,conditional:void 0}),g=m=>n.variables.map(b=>m==="static"?d(b._current):b._current[m]),p=M.mergeObjects(d(r.variables),g("static")),j=y(p),h=M.mergeObjects((le=r.variables)==null?void 0:le.responsive,g("responsive")),C=$(h),N=M.mergeObjects((fe=r.variables)==null?void 0:fe.conditional,g("conditional")),P=l(N),J=i.join(s,"css/_variables.css"),T=`:root { ${j.join("")} ${C.join("")} } ${P.join("")}`;c.writeFileSync(J,T),o.staticVariables=p;const q=i.join(s,"css/_global.css"),_=M.mergeObjects(r.global,n.globalStyles),I=await X.parseAndJoinStyles(_,"");c.writeFileSync(q,`@layer global { ${I} }`);const f=i.join(s,"css/_reset.css"),w=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:Oe,u=await X.parseAndJoinStyles(w,"");c.writeFileSync(f,`@layer reset { ${u} }`);const F=i.join(s,"css/_templates.css"),x=M.mergeObjects(r.templates,n.templates),E=await ye(x),W=Pe(x);c.writeFileSync(F,`@layer templates { ${E} }`),o.templates=x;const A=M.mergeFactories(n.templates);o.templatePaths=Object.fromEntries(Object.entries(A).map(([m,b])=>[m,b._path]));const{mediaQueries:z}=n;o.mediaQueries=Object.fromEntries(z.map(([m,b])=>[`@${m}`,b]));const L=z.map(([m])=>`'@${m}'`).join(" | "),ee=i.join(s,"types/css-tokens.d.ts"),Z=`
|
3
|
+
// Variable types
|
4
|
+
type VariableTokens = ${[...a].join("|")};
|
5
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
+
|
7
|
+
// Template types
|
8
|
+
type TemplateTokens = {
|
9
|
+
${Object.entries(W).map(([m,b])=>`${m}?: ${b}`).join(`
|
10
|
+
`)}
|
11
|
+
}
|
12
|
+
|
13
|
+
// Media query types
|
14
|
+
type MediaQueryKeys = ${L||"''"};
|
15
|
+
`;c.writeFileSync(ee,Z);const $e=i.join(s,"cache/config-cache.json");c.writeFileSync($e,JSON.stringify(o,null,2))},de=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const a=r.exec(e);if(a){const y=a.at(1);if(ie.some(l=>y==null?void 0:y.includes(l)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
+
|
17
|
+
${e}`:`globalThis.saltyConfig = {};
|
18
|
+
|
19
|
+
${e}`}catch{return e}},K=async(e,t,s)=>{const n=D.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const o=i.parse(t);let a=c.readFileSync(t,"utf8");a=de(a),a=Ee(a,e);const y=i.join(s,"js",n+".js"),$=await re(e),l=i.join(e,($==null?void 0:$.configDir)||"","salty.config.ts"),d=je(l),g=await he(e);await pe.build({stdin:{contents:a,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},C=>{const N=c.readFileSync(C.path,"utf8");return{contents:de(N),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${y}?t=${p}`),outputFilePath:y}},Re=async e=>{const t=await v(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await v(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:o}=await import(`${n}?t=${r}`);return M.mergeObjects(o,t)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const r=[],o=[],a=await v(e),y=i.join(a,"index.css");s&&(()=>{c.existsSync(a)&&xe.execSync("rm -rf "+a),c.mkdirSync(a,{recursive:!0}),c.mkdirSync(i.join(a,"css")),c.mkdirSync(i.join(a,"types")),c.mkdirSync(i.join(a,"js")),c.mkdirSync(i.join(a,"cache"))})();const l=new Set,d=new Set;async function g(f){const S=["node_modules","saltygen"],w=c.statSync(f);if(w.isDirectory()){const u=c.readdirSync(f);if(S.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>g(i.join(f,x))))}else if(w.isFile()&&Y(f)){l.add(f);const F=c.readFileSync(f,"utf8");/define[\w\d]+\(/.test(F)&&d.add(f)}}await g(e),await Fe(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:S}=await K(e,f,a);Object.entries(S).forEach(([w,u])=>{u.isKeyframes?p.keyframes.push({value:u,src:f,name:w}):u.isClassName?p.classNames.push({...u,src:f,name:w}):u.generator&&p.components.push({...u,src:f,name:w})})}));const j=await ae(e);for(const f of p.keyframes){const{value:S}=f,w=`a_${S.animationName}.css`,u=`css/${w}`,F=i.join(a,u);r.push(w),c.writeFileSync(F,S.css)}const h={};for(const f of p.components){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j});o[u.priority]||(o[u.priority]=[]);const F=await u.css;if(!F)continue;o[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}for(const f of p.classNames){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j}),F=await u.css;if(!F)continue;o[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}j.importStrategy==="component"&&Object.entries(h).forEach(([f,S])=>{const w=S.map(W=>`@import url('./${W}');`).join(`
|
20
|
+
`),u=D.toHash(f,6),F=i.parse(f),x=D.dashCase(F.name),E=i.join(a,`css/f_${x}-${u}.css`);c.writeFileSync(E,w)});const C=r.map(f=>`@import url('./css/${f}');`).join(`
|
21
|
+
`);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
|
+
|
23
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return c.readFileSync(i.join(a,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
24
|
+
`)}
|
25
|
+
${C}`;if(j.importStrategy!=="component"){const f=o.reduce((S,w,u)=>{const F=w.reduce((A,z)=>{var Z;const L=i.join(a,"css",z),ee=c.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(z))==null?void 0:Z.at(1))||D.toHash(L,6);return A.includes(Q)?A:`${A}
|
26
|
+
/*start:${Q}-${z}*/
|
27
|
+
${ee}
|
28
|
+
/*end:${Q}*/
|
29
|
+
`},""),x=`l_${u}.css`,E=i.join(a,"css",x),W=`@layer l${u} { ${F}
|
30
|
+
}`;return c.writeFileSync(E,W),`${S}
|
31
|
+
@import url('./css/${x}');`},"");T+=f}c.writeFileSync(y,T);const _=Date.now()-n,I=_<200?"🔥":_<500?"🚀":_<1e3?"🎉":_<2e3?"🚗":_<5e3?"🤔":"🥴";G.info(`Generated CSS in ${_}ms! ${I}`)}catch(n){console.error(n)}},Me=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=[],a=await ae(e),{contents:y}=await K(e,t,n);for(const[$,l]of Object.entries(y)){if(l.isKeyframes&&l.css){const C=`css/${`a_${l.animationName}.css`}`,N=i.join(n,C);c.writeFileSync(N,await l.css);return}if(l.isClassName){const h=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),C=await h.css;if(!C)continue;o[0].push(h.cssFileName);const N=`css/${h.cssFileName}`,P=i.join(n,N);c.writeFileSync(P,C)}if(!l.generator)return;const d=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),g=await d.css;if(!g)continue;const p=`css/${d.cssFileName}`,j=i.join(n,p);c.writeFileSync(j,g),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}if(a.importStrategy!=="component")o.forEach(($,l)=>{const d=`l_${l}.css`,g=i.join(n,"css",d);let p=c.readFileSync(g,"utf8");$.forEach(j=>{var P;const h=i.join(n,"css",j),C=((P=/.*-([^-]+)-\d+.css/.exec(j))==null?void 0:P.at(1))||D.toHash(h,6);if(!p.includes(C)){const J=c.readFileSync(h,"utf8"),T=`/*start:${C}-${j}*/
|
32
|
+
${J}
|
33
|
+
/*end:${C}*/
|
34
|
+
`;p=`${p.replace(/\}$/,"")}
|
35
|
+
${T}
|
36
|
+
}`}}),c.writeFileSync(g,p)});else{const $=o.flat().map(j=>`@import url('./${j}');`).join(`
|
37
|
+
`),l=D.toHash(t,6),d=i.parse(t),g=D.dashCase(d.name),p=i.join(n,`css/f_${g}-${l}.css`);c.writeFileSync(p,$)}}}catch(n){console.error(n)}},ve=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=c.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==o&&await oe.writeFile(t,o);const y=await ae(e),{contents:$}=await K(e,t,n);let l=o;if(Object.entries($).forEach(([d,g])=>{var u;if(g.isKeyframes||!g.generator)return;const p=g.generator._withBuildContext({callerName:d,isProduction:s,config:y}),j=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!j)return console.error("Could not find the original declaration");const h=(u=j.at(1))==null?void 0:u.trim(),C=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(l);if(!C)return console.error("Could not find the original declaration");const{index:N}=C;let P=!1;const J=setTimeout(()=>P=!0,5e3);let T=0,q=!1,_=0;for(;!q&&!P;){const F=l[N+T];F==="("&&_++,F===")"&&_--,_===0&&F===")"&&(q=!0),T>l.length&&(P=!0),T++}if(!P)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const I=N+T,f=l.slice(N,I),S=l,w=` ${d} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;l=l.replace(f,w),S===l&&console.error("Minimize file failed to change content",{name:d,tagName:h})}),y.importStrategy==="component"){const d=D.toHash(t,6),g=i.parse(t);l=`import '../../saltygen/css/${`f_${D.dashCase(g.name)}-${d}.css`}';
|
38
|
+
${l}`}return l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=Fe;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
|