| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?php
-
- namespace App\StorePlan;
-
- /**
- * The single definition of what a "store plan" may contain.
- *
- * A store plan is the saved design of a store:
- * - a theme (colours, fonts, corner radius)
- * - one header and one footer, shared by every page
- * - one or more pages, each an ordered list of sections. The first page is always "home".
- * It belongs to us, not to any AI provider. Whoever writes a plan (a person, Claude,
- * DeepSeek, anything later) must produce this shape, and PlanValidator checks it.
- *
- * Keep this file in step with resources/js/storefront/types.ts.
- */
- final class PlanSchema
- {
- public const int VERSION = 2;
-
- /**
- * Theme colours every plan must define, as 6-digit hex values.
- *
- * @var list<string>
- */
- public const array COLORS = [
- 'background',
- 'surface',
- 'foreground',
- 'muted',
- 'primary',
- 'primaryForeground',
- 'accent',
- 'border',
- ];
-
- /**
- * Fonts the storefront can load. Key is what the plan stores, value is the font family name.
- *
- * @var array<string, string>
- */
- public const array FONTS = [
- 'inter' => 'Inter',
- 'dm-sans' => 'DM Sans',
- 'poppins' => 'Poppins',
- 'manrope' => 'Manrope',
- 'space-grotesk' => 'Space Grotesk',
- 'playfair-display' => 'Playfair Display',
- 'lora' => 'Lora',
- 'fraunces' => 'Fraunces',
- // Added in Step 9 part 4, for more personality.
- 'cormorant-garamond' => 'Cormorant Garamond',
- 'dm-serif-display' => 'DM Serif Display',
- 'libre-baskerville' => 'Libre Baskerville',
- 'bricolage-grotesque' => 'Bricolage Grotesque',
- 'syne' => 'Syne',
- 'unbounded' => 'Unbounded',
- 'archivo-black' => 'Archivo Black',
- 'bebas-neue' => 'Bebas Neue',
- 'outfit' => 'Outfit',
- 'jost' => 'Jost',
- 'nunito' => 'Nunito',
- 'caveat' => 'Caveat',
- ];
-
- /**
- * Fonts that only suit big headings: one weight, all capitals or handwriting. Never for body text.
- *
- * @var list<string>
- */
- public const array HEADING_ONLY_FONTS = ['archivo-black', 'bebas-neue', 'caveat', 'dm-serif-display'];
-
- /**
- * The look of the whole store, beyond colours and fonts. Every option is optional; an old plan without
- * "style" uses the defaults, which look exactly like stores did before.
- *
- * - buttons: solid, outline (a line around, filled on hover) or shadow (a solid offset shadow, playful and bold)
- * - cards: border (thin line), shadow (soft lift), plain (no edge) or hard (thick line and solid offset shadow)
- * - spacing: compact, normal or airy (room between sections)
- * - headings: normal, uppercase (spaced capitals, elegant) or heavy (extra bold and tight)
- * - backgrounds: plain, or alternate (every other section on a soft band)
- * - motion: none, or gentle (sections fade up as they come into view; never for visitors who ask for less motion)
- *
- * @var array<string, list<string>>
- */
- public const array STYLE_OPTIONS = [
- 'buttons' => ['solid', 'outline', 'shadow'],
- 'cards' => ['border', 'shadow', 'plain', 'hard'],
- 'spacing' => ['compact', 'normal', 'airy'],
- 'headings' => ['normal', 'uppercase', 'heavy'],
- 'backgrounds' => ['plain', 'alternate'],
- 'motion' => ['none', 'gentle'],
- ];
-
- /** @var array<string, string> */
- public const array STYLE_DEFAULTS = [
- 'buttons' => 'solid',
- 'cards' => 'border',
- 'spacing' => 'normal',
- 'headings' => 'normal',
- 'backgrounds' => 'plain',
- 'motion' => 'none',
- ];
-
- /**
- * Ready-made looks for the Design tab's Style box. Each sets the style, corner roundness and fonts;
- * colours stay as they are.
- *
- * @var array<string, array{label: string, hint: string, radius: string, fonts: array{heading: string, body: string}, style: array<string, string>}>
- */
- public const array STYLE_PRESETS = [
- 'minimal' => [
- 'label' => 'Minimal',
- 'hint' => 'Clean, lots of space, quiet details',
- 'radius' => 'small',
- 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
- 'style' => ['buttons' => 'solid', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'plain', 'motion' => 'gentle'],
- ],
- 'soft' => [
- 'label' => 'Soft',
- 'hint' => 'Rounded, gentle shadows, friendly',
- 'radius' => 'large',
- 'fonts' => ['heading' => 'outfit', 'body' => 'nunito'],
- 'style' => ['buttons' => 'solid', 'cards' => 'shadow', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
- ],
- 'elegant' => [
- 'label' => 'Elegant',
- 'hint' => 'Serif headings, fine lines, premium',
- 'radius' => 'none',
- 'fonts' => ['heading' => 'cormorant-garamond', 'body' => 'jost'],
- 'style' => ['buttons' => 'outline', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'uppercase', 'backgrounds' => 'plain', 'motion' => 'gentle'],
- ],
- 'bold' => [
- 'label' => 'Bold',
- 'hint' => 'Heavy type, hard shadows, loud',
- 'radius' => 'none',
- 'fonts' => ['heading' => 'archivo-black', 'body' => 'space-grotesk'],
- 'style' => ['buttons' => 'shadow', 'cards' => 'hard', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
- ],
- 'playful' => [
- 'label' => 'Playful',
- 'hint' => 'Round shapes, fun type, lively',
- 'radius' => 'full',
- 'fonts' => ['heading' => 'bricolage-grotesque', 'body' => 'dm-sans'],
- 'style' => ['buttons' => 'shadow', 'cards' => 'shadow', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
- ],
- 'classic' => [
- 'label' => 'Classic',
- 'hint' => 'How stores looked before: simple and safe',
- 'radius' => 'medium',
- 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
- 'style' => self::STYLE_DEFAULTS,
- ],
- ];
-
- /**
- * How rounded corners are.
- *
- * @var list<string>
- */
- public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
-
- /**
- * Section types and the layout variants each one supports.
- *
- * @var array<string, list<string>>
- */
- public const array SECTIONS = [
- 'header' => ['simple', 'centered'],
- // centered: text only. split: text beside a photo. image-full: a full-width photo with the text on it.
- 'hero' => ['centered', 'split', 'image-full'],
- // A row of short reassurances, such as free shipping and secure payment. row: a band. boxed: small cards.
- 'trust_bar' => ['row', 'boxed'],
- 'product_grid' => ['grid', 'minimal'],
- 'featured_product' => ['image-left', 'image-right'],
- 'about' => ['simple', 'with-stats'],
- 'testimonials' => ['cards', 'single'],
- 'faq' => ['list', 'two-column'],
- 'newsletter' => ['banner', 'card'],
- 'contact' => ['simple', 'card'],
- 'footer' => ['simple', 'centered'],
- ];
-
- /**
- * Section types a page may contain. The header and footer are not here:
- * they live once at the top of the plan and appear on every page.
- *
- * @return array<string, list<string>>
- */
- public static function pageSections(): array
- {
- return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
- }
-
- /** What a trust row item can be. */
- public const array TRUST_KINDS = ['shipping', 'payment', 'whatsapp', 'custom'];
-
- /** Icons a trust row item may use. */
- public const array TRUST_ICONS = ['truck', 'shield', 'chat', 'refresh', 'leaf', 'star', 'gift', 'clock', 'heart', 'award', 'map-pin', 'package'];
-
- /** Sections per page. */
- public const int MAX_SECTIONS = 20;
-
- public const int MAX_PAGES = 10;
-
- /**
- * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
- *
- * @var list<string>
- */
- public const array BUILT_IN_PATHS = ['shop', 'products', 'cart'];
-
- /** The first page of every plan. */
- public const string HOME_PAGE = 'home';
-
- /**
- * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
- *
- * @var list<string>
- */
- public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
-
- /**
- * Links may only point inside the page, inside the site, or to safe outside targets.
- * This blocks things like "javascript:" links.
- */
- public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
-
- public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
-
- public const string PRODUCT_SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
-
- /** Used for both section ids and page ids. */
- public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
-
- /**
- * Validation rules for the content of one section type.
- * Keys are relative to the section's "content" object.
- *
- * @return array<string, list<string>>
- */
- public static function contentRules(string $type): array
- {
- $text = fn (int $max) => ['required', 'string', 'max:'.$max];
- $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
- $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
- $price = ['required', 'numeric', 'min:0', 'max:999999'];
-
- return match ($type) {
- 'header' => [
- 'logoText' => $text(40),
- 'links' => ['present', 'array', 'max:6'],
- 'links.*.label' => $text(30),
- 'links.*.href' => $link,
- 'cta' => ['nullable', 'array'],
- 'cta.label' => ['required_with:cta', 'string', 'max:30'],
- 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
- ],
- 'hero' => [
- 'eyebrow' => $optionalText(60),
- 'headline' => $text(120),
- 'subheadline' => $text(300),
- 'primaryCta' => ['required', 'array'],
- 'primaryCta.label' => $text(30),
- 'primaryCta.href' => $link,
- 'secondaryCta' => ['nullable', 'array'],
- 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
- 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
- // "upload:12" (a photo uploaded in the Design tab) or "product:web-address-name" (a product's main photo).
- // Null means automatic: the store's own product photos are used.
- 'image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
- ],
- 'product_grid' => [
- 'heading' => $text(80),
- 'subheading' => $optionalText(200),
- 'items' => ['required', 'array', 'min:2', 'max:8'],
- 'items.*.name' => $text(80),
- 'items.*.price' => $price,
- 'items.*.badge' => $optionalText(20),
- ],
- 'featured_product' => [
- 'eyebrow' => $optionalText(60),
- 'name' => $text(80),
- 'description' => $text(500),
- 'price' => $price,
- 'bullets' => ['present', 'array', 'max:5'],
- 'bullets.*' => $text(100),
- 'cta' => ['required', 'array'],
- 'cta.label' => $text(30),
- 'cta.href' => $link,
- // The web-address name of one of the store's real products. When set, the store shows that
- // product's real name, price and photo instead of "name" and "price" above.
- 'productSlug' => ['nullable', 'string', 'max:120', 'regex:'.self::PRODUCT_SLUG_PATTERN],
- ],
- 'about' => [
- 'heading' => $text(80),
- 'body' => $text(1200),
- 'stats' => ['present', 'array', 'max:4'],
- 'stats.*.value' => $text(12),
- 'stats.*.label' => $text(40),
- ],
- 'trust_bar' => [
- 'items' => ['required', 'array', 'min:2', 'max:4'],
- // shipping, payment and whatsapp are written by the store itself from its real settings, so they
- // stay true when the merchant changes them. custom uses the title and text below.
- 'items.*.kind' => ['required', 'string', 'in:'.implode(',', self::TRUST_KINDS)],
- 'items.*.icon' => ['nullable', 'string', 'in:'.implode(',', self::TRUST_ICONS)],
- 'items.*.title' => ['required_if:items.*.kind,custom', 'nullable', 'string', 'max:40'],
- 'items.*.text' => ['nullable', 'string', 'max:80'],
- ],
- 'testimonials' => [
- 'heading' => $text(80),
- 'items' => ['required', 'array', 'min:1', 'max:6'],
- 'items.*.quote' => $text(400),
- 'items.*.name' => $text(60),
- 'items.*.role' => $optionalText(60),
- ],
- 'faq' => [
- 'heading' => $text(80),
- 'items' => ['required', 'array', 'min:1', 'max:10'],
- 'items.*.question' => $text(160),
- 'items.*.answer' => $text(600),
- ],
- 'newsletter' => [
- 'heading' => $text(80),
- 'body' => $optionalText(240),
- 'placeholder' => $text(40),
- 'buttonLabel' => $text(30),
- ],
- 'contact' => [
- 'heading' => $text(80),
- 'body' => $optionalText(300),
- 'email' => ['nullable', 'email', 'max:120'],
- 'phone' => $optionalText(30),
- 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
- 'address' => $optionalText(200),
- ],
- 'footer' => [
- 'text' => $text(160),
- 'links' => ['present', 'array', 'max:8'],
- 'links.*.label' => $text(30),
- 'links.*.href' => $link,
- ],
- default => [],
- };
- }
- }
|