@pandacss/shared
Advanced tools
Comparing version 0.35.0 to 0.36.0
@@ -1,3 +0,3 @@ | ||
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './shared-4wnn7ulW.js'; | ||
export { x as WalkObjectOptions, f as compact, d as createCss, e as createMergeCss, h as filterBaseConditions, q as getPatternStyles, s as getSlotCompoundVariant, r as getSlotRecipes, l as hypenateProperty, g as isBaseCondition, a as isBoolean, b as isFunction, j as isImportant, c as isObject, i as isString, z as mapObject, m as markImportant, n as memo, o as mergeProps, p as patternFns, u as splitProps, t as toHash, v as uniq, y as walkObject, w as withoutImportant, k as withoutSpace } from './shared-4wnn7ulW.js'; | ||
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './shared-5yRolXii.js'; | ||
export { x as WalkObjectOptions, f as compact, d as createCss, e as createMergeCss, h as filterBaseConditions, q as getPatternStyles, s as getSlotCompoundVariant, r as getSlotRecipes, j as hypenateProperty, g as isBaseCondition, a as isBoolean, b as isFunction, k as isImportant, c as isObject, i as isString, z as mapObject, m as markImportant, n as memo, o as mergeProps, p as patternFns, u as splitProps, t as toHash, v as uniq, y as walkObject, w as withoutImportant, l as withoutSpace } from './shared-5yRolXii.js'; | ||
export { astish } from './astish.js'; | ||
@@ -7,2 +7,4 @@ | ||
declare function assign(target: any, ...sources: any[]): any; | ||
type Operand = string | number | { | ||
@@ -21,7 +23,2 @@ ref: string; | ||
declare function getUnit(value?: string): string | undefined; | ||
declare function toPx(value?: string | number): string | undefined; | ||
declare function toEm(value?: string, fontSize?: number): string | undefined; | ||
declare function toRem(value?: string): string | undefined; | ||
interface CssVar { | ||
@@ -74,2 +71,4 @@ var: `--${string}`; | ||
declare function mergeWith(target: any, ...sources: any[]): any; | ||
type NormalizeContext = Pick<CreateCssContext, 'utility' | 'conditions'>; | ||
@@ -79,2 +78,4 @@ declare function toResponsiveObject(values: string[], breakpoints: string[]): Record<string, string>; | ||
declare const omit: <T, K extends (string & {}) | keyof T>(obj: T, paths: K[]) => Omit<T, K>; | ||
declare const createRegex: (item: Array<string | RegExp>) => RegExp; | ||
@@ -135,2 +136,7 @@ | ||
export { CreateCssContext, type CssVar, type CssVarOptions, type MapToRecord, MappedObject, PandaError, type PandaErrorCode, WalkObjectStopFn, calc, camelCaseProperty, capitalize, createRegex, cssVar, dashCase, deepSet, entries, esc, flatten, fromEntries, getArbitraryValue, getDotPath, getNegativePath, getOrCreateSet, getPropertyPriority, getUnit, isCssFunction, isCssUnit, isCssVar, isObjectOrArray, mapEntries, mapToJson, normalizeStyleObject, parseJson, splitBy, splitDotPath, stringifyJson, toEm, toPx, toRem, toResponsiveObject, traverse, uncapitalize, unionType }; | ||
declare function getUnit(value?: string): string | undefined; | ||
declare function toPx(value?: string | number): string | undefined; | ||
declare function toEm(value?: string, fontSize?: number): string | undefined; | ||
declare function toRem(value?: string): string | undefined; | ||
export { CreateCssContext, type CssVar, type CssVarOptions, type MapToRecord, MappedObject, PandaError, type PandaErrorCode, WalkObjectStopFn, assign, calc, camelCaseProperty, capitalize, createRegex, cssVar, dashCase, deepSet, entries, esc, flatten, fromEntries, getArbitraryValue, getDotPath, getNegativePath, getOrCreateSet, getPropertyPriority, getUnit, isCssFunction, isCssUnit, isCssVar, isObjectOrArray, mapEntries, mapToJson, mergeWith, normalizeStyleObject, omit, parseJson, splitBy, splitDotPath, stringifyJson, toEm, toPx, toRem, toResponsiveObject, traverse, uncapitalize, unionType }; |
@@ -24,2 +24,3 @@ "use strict"; | ||
PandaError: () => PandaError, | ||
assign: () => assign, | ||
astish: () => astish, | ||
@@ -67,3 +68,5 @@ calc: () => calc, | ||
mergeProps: () => mergeProps, | ||
mergeWith: () => mergeWith, | ||
normalizeStyleObject: () => normalizeStyleObject, | ||
omit: () => omit, | ||
parseJson: () => parseJson, | ||
@@ -123,2 +126,14 @@ patternFns: () => patternFns, | ||
// src/assign.ts | ||
function assign(target, ...sources) { | ||
for (const source of sources) { | ||
for (const key in source) { | ||
if (!target?.hasOwnProperty?.(key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
// src/astish.ts | ||
@@ -399,56 +414,2 @@ var newRule = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g; | ||
// src/unit-conversion.ts | ||
var BASE_FONT_SIZE = 16; | ||
var UNIT_PX = "px"; | ||
var UNIT_EM = "em"; | ||
var UNIT_REM = "rem"; | ||
function getUnit(value = "") { | ||
const DIGIT_REGEX = new RegExp(String.raw`-?\d+(?:\.\d+|\d*)`); | ||
const UNIT_REGEX = new RegExp(`${UNIT_PX}|${UNIT_EM}|${UNIT_REM}`); | ||
const unit = value.match(new RegExp(`${DIGIT_REGEX.source}(${UNIT_REGEX.source})`)); | ||
return unit?.[1]; | ||
} | ||
function toPx(value = "") { | ||
if (typeof value === "number") { | ||
return `${value}px`; | ||
} | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_PX) { | ||
return value; | ||
} | ||
if (unit === UNIT_EM || unit === UNIT_REM) { | ||
return `${parseFloat(value) * BASE_FONT_SIZE}${UNIT_PX}`; | ||
} | ||
} | ||
function toEm(value = "", fontSize = BASE_FONT_SIZE) { | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_EM) { | ||
return value; | ||
} | ||
if (unit === UNIT_PX) { | ||
return `${parseFloat(value) / fontSize}${UNIT_EM}`; | ||
} | ||
if (unit === UNIT_REM) { | ||
return `${parseFloat(value) * BASE_FONT_SIZE / fontSize}${UNIT_EM}`; | ||
} | ||
} | ||
function toRem(value = "") { | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_REM) { | ||
return value; | ||
} | ||
if (unit === UNIT_EM) { | ||
return `${parseFloat(value)}${UNIT_REM}`; | ||
} | ||
if (unit === UNIT_PX) { | ||
return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`; | ||
} | ||
} | ||
// src/css-var.ts | ||
@@ -600,2 +561,71 @@ var escRegex = /[^a-zA-Z0-9_\u0081-\uffff-]/g; | ||
// src/merge-with.ts | ||
function mergeWith(target, ...sources) { | ||
const customizer = sources.pop(); | ||
for (const source of sources) { | ||
for (const key in source) { | ||
const merged = customizer(target[key], source[key]); | ||
if (merged === void 0) { | ||
if (isObject(target[key]) && isObject(source[key])) { | ||
target[key] = mergeWith({}, target[key], source[key], customizer); | ||
} else { | ||
target[key] = source[key]; | ||
} | ||
} else { | ||
target[key] = merged; | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
// src/traverse.ts | ||
var isObjectOrArray = (obj) => typeof obj === "object" && obj !== null; | ||
var defaultOptions = { | ||
separator: ".", | ||
maxDepth: Infinity | ||
}; | ||
function traverse(obj, callback2, options = defaultOptions) { | ||
const maxDepth = options.maxDepth ?? defaultOptions.maxDepth; | ||
const separator = options.separator ?? defaultOptions.separator; | ||
const stack = [{ value: obj, path: "", paths: [], depth: -1, parent: null, key: "" }]; | ||
while (stack.length > 0) { | ||
const currentItem = stack.pop(); | ||
if (currentItem.parent !== null) { | ||
callback2(currentItem); | ||
} | ||
if (options.stop?.(currentItem)) { | ||
continue; | ||
} | ||
if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) { | ||
const keys = Object.keys(currentItem.value); | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
const value = currentItem.value[key]; | ||
const path = currentItem.path ? currentItem.path + separator + key : key; | ||
const paths = currentItem.paths.concat(key); | ||
stack.push({ | ||
value, | ||
path, | ||
paths, | ||
depth: currentItem.depth + 1, | ||
parent: currentItem.value, | ||
key | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
// src/omit.ts | ||
var omit = (obj, paths) => { | ||
const result = { ...obj }; | ||
traverse(result, ({ path, parent, key }) => { | ||
if (paths.includes(path)) { | ||
delete parent[key]; | ||
} | ||
}); | ||
return result; | ||
}; | ||
// src/pattern-fns.ts | ||
@@ -858,40 +888,2 @@ var patternFns = { | ||
// src/traverse.ts | ||
var isObjectOrArray = (obj) => typeof obj === "object" && obj !== null; | ||
var defaultOptions = { | ||
separator: ".", | ||
maxDepth: Infinity | ||
}; | ||
function traverse(obj, callback2, options = defaultOptions) { | ||
const maxDepth = options.maxDepth ?? defaultOptions.maxDepth; | ||
const separator = options.separator ?? defaultOptions.separator; | ||
const stack = [{ value: obj, path: "", paths: [], depth: -1, parent: null, key: "" }]; | ||
while (stack.length > 0) { | ||
const currentItem = stack.pop(); | ||
if (currentItem.parent !== null) { | ||
callback2(currentItem); | ||
} | ||
if (options.stop?.(currentItem)) { | ||
continue; | ||
} | ||
if (isObjectOrArray(currentItem.value) && currentItem.depth < maxDepth) { | ||
const keys = Object.keys(currentItem.value); | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
const value = currentItem.value[key]; | ||
const path = currentItem.path ? currentItem.path + separator + key : key; | ||
const paths = currentItem.paths.concat(key); | ||
stack.push({ | ||
value, | ||
path, | ||
paths, | ||
depth: currentItem.depth + 1, | ||
parent: currentItem.value, | ||
key | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
// src/typegen.ts | ||
@@ -904,5 +896,60 @@ function unionType(values) { | ||
var uniq = (...items) => items.filter(Boolean).reduce((acc, item) => Array.from(/* @__PURE__ */ new Set([...acc, ...item])), []); | ||
// src/unit-conversion.ts | ||
var BASE_FONT_SIZE = 16; | ||
var UNIT_PX = "px"; | ||
var UNIT_EM = "em"; | ||
var UNIT_REM = "rem"; | ||
function getUnit(value = "") { | ||
const DIGIT_REGEX = new RegExp(String.raw`-?\d+(?:\.\d+|\d*)`); | ||
const UNIT_REGEX = new RegExp(`${UNIT_PX}|${UNIT_EM}|${UNIT_REM}`); | ||
const unit = value.match(new RegExp(`${DIGIT_REGEX.source}(${UNIT_REGEX.source})`)); | ||
return unit?.[1]; | ||
} | ||
function toPx(value = "") { | ||
if (typeof value === "number") { | ||
return `${value}px`; | ||
} | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_PX) { | ||
return value; | ||
} | ||
if (unit === UNIT_EM || unit === UNIT_REM) { | ||
return `${parseFloat(value) * BASE_FONT_SIZE}${UNIT_PX}`; | ||
} | ||
} | ||
function toEm(value = "", fontSize = BASE_FONT_SIZE) { | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_EM) { | ||
return value; | ||
} | ||
if (unit === UNIT_PX) { | ||
return `${parseFloat(value) / fontSize}${UNIT_EM}`; | ||
} | ||
if (unit === UNIT_REM) { | ||
return `${parseFloat(value) * BASE_FONT_SIZE / fontSize}${UNIT_EM}`; | ||
} | ||
} | ||
function toRem(value = "") { | ||
const unit = getUnit(value); | ||
if (!unit) | ||
return value; | ||
if (unit === UNIT_REM) { | ||
return value; | ||
} | ||
if (unit === UNIT_EM) { | ||
return `${parseFloat(value)}${UNIT_REM}`; | ||
} | ||
if (unit === UNIT_PX) { | ||
return `${parseFloat(value) / BASE_FONT_SIZE}${UNIT_REM}`; | ||
} | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
PandaError, | ||
assign, | ||
astish, | ||
@@ -950,3 +997,5 @@ calc, | ||
mergeProps, | ||
mergeWith, | ||
normalizeStyleObject, | ||
omit, | ||
parseJson, | ||
@@ -953,0 +1002,0 @@ patternFns, |
@@ -1,1 +0,1 @@ | ||
export { f as compact, d as createCss, e as createMergeCss, h as filterBaseConditions, q as getPatternStyles, s as getSlotCompoundVariant, r as getSlotRecipes, l as hypenateProperty, g as isBaseCondition, c as isObject, z as mapObject, n as memo, o as mergeProps, p as patternFns, u as splitProps, t as toHash, v as uniq, y as walkObject, k as withoutSpace } from './shared-4wnn7ulW.js'; | ||
export { f as compact, d as createCss, e as createMergeCss, h as filterBaseConditions, q as getPatternStyles, s as getSlotCompoundVariant, r as getSlotRecipes, j as hypenateProperty, g as isBaseCondition, c as isObject, z as mapObject, n as memo, o as mergeProps, p as patternFns, u as splitProps, t as toHash, v as uniq, y as walkObject, l as withoutSpace } from './shared-5yRolXii.js'; |
{ | ||
"name": "@pandacss/shared", | ||
"version": "0.35.0", | ||
"version": "0.36.0", | ||
"description": "Shared utilities for css panda", | ||
@@ -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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105054
2785