@baseline-ui/utils
Advanced tools
Comparing version 0.0.0-canary-20240724000523 to 0.0.0-canary-20240724103021
'use strict'; | ||
var color = require('@react-stately/color'); | ||
var utils = require('@react-aria/utils'); | ||
var h = require('dompurify'); | ||
var g = require('dompurify'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var h__default = /*#__PURE__*/_interopDefault(h); | ||
var g__default = /*#__PURE__*/_interopDefault(g); | ||
@@ -20,15 +19,15 @@ /** | ||
*/ | ||
function f(t,r){if(!t)throw new Error(r||"Invariant failed")}function l(...t){let r=t.filter(Boolean),n=[];for(let e of r)if(Array.isArray(e))n.push(l(...e));else if(typeof e=="object"){let o=Object.keys(e);for(let i of o)e[i]&&n.push(i);}else typeof e=="string"&&n.push(e);return n.join(" ")}function M(t,r){if(!t)return null;if(typeof t=="string")return r.querySelector(t);if(t instanceof HTMLElement)return t;if("current"in t)return t.current}function u({text:t,fontSize:r=16,fontFamily:n="Arial",fontWeight:e="normal",fontStyle:o="normal",font:i}){let s=document.createElement("canvas").getContext("2d");if(!s)return {width:0,height:0};s.font=i||`${o} ${e} ${r}px ${n}`;let c=s.measureText(t);return {width:c.width,height:c.actualBoundingBoxAscent+c.actualBoundingBoxDescent}}function T({text:t,maxWidth:r,initialFontSize:n=50,fontFamily:e="Arial",fontWeight:o="normal",fontStyle:i="normal"}){let{width:a}=u({text:t,fontSize:n,fontFamily:e,fontWeight:o,fontStyle:i}),s=n,c=a;for(;c>r;)s-=.5,c=u({text:t,fontSize:s,fontFamily:e,fontWeight:o,fontStyle:i}).width;return Math.max(s,1)}function p(t,r,n,e){return [(t+n)/2,(r+e)/2]}function E(t){if(!t.length)return "";let r=["M",...t[0],"Q"];for(let n=0;n<t.length;n++){let[e,o]=t[n],[i,a]=t[(n+1)%t.length],s=p(e,o,i,a);r=[...r,e,o,...s];}return r.push("Z"),r.join(" ")}function g(t){return t.split("/").pop()?.split(".").shift()}function S(t){let r={};for(let n of Object.keys(t)){let e=g(n)??"";r[e]=t[n];}return r}function C(t){return Object.fromEntries(Object.entries(t).filter(([,r])=>!!r))}function L(t,r){f(r>=0&&r<=100,"Percent must be between 0 and 100");let n=color.parseColor(t),e=n.getChannelValue("red"),o=n.getChannelValue("green"),i=n.getChannelValue("blue"),a=Math.round(e+(255-e)*r/100),s=Math.round(o+(255-o)*r/100),c=Math.round(i+(255-i)*r/100);return `#${a.toString(16)}${s.toString(16)}${c.toString(16)}`}function d(t,r){if(t=t.trim(),t.includes(" "))return !1;try{return new URL(t),!0}catch{return r?d(`https://${t}`):!1}}function B(t,r=!1){return utils.isMac()?t.replace("Ctrl+",r?"\u2318":"Cmd+").replace("Alt+",r?"\u2325":"Option+").replace("Shift+",r?"\u21E7":"Shift+").replace("Enter+",r?"\u21A9":"Enter+").replace("Space+",r?"\u2423":"Space+").replace("Enter",r?"\u21A9":"Enter"):t}var V=t=>new DOMParser().parseFromString(h__default.default.sanitize(t),"text/html").body.textContent||""; | ||
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||""; | ||
exports.calculateFontSizeToFitWidth = T; | ||
exports.classNames = l; | ||
exports.cleanKeyFromGlobImport = S; | ||
exports.filterTruthyValues = C; | ||
exports.getHTMLElement = M; | ||
exports.getOsSpecificKeyboardShortcutLabel = B; | ||
exports.getPlainText = V; | ||
exports.calculateFontSizeToFitWidth = v; | ||
exports.classNames = p; | ||
exports.cleanKeyFromGlobImport = y; | ||
exports.filterTruthyValues = O; | ||
exports.getHTMLElement = P; | ||
exports.getOsSpecificKeyboardShortcutLabel = G; | ||
exports.getPlainText = Z; | ||
exports.getSvgPathFromStroke = E; | ||
exports.getTextDimensions = u; | ||
exports.invariant = f; | ||
exports.isUrl = d; | ||
exports.lightenColor = L; | ||
exports.getTextDimensions = d; | ||
exports.invariant = $; | ||
exports.isUrl = m; | ||
exports.lightenColor = T; |
{ | ||
"name": "@baseline-ui/utils", | ||
"version": "0.0.0-canary-20240724000523", | ||
"version": "0.0.0-canary-20240724103021", | ||
"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
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
1417390