@umber-style/react 0.1.0-rc.2 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CacheProvider.cjs +7 -6
- package/dist/CacheProvider.mjs +8 -6
- package/dist/ProviderScope.cjs +11 -8
- package/dist/ProviderScope.mjs +12 -9
- package/dist/defaultStyle.cjs +4 -0
- package/dist/defaultStyle.mjs +5 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.server.cjs +2 -2
- package/dist/index.server.mjs +2 -2
- package/dist/styledParts.cjs +2 -2
- package/dist/styledParts.mjs +2 -2
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/watchProvidedCaches.cjs +24 -0
- package/dist/watchProvidedCaches.mjs +23 -0
- package/package.json +4 -4
- package/dist/domProps.cjs +0 -27
- package/dist/domProps.mjs +0 -27
package/dist/CacheProvider.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
let react = require("react");
|
|
3
3
|
// src/CacheProvider.tsx
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const provided = (0, require("@umber-style/core").readSharedState)("react.cache-provider@1", () => ({
|
|
5
|
+
context: (0, react.createContext)(void 0),
|
|
6
|
+
isProvided: false
|
|
7
|
+
}));
|
|
7
8
|
/** The cache of the nearest `CacheProvider`, or undefined with none above (read only once one has rendered). */
|
|
8
9
|
function useProvidedCache() {
|
|
9
|
-
return isProvided ? (0, react.use)(
|
|
10
|
+
return provided.isProvided ? (0, react.use)(provided.context) : void 0;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Gives the subtree below it its cache: every rule that a component of the binding writes there goes to
|
|
@@ -16,8 +17,8 @@ function useProvidedCache() {
|
|
|
16
17
|
* app sends the rules of the cache itself (a registry, or `@umber-style/server`).
|
|
17
18
|
*/
|
|
18
19
|
function CacheProvider({ value, children }) {
|
|
19
|
-
isProvided = true;
|
|
20
|
-
return (0, react.createElement)(
|
|
20
|
+
provided.isProvided = true;
|
|
21
|
+
return (0, react.createElement)(provided.context.Provider, { value }, children);
|
|
21
22
|
}
|
|
22
23
|
exports.CacheProvider = CacheProvider;
|
|
23
24
|
exports.useProvidedCache = useProvidedCache;
|
package/dist/CacheProvider.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createContext, createElement, use } from "react";
|
|
3
|
+
import { readSharedState } from "@umber-style/core";
|
|
3
4
|
// src/CacheProvider.tsx
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const provided = readSharedState("react.cache-provider@1", () => ({
|
|
6
|
+
context: createContext(void 0),
|
|
7
|
+
isProvided: false
|
|
8
|
+
}));
|
|
7
9
|
/** The cache of the nearest `CacheProvider`, or undefined with none above (read only once one has rendered). */
|
|
8
10
|
function useProvidedCache() {
|
|
9
|
-
return isProvided ? use(
|
|
11
|
+
return provided.isProvided ? use(provided.context) : void 0;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Gives the subtree below it its cache: every rule that a component of the binding writes there goes to
|
|
@@ -16,7 +18,7 @@ function useProvidedCache() {
|
|
|
16
18
|
* app sends the rules of the cache itself (a registry, or `@umber-style/server`).
|
|
17
19
|
*/
|
|
18
20
|
function CacheProvider({ value, children }) {
|
|
19
|
-
isProvided = true;
|
|
20
|
-
return createElement(
|
|
21
|
+
provided.isProvided = true;
|
|
22
|
+
return createElement(provided.context.Provider, { value }, children);
|
|
21
23
|
}
|
|
22
24
|
export { CacheProvider, useProvidedCache };
|
package/dist/ProviderScope.cjs
CHANGED
|
@@ -5,11 +5,11 @@ let _umber_style_core = require("@umber-style/core");
|
|
|
5
5
|
react = require_runtime.__toESM(react, 1);
|
|
6
6
|
// src/ProviderScope.tsx
|
|
7
7
|
const NO_MARKS = /* @__PURE__ */ new Map();
|
|
8
|
-
|
|
8
|
+
const sharedMarks = (0, _umber_style_core.readSharedState)("react.marks@1", () => ({ context: void 0 }));
|
|
9
9
|
/** The context of the marks, made on first use: where this module is loaded with the server build of React, nothing renders it. */
|
|
10
10
|
function getMarksContext() {
|
|
11
|
-
|
|
12
|
-
return
|
|
11
|
+
sharedMarks.context ??= react.createContext(NO_MARKS);
|
|
12
|
+
return sharedMarks.context;
|
|
13
13
|
}
|
|
14
14
|
/** `marks`, with `mark` as the nearest provider of `key`. */
|
|
15
15
|
function addMark(marks, key, mark) {
|
|
@@ -22,14 +22,16 @@ function createThemeContexts() {
|
|
|
22
22
|
ViewContext: react.createContext(void 0)
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const prefixes = (0, _umber_style_core.readSharedState)("react.prefix-styles@1", () => ({
|
|
26
|
+
styles: /* @__PURE__ */ new Map(),
|
|
27
|
+
claim: void 0
|
|
28
|
+
}));
|
|
27
29
|
/**
|
|
28
30
|
* The default style's claim on a prefix: its contexts exist before its engine and its prefix, which
|
|
29
31
|
* `readPrefix` gives on demand. The prefix is the one it will have when its options are set.
|
|
30
32
|
*/
|
|
31
33
|
function claimPrefixStyle(readPrefix, style) {
|
|
32
|
-
claim = {
|
|
34
|
+
prefixes.claim = {
|
|
33
35
|
readPrefix,
|
|
34
36
|
style
|
|
35
37
|
};
|
|
@@ -40,10 +42,11 @@ function claimPrefixStyle(readPrefix, style) {
|
|
|
40
42
|
* share its marks, and so does the browser part of a provider of the server build, which needs no engine.
|
|
41
43
|
*/
|
|
42
44
|
function readPrefixStyle(prefix) {
|
|
43
|
-
|
|
45
|
+
const { styles, claim } = prefixes;
|
|
46
|
+
let style = styles.get(prefix);
|
|
44
47
|
if (style === void 0) {
|
|
45
48
|
style = claim?.readPrefix() === prefix ? claim.style : { contexts: createThemeContexts() };
|
|
46
|
-
|
|
49
|
+
styles.set(prefix, style);
|
|
47
50
|
}
|
|
48
51
|
return style;
|
|
49
52
|
}
|
package/dist/ProviderScope.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { ROOT_SELECTOR, createThemeRule, createTokens, mergeTheme, toDeclarationText } from "@umber-style/core";
|
|
3
|
+
import { ROOT_SELECTOR, createThemeRule, createTokens, mergeTheme, readSharedState, toDeclarationText } from "@umber-style/core";
|
|
4
4
|
// src/ProviderScope.tsx
|
|
5
5
|
const NO_MARKS = /* @__PURE__ */ new Map();
|
|
6
|
-
|
|
6
|
+
const sharedMarks = readSharedState("react.marks@1", () => ({ context: void 0 }));
|
|
7
7
|
/** The context of the marks, made on first use: where this module is loaded with the server build of React, nothing renders it. */
|
|
8
8
|
function getMarksContext() {
|
|
9
|
-
|
|
10
|
-
return
|
|
9
|
+
sharedMarks.context ??= React.createContext(NO_MARKS);
|
|
10
|
+
return sharedMarks.context;
|
|
11
11
|
}
|
|
12
12
|
/** `marks`, with `mark` as the nearest provider of `key`. */
|
|
13
13
|
function addMark(marks, key, mark) {
|
|
@@ -20,14 +20,16 @@ function createThemeContexts() {
|
|
|
20
20
|
ViewContext: React.createContext(void 0)
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const prefixes = readSharedState("react.prefix-styles@1", () => ({
|
|
24
|
+
styles: /* @__PURE__ */ new Map(),
|
|
25
|
+
claim: void 0
|
|
26
|
+
}));
|
|
25
27
|
/**
|
|
26
28
|
* The default style's claim on a prefix: its contexts exist before its engine and its prefix, which
|
|
27
29
|
* `readPrefix` gives on demand. The prefix is the one it will have when its options are set.
|
|
28
30
|
*/
|
|
29
31
|
function claimPrefixStyle(readPrefix, style) {
|
|
30
|
-
claim = {
|
|
32
|
+
prefixes.claim = {
|
|
31
33
|
readPrefix,
|
|
32
34
|
style
|
|
33
35
|
};
|
|
@@ -38,10 +40,11 @@ function claimPrefixStyle(readPrefix, style) {
|
|
|
38
40
|
* share its marks, and so does the browser part of a provider of the server build, which needs no engine.
|
|
39
41
|
*/
|
|
40
42
|
function readPrefixStyle(prefix) {
|
|
41
|
-
|
|
43
|
+
const { styles, claim } = prefixes;
|
|
44
|
+
let style = styles.get(prefix);
|
|
42
45
|
if (style === void 0) {
|
|
43
46
|
style = claim?.readPrefix() === prefix ? claim.style : { contexts: createThemeContexts() };
|
|
44
|
-
|
|
47
|
+
styles.set(prefix, style);
|
|
45
48
|
}
|
|
46
49
|
return style;
|
|
47
50
|
}
|
package/dist/defaultStyle.cjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
let _umber_style_core = require("@umber-style/core");
|
|
2
2
|
const require_createStyle = require("./createStyle.cjs");
|
|
3
3
|
const require_ProviderScope = require("./ProviderScope.cjs");
|
|
4
|
+
const require_watchProvidedCaches = require("./watchProvidedCaches.cjs");
|
|
4
5
|
// src/defaultStyle.ts
|
|
5
6
|
/** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
|
|
6
7
|
function createDefaultStyle() {
|
|
7
8
|
let pending = {};
|
|
9
|
+
let isConfigured = false;
|
|
8
10
|
let bound;
|
|
9
11
|
const contexts = require_ProviderScope.createThemeContexts();
|
|
10
12
|
const getStyle = () => {
|
|
11
13
|
if (!bound) {
|
|
12
14
|
const engine = pending.engine ?? (0, _umber_style_core.createLazyEngine)(pending);
|
|
15
|
+
if (!isConfigured && (0, _umber_style_core.isDevelopment)()) require_watchProvidedCaches.watchProvidedCaches(engine);
|
|
13
16
|
if (pending.theme) engine.setTheme(pending.theme);
|
|
14
17
|
bound = require_createStyle.bindEngine(engine, pending, contexts);
|
|
15
18
|
}
|
|
@@ -25,6 +28,7 @@ function createDefaultStyle() {
|
|
|
25
28
|
function configure(options) {
|
|
26
29
|
if (bound) throw new Error("configure must be called before the default style is used.");
|
|
27
30
|
pending = options;
|
|
31
|
+
isConfigured = true;
|
|
28
32
|
}
|
|
29
33
|
const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
|
|
30
34
|
const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
|
package/dist/defaultStyle.mjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { createDeferredObject, createDeferredRecord, createLazyEngine, globalStyles, keyframes, withTagShorthands } from "@umber-style/core";
|
|
1
|
+
import { createDeferredObject, createDeferredRecord, createLazyEngine, globalStyles, isDevelopment, keyframes, withTagShorthands } from "@umber-style/core";
|
|
2
2
|
import { bindEngine } from "./createStyle.mjs";
|
|
3
3
|
import { claimPrefixStyle, createThemeContexts } from "./ProviderScope.mjs";
|
|
4
|
+
import { watchProvidedCaches } from "./watchProvidedCaches.mjs";
|
|
4
5
|
// src/defaultStyle.ts
|
|
5
6
|
/** Makes the default styling: one engine, made on first use, behind `styled`, `ThemeProvider` and the rest. */
|
|
6
7
|
function createDefaultStyle() {
|
|
7
8
|
let pending = {};
|
|
9
|
+
let isConfigured = false;
|
|
8
10
|
let bound;
|
|
9
11
|
const contexts = createThemeContexts();
|
|
10
12
|
const getStyle = () => {
|
|
11
13
|
if (!bound) {
|
|
12
14
|
const engine = pending.engine ?? createLazyEngine(pending);
|
|
15
|
+
if (!isConfigured && isDevelopment()) watchProvidedCaches(engine);
|
|
13
16
|
if (pending.theme) engine.setTheme(pending.theme);
|
|
14
17
|
bound = bindEngine(engine, pending, contexts);
|
|
15
18
|
}
|
|
@@ -25,6 +28,7 @@ function createDefaultStyle() {
|
|
|
25
28
|
function configure(options) {
|
|
26
29
|
if (bound) throw new Error("configure must be called before the default style is used.");
|
|
27
30
|
pending = options;
|
|
31
|
+
isConfigured = true;
|
|
28
32
|
}
|
|
29
33
|
const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
|
|
30
34
|
const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_defaultStyle = require("./defaultStyle.cjs");
|
|
3
2
|
let _umber_style_core = require("@umber-style/core");
|
|
3
|
+
const require_defaultStyle = require("./defaultStyle.cjs");
|
|
4
4
|
const require_CacheProvider = require("./CacheProvider.cjs");
|
|
5
5
|
const require_useMediaQuery = require("./useMediaQuery.cjs");
|
|
6
6
|
const require_createStyle = require("./createStyle.cjs");
|
|
7
|
-
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = require_defaultStyle.createDefaultStyle
|
|
7
|
+
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.default-style@1", require_defaultStyle.createDefaultStyle);
|
|
8
8
|
exports.CacheProvider = require_CacheProvider.CacheProvider;
|
|
9
9
|
exports.Global = Global;
|
|
10
10
|
exports.StyleSheet = StyleSheet;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { add, alpha, at, divide, multiply, negate, readSharedState, subtract } from "@umber-style/core";
|
|
1
2
|
import { createDefaultStyle } from "./defaultStyle.mjs";
|
|
2
|
-
import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
|
|
3
3
|
import { CacheProvider } from "./CacheProvider.mjs";
|
|
4
4
|
import { useMediaQuery } from "./useMediaQuery.mjs";
|
|
5
5
|
import { bindEngine, createStyle } from "./createStyle.mjs";
|
|
6
|
-
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = createDefaultStyle
|
|
6
|
+
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.default-style@1", createDefaultStyle);
|
|
7
7
|
export { CacheProvider, Global, StyleSheet, ThemeContext, ThemeProvider, ThemeScope, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useMediaQuery, useStyle, useTheme, useThemeClass, when, whenScheme };
|
package/dist/index.server.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_defaultStyle_server = require("./defaultStyle.server.cjs");
|
|
3
2
|
let _umber_style_core = require("@umber-style/core");
|
|
3
|
+
const require_defaultStyle_server = require("./defaultStyle.server.cjs");
|
|
4
4
|
const require_createStyle_server = require("./createStyle.server.cjs");
|
|
5
|
-
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = require_defaultStyle_server.createDefaultStyle
|
|
5
|
+
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("react.server-default-style@1", require_defaultStyle_server.createDefaultStyle);
|
|
6
6
|
exports.Global = Global;
|
|
7
7
|
exports.StyleSheet = StyleSheet;
|
|
8
8
|
exports.ThemeProvider = ThemeProvider;
|
package/dist/index.server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { add, alpha, at, divide, multiply, negate, readSharedState, subtract } from "@umber-style/core";
|
|
1
2
|
import { createDefaultStyle } from "./defaultStyle.server.mjs";
|
|
2
|
-
import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
|
|
3
3
|
import { bindEngine, createStyle } from "./createStyle.server.mjs";
|
|
4
|
-
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = createDefaultStyle
|
|
4
|
+
const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, readTheme, ThemeProvider, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("react.server-default-style@1", createDefaultStyle);
|
|
5
5
|
export { Global, StyleSheet, ThemeProvider, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, readTheme, styled, subtract, themeClass, useStyle, useTheme, when, whenScheme };
|
package/dist/styledParts.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let _umber_style_core = require("@umber-style/core");
|
|
2
|
-
|
|
2
|
+
let _umber_style_is_prop_valid_react = require("@umber-style/is-prop-valid/react");
|
|
3
3
|
// src/styledParts.ts
|
|
4
4
|
/** Whether `tag` is a component made by `styled`. */
|
|
5
5
|
function isStyledComponent(tag) {
|
|
@@ -8,7 +8,7 @@ function isStyledComponent(tag) {
|
|
|
8
8
|
/** The filter of the props of `element`: the one given, whatever the element is; else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop), and none for a component. */
|
|
9
9
|
function readFilter(element, given) {
|
|
10
10
|
if (given || typeof element !== "string") return given;
|
|
11
|
-
return element.includes("-") ? void 0 :
|
|
11
|
+
return element.includes("-") ? void 0 : _umber_style_is_prop_valid_react.isPropValid;
|
|
12
12
|
}
|
|
13
13
|
/** What both builds of `styled` share: the styler, and the element and props that a component renders. */
|
|
14
14
|
function prepareStyled(engine, tag, options, styles) {
|
package/dist/styledParts.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponentSelector, flattenStyle } from "@umber-style/core";
|
|
2
|
-
import {
|
|
2
|
+
import { isPropValid } from "@umber-style/is-prop-valid/react";
|
|
3
3
|
// src/styledParts.ts
|
|
4
4
|
/** Whether `tag` is a component made by `styled`. */
|
|
5
5
|
function isStyledComponent(tag) {
|
|
@@ -8,7 +8,7 @@ function isStyledComponent(tag) {
|
|
|
8
8
|
/** The filter of the props of `element`: the one given, whatever the element is; else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop), and none for a component. */
|
|
9
9
|
function readFilter(element, given) {
|
|
10
10
|
if (given || typeof element !== "string") return given;
|
|
11
|
-
return element.includes("-") ? void 0 :
|
|
11
|
+
return element.includes("-") ? void 0 : isPropValid;
|
|
12
12
|
}
|
|
13
13
|
/** What both builds of `styled` share: the styler, and the element and props that a component renders. */
|
|
14
14
|
function prepareStyled(engine, tag, options, styles) {
|
package/dist/types.d.cts
CHANGED
|
@@ -117,12 +117,12 @@ type OwnProps<P extends object> = 'style' extends keyof P ? Omit<P, 'style'> : P
|
|
|
117
117
|
* selector: `.` and a class that every element of it has (its `target`, else its class when none of its
|
|
118
118
|
* styles is a function).
|
|
119
119
|
*/
|
|
120
|
-
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & OwnProps<P> & {
|
|
120
|
+
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<([keyof P] extends [never] ? Omit<Base, 'as' | 'style'> : [Record<never, never>] extends [Record<keyof P, unknown>] ? Omit<Base, keyof P | 'as' | 'style'> : [keyof P] extends [Exclude<keyof P, keyof Base>] ? Omit<Base, 'as' | 'style'> : Omit<Base, keyof P | 'as' | 'style'>) & OwnProps<P> & {
|
|
121
121
|
as?: AsProp<Base>;
|
|
122
122
|
style?: StyleProp;
|
|
123
123
|
}> & StyledStatics;
|
|
124
124
|
/** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
|
|
125
|
-
type StyleFunctionProps<Base extends object, P extends object> = Omit<Base, keyof P> & P;
|
|
125
|
+
type StyleFunctionProps<Base extends object, P extends object> = [keyof P] extends [never] ? Pick<Base, keyof Base> & P : [Record<never, never>] extends [Record<keyof P, unknown>] ? Omit<Base, keyof P> & P : [keyof P] extends [Exclude<keyof P, keyof Base>] ? Pick<Base, keyof Base> & P : Omit<Base, keyof P> & P;
|
|
126
126
|
/** The props that the element of a styled component takes: those of the component, of the tag, and the ones only the element takes. */
|
|
127
127
|
type ElementProps<ComponentProps extends object, SpecificComponentProps extends object, JSXProps extends object> = ComponentProps & SpecificComponentProps & JSXProps;
|
|
128
128
|
/**
|
package/dist/types.d.mts
CHANGED
|
@@ -117,12 +117,12 @@ type OwnProps<P extends object> = 'style' extends keyof P ? Omit<P, 'style'> : P
|
|
|
117
117
|
* selector: `.` and a class that every element of it has (its `target`, else its class when none of its
|
|
118
118
|
* styles is a function).
|
|
119
119
|
*/
|
|
120
|
-
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & OwnProps<P> & {
|
|
120
|
+
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<([keyof P] extends [never] ? Omit<Base, 'as' | 'style'> : [Record<never, never>] extends [Record<keyof P, unknown>] ? Omit<Base, keyof P | 'as' | 'style'> : [keyof P] extends [Exclude<keyof P, keyof Base>] ? Omit<Base, 'as' | 'style'> : Omit<Base, keyof P | 'as' | 'style'>) & OwnProps<P> & {
|
|
121
121
|
as?: AsProp<Base>;
|
|
122
122
|
style?: StyleProp;
|
|
123
123
|
}> & StyledStatics;
|
|
124
124
|
/** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
|
|
125
|
-
type StyleFunctionProps<Base extends object, P extends object> = Omit<Base, keyof P> & P;
|
|
125
|
+
type StyleFunctionProps<Base extends object, P extends object> = [keyof P] extends [never] ? Pick<Base, keyof Base> & P : [Record<never, never>] extends [Record<keyof P, unknown>] ? Omit<Base, keyof P> & P : [keyof P] extends [Exclude<keyof P, keyof Base>] ? Pick<Base, keyof Base> & P : Omit<Base, keyof P> & P;
|
|
126
126
|
/** The props that the element of a styled component takes: those of the component, of the tag, and the ones only the element takes. */
|
|
127
127
|
type ElementProps<ComponentProps extends object, SpecificComponentProps extends object, JSXProps extends object> = ComponentProps & SpecificComponentProps & JSXProps;
|
|
128
128
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/watchProvidedCaches.ts
|
|
2
|
+
/** The text of the warning, for a default style of the prefix `own` used under a cache of the key `provided`. */
|
|
3
|
+
function createUnconfiguredMessage(own, provided) {
|
|
4
|
+
return `[${own}] A component of the default style rendered under a CacheProvider whose cache has the key "${provided}", and the default style was never configured: it still has the prefix "${own}" and every default option. If it was meant to be configured, configure() did not run before the style was used. The usual causes: a configure() call in a module imported only for its side effect, which a bundler drops when the package says "sideEffects": false; or a configure() call that runs after the first styled() call. Call configure() from a function that the app calls before it renders (or list the module in "sideEffects"), or give the cache the key "${own}" if the default prefix is meant.`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Makes `engine.withCache` warn once, in the console, when it is given a cache whose prefix is not the
|
|
8
|
+
* engine's: every component of the binding (a styled component, `Global`, `ThemeProvider`, `useStyle`)
|
|
9
|
+
* calls it under a `CacheProvider`. The default style calls this for its engine in development only,
|
|
10
|
+
* and only when `configure` was never called.
|
|
11
|
+
*/
|
|
12
|
+
function watchProvidedCaches(engine) {
|
|
13
|
+
const { withCache } = engine;
|
|
14
|
+
let hasWarned = false;
|
|
15
|
+
engine.withCache = (cache) => {
|
|
16
|
+
if (!hasWarned && cache.prefix !== engine.cache.prefix) {
|
|
17
|
+
hasWarned = true;
|
|
18
|
+
console.warn(createUnconfiguredMessage(engine.cache.prefix, cache.prefix));
|
|
19
|
+
}
|
|
20
|
+
return withCache(cache);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.createUnconfiguredMessage = createUnconfiguredMessage;
|
|
24
|
+
exports.watchProvidedCaches = watchProvidedCaches;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/watchProvidedCaches.ts
|
|
2
|
+
/** The text of the warning, for a default style of the prefix `own` used under a cache of the key `provided`. */
|
|
3
|
+
function createUnconfiguredMessage(own, provided) {
|
|
4
|
+
return `[${own}] A component of the default style rendered under a CacheProvider whose cache has the key "${provided}", and the default style was never configured: it still has the prefix "${own}" and every default option. If it was meant to be configured, configure() did not run before the style was used. The usual causes: a configure() call in a module imported only for its side effect, which a bundler drops when the package says "sideEffects": false; or a configure() call that runs after the first styled() call. Call configure() from a function that the app calls before it renders (or list the module in "sideEffects"), or give the cache the key "${own}" if the default prefix is meant.`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Makes `engine.withCache` warn once, in the console, when it is given a cache whose prefix is not the
|
|
8
|
+
* engine's: every component of the binding (a styled component, `Global`, `ThemeProvider`, `useStyle`)
|
|
9
|
+
* calls it under a `CacheProvider`. The default style calls this for its engine in development only,
|
|
10
|
+
* and only when `configure` was never called.
|
|
11
|
+
*/
|
|
12
|
+
function watchProvidedCaches(engine) {
|
|
13
|
+
const { withCache } = engine;
|
|
14
|
+
let hasWarned = false;
|
|
15
|
+
engine.withCache = (cache) => {
|
|
16
|
+
if (!hasWarned && cache.prefix !== engine.cache.prefix) {
|
|
17
|
+
hasWarned = true;
|
|
18
|
+
console.warn(createUnconfiguredMessage(engine.cache.prefix, cache.prefix));
|
|
19
|
+
}
|
|
20
|
+
return withCache(cache);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { createUnconfiguredMessage, watchProvidedCaches };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umber-style/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
4
|
"description": "UmberStyle for React: styled, ThemeProvider, useTheme, StyleSheet, useStyle and apply, with a server build for server components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"styling",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@umber-style/core": "0.
|
|
57
|
+
"@umber-style/core": "^0.2.0-alpha.1",
|
|
58
|
+
"@umber-style/is-prop-valid": "^0.2.0-alpha.0"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"react": "^19.2.8"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@soroush.tech/bench": "^2.2.3",
|
|
64
|
-
"@emotion/is-prop-valid": "^1.4.0",
|
|
65
65
|
"@soroush.tech/styled-system": "^6.0.1",
|
|
66
66
|
"@testing-library/react": "^16.3.3",
|
|
67
67
|
"@types/node": "^26.6.6",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "tsdown",
|
|
84
84
|
"lint": "oxlint --deny-warnings",
|
|
85
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.augmentation.json && tsc --noEmit -p tsconfig.server.json && tsc --noEmit -p tsconfig.strict.json",
|
|
85
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.augmentation.json && tsc --noEmit -p tsconfig.server.json && tsc --noEmit -p tsconfig.strict.json && node ../../scripts/check-type-cost.mjs",
|
|
86
86
|
"test": "vitest run",
|
|
87
87
|
"test:coverage": "vitest run --coverage",
|
|
88
88
|
"test:browser": "vitest run --config vitest.browser.config.ts"
|
package/dist/domProps.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/domProps.ts
|
|
2
|
-
/**
|
|
3
|
-
* The props that a string tag receives by default, under the names React gives them: the attributes of
|
|
4
|
-
* the HTML and SVG specifications (global, of each element, RDFa and microdata, SVG presentation, filter
|
|
5
|
-
* and animation attributes) and React's own (`children`, `ref`, `key`, `dangerouslySetInnerHTML`,
|
|
6
|
-
* `defaultValue`, `suppressHydrationWarning` and the rest). `data-*`, `aria-*` and `on[A-Z]*` are matched
|
|
7
|
-
* by their start. Written in groups: `head:a,b` stands for `heada` and `headb`, an empty tail for `head`.
|
|
8
|
-
*/
|
|
9
|
-
const NAMES = "abbr about accept:,Charset accessKey action allow:,FullScreen alt async auto:Capitalize,Complete,Correct,Focus,Play blocking capture charSet checked children cite closedBy col:s,Span command:,For content:,Editable controls:,List coords crossOrigin dangerouslySetInnerHTML data datatype dateTime decoding default:,Checked,Value defer dir:,Name disable:d,PictureInPicture,RemotePlayback download draggable encType enterKeyHint exportParts fetchPriority form:,Action,EncType,Method,NoValidate,Target headers height hidden high href:,Lang htmlFor httpEquiv id image:Rendering,Sizes,SrcSet inert inlist inputMode integrity is isMap item:ID,Prop,Ref,Scope,Type key kind label lang list loading loop low max:,Length media method min:,Length multiple muted name noModule nonce noValidate open optimum part ping placeholder playsInline popover:,Target,TargetAction poster precedence prefix preload property readOnly ref referrerPolicy rel required resource rev reversed role rowSpan rows sandbox scope selected shadowRoot:Clonable,DelegatesFocus,Mode,Serializable shape size:,s slot span spellCheck src:,Doc,Lang,Set start step suppress:ContentEditableWarning,HydrationWarning tabIndex title translate type typeof useMap value vocab width wrap writingSuggestions accumulate additive alignmentBaseline amplitude attribute:Name,Type azimuth baseFrequency baselineShift begin bias by calcMode clip:,Path,PathUnits,Rule color:,Interpolation,InterpolationFilters cursor cx cy d diffuseConstant direction display divisor dominantBaseline dur dx dy edgeMode elevation end exponent fill:,Opacity,Rule filter:,Units flood:Color,Opacity focusable font:Family,Size,SizeAdjust,Stretch,Style,Variant,Weight fr from fx fy gradient:Transform,Units in:,2,tercept k:,1,2,3,4,ernelMatrix,ernelUnitLength key:Points,Splines,Times lengthAdjust letterSpacing lightingColor limitingConeAngle marker:End,Height,Mid,Start,Units,Width mask:,ContentUnits,Type,Units mode numOctaves offset opacity operator order orient overflow paintOrder pathLength pattern:,ContentUnits,Transform,Units pointerEvents points:,AtX,AtY,AtZ preserve:Alpha,AspectRatio primitiveUnits r radius refX refY repeat:Count,Dur requiredExtensions restart result rotate rx ry scale seed shapeRendering side slope spacing specular:Constant,Exponent spreadMethod startOffset stdDeviation stitchTiles stop:Color,Opacity stroke:,Dasharray,Dashoffset,Linecap,Linejoin,Miterlimit,Opacity,Width surfaceScale systemLanguage tableValues target:,X,Y text:Anchor,Decoration,Length,Rendering to transform:,Origin unicodeBidi values vectorEffect viewBox visibility wordSpacing writingMode x:,1,2,ChannelSelector xlink:Actuate,Arcrole,Href,Role,Show,Title,Type xml:Base,Lang,Space,ns,nsXlink y:,1,2,ChannelSelector z";
|
|
10
|
-
const PREFIXED = /^(?:data-|aria-|on[A-Z])/;
|
|
11
|
-
let names;
|
|
12
|
-
/** The names that `groups` stands for. */
|
|
13
|
-
function expand(groups) {
|
|
14
|
-
const expanded = /* @__PURE__ */ new Set();
|
|
15
|
-
for (const group of groups.split(" ")) {
|
|
16
|
-
const [head, tails] = group.split(":");
|
|
17
|
-
if (tails === void 0) expanded.add(head);
|
|
18
|
-
else for (const tail of tails.split(",")) expanded.add(head + tail);
|
|
19
|
-
}
|
|
20
|
-
return expanded;
|
|
21
|
-
}
|
|
22
|
-
/** Whether a string tag receives `prop` when its component has no `shouldForwardProp`: an attribute of HTML or SVG, a `data-` or `aria-` attribute, an event handler, or a prop of React's own. */
|
|
23
|
-
function isDomProp(prop) {
|
|
24
|
-
names ??= expand(NAMES);
|
|
25
|
-
return names.has(prop) || PREFIXED.test(prop);
|
|
26
|
-
}
|
|
27
|
-
exports.isDomProp = isDomProp;
|
package/dist/domProps.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/domProps.ts
|
|
2
|
-
/**
|
|
3
|
-
* The props that a string tag receives by default, under the names React gives them: the attributes of
|
|
4
|
-
* the HTML and SVG specifications (global, of each element, RDFa and microdata, SVG presentation, filter
|
|
5
|
-
* and animation attributes) and React's own (`children`, `ref`, `key`, `dangerouslySetInnerHTML`,
|
|
6
|
-
* `defaultValue`, `suppressHydrationWarning` and the rest). `data-*`, `aria-*` and `on[A-Z]*` are matched
|
|
7
|
-
* by their start. Written in groups: `head:a,b` stands for `heada` and `headb`, an empty tail for `head`.
|
|
8
|
-
*/
|
|
9
|
-
const NAMES = "abbr about accept:,Charset accessKey action allow:,FullScreen alt async auto:Capitalize,Complete,Correct,Focus,Play blocking capture charSet checked children cite closedBy col:s,Span command:,For content:,Editable controls:,List coords crossOrigin dangerouslySetInnerHTML data datatype dateTime decoding default:,Checked,Value defer dir:,Name disable:d,PictureInPicture,RemotePlayback download draggable encType enterKeyHint exportParts fetchPriority form:,Action,EncType,Method,NoValidate,Target headers height hidden high href:,Lang htmlFor httpEquiv id image:Rendering,Sizes,SrcSet inert inlist inputMode integrity is isMap item:ID,Prop,Ref,Scope,Type key kind label lang list loading loop low max:,Length media method min:,Length multiple muted name noModule nonce noValidate open optimum part ping placeholder playsInline popover:,Target,TargetAction poster precedence prefix preload property readOnly ref referrerPolicy rel required resource rev reversed role rowSpan rows sandbox scope selected shadowRoot:Clonable,DelegatesFocus,Mode,Serializable shape size:,s slot span spellCheck src:,Doc,Lang,Set start step suppress:ContentEditableWarning,HydrationWarning tabIndex title translate type typeof useMap value vocab width wrap writingSuggestions accumulate additive alignmentBaseline amplitude attribute:Name,Type azimuth baseFrequency baselineShift begin bias by calcMode clip:,Path,PathUnits,Rule color:,Interpolation,InterpolationFilters cursor cx cy d diffuseConstant direction display divisor dominantBaseline dur dx dy edgeMode elevation end exponent fill:,Opacity,Rule filter:,Units flood:Color,Opacity focusable font:Family,Size,SizeAdjust,Stretch,Style,Variant,Weight fr from fx fy gradient:Transform,Units in:,2,tercept k:,1,2,3,4,ernelMatrix,ernelUnitLength key:Points,Splines,Times lengthAdjust letterSpacing lightingColor limitingConeAngle marker:End,Height,Mid,Start,Units,Width mask:,ContentUnits,Type,Units mode numOctaves offset opacity operator order orient overflow paintOrder pathLength pattern:,ContentUnits,Transform,Units pointerEvents points:,AtX,AtY,AtZ preserve:Alpha,AspectRatio primitiveUnits r radius refX refY repeat:Count,Dur requiredExtensions restart result rotate rx ry scale seed shapeRendering side slope spacing specular:Constant,Exponent spreadMethod startOffset stdDeviation stitchTiles stop:Color,Opacity stroke:,Dasharray,Dashoffset,Linecap,Linejoin,Miterlimit,Opacity,Width surfaceScale systemLanguage tableValues target:,X,Y text:Anchor,Decoration,Length,Rendering to transform:,Origin unicodeBidi values vectorEffect viewBox visibility wordSpacing writingMode x:,1,2,ChannelSelector xlink:Actuate,Arcrole,Href,Role,Show,Title,Type xml:Base,Lang,Space,ns,nsXlink y:,1,2,ChannelSelector z";
|
|
10
|
-
const PREFIXED = /^(?:data-|aria-|on[A-Z])/;
|
|
11
|
-
let names;
|
|
12
|
-
/** The names that `groups` stands for. */
|
|
13
|
-
function expand(groups) {
|
|
14
|
-
const expanded = /* @__PURE__ */ new Set();
|
|
15
|
-
for (const group of groups.split(" ")) {
|
|
16
|
-
const [head, tails] = group.split(":");
|
|
17
|
-
if (tails === void 0) expanded.add(head);
|
|
18
|
-
else for (const tail of tails.split(",")) expanded.add(head + tail);
|
|
19
|
-
}
|
|
20
|
-
return expanded;
|
|
21
|
-
}
|
|
22
|
-
/** Whether a string tag receives `prop` when its component has no `shouldForwardProp`: an attribute of HTML or SVG, a `data-` or `aria-` attribute, an event handler, or a prop of React's own. */
|
|
23
|
-
function isDomProp(prop) {
|
|
24
|
-
names ??= expand(NAMES);
|
|
25
|
-
return names.has(prop) || PREFIXED.test(prop);
|
|
26
|
-
}
|
|
27
|
-
export { isDomProp };
|