@salty-css/astro 0.0.1-alpha.339 → 0.0.1-alpha.340

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.
@@ -1,11 +1,15 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("@salty-css/core/compiler/helpers"),H=require("@salty-css/core/compiler/get-function-range"),J=require("@salty-css/core/compiler/as-class"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),f=require("fs/promises"),x=require("path"),b=D=>{const m=new J.SaltyCompiler(D);return{name:"stylegen",configureServer(t){m.importFile=async r=>{const a=Date.now();return t.ssrLoadModule(`${r}?t=${a}`)}},buildStart:async()=>{await m.generateCss()},load:async t=>{var a,F;if(j.isSaltyFile(t)){const d=await m.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const h=new URLSearchParams(t.split("?")[1]).get("configFile");if(!h)return;const i=x.join(d,"astro",h),$=await f.readFile(i,"utf-8");if(!$)return;try{const c=JSON.parse($),{clientProps:o={},classNames:s="",tagIsComponent:u,tagName:n="div"}=c,w=c.imports||[],y=u?n:`props.element || "${o.element||n}"`;let l="";if(o.element&&u&&(l+=` element="${o.element}"`),o.attr)for(const[S,p]of Object.entries(o.attr))l+=` ${S}="${p}"`;return l=l.trim(),`---
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("@salty-css/core/compiler/helpers"),H=require("@salty-css/core/compiler/get-function-range"),J=require("@salty-css/core/compiler/as-class"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),d=require("fs/promises"),x=require("path"),b=D=>{const g=new J.SaltyCompiler(D);return{name:"stylegen",configureServer(t){g.importFile=async c=>{const l=Date.now();return t.ssrLoadModule(`${c}?t=${l}`)}},buildStart:async()=>{await g.generateCss()},load:async t=>{var l,C;if(j.isSaltyFile(t)){const $=await g.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const h=new URLSearchParams(t.split("?")[1]).get("configFile");if(!h)return;const m=x.join($,"astro",h),y=await d.readFile(m,"utf-8");if(!y)return;try{const u=JSON.parse(y),{clientProps:o={},classNames:s="",tagIsComponent:f,tagName:r="div"}=u,w=u.imports||[],F=f?r:`props.element || "${o.element||r}"`;let p="";if(o.element&&f&&(p+=` element="${o.element}"`),o.attr)for(const[i,n]of Object.entries(o.attr))p+=` ${i}="${n}"`;p=p.trim();const v=o.variantKeys||[];return`---
2
2
  ${w.join(`
3
3
  `)}
4
4
  const { props } = Astro;
5
- const Element = ${y};
5
+ const Element = ${F};
6
+ const variantClasses = [
7
+ ${v.map(i=>{const[n,a]=i.split("=");return`props.${n} !== undefined ? "${n}-" + props.${n} : ${a!==void 0?`"${n}-${a}"`:'""'}`}).join(`,
8
+ `)}
9
+ ]
6
10
  ---
7
- <Element class:list={["${s}", props.class]} ${l} {...props}><slot/></Element>`}catch(c){console.error("Error parsing config file:",c);return}}const R=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],q=[],C=[],N=await f.readFile(t,"utf-8"),k=await m.compileSaltyFile(t,d),I=Object.entries(k.contents);for(const[e,h]of I){const i=await j.resolveExportValue(h,1);if(!i.generator)continue;if(i.isClassName){const p=i.generator._withBuildContext({callerName:e,isProduction:!1,config:{}});q.push(`const ${e} = classNameInstance(${JSON.stringify(p.params)});`),C.push(e);continue}const[$,c]=await H.getFunctionRange(N,e),o=N.slice($,c),s=(F=(a=/styled\(([^,]+),/.exec(o))==null?void 0:a.at(1))==null?void 0:F.trim();if(!s){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const u=i.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),n={componentName:e,tagName:s.replace(/['"`]/g,""),tagIsComponent:!1,classNames:u.classNames,imports:[],clientProps:u.clientProps},w=/^\w+$/.test(s);if(n.tagIsComponent=w,w){const p=I.some(([g])=>g===s),E=N.match(new RegExp(`import[^;]*${s}[^;]*;`));if(p){const g=P.toHash(s),_=`import ${s} from '${t}.astro?configFile=${g}.config';`;n.imports=[_]}else if(E){const g=E.at(0);n.imports=[g]}}const y=x.join(d,"astro");await f.readFile(y,"utf-8").catch(()=>!1)||await f.mkdir(y,{recursive:!0});const v=P.toHash(e),S=x.join(d,"astro",`${v}.config`);await f.writeFile(S,JSON.stringify(n)),R.push(`import ${e} from '${t}.astro?configFile=${v}.config';`),C.push(e)}return`${R.join(`
11
+ <Element class:list={["${s}", ...variantClasses, props.class]} ${p} {...props}><slot/></Element>`}catch(u){console.error("Error parsing config file:",u);return}}const R=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],q=[],N=[],S=await d.readFile(t,"utf-8"),k=await g.compileSaltyFile(t,$),I=Object.entries(k.contents);for(const[e,h]of I){const m=await j.resolveExportValue(h,1);if(!m.generator)continue;if(m.isClassName){const i=m.generator._withBuildContext({callerName:e,isProduction:!1,config:{}});q.push(`const ${e} = classNameInstance(${JSON.stringify(i.params)});`),N.push(e);continue}const[y,u]=await H.getFunctionRange(S,e),o=S.slice(y,u),s=(C=(l=/styled\(([^,]+),/.exec(o))==null?void 0:l.at(1))==null?void 0:C.trim();if(!s){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const f=m.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),r={componentName:e,tagName:s.replace(/['"`]/g,""),tagIsComponent:!1,classNames:f.classNames,imports:[],clientProps:f.clientProps},w=/^\w+$/.test(s);if(r.tagIsComponent=w,w){const i=I.some(([a])=>a===s),n=S.match(new RegExp(`import[^;]*${s}[^;]*;`));if(i){const a=P.toHash(s),_=`import ${s} from '${t}.astro?configFile=${a}.config';`;r.imports=[_]}else if(n){const a=n.at(0);r.imports=[a]}}const F=x.join($,"astro");await d.readFile(F,"utf-8").catch(()=>!1)||await d.mkdir(F,{recursive:!0});const v=P.toHash(e),E=x.join($,"astro",`${v}.config`);await d.writeFile(E,JSON.stringify(r)),R.push(`import ${e} from '${t}.astro?configFile=${v}.config';`),N.push(e)}return`${R.join(`
8
12
  `)}
9
13
  ${q.join(`
10
14
  `)}
11
- export { ${C.join(", ")} };`}},handleHotUpdate:async({file:t,server:r})=>{await O.checkShouldRestart(t)&&r.restart()},watchChange:{handler:async(t,r)=>{j.isSaltyFile(t)&&r.event!=="delete"&&(await O.checkShouldRestart(t)||await m.generateFile(t))}}}};exports.default=b;exports.saltyPlugin=b;
15
+ export { ${N.join(", ")} };`}},handleHotUpdate:async({file:t,server:c})=>{await O.checkShouldRestart(t)&&c.restart()},watchChange:{handler:async(t,c)=>{j.isSaltyFile(t)&&c.event!=="delete"&&(await O.checkShouldRestart(t)||await g.generateFile(t))}}}};exports.default=b;exports.saltyPlugin=b;
@@ -3,104 +3,113 @@ import { getFunctionRange as B } from "@salty-css/core/compiler/get-function-ran
3
3
  import { SaltyCompiler as H } from "@salty-css/core/compiler/as-class";
4
4
  import { checkShouldRestart as O } from "@salty-css/core/server";
5
5
  import { toHash as P } from "@salty-css/core/util";
6
- import { readFile as x, mkdir as L, writeFile as U } from "fs/promises";
6
+ import { readFile as x, mkdir as K, writeFile as L } from "fs/promises";
7
7
  import { join as S } from "path";
8
8
  const T = (b) => {
9
- const m = new H(b);
9
+ const u = new H(b);
10
10
  return {
11
11
  name: "stylegen",
12
12
  configureServer(t) {
13
- m.importFile = async (r) => {
14
- const a = Date.now();
15
- return t.ssrLoadModule(`${r}?t=${a}`);
13
+ u.importFile = async (c) => {
14
+ const l = Date.now();
15
+ return t.ssrLoadModule(`${c}?t=${l}`);
16
16
  };
17
17
  },
18
18
  buildStart: async () => {
19
- await m.generateCss();
19
+ await u.generateCss();
20
20
  },
21
21
  load: async (t) => {
22
- var a, y;
22
+ var l, F;
23
23
  if (D(t)) {
24
- const u = await m.getDestDir();
24
+ const d = await u.getDestDir();
25
25
  if (/.+\?configFile=(\w+).+/.test(t)) {
26
- const d = new URLSearchParams(t.split("?")[1]).get("configFile");
27
- if (!d) return;
28
- const i = S(u, "astro", d), $ = await x(i, "utf-8");
26
+ const $ = new URLSearchParams(t.split("?")[1]).get("configFile");
29
27
  if (!$) return;
28
+ const m = S(d, "astro", $), w = await x(m, "utf-8");
29
+ if (!w) return;
30
30
  try {
31
- const c = JSON.parse($), { clientProps: s = {}, classNames: o = "", tagIsComponent: p, tagName: n = "div" } = c, w = c.imports || [], h = p ? n : `props.element || "${s.element || n}"`;
32
- let l = "";
33
- if (s.element && p && (l += ` element="${s.element}"`), s.attr) for (const [v, f] of Object.entries(s.attr)) l += ` ${v}="${f}"`;
34
- return l = l.trim(), `---
35
- ${w.join(`
31
+ const p = JSON.parse(w), { clientProps: n = {}, classNames: s = "", tagIsComponent: g, tagName: r = "div" } = p, h = p.imports || [], y = g ? r : `props.element || "${n.element || r}"`;
32
+ let f = "";
33
+ if (n.element && g && (f += ` element="${n.element}"`), n.attr) for (const [i, o] of Object.entries(n.attr)) f += ` ${i}="${o}"`;
34
+ f = f.trim();
35
+ const C = n.variantKeys || [];
36
+ return `---
37
+ ${h.join(`
36
38
  `)}
37
39
  const { props } = Astro;
38
- const Element = ${h};
40
+ const Element = ${y};
41
+ const variantClasses = [
42
+ ${C.map((i) => {
43
+ const [o, a] = i.split("=");
44
+ return `props.${o} !== undefined ? "${o}-" + props.${o} : ${a !== void 0 ? `"${o}-${a}"` : '""'}`;
45
+ }).join(`,
46
+ `)}
47
+ ]
39
48
  ---
40
- <Element class:list={["${o}", props.class]} ${l} {...props}><slot/></Element>`;
41
- } catch (c) {
42
- console.error("Error parsing config file:", c);
49
+ <Element class:list={["${s}", ...variantClasses, props.class]} ${f} {...props}><slot/></Element>`;
50
+ } catch (p) {
51
+ console.error("Error parsing config file:", p);
43
52
  return;
44
53
  }
45
54
  }
46
- const R = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], j = [], F = [], C = await x(t, "utf-8"), k = await m.compileSaltyFile(t, u), I = Object.entries(k.contents);
47
- for (const [e, d] of I) {
48
- const i = await A(d, 1);
49
- if (!i.generator) continue;
50
- if (i.isClassName) {
51
- const f = i.generator._withBuildContext({
55
+ const j = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], R = [], v = [], N = await x(t, "utf-8"), k = await u.compileSaltyFile(t, d), I = Object.entries(k.contents);
56
+ for (const [e, $] of I) {
57
+ const m = await A($, 1);
58
+ if (!m.generator) continue;
59
+ if (m.isClassName) {
60
+ const i = m.generator._withBuildContext({
52
61
  callerName: e,
53
62
  isProduction: !1,
54
63
  config: {}
55
64
  });
56
- j.push(`const ${e} = classNameInstance(${JSON.stringify(f.params)});`), F.push(e);
65
+ R.push(`const ${e} = classNameInstance(${JSON.stringify(i.params)});`), v.push(e);
57
66
  continue;
58
67
  }
59
- const [$, c] = await B(C, e), s = C.slice($, c), o = (y = (a = /styled\(([^,]+),/.exec(s)) == null ? void 0 : a.at(1)) == null ? void 0 : y.trim();
60
- if (!o) {
68
+ const [w, p] = await B(N, e), n = N.slice(w, p), s = (F = (l = /styled\(([^,]+),/.exec(n)) == null ? void 0 : l.at(1)) == null ? void 0 : F.trim();
69
+ if (!s) {
61
70
  console.warn(`Could not determine tag name for ${e} in ${t}`);
62
71
  continue;
63
72
  }
64
- const p = i.generator._withBuildContext({
73
+ const g = m.generator._withBuildContext({
65
74
  callerName: e,
66
75
  isProduction: !1,
67
76
  config: {}
68
- }), n = {
77
+ }), r = {
69
78
  componentName: e,
70
- tagName: o.replace(/['"`]/g, ""),
79
+ tagName: s.replace(/['"`]/g, ""),
71
80
  tagIsComponent: !1,
72
- classNames: p.classNames,
81
+ classNames: g.classNames,
73
82
  imports: [],
74
- clientProps: p.clientProps
75
- }, w = /^\w+$/.test(o);
76
- if (n.tagIsComponent = w, w) {
77
- const f = I.some(([g]) => g === o), E = C.match(new RegExp(`import[^;]*${o}[^;]*;`));
78
- if (f) {
79
- const g = P(o), J = `import ${o} from '${t}.astro?configFile=${g}.config';`;
80
- n.imports = [J];
81
- } else if (E) {
82
- const g = E.at(0);
83
- n.imports = [g];
83
+ clientProps: g.clientProps
84
+ }, h = /^\w+$/.test(s);
85
+ if (r.tagIsComponent = h, h) {
86
+ const i = I.some(([a]) => a === s), o = N.match(new RegExp(`import[^;]*${s}[^;]*;`));
87
+ if (i) {
88
+ const a = P(s), J = `import ${s} from '${t}.astro?configFile=${a}.config';`;
89
+ r.imports = [J];
90
+ } else if (o) {
91
+ const a = o.at(0);
92
+ r.imports = [a];
84
93
  }
85
94
  }
86
- const h = S(u, "astro");
87
- await x(h, "utf-8").catch(() => !1) || await L(h, { recursive: !0 });
88
- const N = P(e), v = S(u, "astro", `${N}.config`);
89
- await U(v, JSON.stringify(n)), R.push(`import ${e} from '${t}.astro?configFile=${N}.config';`), F.push(e);
95
+ const y = S(d, "astro");
96
+ await x(y, "utf-8").catch(() => !1) || await K(y, { recursive: !0 });
97
+ const C = P(e), E = S(d, "astro", `${C}.config`);
98
+ await L(E, JSON.stringify(r)), j.push(`import ${e} from '${t}.astro?configFile=${C}.config';`), v.push(e);
90
99
  }
91
- return `${R.join(`
100
+ return `${j.join(`
92
101
  `)}
93
- ${j.join(`
102
+ ${R.join(`
94
103
  `)}
95
- export { ${F.join(", ")} };`;
104
+ export { ${v.join(", ")} };`;
96
105
  }
97
106
  },
98
- handleHotUpdate: async ({ file: t, server: r }) => {
99
- await O(t) && r.restart();
107
+ handleHotUpdate: async ({ file: t, server: c }) => {
108
+ await O(t) && c.restart();
100
109
  },
101
110
  watchChange: {
102
- handler: async (t, r) => {
103
- D(t) && r.event !== "delete" && (await O(t) || await m.generateFile(t));
111
+ handler: async (t, c) => {
112
+ D(t) && c.event !== "delete" && (await O(t) || await u.generateFile(t));
104
113
  }
105
114
  }
106
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/astro",
3
- "version": "0.0.1-alpha.339",
3
+ "version": "0.0.1-alpha.340",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -66,7 +66,7 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@salty-css/core": "^0.0.1-alpha.339",
69
+ "@salty-css/core": "^0.0.1-alpha.340",
70
70
  "astro": "^5.13.2",
71
71
  "vite": "^6.3.5"
72
72
  }