@umber-style/react 0.1.0-alpha.1 → 0.1.0-rc.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.
@@ -26,7 +26,7 @@ function createDefaultStyle() {
26
26
  if (bound) throw new Error("configure must be called before the default style is used.");
27
27
  pending = options;
28
28
  }
29
- const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => getStyle().styled(tag, options)));
29
+ const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
30
30
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
31
31
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
32
32
  function useTheme() {
@@ -26,7 +26,7 @@ function createDefaultStyle() {
26
26
  if (bound) throw new Error("configure must be called before the default style is used.");
27
27
  pending = options;
28
28
  }
29
- const styled = withTagShorthands(((tag, options) => getStyle().styled(tag, options)));
29
+ const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
30
30
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
31
31
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
32
32
  function useTheme() {
@@ -18,7 +18,7 @@ function createDefaultStyle() {
18
18
  if (bound) throw new Error("configure must be called before the default style is used.");
19
19
  pending = options;
20
20
  }
21
- const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => getStyle().styled(tag, options)));
21
+ const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
22
22
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
23
23
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
24
24
  function useTheme() {
@@ -18,7 +18,7 @@ function createDefaultStyle() {
18
18
  if (bound) throw new Error("configure must be called before the default style is used.");
19
19
  pending = options;
20
20
  }
21
- const styled = withTagShorthands(((tag, options) => getStyle().styled(tag, options)));
21
+ const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
22
22
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
23
23
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
24
24
  function useTheme() {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
2
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
3
3
  import { CacheProvider } from "./CacheProvider.cjs";
4
4
  import { MediaQueryOptions, useMediaQuery } from "./useMediaQuery.cjs";
5
5
  import { bindEngine, createStyle } from "./createStyle.cjs";
@@ -25,4 +25,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
25
25
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
26
26
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
27
27
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
28
- export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
28
+ export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
1
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
2
2
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  import { CacheProvider } from "./CacheProvider.mjs";
4
4
  import { MediaQueryOptions, useMediaQuery } from "./useMediaQuery.mjs";
@@ -25,4 +25,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
25
25
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
26
26
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
27
27
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
28
- export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
28
+ export { type AlphaColor, type CSSObject, CacheProvider, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type MediaQueryOptions, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract, useMediaQuery };
@@ -1,5 +1,5 @@
1
1
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
2
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.cjs";
3
3
  import { bindEngine, createStyle } from "./createStyle.server.cjs";
4
4
  import { createDefaultStyle } from "./defaultStyle.server.cjs";
5
5
  export declare const configure: (options: DefaultStyleOptions) => void, getEngine: () => import("@umber-style/core").Engine<Theme>, styled: Styled<Theme>, StyleSheet: {
@@ -23,4 +23,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
23
23
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
24
24
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
25
25
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
26
- export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
26
+ export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
@@ -1,4 +1,4 @@
1
- import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
1
+ import { AlphaColor, CSSObject, CacheProviderProps, ComponentSelector, CreateStyled, CreateStyledComponent, CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, GlobalInput, GlobalProps, GlobalStyleObject, GlobalStyles, Interpolation, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, PropsOf, SchemeKey, SchemeName, SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, SheetEntry, StaticTemplateValue, Style, StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, TemplateValue, Theme, ThemeInput, ThemeKey, ThemeProviderProps, ThemeScopeProps, UmberCache, WebNested, WebProperties, WebStyle, WebStyleObject, WebThemeProviderProps } from "./types.mjs";
2
2
  import { add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  import { bindEngine, createStyle } from "./createStyle.server.mjs";
4
4
  import { createDefaultStyle } from "./defaultStyle.server.mjs";
@@ -23,4 +23,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
23
23
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
24
24
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
25
25
  }, Global: (props: GlobalProps<Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
26
- export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
26
+ export { type AlphaColor, type CSSObject, CacheProviderProps, type ComponentSelector, CreateStyled, CreateStyledComponent, type CssArgument, CssFunction, DefaultStyleOptions, FilteringStyledOptions, type GlobalInput, GlobalProps, type GlobalStyleObject, type GlobalStyles, Interpolation, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, PropsOf, type SchemeKey, type SchemeName, type SerializedStyles, ServerStyle, ServerStyleOptions, SheetDefinition, type SheetEntry, type StaticTemplateValue, Style, type StyleObject, StyleOptions, StyleProp, Styled, StyledCall, StyledComponent, StyledFactory, StyledOptions, StyledStatics, StyledTags, type TemplateValue, Theme, type ThemeInput, type ThemeKey, ThemeProviderProps, ThemeScopeProps, type UmberCache, type WebNested, type WebProperties, WebStyle, type WebStyleObject, WebThemeProviderProps, add, alpha, at, bindEngine, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
@@ -5,15 +5,16 @@ const require_domProps = require("./domProps.cjs");
5
5
  function isStyledComponent(tag) {
6
6
  return typeof tag === "function" && "_styles" in tag;
7
7
  }
8
- /** The filter of the props of `element`: the one given, else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop); none for a component. */
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
- if (typeof element !== "string") return void 0;
11
- return given ?? (element.includes("-") ? void 0 : require_domProps.isDomProp);
10
+ if (given || typeof element !== "string") return given;
11
+ return element.includes("-") ? void 0 : require_domProps.isDomProp;
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) {
15
15
  const inner = isStyledComponent(tag) ? tag : void 0;
16
16
  const baseTag = inner?._tag ?? tag;
17
+ const isTag = typeof baseTag === "string";
17
18
  const shouldForward = options.shouldForwardProp ?? inner?._shouldForwardProp;
18
19
  const target = [inner?._target, options.target].filter(Boolean).join(" ") || void 0;
19
20
  const styler = engine.createStyler(options, styles, inner?._styles);
@@ -40,10 +41,10 @@ function prepareStyled(engine, tag, options, styles) {
40
41
  const held = canHold && props.style ? own.getHeldClass(props, extra, theme) : void 0;
41
42
  let className = held ? held.className : own.getClassName(props, extra, theme);
42
43
  if (target) className = className ? `${className} ${target}` : target;
43
- const element = props.as ?? baseTag;
44
+ const element = isTag ? props.as ?? baseTag : baseTag;
44
45
  const filter = readFilter(element, shouldForward);
45
46
  const forwarded = {};
46
- for (const [key, value] of Object.entries(props)) if (!(key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
47
+ for (const [key, value] of Object.entries(props)) if (!(isTag && key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
47
48
  forwarded.className = className || void 0;
48
49
  return {
49
50
  element,
@@ -5,15 +5,16 @@ import { isDomProp } from "./domProps.mjs";
5
5
  function isStyledComponent(tag) {
6
6
  return typeof tag === "function" && "_styles" in tag;
7
7
  }
8
- /** The filter of the props of `element`: the one given, else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop); none for a component. */
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
- if (typeof element !== "string") return void 0;
11
- return given ?? (element.includes("-") ? void 0 : isDomProp);
10
+ if (given || typeof element !== "string") return given;
11
+ return element.includes("-") ? void 0 : isDomProp;
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) {
15
15
  const inner = isStyledComponent(tag) ? tag : void 0;
16
16
  const baseTag = inner?._tag ?? tag;
17
+ const isTag = typeof baseTag === "string";
17
18
  const shouldForward = options.shouldForwardProp ?? inner?._shouldForwardProp;
18
19
  const target = [inner?._target, options.target].filter(Boolean).join(" ") || void 0;
19
20
  const styler = engine.createStyler(options, styles, inner?._styles);
@@ -40,10 +41,10 @@ function prepareStyled(engine, tag, options, styles) {
40
41
  const held = canHold && props.style ? own.getHeldClass(props, extra, theme) : void 0;
41
42
  let className = held ? held.className : own.getClassName(props, extra, theme);
42
43
  if (target) className = className ? `${className} ${target}` : target;
43
- const element = props.as ?? baseTag;
44
+ const element = isTag ? props.as ?? baseTag : baseTag;
44
45
  const filter = readFilter(element, shouldForward);
45
46
  const forwarded = {};
46
- for (const [key, value] of Object.entries(props)) if (!(key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
47
+ for (const [key, value] of Object.entries(props)) if (!(isTag && key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
47
48
  forwarded.className = className || void 0;
48
49
  return {
49
50
  element,
package/dist/types.d.cts CHANGED
@@ -35,13 +35,19 @@ export interface DefaultStyleOptions extends BindingOptions<Theme>, ServerStyleO
35
35
  /** The base theme, for an app that has no provider at all. */
36
36
  theme?: Theme;
37
37
  }
38
- /** The options of `styled(tag, options)`: the label of the class, which props reach the element, and a class of your own. */
39
- export interface StyledOptions extends StylerOptions {
38
+ /**
39
+ * The options of `styled(tag, options)`: the label of the class, which props reach the element, and a class
40
+ * of your own. `_Props`, the props of the tag, changes nothing: it lets a wrapper of `styled` write
41
+ * `StyledOptions<ComponentProps<C>>` next to `FilteringStyledOptions<ComponentProps<C>, Forwarded>`.
42
+ */
43
+ export interface StyledOptions<_Props = unknown> extends StylerOptions {
40
44
  /**
41
- * Whether a prop is forwarded to a string tag. It replaces the default, which forwards the attributes
42
- * of HTML and SVG (by their React names), `data-*`, `aria-*`, event handlers and React's own props, and
43
- * every prop to a custom element (a tag with a hyphen). `as`, `theme`, `className` and `style` are the
44
- * component's own and are never forwarded. A component tag receives every prop but those four.
45
+ * Whether a prop is forwarded to the element or component that is rendered. It replaces the default,
46
+ * which forwards to a string tag the attributes of HTML and SVG (by their React names), `data-*`,
47
+ * `aria-*`, event handlers and React's own props, and every prop to a custom element (a tag with a
48
+ * hyphen) and to a component. `theme`, `className` and `style` are the component's own and are never
49
+ * forwarded, and so is `as` where it replaces a string tag; a component that is not made by `styled`
50
+ * is always rendered, and is given `as` as a prop.
45
51
  */
46
52
  shouldForwardProp?: (prop: string) => boolean;
47
53
  /**
@@ -55,8 +61,8 @@ export interface StyledOptions extends StylerOptions {
55
61
  * `StyledOptions` whose `shouldForwardProp` is a type guard: the props of the tag that a styled component
56
62
  * then takes are only the ones it names, `Forwarded`.
57
63
  */
58
- export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions {
59
- /** A type guard of the props that are forwarded to a string tag: the component takes only the props of the tag that it names. */
64
+ export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions<Props> {
65
+ /** A type guard of the props that are forwarded: the component takes only the props of the tag that it names. */
60
66
  shouldForwardProp?: (prop: string) => prop is Forwarded;
61
67
  }
62
68
  /** The props of a component or a tag, as an element of it takes them. */
@@ -82,6 +88,13 @@ export interface StyledStatics {
82
88
  * an error.
83
89
  */
84
90
  export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefined | readonly StyleProp[];
91
+ /**
92
+ * The `as` of a styled component whose tag takes the props `Base`: the type of the tag's own `as` when it
93
+ * has one (a component that is not made by `styled` is given `as` as a prop), else any element type.
94
+ */
95
+ type AsProp<Base> = Base extends {
96
+ as?: infer As;
97
+ } ? unknown extends As ? ElementType : As : ElementType;
85
98
  /**
86
99
  * A component made by `styled`: it takes the props of the tag (`Base`: all of them, unless a
87
100
  * `shouldForwardProp` type guard named some), its own props `P`, `as` and `style`. As text it is a
@@ -89,20 +102,34 @@ export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefin
89
102
  * styles is a function).
90
103
  */
91
104
  export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & P & {
92
- as?: ElementType;
105
+ as?: AsProp<Base>;
93
106
  style?: StyleProp;
94
107
  }> & StyledStatics;
108
+ /** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
109
+ type StyleFunctionProps<Base extends object, P extends object> = Omit<Base, keyof P> & P;
110
+ /** The props that the element of a styled component takes: those of the component, of the tag, and the ones only the element takes. */
111
+ type ElementProps<ComponentProps extends object, SpecificComponentProps extends object, JSXProps extends object> = ComponentProps & SpecificComponentProps & JSXProps;
95
112
  /**
96
- * What `styled(tag, options)` returns: it takes the styles and makes the component, or is used as a tag,
97
- * whose template is one style (a function of the props when an interpolation is a function).
113
+ * What `styled(tag, options)` returns, in the form that a wrapper of `styled` names it: the props of the
114
+ * component are `ComponentProps` and `SpecificComponentProps` (a wrapper puts its own, such as `theme`, in
115
+ * the first, and the props of the tag in the second), and `JSXProps` are props that only the element takes
116
+ * (`ref`). It takes the styles and makes the component, or is used as a tag, whose template is one style.
117
+ * The props of the component's own are a type argument, `AdditionalProps`. A function style reads all of
118
+ * them, the component's own over the others, and `theme`, the theme `T`.
98
119
  */
99
- export interface StyledFactory<T, C extends ElementType, Base extends object = ComponentProps<C>> {
100
- <P extends object = object>(style: (props: P & {
120
+ export interface CreateStyledComponent<ComponentProps extends object, SpecificComponentProps extends object = object, JSXProps extends object = object, T = Theme> {
121
+ <AdditionalProps extends object = object>(style: (props: StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps> & {
101
122
  theme: T;
102
- }) => InterpolationResult$1, ...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
103
- <P extends object = object>(template: TemplateStringsArray, ...values: TemplateValue$1<NoInfer<P>, T>[]): StyledComponent<C, P, Base>;
104
- <P extends object = object>(...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
123
+ }) => InterpolationResult$1, ...styles: Interpolation<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
124
+ <AdditionalProps extends object = object>(template: TemplateStringsArray, ...values: TemplateValue$1<NoInfer<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
125
+ <AdditionalProps extends object = object>(...styles: Interpolation<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
105
126
  }
127
+ /**
128
+ * What `styled(tag, options)` returns for the theme `T` and the tag `C`, whose props the component takes
129
+ * (`Base`: all of them, unless a `shouldForwardProp` type guard named some): `CreateStyledComponent` with
130
+ * the props of the tag.
131
+ */
132
+ export type StyledFactory<T, C extends ElementType, Base extends object = ComponentProps<C>> = CreateStyledComponent<object, Base, object, T>;
106
133
  /** The shorthand of each HTML and SVG tag: `styled.div(...styles)` is `styled('div')(...styles)`. */
107
134
  export type StyledTags<T> = { readonly [K in keyof JSX.IntrinsicElements]: StyledFactory<T, K>; };
108
135
  /** `styled(tag, options)`: with a `shouldForwardProp` type guard, the component takes only the props of `tag` that it names. */
@@ -126,13 +153,28 @@ export interface SheetDefinition<S extends SheetStyles, E> {
126
153
  /** Never set at run time: it only carries the types. */
127
154
  readonly entries?: { [K in keyof S]: E; };
128
155
  }
156
+ /**
157
+ * What the `theme` of a provider of the theme `T` takes: `ThemeInput<T>`. The `Theme` of the default style
158
+ * has no member of its own until an app declares its members in it, and until then no theme of the app
159
+ * would match it (TypeScript rejects an object that shares no member with a type whose members are all
160
+ * optional); so while it has none, the provider takes any theme object, or a function of the theme above
161
+ * whose parameter the app types (`(outer: AppTheme) => AppTheme`).
162
+ */
163
+ type ProviderThemeInput<T> = [Exclude<keyof T, '_theme'>] extends [never] ? object | UntypedThemeFunction['derive'] : ThemeInput$1<T>;
164
+ /**
165
+ * The function form of `ProviderThemeInput` for a theme with no members: its parameter is compared both
166
+ * ways, as a method's is, so a function whose parameter the app types as its own theme is taken.
167
+ */
168
+ interface UntypedThemeFunction {
169
+ derive(outer: object): object;
170
+ }
129
171
  /** The props of `ThemeProvider`: the theme of the subtree, and on the web its color scheme and wrapper. */
130
172
  export interface ThemeProviderProps<T> {
131
173
  /**
132
174
  * The theme, or the part of it that this subtree changes; or a function of the theme above (the base
133
175
  * theme, or an empty object, for the outermost provider) that returns it. It is merged over the theme above.
134
176
  */
135
- readonly theme: ThemeInput$1<T>;
177
+ readonly theme: ProviderThemeInput<T>;
136
178
  /** Web only. */
137
179
  readonly colorScheme?: ColorScheme;
138
180
  /** Web only: a class of the wrapper of a nested provider. */
package/dist/types.d.mts CHANGED
@@ -35,13 +35,19 @@ export interface DefaultStyleOptions extends BindingOptions<Theme>, ServerStyleO
35
35
  /** The base theme, for an app that has no provider at all. */
36
36
  theme?: Theme;
37
37
  }
38
- /** The options of `styled(tag, options)`: the label of the class, which props reach the element, and a class of your own. */
39
- export interface StyledOptions extends StylerOptions {
38
+ /**
39
+ * The options of `styled(tag, options)`: the label of the class, which props reach the element, and a class
40
+ * of your own. `_Props`, the props of the tag, changes nothing: it lets a wrapper of `styled` write
41
+ * `StyledOptions<ComponentProps<C>>` next to `FilteringStyledOptions<ComponentProps<C>, Forwarded>`.
42
+ */
43
+ export interface StyledOptions<_Props = unknown> extends StylerOptions {
40
44
  /**
41
- * Whether a prop is forwarded to a string tag. It replaces the default, which forwards the attributes
42
- * of HTML and SVG (by their React names), `data-*`, `aria-*`, event handlers and React's own props, and
43
- * every prop to a custom element (a tag with a hyphen). `as`, `theme`, `className` and `style` are the
44
- * component's own and are never forwarded. A component tag receives every prop but those four.
45
+ * Whether a prop is forwarded to the element or component that is rendered. It replaces the default,
46
+ * which forwards to a string tag the attributes of HTML and SVG (by their React names), `data-*`,
47
+ * `aria-*`, event handlers and React's own props, and every prop to a custom element (a tag with a
48
+ * hyphen) and to a component. `theme`, `className` and `style` are the component's own and are never
49
+ * forwarded, and so is `as` where it replaces a string tag; a component that is not made by `styled`
50
+ * is always rendered, and is given `as` as a prop.
45
51
  */
46
52
  shouldForwardProp?: (prop: string) => boolean;
47
53
  /**
@@ -55,8 +61,8 @@ export interface StyledOptions extends StylerOptions {
55
61
  * `StyledOptions` whose `shouldForwardProp` is a type guard: the props of the tag that a styled component
56
62
  * then takes are only the ones it names, `Forwarded`.
57
63
  */
58
- export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions {
59
- /** A type guard of the props that are forwarded to a string tag: the component takes only the props of the tag that it names. */
64
+ export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions<Props> {
65
+ /** A type guard of the props that are forwarded: the component takes only the props of the tag that it names. */
60
66
  shouldForwardProp?: (prop: string) => prop is Forwarded;
61
67
  }
62
68
  /** The props of a component or a tag, as an element of it takes them. */
@@ -82,6 +88,13 @@ export interface StyledStatics {
82
88
  * an error.
83
89
  */
84
90
  export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefined | readonly StyleProp[];
91
+ /**
92
+ * The `as` of a styled component whose tag takes the props `Base`: the type of the tag's own `as` when it
93
+ * has one (a component that is not made by `styled` is given `as` as a prop), else any element type.
94
+ */
95
+ type AsProp<Base> = Base extends {
96
+ as?: infer As;
97
+ } ? unknown extends As ? ElementType : As : ElementType;
85
98
  /**
86
99
  * A component made by `styled`: it takes the props of the tag (`Base`: all of them, unless a
87
100
  * `shouldForwardProp` type guard named some), its own props `P`, `as` and `style`. As text it is a
@@ -89,20 +102,34 @@ export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefin
89
102
  * styles is a function).
90
103
  */
91
104
  export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & P & {
92
- as?: ElementType;
105
+ as?: AsProp<Base>;
93
106
  style?: StyleProp;
94
107
  }> & StyledStatics;
108
+ /** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
109
+ type StyleFunctionProps<Base extends object, P extends object> = Omit<Base, keyof P> & P;
110
+ /** The props that the element of a styled component takes: those of the component, of the tag, and the ones only the element takes. */
111
+ type ElementProps<ComponentProps extends object, SpecificComponentProps extends object, JSXProps extends object> = ComponentProps & SpecificComponentProps & JSXProps;
95
112
  /**
96
- * What `styled(tag, options)` returns: it takes the styles and makes the component, or is used as a tag,
97
- * whose template is one style (a function of the props when an interpolation is a function).
113
+ * What `styled(tag, options)` returns, in the form that a wrapper of `styled` names it: the props of the
114
+ * component are `ComponentProps` and `SpecificComponentProps` (a wrapper puts its own, such as `theme`, in
115
+ * the first, and the props of the tag in the second), and `JSXProps` are props that only the element takes
116
+ * (`ref`). It takes the styles and makes the component, or is used as a tag, whose template is one style.
117
+ * The props of the component's own are a type argument, `AdditionalProps`. A function style reads all of
118
+ * them, the component's own over the others, and `theme`, the theme `T`.
98
119
  */
99
- export interface StyledFactory<T, C extends ElementType, Base extends object = ComponentProps<C>> {
100
- <P extends object = object>(style: (props: P & {
120
+ export interface CreateStyledComponent<ComponentProps extends object, SpecificComponentProps extends object = object, JSXProps extends object = object, T = Theme> {
121
+ <AdditionalProps extends object = object>(style: (props: StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps> & {
101
122
  theme: T;
102
- }) => InterpolationResult$1, ...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
103
- <P extends object = object>(template: TemplateStringsArray, ...values: TemplateValue$1<NoInfer<P>, T>[]): StyledComponent<C, P, Base>;
104
- <P extends object = object>(...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
123
+ }) => InterpolationResult$1, ...styles: Interpolation<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
124
+ <AdditionalProps extends object = object>(template: TemplateStringsArray, ...values: TemplateValue$1<NoInfer<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
125
+ <AdditionalProps extends object = object>(...styles: Interpolation<StyleFunctionProps<ComponentProps & SpecificComponentProps, AdditionalProps>, T>[]): StyledComponent<ElementType, AdditionalProps, ElementProps<ComponentProps, SpecificComponentProps, JSXProps>>;
105
126
  }
127
+ /**
128
+ * What `styled(tag, options)` returns for the theme `T` and the tag `C`, whose props the component takes
129
+ * (`Base`: all of them, unless a `shouldForwardProp` type guard named some): `CreateStyledComponent` with
130
+ * the props of the tag.
131
+ */
132
+ export type StyledFactory<T, C extends ElementType, Base extends object = ComponentProps<C>> = CreateStyledComponent<object, Base, object, T>;
106
133
  /** The shorthand of each HTML and SVG tag: `styled.div(...styles)` is `styled('div')(...styles)`. */
107
134
  export type StyledTags<T> = { readonly [K in keyof JSX.IntrinsicElements]: StyledFactory<T, K>; };
108
135
  /** `styled(tag, options)`: with a `shouldForwardProp` type guard, the component takes only the props of `tag` that it names. */
@@ -126,13 +153,28 @@ export interface SheetDefinition<S extends SheetStyles, E> {
126
153
  /** Never set at run time: it only carries the types. */
127
154
  readonly entries?: { [K in keyof S]: E; };
128
155
  }
156
+ /**
157
+ * What the `theme` of a provider of the theme `T` takes: `ThemeInput<T>`. The `Theme` of the default style
158
+ * has no member of its own until an app declares its members in it, and until then no theme of the app
159
+ * would match it (TypeScript rejects an object that shares no member with a type whose members are all
160
+ * optional); so while it has none, the provider takes any theme object, or a function of the theme above
161
+ * whose parameter the app types (`(outer: AppTheme) => AppTheme`).
162
+ */
163
+ type ProviderThemeInput<T> = [Exclude<keyof T, '_theme'>] extends [never] ? object | UntypedThemeFunction['derive'] : ThemeInput$1<T>;
164
+ /**
165
+ * The function form of `ProviderThemeInput` for a theme with no members: its parameter is compared both
166
+ * ways, as a method's is, so a function whose parameter the app types as its own theme is taken.
167
+ */
168
+ interface UntypedThemeFunction {
169
+ derive(outer: object): object;
170
+ }
129
171
  /** The props of `ThemeProvider`: the theme of the subtree, and on the web its color scheme and wrapper. */
130
172
  export interface ThemeProviderProps<T> {
131
173
  /**
132
174
  * The theme, or the part of it that this subtree changes; or a function of the theme above (the base
133
175
  * theme, or an empty object, for the outermost provider) that returns it. It is merged over the theme above.
134
176
  */
135
- readonly theme: ThemeInput$1<T>;
177
+ readonly theme: ProviderThemeInput<T>;
136
178
  /** Web only. */
137
179
  readonly colorScheme?: ColorScheme;
138
180
  /** Web only: a class of the wrapper of a nested provider. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umber-style/react",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-rc.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,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@umber-style/core": "0.1.0-alpha.4"
57
+ "@umber-style/core": "0.1.0-rc.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": "^19.2.8"