@umber-style/react 0.2.0 → 0.3.0-alpha.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.
@@ -148,10 +148,23 @@ function ProviderScope({ prefix, given, theme, children }) {
148
148
  className
149
149
  ]);
150
150
  const scope = theme === void 0 ? above?.scope ?? null : wrapper ?? null;
151
- const below = react.useMemo(() => addMark(marks, prefix, { scope }), [
151
+ const nested = react.useMemo(() => {
152
+ if (isNested) return (0, _umber_style_core.mergeTheme)(above?.nested, given);
153
+ return theme === void 0 ? above?.nested : void 0;
154
+ }, [
155
+ isNested,
156
+ above,
157
+ given,
158
+ theme
159
+ ]);
160
+ const below = react.useMemo(() => addMark(marks, prefix, {
161
+ scope,
162
+ nested
163
+ }), [
152
164
  marks,
153
165
  prefix,
154
- scope
166
+ scope,
167
+ nested
155
168
  ]);
156
169
  const { contexts, holder } = readPrefixStyle(prefix);
157
170
  const outer = react.use(contexts.ThemeContext) ?? holder?.givenTheme;
@@ -189,7 +202,8 @@ function ProviderScope({ prefix, given, theme, children }) {
189
202
  return react.createElement(react.Fragment, null, styles.list.map(({ href, text }) => react.createElement("style", {
190
203
  key: href,
191
204
  href,
192
- precedence: prefix
205
+ precedence: prefix,
206
+ nonce: theme?.nonce
193
207
  }, text)), wrapper === void 0 ? content : react.createElement(wrapper.as, { className: wrapper.className }, content));
194
208
  }
195
209
  exports.ProviderScope = ProviderScope;
@@ -146,10 +146,23 @@ function ProviderScope({ prefix, given, theme, children }) {
146
146
  className
147
147
  ]);
148
148
  const scope = theme === void 0 ? above?.scope ?? null : wrapper ?? null;
149
- const below = React.useMemo(() => addMark(marks, prefix, { scope }), [
149
+ const nested = React.useMemo(() => {
150
+ if (isNested) return mergeTheme(above?.nested, given);
151
+ return theme === void 0 ? above?.nested : void 0;
152
+ }, [
153
+ isNested,
154
+ above,
155
+ given,
156
+ theme
157
+ ]);
158
+ const below = React.useMemo(() => addMark(marks, prefix, {
159
+ scope,
160
+ nested
161
+ }), [
150
162
  marks,
151
163
  prefix,
152
- scope
164
+ scope,
165
+ nested
153
166
  ]);
154
167
  const { contexts, holder } = readPrefixStyle(prefix);
155
168
  const outer = React.use(contexts.ThemeContext) ?? holder?.givenTheme;
@@ -187,7 +200,8 @@ function ProviderScope({ prefix, given, theme, children }) {
187
200
  return React.createElement(React.Fragment, null, styles.list.map(({ href, text }) => React.createElement("style", {
188
201
  key: href,
189
202
  href,
190
- precedence: prefix
203
+ precedence: prefix,
204
+ nonce: theme?.nonce
191
205
  }, text)), wrapper === void 0 ? content : React.createElement(wrapper.as, { className: wrapper.className }, content));
192
206
  }
193
207
  export { ProviderScope, addMark, claimPrefixStyle, createNestedStyles, createRootStyle, createThemeContexts, declareValues, getMarksContext, keepRootRule, readPrefixStyle };
@@ -16,9 +16,10 @@ let react_jsx_runtime = require("react/jsx-runtime");
16
16
  * the shape of its tokens when it has none (`adoptTheme`), which is not a base theme that a tree with no
17
17
  * provider reads.
18
18
  * - A nested provider renders its wrapper: the theme class of the theme it was given (with the boundary
19
- * and scheme markers that conditions use), the theme class of its merged theme (every variable, so that
20
- * it is right where its element is not inside the wrapper of the provider above, in a portal), and the
21
- * scope class, which has `display: contents`.
19
+ * and scheme markers that conditions use), the theme class of the themes of the nested providers above
20
+ * it and its own, merged (so that it is right where its element is not inside their wrappers, in a
21
+ * portal; the outermost theme is left out, as it is on `:root` or on the class of `<html>`, which reach
22
+ * every element), and the scope class, which has `display: contents`.
22
23
  * - With `isRoot` it renders no element and makes no rule: the app puts `themeClass(theme)` on an ancestor
23
24
  * of its own, usually `<html>`.
24
25
  *
@@ -48,10 +49,15 @@ function createThemeProvider({ engine: baseEngine, contexts: { ThemeContext, Vie
48
49
  const given = (0, react.useMemo)(() => (0, _umber_style_core.resolveThemeInput)(theme, outer ?? _umber_style_core.EMPTY_THEME), [theme, outer]);
49
50
  engine.adoptTheme(given);
50
51
  const merged = (0, react.useMemo)(() => (0, _umber_style_core.mergeTheme)(outer, given), [outer, given]);
52
+ const nested = (0, react.useMemo)(() => isNested ? (0, _umber_style_core.mergeTheme)(above.nested, given) : above?.nested, [
53
+ isNested,
54
+ above,
55
+ given
56
+ ]);
51
57
  const wrapper = (0, react.useMemo)(() => {
52
58
  if (!isNested) return void 0;
53
59
  const own = engine.themeClass(given, colorScheme);
54
- const full = engine.themeId(merged, colorScheme);
60
+ const full = engine.themeId(nested, colorScheme);
55
61
  return {
56
62
  as,
57
63
  className: [
@@ -65,16 +71,20 @@ function createThemeProvider({ engine: baseEngine, contexts: { ThemeContext, Vie
65
71
  engine,
66
72
  isNested,
67
73
  given,
68
- merged,
74
+ nested,
69
75
  colorScheme,
70
76
  className,
71
77
  as
72
78
  ]);
73
- const below = (0, react.useMemo)(() => require_ProviderScope.addMark(marks, key, { scope: wrapper ?? above?.scope ?? null }), [
79
+ const below = (0, react.useMemo)(() => require_ProviderScope.addMark(marks, key, {
80
+ scope: wrapper ?? above?.scope ?? null,
81
+ nested
82
+ }), [
74
83
  marks,
75
84
  key,
76
85
  wrapper,
77
- above
86
+ above,
87
+ nested
78
88
  ]);
79
89
  (0, react.useInsertionEffect)(() => {
80
90
  if (isOutermost) engine.declareRoot(merged, colorScheme);
@@ -16,9 +16,10 @@ import { jsx } from "react/jsx-runtime";
16
16
  * the shape of its tokens when it has none (`adoptTheme`), which is not a base theme that a tree with no
17
17
  * provider reads.
18
18
  * - A nested provider renders its wrapper: the theme class of the theme it was given (with the boundary
19
- * and scheme markers that conditions use), the theme class of its merged theme (every variable, so that
20
- * it is right where its element is not inside the wrapper of the provider above, in a portal), and the
21
- * scope class, which has `display: contents`.
19
+ * and scheme markers that conditions use), the theme class of the themes of the nested providers above
20
+ * it and its own, merged (so that it is right where its element is not inside their wrappers, in a
21
+ * portal; the outermost theme is left out, as it is on `:root` or on the class of `<html>`, which reach
22
+ * every element), and the scope class, which has `display: contents`.
22
23
  * - With `isRoot` it renders no element and makes no rule: the app puts `themeClass(theme)` on an ancestor
23
24
  * of its own, usually `<html>`.
24
25
  *
@@ -48,10 +49,15 @@ function createThemeProvider({ engine: baseEngine, contexts: { ThemeContext, Vie
48
49
  const given = useMemo(() => resolveThemeInput(theme, outer ?? EMPTY_THEME), [theme, outer]);
49
50
  engine.adoptTheme(given);
50
51
  const merged = useMemo(() => mergeTheme(outer, given), [outer, given]);
52
+ const nested = useMemo(() => isNested ? mergeTheme(above.nested, given) : above?.nested, [
53
+ isNested,
54
+ above,
55
+ given
56
+ ]);
51
57
  const wrapper = useMemo(() => {
52
58
  if (!isNested) return void 0;
53
59
  const own = engine.themeClass(given, colorScheme);
54
- const full = engine.themeId(merged, colorScheme);
60
+ const full = engine.themeId(nested, colorScheme);
55
61
  return {
56
62
  as,
57
63
  className: [
@@ -65,16 +71,20 @@ function createThemeProvider({ engine: baseEngine, contexts: { ThemeContext, Vie
65
71
  engine,
66
72
  isNested,
67
73
  given,
68
- merged,
74
+ nested,
69
75
  colorScheme,
70
76
  className,
71
77
  as
72
78
  ]);
73
- const below = useMemo(() => addMark(marks, key, { scope: wrapper ?? above?.scope ?? null }), [
79
+ const below = useMemo(() => addMark(marks, key, {
80
+ scope: wrapper ?? above?.scope ?? null,
81
+ nested
82
+ }), [
74
83
  marks,
75
84
  key,
76
85
  wrapper,
77
- above
86
+ above,
87
+ nested
78
88
  ]);
79
89
  useInsertionEffect(() => {
80
90
  if (isOutermost) engine.declareRoot(merged, colorScheme);
@@ -86,7 +86,8 @@ function createThemeProvider(engine, { readFirstSlot, readBaseTheme }) {
86
86
  properties: text.properties,
87
87
  isWhole,
88
88
  ...base && { base },
89
- styles: require_styleElements.collectStyleTexts(cache, others)
89
+ styles: require_styleElements.collectStyleTexts(cache, others),
90
+ ...cache.nonce !== void 0 && { nonce: cache.nonce }
90
91
  };
91
92
  };
92
93
  const described = /* @__PURE__ */ new WeakMap();
@@ -86,7 +86,8 @@ function createThemeProvider(engine, { readFirstSlot, readBaseTheme }) {
86
86
  properties: text.properties,
87
87
  isWhole,
88
88
  ...base && { base },
89
- styles: collectStyleTexts(cache, others)
89
+ styles: collectStyleTexts(cache, others),
90
+ ...cache.nonce !== void 0 && { nonce: cache.nonce }
90
91
  };
91
92
  };
92
93
  const described = /* @__PURE__ */ new WeakMap();
@@ -6,6 +6,7 @@ const require_styleElements = require("./styleElements.cjs");
6
6
  const require_styled = require("./styled.cjs");
7
7
  const require_ThemeProvider = require("./ThemeProvider.cjs");
8
8
  const require_ThemeValue = require("./ThemeValue.cjs");
9
+ const require_useStyleValue = require("./useStyleValue.cjs");
9
10
  // src/createStyle.ts
10
11
  /** The contexts of the prefix of `engine`, which every style of that prefix shares; this engine's base theme is the one a provider of the server build merges over, unless another style of the prefix gave one. */
11
12
  function readSharedContexts(engine) {
@@ -34,6 +35,7 @@ function bindEngine(engine, { hasServerStyleElements = true } = {}, contexts = r
34
35
  styled: require_styled.createStyled(engine, useThemeView, renderStyleElements),
35
36
  StyleSheet: { create },
36
37
  useStyle,
38
+ useStyleValue: require_useStyleValue.createUseStyleValue(() => engine.cache),
37
39
  apply: (...entries) => ({ className: ((0, _umber_style_core.findEntryCache)(entries) ?? engine.cache).css(...entries) || void 0 }),
38
40
  css: ((...args) => (0, _umber_style_core.createCssEntry)(engine.cache, args)),
39
41
  ThemeProvider: require_ThemeProvider.createThemeProvider({
@@ -6,6 +6,7 @@ import { createGlobalElements, createGlobalMarkerElements, createStampElement, c
6
6
  import { createStyled } from "./styled.mjs";
7
7
  import { createThemeProvider } from "./ThemeProvider.mjs";
8
8
  import { createThemeValue } from "./ThemeValue.mjs";
9
+ import { createUseStyleValue } from "./useStyleValue.mjs";
9
10
  // src/createStyle.ts
10
11
  /** The contexts of the prefix of `engine`, which every style of that prefix shares; this engine's base theme is the one a provider of the server build merges over, unless another style of the prefix gave one. */
11
12
  function readSharedContexts(engine) {
@@ -34,6 +35,7 @@ function bindEngine(engine, { hasServerStyleElements = true } = {}, contexts = r
34
35
  styled: createStyled(engine, useThemeView, renderStyleElements),
35
36
  StyleSheet: { create },
36
37
  useStyle,
38
+ useStyleValue: createUseStyleValue(() => engine.cache),
37
39
  apply: (...entries) => ({ className: (findEntryCache(entries) ?? engine.cache).css(...entries) || void 0 }),
38
40
  css: ((...args) => createCssEntry(engine.cache, args)),
39
41
  ThemeProvider: createThemeProvider({
@@ -3,6 +3,7 @@ const require_Global_server = require("./Global.server.cjs");
3
3
  const require_serverContext = require("./serverContext.cjs");
4
4
  const require_styled_server = require("./styled.server.cjs");
5
5
  const require_ThemeProvider_server = require("./ThemeProvider.server.cjs");
6
+ const require_useStyleValue_server = require("./useStyleValue.server.cjs");
6
7
  // src/createStyle.server.ts
7
8
  /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
8
9
  function bindEngine(engine, cache) {
@@ -34,6 +35,7 @@ function bindEngine(engine, cache) {
34
35
  styled: require_styled_server.createStyled(engine, readViewTheme),
35
36
  StyleSheet: { create },
36
37
  useStyle,
38
+ useStyleValue: require_useStyleValue_server.createServerStyleValue(engine.cache),
37
39
  apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
38
40
  css: ((...args) => (0, _umber_style_core.createCssEntry)(engine.cache, args)),
39
41
  ThemeProvider: require_ThemeProvider_server.createThemeProvider(engine, {
@@ -3,6 +3,7 @@ import { createGlobal } from "./Global.server.mjs";
3
3
  import { createRequestSlot } from "./serverContext.mjs";
4
4
  import { createStyled } from "./styled.server.mjs";
5
5
  import { createThemeProvider } from "./ThemeProvider.server.mjs";
6
+ import { createServerStyleValue } from "./useStyleValue.server.mjs";
6
7
  // src/createStyle.server.ts
7
8
  /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
8
9
  function bindEngine(engine, cache) {
@@ -34,6 +35,7 @@ function bindEngine(engine, cache) {
34
35
  styled: createStyled(engine, readViewTheme),
35
36
  StyleSheet: { create },
36
37
  useStyle,
38
+ useStyleValue: createServerStyleValue(engine.cache),
37
39
  apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
38
40
  css: ((...args) => createCssEntry(engine.cache, args)),
39
41
  ThemeProvider: createThemeProvider(engine, {
@@ -33,6 +33,7 @@ function createDefaultStyle() {
33
33
  const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
34
34
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
35
35
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
36
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
36
37
  function useTheme() {
37
38
  return getStyle().useTheme();
38
39
  }
@@ -54,6 +55,7 @@ function createDefaultStyle() {
54
55
  styled,
55
56
  StyleSheet,
56
57
  useStyle,
58
+ useStyleValue,
57
59
  useTheme,
58
60
  ThemeProvider,
59
61
  ThemeScope,
@@ -1,4 +1,4 @@
1
- import { DefaultStyleOptions, GlobalProps, SheetDefinition, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.cjs";
1
+ import { DefaultStyleOptions, GlobalProps, SheetDefinition, StyleValueSetter, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.cjs";
2
2
  import { WebStyleObject } from "@umber-style/core";
3
3
  /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
4
4
  export declare function createDefaultStyle(): {
@@ -13,6 +13,7 @@ export declare function createDefaultStyle(): {
13
13
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
14
14
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
15
15
  };
16
+ useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter];
16
17
  useTheme: () => Theme$1;
17
18
  ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
19
  ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
@@ -1,4 +1,4 @@
1
- import { DefaultStyleOptions, GlobalProps, SheetDefinition, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.mjs";
1
+ import { DefaultStyleOptions, GlobalProps, SheetDefinition, StyleValueSetter, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.mjs";
2
2
  import { WebStyleObject } from "@umber-style/core";
3
3
  /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
4
4
  export declare function createDefaultStyle(): {
@@ -13,6 +13,7 @@ export declare function createDefaultStyle(): {
13
13
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
14
14
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
15
15
  };
16
+ useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter];
16
17
  useTheme: () => Theme$1;
17
18
  ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
19
  ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
@@ -33,6 +33,7 @@ function createDefaultStyle() {
33
33
  const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
34
34
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
35
35
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
36
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
36
37
  function useTheme() {
37
38
  return getStyle().useTheme();
38
39
  }
@@ -54,6 +55,7 @@ function createDefaultStyle() {
54
55
  styled,
55
56
  StyleSheet,
56
57
  useStyle,
58
+ useStyleValue,
57
59
  useTheme,
58
60
  ThemeProvider,
59
61
  ThemeScope,
@@ -21,6 +21,7 @@ function createDefaultStyle() {
21
21
  const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
22
22
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
23
23
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
24
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
24
25
  function useTheme() {
25
26
  return getStyle().useTheme();
26
27
  }
@@ -36,6 +37,7 @@ function createDefaultStyle() {
36
37
  styled,
37
38
  StyleSheet,
38
39
  useStyle,
40
+ useStyleValue,
39
41
  useTheme,
40
42
  readTheme: useTheme,
41
43
  ThemeProvider,
@@ -1,4 +1,4 @@
1
- import { DefaultStyleOptions, GlobalProps, ServerStyle, SheetDefinition, Styled, Theme as Theme$1, WebThemeProviderProps } from "./types.cjs";
1
+ import { DefaultStyleOptions, GlobalProps, ServerStyle, SheetDefinition, StyleValueSetter, Styled, Theme as Theme$1, WebThemeProviderProps } from "./types.cjs";
2
2
  import { WebStyleObject } from "@umber-style/core";
3
3
  /** Makes the default styling for server components: one engine, made on first use. */
4
4
  export declare function createDefaultStyle(): {
@@ -13,6 +13,7 @@ export declare function createDefaultStyle(): {
13
13
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
14
14
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
15
15
  };
16
+ useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter];
16
17
  useTheme: () => Theme$1;
17
18
  readTheme: () => Theme$1;
18
19
  ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
@@ -1,4 +1,4 @@
1
- import { DefaultStyleOptions, GlobalProps, ServerStyle, SheetDefinition, Styled, Theme as Theme$1, WebThemeProviderProps } from "./types.mjs";
1
+ import { DefaultStyleOptions, GlobalProps, ServerStyle, SheetDefinition, StyleValueSetter, Styled, Theme as Theme$1, WebThemeProviderProps } from "./types.mjs";
2
2
  import { WebStyleObject } from "@umber-style/core";
3
3
  /** Makes the default styling for server components: one engine, made on first use. */
4
4
  export declare function createDefaultStyle(): {
@@ -13,6 +13,7 @@ export declare function createDefaultStyle(): {
13
13
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
14
14
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
15
15
  };
16
+ useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter];
16
17
  useTheme: () => Theme$1;
17
18
  readTheme: () => Theme$1;
18
19
  ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
@@ -21,6 +21,7 @@ function createDefaultStyle() {
21
21
  const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
22
22
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
23
23
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
24
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
24
25
  function useTheme() {
25
26
  return getStyle().useTheme();
26
27
  }
@@ -36,6 +37,7 @@ function createDefaultStyle() {
36
37
  styled,
37
38
  StyleSheet,
38
39
  useStyle,
40
+ useStyleValue,
39
41
  useTheme,
40
42
  readTheme: useTheme,
41
43
  ThemeProvider,
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ const require_defaultStyle = require("./defaultStyle.cjs");
4
4
  const require_CacheProvider = require("./CacheProvider.cjs");
5
5
  const require_useMediaQuery = require("./useMediaQuery.cjs");
6
6
  const require_createStyle = require("./createStyle.cjs");
7
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.default-style@1", require_defaultStyle.createDefaultStyle);
7
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.default-style@1", require_defaultStyle.createDefaultStyle);
8
8
  exports.CacheProvider = require_CacheProvider.CacheProvider;
9
9
  exports.Global = Global;
10
10
  exports.StyleSheet = StyleSheet;
@@ -66,6 +66,7 @@ Object.defineProperty(exports, "subtract", {
66
66
  exports.themeClass = themeClass;
67
67
  exports.useMediaQuery = require_useMediaQuery.useMediaQuery;
68
68
  exports.useStyle = useStyle;
69
+ exports.useStyleValue = useStyleValue;
69
70
  exports.useTheme = useTheme;
70
71
  exports.useThemeClass = useThemeClass;
71
72
  exports.when = when;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
2
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
3
3
  import { CacheProvider } from "./CacheProvider.cjs";
4
4
  import { MediaQueryOptions, useMediaQuery } from "./useMediaQuery.cjs";
5
5
  import { bindEngine, createStyle } from "./createStyle.cjs";
@@ -10,7 +10,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
10
10
  }, useStyle: {
11
11
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
12
12
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
13
- }, useTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, useThemeClass: () => string | undefined, ThemeContext: import("react").Context<Theme | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
13
+ }, useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter], useTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, useThemeClass: () => string | undefined, ThemeContext: import("react").Context<Theme | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
14
14
  className?: string;
15
15
  }, css: CssFunction, themeClass: (theme: {
16
16
  readonly _theme?: never;
@@ -25,4 +25,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
25
25
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
26
26
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
27
27
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
28
- export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
28
+ export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
1
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
2
2
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  import { CacheProvider } from "./CacheProvider.mjs";
4
4
  import { MediaQueryOptions, useMediaQuery } from "./useMediaQuery.mjs";
@@ -10,7 +10,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
10
10
  }, useStyle: {
11
11
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
12
12
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
13
- }, useTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, useThemeClass: () => string | undefined, ThemeContext: import("react").Context<Theme | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
13
+ }, useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter], useTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, useThemeClass: () => string | undefined, ThemeContext: import("react").Context<Theme | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
14
14
  className?: string;
15
15
  }, css: CssFunction, themeClass: (theme: {
16
16
  readonly _theme?: never;
@@ -25,4 +25,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
25
25
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
26
26
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
27
27
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
28
- export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
28
+ export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
package/dist/index.mjs CHANGED
@@ -3,5 +3,5 @@ import { createDefaultStyle } from "./defaultStyle.mjs";
3
3
  import { CacheProvider } from "./CacheProvider.mjs";
4
4
  import { useMediaQuery } from "./useMediaQuery.mjs";
5
5
  import { bindEngine, createStyle } from "./createStyle.mjs";
6
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.default-style@1", createDefaultStyle);
7
- export { CacheProvider, Global, StyleSheet, ThemeContext, ThemeProvider, ThemeScope, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useMediaQuery, useStyle, useTheme, useThemeClass, when, whenScheme };
6
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.default-style@1", createDefaultStyle);
7
+ export { CacheProvider, Global, StyleSheet, ThemeContext, ThemeProvider, ThemeScope, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useMediaQuery, useStyle, useStyleValue, useTheme, useThemeClass, when, whenScheme };
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _umber_style_core = require("@umber-style/core");
3
3
  const require_defaultStyle_server = require("./defaultStyle.server.cjs");
4
4
  const require_createStyle_server = require("./createStyle.server.cjs");
5
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.server-default-style@1", require_defaultStyle_server.createDefaultStyle);
5
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.server-default-style@1", require_defaultStyle_server.createDefaultStyle);
6
6
  exports.Global = Global;
7
7
  exports.StyleSheet = StyleSheet;
8
8
  exports.ThemeProvider = ThemeProvider;
@@ -61,6 +61,7 @@ Object.defineProperty(exports, "subtract", {
61
61
  });
62
62
  exports.themeClass = themeClass;
63
63
  exports.useStyle = useStyle;
64
+ exports.useStyleValue = useStyleValue;
64
65
  exports.useTheme = useTheme;
65
66
  exports.when = when;
66
67
  exports.whenScheme = whenScheme;
@@ -1,5 +1,5 @@
1
1
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
2
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
3
3
  import { bindEngine, createStyle } from "./createStyle.server.cjs";
4
4
  import { createDefaultStyle } from "./defaultStyle.server.cjs";
5
5
  export declare const configure: (options: DefaultStyleOptions) => void, getEngine: () => import("@umber-style/core").Engine<Theme>, styled: Styled<Theme>, StyleSheet: {
@@ -8,7 +8,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
8
8
  }, useStyle: {
9
9
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
10
10
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
11
- }, useTheme: () => Theme, readTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
11
+ }, useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter], useTheme: () => Theme, readTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
12
12
  className?: string;
13
13
  }, css: CssFunction, themeClass: (theme: {
14
14
  readonly _theme?: never;
@@ -23,4 +23,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
23
23
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
24
24
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
25
25
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
26
- export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
26
+ export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
@@ -1,4 +1,4 @@
1
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
1
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
2
2
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  import { bindEngine, createStyle } from "./createStyle.server.mjs";
4
4
  import { createDefaultStyle } from "./defaultStyle.server.mjs";
@@ -8,7 +8,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
8
8
  }, useStyle: {
9
9
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
10
10
  <S extends import("@umber-style/core").SheetStyles>(sheet: SheetDefinition<S, import("@umber-style/core").SheetEntry>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
11
- }, useTheme: () => Theme, readTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
11
+ }, useStyleValue: (initial: number, unit?: string) => [import("@umber-style/core").LiveValue, StyleValueSetter], useTheme: () => Theme, readTheme: () => Theme, ThemeProvider: (props: WebThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
12
12
  className?: string;
13
13
  }, css: CssFunction, themeClass: (theme: {
14
14
  readonly _theme?: never;
@@ -23,4 +23,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
23
23
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
24
24
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
25
25
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
26
- export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
26
+ export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, type StyleTypeOptions, StyleValueSetter, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
@@ -1,5 +1,5 @@
1
1
  import { add, alpha, at, divide, multiply, negate, readSharedState, subtract } from "@umber-style/core";
2
2
  import { createDefaultStyle } from "./defaultStyle.server.mjs";
3
3
  import { bindEngine, createStyle } from "./createStyle.server.mjs";
4
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.server-default-style@1", createDefaultStyle);
5
- export { Global, StyleSheet, ThemeProvider, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, readTheme, styled, subtract, themeClass, useStyle, useTheme, when, whenScheme };
4
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.server-default-style@1", createDefaultStyle);
5
+ export { Global, StyleSheet, ThemeProvider, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, readTheme, styled, subtract, themeClass, useStyle, useStyleValue, useTheme, when, whenScheme };
@@ -6,23 +6,37 @@ function isPlainObject(value) {
6
6
  const prototype = Object.getPrototypeOf(value);
7
7
  return prototype === Object.prototype || prototype === null;
8
8
  }
9
- /** `value` as plain data, the same value when it already is; `DROPPED` for a value that cannot cross. */
10
- function toPlain(value, path, dropped) {
9
+ /**
10
+ * `value` as plain data, the same value when it already is; `DROPPED` for a value that cannot cross.
11
+ * `ancestors` holds the objects that `value` is inside of: one of them met again is a cycle, left out.
12
+ */
13
+ function toPlain(value, path, dropped, ancestors) {
11
14
  if (typeof value === "function" || typeof value === "symbol") {
12
15
  dropped.push(path);
13
16
  return DROPPED;
14
17
  }
15
18
  if (typeof value !== "object" || value === null) return value;
19
+ if (ancestors.has(value)) {
20
+ dropped.push(path);
21
+ return DROPPED;
22
+ }
23
+ ancestors.add(value);
24
+ const plain = toPlainContainer(value, path, dropped, ancestors);
25
+ ancestors.delete(value);
26
+ return plain;
27
+ }
28
+ /** `toPlain` of an object: an array, a plain object, or another object, which cannot cross. */
29
+ function toPlainContainer(value, path, dropped, ancestors) {
16
30
  const joinPath = (key) => path === "" ? String(key) : `${path}.${key}`;
17
31
  if (Array.isArray(value)) {
18
- const plain = value.map((item, index) => toPlain(item, joinPath(index), dropped)).map((item) => item === DROPPED ? void 0 : item);
32
+ const plain = value.map((item, index) => toPlain(item, joinPath(index), dropped, ancestors)).map((item) => item === DROPPED ? void 0 : item);
19
33
  return plain.every((item, index) => item === value[index]) ? value : plain;
20
34
  }
21
35
  if (!isPlainObject(value)) {
22
36
  dropped.push(path);
23
37
  return DROPPED;
24
38
  }
25
- const entries = Object.entries(value).map(([key, member]) => [key, toPlain(member, joinPath(key), dropped)]);
39
+ const entries = Object.entries(value).map(([key, member]) => [key, toPlain(member, joinPath(key), dropped, ancestors)]);
26
40
  const kept = entries.filter(([, member]) => member !== DROPPED);
27
41
  return Object.getPrototypeOf(value) === Object.prototype && kept.length === entries.length && kept.every(([key, member]) => member === value[key]) ? value : Object.fromEntries(kept);
28
42
  }
@@ -30,14 +44,15 @@ const plainThemes = /* @__PURE__ */ new WeakMap();
30
44
  /**
31
45
  * The plain data of `theme`: strings, numbers, booleans, `null`, `undefined`, lists and plain objects,
32
46
  * deeply. A function, a symbol and an object that is not plain (a class instance, a `Date`, a `Map`) are
33
- * left out, and their paths listed. Only own enumerable members are read. Made once for each theme
47
+ * left out, and their paths listed, and so is a member that refers back to an object it is inside of (a
48
+ * cycle). Only own enumerable members are read. Made once for each theme
34
49
  * object, so a payload that names one theme in several places holds it once.
35
50
  */
36
51
  function toPlainTheme(theme) {
37
52
  let found = plainThemes.get(theme);
38
53
  if (found === void 0) {
39
54
  const dropped = [];
40
- const plain = toPlain(theme, "", dropped);
55
+ const plain = toPlain(theme, "", dropped, /* @__PURE__ */ new Set());
41
56
  found = {
42
57
  theme: plain === DROPPED ? {} : plain,
43
58
  dropped
@@ -6,23 +6,37 @@ function isPlainObject(value) {
6
6
  const prototype = Object.getPrototypeOf(value);
7
7
  return prototype === Object.prototype || prototype === null;
8
8
  }
9
- /** `value` as plain data, the same value when it already is; `DROPPED` for a value that cannot cross. */
10
- function toPlain(value, path, dropped) {
9
+ /**
10
+ * `value` as plain data, the same value when it already is; `DROPPED` for a value that cannot cross.
11
+ * `ancestors` holds the objects that `value` is inside of: one of them met again is a cycle, left out.
12
+ */
13
+ function toPlain(value, path, dropped, ancestors) {
11
14
  if (typeof value === "function" || typeof value === "symbol") {
12
15
  dropped.push(path);
13
16
  return DROPPED;
14
17
  }
15
18
  if (typeof value !== "object" || value === null) return value;
19
+ if (ancestors.has(value)) {
20
+ dropped.push(path);
21
+ return DROPPED;
22
+ }
23
+ ancestors.add(value);
24
+ const plain = toPlainContainer(value, path, dropped, ancestors);
25
+ ancestors.delete(value);
26
+ return plain;
27
+ }
28
+ /** `toPlain` of an object: an array, a plain object, or another object, which cannot cross. */
29
+ function toPlainContainer(value, path, dropped, ancestors) {
16
30
  const joinPath = (key) => path === "" ? String(key) : `${path}.${key}`;
17
31
  if (Array.isArray(value)) {
18
- const plain = value.map((item, index) => toPlain(item, joinPath(index), dropped)).map((item) => item === DROPPED ? void 0 : item);
32
+ const plain = value.map((item, index) => toPlain(item, joinPath(index), dropped, ancestors)).map((item) => item === DROPPED ? void 0 : item);
19
33
  return plain.every((item, index) => item === value[index]) ? value : plain;
20
34
  }
21
35
  if (!isPlainObject(value)) {
22
36
  dropped.push(path);
23
37
  return DROPPED;
24
38
  }
25
- const entries = Object.entries(value).map(([key, member]) => [key, toPlain(member, joinPath(key), dropped)]);
39
+ const entries = Object.entries(value).map(([key, member]) => [key, toPlain(member, joinPath(key), dropped, ancestors)]);
26
40
  const kept = entries.filter(([, member]) => member !== DROPPED);
27
41
  return Object.getPrototypeOf(value) === Object.prototype && kept.length === entries.length && kept.every(([key, member]) => member === value[key]) ? value : Object.fromEntries(kept);
28
42
  }
@@ -30,14 +44,15 @@ const plainThemes = /* @__PURE__ */ new WeakMap();
30
44
  /**
31
45
  * The plain data of `theme`: strings, numbers, booleans, `null`, `undefined`, lists and plain objects,
32
46
  * deeply. A function, a symbol and an object that is not plain (a class instance, a `Date`, a `Map`) are
33
- * left out, and their paths listed. Only own enumerable members are read. Made once for each theme
47
+ * left out, and their paths listed, and so is a member that refers back to an object it is inside of (a
48
+ * cycle). Only own enumerable members are read. Made once for each theme
34
49
  * object, so a payload that names one theme in several places holds it once.
35
50
  */
36
51
  function toPlainTheme(theme) {
37
52
  let found = plainThemes.get(theme);
38
53
  if (found === void 0) {
39
54
  const dropped = [];
40
- const plain = toPlain(theme, "", dropped);
55
+ const plain = toPlain(theme, "", dropped, /* @__PURE__ */ new Set());
41
56
  found = {
42
57
  theme: plain === DROPPED ? {} : plain,
43
58
  dropped
@@ -1,11 +1,17 @@
1
1
  let react = require("react");
2
2
  let _umber_style_core = require("@umber-style/core");
3
3
  // src/styleElements.ts
4
- /** The `<style href precedence>` element of `style`, in the precedence of the prefix of `cache`. */
4
+ /**
5
+ * The `<style href precedence>` element of `style`, in the precedence of the prefix of `cache`, with the
6
+ * nonce of the cache when it has one: React keeps the rules of such an element only when its nonce is the
7
+ * style nonce of the render (`nonce: { style }` of React's server render), and sets it on the element it
8
+ * makes in the browser.
9
+ */
5
10
  const toElement = (cache) => ({ href, text }) => (0, react.createElement)("style", {
6
11
  key: href,
7
12
  href,
8
- precedence: cache.prefix
13
+ precedence: cache.prefix,
14
+ nonce: cache.nonce
9
15
  }, text);
10
16
  /**
11
17
  * The style elements of the animations in `names` that `sent` does not hold yet, which it adds them to:
@@ -1,11 +1,17 @@
1
1
  import { createElement } from "react";
2
2
  import { createGlobalMarker } from "@umber-style/core";
3
3
  // src/styleElements.ts
4
- /** The `<style href precedence>` element of `style`, in the precedence of the prefix of `cache`. */
4
+ /**
5
+ * The `<style href precedence>` element of `style`, in the precedence of the prefix of `cache`, with the
6
+ * nonce of the cache when it has one: React keeps the rules of such an element only when its nonce is the
7
+ * style nonce of the render (`nonce: { style }` of React's server render), and sets it on the element it
8
+ * makes in the browser.
9
+ */
5
10
  const toElement = (cache) => ({ href, text }) => createElement("style", {
6
11
  key: href,
7
12
  href,
8
- precedence: cache.prefix
13
+ precedence: cache.prefix,
14
+ nonce: cache.nonce
9
15
  }, text);
10
16
  /**
11
17
  * The style elements of the animations in `names` that `sent` does not hold yet, which it adds them to:
package/dist/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ComponentProps, Context, ElementType, FunctionComponent, JSX, ReactElement, ReactNode } from "react";
2
- import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, DeepPartial, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StyleTypeOptions as StyleTypeOptions$1, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, ThemeKey as ThemeKey$1, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
2
+ import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, DeepPartial, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, LiveValue, LiveValue as LiveValue$1, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StyleTypeOptions as StyleTypeOptions$1, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, ThemeKey as ThemeKey$1, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
3
3
  /** What only the client build of the React binding takes: it can render the style of its classes on a server. */
4
4
  export interface ServerStyleOptions {
5
5
  /**
@@ -298,8 +298,21 @@ export interface ServerStyle<T> extends Omit<WebStyle<T>, 'useTheme' | 'ThemeCon
298
298
  /** Another name of `useTheme` in this build. */
299
299
  readTheme(): T;
300
300
  }
301
+ /** The setter of `useStyleValue`: a new number, or a function of the number before. */
302
+ export type StyleValueSetter = (next: number | ((previous: number) => number)) => void;
301
303
  /** The styling of the client build of the web binding: what `createStyle` returns, and the default style. */
302
304
  export interface WebStyle<T> extends Omit<Style<T, SheetEntry$1>, 'ThemeProvider' | 'apply'> {
305
+ /**
306
+ * A number that a style reads through a CSS variable of its own, and its setter, as the state hook of React gives a
307
+ * state: `const [left, setLeft] = useStyleValue(0, '%')`. In a style the value is the reference to the
308
+ * variable (`${left}`, or an operand of `add`, `multiply` and the other helpers), so the class does
309
+ * not change when the number does; `setLeft(next)` changes the declaration of the variable in place,
310
+ * and renders nothing. `left.get()` is the number now. The number is written with `unit` after it,
311
+ * or as it is without one. Its rule is on `:root`, in the theme layer, while the component is mounted;
312
+ * the reference falls back to the first number, which a server render shows with no rule. In the
313
+ * server components build the setter does nothing (a warning in development).
314
+ */
315
+ useStyleValue(initial: number, unit?: string): [LiveValue$1, StyleValueSetter];
303
316
  /** The props that apply sheet entries (or class names) to a plain element: a class name. */
304
317
  apply(...entries: (SheetEntry$1 | string | null | undefined | false)[]): {
305
318
  className?: string;
@@ -329,4 +342,4 @@ export interface WebStyle<T> extends Omit<Style<T, SheetEntry$1>, 'ThemeProvider
329
342
  /** The cache of the engine, which holds the rules. */
330
343
  cache: Cache;
331
344
  }
332
- export type { AlphaColor, CSSObject, ComponentSelector, CssArgument, GlobalInput, GlobalStyleObject, GlobalStyles, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, SchemeKey, SchemeName, SerializedStyles, SheetEntry, StaticTemplateValue, StyleObject, StyleTypeOptions, TemplateValue, ThemeInput, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject };
345
+ export type { AlphaColor, CSSObject, ComponentSelector, CssArgument, GlobalInput, GlobalStyleObject, GlobalStyles, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, SchemeKey, SchemeName, SerializedStyles, SheetEntry, StaticTemplateValue, StyleObject, StyleTypeOptions, TemplateValue, ThemeInput, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject };
package/dist/types.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ComponentProps, Context, ElementType, FunctionComponent, JSX, ReactElement, ReactNode } from "react";
2
- import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, DeepPartial, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StyleTypeOptions as StyleTypeOptions$1, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, ThemeKey as ThemeKey$1, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
2
+ import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, DeepPartial, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, LiveValue, LiveValue as LiveValue$1, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StyleTypeOptions as StyleTypeOptions$1, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, ThemeKey as ThemeKey$1, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
3
3
  /** What only the client build of the React binding takes: it can render the style of its classes on a server. */
4
4
  export interface ServerStyleOptions {
5
5
  /**
@@ -298,8 +298,21 @@ export interface ServerStyle<T> extends Omit<WebStyle<T>, 'useTheme' | 'ThemeCon
298
298
  /** Another name of `useTheme` in this build. */
299
299
  readTheme(): T;
300
300
  }
301
+ /** The setter of `useStyleValue`: a new number, or a function of the number before. */
302
+ export type StyleValueSetter = (next: number | ((previous: number) => number)) => void;
301
303
  /** The styling of the client build of the web binding: what `createStyle` returns, and the default style. */
302
304
  export interface WebStyle<T> extends Omit<Style<T, SheetEntry$1>, 'ThemeProvider' | 'apply'> {
305
+ /**
306
+ * A number that a style reads through a CSS variable of its own, and its setter, as the state hook of React gives a
307
+ * state: `const [left, setLeft] = useStyleValue(0, '%')`. In a style the value is the reference to the
308
+ * variable (`${left}`, or an operand of `add`, `multiply` and the other helpers), so the class does
309
+ * not change when the number does; `setLeft(next)` changes the declaration of the variable in place,
310
+ * and renders nothing. `left.get()` is the number now. The number is written with `unit` after it,
311
+ * or as it is without one. Its rule is on `:root`, in the theme layer, while the component is mounted;
312
+ * the reference falls back to the first number, which a server render shows with no rule. In the
313
+ * server components build the setter does nothing (a warning in development).
314
+ */
315
+ useStyleValue(initial: number, unit?: string): [LiveValue$1, StyleValueSetter];
303
316
  /** The props that apply sheet entries (or class names) to a plain element: a class name. */
304
317
  apply(...entries: (SheetEntry$1 | string | null | undefined | false)[]): {
305
318
  className?: string;
@@ -329,4 +342,4 @@ export interface WebStyle<T> extends Omit<Style<T, SheetEntry$1>, 'ThemeProvider
329
342
  /** The cache of the engine, which holds the rules. */
330
343
  cache: Cache;
331
344
  }
332
- export type { AlphaColor, CSSObject, ComponentSelector, CssArgument, GlobalInput, GlobalStyleObject, GlobalStyles, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, SchemeKey, SchemeName, SerializedStyles, SheetEntry, StaticTemplateValue, StyleObject, StyleTypeOptions, TemplateValue, ThemeInput, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject };
345
+ export type { AlphaColor, CSSObject, ComponentSelector, CssArgument, GlobalInput, GlobalStyleObject, GlobalStyles, InterpolationResult, Keyframes, KeyframesSteps, LiveValue, NestedKey, SchemeKey, SchemeName, SerializedStyles, SheetEntry, StaticTemplateValue, StyleObject, StyleTypeOptions, TemplateValue, ThemeInput, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject };
@@ -0,0 +1,40 @@
1
+ let react = require("react");
2
+ let _umber_style_core = require("@umber-style/core");
3
+ const require_CacheProvider = require("./CacheProvider.cjs");
4
+ // src/useStyleValue.ts
5
+ /** The state of a value of the variable `name` in `cache`, which holds `initial` written with `unit`. */
6
+ function createValueState(cache, name, initial, unit) {
7
+ const value = (0, _umber_style_core.createLiveValue)(name, initial, unit);
8
+ let rule;
9
+ return {
10
+ value,
11
+ set: (next) => {
12
+ const text = (0, _umber_style_core.writeLiveValue)(value, typeof next === "function" ? next(value.get()) : next);
13
+ rule?.set(text);
14
+ },
15
+ mount: () => {
16
+ const declared = (0, _umber_style_core.declareLiveValue)(cache, value);
17
+ rule = declared;
18
+ return () => {
19
+ declared.remove();
20
+ rule = void 0;
21
+ };
22
+ }
23
+ };
24
+ }
25
+ /**
26
+ * Makes `useStyleValue` for the cache `readCache` gives (the engine's), or the one of a `CacheProvider`
27
+ * above. The value is made once for the component, with a variable named from its `useId`, so that the
28
+ * server and the browser name it alike; its rule is declared while the component is mounted, with the
29
+ * number it holds then, and removed when it unmounts.
30
+ */
31
+ function createUseStyleValue(readCache) {
32
+ return function useStyleValue(initial, unit) {
33
+ const id = (0, react.useId)();
34
+ const cache = require_CacheProvider.useProvidedCache() ?? readCache();
35
+ const [state] = (0, react.useState)(() => createValueState(cache, `--${cache.prefix}-value-${(0, _umber_style_core.hashString)(id)}`, initial, unit));
36
+ (0, react.useInsertionEffect)(state.mount, [state]);
37
+ return [state.value, state.set];
38
+ };
39
+ }
40
+ exports.createUseStyleValue = createUseStyleValue;
@@ -0,0 +1,40 @@
1
+ import { useId, useInsertionEffect, useState } from "react";
2
+ import { createLiveValue, declareLiveValue, hashString, writeLiveValue } from "@umber-style/core";
3
+ import { useProvidedCache } from "./CacheProvider.mjs";
4
+ // src/useStyleValue.ts
5
+ /** The state of a value of the variable `name` in `cache`, which holds `initial` written with `unit`. */
6
+ function createValueState(cache, name, initial, unit) {
7
+ const value = createLiveValue(name, initial, unit);
8
+ let rule;
9
+ return {
10
+ value,
11
+ set: (next) => {
12
+ const text = writeLiveValue(value, typeof next === "function" ? next(value.get()) : next);
13
+ rule?.set(text);
14
+ },
15
+ mount: () => {
16
+ const declared = declareLiveValue(cache, value);
17
+ rule = declared;
18
+ return () => {
19
+ declared.remove();
20
+ rule = void 0;
21
+ };
22
+ }
23
+ };
24
+ }
25
+ /**
26
+ * Makes `useStyleValue` for the cache `readCache` gives (the engine's), or the one of a `CacheProvider`
27
+ * above. The value is made once for the component, with a variable named from its `useId`, so that the
28
+ * server and the browser name it alike; its rule is declared while the component is mounted, with the
29
+ * number it holds then, and removed when it unmounts.
30
+ */
31
+ function createUseStyleValue(readCache) {
32
+ return function useStyleValue(initial, unit) {
33
+ const id = useId();
34
+ const cache = useProvidedCache() ?? readCache();
35
+ const [state] = useState(() => createValueState(cache, `--${cache.prefix}-value-${hashString(id)}`, initial, unit));
36
+ useInsertionEffect(state.mount, [state]);
37
+ return [state.value, state.set];
38
+ };
39
+ }
40
+ export { createUseStyleValue };
@@ -0,0 +1,23 @@
1
+ let _umber_style_core = require("@umber-style/core");
2
+ // src/useStyleValue.server.ts
3
+ /**
4
+ * Makes `useStyleValue` for server components, which have no hook and never run in the browser: the
5
+ * value is a reference to a variable that nothing declares, so its fallback, the first number, is what
6
+ * a style reads, and the setter changes only what `get()` returns, with one warning in development.
7
+ * The same source written for a client component works in either build.
8
+ */
9
+ function createServerStyleValue(cache) {
10
+ let hasWarned = false;
11
+ const set = (value) => (next) => {
12
+ if (!hasWarned && (0, _umber_style_core.isDevelopment)()) {
13
+ hasWarned = true;
14
+ console.warn(`[${cache.prefix}] The setter of useStyleValue() was called in a server component, which does not run in the browser: the page keeps the first value. Call useStyleValue() in a client component to change it.`);
15
+ }
16
+ (0, _umber_style_core.writeLiveValue)(value, typeof next === "function" ? next(value.get()) : next);
17
+ };
18
+ return function useStyleValue(initial, unit) {
19
+ const value = (0, _umber_style_core.createLiveValue)(`--${cache.prefix}-value-server`, initial, unit);
20
+ return [value, set(value)];
21
+ };
22
+ }
23
+ exports.createServerStyleValue = createServerStyleValue;
@@ -0,0 +1,23 @@
1
+ import { createLiveValue, isDevelopment, writeLiveValue } from "@umber-style/core";
2
+ // src/useStyleValue.server.ts
3
+ /**
4
+ * Makes `useStyleValue` for server components, which have no hook and never run in the browser: the
5
+ * value is a reference to a variable that nothing declares, so its fallback, the first number, is what
6
+ * a style reads, and the setter changes only what `get()` returns, with one warning in development.
7
+ * The same source written for a client component works in either build.
8
+ */
9
+ function createServerStyleValue(cache) {
10
+ let hasWarned = false;
11
+ const set = (value) => (next) => {
12
+ if (!hasWarned && isDevelopment()) {
13
+ hasWarned = true;
14
+ console.warn(`[${cache.prefix}] The setter of useStyleValue() was called in a server component, which does not run in the browser: the page keeps the first value. Call useStyleValue() in a client component to change it.`);
15
+ }
16
+ writeLiveValue(value, typeof next === "function" ? next(value.get()) : next);
17
+ };
18
+ return function useStyleValue(initial, unit) {
19
+ const value = createLiveValue(`--${cache.prefix}-value-server`, initial, unit);
20
+ return [value, set(value)];
21
+ };
22
+ }
23
+ export { createServerStyleValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umber-style/react",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-alpha.0",
4
4
  "description": "UmberStyle for React: styled, ThemeProvider, useTheme, StyleSheet, useStyle and apply, with a server build for server components.",
5
5
  "keywords": [
6
6
  "styling",
@@ -54,8 +54,8 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@umber-style/core": "^0.2.0",
58
- "@umber-style/is-prop-valid": "^0.2.0"
57
+ "@umber-style/core": "^0.3.0-alpha.0",
58
+ "@umber-style/is-prop-valid": "^0.3.0-alpha.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "react": "^19.2.8"