UNPKG

@prop-styles/core

Version:

The library provides a static method createPropStyles to create Style objects.

18 lines (17 loc) 3.17 kB
/*! * @prop-styles/core version 1.0.0-beta * Author: Capricorncd<capricorncd@qq.com> * Homepage: https://github.com/capricorncd/prop-styles#readme * Released on: 2025-05-11 14:01:37 (GMT+0000) */ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o["prop-styles-core"]={}))})(this,function(o){"use strict";/*! * @zx-libs/utils version 0.0.5 * Author: Capricorncd<capricorncd@qq.com> * Homepage: https://github.com/capricorncd/zx-libs/libs/utils#readme * Released on: 2024-04-30 20:19:27 (GMT+0900) *//*! * date-utils-2020 v1.1.1 * Author: Capricorncd * Repository: https://github.com/capricorncd/date-utils-2020#readme * Released on: 2024/04/02 21:28:40 GMT+0900 */function s(t){return typeof t=="string"?/^-?\d+(\.\d+)?$/.test(t):p(t)}function p(t){return Number.isFinite(t)}const g=/^((-?\d+(\.\d+)?)?([a-z]+|%)?\s*)+$/i,c=/(\d+\s|\s-?\d+(\.\d+)?$)/;function a(t,i="px"){if(s(t))return`${t}${i}`;if(t&&typeof t=="string"){const e=t.trim().replace(/\s{2,}/g," ");return g.test(e)&&c.test(e)?e.trim().split(" ").map(r=>a(r,i)).join(" "):e}return""}const m=/^(#[a-f0-9]{3,8}|(rgba?|hsla?|hwb|lab|lch|oklab|oklch|hwb|lch|light-dark)\(.+\))$/i;function u(t){return typeof t!="string"?!1:m.test(t)}const n=(t,i,e)=>!i&&i!==0?null:{key:t,value:e??String(i)},h=(t,i)=>{const e={};let r;for(const l of Object.keys(t)){if(r=i[l],!r)continue;const f=r(t[l],t);if(f)if(Array.isArray(f))f.forEach(d=>{d&&(e[d.key]=d.value)});else{const{key:d,value:P}=f;e[d]=P}}return e},b=/^-?\d+(\.\d+)?[a-z]+$/i,y=t=>typeof t=="string"&&b.test(t),x=t=>s(t)||y(t)?{key:"borderWidth",value:a(t)}:u(t)?{key:"borderColor",value:t}:n("border",t),S={display:"display",width:"width",minWidth:"minWidth",maxWidth:"maxWidth",height:"height",minHeight:"minHeight",maxHeight:"maxHeight",flex:"flex",gap:"gap",fd:"flexDirection",ai:"alignItems",ac:"alignContent",ji:"justifyItems",jc:"justifyContent",ws:"whiteSpace",p:"padding",pt:"paddingTop",pr:"paddingRight",pb:"paddingBottom",pl:"paddingLeft",px:"paddingInline",py:"paddingBlock",m:"margin",mt:"marginTop",mr:"marginRight",mb:"marginBottom",ml:"marginLeft",mx:"marginInline",my:"marginBlock",radius:"borderRadius",fs:"fontSize",lh:"lineHeight",color:"color",bg:"background",fw:"fontWeight",border:"border",gtc:"gridTemplateColumns",gtr:"gridTemplateRows",ta:"textAlign",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",zIndex:"zIndex",inset:"inset",transform:"transform"},k={column:t=>n("flexDirection",t,"column"),wrap:t=>n("flexWrap",t,t===!0?"wrap":String(t)),breakWord:t=>n("overflowWrap",t,"break-word"),scroll:t=>n(`overflow${typeof t=="string"?t.toUpperCase():""}`,t,"auto")},w={...Object.entries(S).reduce((t,[i,e])=>(t[i]=r=>n(e,r,a(r)),t),{}),...k,flex:t=>n("flex",t),border:x,fw:t=>n("fontWeight",t,String(t)),gtc:t=>n("gridTemplateColumns",t,a(t,"fr")),gtr:t=>n("gridTemplateRows",t,a(t,"fr")),zIndex:t=>n("zIndex",t,String(t))},C=(t,i)=>{const e={...w,...i};return h(t,e)};o.createPropStyles=C,o.transform=n,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});