@salty-css/astro 0.0.1-alpha.317 → 0.0.1-alpha.318

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