@salty-css/astro 0.1.0-alpha.1 → 0.1.0-alpha.11
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/astro-vite-plugin.cjs +8 -11
- package/astro-vite-plugin.js +77 -78
- package/class-name.cjs +1 -1
- package/class-name.d.ts +1 -0
- package/class-name.js +14 -10
- package/dynamic-styles.cjs +1 -0
- package/dynamic-styles.d.ts +20 -0
- package/dynamic-styles.js +11 -0
- package/element-props.cjs +1 -0
- package/element-props.d.ts +20 -0
- package/element-props.js +56 -0
- package/package.json +14 -2
- package/runtime.cjs +1 -0
- package/runtime.d.ts +1 -0
- package/runtime.js +1 -0
package/astro-vite-plugin.cjs
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
2
|
-
${
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("@salty-css/core/compiler/helpers"),G=require("@salty-css/core/compiler/get-function-range"),b=require("@salty-css/core/compiler/salty-compiler"),M=require("@salty-css/core/server"),D=require("@salty-css/core/util"),f=require("fs/promises"),x=require("path"),O=P=>{const c=new b.SaltyCompiler(P);return{name:"stylegen",configureServer:function(t){c.importFile=async e=>{const r=Date.now();return t.ssrLoadModule(`${e}?t=${r}`)}},buildStart:async function(){await c.generateCss()},load:async function(t){var r,g;if(S.isSaltyFile(t)){const p=await c.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const y=new URLSearchParams(t.split("?")[1]).get("configFile");if(!y)return;const i=x.join(p,"astro",y);this.addWatchFile(i);const w=await f.readFile(i,"utf-8");if(!w)return;try{const m=JSON.parse(w),{clientProps:F={},classNames:n="",tagIsComponent:N,tagName:a="div"}=m,$=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...m.imports||[]],j=N?a:`__r.element || ${JSON.stringify(F.element||a)}`;return`---
|
|
2
|
+
${$.join(`
|
|
3
3
|
`)}
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
${v.map(i=>{const[n,r]=i.split("=");return`props.${n} !== undefined ? "${n}-" + props.${n} : ${r!==void 0?`"${n}-${r}"`:'""'}`}).join(`,
|
|
8
|
-
`)}
|
|
9
|
-
]
|
|
4
|
+
const __gp = ${JSON.stringify(F)};
|
|
5
|
+
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(n)});
|
|
6
|
+
const Element = ${j};
|
|
10
7
|
---
|
|
11
|
-
<Element class:list={
|
|
8
|
+
<Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(m){console.error("Error parsing config file:",m);return}}const h=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],l=[],o=[],u=await f.readFile(t,"utf-8"),q=await c.compileSaltyFile(t,p),R=Object.entries(q.contents);for(const[s,y]of R){const i=await S.resolveExportValue(y,1);if(!i.generator)continue;if(i.isClassName){const v=i.generator._withBuildContext({callerName:s,isProduction:!1,config:{}});l.push(`const ${s} = classNameInstance(${JSON.stringify(v.params)});`),o.push(s);continue}const[w,m]=await G.getFunctionRange(u,s),F=u.slice(w,m),n=(g=(r=/styled\(([^,]+),/.exec(F))==null?void 0:r.at(1))==null?void 0:g.trim();if(!n){console.warn(`Could not determine tag name for ${s} in ${t}`);continue}const N=i.generator._withBuildContext({callerName:s,isProduction:!1,config:{}}),a={componentName:s,tagName:n.replace(/['"`]/g,""),tagIsComponent:!1,classNames:N.classNames,imports:[],clientProps:N.clientProps},C=/^\w+$/.test(n);if(a.tagIsComponent=C,C){const v=R.some(([d])=>d===n),I=u.match(new RegExp(`import[^;]*${n}[^;]*;`));if(v){const d=D.toHash(n),J=`import ${n} from '${t}.astro?configFile=${d}.config';`;a.imports=[J]}else if(I){const d=I.at(0);a.imports=[d]}}const $=x.join(p,"astro");await f.readFile($,"utf-8").catch(()=>!1)||await f.mkdir($,{recursive:!0});const _=D.toHash(s),E=x.join(p,"astro",`${_}.config`);await f.writeFile(E,JSON.stringify(a)),h.push(`import ${s} from '${t}.astro?configFile=${_}.config';`),o.push(s)}return`${h.join(`
|
|
12
9
|
`)}
|
|
13
|
-
${
|
|
10
|
+
${l.join(`
|
|
14
11
|
`)}
|
|
15
|
-
export { ${
|
|
12
|
+
export { ${o.join(", ")} };`}},handleHotUpdate:async function({file:t,server:e,modules:r}){if(await M.checkShouldRestart(t))return e.restart();if(!S.isSaltyFile(t))return;const h=await c.getDestDir(),l=[];for(const[o,u]of e.moduleGraph.idToModuleMap)o.startsWith(t+".astro?configFile=")&&(e.moduleGraph.invalidateModule(u),l.push(u));for(const o of e.moduleGraph.urlToModuleMap.values())o.file&&o.file.startsWith(h)&&(e.moduleGraph.invalidateModule(o),l.push(o));return e.ws.send({type:"update",updates:[]}),[...r,...l]},watchChange:{handler:async function(t,e){S.isSaltyFile(t)&&e.event!=="delete"&&(await M.checkShouldRestart(t)||await c.generateFile(t))}}}};exports.default=O;exports.saltyPlugin=O;
|
package/astro-vite-plugin.js
CHANGED
|
@@ -1,120 +1,119 @@
|
|
|
1
|
-
import { isSaltyFile as
|
|
2
|
-
import { getFunctionRange as
|
|
1
|
+
import { isSaltyFile as S, resolveExportValue as G } from "@salty-css/core/compiler/helpers";
|
|
2
|
+
import { getFunctionRange as A } from "@salty-css/core/compiler/get-function-range";
|
|
3
3
|
import { SaltyCompiler as H } from "@salty-css/core/compiler/salty-compiler";
|
|
4
|
-
import { checkShouldRestart as
|
|
5
|
-
import { toHash as
|
|
6
|
-
import { readFile as x, mkdir as
|
|
7
|
-
import { join as
|
|
8
|
-
const
|
|
9
|
-
const
|
|
4
|
+
import { checkShouldRestart as E } from "@salty-css/core/server";
|
|
5
|
+
import { toHash as M } from "@salty-css/core/util";
|
|
6
|
+
import { readFile as x, mkdir as W, writeFile as b } from "fs/promises";
|
|
7
|
+
import { join as v } from "path";
|
|
8
|
+
const K = (O) => {
|
|
9
|
+
const c = new H(O);
|
|
10
10
|
return {
|
|
11
11
|
name: "stylegen",
|
|
12
|
-
configureServer(t) {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
return t.ssrLoadModule(`${
|
|
12
|
+
configureServer: function(t) {
|
|
13
|
+
c.importFile = async (o) => {
|
|
14
|
+
const r = Date.now();
|
|
15
|
+
return t.ssrLoadModule(`${o}?t=${r}`);
|
|
16
16
|
};
|
|
17
17
|
},
|
|
18
|
-
buildStart: async ()
|
|
19
|
-
await
|
|
18
|
+
buildStart: async function() {
|
|
19
|
+
await c.generateCss();
|
|
20
20
|
},
|
|
21
|
-
load: async (t)
|
|
22
|
-
var
|
|
23
|
-
if (
|
|
24
|
-
const
|
|
21
|
+
load: async function(t) {
|
|
22
|
+
var r, d;
|
|
23
|
+
if (S(t)) {
|
|
24
|
+
const u = await c.getDestDir();
|
|
25
25
|
if (/.+\?configFile=(\w+).+/.test(t)) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
|
|
26
|
+
const h = new URLSearchParams(t.split("?")[1]).get("configFile");
|
|
27
|
+
if (!h) return;
|
|
28
|
+
const i = v(u, "astro", h);
|
|
29
|
+
this.addWatchFile(i);
|
|
30
|
+
const y = await x(i, "utf-8");
|
|
31
|
+
if (!y) return;
|
|
30
32
|
try {
|
|
31
|
-
const p = JSON.parse(
|
|
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 || [];
|
|
33
|
+
const p = JSON.parse(y), { clientProps: w = {}, classNames: n = "", tagIsComponent: $, tagName: a = "div" } = p, F = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...p.imports || []], D = $ ? a : `__r.element || ${JSON.stringify(w.element || a)}`;
|
|
36
34
|
return `---
|
|
37
|
-
${
|
|
35
|
+
${F.join(`
|
|
38
36
|
`)}
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
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
|
-
]
|
|
37
|
+
const __gp = ${JSON.stringify(w)};
|
|
38
|
+
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(n)});
|
|
39
|
+
const Element = ${D};
|
|
48
40
|
---
|
|
49
|
-
<Element class:list={
|
|
41
|
+
<Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`;
|
|
50
42
|
} catch (p) {
|
|
51
43
|
console.error("Error parsing config file:", p);
|
|
52
44
|
return;
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
|
-
const
|
|
56
|
-
for (const [
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
if (
|
|
60
|
-
const
|
|
61
|
-
callerName:
|
|
47
|
+
const g = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], l = [], e = [], m = await x(t, "utf-8"), j = await c.compileSaltyFile(t, u), I = Object.entries(j.contents);
|
|
48
|
+
for (const [s, h] of I) {
|
|
49
|
+
const i = await G(h, 1);
|
|
50
|
+
if (!i.generator) continue;
|
|
51
|
+
if (i.isClassName) {
|
|
52
|
+
const _ = i.generator._withBuildContext({
|
|
53
|
+
callerName: s,
|
|
62
54
|
isProduction: !1,
|
|
63
55
|
config: {}
|
|
64
56
|
});
|
|
65
|
-
|
|
57
|
+
l.push(`const ${s} = classNameInstance(${JSON.stringify(_.params)});`), e.push(s);
|
|
66
58
|
continue;
|
|
67
59
|
}
|
|
68
|
-
const [
|
|
69
|
-
if (!
|
|
70
|
-
console.warn(`Could not determine tag name for ${
|
|
60
|
+
const [y, p] = await A(m, s), w = m.slice(y, p), n = (d = (r = /styled\(([^,]+),/.exec(w)) == null ? void 0 : r.at(1)) == null ? void 0 : d.trim();
|
|
61
|
+
if (!n) {
|
|
62
|
+
console.warn(`Could not determine tag name for ${s} in ${t}`);
|
|
71
63
|
continue;
|
|
72
64
|
}
|
|
73
|
-
const
|
|
74
|
-
callerName:
|
|
65
|
+
const $ = i.generator._withBuildContext({
|
|
66
|
+
callerName: s,
|
|
75
67
|
isProduction: !1,
|
|
76
68
|
config: {}
|
|
77
|
-
}),
|
|
78
|
-
componentName:
|
|
79
|
-
tagName:
|
|
69
|
+
}), a = {
|
|
70
|
+
componentName: s,
|
|
71
|
+
tagName: n.replace(/['"`]/g, ""),
|
|
80
72
|
tagIsComponent: !1,
|
|
81
|
-
classNames:
|
|
73
|
+
classNames: $.classNames,
|
|
82
74
|
imports: [],
|
|
83
|
-
clientProps:
|
|
84
|
-
},
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
} else if (
|
|
91
|
-
const
|
|
92
|
-
|
|
75
|
+
clientProps: $.clientProps
|
|
76
|
+
}, N = /^\w+$/.test(n);
|
|
77
|
+
if (a.tagIsComponent = N, N) {
|
|
78
|
+
const _ = I.some(([f]) => f === n), R = m.match(new RegExp(`import[^;]*${n}[^;]*;`));
|
|
79
|
+
if (_) {
|
|
80
|
+
const f = M(n), P = `import ${n} from '${t}.astro?configFile=${f}.config';`;
|
|
81
|
+
a.imports = [P];
|
|
82
|
+
} else if (R) {
|
|
83
|
+
const f = R.at(0);
|
|
84
|
+
a.imports = [f];
|
|
93
85
|
}
|
|
94
86
|
}
|
|
95
|
-
const
|
|
96
|
-
await x(
|
|
97
|
-
const C =
|
|
98
|
-
await
|
|
87
|
+
const F = v(u, "astro");
|
|
88
|
+
await x(F, "utf-8").catch(() => !1) || await W(F, { recursive: !0 });
|
|
89
|
+
const C = M(s), J = v(u, "astro", `${C}.config`);
|
|
90
|
+
await b(J, JSON.stringify(a)), g.push(`import ${s} from '${t}.astro?configFile=${C}.config';`), e.push(s);
|
|
99
91
|
}
|
|
100
|
-
return `${
|
|
92
|
+
return `${g.join(`
|
|
101
93
|
`)}
|
|
102
|
-
${
|
|
94
|
+
${l.join(`
|
|
103
95
|
`)}
|
|
104
|
-
export { ${
|
|
96
|
+
export { ${e.join(", ")} };`;
|
|
105
97
|
}
|
|
106
98
|
},
|
|
107
|
-
handleHotUpdate: async ({ file: t, server:
|
|
108
|
-
await
|
|
99
|
+
handleHotUpdate: async function({ file: t, server: o, modules: r }) {
|
|
100
|
+
if (await E(t)) return o.restart();
|
|
101
|
+
if (!S(t)) return;
|
|
102
|
+
const g = await c.getDestDir(), l = [];
|
|
103
|
+
for (const [e, m] of o.moduleGraph.idToModuleMap)
|
|
104
|
+
e.startsWith(t + ".astro?configFile=") && (o.moduleGraph.invalidateModule(m), l.push(m));
|
|
105
|
+
for (const e of o.moduleGraph.urlToModuleMap.values())
|
|
106
|
+
e.file && e.file.startsWith(g) && (o.moduleGraph.invalidateModule(e), l.push(e));
|
|
107
|
+
return o.ws.send({ type: "update", updates: [] }), [...r, ...l];
|
|
109
108
|
},
|
|
110
109
|
watchChange: {
|
|
111
|
-
handler: async (t,
|
|
112
|
-
|
|
110
|
+
handler: async function(t, o) {
|
|
111
|
+
S(t) && o.event !== "delete" && (await E(t) || await c.generateFile(t));
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
};
|
|
116
115
|
};
|
|
117
116
|
export {
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
K as default,
|
|
118
|
+
K as saltyPlugin
|
|
120
119
|
};
|
package/class-name.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@salty-css/core/generators"),C=o=>{const c=new m.ClassNameGenerator(o),t=i=>{const e=new String(i);return Object.assign(e,{get isClassName(){return!0},variant:(r,n)=>{const a=`${r}-${n}`,s=`${e} ${a}`;return t(s)},variants:r=>{const n=Object.entries(r).reduce((s,[l,u])=>(s+=` ${l}-${u}`,s),""),a=`${e}${n}`.trim();return t(a)},generator:c}),e};return t(c.cssClassName)};exports.className=C;
|
package/class-name.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface ClassNameMethods<STYLE_PARAMS extends StyledParams> {
|
|
|
4
4
|
generator: ClassNameGenerator<STYLE_PARAMS>;
|
|
5
5
|
isClassName: boolean;
|
|
6
6
|
variant: (name: string, value: string) => string & ClassNameFunction<STYLE_PARAMS>;
|
|
7
|
+
variants: (variants: Record<string, string>) => string & ClassNameFunction<STYLE_PARAMS>;
|
|
7
8
|
}
|
|
8
9
|
type ClassNameFunction<STYLE_PARAMS extends StyledParams> = string & ClassNameMethods<STYLE_PARAMS>;
|
|
9
10
|
export declare const className: <const STYLE_PARAMS extends StyledParams>(params: STYLE_PARAMS) => ClassNameFunction<STYLE_PARAMS>;
|
package/class-name.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { ClassNameGenerator as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const s = new String(
|
|
1
|
+
import { ClassNameGenerator as u } from "@salty-css/core/generators";
|
|
2
|
+
const $ = (c) => {
|
|
3
|
+
const o = new u(c), e = (i) => {
|
|
4
|
+
const s = new String(i);
|
|
5
5
|
return Object.assign(s, {
|
|
6
6
|
get isClassName() {
|
|
7
7
|
return !0;
|
|
8
8
|
},
|
|
9
|
-
variant: (
|
|
10
|
-
const
|
|
11
|
-
return e(
|
|
9
|
+
variant: (r, n) => {
|
|
10
|
+
const a = `${r}-${n}`, t = `${s} ${a}`;
|
|
11
|
+
return e(t);
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
variants: (r) => {
|
|
14
|
+
const n = Object.entries(r).reduce((t, [l, m]) => (t += ` ${l}-${m}`, t), ""), a = `${s}${n}`.trim();
|
|
15
|
+
return e(a);
|
|
16
|
+
},
|
|
17
|
+
generator: o
|
|
14
18
|
}), s;
|
|
15
19
|
};
|
|
16
|
-
return e(
|
|
20
|
+
return e(o.cssClassName);
|
|
17
21
|
};
|
|
18
22
|
export {
|
|
19
|
-
|
|
23
|
+
$ as className
|
|
20
24
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@salty-css/core/css/dynamic-styles"),n=async(t,a)=>{const s=e.getDynamicStylesClassName(t),y=await e.getDynamicStylesCss(t,a||`.${s}`);return{className:s,css:y}};Object.defineProperty(exports,"getDynamicStylesClassName",{enumerable:!0,get:()=>e.getDynamicStylesClassName});Object.defineProperty(exports,"getDynamicStylesCss",{enumerable:!0,get:()=>e.getDynamicStylesCss});exports.resolveDynamicStyles=n;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseStyles } from '@salty-css/core/types';
|
|
2
|
+
import { getDynamicStylesClassName, getDynamicStylesCss } from '@salty-css/core/css/dynamic-styles';
|
|
3
|
+
export { getDynamicStylesClassName, getDynamicStylesCss };
|
|
4
|
+
/**
|
|
5
|
+
* Resolve dynamic styles for SSR usage inside an `.astro` component.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```astro
|
|
9
|
+
* ---
|
|
10
|
+
* import { resolveDynamicStyles } from '@salty-css/astro/dynamic-styles';
|
|
11
|
+
* const { className, css } = await resolveDynamicStyles({ color: 'red' });
|
|
12
|
+
* ---
|
|
13
|
+
* <style set:html={css}></style>
|
|
14
|
+
* <div class={className}><slot/></div>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveDynamicStyles: (styles: BaseStyles, scope?: string) => Promise<{
|
|
18
|
+
className: string;
|
|
19
|
+
css: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getDynamicStylesClassName as c, getDynamicStylesCss as m } from "@salty-css/core/css/dynamic-styles";
|
|
2
|
+
import { getDynamicStylesClassName as r, getDynamicStylesCss as i } from "@salty-css/core/css/dynamic-styles";
|
|
3
|
+
const y = async (s, t) => {
|
|
4
|
+
const e = c(s), a = await m(s, t || `.${e}`);
|
|
5
|
+
return { className: e, css: a };
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
r as getDynamicStylesClassName,
|
|
9
|
+
i as getDynamicStylesCss,
|
|
10
|
+
y as resolveDynamicStyles
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@salty-css/core/util"),j=require("@salty-css/core/parsers"),A=["passProps"],O=(p={},t={},y="",d)=>{const{class:v="",className:m,element:k,passProps:i=t.passProps,_vks:u,style:r,...b}=p,n={passProps:i};if(t.attr)for(const[s,e]of Object.entries(t.attr))e!==void 0&&(n[s]=e);d&&Object.assign(n,d);const c={...b};if(t.defaultProps)for(const[s,e]of Object.entries(t.defaultProps))c[s]===void 0&&(c[s]=e);Object.assign(n,c);const f=new Set;for(const s of String(y).split(" "))s&&f.add(s);for(const s of String(v||"").split(" "))s&&f.add(s);for(const s of String(m||"").split(" "))s&&f.add(s);const l={};if(r&&typeof r=="object")for(const[s,e]of Object.entries(r)){const o=j.parseVariableTokens(e);l[s]=o?o.transformed:e}const a=new Set(Array.isArray(u)?u:[]);if(t.propValueKeys)for(const s of t.propValueKeys){const e=`css-${s}`,o=c[e];o!==void 0&&(l[`--props-${S.dashCase(s)}`]=o,a.add(e))}if(t.variantKeys)for(const s of t.variantKeys){const[e,o]=s.split("=");c[e]!==void 0?(f.add(`${e}-${c[e]}`),a.add(e)):o!==void 0&&f.add(`${e}-${o}`)}for(const s of a)i!==!0&&(Array.isArray(i)&&i.includes(s)||typeof i=="string"&&i===s||delete n[s]);for(const s of A)delete n[s];return{class:[...f],style:l,rest:n,element:k||t.element,_vks:[...a]}};exports.resolveAstroProps=O;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StyledGeneratorClientProps } from '@salty-css/core/generators';
|
|
2
|
+
export interface ResolvedAstroProps {
|
|
3
|
+
class: string[];
|
|
4
|
+
style: Record<string, any>;
|
|
5
|
+
rest: Record<string, any>;
|
|
6
|
+
element?: string;
|
|
7
|
+
_vks: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* SSR equivalent of the React `elementFactory`. Takes the raw `Astro.props` of a
|
|
11
|
+
* generated `.astro` Salty component plus the build-time generator props and
|
|
12
|
+
* returns cleaned values ready to apply on the underlying `<Element>` tag:
|
|
13
|
+
*
|
|
14
|
+
* - `class` — array for `class:list`
|
|
15
|
+
* - `style` — object for `style={}`
|
|
16
|
+
* - `rest` — object to `{...spread}` onto the element (variants and `css-*` props removed unless `passProps` allows)
|
|
17
|
+
* - `element` — runtime element override
|
|
18
|
+
* - `_vks` — variant keys consumed at this level, forwarded so wrapping styled components can keep stripping them
|
|
19
|
+
*/
|
|
20
|
+
export declare const resolveAstroProps: (astroProps?: Record<string, any>, generatorProps?: StyledGeneratorClientProps, baseClassName?: string, additionalProps?: Record<string, any>) => ResolvedAstroProps;
|
package/element-props.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { dashCase as j } from "@salty-css/core/util";
|
|
2
|
+
import { parseVariableTokens as S } from "@salty-css/core/parsers";
|
|
3
|
+
const $ = ["passProps"], O = (y = {}, t = {}, m = "", d) => {
|
|
4
|
+
const {
|
|
5
|
+
class: u = "",
|
|
6
|
+
className: v,
|
|
7
|
+
element: k,
|
|
8
|
+
passProps: i = t.passProps,
|
|
9
|
+
_vks: p,
|
|
10
|
+
style: l,
|
|
11
|
+
...b
|
|
12
|
+
} = y, n = { passProps: i };
|
|
13
|
+
if (t.attr)
|
|
14
|
+
for (const [s, e] of Object.entries(t.attr))
|
|
15
|
+
e !== void 0 && (n[s] = e);
|
|
16
|
+
d && Object.assign(n, d);
|
|
17
|
+
const c = { ...b };
|
|
18
|
+
if (t.defaultProps)
|
|
19
|
+
for (const [s, e] of Object.entries(t.defaultProps))
|
|
20
|
+
c[s] === void 0 && (c[s] = e);
|
|
21
|
+
Object.assign(n, c);
|
|
22
|
+
const f = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const s of String(m).split(" ")) s && f.add(s);
|
|
24
|
+
for (const s of String(u || "").split(" ")) s && f.add(s);
|
|
25
|
+
for (const s of String(v || "").split(" ")) s && f.add(s);
|
|
26
|
+
const r = {};
|
|
27
|
+
if (l && typeof l == "object")
|
|
28
|
+
for (const [s, e] of Object.entries(l)) {
|
|
29
|
+
const o = S(e);
|
|
30
|
+
r[s] = o ? o.transformed : e;
|
|
31
|
+
}
|
|
32
|
+
const a = new Set(Array.isArray(p) ? p : []);
|
|
33
|
+
if (t.propValueKeys)
|
|
34
|
+
for (const s of t.propValueKeys) {
|
|
35
|
+
const e = `css-${s}`, o = c[e];
|
|
36
|
+
o !== void 0 && (r[`--props-${j(s)}`] = o, a.add(e));
|
|
37
|
+
}
|
|
38
|
+
if (t.variantKeys)
|
|
39
|
+
for (const s of t.variantKeys) {
|
|
40
|
+
const [e, o] = s.split("=");
|
|
41
|
+
c[e] !== void 0 ? (f.add(`${e}-${c[e]}`), a.add(e)) : o !== void 0 && f.add(`${e}-${o}`);
|
|
42
|
+
}
|
|
43
|
+
for (const s of a)
|
|
44
|
+
i !== !0 && (Array.isArray(i) && i.includes(s) || typeof i == "string" && i === s || delete n[s]);
|
|
45
|
+
for (const s of $) delete n[s];
|
|
46
|
+
return {
|
|
47
|
+
class: [...f],
|
|
48
|
+
style: r,
|
|
49
|
+
rest: n,
|
|
50
|
+
element: k || t.element,
|
|
51
|
+
_vks: [...a]
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
O as resolveAstroProps
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/astro",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -48,6 +48,18 @@
|
|
|
48
48
|
"import": "./class-name.js",
|
|
49
49
|
"require": "./class-name.cjs"
|
|
50
50
|
},
|
|
51
|
+
"./element-props": {
|
|
52
|
+
"import": "./element-props.js",
|
|
53
|
+
"require": "./element-props.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./dynamic-styles": {
|
|
56
|
+
"import": "./dynamic-styles.js",
|
|
57
|
+
"require": "./dynamic-styles.cjs"
|
|
58
|
+
},
|
|
59
|
+
"./runtime": {
|
|
60
|
+
"import": "./runtime.js",
|
|
61
|
+
"require": "./runtime.cjs"
|
|
62
|
+
},
|
|
51
63
|
"./keyframes": {
|
|
52
64
|
"import": "./keyframes.js",
|
|
53
65
|
"require": "./keyframes.cjs"
|
|
@@ -66,7 +78,7 @@
|
|
|
66
78
|
}
|
|
67
79
|
},
|
|
68
80
|
"dependencies": {
|
|
69
|
-
"@salty-css/core": "^0.1.0-alpha.
|
|
81
|
+
"@salty-css/core": "^0.1.0-alpha.11",
|
|
70
82
|
"astro": "^5.13.2",
|
|
71
83
|
"vite": "^6.3.5"
|
|
72
84
|
}
|
package/runtime.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@salty-css/core/runtime");Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
package/runtime.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@salty-css/core/runtime';
|
package/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@salty-css/core/runtime";
|