@vitus-labs/unistyle 2.0.0-alpha.9 → 2.0.0-beta.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vitus-labs/unistyle
2
2
 
3
- Responsive CSS engine for React and styled-components.
3
+ Responsive CSS engine for React.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@vitus-labs/unistyle)](https://www.npmjs.com/package/@vitus-labs/unistyle)
6
6
  [![license](https://img.shields.io/npm/l/@vitus-labs/unistyle)](https://github.com/vitus-labs/ui-system/blob/main/LICENSE)
@@ -186,12 +186,17 @@ Every property in the theme object supports three formats:
186
186
 
187
187
  When using `normalize: true` (default), missing breakpoints inherit from the previous one.
188
188
 
189
+ ## React Native
190
+
191
+ On React Native, CSS `@media` queries are not available. When initialized with `@vitus-labs/connector-native`, unistyle uses `Dimensions.get('window').width` to evaluate breakpoints at render time (mobile-first). This is handled automatically via `createMediaQueries` passed to `init()`.
192
+
189
193
  ## Peer Dependencies
190
194
 
191
195
  | Package | Version |
192
196
  | ------- | ------- |
193
197
  | react | >= 19 |
194
198
  | @vitus-labs/core | * |
199
+ | react-native | >= 0.76 (optional) |
195
200
 
196
201
  ## License
197
202
 
package/lib/index.d.ts CHANGED
@@ -98,16 +98,6 @@ type MakeItResponsive = ({
98
98
  theme?: Theme$1;
99
99
  [key: string]: any;
100
100
  }) => any;
101
- /**
102
- * Core responsive engine used by every styled component in the system.
103
- *
104
- * Returns a styled-components interpolation function that:
105
- * 1. Reads the component's theme prop (via `key` or direct `theme`)
106
- * 2. Without breakpoints → renders plain CSS
107
- * 3. With breakpoints → normalizes, transforms (property-per-breakpoint →
108
- * breakpoint-per-property), optimizes (deduplicates identical breakpoints),
109
- * and wraps each breakpoint's styles in the appropriate `@media` query.
110
- */
111
101
  declare const makeItResponsive: MakeItResponsive;
112
102
  //#endregion
113
103
  //#region src/responsive/normalizeTheme.d.ts
package/lib/index.js CHANGED
@@ -154,6 +154,7 @@ const transformTheme = ({ theme, breakpoints }) => {
154
154
  * breakpoint-per-property), optimizes (deduplicates identical breakpoints),
155
155
  * and wraps each breakpoint's styles in the appropriate `@media` query.
156
156
  */
157
+ const themeCache = /* @__PURE__ */ new WeakMap();
157
158
  const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
158
159
  const internalTheme = customTheme || props[key];
159
160
  if (isEmpty(internalTheme)) return "";
@@ -168,18 +169,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
168
169
  ${renderStyles(internalTheme)}
169
170
  `;
170
171
  const { media, sortedBreakpoints } = __VITUS_LABS__;
171
- let helperTheme = internalTheme;
172
- if (normalize) helperTheme = normalizeTheme({
173
- theme: internalTheme,
174
- breakpoints: sortedBreakpoints
175
- });
176
- const optimizedTheme = optimizeTheme({
177
- theme: transformTheme({
178
- theme: helperTheme,
172
+ let optimizedTheme;
173
+ const cached = themeCache.get(internalTheme);
174
+ if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
175
+ else {
176
+ let helperTheme = internalTheme;
177
+ if (normalize) helperTheme = normalizeTheme({
178
+ theme: internalTheme,
179
179
  breakpoints: sortedBreakpoints
180
- }),
181
- breakpoints: sortedBreakpoints
182
- });
180
+ });
181
+ optimizedTheme = optimizeTheme({
182
+ theme: transformTheme({
183
+ theme: helperTheme,
184
+ breakpoints: sortedBreakpoints
185
+ }),
186
+ breakpoints: sortedBreakpoints
187
+ });
188
+ themeCache.set(internalTheme, {
189
+ breakpoints: sortedBreakpoints,
190
+ optimized: optimizedTheme
191
+ });
192
+ }
183
193
  return sortedBreakpoints.map((item) => {
184
194
  const breakpointTheme = optimizedTheme[item];
185
195
  if (!breakpointTheme || !media) return "";
@@ -210,7 +220,7 @@ const Provider = ({ theme, children, ...props }) => {
210
220
  if (breakpoints && !isEmpty(breakpoints)) return sortBreakpoints(breakpoints);
211
221
  }, [breakpoints]);
212
222
  const media = useMemo(() => {
213
- if (breakpoints && !isEmpty(breakpoints)) return createMediaQueries({
223
+ if (breakpoints && !isEmpty(breakpoints)) return (config.createMediaQueries ?? createMediaQueries)({
214
224
  breakpoints,
215
225
  css: config.css,
216
226
  rootSize
@@ -286,6 +296,7 @@ const extendCss = (styles) => {
286
296
 
287
297
  //#endregion
288
298
  //#region src/units/stripUnit.ts
299
+ const CSS_UNIT_REGEX = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
289
300
  /**
290
301
  * Strips the CSS unit suffix from a value.
291
302
  * With `unitReturn=true`, returns a `[number, unit]` tuple.
@@ -293,9 +304,8 @@ const extendCss = (styles) => {
293
304
  * Non-string inputs are passed through unchanged.
294
305
  */
295
306
  const stripUnit = (value, unitReturn) => {
296
- const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
297
307
  if (typeof value !== "string") return unitReturn ? [value, void 0] : value;
298
- const matchedValue = value.match(cssRegex);
308
+ const matchedValue = value.match(CSS_UNIT_REGEX);
299
309
  if (unitReturn) {
300
310
  if (matchedValue) return [parseFloat(value), matchedValue[2]];
301
311
  return [value, void 0];
@@ -154,6 +154,7 @@ const transformTheme = ({ theme, breakpoints }) => {
154
154
  * breakpoint-per-property), optimizes (deduplicates identical breakpoints),
155
155
  * and wraps each breakpoint's styles in the appropriate `@media` query.
156
156
  */
157
+ const themeCache = /* @__PURE__ */ new WeakMap();
157
158
  const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
158
159
  const internalTheme = customTheme || props[key];
159
160
  if (isEmpty(internalTheme)) return "";
@@ -168,18 +169,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
168
169
  ${renderStyles(internalTheme)}
169
170
  `;
170
171
  const { media, sortedBreakpoints } = __VITUS_LABS__;
171
- let helperTheme = internalTheme;
172
- if (normalize) helperTheme = normalizeTheme({
173
- theme: internalTheme,
174
- breakpoints: sortedBreakpoints
175
- });
176
- const optimizedTheme = optimizeTheme({
177
- theme: transformTheme({
178
- theme: helperTheme,
172
+ let optimizedTheme;
173
+ const cached = themeCache.get(internalTheme);
174
+ if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
175
+ else {
176
+ let helperTheme = internalTheme;
177
+ if (normalize) helperTheme = normalizeTheme({
178
+ theme: internalTheme,
179
179
  breakpoints: sortedBreakpoints
180
- }),
181
- breakpoints: sortedBreakpoints
182
- });
180
+ });
181
+ optimizedTheme = optimizeTheme({
182
+ theme: transformTheme({
183
+ theme: helperTheme,
184
+ breakpoints: sortedBreakpoints
185
+ }),
186
+ breakpoints: sortedBreakpoints
187
+ });
188
+ themeCache.set(internalTheme, {
189
+ breakpoints: sortedBreakpoints,
190
+ optimized: optimizedTheme
191
+ });
192
+ }
183
193
  return sortedBreakpoints.map((item) => {
184
194
  const breakpointTheme = optimizedTheme[item];
185
195
  if (!breakpointTheme || !media) return "";
@@ -210,7 +220,7 @@ const Provider = ({ theme, children, ...props }) => {
210
220
  if (breakpoints && !isEmpty(breakpoints)) return sortBreakpoints(breakpoints);
211
221
  }, [breakpoints]);
212
222
  const media = useMemo(() => {
213
- if (breakpoints && !isEmpty(breakpoints)) return createMediaQueries({
223
+ if (breakpoints && !isEmpty(breakpoints)) return (config.createMediaQueries ?? createMediaQueries)({
214
224
  breakpoints,
215
225
  css: config.css,
216
226
  rootSize
@@ -286,6 +296,7 @@ const extendCss = (styles) => {
286
296
 
287
297
  //#endregion
288
298
  //#region src/units/stripUnit.ts
299
+ const CSS_UNIT_REGEX = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
289
300
  /**
290
301
  * Strips the CSS unit suffix from a value.
291
302
  * With `unitReturn=true`, returns a `[number, unit]` tuple.
@@ -293,9 +304,8 @@ const extendCss = (styles) => {
293
304
  * Non-string inputs are passed through unchanged.
294
305
  */
295
306
  const stripUnit = (value, unitReturn) => {
296
- const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
297
307
  if (typeof value !== "string") return unitReturn ? [value, void 0] : value;
298
- const matchedValue = value.match(cssRegex);
308
+ const matchedValue = value.match(CSS_UNIT_REGEX);
299
309
  if (unitReturn) {
300
310
  if (matchedValue) return [parseFloat(value), matchedValue[2]];
301
311
  return [value, void 0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/unistyle",
3
- "version": "2.0.0-alpha.9+f2f47db",
3
+ "version": "2.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.cz>",
6
6
  "maintainers": [
@@ -10,11 +10,13 @@
10
10
  "sideEffects": false,
11
11
  "exports": {
12
12
  "source": "./src/index.ts",
13
+ "react-native": "./lib/vitus-labs-unistyle.native.js",
13
14
  "import": "./lib/index.js",
14
15
  "types": "./lib/index.d.ts"
15
16
  },
16
17
  "types": "./lib/index.d.ts",
17
- "react-native": "lib/vitus-labs-unistyle.native.js",
18
+ "react-native": "./lib/vitus-labs-unistyle.native.js",
19
+ "main": "./lib/index.js",
18
20
  "files": [
19
21
  "lib",
20
22
  "!lib/**/*.map",
@@ -31,7 +33,8 @@
31
33
  "test:coverage": "vitest run --coverage",
32
34
  "test:watch": "vitest",
33
35
  "cover": "coveralls < .coverage/lcov.info",
34
- "typecheck": "tsc --noEmit"
36
+ "typecheck": "tsc --noEmit",
37
+ "version": "node ../../scripts/sync-peer-deps.mjs"
35
38
  },
36
39
  "publishConfig": {
37
40
  "access": "public"
@@ -48,13 +51,18 @@
48
51
  "node": ">= 18"
49
52
  },
50
53
  "peerDependencies": {
51
- "@vitus-labs/core": "^1.4.0",
52
- "react": ">= 19"
54
+ "@vitus-labs/core": "2.0.0-beta.1",
55
+ "react": ">= 19",
56
+ "react-native": ">= 0.76"
53
57
  },
54
- "devDependencies": {
55
- "@vitus-labs/core": "2.0.0-alpha.9+f2f47db",
56
- "@vitus-labs/tools-rolldown": "^1.6.0",
57
- "@vitus-labs/tools-typescript": "^1.6.0"
58
+ "peerDependenciesMeta": {
59
+ "react-native": {
60
+ "optional": true
61
+ }
58
62
  },
59
- "gitHead": "f2f47db887d6a846ee5f9e96f290c59cdde4772a"
63
+ "devDependencies": {
64
+ "@vitus-labs/core": "workspace:*",
65
+ "@vitus-labs/tools-rolldown": "2.2.0",
66
+ "@vitus-labs/tools-typescript": "2.1.0"
67
+ }
60
68
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023-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.