@baseline-ui/utils
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -0,1 +1,5 @@ | ||
'use strict'; | ||
var color = require('@react-stately/color'); | ||
/** | ||
@@ -10,2 +14,12 @@ * Copyright (c) 2023-2024 PSPDFKit GmbH. All rights reserved. | ||
*/ | ||
"use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var h=(t,n)=>{for(var e in n)a(t,e,{get:n[e],enumerable:!0})},x=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of d(n))!p.call(t,o)&&o!==e&&a(t,o,{get:()=>n[o],enumerable:!(r=g(n,o))||r.enumerable});return t};var b=t=>x(a({},"__esModule",{value:!0}),t);var R={};h(R,{calculateFontSizeToFitWidth:()=>w,classNames:()=>y,cleanKeyFromGlobImport:()=>P,filterTruthyValues:()=>j,getHTMLElement:()=>T,getSvgPathFromStroke:()=>S,getTextDimensions:()=>f,invariant:()=>l,lightenColor:()=>F});module.exports=b(R);function l(t,n){if(!t)throw new Error(n||"Invariant failed")}function y(...t){let n=t.filter(Boolean),e=[];for(let r of n)if(typeof r=="object"){let o=Object.keys(r);for(let i of o)r[i]&&e.push(i)}else typeof r=="string"&&e.push(r);return e.join(" ")}function T(t,n){if(!t)return null;if(typeof t=="string")return n.querySelector(t);if(t instanceof HTMLElement)return t;if("current"in t)return t.current}function f({text:t,fontSize:n,fontFamily:e="Arial",fontWeight:r="normal",fontStyle:o="normal"}){let c=document.createElement("canvas").getContext("2d");if(!c)return{width:0,height:0};c.font=`${o} ${r} ${n}px ${e}`;let s=c.measureText(t);return{width:s.width,height:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent}}function w({text:t,maxWidth:n,initialFontSize:e=50,fontFamily:r="Arial",fontWeight:o="normal",fontStyle:i="normal"}){let{width:c}=f({text:t,fontSize:e,fontFamily:r,fontWeight:o,fontStyle:i}),s=e,u=c;for(;u>n;)s-=.5,u=f({text:t,fontSize:s,fontFamily:r,fontWeight:o,fontStyle:i}).width;return Math.max(s,1)}function M(t,n,e,r){return[(t+e)/2,(n+r)/2]}function S(t){if(!t.length)return"";let n=["M",...t[0],"Q"];for(let e=0;e<t.length;e++){let[r,o]=t[e],[i,c]=t[(e+1)%t.length],s=M(r,o,i,c);n=[...n,r,o,...s]}return n.push("Z"),n.join(" ")}function E(t){return t.split("/").pop()?.split(".").shift()}function P(t){let n={};for(let e of Object.keys(t)){let r=E(e)??"";n[r]=t[e]}return n}function j(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>!!n))}var m=require("@react-stately/color");function F(t,n){l(n>=0&&n<=100,"Percent must be between 0 and 100");let e=(0,m.parseColor)(t),r=e.getChannelValue("red"),o=e.getChannelValue("green"),i=e.getChannelValue("blue"),c=Math.round(r+(255-r)*n/100),s=Math.round(o+(255-o)*n/100),u=Math.round(i+(255-i)*n/100);return`#${c.toString(16)}${s.toString(16)}${u.toString(16)}`}0&&(module.exports={calculateFontSizeToFitWidth,classNames,cleanKeyFromGlobImport,filterTruthyValues,getHTMLElement,getSvgPathFromStroke,getTextDimensions,invariant,lightenColor}); | ||
function a(t,n){if(!t)throw new Error(n||"Invariant failed")}function p(...t){let n=t.filter(Boolean),e=[];for(let r of n)if(typeof r=="object"){let o=Object.keys(r);for(let i of o)r[i]&&e.push(i);}else typeof r=="string"&&e.push(r);return e.join(" ")}function x(t,n){if(!t)return null;if(typeof t=="string")return n.querySelector(t);if(t instanceof HTMLElement)return t;if("current"in t)return t.current}function l({text:t,fontSize:n,fontFamily:e="Arial",fontWeight:r="normal",fontStyle:o="normal"}){let c=document.createElement("canvas").getContext("2d");if(!c)return {width:0,height:0};c.font=`${o} ${r} ${n}px ${e}`;let s=c.measureText(t);return {width:s.width,height:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent}}function b({text:t,maxWidth:n,initialFontSize:e=50,fontFamily:r="Arial",fontWeight:o="normal",fontStyle:i="normal"}){let{width:c}=l({text:t,fontSize:e,fontFamily:r,fontWeight:o,fontStyle:i}),s=e,u=c;for(;u>n;)s-=.5,u=l({text:t,fontSize:s,fontFamily:r,fontWeight:o,fontStyle:i}).width;return Math.max(s,1)}function f(t,n,e,r){return [(t+e)/2,(n+r)/2]}function T(t){if(!t.length)return "";let n=["M",...t[0],"Q"];for(let e=0;e<t.length;e++){let[r,o]=t[e],[i,c]=t[(e+1)%t.length],s=f(r,o,i,c);n=[...n,r,o,...s];}return n.push("Z"),n.join(" ")}function m(t){return t.split("/").pop()?.split(".").shift()}function M(t){let n={};for(let e of Object.keys(t)){let r=m(e)??"";n[r]=t[e];}return n}function E(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>!!n))}function R(t,n){a(n>=0&&n<=100,"Percent must be between 0 and 100");let e=color.parseColor(t),r=e.getChannelValue("red"),o=e.getChannelValue("green"),i=e.getChannelValue("blue"),c=Math.round(r+(255-r)*n/100),s=Math.round(o+(255-o)*n/100),u=Math.round(i+(255-i)*n/100);return `#${c.toString(16)}${s.toString(16)}${u.toString(16)}`} | ||
exports.calculateFontSizeToFitWidth = b; | ||
exports.classNames = p; | ||
exports.cleanKeyFromGlobImport = M; | ||
exports.filterTruthyValues = E; | ||
exports.getHTMLElement = x; | ||
exports.getSvgPathFromStroke = T; | ||
exports.getTextDimensions = l; | ||
exports.invariant = a; | ||
exports.lightenColor = R; |
{ | ||
"name": "@baseline-ui/utils", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "A collection of utility functions for Baseline UI", | ||
@@ -26,5 +26,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format cjs,esm --minify --dts", | ||
"build": "tsup src/index.ts --format cjs,esm --minify --dts --treeshake", | ||
"build:docs": "typedoc --hidePageTitle --useCodeBlocks --parametersFormat table --hidePageHeader --hideBreadcrumbs false --outputFileStrategy modules" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
184
15791