@vitus-labs/unistyle 2.0.0-beta.4 → 2.1.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/lib/index.js CHANGED
@@ -279,19 +279,10 @@ const transformTheme = ({ theme, breakpoints }) => {
279
279
  const stringifyResult = (result) => {
280
280
  if (result == null) return "";
281
281
  if (typeof result === "string") return result;
282
+ if (typeof result === "object" && "strings" in result && "values" in result) return String(result);
282
283
  const text = String(result);
283
284
  return text.includes("[object ") ? null : text;
284
285
  };
285
- /**
286
- * Core responsive engine used by every styled component in the system.
287
- *
288
- * Returns a styled-components interpolation function that:
289
- * 1. Reads the component's theme prop (via `key` or direct `theme`)
290
- * 2. Without breakpoints → renders plain CSS
291
- * 3. With breakpoints → normalizes, transforms (property-per-breakpoint →
292
- * breakpoint-per-property), optimizes (deduplicates identical breakpoints),
293
- * and wraps each breakpoint's styles in the appropriate `@media` query.
294
- */
295
286
  const themeCache = /* @__PURE__ */ new WeakMap();
296
287
  const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
297
288
  const internalTheme = customTheme || props[key];
@@ -308,8 +299,13 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
308
299
  `;
309
300
  const { media, sortedBreakpoints } = __VITUS_LABS__;
310
301
  let optimizedTheme;
311
- const cached = themeCache.get(internalTheme);
312
- if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
302
+ const entry = themeCache.get(internalTheme);
303
+ const breakpointsMatch = entry?.breakpoints === sortedBreakpoints;
304
+ if (entry && breakpointsMatch && entry.rendered) {
305
+ const memoized = entry.rendered.get(theme);
306
+ if (memoized) return memoized;
307
+ }
308
+ if (entry && breakpointsMatch) optimizedTheme = entry.optimized;
313
309
  else {
314
310
  let helperTheme = internalTheme;
315
311
  if (normalize) helperTheme = normalizeTheme({
@@ -325,7 +321,8 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
325
321
  });
326
322
  themeCache.set(internalTheme, {
327
323
  breakpoints: sortedBreakpoints,
328
- optimized: optimizedTheme
324
+ optimized: optimizedTheme,
325
+ rendered: entry?.rendered
329
326
  });
330
327
  }
331
328
  const renderedTexts = sortedBreakpoints.map((item) => {
@@ -333,22 +330,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
333
330
  if (!breakpointTheme || !media) return "";
334
331
  return stringifyResult(renderStyles(breakpointTheme));
335
332
  });
336
- if (renderedTexts.every((t) => t !== null)) {
333
+ const canOptimize = renderedTexts.every((t) => t !== null);
334
+ let result;
335
+ if (canOptimize) {
337
336
  const deltas = optimizeBreakpointDeltas(renderedTexts);
338
- return sortedBreakpoints.map((item, i) => {
337
+ result = sortedBreakpoints.map((item, i) => {
339
338
  const css = deltas[i];
340
339
  if (!css || !media) return "";
341
340
  return media[item]`${css}`;
342
341
  });
343
- }
344
- return sortedBreakpoints.map((item) => {
342
+ } else result = sortedBreakpoints.map((item) => {
345
343
  const breakpointTheme = optimizedTheme[item];
346
344
  if (!breakpointTheme || !media) return "";
347
- const result = renderStyles(breakpointTheme);
345
+ const r = renderStyles(breakpointTheme);
348
346
  return media[item]`
349
- ${result};
350
- `;
347
+ ${r};
348
+ `;
351
349
  });
350
+ const cacheEntry = themeCache.get(internalTheme);
351
+ if (!cacheEntry.rendered) cacheEntry.rendered = /* @__PURE__ */ new WeakMap();
352
+ cacheEntry.rendered.set(theme, result);
353
+ return result;
352
354
  };
353
355
 
354
356
  //#endregion
@@ -279,19 +279,10 @@ const transformTheme = ({ theme, breakpoints }) => {
279
279
  const stringifyResult = (result) => {
280
280
  if (result == null) return "";
281
281
  if (typeof result === "string") return result;
282
+ if (typeof result === "object" && "strings" in result && "values" in result) return String(result);
282
283
  const text = String(result);
283
284
  return text.includes("[object ") ? null : text;
284
285
  };
285
- /**
286
- * Core responsive engine used by every styled component in the system.
287
- *
288
- * Returns a styled-components interpolation function that:
289
- * 1. Reads the component's theme prop (via `key` or direct `theme`)
290
- * 2. Without breakpoints → renders plain CSS
291
- * 3. With breakpoints → normalizes, transforms (property-per-breakpoint →
292
- * breakpoint-per-property), optimizes (deduplicates identical breakpoints),
293
- * and wraps each breakpoint's styles in the appropriate `@media` query.
294
- */
295
286
  const themeCache = /* @__PURE__ */ new WeakMap();
296
287
  const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize = true }) => ({ theme = {}, ...props }) => {
297
288
  const internalTheme = customTheme || props[key];
@@ -308,8 +299,13 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
308
299
  `;
309
300
  const { media, sortedBreakpoints } = __VITUS_LABS__;
310
301
  let optimizedTheme;
311
- const cached = themeCache.get(internalTheme);
312
- if (cached && cached.breakpoints === sortedBreakpoints) optimizedTheme = cached.optimized;
302
+ const entry = themeCache.get(internalTheme);
303
+ const breakpointsMatch = entry?.breakpoints === sortedBreakpoints;
304
+ if (entry && breakpointsMatch && entry.rendered) {
305
+ const memoized = entry.rendered.get(theme);
306
+ if (memoized) return memoized;
307
+ }
308
+ if (entry && breakpointsMatch) optimizedTheme = entry.optimized;
313
309
  else {
314
310
  let helperTheme = internalTheme;
315
311
  if (normalize) helperTheme = normalizeTheme({
@@ -325,7 +321,8 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
325
321
  });
326
322
  themeCache.set(internalTheme, {
327
323
  breakpoints: sortedBreakpoints,
328
- optimized: optimizedTheme
324
+ optimized: optimizedTheme,
325
+ rendered: entry?.rendered
329
326
  });
330
327
  }
331
328
  const renderedTexts = sortedBreakpoints.map((item) => {
@@ -333,22 +330,27 @@ const makeItResponsive = ({ theme: customTheme, key = "", css, styles, normalize
333
330
  if (!breakpointTheme || !media) return "";
334
331
  return stringifyResult(renderStyles(breakpointTheme));
335
332
  });
336
- if (renderedTexts.every((t) => t !== null)) {
333
+ const canOptimize = renderedTexts.every((t) => t !== null);
334
+ let result;
335
+ if (canOptimize) {
337
336
  const deltas = optimizeBreakpointDeltas(renderedTexts);
338
- return sortedBreakpoints.map((item, i) => {
337
+ result = sortedBreakpoints.map((item, i) => {
339
338
  const css = deltas[i];
340
339
  if (!css || !media) return "";
341
340
  return media[item]`${css}`;
342
341
  });
343
- }
344
- return sortedBreakpoints.map((item) => {
342
+ } else result = sortedBreakpoints.map((item) => {
345
343
  const breakpointTheme = optimizedTheme[item];
346
344
  if (!breakpointTheme || !media) return "";
347
- const result = renderStyles(breakpointTheme);
345
+ const r = renderStyles(breakpointTheme);
348
346
  return media[item]`
349
- ${result};
350
- `;
347
+ ${r};
348
+ `;
351
349
  });
350
+ const cacheEntry = themeCache.get(internalTheme);
351
+ if (!cacheEntry.rendered) cacheEntry.rendered = /* @__PURE__ */ new WeakMap();
352
+ cacheEntry.rendered.set(theme, result);
353
+ return result;
352
354
  };
353
355
 
354
356
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/unistyle",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.cz>",
6
6
  "maintainers": [
@@ -51,7 +51,7 @@
51
51
  "node": ">= 18"
52
52
  },
53
53
  "peerDependencies": {
54
- "@vitus-labs/core": "2.0.0-beta.4",
54
+ "@vitus-labs/core": "2.1.0",
55
55
  "react": ">= 19",
56
56
  "react-native": ">= 0.76"
57
57
  },
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "devDependencies": {
64
64
  "@vitus-labs/core": "workspace:*",
65
- "@vitus-labs/tools-rolldown": "2.2.0",
66
- "@vitus-labs/tools-typescript": "2.1.0"
65
+ "@vitus-labs/tools-rolldown": "2.3.0",
66
+ "@vitus-labs/tools-typescript": "2.3.0"
67
67
  }
68
68
  }