@takumi-rs/helpers 0.14.1 → 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
@@ -528,8 +528,7 @@ export declare function gradient(from: ColorInput, to: ColorInput, angle?: numbe
528
528
  to: ColorInput;
529
529
  angle: number;
530
530
  };
531
- export type Nodes = Node$1 | Nodes[];
532
- export declare function fromJsx(element: ReactNode): Promise<Nodes | undefined>;
531
+ export declare function fromJsx(element: ReactNode): Promise<Node$1[]>;
533
532
 
534
533
  export {
535
534
  Node$1 as Node,
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function $(t){return{type:"container",...t}}function C(t,e){return{...e,type:"text",text:t}}function E(t,e){return{...e,type:"image",src:t}}function st(t){return t}function J(t){return{percentage:t}}function S(t){return{vw:t}}function j(t){return{vh:t}}function G(t){return{em:t}}function k(t){return{rem:t}}function B(t){return{fr:t}}function xt(t,e,o=0){return{from:t,to:e,angle:o}}function X(t){return t.replace(/[A-Z]/g,(e)=>`_${e.toLowerCase()}`)}var M=["-moz-","-webkit-","-o-","-ms-"];function Z(t){if(typeof t!=="string")return t;if(W(t))return;if(t[0]==="-"){for(let e of M)if(t.startsWith(e))return t.slice(e.length);throw new Error(`Unsupported prefix in value: ${t}`)}return t}function W(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 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 U(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 a(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),d=Number(n),h=Number(r);if(m<0||m>255||y<0||y>255||d<0||d>255)return null;if(h<0||h>1)return null;return[m,y,d,h]}return null}function x(t){if(t.startsWith("#"))return c(t);if(t.startsWith("rgb(")){let e=U(t);if(e!==null)return e}if(t.startsWith("rgba(")){let e=a(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 J(n);case"rem":return k(n);case"em":return G(n);case"vh":return j(n);case"vw":return S(n);case"px":case"":return n;default:return n}}function s(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 q(t){if(t.inset!==void 0)return s(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 H(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 P(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 Y(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",d="0px",h="0px",F="0px"]=m;try{return{color:x(f),offset_x:i(y)??0,offset_y:i(d)??0,blur_radius:i(h)??0,spread_radius:i(F)??0,inset:o}}catch{throw new Error(`Invalid box-shadow color: ${f}`)}}function V(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 g(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 L(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 _(t){let e=t.match(/repeat\(([^,]+),\s*(.+)\)/);if(e){let o=u(e);if(!o)throw new Error(`Invalid repeat function: ${t}`);return o}return v(t)}function u(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 v(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 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 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 V(t);if(Array.isArray(t))return t;return typeof t==="number"?[t]:[B(1)]}function A(t){if(typeof t==="string")return L(t);if(typeof t==="number")return{start:t,end:null};return t}function K(t){if(typeof t==="string")return _(t);if(Array.isArray(t))return t;return typeof t==="number"?[{single:t}]:[{single:0}]}function z(t){if(typeof t==="string")return _(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 b=Symbol("skip-parsing"),tt={display:H,position:P,width:i,height:i,maxWidth:i,maxHeight:i,minWidth:i,minHeight:i,aspectRatio:Q,padding:s,margin:s,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:s,backgroundColor:x,boxShadow:Y,objectFit:b,gridAutoColumns:l,gridAutoRows:l,gridAutoFlow:g,gridColumn:A,gridRow:A,gridTemplateColumns:K,gridTemplateRows:z,textOverflow:(t)=>t,borderColor:x,color:x,fontSize:i,fontFamily:b,lineHeight:i,fontWeight:I,lineClamp:R,borderRadius:(t)=>s(t),textAlign(t){if(t==="match-parent")return void console.warn("Unsupported value for text-align found:",t);return t},letterSpacing:i,inset:(t)=>s(t)},et=new Set(["top","right","bottom","left"]);function ot(t,e,o){if(et.has(e))return;let f=Z(o);if(f===void 0||f===null)return;let n=tt[e];if(!n){console.warn(`No parser found for CSS property: ${e}`);return}let r=X(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))ot(e,f,n);let o=q(t);if(o!==void 0)e.inset=o;return Object.keys(e).length>0?e:void 0}var ft=Symbol.for("react.transitional.element");function nt(t){return typeof t==="object"&&t!==null&&"$$typeof"in t&&t.$$typeof===ft}function N(t){let e=[];for(let o of t)if(Array.isArray(o))e.push(...N(o));else e.push(o);return e}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 yt(t);if(nt(t))return it(t);return C(String(t))}async function it(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 O(t)||[];if(rt(t,"img")&&t.props.src)return E(t.props.src,D(t.props.style));let e=await O(t),o=mt(t.props);return $({children:e,...D(o)})}function mt(t){return typeof t==="object"&&t&&"style"in t?t.style:void 0}function rt(t,e){return t.type===e}async function O(t){if(typeof t.props!=="object"||t.props===null||!("children"in t.props))return;let e=await T(t.props.children);if(!e)return;return Array.isArray(e)?N(e):[e]}async function yt(t){let e=await Promise.all(Array.from(t).map(T));return N(e.filter((o)=>o!==void 0))}export{S as vw,j as vh,C as text,st as style,k as rem,J as percentage,E as image,xt as gradient,T as fromJsx,B as fr,G as em,$ 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.1",
3
+ "version": "0.14.2",
4
4
  "author": {
5
5
  "email": "me@kane.tw",
6
6
  "name": "Kane Wang",