|
48 | 48 | import { |
49 | 49 | BarSchemes, |
50 | 50 | BarTypes, |
| 51 | + BackgroundTypes, |
51 | 52 | ColorSchemes, |
52 | | - StyleSetTypes |
| 53 | + StyleSetTypes, |
| 54 | + Alignments |
53 | 55 | } from "../../service/canvas/Constants"; |
54 | 56 | import ABar from "../atoms/ABar"; |
55 | 57 |
|
|
70 | 72 | colorSchema: 'canvas/getColorSchema', |
71 | 73 | bars: 'canvas/getBars', |
72 | 74 | textFitsImage: 'canvas/getTextFitsImage', |
| 75 | + backgroundType: 'canvas/getBackgroundType', |
73 | 76 | }), |
74 | 77 |
|
75 | 78 | fontSizePercent: { |
|
131 | 134 | ) |
132 | 135 | }, |
133 | 136 |
|
| 137 | + updateBarSchemas() { |
| 138 | + // Handle bars based on layout and color scheme |
| 139 | + if (this.bars.length > 0 && this.bars[0].type === BarTypes.headline) { |
| 140 | + const schema = this.getSchemaForBar(0); |
| 141 | + this.$store.dispatch('canvas/setBar', { |
| 142 | + index: 0, |
| 143 | + bar: { ...this.bars[0], schema } |
| 144 | + }); |
| 145 | + } |
| 146 | +
|
| 147 | + // Force the second headline to use the scheme for current layout |
| 148 | + if (this.bars.length > 1 && this.bars[1].type === BarTypes.headline) { |
| 149 | + const schema = this.getSchemaForBar(1); |
| 150 | + this.$store.dispatch('canvas/setBar', { |
| 151 | + index: 1, |
| 152 | + bar: { ...this.bars[1], schema } |
| 153 | + }); |
| 154 | + } |
| 155 | +
|
| 156 | + // Handle third headline bar if present (for green layout with 3 headline bars) |
| 157 | + if (this.bars.length > 2 && this.bars[2].type === BarTypes.headline && |
| 158 | + !(this.styleSet === StyleSetTypes.green2025 || this.styleSet === StyleSetTypes.green2025Centered)) { |
| 159 | + this.$store.dispatch('canvas/setBar', { |
| 160 | + index: 2, |
| 161 | + bar: { ...this.bars[2], schema: BarSchemes.magenta } |
| 162 | + }); |
| 163 | + } |
| 164 | +
|
| 165 | + // For subline, use the computed sublineSchema which is based on current style set |
| 166 | + if (this.bars.length > 2 && this.bars[2].type === BarTypes.subline) { |
| 167 | + this.$store.dispatch('canvas/setBar', { |
| 168 | + index: 2, |
| 169 | + bar: { ...this.bars[2], schema: this.sublineSchema } |
| 170 | + }); |
| 171 | + } |
| 172 | + }, |
| 173 | +
|
| 174 | + getSchemaForBar(index) { |
| 175 | + // Green2025 layout |
| 176 | + if (this.styleSet === StyleSetTypes.green2025 || this.styleSet === StyleSetTypes.green2025Centered) { |
| 177 | + return BarSchemes.green2025; |
| 178 | + } |
| 179 | +
|
| 180 | + // Young layout |
| 181 | + if (this.styleSet === StyleSetTypes.young) { |
| 182 | + if(index === 0) { |
| 183 | + return (this.colorSchema === ColorSchemes.white) |
| 184 | + ? BarSchemes.white |
| 185 | + : BarSchemes.green; |
| 186 | + } else { |
| 187 | + return BarSchemes.magenta; |
| 188 | + } |
| 189 | + } |
| 190 | +
|
| 191 | + // Green layout |
| 192 | + const backgroundRequiresGreen = |
| 193 | + this.backgroundType === BackgroundTypes.transparent || |
| 194 | + this.backgroundType === BackgroundTypes.image; |
| 195 | +
|
| 196 | + if (index === 0 || (index === 1 && this.bars.length >2 && this.bars[2].type === BarTypes.headline)) { |
| 197 | + return backgroundRequiresGreen ? BarSchemes.green : BarSchemes.white; |
| 198 | + } |
| 199 | +
|
| 200 | + return BarSchemes.magenta; |
| 201 | + }, |
| 202 | +
|
134 | 203 | maybeRemoveSubline() { |
135 | 204 | // remove sublines for style set young |
136 | 205 | if (this.styleSet === StyleSetTypes.young) { |
|
148 | 217 | // remove first primary headline if there are two |
149 | 218 | const primaryHeadlines = this.bars.filter( |
150 | 219 | bar => bar.type === BarTypes.headline |
151 | | - && (bar.schema === BarSchemes.white || bar.schema === BarSchemes.green) |
| 220 | + && (bar.schema === BarSchemes.white || |
| 221 | + bar.schema === BarSchemes.green || |
| 222 | + bar.schema === BarSchemes.green2025) |
152 | 223 | ); |
153 | 224 | if (primaryHeadlines.length > 1) { |
154 | 225 | this.$store.commit('canvas/removeBar', {index: 0}) |
|
157 | 228 | // remove first secondary headline if there are two |
158 | 229 | const secondaryHeadlines = this.bars.filter( |
159 | 230 | bar => bar.type === BarTypes.headline |
160 | | - && (bar.schema === BarSchemes.magenta) |
| 231 | + && (bar.schema === BarSchemes.magenta || |
| 232 | + bar.schema === BarSchemes.transparent2025) |
161 | 233 | ); |
162 | 234 | if (secondaryHeadlines.length > 1) { |
163 | 235 | this.$store.commit('canvas/removeBar', {index: 1}) |
164 | 236 | } |
165 | 237 | } |
| 238 | + }, |
| 239 | +
|
| 240 | + maybeAddHeadline() { |
| 241 | + // Green and young layouts need at least 2 headline bars |
| 242 | + if ((this.styleSet !== StyleSetTypes.green2025 && |
| 243 | + this.styleSet !== StyleSetTypes.green2025Centered) && |
| 244 | + this.bars.filter(bar => bar.type === BarTypes.headline).length === 1) { |
| 245 | +
|
| 246 | + const secondHeadline = { |
| 247 | + type: BarTypes.headline, |
| 248 | + schema: BarSchemes.magenta, |
| 249 | + text: 'Headline', |
| 250 | + canvas: null, |
| 251 | + padding: 0, |
| 252 | + }; |
| 253 | +
|
| 254 | + this.$store.dispatch( |
| 255 | + 'canvas/addBar', |
| 256 | + {index: 1, bar: secondHeadline} |
| 257 | + ); |
| 258 | + } |
166 | 259 | } |
167 | 260 | }, |
168 | 261 |
|
169 | 262 | watch: { |
170 | 263 | styleSet() { |
171 | | - this.maybeRemoveSubline() |
172 | | - this.maybeRemoveHeadline() |
| 264 | + this.maybeRemoveSubline(); |
| 265 | + this.maybeRemoveHeadline(); |
| 266 | + this.maybeAddHeadline(); |
| 267 | +
|
| 268 | + // Handle alignment based on style set |
| 269 | + const currentAlignment = this.$store.getters['canvas/getAlignment']; |
| 270 | +
|
| 271 | + if ((this.styleSet === StyleSetTypes.green || this.styleSet === StyleSetTypes.green2025) && |
| 272 | + currentAlignment !== Alignments.left) { |
| 273 | + this.$store.dispatch('canvas/setAlignment', Alignments.left); |
| 274 | + } else if (this.styleSet === StyleSetTypes.greenCentered || |
| 275 | + this.styleSet === StyleSetTypes.green2025Centered || |
| 276 | + this.styleSet === StyleSetTypes.young) { |
| 277 | + this.$store.dispatch('canvas/setAlignment', Alignments.center); |
| 278 | + } |
| 279 | +
|
| 280 | + this.$nextTick(() => { |
| 281 | + this.updateBarSchemas(); |
| 282 | + }); |
| 283 | + }, |
| 284 | + colorSchema() { |
| 285 | + this.$nextTick(() => { |
| 286 | + this.updateBarSchemas(); |
| 287 | + }); |
173 | 288 | }, |
174 | 289 | textFitsImage(val) { |
175 | 290 | if (!val) { |
|
0 commit comments