@tsminh/spreacte 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +11 -13
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";var n=require("react/jsx-runtime"),t=require("react"),e=require("@fluejs/noscroll"),i=require("styled-components"),r=function(){return r=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},r.apply(this,arguments)};function o(n,t){return Object.defineProperty?Object.defineProperty(n,"raw",{value:t}):n.raw=t,n}"function"==typeof SuppressedError&&SuppressedError;var a,s,c,d,u=function(){document.documentElement.style.setProperty("--vw","".concat(window.innerWidth,"px")),document.documentElement.style.setProperty("--vh","".concat(window.innerHeight,"px"))},l=Object.freeze({__proto__:null,isDev:function(){return window.location.hostname.includes("localhost")},measureWindowSize:u,numberWithCommas:function(n){void 0===n&&(n=0);var t=n.toString().split(".");return t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,"."),t.join(".")}}),p=t.createContext({ratio:1,imgRootPath:""}),f=function(){return t.useContext(p)},h={mt:["marginTop"],mb:["marginBottom"],ml:["marginLeft"],mr:["marginRight"],mx:["marginLeft","marginRight"],my:["marginTop","marginBottom"],pt:["paddingTop"],pb:["paddingBottom"],pl:["paddingLeft"],pr:["paddingRight"],px:["paddingLeft","paddingRight"],py:["paddingTop","paddingBottom"]},v=new Set(["onClick","children","className","style","img","fwidth","safeAreaTop"]),m=new Set(["fwidth","safeAreaTop","img"]),g=function(n){var t=n.img,e=n.imgRootPath;return t?{backgroundImage:t.startsWith("http")?t:"url(".concat([process.env.PUBLIC_URL,e,t].filter(function(n){return!!n}).join("/"),")"),backgroundSize:"cover",backgroundRepeat:"no-repeat",backgroundPosition:"center"}:void 0},w=i.div(s||(s=o(["\n background: rgba(0, 0, 0, 0.7);\n width: var(--vw);\n height: var(--vh);\n position: fixed;\n top: 0;\n left: 0;\n z-index: 99;\n transition: 0.5s ease all;\n ","\n"],["\n background: rgba(0, 0, 0, 0.7);\n width: var(--vw);\n height: var(--vh);\n position: fixed;\n top: 0;\n left: 0;\n z-index: 99;\n transition: 0.5s ease all;\n ","\n"])),function(n){var t=n.$open;return i.css(a||(a=o(["\n opacity: ",";\n pointer-events: ",";\n "],["\n opacity: ",";\n pointer-events: ",";\n "])),t?1:0,t?"all":"none")}),x=i.div(d||(d=o(["\n width: var(--vw);\n height: var(--vh);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 100;\n transition: 0.2s ease all;\n ","\n"],["\n width: var(--vw);\n height: var(--vh);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 100;\n transition: 0.2s ease all;\n ","\n"])),function(n){var t=n.$open;return i.css(c||(c=o(["\n opacity: ",";\n pointer-events: ",";\n transform: translateY(","px) scale(",");\n "],["\n opacity: ",";\n pointer-events: ",";\n transform: translateY(","px) scale(",");\n "])),t?1:0,t?"all":"none",t?0:20,t?1:.9)});exports.Box=function(e){var i=f(),o=i.ratio,a=i.imgRootPath,s=t.useMemo(function(){var n;return r({style:r(r(r(r(r(r({},Object.fromEntries(Object.entries(e).filter(function(n){var t=n[0];return!v.has(t)&&"style"!==t}).flatMap(function(n){var t=n[0],e=n[1];return h[t]?h[t].map(function(n){return[n,e*o]}):[[t,e*o]]}))),g({img:e.img,imgRootPath:a})),e.safeAreaTop?{top:"calc(var(--ot) + ".concat((null!==(n=e.top)&&void 0!==n?n:0)*o,"px)")}:void 0),e.fwidth?{width:"var(--vw)"}:void 0),{aspectRatio:e.aspectRatio,pointerEvents:e.onClick||!e.img?"all":"none"}),e.style)},Object.fromEntries(Object.entries(e).filter(function(n){var t=n[0];return v.has(t)&&!m.has(t)}).map(function(n){return[n[0],n[1]]})))},[a,e,o]);return n.jsx("div",r({},s))},exports.GlobalContextProvider=function(e){var i=e.children,o=e.width,a=e.imgRootPath,s=void 0===a?"":a,c=function(n){var e=t.useState({width:window.innerWidth,height:window.innerHeight,ratio:window.innerWidth/n}),i=e[0],r=e[1];return t.useEffect(function(){function t(){r({width:window.screen.availWidth,height:window.screen.availHeight,ratio:window.screen.availWidth/n})}return window.addEventListener("resize",t),t(),function(){return window.removeEventListener("resize",t)}},[n]),i}(o).ratio,d=t.useMemo(function(){return{ratio:c,imgRootPath:s}},[s,c]);return t.useEffect(function(){window.addEventListener("resize",u),u()},[]),n.jsx(p.Provider,r({value:d},{children:i}))},exports.Modal=function(i){var o=i.open,a=i.children,s=t.useMemo(function(){return Math.floor(1e3*Math.random())},[]);return t.useEffect(function(){o?e.disablePageScroll():e.enablePageScroll()},[o]),n.jsxs(n.Fragment,{children:[n.jsx(w,{"data-mid":s,$open:o}),n.jsx(x,r({"data-mid":s,$open:o},{children:a}))]})},exports.useGlobalContext=f,exports.utils=l;
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as n,jsxs as t,Fragment as e}from"react/jsx-runtime";import{useState as
|
|
1
|
+
import{jsx as n,jsxs as t,Fragment as e}from"react/jsx-runtime";import{useState as i,useEffect as r,createContext as o,useMemo as a,useContext as c}from"react";import{disablePageScroll as d,enablePageScroll as s}from"@fluejs/noscroll";import p,{css as l}from"styled-components";var u=function(){return u=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},u.apply(this,arguments)};function f(n,t){return Object.defineProperty?Object.defineProperty(n,"raw",{value:t}):n.raw=t,n}"function"==typeof SuppressedError&&SuppressedError;var m,h,v,g,w=function(){document.documentElement.style.setProperty("--vw","".concat(window.innerWidth,"px")),document.documentElement.style.setProperty("--vh","".concat(window.innerHeight,"px"))},y=Object.freeze({__proto__:null,isDev:function(){return window.location.hostname.includes("localhost")},measureWindowSize:w,numberWithCommas:function(n){void 0===n&&(n=0);var t=n.toString().split(".");return t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,"."),t.join(".")}}),x=o({ratio:1,imgRootPath:""}),b=function(t){var e=t.children,o=t.width,c=t.imgRootPath,d=void 0===c?"":c,s=function(n){var t=i({width:window.innerWidth,height:window.innerHeight,ratio:window.innerWidth/n}),e=t[0],o=t[1];return r(function(){function t(){o({width:window.screen.availWidth,height:window.screen.availHeight,ratio:window.screen.availWidth/n})}return window.addEventListener("resize",t),t(),function(){return window.removeEventListener("resize",t)}},[n]),e}(o).ratio,p=a(function(){return{ratio:s,imgRootPath:d}},[d,s]);return r(function(){window.addEventListener("resize",w),w()},[]),n(x.Provider,u({value:p},{children:e}))},j=function(){return c(x)},P={mt:["marginTop"],mb:["marginBottom"],ml:["marginLeft"],mr:["marginRight"],mx:["marginLeft","marginRight"],my:["marginTop","marginBottom"],pt:["paddingTop"],pb:["paddingBottom"],pl:["paddingLeft"],pr:["paddingRight"],px:["paddingLeft","paddingRight"],py:["paddingTop","paddingBottom"]},R=new Set(["onClick","children","className","style","img","fwidth","safeAreaTop"]),z=new Set(["fwidth","safeAreaTop","img"]),E=function(n){var t=n.img,e=n.imgRootPath;return t?{backgroundImage:t.startsWith("http")?t:"url(".concat([process.env.PUBLIC_URL,e,t].filter(function(n){return!!n}).join("/"),")"),backgroundSize:"cover",backgroundRepeat:"no-repeat",backgroundPosition:"center"}:void 0},O=function(t){var e=j(),i=e.ratio,r=e.imgRootPath,o=a(function(){var n;return u({style:u(u(u(u(u(u({},Object.fromEntries(Object.entries(t).filter(function(n){var t=n[0];return!R.has(t)&&"style"!==t}).flatMap(function(n){var t=n[0],e=n[1];return P[t]?P[t].map(function(n){return[n,e*i]}):[[t,e*i]]}))),E({img:t.img,imgRootPath:r})),t.safeAreaTop?{top:"calc(var(--ot) + ".concat((null!==(n=t.top)&&void 0!==n?n:0)*i,"px)")}:void 0),t.fwidth?{width:"var(--vw)"}:void 0),{aspectRatio:t.aspectRatio,pointerEvents:t.onClick||!t.img?"all":"none"}),t.style)},Object.fromEntries(Object.entries(t).filter(function(n){var t=n[0];return R.has(t)&&!z.has(t)}).map(function(n){return[n[0],n[1]]})))},[r,t,i]);return n("div",u({},o))},L=p.div(h||(h=f(["\n background: rgba(0, 0, 0, 0.7);\n width: var(--vw);\n height: var(--vh);\n position: fixed;\n top: 0;\n left: 0;\n z-index: 99;\n transition: 0.5s ease all;\n ","\n"],["\n background: rgba(0, 0, 0, 0.7);\n width: var(--vw);\n height: var(--vh);\n position: fixed;\n top: 0;\n left: 0;\n z-index: 99;\n transition: 0.5s ease all;\n ","\n"])),function(n){var t=n.$open;return l(m||(m=f(["\n opacity: ",";\n pointer-events: ",";\n "],["\n opacity: ",";\n pointer-events: ",";\n "])),t?1:0,t?"all":"none")}),k=p.div(g||(g=f(["\n width: var(--vw);\n height: var(--vh);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 100;\n transition: 0.2s ease all;\n ","\n"],["\n width: var(--vw);\n height: var(--vh);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 100;\n transition: 0.2s ease all;\n ","\n"])),function(n){var t=n.$open;return l(v||(v=f(["\n opacity: ",";\n pointer-events: ",";\n transform: translateY(","px) scale(",");\n "],["\n opacity: ",";\n pointer-events: ",";\n transform: translateY(","px) scale(",");\n "])),t?1:0,t?"all":"none",t?0:20,t?1:.9)}),W=function(i){var o=i.open,c=i.children,p=a(function(){return Math.floor(1e3*Math.random())},[]);return r(function(){o?d():s()},[o]),t(e,{children:[n(L,{"data-mid":p,$open:o}),n(k,u({"data-mid":p,$open:o},{children:c}))]})};export{O as Box,b as GlobalContextProvider,W as Modal,j as useGlobalContext,y as utils};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { ReactNode, CSSProperties } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
children?: ReactNode;
|
|
6
|
-
style?: CSSProperties;
|
|
3
|
+
type SpacingKey = "mt" | "mb" | "ml" | "mr" | "pt" | "pb" | "pl" | "pr" | "px" | "py" | "mx" | "my";
|
|
4
|
+
type StyleNumberProps = {
|
|
7
5
|
width?: number;
|
|
8
6
|
height?: number;
|
|
9
|
-
mt?: number;
|
|
10
|
-
mb?: number;
|
|
11
|
-
ml?: number;
|
|
12
|
-
mr?: number;
|
|
13
|
-
pt?: number;
|
|
14
|
-
pb?: number;
|
|
15
|
-
pl?: number;
|
|
16
|
-
pr?: number;
|
|
17
7
|
top?: number;
|
|
18
8
|
left?: number;
|
|
19
9
|
right?: number;
|
|
20
10
|
bottom?: number;
|
|
21
11
|
fontSize?: number;
|
|
22
|
-
img?: string;
|
|
23
12
|
aspectRatio?: number;
|
|
13
|
+
borderRadius?: number;
|
|
14
|
+
} & Partial<Record<SpacingKey, number>>;
|
|
15
|
+
interface BoxProps extends StyleNumberProps {
|
|
16
|
+
onClick?: () => void;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
style?: CSSProperties;
|
|
24
19
|
className?: string;
|
|
20
|
+
img?: string;
|
|
25
21
|
fwidth?: boolean;
|
|
26
22
|
safeAreaTop?: boolean;
|
|
27
23
|
}
|
|
@@ -53,9 +49,11 @@ declare namespace utils {
|
|
|
53
49
|
declare const GlobalContextProvider: React.FC<{
|
|
54
50
|
children: ReactNode;
|
|
55
51
|
width: number;
|
|
52
|
+
imgRootPath?: string;
|
|
56
53
|
}>;
|
|
57
54
|
declare const useGlobalContext: () => {
|
|
58
55
|
ratio: number;
|
|
56
|
+
imgRootPath: string;
|
|
59
57
|
};
|
|
60
58
|
|
|
61
59
|
export { Box, GlobalContextProvider, Modal, useGlobalContext, utils };
|