@bifrostui/utils 1.5.3 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/domUtils/addClass.d.ts +1 -0
  2. package/dist/domUtils/addClass.js +46 -0
  3. package/dist/domUtils/index.d.ts +3 -12
  4. package/dist/domUtils/index.js +10 -21
  5. package/dist/domUtils/index.miniapp.d.ts +3 -2
  6. package/dist/domUtils/index.miniapp.js +10 -61
  7. package/dist/domUtils/rect.d.ts +12 -0
  8. package/dist/domUtils/rect.js +46 -0
  9. package/dist/domUtils/rect.miniapp.d.ts +2 -0
  10. package/dist/domUtils/rect.miniapp.js +86 -0
  11. package/dist/domUtils/removeClass.d.ts +1 -0
  12. package/dist/domUtils/removeClass.js +47 -0
  13. package/dist/getBoundingClientRect/index.d.ts +1 -1
  14. package/dist/getBoundingClientRect/index.js +13 -0
  15. package/dist/hooks/useDidMountEffect.d.ts +1 -1
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +5 -6
  18. package/dist/render.d.ts +2 -2
  19. package/dist/themeCreator/createTheme.d.ts +10 -0
  20. package/dist/themeCreator/createTheme.js +61 -0
  21. package/dist/themeCreator/cssVarToValue.d.ts +5 -0
  22. package/dist/themeCreator/cssVarToValue.js +52 -0
  23. package/dist/themeCreator/index.d.ts +3 -0
  24. package/dist/themeCreator/index.js +25 -0
  25. package/dist/themeCreator/index.types.d.ts +37 -0
  26. package/dist/themeCreator/index.types.js +15 -0
  27. package/es/domUtils/addClass.d.ts +1 -0
  28. package/es/domUtils/addClass.js +23 -0
  29. package/es/domUtils/index.d.ts +3 -12
  30. package/es/domUtils/index.js +6 -19
  31. package/es/domUtils/index.miniapp.d.ts +3 -2
  32. package/es/domUtils/index.miniapp.js +6 -51
  33. package/es/domUtils/rect.d.ts +12 -0
  34. package/es/domUtils/rect.js +22 -0
  35. package/es/domUtils/rect.miniapp.d.ts +2 -0
  36. package/es/domUtils/rect.miniapp.js +54 -0
  37. package/es/domUtils/removeClass.d.ts +1 -0
  38. package/es/domUtils/removeClass.js +24 -0
  39. package/es/getBoundingClientRect/index.d.ts +1 -1
  40. package/es/getBoundingClientRect/index.js +13 -0
  41. package/es/hooks/useDidMountEffect.d.ts +1 -1
  42. package/es/index.d.ts +2 -1
  43. package/es/index.js +2 -3
  44. package/es/render.d.ts +2 -2
  45. package/es/themeCreator/createTheme.d.ts +10 -0
  46. package/es/themeCreator/createTheme.js +37 -0
  47. package/es/themeCreator/cssVarToValue.d.ts +5 -0
  48. package/es/themeCreator/cssVarToValue.js +29 -0
  49. package/es/themeCreator/index.d.ts +3 -0
  50. package/es/themeCreator/index.js +3 -0
  51. package/es/themeCreator/index.types.d.ts +37 -0
  52. package/es/themeCreator/index.types.js +1 -0
  53. package/package.json +3 -2
@@ -0,0 +1 @@
1
+ export declare const addClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,46 @@
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 addClass_exports = {};
19
+ __export(addClass_exports, {
20
+ addClass: () => addClass
21
+ });
22
+ module.exports = __toCommonJS(addClass_exports);
23
+ const hasClass = (element, className) => {
24
+ if (element.classList)
25
+ return !!className && element.classList.contains(className);
26
+ return ` ${element.className.baseVal || element.className} `.indexOf(
27
+ ` ${className} `
28
+ ) !== -1;
29
+ };
30
+ const addClass = (element, className) => {
31
+ if (element.classList) {
32
+ element.classList.add(className);
33
+ } else if (!hasClass(element, className))
34
+ if (typeof element.className === "string") {
35
+ element.className = `${element.className} ${className}`;
36
+ } else {
37
+ element.setAttribute(
38
+ "class",
39
+ `${element.className && element.className.baseVal || ""} ${className}`
40
+ );
41
+ }
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ addClass
46
+ });
@@ -1,12 +1,3 @@
1
- export declare const getClientRect: () => Promise<{
2
- width: number;
3
- height: number;
4
- left: number;
5
- top: number;
6
- right: number;
7
- bottom: number;
8
- }>;
9
- export declare const getScrollRect: () => Promise<{
10
- top: number;
11
- left: number;
12
- }>;
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -17,30 +17,19 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var domUtils_exports = {};
19
19
  __export(domUtils_exports, {
20
- getClientRect: () => getClientRect,
21
- getScrollRect: () => getScrollRect
20
+ addClass: () => import_addClass.addClass,
21
+ getClientRect: () => import_rect.getClientRect,
22
+ getScrollRect: () => import_rect.getScrollRect,
23
+ removeClass: () => import_removeClass.removeClass
22
24
  });
23
25
  module.exports = __toCommonJS(domUtils_exports);
24
- const getClientRect = () => {
25
- const width = window.innerWidth || document.documentElement.clientWidth;
26
- const height = window.innerHeight || document.documentElement.clientHeight;
27
- return Promise.resolve({
28
- width,
29
- height,
30
- left: 0,
31
- top: 0,
32
- right: width,
33
- bottom: height
34
- });
35
- };
36
- const getScrollRect = () => {
37
- return Promise.resolve({
38
- top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
39
- left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
40
- });
41
- };
26
+ var import_rect = require("./rect");
27
+ var import_addClass = require("./addClass");
28
+ var import_removeClass = require("./removeClass");
42
29
  // Annotate the CommonJS export names for ESM import in node:
43
30
  0 && (module.exports = {
31
+ addClass,
44
32
  getClientRect,
45
- getScrollRect
33
+ getScrollRect,
34
+ removeClass
46
35
  });
@@ -1,2 +1,3 @@
1
- export declare const getClientRect: () => Promise<unknown>;
2
- export declare const getScrollRect: () => Promise<unknown>;
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -1,26 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
5
  var __export = (target, all) => {
25
6
  for (var name in all)
26
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -33,54 +14,22 @@ var __copyProps = (to, from, except, desc) => {
33
14
  }
34
15
  return to;
35
16
  };
36
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
- // If the importer is in node compatibility mode or this is not an ESM
38
- // file that has been converted to a CommonJS file using a Babel-
39
- // compatible transform (i.e. "__esModule" has not been set), then set
40
- // "default" to the CommonJS "module.exports" for node compatibility.
41
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
- mod
43
- ));
44
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
18
  var index_miniapp_exports = {};
46
19
  __export(index_miniapp_exports, {
47
- getClientRect: () => getClientRect,
48
- getScrollRect: () => getScrollRect
20
+ addClass: () => import_addClass.addClass,
21
+ getClientRect: () => import_rect.getClientRect,
22
+ getScrollRect: () => import_rect.getScrollRect,
23
+ removeClass: () => import_removeClass.removeClass
49
24
  });
50
25
  module.exports = __toCommonJS(index_miniapp_exports);
51
- var import_taro = __toESM(require("@tarojs/taro"));
52
- const getClientRect = () => {
53
- return new Promise((resolve, reject) => {
54
- try {
55
- const res = import_taro.default.getSystemInfoSync();
56
- const width = res.windowWidth;
57
- const height = res.windowHeight;
58
- const clientInfo = __spreadProps(__spreadValues({}, res), {
59
- width,
60
- height,
61
- left: 0,
62
- top: 0,
63
- right: width,
64
- bottom: height
65
- });
66
- resolve(clientInfo);
67
- } catch (error) {
68
- reject(error);
69
- }
70
- });
71
- };
72
- const getScrollRect = () => {
73
- return new Promise((resolve) => {
74
- import_taro.default.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
75
- resolve({
76
- top: res[0].scrollTop,
77
- left: res[0].scrollLeft
78
- });
79
- });
80
- });
81
- };
26
+ var import_rect = require("./rect");
27
+ var import_addClass = require("./addClass");
28
+ var import_removeClass = require("./removeClass");
82
29
  // Annotate the CommonJS export names for ESM import in node:
83
30
  0 && (module.exports = {
31
+ addClass,
84
32
  getClientRect,
85
- getScrollRect
33
+ getScrollRect,
34
+ removeClass
86
35
  });
@@ -0,0 +1,12 @@
1
+ export declare const getClientRect: () => Promise<{
2
+ width: number;
3
+ height: number;
4
+ left: number;
5
+ top: number;
6
+ right: number;
7
+ bottom: number;
8
+ }>;
9
+ export declare const getScrollRect: () => Promise<{
10
+ top: number;
11
+ left: number;
12
+ }>;
@@ -0,0 +1,46 @@
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 rect_exports = {};
19
+ __export(rect_exports, {
20
+ getClientRect: () => getClientRect,
21
+ getScrollRect: () => getScrollRect
22
+ });
23
+ module.exports = __toCommonJS(rect_exports);
24
+ const getClientRect = () => {
25
+ const width = window.innerWidth || document.documentElement.clientWidth;
26
+ const height = window.innerHeight || document.documentElement.clientHeight;
27
+ return Promise.resolve({
28
+ width,
29
+ height,
30
+ left: 0,
31
+ top: 0,
32
+ right: width,
33
+ bottom: height
34
+ });
35
+ };
36
+ const getScrollRect = () => {
37
+ return Promise.resolve({
38
+ top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
39
+ left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
40
+ });
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ getClientRect,
45
+ getScrollRect
46
+ });
@@ -0,0 +1,2 @@
1
+ export declare const getClientRect: () => Promise<unknown>;
2
+ export declare const getScrollRect: () => Promise<unknown>;
@@ -0,0 +1,86 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
44
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
+ var rect_miniapp_exports = {};
46
+ __export(rect_miniapp_exports, {
47
+ getClientRect: () => getClientRect,
48
+ getScrollRect: () => getScrollRect
49
+ });
50
+ module.exports = __toCommonJS(rect_miniapp_exports);
51
+ var import_taro = __toESM(require("@tarojs/taro"));
52
+ const getClientRect = () => {
53
+ return new Promise((resolve, reject) => {
54
+ try {
55
+ const res = import_taro.default.getSystemInfoSync();
56
+ const width = res.windowWidth;
57
+ const height = res.windowHeight;
58
+ const clientInfo = __spreadProps(__spreadValues({}, res), {
59
+ width,
60
+ height,
61
+ left: 0,
62
+ top: 0,
63
+ right: width,
64
+ bottom: height
65
+ });
66
+ resolve(clientInfo);
67
+ } catch (error) {
68
+ reject(error);
69
+ }
70
+ });
71
+ };
72
+ const getScrollRect = () => {
73
+ return new Promise((resolve) => {
74
+ import_taro.default.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
75
+ resolve({
76
+ top: res[0].scrollTop,
77
+ left: res[0].scrollLeft
78
+ });
79
+ });
80
+ });
81
+ };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ getClientRect,
85
+ getScrollRect
86
+ });
@@ -0,0 +1 @@
1
+ export declare const removeClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,47 @@
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 removeClass_exports = {};
19
+ __export(removeClass_exports, {
20
+ removeClass: () => removeClass
21
+ });
22
+ module.exports = __toCommonJS(removeClass_exports);
23
+ const replaceClassName = (origClass, classToRemove) => {
24
+ return origClass.replace(new RegExp(`(^|\\s)${classToRemove}(?:\\s|$)`, "g"), "$1").replace(/\s+/g, " ").replace(/^\s*|\s*$/g, "");
25
+ };
26
+ const removeClass = (element, className) => {
27
+ if (element.classList) {
28
+ element.classList.remove(className);
29
+ } else if (typeof element.className === "string") {
30
+ element.className = replaceClassName(
31
+ element.className,
32
+ className
33
+ );
34
+ } else {
35
+ element.setAttribute(
36
+ "class",
37
+ replaceClassName(
38
+ element.className && element.className.baseVal || "",
39
+ className
40
+ )
41
+ );
42
+ }
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ removeClass
47
+ });
@@ -1 +1 @@
1
- export default function getBoundingClientRect(ele: Element): Promise<DOMRect>;
1
+ export default function getBoundingClientRect(ele: Element | null): Promise<DOMRect>;
@@ -21,5 +21,18 @@ __export(getBoundingClientRect_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(getBoundingClientRect_exports);
23
23
  function getBoundingClientRect(ele) {
24
+ if (!ele) {
25
+ return Promise.resolve({
26
+ width: 0,
27
+ height: 0,
28
+ top: 0,
29
+ right: 0,
30
+ bottom: 0,
31
+ left: 0,
32
+ x: 0,
33
+ y: 0,
34
+ toJSON: () => ({})
35
+ });
36
+ }
24
37
  return Promise.resolve(ele.getBoundingClientRect());
25
38
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * skip inital run useEffect
2
+ * skip initial run useEffect
3
3
  */
4
4
  declare const useDidMountEffect: (func: any, deps: any) => void;
5
5
  export default useDidMountEffect;
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { default as blockTouch } from './touchBlocker';
11
11
  export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
12
12
  export { default as getRootContainer } from './getRootContainer';
13
13
  export { default as getBoundingClientRect } from './getBoundingClientRect';
14
- export { getScrollRect, getClientRect } from './domUtils';
14
+ export * from './domUtils';
15
15
  export * from './isType';
16
16
  export * from './render';
17
+ export * from './themeCreator';
package/dist/index.js CHANGED
@@ -38,10 +38,8 @@ __export(src_exports, {
38
38
  emulateTouchMove: () => import_hooks.emulateTouchMove,
39
39
  emulateTouchStart: () => import_hooks.emulateTouchStart,
40
40
  getBoundingClientRect: () => import_getBoundingClientRect.default,
41
- getClientRect: () => import_domUtils.getClientRect,
42
41
  getNewDirectionLocation: () => import_directionLocationUtil.getNewDirectionLocation,
43
42
  getRootContainer: () => import_getRootContainer.default,
44
- getScrollRect: () => import_domUtils.getScrollRect,
45
43
  getStylesAndLocation: () => import_directionLocationUtil.getStylesAndLocation,
46
44
  getTransitionProps: () => import_transitions.getTransitionProps,
47
45
  isAlipay: () => import_isMini.isAlipay,
@@ -80,9 +78,10 @@ var import_touchBlocker = __toESM(require("./touchBlocker"));
80
78
  var import_transitions = require("./transitions");
81
79
  var import_getRootContainer = __toESM(require("./getRootContainer"));
82
80
  var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
83
- var import_domUtils = require("./domUtils");
81
+ __reExport(src_exports, require("./domUtils"), module.exports);
84
82
  __reExport(src_exports, require("./isType"), module.exports);
85
83
  __reExport(src_exports, require("./render"), module.exports);
84
+ __reExport(src_exports, require("./themeCreator"), module.exports);
86
85
  // Annotate the CommonJS export names for ESM import in node:
87
86
  0 && (module.exports = {
88
87
  blockTouch,
@@ -95,10 +94,8 @@ __reExport(src_exports, require("./render"), module.exports);
95
94
  emulateTouchMove,
96
95
  emulateTouchStart,
97
96
  getBoundingClientRect,
98
- getClientRect,
99
97
  getNewDirectionLocation,
100
98
  getRootContainer,
101
- getScrollRect,
102
99
  getStylesAndLocation,
103
100
  getTransitionProps,
104
101
  isAlipay,
@@ -122,6 +119,8 @@ __reExport(src_exports, require("./render"), module.exports);
122
119
  useTouchEmulator,
123
120
  useUniqueId,
124
121
  useValue,
122
+ ...require("./domUtils"),
125
123
  ...require("./isType"),
126
- ...require("./render")
124
+ ...require("./render"),
125
+ ...require("./themeCreator")
127
126
  });
package/dist/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): boolean;
12
- export declare function unmount(container: ContainerType): boolean | Promise<void>;
11
+ export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): any;
12
+ export declare function unmount(container: ContainerType): any;
13
13
  export {};
@@ -0,0 +1,10 @@
1
+ import { MountThemeVarsOptions, ThemeCreatorOptions } from './index.types';
2
+ /**
3
+ * 挂载自定义主题
4
+ */
5
+ declare const mountThemeVars: (options: MountThemeVarsOptions) => void;
6
+ /**
7
+ * 创建主题
8
+ */
9
+ declare const createTheme: (options: ThemeCreatorOptions) => string;
10
+ export { createTheme, mountThemeVars };
@@ -0,0 +1,61 @@
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 createTheme_exports = {};
19
+ __export(createTheme_exports, {
20
+ createTheme: () => createTheme,
21
+ mountThemeVars: () => mountThemeVars
22
+ });
23
+ module.exports = __toCommonJS(createTheme_exports);
24
+ const convertToCss = (styles) => {
25
+ let result = "";
26
+ const cssVarKeys = Object.keys(styles);
27
+ cssVarKeys.forEach((key, index) => {
28
+ const value = styles[key];
29
+ if (value.includes("PX")) {
30
+ result += "/* prettier-ignore */\n ";
31
+ }
32
+ result += `${key}: ${value};
33
+ ${index === cssVarKeys.length - 1 ? "" : " "}`;
34
+ });
35
+ return result;
36
+ };
37
+ const mountThemeVars = (options) => {
38
+ const { theme = "", container } = options || {};
39
+ const style = document.createElement("style");
40
+ style.type = "text/css";
41
+ style.appendChild(document.createTextNode(theme));
42
+ if (!container) {
43
+ document.head.appendChild(style);
44
+ return;
45
+ }
46
+ container.appendChild(style);
47
+ };
48
+ const createTheme = (options) => {
49
+ const {
50
+ rootSelector = ":root, [data-color-mode='light'][data-theme]",
51
+ cssVars = {}
52
+ } = options || {};
53
+ const rootContent = `${rootSelector} {
54
+ ${convertToCss(cssVars)} }`;
55
+ return rootContent;
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ createTheme,
60
+ mountThemeVars
61
+ });
@@ -0,0 +1,5 @@
1
+ import { CssVarToValueOptions } from './index.types';
2
+ /**
3
+ * css变量转值
4
+ */
5
+ export declare const cssVarToValue: (options: CssVarToValueOptions) => string | undefined;
@@ -0,0 +1,52 @@
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 cssVarToValue_exports = {};
19
+ __export(cssVarToValue_exports, {
20
+ cssVarToValue: () => cssVarToValue
21
+ });
22
+ module.exports = __toCommonJS(cssVarToValue_exports);
23
+ var import_registry = require("@bifrostui/styles/registry");
24
+ const cssVarToValue = (options) => {
25
+ var _a;
26
+ const {
27
+ cssVar,
28
+ themeVars = (_a = import_registry.defaultLight) == null ? void 0 : _a.cssVars,
29
+ _visitedKeys = /* @__PURE__ */ new Set()
30
+ } = options || {};
31
+ if (!cssVar)
32
+ return "";
33
+ const variableKey = cssVar.replace(/^var\(/, "").replace(/\)$/, "");
34
+ const variableValue = themeVars == null ? void 0 : themeVars[variableKey];
35
+ if (_visitedKeys.has(variableKey)) {
36
+ console.warn(`\u68C0\u6D4B\u5230CSS\u53D8\u91CF\u5FAA\u73AF\u5F15\u7528: ${variableKey}`);
37
+ return variableValue;
38
+ }
39
+ const nextVisited = new Set(_visitedKeys).add(variableKey);
40
+ if (variableValue && variableValue.startsWith("var(")) {
41
+ return cssVarToValue({
42
+ cssVar: variableValue,
43
+ themeVars,
44
+ _visitedKeys: nextVisited
45
+ });
46
+ }
47
+ return variableValue;
48
+ };
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ cssVarToValue
52
+ });
@@ -0,0 +1,3 @@
1
+ export * from './createTheme';
2
+ export * from './cssVarToValue';
3
+ export * from './index.types';
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var themeCreator_exports = {};
16
+ module.exports = __toCommonJS(themeCreator_exports);
17
+ __reExport(themeCreator_exports, require("./createTheme"), module.exports);
18
+ __reExport(themeCreator_exports, require("./cssVarToValue"), module.exports);
19
+ __reExport(themeCreator_exports, require("./index.types"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./createTheme"),
23
+ ...require("./cssVarToValue"),
24
+ ...require("./index.types")
25
+ });
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 挂载自定义主题选项
3
+ */
4
+ export interface MountThemeVarsOptions {
5
+ theme: string;
6
+ container?: HTMLElement;
7
+ }
8
+ export interface ThemeCreatorOptions {
9
+ /**
10
+ * 主题所挂在的根选择器
11
+ * @default `:root, [data-color-mode='light'][data-theme]`
12
+ */
13
+ rootSelector?: string;
14
+ /**
15
+ * 主题全局变量
16
+ */
17
+ cssVars: Record<string, string>;
18
+ }
19
+ /**
20
+ * css变量转值
21
+ */
22
+ export interface CssVarToValueOptions {
23
+ /**
24
+ * 当前主题
25
+ */
26
+ cssVar: string;
27
+ /**
28
+ * 当前主题模式
29
+ * @default defaultLight
30
+ */
31
+ themeVars?: Record<string, string>;
32
+ /**
33
+ * 记录已解析的变量路径
34
+ * 函数内部使用参数
35
+ */
36
+ _visitedKeys?: Set<string>;
37
+ }
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var index_types_exports = {};
15
+ module.exports = __toCommonJS(index_types_exports);
@@ -0,0 +1 @@
1
+ export declare const addClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,23 @@
1
+ const hasClass = (element, className) => {
2
+ if (element.classList)
3
+ return !!className && element.classList.contains(className);
4
+ return ` ${element.className.baseVal || element.className} `.indexOf(
5
+ ` ${className} `
6
+ ) !== -1;
7
+ };
8
+ const addClass = (element, className) => {
9
+ if (element.classList) {
10
+ element.classList.add(className);
11
+ } else if (!hasClass(element, className))
12
+ if (typeof element.className === "string") {
13
+ element.className = `${element.className} ${className}`;
14
+ } else {
15
+ element.setAttribute(
16
+ "class",
17
+ `${element.className && element.className.baseVal || ""} ${className}`
18
+ );
19
+ }
20
+ };
21
+ export {
22
+ addClass
23
+ };
@@ -1,12 +1,3 @@
1
- export declare const getClientRect: () => Promise<{
2
- width: number;
3
- height: number;
4
- left: number;
5
- top: number;
6
- right: number;
7
- bottom: number;
8
- }>;
9
- export declare const getScrollRect: () => Promise<{
10
- top: number;
11
- left: number;
12
- }>;
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -1,22 +1,9 @@
1
- const getClientRect = () => {
2
- const width = window.innerWidth || document.documentElement.clientWidth;
3
- const height = window.innerHeight || document.documentElement.clientHeight;
4
- return Promise.resolve({
5
- width,
6
- height,
7
- left: 0,
8
- top: 0,
9
- right: width,
10
- bottom: height
11
- });
12
- };
13
- const getScrollRect = () => {
14
- return Promise.resolve({
15
- top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
16
- left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
17
- });
18
- };
1
+ import { getClientRect, getScrollRect } from "./rect";
2
+ import { addClass } from "./addClass";
3
+ import { removeClass } from "./removeClass";
19
4
  export {
5
+ addClass,
20
6
  getClientRect,
21
- getScrollRect
7
+ getScrollRect,
8
+ removeClass
22
9
  };
@@ -1,2 +1,3 @@
1
- export declare const getClientRect: () => Promise<unknown>;
2
- export declare const getScrollRect: () => Promise<unknown>;
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -1,54 +1,9 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import Taro from "@tarojs/taro";
21
- const getClientRect = () => {
22
- return new Promise((resolve, reject) => {
23
- try {
24
- const res = Taro.getSystemInfoSync();
25
- const width = res.windowWidth;
26
- const height = res.windowHeight;
27
- const clientInfo = __spreadProps(__spreadValues({}, res), {
28
- width,
29
- height,
30
- left: 0,
31
- top: 0,
32
- right: width,
33
- bottom: height
34
- });
35
- resolve(clientInfo);
36
- } catch (error) {
37
- reject(error);
38
- }
39
- });
40
- };
41
- const getScrollRect = () => {
42
- return new Promise((resolve) => {
43
- Taro.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
44
- resolve({
45
- top: res[0].scrollTop,
46
- left: res[0].scrollLeft
47
- });
48
- });
49
- });
50
- };
1
+ import { getClientRect, getScrollRect } from "./rect";
2
+ import { addClass } from "./addClass";
3
+ import { removeClass } from "./removeClass";
51
4
  export {
5
+ addClass,
52
6
  getClientRect,
53
- getScrollRect
7
+ getScrollRect,
8
+ removeClass
54
9
  };
@@ -0,0 +1,12 @@
1
+ export declare const getClientRect: () => Promise<{
2
+ width: number;
3
+ height: number;
4
+ left: number;
5
+ top: number;
6
+ right: number;
7
+ bottom: number;
8
+ }>;
9
+ export declare const getScrollRect: () => Promise<{
10
+ top: number;
11
+ left: number;
12
+ }>;
@@ -0,0 +1,22 @@
1
+ const getClientRect = () => {
2
+ const width = window.innerWidth || document.documentElement.clientWidth;
3
+ const height = window.innerHeight || document.documentElement.clientHeight;
4
+ return Promise.resolve({
5
+ width,
6
+ height,
7
+ left: 0,
8
+ top: 0,
9
+ right: width,
10
+ bottom: height
11
+ });
12
+ };
13
+ const getScrollRect = () => {
14
+ return Promise.resolve({
15
+ top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
16
+ left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
17
+ });
18
+ };
19
+ export {
20
+ getClientRect,
21
+ getScrollRect
22
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getClientRect: () => Promise<unknown>;
2
+ export declare const getScrollRect: () => Promise<unknown>;
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import Taro from "@tarojs/taro";
21
+ const getClientRect = () => {
22
+ return new Promise((resolve, reject) => {
23
+ try {
24
+ const res = Taro.getSystemInfoSync();
25
+ const width = res.windowWidth;
26
+ const height = res.windowHeight;
27
+ const clientInfo = __spreadProps(__spreadValues({}, res), {
28
+ width,
29
+ height,
30
+ left: 0,
31
+ top: 0,
32
+ right: width,
33
+ bottom: height
34
+ });
35
+ resolve(clientInfo);
36
+ } catch (error) {
37
+ reject(error);
38
+ }
39
+ });
40
+ };
41
+ const getScrollRect = () => {
42
+ return new Promise((resolve) => {
43
+ Taro.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
44
+ resolve({
45
+ top: res[0].scrollTop,
46
+ left: res[0].scrollLeft
47
+ });
48
+ });
49
+ });
50
+ };
51
+ export {
52
+ getClientRect,
53
+ getScrollRect
54
+ };
@@ -0,0 +1 @@
1
+ export declare const removeClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,24 @@
1
+ const replaceClassName = (origClass, classToRemove) => {
2
+ return origClass.replace(new RegExp(`(^|\\s)${classToRemove}(?:\\s|$)`, "g"), "$1").replace(/\s+/g, " ").replace(/^\s*|\s*$/g, "");
3
+ };
4
+ const removeClass = (element, className) => {
5
+ if (element.classList) {
6
+ element.classList.remove(className);
7
+ } else if (typeof element.className === "string") {
8
+ element.className = replaceClassName(
9
+ element.className,
10
+ className
11
+ );
12
+ } else {
13
+ element.setAttribute(
14
+ "class",
15
+ replaceClassName(
16
+ element.className && element.className.baseVal || "",
17
+ className
18
+ )
19
+ );
20
+ }
21
+ };
22
+ export {
23
+ removeClass
24
+ };
@@ -1 +1 @@
1
- export default function getBoundingClientRect(ele: Element): Promise<DOMRect>;
1
+ export default function getBoundingClientRect(ele: Element | null): Promise<DOMRect>;
@@ -1,4 +1,17 @@
1
1
  function getBoundingClientRect(ele) {
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
+ });
14
+ }
2
15
  return Promise.resolve(ele.getBoundingClientRect());
3
16
  }
4
17
  export {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * skip inital run useEffect
2
+ * skip initial run useEffect
3
3
  */
4
4
  declare const useDidMountEffect: (func: any, deps: any) => void;
5
5
  export default useDidMountEffect;
package/es/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { default as blockTouch } from './touchBlocker';
11
11
  export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
12
12
  export { default as getRootContainer } from './getRootContainer';
13
13
  export { default as getBoundingClientRect } from './getBoundingClientRect';
14
- export { getScrollRect, getClientRect } from './domUtils';
14
+ export * from './domUtils';
15
15
  export * from './isType';
16
16
  export * from './render';
17
+ export * from './themeCreator';
package/es/index.js CHANGED
@@ -36,9 +36,10 @@ import {
36
36
  } from "./transitions";
37
37
  import { default as default9 } from "./getRootContainer";
38
38
  import { default as default10 } from "./getBoundingClientRect";
39
- import { getScrollRect, getClientRect } from "./domUtils";
39
+ export * from "./domUtils";
40
40
  export * from "./isType";
41
41
  export * from "./render";
42
+ export * from "./themeCreator";
42
43
  export {
43
44
  default8 as blockTouch,
44
45
  default3 as convertHexToRGBA,
@@ -50,10 +51,8 @@ export {
50
51
  emulateTouchMove,
51
52
  emulateTouchStart,
52
53
  default10 as getBoundingClientRect,
53
- getClientRect,
54
54
  getNewDirectionLocation,
55
55
  default9 as getRootContainer,
56
- getScrollRect,
57
56
  getStylesAndLocation,
58
57
  getTransitionProps,
59
58
  isAlipay,
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): boolean;
12
- export declare function unmount(container: ContainerType): boolean | Promise<void>;
11
+ export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): any;
12
+ export declare function unmount(container: ContainerType): any;
13
13
  export {};
@@ -0,0 +1,10 @@
1
+ import { MountThemeVarsOptions, ThemeCreatorOptions } from './index.types';
2
+ /**
3
+ * 挂载自定义主题
4
+ */
5
+ declare const mountThemeVars: (options: MountThemeVarsOptions) => void;
6
+ /**
7
+ * 创建主题
8
+ */
9
+ declare const createTheme: (options: ThemeCreatorOptions) => string;
10
+ export { createTheme, mountThemeVars };
@@ -0,0 +1,37 @@
1
+ const convertToCss = (styles) => {
2
+ let result = "";
3
+ const cssVarKeys = Object.keys(styles);
4
+ cssVarKeys.forEach((key, index) => {
5
+ const value = styles[key];
6
+ if (value.includes("PX")) {
7
+ result += "/* prettier-ignore */\n ";
8
+ }
9
+ result += `${key}: ${value};
10
+ ${index === cssVarKeys.length - 1 ? "" : " "}`;
11
+ });
12
+ return result;
13
+ };
14
+ const mountThemeVars = (options) => {
15
+ const { theme = "", container } = options || {};
16
+ const style = document.createElement("style");
17
+ style.type = "text/css";
18
+ style.appendChild(document.createTextNode(theme));
19
+ if (!container) {
20
+ document.head.appendChild(style);
21
+ return;
22
+ }
23
+ container.appendChild(style);
24
+ };
25
+ const createTheme = (options) => {
26
+ const {
27
+ rootSelector = ":root, [data-color-mode='light'][data-theme]",
28
+ cssVars = {}
29
+ } = options || {};
30
+ const rootContent = `${rootSelector} {
31
+ ${convertToCss(cssVars)} }`;
32
+ return rootContent;
33
+ };
34
+ export {
35
+ createTheme,
36
+ mountThemeVars
37
+ };
@@ -0,0 +1,5 @@
1
+ import { CssVarToValueOptions } from './index.types';
2
+ /**
3
+ * css变量转值
4
+ */
5
+ export declare const cssVarToValue: (options: CssVarToValueOptions) => string | undefined;
@@ -0,0 +1,29 @@
1
+ import { defaultLight } from "@bifrostui/styles/registry";
2
+ const cssVarToValue = (options) => {
3
+ var _a;
4
+ const {
5
+ cssVar,
6
+ themeVars = (_a = defaultLight) == null ? void 0 : _a.cssVars,
7
+ _visitedKeys = /* @__PURE__ */ new Set()
8
+ } = options || {};
9
+ if (!cssVar)
10
+ return "";
11
+ const variableKey = cssVar.replace(/^var\(/, "").replace(/\)$/, "");
12
+ const variableValue = themeVars == null ? void 0 : themeVars[variableKey];
13
+ if (_visitedKeys.has(variableKey)) {
14
+ console.warn(`\u68C0\u6D4B\u5230CSS\u53D8\u91CF\u5FAA\u73AF\u5F15\u7528: ${variableKey}`);
15
+ return variableValue;
16
+ }
17
+ const nextVisited = new Set(_visitedKeys).add(variableKey);
18
+ if (variableValue && variableValue.startsWith("var(")) {
19
+ return cssVarToValue({
20
+ cssVar: variableValue,
21
+ themeVars,
22
+ _visitedKeys: nextVisited
23
+ });
24
+ }
25
+ return variableValue;
26
+ };
27
+ export {
28
+ cssVarToValue
29
+ };
@@ -0,0 +1,3 @@
1
+ export * from './createTheme';
2
+ export * from './cssVarToValue';
3
+ export * from './index.types';
@@ -0,0 +1,3 @@
1
+ export * from "./createTheme";
2
+ export * from "./cssVarToValue";
3
+ export * from "./index.types";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 挂载自定义主题选项
3
+ */
4
+ export interface MountThemeVarsOptions {
5
+ theme: string;
6
+ container?: HTMLElement;
7
+ }
8
+ export interface ThemeCreatorOptions {
9
+ /**
10
+ * 主题所挂在的根选择器
11
+ * @default `:root, [data-color-mode='light'][data-theme]`
12
+ */
13
+ rootSelector?: string;
14
+ /**
15
+ * 主题全局变量
16
+ */
17
+ cssVars: Record<string, string>;
18
+ }
19
+ /**
20
+ * css变量转值
21
+ */
22
+ export interface CssVarToValueOptions {
23
+ /**
24
+ * 当前主题
25
+ */
26
+ cssVar: string;
27
+ /**
28
+ * 当前主题模式
29
+ * @default defaultLight
30
+ */
31
+ themeVars?: Record<string, string>;
32
+ /**
33
+ * 记录已解析的变量路径
34
+ * 函数内部使用参数
35
+ */
36
+ _visitedKeys?: Set<string>;
37
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "1.5.3",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "BUI React utilities for building components.",
5
5
  "main": "dist/index.js",
6
6
  "module": "es/index.js",
@@ -16,7 +16,8 @@
16
16
  "glob": "11.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "react-is": "^18.0.0"
19
+ "react-is": "^18.0.0",
20
+ "@bifrostui/styles": "2.0.0-alpha.1"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "@tarojs/runtime": "^3.0.0",