@umber-style/react 0.0.0 → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -1
  3. package/dist/CacheProvider.cjs +23 -0
  4. package/dist/CacheProvider.d.cts +10 -0
  5. package/dist/CacheProvider.d.mts +11 -0
  6. package/dist/CacheProvider.mjs +22 -0
  7. package/dist/Global.cjs +52 -0
  8. package/dist/Global.mjs +52 -0
  9. package/dist/Global.server.cjs +27 -0
  10. package/dist/Global.server.mjs +27 -0
  11. package/dist/GlobalRelease.cjs +32 -0
  12. package/dist/GlobalRelease.mjs +30 -0
  13. package/dist/ProviderScope.cjs +201 -0
  14. package/dist/ProviderScope.d.cts +14 -0
  15. package/dist/ProviderScope.d.mts +15 -0
  16. package/dist/ProviderScope.mjs +190 -0
  17. package/dist/ThemeProvider.cjs +104 -0
  18. package/dist/ThemeProvider.mjs +104 -0
  19. package/dist/ThemeProvider.server.cjs +140 -0
  20. package/dist/ThemeProvider.server.mjs +140 -0
  21. package/dist/ThemeValue.cjs +64 -0
  22. package/dist/ThemeValue.d.cts +3 -0
  23. package/dist/ThemeValue.d.mts +4 -0
  24. package/dist/ThemeValue.mjs +62 -0
  25. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  26. package/dist/createStyle.cjs +66 -0
  27. package/dist/createStyle.d.cts +9 -0
  28. package/dist/createStyle.d.mts +9 -0
  29. package/dist/createStyle.mjs +65 -0
  30. package/dist/createStyle.server.cjs +60 -0
  31. package/dist/createStyle.server.d.cts +8 -0
  32. package/dist/createStyle.server.d.mts +8 -0
  33. package/dist/createStyle.server.mjs +59 -0
  34. package/dist/defaultStyle.cjs +68 -0
  35. package/dist/defaultStyle.d.cts +29 -0
  36. package/dist/defaultStyle.d.mts +29 -0
  37. package/dist/defaultStyle.mjs +68 -0
  38. package/dist/defaultStyle.server.cjs +52 -0
  39. package/dist/defaultStyle.server.d.cts +27 -0
  40. package/dist/defaultStyle.server.d.mts +27 -0
  41. package/dist/defaultStyle.server.mjs +52 -0
  42. package/dist/domProps.cjs +27 -0
  43. package/dist/domProps.mjs +27 -0
  44. package/dist/index.cjs +72 -0
  45. package/dist/index.d.cts +28 -0
  46. package/dist/index.d.mts +28 -0
  47. package/dist/index.mjs +7 -0
  48. package/dist/index.server.cjs +66 -0
  49. package/dist/index.server.d.cts +26 -0
  50. package/dist/index.server.d.mts +26 -0
  51. package/dist/index.server.mjs +5 -0
  52. package/dist/plainTheme.cjs +49 -0
  53. package/dist/plainTheme.mjs +49 -0
  54. package/dist/serverContext.cjs +14 -0
  55. package/dist/serverContext.d.cts +2 -0
  56. package/dist/serverContext.d.mts +2 -0
  57. package/dist/serverContext.mjs +14 -0
  58. package/dist/styleElements.cjs +99 -0
  59. package/dist/styleElements.d.cts +1 -0
  60. package/dist/styleElements.d.mts +2 -0
  61. package/dist/styleElements.mjs +95 -0
  62. package/dist/styled.cjs +51 -0
  63. package/dist/styled.mjs +51 -0
  64. package/dist/styled.server.cjs +24 -0
  65. package/dist/styled.server.mjs +24 -0
  66. package/dist/styledParts.cjs +67 -0
  67. package/dist/styledParts.mjs +67 -0
  68. package/dist/types.d.cts +274 -0
  69. package/dist/types.d.mts +274 -0
  70. package/dist/useMediaQuery.cjs +20 -0
  71. package/dist/useMediaQuery.d.cts +13 -0
  72. package/dist/useMediaQuery.d.mts +13 -0
  73. package/dist/useMediaQuery.mjs +20 -0
  74. package/package.json +88 -5
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ let react = require("react");
3
+ let _umber_style_core = require("@umber-style/core");
4
+ const require_CacheProvider = require("./CacheProvider.cjs");
5
+ const require_ProviderScope = require("./ProviderScope.cjs");
6
+ // src/ThemeValue.tsx
7
+ /**
8
+ * The key of the marks for `engine` under the cache that a `CacheProvider` gives (`cache`): the prefix of
9
+ * the engine's cache, which a provider of the server build marks too, or the given cache when it is
10
+ * another one.
11
+ */
12
+ function readMarkKey(engine, cache) {
13
+ return cache === void 0 || cache === engine.cache ? engine.cache.prefix : cache;
14
+ }
15
+ /** The hooks of one style, and `ThemeScope`, over its contexts. */
16
+ function createThemeValue(holder, { ThemeContext, ViewContext }) {
17
+ /** The theme where no provider is above: the base theme, or the empty theme. */
18
+ const readOwnTheme = () => holder.baseTheme ?? _umber_style_core.EMPTY_THEME;
19
+ /** The real theme of the nearest provider, the base theme, or an empty object. */
20
+ function useTheme() {
21
+ return (0, react.useContext)(ThemeContext) ?? readOwnTheme();
22
+ }
23
+ /**
24
+ * The view of the theme that function styles read: of the nearest provider, else of the base theme (or
25
+ * of the empty theme). It is the view that a provider of the client build gives; below a provider of the
26
+ * server build, which gives none, and under a `CacheProvider` (`cache`, which `useProvidedCache` read),
27
+ * it is made from the real theme of the nearest provider, by the engine over that cache: its references
28
+ * name the variables of that cache's prefix. The theme context is read only then, so that a component
29
+ * that reads a view given renders again only when the view changes.
30
+ */
31
+ function useThemeView(cache) {
32
+ const view = (0, react.useContext)(ViewContext);
33
+ const local = cache === void 0 ? holder : holder.withCache(cache);
34
+ if (local === holder && view !== void 0) return view;
35
+ return local.createThemeView((0, react.use)(ThemeContext) ?? readOwnTheme());
36
+ }
37
+ /** The wrapper of the nearest nested provider of either build: null under the outermost one, undefined with none. */
38
+ function useScope() {
39
+ return (0, react.use)(require_ProviderScope.getMarksContext()).get(readMarkKey(holder, require_CacheProvider.useProvidedCache()))?.scope;
40
+ }
41
+ /** The class string of the wrapper of the nearest nested provider; undefined under the outermost one or none. */
42
+ function useThemeClass() {
43
+ return useScope()?.className;
44
+ }
45
+ /**
46
+ * Renders the wrapper of the nearest nested provider again around its children (the same element and
47
+ * classes), for content that a portal puts somewhere else in the document; under the outermost provider,
48
+ * or none, its children alone.
49
+ */
50
+ function ThemeScope({ children }) {
51
+ const scope = useScope();
52
+ if (!scope) return (0, react.createElement)(react.Fragment, null, children);
53
+ return (0, react.createElement)(scope.as, { className: scope.className }, children);
54
+ }
55
+ return {
56
+ useTheme,
57
+ useThemeView,
58
+ useThemeClass,
59
+ ThemeScope
60
+ };
61
+ }
62
+ exports.createThemeContexts = require_ProviderScope.createThemeContexts;
63
+ exports.createThemeValue = createThemeValue;
64
+ exports.readMarkKey = readMarkKey;
@@ -0,0 +1,3 @@
1
+ import { ThemeContexts } from "./ProviderScope.cjs";
2
+ import "./types.cjs";
3
+ export type { ThemeContexts };
@@ -0,0 +1,4 @@
1
+ import "@umber-style/core";
2
+ import { ThemeContexts } from "./ProviderScope.mjs";
3
+ import "./types.mjs";
4
+ export type { ThemeContexts };
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { Fragment, createElement, use, useContext } from "react";
3
+ import { EMPTY_THEME } from "@umber-style/core";
4
+ import { useProvidedCache } from "./CacheProvider.mjs";
5
+ import { createThemeContexts, getMarksContext } from "./ProviderScope.mjs";
6
+ // src/ThemeValue.tsx
7
+ /**
8
+ * The key of the marks for `engine` under the cache that a `CacheProvider` gives (`cache`): the prefix of
9
+ * the engine's cache, which a provider of the server build marks too, or the given cache when it is
10
+ * another one.
11
+ */
12
+ function readMarkKey(engine, cache) {
13
+ return cache === void 0 || cache === engine.cache ? engine.cache.prefix : cache;
14
+ }
15
+ /** The hooks of one style, and `ThemeScope`, over its contexts. */
16
+ function createThemeValue(holder, { ThemeContext, ViewContext }) {
17
+ /** The theme where no provider is above: the base theme, or the empty theme. */
18
+ const readOwnTheme = () => holder.baseTheme ?? EMPTY_THEME;
19
+ /** The real theme of the nearest provider, the base theme, or an empty object. */
20
+ function useTheme() {
21
+ return useContext(ThemeContext) ?? readOwnTheme();
22
+ }
23
+ /**
24
+ * The view of the theme that function styles read: of the nearest provider, else of the base theme (or
25
+ * of the empty theme). It is the view that a provider of the client build gives; below a provider of the
26
+ * server build, which gives none, and under a `CacheProvider` (`cache`, which `useProvidedCache` read),
27
+ * it is made from the real theme of the nearest provider, by the engine over that cache: its references
28
+ * name the variables of that cache's prefix. The theme context is read only then, so that a component
29
+ * that reads a view given renders again only when the view changes.
30
+ */
31
+ function useThemeView(cache) {
32
+ const view = useContext(ViewContext);
33
+ const local = cache === void 0 ? holder : holder.withCache(cache);
34
+ if (local === holder && view !== void 0) return view;
35
+ return local.createThemeView(use(ThemeContext) ?? readOwnTheme());
36
+ }
37
+ /** The wrapper of the nearest nested provider of either build: null under the outermost one, undefined with none. */
38
+ function useScope() {
39
+ return use(getMarksContext()).get(readMarkKey(holder, useProvidedCache()))?.scope;
40
+ }
41
+ /** The class string of the wrapper of the nearest nested provider; undefined under the outermost one or none. */
42
+ function useThemeClass() {
43
+ return useScope()?.className;
44
+ }
45
+ /**
46
+ * Renders the wrapper of the nearest nested provider again around its children (the same element and
47
+ * classes), for content that a portal puts somewhere else in the document; under the outermost provider,
48
+ * or none, its children alone.
49
+ */
50
+ function ThemeScope({ children }) {
51
+ const scope = useScope();
52
+ if (!scope) return createElement(Fragment, null, children);
53
+ return createElement(scope.as, { className: scope.className }, children);
54
+ }
55
+ return {
56
+ useTheme,
57
+ useThemeView,
58
+ useThemeClass,
59
+ ThemeScope
60
+ };
61
+ }
62
+ export { createThemeContexts, createThemeValue, readMarkKey };
@@ -0,0 +1,22 @@
1
+ // \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ exports.__toESM = __toESM;
@@ -0,0 +1,66 @@
1
+ let _umber_style_core = require("@umber-style/core");
2
+ const require_CacheProvider = require("./CacheProvider.cjs");
3
+ const require_Global = require("./Global.cjs");
4
+ const require_ProviderScope = require("./ProviderScope.cjs");
5
+ const require_styleElements = require("./styleElements.cjs");
6
+ const require_styled = require("./styled.cjs");
7
+ const require_ThemeProvider = require("./ThemeProvider.cjs");
8
+ const require_ThemeValue = require("./ThemeValue.cjs");
9
+ // src/createStyle.ts
10
+ /** 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
+ function readSharedContexts(engine) {
12
+ const shared = require_ProviderScope.readPrefixStyle(engine.cache.prefix);
13
+ shared.holder ??= engine;
14
+ return shared.contexts;
15
+ }
16
+ /** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme`; `contexts` are those of its prefix unless given. */
17
+ function bindEngine(engine, { hasServerStyleElements = true } = {}, contexts = readSharedContexts(engine)) {
18
+ const { useTheme, useThemeView, useThemeClass, ThemeScope } = require_ThemeValue.createThemeValue(engine, contexts);
19
+ const hasStyleElements = () => hasServerStyleElements && typeof document === "undefined";
20
+ const renderStyleElements = (className, cache) => cache === void 0 && hasStyleElements() ? require_styleElements.createStyleElements(engine.cache, className) : [];
21
+ const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
22
+ const useStyle = ((sheet) => {
23
+ const cache = require_CacheProvider.useProvidedCache();
24
+ const view = useThemeView(cache);
25
+ const entries = (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.resolve(view) : sheet;
26
+ return cache === void 0 ? entries : engine.withCache(cache).adoptSheet(entries);
27
+ });
28
+ function create(styles) {
29
+ return engine.createSheet(styles);
30
+ }
31
+ return {
32
+ engine,
33
+ cache: engine.cache,
34
+ styled: require_styled.createStyled(engine, useThemeView, renderStyleElements),
35
+ StyleSheet: { create },
36
+ useStyle,
37
+ apply: (...entries) => ({ className: ((0, _umber_style_core.findEntryCache)(entries) ?? engine.cache).css(...entries) || void 0 }),
38
+ css: ((...args) => (0, _umber_style_core.createCssEntry)(engine.cache, args)),
39
+ ThemeProvider: require_ThemeProvider.createThemeProvider({
40
+ engine,
41
+ contexts,
42
+ getServerStyle: () => hasStyleElements() ? {
43
+ createStyleElements: renderStyleElements,
44
+ createStamp: () => require_styleElements.createStampElement(engine.cache)
45
+ } : void 0
46
+ }),
47
+ ThemeScope,
48
+ ThemeContext: contexts.ThemeContext,
49
+ useTheme,
50
+ useThemeClass,
51
+ themeClass,
52
+ when: engine.when,
53
+ whenScheme: engine.whenScheme,
54
+ keyframes: engine.keyframes,
55
+ globalStyles: _umber_style_core.globalStyles,
56
+ Global: require_Global.createGlobal(engine, useThemeView, (sets, cache) => cache === void 0 && hasStyleElements() ? require_styleElements.createGlobalElements(engine.cache, sets) : require_styleElements.createGlobalMarkerElements(cache ?? engine.cache, sets))
57
+ };
58
+ }
59
+ /** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
60
+ function createStyle(theme, options = {}) {
61
+ const engine = options.engine ?? (0, _umber_style_core.createEngine)(theme, options);
62
+ if (!engine.hasTheme) engine.setTheme(theme);
63
+ return bindEngine(engine, options);
64
+ }
65
+ exports.bindEngine = bindEngine;
66
+ exports.createStyle = createStyle;
@@ -0,0 +1,9 @@
1
+ import { Engine } from "@umber-style/core";
2
+ import "./ThemeValue.cjs";
3
+ import { ThemeContexts } from "./ProviderScope.cjs";
4
+ import { ServerStyleOptions, StyleOptions, WebStyle } from "./types.cjs";
5
+ /** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme`; `contexts` are those of its prefix unless given. */
6
+ export declare function bindEngine<T extends object>(engine: Engine<T>, { hasServerStyleElements }?: ServerStyleOptions, contexts?: ThemeContexts<T>): WebStyle<T>;
7
+ /** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
8
+ export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): WebStyle<T>;
9
+ export type { StyleOptions };
@@ -0,0 +1,9 @@
1
+ import { Engine } from "@umber-style/core";
2
+ import "./ThemeValue.mjs";
3
+ import { ThemeContexts } from "./ProviderScope.mjs";
4
+ import { ServerStyleOptions, StyleOptions, WebStyle } from "./types.mjs";
5
+ /** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme`; `contexts` are those of its prefix unless given. */
6
+ export declare function bindEngine<T extends object>(engine: Engine<T>, { hasServerStyleElements }?: ServerStyleOptions, contexts?: ThemeContexts<T>): WebStyle<T>;
7
+ /** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
8
+ export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): WebStyle<T>;
9
+ export type { StyleOptions };
@@ -0,0 +1,65 @@
1
+ import { createCssEntry, createEngine, findEntryCache, globalStyles, isThemedSheet } from "@umber-style/core";
2
+ import { useProvidedCache } from "./CacheProvider.mjs";
3
+ import { createGlobal } from "./Global.mjs";
4
+ import { readPrefixStyle } from "./ProviderScope.mjs";
5
+ import { createGlobalElements, createGlobalMarkerElements, createStampElement, createStyleElements } from "./styleElements.mjs";
6
+ import { createStyled } from "./styled.mjs";
7
+ import { createThemeProvider } from "./ThemeProvider.mjs";
8
+ import { createThemeValue } from "./ThemeValue.mjs";
9
+ // src/createStyle.ts
10
+ /** 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
+ function readSharedContexts(engine) {
12
+ const shared = readPrefixStyle(engine.cache.prefix);
13
+ shared.holder ??= engine;
14
+ return shared.contexts;
15
+ }
16
+ /** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme`; `contexts` are those of its prefix unless given. */
17
+ function bindEngine(engine, { hasServerStyleElements = true } = {}, contexts = readSharedContexts(engine)) {
18
+ const { useTheme, useThemeView, useThemeClass, ThemeScope } = createThemeValue(engine, contexts);
19
+ const hasStyleElements = () => hasServerStyleElements && typeof document === "undefined";
20
+ const renderStyleElements = (className, cache) => cache === void 0 && hasStyleElements() ? createStyleElements(engine.cache, className) : [];
21
+ const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
22
+ const useStyle = ((sheet) => {
23
+ const cache = useProvidedCache();
24
+ const view = useThemeView(cache);
25
+ const entries = isThemedSheet(sheet) ? sheet.resolve(view) : sheet;
26
+ return cache === void 0 ? entries : engine.withCache(cache).adoptSheet(entries);
27
+ });
28
+ function create(styles) {
29
+ return engine.createSheet(styles);
30
+ }
31
+ return {
32
+ engine,
33
+ cache: engine.cache,
34
+ styled: createStyled(engine, useThemeView, renderStyleElements),
35
+ StyleSheet: { create },
36
+ useStyle,
37
+ apply: (...entries) => ({ className: (findEntryCache(entries) ?? engine.cache).css(...entries) || void 0 }),
38
+ css: ((...args) => createCssEntry(engine.cache, args)),
39
+ ThemeProvider: createThemeProvider({
40
+ engine,
41
+ contexts,
42
+ getServerStyle: () => hasStyleElements() ? {
43
+ createStyleElements: renderStyleElements,
44
+ createStamp: () => createStampElement(engine.cache)
45
+ } : void 0
46
+ }),
47
+ ThemeScope,
48
+ ThemeContext: contexts.ThemeContext,
49
+ useTheme,
50
+ useThemeClass,
51
+ themeClass,
52
+ when: engine.when,
53
+ whenScheme: engine.whenScheme,
54
+ keyframes: engine.keyframes,
55
+ globalStyles,
56
+ Global: createGlobal(engine, useThemeView, (sets, cache) => cache === void 0 && hasStyleElements() ? createGlobalElements(engine.cache, sets) : createGlobalMarkerElements(cache ?? engine.cache, sets))
57
+ };
58
+ }
59
+ /** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
60
+ function createStyle(theme, options = {}) {
61
+ const engine = options.engine ?? createEngine(theme, options);
62
+ if (!engine.hasTheme) engine.setTheme(theme);
63
+ return bindEngine(engine, options);
64
+ }
65
+ export { bindEngine, createStyle };
@@ -0,0 +1,60 @@
1
+ let _umber_style_core = require("@umber-style/core");
2
+ const require_Global_server = require("./Global.server.cjs");
3
+ const require_serverContext = require("./serverContext.cjs");
4
+ const require_styled_server = require("./styled.server.cjs");
5
+ const require_ThemeProvider_server = require("./ThemeProvider.server.cjs");
6
+ // src/createStyle.server.ts
7
+ /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
8
+ function bindEngine(engine, cache) {
9
+ const readFirstSlot = require_serverContext.createRequestSlot(void 0, cache);
10
+ let hasWarned = false;
11
+ const readBaseTheme = () => engine.baseTheme ?? _umber_style_core.EMPTY_THEME;
12
+ /**
13
+ * The base theme: the one given to `createStyle(theme)` or `configure({ theme })`, the same in every
14
+ * render of every request, whatever providers render. With none, an empty object, and one warning in
15
+ * development. A server component cannot see the providers above it: what needs the nearest theme's
16
+ * values is a client component, whose `useTheme()` reads them.
17
+ */
18
+ const useTheme = () => {
19
+ if (engine.baseTheme === void 0 && !hasWarned && (0, _umber_style_core.isDevelopment)()) {
20
+ hasWarned = true;
21
+ console.warn(`[${engine.cache.prefix}] useTheme() in a server component returns the base theme, and there is none: give the theme to createStyle(theme) or configure({ theme }) to read it in server components. It returns an empty object.`);
22
+ }
23
+ return readBaseTheme();
24
+ };
25
+ const readViewTheme = () => engine.baseTheme ?? readFirstSlot().current ?? _umber_style_core.EMPTY_THEME;
26
+ const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
27
+ const useStyle = ((sheet) => (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.resolve(engine.createThemeView(readViewTheme())) : sheet);
28
+ function create(styles) {
29
+ return engine.createSheet(styles);
30
+ }
31
+ return {
32
+ engine,
33
+ cache: engine.cache,
34
+ styled: require_styled_server.createStyled(engine, readViewTheme),
35
+ StyleSheet: { create },
36
+ useStyle,
37
+ apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
38
+ css: ((...args) => (0, _umber_style_core.createCssEntry)(engine.cache, args)),
39
+ ThemeProvider: require_ThemeProvider_server.createThemeProvider(engine, {
40
+ readFirstSlot,
41
+ readBaseTheme
42
+ }),
43
+ useTheme,
44
+ readTheme: useTheme,
45
+ themeClass,
46
+ when: engine.when,
47
+ whenScheme: engine.whenScheme,
48
+ keyframes: engine.keyframes,
49
+ globalStyles: _umber_style_core.globalStyles,
50
+ Global: require_Global_server.createGlobal(engine, readViewTheme)
51
+ };
52
+ }
53
+ /** Makes the styling for server components of one theme shape: its own engine, or the one given. */
54
+ function createStyle(theme, options = {}) {
55
+ const engine = options.engine ?? (0, _umber_style_core.createEngine)(theme, options);
56
+ if (!engine.hasTheme) engine.setTheme(theme);
57
+ return bindEngine(engine);
58
+ }
59
+ exports.bindEngine = bindEngine;
60
+ exports.createStyle = createStyle;
@@ -0,0 +1,8 @@
1
+ import { Engine } from "@umber-style/core";
2
+ import { CacheFunction } from "./serverContext.cjs";
3
+ import { ServerStyle, StyleOptions } from "./types.cjs";
4
+ /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
5
+ export declare function bindEngine<T extends object>(engine: Engine<T>, cache?: CacheFunction): ServerStyle<T>;
6
+ /** Makes the styling for server components of one theme shape: its own engine, or the one given. */
7
+ export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): ServerStyle<T>;
8
+ export type { StyleOptions };
@@ -0,0 +1,8 @@
1
+ import { Engine } from "@umber-style/core";
2
+ import { CacheFunction } from "./serverContext.mjs";
3
+ import { ServerStyle, StyleOptions } from "./types.mjs";
4
+ /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
5
+ export declare function bindEngine<T extends object>(engine: Engine<T>, cache?: CacheFunction): ServerStyle<T>;
6
+ /** Makes the styling for server components of one theme shape: its own engine, or the one given. */
7
+ export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): ServerStyle<T>;
8
+ export type { StyleOptions };
@@ -0,0 +1,59 @@
1
+ import { EMPTY_THEME, createCssEntry, createEngine, globalStyles, isDevelopment, isThemedSheet } from "@umber-style/core";
2
+ import { createGlobal } from "./Global.server.mjs";
3
+ import { createRequestSlot } from "./serverContext.mjs";
4
+ import { createStyled } from "./styled.server.mjs";
5
+ import { createThemeProvider } from "./ThemeProvider.server.mjs";
6
+ // src/createStyle.server.ts
7
+ /** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
8
+ function bindEngine(engine, cache) {
9
+ const readFirstSlot = createRequestSlot(void 0, cache);
10
+ let hasWarned = false;
11
+ const readBaseTheme = () => engine.baseTheme ?? EMPTY_THEME;
12
+ /**
13
+ * The base theme: the one given to `createStyle(theme)` or `configure({ theme })`, the same in every
14
+ * render of every request, whatever providers render. With none, an empty object, and one warning in
15
+ * development. A server component cannot see the providers above it: what needs the nearest theme's
16
+ * values is a client component, whose `useTheme()` reads them.
17
+ */
18
+ const useTheme = () => {
19
+ if (engine.baseTheme === void 0 && !hasWarned && isDevelopment()) {
20
+ hasWarned = true;
21
+ console.warn(`[${engine.cache.prefix}] useTheme() in a server component returns the base theme, and there is none: give the theme to createStyle(theme) or configure({ theme }) to read it in server components. It returns an empty object.`);
22
+ }
23
+ return readBaseTheme();
24
+ };
25
+ const readViewTheme = () => engine.baseTheme ?? readFirstSlot().current ?? EMPTY_THEME;
26
+ const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
27
+ const useStyle = ((sheet) => isThemedSheet(sheet) ? sheet.resolve(engine.createThemeView(readViewTheme())) : sheet);
28
+ function create(styles) {
29
+ return engine.createSheet(styles);
30
+ }
31
+ return {
32
+ engine,
33
+ cache: engine.cache,
34
+ styled: createStyled(engine, readViewTheme),
35
+ StyleSheet: { create },
36
+ useStyle,
37
+ apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
38
+ css: ((...args) => createCssEntry(engine.cache, args)),
39
+ ThemeProvider: createThemeProvider(engine, {
40
+ readFirstSlot,
41
+ readBaseTheme
42
+ }),
43
+ useTheme,
44
+ readTheme: useTheme,
45
+ themeClass,
46
+ when: engine.when,
47
+ whenScheme: engine.whenScheme,
48
+ keyframes: engine.keyframes,
49
+ globalStyles,
50
+ Global: createGlobal(engine, readViewTheme)
51
+ };
52
+ }
53
+ /** Makes the styling for server components of one theme shape: its own engine, or the one given. */
54
+ function createStyle(theme, options = {}) {
55
+ const engine = options.engine ?? createEngine(theme, options);
56
+ if (!engine.hasTheme) engine.setTheme(theme);
57
+ return bindEngine(engine);
58
+ }
59
+ export { bindEngine, createStyle };
@@ -0,0 +1,68 @@
1
+ let _umber_style_core = require("@umber-style/core");
2
+ const require_createStyle = require("./createStyle.cjs");
3
+ const require_ProviderScope = require("./ProviderScope.cjs");
4
+ // src/defaultStyle.ts
5
+ /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
6
+ function createDefaultStyle() {
7
+ let pending = {};
8
+ let bound;
9
+ const contexts = require_ProviderScope.createThemeContexts();
10
+ const getStyle = () => {
11
+ if (!bound) {
12
+ const engine = pending.engine ?? (0, _umber_style_core.createLazyEngine)(pending);
13
+ if (pending.theme) engine.setTheme(pending.theme);
14
+ bound = require_createStyle.bindEngine(engine, pending, contexts);
15
+ }
16
+ return bound;
17
+ };
18
+ require_ProviderScope.claimPrefixStyle(() => bound?.cache.prefix ?? pending.engine?.cache.prefix ?? pending.cache?.prefix ?? pending.prefix ?? "css", {
19
+ contexts,
20
+ holder: { get baseTheme() {
21
+ return bound?.engine.baseTheme ?? pending.theme ?? pending.engine?.baseTheme;
22
+ } }
23
+ });
24
+ /** Sets the options of the default engine, and gives it a base theme or an engine to share. Throws once the default style was used. */
25
+ function configure(options) {
26
+ if (bound) throw new Error("configure must be called before the default style is used.");
27
+ pending = options;
28
+ }
29
+ const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => getStyle().styled(tag, options)));
30
+ const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
31
+ const useStyle = ((sheet) => getStyle().useStyle(sheet));
32
+ function useTheme() {
33
+ return getStyle().useTheme();
34
+ }
35
+ function ThemeProvider(props) {
36
+ return getStyle().ThemeProvider(props);
37
+ }
38
+ function Global(props) {
39
+ return getStyle().Global(props);
40
+ }
41
+ function ThemeScope(props) {
42
+ return getStyle().ThemeScope(props);
43
+ }
44
+ function useThemeClass() {
45
+ return getStyle().useThemeClass();
46
+ }
47
+ return {
48
+ configure,
49
+ getEngine: () => getStyle().engine,
50
+ styled,
51
+ StyleSheet,
52
+ useStyle,
53
+ useTheme,
54
+ ThemeProvider,
55
+ ThemeScope,
56
+ useThemeClass,
57
+ ThemeContext: contexts.ThemeContext,
58
+ apply: ((...entries) => getStyle().apply(...entries)),
59
+ css: ((...args) => (0, _umber_style_core.createDeferredObject)(() => getStyle().css(...args))),
60
+ when: ((theme, colorScheme) => getStyle().when(theme, colorScheme)),
61
+ whenScheme: ((scheme) => getStyle().whenScheme(scheme)),
62
+ themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme)),
63
+ keyframes: _umber_style_core.keyframes,
64
+ globalStyles: _umber_style_core.globalStyles,
65
+ Global
66
+ };
67
+ }
68
+ exports.createDefaultStyle = createDefaultStyle;
@@ -0,0 +1,29 @@
1
+ import { DefaultStyleOptions, GlobalProps, SheetDefinition, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.cjs";
2
+ import { WebStyleObject } from "@umber-style/core";
3
+ /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
4
+ export declare function createDefaultStyle(): {
5
+ configure: (options: DefaultStyleOptions) => void;
6
+ getEngine: () => import("@umber-style/core").Engine<Theme$1>;
7
+ styled: Styled<Theme$1>;
8
+ StyleSheet: {
9
+ create<K extends string>(styles: import("@umber-style/core").ObjectSheet<K>): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
10
+ create<K extends string>(styles: (theme: Theme$1) => Record<K, WebStyleObject>): SheetDefinition<Record<K, WebStyleObject>, import("@umber-style/core").SheetEntry>;
11
+ };
12
+ useStyle: {
13
+ <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
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
+ };
16
+ useTheme: () => Theme$1;
17
+ ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
+ ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
+ useThemeClass: () => string | undefined;
20
+ ThemeContext: import("react").Context<Theme$1 | undefined>;
21
+ apply: WebStyle<Theme$1>['apply'];
22
+ css: WebStyle<Theme$1>['css'];
23
+ when: WebStyle<Theme$1>['when'];
24
+ whenScheme: WebStyle<Theme$1>['whenScheme'];
25
+ themeClass: WebStyle<Theme$1>['themeClass'];
26
+ keyframes: WebStyle<Theme$1>['keyframes'];
27
+ globalStyles: WebStyle<Theme$1>['globalStyles'];
28
+ Global: (props: GlobalProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
29
+ };
@@ -0,0 +1,29 @@
1
+ import { DefaultStyleOptions, GlobalProps, SheetDefinition, Styled, Theme as Theme$1, ThemeScopeProps, WebStyle, WebThemeProviderProps } from "./types.mjs";
2
+ import { WebStyleObject } from "@umber-style/core";
3
+ /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
4
+ export declare function createDefaultStyle(): {
5
+ configure: (options: DefaultStyleOptions) => void;
6
+ getEngine: () => import("@umber-style/core").Engine<Theme$1>;
7
+ styled: Styled<Theme$1>;
8
+ StyleSheet: {
9
+ create<K extends string>(styles: import("@umber-style/core").ObjectSheet<K>): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
10
+ create<K extends string>(styles: (theme: Theme$1) => Record<K, WebStyleObject>): SheetDefinition<Record<K, WebStyleObject>, import("@umber-style/core").SheetEntry>;
11
+ };
12
+ useStyle: {
13
+ <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
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
+ };
16
+ useTheme: () => Theme$1;
17
+ ThemeProvider: (props: WebThemeProviderProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
+ ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
+ useThemeClass: () => string | undefined;
20
+ ThemeContext: import("react").Context<Theme$1 | undefined>;
21
+ apply: WebStyle<Theme$1>['apply'];
22
+ css: WebStyle<Theme$1>['css'];
23
+ when: WebStyle<Theme$1>['when'];
24
+ whenScheme: WebStyle<Theme$1>['whenScheme'];
25
+ themeClass: WebStyle<Theme$1>['themeClass'];
26
+ keyframes: WebStyle<Theme$1>['keyframes'];
27
+ globalStyles: WebStyle<Theme$1>['globalStyles'];
28
+ Global: (props: GlobalProps<Theme$1>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
29
+ };
@@ -0,0 +1,68 @@
1
+ import { createDeferredObject, createDeferredRecord, createLazyEngine, globalStyles, keyframes, withTagShorthands } from "@umber-style/core";
2
+ import { bindEngine } from "./createStyle.mjs";
3
+ import { claimPrefixStyle, createThemeContexts } from "./ProviderScope.mjs";
4
+ // src/defaultStyle.ts
5
+ /** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
6
+ function createDefaultStyle() {
7
+ let pending = {};
8
+ let bound;
9
+ const contexts = createThemeContexts();
10
+ const getStyle = () => {
11
+ if (!bound) {
12
+ const engine = pending.engine ?? createLazyEngine(pending);
13
+ if (pending.theme) engine.setTheme(pending.theme);
14
+ bound = bindEngine(engine, pending, contexts);
15
+ }
16
+ return bound;
17
+ };
18
+ claimPrefixStyle(() => bound?.cache.prefix ?? pending.engine?.cache.prefix ?? pending.cache?.prefix ?? pending.prefix ?? "css", {
19
+ contexts,
20
+ holder: { get baseTheme() {
21
+ return bound?.engine.baseTheme ?? pending.theme ?? pending.engine?.baseTheme;
22
+ } }
23
+ });
24
+ /** Sets the options of the default engine, and gives it a base theme or an engine to share. Throws once the default style was used. */
25
+ function configure(options) {
26
+ if (bound) throw new Error("configure must be called before the default style is used.");
27
+ pending = options;
28
+ }
29
+ const styled = withTagShorthands(((tag, options) => getStyle().styled(tag, options)));
30
+ const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
31
+ const useStyle = ((sheet) => getStyle().useStyle(sheet));
32
+ function useTheme() {
33
+ return getStyle().useTheme();
34
+ }
35
+ function ThemeProvider(props) {
36
+ return getStyle().ThemeProvider(props);
37
+ }
38
+ function Global(props) {
39
+ return getStyle().Global(props);
40
+ }
41
+ function ThemeScope(props) {
42
+ return getStyle().ThemeScope(props);
43
+ }
44
+ function useThemeClass() {
45
+ return getStyle().useThemeClass();
46
+ }
47
+ return {
48
+ configure,
49
+ getEngine: () => getStyle().engine,
50
+ styled,
51
+ StyleSheet,
52
+ useStyle,
53
+ useTheme,
54
+ ThemeProvider,
55
+ ThemeScope,
56
+ useThemeClass,
57
+ ThemeContext: contexts.ThemeContext,
58
+ apply: ((...entries) => getStyle().apply(...entries)),
59
+ css: ((...args) => createDeferredObject(() => getStyle().css(...args))),
60
+ when: ((theme, colorScheme) => getStyle().when(theme, colorScheme)),
61
+ whenScheme: ((scheme) => getStyle().whenScheme(scheme)),
62
+ themeClass: ((theme, colorScheme) => getStyle().themeClass(theme, colorScheme)),
63
+ keyframes,
64
+ globalStyles,
65
+ Global
66
+ };
67
+ }
68
+ export { createDefaultStyle };