@littlepress/renderer-web 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +20 -0
  3. package/README.md +229 -2
  4. package/dist/answer/answerComponents.d.ts +107 -0
  5. package/dist/answer/answerComponents.js +637 -0
  6. package/dist/answer/download.d.ts +63 -0
  7. package/dist/answer/download.js +109 -0
  8. package/dist/answer/downloadExport.d.ts +44 -0
  9. package/dist/answer/downloadExport.js +266 -0
  10. package/dist/answer/hostValues.d.ts +28 -0
  11. package/dist/answer/hostValues.js +379 -0
  12. package/dist/answer/mapComponent.d.ts +6 -0
  13. package/dist/answer/mapComponent.js +213 -0
  14. package/dist/answer/math.d.ts +57 -0
  15. package/dist/answer/math.js +168 -0
  16. package/dist/answer/surfaceStream.d.ts +51 -0
  17. package/dist/answer/surfaceStream.js +260 -0
  18. package/dist/answer/tableLayout.d.ts +42 -0
  19. package/dist/answer/tableLayout.js +89 -0
  20. package/dist/controls/ActionFeedback.d.ts +5 -0
  21. package/dist/controls/ActionFeedback.js +43 -0
  22. package/dist/controls/actionDispatch.d.ts +51 -0
  23. package/dist/controls/actionDispatch.js +211 -0
  24. package/dist/controls/actionOutcome.generated.d.ts +64 -0
  25. package/dist/controls/actionOutcome.generated.js +64 -0
  26. package/dist/controls/calculationPublisher.d.ts +14 -0
  27. package/dist/controls/calculationPublisher.js +6 -0
  28. package/dist/controls/calculations.d.ts +20 -0
  29. package/dist/controls/calculations.generated.d.ts +73 -0
  30. package/dist/controls/calculations.generated.js +85 -0
  31. package/dist/controls/calculations.js +208 -0
  32. package/dist/controls/controlState.d.ts +84 -0
  33. package/dist/controls/controlState.js +256 -0
  34. package/dist/controls/fieldMessages.d.ts +41 -0
  35. package/dist/controls/fieldMessages.js +81 -0
  36. package/dist/controls/fieldValidation.d.ts +19 -0
  37. package/dist/controls/fieldValidation.js +98 -0
  38. package/dist/controls/formComponents.d.ts +23 -0
  39. package/dist/controls/formComponents.js +738 -0
  40. package/dist/controls/formProgress.d.ts +63 -0
  41. package/dist/controls/formProgress.js +122 -0
  42. package/dist/controls/inputDrafts.d.ts +55 -0
  43. package/dist/controls/inputDrafts.js +183 -0
  44. package/dist/controls/inputValidation.d.ts +33 -0
  45. package/dist/controls/inputValidation.js +119 -0
  46. package/dist/controls/localWrites.d.ts +9 -0
  47. package/dist/controls/localWrites.js +29 -0
  48. package/dist/core/A2uiSurface.d.ts +13 -0
  49. package/dist/core/A2uiSurface.js +15 -0
  50. package/dist/core/AtlasIcon.d.ts +18 -0
  51. package/dist/core/AtlasIcon.js +22 -0
  52. package/dist/core/AtlasMedia.d.ts +22 -0
  53. package/dist/core/AtlasMedia.js +45 -0
  54. package/dist/core/Carousel.d.ts +61 -0
  55. package/dist/core/Carousel.js +183 -0
  56. package/dist/core/CoreMedia.d.ts +19 -0
  57. package/dist/core/CoreMedia.js +25 -0
  58. package/dist/core/FoundationA2uiSurface.d.ts +86 -0
  59. package/dist/core/FoundationA2uiSurface.js +440 -0
  60. package/dist/core/ImagePreview.d.ts +42 -0
  61. package/dist/core/ImagePreview.js +73 -0
  62. package/dist/core/LucideIcon.d.ts +19 -0
  63. package/dist/core/LucideIcon.js +42 -0
  64. package/dist/core/SurfaceLink.d.ts +35 -0
  65. package/dist/core/SurfaceLink.js +60 -0
  66. package/dist/core/appearance/aegis.d.ts +49 -0
  67. package/dist/core/appearance/aegis.js +34 -0
  68. package/dist/core/appearance/colour.d.ts +24 -0
  69. package/dist/core/appearance/colour.js +103 -0
  70. package/dist/core/appearance/css.d.ts +17 -0
  71. package/dist/core/appearance/css.js +153 -0
  72. package/dist/core/appearance/presets.generated.d.ts +4 -0
  73. package/dist/core/appearance/presets.generated.js +1184 -0
  74. package/dist/core/appearance/react.d.ts +29 -0
  75. package/dist/core/appearance/react.js +110 -0
  76. package/dist/core/appearance/resolve.d.ts +76 -0
  77. package/dist/core/appearance/resolve.js +127 -0
  78. package/dist/core/appearance/textScale.d.ts +11 -0
  79. package/dist/core/appearance/textScale.js +51 -0
  80. package/dist/core/appearance/theme.d.ts +138 -0
  81. package/dist/core/appearance/theme.js +274 -0
  82. package/dist/core/baseComponents.d.ts +53 -0
  83. package/dist/core/baseComponents.js +480 -0
  84. package/dist/core/binding.d.ts +46 -0
  85. package/dist/core/binding.js +118 -0
  86. package/dist/core/bundle.d.ts +23 -0
  87. package/dist/core/bundle.js +75 -0
  88. package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
  89. package/dist/core/catalog/catalog-index.generated.js +79 -0
  90. package/dist/core/catalog/icons.generated.d.ts +6 -0
  91. package/dist/core/catalog/icons.generated.js +1788 -0
  92. package/dist/core/catalog.d.ts +6 -0
  93. package/dist/core/catalog.generated.d.ts +50 -0
  94. package/dist/core/catalog.generated.js +2174 -0
  95. package/dist/core/catalog.js +8 -0
  96. package/dist/core/chartRows.d.ts +7 -0
  97. package/dist/core/chartRows.js +38 -0
  98. package/dist/core/component-support.d.ts +39 -0
  99. package/dist/core/component-support.js +127 -0
  100. package/dist/core/components/actions.d.ts +4 -0
  101. package/dist/core/components/actions.js +21 -0
  102. package/dist/core/components/cards.d.ts +9 -0
  103. package/dist/core/components/cards.js +227 -0
  104. package/dist/core/components/charts.d.ts +18 -0
  105. package/dist/core/components/charts.js +412 -0
  106. package/dist/core/components/comparisonTable.d.ts +50 -0
  107. package/dist/core/components/comparisonTable.js +89 -0
  108. package/dist/core/components/content.d.ts +13 -0
  109. package/dist/core/components/content.js +108 -0
  110. package/dist/core/components/seriesCharts.d.ts +531 -0
  111. package/dist/core/components/seriesCharts.js +1053 -0
  112. package/dist/core/components/stepFlow.d.ts +7 -0
  113. package/dist/core/components/stepFlow.js +13 -0
  114. package/dist/core/components.full.d.ts +10 -0
  115. package/dist/core/components.full.js +41 -0
  116. package/dist/core/context.d.ts +207 -0
  117. package/dist/core/context.js +172 -0
  118. package/dist/core/coverage.d.ts +30 -0
  119. package/dist/core/coverage.js +93 -0
  120. package/dist/core/foundation.d.ts +21 -0
  121. package/dist/core/foundation.js +22 -0
  122. package/dist/core/fullTheme.d.ts +5 -0
  123. package/dist/core/fullTheme.js +9 -0
  124. package/dist/core/iconNodes.generated.d.ts +7 -0
  125. package/dist/core/iconNodes.generated.js +5 -0
  126. package/dist/core/lucideIcons.d.ts +5 -0
  127. package/dist/core/lucideIcons.js +7 -0
  128. package/dist/core/messages.d.ts +111 -0
  129. package/dist/core/messages.js +134 -0
  130. package/dist/core/pointer.d.ts +17 -0
  131. package/dist/core/pointer.js +104 -0
  132. package/dist/core/registry.d.ts +12 -0
  133. package/dist/core/registry.js +114 -0
  134. package/dist/core/runtime.d.ts +8 -0
  135. package/dist/core/runtime.js +6 -0
  136. package/dist/core/state.d.ts +73 -0
  137. package/dist/core/state.js +274 -0
  138. package/dist/core/surfaceMotion.d.ts +5 -0
  139. package/dist/core/surfaceMotion.js +46 -0
  140. package/dist/core/theme.d.ts +5 -0
  141. package/dist/core/theme.js +7 -0
  142. package/dist/core/useSurfaceImage.d.ts +20 -0
  143. package/dist/core/useSurfaceImage.js +65 -0
  144. package/dist/graph/RelationshipGraph.d.ts +14 -0
  145. package/dist/graph/RelationshipGraph.js +206 -0
  146. package/dist/graph/model.d.ts +20 -0
  147. package/dist/graph/model.js +36 -0
  148. package/dist/graph/program/assets.d.ts +3 -0
  149. package/dist/graph/program/assets.js +3 -0
  150. package/dist/graph/program/bridge.d.ts +6 -0
  151. package/dist/graph/program/bridge.generated.d.ts +136 -0
  152. package/dist/graph/program/bridge.generated.js +1 -0
  153. package/dist/graph/program/bridge.js +24 -0
  154. package/dist/graph/program/bridge.schema.json +717 -0
  155. package/dist/graph/program/bridgeValidator.cjs +2 -0
  156. package/dist/graph/program/bridgeValidator.d.cts +4 -0
  157. package/dist/graph/program/runner.d.ts +1 -0
  158. package/dist/graph/program/runner.html +2193 -0
  159. package/dist/graph/program/runner.js +157 -0
  160. package/dist/graph/program/runtime-manifest.json +1 -0
  161. package/dist/graph/program/view.d.ts +11 -0
  162. package/dist/graph/program/view.js +210 -0
  163. package/dist/graph/program/worker.d.ts +1 -0
  164. package/dist/graph/program/worker.js +2186 -0
  165. package/dist/index.d.ts +20 -0
  166. package/dist/index.js +45 -0
  167. package/dist/internal/dsh.d.ts +4 -0
  168. package/dist/internal/dsh.js +3 -0
  169. package/dist/internal/relationship-graph.d.ts +4 -0
  170. package/dist/internal/relationship-graph.js +7202 -0
  171. package/dist/page/layoutComponents.d.ts +6 -0
  172. package/dist/page/layoutComponents.js +123 -0
  173. package/dist/page/layoutGeometry.d.ts +68 -0
  174. package/dist/page/layoutGeometry.js +174 -0
  175. package/dist/page/pageFormat.d.ts +34 -0
  176. package/dist/page/pageFormat.js +119 -0
  177. package/dist/page/printFit.d.ts +81 -0
  178. package/dist/page/printFit.js +338 -0
  179. package/dist/react/index.d.ts +5 -0
  180. package/dist/react/index.js +2 -0
  181. package/dist/report/locate.d.ts +42 -0
  182. package/dist/report/locate.js +34 -0
  183. package/dist/styles/renderer.css +4580 -0
  184. package/licenses/LUCIDE-LICENSE.txt +43 -0
  185. package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
  186. package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
  187. package/package.json +68 -3
@@ -0,0 +1,18 @@
1
+ import { type RendererIconName } from "./catalog/icons.generated.ts";
2
+ export type { RendererIconName } from "./catalog/icons.generated.ts";
3
+ export type AtlasIconSize = "sm" | "md" | "lg";
4
+ export type AtlasIconTone = "default" | "muted" | "accent" | "info" | "positive" | "warning" | "danger";
5
+ export declare function isRendererIconName(value: unknown): value is RendererIconName;
6
+ export type AtlasIconProps = {
7
+ name: unknown;
8
+ size?: AtlasIconSize;
9
+ tone?: AtlasIconTone;
10
+ label?: string;
11
+ decorative?: boolean;
12
+ className?: string;
13
+ };
14
+ /**
15
+ * Renders only markup generated from the vendored Atlas icon allowlist.
16
+ * Surface data can select a name, but can never inject SVG or path data.
17
+ */
18
+ export declare function AtlasIcon({ name, size, tone, label, decorative, className, }: AtlasIconProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { rendererIconMarkup, rendererIconNames, } from "./catalog/icons.generated.js";
3
+ const iconNames = new Set(rendererIconNames);
4
+ export function isRendererIconName(value) {
5
+ return typeof value === "string" && iconNames.has(value);
6
+ }
7
+ /**
8
+ * Renders only markup generated from the vendored Atlas icon allowlist.
9
+ * Surface data can select a name, but can never inject SVG or path data.
10
+ */
11
+ export function AtlasIcon({ name, size = "md", tone = "default", label, decorative = !label, className, }) {
12
+ if (!isRendererIconName(name)) {
13
+ if (decorative)
14
+ return null;
15
+ const fallbackLabel = label?.trim() || "Icon unavailable";
16
+ return (_jsx("span", { className: `lp-icon-slot lp-icon-fallback ${className ?? ""}`.trim(), "data-icon-fallback": "true", role: "img", "aria-label": fallbackLabel, children: fallbackLabel }));
17
+ }
18
+ const semantics = decorative
19
+ ? { "aria-hidden": true }
20
+ : { role: "img", "aria-label": label ?? name };
21
+ return (_jsx("span", { className: `lp-icon-slot ${className ?? ""}`.trim(), "data-icon": name, "data-size": size, "data-tone": tone, ...semantics, dangerouslySetInnerHTML: { __html: rendererIconMarkup[name] } }));
22
+ }
@@ -0,0 +1,22 @@
1
+ import type { RenderContext } from "./context.ts";
2
+ export type AtlasMediaValue = {
3
+ url?: string;
4
+ alt?: string;
5
+ caption?: string;
6
+ credit?: string;
7
+ };
8
+ /** v1.0 has no DynamicObject, so cover art arrives as an untyped DynamicValue. */
9
+ export declare function readMediaValue(value: unknown): AtlasMediaValue | null;
10
+ export type AtlasMediaProps = {
11
+ media: AtlasMediaValue;
12
+ /** Enum ratio steps only — Atlas forbids arbitrary aspect ratios. */
13
+ ratio?: "wide" | "feature" | "square" | "portrait";
14
+ className?: string;
15
+ context?: RenderContext;
16
+ };
17
+ /**
18
+ * Media frame with a built-in degraded state: preview sources are frequently
19
+ * placeholder URLs that 404, and a broken-image icon would misrepresent the
20
+ * surface. The Atlas gradient block stands in and keeps the alt text visible.
21
+ */
22
+ export declare function AtlasMedia({ media, ratio, className, context }: AtlasMediaProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { isRecord } from "./foundation.js";
3
+ import { surfaceIsStreaming } from "../controls/actionDispatch.js";
4
+ import { useSurfaceImage } from "./useSurfaceImage.js";
5
+ /** v1.0 has no DynamicObject, so cover art arrives as an untyped DynamicValue. */
6
+ export function readMediaValue(value) {
7
+ if (typeof value === "string")
8
+ return value.length > 0 ? { url: value } : null;
9
+ if (!isRecord(value))
10
+ return null;
11
+ const url = typeof value.url === "string" ? value.url : typeof value.src === "string" ? value.src : undefined;
12
+ const alt = typeof value.alt === "string" ? value.alt : undefined;
13
+ const caption = typeof value.caption === "string" ? value.caption : undefined;
14
+ const credit = typeof value.credit === "string" ? value.credit : undefined;
15
+ if (!url && !alt && !caption)
16
+ return null;
17
+ return { url, alt, caption, credit };
18
+ }
19
+ const placeholderTints = ["ph-a", "ph-b", "ph-c", "ph-d", "ph-e", "ph-f"];
20
+ /** Stable tint per asset so a re-render never reshuffles the page's colors. */
21
+ function pickTint(seed) {
22
+ let hash = 0;
23
+ for (let index = 0; index < seed.length; index += 1) {
24
+ hash = (hash * 31 + seed.charCodeAt(index)) % 997;
25
+ }
26
+ return placeholderTints[hash % placeholderTints.length];
27
+ }
28
+ const ratioValues = {
29
+ wide: "16 / 9",
30
+ feature: "3 / 2",
31
+ square: "1 / 1",
32
+ portrait: "4 / 5",
33
+ };
34
+ /**
35
+ * Media frame with a built-in degraded state: preview sources are frequently
36
+ * placeholder URLs that 404, and a broken-image icon would misrepresent the
37
+ * surface. The Atlas gradient block stands in and keeps the alt text visible.
38
+ */
39
+ export function AtlasMedia({ media, ratio = "feature", className, context }) {
40
+ const streaming = surfaceIsStreaming(context?.state ?? null);
41
+ const { src, onError } = useSurfaceImage(media.url, context, { streaming });
42
+ const seed = media.url ?? media.alt ?? "media";
43
+ const showImage = Boolean(src);
44
+ return (_jsx("div", { className: `lp-media ${showImage ? "" : pickTint(seed)} ${className ?? ""}`.replace(/\s+/g, " ").trim(), style: { aspectRatio: ratioValues[ratio] }, "data-print-part": "media", "data-print-policy": "crop", role: "img", "aria-label": media.alt ?? "Media", children: showImage && src ? (_jsx("img", { src: src, alt: media.alt ?? "", referrerPolicy: "no-referrer", onError: onError, loading: "lazy" })) : (_jsx("span", { className: "lp-media-alt lp-caption", children: media.alt ?? "Media placeholder" })) }));
45
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * `lp.pager` as a carousel: its items in one row that scrolls sideways and snaps to an item,
3
+ * with the next item peeking at the edge, the left and right arrow keys, and below the row an
4
+ * "i / n" count between previous and next buttons. Compose and SwiftUI draw the same layout
5
+ * from the same numbers (`ui-foundation/surface/contracts/fixtures/renderer/carousel.json` `expect`).
6
+ *
7
+ * Every item stays in the DOM and in reading order: a screen reader or a Tab into an item that
8
+ * is off screen scrolls it into view, so nothing is trapped behind a swipe. While the answer
9
+ * streams, the buttons and keys do nothing; the row still scrolls.
10
+ */
11
+ import { type ReactNode } from "react";
12
+ /** The words every renderer uses for a carousel (English, as the other built-in prompts). */
13
+ export declare const carouselCopy: {
14
+ readonly roleDescription: "carousel";
15
+ readonly label: "Carousel";
16
+ readonly previous: "Previous item";
17
+ readonly next: "Next item";
18
+ readonly item: (index: number, count: number) => string;
19
+ };
20
+ /** `gap` tokens in CSS pixels, as `lp.stack` spaces its children. */
21
+ export declare const carouselGaps: {
22
+ readonly xs: 6;
23
+ readonly sm: 10;
24
+ readonly md: 16;
25
+ readonly lg: 24;
26
+ };
27
+ export type CarouselGap = keyof typeof carouselGaps;
28
+ /** No item is narrower than this; a narrow carousel shows fewer items side by side. */
29
+ export declare const carouselMinItemWidth = 160;
30
+ /** The share of the width the next item peeks into when more items follow. */
31
+ export declare const carouselPeek = 0.1;
32
+ export declare function carouselGap(value: unknown): CarouselGap;
33
+ export declare function carouselVisibleItems(value: unknown): 1 | 2 | 3;
34
+ /**
35
+ * How many items fit side by side in `width`, and how wide each is. With more items than fit,
36
+ * the row leaves `carouselPeek` of the width for the next one; with all of them in view, they
37
+ * share the width. An item first takes `carouselMinItemWidth` (or the whole width, when the
38
+ * carousel is narrower): the next item peeks only into the room beyond that.
39
+ */
40
+ export declare function carouselLayout(width: number, gap: number, visibleItems: number, count: number): {
41
+ perView: number;
42
+ itemWidth: number;
43
+ peeking: boolean;
44
+ };
45
+ /** The first item in view at `scrollLeft`, given one item and its gap take `step`. */
46
+ export declare function carouselIndex(scrollLeft: number, maxScroll: number, step: number, count: number, perView: number): number;
47
+ /** Which item a key moves to from `index`, or null when the key is not one the carousel takes. */
48
+ export declare function carouselKeyTarget(key: string, index: number, count: number): number | null;
49
+ export type CarouselProps = {
50
+ items: {
51
+ key: string;
52
+ node: ReactNode;
53
+ }[];
54
+ label?: string;
55
+ gap?: unknown;
56
+ visibleItems?: unknown;
57
+ showArrows?: unknown;
58
+ /** While the answer streams, the buttons and keys do nothing. */
59
+ locked: boolean;
60
+ };
61
+ export declare function Carousel({ items, label, gap, visibleItems, showArrows, locked }: CarouselProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,183 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * `lp.pager` as a carousel: its items in one row that scrolls sideways and snaps to an item,
4
+ * with the next item peeking at the edge, the left and right arrow keys, and below the row an
5
+ * "i / n" count between previous and next buttons. Compose and SwiftUI draw the same layout
6
+ * from the same numbers (`ui-foundation/surface/contracts/fixtures/renderer/carousel.json` `expect`).
7
+ *
8
+ * Every item stays in the DOM and in reading order: a screen reader or a Tab into an item that
9
+ * is off screen scrolls it into view, so nothing is trapped behind a swipe. While the answer
10
+ * streams, the buttons and keys do nothing; the row still scrolls.
11
+ */
12
+ import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
13
+ import { LucideIcon } from "./LucideIcon.js";
14
+ /** The words every renderer uses for a carousel (English, as the other built-in prompts). */
15
+ export const carouselCopy = {
16
+ roleDescription: "carousel",
17
+ label: "Carousel",
18
+ previous: "Previous item",
19
+ next: "Next item",
20
+ item: (index, count) => `Item ${index} of ${count}`,
21
+ };
22
+ /** `gap` tokens in CSS pixels, as `lp.stack` spaces its children. */
23
+ export const carouselGaps = { xs: 6, sm: 10, md: 16, lg: 24 };
24
+ /** No item is narrower than this; a narrow carousel shows fewer items side by side. */
25
+ export const carouselMinItemWidth = 160;
26
+ /** The share of the width the next item peeks into when more items follow. */
27
+ export const carouselPeek = 0.1;
28
+ export function carouselGap(value) {
29
+ return typeof value === "string" && value in carouselGaps ? value : "sm";
30
+ }
31
+ export function carouselVisibleItems(value) {
32
+ return value === 2 || value === 3 ? value : 1;
33
+ }
34
+ /**
35
+ * How many items fit side by side in `width`, and how wide each is. With more items than fit,
36
+ * the row leaves `carouselPeek` of the width for the next one; with all of them in view, they
37
+ * share the width. An item first takes `carouselMinItemWidth` (or the whole width, when the
38
+ * carousel is narrower): the next item peeks only into the room beyond that.
39
+ */
40
+ export function carouselLayout(width, gap, visibleItems, count) {
41
+ const wanted = Math.max(1, Math.min(visibleItems, count));
42
+ const fits = (perView) => {
43
+ const peeking = count > perView;
44
+ const room = peeking ? width * (1 - carouselPeek) - gap * perView : width - gap * (perView - 1);
45
+ return Math.max(0, room / perView);
46
+ };
47
+ let perView = wanted;
48
+ while (perView > 1 && fits(perView) < carouselMinItemWidth)
49
+ perView -= 1;
50
+ const itemWidth = perView === 1 ? Math.max(fits(1), Math.min(carouselMinItemWidth, width)) : fits(perView);
51
+ return { perView, itemWidth, peeking: count > perView };
52
+ }
53
+ /** The first item in view at `scrollLeft`, given one item and its gap take `step`. */
54
+ export function carouselIndex(scrollLeft, maxScroll, step, count, perView) {
55
+ if (count <= 0 || step <= 0)
56
+ return 0;
57
+ // At the end of the row the last items are in view, even where they cannot snap to the start.
58
+ if (maxScroll > 0 && scrollLeft >= maxScroll - 1)
59
+ return Math.max(0, Math.min(count - 1, Math.max(Math.round(scrollLeft / step), count - perView)));
60
+ return Math.max(0, Math.min(count - 1, Math.round(scrollLeft / step)));
61
+ }
62
+ /** Which item a key moves to from `index`, or null when the key is not one the carousel takes. */
63
+ export function carouselKeyTarget(key, index, count) {
64
+ if (key === "ArrowRight")
65
+ return Math.min(count - 1, index + 1);
66
+ if (key === "ArrowLeft")
67
+ return Math.max(0, index - 1);
68
+ if (key === "Home")
69
+ return 0;
70
+ if (key === "End")
71
+ return count - 1;
72
+ return null;
73
+ }
74
+ /** Keys inside these stay theirs: a text field or a slider moves its own caret or value. */
75
+ function ownsArrowKeys(target) {
76
+ if (!(target instanceof HTMLElement))
77
+ return false;
78
+ if (target.isContentEditable)
79
+ return true;
80
+ const tag = target.tagName;
81
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT")
82
+ return true;
83
+ const role = target.getAttribute("role");
84
+ return role === "slider" || role === "tab" || role === "radio" || role === "listbox" || role === "combobox";
85
+ }
86
+ function reducedMotion(element) {
87
+ if (element.closest('[data-reduced-motion="true"]'))
88
+ return true;
89
+ return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
90
+ }
91
+ export function Carousel({ items, label, gap, visibleItems, showArrows, locked }) {
92
+ const trackId = useId();
93
+ const trackRef = useRef(null);
94
+ const count = items.length;
95
+ const gapToken = carouselGap(gap);
96
+ const gapPx = carouselGaps[gapToken];
97
+ const wanted = carouselVisibleItems(visibleItems);
98
+ const [width, setWidth] = useState(0);
99
+ const [index, setIndex] = useState(0);
100
+ const [atEnd, setAtEnd] = useState(count <= 1);
101
+ const [announcement, setAnnouncement] = useState("");
102
+ // A move the buttons or keys asked for is announced once the row stops, from where it stopped.
103
+ const announcing = useRef(false);
104
+ const settle = useRef(null);
105
+ const layout = carouselLayout(width, gapPx, wanted, count);
106
+ // With every item in view nothing scrolls: no count, no arrows, nothing to announce.
107
+ const scrolls = layout.peeking;
108
+ const arrows = showArrows !== false && scrolls;
109
+ const measure = useCallback(() => {
110
+ const track = trackRef.current;
111
+ if (!track)
112
+ return;
113
+ setWidth(track.clientWidth);
114
+ const step = layout.itemWidth + gapPx;
115
+ const maxScroll = track.scrollWidth - track.clientWidth;
116
+ const current = carouselIndex(track.scrollLeft, maxScroll, step, count, layout.perView);
117
+ setIndex(current);
118
+ setAtEnd(maxScroll <= 1 || track.scrollLeft >= maxScroll - 1);
119
+ if (announcing.current) {
120
+ if (settle.current)
121
+ clearTimeout(settle.current);
122
+ settle.current = setTimeout(() => {
123
+ announcing.current = false;
124
+ setAnnouncement(carouselCopy.item(current + 1, count));
125
+ }, 150);
126
+ }
127
+ }, [count, gapPx, layout.itemWidth, layout.perView]);
128
+ useEffect(() => () => {
129
+ if (settle.current)
130
+ clearTimeout(settle.current);
131
+ }, []);
132
+ useLayoutEffect(() => {
133
+ const track = trackRef.current;
134
+ if (!track)
135
+ return;
136
+ measure();
137
+ if (typeof ResizeObserver !== "function")
138
+ return;
139
+ const observer = new ResizeObserver(() => measure());
140
+ observer.observe(track);
141
+ return () => observer.disconnect();
142
+ }, [measure]);
143
+ useEffect(() => {
144
+ if (!announcement)
145
+ return;
146
+ const timer = setTimeout(() => setAnnouncement(""), 1500);
147
+ return () => clearTimeout(timer);
148
+ }, [announcement]);
149
+ const go = (target) => {
150
+ const track = trackRef.current;
151
+ if (!track || locked || count === 0)
152
+ return;
153
+ const next = Math.max(0, Math.min(count - 1, target));
154
+ const item = track.children[next];
155
+ // The track is the items' offset parent (`position: relative`), so this is the item's place in the row.
156
+ const maxScroll = Math.max(0, track.scrollWidth - track.clientWidth);
157
+ const left = Math.min(maxScroll, item ? item.offsetLeft : next * (layout.itemWidth + gapPx));
158
+ // Already there (the end of a row that shows its last items, or a row that does not scroll):
159
+ // nothing moves, so nothing is announced.
160
+ if (Math.abs(left - track.scrollLeft) < 1)
161
+ return;
162
+ announcing.current = true;
163
+ setAnnouncement("");
164
+ track.scrollTo({ left, behavior: reducedMotion(track) ? "auto" : "smooth" });
165
+ };
166
+ const onKeyDown = (event) => {
167
+ if (!scrolls || event.altKey || event.ctrlKey || event.metaKey || ownsArrowKeys(event.target))
168
+ return;
169
+ const target = carouselKeyTarget(event.key, index, count);
170
+ if (target === null)
171
+ return;
172
+ // The row would otherwise scroll by the browser's own step, between two items.
173
+ event.preventDefault();
174
+ go(target);
175
+ };
176
+ const itemStyle = width > 0 ? { width: `${layout.itemWidth}px` } : undefined;
177
+ return (_jsxs("section", { className: "lp-carousel", "aria-roledescription": carouselCopy.roleDescription, "aria-label": label || carouselCopy.label, "data-visible-items": wanted, "data-gap": gapToken, "data-peeking": layout.peeking ? "true" : undefined, "data-locked": locked ? "true" : undefined, children: [_jsx("div", { className: "lp-carousel-viewport", children: _jsx("div", { id: trackId, ref: trackRef, className: "lp-carousel-track",
178
+ // A scrolling row is reachable by keyboard even when no item holds a control.
179
+ tabIndex: scrolls ? 0 : undefined, onScroll: measure, onKeyDown: onKeyDown, style: { gap: `${gapPx}px`, ["--lp-carousel-per-view"]: String(layout.perView) }, children: items.map((item, position) => (_jsx("div", { className: "lp-carousel-item", role: "group", "aria-label": carouselCopy.item(position + 1, count), style: itemStyle, children: item.node }, item.key))) }) }), scrolls ? (
180
+ // Below the row, never over it, so the buttons cover no item at any width (as Compose and
181
+ // SwiftUI draw them).
182
+ _jsxs("div", { className: "lp-carousel-controls", children: [arrows ? (_jsx("button", { type: "button", className: "lp-carousel-arrow", "data-direction": "previous", "aria-label": carouselCopy.previous, "aria-controls": trackId, disabled: locked || index === 0, onClick: () => go(index - 1), children: _jsx("span", { className: "lp-carousel-arrow-disc", children: _jsx(LucideIcon, { name: "chevron-left", size: "sm" }) }) })) : null, _jsxs("p", { className: "lp-carousel-count lp-caption", "aria-hidden": "true", children: [index + 1, " / ", count] }), arrows ? (_jsx("button", { type: "button", className: "lp-carousel-arrow", "data-direction": "next", "aria-label": carouselCopy.next, "aria-controls": trackId, disabled: locked || atEnd, onClick: () => go(index + 1), children: _jsx("span", { className: "lp-carousel-arrow-disc", children: _jsx(LucideIcon, { name: "chevron-right", size: "sm" }) }) })) : null] })) : null, _jsx("span", { className: "lp-visually-hidden", "aria-live": "polite", "aria-atomic": "true", children: announcement })] }));
183
+ }
@@ -0,0 +1,19 @@
1
+ import type { RenderContext } from "./context.ts";
2
+ export type CoreMediaValue = {
3
+ url?: string;
4
+ alt?: string;
5
+ caption?: string;
6
+ credit?: string;
7
+ };
8
+ export declare function readMediaValue(value: unknown): CoreMediaValue | null;
9
+ export type CoreMediaProps = {
10
+ media: CoreMediaValue;
11
+ ratio?: "wide" | "feature" | "square" | "portrait";
12
+ className?: string;
13
+ context?: RenderContext;
14
+ streaming?: boolean;
15
+ /** Optional pre-resolved image src shared with a parent (e.g. `ImagePreview`). */
16
+ resolvedSrc?: string | null;
17
+ onImageError?: () => void;
18
+ };
19
+ export declare function CoreMedia({ media, ratio, className, context, streaming, resolvedSrc, onImageError }: CoreMediaProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { isRecord } from "./messages.js";
3
+ import { useSurfaceImage } from "./useSurfaceImage.js";
4
+ export function readMediaValue(value) {
5
+ if (typeof value === "string")
6
+ return value.length > 0 ? { url: value } : null;
7
+ if (!isRecord(value))
8
+ return null;
9
+ const url = typeof value.url === "string" ? value.url : typeof value.src === "string" ? value.src : undefined;
10
+ const alt = typeof value.alt === "string" ? value.alt : undefined;
11
+ const caption = typeof value.caption === "string" ? value.caption : undefined;
12
+ const credit = typeof value.credit === "string" ? value.credit : undefined;
13
+ return url || alt || caption ? { url, alt, caption, credit } : null;
14
+ }
15
+ const ratios = { wide: "16 / 9", feature: "3 / 2", square: "1 / 1", portrait: "4 / 5" };
16
+ export function CoreMedia({ media, ratio = "feature", className, context, streaming, resolvedSrc, onImageError }) {
17
+ const internal = useSurfaceImage(resolvedSrc === undefined ? media.url : undefined, context, { streaming });
18
+ const src = resolvedSrc === undefined ? internal.src : resolvedSrc;
19
+ const handleError = resolvedSrc === undefined ? internal.onError : onImageError;
20
+ if (src) {
21
+ return (_jsx("div", { className: `lp-media ${className ?? ""}`.trim(), style: { aspectRatio: ratios[ratio] }, "data-print-part": "media", "data-print-policy": "crop", children: _jsx("img", { src: src, alt: media.alt ?? "", referrerPolicy: "no-referrer", onError: handleError, loading: "lazy" }) }));
22
+ }
23
+ const label = media.alt ?? media.caption ?? "Media unavailable";
24
+ return (_jsx("div", { className: `lp-media lp-media-fallback ${className ?? ""}`.trim(), style: { aspectRatio: ratios[ratio] }, role: "img", "aria-label": label, children: _jsx("span", { className: "lp-media-alt lp-caption", children: label }) }));
25
+ }
@@ -0,0 +1,86 @@
1
+ import type { ReactNode } from "react";
2
+ import { type RendererMode } from "./theme.ts";
3
+ import { type BindingContext, type ValueFunction } from "./binding.ts";
4
+ import type { A2uiSurfaceState } from "./state.ts";
5
+ import type { SurfaceStream } from "../answer/surfaceStream.ts";
6
+ import { type PageFormatSpec } from "../page/pageFormat.ts";
7
+ import { type A2uiSurfaceHandle } from "../report/locate.ts";
8
+ import { type A2uiActionHandler } from "../controls/actionDispatch.ts";
9
+ import type { A2uiInputChangeHandler, AegisBlockRenderer, LayoutRenderMode, MapAdapterRenderer, RendererRegistry, SaveFileHandler, SurfaceImageLoader } from "./context.ts";
10
+ export type A2uiSurfaceProps = {
11
+ /** The folded surface to draw. Give this or `stream`. */
12
+ state?: A2uiSurfaceState | null;
13
+ /**
14
+ * A surface the Host keeps current with a snapshot and then only updates (`createSurfaceStream`).
15
+ * Draws each applied revision and nothing before the first snapshot; `state` is then unused.
16
+ */
17
+ stream?: SurfaceStream;
18
+ /**
19
+ * Draw this surface with a preset theme (`themePresets`), overriding the surrounding
20
+ * `LittlePressAppearance`; used by the playground picker. Unknown names are ignored.
21
+ */
22
+ pack?: string;
23
+ /** The preset names `pack` may choose from in this composition root. */
24
+ stylePacks?: readonly string[];
25
+ /** Overrides the surrounding colour mode for this surface. `system` follows prefers-color-scheme. */
26
+ mode?: RendererMode;
27
+ /**
28
+ * How the N2 layout containers materialize: "print" is the fixed typeset
29
+ * page, "flow" one scrolling column. Defaults to what the compiled page
30
+ * says about itself (`pageScrollable: false` -> print).
31
+ */
32
+ layout?: LayoutRenderMode;
33
+ /** Host chrome override. The compiled hint is used when this is omitted. */
34
+ frame?: "card" | "none";
35
+ /** Host override for authored section rules. */
36
+ sectionDividers?: "none" | "subtle" | "strong";
37
+ /** Host override for separators between repeated rows. */
38
+ itemDividers?: "none" | "inset" | "full";
39
+ /** Host routing, execution and optional original-operation queries. */
40
+ actionHandler?: A2uiActionHandler;
41
+ /** Receives controlled field changes; final submission uses actionHandler. */
42
+ onInputChange?: A2uiInputChangeHandler;
43
+ valueFunctions?: Readonly<Record<string, ValueFunction>>;
44
+ /** Optional component extension. Foundation remains the default registry. */
45
+ registry?: RendererRegistry;
46
+ /** Optional Host renderer for inline `LPAegisBlock_Default` blocks (keeps Aegis optional). */
47
+ renderAegisBlock?: AegisBlockRenderer;
48
+ /**
49
+ * Optional Host save for `LPDownload_Default` buttons (a native share sheet, cloud storage).
50
+ * Without it the browser downloads the file through a Blob URL.
51
+ */
52
+ saveFile?: SaveFileHandler;
53
+ /** Host-supplied preloaded images keyed by exact HTTPS URL (used in both live and replay). */
54
+ images?: Readonly<Record<string, string>>;
55
+ /** Optional Host image loader invoked only after streaming completes; omitted in replay. */
56
+ imageLoader?: SurfaceImageLoader;
57
+ /** Optional Host map adapter for `LPMap_Default` blocks (SDK binds no map vendor or API key). */
58
+ renderMap?: MapAdapterRenderer;
59
+ /** Optional extension-owned presentation metadata keyed by component name. */
60
+ componentMetadata?: Readonly<Record<string, {
61
+ printMode?: string;
62
+ }>>;
63
+ className?: string;
64
+ };
65
+ export declare function collectAdmittedAegisBlockIds(state: A2uiSurfaceState | null, binding: BindingContext, valueFunctions?: Readonly<Record<string, ValueFunction>>): Set<string>;
66
+ /**
67
+ * The A2UI v1.0 surface renderer.
68
+ *
69
+ * Takes the folded state (not raw messages) so the caller owns the message
70
+ * history and partial updates re-render exactly the branch that changed.
71
+ * A `ref` receives an `A2uiSurfaceHandle` for moving the reader to a heading.
72
+ */
73
+ export declare const A2uiSurface: import("react").ForwardRefExoticComponent<A2uiSurfaceProps & import("react").RefAttributes<A2uiSurfaceHandle>>;
74
+ export type A2uiPageFrameProps = {
75
+ pageFormat: PageFormatSpec | null;
76
+ children: ReactNode;
77
+ /** Set when the frame shows a trim the current surface was not compiled for. */
78
+ isUncompiledTrim?: boolean;
79
+ };
80
+ /**
81
+ * Fixed-ratio page frame. A scrollable format keeps one scrolling surface at
82
+ * the trim aspect ratio; a non-scrollable format (every print trim) clips at
83
+ * the page edge and shows an overflow badge instead — a fixed page that
84
+ * pretends to scroll is lying about what fits.
85
+ */
86
+ export declare function A2uiPageFrame({ pageFormat, children, isUncompiledTrim }: A2uiPageFrameProps): import("react/jsx-runtime").JSX.Element;