@takumi-rs/helpers 0.14.0 → 0.14.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.d.ts +4 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
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,8 @@ export declare function gradient(from: ColorInput, to: ColorInput, angle?: numbe
|
|
|
526
528
|
to: ColorInput;
|
|
527
529
|
angle: number;
|
|
528
530
|
};
|
|
531
|
+
export type Nodes = Node$1 | Nodes[];
|
|
532
|
+
export declare function fromJsx(element: ReactNode): Promise<Nodes | undefined>;
|
|
529
533
|
|
|
530
534
|
export {
|
|
531
535
|
Node$1 as Node,
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
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};
|