@baseline-ui/utils
Advanced tools
Comparing version 0.24.0 to 0.24.1
@@ -114,3 +114,3 @@ import React from 'react'; | ||
* This function takes a list of [x, y] coordinates representing a stroke and | ||
* returns an SVG path string. | ||
* returns a SVG path string. | ||
* | ||
@@ -125,4 +125,5 @@ * @example | ||
* @param stroke The stroke to convert to an SVG path | ||
* @param closed | ||
*/ | ||
declare function getSvgPathFromStroke(stroke: number[][]): string; | ||
declare function getSvgPathFromStroke(stroke: number[][], closed?: boolean): string; | ||
@@ -129,0 +130,0 @@ declare function cleanKeyFromGlobImport(modules: Record<string, Record<string, string>>): Record<string, Record<string, string>>; |
@@ -19,15 +19,15 @@ 'use strict'; | ||
*/ | ||
function $(e,t){if(!e)throw new Error(t||"Invariant failed")}function p(...e){let t=e.filter(Boolean),r=[];for(let o of t)if(Array.isArray(o))r.push(p(...o));else if(typeof o=="object"){let a=Object.keys(o);for(let n of a)o[n]&&r.push(n);}else typeof o=="string"&&r.push(o);return r.join(" ")}function P(e,t){if(!e)return null;if(typeof e=="string")return t.querySelector(e);if(e instanceof HTMLElement)return e;if("current"in e)return e.current}function d({text:e,fontSize:t=16,fontFamily:r="Arial",fontWeight:o="normal",fontStyle:a="normal",font:n}){let s=document.createElement("canvas").getContext("2d");if(!s)return {width:0,height:0};s.font=n||`${a} ${o} ${t}px ${r}`;let i=s.measureText(e);return {width:i.width,height:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent}}function v({text:e,maxWidth:t,initialFontSize:r=50,fontFamily:o="Arial",fontWeight:a="normal",fontStyle:n="normal"}){let{width:c}=d({text:e,fontSize:r,fontFamily:o,fontWeight:a,fontStyle:n}),s=r,i=c;for(;i>t;)s-=.5,i=d({text:e,fontSize:s,fontFamily:o,fontWeight:a,fontStyle:n}).width;return Math.max(s,1)}function u(e,t,r,o){return [(e+r)/2,(t+o)/2]}function E(e){if(!e.length)return "";let t=["M",...e[0],"Q"];for(let r=0;r<e.length;r++){let[o,a]=e[r],[n,c]=e[(r+1)%e.length],s=u(o,a,n,c);t=[...t,o,a,...s];}return t.push("Z"),t.join(" ")}function b(e){return e.split("/").pop()?.split(".").shift()}function y(e){let t={};for(let r of Object.keys(e)){let o=b(r)??"";t[o]=e[r];}return t}function O(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>!!t))}function T(e,t){$(t>=0&&t<=100,"Percent must be between 0 and 100");let r=color.parseColor(e),o=r.getChannelValue("red"),a=r.getChannelValue("green"),n=r.getChannelValue("blue"),c=Math.round(o+(255-o)*t/100),s=Math.round(a+(255-a)*t/100),i=Math.round(n+(255-n)*t/100);return `#${c.toString(16)}${s.toString(16)}${i.toString(16)}`}function m(e,t){if(e=e.trim(),e.includes(" "))return !1;try{return new URL(e),!0}catch{return t?m(`https://${e}`):!1}}function x(e){var t;return typeof window<"u"&&window.navigator!=null?e.test(((t=window.navigator.userAgentData)===null||t===void 0?void 0:t.platform)||window.navigator.platform):!1}function f(){return x(/^Mac/i)}function G(e,t=!1){return f()?e.replace("Ctrl+",t?"\u2318":"Cmd+").replace("Alt+",t?"\u2325":"Option+").replace("Shift+",t?"\u21E7":"Shift+").replace("Enter+",t?"\u21A9":"Enter+").replace("Space+",t?"\u2423":"Space+").replace("Enter",t?"\u21A9":"Enter"):e}var Z=e=>new DOMParser().parseFromString(g__default.default.sanitize(e),"text/html").body.textContent||""; | ||
function d(e,t){if(!e)throw new Error(t||"Invariant failed")}function u(...e){let t=e.filter(Boolean),o=[];for(let r of t)if(Array.isArray(r))o.push(u(...r));else if(typeof r=="object"){let a=Object.keys(r);for(let n of a)r[n]&&o.push(n);}else typeof r=="string"&&o.push(r);return o.join(" ")}function v(e,t){if(!e)return null;if(typeof e=="string")return t.querySelector(e);if(e instanceof HTMLElement)return e;if("current"in e)return e.current}function p({text:e,fontSize:t=16,fontFamily:o="Arial",fontWeight:r="normal",fontStyle:a="normal",font:n}){let s=document.createElement("canvas").getContext("2d");if(!s)return {width:0,height:0};s.font=n||`${a} ${r} ${t}px ${o}`;let i=s.measureText(e);return {width:i.width,height:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent}}function P({text:e,maxWidth:t,initialFontSize:o=50,fontFamily:r="Arial",fontWeight:a="normal",fontStyle:n="normal"}){let{width:c}=p({text:e,fontSize:o,fontFamily:r,fontWeight:a,fontStyle:n}),s=o,i=c;for(;i>t;)s-=.5,i=p({text:e,fontSize:s,fontFamily:r,fontWeight:a,fontStyle:n}).width;return Math.max(s,1)}var f=(e,t)=>(e+t)/2;function E(e,t=!1){if(!e.length)return "";let o=e.length;if(o<4)return "";let r=e[0],a=e[1],n=e[2],c=`M${r[0].toFixed(2)},${r[1].toFixed(2)} Q${a[0].toFixed(2)},${a[1].toFixed(2)} ${f(a[0],n[0]).toFixed(2)},${f(a[1],n[1]).toFixed(2)} T`;for(let s=2,i=o-1;s<i;s++)r=e[s],a=e[s+1],c+=`${f(r[0],a[0]).toFixed(2)},${f(r[1],a[1]).toFixed(2)} `;return t&&(c+="Z"),c}function b(e){return e.split("/").pop()?.split(".").shift()}function D(e){let t={};for(let o of Object.keys(e)){let r=b(o)??"";t[r]=e[o];}return t}function y(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>!!t))}function T(e,t){d(t>=0&&t<=100,"Percent must be between 0 and 100");let o=color.parseColor(e),r=o.getChannelValue("red"),a=o.getChannelValue("green"),n=o.getChannelValue("blue"),c=Math.round(r+(255-r)*t/100),s=Math.round(a+(255-a)*t/100),i=Math.round(n+(255-n)*t/100);return `#${c.toString(16)}${s.toString(16)}${i.toString(16)}`}function m(e,t){if(e=e.trim(),e.includes(" "))return !1;try{return new URL(e),!0}catch{return t?m(`https://${e}`):!1}}function x(e){var t;return typeof window<"u"&&window.navigator!=null?e.test(((t=window.navigator.userAgentData)===null||t===void 0?void 0:t.platform)||window.navigator.platform):!1}function $(){return x(/^Mac/i)}function G(e,t=!1){return $()?e.replace("Ctrl+",t?"\u2318":"Cmd+").replace("Alt+",t?"\u2325":"Option+").replace("Shift+",t?"\u21E7":"Shift+").replace("Enter+",t?"\u21A9":"Enter+").replace("Space+",t?"\u2423":"Space+").replace("Enter",t?"\u21A9":"Enter"):e}var Z=e=>new DOMParser().parseFromString(g__default.default.sanitize(e),"text/html").body.textContent||""; | ||
exports.calculateFontSizeToFitWidth = v; | ||
exports.classNames = p; | ||
exports.cleanKeyFromGlobImport = y; | ||
exports.filterTruthyValues = O; | ||
exports.getHTMLElement = P; | ||
exports.calculateFontSizeToFitWidth = P; | ||
exports.classNames = u; | ||
exports.cleanKeyFromGlobImport = D; | ||
exports.filterTruthyValues = y; | ||
exports.getHTMLElement = v; | ||
exports.getOsSpecificKeyboardShortcutLabel = G; | ||
exports.getPlainText = Z; | ||
exports.getSvgPathFromStroke = E; | ||
exports.getTextDimensions = d; | ||
exports.invariant = $; | ||
exports.getTextDimensions = p; | ||
exports.invariant = d; | ||
exports.isUrl = m; | ||
exports.lightenColor = T; |
{ | ||
"name": "@baseline-ui/utils", | ||
"version": "0.24.0", | ||
"version": "0.24.1", | ||
"description": "A collection of utility functions for Baseline UI", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1407889
235