AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. namespace App\StorePlan;
  3. /**
  4. * The single definition of what a "store plan" may contain.
  5. *
  6. * A store plan is the saved design of a store:
  7. * - a theme (colours, fonts, corner radius)
  8. * - one header and one footer, shared by every page
  9. * - one or more pages, each an ordered list of sections. The first page is always "home".
  10. * It belongs to us, not to any AI provider. Whoever writes a plan (a person, Claude,
  11. * DeepSeek, anything later) must produce this shape, and PlanValidator checks it.
  12. *
  13. * Keep this file in step with resources/js/storefront/types.ts.
  14. */
  15. final class PlanSchema
  16. {
  17. public const int VERSION = 2;
  18. /**
  19. * Theme colours every plan must define, as 6-digit hex values.
  20. *
  21. * @var list<string>
  22. */
  23. public const array COLORS = [
  24. 'background',
  25. 'surface',
  26. 'foreground',
  27. 'muted',
  28. 'primary',
  29. 'primaryForeground',
  30. 'accent',
  31. 'border',
  32. ];
  33. /**
  34. * Fonts the storefront can load. Key is what the plan stores, value is the font family name.
  35. *
  36. * @var array<string, string>
  37. */
  38. public const array FONTS = [
  39. 'inter' => 'Inter',
  40. 'dm-sans' => 'DM Sans',
  41. 'poppins' => 'Poppins',
  42. 'manrope' => 'Manrope',
  43. 'space-grotesk' => 'Space Grotesk',
  44. 'playfair-display' => 'Playfair Display',
  45. 'lora' => 'Lora',
  46. 'fraunces' => 'Fraunces',
  47. // Added in Step 9 part 4, for more personality.
  48. 'cormorant-garamond' => 'Cormorant Garamond',
  49. 'dm-serif-display' => 'DM Serif Display',
  50. 'libre-baskerville' => 'Libre Baskerville',
  51. 'bricolage-grotesque' => 'Bricolage Grotesque',
  52. 'syne' => 'Syne',
  53. 'unbounded' => 'Unbounded',
  54. 'archivo-black' => 'Archivo Black',
  55. 'bebas-neue' => 'Bebas Neue',
  56. 'outfit' => 'Outfit',
  57. 'jost' => 'Jost',
  58. 'nunito' => 'Nunito',
  59. 'caveat' => 'Caveat',
  60. ];
  61. /**
  62. * Fonts that only suit big headings: one weight, all capitals or handwriting. Never for body text.
  63. *
  64. * @var list<string>
  65. */
  66. public const array HEADING_ONLY_FONTS = ['archivo-black', 'bebas-neue', 'caveat', 'dm-serif-display'];
  67. /**
  68. * The look of the whole store, beyond colours and fonts. Every option is optional; an old plan without
  69. * "style" uses the defaults, which look exactly like stores did before.
  70. *
  71. * - buttons: solid, outline (a line around, filled on hover) or shadow (a solid offset shadow, playful and bold)
  72. * - cards: border (thin line), shadow (soft lift), plain (no edge) or hard (thick line and solid offset shadow)
  73. * - spacing: compact, normal or airy (room between sections)
  74. * - headings: normal, uppercase (spaced capitals, elegant) or heavy (extra bold and tight)
  75. * - backgrounds: plain, or alternate (every other section on a soft band)
  76. * - motion: none, or gentle (sections fade up as they come into view; never for visitors who ask for less motion)
  77. *
  78. * @var array<string, list<string>>
  79. */
  80. public const array STYLE_OPTIONS = [
  81. 'buttons' => ['solid', 'outline', 'shadow'],
  82. 'cards' => ['border', 'shadow', 'plain', 'hard'],
  83. 'spacing' => ['compact', 'normal', 'airy'],
  84. 'headings' => ['normal', 'uppercase', 'heavy'],
  85. 'backgrounds' => ['plain', 'alternate'],
  86. 'motion' => ['none', 'gentle'],
  87. ];
  88. /** @var array<string, string> */
  89. public const array STYLE_DEFAULTS = [
  90. 'buttons' => 'solid',
  91. 'cards' => 'border',
  92. 'spacing' => 'normal',
  93. 'headings' => 'normal',
  94. 'backgrounds' => 'plain',
  95. 'motion' => 'none',
  96. ];
  97. /**
  98. * Ready-made looks for the Design tab's Style box. Each sets the style, corner roundness and fonts;
  99. * colours stay as they are.
  100. *
  101. * @var array<string, array{label: string, hint: string, radius: string, fonts: array{heading: string, body: string}, style: array<string, string>}>
  102. */
  103. public const array STYLE_PRESETS = [
  104. 'minimal' => [
  105. 'label' => 'Minimal',
  106. 'hint' => 'Clean, lots of space, quiet details',
  107. 'radius' => 'small',
  108. 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
  109. 'style' => ['buttons' => 'solid', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'plain', 'motion' => 'gentle'],
  110. ],
  111. 'soft' => [
  112. 'label' => 'Soft',
  113. 'hint' => 'Rounded, gentle shadows, friendly',
  114. 'radius' => 'large',
  115. 'fonts' => ['heading' => 'outfit', 'body' => 'nunito'],
  116. 'style' => ['buttons' => 'solid', 'cards' => 'shadow', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  117. ],
  118. 'elegant' => [
  119. 'label' => 'Elegant',
  120. 'hint' => 'Serif headings, fine lines, premium',
  121. 'radius' => 'none',
  122. 'fonts' => ['heading' => 'cormorant-garamond', 'body' => 'jost'],
  123. 'style' => ['buttons' => 'outline', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'uppercase', 'backgrounds' => 'plain', 'motion' => 'gentle'],
  124. ],
  125. 'bold' => [
  126. 'label' => 'Bold',
  127. 'hint' => 'Heavy type, hard shadows, loud',
  128. 'radius' => 'none',
  129. 'fonts' => ['heading' => 'archivo-black', 'body' => 'space-grotesk'],
  130. 'style' => ['buttons' => 'shadow', 'cards' => 'hard', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  131. ],
  132. 'playful' => [
  133. 'label' => 'Playful',
  134. 'hint' => 'Round shapes, fun type, lively',
  135. 'radius' => 'full',
  136. 'fonts' => ['heading' => 'bricolage-grotesque', 'body' => 'dm-sans'],
  137. 'style' => ['buttons' => 'shadow', 'cards' => 'shadow', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  138. ],
  139. 'classic' => [
  140. 'label' => 'Classic',
  141. 'hint' => 'How stores looked before: simple and safe',
  142. 'radius' => 'medium',
  143. 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
  144. 'style' => self::STYLE_DEFAULTS,
  145. ],
  146. ];
  147. /**
  148. * How rounded corners are.
  149. *
  150. * @var list<string>
  151. */
  152. public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
  153. /**
  154. * Section types and the layout variants each one supports.
  155. *
  156. * @var array<string, list<string>>
  157. */
  158. public const array SECTIONS = [
  159. 'header' => ['simple', 'centered'],
  160. // centered: text only. split: text beside a photo. image-full: a full-width photo with the text on it.
  161. 'hero' => ['centered', 'split', 'image-full'],
  162. // A row of short reassurances, such as free shipping and secure payment. row: a band. boxed: small cards.
  163. 'trust_bar' => ['row', 'boxed'],
  164. 'product_grid' => ['grid', 'minimal'],
  165. 'featured_product' => ['image-left', 'image-right'],
  166. 'about' => ['simple', 'with-stats'],
  167. 'testimonials' => ['cards', 'single'],
  168. 'faq' => ['list', 'two-column'],
  169. 'newsletter' => ['banner', 'card'],
  170. 'contact' => ['simple', 'card'],
  171. 'footer' => ['simple', 'centered'],
  172. ];
  173. /**
  174. * Section types a page may contain. The header and footer are not here:
  175. * they live once at the top of the plan and appear on every page.
  176. *
  177. * @return array<string, list<string>>
  178. */
  179. public static function pageSections(): array
  180. {
  181. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  182. }
  183. /** What a trust row item can be. */
  184. public const array TRUST_KINDS = ['shipping', 'payment', 'whatsapp', 'custom'];
  185. /** Icons a trust row item may use. */
  186. public const array TRUST_ICONS = ['truck', 'shield', 'chat', 'refresh', 'leaf', 'star', 'gift', 'clock', 'heart', 'award', 'map-pin', 'package'];
  187. /** Sections per page. */
  188. public const int MAX_SECTIONS = 20;
  189. public const int MAX_PAGES = 10;
  190. /**
  191. * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
  192. *
  193. * @var list<string>
  194. */
  195. public const array BUILT_IN_PATHS = ['shop', 'products', 'cart'];
  196. /** The first page of every plan. */
  197. public const string HOME_PAGE = 'home';
  198. /**
  199. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  200. *
  201. * @var list<string>
  202. */
  203. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
  204. /**
  205. * Links may only point inside the page, inside the site, or to safe outside targets.
  206. * This blocks things like "javascript:" links.
  207. */
  208. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  209. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  210. public const string PRODUCT_SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
  211. /** Used for both section ids and page ids. */
  212. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  213. /**
  214. * Validation rules for the content of one section type.
  215. * Keys are relative to the section's "content" object.
  216. *
  217. * @return array<string, list<string>>
  218. */
  219. public static function contentRules(string $type): array
  220. {
  221. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  222. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  223. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  224. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  225. return match ($type) {
  226. 'header' => [
  227. 'logoText' => $text(40),
  228. 'links' => ['present', 'array', 'max:6'],
  229. 'links.*.label' => $text(30),
  230. 'links.*.href' => $link,
  231. 'cta' => ['nullable', 'array'],
  232. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  233. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  234. ],
  235. 'hero' => [
  236. 'eyebrow' => $optionalText(60),
  237. 'headline' => $text(120),
  238. 'subheadline' => $text(300),
  239. 'primaryCta' => ['required', 'array'],
  240. 'primaryCta.label' => $text(30),
  241. 'primaryCta.href' => $link,
  242. 'secondaryCta' => ['nullable', 'array'],
  243. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  244. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  245. // "upload:12" (a photo uploaded in the Design tab) or "product:web-address-name" (a product's main photo).
  246. // Null means automatic: the store's own product photos are used.
  247. 'image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
  248. ],
  249. 'product_grid' => [
  250. 'heading' => $text(80),
  251. 'subheading' => $optionalText(200),
  252. 'items' => ['required', 'array', 'min:2', 'max:8'],
  253. 'items.*.name' => $text(80),
  254. 'items.*.price' => $price,
  255. 'items.*.badge' => $optionalText(20),
  256. ],
  257. 'featured_product' => [
  258. 'eyebrow' => $optionalText(60),
  259. 'name' => $text(80),
  260. 'description' => $text(500),
  261. 'price' => $price,
  262. 'bullets' => ['present', 'array', 'max:5'],
  263. 'bullets.*' => $text(100),
  264. 'cta' => ['required', 'array'],
  265. 'cta.label' => $text(30),
  266. 'cta.href' => $link,
  267. // The web-address name of one of the store's real products. When set, the store shows that
  268. // product's real name, price and photo instead of "name" and "price" above.
  269. 'productSlug' => ['nullable', 'string', 'max:120', 'regex:'.self::PRODUCT_SLUG_PATTERN],
  270. ],
  271. 'about' => [
  272. 'heading' => $text(80),
  273. 'body' => $text(1200),
  274. 'stats' => ['present', 'array', 'max:4'],
  275. 'stats.*.value' => $text(12),
  276. 'stats.*.label' => $text(40),
  277. ],
  278. 'trust_bar' => [
  279. 'items' => ['required', 'array', 'min:2', 'max:4'],
  280. // shipping, payment and whatsapp are written by the store itself from its real settings, so they
  281. // stay true when the merchant changes them. custom uses the title and text below.
  282. 'items.*.kind' => ['required', 'string', 'in:'.implode(',', self::TRUST_KINDS)],
  283. 'items.*.icon' => ['nullable', 'string', 'in:'.implode(',', self::TRUST_ICONS)],
  284. 'items.*.title' => ['required_if:items.*.kind,custom', 'nullable', 'string', 'max:40'],
  285. 'items.*.text' => ['nullable', 'string', 'max:80'],
  286. ],
  287. 'testimonials' => [
  288. 'heading' => $text(80),
  289. 'items' => ['required', 'array', 'min:1', 'max:6'],
  290. 'items.*.quote' => $text(400),
  291. 'items.*.name' => $text(60),
  292. 'items.*.role' => $optionalText(60),
  293. ],
  294. 'faq' => [
  295. 'heading' => $text(80),
  296. 'items' => ['required', 'array', 'min:1', 'max:10'],
  297. 'items.*.question' => $text(160),
  298. 'items.*.answer' => $text(600),
  299. ],
  300. 'newsletter' => [
  301. 'heading' => $text(80),
  302. 'body' => $optionalText(240),
  303. 'placeholder' => $text(40),
  304. 'buttonLabel' => $text(30),
  305. ],
  306. 'contact' => [
  307. 'heading' => $text(80),
  308. 'body' => $optionalText(300),
  309. 'email' => ['nullable', 'email', 'max:120'],
  310. 'phone' => $optionalText(30),
  311. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  312. 'address' => $optionalText(200),
  313. ],
  314. 'footer' => [
  315. 'text' => $text(160),
  316. 'links' => ['present', 'array', 'max:8'],
  317. 'links.*.label' => $text(30),
  318. 'links.*.href' => $link,
  319. ],
  320. default => [],
  321. };
  322. }
  323. }