@bendyline/squisq 1.1.0 → 1.1.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 (211) hide show
  1. package/dist/ContentContainer-DNx460y8.d.ts +88 -0
  2. package/dist/{Doc-1hmT1LZl.d.ts → Doc-Cvt2lyzn.d.ts} +56 -4
  3. package/dist/__tests__/markdownToDoc.test.js +75 -0
  4. package/dist/__tests__/markdownToDoc.test.js.map +1 -1
  5. package/dist/{chunk-PJ7AODIM.js → chunk-3WBJAZZ5.js} +394 -52
  6. package/dist/chunk-3WBJAZZ5.js.map +1 -0
  7. package/dist/{chunk-6YJPI6VI.js → chunk-4X3JQXNM.js} +1 -1
  8. package/dist/{chunk-S4F2RY37.js → chunk-CORGFIFU.js} +1 -1
  9. package/dist/chunk-CORGFIFU.js.map +1 -0
  10. package/dist/chunk-DNJKBAI7.js +1 -0
  11. package/dist/chunk-DNJKBAI7.js.map +1 -0
  12. package/dist/{chunk-VP5SZTZ2.js → chunk-MIBRIRGJ.js} +2 -139
  13. package/dist/chunk-MIBRIRGJ.js.map +1 -0
  14. package/dist/{chunk-URU6QMLY.js → chunk-NJLL5XYC.js} +15 -8
  15. package/dist/chunk-NJLL5XYC.js.map +1 -0
  16. package/dist/chunk-OFU53HI7.js +165 -0
  17. package/dist/chunk-OFU53HI7.js.map +1 -0
  18. package/dist/chunk-TSG2OSE6.js +145 -0
  19. package/dist/chunk-TSG2OSE6.js.map +1 -0
  20. package/dist/{chunk-O5HCIUAD.js → chunk-TVPKD76V.js} +81 -187
  21. package/dist/chunk-TVPKD76V.js.map +1 -0
  22. package/dist/contentExtractor-BNfVJV2U.d.ts +113 -0
  23. package/dist/doc/audioMapping.d.ts +36 -0
  24. package/dist/doc/audioMapping.d.ts.map +1 -0
  25. package/dist/doc/audioMapping.js +279 -0
  26. package/dist/doc/audioMapping.js.map +1 -0
  27. package/dist/doc/index.d.ts +1 -0
  28. package/dist/doc/index.d.ts.map +1 -1
  29. package/dist/doc/index.js +1 -0
  30. package/dist/doc/index.js.map +1 -1
  31. package/dist/doc/markdownToDoc.d.ts.map +1 -1
  32. package/dist/doc/markdownToDoc.js +126 -1
  33. package/dist/doc/markdownToDoc.js.map +1 -1
  34. package/dist/doc/templates/comparisonBar.d.ts.map +1 -1
  35. package/dist/doc/templates/comparisonBar.js +23 -5
  36. package/dist/doc/templates/comparisonBar.js.map +1 -1
  37. package/dist/doc/templates/coverBlock.d.ts.map +1 -1
  38. package/dist/doc/templates/coverBlock.js +3 -0
  39. package/dist/doc/templates/coverBlock.js.map +1 -1
  40. package/dist/doc/templates/dateEvent.d.ts.map +1 -1
  41. package/dist/doc/templates/dateEvent.js +4 -0
  42. package/dist/doc/templates/dateEvent.js.map +1 -1
  43. package/dist/doc/templates/definitionCard.d.ts.map +1 -1
  44. package/dist/doc/templates/definitionCard.js +4 -1
  45. package/dist/doc/templates/definitionCard.js.map +1 -1
  46. package/dist/doc/templates/factCard.d.ts.map +1 -1
  47. package/dist/doc/templates/factCard.js +4 -0
  48. package/dist/doc/templates/factCard.js.map +1 -1
  49. package/dist/doc/templates/fullBleedQuote.d.ts.map +1 -1
  50. package/dist/doc/templates/fullBleedQuote.js +2 -1
  51. package/dist/doc/templates/fullBleedQuote.js.map +1 -1
  52. package/dist/doc/templates/imageWithCaption.d.ts.map +1 -1
  53. package/dist/doc/templates/imageWithCaption.js +4 -0
  54. package/dist/doc/templates/imageWithCaption.js.map +1 -1
  55. package/dist/doc/templates/listBlock.d.ts.map +1 -1
  56. package/dist/doc/templates/listBlock.js +3 -0
  57. package/dist/doc/templates/listBlock.js.map +1 -1
  58. package/dist/doc/templates/mapBlock.d.ts.map +1 -1
  59. package/dist/doc/templates/mapBlock.js +3 -0
  60. package/dist/doc/templates/mapBlock.js.map +1 -1
  61. package/dist/doc/templates/photoGrid.d.ts.map +1 -1
  62. package/dist/doc/templates/photoGrid.js +3 -0
  63. package/dist/doc/templates/photoGrid.js.map +1 -1
  64. package/dist/doc/templates/pullQuote.d.ts.map +1 -1
  65. package/dist/doc/templates/pullQuote.js +4 -0
  66. package/dist/doc/templates/pullQuote.js.map +1 -1
  67. package/dist/doc/templates/quoteBlock.d.ts.map +1 -1
  68. package/dist/doc/templates/quoteBlock.js +4 -0
  69. package/dist/doc/templates/quoteBlock.js.map +1 -1
  70. package/dist/doc/templates/sectionHeader.d.ts.map +1 -1
  71. package/dist/doc/templates/sectionHeader.js +3 -2
  72. package/dist/doc/templates/sectionHeader.js.map +1 -1
  73. package/dist/doc/templates/statHighlight.d.ts.map +1 -1
  74. package/dist/doc/templates/statHighlight.js +4 -1
  75. package/dist/doc/templates/statHighlight.js.map +1 -1
  76. package/dist/doc/templates/titleBlock.d.ts.map +1 -1
  77. package/dist/doc/templates/titleBlock.js +3 -0
  78. package/dist/doc/templates/titleBlock.js.map +1 -1
  79. package/dist/doc/templates/twoColumn.d.ts.map +1 -1
  80. package/dist/doc/templates/twoColumn.js +7 -1
  81. package/dist/doc/templates/twoColumn.js.map +1 -1
  82. package/dist/doc/templates/videoPullQuote.d.ts.map +1 -1
  83. package/dist/doc/templates/videoPullQuote.js +4 -0
  84. package/dist/doc/templates/videoPullQuote.js.map +1 -1
  85. package/dist/doc/templates/videoWithCaption.d.ts.map +1 -1
  86. package/dist/doc/templates/videoWithCaption.js +3 -0
  87. package/dist/doc/templates/videoWithCaption.js.map +1 -1
  88. package/dist/doc/utils/themeUtils.d.ts +9 -0
  89. package/dist/doc/utils/themeUtils.d.ts.map +1 -1
  90. package/dist/doc/utils/themeUtils.js +26 -0
  91. package/dist/doc/utils/themeUtils.js.map +1 -1
  92. package/dist/markdown/convert.d.ts.map +1 -1
  93. package/dist/markdown/convert.js +16 -7
  94. package/dist/markdown/convert.js.map +1 -1
  95. package/dist/markdown/types.d.ts +4 -2
  96. package/dist/markdown/types.d.ts.map +1 -1
  97. package/dist/schemas/BlockTemplates.d.ts +2 -2
  98. package/dist/schemas/BlockTemplates.d.ts.map +1 -1
  99. package/dist/schemas/BlockTemplates.js +2 -2
  100. package/dist/schemas/BlockTemplates.js.map +1 -1
  101. package/dist/schemas/Doc.d.ts +52 -0
  102. package/dist/schemas/Doc.d.ts.map +1 -1
  103. package/dist/schemas/Doc.js.map +1 -1
  104. package/dist/schemas/themeLibrary.d.ts +2 -2
  105. package/dist/schemas/themeLibrary.d.ts.map +1 -1
  106. package/dist/schemas/themeLibrary.js +91 -26
  107. package/dist/schemas/themeLibrary.js.map +1 -1
  108. package/dist/story/index.d.ts +50 -5
  109. package/dist/story/index.js +15 -5
  110. package/dist/{themeLibrary-DR1VRo-8.d.ts → themeLibrary-VOHfPzRB.d.ts} +3 -3
  111. package/dist/transform/applyTransform.d.ts +22 -0
  112. package/dist/transform/applyTransform.d.ts.map +1 -0
  113. package/dist/transform/applyTransform.js +68 -0
  114. package/dist/transform/applyTransform.js.map +1 -0
  115. package/dist/transform/blockAnalyzer.d.ts +48 -0
  116. package/dist/transform/blockAnalyzer.d.ts.map +1 -0
  117. package/dist/transform/blockAnalyzer.js +135 -0
  118. package/dist/transform/blockAnalyzer.js.map +1 -0
  119. package/dist/transform/index.d.ts +6 -0
  120. package/dist/transform/index.d.ts.map +1 -0
  121. package/dist/transform/index.js +4 -0
  122. package/dist/transform/index.js.map +1 -0
  123. package/dist/transform/registry.d.ts +19 -0
  124. package/dist/transform/registry.d.ts.map +1 -0
  125. package/dist/transform/registry.js +41 -0
  126. package/dist/transform/registry.js.map +1 -0
  127. package/dist/transform/styles/dataDriven.d.ts +4 -0
  128. package/dist/transform/styles/dataDriven.d.ts.map +1 -0
  129. package/dist/transform/styles/dataDriven.js +15 -0
  130. package/dist/transform/styles/dataDriven.js.map +1 -0
  131. package/dist/transform/styles/documentary.d.ts +4 -0
  132. package/dist/transform/styles/documentary.d.ts.map +1 -0
  133. package/dist/transform/styles/documentary.js +15 -0
  134. package/dist/transform/styles/documentary.js.map +1 -0
  135. package/dist/transform/styles/index.d.ts +6 -0
  136. package/dist/transform/styles/index.d.ts.map +1 -0
  137. package/dist/transform/styles/index.js +6 -0
  138. package/dist/transform/styles/index.js.map +1 -0
  139. package/dist/transform/styles/magazine.d.ts +4 -0
  140. package/dist/transform/styles/magazine.d.ts.map +1 -0
  141. package/dist/transform/styles/magazine.js +15 -0
  142. package/dist/transform/styles/magazine.js.map +1 -0
  143. package/dist/transform/styles/minimal.d.ts +4 -0
  144. package/dist/transform/styles/minimal.d.ts.map +1 -0
  145. package/dist/transform/styles/minimal.js +15 -0
  146. package/dist/transform/styles/minimal.js.map +1 -0
  147. package/dist/transform/styles/narrative.d.ts +4 -0
  148. package/dist/transform/styles/narrative.d.ts.map +1 -0
  149. package/dist/transform/styles/narrative.js +15 -0
  150. package/dist/transform/styles/narrative.js.map +1 -0
  151. package/dist/transform/templateSelector.d.ts +30 -0
  152. package/dist/transform/templateSelector.d.ts.map +1 -0
  153. package/dist/transform/templateSelector.js +218 -0
  154. package/dist/transform/templateSelector.js.map +1 -0
  155. package/dist/transform/timingAllocator.d.ts +21 -0
  156. package/dist/transform/timingAllocator.d.ts.map +1 -0
  157. package/dist/transform/timingAllocator.js +111 -0
  158. package/dist/transform/timingAllocator.js.map +1 -0
  159. package/dist/transform/types.d.ts +86 -0
  160. package/dist/transform/types.d.ts.map +1 -0
  161. package/dist/transform/types.js +9 -0
  162. package/dist/transform/types.js.map +1 -0
  163. package/dist/{types-DHiv_Pnm.d.ts → types-DYAzisMG.d.ts} +4 -2
  164. package/package.json +6 -1
  165. package/src/__tests__/markdownToDoc.test.ts +96 -0
  166. package/src/doc/audioMapping.ts +346 -0
  167. package/src/doc/index.ts +1 -0
  168. package/src/doc/markdownToDoc.ts +136 -2
  169. package/src/doc/templates/comparisonBar.ts +23 -5
  170. package/src/doc/templates/coverBlock.ts +3 -0
  171. package/src/doc/templates/dateEvent.ts +4 -0
  172. package/src/doc/templates/definitionCard.ts +4 -1
  173. package/src/doc/templates/factCard.ts +4 -0
  174. package/src/doc/templates/fullBleedQuote.ts +2 -1
  175. package/src/doc/templates/imageWithCaption.ts +4 -0
  176. package/src/doc/templates/listBlock.ts +3 -0
  177. package/src/doc/templates/mapBlock.ts +3 -0
  178. package/src/doc/templates/photoGrid.ts +3 -0
  179. package/src/doc/templates/pullQuote.ts +4 -0
  180. package/src/doc/templates/quoteBlock.ts +4 -0
  181. package/src/doc/templates/sectionHeader.ts +3 -2
  182. package/src/doc/templates/statHighlight.ts +4 -1
  183. package/src/doc/templates/titleBlock.ts +3 -0
  184. package/src/doc/templates/twoColumn.ts +7 -1
  185. package/src/doc/templates/videoPullQuote.ts +4 -0
  186. package/src/doc/templates/videoWithCaption.ts +3 -0
  187. package/src/doc/utils/themeUtils.ts +29 -0
  188. package/src/markdown/convert.ts +17 -7
  189. package/src/markdown/types.ts +4 -2
  190. package/src/schemas/BlockTemplates.ts +2 -2
  191. package/src/schemas/Doc.ts +60 -0
  192. package/src/schemas/themeLibrary.ts +95 -26
  193. package/src/transform/applyTransform.ts +83 -0
  194. package/src/transform/blockAnalyzer.ts +181 -0
  195. package/src/transform/index.ts +20 -0
  196. package/src/transform/registry.ts +47 -0
  197. package/src/transform/styles/dataDriven.ts +16 -0
  198. package/src/transform/styles/documentary.ts +16 -0
  199. package/src/transform/styles/index.ts +5 -0
  200. package/src/transform/styles/magazine.ts +16 -0
  201. package/src/transform/styles/minimal.ts +16 -0
  202. package/src/transform/styles/narrative.ts +16 -0
  203. package/src/transform/templateSelector.ts +294 -0
  204. package/src/transform/timingAllocator.ts +126 -0
  205. package/src/transform/types.ts +105 -0
  206. package/dist/chunk-O5HCIUAD.js.map +0 -1
  207. package/dist/chunk-PJ7AODIM.js.map +0 -1
  208. package/dist/chunk-S4F2RY37.js.map +0 -1
  209. package/dist/chunk-URU6QMLY.js.map +0 -1
  210. package/dist/chunk-VP5SZTZ2.js.map +0 -1
  211. /package/dist/{chunk-6YJPI6VI.js.map → chunk-4X3JQXNM.js.map} +0 -0
@@ -19,11 +19,32 @@ import type { Theme, ThemeColorScheme } from './Theme.js';
19
19
  // Shared constants
20
20
  // ============================================
21
21
 
22
- const SERIF = '"PT Serif", Georgia, "Times New Roman", serif';
23
- const SANS = '"Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
24
- const MONO = '"JetBrains Mono", "Fira Code", "Consolas", monospace';
25
- const MERRIWEATHER = '"Merriweather", Georgia, "Times New Roman", serif';
26
- const GEORGIA = 'Georgia, "Times New Roman", serif';
22
+ // ── Font stacks ──────────────────────────────────────────────────
23
+ // Each stack lists the recommended Google Font first (works when the
24
+ // wrapping site loads it), then degrades to safe system fonts.
25
+ // Squisq itself does NOT load Google Fonts.
26
+
27
+ /** System fonts only — no external dependencies. */
28
+ const SYSTEM_SANS = 'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
29
+ const SYSTEM_SERIF = 'Georgia, "Times New Roman", serif';
30
+ const SYSTEM_MONO = 'Consolas, "Courier New", monospace';
31
+
32
+ /** Theme-specific stacks with Google Font leads. */
33
+ const PLAYFAIR = '"Playfair Display", Georgia, serif';
34
+ const SOURCE_SERIF = '"Source Serif 4", "PT Serif", Georgia, serif';
35
+ const INTER = '"Inter", "Segoe UI", Roboto, sans-serif';
36
+ const OSWALD = '"Oswald", Impact, "Arial Black", sans-serif';
37
+ const ROBOTO = '"Roboto", "Segoe UI", Arial, sans-serif';
38
+ const MERRIWEATHER = '"Merriweather", Georgia, serif';
39
+ const LORA = '"Lora", "Merriweather", Georgia, serif';
40
+ const JETBRAINS_MONO = '"JetBrains Mono", "Fira Code", Consolas, monospace';
41
+ const IBM_PLEX_SANS = '"IBM Plex Sans", "Segoe UI", Roboto, sans-serif';
42
+ const DM_SERIF = '"DM Serif Display", Georgia, serif';
43
+ const DM_SANS = '"DM Sans", "Segoe UI", Roboto, sans-serif';
44
+ const CORMORANT = '"Cormorant Garamond", Garamond, Georgia, serif';
45
+ const CRIMSON = '"Crimson Text", Georgia, serif';
46
+ const PT_SERIF = '"PT Serif", Georgia, serif';
47
+ const HANKEN_GROTESK = '"Hanken Grotesk", system-ui, sans-serif';
27
48
 
28
49
  /** Standard 6-scheme set used by the documentary theme (migrated from old COLOR_SCHEMES). */
29
50
  const CLASSIC_COLOR_SCHEMES: Record<string, ThemeColorScheme> = {
@@ -36,13 +57,60 @@ const CLASSIC_COLOR_SCHEMES: Record<string, ThemeColorScheme> = {
36
57
  };
37
58
 
38
59
  // ============================================
39
- // 1. Documentary (default — migrated from old DEFAULT_THEME)
60
+ // 1. Standard (default — safe system fonts, no external dependencies)
61
+ // ============================================
62
+
63
+ const standard: Theme = {
64
+ id: 'standard',
65
+ name: 'Standard',
66
+ description: 'Clean and safe. System fonts only — no external font dependencies.',
67
+ colors: {
68
+ primary: '#3182ce',
69
+ secondary: '#4a5568',
70
+ background: '#1a202c',
71
+ backgroundLight: '#2d3748',
72
+ text: '#f7fafc',
73
+ textMuted: '#a0aec0',
74
+ highlight: '#4299e1',
75
+ warning: '#fc8181',
76
+ },
77
+ typography: {
78
+ bodyFontFamily: SYSTEM_SANS,
79
+ titleFontFamily: SYSTEM_SERIF,
80
+ monoFontFamily: SYSTEM_MONO,
81
+ titleWeight: 'bold',
82
+ },
83
+ style: {
84
+ textShadow: true,
85
+ overlayOpacity: 0.45,
86
+ animationSpeed: 1.0,
87
+ },
88
+ renderStyle: {
89
+ name: 'standard',
90
+ defaultTextAnimation: 'fadeIn',
91
+ defaultImageAnimation: 'slowZoom',
92
+ ambientMotion: true,
93
+ defaultTransition: { type: 'fade', duration: 0.7 },
94
+ },
95
+ colorSchemes: CLASSIC_COLOR_SCHEMES,
96
+ persistentLayers: {
97
+ bottomLayers: [
98
+ {
99
+ template: 'gradientBackground',
100
+ config: { type: 'gradientBackground', preset: 'dark-vignette' },
101
+ },
102
+ ],
103
+ },
104
+ };
105
+
106
+ // ============================================
107
+ // 2. Documentary
40
108
  // ============================================
41
109
 
42
110
  const documentary: Theme = {
43
111
  id: 'documentary',
44
112
  name: 'Documentary',
45
- description: 'Classic dark cinematic look with serif typography. The original Squisq style.',
113
+ description: 'Classic dark cinematic look with elegant serif typography.',
46
114
  colors: {
47
115
  primary: '#3d5a80',
48
116
  secondary: '#63b3ed',
@@ -54,8 +122,8 @@ const documentary: Theme = {
54
122
  warning: '#fc8181',
55
123
  },
56
124
  typography: {
57
- bodyFontFamily: SERIF,
58
- titleFontFamily: SERIF,
125
+ bodyFontFamily: SOURCE_SERIF,
126
+ titleFontFamily: PLAYFAIR,
59
127
  titleWeight: 'bold',
60
128
  },
61
129
  style: {
@@ -100,8 +168,8 @@ const minimalist: Theme = {
100
168
  warning: '#e53e3e',
101
169
  },
102
170
  typography: {
103
- bodyFontFamily: SANS,
104
- titleFontFamily: SANS,
171
+ bodyFontFamily: INTER,
172
+ titleFontFamily: INTER,
105
173
  titleWeight: 'bold',
106
174
  lineHeight: 1.6,
107
175
  },
@@ -149,8 +217,8 @@ const bold: Theme = {
149
217
  warning: '#fc8181',
150
218
  },
151
219
  typography: {
152
- bodyFontFamily: SANS,
153
- titleFontFamily: SANS,
220
+ bodyFontFamily: ROBOTO,
221
+ titleFontFamily: OSWALD,
154
222
  titleWeight: 'bold',
155
223
  titleScale: 1.15,
156
224
  bodyScale: 1.0,
@@ -201,7 +269,7 @@ const morningLight: Theme = {
201
269
  warning: '#c53030',
202
270
  },
203
271
  typography: {
204
- bodyFontFamily: MERRIWEATHER,
272
+ bodyFontFamily: LORA,
205
273
  titleFontFamily: MERRIWEATHER,
206
274
  titleWeight: 'bold',
207
275
  lineHeight: 1.7,
@@ -247,9 +315,9 @@ const techDark: Theme = {
247
315
  warning: '#ff5252',
248
316
  },
249
317
  typography: {
250
- bodyFontFamily: SANS,
251
- titleFontFamily: MONO,
252
- monoFontFamily: MONO,
318
+ bodyFontFamily: IBM_PLEX_SANS,
319
+ titleFontFamily: JETBRAINS_MONO,
320
+ monoFontFamily: JETBRAINS_MONO,
253
321
  titleWeight: 'bold',
254
322
  titleScale: 0.9,
255
323
  lineHeight: 1.5,
@@ -299,8 +367,8 @@ const magazine: Theme = {
299
367
  warning: '#fc8181',
300
368
  },
301
369
  typography: {
302
- bodyFontFamily: SANS,
303
- titleFontFamily: GEORGIA,
370
+ bodyFontFamily: DM_SANS,
371
+ titleFontFamily: DM_SERIF,
304
372
  titleWeight: 'bold',
305
373
  titleScale: 1.05,
306
374
  lineHeight: 1.5,
@@ -347,8 +415,8 @@ const cinematic: Theme = {
347
415
  warning: '#fc8181',
348
416
  },
349
417
  typography: {
350
- bodyFontFamily: SERIF,
351
- titleFontFamily: SERIF,
418
+ bodyFontFamily: CRIMSON,
419
+ titleFontFamily: CORMORANT,
352
420
  titleWeight: 'bold',
353
421
  lineHeight: 1.5,
354
422
  titleLineHeight: 1.2,
@@ -405,8 +473,8 @@ const warmEarth: Theme = {
405
473
  warning: '#e53e3e',
406
474
  },
407
475
  typography: {
408
- bodyFontFamily: GEORGIA,
409
- titleFontFamily: GEORGIA,
476
+ bodyFontFamily: HANKEN_GROTESK,
477
+ titleFontFamily: PT_SERIF,
410
478
  titleWeight: 'bold',
411
479
  lineHeight: 1.6,
412
480
  },
@@ -448,6 +516,7 @@ const warmEarth: Theme = {
448
516
  * All built-in themes, keyed by id.
449
517
  */
450
518
  export const THEMES: Record<string, Theme> = {
519
+ standard,
451
520
  documentary,
452
521
  minimalist,
453
522
  bold,
@@ -459,10 +528,10 @@ export const THEMES: Record<string, Theme> = {
459
528
  };
460
529
 
461
530
  /** The default theme id. */
462
- export const DEFAULT_THEME_ID = 'documentary';
531
+ export const DEFAULT_THEME_ID = 'standard';
463
532
 
464
- /** The default theme (documentarymigrated from old DEFAULT_THEME). */
465
- export const DEFAULT_THEME: Theme = documentary;
533
+ /** The default theme (standardsafe system fonts, no external dependencies). */
534
+ export const DEFAULT_THEME: Theme = standard;
466
535
 
467
536
  /**
468
537
  * Resolve a theme by id. Returns the default theme when `id` is
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Apply Transform
3
+ *
4
+ * Main entry point for the transform module. Takes a Doc and a style,
5
+ * analyzes block content, selects extractions to promote, and returns
6
+ * a new Doc with blocks optimized for visual presentation.
7
+ *
8
+ * The input Doc is never mutated — a fresh Doc is always returned.
9
+ */
10
+
11
+ import type { Doc } from '../schemas/Doc.js';
12
+ import type { TransformStyleId, TransformOptions, TransformResult } from './types.js';
13
+ import { resolveTransformStyle } from './registry.js';
14
+ import { analyzeBlocks, extractDocImages } from './blockAnalyzer.js';
15
+ import { selectAndBuild } from './templateSelector.js';
16
+ import { allocateTiming } from './timingAllocator.js';
17
+ import { hashString } from '../random/SeededRandom.js';
18
+
19
+ /**
20
+ * Apply a transform style to a Doc, producing a new Doc with blocks
21
+ * optimized for visual presentation.
22
+ *
23
+ * @param doc - The source Doc (not mutated).
24
+ * @param styleId - Registered transform style id (e.g. 'documentary', 'magazine').
25
+ * @param options - Optional seed, images, theme override.
26
+ * @returns TransformResult with the new Doc and stats.
27
+ */
28
+ export function applyTransform(
29
+ doc: Doc,
30
+ styleId: TransformStyleId,
31
+ options?: TransformOptions,
32
+ ): TransformResult {
33
+ const baseConfig = resolveTransformStyle(styleId);
34
+ const config = options?.overrides
35
+ ? { ...baseConfig, ...options.overrides, id: baseConfig.id }
36
+ : baseConfig;
37
+
38
+ const seed = options?.seed ?? hashString(doc.articleId || 'transform');
39
+
40
+ // Use provided images or auto-extract from the doc's markdown content
41
+ const images = options?.images ?? extractDocImages(doc.blocks);
42
+
43
+ // 1. Analyze blocks
44
+ const analyzed = analyzeBlocks(doc.blocks, {
45
+ minConfidence: config.minConfidence,
46
+ types: config.preferredTypes,
47
+ });
48
+
49
+ // If no blocks have meaningful content, return the doc unchanged
50
+ const hasContent = analyzed.some((ab) => ab.bodyWordCount >= 5);
51
+ if (!hasContent) {
52
+ return {
53
+ doc: { ...doc },
54
+ stats: {
55
+ totalInputBlocks: doc.blocks.length,
56
+ transformedBlocks: 0,
57
+ insertedBlocks: 0,
58
+ },
59
+ };
60
+ }
61
+
62
+ // 2. Select extractions and build template blocks
63
+ const selection = selectAndBuild(analyzed, config, images, seed);
64
+
65
+ // 3. Allocate timing across the new block sequence
66
+ const timedBlocks = allocateTiming(selection.blocks, doc.duration);
67
+
68
+ // 4. Assemble the output Doc
69
+ const transformedDoc: Doc = {
70
+ ...doc,
71
+ blocks: timedBlocks,
72
+ themeId: options?.themeId ?? doc.themeId,
73
+ };
74
+
75
+ return {
76
+ doc: transformedDoc,
77
+ stats: {
78
+ totalInputBlocks: doc.blocks.length,
79
+ transformedBlocks: selection.transformedCount,
80
+ insertedBlocks: selection.insertedCount,
81
+ },
82
+ };
83
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Block Analyzer
3
+ *
4
+ * Walks Doc blocks, extracts plain text from their markdown contents,
5
+ * and runs the content extractor on each block to identify stats, dates,
6
+ * quotes, etc. that can be promoted to visual template blocks.
7
+ */
8
+
9
+ import type { Block } from '../schemas/Doc.js';
10
+ import type { MarkdownBlockNode, MarkdownNode } from '../markdown/types.js';
11
+ import type { ExtractedElement, ExtractionOptions } from '../generate/contentExtractor.js';
12
+ import type { TransformImage } from './types.js';
13
+ import { extractContent, stripMarkdown } from '../generate/contentExtractor.js';
14
+ import { extractPlainText, getChildren } from '../markdown/utils.js';
15
+
16
+ /** An image found in a block's markdown contents. */
17
+ export interface BlockImage {
18
+ /** Image URL (relative or absolute). */
19
+ src: string;
20
+ /** Alt text. */
21
+ alt: string;
22
+ /** Index of the source block in the analyzed array. */
23
+ sourceBlockIndex: number;
24
+ }
25
+
26
+ /** A block enriched with extraction analysis. */
27
+ export interface AnalyzedBlock {
28
+ /** The original block. */
29
+ block: Block;
30
+ /** Plain text extracted from the block's contents. */
31
+ plainText: string;
32
+ /** Content extractions found in the block's text. */
33
+ extractions: ExtractedElement[];
34
+ /** Whether this block has child blocks. */
35
+ hasChildren: boolean;
36
+ /** Word count of the block's body text. */
37
+ bodyWordCount: number;
38
+ /** Images found in this block's markdown contents. */
39
+ images: BlockImage[];
40
+ }
41
+
42
+ /**
43
+ * Extract plain text from an array of MarkdownBlockNodes.
44
+ */
45
+ function contentsToPlainText(contents: MarkdownBlockNode[]): string {
46
+ return contents.map((node) => extractPlainText(node)).join('\n');
47
+ }
48
+
49
+ /**
50
+ * Recursively walk a markdown node tree and collect all images.
51
+ */
52
+ function collectImages(node: MarkdownNode): Array<{ src: string; alt: string }> {
53
+ const results: Array<{ src: string; alt: string }> = [];
54
+
55
+ if ('type' in node && node.type === 'image' && 'url' in node) {
56
+ const img = node as { url: string; alt?: string };
57
+ if (img.url) {
58
+ results.push({ src: img.url, alt: img.alt ?? '' });
59
+ }
60
+ }
61
+
62
+ for (const child of getChildren(node)) {
63
+ results.push(...collectImages(child));
64
+ }
65
+
66
+ return results;
67
+ }
68
+
69
+ /**
70
+ * Extract images from a block's markdown contents.
71
+ */
72
+ function extractBlockImages(block: Block, blockIndex: number): BlockImage[] {
73
+ if (!block.contents || block.contents.length === 0) return [];
74
+
75
+ const images: BlockImage[] = [];
76
+ for (const node of block.contents) {
77
+ for (const img of collectImages(node)) {
78
+ images.push({ ...img, sourceBlockIndex: blockIndex });
79
+ }
80
+ }
81
+ return images;
82
+ }
83
+
84
+ /**
85
+ * Collect all unique images from all blocks in a Doc.
86
+ * Returns them as TransformImages for use in the transform pipeline.
87
+ */
88
+ export function extractDocImages(blocks: Block[]): TransformImage[] {
89
+ const seen = new Set<string>();
90
+ const images: TransformImage[] = [];
91
+
92
+ function walk(blockList: Block[]): void {
93
+ for (const block of blockList) {
94
+ if (block.contents) {
95
+ for (const node of block.contents) {
96
+ for (const img of collectImages(node)) {
97
+ if (!seen.has(img.src)) {
98
+ seen.add(img.src);
99
+ images.push({ src: img.src, alt: img.alt });
100
+ }
101
+ }
102
+ }
103
+ }
104
+ if (block.children) {
105
+ walk(block.children);
106
+ }
107
+ }
108
+ }
109
+
110
+ walk(blocks);
111
+ return images;
112
+ }
113
+
114
+ /**
115
+ * Collect leaf blocks from a nested block tree.
116
+ * Only returns blocks that have their own `contents` but no children,
117
+ * preventing parent blocks from duplicating text that also appears
118
+ * in their children. Parent-only blocks (with a title but no body
119
+ * content) are included as structural placeholders.
120
+ */
121
+ function collectLeafBlocks(blocks: Block[]): Block[] {
122
+ const result: Block[] = [];
123
+ for (const block of blocks) {
124
+ if (block.children && block.children.length > 0) {
125
+ // Parent block — only include it as a structural marker
126
+ // (title only, no body extraction) if it has no contents of its own.
127
+ // Then recurse into children for the actual content.
128
+ if (!block.contents || block.contents.length === 0) {
129
+ result.push(block);
130
+ }
131
+ result.push(...collectLeafBlocks(block.children));
132
+ } else {
133
+ // Leaf block — include for content analysis
134
+ result.push(block);
135
+ }
136
+ }
137
+ return result;
138
+ }
139
+
140
+ /**
141
+ * Analyze all blocks in a Doc, extracting text and running content extraction.
142
+ *
143
+ * @param blocks - The Doc's block array (may be nested via children).
144
+ * @param options - Extraction options (minConfidence, types filter).
145
+ * @returns Analyzed blocks with extractions, in flattened order.
146
+ */
147
+ export function analyzeBlocks(blocks: Block[], options?: ExtractionOptions): AnalyzedBlock[] {
148
+ const flat = collectLeafBlocks(blocks);
149
+ const results: AnalyzedBlock[] = [];
150
+
151
+ for (const block of flat) {
152
+ let plainText = '';
153
+
154
+ if (block.contents && block.contents.length > 0) {
155
+ plainText = contentsToPlainText(block.contents);
156
+ } else if (block.title) {
157
+ plainText = block.title;
158
+ }
159
+
160
+ // Strip any remaining markdown syntax
161
+ const stripped = stripMarkdown(plainText);
162
+ const bodyWordCount = stripped.split(/\s+/).filter((w) => w.length > 0).length;
163
+
164
+ // Run content extraction
165
+ const extraction = extractContent(stripped, options);
166
+
167
+ // Extract images from markdown contents
168
+ const images = extractBlockImages(block, results.length);
169
+
170
+ results.push({
171
+ block,
172
+ plainText: stripped,
173
+ extractions: extraction.elements,
174
+ hasChildren: !!(block.children && block.children.length > 0),
175
+ bodyWordCount,
176
+ images,
177
+ });
178
+ }
179
+
180
+ return results;
181
+ }
@@ -0,0 +1,20 @@
1
+ export { applyTransform } from './applyTransform.js';
2
+
3
+ export {
4
+ resolveTransformStyle,
5
+ getTransformStyleIds,
6
+ getTransformStyleSummaries,
7
+ DEFAULT_TRANSFORM_STYLE_ID,
8
+ } from './registry.js';
9
+
10
+ export type {
11
+ TransformStyleId,
12
+ TransformStyleSummary,
13
+ TransformStyleConfig,
14
+ TransformImage,
15
+ TransformOptions,
16
+ TransformResult,
17
+ } from './types.js';
18
+
19
+ export type { AnalyzedBlock, BlockImage } from './blockAnalyzer.js';
20
+ export { analyzeBlocks, extractDocImages } from './blockAnalyzer.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Transform Style Registry
3
+ *
4
+ * Central registry of built-in transform styles. Follows the same pattern
5
+ * as themeLibrary.ts — a record of configs with lookup/summary helpers.
6
+ */
7
+
8
+ import type { TransformStyleConfig, TransformStyleSummary } from './types.js';
9
+ import { documentaryStyle } from './styles/documentary.js';
10
+ import { magazineStyle } from './styles/magazine.js';
11
+ import { dataDrivenStyle } from './styles/dataDriven.js';
12
+ import { narrativeStyle } from './styles/narrative.js';
13
+ import { minimalStyle } from './styles/minimal.js';
14
+
15
+ /** All registered transform styles, keyed by id. */
16
+ const TRANSFORM_STYLES: Record<string, TransformStyleConfig> = {
17
+ [documentaryStyle.id]: documentaryStyle,
18
+ [magazineStyle.id]: magazineStyle,
19
+ [dataDrivenStyle.id]: dataDrivenStyle,
20
+ [narrativeStyle.id]: narrativeStyle,
21
+ [minimalStyle.id]: minimalStyle,
22
+ };
23
+
24
+ /** Default style used when no id is provided. */
25
+ export const DEFAULT_TRANSFORM_STYLE_ID = 'documentary';
26
+
27
+ /**
28
+ * Resolve a transform style by id.
29
+ * Returns the default style if the id is not found.
30
+ */
31
+ export function resolveTransformStyle(id: string): TransformStyleConfig {
32
+ return TRANSFORM_STYLES[id] ?? TRANSFORM_STYLES[DEFAULT_TRANSFORM_STYLE_ID];
33
+ }
34
+
35
+ /** Get all registered style ids. */
36
+ export function getTransformStyleIds(): string[] {
37
+ return Object.keys(TRANSFORM_STYLES);
38
+ }
39
+
40
+ /** Get summary info for all styles (for UI dropdowns). */
41
+ export function getTransformStyleSummaries(): TransformStyleSummary[] {
42
+ return Object.values(TRANSFORM_STYLES).map(({ id, name, description }) => ({
43
+ id,
44
+ name,
45
+ description,
46
+ }));
47
+ }
@@ -0,0 +1,16 @@
1
+ import type { TransformStyleConfig } from '../types.js';
2
+
3
+ /** Numbers-forward — aggressively extracts stats, comparisons, and dates. */
4
+ export const dataDrivenStyle: TransformStyleConfig = {
5
+ id: 'data-driven',
6
+ name: 'Data-Driven',
7
+ description: 'Aggressively highlights statistics, comparisons, and timelines',
8
+ minConfidence: 0.3,
9
+ transformRatio: 0.8,
10
+ preferredTypes: ['stat', 'comparison', 'date', 'list', 'fact'],
11
+ colorSchemes: ['blue', 'orange', 'green', 'purple', 'red'],
12
+ insertSectionHeaders: true,
13
+ interleaveImages: false,
14
+ blocksPerSection: { min: 2, max: 6 },
15
+ transitionStyle: 'cut',
16
+ };
@@ -0,0 +1,16 @@
1
+ import type { TransformStyleConfig } from '../types.js';
2
+
3
+ /** Conservative style — sparse highlights, preserves most text as-is. */
4
+ export const documentaryStyle: TransformStyleConfig = {
5
+ id: 'documentary',
6
+ name: 'Documentary',
7
+ description: 'Conservative — highlights only the strongest stats, dates, and quotes',
8
+ minConfidence: 0.5,
9
+ transformRatio: 0.3,
10
+ preferredTypes: ['stat', 'date', 'quote', 'fact'],
11
+ colorSchemes: ['blue', 'green', 'purple'],
12
+ insertSectionHeaders: false,
13
+ interleaveImages: true,
14
+ blocksPerSection: { min: 1, max: 3 },
15
+ transitionStyle: 'fade',
16
+ };
@@ -0,0 +1,5 @@
1
+ export { documentaryStyle } from './documentary.js';
2
+ export { magazineStyle } from './magazine.js';
3
+ export { dataDrivenStyle } from './dataDriven.js';
4
+ export { narrativeStyle } from './narrative.js';
5
+ export { minimalStyle } from './minimal.js';
@@ -0,0 +1,16 @@
1
+ import type { TransformStyleConfig } from '../types.js';
2
+
3
+ /** Visual variety — pull quotes, definitions, image-heavy layout. */
4
+ export const magazineStyle: TransformStyleConfig = {
5
+ id: 'magazine',
6
+ name: 'Magazine',
7
+ description: 'Visual variety with pull quotes, facts, and rich image layouts',
8
+ minConfidence: 0.4,
9
+ transformRatio: 0.6,
10
+ preferredTypes: ['quote', 'fact', 'list', 'definition', 'stat', 'impactLine'],
11
+ colorSchemes: ['blue', 'green', 'purple', 'orange', 'red'],
12
+ insertSectionHeaders: true,
13
+ interleaveImages: true,
14
+ blocksPerSection: { min: 2, max: 5 },
15
+ transitionStyle: 'dissolve',
16
+ };
@@ -0,0 +1,16 @@
1
+ import type { TransformStyleConfig } from '../types.js';
2
+
3
+ /** Light touch — only the highest-confidence items get transformed. */
4
+ export const minimalStyle: TransformStyleConfig = {
5
+ id: 'minimal',
6
+ name: 'Minimal',
7
+ description: 'Light touch — only the strongest highlights, mostly text',
8
+ minConfidence: 0.6,
9
+ transformRatio: 0.2,
10
+ preferredTypes: ['stat', 'quote'],
11
+ colorSchemes: ['blue', 'green'],
12
+ insertSectionHeaders: false,
13
+ interleaveImages: false,
14
+ blocksPerSection: { min: 1, max: 2 },
15
+ transitionStyle: 'fade',
16
+ };
@@ -0,0 +1,16 @@
1
+ import type { TransformStyleConfig } from '../types.js';
2
+
3
+ /** Timeline-focused — emphasizes dates, quotes, and story arc. */
4
+ export const narrativeStyle: TransformStyleConfig = {
5
+ id: 'narrative',
6
+ name: 'Narrative',
7
+ description: 'Story-driven with timeline events, quotes, and impact moments',
8
+ minConfidence: 0.4,
9
+ transformRatio: 0.5,
10
+ preferredTypes: ['date', 'quote', 'impactLine', 'fact', 'stat'],
11
+ colorSchemes: ['blue', 'purple', 'green'],
12
+ insertSectionHeaders: true,
13
+ interleaveImages: true,
14
+ blocksPerSection: { min: 1, max: 4 },
15
+ transitionStyle: 'fade',
16
+ };