@salty-css/react 0.0.1-alpha.2 → 0.0.1-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Salty Css
2
+
3
+ ## Basic usage example with Button
4
+
5
+ ### Initial requirements
6
+
7
+ 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
+ 2. Create `salty-config.ts` to the root of your project
9
+ 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
+ 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
11
+
12
+ ### Code examples
13
+
14
+ **Salty config**
15
+
16
+ ```tsx
17
+ import { defineConfig } from '@salty-css/core/config';
18
+
19
+ export const config = defineConfig({
20
+ variables: {
21
+ colors: {
22
+ brand: '#111',
23
+ highlight: 'yellow',
24
+ },
25
+ },
26
+ global: {
27
+ html: {
28
+ backgroundColor: '#f8f8f8',
29
+ },
30
+ },
31
+ });
32
+ ```
33
+
34
+ **Your React component file**
35
+
36
+ ```tsx
37
+ import { Wrapper } from '../components/wrapper/wrapper.css';
38
+ import { Button } from '../components/button/button.css';
39
+
40
+ export const IndexPage = () => {
41
+ return (
42
+ <Wrapper>
43
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
44
+ Outlined
45
+ </Button>
46
+ </Wrapper>
47
+ );
48
+ };
49
+ ```
50
+
51
+ **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
+
53
+ ```tsx
54
+ import { styled } from '@salty-css/react/styled';
55
+
56
+ export const Wrapper = styled('div', {
57
+ display: 'block',
58
+ padding: '2vw',
59
+ });
60
+ ```
61
+
62
+ **Button** (`components/button/button.css.ts`)
63
+
64
+ ```tsx
65
+ import { styled } from '@salty-css/react/styled';
66
+
67
+ export const Button = styled('button', {
68
+ display: 'block',
69
+ padding: `0.6em 1.2em`,
70
+ border: '1px solid currentColor',
71
+ background: 'transparent',
72
+ color: 'currentColor/40',
73
+ cursor: 'pointer',
74
+ transition: '200ms',
75
+ textDecoration: 'none',
76
+ '&:hover': {
77
+ background: 'black',
78
+ borderColor: 'black',
79
+ color: 'white',
80
+ },
81
+ '&:disabled': {
82
+ opacity: 0.25,
83
+ pointerEvents: 'none',
84
+ },
85
+ variants: {
86
+ variant: {
87
+ outlined: {
88
+ // same as default styles
89
+ },
90
+ solid: {
91
+ '&:not(:hover)': {
92
+ background: 'black',
93
+ borderColor: 'black',
94
+ color: 'white',
95
+ },
96
+ '&:hover': {
97
+ background: 'transparent',
98
+ borderColor: 'currentColor',
99
+ color: 'currentColor',
100
+ },
101
+ },
102
+ },
103
+ },
104
+ });
105
+ ```
106
+
107
+ More examples coming soon
@@ -0,0 +1,52 @@
1
+ import { createElement as w } from "react";
2
+ function j(t) {
3
+ var n, s, e = "";
4
+ if (typeof t == "string" || typeof t == "number") e += t;
5
+ else if (typeof t == "object") if (Array.isArray(t)) {
6
+ var i = t.length;
7
+ for (n = 0; n < i; n++) t[n] && (s = j(t[n])) && (e && (e += " "), e += s);
8
+ } else for (s in t) t[s] && (e && (e += " "), e += s);
9
+ return e;
10
+ }
11
+ function O() {
12
+ for (var t, n, s = 0, e = "", i = arguments.length; s < i; s++) (t = arguments[s]) && (n = j(t)) && (e && (e += " "), e += n);
13
+ return e;
14
+ }
15
+ const C = ["passVariantProps"], A = (t, n, s, e, i) => {
16
+ const m = ({
17
+ extend: c = t,
18
+ element: g = s,
19
+ className: p = "",
20
+ children: E,
21
+ passVariantProps: S,
22
+ _vks: f = /* @__PURE__ */ new Set(),
23
+ ...d
24
+ }) => {
25
+ const o = { passVariantProps: S };
26
+ d && Object.assign(o, d), i && Object.assign(o, i);
27
+ const u = new Set(p.split(" ")), l = typeof c == "function", y = l && "isStyled" in c, b = l ? c : g || c;
28
+ if (!b) throw new Error("No element provided");
29
+ e && e.forEach((a) => {
30
+ const [r, h] = a.split("=");
31
+ d[r] !== void 0 ? (u.add(`${r}-${d[r]}`), l ? f && f.add(r) : delete o[r]) : h !== void 0 && u.add(`${r}-${h}`);
32
+ }), f && (!l || !y && !S) ? f.forEach((a) => delete o[a]) : y && Object.assign(o, { _vks: f }), y || C.forEach((a) => delete o[a]);
33
+ const $ = O(n, ...u);
34
+ return w(
35
+ b,
36
+ {
37
+ element: l ? g : void 0,
38
+ className: $,
39
+ ...o
40
+ },
41
+ E
42
+ );
43
+ };
44
+ return Object.assign(m, {
45
+ isStyled: !0,
46
+ className: n,
47
+ toString: () => `.${n}`
48
+ }), m;
49
+ };
50
+ export {
51
+ A as e
52
+ };
@@ -0,0 +1 @@
1
+ "use strict";const w=require("react");function j(t){var n,s,e="";if(typeof t=="string"||typeof t=="number")e+=t;else if(typeof t=="object")if(Array.isArray(t)){var o=t.length;for(n=0;n<o;n++)t[n]&&(s=j(t[n]))&&(e&&(e+=" "),e+=s)}else for(s in t)t[s]&&(e&&(e+=" "),e+=s);return e}function O(){for(var t,n,s=0,e="",o=arguments.length;s<o;s++)(t=arguments[s])&&(n=j(t))&&(e&&(e+=" "),e+=n);return e}const C=["passVariantProps"],V=(t,n,s,e,o)=>{const g=({extend:a=t,element:m=s,className:E="",children:$,passVariantProps:S,_vks:c=new Set,...d})=>{const i={passVariantProps:S};d&&Object.assign(i,d),o&&Object.assign(i,o);const u=new Set(E.split(" ")),f=typeof a=="function",y=f&&"isStyled"in a,b=f?a:m||a;if(!b)throw new Error("No element provided");e&&e.forEach(l=>{const[r,h]=l.split("=");d[r]!==void 0?(u.add(`${r}-${d[r]}`),f?c&&c.add(r):delete i[r]):h!==void 0&&u.add(`${r}-${h}`)}),c&&(!f||!y&&!S)?c.forEach(l=>delete i[l]):y&&Object.assign(i,{_vks:c}),y||C.forEach(l=>delete i[l]);const p=O(n,...u);return w.createElement(b,{element:f?m:void 0,className:p,...i},$)};return Object.assign(g,{isStyled:!0,className:n,toString:()=>`.${n}`}),g};exports.elementFactory=V;
@@ -0,0 +1,2 @@
1
+ import { StyledComponentProps, Tag } from '../../core/src/types';
2
+ export declare const elementFactory: (tagName: Tag<any>, _className: string, _element?: string, _variantKeys?: string[], _additionalProps?: Record<PropertyKey, any>) => ({ extend, element, className, children, passVariantProps, _vks, ...props }: StyledComponentProps) => import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>>;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./parse-styles-PkK9Yzyn.cjs"),b=({animationName:u,params:l,appendInitialStyles:m,...t})=>{const s=u||c.toHash(t),n=(r={})=>{const{duration:e="500ms",easing:o="ease-in-out",delay:a="0s",iterationCount:i="1",direction:S="normal",fillMode:d="forwards",playState:p="running"}={...l,...r},$=`${s} ${e} ${o} ${a} ${i} ${S} ${d} ${p}`;if(!m)return $;const g=c.parseStyles(t.from||t["0%"],"");return`${$};${g}`},y=Object.entries(t).reduce((r,[e,o])=>{const a=c.parseStyles(o,""),i=typeof e=="number"?`${e}%`:e;return`${r}${i}{${a}}`},""),f=`@keyframes ${s} {${y}}`;return Object.assign(n,{toString:n,isKeyframes:!0,animationName:s,css:f,keyframes:t}),n};exports.keyframes=b;
@@ -0,0 +1,22 @@
1
+ import { CssStyles, StyleValue } from '../../core/src/types';
2
+ type KeyframeKeys = number | 'from' | 'to' | `${number}%`;
3
+ type Keyframes = {
4
+ [key in KeyframeKeys]: CssStyles;
5
+ };
6
+ interface KeyframesConfig {
7
+ animationName?: string;
8
+ appendInitialStyles?: boolean;
9
+ params?: KeyframesParams;
10
+ }
11
+ interface KeyframesParams {
12
+ duration?: string;
13
+ delay?: string;
14
+ iterationCount?: string | number;
15
+ easing?: StyleValue<'animationTimingFunction'>;
16
+ direction?: StyleValue<'animationDirection'>;
17
+ fillMode?: StyleValue<'animationFillMode'>;
18
+ playState?: StyleValue<'animationPlayState'>;
19
+ }
20
+ type KeyframesProps = Keyframes & KeyframesConfig;
21
+ export declare const keyframes: ({ animationName: _name, params: _params, appendInitialStyles, ...keyframes }: KeyframesProps) => (params?: KeyframesParams) => string;
22
+ export {};
@@ -0,0 +1,30 @@
1
+ import { t as b, p as c } from "./parse-styles-BRv2UFN0.js";
2
+ const C = ({ animationName: m, params: u, appendInitialStyles: f, ...t }) => {
3
+ const s = m || b(t), e = (r = {}) => {
4
+ const {
5
+ duration: n = "500ms",
6
+ easing: o = "ease-in-out",
7
+ delay: a = "0s",
8
+ iterationCount: i = "1",
9
+ direction: d = "normal",
10
+ fillMode: y = "forwards",
11
+ playState: S = "running"
12
+ } = { ...u, ...r }, $ = `${s} ${n} ${o} ${a} ${i} ${d} ${y} ${S}`;
13
+ if (!f) return $;
14
+ const g = c(t.from || t["0%"], "");
15
+ return `${$};${g}`;
16
+ }, l = Object.entries(t).reduce((r, [n, o]) => {
17
+ const a = c(o, ""), i = typeof n == "number" ? `${n}%` : n;
18
+ return `${r}${i}{${a}}`;
19
+ }, ""), p = `@keyframes ${s} {${l}}`;
20
+ return Object.assign(e, {
21
+ toString: e,
22
+ isKeyframes: !0,
23
+ animationName: s,
24
+ css: p,
25
+ keyframes: t
26
+ }), e;
27
+ };
28
+ export {
29
+ C as keyframes
30
+ };
package/dist/media.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class n{constructor(e="@media"){this.base=e,this.next=t=>{const s=new String(t);return Object.assign(s,{get and(){return new n(`${t} and`)},get or(){return new n(`${t},`)}}),s}}custom(e){return this.next(`${this.base} ${e}`)}minWidth(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (min-width: ${t})`;return this.next(s)}maxWidth(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (max-width: ${t})`;return this.next(s)}minHeight(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (min-height: ${t})`;return this.next(s)}maxHeight(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (max-height: ${t})`;return this.next(s)}get portrait(){const e=`${this.base} (orientation: portrait)`;return this.next(e)}get landscape(){const e=`${this.base} (orientation: landscape)`;return this.next(e)}prefersColorScheme(e){const t=`${this.base} (prefers-color-scheme: ${e})`;return this.next(t)}get dark(){return this.prefersColorScheme("dark")}get light(){return this.prefersColorScheme("light")}get print(){const e=`${this.base} print`;return this.next(e)}get screen(){const e=`${this.base} screen`;return this.next(e)}get speech(){const e=`${this.base} speech`;return this.next(e)}get all(){const e=`${this.base} all`;return this.next(e)}get not(){const e=`${this.base} not`;return this.next(e)}get reducedMotion(){const e=`${this.base} (prefers-reduced-motion: reduce)`;return this.next(e)}}const r=new n;exports.MediaQueryFactory=n;exports.media=r;
@@ -0,0 +1,71 @@
1
+ import { OrNumber, OrString } from '../../core/src/types/util-types';
2
+ export declare class MediaQueryFactory {
3
+ private base;
4
+ constructor(base?: string);
5
+ private next;
6
+ custom(value: string): string & {
7
+ and: MediaQueryFactory;
8
+ or: MediaQueryFactory;
9
+ };
10
+ minWidth(width: OrString | OrNumber): string & {
11
+ and: MediaQueryFactory;
12
+ or: MediaQueryFactory;
13
+ };
14
+ maxWidth(width: OrString | OrNumber): string & {
15
+ and: MediaQueryFactory;
16
+ or: MediaQueryFactory;
17
+ };
18
+ minHeight(height: OrString | OrNumber): string & {
19
+ and: MediaQueryFactory;
20
+ or: MediaQueryFactory;
21
+ };
22
+ maxHeight(height: OrString | OrNumber): string & {
23
+ and: MediaQueryFactory;
24
+ or: MediaQueryFactory;
25
+ };
26
+ get portrait(): string & {
27
+ and: MediaQueryFactory;
28
+ or: MediaQueryFactory;
29
+ };
30
+ get landscape(): string & {
31
+ and: MediaQueryFactory;
32
+ or: MediaQueryFactory;
33
+ };
34
+ prefersColorScheme(scheme: 'dark' | 'light' | OrString): string & {
35
+ and: MediaQueryFactory;
36
+ or: MediaQueryFactory;
37
+ };
38
+ get dark(): string & {
39
+ and: MediaQueryFactory;
40
+ or: MediaQueryFactory;
41
+ };
42
+ get light(): string & {
43
+ and: MediaQueryFactory;
44
+ or: MediaQueryFactory;
45
+ };
46
+ get print(): string & {
47
+ and: MediaQueryFactory;
48
+ or: MediaQueryFactory;
49
+ };
50
+ get screen(): string & {
51
+ and: MediaQueryFactory;
52
+ or: MediaQueryFactory;
53
+ };
54
+ get speech(): string & {
55
+ and: MediaQueryFactory;
56
+ or: MediaQueryFactory;
57
+ };
58
+ get all(): string & {
59
+ and: MediaQueryFactory;
60
+ or: MediaQueryFactory;
61
+ };
62
+ get not(): string & {
63
+ and: MediaQueryFactory;
64
+ or: MediaQueryFactory;
65
+ };
66
+ get reducedMotion(): string & {
67
+ and: MediaQueryFactory;
68
+ or: MediaQueryFactory;
69
+ };
70
+ }
71
+ export declare const media: MediaQueryFactory;
package/dist/media.js ADDED
@@ -0,0 +1,81 @@
1
+ class n {
2
+ constructor(t = "@media") {
3
+ this.base = t, this.next = (e) => {
4
+ const s = new String(e);
5
+ return Object.assign(s, {
6
+ get and() {
7
+ return new n(`${e} and`);
8
+ },
9
+ get or() {
10
+ return new n(`${e},`);
11
+ }
12
+ }), s;
13
+ };
14
+ }
15
+ custom(t) {
16
+ return this.next(`${this.base} ${t}`);
17
+ }
18
+ minWidth(t) {
19
+ const e = typeof t == "number" ? `${t}px` : t, s = `${this.base} (min-width: ${e})`;
20
+ return this.next(s);
21
+ }
22
+ maxWidth(t) {
23
+ const e = typeof t == "number" ? `${t}px` : t, s = `${this.base} (max-width: ${e})`;
24
+ return this.next(s);
25
+ }
26
+ minHeight(t) {
27
+ const e = typeof t == "number" ? `${t}px` : t, s = `${this.base} (min-height: ${e})`;
28
+ return this.next(s);
29
+ }
30
+ maxHeight(t) {
31
+ const e = typeof t == "number" ? `${t}px` : t, s = `${this.base} (max-height: ${e})`;
32
+ return this.next(s);
33
+ }
34
+ get portrait() {
35
+ const t = `${this.base} (orientation: portrait)`;
36
+ return this.next(t);
37
+ }
38
+ get landscape() {
39
+ const t = `${this.base} (orientation: landscape)`;
40
+ return this.next(t);
41
+ }
42
+ prefersColorScheme(t) {
43
+ const e = `${this.base} (prefers-color-scheme: ${t})`;
44
+ return this.next(e);
45
+ }
46
+ get dark() {
47
+ return this.prefersColorScheme("dark");
48
+ }
49
+ get light() {
50
+ return this.prefersColorScheme("light");
51
+ }
52
+ get print() {
53
+ const t = `${this.base} print`;
54
+ return this.next(t);
55
+ }
56
+ get screen() {
57
+ const t = `${this.base} screen`;
58
+ return this.next(t);
59
+ }
60
+ get speech() {
61
+ const t = `${this.base} speech`;
62
+ return this.next(t);
63
+ }
64
+ get all() {
65
+ const t = `${this.base} all`;
66
+ return this.next(t);
67
+ }
68
+ get not() {
69
+ const t = `${this.base} not`;
70
+ return this.next(t);
71
+ }
72
+ get reducedMotion() {
73
+ const t = `${this.base} (prefers-reduced-motion: reduce)`;
74
+ return this.next(t);
75
+ }
76
+ }
77
+ const r = new n();
78
+ export {
79
+ n as MediaQueryFactory,
80
+ r as media
81
+ };
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@salty-css/react",
3
+ "version": "0.0.1-alpha.3",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "typings": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "homepage": "https://github.com/margarita-form/salty-css",
14
+ "bugs": {
15
+ "url": "https://github.com/margarita-form/salty-css/issues"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!**/*.tsbuildinfo"
20
+ ],
21
+ "nx": {
22
+ "name": "react"
23
+ },
24
+ "exports": {
25
+ "./styled": {
26
+ "import": "./styled.js",
27
+ "require": "./styled.cjs"
28
+ },
29
+ "./styled-client": {
30
+ "import": "./styled-client.js",
31
+ "require": "./styled-client.cjs"
32
+ },
33
+ "./keyframes": {
34
+ "import": "./keyframes.js",
35
+ "require": "./keyframes.cjs"
36
+ },
37
+ "./media": {
38
+ "import": "./media.js",
39
+ "require": "./media.cjs"
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,87 @@
1
+ const j = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), P = (t, e) => {
2
+ let r = "", n;
3
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) r = j(n % 52) + r;
4
+ return r = j(n % 52) + r, r.length < e ? r = r.padStart(e, "a") : r.length > e && (r = r.slice(-e)), r;
5
+ }, T = (t, e) => {
6
+ let r = e.length;
7
+ for (; r; ) t = t * 33 ^ e.charCodeAt(--r);
8
+ return t;
9
+ }, M = (t, e = 3) => {
10
+ const r = T(5381, JSON.stringify(t)) >>> 0;
11
+ return P(r, e);
12
+ };
13
+ function O(t) {
14
+ return t ? typeof t != "string" ? String(t) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, r) => (r > 0 ? "-" : "") + e.toLowerCase()) : "";
15
+ }
16
+ const W = (t, e) => {
17
+ if (typeof t != "string") return { result: t };
18
+ if (!e) return { result: t };
19
+ const r = [];
20
+ return Object.values(e).forEach((n) => {
21
+ const { pattern: c, transform: h } = n;
22
+ t = t.replace(c, (d) => {
23
+ const { value: i, css: l } = h(d);
24
+ return l && r.push(l), i;
25
+ });
26
+ }), { result: t, additionalCss: r };
27
+ }, w = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, $ = (t, e, r, n) => {
28
+ const c = [], h = Object.entries(t).reduce((i, [l, s]) => {
29
+ const o = l.trim();
30
+ if (typeof s == "function" && (s = s()), typeof s == "object") {
31
+ if (!s) return i;
32
+ if (o === "variants")
33
+ return Object.entries(s).forEach(([f, p]) => {
34
+ p && Object.entries(p).forEach(([m, b]) => {
35
+ if (!b) return;
36
+ const y = `${e}.${f}-${m}`, A = $(b, y, r);
37
+ c.push(A);
38
+ });
39
+ }), i;
40
+ if (o === "defaultVariants")
41
+ return i;
42
+ if (o === "compoundVariants")
43
+ return s.forEach((f) => {
44
+ const { css: p, ...m } = f, b = Object.entries(m).reduce((A, [k, N]) => `${A}.${k}-${N}`, e), y = $(p, b, r);
45
+ c.push(y);
46
+ }), i;
47
+ if (o.startsWith("@")) {
48
+ const f = $(s, e, r), p = `${o} {
49
+ ${f.replace(`
50
+ `, `
51
+ `)}
52
+ }`;
53
+ return c.push(p), i;
54
+ }
55
+ const u = l.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, a = $(s, u, r);
56
+ return c.push(a), i;
57
+ }
58
+ if (n != null && n.templates && n.templates[o]) {
59
+ const a = s.split(".").reduce((p, m) => p[m], n.templates[o]), f = $(a, "");
60
+ return `${i}${f}`;
61
+ }
62
+ const E = o.startsWith("-") ? o : O(o), S = (u, a = ";") => i = `${i}${u}${a}`, g = (u) => S(`${E}:${u}`);
63
+ if (typeof s == "number") return g(s);
64
+ if (typeof s != "string")
65
+ if ("toString" in s) s = s.toString();
66
+ else return i;
67
+ const { modifiers: V } = n || {}, Z = function* () {
68
+ yield w(s), yield W(s, V);
69
+ }();
70
+ for (const { result: u, additionalCss: a = [] } of Z)
71
+ s = u, a.forEach((f) => {
72
+ const p = $(f, "");
73
+ S(p, "");
74
+ });
75
+ return g(s);
76
+ }, "");
77
+ if (!h) return c.join(`
78
+ `);
79
+ if (!e) return h;
80
+ let d = "";
81
+ return r !== void 0 ? d = `@layer l${r} { ${e} { ${h} } }` : d = `${e} { ${h} }`, [d, ...c].join(`
82
+ `);
83
+ };
84
+ export {
85
+ $ as p,
86
+ M as t
87
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";const j=t=>String.fromCharCode(t+(t>25?39:97)),N=(t,e)=>{let r="",n;for(n=Math.abs(t);n>52;n=n/52|0)r=j(n%52)+r;return r=j(n%52)+r,r.length<e?r=r.padStart(e,"a"):r.length>e&&(r=r.slice(-e)),r},P=(t,e)=>{let r=e.length;for(;r;)t=t*33^e.charCodeAt(--r);return t},T=(t,e=3)=>{const r=P(5381,JSON.stringify(t))>>>0;return N(r,e)};function O(t){return t?typeof t!="string"?String(t):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,r)=>(r>0?"-":"")+e.toLowerCase()):""}const W=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const r=[];return Object.values(e).forEach(n=>{const{pattern:c,transform:$}=n;t=t.replace(c,d=>{const{value:i,css:l}=$(d);return l&&r.push(l),i})}),{result:t,additionalCss:r}},w=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${O(n[1].replaceAll(".","-"))})`)}:{result:t},a=(t,e,r,n)=>{const c=[],$=Object.entries(t).reduce((i,[l,s])=>{const o=l.trim();if(typeof s=="function"&&(s=s()),typeof s=="object"){if(!s)return i;if(o==="variants")return Object.entries(s).forEach(([f,p])=>{p&&Object.entries(p).forEach(([m,b])=>{if(!b)return;const y=`${e}.${f}-${m}`,S=a(b,y,r);c.push(S)})}),i;if(o==="defaultVariants")return i;if(o==="compoundVariants")return s.forEach(f=>{const{css:p,...m}=f,b=Object.entries(m).reduce((S,[k,H])=>`${S}.${k}-${H}`,e),y=a(p,b,r);c.push(y)}),i;if(o.startsWith("@")){const f=a(s,e,r),p=`${o} {
2
+ ${f.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return c.push(p),i}const u=l.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,h=a(s,u,r);return c.push(h),i}if(n!=null&&n.templates&&n.templates[o]){const h=s.split(".").reduce((p,m)=>p[m],n.templates[o]),f=a(h,"");return`${i}${f}`}const E=o.startsWith("-")?o:O(o),A=(u,h=";")=>i=`${i}${u}${h}`,g=u=>A(`${E}:${u}`);if(typeof s=="number")return g(s);if(typeof s!="string")if("toString"in s)s=s.toString();else return i;const{modifiers:V}=n||{},Z=function*(){yield w(s),yield W(s,V)}();for(const{result:u,additionalCss:h=[]}of Z)s=u,h.forEach(f=>{const p=a(f,"");A(p,"")});return g(s)},"");if(!$)return c.join(`
6
+ `);if(!e)return $;let d="";return r!==void 0?d=`@layer l${r} { ${e} { ${$} } }`:d=`${e} { ${$} }`,[d,...c].join(`
7
+ `)};exports.parseStyles=a;exports.toHash=T;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./element-factory-DvBlAL2I.cjs"),a=(e,t,n,o,r)=>l.elementFactory(e,t,o,r,{"data-component-name":n});exports.styledClient=a;
@@ -0,0 +1,2 @@
1
+ import { Tag } from '../../core/src/types';
2
+ export declare const styledClient: (tagName: Tag<any>, className: string, callerName?: string, element?: string, variantKeys?: string[]) => ({ extend, element, className, children, passVariantProps, _vks, ...props }: import('../../core/src/types').StyledComponentProps) => import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>>;
@@ -0,0 +1,7 @@
1
+ import { e as a } from "./element-factory-CHdv47Y_.js";
2
+ const c = (e, t, n, o, r) => a(e, t, o, r, {
3
+ "data-component-name": n
4
+ });
5
+ export {
6
+ c as styledClient
7
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./parse-styles-PkK9Yzyn.cjs"),o=require("./element-factory-DvBlAL2I.cjs"),c=r=>Object.keys(r);class l{constructor(t,s,e){this.tagName=t,this.styles=s,this.options=e}get hash(){return a.toHash(this.styles)}get priority(){var t;return typeof this.tagName=="function"?(((t=this.tagName.generator)==null?void 0:t.priority)||0)+1:0}get classNames(){const t=[this.hash],{className:s}=this.options;return s&&t.push(s),t.join(" ")}get cssClassName(){return this.hash}get cssDisplayNameVar(){return`--${this.hash}-display-name: ${this._callerName};`}get templateKeys(){var t;return(t=this._context)!=null&&t.config.templates?c(this._context.config.templates):[]}get css(){var t;return a.parseStyles(this.styles,`.${this.cssClassName}`,this.priority,(t=this._context)==null?void 0:t.config)}get props(){const{element:t}=this.options,s=this.styles.variants?Object.keys(this.styles.variants).map(e=>{var i;const n=(i=this.styles.defaultVariants)==null?void 0:i[e];return n!==void 0?`${e}=${String(n)}`:e}):void 0;return{element:t,variantKeys:s}}_withBuildContext(t){this._context=t;const{name:s,config:e}=t;return this._callerName=s,this}}const h=(r,t,s={})=>{const e=new l(r,t,s),n=o.elementFactory(r,e.cssClassName,e.props.element,e.props.variantKeys,{"data-unoptimized-client-component":!0});return Object.assign(n,{generator:e}),n};exports.styled=h;
@@ -0,0 +1,3 @@
1
+ import { HTMLAttributes, ReactDOM, ReactNode } from 'react';
2
+ import { Tag, StyledComponentProps, GeneratorOptions, CreateElementProps, VariantProps, ParentComponentProps, StyledParams } from '../../core/src/types';
3
+ export declare const styled: <const PROPS extends StyledComponentProps, const TAG extends Tag<Required<PROPS>>, const PARAMS extends StyledParams>(tagName: TAG, styles: PARAMS, options?: GeneratorOptions) => (<T extends object>(props: (T & CreateElementProps & ParentComponentProps<TAG>) | VariantProps<STYLES> | (TAG extends keyof ReactDOM ? ReactDOM[TAG] extends (...props: infer R) => any ? R[0] : TAG extends string ? HTMLAttributes<HTMLElement> : never : TAG extends string ? HTMLAttributes<HTMLElement> : never)) => ReactNode) & string;
package/dist/styled.js ADDED
@@ -0,0 +1,60 @@
1
+ import { t as a, p as o } from "./parse-styles-BRv2UFN0.js";
2
+ import { e as c } from "./element-factory-CHdv47Y_.js";
3
+ const h = (r) => Object.keys(r);
4
+ class l {
5
+ constructor(t, s, e) {
6
+ this.tagName = t, this.styles = s, this.options = e;
7
+ }
8
+ get hash() {
9
+ return a(this.styles);
10
+ }
11
+ get priority() {
12
+ var t;
13
+ return typeof this.tagName == "function" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
14
+ }
15
+ get classNames() {
16
+ const t = [this.hash], { className: s } = this.options;
17
+ return s && t.push(s), t.join(" ");
18
+ }
19
+ get cssClassName() {
20
+ return this.hash;
21
+ }
22
+ get cssDisplayNameVar() {
23
+ return `--${this.hash}-display-name: ${this._callerName};`;
24
+ }
25
+ get templateKeys() {
26
+ var t;
27
+ return (t = this._context) != null && t.config.templates ? h(this._context.config.templates) : [];
28
+ }
29
+ get css() {
30
+ var t;
31
+ return o(this.styles, `.${this.cssClassName}`, this.priority, (t = this._context) == null ? void 0 : t.config);
32
+ }
33
+ get props() {
34
+ const { element: t } = this.options, s = this.styles.variants ? Object.keys(this.styles.variants).map((e) => {
35
+ var i;
36
+ const n = (i = this.styles.defaultVariants) == null ? void 0 : i[e];
37
+ return n !== void 0 ? `${e}=${String(n)}` : e;
38
+ }) : void 0;
39
+ return {
40
+ element: t,
41
+ variantKeys: s
42
+ };
43
+ }
44
+ _withBuildContext(t) {
45
+ this._context = t;
46
+ const { name: s, config: e } = t;
47
+ return this._callerName = s, this;
48
+ }
49
+ }
50
+ const u = (r, t, s = {}) => {
51
+ const e = new l(r, t, s), n = c(r, e.cssClassName, e.props.element, e.props.variantKeys, {
52
+ "data-unoptimized-client-component": !0
53
+ });
54
+ return Object.assign(n, {
55
+ generator: e
56
+ }), n;
57
+ };
58
+ export {
59
+ u as styled
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/react",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",