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

Function write

packages/core/src/stringify.ts:25–72  ·  view source on GitHub ↗
(
    cssText: string,
    selectors: StringifyContext['selectors'],
    conditions: String[],
    name: string,
    data: string | number | boolean,
    isAtRuleLike: boolean,
    isVariableLike: boolean,
  )

Source from the content-addressed store, hash-verified

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 1

parseFunction · 0.85

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected