MCPcopy
hub / github.com/GrapesJS/grapesjs / build

Method build

packages/core/src/code_manager/model/CssGenerator.ts:91–165  ·  view source on GitHub ↗
(model: Component, opts: CssGeneratorBuildOptionsProps = {})

Source from the content-addressed store, hash-verified

89 }
90
91 build(model: Component, opts: CssGeneratorBuildOptionsProps = {}) {
92 const { json } = opts;
93 const em = opts.em;
94 const cssc = opts.cssc || em?.Css;
95 this.em = em;
96 this.compCls = [];
97 this.ids = [];
98 this.model = model;
99 const codeJson: CssRule[] = [];
100 let code = model ? this.buildFromModel(model, opts) : '';
101 const clearStyles = isUndefined(opts.clearStyles) && em ? em.getConfig().clearStyles : opts.clearStyles;
102
103 if (cssc) {
104 let rules: CssRules | CssRule[] = opts.rules || cssc.getAll();
105 const atRules: AtRules = {};
106 const dump: CssRule[] = [];
107
108 if (opts.onlyMatched && model && hasWin()) {
109 rules = this.matchedRules(model, rules);
110 }
111
112 rules.forEach((rule) => {
113 if (rule.isNested()) return;
114
115 const atRule = rule.getAtRule();
116
117 if (atRule) {
118 const mRules = atRules[atRule];
119 if (mRules) {
120 mRules.push(rule);
121 } else {
122 atRules[atRule] = [rule];
123 }
124 return;
125 }
126
127 const res = this.buildFromRule(rule, dump, opts);
128
129 if (json) {
130 codeJson.push(res as CssRule);
131 } else {
132 code += res;
133 }
134 });
135
136 this.sortMediaObject(atRules).forEach((item) => {
137 let rulesStr = '';
138 const atRule = item.key;
139 const mRules = item.value;
140
141 mRules.forEach((rule) => {
142 if (rule.isNested()) return;
143
144 const ruleStr = this.buildFromRule(rule, dump, opts);
145
146 if (rule.get('singleAtRule')) {
147 code += `${atRule}{${ruleStr}}`;
148 } else {

Callers

nothing calls this directly

Calls 12

buildFromModelMethod · 0.95
matchedRulesMethod · 0.95
buildFromRuleMethod · 0.95
sortMediaObjectMethod · 0.95
hasWinFunction · 0.90
isUndefinedFunction · 0.85
isNestedMethod · 0.80
getAtRuleMethod · 0.80
getConfigMethod · 0.45
getAllMethod · 0.45
getMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected