create-skybridge 0.0.0-dev.ea04428 → 0.0.0-dev.ea09368

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 (116) hide show
  1. package/dist/index.js +335 -212
  2. package/package.json +6 -5
  3. package/{template → templates/blank}/Dockerfile +3 -3
  4. package/templates/blank/README.md +92 -0
  5. package/{template → templates/blank}/_gitignore +2 -1
  6. package/templates/blank/node_modules/.bin/alpic +21 -0
  7. package/{template → templates/blank}/node_modules/.bin/tsx +2 -2
  8. package/{template → templates/blank}/node_modules/.bin/vite +2 -2
  9. package/templates/blank/package.json +29 -0
  10. package/templates/blank/src/server.ts +16 -0
  11. package/templates/blank/tsconfig.json +5 -0
  12. package/templates/blank/vite.config.ts +6 -0
  13. package/templates/demo/.dockerignore +4 -0
  14. package/templates/demo/AGENTS.md +1 -0
  15. package/templates/demo/Dockerfile +53 -0
  16. package/{template → templates/demo}/README.md +16 -15
  17. package/templates/demo/_gitignore +7 -0
  18. package/templates/demo/alpic.json +3 -0
  19. package/templates/demo/node_modules/.bin/alpic +21 -0
  20. package/templates/demo/node_modules/.bin/sb +21 -0
  21. package/templates/demo/node_modules/.bin/skybridge +21 -0
  22. package/templates/demo/node_modules/.bin/tsc +21 -0
  23. package/templates/demo/node_modules/.bin/tsserver +21 -0
  24. package/templates/demo/node_modules/.bin/tsx +21 -0
  25. package/templates/demo/node_modules/.bin/vite +21 -0
  26. package/{template → templates/demo}/package.json +15 -15
  27. package/templates/demo/src/helpers.ts +4 -0
  28. package/{template → templates/demo}/src/server.ts +23 -6
  29. package/{template → templates/demo}/src/views/components/steps/tool-output.tsx +2 -2
  30. package/{template → templates/demo}/src/views/onboarding.tsx +1 -1
  31. package/templates/ecom/.dockerignore +4 -0
  32. package/templates/ecom/.env.template +2 -0
  33. package/templates/ecom/.ladle/components.tsx +26 -0
  34. package/templates/ecom/.ladle/config.mjs +11 -0
  35. package/templates/ecom/.ladle/vite.config.ts +11 -0
  36. package/templates/ecom/AGENTS.md +2 -0
  37. package/templates/ecom/Dockerfile +53 -0
  38. package/templates/ecom/README.md +92 -0
  39. package/templates/ecom/_gitignore +9 -0
  40. package/templates/ecom/alpic.json +3 -0
  41. package/templates/ecom/node_modules/.bin/alpic +21 -0
  42. package/templates/ecom/node_modules/.bin/ladle +21 -0
  43. package/templates/ecom/node_modules/.bin/sb +21 -0
  44. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  45. package/templates/ecom/node_modules/.bin/tsc +21 -0
  46. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  47. package/templates/ecom/node_modules/.bin/tsx +21 -0
  48. package/templates/ecom/node_modules/.bin/vite +21 -0
  49. package/templates/ecom/package.json +41 -0
  50. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  51. package/templates/ecom/src/components/empty-state.tsx +12 -0
  52. package/templates/ecom/src/components/product-card.css.ts +136 -0
  53. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  54. package/templates/ecom/src/components/product-card.tsx +101 -0
  55. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  56. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  57. package/templates/ecom/src/components/product-carousel.tsx +195 -0
  58. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  59. package/templates/ecom/src/components/view-frame.tsx +27 -0
  60. package/templates/ecom/src/config.ts +12 -0
  61. package/templates/ecom/src/design/contract.css.ts +39 -0
  62. package/templates/ecom/src/design/fonts.css +15 -0
  63. package/templates/ecom/src/design/primitives.css.ts +101 -0
  64. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  65. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  66. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  67. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  68. package/templates/ecom/src/design/tokens.ts +8 -0
  69. package/templates/ecom/src/helpers.ts +4 -0
  70. package/templates/ecom/src/i18n.ts +27 -0
  71. package/templates/ecom/src/index.css +9 -0
  72. package/templates/ecom/src/lib/cx.ts +9 -0
  73. package/templates/ecom/src/lib/format.ts +9 -0
  74. package/templates/ecom/src/server.ts +43 -0
  75. package/templates/ecom/src/tools/render-carousel.ts +234 -0
  76. package/templates/ecom/src/tools/search-products.ts +182 -0
  77. package/templates/ecom/src/types.ts +13 -0
  78. package/templates/ecom/src/views/carousel/index.tsx +94 -0
  79. package/templates/ecom/tsconfig.json +11 -0
  80. package/templates/ecom/vite.config.ts +8 -0
  81. package/dist/index.test.d.ts +0 -1
  82. package/dist/index.test.js +0 -35
  83. package/template/node_modules/.bin/alpic +0 -21
  84. package/template/src/vite-manifest.d.ts +0 -4
  85. /package/{template → templates/blank}/.dockerignore +0 -0
  86. /package/{template → templates/blank}/AGENTS.md +0 -0
  87. /package/{template → templates/blank}/alpic.json +0 -0
  88. /package/{template → templates/blank}/node_modules/.bin/sb +0 -0
  89. /package/{template → templates/blank}/node_modules/.bin/skybridge +0 -0
  90. /package/{template → templates/blank}/node_modules/.bin/tsc +0 -0
  91. /package/{template → templates/blank}/node_modules/.bin/tsserver +0 -0
  92. /package/{template → templates/blank}/src/helpers.ts +0 -0
  93. /package/{template → templates/demo}/src/index.css +0 -0
  94. /package/{template → templates/demo}/src/views/components/doc-link.tsx +0 -0
  95. /package/{template → templates/demo}/src/views/components/doc.tsx +0 -0
  96. /package/{template → templates/demo}/src/views/components/nav.tsx +0 -0
  97. /package/{template → templates/demo}/src/views/components/progress.tsx +0 -0
  98. /package/{template → templates/demo}/src/views/components/steps/outro.tsx +0 -0
  99. /package/{template → templates/demo}/src/views/components/steps/state.tsx +0 -0
  100. /package/{template → templates/demo}/src/views/components/steps/tool-call.tsx +0 -0
  101. /package/{template → templates/demo}/src/views/images/mascot/beret.png +0 -0
  102. /package/{template → templates/demo}/src/views/images/mascot/chapka.png +0 -0
  103. /package/{template → templates/demo}/src/views/images/mascot/cowboy-hat.png +0 -0
  104. /package/{template → templates/demo}/src/views/images/mascot/fez.png +0 -0
  105. /package/{template → templates/demo}/src/views/images/mascot/jester-hat.png +0 -0
  106. /package/{template → templates/demo}/src/views/images/mascot/mitre.png +0 -0
  107. /package/{template → templates/demo}/src/views/images/mascot/non-la.png +0 -0
  108. /package/{template → templates/demo}/src/views/images/mascot/original.png +0 -0
  109. /package/{template → templates/demo}/src/views/images/mascot/propeller-beanie.png +0 -0
  110. /package/{template → templates/demo}/src/views/images/mascot/ski-mask.png +0 -0
  111. /package/{template → templates/demo}/src/views/images/mascot/sombrero.png +0 -0
  112. /package/{template → templates/demo}/src/views/images/mascot/top-hat.png +0 -0
  113. /package/{template → templates/demo}/src/views/images/mascot/viking-helmet.png +0 -0
  114. /package/{template → templates/demo}/src/views/use-mascot.ts +0 -0
  115. /package/{template → templates/demo}/tsconfig.json +0 -0
  116. /package/{template → templates/demo}/vite.config.ts +0 -0
@@ -0,0 +1,58 @@
1
+ import { ProductCard, ProductCardSkeleton } from "./product-card";
2
+
3
+ const IMAGE =
4
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Crect width='240' height='240' fill='%23e5e5e5'/%3E%3Ccircle cx='120' cy='120' r='70' fill='%23bcbcbc'/%3E%3C/svg%3E";
5
+
6
+ const frame = { maxWidth: 220 };
7
+
8
+ export const Default = () => (
9
+ <div style={frame}>
10
+ <ProductCard
11
+ title="Merino wool sweater"
12
+ price={{ amount: 129.9, currency: "EUR" }}
13
+ media={[IMAGE]}
14
+ />
15
+ </div>
16
+ );
17
+
18
+ export const LongTitle = () => (
19
+ <div style={frame}>
20
+ <ProductCard
21
+ title="Extra long product title that wraps onto two lines and then clamps"
22
+ price={{ amount: 1290, currency: "USD" }}
23
+ media={[IMAGE]}
24
+ />
25
+ </div>
26
+ );
27
+
28
+ export const NoImage = () => (
29
+ <div style={frame}>
30
+ <ProductCard
31
+ title="Product without an image"
32
+ price={{ amount: 49, currency: "EUR" }}
33
+ />
34
+ </div>
35
+ );
36
+
37
+ export const NoPrice = () => (
38
+ <div style={frame}>
39
+ <ProductCard title="Price on request" media={[IMAGE]} />
40
+ </div>
41
+ );
42
+
43
+ export const OutOfStock = () => (
44
+ <div style={frame}>
45
+ <ProductCard
46
+ title="Sold out product"
47
+ price={{ amount: 89, currency: "EUR" }}
48
+ media={[IMAGE]}
49
+ outOfStock
50
+ />
51
+ </div>
52
+ );
53
+
54
+ export const Skeleton = () => (
55
+ <div style={frame}>
56
+ <ProductCardSkeleton />
57
+ </div>
58
+ );
@@ -0,0 +1,101 @@
1
+ import type { ReactNode } from "react";
2
+ import { useUser } from "skybridge/web";
3
+ import { text } from "../design/tokens";
4
+ import { useLabels } from "../i18n";
5
+ import { cx } from "../lib/cx";
6
+ import { formatPrice } from "../lib/format";
7
+ import type { Price } from "../types.js";
8
+ import * as styles from "./product-card.css";
9
+
10
+ type ProductCardProps = {
11
+ title: string;
12
+ price?: Price;
13
+ media?: string[]; // all images; the card decides which to show
14
+ outOfStock?: boolean;
15
+ };
16
+
17
+ // @todo: for boxed cards (border + background), set this to true and leave the
18
+ // carousel unframed. Pick one, not both.
19
+ const FRAMED = false;
20
+
21
+ /**
22
+ * A single product card: image, title, price, and an out-of-stock treatment.
23
+ * Maps a product's display fields to markup; the view passes them in.
24
+ */
25
+ export function ProductCard({
26
+ title,
27
+ price,
28
+ media,
29
+ outOfStock,
30
+ }: ProductCardProps) {
31
+ const { locale } = useUser();
32
+ const labels = useLabels();
33
+ // Show the first image. @todo: the rest of `media` is available here, e.g.
34
+ // to cross-fade to media[1] on hover.
35
+ const cover = media?.[0];
36
+ return (
37
+ <article className={styles.card({ framed: FRAMED })}>
38
+ <div className={styles.imageBox}>
39
+ {cover ? (
40
+ <img
41
+ className={cx(styles.image, outOfStock && styles.imageDimmed)}
42
+ src={cover}
43
+ alt={title}
44
+ loading="lazy"
45
+ draggable={false}
46
+ />
47
+ ) : (
48
+ <div className={styles.placeholder} />
49
+ )}
50
+ {outOfStock ? (
51
+ <span className={styles.oosBadge}>{labels.outOfStock}</span>
52
+ ) : null}
53
+ </div>
54
+
55
+ <div className={styles.body}>
56
+ <p
57
+ className={cx(
58
+ text({ style: "bodyS", weight: "medium" }),
59
+ styles.title,
60
+ )}
61
+ >
62
+ {title}
63
+ </p>
64
+ {price ? (
65
+ <p className={cx(text({ style: "bodyS" }), styles.price)}>
66
+ {formatPrice(price, locale)}
67
+ </p>
68
+ ) : null}
69
+ {/* @todo: extra fields. Render catalog-specific data here, e.g. from the
70
+ product's `attributes`: ratings, discounts, tags, badges. */}
71
+ </div>
72
+ </article>
73
+ );
74
+ }
75
+
76
+ /** Placeholder card shown while the tool resolves. Same footprint as the card
77
+ * so the layout does not jump when data arrives. */
78
+ export function ProductCardSkeleton() {
79
+ const titleLines: ReactNode[] = [];
80
+ for (let i = 0; i < styles.TITLE_LINES; i++) {
81
+ const isLast = i === styles.TITLE_LINES - 1;
82
+ titleLines.push(
83
+ <div
84
+ key={i}
85
+ className={cx(
86
+ styles.skeletonBox,
87
+ isLast ? styles.skeletonLineShort : styles.skeletonLine,
88
+ )}
89
+ />,
90
+ );
91
+ }
92
+ return (
93
+ <div className={styles.card({ framed: FRAMED })} aria-hidden="true">
94
+ <div className={cx(styles.skeletonBox, styles.skeletonImage)} />
95
+ <div className={styles.skeletonBody}>
96
+ {titleLines}
97
+ <div className={cx(styles.skeletonBox, styles.skeletonPrice)} />
98
+ </div>
99
+ </div>
100
+ );
101
+ }
@@ -0,0 +1,134 @@
1
+ import { globalStyle, style } from "@vanilla-extract/css";
2
+ import { recipe } from "@vanilla-extract/recipes";
3
+ import { colors, primitives } from "../design/tokens";
4
+
5
+ // Carousel tuning knobs. @todo: tune to your card design.
6
+ const gap = primitives.space["2xs"]; // gap between cards
7
+ // Cards visible at each width; the fractional part is the peek that signals the
8
+ // row scrolls. If you change a count, adjust the gap multiplier in its
9
+ // `--card-width` calc (full gaps visible = the whole-number part).
10
+ const CARDS_VISIBLE = 2.5;
11
+ const CARDS_VISIBLE_COMPACT = 1.5;
12
+ // Below this container width, switch to the compact count.
13
+ const COMPACT_MAX_WIDTH = "560px";
14
+
15
+ // Structural wrapper (kept as a plain class so the nav-reveal globalStyle below
16
+ // can target it). The recipe composes it as its base.
17
+ const carouselBase = style({
18
+ position: "relative",
19
+ // Size cards against the carousel width, not the iframe viewport.
20
+ containerType: "inline-size",
21
+ });
22
+
23
+ // `framed: true` frames the whole carousel; the default is flush (pair it with
24
+ // framed cards instead). Pick one of the two.
25
+ export const carousel = recipe({
26
+ base: carouselBase,
27
+ variants: {
28
+ framed: {
29
+ // @todo: tune the outer frame to your brand. Soften the shadow in dark
30
+ // mode if the strip reads as a hard box against the host.
31
+ true: {
32
+ // Pad top/bottom only; the leading/trailing inset lives on the track's
33
+ // own `framed` variant so it scrolls away. Cards bleed to the left/right
34
+ // border, and `overflow: hidden` masks them to the rounded corners, so
35
+ // a scrolled card disappears exactly at the frame edge.
36
+ paddingBlock: primitives.space.xs,
37
+ borderRadius: primitives.radius.l,
38
+ border: `${primitives.stroke.thin} solid ${colors.border.thin}`,
39
+ backgroundColor: colors.surface.extraLight,
40
+ boxShadow: "0 10px 20px -20px rgba(0, 0, 0, 0.18)",
41
+ overflow: "hidden",
42
+ },
43
+ false: {},
44
+ },
45
+ },
46
+ defaultVariants: { framed: false },
47
+ });
48
+
49
+ // Kept as a plain class so the scrollbar-hiding globalStyle below can target it.
50
+ // The recipe composes it as its base.
51
+ const trackBase = style({
52
+ display: "flex",
53
+ gap,
54
+ overflowX: "auto",
55
+ scrollSnapType: "x mandatory",
56
+ scrollBehavior: "smooth",
57
+ scrollbarWidth: "none",
58
+ vars: { "--card-width": `calc((100% - 2 * ${gap}) / ${CARDS_VISIBLE})` },
59
+ "@container": {
60
+ [`(max-width: ${COMPACT_MAX_WIDTH})`]: {
61
+ vars: {
62
+ "--card-width": `calc((100% - ${gap}) / ${CARDS_VISIBLE_COMPACT})`,
63
+ },
64
+ },
65
+ },
66
+ "@media": {
67
+ "(prefers-reduced-motion: reduce)": { scrollBehavior: "auto" },
68
+ },
69
+ });
70
+
71
+ globalStyle(`${trackBase}::-webkit-scrollbar`, { display: "none" });
72
+
73
+ // `framed: true` adds an inset on both ends. Padding on the scroll track (not on
74
+ // the frame) so it shows before the first card and after the last at rest, but
75
+ // scrolls away in between: a card scrolled past clips at the border, not at a
76
+ // fixed gutter. scroll-padding keeps mandatory snap from collapsing the inset.
77
+ export const track = recipe({
78
+ base: trackBase,
79
+ variants: {
80
+ framed: {
81
+ true: {
82
+ paddingInline: primitives.space.xs,
83
+ scrollPaddingInline: primitives.space.xs,
84
+ },
85
+ false: {},
86
+ },
87
+ // Skeleton state: lock the scroll, there is nothing to scroll to yet.
88
+ loading: {
89
+ true: { overflowX: "hidden" },
90
+ false: {},
91
+ },
92
+ },
93
+ defaultVariants: { framed: false, loading: false },
94
+ });
95
+
96
+ export const cell = style({
97
+ flex: "0 0 var(--card-width)",
98
+ scrollSnapAlign: "start",
99
+ });
100
+
101
+ // Prev/next buttons: desktop only. Hidden on touch, revealed on hover/focus,
102
+ // disabled at the scroll ends.
103
+ export const nav = style({
104
+ position: "absolute",
105
+ top: "50%",
106
+ transform: "translateY(-50%)",
107
+ display: "grid",
108
+ placeItems: "center",
109
+ width: "36px",
110
+ height: "36px",
111
+ padding: 0,
112
+ borderRadius: primitives.radius.full,
113
+ border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
114
+ backgroundColor: colors.surface.extraLight,
115
+ color: colors.content.intense,
116
+ cursor: "pointer",
117
+ opacity: 0,
118
+ transition: "opacity 150ms ease",
119
+ selectors: {
120
+ "&:disabled": { opacity: 0, pointerEvents: "none" },
121
+ },
122
+ "@media": {
123
+ "(hover: none)": { display: "none" },
124
+ },
125
+ });
126
+
127
+ export const navPrev = style({ left: primitives.space["3xs"] });
128
+ export const navNext = style({ right: primitives.space["3xs"] });
129
+
130
+ // Reveal the (enabled) buttons on hover or keyboard focus within the carousel.
131
+ globalStyle(
132
+ `${carouselBase}:hover ${nav}:not(:disabled), ${carouselBase}:focus-within ${nav}:not(:disabled)`,
133
+ { opacity: 1 },
134
+ );
@@ -0,0 +1,64 @@
1
+ import type { ReactNode } from "react";
2
+ import type { Price } from "../types.js";
3
+ import { ProductCard, ProductCardSkeleton } from "./product-card";
4
+ import { ProductCarousel } from "./product-carousel";
5
+
6
+ const IMAGE =
7
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Crect width='240' height='240' fill='%23e5e5e5'/%3E%3Ccircle cx='120' cy='120' r='70' fill='%23bcbcbc'/%3E%3C/svg%3E";
8
+
9
+ type Sample = { title: string; price: Price; outOfStock?: boolean };
10
+
11
+ const SAMPLE: Sample[] = [
12
+ { title: "Merino wool sweater", price: { amount: 129.9, currency: "EUR" } },
13
+ { title: "Oxford cotton shirt", price: { amount: 79, currency: "EUR" } },
14
+ { title: "Slim chino trousers", price: { amount: 89.5, currency: "EUR" } },
15
+ {
16
+ title: "Leather derby shoes",
17
+ price: { amount: 210, currency: "EUR" },
18
+ outOfStock: true,
19
+ },
20
+ { title: "Cashmere scarf", price: { amount: 145, currency: "EUR" } },
21
+ { title: "Quilted field jacket", price: { amount: 320, currency: "EUR" } },
22
+ ];
23
+
24
+ function sampleCards(): ReactNode[] {
25
+ const cards: ReactNode[] = [];
26
+ for (let i = 0; i < SAMPLE.length; i++) {
27
+ const item = SAMPLE[i];
28
+ cards.push(
29
+ <ProductCard
30
+ key={i}
31
+ title={item.title}
32
+ price={item.price}
33
+ media={[IMAGE]}
34
+ outOfStock={item.outOfStock}
35
+ />,
36
+ );
37
+ }
38
+ return cards;
39
+ }
40
+
41
+ export const Default = () => <ProductCarousel>{sampleCards()}</ProductCarousel>;
42
+
43
+ export const Loading = () => {
44
+ const skeletons: ReactNode[] = [];
45
+ for (let i = 0; i < 4; i++) {
46
+ skeletons.push(<ProductCardSkeleton key={i} />);
47
+ }
48
+ return <ProductCarousel loading>{skeletons}</ProductCarousel>;
49
+ };
50
+
51
+ export const FewItems = () => (
52
+ <ProductCarousel>
53
+ <ProductCard
54
+ title="Merino wool sweater"
55
+ price={{ amount: 129.9, currency: "EUR" }}
56
+ media={[IMAGE]}
57
+ />
58
+ <ProductCard
59
+ title="Oxford cotton shirt"
60
+ price={{ amount: 79, currency: "EUR" }}
61
+ media={[IMAGE]}
62
+ />
63
+ </ProductCarousel>
64
+ );
@@ -0,0 +1,195 @@
1
+ import {
2
+ Children,
3
+ type ReactNode,
4
+ useCallback,
5
+ useEffect,
6
+ useRef,
7
+ useState,
8
+ } from "react";
9
+ import { useLabels } from "../i18n";
10
+ import { cx } from "../lib/cx";
11
+ import * as styles from "./product-carousel.css";
12
+
13
+ // How long to wait after the last intersection change before reporting, so a
14
+ // fast scroll does not spam updates.
15
+ const VISIBILITY_DEBOUNCE_MS = 200;
16
+
17
+ // @todo: for boxed cards (border + background), set this to true and leave the
18
+ // carousel unframed. Pick one, not both.
19
+ const FRAMED = false;
20
+
21
+ function Chevron({ direction }: { direction: "left" | "right" }) {
22
+ const d = direction === "left" ? "M15 18l-6-6 6-6" : "M9 18l6-6-6-6";
23
+ return (
24
+ <svg
25
+ width="20"
26
+ height="20"
27
+ viewBox="0 0 24 24"
28
+ fill="none"
29
+ stroke="currentColor"
30
+ strokeWidth="2"
31
+ strokeLinecap="round"
32
+ strokeLinejoin="round"
33
+ aria-hidden="true"
34
+ >
35
+ <path d={d} />
36
+ </svg>
37
+ );
38
+ }
39
+
40
+ type ProductCarouselProps = {
41
+ children: ReactNode;
42
+ // Reports which child indices are at least half in view, in ascending order,
43
+ // debounced. Use it to narrate only what the user actually sees.
44
+ onVisibleChange?: (indices: number[]) => void;
45
+ // Skeleton state: locks the scroll and hides the nav buttons.
46
+ loading?: boolean;
47
+ };
48
+
49
+ /**
50
+ * Horizontal, scroll-snapping track of cards. Generic: it renders whatever
51
+ * children it is given, one per snap cell. Native scroll handles touch; the
52
+ * prev/next buttons are desktop-only affordances (see product-carousel.css.ts).
53
+ */
54
+ export function ProductCarousel({
55
+ children,
56
+ onVisibleChange,
57
+ loading = false,
58
+ }: ProductCarouselProps) {
59
+ const labels = useLabels();
60
+ const trackRef = useRef<HTMLElement>(null);
61
+ const [canScrollLeft, setCanScrollLeft] = useState(false);
62
+ const [canScrollRight, setCanScrollRight] = useState(false);
63
+
64
+ // Keep the latest callback in a ref so the observer effect does not
65
+ // re-subscribe when the parent passes a new function each render.
66
+ const onVisibleChangeRef = useRef(onVisibleChange);
67
+ onVisibleChangeRef.current = onVisibleChange;
68
+
69
+ const updateEdges = useCallback(() => {
70
+ const el = trackRef.current;
71
+ if (!el) {
72
+ return;
73
+ }
74
+ setCanScrollLeft(el.scrollLeft > 0);
75
+ setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
76
+ }, []);
77
+
78
+ useEffect(() => {
79
+ const el = trackRef.current;
80
+ if (!el) {
81
+ return;
82
+ }
83
+ updateEdges();
84
+ el.addEventListener("scroll", updateEdges, { passive: true });
85
+ const observer = new ResizeObserver(updateEdges);
86
+ observer.observe(el);
87
+ return () => {
88
+ el.removeEventListener("scroll", updateEdges);
89
+ observer.disconnect();
90
+ };
91
+ }, [updateEdges]);
92
+
93
+ // Track which cells are in view and report them (only when a consumer asks).
94
+ const childCount = Children.count(children);
95
+ // Re-subscribe when a consumer starts (or stops) passing onVisibleChange, even
96
+ // if the child count is unchanged; the callback itself is read via the ref.
97
+ const observeVisibility = onVisibleChange != null;
98
+ // biome-ignore lint/correctness/useExhaustiveDependencies: childCount and observeVisibility drive re-subscription; neither is read inside the effect.
99
+ useEffect(() => {
100
+ const el = trackRef.current;
101
+ if (!el || !observeVisibility) {
102
+ return;
103
+ }
104
+ const cells = Array.from(el.children);
105
+ const visible = new Set<number>();
106
+ let timer: number | undefined;
107
+ const emit = () => {
108
+ const indices = [...visible].sort((a, b) => a - b);
109
+ onVisibleChangeRef.current?.(indices);
110
+ };
111
+ const observer = new IntersectionObserver(
112
+ (entries) => {
113
+ for (const entry of entries) {
114
+ const index = cells.indexOf(entry.target);
115
+ if (index === -1) {
116
+ continue;
117
+ }
118
+ if (entry.isIntersecting) {
119
+ visible.add(index);
120
+ } else {
121
+ visible.delete(index);
122
+ }
123
+ }
124
+ window.clearTimeout(timer);
125
+ timer = window.setTimeout(emit, VISIBILITY_DEBOUNCE_MS);
126
+ },
127
+ { root: el, threshold: 0.5 },
128
+ );
129
+ for (const cell of cells) {
130
+ observer.observe(cell);
131
+ }
132
+ return () => {
133
+ window.clearTimeout(timer);
134
+ observer.disconnect();
135
+ };
136
+ }, [childCount, observeVisibility]);
137
+
138
+ const step = (direction: 1 | -1) => {
139
+ const el = trackRef.current;
140
+ if (!el) {
141
+ return;
142
+ }
143
+ const cell = el.firstElementChild as HTMLElement | null;
144
+ const gap = Number.parseFloat(getComputedStyle(el).columnGap) || 0;
145
+ const distance = cell ? cell.offsetWidth + gap : el.clientWidth;
146
+ // No `behavior`: inherits the track's CSS scroll-behavior (respects
147
+ // prefers-reduced-motion).
148
+ el.scrollBy({ left: direction * distance });
149
+ };
150
+
151
+ const cells: ReactNode[] = [];
152
+ const items = Children.toArray(children);
153
+ for (let i = 0; i < items.length; i++) {
154
+ cells.push(
155
+ <div key={i} className={styles.cell}>
156
+ {items[i]}
157
+ </div>,
158
+ );
159
+ }
160
+
161
+ return (
162
+ <div className={styles.carousel({ framed: FRAMED })}>
163
+ <section
164
+ ref={trackRef}
165
+ className={styles.track({ framed: FRAMED, loading })}
166
+ aria-roledescription={labels.carousel}
167
+ aria-label={labels.products}
168
+ >
169
+ {cells}
170
+ </section>
171
+ {loading ? null : (
172
+ <>
173
+ <button
174
+ type="button"
175
+ aria-label={labels.previous}
176
+ className={cx(styles.nav, styles.navPrev)}
177
+ disabled={!canScrollLeft}
178
+ onClick={() => step(-1)}
179
+ >
180
+ <Chevron direction="left" />
181
+ </button>
182
+ <button
183
+ type="button"
184
+ aria-label={labels.next}
185
+ className={cx(styles.nav, styles.navNext)}
186
+ disabled={!canScrollRight}
187
+ onClick={() => step(1)}
188
+ >
189
+ <Chevron direction="right" />
190
+ </button>
191
+ </>
192
+ )}
193
+ </div>
194
+ );
195
+ }
@@ -0,0 +1,22 @@
1
+ import { globalStyle, style } from "@vanilla-extract/css";
2
+ import { colors, primitives } from "../design/tokens";
3
+
4
+ /**
5
+ * Base frame for every view. Transparent so the widget blends into the host
6
+ * surface; it pins the design system's font + content color so descendants
7
+ * inherit from the DS, not from the host page (whose text color could be white
8
+ * on a dark host and make card text vanish).
9
+ */
10
+ export const viewFrame = style({
11
+ color: colors.content.intense,
12
+ fontFamily: primitives.font.family.primary,
13
+ fontSize: primitives.font.size.m,
14
+ lineHeight: primitives.font.lineHeight.normal,
15
+ WebkitFontSmoothing: "antialiased",
16
+ MozOsxFontSmoothing: "grayscale",
17
+ });
18
+
19
+ // Box-sizing reset scoped to the frame subtree.
20
+ globalStyle(`${viewFrame} *, ${viewFrame} *::before, ${viewFrame} *::after`, {
21
+ boxSizing: "border-box",
22
+ });
@@ -0,0 +1,27 @@
1
+ import type { HTMLAttributes } from "react";
2
+ import { useLayout } from "skybridge/web";
3
+ import { darkTheme, lightTheme } from "../design/tokens";
4
+ import { cx } from "../lib/cx";
5
+ import { viewFrame } from "./view-frame.css";
6
+
7
+ /**
8
+ * ViewFrame: the top-level wrapper every view mounts inside. It activates the
9
+ * design system by applying the active theme class (which sets the CSS
10
+ * variables the color contract declares) and paints the base surface + font +
11
+ * content color so descendants inherit from the DS instead of the host page.
12
+ *
13
+ * It follows the host theme via useLayout(). To lock the widget to one palette
14
+ * (e.g. always light), drop useLayout and hardcode the theme class.
15
+ *
16
+ * Keep view entry files thin: render <ViewFrame> at the root and let this carry
17
+ * the theme + base-style boilerplate.
18
+ */
19
+ type ViewFrameProps = HTMLAttributes<HTMLDivElement>;
20
+
21
+ export function ViewFrame({ className, ...rest }: ViewFrameProps) {
22
+ const { theme } = useLayout();
23
+ const themeClass = theme === "dark" ? darkTheme : lightTheme;
24
+
25
+ return <div {...rest} className={cx(themeClass, viewFrame, className)} />;
26
+ }
27
+ ViewFrame.displayName = "ViewFrame";
@@ -0,0 +1,12 @@
1
+ // App-wide tuning knobs, shared by the server prompt and the tools.
2
+
3
+ // @todo: minimum number of searches the model runs before rendering. Feeds the
4
+ // prompts to enforce multi-call exploration; raise for deeper results.
5
+ export const MIN_SEARCH_ITERATIONS = 2;
6
+
7
+ // @todo: the maximum number of products the carousel shows.
8
+ export const CAROUSEL_MAX_SIZE = 6;
9
+
10
+ // A "min-max" string (e.g. "3-6") derived from CAROUSEL_MAX_SIZE, interpolated
11
+ // into the prompts to tell the model how many products to curate toward.
12
+ export const CAROUSEL_RANGE = `${Math.ceil(CAROUSEL_MAX_SIZE / 2)}-${CAROUSEL_MAX_SIZE}`;
@@ -0,0 +1,39 @@
1
+ import { createThemeContract } from "@vanilla-extract/css";
2
+
3
+ /**
4
+ * Semantic color contract. Every field must be satisfied by both
5
+ * themes/light.css.ts and themes/dark.css.ts: TypeScript errors on drift.
6
+ *
7
+ * Adding a field here forces both themes to set a value. The compiler is the
8
+ * enforcement mechanism that keeps light and dark coherent.
9
+ *
10
+ * @todo: add or remove semantic slots to fit your UI. Keep names intent-based
11
+ * (surface.subtle, content.intense), not literal (grey100): the point is that
12
+ * components reference meaning, and the theme decides the hex.
13
+ */
14
+ export const colors = createThemeContract({
15
+ surface: {
16
+ extraLight: null,
17
+ light: null,
18
+ subtle: null,
19
+ intense: null,
20
+ },
21
+ content: {
22
+ intense: null,
23
+ subtle: null,
24
+ invertIntense: null,
25
+ invertSubtle: null,
26
+ },
27
+ border: {
28
+ thin: null,
29
+ subtle: null,
30
+ intense: null,
31
+ },
32
+ common: {
33
+ accent: null,
34
+ invertAccent: null,
35
+ highlight: null,
36
+ error: null,
37
+ success: null,
38
+ },
39
+ });
@@ -0,0 +1,15 @@
1
+ /* @todo: add your brand's @font-face rules here, then point
2
+ primitives.font.family.primary at the family name. Drop the font files in
3
+ public/fonts/ so they are served under /assets/fonts/.
4
+
5
+ The template ships with the system font stack, which needs no @font-face,
6
+ so this file is empty by default. Example:
7
+
8
+ @font-face {
9
+ font-family: "My Brand";
10
+ font-style: normal;
11
+ font-weight: 400;
12
+ font-display: block;
13
+ src: url("/assets/fonts/MyBrand-Regular.woff2") format("woff2");
14
+ }
15
+ */