@designcrowd/library.brand-page 6.1.0-websitev2-dev-2 → 6.1.0

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 (97) hide show
  1. package/lib/src/{CreatedOnBrandCrowd-de-de-D_qQ0sPW.js → CreatedOnBrandCrowd-de-de-CW5bD06L.js} +1 -1
  2. package/lib/src/{CreatedOnBrandCrowd-en-us-CNMxavFU.js → CreatedOnBrandCrowd-en-us-CofG4e3V.js} +1 -1
  3. package/lib/src/{CreatedOnBrandCrowd-es-es-Cyaiw1-R.js → CreatedOnBrandCrowd-es-es-XpL0-LWx.js} +1 -1
  4. package/lib/src/{CreatedOnBrandCrowd-fr-fr-DbniOtuE.js → CreatedOnBrandCrowd-fr-ca-dlVN3zaX.js} +1 -1
  5. package/lib/src/{CreatedOnBrandCrowd-fr-ca-DbniOtuE.js → CreatedOnBrandCrowd-fr-fr-dlVN3zaX.js} +1 -1
  6. package/lib/src/{CreatedOnBrandCrowd-pt-pt-DI3JfwR8.js → CreatedOnBrandCrowd-pt-br-98gqdDVF.js} +1 -1
  7. package/lib/src/{CreatedOnBrandCrowd-pt-br-DI3JfwR8.js → CreatedOnBrandCrowd-pt-pt-98gqdDVF.js} +1 -1
  8. package/lib/src/{CreatedOnDcom-de-de-DqBzJ_O9.js → CreatedOnDcom-de-de-Dbmlc0i1.js} +1 -1
  9. package/lib/src/{CreatedOnDcom-en-us-B8uZjYMi.js → CreatedOnDcom-en-us-Dy9z7h1o.js} +1 -1
  10. package/lib/src/{CreatedOnDcom-es-es-BOLxcx3H.js → CreatedOnDcom-es-es-B3ksvNj9.js} +1 -1
  11. package/lib/src/{CreatedOnDcom-fr-ca-CbGneDvu.js → CreatedOnDcom-fr-ca-CC9ieRzX.js} +1 -1
  12. package/lib/src/{CreatedOnDcom-fr-fr-B-UwXpW3.js → CreatedOnDcom-fr-fr-BtnGJjF2.js} +1 -1
  13. package/lib/src/{CreatedOnDcom-pt-br-CRPrLx5_.js → CreatedOnDcom-pt-br-DT4doFYO.js} +1 -1
  14. package/lib/src/{CreatedOnDcom-pt-pt-4p2rdAnc.js → CreatedOnDcom-pt-pt-CloXyOe6.js} +1 -1
  15. package/lib/src/brand-page/components/contact-form/ContactForm.mixin.js +3 -5
  16. package/lib/src/brand-page/components/mailing-list/MailingList.mixin.js +4 -6
  17. package/lib/src/brand-page/components/page-footer/PageFooter.mixin.d.ts +0 -1
  18. package/lib/src/brand-page/components/page-footer/PageFooter.mixin.js +1 -4
  19. package/lib/src/brand-page/components/payment/Payment.mixin.js +3 -4
  20. package/lib/src/brand-page/components/payment/__fixtures__/request-payment.d.ts +0 -1
  21. package/lib/src/brand-page/components/payment/__fixtures__/support-me.d.ts +0 -1
  22. package/lib/src/brand-page/components/payment/request-payment/RequestPayment.mixin.d.ts +0 -1
  23. package/lib/src/brand-page/components/payment/request-payment/RequestPayment.mixin.js +1 -4
  24. package/lib/src/brand-page/composables/consent.composable.d.ts +0 -2
  25. package/lib/src/brand-page/composables/consent.composable.js +3 -9
  26. package/lib/src/brand-page/models/brand-page-context.model.d.ts +0 -7
  27. package/lib/src/brand-page/utils/context.util.d.ts +0 -8
  28. package/lib/src/brand-page/utils/context.util.js +0 -8
  29. package/lib/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.js +3 -7
  30. package/lib/src/clients/ai-assistant-client.d.ts +0 -1
  31. package/lib/src/clients/ai-assistant-client.js +0 -1
  32. package/lib/src/css/library.brand-page-brandCrowd.min.css +60 -60
  33. package/lib/src/css/library.brand-page-brandPage.min.css +60 -60
  34. package/lib/src/css/library.brand-page-designCom.min.css +60 -60
  35. package/lib/src/css/library.brand-page-preview.min.css +60 -60
  36. package/lib/src/index.d.ts +0 -1
  37. package/lib/src/index.mjs +217 -220
  38. package/lib/src/{lib-DhEJMZFn.js → lib-D7ubPlpu.js} +18168 -18341
  39. package/lib/src/lib.js +0 -1
  40. package/lib/src/metadata-builder/builders/global-styles-builder.js +0 -16
  41. package/lib/src/metadata-builder/builders/section-builders/index.d.ts +0 -1
  42. package/lib/src/metadata-builder/builders/section-builders/index.js +0 -1
  43. package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +2 -5
  44. package/lib/src/metadata-builder/builders/section-field-maps.js +0 -15
  45. package/lib/src/metadata-builder/builders/section-field-utils.d.ts +1 -6
  46. package/lib/src/metadata-builder/builders/section-field-utils.js +12 -48
  47. package/lib/src/metadata-builder/metadata-executor.js +1 -3
  48. package/lib/src/metadata-builder/models.d.ts +0 -2
  49. package/lib/src/metadata-builder/models.js +0 -2
  50. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +0 -1
  51. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.js +0 -4
  52. package/lib/src/metadata-builder/parsers/section-tool-arguments.d.ts +2 -14
  53. package/lib/src/utils/minify-brand-page-metadata.js +0 -7
  54. package/package.json +1 -1
  55. package/src/brand-page/components/contact-form/ContactForm.mixin.ts +2 -7
  56. package/src/brand-page/components/cookie-consent/CookieConsent.vue +0 -1
  57. package/src/brand-page/components/mailing-list/MailingList.mixin.ts +3 -8
  58. package/src/brand-page/components/navigation/navigation-carousel/NavigationCarousel.vue +1 -5
  59. package/src/brand-page/components/page-footer/PageFooter.mixin.ts +1 -4
  60. package/src/brand-page/components/page-footer/PageFooter.vue +1 -1
  61. package/src/brand-page/components/payment/Payment.mixin.ts +3 -4
  62. package/src/brand-page/components/payment/request-payment/RequestPayment.mixin.ts +1 -8
  63. package/src/brand-page/components/payment/request-payment/RequestPayment.vue +1 -1
  64. package/src/brand-page/components/save-contact/SaveContactWidget.vue +1 -2
  65. package/src/brand-page/components/shop/Shop.vue +3 -6
  66. package/src/brand-page/components/social-links/SocialLinks.vue +2 -5
  67. package/src/brand-page/composables/consent.composable.ts +4 -18
  68. package/src/brand-page/models/brand-page-context.model.ts +0 -7
  69. package/src/brand-page/utils/context.util.ts +0 -10
  70. package/src/brand-page-maker/components/ai-website-builder/AiWebsiteBuilder.vue +1 -1
  71. package/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.ts +3 -7
  72. package/src/clients/ai-assistant-client.ts +0 -1
  73. package/src/lib.ts +0 -1
  74. package/src/metadata-builder/builders/global-styles-builder.ts +0 -21
  75. package/src/metadata-builder/builders/section-builders/index.ts +0 -1
  76. package/src/metadata-builder/builders/section-builders/text-section-builder.ts +2 -5
  77. package/src/metadata-builder/builders/section-field-maps.ts +0 -18
  78. package/src/metadata-builder/builders/section-field-utils.ts +18 -69
  79. package/src/metadata-builder/metadata-executor.ts +0 -3
  80. package/src/metadata-builder/models.ts +0 -2
  81. package/src/metadata-builder/parsers/ai-toolcall-parser.ts +0 -4
  82. package/src/metadata-builder/parsers/section-tool-arguments.ts +1 -14
  83. package/src/utils/minify-brand-page-metadata.ts +0 -8
  84. package/lib/src/metadata-builder/builders/global-font-propagation.d.ts +0 -28
  85. package/lib/src/metadata-builder/builders/global-font-propagation.js +0 -125
  86. package/lib/src/metadata-builder/builders/section-builders/support-me-builder.d.ts +0 -8
  87. package/lib/src/metadata-builder/builders/section-builders/support-me-builder.js +0 -25
  88. package/lib/src/metadata-builder/builders/section-rules/support-me.rules.d.ts +0 -2
  89. package/lib/src/metadata-builder/builders/section-rules/support-me.rules.js +0 -17
  90. package/src/brand-page/utils/context.util.test.ts +0 -43
  91. package/src/metadata-builder/builders/global-font-propagation.test.ts +0 -269
  92. package/src/metadata-builder/builders/global-font-propagation.ts +0 -205
  93. package/src/metadata-builder/builders/section-builders/support-me-builder.test.ts +0 -177
  94. package/src/metadata-builder/builders/section-builders/support-me-builder.ts +0 -43
  95. package/src/metadata-builder/builders/section-field-utils.test.ts +0 -83
  96. package/src/metadata-builder/builders/section-rules/support-me.rules.ts +0 -39
  97. package/src/utils/minify-brand-page-metadata.test.ts +0 -61
@@ -1,25 +0,0 @@
1
- import { applyScalarFields, applyStyleFields } from '../section-field-utils';
2
- import { BaseSectionBuilder } from './base-section-builder';
3
- import { validateSupportMe } from '../section-rules/support-me.rules';
4
- export class SupportMeBuilder extends BaseSectionBuilder {
5
- get sectionValidate() {
6
- return validateSupportMe;
7
- }
8
- async buildAsync(model) {
9
- this.log('Build called');
10
- const validation = await this.validateAsync();
11
- if (validation.errors.length) {
12
- return { request: this.request, model, errors: validation.errors };
13
- }
14
- const resolved = this.resolveAndRepositionContent(model);
15
- if ('error' in resolved)
16
- return resolved.error;
17
- const content = resolved.content;
18
- // title/description/success_message are plain-text fields (no RTE support),
19
- // so scalar application covers all content fields. supportMeConfig (payment
20
- // options) is intentionally not AI-editable — it comes from the factory.
21
- applyScalarFields(content, this.args, this.sectionType);
22
- applyStyleFields(content, this.args, this.sectionType, this.getGlobalTextStyles(model));
23
- return { request: this.request, model };
24
- }
25
- }
@@ -1,2 +0,0 @@
1
- import { type ValidationContext } from '../../sanitizers/section-args-validator';
2
- export declare function validateSupportMe(args: Record<string, unknown>, ctx: ValidationContext): string[];
@@ -1,17 +0,0 @@
1
- import { MAX_TITLE_LENGTH, MAX_DESCRIPTION_LENGTH, } from '../../../brand-page/constants/font.constants';
2
- import { DISPLAY_STYLE_PREVIEW, DISPLAY_STYLE_COLLAPSED, } from '../../../brand-page/constants';
3
- import { enumCheck, runChecks, styleCheck, textCheck, } from '../../sanitizers/section-args-validator';
4
- const CHECKS = [
5
- textCheck('title', MAX_TITLE_LENGTH),
6
- textCheck('description', MAX_DESCRIPTION_LENGTH),
7
- textCheck('success_message', MAX_DESCRIPTION_LENGTH),
8
- styleCheck('title_style'),
9
- styleCheck('heading_style'),
10
- styleCheck('description_style'),
11
- styleCheck('item_text_style'),
12
- styleCheck('button_text_style'),
13
- enumCheck('display_style', [DISPLAY_STYLE_PREVIEW, DISPLAY_STYLE_COLLAPSED], 'support-me'),
14
- ];
15
- export function validateSupportMe(args, ctx) {
16
- return runChecks(CHECKS, args, ctx);
17
- }
@@ -1,43 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { BrandPageContext } from '../models';
3
- import { getSlugFromContext, isPreviewMode } from './context.util';
4
-
5
- const baseContext = {
6
- isPreview: false,
7
- isLivePreview: false,
8
- brandPageSlug: 'my-site',
9
- } as unknown as BrandPageContext;
10
-
11
- describe('isPreviewMode', () => {
12
- it('is false for a live render (neither preview flag set)', () => {
13
- expect(isPreviewMode(baseContext)).toBe(false);
14
- });
15
-
16
- it('is true for the editor preview', () => {
17
- expect(isPreviewMode({ ...baseContext, isPreview: true })).toBe(true);
18
- });
19
-
20
- it('is true for the customer live-preview', () => {
21
- expect(isPreviewMode({ ...baseContext, isLivePreview: true })).toBe(true);
22
- });
23
-
24
- it('treats a missing isLivePreview as not-preview', () => {
25
- const ctx = { isPreview: false } as unknown as BrandPageContext;
26
-
27
- expect(isPreviewMode(ctx)).toBe(false);
28
- });
29
- });
30
-
31
- describe('getSlugFromContext', () => {
32
- it('returns the literal editor slug for the editor preview only', () => {
33
- expect(getSlugFromContext({ ...baseContext, isPreview: true })).toBe(
34
- 'slug',
35
- );
36
- });
37
-
38
- it('returns the real slug for a customer preview (renders like live)', () => {
39
- expect(getSlugFromContext({ ...baseContext, isLivePreview: true })).toBe(
40
- 'my-site',
41
- );
42
- });
43
- });
@@ -1,269 +0,0 @@
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
- });
@@ -1,205 +0,0 @@
1
- import type { BrandPageModel, Content } from '../../brand-page/models';
2
- import type { TextStyleDeclaration } from '../../brand-page/models';
3
- import { hasRTEContent } from '../../brand-page-maker/utils';
4
- import { useExternalRichTextEditor } from '../../brand-page-maker/composables/rich-text-editor/useRichTextEditor';
5
- import { applyStyleToRTEText } from '../helpers/rte.helpers';
6
- import type { UpdateGlobalStylesArguments } from '../parsers/ai-toolcall-parser';
7
-
8
- /**
9
- * Propagation of AI global font-family changes into existing section content.
10
- *
11
- * A `tool_update_global_styles` call merges new per-category font families into
12
- * `styles.textStyles.textStyleOptions` — but only content whose style is still
13
- * bound to a preset (`textStyleType`) follows that change. Template-authored
14
- * content carries detached `*Style` objects AND inline `font-family` marks in
15
- * its RTE HTML, both of which override the preset at render time, so a global
16
- * font change was invisible on most templates (BP-5780 ISSUE-01).
17
- *
18
- * This module walks every page's contents and, for each text field whose
19
- * resolved category received a new family, aligns the detached style object and
20
- * rewrites the RTE HTML's inline font-family marks. Preset-bound styles are NOT
21
- * detached — they already follow the preset; only their RTE inline marks are
22
- * rewritten (the marks would otherwise still win over the preset).
23
- */
24
-
25
- export type GlobalFontCategory =
26
- | 'titles'
27
- | 'headings'
28
- | 'paragraphs'
29
- | 'buttons';
30
-
31
- /**
32
- * Default category per text field when its style is detached (no `textStyleType`).
33
- * Mirrors the AI service's slot→category stamping (titles←h1, headings←h2-h4,
34
- * paragraphs←body, buttons←button). `title` upgrades to `titles` on banner
35
- * sections (the hero headline) via `resolveFieldCategory`.
36
- */
37
- const FIELD_DEFAULT_CATEGORY: Record<string, GlobalFontCategory> = {
38
- title: 'headings',
39
- heading: 'headings',
40
- name: 'headings',
41
- description: 'paragraphs',
42
- paragraph: 'paragraphs',
43
- text: 'paragraphs',
44
- testimonial: 'paragraphs',
45
- position: 'paragraphs',
46
- question: 'headings',
47
- answer: 'paragraphs',
48
- buttonText: 'buttons',
49
- successMessage: 'paragraphs',
50
- };
51
-
52
- const CATEGORIES: readonly GlobalFontCategory[] = [
53
- 'titles',
54
- 'headings',
55
- 'paragraphs',
56
- 'buttons',
57
- ];
58
-
59
- const isPlainObject = (v: unknown): v is Record<string, unknown> =>
60
- !!v && typeof v === 'object' && !Array.isArray(v);
61
-
62
- /** Extract the per-category families this AI call actually changes. */
63
- export const collectChangedFontFamilies = (
64
- textStyles: UpdateGlobalStylesArguments['textStyles'],
65
- ): Partial<Record<GlobalFontCategory, string>> => {
66
- const changed: Partial<Record<GlobalFontCategory, string>> = {};
67
-
68
- if (!textStyles) return changed;
69
-
70
- for (const category of CATEGORIES) {
71
- const family = textStyles.textStyleOptions?.[category]?.style?.fontFamily;
72
-
73
- if (typeof family === 'string' && family.trim()) {
74
- changed[category] = family;
75
- }
76
- }
77
-
78
- // Base text family covers paragraphs when no explicit paragraphs entry came in.
79
- if (
80
- !changed.paragraphs &&
81
- typeof textStyles.textFontFamily === 'string' &&
82
- textStyles.textFontFamily.trim()
83
- ) {
84
- changed.paragraphs = textStyles.textFontFamily;
85
- }
86
-
87
- return changed;
88
- };
89
-
90
- const resolveFieldCategory = (
91
- fieldName: string,
92
- style: unknown,
93
- content: Content,
94
- ): GlobalFontCategory | undefined => {
95
- const preset = isPlainObject(style)
96
- ? (style.textStyleType as GlobalFontCategory | undefined)
97
- : undefined;
98
-
99
- if (preset && CATEGORIES.includes(preset)) return preset;
100
-
101
- if (fieldName === 'title' && content.type === 'banner-section') {
102
- return 'titles';
103
- }
104
-
105
- return FIELD_DEFAULT_CATEGORY[fieldName];
106
- };
107
-
108
- /** `testimonialsStyle` → `testimonial`, `titleStyle` → `title`. */
109
- const styleKeyToFieldName = (styleKey: string): string => {
110
- const base = styleKey.slice(0, -'Style'.length);
111
-
112
- return base.endsWith('s') && !(base in FIELD_DEFAULT_CATEGORY)
113
- ? base.slice(0, -1)
114
- : base;
115
- };
116
-
117
- export type ApplyFontToRTE = (text: string, fontFamily: string) => string;
118
-
119
- const walkRecord = (
120
- record: Record<string, unknown>,
121
- content: Content,
122
- changed: Partial<Record<GlobalFontCategory, string>>,
123
- applyFont: ApplyFontToRTE,
124
- ): void => {
125
- for (const [key, value] of Object.entries(record)) {
126
- if (key.endsWith('Style') && isPlainObject(value)) {
127
- // Detached style objects carry their own fontFamily override — align it.
128
- // Preset-bound styles keep following the preset (never detach here).
129
- const category = resolveFieldCategory(
130
- styleKeyToFieldName(key),
131
- value,
132
- content,
133
- );
134
- const family = category ? changed[category] : undefined;
135
-
136
- if (family && !value.textStyleType) {
137
- (value as TextStyleDeclaration).fontFamily =
138
- family as TextStyleDeclaration['fontFamily'];
139
- }
140
- } else if (
141
- key in FIELD_DEFAULT_CATEGORY &&
142
- typeof value === 'string' &&
143
- hasRTEContent(value)
144
- ) {
145
- // Inline RTE marks override every style layer at render — rewrite them.
146
- const category = resolveFieldCategory(
147
- key,
148
- record[`${key}Style`],
149
- content,
150
- );
151
- const family = category ? changed[category] : undefined;
152
-
153
- if (family) {
154
- record[key] = applyFont(value, family);
155
- }
156
- } else if (Array.isArray(value)) {
157
- for (const item of value) {
158
- if (isPlainObject(item)) {
159
- walkRecord(item, content, changed, applyFont);
160
- }
161
- }
162
- }
163
- }
164
- };
165
-
166
- /**
167
- * Walk every page's contents and propagate the changed families.
168
- * `applyFont` is injectable for tests; the default rewrites inline marks via
169
- * the external Tiptap editor.
170
- */
171
- export const propagateFontFamiliesToContents = (
172
- model: BrandPageModel,
173
- changed: Partial<Record<GlobalFontCategory, string>>,
174
- applyFont?: ApplyFontToRTE,
175
- ): void => {
176
- if (!Object.keys(changed).length) return;
177
-
178
- let editor:
179
- | ReturnType<typeof useExternalRichTextEditor>['externalEditor']
180
- | undefined;
181
- const apply: ApplyFontToRTE =
182
- applyFont ??
183
- ((text, fontFamily) => {
184
- editor = editor ?? useExternalRichTextEditor().externalEditor;
185
-
186
- return applyStyleToRTEText(editor, text, {
187
- fontFamily,
188
- } as TextStyleDeclaration);
189
- });
190
-
191
- try {
192
- for (const page of model.pages) {
193
- for (const content of page.contents) {
194
- walkRecord(
195
- content as unknown as Record<string, unknown>,
196
- content,
197
- changed,
198
- apply,
199
- );
200
- }
201
- }
202
- } finally {
203
- editor?.destroy();
204
- }
205
- };