@caartzee/theme-sdk 0.0.0-stage → 1.0.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 (142) hide show
  1. package/README.md +34 -2
  2. package/dist/bin/caartzee-theme.js +7449 -0
  3. package/dist/lib/index.js +9838 -0
  4. package/dist/types/src/auth/credentials-store.d.ts +18 -0
  5. package/dist/types/src/auth/index.d.ts +2 -0
  6. package/dist/types/src/auth/oauth-client.d.ts +39 -0
  7. package/dist/types/src/blocks/block-contract.d.ts +242 -0
  8. package/dist/types/src/candy/compatibility-matrix.d.ts +10 -0
  9. package/dist/types/src/candy/context-builder.d.ts +31 -0
  10. package/dist/types/src/candy/engine.d.ts +69 -0
  11. package/dist/types/src/candy/filters.d.ts +32 -0
  12. package/dist/types/src/candy/ide-support.d.ts +20 -0
  13. package/dist/types/src/candy/index.d.ts +9 -0
  14. package/dist/types/src/candy/schema-parser.d.ts +13 -0
  15. package/dist/types/src/candy/security.d.ts +54 -0
  16. package/dist/types/src/candy/tags.d.ts +11 -0
  17. package/dist/types/src/candy/types.d.ts +185 -0
  18. package/dist/types/src/cli/caartzee-cli.d.ts +9 -0
  19. package/dist/types/src/cli/index.d.ts +1 -0
  20. package/dist/types/src/cli/sdk-client.d.ts +12 -0
  21. package/dist/types/src/contracts/category-selection.d.ts +15 -0
  22. package/dist/types/src/contracts/commerce.d.ts +282 -0
  23. package/dist/types/src/contracts/footer-builder.d.ts +125 -0
  24. package/dist/types/src/contracts/hooks.d.ts +37 -0
  25. package/dist/types/src/contracts/manifest.d.ts +3127 -0
  26. package/dist/types/src/contracts/navigation.d.ts +39 -0
  27. package/dist/types/src/contracts/order-tracking.d.ts +40 -0
  28. package/dist/types/src/contracts/page.d.ts +262 -0
  29. package/dist/types/src/contracts/storefront-content.d.ts +60 -0
  30. package/dist/types/src/contracts/style-document.d.ts +2 -0
  31. package/dist/types/src/contracts/styles.d.ts +2002 -0
  32. package/dist/types/src/contracts/theme.d.ts +35 -0
  33. package/dist/types/src/dev-server/catalog-preview.d.ts +25 -0
  34. package/dist/types/src/dev-server/dev-server.d.ts +22 -0
  35. package/dist/types/src/dev-server/index.d.ts +1 -0
  36. package/dist/types/src/dev-server/theme-preview.d.ts +4 -0
  37. package/dist/types/src/index.d.ts +27 -0
  38. package/dist/types/src/mock/index.d.ts +10 -0
  39. package/dist/types/src/mock/mock-categories.d.ts +2 -0
  40. package/dist/types/src/mock/mock-commerce.d.ts +55 -0
  41. package/dist/types/src/mock/mock-customer.d.ts +47 -0
  42. package/dist/types/src/mock/mock-hooks.d.ts +2 -0
  43. package/dist/types/src/mock/mock-products.d.ts +3 -0
  44. package/dist/types/src/rendering/commerce-pages.d.ts +16 -0
  45. package/dist/types/src/rendering/raw-html.d.ts +12 -0
  46. package/dist/types/src/rendering/section-wrapper.d.ts +30 -0
  47. package/dist/types/src/scaffold/candy-starter-assets.d.ts +2 -0
  48. package/dist/types/src/scaffold/commerce-generator.d.ts +3 -0
  49. package/dist/types/src/scaffold/index.d.ts +2 -0
  50. package/dist/types/src/scaffold/template-generator.d.ts +21 -0
  51. package/dist/types/src/sections/section-contract.d.ts +350 -0
  52. package/dist/types/src/settings/global-settings.d.ts +25 -0
  53. package/dist/types/src/templates/json-template.d.ts +991 -0
  54. package/dist/types/src/validation/package-validator.d.ts +53 -0
  55. package/dist/types/src/validation/rich-text.d.ts +24 -0
  56. package/package.json +28 -3
  57. package/templates/commerce/README.md +165 -0
  58. package/templates/commerce/assets/theme.css +1 -0
  59. package/templates/commerce/manifest.json +1 -0
  60. package/templates/commerce/src/blocks/index.ts +184 -0
  61. package/templates/commerce/src/config/settings-defaults.ts +25 -0
  62. package/templates/commerce/src/config/settings-schema.ts +102 -0
  63. package/templates/commerce/src/index.ts +90 -0
  64. package/templates/commerce/src/layouts/default.ts +275 -0
  65. package/templates/commerce/src/manifest.ts +976 -0
  66. package/templates/commerce/src/pages/account/components.ts +369 -0
  67. package/templates/commerce/src/pages/account/tabs.ts +792 -0
  68. package/templates/commerce/src/pages/account.ts +55 -0
  69. package/templates/commerce/src/pages/campaign.ts +423 -0
  70. package/templates/commerce/src/pages/cart.ts +261 -0
  71. package/templates/commerce/src/pages/category-detail.ts +124 -0
  72. package/templates/commerce/src/pages/category-list.ts +87 -0
  73. package/templates/commerce/src/pages/checkout.ts +712 -0
  74. package/templates/commerce/src/pages/commerce.ts +45 -0
  75. package/templates/commerce/src/pages/home.ts +160 -0
  76. package/templates/commerce/src/pages/index.ts +99 -0
  77. package/templates/commerce/src/pages/login.ts +204 -0
  78. package/templates/commerce/src/pages/order-success.ts +80 -0
  79. package/templates/commerce/src/pages/product-detail.ts +489 -0
  80. package/templates/commerce/src/pages/product-list.ts +125 -0
  81. package/templates/commerce/src/pages/search.ts +88 -0
  82. package/templates/commerce/src/pages/signup.ts +253 -0
  83. package/templates/commerce/src/pages/status.ts +7 -0
  84. package/templates/commerce/src/pages/theme-layout.ts +491 -0
  85. package/templates/commerce/src/pages/track-order.ts +196 -0
  86. package/templates/commerce/src/pages/wishlist.ts +83 -0
  87. package/templates/commerce/src/sections/about-story.ts +117 -0
  88. package/templates/commerce/src/sections/announcement-bar.ts +101 -0
  89. package/templates/commerce/src/sections/banner-grid.ts +319 -0
  90. package/templates/commerce/src/sections/campaign-banners.ts +158 -0
  91. package/templates/commerce/src/sections/category-slider.ts +144 -0
  92. package/templates/commerce/src/sections/content-builder.ts +123 -0
  93. package/templates/commerce/src/sections/content-controls.ts +45 -0
  94. package/templates/commerce/src/sections/custom-form.ts +59 -0
  95. package/templates/commerce/src/sections/faq-accordion.ts +123 -0
  96. package/templates/commerce/src/sections/footer.ts +728 -0
  97. package/templates/commerce/src/sections/header.ts +439 -0
  98. package/templates/commerce/src/sections/hero-slider.ts +492 -0
  99. package/templates/commerce/src/sections/hero.ts +137 -0
  100. package/templates/commerce/src/sections/index.ts +102 -0
  101. package/templates/commerce/src/sections/mobile-slider.ts +102 -0
  102. package/templates/commerce/src/sections/newsletter.ts +43 -0
  103. package/templates/commerce/src/sections/product-grid.ts +191 -0
  104. package/templates/commerce/src/sections/raw-html.ts +1 -0
  105. package/templates/commerce/src/sections/rich-text.ts +26 -0
  106. package/templates/commerce/src/sections/services-features.ts +211 -0
  107. package/templates/commerce/src/sections/testimonials.ts +194 -0
  108. package/templates/commerce/src/snippets/product-card.ts +178 -0
  109. package/templates/commerce/src/snippets/product-price.ts +46 -0
  110. package/templates/commerce/src/snippets/responsive-image.ts +29 -0
  111. package/templates/commerce/src/styles.ts +477 -0
  112. package/templates/commerce/src/templates/404.json +26 -0
  113. package/templates/commerce/src/templates/account.json +17 -0
  114. package/templates/commerce/src/templates/cart.json +17 -0
  115. package/templates/commerce/src/templates/category.json +16 -0
  116. package/templates/commerce/src/templates/checkout.json +15 -0
  117. package/templates/commerce/src/templates/collection.json +16 -0
  118. package/templates/commerce/src/templates/index.json +180 -0
  119. package/templates/commerce/src/templates/login.json +17 -0
  120. package/templates/commerce/src/templates/order-success.json +17 -0
  121. package/templates/commerce/src/templates/page.json +17 -0
  122. package/templates/commerce/src/templates/product.json +17 -0
  123. package/templates/commerce/src/templates/search.json +18 -0
  124. package/templates/commerce/src/templates/signup.json +17 -0
  125. package/templates/commerce/src/templates/track-order.json +17 -0
  126. package/templates/commerce/src/templates/wishlist.json +17 -0
  127. package/templates/commerce/src/templates.ts +510 -0
  128. package/templates/commerce/src/tokens.ts +22 -0
  129. package/templates/vscode-candy/README.md +22 -0
  130. package/templates/vscode-candy/extension.js +338 -0
  131. package/templates/vscode-candy/icons/candy-dark.svg +23 -0
  132. package/templates/vscode-candy/icons/candy-light.svg +23 -0
  133. package/templates/vscode-candy/icons/candy-logo.png +0 -0
  134. package/templates/vscode-candy/icons/candy-sweet-dark.svg +23 -0
  135. package/templates/vscode-candy/icons/candy-sweet-light.svg +23 -0
  136. package/templates/vscode-candy/language-configuration.json +47 -0
  137. package/templates/vscode-candy/package.json +103 -0
  138. package/templates/vscode-candy/schemas/candy-config.schema.json +56 -0
  139. package/templates/vscode-candy/schemas/candy-settings.schema.json +70 -0
  140. package/templates/vscode-candy/snippets/candy.code-snippets +179 -0
  141. package/templates/vscode-candy/syntaxes/candy.tmLanguage.json +296 -0
  142. package/templates/vscode-candy/vim/ftdetect/candy.vim +5 -0
@@ -0,0 +1,123 @@
1
+ import { escapeHtml, sanitizeRichText, sanitizeNavUrl, sanitizePaddingValue, sanitizeMarginCssValue, type SectionManifest, type SectionRenderContext, type BlockManifest } from '@caartzee/theme-sdk';
2
+ import { headingBlock, textBlock, imageBlock, videoBlock, buttonBlock, spacerBlock } from '../blocks';
3
+ import { contentSectionControls, withContentControls } from './content-controls';
4
+
5
+ const richTextBlock: BlockManifest = { type: 'rich-text', label: 'Rich text', settings: [{ id: 'content', type: 'richtext', label: 'Content', default: '<p>Add your content.</p>' }] };
6
+ export const contentBuilderBlocks = [headingBlock, textBlock, richTextBlock, imageBlock, videoBlock, buttonBlock, spacerBlock].map(withContentControls);
7
+
8
+ /** Additive section types use the existing ordered sections/blocks document format. */
9
+ export const contentBuilderSections: SectionManifest[] = [
10
+ {
11
+ type: 'content-container', label: 'Container / columns', category: 'Page builder', allowedRegions: ['body'], maxBlocks: 50,
12
+ settings: [
13
+ { id: 'columns', type: 'select', label: 'Desktop columns', default: '1', options: [1, 2, 3, 4].map(n => ({ label: String(n), value: String(n) })) },
14
+ { id: 'gap', type: 'range', label: 'Gap (px)', default: 24, min: 0, max: 96, step: 4 },
15
+ { id: 'maxWidth', type: 'number', label: 'Content width (px)', default: 1200, min: 320, max: 1920 },
16
+ { id: 'alignment', type: 'select', label: 'Text alignment', default: 'left', options: ['left', 'center', 'right'].map(value => ({ label: value, value })) },
17
+ { id: 'verticalAlignment', type: 'select', label: 'Vertical alignment', default: 'start', options: ['start', 'center', 'end', 'stretch'].map(value => ({ label: value, value })) },
18
+ ...contentSectionControls.filter(field => field.id !== 'maxWidth'),
19
+ ],
20
+ blocks: contentBuilderBlocks,
21
+ presets: [
22
+ { name: 'Empty container', settings: { columns: '1' }, blocks: [] },
23
+ { name: 'Text and image', settings: { columns: '2' }, blocks: [{ type: 'text', settings: { content: 'Tell your story.' } }, { type: 'image', settings: {} }] },
24
+ ],
25
+ },
26
+ ...contentBuilderBlocks.map(block => ({
27
+ type: `content-${block.type}`, label: block.label, category: 'Page builder', allowedRegions: ['body'] as ('body')[],
28
+ settings: [...(block.settings || []), ...contentSectionControls], blocks: [],
29
+ })),
30
+ ];
31
+
32
+ const text = (value: unknown) => typeof value === 'string' ? value : '';
33
+ const bounded = (value: unknown, fallback: number, min: number, max: number) => {
34
+ const number = Number(value ?? fallback);
35
+ return Number.isFinite(number) ? Math.min(max, Math.max(min, number)) : fallback;
36
+ };
37
+ const choice = (value: unknown, allowed: string[], fallback: string) => allowed.includes(text(value)) ? text(value) : fallback;
38
+ const color = (value: unknown, fallback: string) => /^#[\da-f]{3,8}$/i.test(text(value)) ? text(value) : fallback;
39
+ const align = (settings: Record<string, unknown>) => choice(settings.alignment, ['left', 'center', 'right', 'justify'], 'left');
40
+ const typography = (settings: Record<string, unknown>, fallback: number) => `text-align:${align(settings)};font-size:${bounded(settings.fontSizePx || fallback, fallback, 8, 120)}px;line-height:${bounded(settings.lineHeight, 1.6, 1, 3)};font-weight:${choice(settings.fontWeight, ['400','500','600','700','800'], '400')};color:${color(settings.textColor, 'inherit')}`;
41
+ function mediaUrl(value: unknown): string {
42
+ const url = text(value).trim();
43
+ if (url.startsWith('/') && !url.startsWith('//')) return url;
44
+ try { const parsed = new URL(url); return ['http:', 'https:'].includes(parsed.protocol) && !parsed.username && !parsed.password ? parsed.toString() : ''; } catch { return ''; }
45
+ }
46
+
47
+ /** Pure block renderer: no scripts, demo media or client-side hydration required. */
48
+ export function renderContentBlock(type: string, settings: Record<string, unknown>): string {
49
+ if (type === 'heading') {
50
+ const tag = ['h1', 'h2', 'h3', 'h4'].includes(text(settings.level)) ? text(settings.level) : 'h2';
51
+ const alignment = ['left', 'center', 'right'].includes(text(settings.alignment)) ? text(settings.alignment) : 'left';
52
+ return `<${tag} style="${typography({ ...settings, alignment, fontWeight: settings.fontWeight || '600' }, 28)}" class="text-2xl font-semibold">${escapeHtml(text(settings.text))}</${tag}>`;
53
+ }
54
+ if (type === 'text') return `<p style="white-space:pre-line;${typography(settings, settings.fontSize === 'sm' ? 14 : settings.fontSize === 'lg' ? 20 : 16)}">${escapeHtml(text(settings.content))}</p>`;
55
+ if (type === 'rich-text') return `<div class="prose max-w-none" style="${typography(settings, 16)}">${sanitizeRichText(text(settings.content))}</div>`;
56
+ if (type === 'image') {
57
+ const src = mediaUrl(settings.imageUrl);
58
+ if (!src) return '';
59
+ const widthMode = choice(settings.imageWidthMode, ['natural', 'full', 'custom'], 'natural');
60
+ const width = widthMode === 'full' ? '100%' : widthMode === 'custom' ? `${bounded(settings.imageWidth, 640, 32, 1920)}px` : 'auto';
61
+ const height = bounded(settings.imageHeight, 0, 0, 1600);
62
+ const position = choice(settings.imagePosition, ['center','top','bottom','left','right','top left','top right','bottom left','bottom right'], 'center');
63
+ const image = `<img data-element="image" src="${escapeHtml(src)}" alt="${escapeHtml(text(settings.altText))}" loading="${choice(settings.imageLoading, ['lazy','eager'], 'lazy')}" style="display:inline-block;vertical-align:middle;max-width:100%;width:${width};height:${height ? height + 'px' : 'auto'};aspect-ratio:${choice(settings.imageRatio, ['auto','1/1','4/3','3/4','16/9'], 'auto')};object-fit:${choice(settings.imageFit, ['contain','cover','fill','none'], 'contain')};object-position:${position};border-radius:${bounded(settings.imageRadius,0,0,200)}px;border:${bounded(settings.imageBorderWidth,0,0,20)}px solid ${color(settings.imageBorderColor,'#e5e7eb')};opacity:${bounded(settings.imageOpacity,100,0,100)/100}" />`;
64
+ const href = sanitizeNavUrl(settings.linkUrl, '');
65
+ const content = href ? `<a href="${escapeHtml(href)}"${settings.openNewTab === true ? ' target="_blank" rel="noopener noreferrer"' : ''}>${image}</a>` : image;
66
+ return `<figure style="margin:0;text-align:${align(settings)}">${content}${text(settings.imageCaption) ? `<figcaption class="text-sm mt-2">${escapeHtml(text(settings.imageCaption))}</figcaption>` : ''}</figure>`;
67
+ }
68
+ if (type === 'video') {
69
+ const src = mediaUrl(settings.videoUrl);
70
+ if (!src) return '';
71
+ let embed = '';
72
+ try {
73
+ const url = new URL(src);
74
+ const youtube = ['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtube-nocookie.com'].includes(url.hostname);
75
+ const id = youtube ? (url.hostname === 'youtu.be' ? url.pathname.slice(1) : url.searchParams.get('v') || url.pathname.split('/embed/')[1]) : null;
76
+ if (id && /^[\w-]{11}$/.test(id)) embed = `https://www.youtube-nocookie.com/embed/${id}`;
77
+ if (['vimeo.com', 'www.vimeo.com', 'player.vimeo.com'].includes(url.hostname)) {
78
+ const id = url.pathname.split('/').filter(Boolean).pop();
79
+ if (id && /^\d+$/.test(id)) embed = `https://player.vimeo.com/video/${id}`;
80
+ }
81
+ } catch { /* Relative URLs are native video sources. */ }
82
+ const ratio = choice(settings.videoRatio, ['16/9','4/3','1/1','9/16'], '16/9');
83
+ if (embed) {
84
+ const params = new URLSearchParams();
85
+ if (settings.autoplay === true) { params.set('autoplay','1'); params.set('mute','1'); params.set('muted','1'); }
86
+ if (settings.loop === true) { params.set('loop','1'); if (embed.includes('youtube')) params.set('playlist',embed.split('/').pop()!); }
87
+ if (settings.videoControls === false) params.set('controls','0');
88
+ return `<iframe src="${escapeHtml(embed + (params.size ? '?' + params.toString() : ''))}" title="Video" loading="lazy" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen style="width:100%;aspect-ratio:${ratio};border:0"></iframe>`;
89
+ }
90
+ if (!/\.(mp4|webm|ogg)(?:[?#]|$)/i.test(src)) return '';
91
+ const poster = mediaUrl(settings.posterImage);
92
+ return `<video${settings.videoControls !== false ? ' controls' : ''} playsinline preload="metadata" style="width:100%;aspect-ratio:${ratio}"${poster ? ` poster="${escapeHtml(poster)}"` : ''}${settings.autoplay === true ? ' autoplay muted' : settings.videoMuted === true ? ' muted' : ''}${settings.loop === true ? ' loop' : ''}><source src="${escapeHtml(src)}" /></video>`;
93
+ }
94
+ if (type === 'button') {
95
+ const href = sanitizeNavUrl(settings.url, '');
96
+ const padding = settings.buttonSize === 'small' ? '8px 16px' : settings.buttonSize === 'large' ? '18px 32px' : '12px 24px';
97
+ return href && text(settings.label) ? `<div style="text-align:${align(settings)}"><a class="sf-btn ${settings.style === 'primary' ? 'sf-btn--primary' : 'sf-btn--secondary'}" style="padding:${padding};border-radius:${bounded(settings.buttonRadius,8,0,100)}px;${settings.buttonFullWidth === true ? 'width:100%;' : ''}" href="${escapeHtml(href)}"${settings.openNewTab === true ? ' target="_blank" rel="noopener noreferrer"' : ''}>${escapeHtml(text(settings.label))}</a></div>` : '';
98
+ }
99
+ if (type === 'spacer') return `<div aria-hidden="true" style="height:${bounded(settings.height, 32, 0, 256)}px">${settings.showDivider === true ? `<hr style="margin-inline:auto;width:${bounded(settings.dividerWidth,100,1,100)}%;border:0;border-top:${bounded(settings.dividerThickness,1,1,12)}px solid ${color(settings.dividerColor,'#e5e7eb')}" />` : ''}</div>`;
100
+ return '';
101
+ }
102
+
103
+ export function renderContentBuilder(ctx: SectionRenderContext): string {
104
+ const section = ctx.section;
105
+ const settings = section.settings || {};
106
+ const columns = Math.round(bounded(settings.columns, 1, 1, 4));
107
+ const alignment = ['left', 'center', 'right'].includes(text(settings.alignment)) ? text(settings.alignment) : 'left';
108
+ const blocks = section.type === 'content-container' ? (section.blocks || []) : [{ id: `${section.id}-content`, type: section.type.replace(/^content-/, ''), settings }];
109
+ const blockSpacing = (block: typeof blocks[number]) => {
110
+ if (section.type !== 'content-container') return '';
111
+ const styles = { ...(block.settings?.styles as object || {}), ...('styles' in block && typeof block.styles === 'object' ? block.styles : {}) } as Record<string, unknown>;
112
+ return ['Top', 'Right', 'Bottom', 'Left'].flatMap(side => {
113
+ const padding = sanitizePaddingValue(styles[`padding${side}`] ?? block.settings?.[`padding${side}`]);
114
+ const margin = sanitizeMarginCssValue(styles[`margin${side}`] ?? block.settings?.[`margin${side}`]);
115
+ return [padding !== undefined ? `padding-${side.toLowerCase()}:${padding}px` : '', margin !== undefined ? `margin-${side.toLowerCase()}:${margin}` : ''].filter(Boolean);
116
+ }).join(';');
117
+ };
118
+ return `<section id="${escapeHtml(section.id)}" data-section-id="${escapeHtml(section.id)}" data-section-type="${escapeHtml(section.type)}" class="sf-content-builder" style="text-align:${alignment};background-color:${color(settings.sectionBackground,'transparent')};border-radius:${bounded(settings.sectionRadius,0,0,200)}px;min-height:${bounded(settings.sectionMinHeight,0,0,1200)}px">
119
+ <div class="sf-content-builder__grid sf-content-builder__grid--${columns}" style="max-width:${bounded(settings.maxWidth, 1200, 320, 1920)}px;margin-inline:auto;padding-inline:16px;gap:${bounded(settings.gap, 24, 0, 96)}px;align-items:${choice(settings.verticalAlignment,['start','center','end','stretch'],'start')}">
120
+ ${blocks.map(block => `<div data-block-id="${escapeHtml(block.id)}" data-block-type="${escapeHtml(block.type)}" style="min-width:0;${blockSpacing(block)}">${renderContentBlock(block.type, block.settings || {})}</div>`).join('')}
121
+ </div>
122
+ </section>`;
123
+ }
@@ -0,0 +1,45 @@
1
+ import type { BlockManifest, SettingField } from '@caartzee/theme-sdk';
2
+
3
+ const select = (id: string, label: string, values: string[], value: string): SettingField => ({ id, label, type: 'select', default: value, options: values.map(value => ({ label: value, value })) });
4
+ const range = (id: string, label: string, value: number, min: number, max: number): SettingField => ({ id, label, type: 'range', default: value, min, max, step: 1 });
5
+ const alignment = select('alignment', 'Alignment', ['left', 'center', 'right'], 'left');
6
+ const color: SettingField = { id: 'textColor', label: 'Text color', type: 'color', default: '#111827' };
7
+ const typography: SettingField[] = [alignment, range('fontSizePx', 'Font size in px (0 = theme default)', 0, 0, 120), select('fontWeight', 'Font weight', ['400', '500', '600', '700', '800'], '400'), { id: 'lineHeight', label: 'Line height', type: 'number', default: 1.6, min: 1, max: 3, step: 0.1 }, color];
8
+
9
+ export const contentSectionControls: SettingField[] = [
10
+ range('maxWidth', 'Content width (px)', 1200, 320, 1920),
11
+ range('sectionMinHeight', 'Minimum section height (px)', 0, 0, 1200),
12
+ { id: 'sectionBackground', label: 'Section background color', type: 'color' },
13
+ range('sectionRadius', 'Section corner radius (px)', 0, 0, 200),
14
+ ];
15
+
16
+ export function withContentControls(block: BlockManifest): BlockManifest {
17
+ let extra: SettingField[] = [];
18
+ if (['heading', 'text', 'rich-text'].includes(block.type)) extra = typography.map(field => block.type === 'heading' && field.id === 'fontWeight' ? { ...field, default: '600' } : field);
19
+ if (block.type === 'image') extra = [
20
+ alignment,
21
+ select('imageWidthMode', 'Image width', ['natural', 'full', 'custom'], 'natural'),
22
+ range('imageWidth', 'Custom image width (px)', 640, 32, 1920),
23
+ range('imageHeight', 'Image height in px (0 = automatic)', 0, 0, 1600),
24
+ select('imageRatio', 'Aspect ratio', ['auto', '1/1', '4/3', '3/4', '16/9'], 'auto'),
25
+ select('imageFit', 'Image fit', ['contain', 'cover', 'fill', 'none'], 'contain'),
26
+ select('imagePosition', 'Crop position', ['center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right'], 'center'),
27
+ range('imageRadius', 'Image corner radius (px)', 0, 0, 200),
28
+ range('imageBorderWidth', 'Image border width (px)', 0, 0, 20),
29
+ { id: 'imageBorderColor', label: 'Image border color', type: 'color', default: '#e5e7eb' },
30
+ range('imageOpacity', 'Image opacity (%)', 100, 0, 100),
31
+ { id: 'imageCaption', label: 'Image caption', type: 'text' },
32
+ select('imageLoading', 'Image loading', ['lazy', 'eager'], 'lazy'),
33
+ { id: 'openNewTab', label: 'Open link in new tab', type: 'boolean', default: false },
34
+ ];
35
+ if (block.type === 'video') extra = [
36
+ select('videoRatio', 'Video aspect ratio', ['16/9', '4/3', '1/1', '9/16'], '16/9'),
37
+ { id: 'posterImage', label: 'Video poster image', type: 'image' },
38
+ { id: 'videoControls', label: 'Show video controls', type: 'boolean', default: true },
39
+ { id: 'videoMuted', label: 'Mute video', type: 'boolean', default: false },
40
+ ];
41
+ if (block.type === 'button') extra = [alignment, { id: 'buttonFullWidth', label: 'Full width button', type: 'boolean', default: false }, range('buttonRadius', 'Button corner radius (px)', 8, 0, 100), select('buttonSize', 'Button size', ['small', 'medium', 'large'], 'medium'), { id: 'openNewTab', label: 'Open link in new tab', type: 'boolean', default: false }];
42
+ if (block.type === 'spacer') extra = [range('dividerWidth', 'Divider width (%)', 100, 1, 100), range('dividerThickness', 'Divider thickness (px)', 1, 1, 12), { id: 'dividerColor', label: 'Divider color', type: 'color', default: '#e5e7eb' }];
43
+ // Existing identifiers/defaults keep their meaning for saved documents.
44
+ return { ...block, settings: [...(block.settings || []), ...extra.filter(field => !block.settings?.some(existing => existing.id === field.id))] };
45
+ }
@@ -0,0 +1,59 @@
1
+ import type { SectionRenderContext } from '@caartzee/theme-sdk';
2
+
3
+ function escapeHtml(str: string): string {
4
+ return str
5
+ .replace(/&/g, '&amp;')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;')
8
+ .replace(/"/g, '&quot;')
9
+ .replace(/'/g, '&#039;');
10
+ }
11
+
12
+ export function renderCustomForm(ctx: SectionRenderContext): string {
13
+ const settings = ctx.section.settings || {};
14
+ const heading =
15
+ typeof settings.heading === 'string'
16
+ ? settings.heading
17
+ : typeof settings.title === 'string'
18
+ ? settings.title
19
+ : 'Contact Us';
20
+ const description =
21
+ typeof settings.description === 'string'
22
+ ? settings.description
23
+ : typeof settings.subheading === 'string'
24
+ ? settings.subheading
25
+ : '';
26
+ const formId = settings.formId || settings.form_id || '';
27
+ const containerWidth =
28
+ settings.containerWidth === 'full'
29
+ ? 'w-full px-4 sm:px-6'
30
+ : 'max-w-4xl mx-auto px-4 sm:px-6 lg:px-8';
31
+ const bgColor =
32
+ typeof settings.backgroundColor === 'string' && settings.backgroundColor
33
+ ? `background-color: ${escapeHtml(settings.backgroundColor)};`
34
+ : '';
35
+
36
+ return `
37
+ <section class="sf-section sf-custom-form py-14 sm:py-20" id="${escapeHtml(ctx.section.id)}" data-section-id="${escapeHtml(ctx.section.id)}" data-section-type="custom-form" data-region="body" style="${bgColor}">
38
+ <div class="sf-custom-form-wrapper ${containerWidth}">
39
+ <div class="sf-custom-form-header text-center mb-10 max-w-2xl mx-auto space-y-2.5" ${heading || description ? '' : 'style="display:none;"'}>
40
+ <h2 class="text-2xl sm:text-3xl font-extrabold text-slate-900 dark:text-white tracking-tight" data-setting="heading">${escapeHtml(heading || '')}</h2>
41
+ <p class="text-sm text-slate-600 dark:text-slate-300 leading-relaxed" data-setting="description">${escapeHtml(description || '')}</p>
42
+ </div>
43
+ <div class="sf-custom-form-container bg-white dark:bg-zinc-900 rounded-2xl border border-slate-200/80 dark:border-zinc-800 p-6 sm:p-10 shadow-sm" data-form-id="${escapeHtml(String(formId))}">
44
+ ${
45
+ formId
46
+ ? `
47
+ <div id="custom-form-mount-${escapeHtml(String(formId))}" data-published-form-id="${escapeHtml(String(formId))}">
48
+ <div class="text-center py-6 text-slate-400 text-xs animate-pulse">Loading form...</div>
49
+ </div>
50
+ `
51
+ : `
52
+ <div class="text-center py-8 text-slate-400 text-xs italic sf-custom-form-empty">No form selected for this section.</div>
53
+ `
54
+ }
55
+ </div>
56
+ </div>
57
+ </section>
58
+ `;
59
+ }
@@ -0,0 +1,123 @@
1
+ import type { SectionRenderContext } from '@caartzee/theme-sdk';
2
+ import { escapeHtml } from '@caartzee/theme-sdk';
3
+
4
+ export interface FaqItemSettings {
5
+ question?: string;
6
+ title?: string;
7
+ answer?: string;
8
+ content?: string;
9
+ }
10
+
11
+ export interface FaqAccordionSettings {
12
+ title?: string;
13
+ heading?: string;
14
+ subtitle?: string;
15
+ subheading?: string;
16
+ maxWidth?: 'narrow' | 'standard' | 'wide' | string;
17
+ }
18
+
19
+ /**
20
+ * Reusable FAQ Accordion Section
21
+ *
22
+ * Built using native semantic HTML5 `<details>` and `<summary>` elements.
23
+ * Features:
24
+ * - 100% keyboard-navigable and accessible out of the box (Enter / Space).
25
+ * - Zero third-party JavaScript dependencies.
26
+ * - CSS-animated rotating indicator chevron.
27
+ * - Focus-visible ring indicators for high accessibility.
28
+ * - Handles missing questions/answers safely.
29
+ */
30
+ export function renderFaqAccordion(ctx: SectionRenderContext): string {
31
+ const settings = (ctx.section.settings || {}) as FaqAccordionSettings;
32
+ const blocks = ctx.section.blocks || [];
33
+
34
+ const rawHeading = settings.heading || settings.title || 'Frequently Asked Questions';
35
+ const rawSubheading = settings.subheading || settings.subtitle || 'Answers to common inquiries about sizing, delivery, and orders';
36
+ const heading = typeof rawHeading === 'string' ? rawHeading.trim() : '';
37
+ const subheading = typeof rawSubheading === 'string' ? rawSubheading.trim() : '';
38
+
39
+ // Extract valid items
40
+ const items: FaqItemSettings[] = [];
41
+ for (const block of blocks) {
42
+ const bs = (block.settings || {}) as FaqItemSettings;
43
+ const q = bs.question || bs.title || '';
44
+ const a = bs.answer || bs.content || '';
45
+ const question = typeof q === 'string' ? q.trim() : '';
46
+ const answer = typeof a === 'string' ? a.trim() : '';
47
+
48
+ if (question && answer) {
49
+ items.push({ question, answer });
50
+ }
51
+ }
52
+
53
+ // Safe empty state: do not fabricate business promises or return policies if unconfigured
54
+ if (items.length === 0) {
55
+ return '';
56
+ }
57
+
58
+ const effectiveItems = items;
59
+
60
+ const maxWidthSetting = settings.maxWidth || 'standard';
61
+ let maxWidthClass = 'max-w-3xl';
62
+ if (maxWidthSetting === 'narrow') maxWidthClass = 'max-w-2xl';
63
+ if (maxWidthSetting === 'wide') maxWidthClass = 'max-w-4xl';
64
+
65
+ const sectionId = escapeHtml(ctx.section.id || 'faq-accordion');
66
+
67
+ const itemsHtml = effectiveItems.map((item, idx) => {
68
+ const q = escapeHtml(item.question || '');
69
+ const a = escapeHtml(item.answer || '');
70
+
71
+ return `
72
+ <details
73
+ class="group border border-neutral-200/90 dark:border-neutral-800 rounded-xl bg-white dark:bg-neutral-900/60 shadow-sm mb-3 overflow-hidden transition-all duration-200"
74
+ data-element="faq-item"
75
+ data-index="${idx}"
76
+ >
77
+ <summary
78
+ class="flex items-center justify-between gap-4 p-5 sm:p-6 text-left font-semibold text-neutral-900 dark:text-white cursor-pointer select-none list-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-neutral-900 dark:focus-visible:ring-white rounded-xl"
79
+ data-element="faq-question"
80
+ >
81
+ <span class="text-base sm:text-lg leading-snug">${q}</span>
82
+ <span
83
+ class="flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300 group-open:rotate-180 transition-transform duration-200"
84
+ aria-hidden="true"
85
+ >
86
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
87
+ <polyline points="6 9 12 15 18 9"></polyline>
88
+ </svg>
89
+ </span>
90
+ </summary>
91
+ <div
92
+ class="px-5 sm:px-6 pb-5 sm:pb-6 pt-1 text-sm sm:text-base text-neutral-600 dark:text-neutral-300 leading-relaxed border-t border-neutral-100 dark:border-neutral-800/80"
93
+ data-element="faq-answer"
94
+ >
95
+ ${a}
96
+ </div>
97
+ </details>
98
+ `.trim();
99
+ }).join('\n');
100
+
101
+ return `
102
+ <section
103
+ class="sf-section sf-faq-accordion py-12 sm:py-16"
104
+ id="${sectionId}"
105
+ data-element="faq-accordion"
106
+ role="region"
107
+ aria-label="${heading || 'Frequently Asked Questions'}"
108
+ >
109
+ <div class="sf-container mx-auto px-4 sm:px-6 lg:px-8">
110
+ ${(heading || subheading) ? `
111
+ <div class="sf-section-header text-center max-w-2xl mx-auto mb-10 sm:mb-14">
112
+ ${heading ? `<h2 class="text-2xl sm:text-3xl font-bold tracking-tight text-neutral-900 dark:text-white mb-2">${escapeHtml(heading)}</h2>` : ''}
113
+ ${subheading ? `<p class="text-sm sm:text-base text-neutral-500 dark:text-neutral-400">${escapeHtml(subheading)}</p>` : ''}
114
+ </div>
115
+ ` : ''}
116
+
117
+ <div class="${maxWidthClass} mx-auto">
118
+ ${itemsHtml}
119
+ </div>
120
+ </div>
121
+ </section>
122
+ `.trim();
123
+ }