@caartzee/theme-sdk 0.0.0-stage → 1.2.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 (179) hide show
  1. package/README.md +222 -2
  2. package/dist/bin/caartzee-theme.js +9223 -0
  3. package/dist/lib/index.js +11614 -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/candy-mcp.d.ts +2 -0
  20. package/dist/types/src/cli/candy-tool-server.d.ts +39 -0
  21. package/dist/types/src/cli/index.d.ts +1 -0
  22. package/dist/types/src/cli/mcp/component-tools.d.ts +2 -0
  23. package/dist/types/src/cli/mcp/docs-tools.d.ts +89 -0
  24. package/dist/types/src/cli/mcp/editor-tools.d.ts +22 -0
  25. package/dist/types/src/cli/mcp/resources-and-prompts.d.ts +2 -0
  26. package/dist/types/src/cli/mcp/testing-tools.d.ts +54 -0
  27. package/dist/types/src/cli/sdk-client.d.ts +12 -0
  28. package/dist/types/src/contracts/category-selection.d.ts +15 -0
  29. package/dist/types/src/contracts/commerce.d.ts +282 -0
  30. package/dist/types/src/contracts/footer-builder.d.ts +125 -0
  31. package/dist/types/src/contracts/hooks.d.ts +37 -0
  32. package/dist/types/src/contracts/manifest.d.ts +3127 -0
  33. package/dist/types/src/contracts/navigation.d.ts +39 -0
  34. package/dist/types/src/contracts/order-tracking.d.ts +40 -0
  35. package/dist/types/src/contracts/page.d.ts +262 -0
  36. package/dist/types/src/contracts/storefront-content.d.ts +60 -0
  37. package/dist/types/src/contracts/style-document.d.ts +2 -0
  38. package/dist/types/src/contracts/styles.d.ts +2002 -0
  39. package/dist/types/src/contracts/theme.d.ts +35 -0
  40. package/dist/types/src/dev-server/catalog-preview.d.ts +25 -0
  41. package/dist/types/src/dev-server/dev-server.d.ts +25 -0
  42. package/dist/types/src/dev-server/index.d.ts +1 -0
  43. package/dist/types/src/dev-server/local-commerce-runtime.d.ts +76 -0
  44. package/dist/types/src/dev-server/local-editor-server.d.ts +22 -0
  45. package/dist/types/src/dev-server/theme-preview.d.ts +8 -0
  46. package/dist/types/src/index.d.ts +27 -0
  47. package/dist/types/src/mock/index.d.ts +10 -0
  48. package/dist/types/src/mock/mock-categories.d.ts +2 -0
  49. package/dist/types/src/mock/mock-commerce.d.ts +55 -0
  50. package/dist/types/src/mock/mock-customer.d.ts +47 -0
  51. package/dist/types/src/mock/mock-hooks.d.ts +2 -0
  52. package/dist/types/src/mock/mock-products.d.ts +3 -0
  53. package/dist/types/src/rendering/commerce-pages.d.ts +16 -0
  54. package/dist/types/src/rendering/raw-html.d.ts +12 -0
  55. package/dist/types/src/rendering/section-wrapper.d.ts +30 -0
  56. package/dist/types/src/scaffold/candy-starter-assets.d.ts +2 -0
  57. package/dist/types/src/scaffold/commerce-generator.d.ts +3 -0
  58. package/dist/types/src/scaffold/index.d.ts +2 -0
  59. package/dist/types/src/scaffold/template-generator.d.ts +21 -0
  60. package/dist/types/src/sections/section-contract.d.ts +350 -0
  61. package/dist/types/src/settings/global-settings.d.ts +25 -0
  62. package/dist/types/src/templates/json-template.d.ts +991 -0
  63. package/dist/types/src/validation/package-validator.d.ts +53 -0
  64. package/dist/types/src/validation/rich-text.d.ts +24 -0
  65. package/package.json +29 -3
  66. package/templates/commerce/README.md +165 -0
  67. package/templates/commerce/assets/theme.css +1 -0
  68. package/templates/commerce/manifest.json +1 -0
  69. package/templates/commerce/src/blocks/index.ts +184 -0
  70. package/templates/commerce/src/config/settings-defaults.ts +25 -0
  71. package/templates/commerce/src/config/settings-schema.ts +102 -0
  72. package/templates/commerce/src/index.ts +90 -0
  73. package/templates/commerce/src/layouts/default.ts +275 -0
  74. package/templates/commerce/src/manifest.ts +976 -0
  75. package/templates/commerce/src/pages/account/components.ts +369 -0
  76. package/templates/commerce/src/pages/account/tabs.ts +792 -0
  77. package/templates/commerce/src/pages/account.ts +55 -0
  78. package/templates/commerce/src/pages/campaign.ts +423 -0
  79. package/templates/commerce/src/pages/cart.ts +261 -0
  80. package/templates/commerce/src/pages/category-detail.ts +124 -0
  81. package/templates/commerce/src/pages/category-list.ts +87 -0
  82. package/templates/commerce/src/pages/checkout.ts +712 -0
  83. package/templates/commerce/src/pages/commerce.ts +45 -0
  84. package/templates/commerce/src/pages/home.ts +160 -0
  85. package/templates/commerce/src/pages/index.ts +99 -0
  86. package/templates/commerce/src/pages/login.ts +204 -0
  87. package/templates/commerce/src/pages/order-success.ts +80 -0
  88. package/templates/commerce/src/pages/product-detail.ts +489 -0
  89. package/templates/commerce/src/pages/product-list.ts +125 -0
  90. package/templates/commerce/src/pages/search.ts +88 -0
  91. package/templates/commerce/src/pages/signup.ts +253 -0
  92. package/templates/commerce/src/pages/status.ts +7 -0
  93. package/templates/commerce/src/pages/theme-layout.ts +491 -0
  94. package/templates/commerce/src/pages/track-order.ts +196 -0
  95. package/templates/commerce/src/pages/wishlist.ts +83 -0
  96. package/templates/commerce/src/sections/about-story.ts +117 -0
  97. package/templates/commerce/src/sections/announcement-bar.ts +101 -0
  98. package/templates/commerce/src/sections/banner-grid.ts +319 -0
  99. package/templates/commerce/src/sections/campaign-banners.ts +158 -0
  100. package/templates/commerce/src/sections/category-slider.ts +144 -0
  101. package/templates/commerce/src/sections/content-builder.ts +123 -0
  102. package/templates/commerce/src/sections/content-controls.ts +45 -0
  103. package/templates/commerce/src/sections/custom-form.ts +59 -0
  104. package/templates/commerce/src/sections/faq-accordion.ts +123 -0
  105. package/templates/commerce/src/sections/footer.ts +728 -0
  106. package/templates/commerce/src/sections/header.ts +439 -0
  107. package/templates/commerce/src/sections/hero-slider.ts +492 -0
  108. package/templates/commerce/src/sections/hero.ts +137 -0
  109. package/templates/commerce/src/sections/index.ts +102 -0
  110. package/templates/commerce/src/sections/mobile-slider.ts +102 -0
  111. package/templates/commerce/src/sections/newsletter.ts +43 -0
  112. package/templates/commerce/src/sections/product-grid.ts +191 -0
  113. package/templates/commerce/src/sections/raw-html.ts +1 -0
  114. package/templates/commerce/src/sections/rich-text.ts +26 -0
  115. package/templates/commerce/src/sections/services-features.ts +211 -0
  116. package/templates/commerce/src/sections/testimonials.ts +194 -0
  117. package/templates/commerce/src/snippets/product-card.ts +178 -0
  118. package/templates/commerce/src/snippets/product-price.ts +46 -0
  119. package/templates/commerce/src/snippets/responsive-image.ts +29 -0
  120. package/templates/commerce/src/styles.ts +477 -0
  121. package/templates/commerce/src/templates/404.json +26 -0
  122. package/templates/commerce/src/templates/account.json +17 -0
  123. package/templates/commerce/src/templates/cart.json +17 -0
  124. package/templates/commerce/src/templates/category.json +16 -0
  125. package/templates/commerce/src/templates/checkout.json +15 -0
  126. package/templates/commerce/src/templates/collection.json +16 -0
  127. package/templates/commerce/src/templates/index.json +180 -0
  128. package/templates/commerce/src/templates/login.json +17 -0
  129. package/templates/commerce/src/templates/order-success.json +17 -0
  130. package/templates/commerce/src/templates/page.json +17 -0
  131. package/templates/commerce/src/templates/product.json +17 -0
  132. package/templates/commerce/src/templates/search.json +18 -0
  133. package/templates/commerce/src/templates/signup.json +17 -0
  134. package/templates/commerce/src/templates/track-order.json +17 -0
  135. package/templates/commerce/src/templates/wishlist.json +17 -0
  136. package/templates/commerce/src/templates.ts +510 -0
  137. package/templates/commerce/src/tokens.ts +22 -0
  138. package/templates/theme-candy-boilerplate/.editorconfig +14 -0
  139. package/templates/theme-candy-boilerplate/.gitattributes +1 -0
  140. package/templates/theme-candy-boilerplate/.vscode/extensions.json +7 -0
  141. package/templates/theme-candy-boilerplate/.vscode/settings.json +17 -0
  142. package/templates/theme-candy-boilerplate/assets/theme.css +78 -0
  143. package/templates/theme-candy-boilerplate/assets/theme.js +7 -0
  144. package/templates/theme-candy-boilerplate/candy.config.json +40 -0
  145. package/templates/theme-candy-boilerplate/index.ts +39 -0
  146. package/templates/theme-candy-boilerplate/layout/theme.candy +25 -0
  147. package/templates/theme-candy-boilerplate/locales/en.default.json +37 -0
  148. package/templates/theme-candy-boilerplate/manifest.json +123 -0
  149. package/templates/theme-candy-boilerplate/package.json +16 -0
  150. package/templates/theme-candy-boilerplate/schemas/settings_schema.json +36 -0
  151. package/templates/theme-candy-boilerplate/sections/featured-products.candy +89 -0
  152. package/templates/theme-candy-boilerplate/sections/footer.candy +50 -0
  153. package/templates/theme-candy-boilerplate/sections/header.candy +116 -0
  154. package/templates/theme-candy-boilerplate/sections/hero-banner.candy +135 -0
  155. package/templates/theme-candy-boilerplate/sections/image-with-text.candy +85 -0
  156. package/templates/theme-candy-boilerplate/snippets/price.candy +19 -0
  157. package/templates/theme-candy-boilerplate/snippets/product-card.candy +43 -0
  158. package/templates/theme-candy-boilerplate/templates/404.candy +12 -0
  159. package/templates/theme-candy-boilerplate/templates/cart.candy +51 -0
  160. package/templates/theme-candy-boilerplate/templates/collection.candy +51 -0
  161. package/templates/theme-candy-boilerplate/templates/index.candy +7 -0
  162. package/templates/theme-candy-boilerplate/templates/page.candy +10 -0
  163. package/templates/theme-candy-boilerplate/templates/product.candy +59 -0
  164. package/templates/theme-candy-boilerplate/templates/search.candy +40 -0
  165. package/templates/vscode-candy/LICENSE +21 -0
  166. package/templates/vscode-candy/README.md +22 -0
  167. package/templates/vscode-candy/extension.js +689 -0
  168. package/templates/vscode-candy/icons/candy-dark.svg +23 -0
  169. package/templates/vscode-candy/icons/candy-light.svg +23 -0
  170. package/templates/vscode-candy/icons/candy-logo.png +0 -0
  171. package/templates/vscode-candy/icons/candy-sweet-dark.svg +23 -0
  172. package/templates/vscode-candy/icons/candy-sweet-light.svg +23 -0
  173. package/templates/vscode-candy/language-configuration.json +47 -0
  174. package/templates/vscode-candy/package.json +118 -0
  175. package/templates/vscode-candy/schemas/candy-config.schema.json +56 -0
  176. package/templates/vscode-candy/schemas/candy-settings.schema.json +70 -0
  177. package/templates/vscode-candy/snippets/candy.code-snippets +270 -0
  178. package/templates/vscode-candy/syntaxes/candy.tmLanguage.json +296 -0
  179. package/templates/vscode-candy/vim/ftdetect/candy.vim +5 -0
@@ -0,0 +1,55 @@
1
+ import type { AccountPageData } from '@caartzee/theme-sdk';
2
+ import { renderAccountLayout } from './account/components';
3
+ import {
4
+ renderOverviewTab,
5
+ renderOrdersTab,
6
+ renderProfileTab,
7
+ renderAddressesTab,
8
+ renderDownloadsTab,
9
+ } from './account/tabs';
10
+
11
+ export * from './account/components';
12
+ export * from './account/tabs';
13
+
14
+ /**
15
+ * Starter Theme - Customer Account Portal
16
+ *
17
+ * Production-ready sidebar-based dashboard conforming to Joybee visual identity:
18
+ * - Fixed/sticky desktop sidebar (260px) + spacious content area (max 1200px)
19
+ * - Compact customer identity card with initials avatar & member badge
20
+ * - Dedicated sub-views for Overview, Orders, Profile, Addresses, Downloads
21
+ * - Accessible SVG icon set with consistent sizing & stroke width
22
+ * - Understated hover & clear active route states
23
+ * - Mobile scrollable pill navigation without horizontal page overflow
24
+ * - Preserves all form actions (data-v2-action), feedback containers, and logout triggers
25
+ */
26
+ export function renderBoilerplateAccountPage(data: AccountPageData): string {
27
+ const activeTab = data.activeTab || 'overview';
28
+
29
+ let content = '';
30
+ switch (activeTab) {
31
+ case 'orders':
32
+ content = renderOrdersTab(data);
33
+ break;
34
+ case 'profile':
35
+ content = renderProfileTab(data);
36
+ break;
37
+ case 'addresses':
38
+ content = renderAddressesTab(data);
39
+ break;
40
+ case 'downloads':
41
+ content = renderDownloadsTab(data);
42
+ break;
43
+ case 'overview':
44
+ default:
45
+ content = renderOverviewTab(data);
46
+ break;
47
+ }
48
+
49
+ return renderAccountLayout({
50
+ customer: data.customer,
51
+ activeTab,
52
+ content,
53
+ themeSlug: (data as any).themeSlug,
54
+ });
55
+ }
@@ -0,0 +1,423 @@
1
+ import type { CampaignLandingPageData, StorefrontProduct } from '@caartzee/theme-sdk';
2
+ import { getThemePageProfile } from './theme-layout';
3
+
4
+ function escapeHtml(str: string | null | undefined): string {
5
+ if (!str) return '';
6
+ return String(str)
7
+ .replace(/&/g, '&')
8
+ .replace(/</g, '&lt;')
9
+ .replace(/>/g, '&gt;')
10
+ .replace(/"/g, '&quot;')
11
+ .replace(/'/g, '&#039;');
12
+ }
13
+
14
+ /**
15
+ * Starter Theme — Promotional Campaign Landing Page
16
+ *
17
+ * Implements the Mileora-style campaign landing experience:
18
+ * - Immersive Hero Banner with campaign imagery, title, offer subtitle, and badge
19
+ * - Interactive Listing Toolbar: live product count, sorting options, and Grid/List layout toggle
20
+ * - Authoritative V2 Product Cards: pricing, discount badges, ratings, wishlist toggle, and Add to Cart
21
+ * - Attribution tracking: embeds campaign ID and slug for cart operations
22
+ * - Responsive viewport scaling across 375px mobile through 1440px desktop
23
+ */
24
+ export function renderBoilerplateCampaignPage(data: CampaignLandingPageData): string {
25
+ const { campaign, sort = 'popularity', viewMode = 'grid', nonce } = data;
26
+ const products = (Array.isArray(data.products) && data.products.length > 0)
27
+ ? data.products
28
+ : (Array.isArray(campaign?.products) ? campaign.products : []);
29
+ const slug = campaign.slug || String(campaign.id);
30
+ const title = campaign.title || 'Special Campaign';
31
+ const subtitle = campaign.subtitle || '';
32
+ const count = products.length;
33
+ const bannerImage =
34
+ campaign.imageUrl ||
35
+ campaign.image ||
36
+ 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=1600&auto=format&fit=crop&q=85';
37
+ const badge = campaign.badge || (campaign.freeShipping ? 'Free Shipping Included' : null);
38
+ const themeSlug = (data as any).themeSlug as string | undefined;
39
+ const profile = getThemePageProfile(themeSlug);
40
+
41
+ const renderProductCard = (p: StorefrontProduct, index: number) => {
42
+ const pSlug = p.slug || String(p.id ?? '');
43
+ const priceDisplay = p.formattedSalePrice || p.formattedPrice || (p.price != null ? `$${Number(p.price).toFixed(2)}` : '');
44
+ const hasDiscount = Boolean(p.compareAtPrice && Number(p.compareAtPrice) > Number(p.salePrice ?? p.price ?? 0));
45
+ const originalPrice = hasDiscount && p.compareAtPriceFormatted
46
+ ? p.compareAtPriceFormatted
47
+ : (hasDiscount && p.compareAtPrice ? `$${Number(p.compareAtPrice).toFixed(2)}` : '');
48
+ const discountBadge = p.discountPercentage && p.discountPercentage > 0
49
+ ? `${p.discountPercentage}% OFF`
50
+ : (p.badge?.name || null);
51
+ const categoryName = p.categoryName || (p.category ? p.category.name : null);
52
+ const isPlaceholder = (url: any) => !url || typeof url !== 'string' || !url.trim() || url.startsWith('data:image/svg+xml');
53
+ const img = !isPlaceholder(p.imageUrl)
54
+ ? p.imageUrl
55
+ : (!isPlaceholder(p.galleryImages?.[0])
56
+ ? p.galleryImages[0]
57
+ : (!isPlaceholder((p as any).imageURL)
58
+ ? (p as any).imageURL
59
+ : (!isPlaceholder((p as any).image)
60
+ ? (p as any).image
61
+ : (!isPlaceholder((p as any).img_url)
62
+ ? (p as any).img_url
63
+ : 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=800&auto=format&fit=crop&q=80'))));
64
+ const rating = p.avgRating ?? p.rating ?? null;
65
+ const reviewCount = p.reviewCount ?? 0;
66
+
67
+ return `
68
+ <article
69
+ class="sf-campaign-product-card js-campaign-card group relative flex flex-col ${profile.cardRadiusClass} bg-[var(--sf-color-surface)] border border-[var(--sf-color-border)] shadow-sm hover:shadow-xl hover:-translate-y-1 transition-all duration-300 overflow-hidden"
70
+ data-product-id="${escapeHtml(String(p.id))}"
71
+ data-product-index="${index}"
72
+ data-price="${Number(p.salePrice ?? p.price ?? 0)}"
73
+ data-title="${escapeHtml(p.name || p.title || '')}"
74
+ data-rating="${Number(rating || 0)}"
75
+ >
76
+ <!-- Product Image & Badges -->
77
+ <div class="sf-card-image-wrapper aspect-square overflow-hidden bg-slate-100 dark:bg-slate-800 relative">
78
+ <!-- Discount / Offer Badge -->
79
+ ${discountBadge ? `
80
+ <div class="absolute top-3 left-3 z-10">
81
+ <span class="inline-flex items-center px-2.5 py-1 rounded-full text-[11px] font-bold uppercase tracking-wider bg-rose-600 text-white shadow-sm">
82
+ ${escapeHtml(discountBadge)}
83
+ </span>
84
+ </div>
85
+ ` : ''}
86
+
87
+ <!-- Wishlist Action Button -->
88
+ <button
89
+ type="button"
90
+ class="js-wishlist-toggle absolute top-3 right-3 z-10 w-9 h-9 rounded-full bg-white/90 dark:bg-slate-800/90 backdrop-blur-sm shadow-sm flex items-center justify-center text-slate-400 hover:text-rose-500 hover:scale-110 active:scale-95 transition-all"
91
+ data-product-id="${escapeHtml(String(p.id))}"
92
+ title="Add to Wishlist"
93
+ aria-label="Add to Wishlist"
94
+ >
95
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
96
+ <path stroke-linecap="round" stroke-linejoin="round" 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" />
97
+ </svg>
98
+ </button>
99
+
100
+ <a href="/products/${encodeURIComponent(pSlug)}" class="block w-full h-full">
101
+ <img
102
+ src="${escapeHtml(img)}"
103
+ alt="${escapeHtml(p.name || p.title)}"
104
+ class="w-full h-full object-cover object-center group-hover:scale-105 transition-transform duration-500 ease-out"
105
+ loading="lazy"
106
+ />
107
+ </a>
108
+ </div>
109
+
110
+ <!-- Product Information Body -->
111
+ <div class="sf-card-content flex-1 p-5 flex flex-col justify-between">
112
+ <div>
113
+ ${categoryName ? `
114
+ <span class="text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider mb-1 block">
115
+ ${escapeHtml(categoryName)}
116
+ </span>
117
+ ` : ''}
118
+
119
+ <a href="/products/${encodeURIComponent(pSlug)}">
120
+ <h3 class="text-base font-bold text-[var(--sf-color-text)] line-clamp-2 group-hover:text-[var(--sf-color-primary)] transition-colors mb-2">
121
+ ${escapeHtml(p.name || p.title)}
122
+ </h3>
123
+ </a>
124
+
125
+ <!-- Rating Stars (if available) -->
126
+ ${rating !== null && rating > 0 ? `
127
+ <div class="flex items-center gap-1 mb-3 text-amber-400 text-xs">
128
+ <span class="font-bold text-slate-900 dark:text-slate-100 mr-1">${rating.toFixed(1)}</span>
129
+ <svg class="w-3.5 h-3.5 fill-current" viewBox="0 0 20 20">
130
+ <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" />
131
+ </svg>
132
+ ${reviewCount > 0 ? `<span class="text-slate-500 dark:text-slate-400">(${reviewCount})</span>` : ''}
133
+ </div>
134
+ ` : ''}
135
+ </div>
136
+
137
+ <!-- Price & Action Section -->
138
+ <div class="pt-3 border-t border-slate-100 dark:border-slate-800/80 mt-3">
139
+ <div class="flex items-baseline gap-2 mb-4">
140
+ <span class="text-lg font-extrabold text-slate-900 dark:text-white">
141
+ ${escapeHtml(priceDisplay)}
142
+ </span>
143
+ ${originalPrice ? `
144
+ <span class="text-xs text-slate-400 line-through">
145
+ ${escapeHtml(originalPrice)}
146
+ </span>
147
+ ` : ''}
148
+ </div>
149
+
150
+ <!-- Add to Cart Action -->
151
+ <button
152
+ type="button"
153
+ class="sf-btn sf-btn--primary js-add-to-cart w-full py-2.5 px-4 ${profile.buttonRadiusClass} bg-[var(--sf-color-primary)] hover:bg-[var(--sf-color-secondary)] text-[var(--sf-color-primary-text)] hover:text-white text-xs sm:text-sm font-bold flex items-center justify-center gap-2 shadow-sm hover:shadow transition-all cursor-pointer"
154
+ data-product-id="${escapeHtml(String(p.id))}"
155
+ data-campaign-id="${escapeHtml(String(campaign.id))}"
156
+ data-campaign-slug="${escapeHtml(slug)}"
157
+ data-campaign-name="${escapeHtml(campaign.name || campaign.title || '')}"
158
+ data-product-name="${escapeHtml(p.name || p.title)}"
159
+ data-product-price="${Number(p.salePrice ?? p.price ?? 0)}"
160
+ data-product-compare-at-price="${p.compareAtPrice ? Number(p.compareAtPrice) : ''}"
161
+ data-discount-percentage="${p.discountPercentage || ''}"
162
+ >
163
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
164
+ <path stroke-linecap="round" stroke-linejoin="round" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
165
+ </svg>
166
+ <span>Add to Cart</span>
167
+ </button>
168
+ </div>
169
+ </div>
170
+ </article>
171
+ `;
172
+ };
173
+
174
+ const nonceAttr = nonce ? ` nonce="${escapeHtml(nonce)}"` : '';
175
+
176
+ return `
177
+ <div class="sf-campaign-landing-page min-h-[calc(100vh-80px)] bg-[var(--sf-color-bg)] pb-16">
178
+
179
+ <!-- 1. Campaign Hero Banner -->
180
+ <section class="sf-campaign-hero relative overflow-hidden bg-neutral-900 select-none">
181
+ <div class="relative w-full min-h-[280px] sm:min-h-[380px] lg:min-h-[460px] flex items-center justify-center">
182
+ <!-- Background Image -->
183
+ <img
184
+ src="${escapeHtml(bannerImage)}"
185
+ alt="${escapeHtml(title)}"
186
+ class="absolute inset-0 w-full h-full object-cover object-center"
187
+ loading="eager"
188
+ />
189
+ <!-- Contrast Gradient Overlay -->
190
+ <div class="absolute inset-0 bg-gradient-to-t from-black/85 via-black/50 to-black/30"></div>
191
+
192
+ <!-- Hero Content -->
193
+ <div class="relative z-10 max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12 text-center text-white flex flex-col items-center">
194
+ ${badge ? `
195
+ <span class="inline-flex items-center px-4 py-1.5 rounded-full text-xs font-bold uppercase tracking-widest bg-white/95 text-neutral-950 shadow-md mb-4 backdrop-blur-md">
196
+ ${escapeHtml(badge)}
197
+ </span>
198
+ ` : ''}
199
+
200
+ <h1 class="text-3xl sm:text-5xl lg:text-6xl font-extrabold tracking-tight font-heading leading-tight mb-4 max-w-3xl">
201
+ ${escapeHtml(title)}
202
+ </h1>
203
+
204
+ ${subtitle ? `
205
+ <p class="text-base sm:text-lg lg:text-xl text-neutral-200 max-w-2xl leading-relaxed mb-6 font-normal">
206
+ ${escapeHtml(subtitle)}
207
+ </p>
208
+ ` : ''}
209
+
210
+ <!-- Campaign Meta Pills -->
211
+ <div class="flex items-center gap-3 text-xs sm:text-sm text-neutral-300 flex-wrap justify-center">
212
+ <span class="inline-flex items-center gap-1.5 bg-black/40 backdrop-blur-sm px-3.5 py-1.5 rounded-full border border-white/10">
213
+ <svg class="w-4 h-4 text-emerald-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
214
+ <path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
215
+ </svg>
216
+ <span>Verified Offer</span>
217
+ </span>
218
+ ${campaign.freeShipping ? `
219
+ <span class="inline-flex items-center gap-1.5 bg-black/40 backdrop-blur-sm px-3.5 py-1.5 rounded-full border border-white/10">
220
+ <svg class="w-4 h-4 text-emerald-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
221
+ <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
222
+ </svg>
223
+ <span>Free Shipping Included</span>
224
+ </span>
225
+ ` : ''}
226
+ <span class="inline-flex items-center gap-1.5 bg-black/40 backdrop-blur-sm px-3.5 py-1.5 rounded-full border border-white/10">
227
+ <svg class="w-4 h-4 text-indigo-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
228
+ <path stroke-linecap="round" stroke-linejoin="round" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
229
+ </svg>
230
+ <span>${count} Item${count === 1 ? '' : 's'} Included</span>
231
+ </span>
232
+ </div>
233
+ </div>
234
+ </div>
235
+ </section>
236
+
237
+ <!-- 2. Campaign Product Listing Toolbar -->
238
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 mt-8 sm:mt-10">
239
+ <div class="sf-campaign-toolbar flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 pb-6 mb-8 border-b border-slate-200 dark:border-slate-800">
240
+
241
+ <!-- Product Count Display -->
242
+ <div>
243
+ <span class="text-sm sm:text-base font-bold text-slate-900 dark:text-white js-campaign-count">
244
+ Showing ${count} product${count === 1 ? '' : 's'}
245
+ </span>
246
+ </div>
247
+
248
+ <!-- Sorting & View Mode Controls -->
249
+ <div class="flex items-center gap-3 sm:gap-4 flex-wrap">
250
+ <!-- Sort Selector -->
251
+ <div class="flex items-center gap-2">
252
+ <label for="sf-campaign-sort" class="text-xs font-semibold text-slate-500 dark:text-slate-400">
253
+ Sort:
254
+ </label>
255
+ <select
256
+ id="sf-campaign-sort"
257
+ class="js-campaign-sort px-3.5 py-2 rounded-xl text-xs font-semibold border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 text-slate-800 dark:text-slate-200 focus:outline-none focus:ring-2 focus:ring-indigo-500 shadow-sm"
258
+ >
259
+ <option value="popularity" ${sort === 'popularity' ? 'selected' : ''}>Popularity</option>
260
+ <option value="price_asc" ${sort === 'price_asc' ? 'selected' : ''}>Price: Low to High</option>
261
+ <option value="price_desc" ${sort === 'price_desc' ? 'selected' : ''}>Price: High to Low</option>
262
+ <option value="new" ${sort === 'new' ? 'selected' : ''}>Newest</option>
263
+ <option value="name_asc" ${sort === 'name_asc' ? 'selected' : ''}>Name: A to Z</option>
264
+ </select>
265
+ </div>
266
+
267
+ <!-- Grid vs List Layout Toggle -->
268
+ <div class="flex items-center bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-xl p-1 shadow-sm" role="group" aria-label="Layout View Toggle">
269
+ <button
270
+ type="button"
271
+ class="js-view-toggle px-2.5 py-1.5 rounded-lg text-xs font-semibold flex items-center justify-center transition-all ${
272
+ viewMode !== 'list'
273
+ ? 'bg-neutral-900 text-white dark:bg-white dark:text-neutral-900 shadow-sm'
274
+ : 'text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white'
275
+ }"
276
+ data-view="grid"
277
+ title="Grid View"
278
+ aria-label="Grid View"
279
+ >
280
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
281
+ <path stroke-linecap="round" stroke-linejoin="round" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
282
+ </svg>
283
+ </button>
284
+ <button
285
+ type="button"
286
+ class="js-view-toggle px-2.5 py-1.5 rounded-lg text-xs font-semibold flex items-center justify-center transition-all ${
287
+ viewMode === 'list'
288
+ ? 'bg-neutral-900 text-white dark:bg-white dark:text-neutral-900 shadow-sm'
289
+ : 'text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white'
290
+ }"
291
+ data-view="list"
292
+ title="List View"
293
+ aria-label="List View"
294
+ >
295
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
296
+ <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" />
297
+ </svg>
298
+ </button>
299
+ </div>
300
+ </div>
301
+ </div>
302
+
303
+ <!-- 3. Campaign Products Listing Grid / List -->
304
+ <div
305
+ id="sf-campaign-products-container"
306
+ class="sf-campaign-products-container ${
307
+ viewMode === 'list'
308
+ ? 'flex flex-col gap-4'
309
+ : 'grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6'
310
+ }"
311
+ data-campaign-slug="${escapeHtml(slug)}"
312
+ data-current-view="${viewMode}"
313
+ >
314
+ ${products.length > 0 ? (
315
+ products.map((p, idx) => renderProductCard(p, idx)).join('\n')
316
+ ) : `
317
+ <div class="col-span-full py-16 text-center bg-white dark:bg-slate-900 rounded-3xl border border-slate-200 dark:border-slate-800 shadow-sm">
318
+ <svg class="w-12 h-12 mx-auto text-slate-300 dark:text-slate-600 mb-3" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24">
319
+ <path stroke-linecap="round" stroke-linejoin="round" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
320
+ </svg>
321
+ <h3 class="text-base font-bold text-slate-900 dark:text-white mb-1">No products currently available</h3>
322
+ <p class="text-xs text-slate-500 dark:text-slate-400 max-w-md mx-auto mb-6">
323
+ Products associated with this promotional campaign are currently updating or out of stock.
324
+ </p>
325
+ <a href="/products" class="sf-btn sf-btn--primary px-6 py-2.5 rounded-xl text-xs font-bold inline-block">
326
+ Explore All Catalog Items
327
+ </a>
328
+ </div>
329
+ `}
330
+ </div>
331
+ </div>
332
+
333
+ <!-- Scoped Island Script for Instant Interactivity -->
334
+ <script${nonceAttr}>
335
+ (function() {
336
+ var container = document.getElementById('sf-campaign-products-container');
337
+ var sortSelect = document.getElementById('sf-campaign-sort');
338
+ var viewButtons = document.querySelectorAll('.js-view-toggle');
339
+
340
+ if (!container) return;
341
+
342
+ // View Toggle Handler (Grid vs List)
343
+ viewButtons.forEach(function(btn) {
344
+ btn.addEventListener('click', function(e) {
345
+ e.preventDefault();
346
+ var view = btn.getAttribute('data-view');
347
+ viewButtons.forEach(function(b) {
348
+ b.classList.remove('bg-neutral-900', 'text-white', 'dark:bg-white', 'dark:text-neutral-900', 'shadow-sm');
349
+ b.classList.add('text-slate-500', 'dark:text-slate-400');
350
+ });
351
+ btn.classList.add('bg-neutral-900', 'text-white', 'dark:bg-white', 'dark:text-neutral-900', 'shadow-sm');
352
+ btn.classList.remove('text-slate-500', 'dark:text-slate-400');
353
+
354
+ if (view === 'list') {
355
+ container.classList.remove('grid', 'grid-cols-1', 'sm:grid-cols-2', 'lg:grid-cols-3', 'xl:grid-cols-4', 'gap-6');
356
+ container.classList.add('flex', 'flex-col', 'gap-4', 'is-list-view');
357
+ container.setAttribute('data-current-view', 'list');
358
+ } else {
359
+ container.classList.add('grid', 'grid-cols-1', 'sm:grid-cols-2', 'lg:grid-cols-3', 'xl:grid-cols-4', 'gap-6');
360
+ container.classList.remove('flex', 'flex-col', 'gap-4', 'is-list-view');
361
+ container.setAttribute('data-current-view', 'grid');
362
+ }
363
+ });
364
+ });
365
+
366
+ // Sorting Handler
367
+ if (sortSelect) {
368
+ sortSelect.addEventListener('change', function() {
369
+ var sortBy = sortSelect.value;
370
+ var cards = Array.from(container.querySelectorAll('.js-campaign-card'));
371
+ if (cards.length === 0) return;
372
+
373
+ cards.sort(function(a, b) {
374
+ var priceA = parseFloat(a.getAttribute('data-price') || '0');
375
+ var priceB = parseFloat(b.getAttribute('data-price') || '0');
376
+ var titleA = (a.getAttribute('data-title') || '').toLowerCase();
377
+ var titleB = (b.getAttribute('data-title') || '').toLowerCase();
378
+ var ratingA = parseFloat(a.getAttribute('data-rating') || '0');
379
+ var ratingB = parseFloat(b.getAttribute('data-rating') || '0');
380
+ var indexA = parseInt(a.getAttribute('data-product-index') || '0', 10);
381
+ var indexB = parseInt(b.getAttribute('data-product-index') || '0', 10);
382
+
383
+ if (sortBy === 'price_asc') return priceA - priceB;
384
+ if (sortBy === 'price_desc') return priceB - priceA;
385
+ if (sortBy === 'name_asc') return titleA.localeCompare(titleB);
386
+ if (sortBy === 'new') return indexB - indexA;
387
+ // popularity default
388
+ if (ratingA !== ratingB) return ratingB - ratingA;
389
+ return indexA - indexB;
390
+ });
391
+
392
+ cards.forEach(function(card) {
393
+ container.appendChild(card);
394
+ });
395
+ });
396
+ }
397
+ })();
398
+ </script>
399
+
400
+ <!-- Scoped CSS for List View styling -->
401
+ <style>
402
+ .sf-campaign-products-container.is-list-view .sf-campaign-product-card {
403
+ flex-direction: row !important;
404
+ align-items: stretch !important;
405
+ }
406
+ .sf-campaign-products-container.is-list-view .sf-card-image-wrapper {
407
+ width: 220px !important;
408
+ min-width: 220px !important;
409
+ aspect-ratio: 1 / 1 !important;
410
+ }
411
+ @media (max-width: 640px) {
412
+ .sf-campaign-products-container.is-list-view .sf-campaign-product-card {
413
+ flex-direction: column !important;
414
+ }
415
+ .sf-campaign-products-container.is-list-view .sf-card-image-wrapper {
416
+ width: 100% !important;
417
+ min-width: 100% !important;
418
+ }
419
+ }
420
+ </style>
421
+ </div>
422
+ `;
423
+ }