@pandacss/shared
Advanced tools
Comparing version 0.0.0-dev-20230119005608 to 0.0.0-dev-20230119080852
@@ -1,3 +0,3 @@ | ||
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './merge-fe9cd267.js'; | ||
export { C as CreateCssContext, M as MappedObject, k as WalkObjectOptions, W as WalkObjectStopFn, d as compact, c as createCss, j as deepMerge, f as filterBaseConditions, e as isBaseCondition, a as isFunction, g as isImportant, b as isObject, i as isString, m as mapObject, t as toHash, l as walkObject, w as withoutImportant, h as withoutSpace } from './merge-fe9cd267.js'; | ||
import { W as WalkObjectStopFn, M as MappedObject, C as CreateCssContext } from './split-props-29274d16.js'; | ||
export { C as CreateCssContext, M as MappedObject, k as WalkObjectOptions, W as WalkObjectStopFn, e as compact, c as createCss, d as createMergeCss, g as filterBaseConditions, f as isBaseCondition, a as isFunction, h as isImportant, b as isObject, i as isString, n as mapObject, m as mergeProps, s as splitProps, t as toHash, l as walkObject, w as withoutImportant, j as withoutSpace } from './split-props-29274d16.js'; | ||
@@ -37,2 +37,3 @@ type Operand = string | number | { | ||
type NormalizeContext = Pick<CreateCssContext, 'utility' | 'conditions'>; | ||
declare function normalizeShorthand(styles: Record<string, any>, context: NormalizeContext): MappedObject<Record<string, any>, any>; | ||
declare function normalizeStyleObject(styles: Record<string, any>, context: NormalizeContext): MappedObject<Record<string, any>, any>; | ||
@@ -45,6 +46,2 @@ | ||
type Dict = Record<string, unknown>; | ||
type PickFn = (key: string) => boolean; | ||
declare function splitObject(obj: Dict, pickFn: PickFn): Dict[]; | ||
type MapToRecord<K extends Map<string, any>> = { | ||
@@ -57,2 +54,2 @@ [P in keyof K]: K[P] extends Map<string, infer V> ? Record<string, V> : never; | ||
export { CssVar, CssVarOptions, calc, capitalize, cssVar, dashCase, esc, flatten, getDotPath, getNegativePath, getUnit, mapToJson, memo, normalizeStyleObject, splitBy, splitDotPath, splitObject, toEm, toPx, toRem, uncapitalize, unionType }; | ||
export { CssVar, CssVarOptions, calc, capitalize, cssVar, dashCase, esc, flatten, getDotPath, getNegativePath, getUnit, mapToJson, memo, normalizeShorthand, normalizeStyleObject, splitBy, splitDotPath, toEm, toPx, toRem, uncapitalize, unionType }; |
@@ -27,5 +27,5 @@ "use strict"; | ||
createCss: () => createCss, | ||
createMergeCss: () => createMergeCss, | ||
cssVar: () => cssVar, | ||
dashCase: () => dashCase, | ||
deepMerge: () => deepMerge, | ||
esc: () => esc2, | ||
@@ -45,6 +45,8 @@ filterBaseConditions: () => filterBaseConditions, | ||
memo: () => memo, | ||
mergeProps: () => mergeProps, | ||
normalizeShorthand: () => normalizeShorthand, | ||
normalizeStyleObject: () => normalizeStyleObject, | ||
splitBy: () => splitBy, | ||
splitDotPath: () => splitDotPath, | ||
splitObject: () => splitObject, | ||
splitProps: () => splitProps, | ||
toEm: () => toEm, | ||
@@ -93,2 +95,7 @@ toHash: () => toHash, | ||
// src/compact.ts | ||
function compact(value) { | ||
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0)); | ||
} | ||
// src/condition.ts | ||
@@ -120,2 +127,17 @@ var isBaseCondition = (v) => v === "base"; | ||
// src/merge-props.ts | ||
function mergeProps(...sources) { | ||
const result = {}; | ||
for (const source of sources) { | ||
for (const [key, value] of Object.entries(source)) { | ||
if (isObject(value)) { | ||
result[key] = mergeProps(result[key] || {}, value); | ||
} else { | ||
result[key] = value; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
// src/walk-object.ts | ||
@@ -157,2 +179,10 @@ function walkObject(target, predicate, options = {}) { | ||
} | ||
function normalizeShorthand(styles, context) { | ||
const { hasShorthand, resolveShorthand } = context.utility; | ||
return walkObject(styles, (v) => v, { | ||
getKey: (prop) => { | ||
return hasShorthand ? resolveShorthand(prop) : prop; | ||
} | ||
}); | ||
} | ||
function normalizeStyleObject(styles, context) { | ||
@@ -205,7 +235,20 @@ const { utility, conditions } = context; | ||
} | ||
// src/compact.ts | ||
function compact(value) { | ||
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0)); | ||
function compactStyles(...styles) { | ||
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0); | ||
} | ||
function createMergeCss(context) { | ||
function resolve(styles) { | ||
const allStyles = compactStyles(...styles); | ||
if (allStyles.length === 1) | ||
return allStyles; | ||
return allStyles.map((style) => normalizeShorthand(style, context)); | ||
} | ||
function mergeCss(...styles) { | ||
return mergeProps(...resolve(styles)); | ||
} | ||
function assignCss(...styles) { | ||
return Object.assign({}, ...resolve(styles)); | ||
} | ||
return { mergeCss, assignCss }; | ||
} | ||
@@ -320,21 +363,2 @@ // src/css-unit.ts | ||
// src/merge.ts | ||
function deepMerge(...sources) { | ||
const allSources = sources.filter(isObject); | ||
if (allSources.length === 1) { | ||
return allSources[0]; | ||
} | ||
const result = {}; | ||
for (const source of allSources) { | ||
for (const [key, value] of Object.entries(source)) { | ||
if (isObject(value)) { | ||
result[key] = deepMerge(result[key] || {}, value); | ||
} else { | ||
result[key] = value; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
// src/split.ts | ||
@@ -389,14 +413,19 @@ function splitBy(value, separator = ",") { | ||
// src/split-object.ts | ||
function splitObject(obj, pickFn) { | ||
const omitted = {}; | ||
const picked = {}; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (pickFn(key)) { | ||
picked[key] = value; | ||
} else { | ||
omitted[key] = value; | ||
// src/split-props.ts | ||
function splitProps(props, ...keys) { | ||
const descriptors = Object.getOwnPropertyDescriptors(props); | ||
const dKeys = Object.keys(descriptors); | ||
const split = (k) => { | ||
const clone = {}; | ||
for (let i = 0; i < k.length; i++) { | ||
const key = k[i]; | ||
if (descriptors[key]) { | ||
Object.defineProperty(clone, key, descriptors[key]); | ||
delete descriptors[key]; | ||
} | ||
} | ||
} | ||
return [picked, omitted]; | ||
return clone; | ||
}; | ||
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key)); | ||
return keys.map(fn).concat(split(dKeys)); | ||
} | ||
@@ -427,5 +456,5 @@ | ||
createCss, | ||
createMergeCss, | ||
cssVar, | ||
dashCase, | ||
deepMerge, | ||
esc, | ||
@@ -445,6 +474,8 @@ filterBaseConditions, | ||
memo, | ||
mergeProps, | ||
normalizeShorthand, | ||
normalizeStyleObject, | ||
splitBy, | ||
splitDotPath, | ||
splitObject, | ||
splitProps, | ||
toEm, | ||
@@ -451,0 +482,0 @@ toHash, |
@@ -1,1 +0,10 @@ | ||
export { d as compact, c as createCss, j as deepMerge, f as filterBaseConditions, e as isBaseCondition, b as isObject, m as mapObject, t as toHash, l as walkObject, h as withoutSpace } from './merge-fe9cd267.js'; | ||
export { e as compact, c as createCss, d as createMergeCss, g as filterBaseConditions, f as isBaseCondition, b as isObject, n as mapObject, m as mergeProps, s as splitProps, t as toHash, l as walkObject, j as withoutSpace } from './split-props-29274d16.js'; | ||
declare function normalizeHTMLProps(props: Record<string, any>): { | ||
[k: string]: any; | ||
}; | ||
declare namespace normalizeHTMLProps { | ||
var keys: string[]; | ||
} | ||
export { normalizeHTMLProps }; |
@@ -25,3 +25,3 @@ "use strict"; | ||
createCss: () => createCss, | ||
deepMerge: () => deepMerge, | ||
createMergeCss: () => createMergeCss, | ||
filterBaseConditions: () => filterBaseConditions, | ||
@@ -31,2 +31,5 @@ isBaseCondition: () => isBaseCondition, | ||
mapObject: () => mapObject, | ||
mergeProps: () => mergeProps, | ||
normalizeHTMLProps: () => normalizeHTMLProps, | ||
splitProps: () => splitProps, | ||
toHash: () => toHash, | ||
@@ -43,2 +46,7 @@ walkObject: () => walkObject, | ||
// src/compact.ts | ||
function compact(value) { | ||
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0)); | ||
} | ||
// src/condition.ts | ||
@@ -70,2 +78,17 @@ var isBaseCondition = (v) => v === "base"; | ||
// src/merge-props.ts | ||
function mergeProps(...sources) { | ||
const result = {}; | ||
for (const source of sources) { | ||
for (const [key, value] of Object.entries(source)) { | ||
if (isObject(value)) { | ||
result[key] = mergeProps(result[key] || {}, value); | ||
} else { | ||
result[key] = value; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
// src/walk-object.ts | ||
@@ -107,2 +130,10 @@ function walkObject(target, predicate, options = {}) { | ||
} | ||
function normalizeShorthand(styles, context) { | ||
const { hasShorthand, resolveShorthand } = context.utility; | ||
return walkObject(styles, (v) => v, { | ||
getKey: (prop) => { | ||
return hasShorthand ? resolveShorthand(prop) : prop; | ||
} | ||
}); | ||
} | ||
function normalizeStyleObject(styles, context) { | ||
@@ -155,25 +186,48 @@ const { utility, conditions } = context; | ||
} | ||
function compactStyles(...styles) { | ||
return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0); | ||
} | ||
function createMergeCss(context) { | ||
function resolve(styles) { | ||
const allStyles = compactStyles(...styles); | ||
if (allStyles.length === 1) | ||
return allStyles; | ||
return allStyles.map((style) => normalizeShorthand(style, context)); | ||
} | ||
function mergeCss(...styles) { | ||
return mergeProps(...resolve(styles)); | ||
} | ||
function assignCss(...styles) { | ||
return Object.assign({}, ...resolve(styles)); | ||
} | ||
return { mergeCss, assignCss }; | ||
} | ||
// src/compact.ts | ||
function compact(value) { | ||
return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0)); | ||
// src/normalize-html.ts | ||
var htmlProps = ["htmlSize", "htmlTranslate", "htmlWidth", "htmlHeight"]; | ||
function convert(key) { | ||
return htmlProps.includes(key) ? key.replace("html", "").toLowerCase() : key; | ||
} | ||
function normalizeHTMLProps(props) { | ||
return Object.fromEntries(Object.entries(props).map(([key, value]) => [convert(key), value])); | ||
} | ||
normalizeHTMLProps.keys = htmlProps; | ||
// src/merge.ts | ||
function deepMerge(...sources) { | ||
const allSources = sources.filter(isObject); | ||
if (allSources.length === 1) { | ||
return allSources[0]; | ||
} | ||
const result = {}; | ||
for (const source of allSources) { | ||
for (const [key, value] of Object.entries(source)) { | ||
if (isObject(value)) { | ||
result[key] = deepMerge(result[key] || {}, value); | ||
} else { | ||
result[key] = value; | ||
// src/split-props.ts | ||
function splitProps(props, ...keys) { | ||
const descriptors = Object.getOwnPropertyDescriptors(props); | ||
const dKeys = Object.keys(descriptors); | ||
const split = (k) => { | ||
const clone = {}; | ||
for (let i = 0; i < k.length; i++) { | ||
const key = k[i]; | ||
if (descriptors[key]) { | ||
Object.defineProperty(clone, key, descriptors[key]); | ||
delete descriptors[key]; | ||
} | ||
} | ||
} | ||
return result; | ||
return clone; | ||
}; | ||
const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key)); | ||
return keys.map(fn).concat(split(dKeys)); | ||
} | ||
@@ -184,3 +238,3 @@ // Annotate the CommonJS export names for ESM import in node: | ||
createCss, | ||
deepMerge, | ||
createMergeCss, | ||
filterBaseConditions, | ||
@@ -190,2 +244,5 @@ isBaseCondition, | ||
mapObject, | ||
mergeProps, | ||
normalizeHTMLProps, | ||
splitProps, | ||
toHash, | ||
@@ -192,0 +249,0 @@ walkObject, |
{ | ||
"name": "@pandacss/shared", | ||
"version": "0.0.0-dev-20230119005608", | ||
"version": "0.0.0-dev-20230119080852", | ||
"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
44938
1390