@takumi-rs/helpers 0.14.0 → 0.14.2

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.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { ReactNode } from 'react';
4
+
3
5
  /**
4
6
  * Defines how flex items are aligned along the cross axis.
5
7
  *
@@ -526,6 +528,7 @@ export declare function gradient(from: ColorInput, to: ColorInput, angle?: numbe
526
528
  to: ColorInput;
527
529
  angle: number;
528
530
  };
531
+ export declare function fromJsx(element: ReactNode): Promise<Node$1[]>;
529
532
 
530
533
  export {
531
534
  Node$1 as Node,
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function r(e){return{type:"container",...e}}function i(e,t){return{...t,type:"text",text:e}}function s(e,t){return{...t,type:"image",src:e}}function a(e){return e}function n(e){return{percentage:e}}function l(e){return{vw:e}}function p(e){return{vh:e}}function h(e){return{em:e}}function m(e){return{rem:e}}function f(e){return{fr:e}}function u(e,t,o=0){return{from:e,to:t,angle:o}}export{l as vw,p as vh,i as text,a as style,m as rem,n as percentage,s as image,u as gradient,f as fr,h as em,r as container};
1
+ function $(t){return{type:"container",...t}}function C(t,e){return{...e,type:"text",text:t}}function N(t,e){return{...e,type:"image",src:t}}function yt(t){return t}function E(t){return{percentage:t}}function J(t){return{vw:t}}function S(t){return{vh:t}}function j(t){return{em:t}}function G(t){return{rem:t}}function k(t){return{fr:t}}function xt(t,e,o=0){return{from:t,to:e,angle:o}}function B(t){return t.replace(/[A-Z]/g,(e)=>`_${e.toLowerCase()}`)}var F=["-moz-","-webkit-","-o-","-ms-"];function X(t){if(typeof t!=="string")return t;if(M(t))return;if(t[0]==="-"){for(let e of F)if(t.startsWith(e))return t.slice(e.length);throw new Error(`Unsupported prefix in value: ${t}`)}return t}function M(t){return t==="inherit"||t==="initial"||t==="revert"||t==="unset"}function W(t){if(t.length===7)return Number.parseInt(t.slice(1),16);if(t.length===9){let e=Number.parseInt(t.slice(1),16);return[e>>24&255,e>>16&255,e>>8&255,(e&255)/255]}throw new Error(`Invalid hex color: ${t}`)}function c(t){let e=t.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);if(e){let[,o,f,n]=e;return[Number(o),Number(f),Number(n)]}return null}function U(t){let e=t.match(/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*\)$/);if(e){let[,o,f,n,r]=e,m=Number(o),y=Number(f),h=Number(n),d=Number(r);if(m<0||m>255||y<0||y>255||h<0||h>255)return null;if(d<0||d>1)return null;return[m,y,h,d]}return null}function s(t){if(t.startsWith("#"))return W(t);if(t.startsWith("rgb(")){let e=c(t);if(e!==null)return e}if(t.startsWith("rgba(")){let e=U(t);if(e!==null)return e}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 e=t.match(/^(-?[\d.]+)(.*)$/);if(!e)return 0;let[,o,f]=e;if(!o)return 0;let n=Number.parseFloat(o);switch(f){case"%":return E(n);case"rem":return G(n);case"em":return j(n);case"vh":return S(n);case"vw":return J(n);case"px":case"":return n;default:return n}}function x(t){if(typeof t==="number")return i(t);let o=t.trim().split(/\s+/).map(i);if(o.length===1)return o[0];if(o.length===2||o.length===4)return o;if(o.length===3&&o[0]!==void 0&&o[1]!==void 0&&o[2]!==void 0)return[o[0],o[1],o[2],o[1]];throw new Error(`Invalid sides value: ${t}. Expected 1 to at most 4 values.`)}function Z(t){if(t.inset!==void 0)return x(t.inset);let e=t.top!==void 0?i(t.top):void 0,o=t.right!==void 0?i(t.right):void 0,f=t.bottom!==void 0?i(t.bottom):void 0,n=t.left!==void 0?i(t.left):void 0;if(e===void 0&&o===void 0&&f===void 0&&n===void 0)return;return[e??0,o??0,f??0,n??0]}function q(t){if(typeof t==="number")return t;if(typeof t==="string"&&t.includes("/")){let[e,o]=t.split("/").map(Number.parseFloat);if(e===void 0||o===void 0)throw new Error(`Invalid aspect ratio: ${t}. Expected format 'width/height'.`);if(o===0)throw new Error(`Invalid aspect ratio: ${t}. Denominator cannot be zero.`);return e/o}if(typeof t==="string")return Number.parseFloat(t);throw new Error(`Invalid aspect ratio: ${t}`)}function Q(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 H(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 P(t){let e=t.trim().split(/\s+/);if(e.length<2)throw new Error(`Invalid box-shadow: ${t}`);let o=!1,f="black",n=0;if(e[0]==="inset")o=!0,n=1;let r=/^(#|rgb|rgba|hsl|hsla|[a-zA-Z]+)/,m=[];for(let p=n;p<e.length;p++){let w=e[p]??"";if(p===e.length-1&&r.test(w))f=w;else m.push(w)}if(m.length<2||m.length>4)throw new Error(`Invalid box-shadow format: ${t}`);let[y="0px",h="0px",d="0px",O="0px"]=m;try{return{color:s(f),offset_x:i(y)??0,offset_y:i(h)??0,blur_radius:i(d)??0,spread_radius:i(O)??0,inset:o}}catch{throw new Error(`Invalid box-shadow color: ${f}`)}}function a(t){return t.trim().split(/\s+/).map((o)=>{if(o.endsWith("fr")){let f=Number.parseFloat(o.slice(0,-2));if(Number.isNaN(f))return{fr:0};return{fr:f}}return i(o)??0})}function Y(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 o=Number.parseInt(t.slice(5));if(Number.isNaN(o))throw new Error(`Invalid span value: ${t}`);return{start:o,end:null}}if(t.includes("/")){let o=t.split("/");if(o.length!==2)throw new Error(`Invalid grid line format: ${t}`);let[f="",n=""]=o.map((y)=>y.trim()),r=f==="auto"?null:Number.parseInt(f)||f,m=n==="auto"?null:Number.parseInt(n)||n;return{start:r,end:m}}if(t==="auto")return{start:null,end:null};let e=Number.parseInt(t);if(Number.isNaN(e))return{start:t,end:null};return{start:e,end:null}}function g(t){let e=t.match(/repeat\(([^,]+),\s*(.+)\)/);if(e){let o=L(e);if(!o)throw new Error(`Invalid repeat function: ${t}`);return o}return u(t)}function L(t){let[,e,o]=t;if(!e||!o)return;let f;if(e==="auto-fill")f="auto-fill";else if(e==="auto-fit")f="auto-fit";else{let r=Number.parseInt(e);if(Number.isNaN(r))return;f=r}let n=o.trim().split(/\s+/).map((r)=>{if(r.endsWith("fr")){let m=Number.parseFloat(r.slice(0,-2));return Number.isNaN(m)?0:{fr:m}}return i(r)??0});return[{repeat:[f,n]}]}function u(t){return t.trim().split(/\s+/).map((o)=>{if(o.endsWith("fr")){let f=Number.parseFloat(o.slice(0,-2));return{single:Number.isNaN(f)?0:{fr:f}}}return{single:i(o)??0}})}function _(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 e=Number.parseInt(t);if(!Number.isNaN(e))return Math.max(1,Math.min(1000,e))}}return console.warn(`Invalid font-weight value: ${t}, fallback to 400.`),400}function l(t){if(typeof t==="string")return a(t);if(Array.isArray(t))return t;return typeof t==="number"?[t]:[k(1)]}function A(t){if(typeof t==="string")return V(t);if(typeof t==="number")return{start:t,end:null};return t}function I(t){if(typeof t==="string")return g(t);if(Array.isArray(t))return t;return typeof t==="number"?[{single:t}]:[{single:0}]}function K(t){if(typeof t==="string")return g(t);if(Array.isArray(t))return t;return typeof t==="number"?[{single:t}]:[{single:0}]}function z(t){if(t==="none")return 0;return Number(t)}var b=Symbol("skip-parsing"),v={display:Q,position:H,width:i,height:i,maxWidth:i,maxHeight:i,minWidth:i,minHeight:i,aspectRatio:q,padding:x,margin:x,flexDirection:b,flexWrap:b,justifyContent:(t)=>t,alignContent:(t)=>t,alignItems:(t)=>t,justifyItems:(t)=>t,flexBasis:i,gap:i,flexGrow:(t)=>Number(t),flexShrink:(t)=>Number(t),borderWidth:x,backgroundColor:s,boxShadow:P,objectFit:b,gridAutoColumns:l,gridAutoRows:l,gridAutoFlow:Y,gridColumn:A,gridRow:A,gridTemplateColumns:I,gridTemplateRows:K,textOverflow:(t)=>t,borderColor:s,color:s,fontSize:i,fontFamily:b,lineHeight:i,fontWeight:_,lineClamp:z,borderRadius:(t)=>x(t),textAlign(t){if(t==="match-parent")return void console.warn("Unsupported value for text-align found:",t);return t},letterSpacing:i,inset:(t)=>x(t)},tt=new Set(["top","right","bottom","left"]);function et(t,e,o){if(tt.has(e))return;let f=X(o);if(f===void 0||f===null)return;let n=v[e];if(!n){console.warn(`No parser found for CSS property: ${e}`);return}let r=B(e);if(n===b){t[r]=f;return}try{let m=n(f);if(m!=null&&m!==void 0)t[r]=m}catch(m){console.warn(`Failed to parse ${e}:`,m)}}function D(t){if(!t)return;let e={};for(let[f,n]of Object.entries(t))et(e,f,n);let o=Z(t);if(o!==void 0)e.inset=o;return Object.keys(e).length>0?e:void 0}var ot=Symbol.for("react.transitional.element");function ft(t){return typeof t==="object"&&t!==null&&"$$typeof"in t&&t.$$typeof===ot}async function T(t){if(t===void 0||t===null)return[];if(t instanceof Promise)return T(await t);if(typeof t==="object"&&Symbol.iterator in t)return rt(t);if(ft(t)){let e=await nt(t);return Array.isArray(e)?e:e?[e]:[]}return[C(String(t))]}async function nt(t){if(typeof t.type==="function"){let f=t.type;return T(f(t.props))}if(typeof t.type==="symbol"&&t.type===Symbol.for("react.fragment"))return await R(t)||[];if(mt(t,"img")&&t.props.src)return[N(t.props.src,D(t.props.style))];let e=await R(t),o=it(t.props);return[$({children:e,...D(o)})]}function it(t){return typeof t==="object"&&t&&"style"in t?t.style:void 0}function mt(t,e){return t.type===e}async function R(t){if(typeof t.props!=="object"||t.props===null||!("children"in t.props))return[];return await T(t.props.children)}async function rt(t){return(await Promise.all(Array.from(t).map(T))).flat()}export{J as vw,S as vh,C as text,yt as style,G as rem,E as percentage,N as image,xt as gradient,T as fromJsx,k as fr,j as em,$ as container};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "author": {
5
5
  "email": "me@kane.tw",
6
6
  "name": "Kane Wang",