@umber-style/react-native 0.1.0-alpha.0 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/CacheProvider.cjs +7 -0
  2. package/dist/CacheProvider.d.cts +4 -0
  3. package/dist/CacheProvider.d.mts +4 -0
  4. package/dist/CacheProvider.mjs +7 -0
  5. package/dist/ThemeValue.cjs +32 -15
  6. package/dist/ThemeValue.mjs +33 -16
  7. package/dist/calc.cjs +11 -8
  8. package/dist/calc.mjs +11 -8
  9. package/dist/createStyle.cjs +133 -29
  10. package/dist/createStyle.d.cts +7 -9
  11. package/dist/createStyle.d.mts +7 -9
  12. package/dist/createStyle.mjs +136 -32
  13. package/dist/defaultStyle.cjs +29 -3
  14. package/dist/defaultStyle.d.cts +15 -4
  15. package/dist/defaultStyle.d.mts +15 -4
  16. package/dist/defaultStyle.mjs +30 -4
  17. package/dist/index.cjs +11 -2
  18. package/dist/index.d.cts +10 -7
  19. package/dist/index.d.mts +10 -7
  20. package/dist/index.mjs +4 -3
  21. package/dist/mediaQuery.cjs +179 -0
  22. package/dist/mediaQuery.d.cts +1 -0
  23. package/dist/mediaQuery.mjs +178 -0
  24. package/dist/nativeTheme.cjs +51 -0
  25. package/dist/nativeTheme.d.cts +15 -0
  26. package/dist/nativeTheme.d.mts +15 -0
  27. package/dist/nativeTheme.mjs +50 -0
  28. package/dist/platform.mjs +1 -1
  29. package/dist/styled.cjs +95 -19
  30. package/dist/styled.mjs +96 -20
  31. package/dist/toNativeStyle.cjs +64 -15
  32. package/dist/toNativeStyle.mjs +65 -16
  33. package/dist/types.d.cts +78 -10
  34. package/dist/types.d.mts +78 -10
  35. package/dist/units.cjs +137 -0
  36. package/dist/units.mjs +133 -0
  37. package/dist/warnStyle.cjs +62 -18
  38. package/dist/warnStyle.mjs +61 -19
  39. package/dist/windowState.cjs +89 -0
  40. package/dist/windowState.d.cts +6 -0
  41. package/dist/windowState.d.mts +5 -0
  42. package/dist/windowState.mjs +85 -0
  43. package/package.json +3 -3
@@ -1,33 +1,118 @@
1
- import { createElement } from "react";
1
+ import { Fragment, createElement } from "react";
2
2
  import { createNativeThemeKey } from "./conditions.mjs";
3
- import { NO_THEME_MESSAGE, createLazyRecord, createSchemeKey, isThemedSheet } from "@umber-style/core";
3
+ import { createLazyRecord, createSchemeKey, globalStyles, isThemedSheet, keyframes, readStaticTemplate, rejectFunctions } from "@umber-style/core";
4
4
  import { createThemeValue } from "./ThemeValue.mjs";
5
+ import { DEFAULT_LENGTH_KEYS, toNativeTheme } from "./nativeTheme.mjs";
5
6
  import { createStyled } from "./styled.mjs";
6
7
  import { platformStyleSheet } from "./platform.mjs";
7
- import { hasConditions, toNativeStyle } from "./toNativeStyle.mjs";
8
+ import { collectKeys, toNativeStyle } from "./toNativeStyle.mjs";
9
+ import { readMediaKey, readWindowState, useMediaKey } from "./windowState.mjs";
8
10
  // src/createStyle.ts
9
- /** Registers `source` with the platform StyleSheet, without the keys that only the web has. */
10
- function register(source) {
11
- const pairs = Object.entries(source).map(([key, style]) => [key, toNativeStyle(style)]);
11
+ const NO_QUERIES = [];
12
+ const NO_KEYS = {
13
+ isConditional: false,
14
+ hasScheme: false,
15
+ queries: []
16
+ };
17
+ /** The name of the sheet entry `key` in the development warnings. */
18
+ const toEntryName = (key) => `sheet entry "${key}"`;
19
+ /** Registers `source` with the platform StyleSheet, without the keys that only the web has; a `rem` length is `remBase` times its number. */
20
+ function register(source, remBase) {
21
+ const pairs = Object.entries(source).map(([key, style]) => [key, toNativeStyle(style, void 0, {
22
+ remBase,
23
+ name: toEntryName(key)
24
+ })]);
25
+ const entries = platformStyleSheet.create(Object.fromEntries(pairs));
26
+ let all;
27
+ for (const key in source) all = collectKeys(source[key], all);
28
+ const keys = {};
29
+ if (all !== void 0) for (const key in source) keys[key] = collectKeys(source[key]) ?? NO_KEYS;
12
30
  return {
13
- entries: platformStyleSheet.create(Object.fromEntries(pairs)),
31
+ entries,
14
32
  source,
15
- isConditional: Object.values(source).some(hasConditions)
33
+ keys,
34
+ isConditional: all?.isConditional ?? false,
35
+ queries: all?.queries ?? NO_QUERIES,
36
+ hasScheme: all?.hasScheme ?? false
16
37
  };
17
38
  }
18
- /** The entries of `sheet`, with the ones that have a `when()` or `whenScheme()` key resolved against `condition` (not registered: they change with the providers). */
19
- function resolveEntries(sheet, condition) {
20
- if (!sheet.isConditional) return sheet.entries;
21
- const pairs = Object.entries(sheet.source).map(([key, style]) => [key, hasConditions(style) ? toNativeStyle(style, condition) : sheet.entries[key]]);
39
+ /** The entries of `sheet` for the key of a render, with the ones that depend on the window only resolved and registered once for each set of matching queries. */
40
+ function readWindowEntries(sheet, key, remBase) {
41
+ const { entries, keys, queries, source } = sheet;
42
+ const windowKey = key.slice(0, queries.length);
43
+ const byWindow = sheet.byWindow ??= /* @__PURE__ */ new Map();
44
+ let found = byWindow.get(windowKey);
45
+ if (found === void 0) {
46
+ const state = readWindowState();
47
+ const pairs = Object.entries(source).flatMap(([name, style]) => keys[name].queries.length > 0 && !keys[name].isConditional ? [[name, toNativeStyle(style, void 0, {
48
+ remBase,
49
+ name: toEntryName(name)
50
+ }, state)]] : []);
51
+ found = {
52
+ ...entries,
53
+ ...platformStyleSheet.create(Object.fromEntries(pairs))
54
+ };
55
+ byWindow.set(windowKey, found);
56
+ }
57
+ return found;
58
+ }
59
+ /**
60
+ * The entries of `sheet` for the key of a render: the ones that depend on the window only as registered
61
+ * for the matching queries, and the ones that have a `when()` or `whenScheme()` key resolved against
62
+ * `condition` and the window (not registered: they change with the providers).
63
+ */
64
+ function resolveEntries(sheet, condition, key, remBase) {
65
+ const { isConditional, keys, queries, source } = sheet;
66
+ const hasQueries = queries.length > 0;
67
+ const entries = hasQueries ? readWindowEntries(sheet, key, remBase) : sheet.entries;
68
+ if (!isConditional) return entries;
69
+ const state = hasQueries ? readWindowState() : void 0;
70
+ const pairs = Object.entries(source).map(([name, style]) => [name, keys[name].isConditional ? toNativeStyle(style, condition, {
71
+ remBase,
72
+ name: toEntryName(name)
73
+ }, state) : entries[name]]);
22
74
  return Object.fromEntries(pairs);
23
75
  }
24
- /** Makes the React Native styling over a holder of the base theme. */
25
- function bindHolder(holder) {
26
- const { ThemeValueProvider, useTheme, useThemeValue, useCondition } = createThemeValue(holder);
27
- function ThemeProvider({ theme: partial, colorScheme, children }) {
28
- holder.baseTheme ??= partial;
76
+ /**
77
+ * `css()` on React Native: the styles (lists flattened, falsy values dropped), or the style of a tagged
78
+ * template read as CSS text, each turned into a native style as a sheet entry is, merged in order with
79
+ * the last key winning. Throws a `TypeError` for a function and for anything else that is not a style.
80
+ */
81
+ function mergeNativeStyles(args, remBase) {
82
+ const template = readStaticTemplate(args, "css");
83
+ if (!template) rejectFunctions(args, "css");
84
+ const styles = template ? [template] : args.flat(1e400).filter(Boolean);
85
+ const settings = {
86
+ remBase,
87
+ name: "css()"
88
+ };
89
+ const merged = {};
90
+ for (const style of styles) {
91
+ if (typeof style !== "object") throw new TypeError(`css(): ${JSON.stringify(style)} is not a style: give style objects.`);
92
+ Object.assign(merged, toNativeStyle(style, void 0, settings));
93
+ }
94
+ return merged;
95
+ }
96
+ /** `Global` on React Native: there are no global styles, so it renders nothing and does nothing. */
97
+ function Global(_props) {
98
+ return null;
99
+ }
100
+ /** `ThemeScope` on React Native: there is no wrapper to repeat, and a modal stays inside the tree, so it renders its children. */
101
+ function ThemeScope({ children }) {
102
+ return createElement(Fragment, null, children);
103
+ }
104
+ /** `useThemeClass` on React Native: there are no classes. */
105
+ function useThemeClass() {}
106
+ /**
107
+ * Makes the React Native styling over a holder of the base theme; the theme context is made here unless
108
+ * given. Of `options`, `remBase` and `lengthKeys` are used: a theme is converted under `lengthKeys`.
109
+ */
110
+ function bindHolder(holder, context, options = {}) {
111
+ const { remBase = 16, lengthKeys = DEFAULT_LENGTH_KEYS } = options;
112
+ const { ThemeContext, ThemeValueProvider, useTheme, useCondition } = createThemeValue(holder, (theme) => toNativeTheme(theme, lengthKeys, remBase), context);
113
+ function ThemeProvider({ theme, colorScheme, children }) {
29
114
  return createElement(ThemeValueProvider, {
30
- theme: partial,
115
+ theme,
31
116
  colorScheme
32
117
  }, children);
33
118
  }
@@ -35,44 +120,63 @@ function bindHolder(holder) {
35
120
  if (typeof styles !== "function") {
36
121
  let registered;
37
122
  return createLazyRecord(Object.keys(styles), (key) => {
38
- registered ??= register(styles);
123
+ registered ??= register(styles, remBase);
39
124
  return registered.entries[key];
40
125
  });
41
126
  }
42
127
  const byTheme = /* @__PURE__ */ new WeakMap();
43
- return { resolve(current, condition) {
128
+ const prepare = (current) => {
44
129
  let sheet = byTheme.get(current);
45
130
  if (!sheet) {
46
- sheet = register(styles(current));
131
+ sheet = register(styles(current), remBase);
47
132
  byTheme.set(current, sheet);
48
133
  }
49
- return resolveEntries(sheet, condition);
50
- } };
134
+ return sheet;
135
+ };
136
+ return {
137
+ prepare,
138
+ resolve(current, condition) {
139
+ const sheet = prepare(current);
140
+ return resolveEntries(sheet, condition, readMediaKey(sheet.queries, false, remBase), remBase);
141
+ }
142
+ };
51
143
  }
52
144
  const useStyle = ((sheet) => {
53
- const theme = useThemeValue();
145
+ const theme = useTheme();
54
146
  const condition = useCondition();
55
- if (!isThemedSheet(sheet)) return sheet;
56
- if (theme === void 0) throw new Error(NO_THEME_MESSAGE);
57
- return sheet.resolve(theme, condition);
147
+ const prepared = isThemedSheet(sheet) ? sheet.prepare(theme) : void 0;
148
+ const shouldWatchScheme = !!prepared?.hasScheme && condition.colorScheme === void 0;
149
+ const key = useMediaKey(prepared?.queries ?? NO_QUERIES, shouldWatchScheme, remBase);
150
+ return prepared === void 0 ? sheet : resolveEntries(prepared, condition, key, remBase);
58
151
  });
59
152
  return {
60
- styled: createStyled(useTheme, useCondition),
153
+ styled: createStyled(useTheme, useCondition, remBase),
61
154
  StyleSheet: {
62
155
  ...platformStyleSheet,
63
156
  create
64
157
  },
65
158
  useStyle,
66
159
  apply: (...entries) => ({ style: entries.filter((entry) => !!entry) }),
160
+ css: ((...args) => mergeNativeStyles(args, remBase)),
67
161
  ThemeProvider,
162
+ ThemeScope,
163
+ ThemeContext,
68
164
  useTheme,
165
+ useThemeClass,
69
166
  themeClass: () => "",
70
167
  when: createNativeThemeKey,
71
- whenScheme: createSchemeKey
168
+ whenScheme: createSchemeKey,
169
+ keyframes,
170
+ globalStyles,
171
+ Global
72
172
  };
73
173
  }
74
- /** Makes the styling of one theme shape for React Native, apart from the default one; the options are those of the web and are not used. */
75
- function createStyle(theme, _options = {}) {
76
- return bindHolder({ baseTheme: theme });
174
+ /**
175
+ * Makes the styling of one theme shape for React Native, apart from the default one. The options are
176
+ * those of the web, so that one call runs on both platforms, with `remBase` added; of them only
177
+ * `remBase` and `lengthKeys` are used.
178
+ */
179
+ function createStyle(theme, options = {}) {
180
+ return bindHolder({ baseTheme: theme }, void 0, options);
77
181
  }
78
182
  export { bindHolder, createStyle };
@@ -1,19 +1,24 @@
1
+ let react = require("react");
1
2
  let _umber_style_core = require("@umber-style/core");
2
3
  const require_createStyle = require("./createStyle.cjs");
4
+ const require_windowState = require("./windowState.cjs");
3
5
  let react_native = require("react-native");
4
6
  // src/defaultStyle.ts
5
7
  /** Makes the default styling: one holder of the base theme, behind `styled`, `ThemeProvider` and the rest. */
6
8
  function createDefaultStyle() {
7
9
  const holder = { baseTheme: void 0 };
8
10
  let bound;
11
+ let settings = {};
12
+ const ThemeContext = (0, react.createContext)(void 0);
9
13
  const getStyle = () => {
10
- bound ??= require_createStyle.bindHolder(holder);
14
+ bound ??= require_createStyle.bindHolder(holder, ThemeContext, settings);
11
15
  return bound;
12
16
  };
13
- /** Gives the default style a base theme. Throws once the default style was used. */
17
+ /** Gives the default style a base theme and its options (`remBase`, `lengthKeys`). Throws once the default style was used. */
14
18
  function configure(options) {
15
19
  if (bound) throw new Error("configure must be called before the default style is used.");
16
20
  holder.baseTheme = options.theme;
21
+ settings = options;
17
22
  }
18
23
  const styled = ((tag, options) => getStyle().styled(tag, options));
19
24
  const StyleSheet = {
@@ -27,6 +32,19 @@ function createDefaultStyle() {
27
32
  function ThemeProvider(props) {
28
33
  return getStyle().ThemeProvider(props);
29
34
  }
35
+ function Global(props) {
36
+ return getStyle().Global(props);
37
+ }
38
+ function ThemeScope(props) {
39
+ return getStyle().ThemeScope(props);
40
+ }
41
+ function useThemeClass() {
42
+ return getStyle().useThemeClass();
43
+ }
44
+ /** Whether the media query `query` matches the window; a `rem` or `em` length in it is the `remBase` of `configure`. */
45
+ function useMediaQuery(query, options = {}) {
46
+ return require_windowState.useMediaMatch(query, options, settings.remBase ?? 16);
47
+ }
30
48
  return {
31
49
  configure,
32
50
  styled,
@@ -34,10 +52,18 @@ function createDefaultStyle() {
34
52
  useStyle,
35
53
  useTheme,
36
54
  ThemeProvider,
55
+ ThemeScope,
56
+ useThemeClass,
57
+ useMediaQuery,
58
+ ThemeContext,
37
59
  apply: ((...entries) => getStyle().apply(...entries)),
60
+ css: ((...args) => (0, _umber_style_core.createDeferredObject)(() => getStyle().css(...args))),
38
61
  when: ((theme, colorScheme) => getStyle().when(theme, colorScheme)),
39
62
  whenScheme: ((scheme) => getStyle().whenScheme(scheme)),
40
- themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme))
63
+ themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme)),
64
+ keyframes: _umber_style_core.keyframes,
65
+ globalStyles: _umber_style_core.globalStyles,
66
+ Global
41
67
  };
42
68
  }
43
69
  exports.createDefaultStyle = createDefaultStyle;
@@ -1,6 +1,9 @@
1
- import { NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, Styled, ThemeProviderProps } from "./types.cjs";
1
+ import { GlobalProps, NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, Styled, ThemeProviderProps, ThemeScopeProps } from "./types.cjs";
2
2
  import { NativeSheetStyles, NativeStyleObject } from "./nativeStyle.cjs";
3
3
  import { Theme } from "@umber-style/core";
4
+ import { NativeTheme } from "./nativeTheme.cjs";
5
+ import { MediaQueryOptions } from "./windowState.cjs";
6
+ /** The options of `configure()`: those of `createStyle` for the default style, and its base theme. */
4
7
  export interface DefaultStyleOptions extends StyleOptions<Theme> {
5
8
  /** The base theme, for an app that has no provider at all. */
6
9
  theme?: Theme;
@@ -8,16 +11,24 @@ export interface DefaultStyleOptions extends StyleOptions<Theme> {
8
11
  /** Makes the default styling: one holder of the base theme, behind `styled`, `ThemeProvider` and the rest. */
9
12
  export declare function createDefaultStyle(): {
10
13
  configure: (options: DefaultStyleOptions) => void;
11
- styled: Styled<Theme>;
12
- StyleSheet: NativeStyleSheet<Theme>;
14
+ styled: Styled<NativeTheme<Theme>>;
15
+ StyleSheet: NativeStyleSheet<NativeTheme<Theme>>;
13
16
  useStyle: {
14
17
  <K extends string>(sheet: { readonly [P in K]: NativeStyleObject; }): { readonly [P in K]: NativeStyleObject; };
15
18
  <S extends NativeSheetStyles>(sheet: SheetDefinition<S, NativeStyleObject>): { [K in keyof S]: NativeStyleObject; };
16
19
  };
17
- useTheme: () => Theme;
20
+ useTheme: () => NativeTheme<Theme>;
18
21
  ThemeProvider: (props: ThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
22
+ ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
23
+ useThemeClass: () => string | undefined;
24
+ useMediaQuery: (query: string, options?: MediaQueryOptions) => boolean;
25
+ ThemeContext: import("react").Context<NativeTheme<Theme> | undefined>;
19
26
  apply: NativeStyle<Theme>['apply'];
27
+ css: NativeStyle<Theme>['css'];
20
28
  when: NativeStyle<Theme>['when'];
21
29
  whenScheme: NativeStyle<Theme>['whenScheme'];
22
30
  themeClass: NativeStyle<Theme>['themeClass'];
31
+ keyframes: NativeStyle<Theme>['keyframes'];
32
+ globalStyles: NativeStyle<Theme>['globalStyles'];
33
+ Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
23
34
  };
@@ -1,6 +1,9 @@
1
- import { NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, Styled, ThemeProviderProps } from "./types.mjs";
1
+ import { GlobalProps, NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, Styled, ThemeProviderProps, ThemeScopeProps } from "./types.mjs";
2
2
  import { NativeSheetStyles, NativeStyleObject } from "./nativeStyle.mjs";
3
3
  import { Theme } from "@umber-style/core";
4
+ import { NativeTheme } from "./nativeTheme.mjs";
5
+ import { MediaQueryOptions } from "./windowState.mjs";
6
+ /** The options of `configure()`: those of `createStyle` for the default style, and its base theme. */
4
7
  export interface DefaultStyleOptions extends StyleOptions<Theme> {
5
8
  /** The base theme, for an app that has no provider at all. */
6
9
  theme?: Theme;
@@ -8,16 +11,24 @@ export interface DefaultStyleOptions extends StyleOptions<Theme> {
8
11
  /** Makes the default styling: one holder of the base theme, behind `styled`, `ThemeProvider` and the rest. */
9
12
  export declare function createDefaultStyle(): {
10
13
  configure: (options: DefaultStyleOptions) => void;
11
- styled: Styled<Theme>;
12
- StyleSheet: NativeStyleSheet<Theme>;
14
+ styled: Styled<NativeTheme<Theme>>;
15
+ StyleSheet: NativeStyleSheet<NativeTheme<Theme>>;
13
16
  useStyle: {
14
17
  <K extends string>(sheet: { readonly [P in K]: NativeStyleObject; }): { readonly [P in K]: NativeStyleObject; };
15
18
  <S extends NativeSheetStyles>(sheet: SheetDefinition<S, NativeStyleObject>): { [K in keyof S]: NativeStyleObject; };
16
19
  };
17
- useTheme: () => Theme;
20
+ useTheme: () => NativeTheme<Theme>;
18
21
  ThemeProvider: (props: ThemeProviderProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
22
+ ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
23
+ useThemeClass: () => string | undefined;
24
+ useMediaQuery: (query: string, options?: MediaQueryOptions) => boolean;
25
+ ThemeContext: import("react").Context<NativeTheme<Theme> | undefined>;
19
26
  apply: NativeStyle<Theme>['apply'];
27
+ css: NativeStyle<Theme>['css'];
20
28
  when: NativeStyle<Theme>['when'];
21
29
  whenScheme: NativeStyle<Theme>['whenScheme'];
22
30
  themeClass: NativeStyle<Theme>['themeClass'];
31
+ keyframes: NativeStyle<Theme>['keyframes'];
32
+ globalStyles: NativeStyle<Theme>['globalStyles'];
33
+ Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
23
34
  };
@@ -1,19 +1,24 @@
1
- import { createDeferredRecord } from "@umber-style/core";
1
+ import { createContext } from "react";
2
+ import { createDeferredObject, createDeferredRecord, globalStyles, keyframes } from "@umber-style/core";
2
3
  import { bindHolder } from "./createStyle.mjs";
3
4
  import { platformStyleSheet } from "./platform.mjs";
5
+ import { useMediaMatch } from "./windowState.mjs";
4
6
  // src/defaultStyle.ts
5
7
  /** Makes the default styling: one holder of the base theme, behind `styled`, `ThemeProvider` and the rest. */
6
8
  function createDefaultStyle() {
7
9
  const holder = { baseTheme: void 0 };
8
10
  let bound;
11
+ let settings = {};
12
+ const ThemeContext = createContext(void 0);
9
13
  const getStyle = () => {
10
- bound ??= bindHolder(holder);
14
+ bound ??= bindHolder(holder, ThemeContext, settings);
11
15
  return bound;
12
16
  };
13
- /** Gives the default style a base theme. Throws once the default style was used. */
17
+ /** Gives the default style a base theme and its options (`remBase`, `lengthKeys`). Throws once the default style was used. */
14
18
  function configure(options) {
15
19
  if (bound) throw new Error("configure must be called before the default style is used.");
16
20
  holder.baseTheme = options.theme;
21
+ settings = options;
17
22
  }
18
23
  const styled = ((tag, options) => getStyle().styled(tag, options));
19
24
  const StyleSheet = {
@@ -27,6 +32,19 @@ function createDefaultStyle() {
27
32
  function ThemeProvider(props) {
28
33
  return getStyle().ThemeProvider(props);
29
34
  }
35
+ function Global(props) {
36
+ return getStyle().Global(props);
37
+ }
38
+ function ThemeScope(props) {
39
+ return getStyle().ThemeScope(props);
40
+ }
41
+ function useThemeClass() {
42
+ return getStyle().useThemeClass();
43
+ }
44
+ /** Whether the media query `query` matches the window; a `rem` or `em` length in it is the `remBase` of `configure`. */
45
+ function useMediaQuery(query, options = {}) {
46
+ return useMediaMatch(query, options, settings.remBase ?? 16);
47
+ }
30
48
  return {
31
49
  configure,
32
50
  styled,
@@ -34,10 +52,18 @@ function createDefaultStyle() {
34
52
  useStyle,
35
53
  useTheme,
36
54
  ThemeProvider,
55
+ ThemeScope,
56
+ useThemeClass,
57
+ useMediaQuery,
58
+ ThemeContext,
37
59
  apply: ((...entries) => getStyle().apply(...entries)),
60
+ css: ((...args) => createDeferredObject(() => getStyle().css(...args))),
38
61
  when: ((theme, colorScheme) => getStyle().when(theme, colorScheme)),
39
62
  whenScheme: ((scheme) => getStyle().whenScheme(scheme)),
40
- themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme))
63
+ themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme)),
64
+ keyframes,
65
+ globalStyles,
66
+ Global
41
67
  };
42
68
  }
43
69
  export { createDefaultStyle };
package/dist/index.cjs CHANGED
@@ -1,12 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_defaultStyle = require("./defaultStyle.cjs");
3
3
  let _umber_style_core = require("@umber-style/core");
4
+ const require_CacheProvider = require("./CacheProvider.cjs");
4
5
  const require_alpha = require("./alpha.cjs");
5
6
  const require_calc = require("./calc.cjs");
6
7
  const require_createStyle = require("./createStyle.cjs");
7
- const { configure, styled, StyleSheet, useStyle, useTheme, ThemeProvider, apply, themeClass, when, whenScheme } = require_defaultStyle.createDefaultStyle();
8
+ const { configure, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, useMediaQuery, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = require_defaultStyle.createDefaultStyle();
9
+ exports.CacheProvider = require_CacheProvider.CacheProvider;
10
+ exports.Global = Global;
8
11
  exports.StyleSheet = StyleSheet;
12
+ exports.ThemeContext = ThemeContext;
9
13
  exports.ThemeProvider = ThemeProvider;
14
+ exports.ThemeScope = ThemeScope;
10
15
  exports.add = require_calc.add;
11
16
  exports.alpha = require_alpha.alpha;
12
17
  exports.apply = apply;
@@ -16,17 +21,21 @@ Object.defineProperty(exports, "at", {
16
21
  return _umber_style_core.at;
17
22
  }
18
23
  });
19
- exports.bindHolder = require_createStyle.bindHolder;
20
24
  exports.configure = configure;
21
25
  exports.createDefaultStyle = require_defaultStyle.createDefaultStyle;
22
26
  exports.createStyle = require_createStyle.createStyle;
27
+ exports.css = css;
23
28
  exports.divide = require_calc.divide;
29
+ exports.globalStyles = globalStyles;
30
+ exports.keyframes = keyframes;
24
31
  exports.multiply = require_calc.multiply;
25
32
  exports.negate = require_calc.negate;
26
33
  exports.styled = styled;
27
34
  exports.subtract = require_calc.subtract;
28
35
  exports.themeClass = themeClass;
36
+ exports.useMediaQuery = useMediaQuery;
29
37
  exports.useStyle = useStyle;
30
38
  exports.useTheme = useTheme;
39
+ exports.useThemeClass = useThemeClass;
31
40
  exports.when = when;
32
41
  exports.whenScheme = whenScheme;
package/dist/index.d.cts CHANGED
@@ -1,18 +1,21 @@
1
1
  import { at } from "@umber-style/core";
2
2
  import { DefaultStyleOptions, createDefaultStyle } from "./defaultStyle.cjs";
3
- import { NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps } from "./types.cjs";
3
+ import { NativeLength, NativeTheme } from "./nativeTheme.cjs";
4
+ import { CacheProviderProps, GlobalProps, NativeCssArgument, NativeCssFunction, NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps } from "./types.cjs";
4
5
  import { NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult } from "./nativeStyle.cjs";
6
+ import { MediaQueryOptions } from "./windowState.cjs";
7
+ import { CacheProvider } from "./CacheProvider.cjs";
5
8
  import { alpha } from "./alpha.cjs";
6
9
  import { Operand, Percent, add, divide, multiply, negate, subtract } from "./calc.cjs";
7
- import { NativeHolder, bindHolder, createStyle } from "./createStyle.cjs";
8
- export declare const configure: (options: DefaultStyleOptions) => void, styled: Styled<import("@umber-style/core").Theme>, StyleSheet: NativeStyleSheet<import("@umber-style/core").Theme>, useStyle: {
10
+ import { createStyle } from "./createStyle.cjs";
11
+ export declare const configure: (options: DefaultStyleOptions) => void, styled: Styled<NativeTheme<import("@umber-style/core").Theme>>, StyleSheet: NativeStyleSheet<NativeTheme<import("@umber-style/core").Theme>>, useStyle: {
9
12
  <K extends string>(sheet: { readonly [P in K]: NativeStyleObject; }): { readonly [P in K]: NativeStyleObject; };
10
13
  <S extends NativeSheetStyles>(sheet: SheetDefinition<S, NativeStyleObject>): { [K in keyof S]: NativeStyleObject; };
11
- }, useTheme: () => import("@umber-style/core").Theme, ThemeProvider: (props: ThemeProviderProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (NativeStyleObject | null | undefined | false)[]) => {
14
+ }, useTheme: () => NativeTheme<import("@umber-style/core").Theme>, ThemeProvider: (props: ThemeProviderProps<import("@umber-style/core").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, useMediaQuery: (query: string, options?: MediaQueryOptions) => boolean, ThemeContext: import("react").Context<NativeTheme<import("@umber-style/core").Theme> | undefined>, apply: (...entries: (NativeStyleObject | null | undefined | false)[]) => {
12
15
  style: NativeStyleObject[];
13
- }, themeClass: (theme: {
16
+ }, css: NativeCssFunction, themeClass: (theme: {
14
17
  readonly _theme?: never;
15
18
  }, colorScheme?: import("@umber-style/core").ColorScheme) => string, when: (theme: {
16
19
  readonly _theme?: never;
17
- }, colorScheme?: import("@umber-style/core").ColorScheme) => import("@umber-style/core").ThemeKey, whenScheme: (scheme: import("@umber-style/core").SchemeName) => import("@umber-style/core").SchemeKey;
18
- export { DefaultStyleOptions, NativeHolder, NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyle, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult, NativeStyleSheet, Operand, Percent, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, add, alpha, at, bindHolder, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
20
+ }, colorScheme?: import("@umber-style/core").ColorScheme) => import("@umber-style/core").ThemeKey, whenScheme: (scheme: import("@umber-style/core").SchemeName) => import("@umber-style/core").SchemeKey, keyframes: (steps: import("@umber-style/core").KeyframesInput<import("@umber-style/core").Theme>, options?: import("@umber-style/core").KeyframesOptions) => string, globalStyles: (styles: import("@umber-style/core").GlobalStylesInput<import("@umber-style/core").Theme>) => import("@umber-style/core").GlobalStyles<import("@umber-style/core").Theme>, Global: (props: GlobalProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
21
+ export { CacheProvider, CacheProviderProps, DefaultStyleOptions, GlobalProps, type MediaQueryOptions, NativeCssArgument, NativeCssFunction, type NativeLength, NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyle, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult, NativeStyleSheet, type NativeTheme, Operand, Percent, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps, add, alpha, at, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
package/dist/index.d.mts CHANGED
@@ -1,18 +1,21 @@
1
1
  import { DefaultStyleOptions, createDefaultStyle } from "./defaultStyle.mjs";
2
- import { NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps } from "./types.mjs";
2
+ import { NativeLength, NativeTheme } from "./nativeTheme.mjs";
3
+ import { CacheProviderProps, GlobalProps, NativeCssArgument, NativeCssFunction, NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps } from "./types.mjs";
3
4
  import { NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult } from "./nativeStyle.mjs";
5
+ import { MediaQueryOptions } from "./windowState.mjs";
4
6
  import { at } from "@umber-style/core";
7
+ import { CacheProvider } from "./CacheProvider.mjs";
5
8
  import { alpha } from "./alpha.mjs";
6
9
  import { Operand, Percent, add, divide, multiply, negate, subtract } from "./calc.mjs";
7
- import { NativeHolder, bindHolder, createStyle } from "./createStyle.mjs";
8
- export declare const configure: (options: DefaultStyleOptions) => void, styled: Styled<import("@umber-style/core").Theme>, StyleSheet: NativeStyleSheet<import("@umber-style/core").Theme>, useStyle: {
10
+ import { createStyle } from "./createStyle.mjs";
11
+ export declare const configure: (options: DefaultStyleOptions) => void, styled: Styled<NativeTheme<import("@umber-style/core").Theme>>, StyleSheet: NativeStyleSheet<NativeTheme<import("@umber-style/core").Theme>>, useStyle: {
9
12
  <K extends string>(sheet: { readonly [P in K]: NativeStyleObject; }): { readonly [P in K]: NativeStyleObject; };
10
13
  <S extends NativeSheetStyles>(sheet: SheetDefinition<S, NativeStyleObject>): { [K in keyof S]: NativeStyleObject; };
11
- }, useTheme: () => import("@umber-style/core").Theme, ThemeProvider: (props: ThemeProviderProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, apply: (...entries: (NativeStyleObject | null | undefined | false)[]) => {
14
+ }, useTheme: () => NativeTheme<import("@umber-style/core").Theme>, ThemeProvider: (props: ThemeProviderProps<import("@umber-style/core").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, useMediaQuery: (query: string, options?: MediaQueryOptions) => boolean, ThemeContext: import("react").Context<NativeTheme<import("@umber-style/core").Theme> | undefined>, apply: (...entries: (NativeStyleObject | null | undefined | false)[]) => {
12
15
  style: NativeStyleObject[];
13
- }, themeClass: (theme: {
16
+ }, css: NativeCssFunction, themeClass: (theme: {
14
17
  readonly _theme?: never;
15
18
  }, colorScheme?: import("@umber-style/core").ColorScheme) => string, when: (theme: {
16
19
  readonly _theme?: never;
17
- }, colorScheme?: import("@umber-style/core").ColorScheme) => import("@umber-style/core").ThemeKey, whenScheme: (scheme: import("@umber-style/core").SchemeName) => import("@umber-style/core").SchemeKey;
18
- export { DefaultStyleOptions, NativeHolder, NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyle, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult, NativeStyleSheet, Operand, Percent, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, add, alpha, at, bindHolder, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
20
+ }, colorScheme?: import("@umber-style/core").ColorScheme) => import("@umber-style/core").ThemeKey, whenScheme: (scheme: import("@umber-style/core").SchemeName) => import("@umber-style/core").SchemeKey, keyframes: (steps: import("@umber-style/core").KeyframesInput<import("@umber-style/core").Theme>, options?: import("@umber-style/core").KeyframesOptions) => string, globalStyles: (styles: import("@umber-style/core").GlobalStylesInput<import("@umber-style/core").Theme>) => import("@umber-style/core").GlobalStyles<import("@umber-style/core").Theme>, Global: (props: GlobalProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
21
+ export { CacheProvider, CacheProviderProps, DefaultStyleOptions, GlobalProps, type MediaQueryOptions, NativeCssArgument, NativeCssFunction, type NativeLength, NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyle, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult, NativeStyleSheet, type NativeTheme, Operand, Percent, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps, add, alpha, at, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createDefaultStyle } from "./defaultStyle.mjs";
2
2
  import { at } from "@umber-style/core";
3
+ import { CacheProvider } from "./CacheProvider.mjs";
3
4
  import { alpha } from "./alpha.mjs";
4
5
  import { add, divide, multiply, negate, subtract } from "./calc.mjs";
5
- import { bindHolder, createStyle } from "./createStyle.mjs";
6
- const { configure, styled, StyleSheet, useStyle, useTheme, ThemeProvider, apply, themeClass, when, whenScheme } = createDefaultStyle();
7
- export { StyleSheet, ThemeProvider, add, alpha, apply, at, bindHolder, configure, createDefaultStyle, createStyle, divide, multiply, negate, styled, subtract, themeClass, useStyle, useTheme, when, whenScheme };
6
+ import { createStyle } from "./createStyle.mjs";
7
+ const { configure, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, useMediaQuery, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = createDefaultStyle();
8
+ export { CacheProvider, Global, StyleSheet, ThemeContext, ThemeProvider, ThemeScope, add, alpha, apply, at, configure, createDefaultStyle, createStyle, css, divide, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useMediaQuery, useStyle, useTheme, useThemeClass, when, whenScheme };