@salty-css/core 0.4.5-fix-cli-astro-salty-config-dir.3 → 0.4.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/index.cjs +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/main.cjs +1 -1
- package/dist/bin/main.js +1 -1
- package/dist/bin/templates.d.ts +7 -7
- package/dist/compiler/get-files.cjs +1 -1
- package/dist/compiler/get-files.js +4 -1
- package/dist/compiler/salty-compiler.cjs +1 -1
- package/dist/compiler/salty-compiler.js +1 -1
- package/dist/css/keyframes.cjs +1 -1
- package/dist/css/keyframes.js +1 -1
- package/dist/factories/index.cjs +1 -1
- package/dist/factories/index.js +1 -1
- package/dist/generators/index.cjs +1 -1
- package/dist/generators/index.js +1 -1
- package/dist/{generators-Drnkwo8s.js → generators-DAdl36fA.js} +5 -5
- package/dist/generators-DZKr85A5.cjs +1 -0
- package/dist/helpers/index.cjs +1 -1
- package/dist/instances/classname-instance.cjs +1 -1
- package/dist/instances/classname-instance.js +9 -3
- package/dist/{main-B1k85c5B.js → main-Ca_8cFnn.js} +56 -52
- package/dist/main-CvR1ynqw.cjs +11 -0
- package/dist/maybe.d.ts +2 -0
- package/dist/maybe.d.ts.map +1 -0
- package/dist/{parse-styles-iylx7U1R.js → parse-styles-Cz2VD8e7.js} +6 -4
- package/dist/parse-styles-rgixHoC7.cjs +3 -0
- package/dist/parsers/index.cjs +3 -3
- package/dist/parsers/index.js +16 -14
- package/dist/{chunk-CMqjfN_6.cjs → rolldown-runtime-BocRIvOZ.cjs} +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/salty-compiler-1Mz9ynQ6.cjs +34 -0
- package/dist/{salty-compiler-DGhrdu3X.js → salty-compiler-DEdCuAgC.js} +76 -54
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +2 -4
- package/package.json +1 -1
- package/dist/generators-BVhdBePh.cjs +0 -1
- package/dist/main-DA_29Yks.cjs +0 -11
- package/dist/parse-styles-B51bN86A.cjs +0 -3
- package/dist/salty-compiler-BGq5eocy.cjs +0 -34
package/dist/parsers/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../util/index.cjs"),t=require("../parse-styles-
|
|
2
|
-
`)}let s={};for(let[e,t]of Object.entries(n))if(typeof t!=`function`)if(t&&typeof t==`object`){let n=e.trim(),r=await i(t,[...a,n]);o.push(r)}else s[e]=t
|
|
3
|
-
`)},a=e=>Object.keys(e),o=e=>e?Object.entries(e).reduce((e,[t,n])=>(typeof n==`function`?e[t]=`any`:typeof n==`object`&&(e[t]=s(n).map(e=>`"${e}"`).join(` | `)),e),{}):{},s=(e,n=``,i=new Set)=>e?t.r(e)?(n&&i.add(n),Object.entries(e).forEach(([e,t])=>{r(e,t)&&s(t,n?`${n}.${e}`:e,i)}),[...i]):(Object.entries(e).forEach(([e,t])=>{let r=n?`${n}.${e}`:e;return t&&typeof t==`object`?s(t,r,i):i.add(n)}),[...i]):[],c=e=>{let t={};if(!e)return t;for(let[n,r]of Object.entries(e))
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../util/index.cjs"),t=require("../parse-styles-rgixHoC7.cjs");var n=new Set([`base`,`variants`,`defaultVariants`,`compoundVariants`,`anyOfVariants`]),r=(e,t)=>!n.has(e)&&!!t&&typeof t==`object`&&!Array.isArray(t),i=async(n,a=[])=>{if(!n)return``;let o=[];if(t.r(n)){let s=n,c=a.map(t=>e.dashCase(String(t))).join(`-`);if(s.base){let n=`t_`+e.toHash(c,4),r=await t.t(s.base,`.${c}, .${n}`);o.push(r)}if(s.variants){for(let[n,r]of Object.entries(s.variants))if(r&&typeof r==`object`)for(let[i,a]of Object.entries(r)){if(!a||typeof a!=`object`)continue;let r=`${c}-${e.dashCase(n)}-${e.dashCase(i)}`,s=`tv_`+e.toHash(r,4),l=await t.t(a,`.${r}, .${s}`);o.push(l)}}for(let[e,t]of Object.entries(s)){if(!r(e,t))continue;let n=await i(t,[...a,e.trim()]);o.push(n)}return o.join(`
|
|
2
|
+
`)}let s={};for(let[e,t]of Object.entries(n))if(typeof t!=`function`){if(t&&typeof t==`object`){let n=e.trim(),r=await i(t,[...a,n]);o.push(r)}else s[e]=t}if(Object.keys(s).length){let n=a.map(t=>e.dashCase(String(t))).join(`-`),r=`t_`+e.toHash(n,4),i=await t.t(s,`.${n}, .${r}`);o.push(i)}return o.join(`
|
|
3
|
+
`)},a=e=>Object.keys(e),o=e=>e?Object.entries(e).reduce((e,[t,n])=>(typeof n==`function`?e[t]=`any`:typeof n==`object`&&(e[t]=s(n).map(e=>`"${e}"`).join(` | `)),e),{}):{},s=(e,n=``,i=new Set)=>e?t.r(e)?(n&&i.add(n),Object.entries(e).forEach(([e,t])=>{r(e,t)&&s(t,n?`${n}.${e}`:e,i)}),[...i]):(Object.entries(e).forEach(([e,t])=>{let r=n?`${n}.${e}`:e;return t&&typeof t==`object`?s(t,r,i):i.add(n)}),[...i]):[],c=e=>{let t={};if(!e)return t;for(let[n,r]of Object.entries(e))r&&typeof r==`object`&&typeof r!=`function`&&u(r,[],t[n]||(t[n]={}),{});return t},l=(e,n)=>{let r={};for(let[t,n]of Object.entries(e))r[t]={...n};if(t.r(n)&&n.variants)for(let[e,t]of Object.entries(n.variants)){r[e]=r[e]||{};for(let n of Object.keys(t))r[e][n]=!0}return r},u=(e,n,i,a)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let o=l(a,e),s=n.join(`.`);if(n.length&&(t.r(e)||Object.keys(o).length)){let e={};for(let[t,n]of Object.entries(o)){let r=Object.keys(n);e[t]=r.length===1&&r[0]===`true`?`boolean`:r.map(e=>`"${e}"`).join(` | `)}Object.keys(e).length&&(i[s]=e)}if(t.r(e)){for(let[t,a]of Object.entries(e))r(t,a)&&u(a,[...n,t.trim()],i,o);return}for(let[t,r]of Object.entries(e))r&&typeof r==`object`&&!Array.isArray(r)&&u(r,[...n,t.trim()],i,o)};exports.getTemplateKeys=a,exports.getTemplateTokens=s,exports.getTemplateTypes=o,exports.getTemplateVariantMaps=c,exports.parseAndJoinStyles=t.t,exports.parseStyles=t.n,exports.parseTemplates=i,exports.parseValueModifiers=t.c,exports.parseValueTokens=t.o,exports.parseVariableTokens=t.s,exports.reportParserIssue=t.a;
|
package/dist/parsers/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { dashCase as e, toHash as t } from "../util/index.js";
|
|
2
|
-
import { a as n, c as r, n as i, o as a, r as o, s, t as c } from "../parse-styles-
|
|
2
|
+
import { a as n, c as r, n as i, o as a, r as o, s, t as c } from "../parse-styles-Cz2VD8e7.js";
|
|
3
3
|
//#region src/parsers/parse-templates.ts
|
|
4
|
-
var l = new Set([
|
|
4
|
+
var l = /* @__PURE__ */ new Set([
|
|
5
5
|
"base",
|
|
6
6
|
"variants",
|
|
7
7
|
"defaultVariants",
|
|
8
8
|
"compoundVariants",
|
|
9
9
|
"anyOfVariants"
|
|
10
|
-
]), u = (e, t) => l.has(e)
|
|
10
|
+
]), u = (e, t) => !l.has(e) && !!t && typeof t == "object" && !Array.isArray(t), d = async (n, r = []) => {
|
|
11
11
|
if (!n) return "";
|
|
12
12
|
let i = [];
|
|
13
13
|
if (o(n)) {
|
|
@@ -17,10 +17,10 @@ var l = new Set([
|
|
|
17
17
|
i.push(n);
|
|
18
18
|
}
|
|
19
19
|
if (a.variants) {
|
|
20
|
-
for (let [n, r] of Object.entries(a.variants)) if (
|
|
20
|
+
for (let [n, r] of Object.entries(a.variants)) if (r && typeof r == "object") for (let [a, s] of Object.entries(r)) {
|
|
21
21
|
if (!s || typeof s != "object") continue;
|
|
22
|
-
let r = `${o}-${e(n)}-${e(a)}`, l = await c(s, `.${r}, .${
|
|
23
|
-
i.push(
|
|
22
|
+
let r = `${o}-${e(n)}-${e(a)}`, l = "tv_" + t(r, 4), u = await c(s, `.${r}, .${l}`);
|
|
23
|
+
i.push(u);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
for (let [e, t] of Object.entries(a)) {
|
|
@@ -31,13 +31,15 @@ var l = new Set([
|
|
|
31
31
|
return i.join("\n");
|
|
32
32
|
}
|
|
33
33
|
let a = {};
|
|
34
|
-
for (let [e, t] of Object.entries(n)) if (typeof t != "function")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
for (let [e, t] of Object.entries(n)) if (typeof t != "function") {
|
|
35
|
+
if (t && typeof t == "object") {
|
|
36
|
+
let n = e.trim(), a = await d(t, [...r, n]);
|
|
37
|
+
i.push(a);
|
|
38
|
+
} else a[e] = t;
|
|
39
|
+
}
|
|
38
40
|
if (Object.keys(a).length) {
|
|
39
|
-
let n = r.map((t) => e(String(t))).join("-"), o = await c(a, `.${n}, .${
|
|
40
|
-
i.push(
|
|
41
|
+
let n = r.map((t) => e(String(t))).join("-"), o = "t_" + t(n, 4), s = await c(a, `.${n}, .${o}`);
|
|
42
|
+
i.push(s);
|
|
41
43
|
}
|
|
42
44
|
return i.join("\n");
|
|
43
45
|
}, f = (e) => Object.keys(e), p = (e) => e ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "function" ? e[t] = "any" : typeof n == "object" && (e[t] = m(n).map((e) => `"${e}"`).join(" | ")), e), {}) : {}, m = (e, t = "", n = /* @__PURE__ */ new Set()) => e ? o(e) ? (t && n.add(t), Object.entries(e).forEach(([e, r]) => {
|
|
@@ -48,7 +50,7 @@ var l = new Set([
|
|
|
48
50
|
}), [...n]) : [], h = (e) => {
|
|
49
51
|
let t = {};
|
|
50
52
|
if (!e) return t;
|
|
51
|
-
for (let [n, r] of Object.entries(e))
|
|
53
|
+
for (let [n, r] of Object.entries(e)) r && typeof r == "object" && typeof r != "function" && _(r, [], t[n] || (t[n] = {}), {});
|
|
52
54
|
return t;
|
|
53
55
|
}, g = (e, t) => {
|
|
54
56
|
let n = {};
|
|
@@ -73,7 +75,7 @@ var l = new Set([
|
|
|
73
75
|
for (let [r, a] of Object.entries(e)) u(r, a) && _(a, [...t, r.trim()], n, i);
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
|
-
for (let [r, a] of Object.entries(e))
|
|
78
|
+
for (let [r, a] of Object.entries(e)) a && typeof a == "object" && !Array.isArray(a) && _(a, [...t, r.trim()], n, i);
|
|
77
79
|
};
|
|
78
80
|
//#endregion
|
|
79
81
|
export { f as getTemplateKeys, m as getTemplateTokens, p as getTemplateTypes, h as getTemplateVariantMaps, c as parseAndJoinStyles, i as parseStyles, d as parseTemplates, r as parseValueModifiers, a as parseValueTokens, s as parseVariableTokens, n as reportParserIssue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../util/index.cjs"),t=require("../parse-styles-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../util/index.cjs"),t=require("../parse-styles-rgixHoC7.cjs");var n=n=>{let r=t=>e.toHash(t),i=async(e,r)=>(await t.n(e,r,n)).join(`
|
|
2
2
|
`);return{className:r,css:i,resolve:async(e,t)=>{let n=r(e);return{className:n,css:await i(e,t||`.${n}`)}},getDynamicStylesCss:i}};exports.defineRuntime=n;
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toHash as e } from "../util/index.js";
|
|
2
|
-
import { n as t } from "../parse-styles-
|
|
2
|
+
import { n as t } from "../parse-styles-Cz2VD8e7.js";
|
|
3
3
|
//#region src/runtime/index.ts
|
|
4
4
|
var n = (n) => {
|
|
5
5
|
let r = (t) => e(t), i = async (e, r) => (await t(e, r, n)).join("\n");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./compiler/helpers.cjs"),n=require("./util/index.cjs"),r=require("./factories/index.cjs"),i=require("./parse-styles-rgixHoC7.cjs"),a=require("./css/merge.cjs"),o=require("./compiler/get-files.cjs"),s=require("./parsers/index.cjs");let c=require("fs"),l=require("esbuild");l=e.t(l,1);let u=require("path"),d=require("winston"),f=require("fs/promises"),p=require("child_process"),m=require("module");var h=(0,d.createLogger)({level:`debug`,format:d.format.combine(d.format.colorize(),d.format.cli()),transports:[new d.transports.Console({})]}),g=e=>{h.error(e)},_=/^(?:[a-z][a-z0-9+.-]*:)?\/\//i,v=e=>typeof e==`string`?{url:e}:e,y=e=>e.startsWith(`.`)||e.startsWith(`/`)?e:`./${e}`,b=e=>e.split(`\\`).join(`/`),x=(e,t)=>(0,m.createRequire)(t).resolve(e),S=(e,t)=>{let n=(0,u.dirname)(t);(0,c.existsSync)(n)||(0,c.mkdirSync)(n,{recursive:!0}),(0,c.copyFileSync)(e,t)},C=(e,{media:t,supports:n})=>{let r=`@import url('${e}')`;return n&&(r+=` supports(${n})`),t&&(r+=` ${t}`),`${r};`},w=(e,t,r,i={})=>{let a=v(e),{url:o}=a,s=i.resolveModule??x,c=i.copyAsset??S;if(_.test(o)||o.startsWith(`/`))return{rule:C(o,a)};if(o.startsWith(`./`)||o.startsWith(`../`)){let e=(0,u.resolve)((0,u.dirname)(t),o);return{rule:C(y(b((0,u.relative)((0,u.join)(r,`css`),e))),a)}}let l=s(o.startsWith(`~`)?o.slice(1):o,t),d=`${n.toHash(l,6)}-${(0,u.basename)(l)}`;return c(l,(0,u.join)(r,`imports`,d)),{rule:C(`../imports/${d}`,a)}},T=async e=>{let t=await o.getPackageJson(e);if(t)return t.type},E,D=async e=>{if(E)return E;let t=await T(e);return t===`module`?E=`esm`:(t===`commonjs`||{}.url.endsWith(`.cjs`))&&(E=`cjs`),E||`esm`};function O(e){return e?typeof e==`string`?e.replace(/[^\d\w]/g,`.`):O(String(e)):``}var k={"*, *::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`}},A=class{projectRootDir;options;importFile=e=>import(`${e}?t=${Date.now()}`);cache={rcFile:null,destDir:null,externalModules:[]};constructor(e,t={}){if(this.projectRootDir=e,this.options=t,typeof process>`u`)throw Error(`SaltyServer can only be used in a Node.js environment.`)}get isProduction(){if(this.options.mode)return this.options.mode===`production`;try{return process.env.NODE_ENV!==`development`}catch{return!1}}readRCFile=async(e=this.projectRootDir)=>{if(this.cache.rcFile)return this.cache.rcFile;if(e===`/`)throw Error(`Could not find .saltyrc.json file`);let t=(0,u.join)(e,`.saltyrc.json`),n=await(0,f.readFile)(t,`utf-8`).then(JSON.parse).catch(()=>void 0);return n?(this.cache.rcFile=n,n):this.readRCFile((0,u.join)(e,`..`))};getRCProjectConfig=async e=>{let t=await this.readRCFile(e);return t.projects?.find(t=>e.endsWith(t.dir||``))||t.projects?.find(e=>e.dir===t.defaultProject)};getPathFilter=async()=>{let e=await this.getRCProjectConfig(this.projectRootDir);return{include:e?.include,exclude:e?.exclude}};isAllowedSaltyFile=(e,r)=>{if(!t.isSaltyFile(e))return!1;let i=n.normalizePath((0,u.relative)(this.projectRootDir,e));return n.isPathAllowed(i,r)};getExternalModules=e=>{if(this.cache.externalModules.length>0)return this.cache.externalModules;let t=(0,c.readFileSync)(e,`utf8`).match(/externalModules:\s?\[(.*)\]/);if(!t)return[];let n=t[1].split(`,`).map(e=>e.replace(/['"`]/g,``).trim());return this.cache.externalModules=n,n};getDestDir=async()=>{if(this.cache.destDir)return this.cache.destDir;let e=await this.getRCProjectConfig(this.projectRootDir),t=(0,u.join)(this.projectRootDir,e?.saltygenDir||`saltygen`);return this.cache.destDir=t,t};generateConfig=async()=>{let e=await this.getRCProjectConfig(this.projectRootDir),t=await this.getDestDir(),n=(0,u.join)(this.projectRootDir,e?.configDir||``,`salty.config.ts`),r=(0,u.join)(t,`salty.config.js`),i=await D(this.projectRootDir),a=this.getExternalModules(n);await l.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:i,external:a});let{config:o}=await this.importFile(r);return{config:o,path:r}};addConfigCache=e=>{try{let t=(0,c.readFileSync)((0,u.join)(this.projectRootDir,`saltygen/cache/config-cache.json`),`utf8`);return t?`globalThis.saltyConfig = ${t};\n\n${e}`:`globalThis.saltyConfig = {};\n\n${e}`}catch{return e}};getConfigCache=async()=>{let e=await this.getDestDir(),t=(0,u.join)(e,`cache/config-cache.json`),n=(0,c.readFileSync)(t,`utf8`);if(!n)throw Error(`Could not find config cache file`);return JSON.parse(n)};getConfig=async()=>{let e=await this.getConfigCache(),t=await this.getDestDir(),n=(0,u.join)(t,`salty.config.js`),{config:r}=await this.importFile(n);return a.mergeObjects(r,e)};generateCss=async(e=!0)=>{try{let r=Date.now();this.isProduction?h.info(`Generating CSS in production mode! 🔥`):h.info(`Generating CSS in development mode! 🚀`);let i=[],a=[],o=await this.getDestDir(),s=(0,u.join)(o,`index.css`);e&&((0,c.existsSync)(o)&&(0,p.execSync)(`rm -rf `+o),(0,c.mkdirSync)(o,{recursive:!0}),(0,c.mkdirSync)((0,u.join)(o,`css`)),(0,c.mkdirSync)((0,u.join)(o,`types`)),(0,c.mkdirSync)((0,u.join)(o,`js`)),(0,c.mkdirSync)((0,u.join)(o,`cache`)),(0,c.mkdirSync)((0,u.join)(o,`imports`)));let l=new Set,d=new Set,f=await this.getPathFilter(),{exclude:m}=f,g=this.projectRootDir;async function _(e){let r=[`node_modules`,`saltygen`],i=(0,c.statSync)(e);if(i.isDirectory()){if(r.some(t=>e.includes(t)))return;if(m?.length){let t=n.normalizePath((0,u.relative)(g,e));if(t&&!n.isPathAllowed(t,{exclude:m}))return}let t=(0,c.readdirSync)(e);await Promise.all(t.map(t=>_((0,u.join)(e,t))))}else if(i.isFile()&&t.isSaltyFile(e)&&n.isPathAllowed(n.normalizePath((0,u.relative)(g,e)),f)){l.add(e);let t=(0,c.readFileSync)(e,`utf8`);/define[\w\d]+\(/.test(t)&&d.add(e)}}await _(this.projectRootDir),await this.generateConfigStyles(d);let v={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async e=>{let{contents:n}=await this.compileSaltyFile(e,o);for(let[r,i]of Object.entries(n)){let n=await t.resolveExportValue(i,1);n.isKeyframes?v.keyframes.push({value:n,src:e,name:r}):n.isClassName?v.classNames.push({...i,src:e,name:r}):n.generator&&v.components.push({...i,src:e,name:r})}}));let y=await this.getConfig();for(let e of v.keyframes){let{value:t}=e,n=`a_${t.animationName}.css`,r=`css/${n}`,a=(0,u.join)(o,r);i.push(n),(0,c.writeFileSync)(a,t.css)}let b={};for(let e of v.components){let{src:t,name:n}=e;b[t]||(b[t]=[]);let r=e.generator._withBuildContext({callerName:n,isProduction:this.isProduction,config:y});a[r.priority]||(a[r.priority]=[]);let i=await r.css;if(!i)continue;a[r.priority].push(r.cssFileName);let s=`css/${r.cssFileName}`,l=(0,u.join)(o,s);(0,c.writeFileSync)(l,i),y.importStrategy===`component`&&b[t].push(r.cssFileName)}for(let e of v.classNames){let{src:t,name:n}=e;b[t]||(b[t]=[]);let r=e.generator._withBuildContext({callerName:n,isProduction:this.isProduction,config:y}),i=await r.css;if(!i)continue;a[r.priority]||(a[r.priority]=[]),a[r.priority].push(r.cssFileName);let s=`css/${r.cssFileName}`,l=(0,u.join)(o,s);(0,c.writeFileSync)(l,i),y.importStrategy===`component`&&b[t].push(r.cssFileName)}y.importStrategy===`component`&&Object.entries(b).forEach(([e,t])=>{let r=t.map(e=>`@import url('./${e}');`).join(`
|
|
2
|
+
`),i=n.toHash(e,6),a=(0,u.parse)(e),s=n.dashCase(a.name),l=(0,u.join)(o,`css/f_${s}-${i}.css`);(0,c.writeFileSync)(l,r||`/* Empty file */`)});let x=i.map(e=>`@import url('./css/${e}');`).join(`
|
|
3
|
+
`),S=`/*!
|
|
4
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
|
5
|
+
* Do not edit this file directly
|
|
6
|
+
* Version 0.4.6-alpha.0
|
|
7
|
+
*/
|
|
8
|
+
@layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[`_imports.css`,`_variables.css`,`_reset.css`,`_global.css`,`_templates.css`,`_fonts.css`].filter(e=>{try{return(0,c.readFileSync)((0,u.join)(o,`css`,e),`utf8`).length>0}catch{return!1}}).map(e=>`@import url('./css/${e}')${e===`_imports.css`?` layer(imports)`:``};`).join(`
|
|
9
|
+
`)}\n${x}`;if(y.importStrategy!==`component`){let e=a.reduce((e,t,r)=>{let i=t.reduce((e,t)=>{let r=(0,u.join)(o,`css`,t),i=(0,c.readFileSync)(r,`utf8`),a=/.*-([^-]+)-\d+.css/.exec(t)?.at(1)||n.toHash(r,6);return e.includes(a)?e:`${e}\n/*start:${a}-${t}*/\n${i}\n/*end:${a}*/\n`},``),a=`l_${r}.css`,s=(0,u.join)(o,`css`,a),l=`@layer l${r} { ${i}\n }`;return(0,c.writeFileSync)(s,l),`${e}\n@import url('./css/${a}');`},``);S+=e}(0,c.writeFileSync)(s,S);let C=Date.now()-r,w=C<200?`🔥`:C<500?`🚀`:C<1e3?`🎉`:C<2e3?`🚗`:C<5e3?`🤔`:`🥴`;h.info(`Generated CSS in ${C}ms! ${w}`)}catch(e){console.error(e)}};generateConfigStyles=async e=>{let t=await this.getDestDir(),o={mediaQueries:[],globalStyles:[],variables:[],templates:[],imports:[],fonts:[]};await Promise.all([...e].map(async e=>{let{contents:n,outputFilePath:r}=await this.compileSaltyFile(e,t);Object.entries(n).forEach(([t,n])=>{n.isMedia?o.mediaQueries.push([t,n]):n.isGlobalDefine?o.globalStyles.push(n):n.isDefineVariables?o.variables.push(n):n.isDefineTemplates?o.templates.push(n._setPath(`${t};;${r}`)):n.isDefineImport?o.imports.push(n._setPath(e)):n.isDefineFont&&o.fonts.push(n)})}));let{config:l,path:d}=await this.generateConfig(),f={...l},{mediaQueries:p}=o;f.mediaQueries=Object.fromEntries(p.map(([e,t])=>[`@${e}`,t]));let m=p.map(([e])=>`'@${e}'`).join(` | `),g=new Set,_=async(e,t=[])=>{if(!e)return[];let r=Object.entries(e).map(async([e,r])=>{let a=async r=>{if(!r)return;if(r instanceof Promise)return await a(await r);if(typeof r==`function`)return await a(await r());if(typeof r==`object`)return await _(r,[...t,e]);let o=O(e),s=n.dashCase(e),c=[...t,o].join(`.`);g.add(`"${c}"`);let l=[...t.map(n.dashCase),s].join(`-`),u=i.s(r);return u?`--${l}: ${u.transformed};`:`--${l}: ${r};`};return await a(r)});return(await Promise.all(r)).flat()},v=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=await _(t);return e===`base`?n.join(``):f.mediaQueries[e]?`${f.mediaQueries[e]} { ${n.join(``)} }`:`${e} { ${n.join(``)} }`});return(await Promise.all(t)).flat()},y=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=Object.entries(t).map(async([t,n])=>{let r=await _(n,[e]);return`${`.${e}-${t}, [data-${e}="${t}"]`} { ${r.join(``)} }`});return(await Promise.all(n)).flat()});return(await Promise.all(t)).flat()},b=(e={})=>({...e,responsive:void 0,conditional:void 0}),x=e=>o.variables.map(t=>e===`static`?b(t._current):t._current[e]),S=a.mergeObjects(b(l.variables),x(`static`)),C=await _(S),T=await v(a.mergeObjects(l.variables?.responsive,x(`responsive`))),E=await y(a.mergeObjects(l.variables?.conditional,x(`conditional`))),D=(0,u.join)(t,`css/_variables.css`),A=`:root { ${C.join(``)} ${T.join(``)} } ${E.join(``)}`;(0,c.writeFileSync)(D,A),f.staticVariables=S;let j=(0,u.join)(t,`css/_global.css`),M=a.mergeObjects(l.global,o.globalStyles),N=await i.t(M,``);(0,c.writeFileSync)(j,`@layer global { ${N} }`);let P=(0,u.join)(t,`css/_reset.css`),F=l.reset===`none`?{}:typeof l.reset==`object`?l.reset:k,I=await i.t(F,``);(0,c.writeFileSync)(P,`@layer reset { ${I} }`);let L=(0,u.join)(t,`css/_templates.css`),R=a.mergeObjects(l.templates,o.templates),z=await s.parseTemplates(R),B=s.getTemplateTypes(R),V=s.getTemplateVariantMaps(R);(0,c.writeFileSync)(L,`@layer templates { ${z} }`),f.templates=R;let H=(0,u.join)(t,`css/_imports.css`),U=[];for(let e of o.imports){let n=e._path;if(n)for(let r of e._current)try{let{rule:e}=w(r,n,t);U.push(e)}catch(e){let t=typeof r==`string`?r:r.url;h.error(`Failed to resolve defineImport(${JSON.stringify(t)}) from ${n}: ${e.message}`)}}(0,c.writeFileSync)(H,U.join(`
|
|
10
|
+
`));let W=l.templates?[r.defineTemplates(l.templates)._setPath(`config;;${d}`)]:[],G=a.mergeFactories(o.templates,W);f.templatePaths=Object.fromEntries(Object.entries(G).map(([e,t])=>[e,t._path]));let K=(0,u.join)(t,`css/_fonts.css`);if(o.fonts.length===0)(0,c.writeFileSync)(K,``);else{let e=[],t=[];for(let n of o.fonts){let{imports:r,body:i}=n._toCss();e.push(...r),t.push(i)}let n=e.length?`${e.join(`
|
|
11
|
+
`)}\n\n`:``;(0,c.writeFileSync)(K,`${n}@layer fonts { ${t.join(` `)} }`)}let q=(0,u.join)(t,`types/css-tokens.d.ts`),J=[...g].join(`|`),Y=e=>e.split(/[.\-_]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),X=Object.entries(V),Z=X.some(([,e])=>Object.keys(e).length>0)?`type TemplateVariantTokens = {
|
|
12
|
+
${X.filter(([,e])=>Object.keys(e).length>0).map(([e,t])=>`${e}: {\n ${Object.entries(t).map(([e,t])=>`'${e}': { ${Object.entries(t).map(([e,t])=>`${e}?: ${t}`).join(`; `)} }`).join(`;
|
|
13
|
+
`)}\n }`).join(`;
|
|
14
|
+
`)}
|
|
15
|
+
}`:`type TemplateVariantTokens = Record<string, Record<string, Record<string, never>>>;`,Q=X.flatMap(([e,t])=>Object.keys(t).map(t=>`type ${Y(e)}${Y(t)}Variants = TemplateVariantTokens['${e}']['${t}'];`)).join(`
|
|
16
|
+
`),$=`
|
|
17
|
+
// Variable types
|
|
18
|
+
type VariableTokens = ${J||`''`};
|
|
19
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
|
20
|
+
|
|
21
|
+
// Template types
|
|
22
|
+
type TemplateTokens = {
|
|
23
|
+
${Object.entries(B).map(([e,t])=>!t||t===`any`?`${e}?: ${t||`any`}`:`${e}?: ${t} | \`\${${t}}@\${string}\``).join(`
|
|
24
|
+
`)}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Template variant types (per docs/template-variants-spec.md §7)
|
|
28
|
+
${Z}
|
|
29
|
+
${Q}
|
|
30
|
+
|
|
31
|
+
// Media query types
|
|
32
|
+
type MediaQueryKeys = ${m||`''`};
|
|
33
|
+
`;(0,c.writeFileSync)(q,$);let ee=(0,u.join)(t,`cache/config-cache.json`);(0,c.writeFileSync)(ee,JSON.stringify(f,null,2))};compileSaltyFile=async(e,t)=>{let r=n.toHash(e),i=(0,u.join)(t,`./temp`);(0,c.existsSync)(i)||(0,c.mkdirSync)(i);let a=(0,u.parse)(e),o=(0,c.readFileSync)(e,`utf8`);o=this.replaceStyledTag(o),o=this.addConfigCache(o);let s=n.toHash(o),d=(0,u.join)(t,`js`,`${r}-${s}.js`),f=await this.getRCProjectConfig(this.projectRootDir),p=(0,u.join)(this.projectRootDir,f?.configDir||``,`salty.config.ts`),m=this.getExternalModules(p),h=await D(this.projectRootDir);return await l.build({stdin:{contents:o,sourcefile:a.base,resolveDir:a.dir,loader:`tsx`},minify:!0,treeShaking:!0,bundle:!0,outfile:d,format:h,target:[`node20`],keepNames:!0,external:m,packages:`external`,plugins:[{name:`test`,setup:e=>{e.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},e=>{let t=(0,c.readFileSync)(e.path,`utf8`);return{contents:this.replaceStyledTag(t),loader:`ts`}})}}]}),{contents:await this.importFile(d),outputFilePath:d}};getFramework=async()=>(await this.getRCProjectConfig(this.projectRootDir))?.framework;generateFile=async e=>{try{let r=await this.getDestDir(),i=await this.getPathFilter();if(this.isAllowedSaltyFile(e,i)){let i=[],a=await this.getConfig(),{contents:o}=await this.compileSaltyFile(e,r);for(let[e,n]of Object.entries(o)){let o=await t.resolveExportValue(n,1);if(o.isKeyframes&&o.css){let e=`css/${`a_${o.animationName}.css`}`,t=(0,u.join)(r,e);(0,c.writeFileSync)(t,await o.css);continue}if(o.isClassName){let t=o.generator._withBuildContext({callerName:e,isProduction:this.isProduction,config:a}),n=await t.css;if(!n)continue;i[t.priority]||(i[t.priority]=[]),i[t.priority].push(t.cssFileName);let s=`css/${t.cssFileName}`,l=(0,u.join)(r,s);(0,c.writeFileSync)(l,n);continue}if(!o.generator)continue;let s=o.generator._withBuildContext({callerName:e,isProduction:this.isProduction,config:a}),l=await s.css;if(!l)continue;let d=`css/${s.cssFileName}`,f=(0,u.join)(r,d);(0,c.writeFileSync)(f,l),i[s.priority]||(i[s.priority]=[]),i[s.priority].push(s.cssFileName)}if(a.importStrategy!==`component`)i.forEach((e,t)=>{let i=`l_${t}.css`,a=(0,u.join)(r,`css`,i),o=(0,c.readFileSync)(a,`utf8`);e.forEach(e=>{let t=(0,u.join)(r,`css`,e),i=/.*-([^-]+)-\d+.css/.exec(e)?.at(1)||n.toHash(t,6);if(!o.includes(i)){let n=`/*start:${i}-${e}*/\n${(0,c.readFileSync)(t,`utf8`)}\n/*end:${i}*/\n`;o=`${o.replace(/\}$/,``)}\n${n}\n}`}}),(0,c.writeFileSync)(a,o)});else{let t=i.flat().map(e=>`@import url('./${e}');`).join(`
|
|
34
|
+
`),a=n.toHash(e,6),o=(0,u.parse)(e),s=n.dashCase(o.name),l=(0,u.join)(r,`css/f_${s}-${a}.css`);(0,c.writeFileSync)(l,t||`/* Empty file */`)}}}catch(e){console.error(e)}};replaceStyledTag=e=>e.replace(/styled\(([^"'`{,]+),/g,(n,r)=>{if(/^['"`]/.test(r))return n;let i=RegExp(`import[^;]*${r}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return n;let a=i.exec(e);if(a){let e=a.at(1);if(t.saltyFileExtensions.some(t=>e?.includes(t)))return n}return`styled('div',`})};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return A}});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSaltyFile as e, resolveExportValue as t, saltyFileExtensions as n } from "./compiler/helpers.js";
|
|
2
2
|
import { dashCase as r, isPathAllowed as i, normalizePath as a, toHash as o } from "./util/index.js";
|
|
3
3
|
import { defineTemplates as s } from "./factories/index.js";
|
|
4
|
-
import { s as c, t as l } from "./parse-styles-
|
|
4
|
+
import { s as c, t as l } from "./parse-styles-Cz2VD8e7.js";
|
|
5
5
|
import { mergeFactories as u, mergeObjects as d } from "./css/merge.js";
|
|
6
6
|
import { getPackageJson as f } from "./compiler/get-files.js";
|
|
7
7
|
import { getTemplateTypes as p, getTemplateVariantMaps as m, parseTemplates as h } from "./parsers/index.js";
|
|
@@ -100,8 +100,8 @@ var X = {
|
|
|
100
100
|
readRCFile = async (e = this.projectRootDir) => {
|
|
101
101
|
if (this.cache.rcFile) return this.cache.rcFile;
|
|
102
102
|
if (e === "/") throw Error("Could not find .saltyrc.json file");
|
|
103
|
-
let t =
|
|
104
|
-
return
|
|
103
|
+
let t = E(e, ".saltyrc.json"), n = await N(t, "utf-8").then(JSON.parse).catch(() => void 0);
|
|
104
|
+
return n ? (this.cache.rcFile = n, n) : this.readRCFile(E(e, ".."));
|
|
105
105
|
};
|
|
106
106
|
getRCProjectConfig = async (e) => {
|
|
107
107
|
let t = await this.readRCFile(e);
|
|
@@ -114,7 +114,11 @@ var X = {
|
|
|
114
114
|
exclude: e?.exclude
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
|
-
isAllowedSaltyFile = (t, n) =>
|
|
117
|
+
isAllowedSaltyFile = (t, n) => {
|
|
118
|
+
if (!e(t)) return !1;
|
|
119
|
+
let r = a(O(this.projectRootDir, t));
|
|
120
|
+
return i(r, n);
|
|
121
|
+
};
|
|
118
122
|
getExternalModules = (e) => {
|
|
119
123
|
if (this.cache.externalModules.length > 0) return this.cache.externalModules;
|
|
120
124
|
let t = y(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
|
@@ -153,13 +157,13 @@ var X = {
|
|
|
153
157
|
}
|
|
154
158
|
};
|
|
155
159
|
getConfigCache = async () => {
|
|
156
|
-
let e =
|
|
157
|
-
if (!
|
|
158
|
-
return JSON.parse(
|
|
160
|
+
let e = await this.getDestDir(), t = E(e, "cache/config-cache.json"), n = y(t, "utf8");
|
|
161
|
+
if (!n) throw Error("Could not find config cache file");
|
|
162
|
+
return JSON.parse(n);
|
|
159
163
|
};
|
|
160
164
|
getConfig = async () => {
|
|
161
|
-
let e = await this.getConfigCache(), t =
|
|
162
|
-
return d(
|
|
165
|
+
let e = await this.getConfigCache(), t = await this.getDestDir(), n = E(t, "salty.config.js"), { config: r } = await this.importFile(n);
|
|
166
|
+
return d(r, e);
|
|
163
167
|
};
|
|
164
168
|
generateCss = async (n = !0) => {
|
|
165
169
|
try {
|
|
@@ -211,8 +215,8 @@ var X = {
|
|
|
211
215
|
}));
|
|
212
216
|
let T = await this.getConfig();
|
|
213
217
|
for (let e of w.keyframes) {
|
|
214
|
-
let { value: t } = e, n = `a_${t.animationName}.css`, r =
|
|
215
|
-
c.push(n), S(
|
|
218
|
+
let { value: t } = e, n = `a_${t.animationName}.css`, r = `css/${n}`, i = E(u, r);
|
|
219
|
+
c.push(n), S(i, t.css);
|
|
216
220
|
}
|
|
217
221
|
let k = {};
|
|
218
222
|
for (let e of w.components) {
|
|
@@ -225,7 +229,10 @@ var X = {
|
|
|
225
229
|
});
|
|
226
230
|
l[r.priority] || (l[r.priority] = []);
|
|
227
231
|
let i = await r.css;
|
|
228
|
-
|
|
232
|
+
if (!i) continue;
|
|
233
|
+
l[r.priority].push(r.cssFileName);
|
|
234
|
+
let a = `css/${r.cssFileName}`, o = E(u, a);
|
|
235
|
+
S(o, i), T.importStrategy === "component" && k[t].push(r.cssFileName);
|
|
229
236
|
}
|
|
230
237
|
for (let e of w.classNames) {
|
|
231
238
|
let { src: t, name: n } = e;
|
|
@@ -235,16 +242,19 @@ var X = {
|
|
|
235
242
|
isProduction: this.isProduction,
|
|
236
243
|
config: T
|
|
237
244
|
}), i = await r.css;
|
|
238
|
-
|
|
245
|
+
if (!i) continue;
|
|
246
|
+
l[r.priority] || (l[r.priority] = []), l[r.priority].push(r.cssFileName);
|
|
247
|
+
let a = `css/${r.cssFileName}`, o = E(u, a);
|
|
248
|
+
S(o, i), T.importStrategy === "component" && k[t].push(r.cssFileName);
|
|
239
249
|
}
|
|
240
250
|
T.importStrategy === "component" && Object.entries(k).forEach(([e, t]) => {
|
|
241
|
-
let n = t.map((e) => `@import url('./${e}');`).join("\n"), i = o(e, 6);
|
|
242
|
-
S(
|
|
251
|
+
let n = t.map((e) => `@import url('./${e}');`).join("\n"), i = o(e, 6), a = D(e), s = r(a.name), c = E(u, `css/f_${s}-${i}.css`);
|
|
252
|
+
S(c, n || "/* Empty file */");
|
|
243
253
|
});
|
|
244
254
|
let A = c.map((e) => `@import url('./css/${e}');`).join("\n"), j = `/*!
|
|
245
255
|
* Generated with Salty CSS (https://salty-css.dev)
|
|
246
256
|
* Do not edit this file directly
|
|
247
|
-
* Version 0.4.
|
|
257
|
+
* Version 0.4.6-alpha.0
|
|
248
258
|
*/
|
|
249
259
|
@layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[
|
|
250
260
|
"_imports.css",
|
|
@@ -265,8 +275,8 @@ var X = {
|
|
|
265
275
|
let r = t.reduce((e, t) => {
|
|
266
276
|
let n = E(u, "css", t), r = y(n, "utf8"), i = /.*-([^-]+)-\d+.css/.exec(t)?.at(1) || o(n, 6);
|
|
267
277
|
return e.includes(i) ? e : `${e}\n/*start:${i}-${t}*/\n${r}\n/*end:${i}*/\n`;
|
|
268
|
-
}, ""), i = `l_${n}.css`;
|
|
269
|
-
return S(
|
|
278
|
+
}, ""), i = `l_${n}.css`, a = E(u, "css", i), s = `@layer l${n} { ${r}\n }`;
|
|
279
|
+
return S(a, s), `${e}\n@import url('./css/${i}');`;
|
|
270
280
|
}, "");
|
|
271
281
|
j += e;
|
|
272
282
|
}
|
|
@@ -331,61 +341,68 @@ var X = {
|
|
|
331
341
|
...e,
|
|
332
342
|
responsive: void 0,
|
|
333
343
|
conditional: void 0
|
|
334
|
-
}), C = (e) => n.variables.map((t) => e === "static" ? x(t._current) : t._current[e]), w = d(x(i.variables), C("static")), T = await v(w), D = await y(d(i.variables?.responsive, C("responsive"))), O = await b(d(i.variables?.conditional, C("conditional")))
|
|
335
|
-
S(
|
|
336
|
-
let
|
|
337
|
-
S(
|
|
338
|
-
let P = E(t, "css/
|
|
344
|
+
}), C = (e) => n.variables.map((t) => e === "static" ? x(t._current) : t._current[e]), w = d(x(i.variables), C("static")), T = await v(w), D = await y(d(i.variables?.responsive, C("responsive"))), O = await b(d(i.variables?.conditional, C("conditional"))), k = E(t, "css/_variables.css"), A = `:root { ${T.join("")} ${D.join("")} } ${O.join("")}`;
|
|
345
|
+
S(k, A), o.staticVariables = w;
|
|
346
|
+
let j = E(t, "css/_global.css"), M = d(i.global, n.globalStyles), N = await l(M, "");
|
|
347
|
+
S(j, `@layer global { ${N} }`);
|
|
348
|
+
let P = E(t, "css/_reset.css"), F = i.reset === "none" ? {} : typeof i.reset == "object" ? i.reset : X, L = await l(F, "");
|
|
349
|
+
S(P, `@layer reset { ${L} }`);
|
|
350
|
+
let R = E(t, "css/_templates.css"), z = d(i.templates, n.templates), B = await h(z), V = p(z), H = m(z);
|
|
351
|
+
S(R, `@layer templates { ${B} }`), o.templates = z;
|
|
352
|
+
let U = E(t, "css/_imports.css"), W = [];
|
|
339
353
|
for (let e of n.imports) {
|
|
340
354
|
let n = e._path;
|
|
341
355
|
if (n) for (let r of e._current) try {
|
|
342
356
|
let { rule: e } = G(r, n, t);
|
|
343
|
-
|
|
357
|
+
W.push(e);
|
|
344
358
|
} catch (e) {
|
|
345
359
|
let t = typeof r == "string" ? r : r.url;
|
|
346
360
|
I.error(`Failed to resolve defineImport(${JSON.stringify(t)}) from ${n}: ${e.message}`);
|
|
347
361
|
}
|
|
348
362
|
}
|
|
349
|
-
S(
|
|
350
|
-
let
|
|
351
|
-
o.templatePaths = Object.fromEntries(Object.entries(
|
|
352
|
-
let
|
|
353
|
-
if (n.fonts.length === 0) S(
|
|
363
|
+
S(U, W.join("\n"));
|
|
364
|
+
let K = i.templates ? [s(i.templates)._setPath(`config;;${a}`)] : [], q = u(n.templates, K);
|
|
365
|
+
o.templatePaths = Object.fromEntries(Object.entries(q).map(([e, t]) => [e, t._path]));
|
|
366
|
+
let J = E(t, "css/_fonts.css");
|
|
367
|
+
if (n.fonts.length === 0) S(J, "");
|
|
354
368
|
else {
|
|
355
369
|
let e = [], t = [];
|
|
356
370
|
for (let r of n.fonts) {
|
|
357
371
|
let { imports: n, body: i } = r._toCss();
|
|
358
372
|
e.push(...n), t.push(i);
|
|
359
373
|
}
|
|
360
|
-
|
|
374
|
+
let r = e.length ? `${e.join("\n")}\n\n` : "";
|
|
375
|
+
S(J, `${r}@layer fonts { ${t.join(" ")} }`);
|
|
361
376
|
}
|
|
362
|
-
let
|
|
363
|
-
${
|
|
364
|
-
}` : "type TemplateVariantTokens = Record<string, Record<string, Record<string, never>>>;",
|
|
365
|
-
S(B, `
|
|
377
|
+
let Z = E(t, "types/css-tokens.d.ts"), ee = [..._].join("|"), Q = (e) => e.split(/[.\-_]/).filter(Boolean).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(""), $ = Object.entries(H), te = $.some(([, e]) => Object.keys(e).length > 0) ? `type TemplateVariantTokens = {
|
|
378
|
+
${$.filter(([, e]) => Object.keys(e).length > 0).map(([e, t]) => `${e}: {\n ${Object.entries(t).map(([e, t]) => `'${e}': { ${Object.entries(t).map(([e, t]) => `${e}?: ${t}`).join("; ")} }`).join(";\n ")}\n }`).join(";\n ")}
|
|
379
|
+
}` : "type TemplateVariantTokens = Record<string, Record<string, Record<string, never>>>;", ne = $.flatMap(([e, t]) => Object.keys(t).map((t) => `type ${Q(e)}${Q(t)}Variants = TemplateVariantTokens['${e}']['${t}'];`)).join("\n "), re = `
|
|
366
380
|
// Variable types
|
|
367
|
-
type VariableTokens = ${
|
|
381
|
+
type VariableTokens = ${ee || "''"};
|
|
368
382
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
|
369
383
|
|
|
370
384
|
// Template types
|
|
371
385
|
type TemplateTokens = {
|
|
372
|
-
${Object.entries(
|
|
386
|
+
${Object.entries(V).map(([e, t]) => !t || t === "any" ? `${e}?: ${t || "any"}` : `${e}?: ${t} | \`\${${t}}@\${string}\``).join("\n")}
|
|
373
387
|
}
|
|
374
388
|
|
|
375
389
|
// Template variant types (per docs/template-variants-spec.md §7)
|
|
376
|
-
${
|
|
377
|
-
${
|
|
390
|
+
${te}
|
|
391
|
+
${ne}
|
|
378
392
|
|
|
379
393
|
// Media query types
|
|
380
394
|
type MediaQueryKeys = ${g || "''"};
|
|
381
|
-
|
|
395
|
+
`;
|
|
396
|
+
S(Z, re);
|
|
397
|
+
let ie = E(t, "cache/config-cache.json");
|
|
398
|
+
S(ie, JSON.stringify(o, null, 2));
|
|
382
399
|
};
|
|
383
400
|
compileSaltyFile = async (e, t) => {
|
|
384
401
|
let n = o(e), r = E(t, "./temp");
|
|
385
402
|
_(r) || v(r);
|
|
386
403
|
let i = D(e), a = y(e, "utf8");
|
|
387
404
|
a = this.replaceStyledTag(a), a = this.addConfigCache(a);
|
|
388
|
-
let s = E(t, "js", `${n}-${
|
|
405
|
+
let s = o(a), c = E(t, "js", `${n}-${s}.js`), l = await this.getRCProjectConfig(this.projectRootDir), u = E(this.projectRootDir, l?.configDir || "", "salty.config.ts"), d = this.getExternalModules(u), f = await J(this.projectRootDir);
|
|
389
406
|
return await C.build({
|
|
390
407
|
stdin: {
|
|
391
408
|
contents: a,
|
|
@@ -396,11 +413,11 @@ var X = {
|
|
|
396
413
|
minify: !0,
|
|
397
414
|
treeShaking: !0,
|
|
398
415
|
bundle: !0,
|
|
399
|
-
outfile:
|
|
400
|
-
format:
|
|
416
|
+
outfile: c,
|
|
417
|
+
format: f,
|
|
401
418
|
target: ["node20"],
|
|
402
419
|
keepNames: !0,
|
|
403
|
-
external:
|
|
420
|
+
external: d,
|
|
404
421
|
packages: "external",
|
|
405
422
|
plugins: [{
|
|
406
423
|
name: "test",
|
|
@@ -415,8 +432,8 @@ var X = {
|
|
|
415
432
|
}
|
|
416
433
|
}]
|
|
417
434
|
}), {
|
|
418
|
-
contents: await this.importFile(
|
|
419
|
-
outputFilePath:
|
|
435
|
+
contents: await this.importFile(c),
|
|
436
|
+
outputFilePath: c
|
|
420
437
|
};
|
|
421
438
|
};
|
|
422
439
|
getFramework = async () => (await this.getRCProjectConfig(this.projectRootDir))?.framework;
|
|
@@ -428,7 +445,8 @@ var X = {
|
|
|
428
445
|
for (let [e, r] of Object.entries(s)) {
|
|
429
446
|
let o = await t(r, 1);
|
|
430
447
|
if (o.isKeyframes && o.css) {
|
|
431
|
-
|
|
448
|
+
let e = `css/${`a_${o.animationName}.css`}`, t = E(n, e);
|
|
449
|
+
S(t, await o.css);
|
|
432
450
|
continue;
|
|
433
451
|
}
|
|
434
452
|
if (o.isClassName) {
|
|
@@ -438,7 +456,9 @@ var X = {
|
|
|
438
456
|
config: a
|
|
439
457
|
}), r = await t.css;
|
|
440
458
|
if (!r) continue;
|
|
441
|
-
i[t.priority] || (i[t.priority] = []), i[t.priority].push(t.cssFileName)
|
|
459
|
+
i[t.priority] || (i[t.priority] = []), i[t.priority].push(t.cssFileName);
|
|
460
|
+
let s = `css/${t.cssFileName}`, c = E(n, s);
|
|
461
|
+
S(c, r);
|
|
442
462
|
continue;
|
|
443
463
|
}
|
|
444
464
|
if (!o.generator) continue;
|
|
@@ -447,21 +467,23 @@ var X = {
|
|
|
447
467
|
isProduction: this.isProduction,
|
|
448
468
|
config: a
|
|
449
469
|
}), c = await s.css;
|
|
450
|
-
|
|
470
|
+
if (!c) continue;
|
|
471
|
+
let l = `css/${s.cssFileName}`, u = E(n, l);
|
|
472
|
+
S(u, c), i[s.priority] || (i[s.priority] = []), i[s.priority].push(s.cssFileName);
|
|
451
473
|
}
|
|
452
474
|
if (a.importStrategy !== "component") i.forEach((e, t) => {
|
|
453
|
-
let r = E(n, "css",
|
|
475
|
+
let r = `l_${t}.css`, i = E(n, "css", r), a = y(i, "utf8");
|
|
454
476
|
e.forEach((e) => {
|
|
455
477
|
let t = E(n, "css", e), r = /.*-([^-]+)-\d+.css/.exec(e)?.at(1) || o(t, 6);
|
|
456
|
-
if (!
|
|
478
|
+
if (!a.includes(r)) {
|
|
457
479
|
let n = `/*start:${r}-${e}*/\n${y(t, "utf8")}\n/*end:${r}*/\n`;
|
|
458
|
-
|
|
480
|
+
a = `${a.replace(/\}$/, "")}\n${n}\n}`;
|
|
459
481
|
}
|
|
460
|
-
}), S(
|
|
482
|
+
}), S(i, a);
|
|
461
483
|
});
|
|
462
484
|
else {
|
|
463
|
-
let t = i.flat().map((e) => `@import url('./${e}');`).join("\n"), a = o(e, 6);
|
|
464
|
-
S(
|
|
485
|
+
let t = i.flat().map((e) => `@import url('./${e}');`).join("\n"), a = o(e, 6), s = D(e), c = r(s.name), l = E(n, `css/f_${c}-${a}.css`);
|
|
486
|
+
S(l, t || "/* Empty file */");
|
|
465
487
|
}
|
|
466
488
|
}
|
|
467
489
|
} catch (e) {
|
package/dist/util/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(t){return t?typeof t==`string`?t.replace(/\s/g,`-`).replace(/-([a-z])/g,e=>e[1].toUpperCase()):e(String(t)):``}function t(e){return e?typeof e!=`string`||typeof e!=`string`?t(String(e)):e.replace(/[\s.]/g,`-`).replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,t)=>(t>0?`-`:``)+e.toLowerCase()):``}var n=e=>e.replace(/\\/g,`/`),r=new Map,i=e=>{let t=r.get(e);if(t)return t;let i=n(e),a=[];for(let e=0;e<i.length;e++){let t=i[e];if(t===`*`){let t=1;for(;i[e+1]===`*`;)e++,t++;a.push(t>=2?{type:`globstar`}:{type:`star`})}else t===`?`?a.push({type:`single`}):a.push({type:`lit`,char:t})}return r.set(e,a),a},a=(e,t)=>{let r=i(e),a=n(t),o=r.length,s=a.length,c=new Uint8Array((o+1)*(s+1)),l=(e,t)=>{let n=e*(s+1)+t,i=c[n];if(i)return i===2;let u;if(e===o)u=t===s;else{let n=r[e];switch(n.type){case`lit`:u=t<s&&a[t]===n.char&&l(e+1,t+1);break;case`single`:u=t<s&&a[t]!==`/`&&l(e+1,t+1);break;case`star`:u=l(e+1,t)||t<s&&a[t]!==`/`&&l(e,t+1);break;case`globstar`:u=l(e+1,t)||t<s&&l(e,t+1)
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(t){return t?typeof t==`string`?t.replace(/\s/g,`-`).replace(/-([a-z])/g,e=>e[1].toUpperCase()):e(String(t)):``}function t(e){return e?typeof e!=`string`||typeof e!=`string`?t(String(e)):e.replace(/[\s.]/g,`-`).replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,t)=>(t>0?`-`:``)+e.toLowerCase()):``}var n=e=>e.replace(/\\/g,`/`),r=new Map,i=e=>{let t=r.get(e);if(t)return t;let i=n(e),a=[];for(let e=0;e<i.length;e++){let t=i[e];if(t===`*`){let t=1;for(;i[e+1]===`*`;)e++,t++;a.push(t>=2?{type:`globstar`}:{type:`star`})}else t===`?`?a.push({type:`single`}):a.push({type:`lit`,char:t})}return r.set(e,a),a},a=(e,t)=>{let r=i(e),a=n(t),o=r.length,s=a.length,c=new Uint8Array((o+1)*(s+1)),l=(e,t)=>{let n=e*(s+1)+t,i=c[n];if(i)return i===2;let u;if(e===o)u=t===s;else{let n=r[e];switch(n.type){case`lit`:u=t<s&&a[t]===n.char&&l(e+1,t+1);break;case`single`:u=t<s&&a[t]!==`/`&&l(e+1,t+1);break;case`star`:u=l(e+1,t)||t<s&&a[t]!==`/`&&l(e,t+1);break;case`globstar`:u=l(e+1,t)||t<s&&l(e,t+1)}}return c[n]=u?2:1,u};return l(0,0)},o=(e,t)=>t.some(t=>a(t,e)),s=(e,{include:t,exclude:n}={})=>n?.length&&o(e,n)?!1:!t?.length||o(e,t);function c(e){return e?typeof e==`string`?e.replace(/\s/g,`-`).replace(/[-_]([a-z0-9])/g,e=>e[1].toUpperCase()).replace(/^[a-z]/,e=>e.toUpperCase()):c(String(e)):``}var l=e=>e?typeof e==`string`?t(e.replace(/[^a-zA-Z0-9_-]/g,`-`)):l(String(e)):``,u=e=>String.fromCharCode(e+(e>25?39:97)),d=(e,t)=>{let n=``,r;for(r=Math.abs(e);r>52;r=r/52|0)n=u(r%52)+n;return n=u(r%52)+n,n.length<t?n=n.padStart(t,`a`):n.length>t&&(n=n.slice(-t)),n},f=(e,t)=>{let n=t.length;for(;n;)e=e*33^t.charCodeAt(--n);return e},p=(e,t=5)=>d(f(5381,JSON.stringify(e))>>>0,t);exports.camelCase=e,exports.dashCase=t,exports.isPathAllowed=s,exports.matchesAnyGlob=o,exports.matchesGlob=a,exports.normalizePath=n,exports.pascalCase=c,exports.sanitizeClassName=l,exports.toHash=p;
|
package/dist/util/index.js
CHANGED
|
@@ -43,15 +43,13 @@ var n = (e) => e.replace(/\\/g, "/"), r = /* @__PURE__ */ new Map(), i = (e) =>
|
|
|
43
43
|
case "star":
|
|
44
44
|
u = l(e + 1, t) || t < s && a[t] !== "/" && l(e, t + 1);
|
|
45
45
|
break;
|
|
46
|
-
case "globstar":
|
|
47
|
-
u = l(e + 1, t) || t < s && l(e, t + 1);
|
|
48
|
-
break;
|
|
46
|
+
case "globstar": u = l(e + 1, t) || t < s && l(e, t + 1);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
return c[n] = u ? 2 : 1, u;
|
|
52
50
|
};
|
|
53
51
|
return l(0, 0);
|
|
54
|
-
}, o = (e, t) => t.some((t) => a(t, e)), s = (e, { include: t, exclude: n } = {}) => n?.length && o(e, n) ? !1 : t?.length
|
|
52
|
+
}, o = (e, t) => t.some((t) => a(t, e)), s = (e, { include: t, exclude: n } = {}) => n?.length && o(e, n) ? !1 : !t?.length || o(e, t);
|
|
55
53
|
//#endregion
|
|
56
54
|
//#region src/util/pascal-case.ts
|
|
57
55
|
function c(e) {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./util/index.cjs"),t=require("./parse-styles-B51bN86A.cjs");var n=class{params;buildContext={};constructor(e){this.params=e}get priority(){return 0}get isRoot(){return this.priority===0}get hash(){let{base:t,variants:n,compoundVariants:r,anyOfVariants:i}=this.params;return e.toHash({base:t,variants:n,compoundVariants:r,anyOfVariants:i})}get cssClassName(){return this.hash}get classNames(){let e=new Set([this.cssClassName]),{className:t}=this.params;return typeof t==`string`&&e.add(t),typeof t==`object`&&t.forEach(t=>e.add(t)),this.getTemplateClasses().forEach(t=>e.add(t)),this.buildContext.classNames&&this.buildContext.classNames.forEach(t=>e.add(t)),[...e].join(` `)}get cssFileName(){let{callerName:t}=this.buildContext;return t?`cl_${e.dashCase(t)}-${this.hash}.css`:`${this.hash}.css`}get css(){let{base:e={},variants:n={},compoundVariants:r=[],anyOfVariants:i=[]}=this.params,{config:a}=this.buildContext;return t.t({...e,variants:n,compoundVariants:r,anyOfVariants:i},`.${this.cssClassName}`,a,this.isRoot)}getTemplateClasses(n=this.buildContext.config){if(!n?.templates||!this.params.base||this.priority>0)return[];let r=Object.keys(n.templates);return Object.entries(this.params.base).reduce((n,[i,a])=>{if(!r.includes(i))return n;let o=t.i(a);if(!o||o.path.length===0)return n;let{path:s,variants:c}=o,l=[];for(let t of s){l.push(t);let r=e.dashCase(`${i}-${l.join(`.`)}`);n.push(`t_`+e.toHash(r,4));for(let[t,i]of Object.entries(c)){if(i===!1||i===void 0)continue;let a=i===!0?``:`-${e.dashCase(String(i))}`,o=`${r}-${e.dashCase(t)}${a}`;n.push(`tv_`+e.toHash(o,4))}}return n},[])}_withBuildContext(e){return this.buildContext=e,this}},r=class extends n{_params;constructor(e){super(e),this._params=e}get priority(){return this.params.priority?this.params.priority:0}},i=class extends n{tagName;_params;constructor(e,t){super(t),this.tagName=e,this._params=t}get priority(){return this.params.priority?this.params.priority:this.tagName&&(typeof this.tagName==`function`||typeof this.tagName==`object`)?(this.tagName.generator?.priority||0)+1:0}get clientProps(){let{element:t,as:n,variants:r={},compoundVariants:i=[],anyOfVariants:a=[],defaultVariants:o={},defaultProps:s={},passProps:c}=this.params,l=n??t,{callerName:u,isProduction:d}=this.buildContext,f=new Set([]),p=e=>{let t=o[e];t===void 0?f.add(e):f.add(`${e}=${String(t)}`)};Object.keys(r).forEach(p),i.map(e=>Object.keys(e).forEach(p)),a.map(e=>Object.keys(e).forEach(p));let m=new Set([]);if(this.params.base){let t=JSON.stringify(this.params.base).match(/\{-?props\.([^}]+)\}/gi);t&&t.forEach(t=>{let n=t.replace(/\{(?:-)?props\.([^}]+)\}/gi,`$1`),r=e.dashCase(n);n&&m.add(r)})}return{element:l,hash:this.hash,variantKeys:[...f],propValueKeys:[...m],passProps:c,defaultProps:s,attr:{"data-component-name":d?void 0:u}}}};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
package/dist/main-DA_29Yks.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const e=require("./chunk-CMqjfN_6.cjs"),t=require("./salty-compiler-BGq5eocy.cjs"),n=require("./compiler/helpers.cjs"),r=require("./util/index.cjs"),i=require("./server/index.cjs");let a=require("commander"),o=require("fs"),s=require("path"),c=require("fs/promises"),l=require("child_process"),u=require("ora");u=e.t(u,1);let d=require("ejs");d=e.t(d,1);let f=require("readline/promises");var p=(0,s.join)(process.cwd(),`package.json`),m=async(e=p)=>{let t=await(0,c.readFile)(e,`utf-8`).then(JSON.parse).catch(()=>void 0);if(!t)throw`Could not read package.json file!`;return t},h=async(e,t=p)=>{typeof e==`object`&&(e=JSON.stringify(e,null,2)),await(0,c.writeFile)(t,e)},g=async()=>m(new URL(`../package.json`,``+{}.url)),_={core:e=>`@salty-css/core@${e}`,eslintConfigCore:e=>`@salty-css/eslint-config-core@${e}`},v=e=>{e.scripts||={};let t=e.scripts.prepare;if(t){if(t.includes(`salty-css`))return{changed:!1,pkg:e};e.scripts.prepare=t+` && npx salty-css build`}else e.scripts.prepare=`npx salty-css build`;return{changed:!0,pkg:e}},y=e=>new Promise((t,n)=>{(0,l.exec)(e,e=>{if(e)return n(e);t()})}),b=async(...e)=>{let t=e.map(e=>e.replace(`-D`,``).split(`@`).slice(0,-1).join(`@`).trim()).join(`, `),n=(0,u.default)(`Installing packages: ${t}`).start();await y(`npm install ${e.join(` `)}`),n.succeed(`Installed packages: ${t}`)},x=()=>(0,o.existsSync)((0,s.join)(process.cwd(),`node_modules`,`.bin`,`prettier`));async function S(e){try{if(!x())return;await y(`./node_modules/.bin/prettier --write "${e}"`),t.r.info(`Formatted ${e} with Prettier`)}catch(n){t.r.error(`Error formatting ${e} with Prettier:`,n)}}var C=(e=process.cwd())=>(0,s.join)(e,`.saltyrc.json`),w=async(e=process.cwd())=>await(0,c.readFile)(C(e),`utf-8`).then(JSON.parse).catch(()=>({})),ee=async(e=process.cwd())=>(0,c.readFile)(C(e),`utf-8`).catch(()=>void 0),T=async(e=process.cwd())=>(await w(e)).defaultProject,E=(e,t,n,r={})=>{let i=(0,s.join)(t,n.srcDirectory),a={dir:i,framework:n.name,...r};if(e===void 0)return{content: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:i,projects:[a]},null,2),changed:!0,created:!0};let o=JSON.parse(e),c=o.projects||[];if(c.some(e=>e.dir===i))return{content:e,changed:!1,created:!1};c.push(a),o.projects=[...c];let l=JSON.stringify(o,null,2);return{content:l,changed:l!==e,created:!1}},D=async(e,n,r,i={})=>{let a=C(e),{content:o,changed:s,created:l}=E(await ee(e),n,r,i);return s?(l?t.r.info(`Creating file: `+a):t.r.info(`Edit file: `+a),await(0,c.writeFile)(a,o),await S(a),!0):!1},te=(e,t)=>(e.projects||[]).find(e=>e.dir===t)?.framework,O=(e,t=process.cwd())=>(0,s.join)(t,e===`.`?``:e),k=async e=>{let t=process.cwd(),n=O(e.dir,t),r=(0,s.relative)(t,n)||`.`,i=await m().catch(()=>void 0);if(e.requirePackageJson!==!1&&!i)throw Error(`Salty CSS project must be initialized in a directory with a package.json file.`);return{cwd:t,projectDir:n,relativeProjectPath:r,packageJson:i,rcFile:await w(t),cliVersion:(await g()).version||`0.0.0`,skipInstall:!!e.skipInstall,yes:!!e.yes}},A=(e,r)=>{e.command(`build [directory]`).alias(`b`).description(`Build the Salty-CSS project.`).option(`-d, --dir <dir>`,`Project directory to build the project in.`).option(`--watch`,`Watch for changes and rebuild the project.`).option(`--mode <mode>`,`Build mode: "production" or "development". Defaults to NODE_ENV-based detection.`).action(async function(e=r){t.r.info(`Building the Salty-CSS project...`);let{dir:a=e,watch:s,mode:c}=this.opts();if(c!==void 0&&c!==`production`&&c!==`development`)return t.n(`Invalid --mode "${c}". Expected "production" or "development".`);let l=a??await T();if(!l)return t.n(`Project directory must be provided. Add it as the first argument after build command or use the --dir option.`);let u=O(l),d=new t.t(u,{mode:c});await d.generateCss(),s&&(t.r.info(`Watching for changes in the project directory...`),(0,o.watch)(u,{recursive:!0},async(e,t)=>{if(!t)return console.warn(`File path not provided for change event`);await i.checkShouldRestart(t)?await d.generateCss(!1):n.isSaltyFile(t)&&await d.generateFile(t)}))})},ne=[`astro.config.mjs`,`astro.config.ts`,`astro.config.js`,`astro.config.cjs`],j=e=>{for(let t of ne){let n=(0,s.join)(e,t);if((0,o.existsSync)(n))return n}return null},M=e=>{let t=e.packageJson;if(!t)return!1;let n={...t.dependencies,...t.devDependencies};return Object.prototype.hasOwnProperty.call(n,`astro`)},N={name:`astro`,srcDirectory:`src`,detect:e=>!!j(e.projectDir)||M(e),runtimePackage:e=>`@salty-css/astro@${e}`,templates:{styled:`astro/styled-file.ts`,component:{styled:`astro/styled-file.ts`,wrapper:`astro/component.astro`,wrapperExt:`.astro`}}},P={name:`react`,srcDirectory:``,detect:()=>!0,runtimePackage:e=>`@salty-css/react@${e}`,templates:{styled:`react/styled-file.ts`,component:{styled:`react/styled-file.ts`,wrapper:`react/vanilla-file.ts`,wrapperExt:`.tsx`}}},F=[N,P],I={astro:N,react:P},L=async e=>{for(let t of F)if(await t.detect(e))return t;return P},R=e=>{if(e)return I[e]},z={"salty.config.ts":()=>Promise.resolve().then(()=>require("./salty.config-B0ZiRpHR.cjs")),"styles/index.css":()=>Promise.resolve().then(()=>require("./styles_index-DgmdjfFo.cjs")),"saltygen/index.css":()=>Promise.resolve().then(()=>require("./saltygen_index-BGHLaAOm.cjs")),"react/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-BCbAEzBB.cjs")),"react/vanilla-file.ts":()=>Promise.resolve().then(()=>require("./vanilla-file-Z3VsOa_U.cjs")),"astro/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-DorArlCk.cjs")),"astro/component.astro":()=>Promise.resolve().then(()=>require("./astro-component-r0qEcF1p.cjs"))},B=async(e,t)=>{let{default:n}=await z[e]();return{fileName:e,content:d.default.render(n,t)}},V=(e,n)=>{e.command(`generate [file] [directory]`).alias(`g`).description(`Generate a new component file.`).option(`-f, --file <file>`,`File to generate.`).option(`-d, --dir <dir>`,`Project directory to generate the file in.`).option(`-t, --tag <tag>`,`HTML tag of the component.`,`div`).option(`-n, --name <name>`,`Name of the component.`).option(`-c, --className <className>`,`CSS class of the component.`).option(`-r, --reactComponent`,`Generate a wrapper component file alongside the styled definition.`).action(async function(e,i=n){let{file:a=e,dir:o=i,tag:l,name:u,className:d,reactComponent:f=!1}=this.opts();if(!a)return t.n(`File to generate must be provided. Add it as the first argument after generate command or use the --file option.`);if(!o)return t.n(`Project directory must be provided. Add it as the second argument after generate command or use the --dir option.`);let p;try{p=await k({dir:o,requirePackageJson:!1})}catch(e){return t.n(e instanceof Error?e.message:String(e))}let m=R(te(p.rcFile,p.relativeProjectPath))??await L(p),h=a.split(`/`).slice(0,-1).join(`/`);h&&await(0,c.mkdir)((0,s.join)(p.projectDir,h),{recursive:!0});let g=(0,s.parse)((0,s.join)(p.projectDir,a));g.ext||=`.ts`,g.name.endsWith(`.css`)||(g.name+=`.css`),g.base=g.name+g.ext;let _=(0,s.format)(g);if(await(0,c.readFile)(_,`utf-8`).catch(()=>void 0)!==void 0){t.r.error(`File already exists: `+_);return}let v=r.pascalCase(u||g.base.replace(/\.css\.\w+$/,``));if(f){if(!m.templates.component)return t.n(`--reactComponent is not supported for the ${m.name} framework.`);let e=v+`Component`;v+=`Wrapper`;let n=g.base.replace(/\.css\.\w+$/,``),{content:r}=await B(m.templates.component.wrapper,{tag:l,componentName:e,styledComponentName:v,className:d,fileName:n});g.name=n.replace(/\.css$/,``),g.ext=m.templates.component.wrapperExt,g.base=g.name+g.ext;let i=(0,s.format)(g);t.r.info(`Generating a new file: `+i),await(0,c.writeFile)(i,r),await S(i)}let{content:y}=await B(f&&m.templates.component?m.templates.component.styled:m.templates.styled,{tag:l,name:v,className:d});t.r.info(`Generating a new file: `+_),await(0,c.writeFile)(_,y),await S(_)})},H=e=>{let t=e.trim();return t.startsWith(`-D `)?`${t.slice(3).trim()} (dev)`:t},U=e=>e.map(e=>` + ${H(e)}`).join(`
|
|
2
|
-
`),W=async(e,t,n={})=>{if(t||e.length===0)return;let r=n.input??process.stdin,i=n.output??process.stdout;if(!(n.isTTY??process.stdin.isTTY??!1))throw Error(`Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.`);i.write(`The following packages will be installed:\n${U(e)}\n`);let a=(0,f.createInterface)({input:r,output:i,terminal:!1});try{let e=(await a.question(`Proceed? (y/N) `)).trim().toLowerCase();if(e!==`y`&&e!==`yes`)throw Error(`Install cancelled by user.`)}finally{a.close()}},G=async(e,t={})=>{if(t.yes)return!0;let n=t.input??process.stdin,r=t.output??process.stdout;if(!(t.isTTY??process.stdin.isTTY??!1))return!1;let i=t.defaultYes?`(Y/n)`:`(y/N)`,a=(0,f.createInterface)({input:n,output:r,terminal:!1});try{let n=(await a.question(`${e} ${i} `)).trim().toLowerCase();return n===``?!!t.defaultYes:n===`y`||n===`yes`}finally{a.close()}},K=[`src`,`public`,`assets`,`styles`,`css`,`app`],q=[`styles`,`css`,`app`,`pages`],J=[`index`,`styles`,`main`,`app`,`global`,`globals`],Y=[`.css`,`.scss`,`.sass`],X=async e=>{for(let t of K)for(let n of J)for(let r of Y){let i=(0,s.join)(e,t,n+r);if(await(0,c.readFile)(i,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,i);for(let i of q){let a=(0,s.join)(e,t,i,n+r);if(await(0,c.readFile)(a,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,a)}}},Z=e=>`@salty-css/astro@${e}`,re=`import saltyIntegration from '@salty-css/astro/integration';
|
|
3
|
-
`,ie=e=>{if(e.includes(`@salty-css/astro`))return{content:null};let t=e,n=!1;return/integrations\s*:\s*\[/.test(t)?(t=t.replace(/integrations\s*:\s*\[/,e=>`${e}saltyIntegration(),`),n=!0):/defineConfig\s*\(\s*\{/.test(t)&&(t=t.replace(/defineConfig\s*\(\s*\{/,e=>`${e}\n integrations: [saltyIntegration()],`),n=!0),n?{content:re+t}:{content:null,warning:`Could not find a place to add saltyIntegration() in the Astro config. Please add it manually.`}},ae={name:`astro`,detect:e=>j(e.projectDir),plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let i=ie(r);if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[`-D ${Z(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS integration to Astro config: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},oe=[[`projectJs`,`eslint.config.js`],[`rootJs`,`eslint.config.js`],[`projectMjs`,`eslint.config.mjs`],[`rootMjs`,`eslint.config.mjs`],[`projectJson`,`.eslintrc.json`],[`rootJson`,`.eslintrc.json`]],se=(e,t)=>oe.map(([n,r])=>(0,s.join)(n.startsWith(`root`)?t:e,r)),ce=(e,t)=>{if(e.includes(`salty-css`))return{content:null};if(t){let t=`import saltyCss from "@salty-css/eslint-config-core/flat";\n${e}`;if(e.includes(`typescript-eslint`))if(t.includes(`.config(`))t=t.replace(`.config(`,`.config(saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};else if(t.includes(`export default [`))t=t.replace(`export default [`,`export default [ saltyCss,`);else if(t.includes(`eslintConfig = [`))t=t.replace(`eslintConfig = [`,`eslintConfig = [ saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};return{content:t}}let n=JSON.parse(e);return n.extends||=[],n.extends.includes(`@salty-css/core`)||n.extends.push(`@salty-css/core`),{content:JSON.stringify(n,null,2)}},le={name:`eslint`,detect:e=>se(e.projectDir,e.cwd).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return t.r.error(`Could not read ESLint config file.`),null;let i=ce(r,n.endsWith(`js`));if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[_.eslintConfigCore(e.cliVersion)],execute:async()=>(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},ue=[`next.config.js`,`next.config.cjs`,`next.config.ts`,`next.config.mjs`],de=e=>`@salty-css/next@${e}`,fe=e=>{if(e.includes(`withSaltyCss`))return{content:null};let t=e,n=!1;/\splugins([^=]*)=[^[]\[/.test(t)&&(t=t.replace(/\splugins([^=]*)=[^[]\[/,(e,t)=>` plugins${t}= [withSaltyCss,`),n=!0);let r=t.includes(`module.exports`),i=r?`const { withSaltyCss } = require('@salty-css/next');
|
|
4
|
-
`:`import { withSaltyCss } from '@salty-css/next';
|
|
5
|
-
`;return r&&!n?(t=t.replace(/module.exports = ([^;]+)/,(e,t)=>`module.exports = withSaltyCss(${t})`),n=!0):n||(t=t.replace(/export default ([^;]+)/,(e,t)=>`export default withSaltyCss(${t})`)),{content:i+t}},pe={name:`next`,detect:e=>ue.map(t=>(0,s.join)(e.projectDir,t)).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=fe(r);return i===null?null:{packages:[`-D ${de(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS plugin to Next.js config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},me=e=>`@salty-css/vite@${e}`,he=e=>e.includes(`saltyPlugin`)?{content:null}:{content:`import { saltyPlugin } from '@salty-css/vite';
|
|
6
|
-
`+e.replace(/(plugins: \[)/,`$1
|
|
7
|
-
saltyPlugin(__dirname),`)},ge=[le,{name:`vite`,detect:e=>{let t=(0,s.join)(e.projectDir,`vite.config.ts`);return(0,o.existsSync)(t)?t:null},plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=he(r);return i===null?null:{packages:[`-D ${me(e.cliVersion)}`],execute:async()=>(t.r.info(`Edit file: `+n),t.r.info(`Adding Salty-CSS plugin to Vite config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},pe,ae],_e=async e=>{let t=[];for(let n of ge){let r=await n.detect(e);if(!r)continue;let i=await n.plan(e,r);i&&t.push({name:n.name,configPath:r,plan:i})}return t},ve=async e=>{let t=[];for(let{name:n,configPath:r,plan:i}of e){let e=await i.execute();t.push({name:n,configPath:r,changed:e.changed})}return t},ye={vite:[`dist/**`],next:[`.next/**`,`out/**`]},be=({framework:e,integrations:t,hasSrcDir:n})=>{if(e===`astro`)return{};let r=[...new Set(t.flatMap(e=>ye[e]??[]))],i={};return n&&(i.include=[`src/**`]),r.length&&(i.exclude=r),i},Q=async(e,n,r)=>{let i=(0,s.join)(e,n);if((0,o.existsSync)(i)){t.r.debug(`File already exists: `+i);return}let a=n.split(`/`).slice(0,-1).join(`/`);a&&await(0,c.mkdir)((0,s.join)(e,a),{recursive:!0}),t.r.info(`Creating file: `+i),await(0,c.writeFile)(i,r),await S(i)},xe=async e=>{let n=(0,s.join)(e,`.gitignore`),r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);r!==void 0&&(r.includes(`saltygen`)||(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,r+`
|
|
8
|
-
|
|
9
|
-
# Salty-CSS
|
|
10
|
-
saltygen
|
|
11
|
-
`)))},Se=async(e,n)=>{let r=n??await X(e);if(!r){if(!await G("Could not find a CSS file to import the generated CSS. Do you want to create a new `styles/index.css` file and import it there? (y/N) ")){t.r.warn(`Could not find a CSS file to import the generated CSS. Please add it manually.`);return}let{fileName:n,content:r}=await B(`styles/index.css`);await Q(e,n,r);return}let i=(0,s.join)(e,r),a=await(0,c.readFile)(i,`utf-8`).catch(()=>void 0);if(a===void 0||a.includes(`saltygen`))return;let o=(0,s.relative)((0,s.join)(i,`..`),(0,s.join)(e,`saltygen/index.css`));t.r.info(`Adding global import statement to CSS file: `+i),await(0,c.writeFile)(i,`@import '${o}';\n`+a),await S(i)},Ce=async()=>{let e=await m().catch(()=>{t.n(`Could not read package.json file.`)});if(!e)return;let{pkg:n}=v(e);await h(n)},we=e=>{e.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.`).option(`-y, --yes`,`Skip the install confirmation prompt.`).action(async function(e=`.`){try{let n=this.opts(),r=n.dir??e;if(!r)return t.n(`Project directory must be provided. Add it as the first argument after init command or use the --dir option.`);let i=await k({dir:r,skipInstall:n.skipInstall,yes:n.yes});t.r.info(`Initializing a new Salty-CSS project!`);let a=await L(i);t.r.info(`Detected framework: ${a.name}`);let l=await _e(i);if(!i.skipInstall){let e=[_.core(i.cliVersion),a.runtimePackage(i.cliVersion),...l.flatMap(e=>e.plan.packages)];await W(e,i.yes),await b(...e)}let u=await Promise.all([B(`salty.config.ts`),B(`saltygen/index.css`)]),d=(0,s.join)(i.projectDir,a.srcDirectory);await(0,c.mkdir)(d,{recursive:!0}),await Promise.all(u.map(({fileName:e,content:t})=>Q(d,e,t)));let f=be({framework:a.name,integrations:l.map(e=>e.name),hasSrcDir:(0,o.existsSync)((0,s.join)(i.projectDir,`src`))});await D(i.cwd,i.relativeProjectPath,a,f),await xe(i.cwd),await Se(d,n.cssFile),await ve(l),await Ce(),t.r.info(`Running the build to generate initial CSS...`),await new t.t(d).generateCss(),t.r.info(`🎉 Salty CSS project initialized successfully!`),t.r.info(`Next steps:`),t.r.info("1. Configure variables and templates in `salty.config.ts`"),t.r.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.r.info("3. Run `npx salty-css build` to generate the CSS"),t.r.info(`4. Read about the features in the documentation: https://salty-css.dev`),t.r.info(`5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐`)}catch(e){return t.n(e instanceof Error?e.message:String(e))}})},$=async()=>{let e=(0,s.join)(process.cwd(),`package.json`),n=await m(e).catch(e=>t.n(e));if(!n)return t.n(`Could not read package.json file.`);let r={...n.dependencies,...n.devDependencies},i=Object.entries(r).filter(([e])=>e===`salty-css`||e.startsWith(`@salty-css/`));return i.length?i:t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+e)},Te=e=>{e.command(`update [version]`).alias(`up`).description(`Update Salty-CSS packages to the latest or specified version.`).option(`-v, --version <version>`,`Version to update to.`).option(`--legacy-peer-deps <legacyPeerDeps>`,`Use legacy peer dependencies (not recommended).`,!1).option(`-y, --yes`,`Skip confirmation prompts (install and rebuild).`).option(`-d, --dir <dir>`,`Project directory to rebuild after updating.`).action(async function(e=`latest`){let{legacyPeerDeps:n,version:r=e,yes:i=!1,dir:a}=this.opts(),o=await $();if(!o)return t.n(`Could not update Salty-CSS packages as any were found in package.json.`);let s=await g(),c=o.map(([e])=>r===`@`?`${e}@${s.version}`:`${e}@${r.replace(/^@/,``)}`);try{await W(c,i)}catch(e){return t.n(e instanceof Error?e.message:String(e))}n?(t.r.warn(`Using legacy peer dependencies to update packages.`),await b(...c,`--legacy-peer-deps`)):await b(...c);let l=await $();if(!l)return t.n(`Something went wrong while reading the updated packages.`);let u=l.reduce((e,[t,n])=>(e[n]||(e[n]=[]),e[n].push(t),e),{});if(Object.keys(u).length===1){let e=Object.keys(u)[0];t.r.info(`Updated to all Salty CSS packages successfully to ${e.replace(/^\^/,``)}`)}else for(let[e,n]of Object.entries(u))t.r.info(`Updated to ${e.replace(/^\^/,``)}: ${n.join(`, `)}`);let d=a??await T();if(!d){t.r.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");return}if(!await G(`Rebuild Salty CSS now?`,{yes:i}))return;let f=O(d);t.r.info(`Rebuilding Salty-CSS project...`),await new t.t(f).generateCss(),t.r.info(`Rebuild complete.`)})},Ee=e=>{e.option(`-v, --version`,`Show the current version of Salty-CSS.`).action(async function(){let e=await g();t.r.info(`CLI is running: `+e.version);let n=(0,s.join)(process.cwd(),`package.json`),r=await m(n).catch(e=>t.n(e));if(!r)return;let i={...r.dependencies,...r.devDependencies},a=Object.keys(i).filter(e=>e===`salty-css`||e.startsWith(`@salty-css/`));if(!a.length)return t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+n);for(let e of a)t.r.info(`${e}: ${i[e]}`)})};async function De(){let e=new a.Command;e.name(`salty-css`).description(`Salty-CSS CLI tool to help with annoying configuration tasks.`);let t=await T();we(e),Te(e),Ee(e),A(e,t),V(e,t),e.parseAsync(process.argv)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return De}});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
const e=require("./util/index.cjs"),t=require("./viewport-clamp-CHOyzt37.cjs");var n=e=>t=>{if(typeof t!=`string`||!e)return;let n=t,r=[];return Object.values(e).forEach(e=>{let{pattern:t,transform:i}=e;n=n.replace(t,e=>{let{value:t,css:n}=i(e);return n&&r.push(n),t})}),{transformed:n,additionalCss:r}},r=t=>n=>{if(typeof n==`string`&&/\{[^{}]+\}/g.test(n))return{transformed:n.replace(/\{([^{}]+)\}/g,(...n)=>{let r=e.dashCase(n[1].trim().replaceAll(`.`,`-`));return t&&!t.includes(r)&&console.warn(`Token ${r} might not exist`),r.startsWith(`-`)?`-${r}`:`var(--${r})`})}},i=r(),a=[`top`,`right`,`bottom`,`left`,`min-width`,/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],o=(e,n,r)=>{if(a.some(t=>typeof t==`string`?t===e:t.test(e))){let e=r?.defaultUnit||`px`;if(e.startsWith(`viewport-clamp:`))try{let r=e.split(`:`)[1];return t.t({screenSize:parseInt(r)})(Number(n))}catch(t){throw console.error(t),Error(`Invalid viewport-clamp value: ${e}`)}return`${n}${e}`}return`${n}`},s=[`Webkit`,`Moz`,`ms`,`O`],c=e=>s.some(t=>{if(!e.startsWith(t))return!1;let n=e.charAt(t.length);return n>=`A`&&n<=`Z`}),l=t=>t.startsWith(`-`)?t:c(t)?`-${e.dashCase(t)}`:e.dashCase(t),u=(e,t)=>{if(e===!0)throw Error(`[salty-css] ${t}`);e===`warn`&&console.warn(`[salty-css] ${t}`)},d=/^&(hover|focus(-(visible|within))?|active|visited|checked|disabled|enabled|empty|target|first-child|last-child|first-of-type|last-of-type|placeholder|placeholder-shown|root)\b/,f=/\$\{[^}]+\}/,p=/^@(media|supports|container|layer)\s*$/,m=/^@(?:-(?:webkit|moz|o|ms)-)?keyframes\b/,h=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=Object.keys(e);return t.includes(`base`)||t.includes(`variants`)},g=e=>{if(typeof e==`string`){let[t,n]=e.split(`@`,2),r=t.split(`.`).filter(Boolean);if(!r.length)return;let i={};if(n)for(let e of n.split(`&`)){if(!e)continue;let t=e.indexOf(`=`);if(t===-1)i[e.trim()]=!0;else{let n=e.slice(0,t).trim(),r=e.slice(t+1).trim();if(!n)continue;r===`true`?i[n]=!0:r===`false`?i[n]=!1:i[n]=r}}return{path:r,variants:i}}if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e,n=t.name;if(typeof n!=`string`)return;let r=n.split(`.`).filter(Boolean);if(!r.length)return;let i={};for(let[e,n]of Object.entries(t))e!==`name`&&(typeof n==`string`||typeof n==`boolean`)&&(i[e]=n);return{path:r,variants:i}}},_=e=>{if(e!==void 0)return typeof e==`boolean`?String(e):e},v=(e,t)=>{let n=[{node:e,isRich:h(e)}],r=e;for(let e of t){if(typeof r!=`object`||!r)return;let t=r[e];if(t===void 0)return;n.push({node:t,isRich:h(t)}),r=t}return n},y=(e,t)=>{let n=v(e,t);return n?n.some(e=>e.isRich):!1},b=(e,t)=>{for(let[n,r]of Object.entries(e))if(n!==`css`&&t[n]!==_(r))return!1;return!0},x=(e,t)=>{let n=!1;for(let[r,i]of Object.entries(e))if(r!==`css`&&(n=!0,t[r]===_(i)))return!0;return!n},S=(e,t,n,r)=>{let i=v(e,t);if(!i)return;let a=i.map(e=>e.isRich?e.node:e.node&&typeof e.node==`object`&&!Array.isArray(e.node)?Object.keys(e.node).every(t=>e.node[t]&&typeof e.node[t]==`object`&&!h(e.node[t]))?{}:{base:e.node}:{}),o=new Set;for(let e of a)if(e.variants)for(let t of Object.keys(e.variants))o.add(t);for(let e of a)if(e.defaultVariants)for(let t of Object.keys(e.defaultVariants))o.add(t);let s={};for(let e of o){if(e in n){s[e]=_(n[e]);continue}for(let t=a.length-1;t>=0;t--){let n=a[t].defaultVariants?.[e];if(n!==void 0){s[e]=_(n);break}}}for(let[e,i]of Object.entries(n)){if(!o.has(e)){console.warn(`Template "${r}" path "${t.join(`.`)}" has no variant axis "${e}"; ignored.`);continue}let n=_(i),s=!1;for(let t of a)if(t.variants?.[e]&&n!==void 0&&n in t.variants[e]){s=!0;break}!s&&n!==void 0&&a.some(t=>t.variants&&e in t.variants)&&console.warn(`Template "${r}" axis "${e}" has no value "${n}" on path "${t.join(`.`)}"; ignored.`)}let c={};for(let e of a)e.base&&Object.assign(c,e.base);for(let e of Object.keys(s)){let t=s[e];if(t!==void 0)for(let n=a.length-1;n>=0;n--){let r=a[n].variants?.[e]?.[t];if(r){Object.assign(c,r);break}}}for(let e of a){if(e.compoundVariants)for(let t of e.compoundVariants)b(t,s)&&t.css&&Object.assign(c,t.css);if(e.anyOfVariants)for(let t of e.anyOfVariants)x(t,s)&&t.css&&Object.assign(c,t.css)}return c},C=async(t,i=``,a,s=!1)=>{if(!t)throw Error(`No styles provided to parseStyles function!`);let c=Object.entries(t),h=a?.strict;k(c,a,h);let _=async([t,n])=>{let r=t.trim().replace(/^\?+/g,``),c=l(r),v=[],b=e=>({value:e,nested:v}),x=(e,t=`;`)=>`${c}:${e}${t}`,T={scope:i,config:a};if(typeof n==`function`)try{return await _([t,n(T)])}catch(e){return u(h,`Function value for "${r}" threw: ${e?.message??e}`),b()}if(n instanceof Promise)return _([t,await n]);if(a?.templates&&a.templatePaths?.[r])try{let[e,t]=a.templatePaths[r].split(`;;`),i=await import(t),o=t.includes(`salty.config`),s=o?i[e].templates:i[e],c=o?s[r]:s.params[r];if(s&&typeof c==`function`){let[e]=await C(await c(n),``);return b(e)}}catch(e){return console.error(`Error loading template "${r}" from path "${a.templatePaths[r]}"`,e),b()}if(a?.templates&&a.templates[r]){if(s)return b();let e=a.templates[r],t=g(n);if(t){let{path:n,variants:i}=t;if(Object.keys(i).length>0||y(e,n)){let t=S(e,n,i,r);if(t){let[e]=await C(t,``);return b(e)}return console.warn(`Template "${r}" with path of "${n.join(`.`)}" was not found in config!`),b()}let a=n.reduce((e,t)=>e?.[t],e);if(a){let[e]=await C(a,``);return b(e)}return console.warn(`Template "${r}" with path of "${n.join(`.`)}" was not found in config!`),b()}return console.warn(`Template "${r}" received an unsupported call-site value.`),b()}if(!(r===`compoundVariants`||r===`anyOfVariants`)&&Array.isArray(n))return n.length===0?b():_([t,n.join(`, `)]);if(typeof n==`object`){if(!n)return b();if(n.isColor||n.isDefineFont)return b(x(n.toString()));if(r===`defaultVariants`)return b();if(r===`variants`){let t=Object.entries(n);for(let[n,r]of t){if(!r)continue;let t=Object.entries(r);for(let[r,o]of t)o&&(await C(o,`${i}.${`${e.sanitizeClassName(n)}-${e.sanitizeClassName(r)}`}`,a)).forEach(e=>v.push(e))}return b()}if(r===`compoundVariants`){for(let t of n){let{css:n,...r}=t;(await C(n,Object.entries(r).reduce((t,[n,r=``])=>`${t}.${`${e.sanitizeClassName(n)}-${e.sanitizeClassName(r)}`}`,i),a)).forEach(e=>v.push(e))}return b()}if(r===`anyOfVariants`){for(let t of n){let{css:n,...r}=t;(await C(n,`${i}:where(${Object.entries(r).map(([t,n=``])=>`.${`${e.sanitizeClassName(t)}-${e.sanitizeClassName(n)}`}`).join(`, `)})`,a)).forEach(e=>v.push(e))}return b()}if(r===`global`)return(await C(n,``,a)).forEach(e=>v.push(e)),b();if(r.startsWith(`@`)){p.test(r)&&u(h,`At-rule "${r}" is missing its condition (e.g. "@media (min-width: 600px)").`);let e=m.test(r)?``:i,t=`${a?.mediaQueries?.[r]||r} { ${await w(n,e,a)} }`;return v.push(t),b()}if(Object.keys(n).length===0)return b();d.test(r)&&u(h,`Selector "${r}" looks like a missing-colon typo (did you mean "&:${r.slice(1)}"?).`);let t=D(i,r);return(await C(n,t,a)).forEach(e=>v.push(e)),b()}if(r.startsWith(`$`))return u(h,`Property key "${r}" looks like a SCSS variable — Salty does not support those.`),b();if(r.includes(`:`))return u(h,`Property key "${r}" contains a colon — did you accidentally paste a whole declaration as a key?`),b();if(n==null)return u(h,`Property "${r}" has a ${n===void 0?`undefined`:`null`} value — skipping.`),b();if(typeof n==`boolean`)return u(h,`Property "${r}" has a boolean value (${n}) — skipping.`),b();if(n===``)return b();if(typeof n==`number`)return Number.isFinite(n)?b(x(o(c,n,a))):(u(h,`Property "${r}" has a non-finite numeric value (${n}) — skipping.`),b());if(typeof n!=`string`)if(n&&typeof n==`object`&&`toString`in n)n=n.toString();else return u(h,`Property "${r}" has an unsupported value type (${typeof n}) — skipping.`),b();return typeof n==`string`&&f.test(n)&&u(h,`Property "${r}" value "${n}" contains an unresolved \`\${...}\` — did you forget to interpolate?`),b(x(n))},{modifiers:v}=a||{},b=[r(),n(v)],x=await Promise.all(c.map(_)),T=await Promise.all(x.map(({value:e})=>e===void 0?Promise.resolve(void 0):b.reduce(async(e,t)=>{let n=await e;if(!n)return n;let r=await t(n);if(!r)return n;let{transformed:i,additionalCss:a}=r,o=``;if(a)for(let e of a)o+=await w(e,``);return`${o}${i}`},Promise.resolve(e)))),E=new Set;for(let{nested:e}of x)for(let t of e)E.add(t);let O=T.filter(e=>e!==void 0).join(`
|
|
2
|
-
`);if(!O.trim())return Array.from(E);let A=i?`${i} {\n\t${O}\n}`:O;return E.has(A)?Array.from(E):[A,...E]},w=async(e,t,n,r=!1)=>(await C(e,t,n,r)).join(`
|
|
3
|
-
`),T=e=>{let t=[],n=0,r=``;for(let i of e)if(i===`(`||i===`[`?n++:(i===`)`||i===`]`)&&(n=Math.max(0,n-1)),i===`,`&&n===0){let e=r.trim();e&&t.push(e),r=``}else r+=i;let i=r.trim();return i&&t.push(i),t},E=(e,t)=>t.includes(`&`)?t.replaceAll(`&`,e):t.startsWith(`:`)?`${e}${t}`:`${e} ${t}`,D=(e,t)=>{if(!e)return t;let n=T(e),r=T(t);if(!r.length)return e;if(n.length<=1&&r.length<=1)return E(n[0]??e,r[0]);let i=[];for(let e of n)for(let t of r)i.push(E(e,t));return i.join(`, `)},O=/\((max|min)-width:\s*([\d.]+)(px|r?em)\)/g,k=(e,t,n)=>{if(!n)return;let r={},i={};for(let[n,a]of e){let e=n.trim().replace(/^\?+/g,``);if(!e.startsWith(`@`)||typeof a!=`object`||!a)continue;let o=[...(t?.mediaQueries?.[e]||e).matchAll(O)];if(o.length!==1)continue;let[,s,c,l]=o[0],d=parseFloat(c);if(s===`max`){let t=r[l];t&&d>t.value&&u(`warn`,`Media query "${e}" (max-width: ${d}${l}) is declared after "${t.key}" (max-width: ${t.value}${l}); wider max-width queries override narrower ones at overlapping widths — order them widest → narrowest.`),(!t||d<t.value)&&(r[l]={value:d,key:e})}else{let t=i[l];t&&d<t.value&&u(`warn`,`Media query "${e}" (min-width: ${d}${l}) is declared after "${t.key}" (min-width: ${t.value}${l}); narrower min-width queries are overridden by wider ones at overlapping widths — order them narrowest → widest.`),(!t||d>t.value)&&(i[l]={value:d,key:e})}}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return w}});
|