UNPKG

xuxi

Version:

Dynamically utility for combining different types of values ​​into a single value.

2 lines (1 loc) 4.49 kB
"use strict";(function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s.Xuxi={}))})(this,function(s){"use strict";function a(r){let t=0,i,e="";if(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r===null)e+=r;else if(typeof r=="object")if(Array.isArray(r))for(;t<r.length;t++)r[t]&&(i=a(r[t]))&&(e&&(e+=" "),e+=i);else for(i in r)r[i]&&(e&&(e+=" "),e+=i);else typeof r=="function"&&(e+=a(r(e)));return e}function h(r,t=" "){let i=0,e,n="";if(typeof r=="object"&&r!==null)if(Array.isArray(r))for(;i<r.length;i++)r[i]&&(e=h(r[i],t))&&(n&&(n+=t),n+=e);else{for(e in r)r[e]&&(n&&(n+=t),n+=typeof r[e]=="object"?`${e}.${h(r[e],`${t}${e}.`)}`:`${e}: ${r[e]}`);for(const f of Object.getOwnPropertySymbols(r))r[f]&&(n&&(n+=t),n+=`${String(f)}: ${r[f]}`)}return n}function j(r,t=" "){let i=0,e,n="";if(r instanceof Date)n+=r.toISOString();else if(r instanceof Map)for(const[f,o]of r.entries())o&&(n&&(n+=t),n+=`${f}: ${o}`);else if(r instanceof Set)r.forEach(f=>{f&&(n&&(n+=t),n+=f)});else if(typeof r=="object"){if(Array.isArray(r))for(;i<r.length;i++)r[i]&&(e=j(r[i],t))&&(n&&(n+=t),n+=e)}else typeof r=="function"&&(n+=j(r(n),t));return n}function y(...r){let t="";for(let i=0;i<r.length;i++){const e=r[i],n=e&&a(e);n&&(t&&(t+=" "),t+=n)}return t}function O(...r){return{toString(){return y(...r)},recursive(t={}){return h(r,t.separator)},instanceof(t={}){return j(r,t.separator)},[Symbol.toPrimitive](){return y(...r)}}}function p(r){return(t={})=>{const i={...r.defaultVariants,...t},e=Object.keys(r.variants).map(n=>{const f=i[n],o=String(f),l=r.variants[n],u=o in l?o:f;return u?l[u]:void 0});return y(r.assign,e)}}function c(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}function m(...r){const t=new WeakMap;function i(e,n){if(!n)return e;if(c(n)){if(t.has(n))return t.get(n);const f={...e};t.set(n,f),e=f}if(Array.isArray(n))return{...e,...m(...n)};if(typeof n=="function"){const f=n(e);return c(f)?i(e,f):{...e,...m(f)}}return c(n)&&Reflect.ownKeys(n).forEach(f=>{const o=n[f];c(o)&&c(e[f])?e[f]=i(e[f],o):e[f]=o}),e}return r.reduce((e,n)=>i(e,n),{})}function A(...r){const t=new WeakMap;function i(e,n){if(!n)return e;if(c(n)){if(t.has(n))return t.get(n);const f={...e};t.set(n,f),e=f}if(Array.isArray(n))return{...e,...A(...n)};if(typeof n=="function"){const f=n(e);return c(f)?i(e,f):{...e,...A(f)}}return c(n)&&Reflect.ownKeys(n).forEach(f=>{const o=n[f];e[f]===void 0?e[f]=o:c(o)&&c(e[f])&&(e[f]=i(e[f],o))}),e}return r.reduce((e,n)=>i(e,n),{})}function d(r,t=[],i=new WeakSet){const e=new Set(t);return i.has(r)?r:(i.add(r),Reflect.ownKeys(r).reduce((n,f)=>{const o=r[f];if(c(o)){const l=d(o,t,i);(Object.keys(l).length>0||typeof f=="symbol")&&(n[f]=l)}else if(Array.isArray(o)){const l=o.map(u=>c(u)?d(u,t,i):u).filter(u=>u&&!(c(u)&&Object.keys(u).length===0)||e.has(u));l.length>0&&(n[f]=l)}else(o||e.has(o)||typeof f=="symbol")&&(n[f]=o);return n},{}))}const b=(...r)=>d(m(...r),[0]);b.raw=m,b.preserve=A;function N(...r){return d(m(...r),[0])}const S=g("rem",{shouldScale:!0}),w=g("em");function x(r){const t=P(r);if(typeof t=="number")return t;if(typeof t=="string"){if(t.includes("calc")||t.includes("var"))return t;const i={px:1,rem:16,em:16},e=Object.keys(i).find(f=>t.includes(f));if(e)return parseFloat(t.replace(e,""))*i[e];const n=Number(t);return isNaN(n)?NaN:n}return NaN}function g(r,{shouldScale:t=!1}={}){function i(e){if(e===0||e==="0")return`0${r}`;if(typeof e=="number"){const n=`${e/16}${r}`;return t?$(n):n}if(typeof e=="string"){if(e===""||e.startsWith("calc(")||e.startsWith("clamp(")||e.includes("rgba("))return e;if(e.includes(","))return e.split(",").map(f=>i(f)).join(",");if(e.includes(" "))return e.split(" ").map(f=>i(f)).join(" ");if(e.includes(r))return t?$(e):e;const n=e.replace("px","");if(!Number.isNaN(Number(n))){const f=`${Number(n)/16}${r}`;return t?$(f):f}}return e}return i}function $(r){return r==="0rem"?"0rem":r}function P(r){var t;return typeof r!="string"||!/var\(--.*?scale\)/.test(r)?r:(t=r.match(/^calc\((.*?)\)$/))===null||t===void 0?void 0:t[1].split("*")[0].trim()}var _=Object.freeze({__proto__:null,clean:d,cnx:y,createConverter:g,cvx:p,em:w,isPlainObject:c,object:b,ocx:N,px:x,rem:S,string:O});s.clean=d,s.cnx=y,s.createConverter=g,s.cvx=p,s.default=_,s.em=w,s.isPlainObject=c,s.object=b,s.ocx=N,s.px=x,s.rem=S,s.string=O,s.x=_,Object.defineProperty(s,"__esModule",{value:!0})});