styled-components-jsx 1.0.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/LICENSE +21 -0
- package/README.md +229 -0
- package/dist/helpers/minifyLess.d.ts +8 -0
- package/dist/helpers/minifyLess.d.ts.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/styled-components-jsx.cjs.development.js +83 -0
- package/dist/styled-components-jsx.cjs.development.js.map +1 -0
- package/dist/styled-components-jsx.cjs.production.min.js +2 -0
- package/dist/styled-components-jsx.cjs.production.min.js.map +1 -0
- package/dist/styled-components-jsx.esm.js +77 -0
- package/dist/styled-components-jsx.esm.js.map +1 -0
- package/package.json +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cr0WD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# 🎨 styled-components-jsx
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/styled-components-jsx)
|
|
4
|
+
[](https://www.npmjs.com/package/styled-components-jsx)
|
|
5
|
+
[](https://www.npmjs.com/package/styled-components-jsx)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Write styles like [`styled-components`](https://www.npmjs.com/package/styled-components), powered by [`styled-jsx`](https://www.npmjs.com/package/styled-jsx) under the hood.
|
|
9
|
+
|
|
10
|
+
If you love the simplicity and performance of `styled-jsx` but prefer the ergonomic syntax of `styled-components`, this library gives you the best of both worlds.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 🚀 Installation
|
|
15
|
+
> ⚠️ Requires [`styled-jsx`](https://www.npmjs.com/package/styled-jsx) to be installed and configured in your app.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
With **Yarn**:
|
|
19
|
+
```bash
|
|
20
|
+
yarn add styled-components-jsx
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
With **npm**:
|
|
24
|
+
```bash
|
|
25
|
+
npm install styled-components-jsx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ✨ Basic Usage
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import styled from 'styled-components-jsx'
|
|
35
|
+
|
|
36
|
+
const Button = styled.button`
|
|
37
|
+
background: dodgerblue;
|
|
38
|
+
color: white;
|
|
39
|
+
border: none;
|
|
40
|
+
padding: 12px 20px;
|
|
41
|
+
border-radius: 8px;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
|
|
44
|
+
&:hover {
|
|
45
|
+
background: deepskyblue;
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
const Title = styled.h1`
|
|
50
|
+
font-size: 2rem;
|
|
51
|
+
color: hotpink;
|
|
52
|
+
`
|
|
53
|
+
|
|
54
|
+
export default function App() {
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
<Title>Hello</Title>
|
|
58
|
+
<Button>Click me</Button>
|
|
59
|
+
</>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 🧠 How It Works
|
|
67
|
+
|
|
68
|
+
This library wraps your styles using `styled-jsx`, giving you:
|
|
69
|
+
|
|
70
|
+
- Full CSS scoping via `styled-jsx`
|
|
71
|
+
- `styled-components`-like API
|
|
72
|
+
- Optional interpolations like `${props => props.color}`
|
|
73
|
+
- Support for both DOM elements and custom React components
|
|
74
|
+
- Automatic prop filtering (`$`-prefixed props are stripped from DOM)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🛠 Configuration
|
|
80
|
+
|
|
81
|
+
For full setup (e.g., Babel, SSR, Next.js), refer to the [`styled-jsx` documentation](https://github.com/vercel/styled-jsx).
|
|
82
|
+
|
|
83
|
+
This library builds on top of `styled-jsx` and inherits all of its capabilities.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🎨 About the `.🎨` class Prefix
|
|
88
|
+
|
|
89
|
+
`styled-jsx` does not generate any CSS if there are no selectors in the final output.
|
|
90
|
+
In other words, if your component's styles contain **only raw properties** (without a selector), the CSS will silently be ignored.
|
|
91
|
+
|
|
92
|
+
To work around this, we **always prefix styles with a dummy class**, and we chose `🎨` as a fun and recognizable default.
|
|
93
|
+
|
|
94
|
+
For example, this:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
const Container = styled.div`
|
|
98
|
+
max-width: 960px;
|
|
99
|
+
margin: 0 auto;
|
|
100
|
+
`
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Will render internally like this:
|
|
104
|
+
|
|
105
|
+
```html
|
|
106
|
+
<style id="__jsx-3515400890">
|
|
107
|
+
.🎨.jsx-3515400890 {
|
|
108
|
+
max-width: 960px;
|
|
109
|
+
margin: 0 auto;
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Why `.🎨`?
|
|
115
|
+
|
|
116
|
+
- It ensures your styles are always emitted correctly
|
|
117
|
+
- It’s unique enough to avoid collisions
|
|
118
|
+
- And hey, it looks kinda nice in DevTools too 😎
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 🧩 Interpolations
|
|
123
|
+
|
|
124
|
+
Inject values with functions that receive props:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
const Alert = styled.div`
|
|
128
|
+
color: ${props => (props.$error ? 'red' : 'green')};
|
|
129
|
+
`
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Props prefixed with `$` are automatically excluded from the rendered DOM.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 🧪 Custom Components
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
const Card = ({ className }: { className?: string }) => (
|
|
140
|
+
<div className={className}>Styled Card</div>
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
const StyledCard = styled(Card)`
|
|
144
|
+
padding: 24px;
|
|
145
|
+
border-radius: 12px;
|
|
146
|
+
background: red;
|
|
147
|
+
`
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 🧼 Automatic Minification
|
|
153
|
+
|
|
154
|
+
All styles are **automatically minified** before being passed to `styled-jsx`.
|
|
155
|
+
|
|
156
|
+
This includes:
|
|
157
|
+
|
|
158
|
+
- 🧹 Stripping all comments (`/* */` and `//`)
|
|
159
|
+
- 🧱 Removing extra whitespace and newlines
|
|
160
|
+
- 🧵 Trimming spaces around symbols like `:`, `{}`, `;`, etc.
|
|
161
|
+
- ❌ Eliminating redundant `;` before closing braces
|
|
162
|
+
|
|
163
|
+
### Example
|
|
164
|
+
|
|
165
|
+
This:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
const Box = styled('div')`
|
|
169
|
+
// This is a comment
|
|
170
|
+
padding: 16px ;
|
|
171
|
+
margin: 0 auto ;
|
|
172
|
+
`
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Turns into:
|
|
176
|
+
|
|
177
|
+
```css
|
|
178
|
+
.🎨.jsx-123456 {padding:16px;margin:0 auto;}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
> The minifier is lightweight and built-in — no extra setup required.
|
|
182
|
+
|
|
183
|
+
Under the hood, it's powered by a custom function that processes all styles similarly to how LESS/CSS preprocessors do it, but focused purely on cleanup and safe compression.
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 💻 TypeScript Support
|
|
189
|
+
|
|
190
|
+
- Fully typed components and props
|
|
191
|
+
- Autocomplete for tag names and styles
|
|
192
|
+
- Works seamlessly with React 18+
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 📦 Designed for React
|
|
197
|
+
|
|
198
|
+
Supports React 18 and 19, and integrates smoothly into any React-based project or framework (including Next.js).
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 💡 Why This Exists
|
|
203
|
+
|
|
204
|
+
`styled-jsx` is powerful, but its tagged template syntax isn’t always ergonomic.
|
|
205
|
+
This package brings the comfort and beauty of `styled-components` to the world of `styled-jsx`.
|
|
206
|
+
|
|
207
|
+
**You get the best of both worlds — now with a splash of color. 🎨**
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
Конечно! Вот секция благодарности, оформленная с теплотой и уважением к авторам `styled-jsx` и `styled-components`:
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 🙏 Thanks & Credits
|
|
215
|
+
|
|
216
|
+
A **huge thank you** to the creators and contributors of:
|
|
217
|
+
|
|
218
|
+
- [`styled-jsx`](https://github.com/vercel/styled-jsx) – for pioneering scoped CSS in React and enabling this project’s core functionality
|
|
219
|
+
- [`styled-components`](https://github.com/styled-components/styled-components) – for inspiring the expressive and elegant developer experience this library builds on
|
|
220
|
+
|
|
221
|
+
This library wouldn't exist without the incredible work done by these communities.
|
|
222
|
+
|
|
223
|
+
If you use and enjoy [`styled-components-jsx`](https://www.npmjs.com/package/styled-components-jsx), consider supporting and starring the original projects too — they made all of this possible.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 📄 License
|
|
228
|
+
|
|
229
|
+
MIT © [Cr0WD](https://github.com/Cr0WD)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} lessString - The LESS string to be minified.
|
|
5
|
+
* @returns {string} - The minified LESS string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function minifyLess(lessString: string): string;
|
|
8
|
+
//# sourceMappingURL=minifyLess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minifyLess.d.ts","sourceRoot":"","sources":["../src/helpers/minifyLess.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAOrD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { ElementType, JSX, ReactNode } from 'react';
|
|
2
|
+
import { minifyLess } from './helpers/minifyLess';
|
|
3
|
+
/**
|
|
4
|
+
* Type definition for the styled function.
|
|
5
|
+
* Supports both HTML elements and React components.
|
|
6
|
+
*/
|
|
7
|
+
declare type StyledComponent<T extends ElementType> = <P extends object = React.ComponentProps<T>>(styles: TemplateStringsArray, ...interpolations: Array<((properties: P) => string | number) | string | number>) => (properties: P & {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* Utility type for mapping styled properties to common HTML elements.
|
|
13
|
+
*/
|
|
14
|
+
declare type StyledHTMLTags = {
|
|
15
|
+
[Tag in keyof JSX.IntrinsicElements]: StyledComponent<Tag>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Proxy-based styled function allowing:
|
|
19
|
+
* - `styled("div")`
|
|
20
|
+
* - `styled.div`
|
|
21
|
+
*/
|
|
22
|
+
declare const styled: (<T extends React.ElementType<any, "symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "link" | "main" | "map" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noindex" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "search" | "slot" | "script" | "section" | "select" | "small" | "source" | "span" | "strong" | "style" | "sub" | "summary" | "sup" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view">>(Component: T) => StyledComponent<T>) & StyledHTMLTags;
|
|
23
|
+
export { minifyLess };
|
|
24
|
+
export default styled;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD;;;GAGG;AACH,aAAK,eAAe,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EACxF,MAAM,EAAE,oBAAoB,EAC5B,GAAG,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,KAC5E,CAAC,UAAU,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,GAAG,CAAC,OAAO,CAAA;AAyDlF;;GAEG;AACH,aAAK,cAAc,GAAG;KACpB,GAAG,IAAI,MAAM,GAAG,CAAC,iBAAiB,GAAG,eAAe,CAAC,GAAG,CAAC;CAC1D,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,MAAM,u9DAE8B,CAAA;AAE1C,OAAO,EAAE,UAAU,EAAE,CAAA;AAErB,eAAe,MAAM,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = _interopDefault(require('react'));
|
|
8
|
+
|
|
9
|
+
/* Precompile regular expressions */
|
|
10
|
+
var commentRegex = /\/\*[\s\S]*?\*\/|\/\/.*/g;
|
|
11
|
+
var symbolRegex = /\s*([{}:;,>~+()])\s*/g;
|
|
12
|
+
var whitespaceRegex = /\s+/g;
|
|
13
|
+
var semicolonRegex = /;}/g;
|
|
14
|
+
/**
|
|
15
|
+
* Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} lessString - The LESS string to be minified.
|
|
18
|
+
* @returns {string} - The minified LESS string.
|
|
19
|
+
*/
|
|
20
|
+
function minifyLess(lessString) {
|
|
21
|
+
return lessString.replaceAll(commentRegex, '') // Remove multi-line and single-line comments
|
|
22
|
+
.replaceAll(symbolRegex, '$1') // Remove extra spaces around symbols
|
|
23
|
+
.replaceAll(whitespaceRegex, ' ') // Compress remaining whitespace to a single space
|
|
24
|
+
.replaceAll(semicolonRegex, '}') // Remove extra semicolons before closing braces
|
|
25
|
+
.trim(); // Trim spaces from the beginning and end
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Filters out props starting with '$' or custom props not accepted by HTML elements.
|
|
30
|
+
*/
|
|
31
|
+
var filterDollarProperties = function filterDollarProperties(properties) {
|
|
32
|
+
return Object.fromEntries(Object.entries(properties).filter(function (_ref) {
|
|
33
|
+
var key = _ref[0];
|
|
34
|
+
return !key.startsWith('$');
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Base function to create styled components.
|
|
39
|
+
*
|
|
40
|
+
* @param Component - An HTML tag (e.g., "div", "button") or a React component.
|
|
41
|
+
* @returns A function that takes CSS styles and returns a styled component.
|
|
42
|
+
*/
|
|
43
|
+
var createStyled = function createStyled(Component) {
|
|
44
|
+
return function (styles) {
|
|
45
|
+
for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
46
|
+
interpolations[_key - 1] = arguments[_key];
|
|
47
|
+
}
|
|
48
|
+
return function (properties) {
|
|
49
|
+
// Non-removable class reference for this plugin
|
|
50
|
+
var classNameReference = '🎨';
|
|
51
|
+
// Process styles and replace interpolations with actual prop values
|
|
52
|
+
var processedStyles = styles.map(function (style, index) {
|
|
53
|
+
var interpolation = interpolations[index];
|
|
54
|
+
var value = typeof interpolation === 'function' ? interpolation(properties) : interpolation != null ? interpolation : '';
|
|
55
|
+
return style + value;
|
|
56
|
+
}).join('');
|
|
57
|
+
var isCustomComponent = typeof Component !== 'string';
|
|
58
|
+
var filteredProperties = isCustomComponent ? properties : filterDollarProperties(properties);
|
|
59
|
+
// Ensure Component is a valid React component or HTML tag
|
|
60
|
+
var Element = Component;
|
|
61
|
+
var content = "." + classNameReference + "{" + minifyLess(processedStyles) + "}";
|
|
62
|
+
return React.createElement(React.Fragment, null, React.createElement(Element, Object.assign({}, filteredProperties, {
|
|
63
|
+
className: [properties.className, classNameReference].filter(Boolean).join(' ')
|
|
64
|
+
}), properties.children), React.createElement("style", {
|
|
65
|
+
jsx: true
|
|
66
|
+
}, content));
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Proxy-based styled function allowing:
|
|
72
|
+
* - `styled("div")`
|
|
73
|
+
* - `styled.div`
|
|
74
|
+
*/
|
|
75
|
+
var styled = /*#__PURE__*/new Proxy(createStyled, {
|
|
76
|
+
get: function get(_, tag) {
|
|
77
|
+
return createStyled(tag);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
exports.default = styled;
|
|
82
|
+
exports.minifyLess = minifyLess;
|
|
83
|
+
//# sourceMappingURL=styled-components-jsx.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled-components-jsx.cjs.development.js","sources":["../src/helpers/minifyLess.ts","../src/index.tsx"],"sourcesContent":["/* Precompile regular expressions */\nconst commentRegex = /\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g\nconst symbolRegex = /\\s*([{}:;,>~+()])\\s*/g\nconst whitespaceRegex = /\\s+/g\nconst semicolonRegex = /;}/g\n\n/**\n * Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.\n *\n * @param {string} lessString - The LESS string to be minified.\n * @returns {string} - The minified LESS string.\n */\nexport function minifyLess(lessString: string): string {\n\treturn lessString\n\t\t.replaceAll(commentRegex, '') // Remove multi-line and single-line comments\n\t\t.replaceAll(symbolRegex, '$1') // Remove extra spaces around symbols\n\t\t.replaceAll(whitespaceRegex, ' ') // Compress remaining whitespace to a single space\n\t\t.replaceAll(semicolonRegex, '}') // Remove extra semicolons before closing braces\n\t\t.trim() // Trim spaces from the beginning and end\n}\n","import React, { ElementType, JSX, ReactNode } from 'react'\nimport { minifyLess } from './helpers/minifyLess'\n\n/**\n * Type definition for the styled function.\n * Supports both HTML elements and React components.\n */\ntype StyledComponent<T extends ElementType> = <P extends object = React.ComponentProps<T>>(\n\tstyles: TemplateStringsArray,\n\t...interpolations: Array<((properties: P) => string | number) | string | number>\n) => (properties: P & { children?: ReactNode; className?: string }) => JSX.Element\n\n/**\n * Filters out props starting with '$' or custom props not accepted by HTML elements.\n */\nconst filterDollarProperties = <T extends Record<string, unknown>>(properties: T): Partial<T> =>\n\tObject.fromEntries(\n\t\tObject.entries(properties).filter(([key]) => !key.startsWith('$'))\n\t) as Partial<T>\n\n/**\n * Base function to create styled components.\n *\n * @param Component - An HTML tag (e.g., \"div\", \"button\") or a React component.\n * @returns A function that takes CSS styles and returns a styled component.\n */\nconst createStyled =\n\t<T extends ElementType>(Component: T): StyledComponent<T> =>\n\t(styles, ...interpolations) =>\n\tproperties => {\n\t\t// Non-removable class reference for this plugin\n\t\tconst classNameReference = '🎨'\n\n\t\t// Process styles and replace interpolations with actual prop values\n\t\tconst processedStyles = styles\n\t\t\t.map((style, index) => {\n\t\t\t\tconst interpolation = interpolations[index]\n\t\t\t\tconst value =\n\t\t\t\t\ttypeof interpolation === 'function'\n\t\t\t\t\t\t? interpolation(properties)\n\t\t\t\t\t\t: (interpolation ?? '')\n\t\t\t\treturn style + value\n\t\t\t})\n\t\t\t.join('')\n\n\t\tconst isCustomComponent = typeof Component !== 'string'\n\t\tconst filteredProperties = isCustomComponent\n\t\t\t? properties\n\t\t\t: filterDollarProperties(properties)\n\n\t\t// Ensure Component is a valid React component or HTML tag\n\t\tconst Element: ElementType = Component\n\t\tconst content = `.${classNameReference}{${minifyLess(processedStyles)}}`\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<Element\n\t\t\t\t\t{...filteredProperties}\n\t\t\t\t\tclassName={[properties.className, classNameReference].filter(Boolean).join(' ')}\n\t\t\t\t>\n\t\t\t\t\t{properties.children}\n\t\t\t\t</Element>\n\t\t\t\t<style jsx>{content}</style>\n\t\t\t</>\n\t\t)\n\t}\n\n/**\n * Utility type for mapping styled properties to common HTML elements.\n */\ntype StyledHTMLTags = {\n\t[Tag in keyof JSX.IntrinsicElements]: StyledComponent<Tag>\n}\n\n/**\n * Proxy-based styled function allowing:\n * - `styled(\"div\")`\n * - `styled.div`\n */\nconst styled = new Proxy(createStyled, {\n\tget: (_, tag: keyof JSX.IntrinsicElements) => createStyled(tag),\n}) as typeof createStyled & StyledHTMLTags\n\nexport { minifyLess }\n\nexport default styled\n"],"names":["commentRegex","symbolRegex","whitespaceRegex","semicolonRegex","minifyLess","lessString","replaceAll","trim","filterDollarProperties","properties","Object","fromEntries","entries","filter","_ref","key","startsWith","createStyled","Component","styles","_len","arguments","length","interpolations","Array","_key","classNameReference","processedStyles","map","style","index","interpolation","value","join","isCustomComponent","filteredProperties","Element","content","React","className","Boolean","children","jsx","styled","Proxy","get","_","tag"],"mappings":";;;;;;;;AAAA;AACA,IAAMA,YAAY,GAAG,0BAA0B;AAC/C,IAAMC,WAAW,GAAG,uBAAuB;AAC3C,IAAMC,eAAe,GAAG,MAAM;AAC9B,IAAMC,cAAc,GAAG,KAAK;AAE5B;;;;;;SAMgBC,UAAUA,CAACC,UAAkB;EAC5C,OAAOA,UAAU,CACfC,UAAU,CAACN,YAAY,EAAE,EAAE,CAAC;GAC5BM,UAAU,CAACL,WAAW,EAAE,IAAI,CAAC;GAC7BK,UAAU,CAACJ,eAAe,EAAE,GAAG,CAAC;GAChCI,UAAU,CAACH,cAAc,EAAE,GAAG,CAAC;GAC/BI,IAAI,EAAE,CAAA;AACT;;ACPA;;;AAGA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAuCC,UAAa;EAAA,OAC/EC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAACH,UAAU,CAAC,CAACI,MAAM,CAAC,UAAAC,IAAA;IAAA,IAAEC,GAAG,GAAAD,IAAA;IAAA,OAAM,CAACC,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;IAAC,CACpD;AAAA;AAEhB;;;;;;AAMA,IAAMC,YAAY,GACjB,SADKA,YAAYA,CACOC,SAAY;EAAA,OACpC,UAACC,MAAM;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAKC,cAAc,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAdF,cAAc,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;;IAAA,OAC1B,UAAAhB,UAAU;;MAET,IAAMiB,kBAAkB,GAAG,IAAI;;MAG/B,IAAMC,eAAe,GAAGR,MAAM,CAC5BS,GAAG,CAAC,UAACC,KAAK,EAAEC,KAAK;QACjB,IAAMC,aAAa,GAAGR,cAAc,CAACO,KAAK,CAAC;QAC3C,IAAME,KAAK,GACV,OAAOD,aAAa,KAAK,UAAU,GAChCA,aAAa,CAACtB,UAAU,CAAC,GACxBsB,aAAa,WAAbA,aAAa,GAAI,EAAG;QACzB,OAAOF,KAAK,GAAGG,KAAK;OACpB,CAAC,CACDC,IAAI,CAAC,EAAE,CAAC;MAEV,IAAMC,iBAAiB,GAAG,OAAOhB,SAAS,KAAK,QAAQ;MACvD,IAAMiB,kBAAkB,GAAGD,iBAAiB,GACzCzB,UAAU,GACVD,sBAAsB,CAACC,UAAU,CAAC;;MAGrC,IAAM2B,OAAO,GAAgBlB,SAAS;MACtC,IAAMmB,OAAO,SAAOX,kBAAkB,SAAItB,UAAU,CAACuB,eAAe,CAAC,MAAG;MAExE,OACCW,0CACCA,oBAACF,OAAO,oBACHD,kBAAkB;QACtBI,SAAS,EAAE,CAAC9B,UAAU,CAAC8B,SAAS,EAAEb,kBAAkB,CAAC,CAACb,MAAM,CAAC2B,OAAO,CAAC,CAACP,IAAI,CAAC,GAAG;UAE7ExB,UAAU,CAACgC,QAAQ,CACX,EACVH;QAAOI,GAAG;SAAEL,OAAO,CAAS,CAC1B;KAEJ;;AAAA;AASF;;;;;AAKA,IAAMM,MAAM,gBAAG,IAAIC,KAAK,CAAC3B,YAAY,EAAE;EACtC4B,GAAG,EAAE,SAALA,GAAGA,CAAGC,CAAC,EAAEC,GAAgC;IAAA,OAAK9B,YAAY,CAAC8B,GAAG,CAAC;;CAC/D,CAAyC;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e,r=/\/\*[\s\S]*?\*\/|\/\/.*/g,n=/\s*([{}:;,>~+()])\s*/g,l=/\s+/g,a=/;}/g;function c(e){return e.replaceAll(r,"").replaceAll(n,"$1").replaceAll(l," ").replaceAll(a,"}").trim()}var i=function(e){return Object.fromEntries(Object.entries(e).filter((function(e){return!e[0].startsWith("$")})))},u=function(e){return function(r){for(var n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];return function(n){var a="🎨",u=r.map((function(e,t){var r=l[t];return e+("function"==typeof r?r(n):null!=r?r:"")})).join(""),o="string"!=typeof e?n:i(n),s=e,f="."+a+"{"+c(u)+"}";return t.createElement(t.Fragment,null,t.createElement(s,Object.assign({},o,{className:[n.className,a].filter(Boolean).join(" ")}),n.children),t.createElement("style",{jsx:!0},f))}}};exports.default=new Proxy(u,{get:function(e,t){return u(t)}}),exports.minifyLess=c;
|
|
2
|
+
//# sourceMappingURL=styled-components-jsx.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled-components-jsx.cjs.production.min.js","sources":["../src/helpers/minifyLess.ts","../src/index.tsx"],"sourcesContent":["/* Precompile regular expressions */\nconst commentRegex = /\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g\nconst symbolRegex = /\\s*([{}:;,>~+()])\\s*/g\nconst whitespaceRegex = /\\s+/g\nconst semicolonRegex = /;}/g\n\n/**\n * Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.\n *\n * @param {string} lessString - The LESS string to be minified.\n * @returns {string} - The minified LESS string.\n */\nexport function minifyLess(lessString: string): string {\n\treturn lessString\n\t\t.replaceAll(commentRegex, '') // Remove multi-line and single-line comments\n\t\t.replaceAll(symbolRegex, '$1') // Remove extra spaces around symbols\n\t\t.replaceAll(whitespaceRegex, ' ') // Compress remaining whitespace to a single space\n\t\t.replaceAll(semicolonRegex, '}') // Remove extra semicolons before closing braces\n\t\t.trim() // Trim spaces from the beginning and end\n}\n","import React, { ElementType, JSX, ReactNode } from 'react'\nimport { minifyLess } from './helpers/minifyLess'\n\n/**\n * Type definition for the styled function.\n * Supports both HTML elements and React components.\n */\ntype StyledComponent<T extends ElementType> = <P extends object = React.ComponentProps<T>>(\n\tstyles: TemplateStringsArray,\n\t...interpolations: Array<((properties: P) => string | number) | string | number>\n) => (properties: P & { children?: ReactNode; className?: string }) => JSX.Element\n\n/**\n * Filters out props starting with '$' or custom props not accepted by HTML elements.\n */\nconst filterDollarProperties = <T extends Record<string, unknown>>(properties: T): Partial<T> =>\n\tObject.fromEntries(\n\t\tObject.entries(properties).filter(([key]) => !key.startsWith('$'))\n\t) as Partial<T>\n\n/**\n * Base function to create styled components.\n *\n * @param Component - An HTML tag (e.g., \"div\", \"button\") or a React component.\n * @returns A function that takes CSS styles and returns a styled component.\n */\nconst createStyled =\n\t<T extends ElementType>(Component: T): StyledComponent<T> =>\n\t(styles, ...interpolations) =>\n\tproperties => {\n\t\t// Non-removable class reference for this plugin\n\t\tconst classNameReference = '🎨'\n\n\t\t// Process styles and replace interpolations with actual prop values\n\t\tconst processedStyles = styles\n\t\t\t.map((style, index) => {\n\t\t\t\tconst interpolation = interpolations[index]\n\t\t\t\tconst value =\n\t\t\t\t\ttypeof interpolation === 'function'\n\t\t\t\t\t\t? interpolation(properties)\n\t\t\t\t\t\t: (interpolation ?? '')\n\t\t\t\treturn style + value\n\t\t\t})\n\t\t\t.join('')\n\n\t\tconst isCustomComponent = typeof Component !== 'string'\n\t\tconst filteredProperties = isCustomComponent\n\t\t\t? properties\n\t\t\t: filterDollarProperties(properties)\n\n\t\t// Ensure Component is a valid React component or HTML tag\n\t\tconst Element: ElementType = Component\n\t\tconst content = `.${classNameReference}{${minifyLess(processedStyles)}}`\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<Element\n\t\t\t\t\t{...filteredProperties}\n\t\t\t\t\tclassName={[properties.className, classNameReference].filter(Boolean).join(' ')}\n\t\t\t\t>\n\t\t\t\t\t{properties.children}\n\t\t\t\t</Element>\n\t\t\t\t<style jsx>{content}</style>\n\t\t\t</>\n\t\t)\n\t}\n\n/**\n * Utility type for mapping styled properties to common HTML elements.\n */\ntype StyledHTMLTags = {\n\t[Tag in keyof JSX.IntrinsicElements]: StyledComponent<Tag>\n}\n\n/**\n * Proxy-based styled function allowing:\n * - `styled(\"div\")`\n * - `styled.div`\n */\nconst styled = new Proxy(createStyled, {\n\tget: (_, tag: keyof JSX.IntrinsicElements) => createStyled(tag),\n}) as typeof createStyled & StyledHTMLTags\n\nexport { minifyLess }\n\nexport default styled\n"],"names":["commentRegex","symbolRegex","whitespaceRegex","semicolonRegex","minifyLess","lessString","replaceAll","trim","filterDollarProperties","properties","Object","fromEntries","entries","filter","_ref","startsWith","createStyled","Component","styles","_len","arguments","length","interpolations","Array","_key","classNameReference","processedStyles","map","style","index","interpolation","join","filteredProperties","Element","content","React","className","Boolean","children","jsx","Proxy","get","_","tag"],"mappings":"gJACMA,EAAe,2BACfC,EAAc,wBACdC,EAAkB,OAClBC,EAAiB,eAQPC,EAAWC,GAC1B,OAAOA,EACLC,WAAWN,EAAc,IACzBM,WAAWL,EAAa,MACxBK,WAAWJ,EAAiB,KAC5BI,WAAWH,EAAgB,KAC3BI,OCHH,IAAMC,EAAyB,SAAoCC,GAAa,OAC/EC,OAAOC,YACND,OAAOE,QAAQH,GAAYI,QAAO,SAAAC,GAAK,OAAAA,KAAWC,WAAW,UASzDC,EACL,SAAwBC,GAAY,OACpC,SAACC,GAAM,QAAAC,EAAAC,UAAAC,OAAKC,MAAcC,MAAAJ,IAAAA,OAAAK,IAAAA,EAAAL,EAAAK,IAAdF,EAAcE,KAAAJ,UAAAI,GAAA,OAC1B,SAAAf,GAEC,IAAMgB,EAAqB,KAGrBC,EAAkBR,EACtBS,KAAI,SAACC,EAAOC,GACZ,IAAMC,EAAgBR,EAAeO,GAKrC,OAAOD,GAHmB,mBAAlBE,EACJA,EAAcrB,SACbqB,EAAAA,EAAiB,OAGtBC,KAAK,IAGDC,EADyC,iBAAdf,EAE9BR,EACAD,EAAuBC,GAGpBwB,EAAuBhB,EACvBiB,MAAcT,MAAsBrB,EAAWsB,OAErD,OACCS,gCACCA,gBAACF,mBACID,GACJI,UAAW,CAAC3B,EAAW2B,UAAWX,GAAoBZ,OAAOwB,SAASN,KAAK,OAE1EtB,EAAW6B,UAEbH,yBAAOI,QAAKL,uBAiBD,IAAIM,MAAMxB,EAAc,CACtCyB,IAAK,SAACC,EAAGC,GAAgC,OAAK3B,EAAa2B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/* Precompile regular expressions */
|
|
4
|
+
var commentRegex = /\/\*[\s\S]*?\*\/|\/\/.*/g;
|
|
5
|
+
var symbolRegex = /\s*([{}:;,>~+()])\s*/g;
|
|
6
|
+
var whitespaceRegex = /\s+/g;
|
|
7
|
+
var semicolonRegex = /;}/g;
|
|
8
|
+
/**
|
|
9
|
+
* Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} lessString - The LESS string to be minified.
|
|
12
|
+
* @returns {string} - The minified LESS string.
|
|
13
|
+
*/
|
|
14
|
+
function minifyLess(lessString) {
|
|
15
|
+
return lessString.replaceAll(commentRegex, '') // Remove multi-line and single-line comments
|
|
16
|
+
.replaceAll(symbolRegex, '$1') // Remove extra spaces around symbols
|
|
17
|
+
.replaceAll(whitespaceRegex, ' ') // Compress remaining whitespace to a single space
|
|
18
|
+
.replaceAll(semicolonRegex, '}') // Remove extra semicolons before closing braces
|
|
19
|
+
.trim(); // Trim spaces from the beginning and end
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Filters out props starting with '$' or custom props not accepted by HTML elements.
|
|
24
|
+
*/
|
|
25
|
+
var filterDollarProperties = function filterDollarProperties(properties) {
|
|
26
|
+
return Object.fromEntries(Object.entries(properties).filter(function (_ref) {
|
|
27
|
+
var key = _ref[0];
|
|
28
|
+
return !key.startsWith('$');
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Base function to create styled components.
|
|
33
|
+
*
|
|
34
|
+
* @param Component - An HTML tag (e.g., "div", "button") or a React component.
|
|
35
|
+
* @returns A function that takes CSS styles and returns a styled component.
|
|
36
|
+
*/
|
|
37
|
+
var createStyled = function createStyled(Component) {
|
|
38
|
+
return function (styles) {
|
|
39
|
+
for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
40
|
+
interpolations[_key - 1] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
return function (properties) {
|
|
43
|
+
// Non-removable class reference for this plugin
|
|
44
|
+
var classNameReference = '🎨';
|
|
45
|
+
// Process styles and replace interpolations with actual prop values
|
|
46
|
+
var processedStyles = styles.map(function (style, index) {
|
|
47
|
+
var interpolation = interpolations[index];
|
|
48
|
+
var value = typeof interpolation === 'function' ? interpolation(properties) : interpolation != null ? interpolation : '';
|
|
49
|
+
return style + value;
|
|
50
|
+
}).join('');
|
|
51
|
+
var isCustomComponent = typeof Component !== 'string';
|
|
52
|
+
var filteredProperties = isCustomComponent ? properties : filterDollarProperties(properties);
|
|
53
|
+
// Ensure Component is a valid React component or HTML tag
|
|
54
|
+
var Element = Component;
|
|
55
|
+
var content = "." + classNameReference + "{" + minifyLess(processedStyles) + "}";
|
|
56
|
+
return React.createElement(React.Fragment, null, React.createElement(Element, Object.assign({}, filteredProperties, {
|
|
57
|
+
className: [properties.className, classNameReference].filter(Boolean).join(' ')
|
|
58
|
+
}), properties.children), React.createElement("style", {
|
|
59
|
+
jsx: true
|
|
60
|
+
}, content));
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Proxy-based styled function allowing:
|
|
66
|
+
* - `styled("div")`
|
|
67
|
+
* - `styled.div`
|
|
68
|
+
*/
|
|
69
|
+
var styled = /*#__PURE__*/new Proxy(createStyled, {
|
|
70
|
+
get: function get(_, tag) {
|
|
71
|
+
return createStyled(tag);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export default styled;
|
|
76
|
+
export { minifyLess };
|
|
77
|
+
//# sourceMappingURL=styled-components-jsx.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled-components-jsx.esm.js","sources":["../src/helpers/minifyLess.ts","../src/index.tsx"],"sourcesContent":["/* Precompile regular expressions */\nconst commentRegex = /\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g\nconst symbolRegex = /\\s*([{}:;,>~+()])\\s*/g\nconst whitespaceRegex = /\\s+/g\nconst semicolonRegex = /;}/g\n\n/**\n * Minifies a LESS string by removing comments, extra spaces, and unnecessary semicolons.\n *\n * @param {string} lessString - The LESS string to be minified.\n * @returns {string} - The minified LESS string.\n */\nexport function minifyLess(lessString: string): string {\n\treturn lessString\n\t\t.replaceAll(commentRegex, '') // Remove multi-line and single-line comments\n\t\t.replaceAll(symbolRegex, '$1') // Remove extra spaces around symbols\n\t\t.replaceAll(whitespaceRegex, ' ') // Compress remaining whitespace to a single space\n\t\t.replaceAll(semicolonRegex, '}') // Remove extra semicolons before closing braces\n\t\t.trim() // Trim spaces from the beginning and end\n}\n","import React, { ElementType, JSX, ReactNode } from 'react'\nimport { minifyLess } from './helpers/minifyLess'\n\n/**\n * Type definition for the styled function.\n * Supports both HTML elements and React components.\n */\ntype StyledComponent<T extends ElementType> = <P extends object = React.ComponentProps<T>>(\n\tstyles: TemplateStringsArray,\n\t...interpolations: Array<((properties: P) => string | number) | string | number>\n) => (properties: P & { children?: ReactNode; className?: string }) => JSX.Element\n\n/**\n * Filters out props starting with '$' or custom props not accepted by HTML elements.\n */\nconst filterDollarProperties = <T extends Record<string, unknown>>(properties: T): Partial<T> =>\n\tObject.fromEntries(\n\t\tObject.entries(properties).filter(([key]) => !key.startsWith('$'))\n\t) as Partial<T>\n\n/**\n * Base function to create styled components.\n *\n * @param Component - An HTML tag (e.g., \"div\", \"button\") or a React component.\n * @returns A function that takes CSS styles and returns a styled component.\n */\nconst createStyled =\n\t<T extends ElementType>(Component: T): StyledComponent<T> =>\n\t(styles, ...interpolations) =>\n\tproperties => {\n\t\t// Non-removable class reference for this plugin\n\t\tconst classNameReference = '🎨'\n\n\t\t// Process styles and replace interpolations with actual prop values\n\t\tconst processedStyles = styles\n\t\t\t.map((style, index) => {\n\t\t\t\tconst interpolation = interpolations[index]\n\t\t\t\tconst value =\n\t\t\t\t\ttypeof interpolation === 'function'\n\t\t\t\t\t\t? interpolation(properties)\n\t\t\t\t\t\t: (interpolation ?? '')\n\t\t\t\treturn style + value\n\t\t\t})\n\t\t\t.join('')\n\n\t\tconst isCustomComponent = typeof Component !== 'string'\n\t\tconst filteredProperties = isCustomComponent\n\t\t\t? properties\n\t\t\t: filterDollarProperties(properties)\n\n\t\t// Ensure Component is a valid React component or HTML tag\n\t\tconst Element: ElementType = Component\n\t\tconst content = `.${classNameReference}{${minifyLess(processedStyles)}}`\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<Element\n\t\t\t\t\t{...filteredProperties}\n\t\t\t\t\tclassName={[properties.className, classNameReference].filter(Boolean).join(' ')}\n\t\t\t\t>\n\t\t\t\t\t{properties.children}\n\t\t\t\t</Element>\n\t\t\t\t<style jsx>{content}</style>\n\t\t\t</>\n\t\t)\n\t}\n\n/**\n * Utility type for mapping styled properties to common HTML elements.\n */\ntype StyledHTMLTags = {\n\t[Tag in keyof JSX.IntrinsicElements]: StyledComponent<Tag>\n}\n\n/**\n * Proxy-based styled function allowing:\n * - `styled(\"div\")`\n * - `styled.div`\n */\nconst styled = new Proxy(createStyled, {\n\tget: (_, tag: keyof JSX.IntrinsicElements) => createStyled(tag),\n}) as typeof createStyled & StyledHTMLTags\n\nexport { minifyLess }\n\nexport default styled\n"],"names":["commentRegex","symbolRegex","whitespaceRegex","semicolonRegex","minifyLess","lessString","replaceAll","trim","filterDollarProperties","properties","Object","fromEntries","entries","filter","_ref","key","startsWith","createStyled","Component","styles","_len","arguments","length","interpolations","Array","_key","classNameReference","processedStyles","map","style","index","interpolation","value","join","isCustomComponent","filteredProperties","Element","content","React","className","Boolean","children","jsx","styled","Proxy","get","_","tag"],"mappings":";;AAAA;AACA,IAAMA,YAAY,GAAG,0BAA0B;AAC/C,IAAMC,WAAW,GAAG,uBAAuB;AAC3C,IAAMC,eAAe,GAAG,MAAM;AAC9B,IAAMC,cAAc,GAAG,KAAK;AAE5B;;;;;;SAMgBC,UAAUA,CAACC,UAAkB;EAC5C,OAAOA,UAAU,CACfC,UAAU,CAACN,YAAY,EAAE,EAAE,CAAC;GAC5BM,UAAU,CAACL,WAAW,EAAE,IAAI,CAAC;GAC7BK,UAAU,CAACJ,eAAe,EAAE,GAAG,CAAC;GAChCI,UAAU,CAACH,cAAc,EAAE,GAAG,CAAC;GAC/BI,IAAI,EAAE,CAAA;AACT;;ACPA;;;AAGA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAuCC,UAAa;EAAA,OAC/EC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAACH,UAAU,CAAC,CAACI,MAAM,CAAC,UAAAC,IAAA;IAAA,IAAEC,GAAG,GAAAD,IAAA;IAAA,OAAM,CAACC,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;IAAC,CACpD;AAAA;AAEhB;;;;;;AAMA,IAAMC,YAAY,GACjB,SADKA,YAAYA,CACOC,SAAY;EAAA,OACpC,UAACC,MAAM;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAKC,cAAc,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAdF,cAAc,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;;IAAA,OAC1B,UAAAhB,UAAU;;MAET,IAAMiB,kBAAkB,GAAG,IAAI;;MAG/B,IAAMC,eAAe,GAAGR,MAAM,CAC5BS,GAAG,CAAC,UAACC,KAAK,EAAEC,KAAK;QACjB,IAAMC,aAAa,GAAGR,cAAc,CAACO,KAAK,CAAC;QAC3C,IAAME,KAAK,GACV,OAAOD,aAAa,KAAK,UAAU,GAChCA,aAAa,CAACtB,UAAU,CAAC,GACxBsB,aAAa,WAAbA,aAAa,GAAI,EAAG;QACzB,OAAOF,KAAK,GAAGG,KAAK;OACpB,CAAC,CACDC,IAAI,CAAC,EAAE,CAAC;MAEV,IAAMC,iBAAiB,GAAG,OAAOhB,SAAS,KAAK,QAAQ;MACvD,IAAMiB,kBAAkB,GAAGD,iBAAiB,GACzCzB,UAAU,GACVD,sBAAsB,CAACC,UAAU,CAAC;;MAGrC,IAAM2B,OAAO,GAAgBlB,SAAS;MACtC,IAAMmB,OAAO,SAAOX,kBAAkB,SAAItB,UAAU,CAACuB,eAAe,CAAC,MAAG;MAExE,OACCW,0CACCA,oBAACF,OAAO,oBACHD,kBAAkB;QACtBI,SAAS,EAAE,CAAC9B,UAAU,CAAC8B,SAAS,EAAEb,kBAAkB,CAAC,CAACb,MAAM,CAAC2B,OAAO,CAAC,CAACP,IAAI,CAAC,GAAG;UAE7ExB,UAAU,CAACgC,QAAQ,CACX,EACVH;QAAOI,GAAG;SAAEL,OAAO,CAAS,CAC1B;KAEJ;;AAAA;AASF;;;;;AAKA,IAAMM,MAAM,gBAAG,IAAIC,KAAK,CAAC3B,YAAY,EAAE;EACtC4B,GAAG,EAAE,SAALA,GAAGA,CAAGC,CAAC,EAAEC,GAAgC;IAAA,OAAK9B,YAAY,CAAC8B,GAAG,CAAC;;CAC/D,CAAyC;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"name": "styled-components-jsx",
|
|
5
|
+
"author": {
|
|
6
|
+
"email": "freshcrowd@gmail.com",
|
|
7
|
+
"name": "Denis Orlov",
|
|
8
|
+
"url": "https://github.com/Cr0WD"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/Cr0WD/styled-components-jsx"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"css",
|
|
16
|
+
"styling",
|
|
17
|
+
"babel-plugin-macros",
|
|
18
|
+
"styled-jsx",
|
|
19
|
+
"styled-components",
|
|
20
|
+
"css-in-js",
|
|
21
|
+
"react",
|
|
22
|
+
"reactjs",
|
|
23
|
+
"react-typescript",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"module": "dist/styled-components-jsx.esm.js",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"typings": "dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "tsdx watch",
|
|
34
|
+
"build": "tsdx build",
|
|
35
|
+
"lint": "tsdx lint",
|
|
36
|
+
"prepare": "install-peers && tsdx build",
|
|
37
|
+
"postinstall": "manypkg fix && manypkg check"
|
|
38
|
+
},
|
|
39
|
+
"husky": {
|
|
40
|
+
"hooks": {
|
|
41
|
+
"pre-commit": "tsdx lint"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"prettier": {
|
|
45
|
+
"printWidth": 100,
|
|
46
|
+
"trailingComma": "es5",
|
|
47
|
+
"semi": false,
|
|
48
|
+
"singleQuote": true,
|
|
49
|
+
"bracketSpacing": true,
|
|
50
|
+
"arrowParens": "avoid",
|
|
51
|
+
"endOfLine": "lf",
|
|
52
|
+
"useTabs": true,
|
|
53
|
+
"tabWidth": 4
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"branches": [
|
|
58
|
+
"master"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@types/react": "^18.0.0 ||^19.0.0",
|
|
63
|
+
"react": "^18.0.0 ||^19.0.0",
|
|
64
|
+
"react-dom": "^18.0.0 ||^19.0.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@types/react": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@eslint/js": "9.24.0",
|
|
73
|
+
"@manypkg/cli": "0.23.0",
|
|
74
|
+
"@next/eslint-plugin-next": "^15.3.0",
|
|
75
|
+
"@types/react": "^18.0.0 ||^19.0.0",
|
|
76
|
+
"@types/react-dom": "^19.1.2",
|
|
77
|
+
"@types/styled-jsx": "3.4.4",
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "8.29.1",
|
|
79
|
+
"@typescript-eslint/parser": "8.29.1",
|
|
80
|
+
"eslint": "9.24.0",
|
|
81
|
+
"eslint-config-prettier": "^10.1.2",
|
|
82
|
+
"eslint-import-resolver-typescript": "4.3.2",
|
|
83
|
+
"eslint-plugin-import": "2.31.0",
|
|
84
|
+
"eslint-plugin-jsx-a11y": "6.10.2",
|
|
85
|
+
"eslint-plugin-promise": "7.2.1",
|
|
86
|
+
"eslint-plugin-react": "^7.37.5",
|
|
87
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
88
|
+
"eslint-plugin-security": "3.0.1",
|
|
89
|
+
"eslint-plugin-unicorn": "58.0.0",
|
|
90
|
+
"husky": "^9.1.7",
|
|
91
|
+
"install-peers-cli": "^2.2.0",
|
|
92
|
+
"prettier": "3.5.3",
|
|
93
|
+
"react": "^18.0.0 ||^19.0.0",
|
|
94
|
+
"react-dom": "^18.0.0 ||^19.0.0",
|
|
95
|
+
"semantic-release": "24.2.3",
|
|
96
|
+
"tsdx": "^0.14.1",
|
|
97
|
+
"tslib": "^2.8.1",
|
|
98
|
+
"typescript": "5.8.3",
|
|
99
|
+
"typescript-eslint": "^8.29.1"
|
|
100
|
+
}
|
|
101
|
+
}
|