@bifrostui/utils 1.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ declare const getRootElement: (rootEle?: HTMLElement | (() => HTMLElement)) => HTMLElement;
2
+ export default getRootElement;
@@ -0,0 +1,28 @@
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 getRootElement_exports = {};
19
+ __export(getRootElement_exports, {
20
+ default: () => getRootElement_default
21
+ });
22
+ module.exports = __toCommonJS(getRootElement_exports);
23
+ const getRootElement = (rootEle) => {
24
+ const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
25
+ const defaultRootElement = document.body;
26
+ return rootElement || defaultRootElement;
27
+ };
28
+ var getRootElement_default = getRootElement;
@@ -0,0 +1,3 @@
1
+ import type { TaroElement } from '@tarojs/runtime';
2
+ declare const getRootElement: (rootEle?: TaroElement | (() => TaroElement)) => HTMLElement | TaroElement;
3
+ export default getRootElement;
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var index_miniapp_exports = {};
29
+ __export(index_miniapp_exports, {
30
+ default: () => index_miniapp_default
31
+ });
32
+ module.exports = __toCommonJS(index_miniapp_exports);
33
+ var import_taro = __toESM(require("@tarojs/taro"));
34
+ const getRootElement = (rootEle) => {
35
+ const currentPages = import_taro.default.getCurrentPages() || [];
36
+ const currentPage = currentPages[currentPages.length - 1];
37
+ const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
38
+ const defaultRootElement = document.getElementById(pageElement);
39
+ const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
40
+ return rootElement || defaultRootElement;
41
+ };
42
+ var index_miniapp_default = getRootElement;
package/dist/index.d.ts CHANGED
@@ -8,5 +8,7 @@ export { default as throttle } from './throttle';
8
8
  export { default as toArray } from './toArray';
9
9
  export { default as blockTouch } from './touchBlocker';
10
10
  export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
11
+ export { default as getRootElement } from './getRootElement';
11
12
  export { default as getBoundingClientRect } from './getBoundingClientRect';
12
13
  export * from './isType';
14
+ export * from './render';
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
35
35
  duration: () => import_transitions.duration,
36
36
  easing: () => import_transitions.easing,
37
37
  getBoundingClientRect: () => import_getBoundingClientRect.default,
38
+ getRootElement: () => import_getRootElement.default,
38
39
  getTransitionProps: () => import_transitions.getTransitionProps,
39
40
  isAlipay: () => import_isMini.isAlipay,
40
41
  isDev: () => import_isDev.default,
@@ -65,8 +66,10 @@ var import_throttle = __toESM(require("./throttle"));
65
66
  var import_toArray = __toESM(require("./toArray"));
66
67
  var import_touchBlocker = __toESM(require("./touchBlocker"));
67
68
  var import_transitions = require("./transitions");
69
+ var import_getRootElement = __toESM(require("./getRootElement"));
68
70
  var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
69
71
  __reExport(src_exports, require("./isType"), module.exports);
72
+ __reExport(src_exports, require("./render"), module.exports);
70
73
  // Annotate the CommonJS export names for ESM import in node:
71
74
  0 && (module.exports = {
72
75
  blockTouch,
@@ -76,6 +79,7 @@ __reExport(src_exports, require("./isType"), module.exports);
76
79
  duration,
77
80
  easing,
78
81
  getBoundingClientRect,
82
+ getRootElement,
79
83
  getTransitionProps,
80
84
  isAlipay,
81
85
  isDev,
@@ -94,5 +98,6 @@ __reExport(src_exports, require("./isType"), module.exports);
94
98
  useTouch,
95
99
  useTouchEmulator,
96
100
  useValue,
97
- ...require("./isType")
101
+ ...require("./isType"),
102
+ ...require("./render")
98
103
  });
@@ -0,0 +1,13 @@
1
+ import { ReactElement } from 'react';
2
+ import type { Root } from 'react-dom/client';
3
+ declare const MARK = "__bifrostui_react_root__";
4
+ type ContainerType = (Element | DocumentFragment) & {
5
+ [MARK]?: Root;
6
+ };
7
+ /** @private Test usage. Not work in prod */
8
+ export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
9
+ export declare function render(node: ReactElement, container: ContainerType): void;
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>;
13
+ export {};
package/dist/render.js ADDED
@@ -0,0 +1,138 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+ var render_exports = {};
63
+ __export(render_exports, {
64
+ render: () => render,
65
+ testLegacyUnmount: () => testLegacyUnmount,
66
+ testModernRender: () => testModernRender,
67
+ unmount: () => unmount
68
+ });
69
+ module.exports = __toCommonJS(render_exports);
70
+ var ReactDOM = __toESM(require("react-dom"));
71
+ const MARK = "__bifrostui_react_root__";
72
+ const fullClone = __spreadValues({}, ReactDOM);
73
+ const { version, render: reactRender, unmountComponentAtNode } = fullClone;
74
+ let createRoot;
75
+ try {
76
+ if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
77
+ createRoot = fullClone.createRoot;
78
+ }
79
+ } catch (e) {
80
+ }
81
+ function toggleWarning(skip) {
82
+ const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone;
83
+ if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === "object") {
84
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
85
+ }
86
+ }
87
+ function testModernRender(node, container, isTest) {
88
+ if (process.env.NODE_ENV !== "production" && isTest) {
89
+ return legacyRender(node, container);
90
+ }
91
+ }
92
+ function modernRender(node, container) {
93
+ toggleWarning(true);
94
+ const root = container[MARK] || createRoot(container);
95
+ toggleWarning(false);
96
+ root.render(node);
97
+ container[MARK] = root;
98
+ }
99
+ function legacyRender(node, container) {
100
+ reactRender(node, container);
101
+ }
102
+ function render(node, container) {
103
+ if (createRoot) {
104
+ modernRender(node, container);
105
+ return;
106
+ }
107
+ legacyRender(node, container);
108
+ }
109
+ function testLegacyUnmount(container, isTest) {
110
+ if (process.env.NODE_ENV !== "production" && isTest) {
111
+ return legacyUnmount(container);
112
+ }
113
+ }
114
+ function modernUnmount(container) {
115
+ return __async(this, null, function* () {
116
+ return Promise.resolve().then(() => {
117
+ var _a;
118
+ (_a = container[MARK]) == null ? void 0 : _a.unmount();
119
+ delete container[MARK];
120
+ });
121
+ });
122
+ }
123
+ function legacyUnmount(container) {
124
+ return unmountComponentAtNode(container);
125
+ }
126
+ function unmount(container) {
127
+ if (createRoot) {
128
+ return modernUnmount(container);
129
+ }
130
+ return legacyUnmount(container);
131
+ }
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ render,
135
+ testLegacyUnmount,
136
+ testModernRender,
137
+ unmount
138
+ });
@@ -0,0 +1,2 @@
1
+ declare const getRootElement: (rootEle?: HTMLElement | (() => HTMLElement)) => HTMLElement;
2
+ export default getRootElement;
@@ -0,0 +1,9 @@
1
+ const getRootElement = (rootEle) => {
2
+ const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
3
+ const defaultRootElement = document.body;
4
+ return rootElement || defaultRootElement;
5
+ };
6
+ var getRootElement_default = getRootElement;
7
+ export {
8
+ getRootElement_default as default
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { TaroElement } from '@tarojs/runtime';
2
+ declare const getRootElement: (rootEle?: TaroElement | (() => TaroElement)) => HTMLElement | TaroElement;
3
+ export default getRootElement;
@@ -0,0 +1,13 @@
1
+ import Taro from "@tarojs/taro";
2
+ const getRootElement = (rootEle) => {
3
+ const currentPages = Taro.getCurrentPages() || [];
4
+ const currentPage = currentPages[currentPages.length - 1];
5
+ const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
6
+ const defaultRootElement = document.getElementById(pageElement);
7
+ const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
8
+ return rootElement || defaultRootElement;
9
+ };
10
+ var index_miniapp_default = getRootElement;
11
+ export {
12
+ index_miniapp_default as default
13
+ };
package/es/index.d.ts CHANGED
@@ -8,5 +8,7 @@ export { default as throttle } from './throttle';
8
8
  export { default as toArray } from './toArray';
9
9
  export { default as blockTouch } from './touchBlocker';
10
10
  export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
11
+ export { default as getRootElement } from './getRootElement';
11
12
  export { default as getBoundingClientRect } from './getBoundingClientRect';
12
13
  export * from './isType';
14
+ export * from './render';
package/es/index.js CHANGED
@@ -23,8 +23,10 @@ import {
23
23
  getTransitionProps,
24
24
  createTransitions
25
25
  } from "./transitions";
26
- import { default as default9 } from "./getBoundingClientRect";
26
+ import { default as default9 } from "./getRootElement";
27
+ import { default as default10 } from "./getBoundingClientRect";
27
28
  export * from "./isType";
29
+ export * from "./render";
28
30
  export {
29
31
  default8 as blockTouch,
30
32
  default3 as convertHexToRGBA,
@@ -32,7 +34,8 @@ export {
32
34
  default2 as debounce,
33
35
  duration,
34
36
  easing,
35
- default9 as getBoundingClientRect,
37
+ default10 as getBoundingClientRect,
38
+ default9 as getRootElement,
36
39
  getTransitionProps,
37
40
  isAlipay,
38
41
  default4 as isDev,
package/es/render.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ReactElement } from 'react';
2
+ import type { Root } from 'react-dom/client';
3
+ declare const MARK = "__bifrostui_react_root__";
4
+ type ContainerType = (Element | DocumentFragment) & {
5
+ [MARK]?: Root;
6
+ };
7
+ /** @private Test usage. Not work in prod */
8
+ export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
9
+ export declare function render(node: ReactElement, container: ContainerType): void;
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>;
13
+ export {};
package/es/render.js ADDED
@@ -0,0 +1,104 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
37
+ import * as ReactDOM from "react-dom";
38
+ const MARK = "__bifrostui_react_root__";
39
+ const fullClone = __spreadValues({}, ReactDOM);
40
+ const { version, render: reactRender, unmountComponentAtNode } = fullClone;
41
+ let createRoot;
42
+ try {
43
+ if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
44
+ createRoot = fullClone.createRoot;
45
+ }
46
+ } catch (e) {
47
+ }
48
+ function toggleWarning(skip) {
49
+ const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone;
50
+ if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === "object") {
51
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
52
+ }
53
+ }
54
+ function testModernRender(node, container, isTest) {
55
+ if (process.env.NODE_ENV !== "production" && isTest) {
56
+ return legacyRender(node, container);
57
+ }
58
+ }
59
+ function modernRender(node, container) {
60
+ toggleWarning(true);
61
+ const root = container[MARK] || createRoot(container);
62
+ toggleWarning(false);
63
+ root.render(node);
64
+ container[MARK] = root;
65
+ }
66
+ function legacyRender(node, container) {
67
+ reactRender(node, container);
68
+ }
69
+ function render(node, container) {
70
+ if (createRoot) {
71
+ modernRender(node, container);
72
+ return;
73
+ }
74
+ legacyRender(node, container);
75
+ }
76
+ function testLegacyUnmount(container, isTest) {
77
+ if (process.env.NODE_ENV !== "production" && isTest) {
78
+ return legacyUnmount(container);
79
+ }
80
+ }
81
+ function modernUnmount(container) {
82
+ return __async(this, null, function* () {
83
+ return Promise.resolve().then(() => {
84
+ var _a;
85
+ (_a = container[MARK]) == null ? void 0 : _a.unmount();
86
+ delete container[MARK];
87
+ });
88
+ });
89
+ }
90
+ function legacyUnmount(container) {
91
+ return unmountComponentAtNode(container);
92
+ }
93
+ function unmount(container) {
94
+ if (createRoot) {
95
+ return modernUnmount(container);
96
+ }
97
+ return legacyUnmount(container);
98
+ }
99
+ export {
100
+ render,
101
+ testLegacyUnmount,
102
+ testModernRender,
103
+ unmount
104
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "description": "BUI React utilities for building components.",
5
5
  "main": "dist/index.js",
6
6
  "module": "es/index.js",
@@ -21,7 +21,8 @@
21
21
  "peerDependencies": {
22
22
  "@tarojs/runtime": "^3.0.0",
23
23
  "@tarojs/taro": "^3.0.0",
24
- "react": "^17.0.0 || ^18.0.0"
24
+ "react": "^17.0.0 || ^18.0.0",
25
+ "react-dom": "^17.0.0 || ^18.0.0"
25
26
  },
26
27
  "license": "MIT",
27
28
  "publishConfig": {