@takumi-rs/helpers 0.15.0 → 0.15.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.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function Z(t){return{type:"container",...t}}function q(t,f){return{...f,type:"text",text:t}}function Q(t,f){return{...f,type:"image",src:t}}function Nt(t){return t}function H(t){return{percentage:t}}function p(t){return{vw:t}}function B(t){return{vh:t}}function Y(t){return{em:t}}function _(t){return{rem:t}}function K(t){return{fr:t}}function Et(t,f,n=0){return{from:t,to:f,angle:n}}function z(t){return t.replace(/[A-Z]/g,(f)=>`_${f.toLowerCase()}`)}var P=["-moz-","-webkit-","-o-","-ms-"];function M(t){if(typeof t!=="string")return t;if(l(t))return;if(t[0]==="-"){for(let f of P)if(t.startsWith(f))return t.slice(f.length);throw new Error(`Unsupported prefix in value: ${t}`)}return t}function l(t){return t==="inherit"||t==="initial"||t==="revert"||t==="unset"}function c(t){if(t.length===7)return Number.parseInt(t.slice(1),16);if(t.length===9){let f=Number.parseInt(t.slice(1),16);return[f>>24&255,f>>16&255,f>>8&255,(f&255)/255]}throw new Error(`Invalid hex color: ${t}`)}function e(t){let f=t.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);if(f){let[,n,m,y]=f;return[Number(n),Number(m),Number(y)]}return null}function v(t){let f=t.match(/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/);if(f){let[,n,m,y,h]=f,x=Number(n),T=Number(m),d=Number(y),w=Number(h);if(x<0||x>255||T<0||T>255||d<0||d>255)return null;if(w<0||w>1)return null;return[x,T,d,w]}return null}function C(t){if(t.startsWith("#"))return c(t);if(t.startsWith("rgb(")){let f=e(t);if(f!==null)return f}if(t.startsWith("rgba(")){let f=v(t);if(f!==null)return f}throw new Error(`Invalid RGB color: ${t}`)}function i(t){if(typeof t==="number")return t;if(t==="auto"||t==="min-content"||t==="max-content")return t;let f=t.match(/^(-?[\d.]+)(.*)$/);if(!f)return 0;let[,n,m]=f;if(!n)return 0;let y=Number.parseFloat(n);switch(m){case"%":return H(y);case"rem":return _(y);case"em":return Y(y);case"vh":return B(y);case"vw":return p(y);case"px":case"":return y;default:return y}}function D(t){if(typeof t==="number")return i(t);let n=t.trim().split(/\s+/).map(i);if(n.length===1)return n[0];if(n.length===2||n.length===4)return n;if(n.length===3&&n[0]!==void 0&&n[1]!==void 0&&n[2]!==void 0)return[n[0],n[1],n[2],n[1]];throw new Error(`Invalid sides value: ${t}. Expected 1 to at most 4 values.`)}function R(t){if(typeof t==="number")return t;if(typeof t==="string"&&t.includes("/")){let[f,n]=t.split("/").map(Number.parseFloat);if(f===void 0||n===void 0)throw new Error(`Invalid aspect ratio: ${t}. Expected format 'width/height'.`);if(n===0)throw new Error(`Invalid aspect ratio: ${t}. Denominator cannot be zero.`);return f/n}if(typeof t==="string")return Number.parseFloat(t);throw new Error(`Invalid aspect ratio: ${t}`)}function o(t){switch(t){case"block":case"flex":case"grid":case"none":return t;default:return console.warn(`Invalid display value: ${t}, fallback to 'block'.`),"block"}}function F(t){switch(t){case"relative":case"absolute":return t;case"static":return"relative";default:return console.warn(`Invalid position value: ${t}, fallback to 'relative'.`),"relative"}}function O(t){let f=t.trim().split(/\s+/);if(f.length<2)throw new Error(`Invalid box-shadow: ${t}`);let n=!1,m="black",y=0;if(f[0]==="inset")n=!0,y=1;let h=/^(#|rgb|rgba|hsl|hsla|[a-zA-Z]+)/,x=[];for(let A=y;A<f.length;A++){let j=f[A]??"";if(A===f.length-1&&h.test(j))m=j;else x.push(j)}if(x.length<2||x.length>4)throw new Error(`Invalid box-shadow format: ${t}`);let[T="0px",d="0px",w="0px",$="0px"]=x;try{return{color:C(m),offset_x:i(T)??0,offset_y:i(d)??0,blur_radius:i(w)??0,spread_radius:i($)??0,inset:n}}catch{throw new Error(`Invalid box-shadow color: ${m}`)}}function s(t){return t.trim().split(/\s+/).map((n)=>{if(n.endsWith("fr")){let m=Number.parseFloat(n.slice(0,-2));if(Number.isNaN(m))return{fr:0};return{fr:m}}return i(n)??0})}function S(t){switch(t){case"row":case"column":case"row dense":case"column dense":return t.replace(" ","-");default:return console.warn(`Invalid grid-auto-flow value: ${t}, fallback to 'row'.`),"row"}}function V(t){if(t.startsWith("span ")){let n=Number.parseInt(t.slice(5));if(Number.isNaN(n))throw new Error(`Invalid span value: ${t}`);return{start:n,end:null}}if(t.includes("/")){let n=t.split("/");if(n.length!==2)throw new Error(`Invalid grid line format: ${t}`);let[m="",y=""]=n.map((T)=>T.trim()),h=m==="auto"?null:Number.parseInt(m)||m,x=y==="auto"?null:Number.parseInt(y)||y;return{start:h,end:x}}if(t==="auto")return{start:null,end:null};let f=Number.parseInt(t);if(Number.isNaN(f))return{start:t,end:null};return{start:f,end:null}}function W(t){let f=t.match(/repeat\(([^,]+),\s*(.+)\)/);if(f){let n=a(f);if(!n)throw new Error(`Invalid repeat function: ${t}`);return n}return u(t)}function a(t){let[,f,n]=t;if(!f||!n)return;let m;if(f==="auto-fill")m="auto-fill";else if(f==="auto-fit")m="auto-fit";else{let h=Number.parseInt(f);if(Number.isNaN(h))return;m=h}let y=n.trim().split(/\s+/).map((h)=>{if(h.endsWith("fr")){let x=Number.parseFloat(h.slice(0,-2));return Number.isNaN(x)?0:{fr:x}}return i(h)??0});return[{repeat:[m,y]}]}function u(t){return t.trim().split(/\s+/).map((n)=>{if(n.endsWith("fr")){let m=Number.parseFloat(n.slice(0,-2));return{single:Number.isNaN(m)?0:{fr:m}}}return{single:i(n)??0}})}function I(t){if(typeof t==="number")return Math.max(1,Math.min(1000,t));if(typeof t==="string")switch(t){case"normal":return 400;case"bold":return 700;case"lighter":return 300;case"bolder":return 600;default:{let f=Number.parseInt(t);if(!Number.isNaN(f))return Math.max(1,Math.min(1000,f))}}return console.warn(`Invalid font-weight value: ${t}, fallback to 400.`),400}function G(t){if(typeof t==="string")return s(t);if(Array.isArray(t))return t;return typeof t==="number"?[t]:[K(1)]}function k(t){if(typeof t==="string")return V(t);if(typeof t==="number")return{start:t,end:null};return t}function U(t){if(typeof t==="string")return W(t);if(Array.isArray(t))return t;return typeof t==="number"?[{single:t}]:[{single:0}]}function g(t){if(typeof t==="string")return W(t);if(Array.isArray(t))return t;return typeof t==="number"?[{single:t}]:[{single:0}]}function r(t){if(t==="none")return 0;return Number(t)}var N=Symbol("skip-parsing"),tt={display:o,position:F,width:i,height:i,maxWidth:i,maxHeight:i,minWidth:i,minHeight:i,aspectRatio:R,padding:D,margin:D,flexDirection:N,flexWrap:N,justifyContent:(t)=>t,alignContent:(t)=>t,justifySelf:(t)=>t,alignItems:(t)=>t,alignSelf:(t)=>t,justifyItems:(t)=>t,flexBasis:i,gap:i,flexGrow:(t)=>Number(t),flexShrink:(t)=>Number(t),borderWidth:D,backgroundColor:C,boxShadow:O,objectFit:N,gridAutoColumns:G,gridAutoRows:G,gridAutoFlow:S,gridColumn:k,gridRow:k,gridTemplateColumns:U,gridTemplateRows:g,textOverflow:(t)=>t,borderColor:C,color:C,fontSize:i,fontFamily:N,lineHeight:i,fontWeight:I,lineClamp:r,borderRadius:(t)=>D(t),textAlign(t){if(t==="match-parent")return void console.warn("Unsupported value for text-align found:",t);return t},letterSpacing:i,inset:(t)=>D(t)},ft=new Set(["top","right","bottom","left","marginTop","marginRight","marginBottom","marginLeft","paddingTop","paddingRight","paddingBottom","paddingLeft"]);function nt(t,f,n){if(ft.has(f))return;let m=M(n);if(m===void 0||m===null)return;let y=tt[f];if(!y){console.warn(`No parser found for CSS property: ${f}`);return}let h=z(f);if(y===N){t[h]=m;return}try{let x=y(m);if(x!=null&&x!==void 0)t[h]=x}catch(x){console.warn(`Failed to parse ${f}:`,x)}}function mt(t){let f=D(t);if(typeof f==="number")return{top:f,right:f,bottom:f,left:f};if(Array.isArray(f)){if(f.length===2)return{top:f[0],right:f[1],bottom:f[0],left:f[1]};if(f.length===4)return{top:f[0],right:f[1],bottom:f[2],left:f[3]}}return{top:0,right:0,bottom:0,left:0}}function yt(t,f,n,m,y,h){let x=t[n]!==void 0||t[m]!==void 0||t[y]!==void 0||t[h]!==void 0;return t[f]!==void 0&&!x}function xt(t,f){let n=t[f];if(n!==void 0&&typeof n!=="object")return mt(n);return{top:0,right:0,bottom:0,left:0}}function J(t,f){let n=t[f];if(n!==void 0&&typeof n!=="object")return i(n);return 0}function b(t,f,n,m,y,h){if(t[f]===void 0&&t[n]===void 0&&t[m]===void 0&&t[y]===void 0&&t[h]===void 0)return;if(yt(t,f,n,m,y,h)){let A=t[f];if(A!==void 0)return D(A)}let x=xt(t,f),T=x.top,d=x.right,w=x.bottom,$=x.left;if(t[n]!==void 0)T=J(t,n);if(t[m]!==void 0)d=J(t,m);if(t[y]!==void 0)w=J(t,y);if(t[h]!==void 0)$=J(t,h);if(T===d&&d===w&&w===$)return T;return[T,d,w,$]}function ht(t){return b(t,"padding","paddingTop","paddingRight","paddingBottom","paddingLeft")}function it(t){return b(t,"margin","marginTop","marginRight","marginBottom","marginLeft")}function Tt(t){return b(t,"inset","top","right","bottom","left")}function X(t){if(!t)return;let f={};for(let[h,x]of Object.entries(t))nt(f,h,x);let n=Tt(t);if(n!==void 0)f.inset=n;let m=ht(t);if(m!==void 0)f.padding=m;let y=it(t);if(y!==void 0)f.margin=y;return Object.keys(f).length>0?f:void 0}var dt=Symbol.for("react.transitional.element");function wt(t){return typeof t==="object"&&t!==null&&"$$typeof"in t&&t.$$typeof===dt}async function E(t){if(t===void 0||t===null)return[];if(t instanceof Promise)return E(await t);if(typeof t==="object"&&Symbol.iterator in t)return $t(t);if(wt(t)){let f=await At(t);return Array.isArray(f)?f:f?[f]:[]}return[q(String(t))]}async function At(t){if(typeof t.type==="function"){let m=t.type;return E(m(t.props))}if(typeof t.type==="symbol"&&t.type===Symbol.for("react.fragment"))return await L(t)||[];if(Ct(t,"img")&&t.props.src)return[Q(t.props.src,X(t.props.style))];let f=await L(t),n=Dt(t.props);return[Z({children:f,...X(n)})]}function Dt(t){return typeof t==="object"&&t&&"style"in t?t.style:void 0}function Ct(t,f){return t.type===f}async function L(t){if(typeof t.props!=="object"||t.props===null||!("children"in t.props))return[];return await E(t.props.children)}async function $t(t){return(await Promise.all(Array.from(t).map(E))).flat()}export{p as vw,B as vh,q as text,Nt as style,_ as rem,H as percentage,Q as image,Et as gradient,E as fromJsx,K as fr,Y as em,Z as container};
|