@pyreon/unistyle 0.0.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Vit Bokisch
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,194 @@
1
+ # @pyreon/unistyle
2
+
3
+ Responsive CSS engine for Pyreon.
4
+
5
+ Transforms property-centric theme objects into breakpoint-centric CSS with media queries. Automatic px-to-rem conversion, flex alignment helpers, and a data-driven style processor. Powers the responsive system behind `@pyreon/elements`, `@pyreon/coolgrid`, and `@pyreon/rocketstyle`.
6
+
7
+ ## Features
8
+
9
+ - **Responsive pipeline** — write theme objects, get media queries automatically
10
+ - **px-to-rem conversion** — configurable rootSize, zero-effort unit handling
11
+ - **Breakpoint deduplication** — identical breakpoints are collapsed, no redundant CSS
12
+ - **Three input formats** — scalar, mobile-first array, or breakpoint object per property
13
+ - **Data-driven styles** — 100+ CSS properties processed from a theme object
14
+ - **Alignment helpers** — flex alignment constants for X and Y axes
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ bun add @pyreon/unistyle
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```ts
25
+ import { Provider } from '@pyreon/unistyle'
26
+
27
+ const theme = {
28
+ rootSize: 16,
29
+ breakpoints: { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200 },
30
+ }
31
+
32
+ Provider({ theme, children: [/* your app */] })
33
+ ```
34
+
35
+ ## API
36
+
37
+ ### makeItResponsive
38
+
39
+ The core responsive engine. Takes a theme object and a styles processor, returns CSS with media query wrappers for each breakpoint.
40
+
41
+ ```ts
42
+ import { makeItResponsive, styles } from '@pyreon/unistyle'
43
+ import { config } from '@pyreon/ui-core'
44
+
45
+ const { styled, css } = config
46
+
47
+ const Box = styled('div')`
48
+ ${makeItResponsive({
49
+ key: '$box',
50
+ css,
51
+ styles,
52
+ })}
53
+ `
54
+
55
+ // Single values
56
+ Box({ $box: { padding: 16, fontSize: 14 } })
57
+
58
+ // Responsive breakpoint object
59
+ Box({ $box: { padding: { xs: 8, md: 16, lg: 24 }, fontSize: 14 } })
60
+
61
+ // Responsive mobile-first array
62
+ Box({ $box: { padding: [8, 16, 24], fontSize: 14 } })
63
+ ```
64
+
65
+ **Pipeline:**
66
+
67
+ ```text
68
+ theme object → normalize (fill gaps) → transform (property → breakpoint pivot)
69
+ → optimize (deduplicate) → media queries
70
+ ```
71
+
72
+ **Parameters:**
73
+
74
+ | Param | Type | Description |
75
+ | ----- | ---- | ----------- |
76
+ | key | `string` | Theme prop name to read from styled-component props |
77
+ | css | `function` | `css` tagged template function |
78
+ | styles | `function` | Style processor (use the exported `styles`) |
79
+ | normalize | `boolean` | Fill missing breakpoints by inheriting from previous (default: true) |
80
+
81
+ ### styles
82
+
83
+ Data-driven CSS property processor. Reads a theme object and outputs CSS for all recognized properties — layout, spacing, typography, borders, backgrounds, transforms, and more.
84
+
85
+ Used internally by `makeItResponsive` but can be called directly:
86
+
87
+ ```ts
88
+ import { styles } from '@pyreon/unistyle'
89
+
90
+ // styles({ theme, css, rootSize }) => css``
91
+ ```
92
+
93
+ Supports shorthand properties (`margin`, `padding`, `borderRadius`) with automatic expansion, and converts numeric values to rem units.
94
+
95
+ ### Unit Conversion
96
+
97
+ ```ts
98
+ import { value, values, stripUnit } from '@pyreon/unistyle'
99
+
100
+ // value(input, rootSize?, outputUnit?) => string | number | null
101
+ value(16) // => '1rem' (16 / 16)
102
+ value(24) // => '1.5rem' (24 / 16)
103
+ value(0) // => '0' (always unitless)
104
+ value('2em') // => '2em' (string passthrough)
105
+ value(16, 16, 'px') // => '16px'
106
+
107
+ // stripUnit(input, unitReturn?)
108
+ stripUnit('24px') // => 24
109
+ stripUnit('24px', true) // => [24, 'px']
110
+ stripUnit(24) // => 24
111
+
112
+ // values(array, rootSize?, outputUnit?) => string
113
+ // Picks first non-null and converts
114
+ values([null, 16, 24], 16) // => '1rem'
115
+ ```
116
+
117
+ ### Alignment Helpers
118
+
119
+ ```ts
120
+ import { alignContent, ALIGN_CONTENT_MAP_X, ALIGN_CONTENT_MAP_Y } from '@pyreon/unistyle'
121
+ ```
122
+
123
+ Maps alignment keywords to CSS flex values:
124
+
125
+ | Keyword | X-axis CSS | Y-axis CSS |
126
+ | ------- | ---------- | ---------- |
127
+ | `left` / `top` | `flex-start` | `flex-start` |
128
+ | `center` | `center` | `center` |
129
+ | `right` / `bottom` | `flex-end` | `flex-end` |
130
+ | `spaceBetween` | `space-between` | `space-between` |
131
+ | `spaceAround` | `space-around` | `space-around` |
132
+ | `block` | `stretch` | `stretch` |
133
+
134
+ ### Default Breakpoints
135
+
136
+ ```ts
137
+ import { breakpoints } from '@pyreon/unistyle'
138
+ ```
139
+
140
+ ```ts
141
+ {
142
+ rootSize: 16,
143
+ breakpoints: {
144
+ xs: 0, // mobile
145
+ sm: 576, // small
146
+ md: 768, // tablet
147
+ lg: 992, // desktop
148
+ xl: 1200, // large desktop
149
+ xxl: 1440, // extra large
150
+ },
151
+ }
152
+ ```
153
+
154
+ Breakpoint values are converted to `em` units in media queries for correct cross-browser behavior.
155
+
156
+ ### Other Exports
157
+
158
+ | Export | Description |
159
+ | ------ | ----------- |
160
+ | `createMediaQueries` | Builds breakpoint-name → tagged-template-function map |
161
+ | `transformTheme` | Pivots property-centric theme to breakpoint-centric |
162
+ | `normalizeTheme` | Fills gaps so every breakpoint has a complete set of values |
163
+ | `sortBreakpoints` | Sorts breakpoint definitions by value (ascending) |
164
+ | `extendCss` | Helper for processing ExtendCss props (string, function, callback) |
165
+ | `Provider` / `context` | Theme context provider and consumer |
166
+
167
+ ## Responsive Value Formats
168
+
169
+ Every property in the theme object supports three formats:
170
+
171
+ ```ts
172
+ // 1. Scalar — applied to all breakpoints
173
+ { padding: 16 }
174
+
175
+ // 2. Array — mobile-first, values map to breakpoints by position
176
+ { padding: [8, 12, 16] } // xs: 8, sm: 12, md: 16
177
+
178
+ // 3. Object — explicit breakpoint keys
179
+ { padding: { xs: 8, md: 16, xl: 24 } }
180
+ ```
181
+
182
+ When using `normalize: true` (default), missing breakpoints inherit from the previous one.
183
+
184
+ ## Peer Dependencies
185
+
186
+ | Package | Version |
187
+ | ------- | ------- |
188
+ | @pyreon/core | >= 0.0.1 |
189
+ | @pyreon/reactivity | >= 0.0.1 |
190
+ | @pyreon/ui-core | >= 0.0.1 |
191
+
192
+ ## License
193
+
194
+ MIT