@farcaster/snap 1.5.1 → 2.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 (156) hide show
  1. package/dist/constants.d.ts +0 -107
  2. package/dist/constants.js +0 -148
  3. package/dist/dataStore.d.ts +12 -0
  4. package/dist/dataStore.js +35 -0
  5. package/dist/index.d.ts +6 -3
  6. package/dist/index.js +5 -3
  7. package/dist/middleware.d.ts +3 -0
  8. package/dist/middleware.js +3 -0
  9. package/dist/react/accent-context.d.ts +6 -0
  10. package/dist/react/accent-context.js +10 -0
  11. package/dist/react/catalog-renderer.d.ts +5 -0
  12. package/dist/react/catalog-renderer.js +37 -0
  13. package/dist/react/components/action-button.d.ts +6 -0
  14. package/dist/react/components/action-button.js +22 -0
  15. package/dist/react/components/badge.d.ts +5 -0
  16. package/dist/react/components/badge.js +18 -0
  17. package/dist/react/components/icon.d.ts +7 -0
  18. package/dist/react/components/icon.js +60 -0
  19. package/dist/react/components/image.d.ts +5 -0
  20. package/dist/react/components/image.js +15 -0
  21. package/dist/react/components/input.d.ts +5 -0
  22. package/dist/react/components/input.js +18 -0
  23. package/dist/react/components/item-group.d.ts +7 -0
  24. package/dist/react/components/item-group.js +17 -0
  25. package/dist/react/components/item.d.ts +7 -0
  26. package/dist/react/components/item.js +9 -0
  27. package/dist/react/components/progress.d.ts +5 -0
  28. package/dist/react/components/progress.js +11 -0
  29. package/dist/react/components/separator.d.ts +5 -0
  30. package/dist/react/components/separator.js +7 -0
  31. package/dist/react/components/slider.d.ts +5 -0
  32. package/dist/react/components/slider.js +21 -0
  33. package/dist/react/components/stack.d.ts +7 -0
  34. package/dist/react/components/stack.js +32 -0
  35. package/dist/react/components/switch.d.ts +5 -0
  36. package/dist/react/components/switch.js +23 -0
  37. package/dist/react/components/text.d.ts +5 -0
  38. package/dist/react/components/text.js +25 -0
  39. package/dist/react/components/toggle-group.d.ts +5 -0
  40. package/dist/react/components/toggle-group.js +52 -0
  41. package/dist/react/hooks/use-snap-accent.d.ts +13 -0
  42. package/dist/react/hooks/use-snap-accent.js +32 -0
  43. package/dist/react/index.d.ts +47 -0
  44. package/dist/react/index.js +191 -0
  45. package/dist/react/lib/preview-primary-css.d.ts +6 -0
  46. package/dist/react/lib/preview-primary-css.js +43 -0
  47. package/dist/react/lib/resolve-palette-hex.d.ts +2 -0
  48. package/dist/react/lib/resolve-palette-hex.js +10 -0
  49. package/dist/schemas.d.ts +14 -1629
  50. package/dist/schemas.js +14 -526
  51. package/dist/ui/badge.d.ts +52 -0
  52. package/dist/ui/badge.js +9 -0
  53. package/dist/ui/button.d.ts +42 -28
  54. package/dist/ui/button.js +7 -9
  55. package/dist/ui/catalog.d.ts +280 -155
  56. package/dist/ui/catalog.js +102 -83
  57. package/dist/ui/icon.d.ts +56 -0
  58. package/dist/ui/icon.js +51 -0
  59. package/dist/ui/image.d.ts +1 -0
  60. package/dist/ui/image.js +2 -2
  61. package/dist/ui/index.d.ts +20 -22
  62. package/dist/ui/index.js +10 -11
  63. package/dist/ui/input.d.ts +17 -0
  64. package/dist/ui/input.js +13 -0
  65. package/dist/ui/item-group.d.ts +12 -0
  66. package/dist/ui/item-group.js +7 -0
  67. package/dist/ui/item.d.ts +14 -0
  68. package/dist/ui/item.js +9 -0
  69. package/dist/ui/progress.d.ts +1 -11
  70. package/dist/ui/progress.js +21 -4
  71. package/dist/ui/schema.js +3 -3
  72. package/dist/ui/separator.d.ts +9 -0
  73. package/dist/ui/separator.js +5 -0
  74. package/dist/ui/slider.d.ts +4 -3
  75. package/dist/ui/slider.js +34 -5
  76. package/dist/ui/stack.d.ts +22 -1
  77. package/dist/ui/stack.js +8 -1
  78. package/dist/ui/switch.d.ts +8 -0
  79. package/dist/ui/switch.js +7 -0
  80. package/dist/ui/text.d.ts +15 -7
  81. package/dist/ui/text.js +8 -4
  82. package/dist/ui/toggle-group.d.ts +23 -0
  83. package/dist/ui/toggle-group.js +19 -0
  84. package/dist/validator.d.ts +5 -1
  85. package/dist/validator.js +6 -136
  86. package/package.json +72 -52
  87. package/src/constants.ts +0 -179
  88. package/src/dataStore.ts +62 -0
  89. package/src/index.ts +11 -20
  90. package/src/middleware.ts +7 -0
  91. package/src/react/accent-context.tsx +29 -0
  92. package/src/react/catalog-renderer.tsx +39 -0
  93. package/src/react/components/action-button.tsx +48 -0
  94. package/src/react/components/badge.tsx +37 -0
  95. package/src/react/components/icon.tsx +115 -0
  96. package/src/react/components/image.tsx +33 -0
  97. package/src/react/components/input.tsx +36 -0
  98. package/src/react/components/item-group.tsx +43 -0
  99. package/src/react/components/item.tsx +33 -0
  100. package/src/react/components/progress.tsx +29 -0
  101. package/src/react/components/separator.tsx +14 -0
  102. package/src/react/components/slider.tsx +43 -0
  103. package/src/react/components/stack.tsx +55 -0
  104. package/src/react/components/switch.tsx +46 -0
  105. package/src/react/components/text.tsx +43 -0
  106. package/src/react/components/toggle-group.tsx +85 -0
  107. package/src/react/hooks/use-snap-accent.ts +45 -0
  108. package/src/react/index.tsx +321 -0
  109. package/src/react/lib/preview-primary-css.ts +57 -0
  110. package/src/react/lib/resolve-palette-hex.ts +20 -0
  111. package/src/schemas.ts +18 -644
  112. package/src/ui/badge.ts +13 -0
  113. package/src/ui/button.ts +9 -12
  114. package/src/ui/catalog.ts +106 -86
  115. package/src/ui/icon.ts +56 -0
  116. package/src/ui/image.ts +3 -2
  117. package/src/ui/index.ts +26 -29
  118. package/src/ui/input.ts +17 -0
  119. package/src/ui/item-group.ts +11 -0
  120. package/src/ui/item.ts +13 -0
  121. package/src/ui/progress.ts +25 -7
  122. package/src/ui/schema.ts +3 -3
  123. package/src/ui/separator.ts +9 -0
  124. package/src/ui/slider.ts +40 -10
  125. package/src/ui/stack.ts +9 -1
  126. package/src/ui/switch.ts +11 -0
  127. package/src/ui/text.ts +9 -4
  128. package/src/ui/toggle-group.ts +23 -0
  129. package/src/validator.ts +6 -176
  130. package/dist/ui/bar-chart.d.ts +0 -30
  131. package/dist/ui/bar-chart.js +0 -15
  132. package/dist/ui/button-group.d.ts +0 -19
  133. package/dist/ui/button-group.js +0 -18
  134. package/dist/ui/divider.d.ts +0 -3
  135. package/dist/ui/divider.js +0 -2
  136. package/dist/ui/grid.d.ts +0 -22
  137. package/dist/ui/grid.js +0 -16
  138. package/dist/ui/group.d.ts +0 -7
  139. package/dist/ui/group.js +0 -5
  140. package/dist/ui/list.d.ts +0 -13
  141. package/dist/ui/list.js +0 -13
  142. package/dist/ui/spacer.d.ts +0 -9
  143. package/dist/ui/spacer.js +0 -5
  144. package/dist/ui/text-input.d.ts +0 -7
  145. package/dist/ui/text-input.js +0 -12
  146. package/dist/ui/toggle.d.ts +0 -7
  147. package/dist/ui/toggle.js +0 -6
  148. package/src/ui/bar-chart.ts +0 -20
  149. package/src/ui/button-group.ts +0 -26
  150. package/src/ui/divider.ts +0 -5
  151. package/src/ui/grid.ts +0 -25
  152. package/src/ui/group.ts +0 -8
  153. package/src/ui/list.ts +0 -17
  154. package/src/ui/spacer.ts +0 -8
  155. package/src/ui/text-input.ts +0 -15
  156. package/src/ui/toggle.ts +0 -9
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+
3
+ export const TOGGLE_GROUP_VARIANTS = ["default", "outline"] as const;
4
+ export const TOGGLE_GROUP_ORIENTATIONS = ["horizontal", "vertical"] as const;
5
+ export const TOGGLE_GROUP_MIN_OPTIONS = 2;
6
+ export const TOGGLE_GROUP_MAX_OPTIONS = 6;
7
+ export const TOGGLE_GROUP_MAX_OPTION_CHARS = 30;
8
+ export const TOGGLE_GROUP_MAX_LABEL_CHARS = 60;
9
+
10
+ export const toggleGroupProps = z.object({
11
+ name: z.string().min(1),
12
+ label: z.string().max(TOGGLE_GROUP_MAX_LABEL_CHARS).optional(),
13
+ multiple: z.boolean().optional(),
14
+ orientation: z.enum(TOGGLE_GROUP_ORIENTATIONS).optional(),
15
+ defaultValue: z.union([z.string(), z.array(z.string())]).optional(),
16
+ options: z
17
+ .array(z.string().min(1).max(TOGGLE_GROUP_MAX_OPTION_CHARS))
18
+ .min(TOGGLE_GROUP_MIN_OPTIONS)
19
+ .max(TOGGLE_GROUP_MAX_OPTIONS),
20
+ variant: z.enum(TOGGLE_GROUP_VARIANTS).optional(),
21
+ });
22
+
23
+ export type ToggleGroupProps = z.infer<typeof toggleGroupProps>;
package/src/validator.ts CHANGED
@@ -1,163 +1,16 @@
1
1
  import { z } from "zod";
2
- import {
3
- BUTTON_GROUP_STYLE,
4
- DEFAULT_BUTTON_LAYOUT,
5
- ELEMENT_TYPE,
6
- LIMITS,
7
- SPACER_SIZE,
8
- TEXT_STYLE,
9
- } from "./constants";
10
- import {
11
- firstPageResponseSchema,
12
- snapResponseSchema,
13
- type Button,
14
- type Element,
15
- } from "./schemas";
16
-
17
- type SnapRoot = z.infer<typeof snapResponseSchema>;
2
+ import { snapResponseSchema } from "./schemas";
18
3
 
19
4
  export type ValidationResult = {
20
5
  valid: boolean;
21
6
  issues: z.core.$ZodIssue[];
22
7
  };
23
8
 
24
- /** Not in SPEC — rough px used only for {@link measureHeightBudget}. */
25
- const PAGE_HEIGHT_HEURISTIC = {
26
- baseChromePx: 32,
27
- elementGapPx: 12,
28
- buttonRowPx: 48,
29
- } as const;
30
-
31
- function estimateElementHeight(el: Element): number {
32
- switch (el.type) {
33
- case ELEMENT_TYPE.text: {
34
- const style = el.style;
35
- if (style === TEXT_STYLE.title) return 48;
36
- if (style === TEXT_STYLE.body) return 80;
37
- if (style === TEXT_STYLE.caption) return 36;
38
- if (style === TEXT_STYLE.label) return 24;
39
- return 48;
40
- }
41
- case ELEMENT_TYPE.image:
42
- return 180;
43
- case ELEMENT_TYPE.grid:
44
- return 180;
45
- case ELEMENT_TYPE.progress:
46
- return 32;
47
- case ELEMENT_TYPE.list: {
48
- const items = el.items;
49
- const n = Array.isArray(items) ? items.length : 0;
50
- return Math.min(n, LIMITS.maxListItems) * 30;
51
- }
52
- case ELEMENT_TYPE.slider:
53
- return 56;
54
- case ELEMENT_TYPE.button_group: {
55
- const options = Array.isArray(el.options) ? el.options : [];
56
- const style =
57
- el.style ??
58
- (options.length <= 3
59
- ? BUTTON_GROUP_STYLE.row
60
- : BUTTON_GROUP_STYLE.stack);
61
- if (style === BUTTON_GROUP_STYLE.row)
62
- return PAGE_HEIGHT_HEURISTIC.buttonRowPx;
63
- if (style === BUTTON_GROUP_STYLE.grid) {
64
- return (
65
- Math.ceil(options.length / 2) * PAGE_HEIGHT_HEURISTIC.buttonRowPx
66
- );
67
- }
68
- return options.length * PAGE_HEIGHT_HEURISTIC.buttonRowPx;
69
- }
70
- case ELEMENT_TYPE.text_input:
71
- return 44;
72
- case ELEMENT_TYPE.toggle:
73
- return 40;
74
- case ELEMENT_TYPE.divider:
75
- return 16;
76
- case ELEMENT_TYPE.spacer: {
77
- const size = el.size ?? SPACER_SIZE.medium;
78
- if (size === SPACER_SIZE.small) return 8;
79
- if (size === SPACER_SIZE.large) return 24;
80
- return 16;
81
- }
82
- case ELEMENT_TYPE.bar_chart:
83
- return 140; // fixed: 120px bars + 20px labels
84
- case ELEMENT_TYPE.group: {
85
- let maxH = 0;
86
- for (const child of el.children) {
87
- const h = estimateElementHeight(child);
88
- if (h > maxH) maxH = h;
89
- }
90
- return maxH || 56;
91
- }
92
- default: {
93
- const _exhaustive: never = el;
94
- return _exhaustive;
95
- }
96
- }
97
- }
98
-
99
- function estimateButtonsHeight(
100
- buttons: readonly Button[],
101
- buttonLayout: string,
102
- ): number {
103
- const rowPx = PAGE_HEIGHT_HEURISTIC.buttonRowPx;
104
- if (buttons.length === 0) return 0;
105
- if (buttonLayout === BUTTON_GROUP_STYLE.row) return rowPx;
106
- if (buttonLayout === BUTTON_GROUP_STYLE.grid) {
107
- return Math.ceil(buttons.length / 2) * rowPx;
108
- }
109
- return buttons.length * rowPx;
110
- }
111
-
112
- function measureHeightBudget(
113
- elements: readonly Element[],
114
- buttons: readonly Button[],
115
- buttonLayout: string,
116
- ): number {
117
- let totalHeight = PAGE_HEIGHT_HEURISTIC.baseChromePx;
118
-
119
- for (const el of elements) {
120
- totalHeight += estimateElementHeight(el);
121
- }
122
-
123
- if (elements.length > 1) {
124
- totalHeight += (elements.length - 1) * PAGE_HEIGHT_HEURISTIC.elementGapPx;
125
- }
126
-
127
- totalHeight += estimateButtonsHeight(buttons, buttonLayout);
128
- return totalHeight;
129
- }
130
-
131
- function heightBudgetValidationError(
132
- elements: readonly Element[],
133
- buttons: readonly Button[],
134
- buttonLayout: string,
135
- ): z.core.$ZodIssue | null {
136
- const totalHeight = measureHeightBudget(elements, buttons, buttonLayout);
137
- if (totalHeight <= LIMITS.maxEstimatedPageHeightPx) {
138
- return null;
139
- }
140
- return {
141
- code: "custom",
142
- message: `estimated page height is ~${totalHeight}px, which exceeds the ${LIMITS.maxEstimatedPageHeightPx}px feed card limit (expected max ~${LIMITS.maxEstimatedPageHeightPx}px). Reduce elements or buttons to fit.`,
143
- path: ["page"],
144
- };
145
- }
146
-
147
- function heightBudgetValidationErrorForRoot(
148
- root: SnapRoot,
149
- ): z.core.$ZodIssue | null {
150
- const layout =
151
- typeof root.page.button_layout === "string"
152
- ? root.page.button_layout
153
- : DEFAULT_BUTTON_LAYOUT;
154
- return heightBudgetValidationError(
155
- root.page.elements.children,
156
- root.page.buttons ?? [],
157
- layout,
158
- );
159
- }
160
-
9
+ /**
10
+ * Validates a snap response against the schema.
11
+ * Element-level prop validation is handled by the json-render catalog.
12
+ * This validates the snap envelope (version, theme, effects, spec shape).
13
+ */
161
14
  export function validateSnapResponse(json: unknown): ValidationResult {
162
15
  const parsed = snapResponseSchema.safeParse(json);
163
16
  if (!parsed.success) {
@@ -166,28 +19,5 @@ export function validateSnapResponse(json: unknown): ValidationResult {
166
19
  issues: parsed.error.issues,
167
20
  };
168
21
  }
169
-
170
- const heightErr = heightBudgetValidationErrorForRoot(parsed.data);
171
- if (heightErr) {
172
- return { valid: false, issues: [heightErr] };
173
- }
174
-
175
- return { valid: true, issues: [] };
176
- }
177
-
178
- export function validateFirstPageResponse(json: unknown): ValidationResult {
179
- const parsed = firstPageResponseSchema.safeParse(json);
180
- if (!parsed.success) {
181
- return {
182
- valid: false,
183
- issues: parsed.error.issues,
184
- };
185
- }
186
-
187
- const heightErr = heightBudgetValidationErrorForRoot(parsed.data);
188
- if (heightErr) {
189
- return { valid: false, issues: [heightErr] };
190
- }
191
-
192
22
  return { valid: true, issues: [] };
193
23
  }
@@ -1,30 +0,0 @@
1
- import { z } from "zod";
2
- export declare const barChartProps: z.ZodObject<{
3
- bars: z.ZodArray<z.ZodObject<{
4
- label: z.ZodString;
5
- value: z.ZodNumber;
6
- color: z.ZodOptional<z.ZodEnum<{
7
- gray: "gray";
8
- blue: "blue";
9
- red: "red";
10
- amber: "amber";
11
- green: "green";
12
- teal: "teal";
13
- purple: "purple";
14
- pink: "pink";
15
- }>>;
16
- }, z.core.$strip>>;
17
- max: z.ZodOptional<z.ZodNumber>;
18
- color: z.ZodOptional<z.ZodEnum<{
19
- gray: "gray";
20
- blue: "blue";
21
- red: "red";
22
- amber: "amber";
23
- green: "green";
24
- teal: "teal";
25
- purple: "purple";
26
- pink: "pink";
27
- accent: "accent";
28
- }>>;
29
- }, z.core.$strip>;
30
- export type BarChartProps = z.infer<typeof barChartProps>;
@@ -1,15 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS } from "../constants.js";
3
- import { BAR_CHART_COLOR_VALUES, PALETTE_COLOR_VALUES } from "../colors.js";
4
- export const barChartProps = z.object({
5
- bars: z
6
- .array(z.object({
7
- label: z.string(),
8
- value: z.number().nonnegative(),
9
- color: z.enum(PALETTE_COLOR_VALUES).optional(),
10
- }))
11
- .min(1)
12
- .max(LIMITS.maxBarChartBars),
13
- max: z.number().nonnegative().optional(),
14
- color: z.enum(BAR_CHART_COLOR_VALUES).optional(),
15
- });
@@ -1,19 +0,0 @@
1
- import { z } from "zod";
2
- export declare const buttonGroupProps: z.ZodPipe<z.ZodObject<{
3
- name: z.ZodString;
4
- options: z.ZodArray<z.ZodString>;
5
- style: z.ZodOptional<z.ZodEnum<{
6
- row: "row";
7
- stack: "stack";
8
- grid: "grid";
9
- }>>;
10
- }, z.core.$strip>, z.ZodTransform<{
11
- style: "row" | "stack" | "grid";
12
- name: string;
13
- options: string[];
14
- }, {
15
- name: string;
16
- options: string[];
17
- style?: "row" | "stack" | "grid" | undefined;
18
- }>>;
19
- export type ButtonGroupProps = z.infer<typeof buttonGroupProps>;
@@ -1,18 +0,0 @@
1
- import { z } from "zod";
2
- import { BUTTON_GROUP_STYLE, BUTTON_GROUP_STYLE_VALUES, LIMITS, } from "../constants.js";
3
- export const buttonGroupProps = z
4
- .object({
5
- name: z.string().min(1),
6
- options: z
7
- .array(z.string().max(LIMITS.maxButtonGroupOptionChars))
8
- .min(LIMITS.minButtonGroupOptions)
9
- .max(LIMITS.maxButtonGroupOptions),
10
- style: z.enum(BUTTON_GROUP_STYLE_VALUES).optional(),
11
- })
12
- .transform((val) => ({
13
- ...val,
14
- style: val.style ??
15
- (val.options.length <= 3
16
- ? BUTTON_GROUP_STYLE.row
17
- : BUTTON_GROUP_STYLE.stack),
18
- }));
@@ -1,3 +0,0 @@
1
- import { z } from "zod";
2
- export declare const dividerProps: z.ZodObject<{}, z.core.$strip>;
3
- export type DividerProps = z.infer<typeof dividerProps>;
@@ -1,2 +0,0 @@
1
- import { z } from "zod";
2
- export const dividerProps = z.object({});
package/dist/ui/grid.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { z } from "zod";
2
- export declare const gridProps: z.ZodObject<{
3
- cols: z.ZodNumber;
4
- rows: z.ZodNumber;
5
- cells: z.ZodArray<z.ZodObject<{
6
- row: z.ZodNumber;
7
- col: z.ZodNumber;
8
- color: z.ZodOptional<z.ZodString>;
9
- content: z.ZodOptional<z.ZodString>;
10
- }, z.core.$strip>>;
11
- cellSize: z.ZodOptional<z.ZodEnum<{
12
- auto: "auto";
13
- square: "square";
14
- }>>;
15
- gap: z.ZodOptional<z.ZodEnum<{
16
- small: "small";
17
- medium: "medium";
18
- none: "none";
19
- }>>;
20
- interactive: z.ZodOptional<z.ZodBoolean>;
21
- }, z.core.$strip>;
22
- export type GridProps = z.infer<typeof gridProps>;
package/dist/ui/grid.js DELETED
@@ -1,16 +0,0 @@
1
- import { z } from "zod";
2
- import { GRID_CELL_SIZE_VALUES, GRID_GAP_VALUES, HEX_COLOR_6_RE, LIMITS, } from "../constants.js";
3
- const gridCellZ = z.object({
4
- row: z.number().int().nonnegative(),
5
- col: z.number().int().nonnegative(),
6
- color: z.string().regex(HEX_COLOR_6_RE).optional(),
7
- content: z.string().optional(),
8
- });
9
- export const gridProps = z.object({
10
- cols: z.number().int().min(LIMITS.minGridCols).max(LIMITS.maxGridCols),
11
- rows: z.number().int().min(LIMITS.minGridRows).max(LIMITS.maxGridRows),
12
- cells: z.array(gridCellZ),
13
- cellSize: z.enum(GRID_CELL_SIZE_VALUES).optional(),
14
- gap: z.enum(GRID_GAP_VALUES).optional(),
15
- interactive: z.boolean().optional(),
16
- });
@@ -1,7 +0,0 @@
1
- import { z } from "zod";
2
- export declare const groupProps: z.ZodObject<{
3
- layout: z.ZodEnum<{
4
- row: "row";
5
- }>;
6
- }, z.core.$strip>;
7
- export type GroupProps = z.infer<typeof groupProps>;
package/dist/ui/group.js DELETED
@@ -1,5 +0,0 @@
1
- import { z } from "zod";
2
- import { GROUP_LAYOUT_VALUES } from "../constants.js";
3
- export const groupProps = z.object({
4
- layout: z.enum(GROUP_LAYOUT_VALUES),
5
- });
package/dist/ui/list.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { z } from "zod";
2
- export declare const listProps: z.ZodObject<{
3
- style: z.ZodOptional<z.ZodEnum<{
4
- ordered: "ordered";
5
- unordered: "unordered";
6
- plain: "plain";
7
- }>>;
8
- items: z.ZodArray<z.ZodObject<{
9
- content: z.ZodString;
10
- trailing: z.ZodOptional<z.ZodString>;
11
- }, z.core.$strip>>;
12
- }, z.core.$strip>;
13
- export type ListProps = z.infer<typeof listProps>;
package/dist/ui/list.js DELETED
@@ -1,13 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS, LIST_STYLE_VALUES } from "../constants.js";
3
- const listItemZ = z.object({
4
- content: z.string(),
5
- trailing: z.string().optional(),
6
- });
7
- export const listProps = z.object({
8
- style: z.enum(LIST_STYLE_VALUES).optional(),
9
- items: z
10
- .array(listItemZ)
11
- .min(LIMITS.minListItems)
12
- .max(LIMITS.maxListItems),
13
- });
@@ -1,9 +0,0 @@
1
- import { z } from "zod";
2
- export declare const spacerProps: z.ZodObject<{
3
- size: z.ZodDefault<z.ZodEnum<{
4
- small: "small";
5
- medium: "medium";
6
- large: "large";
7
- }>>;
8
- }, z.core.$strip>;
9
- export type SpacerProps = z.infer<typeof spacerProps>;
package/dist/ui/spacer.js DELETED
@@ -1,5 +0,0 @@
1
- import { z } from "zod";
2
- import { SPACER_SIZE, SPACER_SIZE_VALUES } from "../constants.js";
3
- export const spacerProps = z.object({
4
- size: z.enum(SPACER_SIZE_VALUES).default(SPACER_SIZE.medium),
5
- });
@@ -1,7 +0,0 @@
1
- import { z } from "zod";
2
- export declare const textInputProps: z.ZodObject<{
3
- name: z.ZodString;
4
- placeholder: z.ZodOptional<z.ZodString>;
5
- maxLength: z.ZodOptional<z.ZodNumber>;
6
- }, z.core.$strip>;
7
- export type TextInputProps = z.infer<typeof textInputProps>;
@@ -1,12 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS } from "../constants.js";
3
- export const textInputProps = z.object({
4
- name: z.string().min(1),
5
- placeholder: z.string().optional(),
6
- maxLength: z
7
- .number()
8
- .int()
9
- .positive()
10
- .max(LIMITS.maxTextInputChars)
11
- .optional(),
12
- });
@@ -1,7 +0,0 @@
1
- import { z } from "zod";
2
- export declare const toggleProps: z.ZodObject<{
3
- name: z.ZodString;
4
- label: z.ZodString;
5
- value: z.ZodDefault<z.ZodBoolean>;
6
- }, z.core.$strip>;
7
- export type ToggleProps = z.infer<typeof toggleProps>;
package/dist/ui/toggle.js DELETED
@@ -1,6 +0,0 @@
1
- import { z } from "zod";
2
- export const toggleProps = z.object({
3
- name: z.string().min(1),
4
- label: z.string(),
5
- value: z.boolean().default(false),
6
- });
@@ -1,20 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS } from "../constants.js";
3
- import { BAR_CHART_COLOR_VALUES, PALETTE_COLOR_VALUES } from "../colors.js";
4
-
5
- export const barChartProps = z.object({
6
- bars: z
7
- .array(
8
- z.object({
9
- label: z.string(),
10
- value: z.number().nonnegative(),
11
- color: z.enum(PALETTE_COLOR_VALUES).optional(),
12
- }),
13
- )
14
- .min(1)
15
- .max(LIMITS.maxBarChartBars),
16
- max: z.number().nonnegative().optional(),
17
- color: z.enum(BAR_CHART_COLOR_VALUES).optional(),
18
- });
19
-
20
- export type BarChartProps = z.infer<typeof barChartProps>;
@@ -1,26 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- BUTTON_GROUP_STYLE,
4
- BUTTON_GROUP_STYLE_VALUES,
5
- LIMITS,
6
- } from "../constants.js";
7
-
8
- export const buttonGroupProps = z
9
- .object({
10
- name: z.string().min(1),
11
- options: z
12
- .array(z.string().max(LIMITS.maxButtonGroupOptionChars))
13
- .min(LIMITS.minButtonGroupOptions)
14
- .max(LIMITS.maxButtonGroupOptions),
15
- style: z.enum(BUTTON_GROUP_STYLE_VALUES).optional(),
16
- })
17
- .transform((val) => ({
18
- ...val,
19
- style:
20
- val.style ??
21
- (val.options.length <= 3
22
- ? BUTTON_GROUP_STYLE.row
23
- : BUTTON_GROUP_STYLE.stack),
24
- }));
25
-
26
- export type ButtonGroupProps = z.infer<typeof buttonGroupProps>;
package/src/ui/divider.ts DELETED
@@ -1,5 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const dividerProps = z.object({});
4
-
5
- export type DividerProps = z.infer<typeof dividerProps>;
package/src/ui/grid.ts DELETED
@@ -1,25 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- GRID_CELL_SIZE_VALUES,
4
- GRID_GAP_VALUES,
5
- HEX_COLOR_6_RE,
6
- LIMITS,
7
- } from "../constants.js";
8
-
9
- const gridCellZ = z.object({
10
- row: z.number().int().nonnegative(),
11
- col: z.number().int().nonnegative(),
12
- color: z.string().regex(HEX_COLOR_6_RE).optional(),
13
- content: z.string().optional(),
14
- });
15
-
16
- export const gridProps = z.object({
17
- cols: z.number().int().min(LIMITS.minGridCols).max(LIMITS.maxGridCols),
18
- rows: z.number().int().min(LIMITS.minGridRows).max(LIMITS.maxGridRows),
19
- cells: z.array(gridCellZ),
20
- cellSize: z.enum(GRID_CELL_SIZE_VALUES).optional(),
21
- gap: z.enum(GRID_GAP_VALUES).optional(),
22
- interactive: z.boolean().optional(),
23
- });
24
-
25
- export type GridProps = z.infer<typeof gridProps>;
package/src/ui/group.ts DELETED
@@ -1,8 +0,0 @@
1
- import { z } from "zod";
2
- import { GROUP_LAYOUT_VALUES } from "../constants.js";
3
-
4
- export const groupProps = z.object({
5
- layout: z.enum(GROUP_LAYOUT_VALUES),
6
- });
7
-
8
- export type GroupProps = z.infer<typeof groupProps>;
package/src/ui/list.ts DELETED
@@ -1,17 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS, LIST_STYLE_VALUES } from "../constants.js";
3
-
4
- const listItemZ = z.object({
5
- content: z.string(),
6
- trailing: z.string().optional(),
7
- });
8
-
9
- export const listProps = z.object({
10
- style: z.enum(LIST_STYLE_VALUES).optional(),
11
- items: z
12
- .array(listItemZ)
13
- .min(LIMITS.minListItems)
14
- .max(LIMITS.maxListItems),
15
- });
16
-
17
- export type ListProps = z.infer<typeof listProps>;
package/src/ui/spacer.ts DELETED
@@ -1,8 +0,0 @@
1
- import { z } from "zod";
2
- import { SPACER_SIZE, SPACER_SIZE_VALUES } from "../constants.js";
3
-
4
- export const spacerProps = z.object({
5
- size: z.enum(SPACER_SIZE_VALUES).default(SPACER_SIZE.medium),
6
- });
7
-
8
- export type SpacerProps = z.infer<typeof spacerProps>;
@@ -1,15 +0,0 @@
1
- import { z } from "zod";
2
- import { LIMITS } from "../constants.js";
3
-
4
- export const textInputProps = z.object({
5
- name: z.string().min(1),
6
- placeholder: z.string().optional(),
7
- maxLength: z
8
- .number()
9
- .int()
10
- .positive()
11
- .max(LIMITS.maxTextInputChars)
12
- .optional(),
13
- });
14
-
15
- export type TextInputProps = z.infer<typeof textInputProps>;
package/src/ui/toggle.ts DELETED
@@ -1,9 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const toggleProps = z.object({
4
- name: z.string().min(1),
5
- label: z.string(),
6
- value: z.boolean().default(false),
7
- });
8
-
9
- export type ToggleProps = z.infer<typeof toggleProps>;