@nextui-org/shared-utils
Advanced tools
Comparing version 0.0.0-dev-v2-20230613135041 to 0.0.0-dev-v2-20230613212244
export { Dict, __DEV__, __TEST__, dataAttr, isArray, isEmpty, isEmptyArray, isEmptyObject, isFunction, isNumeric, isObject } from './assertion.js'; | ||
export { ReactRef, assignRef, mergeRefs } from './refs.js'; | ||
export { clsx } from './clsx.js'; | ||
export { AlignContent, AlignItems, AsProp, BreakpointsValue, CardVariants, ContentPosition, CopyTypes, Direction, Display, DividerAlign, DropdownVariants, ExcludedInputProps, Justify, NormalAlignment, NormalColors, NormalLoaders, NormalPlacement, NormalSizes, NormalWeights, ObjectFit, Placement, Position, SelectionBehavior, SelectionMode, SimpleColors, SimplePlacement, SnippetTypes, TextTransforms, TextWeights, TooltipColors, TriggerTypes, Wrap, excludedInputPropsForTextarea, extendedColors, extendedColorsNoGradient, extraColors, normalColors, normalLoaders, normalWeights, simpleColors, textTransforms, textWeights, tuple } from './prop-types.js'; | ||
export { addColorAlpha, colorToRgbValues, getCSSColor, getCssVar, hexFromString, hexToRGBA, hexToRgb, invertHex, isColor, isCssVar, isHex, isNormalColor, isSimpleColor, rgbToRgba } from './color.js'; | ||
export { MergeObject, arrayToObject, cleanObject, cleanObjectKeys, compact, copyObject, getKeyValue, getProp, omitObject, renameProp } from './object.js'; | ||
@@ -10,7 +7,5 @@ export { safeText } from './text.js'; | ||
export { callAll, callAllHandlers, capitalize, extractProperty, getUniqueID } from './functions.js'; | ||
export { CreateContextOptions, CreateContextReturn, createContext } from './context.js'; | ||
export { range } from './numbers.js'; | ||
export { warn } from './console.js'; | ||
export { getValidChildren, pickChildren } from './react.js'; | ||
export { Timer } from './types.js'; | ||
import 'react'; |
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -20,6 +18,2 @@ var __export = (target, all) => { | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -32,5 +26,3 @@ | ||
__TEST__: () => __TEST__, | ||
addColorAlpha: () => addColorAlpha, | ||
arrayToObject: () => arrayToObject, | ||
assignRef: () => assignRef, | ||
callAll: () => callAll, | ||
@@ -42,14 +34,6 @@ callAllHandlers: () => callAllHandlers, | ||
clsx: () => clsx, | ||
colorToRgbValues: () => colorToRgbValues, | ||
compact: () => compact, | ||
copyObject: () => copyObject, | ||
createContext: () => createContext2, | ||
dataAttr: () => dataAttr, | ||
excludedInputPropsForTextarea: () => excludedInputPropsForTextarea, | ||
extendedColors: () => extendedColors, | ||
extendedColorsNoGradient: () => extendedColorsNoGradient, | ||
extraColors: () => extraColors, | ||
extractProperty: () => extractProperty, | ||
getCSSColor: () => getCSSColor, | ||
getCssVar: () => getCssVar, | ||
getKeyValue: () => getKeyValue, | ||
@@ -59,10 +43,3 @@ getMargin: () => getMargin, | ||
getUniqueID: () => getUniqueID, | ||
getValidChildren: () => getValidChildren, | ||
hexFromString: () => hexFromString, | ||
hexToRGBA: () => hexToRGBA, | ||
hexToRgb: () => hexToRgb, | ||
invertHex: () => invertHex, | ||
isArray: () => isArray, | ||
isColor: () => isColor, | ||
isCssVar: () => isCssVar, | ||
isEmpty: () => isEmpty, | ||
@@ -72,21 +49,8 @@ isEmptyArray: () => isEmptyArray, | ||
isFunction: () => isFunction, | ||
isHex: () => isHex, | ||
isNormalColor: () => isNormalColor, | ||
isNumeric: () => isNumeric, | ||
isObject: () => isObject, | ||
isSimpleColor: () => isSimpleColor, | ||
mergeRefs: () => mergeRefs, | ||
normalColors: () => normalColors, | ||
normalLoaders: () => normalLoaders, | ||
normalWeights: () => normalWeights, | ||
omitObject: () => omitObject, | ||
pickChildren: () => pickChildren, | ||
range: () => range, | ||
renameProp: () => renameProp, | ||
rgbToRgba: () => rgbToRgba, | ||
safeText: () => safeText, | ||
simpleColors: () => simpleColors, | ||
textTransforms: () => textTransforms, | ||
textWeights: () => textWeights, | ||
tuple: () => tuple, | ||
warn: () => warn | ||
@@ -127,22 +91,2 @@ }); | ||
// src/refs.ts | ||
function assignRef(ref, value) { | ||
if (ref == null) | ||
return; | ||
if (isFunction(ref)) { | ||
ref(value); | ||
return; | ||
} | ||
try { | ||
ref.current = value; | ||
} catch (error) { | ||
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`); | ||
} | ||
} | ||
function mergeRefs(...refs) { | ||
return (node) => { | ||
refs.forEach((ref) => assignRef(ref, node)); | ||
}; | ||
} | ||
// src/clsx.ts | ||
@@ -187,315 +131,2 @@ function toVal(mix) { | ||
// src/prop-types.ts | ||
var tuple = (...args) => args; | ||
var normalSizes = tuple("xs", "sm", "md", "lg", "xl"); | ||
var normalColors = tuple( | ||
"default", | ||
"primary", | ||
"secondary", | ||
"success", | ||
"warning", | ||
"error", | ||
"gradient" | ||
); | ||
var simpleColors = tuple("default", "primary", "secondary", "success", "warning", "error"); | ||
var extendedColors = tuple( | ||
"default", | ||
"primary", | ||
"secondary", | ||
"success", | ||
"warning", | ||
"error", | ||
"invert", | ||
"gradient" | ||
); | ||
var extendedColorsNoGradient = tuple( | ||
"default", | ||
"primary", | ||
"secondary", | ||
"success", | ||
"warning", | ||
"error", | ||
"invert" | ||
); | ||
var extraColors = tuple( | ||
"default", | ||
"primary", | ||
"secondary", | ||
"success", | ||
"warning", | ||
"error", | ||
"dark", | ||
"lite", | ||
"alert", | ||
"purple", | ||
"violet", | ||
"gradient", | ||
"cyan" | ||
); | ||
var normalLoaders = tuple("default", "points", "points-opacity", "gradient", "spinner"); | ||
var normalWeights = tuple("light", "normal", "bold", "extrabold", "black"); | ||
var textWeights = tuple( | ||
"normal", | ||
"bold", | ||
"lighter", | ||
"bolder", | ||
"inherit", | ||
"initial", | ||
"revert", | ||
"unset" | ||
); | ||
var textTransforms = tuple( | ||
"none", | ||
"capitalize", | ||
"uppercase", | ||
"lowercase", | ||
"full-width", | ||
"full-size-kana", | ||
"inherit", | ||
"initial", | ||
"revert", | ||
"unset" | ||
); | ||
var copyTypes = tuple("default", "slient", "prevent"); | ||
var triggerTypes = tuple("hover", "click"); | ||
var placement = tuple( | ||
"top", | ||
"topStart", | ||
"topEnd", | ||
"left", | ||
"leftStart", | ||
"leftEnd", | ||
"bottom", | ||
"bottomStart", | ||
"bottomEnd", | ||
"right", | ||
"rightStart", | ||
"rightEnd" | ||
); | ||
var normalPlacement = tuple( | ||
"bottom", | ||
"bottom-left", | ||
"bottom-right", | ||
"top", | ||
"top-left", | ||
"top-right", | ||
"left", | ||
"left-top", | ||
"left-bottom", | ||
"right", | ||
"right-top", | ||
"right-bottom" | ||
); | ||
var simplePlacement = tuple("top-right", "top-left", "bottom-right", "bottom-left"); | ||
var position = tuple( | ||
"static", | ||
"relative", | ||
"absolute", | ||
"fixed", | ||
"sticky", | ||
"inherit", | ||
"initial", | ||
"revert", | ||
"unset" | ||
); | ||
var objectFit = tuple( | ||
"contain", | ||
"cover", | ||
"fill", | ||
"none", | ||
"scale-down", | ||
"inherit", | ||
"initial", | ||
"revert", | ||
"unset" | ||
); | ||
var dividerAlign = tuple("start", "center", "end", "left", "right"); | ||
var justify = tuple( | ||
"flex-start", | ||
"center", | ||
"flex-end", | ||
"space-between", | ||
"space-around", | ||
"space-evenly" | ||
); | ||
var alignItems = tuple("flex-start", "flex-end", "center", "stretch", "baseline"); | ||
var alignContent = tuple( | ||
"stretch", | ||
"center", | ||
"flex-start", | ||
"flex-end", | ||
"space-between", | ||
"space-around" | ||
); | ||
var direction = tuple("row", "row-reverse", "column", "column-reverse"); | ||
var wrap = tuple("nowrap", "wrap", "wrap-reverse"); | ||
var display = tuple( | ||
"flex", | ||
"block", | ||
"grid", | ||
"inline", | ||
"inline-block", | ||
"inline-flex", | ||
"inline-grid" | ||
); | ||
var contentPosition = tuple("left", "right"); | ||
var normalAlignments = tuple("start", "center", "end"); | ||
var excludedInputPropsForTextarea = tuple( | ||
"clearable", | ||
"as", | ||
"rounded", | ||
"labelLeft", | ||
"labelRight", | ||
"contentLeft", | ||
"contentRight", | ||
"contentClickable", | ||
"contentLeftStyling", | ||
"contentRightStyling", | ||
"onContentClick", | ||
"onClearClick", | ||
"css" | ||
); | ||
var selectionBehavior = tuple("toggle", "replace"); | ||
var selectionMode = tuple("none", "single", "multiple"); | ||
var dropdownVariants = tuple("flat", "light", "solid", "shadow"); | ||
var cardVariants = tuple("flat", "bordered", "shadow"); | ||
// src/color.ts | ||
var getCssVar = (name, parent = null) => { | ||
if (typeof document === "undefined" || !name) { | ||
return ""; | ||
} | ||
const target = parent || document.documentElement; | ||
const property = isCssVar(name) ? name.replace("var(", "").replace(")", "") : name.includes("--") ? name : `--${name}`; | ||
return getComputedStyle(target).getPropertyValue(property); | ||
}; | ||
var isCssVar = (property) => { | ||
return property && (property == null ? void 0 : property.indexOf("var(")) === 0 ? true : false; | ||
}; | ||
var isHex = (str) => { | ||
const exp = /#[a-fA-F0-9]{3,6}/g; | ||
return exp.test(str); | ||
}; | ||
var hexToRGBA = (hex, alpha = 1) => { | ||
let r = 0, g = 0, b = 0; | ||
if (hex.length == 4) { | ||
r = "0x" + hex[1] + hex[1]; | ||
g = "0x" + hex[2] + hex[2]; | ||
b = "0x" + hex[3] + hex[3]; | ||
} else if (hex.length == 7) { | ||
r = "0x" + hex[1] + hex[2]; | ||
g = "0x" + hex[3] + hex[4]; | ||
b = "0x" + hex[5] + hex[6]; | ||
} | ||
return `rgba(${+r},${+g},${+b},${alpha})`; | ||
}; | ||
var isNormalColor = (color) => { | ||
let c = color.includes("$") ? color.replace("$", "") : color; | ||
let found = normalColors.find((el) => el === c); | ||
return found !== void 0 && found !== null; | ||
}; | ||
var isSimpleColor = (color) => { | ||
let found = simpleColors.find((el) => el === color); | ||
return found !== void 0 && found !== null; | ||
}; | ||
var isColor = (strColor) => { | ||
let s = new Option().style; | ||
s.color = strColor; | ||
return s.color == strColor; | ||
}; | ||
var hexToRgb = (color) => { | ||
const fullReg = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; | ||
const full = color.replace(fullReg, (_, r, g, b) => `${r}${r}${g}${g}${b}${b}`); | ||
const values = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(full); | ||
if (!values) { | ||
throw new Error(`Next UI: Unsupported ${color} color.`); | ||
} | ||
return [ | ||
Number.parseInt(values[1], 16), | ||
Number.parseInt(values[2], 16), | ||
Number.parseInt(values[3], 16) | ||
]; | ||
}; | ||
var hexFromString = (str, defaultColor = "", returnLast = false) => { | ||
const fullReg = /#[a-fA-F0-9]{6}|#[a-fA-F0-9]{3}$/g; | ||
const hexCodes = str.match(fullReg); | ||
if (hexCodes && hexCodes.length > 0) { | ||
return returnLast ? hexCodes[hexCodes.length - 1] : hexCodes; | ||
} | ||
return defaultColor; | ||
}; | ||
var colorToRgbValues = (colorProp) => { | ||
const color = isCssVar(colorProp) ? getCssVar(colorProp) : colorProp; | ||
if (color.charAt(0) === "#") | ||
return hexToRgb(color); | ||
const safeColor = color.replace(/ /g, ""); | ||
const colorType = color.substr(0, 4); | ||
const regArray = safeColor.match(/\((.+)\)/); | ||
if (!colorType.startsWith("rgb") || !regArray) { | ||
console.warn(`NextUI: Only supports ["RGB", "RGBA", "HEX"] color.`); | ||
return [0, 0, 0]; | ||
} | ||
return regArray[1].split(",").map((str) => Number.parseFloat(str)); | ||
}; | ||
var addColorAlpha = (colorProp, alpha = 1) => { | ||
if (!colorProp) | ||
return ""; | ||
const color = isCssVar(colorProp) ? getCssVar(colorProp) : colorProp; | ||
if (isHex(color)) { | ||
return hexToRGBA(color, alpha); | ||
} else if (!/^#|rgb|RGB/.test(color)) { | ||
return color; | ||
} | ||
const [r, g, b] = colorToRgbValues(color); | ||
const safeAlpha = alpha > 1 ? 1 : alpha < 0 ? 0 : alpha; | ||
return `rgba(${r}, ${g}, ${b}, ${safeAlpha})`; | ||
}; | ||
var rgbToRgba = (rgb, alpha = 1) => { | ||
const [r, g, b] = rgb.split(",").map((str) => Number.parseFloat(str)); | ||
const safeAlpha = alpha > 1 ? 1 : alpha < 0 ? 0 : alpha; | ||
return `rgba(${r}, ${g}, ${b}, ${safeAlpha})`; | ||
}; | ||
function padZero(str, len) { | ||
len = len || 2; | ||
var zeros = new Array(len).join("0"); | ||
return (zeros + str).slice(-len); | ||
} | ||
var invertHex = (hexProp, smooth = true) => { | ||
let hex = isCssVar(hexProp) ? getCssVar(hexProp) : hexProp; | ||
if (hex.indexOf("#") === 0) { | ||
hex = hex.slice(1); | ||
} | ||
if (hex.length === 3) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
if (hex.length !== 6) { | ||
return hexProp; | ||
} | ||
let r = parseInt(hex.slice(0, 2), 16), g = parseInt(hex.slice(2, 4), 16), b = parseInt(hex.slice(4, 6), 16); | ||
if (smooth) { | ||
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? "#000000" : "#FFFFFF"; | ||
} | ||
r = 255 - r; | ||
g = 255 - g; | ||
b = 255 - b; | ||
return "#" + padZero(r.toString(16)) + padZero(g.toString(16)) + padZero(b.toString(16)); | ||
}; | ||
function getCSSColor(color, defaultColor = "$colors$text") { | ||
if (!color) { | ||
return defaultColor; | ||
} | ||
if (isNormalColor(color)) { | ||
switch (color) { | ||
case "default": | ||
return defaultColor; | ||
default: | ||
return `$colors$${color}`; | ||
} | ||
} | ||
if ((color == null ? void 0 : color.startsWith("$")) && (color == null ? void 0 : color.includes("$colors"))) { | ||
return `$colors$${color}`; | ||
} | ||
return color; | ||
} | ||
// src/object.ts | ||
@@ -624,26 +255,2 @@ var renameProp = (oldProp, newProp, { [oldProp]: old, ...others }) => ({ | ||
// src/context.ts | ||
var React = __toESM(require("react")); | ||
function createContext2(options = {}) { | ||
const { | ||
strict = true, | ||
errorMessage = "useContext: `context` is undefined. Seems you forgot to wrap component within the Provider", | ||
name | ||
} = options; | ||
const Context = React.createContext(void 0); | ||
Context.displayName = name; | ||
function useContext2() { | ||
var _a; | ||
const context = React.useContext(Context); | ||
if (!context && strict) { | ||
const error = new Error(errorMessage); | ||
error.name = "ContextError"; | ||
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, error, useContext2); | ||
throw error; | ||
} | ||
return context; | ||
} | ||
return [Context.Provider, useContext2, Context]; | ||
} | ||
// src/numbers.ts | ||
@@ -670,24 +277,2 @@ function range(start, end) { | ||
} | ||
// src/react.ts | ||
var import_react = require("react"); | ||
function getValidChildren(children) { | ||
return import_react.Children.toArray(children).filter( | ||
(child) => (0, import_react.isValidElement)(child) | ||
); | ||
} | ||
var pickChildren = (children, targetChild) => { | ||
let target = []; | ||
const withoutTargetChildren = import_react.Children.map(children, (item) => { | ||
if (!(0, import_react.isValidElement)(item)) | ||
return item; | ||
if (item.type === targetChild) { | ||
target.push(item); | ||
return null; | ||
} | ||
return item; | ||
}); | ||
const targetChildren = target.length >= 0 ? target : void 0; | ||
return [withoutTargetChildren, targetChildren]; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -697,5 +282,3 @@ 0 && (module.exports = { | ||
__TEST__, | ||
addColorAlpha, | ||
arrayToObject, | ||
assignRef, | ||
callAll, | ||
@@ -707,14 +290,6 @@ callAllHandlers, | ||
clsx, | ||
colorToRgbValues, | ||
compact, | ||
copyObject, | ||
createContext, | ||
dataAttr, | ||
excludedInputPropsForTextarea, | ||
extendedColors, | ||
extendedColorsNoGradient, | ||
extraColors, | ||
extractProperty, | ||
getCSSColor, | ||
getCssVar, | ||
getKeyValue, | ||
@@ -724,10 +299,3 @@ getMargin, | ||
getUniqueID, | ||
getValidChildren, | ||
hexFromString, | ||
hexToRGBA, | ||
hexToRgb, | ||
invertHex, | ||
isArray, | ||
isColor, | ||
isCssVar, | ||
isEmpty, | ||
@@ -737,22 +305,9 @@ isEmptyArray, | ||
isFunction, | ||
isHex, | ||
isNormalColor, | ||
isNumeric, | ||
isObject, | ||
isSimpleColor, | ||
mergeRefs, | ||
normalColors, | ||
normalLoaders, | ||
normalWeights, | ||
omitObject, | ||
pickChildren, | ||
range, | ||
renameProp, | ||
rgbToRgba, | ||
safeText, | ||
simpleColors, | ||
textTransforms, | ||
textWeights, | ||
tuple, | ||
warn | ||
}); |
{ | ||
"name": "@nextui-org/shared-utils", | ||
"version": "0.0.0-dev-v2-20230613135041", | ||
"version": "0.0.0-dev-v2-20230613212244", | ||
"description": "A set of NextUI utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
0
37918
42
1295