MCPcopy Create free account
hub / github.com/chakra-ui/panda / stringify

Function stringify

packages/core/src/stringify.ts:18–138  ·  view source on GitHub ↗
(
  /** Style object defintion. */
  value: Dict,
)

Source from the content-addressed store, hash-verified

16
17/** Returns a string of CSS from an object of CSS. */
18export function stringify(
19 /** Style object defintion. */
20 value: Dict,
21) {
22 /** Set used to manage the opened and closed state of rules. */
23 const used = new WeakSet()
24
25 const write = (
26 cssText: string,
27 selectors: StringifyContext['selectors'],
28 conditions: String[],
29 name: string,
30 data: string | number | boolean,
31 isAtRuleLike: boolean,
32 isVariableLike: boolean,
33 ) => {
34 if (data === false) return ''
35
36 // Add conditions
37 for (let i = 0; i < conditions.length; ++i) {
38 if (!used.has(conditions[i])) {
39 used.add(conditions[i])
40 cssText += `${conditions[i]} {`
41 }
42 }
43
44 // Then selectors
45 if (selectors.length && !used.has(selectors)) {
46 used.add(selectors)
47 cssText += `${selectors.map((s) => s.replace('& ', ''))} {`
48 }
49
50 let value = data
51
52 if (typeof value === 'number') {
53 const shouldAddPx = !(value === 0 || unitlessProperties.has(name) || isVariableLike)
54 if (shouldAddPx) {
55 value = `${value}px`
56 }
57 }
58
59 // Format property
60 if (isAtRuleLike) {
61 name = `${name} `
62 } else if (isVariableLike) {
63 name = `${name}: `
64 } else {
65 name = `${hypenateProperty(name)}: `
66 }
67
68 // Add it to the CSS string
69 cssText += `${name + String(value)};\n`
70
71 return cssText
72 }
73
74 const parse = (style: Dict, selectors: Array<string>, conditions: String[]) => {
75 let cssText = ''

Callers 10

generateKeyframeCssFunction · 0.90
stringifyVarsFunction · 0.90
stringifyGlobalVarsFunction · 0.90
stringifyPositionTryFunction · 0.90
stringifyFontfaceFunction · 0.90
processMethod · 0.90
StylesheetClass · 0.90
stringify.test.tsFile · 0.90
loadFunction · 0.50
unionTypeFunction · 0.50

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected