@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.
- package/README.md +34 -2
- package/dist/bin/caartzee-theme.js +7449 -0
- package/dist/lib/index.js +9838 -0
- package/dist/types/src/auth/credentials-store.d.ts +18 -0
- package/dist/types/src/auth/index.d.ts +2 -0
- package/dist/types/src/auth/oauth-client.d.ts +39 -0
- package/dist/types/src/blocks/block-contract.d.ts +242 -0
- package/dist/types/src/candy/compatibility-matrix.d.ts +10 -0
- package/dist/types/src/candy/context-builder.d.ts +31 -0
- package/dist/types/src/candy/engine.d.ts +69 -0
- package/dist/types/src/candy/filters.d.ts +32 -0
- package/dist/types/src/candy/ide-support.d.ts +20 -0
- package/dist/types/src/candy/index.d.ts +9 -0
- package/dist/types/src/candy/schema-parser.d.ts +13 -0
- package/dist/types/src/candy/security.d.ts +54 -0
- package/dist/types/src/candy/tags.d.ts +11 -0
- package/dist/types/src/candy/types.d.ts +185 -0
- package/dist/types/src/cli/caartzee-cli.d.ts +9 -0
- package/dist/types/src/cli/index.d.ts +1 -0
- package/dist/types/src/cli/sdk-client.d.ts +12 -0
- package/dist/types/src/contracts/category-selection.d.ts +15 -0
- package/dist/types/src/contracts/commerce.d.ts +282 -0
- package/dist/types/src/contracts/footer-builder.d.ts +125 -0
- package/dist/types/src/contracts/hooks.d.ts +37 -0
- package/dist/types/src/contracts/manifest.d.ts +3127 -0
- package/dist/types/src/contracts/navigation.d.ts +39 -0
- package/dist/types/src/contracts/order-tracking.d.ts +40 -0
- package/dist/types/src/contracts/page.d.ts +262 -0
- package/dist/types/src/contracts/storefront-content.d.ts +60 -0
- package/dist/types/src/contracts/style-document.d.ts +2 -0
- package/dist/types/src/contracts/styles.d.ts +2002 -0
- package/dist/types/src/contracts/theme.d.ts +35 -0
- package/dist/types/src/dev-server/catalog-preview.d.ts +25 -0
- package/dist/types/src/dev-server/dev-server.d.ts +22 -0
- package/dist/types/src/dev-server/index.d.ts +1 -0
- package/dist/types/src/dev-server/theme-preview.d.ts +4 -0
- package/dist/types/src/index.d.ts +27 -0
- package/dist/types/src/mock/index.d.ts +10 -0
- package/dist/types/src/mock/mock-categories.d.ts +2 -0
- package/dist/types/src/mock/mock-commerce.d.ts +55 -0
- package/dist/types/src/mock/mock-customer.d.ts +47 -0
- package/dist/types/src/mock/mock-hooks.d.ts +2 -0
- package/dist/types/src/mock/mock-products.d.ts +3 -0
- package/dist/types/src/rendering/commerce-pages.d.ts +16 -0
- package/dist/types/src/rendering/raw-html.d.ts +12 -0
- package/dist/types/src/rendering/section-wrapper.d.ts +30 -0
- package/dist/types/src/scaffold/candy-starter-assets.d.ts +2 -0
- package/dist/types/src/scaffold/commerce-generator.d.ts +3 -0
- package/dist/types/src/scaffold/index.d.ts +2 -0
- package/dist/types/src/scaffold/template-generator.d.ts +21 -0
- package/dist/types/src/sections/section-contract.d.ts +350 -0
- package/dist/types/src/settings/global-settings.d.ts +25 -0
- package/dist/types/src/templates/json-template.d.ts +991 -0
- package/dist/types/src/validation/package-validator.d.ts +53 -0
- package/dist/types/src/validation/rich-text.d.ts +24 -0
- package/package.json +28 -3
- package/templates/commerce/README.md +165 -0
- package/templates/commerce/assets/theme.css +1 -0
- package/templates/commerce/manifest.json +1 -0
- package/templates/commerce/src/blocks/index.ts +184 -0
- package/templates/commerce/src/config/settings-defaults.ts +25 -0
- package/templates/commerce/src/config/settings-schema.ts +102 -0
- package/templates/commerce/src/index.ts +90 -0
- package/templates/commerce/src/layouts/default.ts +275 -0
- package/templates/commerce/src/manifest.ts +976 -0
- package/templates/commerce/src/pages/account/components.ts +369 -0
- package/templates/commerce/src/pages/account/tabs.ts +792 -0
- package/templates/commerce/src/pages/account.ts +55 -0
- package/templates/commerce/src/pages/campaign.ts +423 -0
- package/templates/commerce/src/pages/cart.ts +261 -0
- package/templates/commerce/src/pages/category-detail.ts +124 -0
- package/templates/commerce/src/pages/category-list.ts +87 -0
- package/templates/commerce/src/pages/checkout.ts +712 -0
- package/templates/commerce/src/pages/commerce.ts +45 -0
- package/templates/commerce/src/pages/home.ts +160 -0
- package/templates/commerce/src/pages/index.ts +99 -0
- package/templates/commerce/src/pages/login.ts +204 -0
- package/templates/commerce/src/pages/order-success.ts +80 -0
- package/templates/commerce/src/pages/product-detail.ts +489 -0
- package/templates/commerce/src/pages/product-list.ts +125 -0
- package/templates/commerce/src/pages/search.ts +88 -0
- package/templates/commerce/src/pages/signup.ts +253 -0
- package/templates/commerce/src/pages/status.ts +7 -0
- package/templates/commerce/src/pages/theme-layout.ts +491 -0
- package/templates/commerce/src/pages/track-order.ts +196 -0
- package/templates/commerce/src/pages/wishlist.ts +83 -0
- package/templates/commerce/src/sections/about-story.ts +117 -0
- package/templates/commerce/src/sections/announcement-bar.ts +101 -0
- package/templates/commerce/src/sections/banner-grid.ts +319 -0
- package/templates/commerce/src/sections/campaign-banners.ts +158 -0
- package/templates/commerce/src/sections/category-slider.ts +144 -0
- package/templates/commerce/src/sections/content-builder.ts +123 -0
- package/templates/commerce/src/sections/content-controls.ts +45 -0
- package/templates/commerce/src/sections/custom-form.ts +59 -0
- package/templates/commerce/src/sections/faq-accordion.ts +123 -0
- package/templates/commerce/src/sections/footer.ts +728 -0
- package/templates/commerce/src/sections/header.ts +439 -0
- package/templates/commerce/src/sections/hero-slider.ts +492 -0
- package/templates/commerce/src/sections/hero.ts +137 -0
- package/templates/commerce/src/sections/index.ts +102 -0
- package/templates/commerce/src/sections/mobile-slider.ts +102 -0
- package/templates/commerce/src/sections/newsletter.ts +43 -0
- package/templates/commerce/src/sections/product-grid.ts +191 -0
- package/templates/commerce/src/sections/raw-html.ts +1 -0
- package/templates/commerce/src/sections/rich-text.ts +26 -0
- package/templates/commerce/src/sections/services-features.ts +211 -0
- package/templates/commerce/src/sections/testimonials.ts +194 -0
- package/templates/commerce/src/snippets/product-card.ts +178 -0
- package/templates/commerce/src/snippets/product-price.ts +46 -0
- package/templates/commerce/src/snippets/responsive-image.ts +29 -0
- package/templates/commerce/src/styles.ts +477 -0
- package/templates/commerce/src/templates/404.json +26 -0
- package/templates/commerce/src/templates/account.json +17 -0
- package/templates/commerce/src/templates/cart.json +17 -0
- package/templates/commerce/src/templates/category.json +16 -0
- package/templates/commerce/src/templates/checkout.json +15 -0
- package/templates/commerce/src/templates/collection.json +16 -0
- package/templates/commerce/src/templates/index.json +180 -0
- package/templates/commerce/src/templates/login.json +17 -0
- package/templates/commerce/src/templates/order-success.json +17 -0
- package/templates/commerce/src/templates/page.json +17 -0
- package/templates/commerce/src/templates/product.json +17 -0
- package/templates/commerce/src/templates/search.json +18 -0
- package/templates/commerce/src/templates/signup.json +17 -0
- package/templates/commerce/src/templates/track-order.json +17 -0
- package/templates/commerce/src/templates/wishlist.json +17 -0
- package/templates/commerce/src/templates.ts +510 -0
- package/templates/commerce/src/tokens.ts +22 -0
- package/templates/vscode-candy/README.md +22 -0
- package/templates/vscode-candy/extension.js +338 -0
- package/templates/vscode-candy/icons/candy-dark.svg +23 -0
- package/templates/vscode-candy/icons/candy-light.svg +23 -0
- package/templates/vscode-candy/icons/candy-logo.png +0 -0
- package/templates/vscode-candy/icons/candy-sweet-dark.svg +23 -0
- package/templates/vscode-candy/icons/candy-sweet-light.svg +23 -0
- package/templates/vscode-candy/language-configuration.json +47 -0
- package/templates/vscode-candy/package.json +103 -0
- package/templates/vscode-candy/schemas/candy-config.schema.json +56 -0
- package/templates/vscode-candy/schemas/candy-settings.schema.json +70 -0
- package/templates/vscode-candy/snippets/candy.code-snippets +179 -0
- package/templates/vscode-candy/syntaxes/candy.tmLanguage.json +296 -0
- package/templates/vscode-candy/vim/ftdetect/candy.vim +5 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { SectionRenderContext } from '@caartzee/theme-sdk';
|
|
2
|
+
import { escapeHtml, sanitizeNavUrl } from '@caartzee/theme-sdk';
|
|
3
|
+
|
|
4
|
+
export interface FeatureItemSettings {
|
|
5
|
+
title?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
linkUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ServicesFeaturesSettings {
|
|
12
|
+
title?: string;
|
|
13
|
+
heading?: string;
|
|
14
|
+
subtitle?: string;
|
|
15
|
+
subheading?: string;
|
|
16
|
+
columns?: number;
|
|
17
|
+
bordered?: boolean;
|
|
18
|
+
variant?: 'strip' | 'cards' | string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getFeatureIconSvg(icon: string = ''): string {
|
|
22
|
+
const norm = String(icon || '').toLowerCase().trim();
|
|
23
|
+
switch (norm) {
|
|
24
|
+
case 'truck':
|
|
25
|
+
case 'shipping':
|
|
26
|
+
case 'delivery':
|
|
27
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="1" y="3" width="15" height="13"></rect><polygon points="16 8 20 8 23 11 23 16 16 16 16 8"></polygon><circle cx="5.5" cy="18.5" r="2.5"></circle><circle cx="18.5" cy="18.5" r="2.5"></circle></svg>`;
|
|
28
|
+
case 'shield':
|
|
29
|
+
case 'security':
|
|
30
|
+
case 'protection':
|
|
31
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path><path d="m9 12 2 2 4-4"></path></svg>`;
|
|
32
|
+
case 'refresh':
|
|
33
|
+
case 'return':
|
|
34
|
+
case 'returns':
|
|
35
|
+
case 'exchange':
|
|
36
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="1 4 1 10 7 10"></polyline><polyline points="23 20 23 14 17 14"></polyline><path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15"></path></svg>`;
|
|
37
|
+
case 'headphones':
|
|
38
|
+
case 'support':
|
|
39
|
+
case 'help':
|
|
40
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 18v-6a9 9 0 0 1 18 0v6"></path><path d="M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"></path></svg>`;
|
|
41
|
+
case 'package':
|
|
42
|
+
case 'gift':
|
|
43
|
+
case 'box':
|
|
44
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="16.5" y1="9.4" x2="7.5" y2="4.21"></line><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path><polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline><line x1="12" y1="22.08" x2="12" y2="12"></line></svg>`;
|
|
45
|
+
case 'lock':
|
|
46
|
+
case 'payment':
|
|
47
|
+
case 'checkout':
|
|
48
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>`;
|
|
49
|
+
case 'star':
|
|
50
|
+
case 'badge':
|
|
51
|
+
case 'quality':
|
|
52
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>`;
|
|
53
|
+
default:
|
|
54
|
+
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><path d="m9 12 2 2 4-4"></path></svg>`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Reusable Services & Features / Trust Badges Section
|
|
60
|
+
*
|
|
61
|
+
* Supports warm cream horizontal strip mode (default when variant === 'strip' or !bordered)
|
|
62
|
+
* and standalone card grid mode. Never renders fabricated promises if blocks are empty.
|
|
63
|
+
*/
|
|
64
|
+
export function renderServicesFeatures(ctx: SectionRenderContext): string {
|
|
65
|
+
const settings = (ctx.section.settings || {}) as ServicesFeaturesSettings;
|
|
66
|
+
const blocks = ctx.section.blocks || [];
|
|
67
|
+
|
|
68
|
+
const rawHeading = settings.heading || settings.title || '';
|
|
69
|
+
const rawSubheading = settings.subheading || settings.subtitle || '';
|
|
70
|
+
const heading = typeof rawHeading === 'string' ? rawHeading.trim() : '';
|
|
71
|
+
const subheading = typeof rawSubheading === 'string' ? rawSubheading.trim() : '';
|
|
72
|
+
|
|
73
|
+
// Extract items from blocks only; do not fabricate commercial promises
|
|
74
|
+
const items: FeatureItemSettings[] = [];
|
|
75
|
+
for (const block of blocks) {
|
|
76
|
+
const bs = (block.settings || {}) as FeatureItemSettings;
|
|
77
|
+
const title = typeof bs.title === 'string' ? bs.title.trim() : '';
|
|
78
|
+
if (title) {
|
|
79
|
+
items.push({
|
|
80
|
+
title,
|
|
81
|
+
description: typeof bs.description === 'string' ? bs.description.trim() : '',
|
|
82
|
+
icon: typeof bs.icon === 'string' ? bs.icon.trim() : 'check',
|
|
83
|
+
linkUrl: typeof bs.linkUrl === 'string' ? sanitizeNavUrl(bs.linkUrl, '') : '',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (items.length === 0) {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const columns = Math.min(Math.max(Number(settings.columns || 4), 2), 4);
|
|
93
|
+
const variant = settings.variant || (settings.bordered === false ? 'strip' : 'strip');
|
|
94
|
+
const isStrip = variant !== 'cards';
|
|
95
|
+
|
|
96
|
+
const colClass = columns === 2
|
|
97
|
+
? 'grid-cols-1 sm:grid-cols-2'
|
|
98
|
+
: (columns === 3 ? 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3' : 'grid-cols-2 lg:grid-cols-4');
|
|
99
|
+
|
|
100
|
+
const sectionId = escapeHtml(ctx.section.id || 'services-features');
|
|
101
|
+
|
|
102
|
+
if (isStrip) {
|
|
103
|
+
const stripItemsHtml = items.map((item, idx) => {
|
|
104
|
+
const title = escapeHtml(item.title || '');
|
|
105
|
+
const desc = escapeHtml(item.description || '');
|
|
106
|
+
const iconSvg = getFeatureIconSvg(item.icon);
|
|
107
|
+
|
|
108
|
+
return `
|
|
109
|
+
<div
|
|
110
|
+
class="sf-feature-card flex items-center justify-center gap-3.5 px-4 py-3 sm:py-1"
|
|
111
|
+
data-element="feature-item"
|
|
112
|
+
data-index="${idx}"
|
|
113
|
+
>
|
|
114
|
+
<div
|
|
115
|
+
class="sf-feature-card__icon flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center text-[#1c1613]"
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
>
|
|
118
|
+
${iconSvg}
|
|
119
|
+
</div>
|
|
120
|
+
<div class="sf-feature-card__body min-w-0 text-left">
|
|
121
|
+
<h3 class="sf-feature-card__title text-xs sm:text-sm font-bold text-[#1c1613] leading-tight">
|
|
122
|
+
${title}
|
|
123
|
+
</h3>
|
|
124
|
+
${desc ? `
|
|
125
|
+
<p class="sf-feature-card__desc text-[11px] sm:text-xs text-[#73655b] leading-snug mt-0.5">
|
|
126
|
+
${desc}
|
|
127
|
+
</p>
|
|
128
|
+
` : ''}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
`.trim();
|
|
132
|
+
}).join('\n');
|
|
133
|
+
|
|
134
|
+
return `
|
|
135
|
+
<section
|
|
136
|
+
class="sf-section sf-services-features w-full bg-[#f8f0e8] border-y border-[#eaded2] py-4 sm:py-5"
|
|
137
|
+
id="${sectionId}"
|
|
138
|
+
data-element="services-features"
|
|
139
|
+
role="region"
|
|
140
|
+
aria-label="${heading || 'Store Features'}"
|
|
141
|
+
>
|
|
142
|
+
<div class="max-w-[1360px] mx-auto px-4 sm:px-6 lg:px-8">
|
|
143
|
+
${(heading || subheading) ? `
|
|
144
|
+
<div class="sf-section-header text-center max-w-2xl mx-auto mb-5">
|
|
145
|
+
${heading ? `<h2 class="text-xl sm:text-2xl font-bold font-heading text-[#1c1613] mb-1">${escapeHtml(heading)}</h2>` : ''}
|
|
146
|
+
${subheading ? `<p class="text-xs sm:text-sm text-[#73655b]">${escapeHtml(subheading)}</p>` : ''}
|
|
147
|
+
</div>
|
|
148
|
+
` : ''}
|
|
149
|
+
|
|
150
|
+
<div class="sf-features-grid grid ${colClass} gap-3 lg:gap-0 lg:divide-x divide-[#e4d5c7]">
|
|
151
|
+
${stripItemsHtml}
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
</section>
|
|
155
|
+
`.trim();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const itemsHtml = items.map((item, idx) => {
|
|
159
|
+
const title = escapeHtml(item.title || '');
|
|
160
|
+
const desc = escapeHtml(item.description || '');
|
|
161
|
+
const iconSvg = getFeatureIconSvg(item.icon);
|
|
162
|
+
|
|
163
|
+
return `
|
|
164
|
+
<div
|
|
165
|
+
class="sf-feature-card flex items-start gap-4 p-5 sm:p-6 rounded-2xl border border-[#eae0d5] bg-white shadow-sm transition-all duration-200 hover:shadow-md"
|
|
166
|
+
data-element="feature-item"
|
|
167
|
+
data-index="${idx}"
|
|
168
|
+
>
|
|
169
|
+
<div
|
|
170
|
+
class="sf-feature-card__icon flex-shrink-0 w-11 h-11 rounded-xl flex items-center justify-center bg-[#f6efe7] text-[#1c1613]"
|
|
171
|
+
aria-hidden="true"
|
|
172
|
+
>
|
|
173
|
+
${iconSvg}
|
|
174
|
+
</div>
|
|
175
|
+
<div class="sf-feature-card__body min-w-0 flex-1">
|
|
176
|
+
<h3 class="sf-feature-card__title text-sm sm:text-base font-semibold text-[#1c1613] leading-snug mb-1">
|
|
177
|
+
${title}
|
|
178
|
+
</h3>
|
|
179
|
+
${desc ? `
|
|
180
|
+
<p class="sf-feature-card__desc text-xs sm:text-sm text-[#73655b] leading-relaxed">
|
|
181
|
+
${desc}
|
|
182
|
+
</p>
|
|
183
|
+
` : ''}
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
`.trim();
|
|
187
|
+
}).join('\n');
|
|
188
|
+
|
|
189
|
+
return `
|
|
190
|
+
<section
|
|
191
|
+
class="sf-section sf-services-features py-8 sm:py-12"
|
|
192
|
+
id="${sectionId}"
|
|
193
|
+
data-element="services-features"
|
|
194
|
+
role="region"
|
|
195
|
+
aria-label="${heading || 'Store Features'}"
|
|
196
|
+
>
|
|
197
|
+
<div class="max-w-[1360px] mx-auto px-4 sm:px-6 lg:px-8">
|
|
198
|
+
${(heading || subheading) ? `
|
|
199
|
+
<div class="sf-section-header text-center max-w-2xl mx-auto mb-8 sm:mb-10">
|
|
200
|
+
${heading ? `<h2 class="text-2xl sm:text-3xl font-bold font-heading tracking-tight text-[#1c1613] mb-2">${escapeHtml(heading)}</h2>` : ''}
|
|
201
|
+
${subheading ? `<p class="text-sm sm:text-base text-[#73655b]">${escapeHtml(subheading)}</p>` : ''}
|
|
202
|
+
</div>
|
|
203
|
+
` : ''}
|
|
204
|
+
|
|
205
|
+
<div class="sf-features-grid grid ${colClass} gap-4 sm:gap-6">
|
|
206
|
+
${itemsHtml}
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</section>
|
|
210
|
+
`.trim();
|
|
211
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { SectionRenderContext } from '@caartzee/theme-sdk';
|
|
2
|
+
import { escapeHtml } from '@caartzee/theme-sdk';
|
|
3
|
+
|
|
4
|
+
export interface TestimonialItemSettings {
|
|
5
|
+
author?: string;
|
|
6
|
+
role?: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
quote?: string;
|
|
9
|
+
review?: string;
|
|
10
|
+
rating?: number;
|
|
11
|
+
verified?: boolean;
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
avatarImage?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TestimonialsSettings {
|
|
17
|
+
title?: string;
|
|
18
|
+
heading?: string;
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
subheading?: string;
|
|
21
|
+
columns?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function renderStarRating(rating: number = 5): string {
|
|
25
|
+
const boundedRating = Math.min(Math.max(Math.round(rating), 1), 5);
|
|
26
|
+
const stars: string[] = [];
|
|
27
|
+
|
|
28
|
+
for (let i = 1; i <= 5; i++) {
|
|
29
|
+
const isFilled = i <= boundedRating;
|
|
30
|
+
stars.push(
|
|
31
|
+
`<svg class="w-4 h-4 ${isFilled ? 'text-amber-400 fill-amber-400' : 'text-neutral-200 dark:text-neutral-700 fill-neutral-200 dark:fill-neutral-700'}" viewBox="0 0 20 20" aria-hidden="true"><path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"></path></svg>`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return stars.join('');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reusable Testimonials / Customer Reviews Section
|
|
40
|
+
*
|
|
41
|
+
* Renders real customer quotes, ratings, and author identities in a responsive grid.
|
|
42
|
+
* Avoids heavy client-side carousel dependencies.
|
|
43
|
+
* If no valid review items exist, renders nothing or follows standard empty-state convention.
|
|
44
|
+
* Never fabricates star ratings or verified-purchaser status when absent.
|
|
45
|
+
*/
|
|
46
|
+
export function renderTestimonials(ctx: SectionRenderContext): string {
|
|
47
|
+
const settings = (ctx.section.settings || {}) as TestimonialsSettings;
|
|
48
|
+
const blocks = ctx.section.blocks || [];
|
|
49
|
+
|
|
50
|
+
const rawHeading = settings.heading || settings.title || 'Customer Impressions';
|
|
51
|
+
const rawSubheading = settings.subheading || settings.subtitle || 'Authentic notes on fit, quality, and craftsmanship';
|
|
52
|
+
const heading = typeof rawHeading === 'string' ? rawHeading.trim() : '';
|
|
53
|
+
const subheading = typeof rawSubheading === 'string' ? rawSubheading.trim() : '';
|
|
54
|
+
|
|
55
|
+
// Extract valid testimonial items with both content and author
|
|
56
|
+
const items: {
|
|
57
|
+
author: string;
|
|
58
|
+
role: string;
|
|
59
|
+
content: string;
|
|
60
|
+
rating?: number | undefined;
|
|
61
|
+
verified?: boolean | undefined;
|
|
62
|
+
avatarUrl?: string | undefined;
|
|
63
|
+
}[] = [];
|
|
64
|
+
for (const block of blocks) {
|
|
65
|
+
const bs = (block.settings || {}) as TestimonialItemSettings;
|
|
66
|
+
const author = typeof bs.author === 'string' ? bs.author.trim() : '';
|
|
67
|
+
const rawContent = bs.content || bs.quote || bs.review || '';
|
|
68
|
+
const content = typeof rawContent === 'string' ? rawContent.trim() : '';
|
|
69
|
+
|
|
70
|
+
if (author && content) {
|
|
71
|
+
const hasRating = typeof bs.rating === 'number' && !isNaN(bs.rating) && bs.rating > 0;
|
|
72
|
+
const isVerified = Boolean(bs.verified === true);
|
|
73
|
+
const item: {
|
|
74
|
+
author: string;
|
|
75
|
+
role: string;
|
|
76
|
+
content: string;
|
|
77
|
+
rating?: number | undefined;
|
|
78
|
+
verified?: boolean | undefined;
|
|
79
|
+
avatarUrl?: string | undefined;
|
|
80
|
+
} = {
|
|
81
|
+
author,
|
|
82
|
+
role: typeof bs.role === 'string' ? bs.role.trim() : '',
|
|
83
|
+
content,
|
|
84
|
+
verified: isVerified,
|
|
85
|
+
avatarUrl: bs.avatarUrl || bs.avatarImage || '',
|
|
86
|
+
};
|
|
87
|
+
if (hasRating) {
|
|
88
|
+
item.rating = bs.rating as number;
|
|
89
|
+
}
|
|
90
|
+
items.push(item);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// If no valid reviews configured, follow section empty-state convention
|
|
95
|
+
if (items.length === 0) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const columns = Math.min(Math.max(Number(settings.columns || 3), 1), 4);
|
|
100
|
+
const colClass = columns === 1
|
|
101
|
+
? 'grid-cols-1 max-w-xl mx-auto'
|
|
102
|
+
: (columns === 2 ? 'grid-cols-1 md:grid-cols-2 max-w-4xl mx-auto' : 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3');
|
|
103
|
+
|
|
104
|
+
const sectionId = escapeHtml(ctx.section.id || 'testimonials');
|
|
105
|
+
|
|
106
|
+
const cardsHtml = items.map((item, idx) => {
|
|
107
|
+
const author = escapeHtml(item.author || '');
|
|
108
|
+
const role = escapeHtml(item.role || '');
|
|
109
|
+
const content = escapeHtml(item.content || '');
|
|
110
|
+
const hasRating = item.rating !== undefined;
|
|
111
|
+
const rating = hasRating ? Math.min(Math.max(Number(item.rating), 1), 5) : 0;
|
|
112
|
+
const avatarUrl = item.avatarUrl ? escapeHtml(item.avatarUrl) : '';
|
|
113
|
+
const initials = author
|
|
114
|
+
.split(' ')
|
|
115
|
+
.map((n) => n[0])
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.slice(0, 2)
|
|
118
|
+
.join('')
|
|
119
|
+
.toUpperCase();
|
|
120
|
+
|
|
121
|
+
return `
|
|
122
|
+
<article
|
|
123
|
+
class="sf-testimonial-card flex flex-col justify-between p-6 sm:p-7 rounded-2xl border border-neutral-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900/60 shadow-sm transition-all duration-200 hover:border-neutral-300 dark:hover:border-neutral-700"
|
|
124
|
+
data-element="testimonial-card"
|
|
125
|
+
data-index="${idx}"
|
|
126
|
+
>
|
|
127
|
+
<div>
|
|
128
|
+
${hasRating ? `
|
|
129
|
+
<div class="flex items-center gap-1 mb-4" role="img" aria-label="${rating} out of 5 stars">
|
|
130
|
+
${renderStarRating(rating)}
|
|
131
|
+
</div>
|
|
132
|
+
` : ''}
|
|
133
|
+
<blockquote class="text-sm sm:text-base text-neutral-700 dark:text-neutral-300 leading-relaxed italic mb-6">
|
|
134
|
+
“${content}”
|
|
135
|
+
</blockquote>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<div class="flex items-center gap-3 pt-4 border-t border-neutral-100 dark:border-neutral-800/80 mt-auto">
|
|
139
|
+
${avatarUrl ? `
|
|
140
|
+
<img
|
|
141
|
+
src="${avatarUrl}"
|
|
142
|
+
alt="${author}"
|
|
143
|
+
class="w-10 h-10 rounded-full object-cover border border-neutral-200 dark:border-neutral-700 flex-shrink-0"
|
|
144
|
+
loading="lazy"
|
|
145
|
+
/>
|
|
146
|
+
` : `
|
|
147
|
+
<div
|
|
148
|
+
class="w-10 h-10 rounded-full bg-neutral-100 dark:bg-neutral-800 flex items-center justify-center text-xs font-bold text-neutral-700 dark:text-neutral-200 flex-shrink-0"
|
|
149
|
+
aria-hidden="true"
|
|
150
|
+
>
|
|
151
|
+
${escapeHtml(initials || 'CB')}
|
|
152
|
+
</div>
|
|
153
|
+
`}
|
|
154
|
+
<div class="min-w-0 flex-1">
|
|
155
|
+
<div class="flex items-center gap-1.5">
|
|
156
|
+
<h4 class="text-sm font-semibold text-neutral-900 dark:text-white truncate">${author}</h4>
|
|
157
|
+
${item.verified ? `
|
|
158
|
+
<span class="inline-flex items-center text-emerald-600 dark:text-emerald-400 text-xs" title="Verified Customer" aria-label="Verified Customer">
|
|
159
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
160
|
+
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
|
|
161
|
+
</svg>
|
|
162
|
+
</span>
|
|
163
|
+
` : ''}
|
|
164
|
+
</div>
|
|
165
|
+
${role ? `<p class="text-xs text-neutral-500 dark:text-neutral-400 truncate">${role}</p>` : ''}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</article>
|
|
169
|
+
`.trim();
|
|
170
|
+
}).join('\n');
|
|
171
|
+
|
|
172
|
+
return `
|
|
173
|
+
<section
|
|
174
|
+
class="sf-section sf-testimonials py-12 sm:py-16 bg-neutral-50/50 dark:bg-neutral-950/40"
|
|
175
|
+
id="${sectionId}"
|
|
176
|
+
data-element="testimonials"
|
|
177
|
+
role="region"
|
|
178
|
+
aria-label="${heading || 'Customer Reviews'}"
|
|
179
|
+
>
|
|
180
|
+
<div class="sf-container mx-auto px-4 sm:px-6 lg:px-8">
|
|
181
|
+
${(heading || subheading) ? `
|
|
182
|
+
<div class="sf-section-header text-center max-w-2xl mx-auto mb-10 sm:mb-14">
|
|
183
|
+
${heading ? `<h2 class="text-2xl sm:text-3xl font-bold tracking-tight text-neutral-900 dark:text-white mb-2">${escapeHtml(heading)}</h2>` : ''}
|
|
184
|
+
${subheading ? `<p class="text-sm sm:text-base text-neutral-500 dark:text-neutral-400">${escapeHtml(subheading)}</p>` : ''}
|
|
185
|
+
</div>
|
|
186
|
+
` : ''}
|
|
187
|
+
|
|
188
|
+
<div class="grid ${colClass} gap-6">
|
|
189
|
+
${cardsHtml}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</section>
|
|
193
|
+
`.trim();
|
|
194
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { StorefrontProduct } from '@caartzee/theme-sdk';
|
|
2
|
+
import { getThemePageProfile } from '../pages/theme-layout';
|
|
3
|
+
|
|
4
|
+
export interface ProductCardSnippetOptions {
|
|
5
|
+
currencySymbol?: string | undefined;
|
|
6
|
+
wishlistActive?: boolean | undefined;
|
|
7
|
+
actionMode?: 'cart' | 'link' | undefined;
|
|
8
|
+
actionLabel?: string | undefined;
|
|
9
|
+
themeSlug?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function escapeHtml(str: string): string {
|
|
13
|
+
return String(str || '')
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Shared luxury product card used across Featured Grid, Catalog (/products), Search, and Wishlist.
|
|
23
|
+
*/
|
|
24
|
+
export function renderStarterProductCard(
|
|
25
|
+
p: StorefrontProduct & Record<string, any>,
|
|
26
|
+
options: ProductCardSnippetOptions = {},
|
|
27
|
+
): string {
|
|
28
|
+
const currencySymbol = options.currencySymbol || '₹';
|
|
29
|
+
const rawPriceDisplay =
|
|
30
|
+
p.formattedSalePrice ||
|
|
31
|
+
p.formattedPrice ||
|
|
32
|
+
p.priceFormatted ||
|
|
33
|
+
(p.price !== undefined && p.price !== null
|
|
34
|
+
? `${currencySymbol}${Number(p.price).toFixed(2)}`
|
|
35
|
+
: `${currencySymbol}0.00`);
|
|
36
|
+
const compareNum = Number((p as any).compareAtPrice ?? p.price);
|
|
37
|
+
const activePriceNum = Number(p.salePrice ?? p.price ?? 0);
|
|
38
|
+
const hasCompareAt = Boolean(
|
|
39
|
+
((p as any).compareAtPrice && Number((p as any).compareAtPrice) > activePriceNum) ||
|
|
40
|
+
((p.hasDiscount || p.onSale) && p.salePrice !== null && p.salePrice !== undefined && Number(p.price) > Number(p.salePrice))
|
|
41
|
+
);
|
|
42
|
+
const compareAtDisplay = hasCompareAt
|
|
43
|
+
? (p.compareAtPriceFormatted || ((p as any).compareAtPrice ? `${currencySymbol}${Number((p as any).compareAtPrice).toFixed(2)}` : (p.formattedPrice || `${currencySymbol}${Number(p.price).toFixed(2)}`)))
|
|
44
|
+
: '';
|
|
45
|
+
const discountPct = Number(p.discountPercentage) > 0
|
|
46
|
+
? Math.round(Number(p.discountPercentage))
|
|
47
|
+
: (hasCompareAt && compareNum > activePriceNum && compareNum > 0
|
|
48
|
+
? Math.round(((compareNum - activePriceNum) / compareNum) * 100)
|
|
49
|
+
: 0);
|
|
50
|
+
|
|
51
|
+
const prodId = p.id ?? p.productId ?? p.product_id ?? '';
|
|
52
|
+
const prodName = p.name || p.title || 'Product';
|
|
53
|
+
const prodSlug = p.slug || String(prodId);
|
|
54
|
+
const imageUrl =
|
|
55
|
+
p.imageUrl ||
|
|
56
|
+
p.image ||
|
|
57
|
+
'https://images.unsplash.com/photo-1596461404969-9ae70f2830c1?w=600&auto=format&fit=crop&q=85';
|
|
58
|
+
|
|
59
|
+
const ratingVal =
|
|
60
|
+
typeof p.avgRating === 'number' && p.avgRating > 0
|
|
61
|
+
? p.avgRating
|
|
62
|
+
: typeof p.rating === 'number' && p.rating > 0
|
|
63
|
+
? p.rating
|
|
64
|
+
: null;
|
|
65
|
+
const reviewCountVal =
|
|
66
|
+
typeof p.reviewCount === 'number' && p.reviewCount > 0 ? p.reviewCount : null;
|
|
67
|
+
|
|
68
|
+
const profile = getThemePageProfile(options.themeSlug);
|
|
69
|
+
const wishlistTitle = options.wishlistActive ? 'Remove from Wishlist' : 'Save to Wishlist';
|
|
70
|
+
const heartBtnClass = options.wishlistActive
|
|
71
|
+
? 'text-[var(--sf-color-primary)] border-[var(--sf-color-primary)] bg-[var(--sf-color-surface)]'
|
|
72
|
+
: 'text-[var(--sf-color-text-muted)] border-[var(--sf-color-border)] bg-[var(--sf-color-surface)] hover:text-[var(--sf-color-primary)] hover:border-[var(--sf-color-primary)]';
|
|
73
|
+
const heartFill = options.wishlistActive ? 'currentColor' : 'none';
|
|
74
|
+
|
|
75
|
+
const ctaLabel = options.actionLabel || 'Add to Cart';
|
|
76
|
+
const ctaHtml =
|
|
77
|
+
options.actionMode === 'link'
|
|
78
|
+
? `
|
|
79
|
+
<a
|
|
80
|
+
href="/products/${encodeURIComponent(prodSlug)}"
|
|
81
|
+
class="w-full py-2.5 px-3 ${profile.buttonRadiusClass} bg-[var(--sf-color-primary)] hover:bg-[var(--sf-color-secondary)] text-[var(--sf-color-primary-text)] hover:text-white border border-[var(--sf-color-primary)] text-xs font-bold tracking-wide shadow-sm transition-all duration-200 active:scale-95 flex items-center justify-center gap-1.5"
|
|
82
|
+
>
|
|
83
|
+
<span>${escapeHtml(ctaLabel)}</span>
|
|
84
|
+
</a>
|
|
85
|
+
`
|
|
86
|
+
: `
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
class="w-full py-2.5 px-3 ${profile.buttonRadiusClass} bg-[var(--sf-color-primary)] hover:bg-[var(--sf-color-secondary)] text-[var(--sf-color-primary-text)] hover:text-white border border-[var(--sf-color-primary)] text-xs font-bold tracking-wide shadow-sm transition-all duration-200 active:scale-95 flex items-center justify-center gap-1.5 cursor-pointer js-add-to-cart js-quick-add"
|
|
90
|
+
data-product-id="${escapeHtml(String(prodId))}"
|
|
91
|
+
data-product-name="${escapeHtml(prodName)}"
|
|
92
|
+
data-product-price="${Number(p.salePrice ?? p.price ?? 0)}"
|
|
93
|
+
data-product-compare-at-price="${p.compareAtPrice ? Number(p.compareAtPrice) : ''}"
|
|
94
|
+
data-discount-percentage="${p.discountPercentage || ''}"
|
|
95
|
+
data-campaign-name="${escapeHtml(p.badge?.name || '')}"
|
|
96
|
+
>
|
|
97
|
+
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
|
|
98
|
+
<path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z" />
|
|
99
|
+
<line x1="3" y1="6" x2="21" y2="6" />
|
|
100
|
+
<path d="M16 10a4 4 0 0 1-8 0" />
|
|
101
|
+
</svg>
|
|
102
|
+
<span>${escapeHtml(ctaLabel)}</span>
|
|
103
|
+
</button>
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
return `
|
|
107
|
+
<article class="sf-product-card group relative flex flex-col ${profile.cardRadiusClass} bg-[var(--sf-color-surface)] border border-[var(--sf-color-border)] p-3.5 transition-all duration-300 hover:shadow-md" data-product-id="${escapeHtml(String(prodId))}">
|
|
108
|
+
<div class="relative aspect-square overflow-hidden ${profile.cardRadiusClass} bg-[var(--sf-color-bg)] border border-[var(--sf-color-border)] flex items-center justify-center">
|
|
109
|
+
${discountPct > 0 ? `
|
|
110
|
+
<span class="absolute top-2.5 left-2.5 z-10 px-2 py-0.5 ${profile.plpPillRadiusClass} bg-[var(--sf-color-secondary)] text-white text-[10px] font-bold tracking-wide shadow-sm">
|
|
111
|
+
-${discountPct}%
|
|
112
|
+
</span>
|
|
113
|
+
` : ''}
|
|
114
|
+
|
|
115
|
+
<button
|
|
116
|
+
type="button"
|
|
117
|
+
class="js-wishlist-toggle absolute top-2.5 right-2.5 z-10 w-8 h-8 rounded-full border shadow-sm flex items-center justify-center ${heartBtnClass} hover:scale-110 active:scale-95 transition-all cursor-pointer"
|
|
118
|
+
data-product-id="${escapeHtml(String(prodId))}"
|
|
119
|
+
title="${escapeHtml(wishlistTitle)}"
|
|
120
|
+
aria-label="${escapeHtml(wishlistTitle)}"
|
|
121
|
+
>
|
|
122
|
+
<svg class="w-4 h-4" fill="${heartFill}" stroke="currentColor" stroke-width="1.8" viewBox="0 0 24 24">
|
|
123
|
+
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" />
|
|
124
|
+
</svg>
|
|
125
|
+
</button>
|
|
126
|
+
|
|
127
|
+
<a href="/products/${encodeURIComponent(prodSlug)}" class="w-full h-full p-3.5 flex items-center justify-center">
|
|
128
|
+
<img
|
|
129
|
+
src="${escapeHtml(imageUrl)}"
|
|
130
|
+
alt="${escapeHtml(prodName)}"
|
|
131
|
+
class="w-full h-full object-contain object-center mix-blend-multiply group-hover:scale-105 transition-transform duration-500 ease-out"
|
|
132
|
+
loading="lazy"
|
|
133
|
+
/>
|
|
134
|
+
</a>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<div class="pt-3 flex-1 flex flex-col justify-between">
|
|
138
|
+
<div>
|
|
139
|
+
<a href="/products/${encodeURIComponent(prodSlug)}">
|
|
140
|
+
<h3 class="text-[13.5px] font-bold text-[var(--sf-color-text)] leading-snug line-clamp-1 group-hover:text-[var(--sf-color-primary)] transition-colors">
|
|
141
|
+
${escapeHtml(prodName)}
|
|
142
|
+
</h3>
|
|
143
|
+
</a>
|
|
144
|
+
${p.categoryName ? `
|
|
145
|
+
<p class="text-[11px] text-[var(--sf-color-text-muted)] font-medium line-clamp-1 mt-0.5">
|
|
146
|
+
${escapeHtml(p.categoryName)}
|
|
147
|
+
</p>
|
|
148
|
+
` : ''}
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div class="mt-2.5 pt-2.5 border-t border-[var(--sf-color-border)]">
|
|
152
|
+
<div class="flex items-center justify-between gap-2 mb-2.5">
|
|
153
|
+
<div class="flex items-baseline gap-1.5 min-w-0">
|
|
154
|
+
<span class="text-[15px] font-extrabold text-[var(--sf-color-text)] tracking-tight tabular-nums">
|
|
155
|
+
${escapeHtml(rawPriceDisplay)}
|
|
156
|
+
</span>
|
|
157
|
+
${compareAtDisplay ? `
|
|
158
|
+
<span class="text-[11px] text-[var(--sf-color-text-muted)] line-through font-medium tabular-nums truncate">
|
|
159
|
+
${escapeHtml(compareAtDisplay)}
|
|
160
|
+
</span>
|
|
161
|
+
` : ''}
|
|
162
|
+
</div>
|
|
163
|
+
${ratingVal !== null ? `
|
|
164
|
+
<span class="inline-flex items-center gap-1 text-[11px] font-semibold text-[var(--sf-color-text-muted)] shrink-0">
|
|
165
|
+
<svg class="w-3.5 h-3.5 text-[#eab308]" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2l2.9 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l7.1-1.01L12 2z"/></svg>
|
|
166
|
+
<span>${ratingVal.toFixed(1)}</span>
|
|
167
|
+
${reviewCountVal !== null ? `<span class="text-[var(--sf-color-text-muted)] font-normal">(${reviewCountVal})</span>` : ''}
|
|
168
|
+
</span>
|
|
169
|
+
` : ''}
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
${ctaHtml}
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
</article>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface ProductPriceSnippetOptions {
|
|
2
|
+
price: string | number;
|
|
3
|
+
salePrice?: string | number | null | undefined;
|
|
4
|
+
hasDiscount?: boolean | undefined;
|
|
5
|
+
currencySymbol?: string | undefined;
|
|
6
|
+
currencyPosition?: 'left' | 'right' | undefined;
|
|
7
|
+
classNames?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function escapeHtml(str: string): string {
|
|
11
|
+
return str
|
|
12
|
+
.replace(/&/g, '&')
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/'/g, ''');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function renderProductPrice(options: ProductPriceSnippetOptions): string {
|
|
20
|
+
const sym = options.currencySymbol || '$';
|
|
21
|
+
const pos = options.currencyPosition || 'left';
|
|
22
|
+
const format = (v: string | number) => (pos === 'left' ? `${sym}${v}` : `${v}${sym}`);
|
|
23
|
+
|
|
24
|
+
const formattedRegular = typeof options.price === 'string' && options.price.includes(sym)
|
|
25
|
+
? options.price
|
|
26
|
+
: format(options.price);
|
|
27
|
+
|
|
28
|
+
if (options.hasDiscount && options.salePrice) {
|
|
29
|
+
const formattedSale = typeof options.salePrice === 'string' && options.salePrice.includes(sym)
|
|
30
|
+
? options.salePrice
|
|
31
|
+
: format(options.salePrice);
|
|
32
|
+
|
|
33
|
+
return `
|
|
34
|
+
<div class="sf-price-row flex items-baseline gap-2 ${options.classNames || ''}">
|
|
35
|
+
<span class="sf-price sf-price--sale font-semibold text-slate-900 dark:text-white">${escapeHtml(formattedSale)}</span>
|
|
36
|
+
<span class="sf-price sf-price--regular text-sm text-slate-400 line-through">${escapeHtml(formattedRegular)}</span>
|
|
37
|
+
</div>
|
|
38
|
+
`.trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return `
|
|
42
|
+
<div class="sf-price-row ${options.classNames || ''}">
|
|
43
|
+
<span class="sf-price font-semibold text-slate-900 dark:text-white">${escapeHtml(formattedRegular)}</span>
|
|
44
|
+
</div>
|
|
45
|
+
`.trim();
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ResponsiveImageSnippetOptions {
|
|
2
|
+
src: string;
|
|
3
|
+
alt?: string | undefined;
|
|
4
|
+
className?: string | undefined;
|
|
5
|
+
loading?: 'lazy' | 'eager' | undefined;
|
|
6
|
+
sizes?: string | undefined;
|
|
7
|
+
aspectRatio?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function escapeHtml(str: string): string {
|
|
11
|
+
return str
|
|
12
|
+
.replace(/&/g, '&')
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/'/g, ''');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function renderResponsiveImage(options: ResponsiveImageSnippetOptions): string {
|
|
20
|
+
if (!options.src) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const alt = options.alt || '';
|
|
25
|
+
const loading = options.loading || 'lazy';
|
|
26
|
+
const cls = options.className || 'w-full h-full object-cover';
|
|
27
|
+
|
|
28
|
+
return `<img src="${escapeHtml(options.src)}" alt="${escapeHtml(alt)}" loading="${loading}" class="${escapeHtml(cls)}" />`;
|
|
29
|
+
}
|