@bifrostui/utils 2.0.0-alpha.2 → 2.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/context-selector/createContext.d.ts +26 -0
  2. package/dist/context-selector/createContext.js +83 -0
  3. package/dist/context-selector/index.d.ts +4 -0
  4. package/dist/context-selector/index.js +33 -0
  5. package/dist/context-selector/types.d.ts +24 -0
  6. package/dist/context-selector/types.js +15 -0
  7. package/dist/context-selector/useContextSelector.d.ts +29 -0
  8. package/dist/context-selector/useContextSelector.js +92 -0
  9. package/dist/context-selector/useHasParentContext.d.ts +26 -0
  10. package/dist/context-selector/useHasParentContext.js +46 -0
  11. package/dist/directionLocationUtil.d.ts +1 -0
  12. package/dist/getBoundingClientRect/index.js +1 -11
  13. package/dist/hooks/useDomReady/index.js +2 -2
  14. package/dist/hooks/useEventCallback.d.ts +12 -3
  15. package/dist/hooks/useEventCallback.js +14 -5
  16. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  17. package/dist/hooks/useIsomorphicLayoutEffect.js +39 -0
  18. package/dist/hooks/useMemoizedFn.js +1 -1
  19. package/dist/hooks/useSize.js +2 -2
  20. package/dist/hooks/useTouchEmulator.js +3 -3
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +3 -1
  23. package/dist/isMini.js +1 -1
  24. package/dist/render.d.ts +2 -2
  25. package/dist/setRef.d.ts +1 -1
  26. package/dist/ssr/canUseDOM.d.ts +4 -0
  27. package/dist/ssr/canUseDOM.js +29 -0
  28. package/dist/ssr/index.d.ts +1 -0
  29. package/dist/ssr/index.js +27 -0
  30. package/dist/themeCreator/cssVarToValue.d.ts +16 -0
  31. package/dist/themeCreator/cssVarToValue.js +32 -4
  32. package/dist/toArray.d.ts +1 -1
  33. package/dist/toArray.js +3 -3
  34. package/dist/transitions.d.ts +1 -1
  35. package/dist/transitions.js +1 -1
  36. package/es/context-selector/createContext.d.ts +26 -0
  37. package/es/context-selector/createContext.js +53 -0
  38. package/es/context-selector/index.d.ts +4 -0
  39. package/es/context-selector/index.js +8 -0
  40. package/es/context-selector/types.d.ts +24 -0
  41. package/es/context-selector/types.js +0 -0
  42. package/es/context-selector/useContextSelector.d.ts +29 -0
  43. package/es/context-selector/useContextSelector.js +59 -0
  44. package/es/context-selector/useHasParentContext.d.ts +26 -0
  45. package/es/context-selector/useHasParentContext.js +13 -0
  46. package/es/directionLocationUtil.d.ts +1 -0
  47. package/es/getBoundingClientRect/index.js +1 -11
  48. package/es/hooks/useDomReady/index.js +1 -1
  49. package/es/hooks/useEventCallback.d.ts +12 -3
  50. package/es/hooks/useEventCallback.js +14 -5
  51. package/es/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  52. package/es/hooks/useIsomorphicLayoutEffect.js +6 -0
  53. package/es/hooks/useMemoizedFn.js +1 -1
  54. package/es/hooks/useSize.js +1 -1
  55. package/es/hooks/useTouchEmulator.js +3 -3
  56. package/es/index.d.ts +1 -0
  57. package/es/index.js +1 -0
  58. package/es/isMini.js +1 -1
  59. package/es/render.d.ts +2 -2
  60. package/es/setRef.d.ts +1 -1
  61. package/es/ssr/canUseDOM.d.ts +4 -0
  62. package/es/ssr/canUseDOM.js +6 -0
  63. package/es/ssr/index.d.ts +1 -0
  64. package/es/ssr/index.js +4 -0
  65. package/es/themeCreator/cssVarToValue.d.ts +16 -0
  66. package/es/themeCreator/cssVarToValue.js +31 -3
  67. package/es/toArray.d.ts +1 -1
  68. package/es/toArray.js +2 -2
  69. package/es/transitions.d.ts +1 -1
  70. package/es/transitions.js +1 -1
  71. package/package.json +5 -4
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var ssr_exports = {};
19
+ __export(ssr_exports, {
20
+ canUseDOM: () => import_canUseDOM.canUseDOM
21
+ });
22
+ module.exports = __toCommonJS(ssr_exports);
23
+ var import_canUseDOM = require("./canUseDOM");
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ canUseDOM
27
+ });
@@ -1,4 +1,20 @@
1
1
  import { CssVarToValueOptions } from './index.types';
2
+ /**
3
+ * 设置全局默认主题变量
4
+ * 建议在小程序入口文件(app.ts)中调用,设置后所有组件都会使用该主题
5
+ * 支持主题继承:如果设置的主题中某个变量不存在,会自动从 defaultLight 继承
6
+ * @param themeVars 主题CSS变量对象
7
+ * @example
8
+ * import { setDefaultThemeVars } from '@bifrostui/utils';
9
+ * import { pioneerLight } from '@bifrostui/styles/registry';
10
+ * setDefaultThemeVars(pioneerLight.cssVars);
11
+ */
12
+ export declare const setDefaultThemeVars: (themeVars: Record<string, string> | undefined) => void;
13
+ /**
14
+ * 获取当前全局默认主题变量
15
+ * 返回合并后的主题变量(自定义主题 + defaultLight 基础主题)
16
+ */
17
+ export declare const getDefaultThemeVars: () => Record<string, string> | undefined;
2
18
  /**
3
19
  * css变量转值
4
20
  */
@@ -1,7 +1,21 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
5
19
  var __export = (target, all) => {
6
20
  for (var name in all)
7
21
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,15 +31,27 @@ var __copyProps = (to, from, except, desc) => {
17
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
32
  var cssVarToValue_exports = {};
19
33
  __export(cssVarToValue_exports, {
20
- cssVarToValue: () => cssVarToValue
34
+ cssVarToValue: () => cssVarToValue,
35
+ getDefaultThemeVars: () => getDefaultThemeVars,
36
+ setDefaultThemeVars: () => setDefaultThemeVars
21
37
  });
22
38
  module.exports = __toCommonJS(cssVarToValue_exports);
23
39
  var import_registry = require("@bifrostui/styles/registry");
40
+ let globalDefaultThemeVars;
41
+ const setDefaultThemeVars = (themeVars) => {
42
+ globalDefaultThemeVars = themeVars;
43
+ };
44
+ const getDefaultThemeVars = () => {
45
+ var _a, _b;
46
+ if (!globalDefaultThemeVars) {
47
+ return (_a = import_registry.defaultLight) == null ? void 0 : _a.cssVars;
48
+ }
49
+ return __spreadValues(__spreadValues({}, (_b = import_registry.defaultLight) == null ? void 0 : _b.cssVars), globalDefaultThemeVars);
50
+ };
24
51
  const cssVarToValue = (options) => {
25
- var _a;
26
52
  const {
27
53
  cssVar,
28
- themeVars = (_a = import_registry.defaultLight) == null ? void 0 : _a.cssVars,
54
+ themeVars = getDefaultThemeVars(),
29
55
  _visitedKeys = /* @__PURE__ */ new Set()
30
56
  } = options || {};
31
57
  if (!cssVar)
@@ -48,5 +74,7 @@ const cssVarToValue = (options) => {
48
74
  };
49
75
  // Annotate the CommonJS export names for ESM import in node:
50
76
  0 && (module.exports = {
51
- cssVarToValue
77
+ cssVarToValue,
78
+ getDefaultThemeVars,
79
+ setDefaultThemeVars
52
80
  });
package/dist/toArray.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  interface Option {
3
3
  keepEmpty?: boolean;
4
4
  }
package/dist/toArray.js CHANGED
@@ -30,17 +30,17 @@ __export(toArray_exports, {
30
30
  default: () => toArray
31
31
  });
32
32
  module.exports = __toCommonJS(toArray_exports);
33
- var import_react = __toESM(require("react"));
33
+ var React = __toESM(require("react"));
34
34
  var import_react_is = require("react-is");
35
35
  function toArray(children, option = {}) {
36
36
  let ret = [];
37
- import_react.default.Children.forEach(children, (child) => {
37
+ React.Children.forEach(children, (child) => {
38
38
  if ((child === void 0 || child === null) && !option.keepEmpty) {
39
39
  return;
40
40
  }
41
41
  if (Array.isArray(child)) {
42
42
  ret = ret.concat(toArray(child));
43
- } else if ((0, import_react_is.isFragment)(child) && child.props) {
43
+ } else if ((0, import_react_is.isFragment)(child) && React.isValidElement(child)) {
44
44
  ret = ret.concat(toArray(child.props.children, option));
45
45
  } else {
46
46
  ret.push(child);
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  interface IEasing {
3
3
  easeInOut: string;
4
4
  easeIn: string;
@@ -75,7 +75,7 @@ function formatMs(milliseconds) {
75
75
  function createTransitions(inputTransitions = {}) {
76
76
  const mergedEasing = __spreadValues(__spreadValues({}, easing), inputTransitions.easing);
77
77
  const mergedDuration = __spreadValues(__spreadValues({}, duration), inputTransitions.duration);
78
- const create = (props = ["all"], options) => {
78
+ const create = (props = ["all"], options = {}) => {
79
79
  const {
80
80
  duration: durationOption = mergedDuration.standard,
81
81
  easing: easingOption = mergedEasing.easeInOut,
@@ -0,0 +1,26 @@
1
+ import { Context } from './types';
2
+ /**
3
+ * Creates a context that supports selective subscriptions.
4
+ * This allows components to subscribe to only specific parts of the context value
5
+ * and re-render only when those parts change.
6
+ *
7
+ * @param defaultValue - The default value for the context
8
+ * @returns A context object that can be used with useContextSelector
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * interface MyContextValue {
13
+ * count: number;
14
+ * name: string;
15
+ * }
16
+ *
17
+ * const MyContext = createContext<MyContextValue>({ count: 0, name: '' });
18
+ *
19
+ * function MyComponent() {
20
+ * // Only re-renders when count changes, not when name changes
21
+ * const count = useContextSelector(MyContext, ctx => ctx.count);
22
+ * return <div>{count}</div>;
23
+ * }
24
+ * ```
25
+ */
26
+ export declare const createContext: <Value>(defaultValue: Value) => Context<Value>;
@@ -0,0 +1,53 @@
1
+ import * as React from "react";
2
+ import {
3
+ unstable_NormalPriority as NormalPriority,
4
+ unstable_runWithPriority as runWithPriority
5
+ } from "scheduler";
6
+ import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect";
7
+ const createProvider = (Original) => {
8
+ const Provider = (props) => {
9
+ const valueRef = React.useRef(props.value);
10
+ const versionRef = React.useRef(0);
11
+ const contextValue = React.useRef(null);
12
+ if (!contextValue.current) {
13
+ contextValue.current = {
14
+ value: valueRef,
15
+ version: versionRef,
16
+ listeners: []
17
+ };
18
+ }
19
+ useIsomorphicLayoutEffect(() => {
20
+ valueRef.current = props.value;
21
+ versionRef.current += 1;
22
+ runWithPriority(NormalPriority, () => {
23
+ contextValue.current.listeners.forEach(
24
+ (listener) => {
25
+ listener([versionRef.current, props.value]);
26
+ }
27
+ );
28
+ });
29
+ }, [props.value]);
30
+ return React.createElement(
31
+ Original,
32
+ { value: contextValue.current },
33
+ props.children
34
+ );
35
+ };
36
+ if (process.env.NODE_ENV !== "production") {
37
+ Provider.displayName = "ContextSelector.Provider";
38
+ }
39
+ return Provider;
40
+ };
41
+ const createContext = (defaultValue) => {
42
+ const context = React.createContext({
43
+ value: { current: defaultValue },
44
+ version: { current: -1 },
45
+ listeners: []
46
+ });
47
+ context.Provider = createProvider(context.Provider);
48
+ delete context.Consumer;
49
+ return context;
50
+ };
51
+ export {
52
+ createContext
53
+ };
@@ -0,0 +1,4 @@
1
+ export { createContext } from './createContext';
2
+ export { useContextSelector } from './useContextSelector';
3
+ export { useHasParentContext } from './useHasParentContext';
4
+ export type { Context, ContextSelector, ContextValue, ContextVersion, } from './types';
@@ -0,0 +1,8 @@
1
+ import { createContext } from "./createContext";
2
+ import { useContextSelector } from "./useContextSelector";
3
+ import { useHasParentContext } from "./useHasParentContext";
4
+ export {
5
+ createContext,
6
+ useContextSelector,
7
+ useHasParentContext
8
+ };
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @internal
4
+ */
5
+ export type Context<Value> = React.Context<Value> & {
6
+ Provider: React.FC<React.ProviderProps<Value>>;
7
+ Consumer: never;
8
+ };
9
+ export type ContextSelector<Value, SelectedValue> = (value: Value) => SelectedValue;
10
+ /**
11
+ * @internal
12
+ */
13
+ export type ContextVersion = number;
14
+ /**
15
+ * @internal
16
+ */
17
+ export type ContextValue<Value> = {
18
+ /** Holds a set of subscribers from components. */
19
+ listeners: ((payload: readonly [ContextVersion, Value]) => void)[];
20
+ /** Holds an actual value of React's context that will be propagated down for computations. */
21
+ value: React.MutableRefObject<Value>;
22
+ /** A version field is used to sync a context value and consumers. */
23
+ version: React.MutableRefObject<ContextVersion>;
24
+ };
File without changes
@@ -0,0 +1,29 @@
1
+ import { Context, ContextSelector } from './types';
2
+ /**
3
+ * This hook returns context selected value by selector.
4
+ * It will only accept context created by `createContext` from this package.
5
+ * It will trigger re-render only if the selected value is referentially changed.
6
+ *
7
+ * @param context - Context created by createContext from this package
8
+ * @param selector - Function that selects a value from the context
9
+ * @returns The selected value from the context
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * interface MyContextValue {
14
+ * count: number;
15
+ * name: string;
16
+ * }
17
+ *
18
+ * const MyContext = createContext<MyContextValue>({ count: 0, name: '' });
19
+ *
20
+ * function Counter() {
21
+ * // Only re-renders when count changes, not when name changes
22
+ * const count = useContextSelector(MyContext, ctx => ctx.count);
23
+ * const increment = useContextSelector(MyContext, ctx => ctx.increment);
24
+ *
25
+ * return <button onClick={increment}>{count}</button>;
26
+ * }
27
+ * ```
28
+ */
29
+ export declare const useContextSelector: <Value, SelectedValue>(context: Context<Value>, selector: ContextSelector<Value, SelectedValue>) => SelectedValue;
@@ -0,0 +1,59 @@
1
+ import * as React from "react";
2
+ import useEventCallback from "../hooks/useEventCallback";
3
+ import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect";
4
+ const useContextSelector = (context, selector) => {
5
+ const contextValue = React.useContext(
6
+ context
7
+ );
8
+ const {
9
+ value: { current: value },
10
+ version: { current: version },
11
+ listeners
12
+ } = contextValue;
13
+ const selected = selector(value);
14
+ const [state, setState] = React.useState([
15
+ value,
16
+ selected
17
+ ]);
18
+ const dispatch = (payload) => {
19
+ setState((prevState) => {
20
+ if (!payload) {
21
+ return [value, selected];
22
+ }
23
+ if (payload[0] <= version) {
24
+ if (Object.is(prevState[1], selected)) {
25
+ return prevState;
26
+ }
27
+ return [value, selected];
28
+ }
29
+ try {
30
+ if (Object.is(prevState[0], payload[1])) {
31
+ return prevState;
32
+ }
33
+ const nextSelected = selector(payload[1]);
34
+ if (Object.is(prevState[1], nextSelected)) {
35
+ return prevState;
36
+ }
37
+ return [payload[1], nextSelected];
38
+ } catch (e) {
39
+ console.error(e);
40
+ }
41
+ return [prevState[0], prevState[1]];
42
+ });
43
+ };
44
+ if (!Object.is(state[1], selected)) {
45
+ dispatch(void 0);
46
+ }
47
+ const stableDispatch = useEventCallback(dispatch);
48
+ useIsomorphicLayoutEffect(() => {
49
+ listeners.push(stableDispatch);
50
+ return () => {
51
+ const index = listeners.indexOf(stableDispatch);
52
+ listeners.splice(index, 1);
53
+ };
54
+ }, [stableDispatch, listeners]);
55
+ return state[1];
56
+ };
57
+ export {
58
+ useContextSelector
59
+ };
@@ -0,0 +1,26 @@
1
+ import { Context } from './types';
2
+ /**
3
+ * Utility hook for contexts created by createContext from this package
4
+ * to determine if a parent context exists.
5
+ *
6
+ * WARNING: This hook will not work for native React contexts
7
+ *
8
+ * @param context - Context created by createContext from this package
9
+ * @returns Whether the hook is wrapped by a parent context provider
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const MyContext = createContext({ value: 'default' });
14
+ *
15
+ * function MyComponent() {
16
+ * const hasContext = useHasParentContext(MyContext);
17
+ *
18
+ * if (hasContext) {
19
+ * return <div>I am inside context provider</div>;
20
+ * } else {
21
+ * return <div>I can only use default context value</div>;
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function useHasParentContext<Value>(context: Context<Value>): boolean;
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ function useHasParentContext(context) {
3
+ const contextValue = React.useContext(
4
+ context
5
+ );
6
+ if (contextValue.version) {
7
+ return contextValue.version.current !== -1;
8
+ }
9
+ return false;
10
+ }
11
+ export {
12
+ useHasParentContext
13
+ };
@@ -1,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  /**
2
3
  * 根据元素宽高判断是否超出边界,超出边界则重新定义方向
3
4
  */
@@ -1,16 +1,6 @@
1
1
  function getBoundingClientRect(ele) {
2
2
  if (!ele) {
3
- return Promise.resolve({
4
- width: 0,
5
- height: 0,
6
- top: 0,
7
- right: 0,
8
- bottom: 0,
9
- left: 0,
10
- x: 0,
11
- y: 0,
12
- toJSON: () => ({})
13
- });
3
+ return Promise.resolve(null);
14
4
  }
15
5
  return Promise.resolve(ele.getBoundingClientRect());
16
6
  }
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import * as React from "react";
2
2
  function useDomReady(cb) {
3
3
  React.useEffect(() => {
4
4
  cb == null ? void 0 : cb();
@@ -1,6 +1,15 @@
1
1
  /**
2
- * https://github.com/facebook/react/issues/14099#issuecomment-440013892
2
+ * Modified `useCallback` that can be used when dependencies change too frequently.
3
3
  *
4
- * @param {function} fn
4
+ * Can occur when:
5
+ * - User props are dependencies which could change on every render
6
+ * - Volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
7
+ *
8
+ * This should not be used often, but can be a useful re-render optimization since the callback
9
+ * is a ref and will not be invalidated between re-renders.
10
+ *
11
+ * @param fn - The callback function that will be used
12
+ * @see https://github.com/facebook/react/issues/14099#issuecomment-440013892
13
+ * @see https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
5
14
  */
6
- export default function useEventCallback(fn: any): (...args: any[]) => any;
15
+ export default function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
@@ -1,10 +1,19 @@
1
- import React, { useLayoutEffect } from "react";
1
+ import * as React from "react";
2
+ import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
2
3
  function useEventCallback(fn) {
3
- const ref = React.useRef(fn);
4
- useLayoutEffect(() => {
5
- ref.current = fn;
4
+ const callbackRef = React.useRef(() => {
5
+ throw new Error("Cannot call an event handler while rendering");
6
6
  });
7
- return React.useCallback((...args) => (0, ref.current)(...args), []);
7
+ useIsomorphicLayoutEffect(() => {
8
+ callbackRef.current = fn;
9
+ }, [fn]);
10
+ return React.useCallback(
11
+ (...args) => {
12
+ const callback = callbackRef.current;
13
+ return callback(...args);
14
+ },
15
+ [callbackRef]
16
+ );
8
17
  }
9
18
  export {
10
19
  useEventCallback as default
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
4
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
5
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
6
+ * the server.
7
+ *
8
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
9
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
10
+ */
11
+ export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import { canUseDOM } from "../ssr";
3
+ const useIsomorphicLayoutEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;
4
+ export {
5
+ useIsomorphicLayoutEffect
6
+ };
@@ -13,7 +13,7 @@ function useMemoizedFn(fn) {
13
13
  fnRef.current = useMemo(() => fn, [fn]);
14
14
  const memoizedFn = useRef();
15
15
  if (!memoizedFn.current) {
16
- memoizedFn.current = function(...args) {
16
+ memoizedFn.current = function memoized(...args) {
17
17
  return fnRef.current.apply(this, args);
18
18
  };
19
19
  }
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import * as React from "react";
2
2
  import useDomReady from "./useDomReady";
3
3
  import getBoundingClientRect from "../getBoundingClientRect";
4
4
  import { getTargetElement } from "../domTarget";
@@ -1,8 +1,8 @@
1
1
  import { useEffect } from "react";
2
2
  let eventTarget;
3
- const Touch = function Touch2(target, identifier, pos, deltaX, deltaY) {
4
- deltaX = deltaX || 0;
5
- deltaY = deltaY || 0;
3
+ const Touch = function Touch2(target, identifier, pos, dx = 0, dy = 0) {
4
+ const deltaX = dx || 0;
5
+ const deltaY = dy || 0;
6
6
  this.identifier = identifier;
7
7
  this.target = target;
8
8
  this.clientX = pos.clientX + deltaX;
package/es/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from './domUtils';
15
15
  export * from './isType';
16
16
  export * from './render';
17
17
  export * from './themeCreator';
18
+ export * from './context-selector';
package/es/index.js CHANGED
@@ -40,6 +40,7 @@ export * from "./domUtils";
40
40
  export * from "./isType";
41
41
  export * from "./render";
42
42
  export * from "./themeCreator";
43
+ export * from "./context-selector";
43
44
  export {
44
45
  default8 as blockTouch,
45
46
  default3 as convertHexToRGBA,
package/es/isMini.js CHANGED
@@ -1,4 +1,4 @@
1
- const isMini = typeof process.env.TARO_ENV === "string";
1
+ const isMini = typeof process.env.TARO_ENV === "string" && ["weapp", "swan", "alipay", "tt", "qq", "jd"].includes(process.env.TARO_ENV);
2
2
  const isWeapp = process.env.TARO_ENV === "weapp";
3
3
  const isAlipay = process.env.TARO_ENV === "alipay";
4
4
  const isTt = process.env.TARO_ENV === "tt";
package/es/render.d.ts CHANGED
@@ -8,6 +8,6 @@ type ContainerType = (Element | DocumentFragment) & {
8
8
  export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
9
9
  export declare function render(node: ReactElement, container: ContainerType): void;
10
10
  /** @private Test usage. Not work in prod */
11
- export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): any;
12
- export declare function unmount(container: ContainerType): any;
11
+ export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean;
12
+ export declare function unmount(container: ContainerType): boolean | Promise<void>;
13
13
  export {};
package/es/setRef.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  export default function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Verifies if an application can use DOM.
3
+ */
4
+ export declare function canUseDOM(): boolean;
@@ -0,0 +1,6 @@
1
+ function canUseDOM() {
2
+ return typeof window !== "undefined" && !!(window.document && window.document.createElement);
3
+ }
4
+ export {
5
+ canUseDOM
6
+ };
@@ -0,0 +1 @@
1
+ export { canUseDOM } from './canUseDOM';
@@ -0,0 +1,4 @@
1
+ import { canUseDOM } from "./canUseDOM";
2
+ export {
3
+ canUseDOM
4
+ };
@@ -1,4 +1,20 @@
1
1
  import { CssVarToValueOptions } from './index.types';
2
+ /**
3
+ * 设置全局默认主题变量
4
+ * 建议在小程序入口文件(app.ts)中调用,设置后所有组件都会使用该主题
5
+ * 支持主题继承:如果设置的主题中某个变量不存在,会自动从 defaultLight 继承
6
+ * @param themeVars 主题CSS变量对象
7
+ * @example
8
+ * import { setDefaultThemeVars } from '@bifrostui/utils';
9
+ * import { pioneerLight } from '@bifrostui/styles/registry';
10
+ * setDefaultThemeVars(pioneerLight.cssVars);
11
+ */
12
+ export declare const setDefaultThemeVars: (themeVars: Record<string, string> | undefined) => void;
13
+ /**
14
+ * 获取当前全局默认主题变量
15
+ * 返回合并后的主题变量(自定义主题 + defaultLight 基础主题)
16
+ */
17
+ export declare const getDefaultThemeVars: () => Record<string, string> | undefined;
2
18
  /**
3
19
  * css变量转值
4
20
  */