@salty-css/react 0.0.1 → 0.1.0-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/react",
3
- "version": "0.0.1",
3
+ "version": "0.1.0-alpha.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -71,10 +71,14 @@
71
71
  "./runtime": {
72
72
  "import": "./runtime.js",
73
73
  "require": "./runtime.cjs"
74
+ },
75
+ "./transform-salty-file": {
76
+ "import": "./transform-salty-file.js",
77
+ "require": "./transform-salty-file.cjs"
74
78
  }
75
79
  },
76
80
  "dependencies": {
77
- "@salty-css/core": "^0.0.1",
81
+ "@salty-css/core": "^0.1.0-alpha.0",
78
82
  "clsx": ">=2.x",
79
83
  "react": ">=19.x || >=18.3.x"
80
84
  }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("fs"),w=require("path"),g=require("@salty-css/core/compiler/helpers"),q=require("@salty-css/core/compiler/get-function-range"),m=require("@salty-css/core/util"),C=async(a,s)=>{var d,y;try{if(!g.isSaltyFile(s))return;const p=await a.getDestDir(),F=v.readFileSync(s,"utf8"),f=await a.getConfig(),{contents:h}=await a.compileSaltyFile(s,p);let e=F;for(const[t,o]of Object.entries(h)){const n=await g.resolveExportValue(o,1);if(n.isKeyframes||!n.generator)continue;const r=n.generator._withBuildContext({callerName:t,isProduction:a.isProduction,config:f}),[S,$]=await q.getFunctionRange(e,t),c=e.slice(S,$);if(n.isClassName){const i=e,l=` ${t} = className("${r.classNames}")`;e=e.replace(c,l),i===e&&console.error("Minimize file failed to change content",{name:t})}if(c.includes("styled")){const i=(y=(d=/styled\(([^,]+),/.exec(c))==null?void 0:d.at(1))==null?void 0:y.trim(),l=e,N=` ${t} = styled(${i}, "${r.classNames}", ${JSON.stringify(r.clientProps)})`;e=e.replace(c,N),l===e&&console.error("Minimize file failed to change content",{name:t,tagName:i})}}if(f.importStrategy==="component"){const t=m.toHash(s,6),o=w.parse(s);e=`import '../../saltygen/css/${`f_${m.dashCase(o.name)}-${t}.css`}';
2
+ ${e}`}return e=e.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),e=e.replace("{ styled }","{ styledClient as styled }"),e=e.replace("@salty-css/react/styled","@salty-css/react/styled-client"),e}catch(u){console.error("Error in transformSaltyFile:",u);return}};exports.transformSaltyFile=C;
@@ -0,0 +1,8 @@
1
+ import { SaltyCompiler } from '@salty-css/core/compiler/salty-compiler';
2
+ /**
3
+ * React-specific minimize transform for salty files. Rewrites `styled()` and
4
+ * `className()` calls to their pre-resolved client-side variants and swaps the
5
+ * relevant `@salty-css/react/*` imports for their `*-client` counterparts so
6
+ * the runtime ships only the minimal client logic.
7
+ */
8
+ export declare const transformSaltyFile: (compiler: SaltyCompiler, file: string) => Promise<string | undefined>;
@@ -0,0 +1,42 @@
1
+ import { readFileSync as N } from "fs";
2
+ import { parse as v } from "path";
3
+ import { isSaltyFile as S, resolveExportValue as w } from "@salty-css/core/compiler/helpers";
4
+ import { getFunctionRange as C } from "@salty-css/core/compiler/get-function-range";
5
+ import { toHash as x, dashCase as z } from "@salty-css/core/util";
6
+ const M = async (n, s) => {
7
+ var m, d;
8
+ try {
9
+ if (!S(s)) return;
10
+ const p = await n.getDestDir(), g = N(s, "utf8"), f = await n.getConfig(), { contents: u } = await n.compileSaltyFile(s, p);
11
+ let e = g;
12
+ for (const [t, c] of Object.entries(u)) {
13
+ const a = await w(c, 1);
14
+ if (a.isKeyframes || !a.generator) continue;
15
+ const o = a.generator._withBuildContext({
16
+ callerName: t,
17
+ isProduction: n.isProduction,
18
+ config: f
19
+ }), [F, $] = await C(e, t), r = e.slice(F, $);
20
+ if (a.isClassName) {
21
+ const i = e, l = ` ${t} = className("${o.classNames}")`;
22
+ e = e.replace(r, l), i === e && console.error("Minimize file failed to change content", { name: t });
23
+ }
24
+ if (r.includes("styled")) {
25
+ const i = (d = (m = /styled\(([^,]+),/.exec(r)) == null ? void 0 : m.at(1)) == null ? void 0 : d.trim(), l = e, h = ` ${t} = styled(${i}, "${o.classNames}", ${JSON.stringify(o.clientProps)})`;
26
+ e = e.replace(r, h), l === e && console.error("Minimize file failed to change content", { name: t, tagName: i });
27
+ }
28
+ }
29
+ if (f.importStrategy === "component") {
30
+ const t = x(s, 6), c = v(s);
31
+ e = `import '../../saltygen/css/${`f_${z(c.name)}-${t}.css`}';
32
+ ${e}`;
33
+ }
34
+ return e = e.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), e = e.replace("{ styled }", "{ styledClient as styled }"), e = e.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), e;
35
+ } catch (y) {
36
+ console.error("Error in transformSaltyFile:", y);
37
+ return;
38
+ }
39
+ };
40
+ export {
41
+ M as transformSaltyFile
42
+ };