@umber-style/react 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.
- package/dist/CacheProvider.cjs +23 -0
- package/dist/CacheProvider.d.cts +10 -0
- package/dist/CacheProvider.d.mts +11 -0
- package/dist/CacheProvider.mjs +22 -0
- package/dist/Global.cjs +52 -0
- package/dist/Global.mjs +52 -0
- package/dist/Global.server.cjs +27 -0
- package/dist/Global.server.mjs +27 -0
- package/dist/GlobalRelease.cjs +32 -0
- package/dist/GlobalRelease.mjs +30 -0
- package/dist/ProviderScope.cjs +201 -0
- package/dist/ProviderScope.d.cts +14 -0
- package/dist/ProviderScope.d.mts +15 -0
- package/dist/ProviderScope.mjs +190 -0
- package/dist/ThemeProvider.cjs +94 -27
- package/dist/ThemeProvider.mjs +95 -28
- package/dist/ThemeProvider.server.cjs +130 -25
- package/dist/ThemeProvider.server.mjs +131 -26
- package/dist/ThemeValue.cjs +52 -20
- package/dist/ThemeValue.d.cts +3 -0
- package/dist/ThemeValue.d.mts +4 -0
- package/dist/ThemeValue.mjs +53 -23
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/createStyle.cjs +30 -20
- package/dist/createStyle.d.cts +4 -2
- package/dist/createStyle.d.mts +4 -2
- package/dist/createStyle.mjs +32 -22
- package/dist/createStyle.server.cjs +29 -22
- package/dist/createStyle.server.mjs +31 -24
- package/dist/defaultStyle.cjs +27 -3
- package/dist/defaultStyle.d.cts +18 -11
- package/dist/defaultStyle.d.mts +18 -11
- package/dist/defaultStyle.mjs +28 -4
- package/dist/defaultStyle.server.cjs +13 -5
- package/dist/defaultStyle.server.d.cts +16 -11
- package/dist/defaultStyle.server.d.mts +16 -11
- package/dist/defaultStyle.server.mjs +14 -6
- package/dist/domProps.cjs +27 -0
- package/dist/domProps.mjs +27 -0
- package/dist/index.cjs +12 -1
- package/dist/index.d.cts +17 -7
- package/dist/index.d.mts +17 -7
- package/dist/index.mjs +4 -2
- package/dist/index.server.cjs +6 -1
- package/dist/index.server.d.cts +15 -7
- package/dist/index.server.d.mts +15 -7
- package/dist/index.server.mjs +2 -2
- package/dist/plainTheme.cjs +49 -0
- package/dist/plainTheme.mjs +49 -0
- package/dist/serverContext.cjs +6 -24
- package/dist/serverContext.d.mts +0 -1
- package/dist/serverContext.mjs +6 -23
- package/dist/styleElements.cjs +75 -9
- package/dist/styleElements.d.cts +1 -0
- package/dist/styleElements.d.mts +2 -0
- package/dist/styleElements.mjs +73 -10
- package/dist/styled.cjs +32 -11
- package/dist/styled.mjs +33 -12
- package/dist/styled.server.cjs +6 -4
- package/dist/styled.server.mjs +6 -4
- package/dist/styledParts.cjs +36 -6
- package/dist/styledParts.mjs +37 -7
- package/dist/types.d.cts +225 -19
- package/dist/types.d.mts +225 -19
- package/dist/useMediaQuery.cjs +20 -0
- package/dist/useMediaQuery.d.cts +13 -0
- package/dist/useMediaQuery.d.mts +13 -0
- package/dist/useMediaQuery.mjs +20 -0
- package/package.json +3 -3
|
@@ -1,35 +1,140 @@
|
|
|
1
1
|
import { Fragment, createElement } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { createThemeClassName, createThemeId, hashString, isDevelopment, resolveThemeInput } from "@umber-style/core";
|
|
3
|
+
import { toPlainTheme } from "./plainTheme.mjs";
|
|
4
|
+
import { ProviderScope } from "./ProviderScope.mjs";
|
|
5
|
+
import { collectStyleTexts, createStampElement, createStyleElements } from "./styleElements.mjs";
|
|
3
6
|
// src/ThemeProvider.server.ts
|
|
4
7
|
/**
|
|
5
|
-
* Makes the `ThemeProvider` for server components
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Makes the `ThemeProvider` for server components. A server component has no context, and a server
|
|
9
|
+
* render of a part of the page (a client-side navigation renders only the segment that changed) does not
|
|
10
|
+
* render the providers of the layouts above, so the server cannot tell whether a provider of the same
|
|
11
|
+
* engine is above this one, nor what theme it has. It decides nothing: it renders `ProviderScope`, a
|
|
12
|
+
* client component, with the theme it was given as plain data and what either outcome needs, and that
|
|
13
|
+
* decides in the tree as it is rendered, on the server for the first HTML and in the browser after a
|
|
14
|
+
* navigation. It puts the theme into the theme context of the client build too, merged over the theme
|
|
15
|
+
* of the provider above it in the page, so `useTheme()` of a client component below reads it.
|
|
16
|
+
*
|
|
17
|
+
* The values of the theme are sent once: the rules are made from them in `ProviderScope`. A member that
|
|
18
|
+
* cannot cross to a client component (a function, a symbol, a class instance) is left out, with one
|
|
19
|
+
* warning in development. The first provider of a request also sends the base theme, for the root rule,
|
|
20
|
+
* when the given theme does not declare all of it (one object for each base theme, which a payload holds
|
|
21
|
+
* once), and the stamp of the cache options (a `<meta>`).
|
|
22
|
+
*
|
|
23
|
+
* It never gives the engine a base theme: that comes from `createStyle(theme)` or `configure({ theme })`.
|
|
24
|
+
* A function theme is called with the base theme, in every render. With `isRoot` it makes no rule: it
|
|
25
|
+
* sends the style of the theme classes that the app already made for its theme with `themeClass`, the
|
|
26
|
+
* class it put on an ancestor, and renders `ProviderScope` with no rules.
|
|
12
27
|
*/
|
|
13
|
-
function createThemeProvider(engine,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
function createThemeProvider(engine, { readFirstSlot, readBaseTheme }) {
|
|
29
|
+
const prefix = engine.cache.prefix;
|
|
30
|
+
const { rawKeys, lengthKeys, modes } = engine.tokenOptions;
|
|
31
|
+
const tokens = {
|
|
32
|
+
...rawKeys && { rawKeys },
|
|
33
|
+
...lengthKeys && { lengthKeys },
|
|
34
|
+
...modes && { modes }
|
|
35
|
+
};
|
|
36
|
+
let sentBase;
|
|
37
|
+
let hasWarned = false;
|
|
38
|
+
/** The plain data of `given`, with one warning in development for the first theme that has members left out. */
|
|
39
|
+
const readPlain = (given) => {
|
|
40
|
+
const { theme, dropped } = toPlainTheme(given);
|
|
41
|
+
if (dropped.length > 0 && !hasWarned && isDevelopment()) {
|
|
42
|
+
hasWarned = true;
|
|
43
|
+
console.warn(`[${prefix}] A ThemeProvider of a server component was given a theme with members that cannot cross to a client component: ${dropped.join(", ")}. They are left out of the theme that client components read below it, where these members keep the values of the theme above.`);
|
|
44
|
+
}
|
|
45
|
+
return theme;
|
|
46
|
+
};
|
|
47
|
+
/** The base theme as sent, for `base`. */
|
|
48
|
+
const readBase = (base) => {
|
|
49
|
+
if (sentBase?.theme !== base) {
|
|
50
|
+
const { properties } = engine.readThemeText(base);
|
|
51
|
+
sentBase = {
|
|
52
|
+
theme: base,
|
|
53
|
+
sent: {
|
|
54
|
+
theme: toPlainTheme(base).theme,
|
|
55
|
+
properties
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return sentBase.sent;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* What `ProviderScope` needs to render either outcome for the theme `given`. The base theme goes under a
|
|
63
|
+
* theme that does not declare all of it, for its root rule, only from the first provider of a request:
|
|
64
|
+
* one that renders after another one in the same request is below it or beside it, and is not the
|
|
65
|
+
* outermost one of the page.
|
|
66
|
+
*/
|
|
67
|
+
const describe = (given, { colorScheme, className, as = "div" }, isFirst) => {
|
|
68
|
+
const { cache, baseTheme } = engine;
|
|
69
|
+
const text = engine.readThemeText(given);
|
|
70
|
+
const classId = createThemeId(prefix, text.declarations, colorScheme);
|
|
71
|
+
const own = text.declarations + (colorScheme ? `color-scheme:${colorScheme};` : "");
|
|
72
|
+
const baseText = baseTheme && engine.readThemeText(baseTheme);
|
|
73
|
+
const names = new Set(text.names);
|
|
74
|
+
const isWhole = baseText === void 0 || baseText.names.every((name) => names.has(name));
|
|
75
|
+
const base = isWhole || !isFirst ? void 0 : readBase(baseTheme);
|
|
76
|
+
const others = [engine.scopeClass(), className].filter(Boolean).join(" ");
|
|
77
|
+
const rootBody = (base === void 0 ? "" : baseText.declarations) + own;
|
|
78
|
+
return {
|
|
79
|
+
as,
|
|
80
|
+
className: [createThemeClassName(prefix, classId, colorScheme), others].join(" "),
|
|
81
|
+
classId,
|
|
82
|
+
rootId: `${prefix}-root-${hashString(rootBody)}`,
|
|
83
|
+
layerOrder: cache.layerOrder,
|
|
84
|
+
...colorScheme && { colorScheme },
|
|
85
|
+
tokens,
|
|
86
|
+
properties: text.properties,
|
|
87
|
+
isWhole,
|
|
88
|
+
...base && { base },
|
|
89
|
+
styles: collectStyleTexts(cache, others)
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const described = /* @__PURE__ */ new WeakMap();
|
|
93
|
+
const readDescription = (given, props, isFirst) => {
|
|
94
|
+
const { colorScheme, className, as } = props;
|
|
95
|
+
const key = [
|
|
96
|
+
colorScheme,
|
|
97
|
+
className,
|
|
98
|
+
as,
|
|
99
|
+
isFirst
|
|
100
|
+
].join("|");
|
|
101
|
+
const known = described.get(given) ?? /* @__PURE__ */ new Map();
|
|
102
|
+
described.set(given, known);
|
|
103
|
+
let made = known.get(key);
|
|
104
|
+
if (made === void 0 || made.base !== engine.baseTheme) {
|
|
105
|
+
made = {
|
|
106
|
+
base: engine.baseTheme,
|
|
107
|
+
theme: describe(given, props, isFirst)
|
|
108
|
+
};
|
|
109
|
+
known.set(key, made);
|
|
110
|
+
}
|
|
111
|
+
return made.theme;
|
|
112
|
+
};
|
|
113
|
+
return function ThemeProvider(props) {
|
|
114
|
+
const { theme, isRoot, children } = props;
|
|
115
|
+
const given = resolveThemeInput(theme, readBaseTheme());
|
|
116
|
+
const slot = readFirstSlot();
|
|
117
|
+
const isFirst = !slot.isSet;
|
|
118
|
+
if (isFirst) {
|
|
119
|
+
slot.isSet = true;
|
|
120
|
+
slot.current = given;
|
|
121
|
+
}
|
|
122
|
+
const stamped = isFirst ? [createStampElement(engine.cache)] : [];
|
|
123
|
+
const plain = readPlain(given);
|
|
19
124
|
if (isRoot) {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
125
|
+
const made = createStyleElements(engine.cache, engine.findThemeIds(given).join(" "));
|
|
126
|
+
const scope = createElement(ProviderScope, {
|
|
127
|
+
prefix,
|
|
128
|
+
given: plain
|
|
129
|
+
}, children);
|
|
130
|
+
return createElement(Fragment, null, ...stamped, ...made, scope);
|
|
23
131
|
}
|
|
24
|
-
const scope =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
className
|
|
31
|
-
].filter(Boolean).join(" ") };
|
|
32
|
-
return createElement(Fragment, null, ...stamped, ...styles, ...createStyleElements(engine.cache, scoped), createElement(as, props, provided));
|
|
132
|
+
const scope = createElement(ProviderScope, {
|
|
133
|
+
prefix,
|
|
134
|
+
given: plain,
|
|
135
|
+
theme: readDescription(given, props, isFirst)
|
|
136
|
+
}, children);
|
|
137
|
+
return createElement(Fragment, null, ...stamped, scope);
|
|
33
138
|
};
|
|
34
139
|
}
|
|
35
140
|
export { createThemeProvider };
|
package/dist/ThemeValue.cjs
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
let react = require("react");
|
|
3
3
|
let _umber_style_core = require("@umber-style/core");
|
|
4
|
-
|
|
4
|
+
const require_CacheProvider = require("./CacheProvider.cjs");
|
|
5
|
+
const require_ProviderScope = require("./ProviderScope.cjs");
|
|
5
6
|
// src/ThemeValue.tsx
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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();
|
|
16
22
|
}
|
|
17
|
-
/**
|
|
18
|
-
function
|
|
19
|
-
|
|
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());
|
|
20
36
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
54
|
}
|
|
26
55
|
return {
|
|
27
|
-
ThemeValueProvider,
|
|
28
56
|
useTheme,
|
|
29
|
-
|
|
57
|
+
useThemeView,
|
|
58
|
+
useThemeClass,
|
|
59
|
+
ThemeScope
|
|
30
60
|
};
|
|
31
61
|
}
|
|
62
|
+
exports.createThemeContexts = require_ProviderScope.createThemeContexts;
|
|
32
63
|
exports.createThemeValue = createThemeValue;
|
|
64
|
+
exports.readMarkKey = readMarkKey;
|
package/dist/ThemeValue.mjs
CHANGED
|
@@ -1,32 +1,62 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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";
|
|
5
6
|
// src/ThemeValue.tsx
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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();
|
|
16
22
|
}
|
|
17
|
-
/**
|
|
18
|
-
function
|
|
19
|
-
|
|
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());
|
|
20
36
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
54
|
}
|
|
26
55
|
return {
|
|
27
|
-
ThemeValueProvider,
|
|
28
56
|
useTheme,
|
|
29
|
-
|
|
57
|
+
useThemeView,
|
|
58
|
+
useThemeClass,
|
|
59
|
+
ThemeScope
|
|
30
60
|
};
|
|
31
61
|
}
|
|
32
|
-
export { createThemeValue };
|
|
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;
|
package/dist/createStyle.cjs
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
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");
|
|
2
5
|
const require_styleElements = require("./styleElements.cjs");
|
|
3
6
|
const require_styled = require("./styled.cjs");
|
|
4
7
|
const require_ThemeProvider = require("./ThemeProvider.cjs");
|
|
5
8
|
const require_ThemeValue = require("./ThemeValue.cjs");
|
|
6
9
|
// src/createStyle.ts
|
|
7
|
-
/**
|
|
8
|
-
function
|
|
9
|
-
const
|
|
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);
|
|
10
19
|
const hasStyleElements = () => hasServerStyleElements && typeof document === "undefined";
|
|
11
|
-
const renderStyleElements = (className) => hasStyleElements() ? require_styleElements.createStyleElements(engine.cache, className) : [];
|
|
12
|
-
const useThemeView = () => engine.createThemeView(useTheme());
|
|
20
|
+
const renderStyleElements = (className, cache) => cache === void 0 && hasStyleElements() ? require_styleElements.createStyleElements(engine.cache, className) : [];
|
|
13
21
|
const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
|
|
14
22
|
const useStyle = ((sheet) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
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);
|
|
18
27
|
});
|
|
19
28
|
function create(styles) {
|
|
20
29
|
return engine.createSheet(styles);
|
|
@@ -25,25 +34,26 @@ function bindEngine(engine, { hasServerStyleElements = true } = {}) {
|
|
|
25
34
|
styled: require_styled.createStyled(engine, useThemeView, renderStyleElements),
|
|
26
35
|
StyleSheet: { create },
|
|
27
36
|
useStyle,
|
|
28
|
-
apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
|
|
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)),
|
|
29
39
|
ThemeProvider: require_ThemeProvider.createThemeProvider({
|
|
40
|
+
engine,
|
|
41
|
+
contexts,
|
|
30
42
|
getServerStyle: () => hasStyleElements() ? {
|
|
31
43
|
createStyleElements: renderStyleElements,
|
|
32
|
-
createStamp: () => require_styleElements.createStampElement(engine.cache)
|
|
33
|
-
|
|
34
|
-
themeId: engine.themeId
|
|
35
|
-
} : void 0,
|
|
36
|
-
learnTheme: (theme) => {
|
|
37
|
-
if (!engine.hasTheme) engine.setTheme(theme);
|
|
38
|
-
},
|
|
39
|
-
themeClass,
|
|
40
|
-
scopeClass: engine.scopeClass,
|
|
41
|
-
ThemeValueProvider
|
|
44
|
+
createStamp: () => require_styleElements.createStampElement(engine.cache)
|
|
45
|
+
} : void 0
|
|
42
46
|
}),
|
|
47
|
+
ThemeScope,
|
|
48
|
+
ThemeContext: contexts.ThemeContext,
|
|
43
49
|
useTheme,
|
|
50
|
+
useThemeClass,
|
|
44
51
|
themeClass,
|
|
45
52
|
when: engine.when,
|
|
46
|
-
whenScheme: engine.whenScheme
|
|
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))
|
|
47
57
|
};
|
|
48
58
|
}
|
|
49
59
|
/** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
|
package/dist/createStyle.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Engine } from "@umber-style/core";
|
|
2
|
+
import "./ThemeValue.cjs";
|
|
3
|
+
import { ThemeContexts } from "./ProviderScope.cjs";
|
|
2
4
|
import { ServerStyleOptions, StyleOptions, WebStyle } from "./types.cjs";
|
|
3
|
-
/** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme
|
|
4
|
-
export declare function bindEngine<T extends object>(engine: Engine<T>, { hasServerStyleElements }?: ServerStyleOptions): WebStyle<T>;
|
|
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>;
|
|
5
7
|
/** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
|
|
6
8
|
export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): WebStyle<T>;
|
|
7
9
|
export type { StyleOptions };
|
package/dist/createStyle.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Engine } from "@umber-style/core";
|
|
2
|
+
import "./ThemeValue.mjs";
|
|
3
|
+
import { ThemeContexts } from "./ProviderScope.mjs";
|
|
2
4
|
import { ServerStyleOptions, StyleOptions, WebStyle } from "./types.mjs";
|
|
3
|
-
/** Makes the React styling over an engine: `styled`, sheets, the theme provider and `useTheme
|
|
4
|
-
export declare function bindEngine<T extends object>(engine: Engine<T>, { hasServerStyleElements }?: ServerStyleOptions): WebStyle<T>;
|
|
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>;
|
|
5
7
|
/** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
|
|
6
8
|
export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): WebStyle<T>;
|
|
7
9
|
export type { StyleOptions };
|
package/dist/createStyle.mjs
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { createEngine, isThemedSheet } from "@umber-style/core";
|
|
2
|
-
import {
|
|
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";
|
|
3
6
|
import { createStyled } from "./styled.mjs";
|
|
4
7
|
import { createThemeProvider } from "./ThemeProvider.mjs";
|
|
5
8
|
import { createThemeValue } from "./ThemeValue.mjs";
|
|
6
9
|
// src/createStyle.ts
|
|
7
|
-
/**
|
|
8
|
-
function
|
|
9
|
-
const
|
|
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);
|
|
10
19
|
const hasStyleElements = () => hasServerStyleElements && typeof document === "undefined";
|
|
11
|
-
const renderStyleElements = (className) => hasStyleElements() ? createStyleElements(engine.cache, className) : [];
|
|
12
|
-
const useThemeView = () => engine.createThemeView(useTheme());
|
|
20
|
+
const renderStyleElements = (className, cache) => cache === void 0 && hasStyleElements() ? createStyleElements(engine.cache, className) : [];
|
|
13
21
|
const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
|
|
14
22
|
const useStyle = ((sheet) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
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);
|
|
18
27
|
});
|
|
19
28
|
function create(styles) {
|
|
20
29
|
return engine.createSheet(styles);
|
|
@@ -25,25 +34,26 @@ function bindEngine(engine, { hasServerStyleElements = true } = {}) {
|
|
|
25
34
|
styled: createStyled(engine, useThemeView, renderStyleElements),
|
|
26
35
|
StyleSheet: { create },
|
|
27
36
|
useStyle,
|
|
28
|
-
apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
|
|
37
|
+
apply: (...entries) => ({ className: (findEntryCache(entries) ?? engine.cache).css(...entries) || void 0 }),
|
|
38
|
+
css: ((...args) => createCssEntry(engine.cache, args)),
|
|
29
39
|
ThemeProvider: createThemeProvider({
|
|
40
|
+
engine,
|
|
41
|
+
contexts,
|
|
30
42
|
getServerStyle: () => hasStyleElements() ? {
|
|
31
43
|
createStyleElements: renderStyleElements,
|
|
32
|
-
createStamp: () => createStampElement(engine.cache)
|
|
33
|
-
|
|
34
|
-
themeId: engine.themeId
|
|
35
|
-
} : void 0,
|
|
36
|
-
learnTheme: (theme) => {
|
|
37
|
-
if (!engine.hasTheme) engine.setTheme(theme);
|
|
38
|
-
},
|
|
39
|
-
themeClass,
|
|
40
|
-
scopeClass: engine.scopeClass,
|
|
41
|
-
ThemeValueProvider
|
|
44
|
+
createStamp: () => createStampElement(engine.cache)
|
|
45
|
+
} : void 0
|
|
42
46
|
}),
|
|
47
|
+
ThemeScope,
|
|
48
|
+
ThemeContext: contexts.ThemeContext,
|
|
43
49
|
useTheme,
|
|
50
|
+
useThemeClass,
|
|
44
51
|
themeClass,
|
|
45
52
|
when: engine.when,
|
|
46
|
-
whenScheme: engine.whenScheme
|
|
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))
|
|
47
57
|
};
|
|
48
58
|
}
|
|
49
59
|
/** Makes the React styling of one theme shape, apart from the default one: its own engine, or the one given. */
|
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
let _umber_style_core = require("@umber-style/core");
|
|
2
|
+
const require_Global_server = require("./Global.server.cjs");
|
|
2
3
|
const require_serverContext = require("./serverContext.cjs");
|
|
3
4
|
const require_styled_server = require("./styled.server.cjs");
|
|
4
5
|
const require_ThemeProvider_server = require("./ThemeProvider.server.cjs");
|
|
5
6
|
// src/createStyle.server.ts
|
|
6
7
|
/** Makes the styling for server components over an engine; `cache` makes the slot of a request, `React.cache` unless a test gives one. */
|
|
7
8
|
function bindEngine(engine, cache) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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.`);
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
let theme = merged.get(rootTheme);
|
|
21
|
-
if (theme === void 0) {
|
|
22
|
-
theme = (0, _umber_style_core.mergeDeep)(base, rootTheme);
|
|
23
|
-
merged.set(rootTheme, theme);
|
|
24
|
-
}
|
|
25
|
-
return theme;
|
|
23
|
+
return readBaseTheme();
|
|
26
24
|
};
|
|
25
|
+
const readViewTheme = () => engine.baseTheme ?? readFirstSlot().current ?? _umber_style_core.EMPTY_THEME;
|
|
27
26
|
const themeClass = (partial, colorScheme) => engine.themeClass(partial, colorScheme);
|
|
28
|
-
const useStyle = ((sheet) => (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.resolve(engine.createThemeView(
|
|
27
|
+
const useStyle = ((sheet) => (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.resolve(engine.createThemeView(readViewTheme())) : sheet);
|
|
29
28
|
function create(styles) {
|
|
30
29
|
return engine.createSheet(styles);
|
|
31
30
|
}
|
|
32
31
|
return {
|
|
33
32
|
engine,
|
|
34
33
|
cache: engine.cache,
|
|
35
|
-
styled: require_styled_server.createStyled(engine,
|
|
34
|
+
styled: require_styled_server.createStyled(engine, readViewTheme),
|
|
36
35
|
StyleSheet: { create },
|
|
37
36
|
useStyle,
|
|
38
37
|
apply: (...entries) => ({ className: engine.css(...entries) || void 0 }),
|
|
39
|
-
|
|
40
|
-
|
|
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,
|
|
41
45
|
themeClass,
|
|
42
46
|
when: engine.when,
|
|
43
|
-
whenScheme: engine.whenScheme
|
|
47
|
+
whenScheme: engine.whenScheme,
|
|
48
|
+
keyframes: engine.keyframes,
|
|
49
|
+
globalStyles: _umber_style_core.globalStyles,
|
|
50
|
+
Global: require_Global_server.createGlobal(engine, readViewTheme)
|
|
44
51
|
};
|
|
45
52
|
}
|
|
46
53
|
/** Makes the styling for server components of one theme shape: its own engine, or the one given. */
|