UNPKG

@nexusui/components

Version:

These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.

2 lines (1 loc) 2.56 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../constants.js");const r=(e,t)=>[e?.trim()||"",t?.trim()||""].map((e=>e.charAt(0))).join("").toUpperCase(),n=e=>r(e.firstName,e.lastName),o=(e,r)=>{const n=Object.keys(t.highlight);let o=0;return 1===r.length?o=r.charCodeAt(0)%n.length:2===r.length&&(o=(r.charCodeAt(0)+r.charCodeAt(1))%n.length),t.highlight[n[o]]};function i(e){if(/^(#|rgb\(|rgba\(|hsl\(|hsla\()/.test(e))return e;if("undefined"==typeof document)return"#000000";const t=document.createElement("canvas").getContext("2d");return t?(t.fillStyle=e,t.fillStyle.toString()):"#000000"}const s=(e,t)=>{const r=t.split(".");return 1===r.length?/^(#|rgb\(|rgba\(|hsl\(|hsla\()/.test(t)?t:i(t):e.palette?.[r[0]]?.[r[1]]};exports.flattenTreeIds=(e,t="itemId",r="children")=>{const n=[],o=e=>{e.forEach((e=>{const i=e[t];"string"==typeof i&&n.push(i);const s=e[r];Array.isArray(s)&&o(s)}))};return Array.isArray(e)&&o(e),n},exports.getContrastTextColor=(e,t,r)=>r||(t?e.palette.getContrastText(s(e,t)??e.vars.palette.grey[50]):"common.white"),exports.getFileSize=e=>e<1048576?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`,exports.getFullName=e=>`${e?.firstName||""} ${e?.lastName||""}`.trim(),exports.getHighlightColor=o,exports.getHighlightColorByUser=(e,t)=>o(0,n(t)),exports.getHumanFileSize=(e,t=!1,r=1)=>{const n=t?1e3:1024;if(Math.abs(e)<n)return`${e} B`;const o=t?["kB","MB","GB","TB","PB","EB","ZB","YB"]:["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"];let i=-1;const s=10**r;do{e/=n,i+=1}while(Math.round(Math.abs(e)*s)/s>=n&&i<o.length-1);return`${e.toFixed(r)} ${o[i]}`},exports.getInitials=r,exports.getInitialsByUser=n,exports.getMenuOrigin=e=>{let t="left";if(e&&window){const r=e.getBoundingClientRect().left;window.innerWidth<=600&&(t=r>window.innerWidth/2?"right":"left"),t=window.innerWidth-r<=300?"right":"left"}return{anchorOrigin:{vertical:"bottom",horizontal:t},transformOrigin:{vertical:"top",horizontal:t}}},exports.isReactNode=function(t){return e.isValidElement(t)||"boolean"==typeof t||null==t||"string"==typeof t||"number"==typeof t},exports.openLink=(e,t="_blank")=>{e&&(window.hxgnapi&&window.hxgnapi.openLink?window.hxgnapi.openLink(e):(window.hxgnapi&&console.warn("Please update your CEF browser 'Hexagon.Framework.WebBrowser' to a version after '2023.0.9000.9032'. The version you are currently using does not support opening links in the system default browser. "),window.open(e,t)))},exports.standardizeColorToHex=s,exports.standardizeNamedColorToHex=i;