@designcrowd/library.brand-page 6.2.3 → 6.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/lib/src/{CreatedOnBrandCrowd-de-de-Cn0M-eZ1.js → CreatedOnBrandCrowd-de-de-ystrO2LW.js} +1 -1
  2. package/lib/src/{CreatedOnBrandCrowd-en-us-DRLMSDZr.js → CreatedOnBrandCrowd-en-us-BU7hNzTZ.js} +1 -1
  3. package/lib/src/{CreatedOnBrandCrowd-es-es-BglTu73U.js → CreatedOnBrandCrowd-es-es-CbuxneQ3.js} +1 -1
  4. package/lib/src/{CreatedOnBrandCrowd-fr-fr-Bj6YZ_el.js → CreatedOnBrandCrowd-fr-ca-BuNUGOFr.js} +1 -1
  5. package/lib/src/{CreatedOnBrandCrowd-fr-ca-Bj6YZ_el.js → CreatedOnBrandCrowd-fr-fr-BuNUGOFr.js} +1 -1
  6. package/lib/src/{CreatedOnBrandCrowd-pt-pt-DEoOmQ1F.js → CreatedOnBrandCrowd-pt-br-BehL88mc.js} +1 -1
  7. package/lib/src/{CreatedOnBrandCrowd-pt-br-DEoOmQ1F.js → CreatedOnBrandCrowd-pt-pt-BehL88mc.js} +1 -1
  8. package/lib/src/{CreatedOnDcom-de-de-BZ7gTt4Z.js → CreatedOnDcom-de-de-CMxjFZt9.js} +1 -1
  9. package/lib/src/{CreatedOnDcom-en-us-CD6Km5sH.js → CreatedOnDcom-en-us-2Cf6WBvx.js} +1 -1
  10. package/lib/src/{CreatedOnDcom-es-es-CNpZHvEl.js → CreatedOnDcom-es-es-CATNnbTq.js} +1 -1
  11. package/lib/src/{CreatedOnDcom-fr-ca-URS-ydJ1.js → CreatedOnDcom-fr-ca-DQtMfB-a.js} +1 -1
  12. package/lib/src/{CreatedOnDcom-fr-fr-D2AVeA3H.js → CreatedOnDcom-fr-fr-C1_FWOQf.js} +1 -1
  13. package/lib/src/{CreatedOnDcom-pt-br-C32frnFs.js → CreatedOnDcom-pt-br-C0QOCW0L.js} +1 -1
  14. package/lib/src/{CreatedOnDcom-pt-pt-TDYGjRXS.js → CreatedOnDcom-pt-pt-lHD-p6o4.js} +1 -1
  15. package/lib/src/brand-page/models/brand-page-context.model.d.ts +5 -0
  16. package/lib/src/brand-page/models/brand-page-context.model.js +8 -1
  17. package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.d.ts +21 -0
  18. package/lib/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.d.ts +21 -0
  19. package/lib/src/brand-page-maker/components/preview/Preview.mixin.d.ts +7 -0
  20. package/lib/src/brand-page-maker/components/quick-link-bar/QuickLinkBar.mixin.d.ts +21 -0
  21. package/lib/src/brand-page-maker/components/seo-settings/SeoPageSettings.mixin.d.ts +22 -1
  22. package/lib/src/brand-page-maker/components/seo-settings/UrlSettings.mixin.d.ts +21 -0
  23. package/lib/src/brand-page-maker/components/seo-settings/UseExistingDomainModal.mixin.d.ts +21 -0
  24. package/lib/src/brand-page-maker/components/template-preview/TemplatePreview.mixin.d.ts +21 -0
  25. package/lib/src/brand-page-maker/components/upgrade-to-premium-button/UpgradeToPremiumButton.mixin.d.ts +21 -0
  26. package/lib/src/brand-page-maker/composables/ai-chat/ai-builder-experiment.d.ts +10 -0
  27. package/lib/src/brand-page-maker/composables/ai-chat/ai-builder-experiment.js +11 -0
  28. package/lib/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.js +14 -4
  29. package/lib/src/brand-page-maker/stores/ai-thread/ai-website-builder-thread-store.d.ts +9 -2
  30. package/lib/src/brand-page-maker/stores/ai-thread/ai-website-builder-thread-store.js +20 -0
  31. package/lib/src/brand-page-maker/stores/brandpage-container/brand-page-container-store.d.ts +21 -0
  32. package/lib/src/clients/ai-assistant-client.d.ts +1 -0
  33. package/lib/src/clients/ai-assistant-client.js +1 -0
  34. package/lib/src/index.mjs +224 -223
  35. package/lib/src/{lib-Dm9AuOJL.js → lib-CqHUUPUW.js} +21920 -21691
  36. package/lib/src/metadata-builder/builders/global-font-propagation.d.ts +41 -0
  37. package/lib/src/metadata-builder/builders/global-font-propagation.js +146 -0
  38. package/lib/src/metadata-builder/builders/global-styles-builder.js +29 -1
  39. package/lib/src/metadata-builder/builders/header-builder.js +8 -0
  40. package/lib/src/metadata-builder/builders/reorder-pages-builder.d.ts +13 -0
  41. package/lib/src/metadata-builder/builders/reorder-pages-builder.js +49 -0
  42. package/lib/src/metadata-builder/builders/section-builders/index.d.ts +1 -0
  43. package/lib/src/metadata-builder/builders/section-builders/index.js +1 -0
  44. package/lib/src/metadata-builder/builders/section-builders/support-me-builder.d.ts +8 -0
  45. package/lib/src/metadata-builder/builders/section-builders/support-me-builder.js +25 -0
  46. package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +5 -2
  47. package/lib/src/metadata-builder/builders/section-field-maps.js +15 -0
  48. package/lib/src/metadata-builder/builders/section-field-utils.d.ts +6 -1
  49. package/lib/src/metadata-builder/builders/section-field-utils.js +48 -12
  50. package/lib/src/metadata-builder/builders/section-rules/support-me.rules.d.ts +2 -0
  51. package/lib/src/metadata-builder/builders/section-rules/support-me.rules.js +17 -0
  52. package/lib/src/metadata-builder/helpers/rte.helpers.d.ts +9 -0
  53. package/lib/src/metadata-builder/helpers/rte.helpers.js +60 -1
  54. package/lib/src/metadata-builder/metadata-executor.js +3 -1
  55. package/lib/src/metadata-builder/models.d.ts +2 -0
  56. package/lib/src/metadata-builder/models.js +2 -0
  57. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +1 -0
  58. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.js +4 -0
  59. package/lib/src/metadata-builder/parsers/section-tool-arguments.d.ts +14 -2
  60. package/lib/src/shared/content-settings/components/GenericTextInput.mixin.d.ts +1 -1
  61. package/lib/src/shared/content-settings/components/email-field/EmailField.mixin.d.ts +1 -1
  62. package/lib/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.d.ts +21 -0
  63. package/lib/src/shared/content-settings/components/tel-field/TelField.mixin.d.ts +1 -1
  64. package/lib/src/shared/content-settings/components/text-field/TextField.mixin.d.ts +1 -1
  65. package/lib/src/shared/content-settings/components/textarea-field/TextareaField.mixin.d.ts +1 -1
  66. package/lib/src/shared/content-settings/components/url-field/UrlField.mixin.d.ts +1 -1
  67. package/lib/src/shared/content-settings/components/youtube-video-field/YoutubeVideoField.mixin.d.ts +1 -1
  68. package/lib/src/shared/logo-settings/components/LogoSettings.mixin.d.ts +21 -0
  69. package/lib/src/shared/page-settings/components/delete-page-modal/DeletePageModal.mixin.d.ts +1 -1
  70. package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +21 -0
  71. package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +21 -0
  72. package/lib/src/shared/publish-brand-page-with-state/PublishBrandPageModalWithState.mixin.d.ts +28 -0
  73. package/lib/src/shared/side-bar/components/SideBar.mixin.d.ts +21 -0
  74. package/lib/src/shared/style-settings/button-style-preset.d.ts +12 -0
  75. package/lib/src/shared/style-settings/button-style-preset.js +39 -0
  76. package/lib/src/shared/style-settings/components/StyleSettings.mixin.d.ts +21 -0
  77. package/lib/src/shared/style-settings/store/style-settings-store.js +6 -32
  78. package/lib/src/utils/minify-brand-page-metadata.d.ts +9 -0
  79. package/lib/src/utils/minify-brand-page-metadata.js +23 -1
  80. package/package.json +1 -12
  81. package/src/brand-page/models/brand-page-context.model.ts +14 -1
  82. package/src/brand-page-maker/components/ai-website-builder/AiWebsiteBuilder.vue +1 -1
  83. package/src/brand-page-maker/composables/ai-chat/ai-builder-experiment.test.ts +82 -0
  84. package/src/brand-page-maker/composables/ai-chat/ai-builder-experiment.ts +19 -0
  85. package/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.ts +18 -4
  86. package/src/brand-page-maker/stores/ai-thread/ai-website-builder-thread-store.ts +30 -0
  87. package/src/clients/ai-assistant-client.ts +1 -0
  88. package/src/metadata-builder/builders/global-font-propagation.test.ts +401 -0
  89. package/src/metadata-builder/builders/global-font-propagation.ts +238 -0
  90. package/src/metadata-builder/builders/global-styles-builder.test.ts +107 -0
  91. package/src/metadata-builder/builders/global-styles-builder.ts +38 -1
  92. package/src/metadata-builder/builders/header-builder.test.ts +45 -0
  93. package/src/metadata-builder/builders/header-builder.ts +20 -0
  94. package/src/metadata-builder/builders/reorder-pages-builder.ts +80 -0
  95. package/src/metadata-builder/builders/section-builders/index.ts +1 -0
  96. package/src/metadata-builder/builders/section-builders/support-me-builder.test.ts +177 -0
  97. package/src/metadata-builder/builders/section-builders/support-me-builder.ts +43 -0
  98. package/src/metadata-builder/builders/section-builders/text-section-builder.ts +5 -2
  99. package/src/metadata-builder/builders/section-field-maps.ts +18 -0
  100. package/src/metadata-builder/builders/section-field-utils.test.ts +83 -0
  101. package/src/metadata-builder/builders/section-field-utils.ts +69 -18
  102. package/src/metadata-builder/builders/section-rules/support-me.rules.ts +39 -0
  103. package/src/metadata-builder/helpers/rte.helpers.ts +82 -1
  104. package/src/metadata-builder/metadata-executor.ts +3 -0
  105. package/src/metadata-builder/models.ts +2 -0
  106. package/src/metadata-builder/parsers/ai-toolcall-parser.ts +4 -0
  107. package/src/metadata-builder/parsers/section-tool-arguments.ts +14 -1
  108. package/src/shared/style-settings/button-style-preset.test.ts +67 -0
  109. package/src/shared/style-settings/button-style-preset.ts +56 -0
  110. package/src/shared/style-settings/store/style-settings-store.ts +9 -38
  111. package/src/utils/minify-brand-page-metadata.test.ts +166 -1
  112. package/src/utils/minify-brand-page-metadata.ts +31 -1
@@ -0,0 +1,401 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import type { BrandPageModel, Content } from '../../brand-page/models';
3
+ import type { UpdateGlobalStylesArguments } from '../parsers/ai-toolcall-parser';
4
+ import { BUILDER_TYPES } from '../models';
5
+ import { GlobalStylesBuilder } from './global-styles-builder';
6
+ import {
7
+ collectChangedFontFamilies,
8
+ propagateFontFamiliesToContents,
9
+ } from './global-font-propagation';
10
+
11
+ /**
12
+ * BP-5780 ISSUE-01: an AI global font change only reached preset-bound content.
13
+ * Template-authored sections carry detached `*Style` objects and inline RTE
14
+ * `font-family` marks that override the preset at render, so "use a serif font"
15
+ * produced a confident reply and a pixel-identical page. Propagation must align
16
+ * detached styles and rewrite inline marks for every changed category.
17
+ */
18
+
19
+ const RTE_TITLE =
20
+ '<p><span style="font-family: Playfair Display">Bloom</span></p>';
21
+
22
+ // Injectable stand-in for the Tiptap rewrite — tags the string so tests can
23
+ // assert exactly which fields were rewritten and with which family.
24
+ const fakeApplyFont = (text: string, fontFamily: string) =>
25
+ `${text}::rewritten(${fontFamily})`;
26
+
27
+ const makeModel = (contents: Partial<Content>[]): BrandPageModel =>
28
+ ({
29
+ styles: { textStyles: { textStyleOptions: {} } },
30
+ pages: [{ id: 'p1', contents }],
31
+ }) as unknown as BrandPageModel;
32
+
33
+ describe('collectChangedFontFamilies', () => {
34
+ it('extracts per-category families from textStyleOptions', () => {
35
+ const changed = collectChangedFontFamilies({
36
+ textStyleOptions: {
37
+ titles: { style: { fontFamily: 'EB Garamond' } },
38
+ headings: { style: { fontFamily: 'EB Garamond' } },
39
+ buttons: { style: { fontFamily: 'Inter' } },
40
+ },
41
+ } as UpdateGlobalStylesArguments['textStyles']);
42
+
43
+ expect(changed).toEqual({
44
+ titles: 'EB Garamond',
45
+ headings: 'EB Garamond',
46
+ buttons: 'Inter',
47
+ });
48
+ });
49
+
50
+ it('falls back textFontFamily → paragraphs when no explicit paragraphs entry', () => {
51
+ const changed = collectChangedFontFamilies({
52
+ textFontFamily: 'Inter',
53
+ } as UpdateGlobalStylesArguments['textStyles']);
54
+
55
+ expect(changed).toEqual({ paragraphs: 'Inter' });
56
+ });
57
+
58
+ it('returns empty for calls that change no fonts', () => {
59
+ expect(collectChangedFontFamilies(undefined)).toEqual({});
60
+ expect(
61
+ collectChangedFontFamilies({
62
+ style: { color: '#111111' },
63
+ } as UpdateGlobalStylesArguments['textStyles']),
64
+ ).toEqual({});
65
+ });
66
+ });
67
+
68
+ describe('propagateFontFamiliesToContents', () => {
69
+ it('aligns detached styles and rewrites RTE marks for the changed category', () => {
70
+ const content = {
71
+ id: 'c1',
72
+ type: 'about-section',
73
+ title: RTE_TITLE,
74
+ titleStyle: { fontFamily: 'Playfair Display' },
75
+ } as unknown as Content;
76
+ const model = makeModel([content]);
77
+
78
+ propagateFontFamiliesToContents(
79
+ model,
80
+ { headings: 'EB Garamond' },
81
+ fakeApplyFont,
82
+ );
83
+
84
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
85
+
86
+ expect((c.titleStyle as Record<string, unknown>).fontFamily).toBe(
87
+ 'EB Garamond',
88
+ );
89
+ expect(c.title).toBe(`${RTE_TITLE}::rewritten(EB Garamond)`);
90
+ });
91
+
92
+ it('banner-section titles follow the titles category, not headings', () => {
93
+ const content = {
94
+ id: 'c1',
95
+ type: 'banner-section',
96
+ title: RTE_TITLE,
97
+ titleStyle: { fontFamily: 'Playfair Display' },
98
+ } as unknown as Content;
99
+ const model = makeModel([content]);
100
+
101
+ propagateFontFamiliesToContents(
102
+ model,
103
+ { titles: 'Lexend Deca', headings: 'EB Garamond' },
104
+ fakeApplyFont,
105
+ );
106
+
107
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
108
+
109
+ expect((c.titleStyle as Record<string, unknown>).fontFamily).toBe(
110
+ 'Lexend Deca',
111
+ );
112
+ expect(c.title).toBe(`${RTE_TITLE}::rewritten(Lexend Deca)`);
113
+ });
114
+
115
+ it('preset-bound styles stay preset-bound; only their RTE marks are rewritten', () => {
116
+ const content = {
117
+ id: 'c1',
118
+ type: 'about-section',
119
+ title: RTE_TITLE,
120
+ titleStyle: { textStyleType: 'headings' },
121
+ } as unknown as Content;
122
+ const model = makeModel([content]);
123
+
124
+ propagateFontFamiliesToContents(
125
+ model,
126
+ { headings: 'EB Garamond' },
127
+ fakeApplyFont,
128
+ );
129
+
130
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
131
+ const style = c.titleStyle as unknown as Record<string, unknown>;
132
+
133
+ expect(style.textStyleType).toBe('headings');
134
+ expect(style.fontFamily).toBeUndefined();
135
+ expect(c.title).toBe(`${RTE_TITLE}::rewritten(EB Garamond)`);
136
+ });
137
+
138
+ it('walks items arrays (per-item text fields and styles)', () => {
139
+ const itemText = '<p>Live music</p>';
140
+ const content = {
141
+ id: 'c1',
142
+ type: 'shapes-section',
143
+ items: [
144
+ {
145
+ heading: itemText,
146
+ headingStyle: { fontFamily: 'Playfair Display' },
147
+ text: itemText,
148
+ },
149
+ ],
150
+ } as unknown as Content;
151
+ const model = makeModel([content]);
152
+
153
+ propagateFontFamiliesToContents(
154
+ model,
155
+ { headings: 'EB Garamond', paragraphs: 'Inter' },
156
+ fakeApplyFont,
157
+ );
158
+
159
+ const item = (
160
+ model.pages[0].contents[0] as unknown as Record<string, unknown>
161
+ ).items as Record<string, unknown>[];
162
+
163
+ expect((item[0].headingStyle as Record<string, unknown>).fontFamily).toBe(
164
+ 'EB Garamond',
165
+ );
166
+ expect(item[0].heading).toBe(`${itemText}::rewritten(EB Garamond)`);
167
+ expect(item[0].text).toBe(`${itemText}::rewritten(Inter)`);
168
+ });
169
+
170
+ it('leaves fields alone when their category did not change', () => {
171
+ const content = {
172
+ id: 'c1',
173
+ type: 'about-section',
174
+ title: RTE_TITLE,
175
+ titleStyle: { fontFamily: 'Playfair Display' },
176
+ description: RTE_TITLE,
177
+ descriptionStyle: { fontFamily: 'Lato' },
178
+ } as unknown as Content;
179
+ const model = makeModel([content]);
180
+
181
+ propagateFontFamiliesToContents(
182
+ model,
183
+ { paragraphs: 'Inter' },
184
+ fakeApplyFont,
185
+ );
186
+
187
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
188
+
189
+ expect((c.titleStyle as Record<string, unknown>).fontFamily).toBe(
190
+ 'Playfair Display',
191
+ );
192
+ expect(c.title).toBe(RTE_TITLE);
193
+ expect((c.descriptionStyle as Record<string, unknown>).fontFamily).toBe(
194
+ 'Inter',
195
+ );
196
+ expect(c.description).toBe(`${RTE_TITLE}::rewritten(Inter)`);
197
+ });
198
+
199
+ it('non-RTE plain text fields are not rewritten (style still aligned)', () => {
200
+ const content = {
201
+ id: 'c1',
202
+ type: 'about-section',
203
+ title: 'Plain title',
204
+ titleStyle: { fontFamily: 'Playfair Display' },
205
+ } as unknown as Content;
206
+ const model = makeModel([content]);
207
+
208
+ propagateFontFamiliesToContents(
209
+ model,
210
+ { headings: 'EB Garamond' },
211
+ fakeApplyFont,
212
+ );
213
+
214
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
215
+
216
+ expect(c.title).toBe('Plain title');
217
+ expect((c.titleStyle as Record<string, unknown>).fontFamily).toBe(
218
+ 'EB Garamond',
219
+ );
220
+ });
221
+ });
222
+
223
+ describe('GlobalStylesBuilder font propagation wiring', () => {
224
+ it('buildAsync propagates changed category families into existing detached styles', async () => {
225
+ const content = {
226
+ id: 'c1',
227
+ type: 'about-section',
228
+ title: 'Plain title', // plain text — the builder path must not need the RTE editor here
229
+ titleStyle: { fontFamily: 'Playfair Display' },
230
+ } as unknown as Content;
231
+ const model = {
232
+ styles: {
233
+ textStyles: {
234
+ textStyleOptions: {
235
+ headings: { style: { fontFamily: 'Lato' }, isModified: false },
236
+ },
237
+ },
238
+ buttonStyles: { style: {} },
239
+ backgroundStyles: { style: {} },
240
+ },
241
+ pages: [{ id: 'p1', contents: [content] }],
242
+ } as unknown as BrandPageModel;
243
+
244
+ const builder = new GlobalStylesBuilder({
245
+ id: 'g1',
246
+ type: BUILDER_TYPES.UPDATE_GLOBAL_STYLES,
247
+ payload: {
248
+ textStyles: {
249
+ textStyleOptions: {
250
+ headings: { style: { fontFamily: 'EB Garamond' } },
251
+ },
252
+ },
253
+ } as UpdateGlobalStylesArguments,
254
+ });
255
+
256
+ const result = await builder.buildAsync(model);
257
+
258
+ expect(result.errors).toBeUndefined();
259
+ // Preset updated (pre-existing behaviour)…
260
+ expect(
261
+ model.styles.textStyles.textStyleOptions.headings.style.fontFamily,
262
+ ).toBe('EB Garamond');
263
+ // …AND the detached section style now follows (the fix).
264
+ expect(
265
+ (model.pages[0].contents[0] as unknown as Record<string, unknown>)
266
+ .titleStyle,
267
+ ).toMatchObject({ fontFamily: 'EB Garamond' });
268
+ });
269
+ });
270
+
271
+ describe('propagateFontFamiliesToContents — Tiptap JSON docs (BP-6079)', () => {
272
+ // The migrated model stores RTE fields as Tiptap JSON; the string-only path
273
+ // skipped them, so every inline mark kept the old family while the *Style
274
+ // objects moved (eval TYP-BP5540, compact-site).
275
+ const doc = (
276
+ family: string | undefined,
277
+ text = 'Your Local Music Destination',
278
+ ) => ({
279
+ type: 'doc',
280
+ content: [
281
+ {
282
+ type: 'paragraph',
283
+ attrs: { textAlign: 'left' },
284
+ content: [
285
+ {
286
+ type: 'text',
287
+ marks: [
288
+ { type: 'bold' },
289
+ {
290
+ type: 'textStyle',
291
+ attrs: {
292
+ ...(family ? { fontFamily: family } : {}),
293
+ fontSize: '4.52em',
294
+ lineHeight: '1.3',
295
+ color: 'rgb(255, 244, 224)',
296
+ },
297
+ },
298
+ ],
299
+ text,
300
+ },
301
+ ],
302
+ },
303
+ ],
304
+ });
305
+
306
+ it('rewrites the fontFamily attr of every textStyle mark, keeping the other attrs and marks', () => {
307
+ const content = {
308
+ id: 'c1',
309
+ type: 'banner-section',
310
+ title: doc('Aboreto'),
311
+ titleStyle: { fontFamily: 'Aboreto' },
312
+ } as unknown as Content;
313
+ const model = makeModel([content]);
314
+
315
+ propagateFontFamiliesToContents(model, { titles: 'Oswald' }, fakeApplyFont);
316
+
317
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
318
+ const run = (c.title as ReturnType<typeof doc>).content[0].content[0];
319
+
320
+ expect((c.titleStyle as Record<string, unknown>).fontFamily).toBe('Oswald');
321
+ expect(run.marks[0]).toEqual({ type: 'bold' });
322
+ expect(run.marks[1].attrs).toEqual({
323
+ fontFamily: 'Oswald',
324
+ fontSize: '4.52em',
325
+ lineHeight: '1.3',
326
+ color: 'rgb(255, 244, 224)',
327
+ });
328
+ expect(run.text).toBe('Your Local Music Destination');
329
+ });
330
+
331
+ it('leaves a textStyle mark without a family alone (it inherits the updated style)', () => {
332
+ const content = {
333
+ id: 'c1',
334
+ type: 'about-section',
335
+ title: doc(undefined),
336
+ titleStyle: { fontFamily: 'Aboreto' },
337
+ } as unknown as Content;
338
+ const model = makeModel([content]);
339
+
340
+ propagateFontFamiliesToContents(
341
+ model,
342
+ { headings: 'Oswald' },
343
+ fakeApplyFont,
344
+ );
345
+
346
+ const c = model.pages[0].contents[0] as unknown as Record<string, unknown>;
347
+ const run = (c.title as ReturnType<typeof doc>).content[0].content[0];
348
+
349
+ expect(run.marks[1].attrs?.fontFamily).toBeUndefined();
350
+ });
351
+
352
+ it('walks item docs (text section textItems)', () => {
353
+ const content = {
354
+ id: 'c1',
355
+ type: 'text',
356
+ textItems: [
357
+ {
358
+ text: doc('Tenor Sans', 'Lessons'),
359
+ textStyle: { fontFamily: 'Tenor Sans' },
360
+ },
361
+ ],
362
+ } as unknown as Content;
363
+ const model = makeModel([content]);
364
+
365
+ propagateFontFamiliesToContents(
366
+ model,
367
+ { paragraphs: 'Oswald' },
368
+ fakeApplyFont,
369
+ );
370
+
371
+ const items = (
372
+ model.pages[0].contents[0] as unknown as Record<string, unknown>
373
+ ).textItems as Record<string, unknown>[];
374
+ const run = (items[0].text as ReturnType<typeof doc>).content[0].content[0];
375
+
376
+ expect((items[0].textStyle as Record<string, unknown>).fontFamily).toBe(
377
+ 'Oswald',
378
+ );
379
+ expect(run.marks[1].attrs?.fontFamily).toBe('Oswald');
380
+ });
381
+
382
+ it('legacy HTML strings still go through the editor rewrite', () => {
383
+ const content = {
384
+ id: 'c1',
385
+ type: 'about-section',
386
+ title: RTE_TITLE,
387
+ titleStyle: { fontFamily: 'Playfair Display' },
388
+ } as unknown as Content;
389
+ const model = makeModel([content]);
390
+
391
+ propagateFontFamiliesToContents(
392
+ model,
393
+ { headings: 'Oswald' },
394
+ fakeApplyFont,
395
+ );
396
+
397
+ expect(
398
+ (model.pages[0].contents[0] as unknown as Record<string, unknown>).title,
399
+ ).toBe(`${RTE_TITLE}::rewritten(Oswald)`);
400
+ });
401
+ });
@@ -0,0 +1,238 @@
1
+ import type { JSONContent } from '@tiptap/vue-3';
2
+ import type { BrandPageModel, Content } from '../../brand-page/models';
3
+ import type { TextStyleDeclaration } from '../../brand-page/models';
4
+ import { hasRTEContent } from '../../brand-page-maker/utils';
5
+ import { useExternalRichTextEditor } from '../../brand-page-maker/composables/rich-text-editor/useRichTextEditor';
6
+ import { applyStyleToRTEText } from '../helpers/rte.helpers';
7
+ import type { UpdateGlobalStylesArguments } from '../parsers/ai-toolcall-parser';
8
+ import { isTiptapDocument } from '../parsers/section-tool-arguments';
9
+
10
+ /**
11
+ * Propagation of AI global font-family changes into existing section content.
12
+ *
13
+ * A `tool_update_global_styles` call merges new per-category font families into
14
+ * `styles.textStyles.textStyleOptions` — but only content whose style is still
15
+ * bound to a preset (`textStyleType`) follows that change. Template-authored
16
+ * content carries detached `*Style` objects AND inline `font-family` marks in
17
+ * its RTE HTML, both of which override the preset at render time, so a global
18
+ * font change was invisible on most templates (BP-5780 ISSUE-01).
19
+ *
20
+ * This module walks every page's contents and, for each text field whose
21
+ * resolved category received a new family, aligns the detached style object and
22
+ * rewrites the RTE field's inline font-family marks. Preset-bound styles are NOT
23
+ * detached — they already follow the preset; only their RTE inline marks are
24
+ * rewritten (the marks would otherwise still win over the preset).
25
+ *
26
+ * RTE fields come in two shapes: legacy inline HTML strings (rewritten through
27
+ * the headless Tiptap editor) and the migrated Tiptap JSON document (rewritten
28
+ * in place — `textStyle` mark attrs). Missing the JSON shape left every mark on
29
+ * the old family while the `*Style` objects moved (BP-6079).
30
+ */
31
+
32
+ export type GlobalFontCategory =
33
+ | 'titles'
34
+ | 'headings'
35
+ | 'paragraphs'
36
+ | 'buttons';
37
+
38
+ /**
39
+ * Default category per text field when its style is detached (no `textStyleType`).
40
+ * Mirrors the AI service's slot→category stamping (titles←h1, headings←h2-h4,
41
+ * paragraphs←body, buttons←button). `title` upgrades to `titles` on banner
42
+ * sections (the hero headline) via `resolveFieldCategory`.
43
+ */
44
+ const FIELD_DEFAULT_CATEGORY: Record<string, GlobalFontCategory> = {
45
+ title: 'headings',
46
+ heading: 'headings',
47
+ name: 'headings',
48
+ description: 'paragraphs',
49
+ paragraph: 'paragraphs',
50
+ text: 'paragraphs',
51
+ testimonial: 'paragraphs',
52
+ position: 'paragraphs',
53
+ question: 'headings',
54
+ answer: 'paragraphs',
55
+ buttonText: 'buttons',
56
+ successMessage: 'paragraphs',
57
+ };
58
+
59
+ const CATEGORIES: readonly GlobalFontCategory[] = [
60
+ 'titles',
61
+ 'headings',
62
+ 'paragraphs',
63
+ 'buttons',
64
+ ];
65
+
66
+ const isPlainObject = (v: unknown): v is Record<string, unknown> =>
67
+ !!v && typeof v === 'object' && !Array.isArray(v);
68
+
69
+ /** Extract the per-category families this AI call actually changes. */
70
+ export const collectChangedFontFamilies = (
71
+ textStyles: UpdateGlobalStylesArguments['textStyles'],
72
+ ): Partial<Record<GlobalFontCategory, string>> => {
73
+ const changed: Partial<Record<GlobalFontCategory, string>> = {};
74
+
75
+ if (!textStyles) return changed;
76
+
77
+ for (const category of CATEGORIES) {
78
+ const family = textStyles.textStyleOptions?.[category]?.style?.fontFamily;
79
+
80
+ if (typeof family === 'string' && family.trim()) {
81
+ changed[category] = family;
82
+ }
83
+ }
84
+
85
+ // Base text family covers paragraphs when no explicit paragraphs entry came in.
86
+ if (
87
+ !changed.paragraphs &&
88
+ typeof textStyles.textFontFamily === 'string' &&
89
+ textStyles.textFontFamily.trim()
90
+ ) {
91
+ changed.paragraphs = textStyles.textFontFamily;
92
+ }
93
+
94
+ return changed;
95
+ };
96
+
97
+ const resolveFieldCategory = (
98
+ fieldName: string,
99
+ style: unknown,
100
+ content: Content,
101
+ ): GlobalFontCategory | undefined => {
102
+ const preset = isPlainObject(style)
103
+ ? (style.textStyleType as GlobalFontCategory | undefined)
104
+ : undefined;
105
+
106
+ if (preset && CATEGORIES.includes(preset)) return preset;
107
+
108
+ if (fieldName === 'title' && content.type === 'banner-section') {
109
+ return 'titles';
110
+ }
111
+
112
+ return FIELD_DEFAULT_CATEGORY[fieldName];
113
+ };
114
+
115
+ /** `testimonialsStyle` → `testimonial`, `titleStyle` → `title`. */
116
+ const styleKeyToFieldName = (styleKey: string): string => {
117
+ const base = styleKey.slice(0, -'Style'.length);
118
+
119
+ return base.endsWith('s') && !(base in FIELD_DEFAULT_CATEGORY)
120
+ ? base.slice(0, -1)
121
+ : base;
122
+ };
123
+
124
+ export type ApplyFontToRTE = (text: string, fontFamily: string) => string;
125
+
126
+ /**
127
+ * Rewrite the `fontFamily` attr of every `textStyle` mark in a Tiptap document.
128
+ * Only marks that already carry a family are touched: a run without one inherits
129
+ * the (already updated) `*Style` / preset at render, so adding a mark would pin
130
+ * it needlessly.
131
+ */
132
+ export const applyFontToTiptapDoc = (
133
+ doc: JSONContent,
134
+ fontFamily: string,
135
+ ): JSONContent => {
136
+ const visit = (node: JSONContent): JSONContent => {
137
+ const marks = node.marks?.map((mark) =>
138
+ mark.type === 'textStyle' && mark.attrs?.fontFamily
139
+ ? { ...mark, attrs: { ...mark.attrs, fontFamily } }
140
+ : mark,
141
+ );
142
+ const content = node.content?.map(visit);
143
+
144
+ return {
145
+ ...node,
146
+ ...(marks ? { marks } : {}),
147
+ ...(content ? { content } : {}),
148
+ };
149
+ };
150
+
151
+ return visit(doc);
152
+ };
153
+
154
+ const walkRecord = (
155
+ record: Record<string, unknown>,
156
+ content: Content,
157
+ changed: Partial<Record<GlobalFontCategory, string>>,
158
+ applyFont: ApplyFontToRTE,
159
+ ): void => {
160
+ for (const [key, value] of Object.entries(record)) {
161
+ if (key.endsWith('Style') && isPlainObject(value)) {
162
+ // Detached style objects carry their own fontFamily override — align it.
163
+ // Preset-bound styles keep following the preset (never detach here).
164
+ const category = resolveFieldCategory(
165
+ styleKeyToFieldName(key),
166
+ value,
167
+ content,
168
+ );
169
+ const family = category ? changed[category] : undefined;
170
+
171
+ if (family && !value.textStyleType) {
172
+ (value as TextStyleDeclaration).fontFamily =
173
+ family as TextStyleDeclaration['fontFamily'];
174
+ }
175
+ } else if (key in FIELD_DEFAULT_CATEGORY && hasRTEContent(value)) {
176
+ // Inline RTE marks override every style layer at render — rewrite them.
177
+ const category = resolveFieldCategory(
178
+ key,
179
+ record[`${key}Style`],
180
+ content,
181
+ );
182
+ const family = category ? changed[category] : undefined;
183
+
184
+ if (family) {
185
+ record[key] = isTiptapDocument(value)
186
+ ? applyFontToTiptapDoc(value, family)
187
+ : applyFont(value as string, family);
188
+ }
189
+ } else if (Array.isArray(value)) {
190
+ for (const item of value) {
191
+ if (isPlainObject(item)) {
192
+ walkRecord(item, content, changed, applyFont);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ };
198
+
199
+ /**
200
+ * Walk every page's contents and propagate the changed families.
201
+ * `applyFont` is injectable for tests; the default rewrites inline marks via
202
+ * the external Tiptap editor.
203
+ */
204
+ export const propagateFontFamiliesToContents = (
205
+ model: BrandPageModel,
206
+ changed: Partial<Record<GlobalFontCategory, string>>,
207
+ applyFont?: ApplyFontToRTE,
208
+ ): void => {
209
+ if (!Object.keys(changed).length) return;
210
+
211
+ let editor:
212
+ | ReturnType<typeof useExternalRichTextEditor>['externalEditor']
213
+ | undefined;
214
+ const apply: ApplyFontToRTE =
215
+ applyFont ??
216
+ ((text, fontFamily) => {
217
+ editor = editor ?? useExternalRichTextEditor().externalEditor;
218
+
219
+ return applyStyleToRTEText(editor, text, {
220
+ fontFamily,
221
+ } as TextStyleDeclaration);
222
+ });
223
+
224
+ try {
225
+ for (const page of model.pages) {
226
+ for (const content of page.contents) {
227
+ walkRecord(
228
+ content as unknown as Record<string, unknown>,
229
+ content,
230
+ changed,
231
+ apply,
232
+ );
233
+ }
234
+ }
235
+ } finally {
236
+ editor?.destroy();
237
+ }
238
+ };