@bendyline/squisq 1.5.0 → 1.5.1

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 (124) hide show
  1. package/README.md +14 -1
  2. package/dist/{ContentContainer-DNx460y8.d.ts → ContentContainer-BXUlIf18.d.ts} +6 -2
  3. package/dist/{Doc-BsMkmzH8.d.ts → Doc-BBVGq1_9.d.ts} +94 -15
  4. package/dist/{ImageEditDoc-DvoeHMP9.d.ts → ImageEditDoc-FuyGtt6o.d.ts} +1 -1
  5. package/dist/{chunk-KZNXZ5SM.js → chunk-6ATE2PSM.js} +18 -7
  6. package/dist/chunk-6ATE2PSM.js.map +1 -0
  7. package/dist/{chunk-7MQGNR76.js → chunk-A4O7GIWE.js} +2 -27
  8. package/dist/chunk-A4O7GIWE.js.map +1 -0
  9. package/dist/chunk-ET53IIEP.js +1 -0
  10. package/dist/chunk-ET53IIEP.js.map +1 -0
  11. package/dist/{chunk-OKJOQXK4.js → chunk-HWVFJAAH.js} +38 -2
  12. package/dist/chunk-HWVFJAAH.js.map +1 -0
  13. package/dist/{chunk-2TMAWB4Y.js → chunk-IMSCRLLV.js} +1 -1
  14. package/dist/chunk-IMSCRLLV.js.map +1 -0
  15. package/dist/{chunk-4AKUQPEE.js → chunk-KKNUBQ6Y.js} +1 -1
  16. package/dist/chunk-KKNUBQ6Y.js.map +1 -0
  17. package/dist/{chunk-TVSGLUID.js → chunk-LDQ2HJIX.js} +3 -3
  18. package/dist/{chunk-4ZFRZBU2.js → chunk-LH7I6SH7.js} +777 -151
  19. package/dist/chunk-LH7I6SH7.js.map +1 -0
  20. package/dist/{chunk-K32VJONL.js → chunk-T5UK6YOB.js} +41 -2
  21. package/dist/chunk-T5UK6YOB.js.map +1 -0
  22. package/dist/{chunk-OH43RPTP.js → chunk-TEEEILMP.js} +12 -2
  23. package/dist/chunk-TEEEILMP.js.map +1 -0
  24. package/dist/{chunk-FR2RBTKO.js → chunk-TQWLI6S2.js} +93 -27
  25. package/dist/chunk-TQWLI6S2.js.map +1 -0
  26. package/dist/{chunk-LRCV7N7F.js → chunk-UY7KGQ5R.js} +2 -2
  27. package/dist/{chunk-3E5F2XMR.js → chunk-VWUFZ6ZG.js} +29 -2
  28. package/dist/chunk-VWUFZ6ZG.js.map +1 -0
  29. package/dist/doc/index.d.ts +4 -4
  30. package/dist/doc/index.js +16 -7
  31. package/dist/generate/index.d.ts +2 -80
  32. package/dist/generate/index.js +2 -7
  33. package/dist/imageEdit/index.d.ts +4 -4
  34. package/dist/index.d.ts +8 -8
  35. package/dist/index.js +32 -23
  36. package/dist/jsonForm/index.d.ts +42 -1
  37. package/dist/jsonForm/index.js +9 -1
  38. package/dist/markdown/index.d.ts +18 -2
  39. package/dist/markdown/index.js +5 -3
  40. package/dist/recommend/index.js +2 -2
  41. package/dist/schemas/index.d.ts +4 -4
  42. package/dist/schemas/index.js +3 -5
  43. package/dist/storage/index.d.ts +2 -2
  44. package/dist/storage/index.js +1 -1
  45. package/dist/story/index.d.ts +125 -11
  46. package/dist/story/index.js +16 -7
  47. package/dist/{themeLibrary-DQQKuRMx.d.ts → themeLibrary-CehcJhzz.d.ts} +1 -1
  48. package/dist/timing/index.js +3 -5
  49. package/dist/transform/index.d.ts +2 -2
  50. package/dist/transform/index.js +3 -3
  51. package/dist/versions/index.d.ts +1 -1
  52. package/package.json +1 -1
  53. package/src/__tests__/contentExtractor.test.ts +60 -0
  54. package/src/__tests__/coverBlock.test.ts +46 -1
  55. package/src/__tests__/customTemplateSample.test.ts +63 -2
  56. package/src/__tests__/customTemplatesFrontmatter.test.ts +31 -0
  57. package/src/__tests__/customThemesFrontmatter.test.ts +27 -0
  58. package/src/__tests__/inputDescriptors.test.ts +162 -0
  59. package/src/__tests__/jsonForm.tokens.test.ts +84 -0
  60. package/src/__tests__/markdown.test.ts +64 -0
  61. package/src/__tests__/markdownSanitize.test.ts +15 -0
  62. package/src/__tests__/markdownToDoc.test.ts +168 -0
  63. package/src/__tests__/mediaAnnotations.test.ts +27 -0
  64. package/src/__tests__/structuredData.test.ts +73 -3
  65. package/src/__tests__/templateMetadata.test.ts +11 -1
  66. package/src/__tests__/templates.test.ts +112 -0
  67. package/src/__tests__/validateDoc.test.ts +160 -0
  68. package/src/doc/annotationBlocks.ts +117 -0
  69. package/src/doc/customTemplatesFrontmatter.ts +7 -1
  70. package/src/doc/customThemesFrontmatter.ts +6 -1
  71. package/src/doc/docToMarkdown.ts +31 -1
  72. package/src/doc/getLayers.ts +11 -2
  73. package/src/doc/index.ts +12 -0
  74. package/src/doc/markdownToDoc.ts +80 -3
  75. package/src/doc/mediaAnnotations.ts +15 -33
  76. package/src/doc/standaloneAnnotation.ts +58 -0
  77. package/src/doc/structuredData.ts +92 -21
  78. package/src/doc/templates/__tests__/customTemplate.test.ts +21 -2
  79. package/src/doc/templates/comparisonBar.ts +8 -1
  80. package/src/doc/templates/coverBlock.ts +29 -2
  81. package/src/doc/templates/customTemplate.ts +10 -4
  82. package/src/doc/templates/factCard.ts +4 -2
  83. package/src/doc/templates/imageWithCaption.ts +10 -8
  84. package/src/doc/templates/index.ts +12 -2
  85. package/src/doc/templates/inputDescriptors.ts +432 -0
  86. package/src/doc/templates/photoGrid.ts +16 -39
  87. package/src/doc/templates/tokens/__tests__/resolveTokens.test.ts +267 -1
  88. package/src/doc/templates/tokens/resolveTokens.ts +0 -0
  89. package/src/doc/templates/videoWithCaption.ts +15 -14
  90. package/src/doc/utils/nearest.ts +59 -0
  91. package/src/doc/validate.ts +153 -54
  92. package/src/generate/contentExtractor.ts +148 -35
  93. package/src/generate/index.ts +0 -3
  94. package/src/jsonForm/index.ts +2 -0
  95. package/src/jsonForm/tokens.ts +78 -0
  96. package/src/markdown/annotationCoercion.ts +1 -1
  97. package/src/markdown/attrTokens.ts +19 -0
  98. package/src/markdown/index.ts +2 -1
  99. package/src/markdown/sanitize.ts +22 -2
  100. package/src/markdown/stringify.ts +12 -3
  101. package/src/markdown/utils.ts +62 -1
  102. package/src/schemas/CustomTemplates.ts +56 -4
  103. package/src/schemas/Doc.ts +39 -41
  104. package/src/schemas/themeCompile.ts +1 -1
  105. package/src/storage/ContentContainer.ts +6 -2
  106. package/src/transform/types.ts +1 -1
  107. package/dist/chunk-2TMAWB4Y.js.map +0 -1
  108. package/dist/chunk-3E5F2XMR.js.map +0 -1
  109. package/dist/chunk-4AKUQPEE.js.map +0 -1
  110. package/dist/chunk-4X3JQXNM.js +0 -35
  111. package/dist/chunk-4X3JQXNM.js.map +0 -1
  112. package/dist/chunk-4ZFRZBU2.js.map +0 -1
  113. package/dist/chunk-7MQGNR76.js.map +0 -1
  114. package/dist/chunk-FBKP5CAO.js +0 -145
  115. package/dist/chunk-FBKP5CAO.js.map +0 -1
  116. package/dist/chunk-FR2RBTKO.js.map +0 -1
  117. package/dist/chunk-K32VJONL.js.map +0 -1
  118. package/dist/chunk-KZNXZ5SM.js.map +0 -1
  119. package/dist/chunk-OH43RPTP.js.map +0 -1
  120. package/dist/chunk-OKJOQXK4.js.map +0 -1
  121. package/src/__tests__/slideshowGenerator.test.ts +0 -128
  122. package/src/generate/slideshowGenerator.ts +0 -280
  123. /package/dist/{chunk-TVSGLUID.js.map → chunk-LDQ2HJIX.js.map} +0 -0
  124. /package/dist/{chunk-LRCV7N7F.js.map → chunk-UY7KGQ5R.js.map} +0 -0
@@ -0,0 +1,432 @@
1
+ /**
2
+ * Template input descriptors — a typed catalog of the inline `{[…]}` params
3
+ * each built-in template understands, plus the pure coercion + lint logic
4
+ * that consumes it.
5
+ *
6
+ * Two jobs, one source of truth:
7
+ *
8
+ * - **Coercion (`coerceTemplateParams`)** turns a flat `key → raw string`
9
+ * param map (from a `{[name key=value]}` annotation, always strings) into a
10
+ * partial typed input the template functions can consume directly — e.g.
11
+ * `center="47.6,-122.3"` → `{ lat: 47.6, lng: -122.3 }`, `zoom=9` → `9`.
12
+ * This is what makes `{[map center="47.6,-122.3" zoom=9]}` render with no
13
+ * changes to any template function. Unknown keys ALWAYS pass through
14
+ * untouched (as strings), so coercion is never lossy; coercion failures are
15
+ * returned as `warnings` and the raw string is preserved.
16
+ *
17
+ * - **Linting (`lintTemplateParams`)** checks a param map against the
18
+ * descriptors and reports unknown keys (with a did-you-mean suggestion),
19
+ * values outside a closed enum / that fail coercion, and missing required
20
+ * inputs. The document validator surfaces these as diagnostics.
21
+ *
22
+ * This mirrors the proven block-meta descriptor pattern in
23
+ * `markdown/annotationCoercion.ts` (`BLOCK_META_KEY_DESCRIPTORS`), extended
24
+ * from block geometry/timing to per-template content inputs.
25
+ *
26
+ * The descriptors are the `{[…]}` counterpart of the template input
27
+ * interfaces in `schemas/BlockTemplates.ts` — only keys/enums that provably
28
+ * exist on those interfaces are declared. Keys that can't be meaningfully
29
+ * expressed as a single inline string (e.g. a `dataTable`'s `rows`) are still
30
+ * declared with `coerce: 'string'` so they aren't mis-flagged as unknown.
31
+ */
32
+
33
+ import { KNOWN_BLOCK_META_KEYS, parseNumber } from '../../markdown/annotationCoercion.js';
34
+ import { resolveTemplateName } from './index.js';
35
+ import { nearestName } from '../utils/nearest.js';
36
+
37
+ // ============================================
38
+ // Types
39
+ // ============================================
40
+
41
+ /** How a raw `{[…]}` param string is coerced into a typed input value. */
42
+ export type InputCoercion =
43
+ | 'string'
44
+ | 'number'
45
+ | 'boolean'
46
+ | 'latLng'
47
+ | 'labeledPair'
48
+ | 'stringList';
49
+
50
+ /**
51
+ * Editor/validator-facing description of a single template input key: what it
52
+ * does, how to coerce its raw string, and either its closed set of valid
53
+ * values or a free-form format hint. `values`/`valueHint` are mutually
54
+ * exclusive (a key has a closed enum OR a hint, not both).
55
+ */
56
+ export interface TemplateInputDescriptor {
57
+ /** The `{[name key=…]}` param key, matching the template input interface. */
58
+ key: string;
59
+ /** One-line description of the input. */
60
+ description: string;
61
+ /** Coercion strategy for the raw string (default `'string'`). */
62
+ coerce?: InputCoercion;
63
+ /** Closed set of valid values, for keys backed by an enum. */
64
+ values?: readonly string[];
65
+ /** Format hint shown when the value is free-form (no closed set). */
66
+ valueHint?: string;
67
+ /** When true, the validator warns if the key is absent and can't be derived. */
68
+ required?: boolean;
69
+ }
70
+
71
+ /** A single lint finding produced by {@link lintTemplateParams}. */
72
+ export interface TemplateParamFinding {
73
+ kind: 'unknown-input' | 'invalid-input-value' | 'missing-input';
74
+ key: string;
75
+ message: string;
76
+ /** Did-you-mean candidate (for `unknown-input`). */
77
+ suggestion?: string;
78
+ }
79
+
80
+ // ============================================
81
+ // Shared enum vocabularies (verified against BlockTemplates.ts)
82
+ // ============================================
83
+
84
+ /** `ambientMotion` on image/video/map templates. */
85
+ const AMBIENT_MOTION_VALUES = ['zoomIn', 'zoomOut', 'panLeft', 'panRight'] as const;
86
+ /** `captionPosition` on imageWithCaption / videoWithCaption. */
87
+ const CAPTION_POSITION_VALUES = ['bottom', 'top', 'center'] as const;
88
+ /** `mapStyle` — mirrors `MapTileStyle` in `schemas/Doc.ts`. */
89
+ const MAP_STYLE_VALUES = ['terrain', 'satellite', 'road', 'toner', 'watercolor'] as const;
90
+ /** `mood` on dateEvent. */
91
+ const DATE_EVENT_MOOD_VALUES = ['neutral', 'somber', 'celebratory'] as const;
92
+
93
+ /** Shared free-form hint for `colorScheme`-style keys. */
94
+ const COLOR_SCHEME_HINT = "theme color-scheme name — e.g. 'blue', 'green'";
95
+
96
+ // ============================================
97
+ // Descriptor tables
98
+ // ============================================
99
+
100
+ /**
101
+ * Inputs shared by every template via `BaseTemplateBlock`. Merged into each
102
+ * template's known-key set for coercion + lint. Block-level timing/geometry
103
+ * keys (`duration`, `x`, `y`, …) are NOT here — those stay owned by the
104
+ * block-meta registry (`KNOWN_BLOCK_META_KEYS`) and are folded into the lint
105
+ * known-key set separately.
106
+ */
107
+ export const BASE_INPUT_DESCRIPTORS: readonly TemplateInputDescriptor[] = [
108
+ {
109
+ key: 'imageTreatment',
110
+ description: "Per-block photographic grade override ('none' opts out)",
111
+ values: ['none', 'mono', 'duotone', 'warm', 'cool'],
112
+ },
113
+ {
114
+ key: 'useBottomLayer',
115
+ description: "Show the doc's bottom persistent layers",
116
+ coerce: 'boolean',
117
+ },
118
+ { key: 'useTopLayer', description: "Show the doc's top persistent layers", coerce: 'boolean' },
119
+ ];
120
+
121
+ /**
122
+ * Per-template input descriptors, keyed by canonical template id. A template
123
+ * absent from this map has no descriptors and is exempt from lint (custom
124
+ * templates and not-yet-described built-ins).
125
+ */
126
+ export const TEMPLATE_INPUT_DESCRIPTORS: Readonly<
127
+ Record<string, readonly TemplateInputDescriptor[]>
128
+ > = {
129
+ title: [
130
+ { key: 'title', description: 'Main title text' },
131
+ { key: 'subtitle', description: 'Subtitle or tagline' },
132
+ { key: 'backgroundColor', description: 'Background color', valueHint: 'CSS color' },
133
+ ],
134
+ statHighlight: [
135
+ { key: 'stat', description: 'The statistic (e.g. "89%", "2x")' },
136
+ { key: 'description', description: 'What the stat means' },
137
+ { key: 'detail', description: 'Additional detail or context' },
138
+ { key: 'colorScheme', description: 'Color scheme for the stat', valueHint: COLOR_SCHEME_HINT },
139
+ ],
140
+ quote: [
141
+ { key: 'quote', description: 'The quote text' },
142
+ { key: 'attribution', description: 'Attribution (author, source)' },
143
+ ],
144
+ pullQuote: [
145
+ { key: 'text', description: 'Quote text' },
146
+ { key: 'attribution', description: 'Attribution' },
147
+ ],
148
+ twoColumn: [
149
+ {
150
+ key: 'left',
151
+ description: 'Left column, as "label|sublabel"',
152
+ coerce: 'labeledPair',
153
+ required: true,
154
+ },
155
+ {
156
+ key: 'right',
157
+ description: 'Right column, as "label|sublabel"',
158
+ coerce: 'labeledPair',
159
+ required: true,
160
+ },
161
+ { key: 'header', description: 'Optional header above the columns' },
162
+ { key: 'leftColor', description: 'Left column color scheme', valueHint: COLOR_SCHEME_HINT },
163
+ { key: 'rightColor', description: 'Right column color scheme', valueHint: COLOR_SCHEME_HINT },
164
+ ],
165
+ dateEvent: [
166
+ { key: 'date', description: 'The date (e.g. "July 14, 1974")' },
167
+ { key: 'description', description: 'What happened' },
168
+ { key: 'footer', description: 'Optional footer text' },
169
+ { key: 'mood', description: 'Emotional tone', values: DATE_EVENT_MOOD_VALUES },
170
+ ],
171
+ imageWithCaption: [
172
+ { key: 'imageSrc', description: 'Path to the image file', required: true },
173
+ { key: 'imageAlt', description: 'Alt text for accessibility' },
174
+ { key: 'caption', description: 'Caption text' },
175
+ { key: 'captionPosition', description: 'Caption placement', values: CAPTION_POSITION_VALUES },
176
+ { key: 'ambientMotion', description: 'Slow zoom/pan effect', values: AMBIENT_MOTION_VALUES },
177
+ { key: 'isTitle', description: 'Style the caption as a title', coerce: 'boolean' },
178
+ { key: 'subtitle', description: 'Subtitle (only when isTitle)' },
179
+ { key: 'imageCredit', description: 'Photo credit / artist name' },
180
+ { key: 'imageLicense', description: 'License identifier' },
181
+ ],
182
+ leftFeature: FEATURE_DESCRIPTORS(),
183
+ rightFeature: FEATURE_DESCRIPTORS(),
184
+ map: [
185
+ {
186
+ key: 'center',
187
+ description: 'Map center as "lat,lng"',
188
+ coerce: 'latLng',
189
+ required: true,
190
+ },
191
+ { key: 'zoom', description: 'Zoom level (4-16)', coerce: 'number' },
192
+ { key: 'mapStyle', description: 'Map tile style', values: MAP_STYLE_VALUES },
193
+ { key: 'title', description: 'Optional title overlay' },
194
+ { key: 'caption', description: 'Optional caption' },
195
+ ],
196
+ photoGrid: [
197
+ { key: 'images', description: 'Comma-separated image paths', coerce: 'stringList' },
198
+ { key: 'caption', description: 'Optional caption below the grid' },
199
+ {
200
+ key: 'ambientMotion',
201
+ description: 'Slow zoom/pan on the largest image',
202
+ values: AMBIENT_MOTION_VALUES,
203
+ },
204
+ ],
205
+ comparisonBar: [
206
+ { key: 'leftLabel', description: 'Left bar label', required: true },
207
+ { key: 'leftValue', description: 'Left bar numeric value', coerce: 'number', required: true },
208
+ { key: 'rightLabel', description: 'Right bar label', required: true },
209
+ { key: 'rightValue', description: 'Right bar numeric value', coerce: 'number', required: true },
210
+ { key: 'unit', description: 'Unit label (e.g. "km")' },
211
+ { key: 'colorScheme', description: 'Color scheme', valueHint: COLOR_SCHEME_HINT },
212
+ ],
213
+ dataTable: [
214
+ { key: 'title', description: 'Optional title above the table' },
215
+ { key: 'headers', description: 'Comma-separated header cells', coerce: 'stringList' },
216
+ // `rows`/`align` are structured (string[][] / alignment[]) and can't be
217
+ // expressed as a single inline string — declared so they aren't flagged
218
+ // as unknown when supplied via a data fence's overriding params.
219
+ { key: 'rows', description: 'Table rows (supply via a data fence)' },
220
+ { key: 'align', description: 'Per-column alignment (supply via a data fence)' },
221
+ { key: 'colorScheme', description: 'Header color scheme', valueHint: COLOR_SCHEME_HINT },
222
+ ],
223
+ videoWithCaption: [
224
+ { key: 'videoSrc', description: 'Path to the video file', required: true },
225
+ { key: 'posterSrc', description: 'Poster frame path' },
226
+ { key: 'videoAlt', description: 'Alt text for accessibility' },
227
+ { key: 'clipStart', description: 'Clip start time (seconds)', coerce: 'number' },
228
+ { key: 'clipEnd', description: 'Clip end time (seconds)', coerce: 'number' },
229
+ { key: 'caption', description: 'Caption text' },
230
+ { key: 'captionPosition', description: 'Caption placement', values: CAPTION_POSITION_VALUES },
231
+ { key: 'videoCredit', description: 'Video credit / artist name' },
232
+ { key: 'videoLicense', description: 'License identifier' },
233
+ ],
234
+ };
235
+
236
+ /** Shared descriptor list for `leftFeature`/`rightFeature` (identical inputs). */
237
+ function FEATURE_DESCRIPTORS(): readonly TemplateInputDescriptor[] {
238
+ return [
239
+ { key: 'imageSrc', description: 'Path to the feature image', required: true },
240
+ { key: 'imageAlt', description: 'Alt text for accessibility' },
241
+ { key: 'imageWidth', description: 'Explicit display width in px', coerce: 'number' },
242
+ { key: 'imageHeight', description: 'Explicit display height in px', coerce: 'number' },
243
+ { key: 'title', description: 'Heading text next to the image' },
244
+ { key: 'body', description: 'Body text below the title' },
245
+ ];
246
+ }
247
+
248
+ // ============================================
249
+ // Descriptor lookup
250
+ // ============================================
251
+
252
+ /** All descriptors (template-specific + base) for a canonical template id. */
253
+ function descriptorsFor(canonical: string): readonly TemplateInputDescriptor[] | undefined {
254
+ const specific = TEMPLATE_INPUT_DESCRIPTORS[canonical];
255
+ if (!specific) return undefined;
256
+ return [...specific, ...BASE_INPUT_DESCRIPTORS];
257
+ }
258
+
259
+ function descriptorMap(
260
+ descriptors: readonly TemplateInputDescriptor[],
261
+ ): Map<string, TemplateInputDescriptor> {
262
+ return new Map(descriptors.map((d) => [d.key, d]));
263
+ }
264
+
265
+ // ============================================
266
+ // Coercion (M2)
267
+ // ============================================
268
+
269
+ /**
270
+ * Coerce a flat `{[…]}` param map into a partial typed template input.
271
+ *
272
+ * Known descriptor keys are coerced per their `coerce` strategy; unknown keys
273
+ * (and `string`-typed keys) pass through unchanged. A coercion failure leaves
274
+ * the raw string in place and adds a human-readable `warnings` entry — the
275
+ * output is never lossy. Returns a fresh object; the caller must NOT feed
276
+ * `templateOverrides` back in — only the ephemeral merged input is coerced.
277
+ */
278
+ export function coerceTemplateParams(
279
+ template: string | undefined,
280
+ params: Record<string, string>,
281
+ ): { input: Record<string, unknown>; warnings: string[] } {
282
+ const input: Record<string, unknown> = {};
283
+ const warnings: string[] = [];
284
+ const descriptors = template ? descriptorsFor(resolveTemplateName(template)) : undefined;
285
+ const byKey = descriptors ? descriptorMap(descriptors) : undefined;
286
+
287
+ for (const [key, raw] of Object.entries(params)) {
288
+ const coerce = byKey?.get(key)?.coerce ?? 'string';
289
+ const { value, warning } = coerceValue(coerce, raw);
290
+ if (warning) {
291
+ warnings.push(`"${key}": ${warning}`);
292
+ input[key] = raw; // preserve the raw string on failure
293
+ } else {
294
+ input[key] = value;
295
+ }
296
+ }
297
+
298
+ return { input, warnings };
299
+ }
300
+
301
+ /** Coerce one raw string per a coercion kind. `warning` set on failure. */
302
+ function coerceValue(coerce: InputCoercion, raw: string): { value: unknown; warning?: string } {
303
+ switch (coerce) {
304
+ case 'number': {
305
+ const n = parseNumber(raw);
306
+ return n == null
307
+ ? { value: raw, warning: `not a number (${JSON.stringify(raw)})` }
308
+ : { value: n };
309
+ }
310
+ case 'boolean':
311
+ return coerceBoolean(raw);
312
+ case 'latLng':
313
+ return coerceLatLng(raw);
314
+ case 'labeledPair':
315
+ return { value: coerceLabeledPair(raw) };
316
+ case 'stringList':
317
+ return { value: coerceStringList(raw) };
318
+ case 'string':
319
+ default:
320
+ return { value: raw };
321
+ }
322
+ }
323
+
324
+ /** `'true'`/`''` (bare flag) → true, `'false'` → false; anything else fails. */
325
+ function coerceBoolean(raw: string): { value: unknown; warning?: string } {
326
+ const t = raw.trim().toLowerCase();
327
+ if (t === 'true' || t === '') return { value: true };
328
+ if (t === 'false') return { value: false };
329
+ return { value: raw, warning: `not a boolean (${JSON.stringify(raw)}) — expected true or false` };
330
+ }
331
+
332
+ /** `"47.6,-122.3"` → `{ lat, lng }`; malformed → failure (raw preserved). */
333
+ function coerceLatLng(raw: string): { value: unknown; warning?: string } {
334
+ const parts = raw.split(',');
335
+ if (parts.length === 2) {
336
+ const lat = parseNumber(parts[0]);
337
+ const lng = parseNumber(parts[1]);
338
+ if (lat != null && lng != null) return { value: { lat, lng } };
339
+ }
340
+ return { value: raw, warning: `not a "lat,lng" pair (${JSON.stringify(raw)})` };
341
+ }
342
+
343
+ /** `"Label|Sub"` → `{ label, sublabel? }`; sublabel omitted when empty. */
344
+ function coerceLabeledPair(raw: string): { label: string; sublabel?: string } {
345
+ const sep = raw.indexOf('|');
346
+ if (sep < 0) return { label: raw.trim() };
347
+ const label = raw.slice(0, sep).trim();
348
+ const sublabel = raw.slice(sep + 1).trim();
349
+ return sublabel ? { label, sublabel } : { label };
350
+ }
351
+
352
+ /** `"a, b ,c"` → `['a','b','c']` (trimmed, empties dropped). */
353
+ function coerceStringList(raw: string): string[] {
354
+ return raw
355
+ .split(',')
356
+ .map((s) => s.trim())
357
+ .filter((s) => s.length > 0);
358
+ }
359
+
360
+ // ============================================
361
+ // Linting (M5)
362
+ // ============================================
363
+
364
+ /**
365
+ * Lint a template's `{[…]}` params against its descriptors. Returns findings
366
+ * for unknown keys, values outside a closed enum / that fail coercion, and
367
+ * missing required inputs. Templates without descriptors (custom or
368
+ * not-yet-described built-ins) return `[]`.
369
+ */
370
+ export function lintTemplateParams(
371
+ template: string,
372
+ params: Record<string, string>,
373
+ ): TemplateParamFinding[] {
374
+ const canonical = resolveTemplateName(template);
375
+ const specific = TEMPLATE_INPUT_DESCRIPTORS[canonical];
376
+ if (!specific) return [];
377
+
378
+ const findings: TemplateParamFinding[] = [];
379
+ const allDescriptors = [...specific, ...BASE_INPUT_DESCRIPTORS];
380
+ const byKey = descriptorMap(allDescriptors);
381
+ // Known keys for did-you-mean: descriptor keys ∪ block-meta keys (which are
382
+ // honored on the same annotation, e.g. `duration`, `transition`).
383
+ const knownKeys = new Set<string>([...byKey.keys(), ...Object.keys(KNOWN_BLOCK_META_KEYS)]);
384
+
385
+ for (const [key, raw] of Object.entries(params)) {
386
+ const descriptor = byKey.get(key);
387
+ if (!descriptor) {
388
+ if (knownKeys.has(key)) continue; // block-meta key — valid, not a template input
389
+ const suggestion = nearestName(key, knownKeys);
390
+ findings.push({
391
+ kind: 'unknown-input',
392
+ key,
393
+ message:
394
+ `Unknown input "${key}" for template "${canonical}"` +
395
+ (suggestion ? `. Did you mean "${suggestion}"?` : ''),
396
+ ...(suggestion ? { suggestion } : {}),
397
+ });
398
+ continue;
399
+ }
400
+
401
+ // Value validation: closed enum first, then coercion.
402
+ if (descriptor.values) {
403
+ const v = raw.trim();
404
+ if (v !== '' && !descriptor.values.includes(v)) {
405
+ findings.push({
406
+ kind: 'invalid-input-value',
407
+ key,
408
+ message: `Invalid value ${JSON.stringify(raw)} for "${key}" — expected one of: ${descriptor.values.join(', ')}`,
409
+ });
410
+ }
411
+ } else if (descriptor.coerce && descriptor.coerce !== 'string') {
412
+ const { warning } = coerceValue(descriptor.coerce, raw);
413
+ if (warning) {
414
+ findings.push({ kind: 'invalid-input-value', key, message: `"${key}": ${warning}` });
415
+ }
416
+ }
417
+ }
418
+
419
+ // Missing required inputs (checked over template-specific descriptors only;
420
+ // base inputs are never required).
421
+ for (const descriptor of specific) {
422
+ if (descriptor.required && params[descriptor.key] == null) {
423
+ findings.push({
424
+ kind: 'missing-input',
425
+ key: descriptor.key,
426
+ message: `Missing required input "${descriptor.key}" for template "${canonical}"`,
427
+ });
428
+ }
429
+ }
430
+
431
+ return findings;
432
+ }
@@ -17,12 +17,7 @@
17
17
 
18
18
  import type { Layer } from '../../schemas/Doc.js';
19
19
  import type { PhotoGridInput, TemplateContext } from '../../schemas/BlockTemplates.js';
20
- import {
21
- getThemeFont,
22
- shouldUseShadow,
23
- themedFontSize,
24
- themedImageTreatment,
25
- } from '../utils/themeUtils.js';
20
+ import { getThemeFont, themedFontSize, themedImageTreatment } from '../utils/themeUtils.js';
26
21
  import { withAlpha } from '../../schemas/colorUtils.js';
27
22
  import { cleanCaption } from './captionUtils.js';
28
23
 
@@ -50,16 +45,11 @@ export function photoGrid(input: PhotoGridInput, context: TemplateContext): Laye
50
45
  },
51
46
  ];
52
47
 
53
- // Reserve bottom space for caption — sized to the caption's one-to-two
54
- // lines rather than a fixed fifth of the block (which left a dead band).
55
- const captionHeight = caption ? (layout.stackColumns ? 16 : 14) : 0;
56
- const gridHeight = 100 - captionHeight;
48
+ const gridHeight = 100;
57
49
 
58
50
  // Generate image positions based on count; stack vertically in portrait
59
51
  const positions = getGridPositions(images.length, gridHeight, layout.stackColumns);
60
52
 
61
- const altFontSize = themedFontSize(24, context, false);
62
-
63
53
  for (let i = 0; i < Math.min(images.length, 4); i++) {
64
54
  const img = images[i];
65
55
  const pos = positions[i];
@@ -72,24 +62,6 @@ export function photoGrid(input: PhotoGridInput, context: TemplateContext): Laye
72
62
  position: { x: `${pos.x}%`, y: `${pos.y}%`, width: `${pos.w}%`, height: `${pos.h}%` },
73
63
  });
74
64
 
75
- // Alt-text label on placeholder
76
- if (img.alt) {
77
- layers.push({
78
- type: 'text',
79
- id: `grid-alt-${i}`,
80
- content: {
81
- text: img.alt,
82
- style: {
83
- fontSize: altFontSize,
84
- fontFamily: getThemeFont(context, 'body'),
85
- color: theme.colors.textMuted,
86
- textAlign: 'center' as const,
87
- },
88
- },
89
- position: { x: `${pos.x + pos.w / 2}%`, y: `${pos.y + pos.h / 2}%`, anchor: 'center' },
90
- });
91
- }
92
-
93
65
  // Image layer (covers placeholder when loaded)
94
66
  layers.push({
95
67
  type: 'image',
@@ -116,20 +88,23 @@ export function photoGrid(input: PhotoGridInput, context: TemplateContext): Laye
116
88
  });
117
89
  }
118
90
 
119
- // Caption with gradient overlay
91
+ // Caption in a compact translucent chip above player controls. Long
92
+ // archival/Wikimedia descriptions are intentionally clamped.
120
93
  if (caption) {
121
- const captionFontSize = themedFontSize(layout.stackColumns ? 28 : 32, context, false);
94
+ const captionFontSize = themedFontSize(layout.stackColumns ? 24 : 26, context, false);
95
+ const captionY = layout.stackColumns ? '78%' : '74%';
96
+ const captionBgY = layout.stackColumns ? '72%' : '68%';
97
+ const captionHeight = layout.stackColumns ? '13%' : '16%';
98
+ const bg = theme.colors.background;
122
99
 
123
- // Caption band fades from the theme surface so the theme text color
124
- // on it always reads (a fixed black band hid dark text in light themes).
125
100
  layers.push({
126
101
  type: 'shape',
127
102
  id: 'caption-bg',
128
103
  content: {
129
104
  shape: 'rect',
130
- fill: `linear-gradient(${withAlpha(theme.colors.background, 0)}, ${withAlpha(theme.colors.background, 0.85)})`,
105
+ fill: `linear-gradient(90deg, ${withAlpha(bg, 0)}, ${withAlpha(bg, 0.78)} 16%, ${withAlpha(bg, 0.78)} 84%, ${withAlpha(bg, 0)})`,
131
106
  },
132
- position: { x: 0, y: `${gridHeight - 4}%`, width: '100%', height: `${captionHeight + 4}%` },
107
+ position: { x: 0, y: captionBgY, width: '100%', height: captionHeight },
133
108
  });
134
109
 
135
110
  layers.push({
@@ -142,14 +117,16 @@ export function photoGrid(input: PhotoGridInput, context: TemplateContext): Laye
142
117
  fontFamily: getThemeFont(context, 'body'),
143
118
  color: theme.colors.text,
144
119
  textAlign: 'center',
145
- shadow: shouldUseShadow(context),
120
+ shadow: true,
121
+ lineHeight: 1.18,
122
+ maxLines: layout.stackColumns ? 2 : 1,
146
123
  },
147
124
  },
148
125
  position: {
149
126
  x: '50%',
150
- y: `${gridHeight + captionHeight / 2}%`,
127
+ y: captionY,
151
128
  anchor: 'center',
152
- width: '90%',
129
+ width: '78%',
153
130
  },
154
131
  animation: { type: 'fadeIn', duration: 1, delay: 0.5 },
155
132
  });