@bendyline/squisq 1.4.1 → 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 (254) 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-BeSeH2iX.d.ts → Doc-BBVGq1_9.d.ts} +922 -273
  4. package/dist/{ImageEditDoc-BTIvw0oq.d.ts → ImageEditDoc-FuyGtt6o.d.ts} +11 -4
  5. package/dist/{chunk-ZTX4PFFT.js → chunk-2OIBZYKP.js} +75 -2
  6. package/dist/chunk-2OIBZYKP.js.map +1 -0
  7. package/dist/chunk-2UQOHYE2.js +45 -0
  8. package/dist/chunk-2UQOHYE2.js.map +1 -0
  9. package/dist/chunk-6ATE2PSM.js +344 -0
  10. package/dist/chunk-6ATE2PSM.js.map +1 -0
  11. package/dist/{chunk-57CVQCFX.js → chunk-A4O7GIWE.js} +74 -23
  12. package/dist/chunk-A4O7GIWE.js.map +1 -0
  13. package/dist/{chunk-5WFRKURX.js → chunk-DLXZMS5K.js} +4 -2
  14. package/dist/chunk-DLXZMS5K.js.map +1 -0
  15. package/dist/chunk-ET53IIEP.js +1 -0
  16. package/dist/chunk-ET53IIEP.js.map +1 -0
  17. package/dist/chunk-HWVFJAAH.js +362 -0
  18. package/dist/chunk-HWVFJAAH.js.map +1 -0
  19. package/dist/{chunk-2TMAWB4Y.js → chunk-IMSCRLLV.js} +1 -1
  20. package/dist/chunk-IMSCRLLV.js.map +1 -0
  21. package/dist/{chunk-B4EEON3N.js → chunk-KKNUBQ6Y.js} +536 -103
  22. package/dist/chunk-KKNUBQ6Y.js.map +1 -0
  23. package/dist/chunk-LDQ2HJIX.js +596 -0
  24. package/dist/chunk-LDQ2HJIX.js.map +1 -0
  25. package/dist/chunk-LH7I6SH7.js +7208 -0
  26. package/dist/chunk-LH7I6SH7.js.map +1 -0
  27. package/dist/chunk-PGGGKYWG.js +1 -0
  28. package/dist/chunk-PGGGKYWG.js.map +1 -0
  29. package/dist/{chunk-7UDSRZKG.js → chunk-Q3ROPT5H.js} +35 -14
  30. package/dist/chunk-Q3ROPT5H.js.map +1 -0
  31. package/dist/chunk-QE7TWGVT.js +178 -0
  32. package/dist/chunk-QE7TWGVT.js.map +1 -0
  33. package/dist/chunk-RUDYOTA6.js +345 -0
  34. package/dist/chunk-RUDYOTA6.js.map +1 -0
  35. package/dist/{chunk-K32VJONL.js → chunk-T5UK6YOB.js} +41 -2
  36. package/dist/chunk-T5UK6YOB.js.map +1 -0
  37. package/dist/{chunk-3K5OG6KI.js → chunk-TEEEILMP.js} +412 -186
  38. package/dist/chunk-TEEEILMP.js.map +1 -0
  39. package/dist/{chunk-FR2RBTKO.js → chunk-TQWLI6S2.js} +93 -27
  40. package/dist/chunk-TQWLI6S2.js.map +1 -0
  41. package/dist/{chunk-WMOI7FN3.js → chunk-UY7KGQ5R.js} +12 -2
  42. package/dist/{chunk-WMOI7FN3.js.map → chunk-UY7KGQ5R.js.map} +1 -1
  43. package/dist/{chunk-3E5F2XMR.js → chunk-VWUFZ6ZG.js} +29 -2
  44. package/dist/chunk-VWUFZ6ZG.js.map +1 -0
  45. package/dist/chunk-ZLQKNOZQ.js +1 -0
  46. package/dist/chunk-ZLQKNOZQ.js.map +1 -0
  47. package/dist/doc/index.d.ts +5 -5
  48. package/dist/doc/index.js +135 -8
  49. package/dist/generate/index.d.ts +3 -74
  50. package/dist/generate/index.js +2 -7
  51. package/dist/icons/index.d.ts +3 -26
  52. package/dist/icons/index.js +13 -0
  53. package/dist/icons/inlineIconMarker.d.ts +1 -0
  54. package/dist/icons/inlineIconMarker.js +15 -0
  55. package/dist/icons/inlineIconMarker.js.map +1 -0
  56. package/dist/imageEdit/index.d.ts +12 -6
  57. package/dist/imageEdit/index.js +4 -1
  58. package/dist/index.d.ts +14 -11
  59. package/dist/index.js +265 -37
  60. package/dist/inlineIconMarker-CiE8Hlvz.d.ts +59 -0
  61. package/dist/jsonForm/index.d.ts +42 -1
  62. package/dist/jsonForm/index.js +9 -1
  63. package/dist/markdown/index.d.ts +228 -3
  64. package/dist/markdown/index.js +42 -7
  65. package/dist/recommend/index.d.ts +1 -1
  66. package/dist/recommend/index.js +3 -2
  67. package/dist/schemas/index.d.ts +28 -8
  68. package/dist/schemas/index.js +36 -8
  69. package/dist/spatial/index.d.ts +9 -4
  70. package/dist/spatial/index.js +1 -1
  71. package/dist/storage/index.d.ts +2 -2
  72. package/dist/storage/index.js +1 -1
  73. package/dist/story/index.d.ts +1021 -41
  74. package/dist/story/index.js +135 -8
  75. package/dist/{themeLibrary-BHjJ0Qx6.d.ts → themeLibrary-CehcJhzz.d.ts} +1 -1
  76. package/dist/timing/index.js +3 -5
  77. package/dist/transform/index.d.ts +48 -10
  78. package/dist/transform/index.js +17 -481
  79. package/dist/transform/index.js.map +1 -1
  80. package/dist/{types-BdZkdJ3z.d.ts → types-DlAZ7MW4.d.ts} +115 -1
  81. package/dist/versions/index.d.ts +1 -1
  82. package/package.json +6 -1
  83. package/src/__tests__/animationUtils.test.ts +40 -0
  84. package/src/__tests__/annotationCoercion.test.ts +243 -0
  85. package/src/__tests__/applyRenderStyle.test.ts +146 -0
  86. package/src/__tests__/atmosphereLayers.test.ts +108 -0
  87. package/src/__tests__/attrTokens.test.ts +162 -0
  88. package/src/__tests__/contentExtractor.test.ts +60 -0
  89. package/src/__tests__/coverBlock.test.ts +46 -1
  90. package/src/__tests__/customTemplateSample.test.ts +144 -0
  91. package/src/__tests__/customTemplatesFrontmatter.test.ts +236 -0
  92. package/src/__tests__/customThemesFrontmatter.test.ts +145 -0
  93. package/src/__tests__/diagramBlock.test.ts +122 -0
  94. package/src/__tests__/diagramLayout.test.ts +134 -0
  95. package/src/__tests__/drawing.test.ts +109 -0
  96. package/src/__tests__/drawingBlock.test.ts +124 -0
  97. package/src/__tests__/drawingLayout.test.ts +171 -0
  98. package/src/__tests__/geohash.test.ts +6 -5
  99. package/src/__tests__/getLayers.test.ts +6 -2
  100. package/src/__tests__/getLayersFallback.test.ts +103 -0
  101. package/src/__tests__/imageEditExportSvg.test.ts +70 -0
  102. package/src/__tests__/imageEditVersions.test.ts +72 -0
  103. package/src/__tests__/inlineIconMarker.test.ts +36 -0
  104. package/src/__tests__/inputDescriptors.test.ts +162 -0
  105. package/src/__tests__/jsonForm.tokens.test.ts +84 -0
  106. package/src/__tests__/layoutBlock.test.ts +83 -0
  107. package/src/__tests__/layoutLayout.test.ts +169 -0
  108. package/src/__tests__/markdown.test.ts +87 -0
  109. package/src/__tests__/markdownSanitize.test.ts +79 -0
  110. package/src/__tests__/markdownToDoc.test.ts +391 -2
  111. package/src/__tests__/mediaAnnotations.test.ts +91 -0
  112. package/src/__tests__/mediaSchedule.test.ts +118 -0
  113. package/src/__tests__/pandocAttrParse.test.ts +187 -0
  114. package/src/__tests__/resolveDocTheme.test.ts +55 -0
  115. package/src/__tests__/rootExports.test.ts +43 -0
  116. package/src/__tests__/shapeGeometry.test.ts +89 -0
  117. package/src/__tests__/shapeVocabulary.test.ts +133 -0
  118. package/src/__tests__/structuredData.test.ts +249 -0
  119. package/src/__tests__/templateAnnotationParse.test.ts +108 -0
  120. package/src/__tests__/templateMetadata.test.ts +31 -0
  121. package/src/__tests__/templates.test.ts +257 -4
  122. package/src/__tests__/themeCompile.test.ts +42 -0
  123. package/src/__tests__/themeValidator.test.ts +6 -0
  124. package/src/__tests__/transformV2.test.ts +137 -0
  125. package/src/__tests__/transitionNormalize.test.ts +61 -0
  126. package/src/__tests__/validateDoc.test.ts +260 -0
  127. package/src/doc/annotationBlocks.ts +117 -0
  128. package/src/doc/customTemplatesFrontmatter.ts +314 -0
  129. package/src/doc/customThemesFrontmatter.ts +95 -0
  130. package/src/doc/docToMarkdown.ts +104 -5
  131. package/src/doc/getLayers.ts +49 -17
  132. package/src/doc/index.ts +47 -1
  133. package/src/doc/markdownToDoc.ts +411 -13
  134. package/src/doc/mediaAnnotations.ts +100 -0
  135. package/src/doc/resolveDocTheme.ts +55 -0
  136. package/src/doc/standaloneAnnotation.ts +58 -0
  137. package/src/doc/structuredData.ts +301 -0
  138. package/src/doc/templateInputs.ts +240 -0
  139. package/src/doc/templates/__tests__/customTemplate.test.ts +170 -0
  140. package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +110 -0
  141. package/src/doc/templates/accentImage.ts +30 -6
  142. package/src/doc/templates/captionUtils.ts +23 -0
  143. package/src/doc/templates/comparisonBar.ts +33 -18
  144. package/src/doc/templates/coverBlock.ts +35 -5
  145. package/src/doc/templates/customTemplate.ts +51 -0
  146. package/src/doc/templates/dataTable.ts +37 -19
  147. package/src/doc/templates/dateEvent.ts +41 -20
  148. package/src/doc/templates/definitionCard.ts +26 -18
  149. package/src/doc/templates/diagramBlock.ts +204 -0
  150. package/src/doc/templates/diagramLayout.ts +159 -0
  151. package/src/doc/templates/drawingBlock.ts +325 -0
  152. package/src/doc/templates/drawingLayout.ts +539 -0
  153. package/src/doc/templates/factCard.ts +54 -26
  154. package/src/doc/templates/fallbackBlock.ts +123 -0
  155. package/src/doc/templates/featureBlock.ts +20 -13
  156. package/src/doc/templates/fullBleedQuote.ts +18 -8
  157. package/src/doc/templates/imageWithCaption.ts +30 -15
  158. package/src/doc/templates/index.ts +225 -46
  159. package/src/doc/templates/inputDescriptors.ts +432 -0
  160. package/src/doc/templates/layoutBlock.ts +43 -0
  161. package/src/doc/templates/layoutLayout.ts +243 -0
  162. package/src/doc/templates/listBlock.ts +56 -30
  163. package/src/doc/templates/mapBlock.ts +15 -12
  164. package/src/doc/templates/metadata.ts +120 -0
  165. package/src/doc/templates/persistentLayers.ts +129 -11
  166. package/src/doc/templates/photoGrid.ts +22 -34
  167. package/src/doc/templates/pullQuote.ts +30 -12
  168. package/src/doc/templates/quoteBlock.ts +54 -29
  169. package/src/doc/templates/sectionHeader.ts +25 -11
  170. package/src/doc/templates/statHighlight.ts +39 -22
  171. package/src/doc/templates/titleBlock.ts +59 -21
  172. package/src/doc/templates/tokens/__tests__/resolveTokens.test.ts +487 -0
  173. package/src/doc/templates/tokens/resolveTokens.ts +453 -0
  174. package/src/doc/templates/twoColumn.ts +48 -30
  175. package/src/doc/templates/videoPullQuote.ts +22 -12
  176. package/src/doc/templates/videoWithCaption.ts +21 -15
  177. package/src/doc/utils/animationUtils.ts +267 -3
  178. package/src/doc/utils/applyRenderStyle.ts +113 -0
  179. package/src/doc/utils/imageTreatment.ts +70 -0
  180. package/src/doc/utils/nearest.ts +59 -0
  181. package/src/doc/utils/shapeGeometry.ts +464 -0
  182. package/src/doc/utils/themeUtils.ts +75 -1
  183. package/src/doc/validate.ts +575 -0
  184. package/src/generate/contentExtractor.ts +148 -35
  185. package/src/generate/index.ts +0 -3
  186. package/src/icons/index.ts +8 -0
  187. package/src/icons/inlineIconMarker.ts +73 -0
  188. package/src/imageEdit/export.ts +85 -2
  189. package/src/imageEdit/index.ts +1 -0
  190. package/src/imageEdit/persistence.ts +51 -0
  191. package/src/index.ts +2 -0
  192. package/src/jsonForm/index.ts +2 -0
  193. package/src/jsonForm/tokens.ts +78 -0
  194. package/src/markdown/annotationCoercion.ts +295 -0
  195. package/src/markdown/attrTokens.ts +241 -0
  196. package/src/markdown/convert.ts +229 -26
  197. package/src/markdown/index.ts +37 -0
  198. package/src/markdown/sanitize.ts +318 -0
  199. package/src/markdown/stringify.ts +96 -6
  200. package/src/markdown/types.ts +66 -0
  201. package/src/markdown/utils.ts +111 -2
  202. package/src/recommend/templates.ts +24 -0
  203. package/src/schemas/BlockTemplates.ts +133 -4
  204. package/src/schemas/CustomTemplates.ts +126 -0
  205. package/src/schemas/Doc.ts +387 -65
  206. package/src/schemas/ImageEditDoc.ts +11 -4
  207. package/src/schemas/Media.ts +169 -0
  208. package/src/schemas/Theme.ts +23 -1
  209. package/src/schemas/Transitions.ts +224 -0
  210. package/src/schemas/colorUtils.ts +33 -0
  211. package/src/schemas/fontStacks.ts +5 -2
  212. package/src/schemas/index.ts +3 -0
  213. package/src/schemas/themeCompile.ts +24 -5
  214. package/src/schemas/themeValidator.ts +49 -11
  215. package/src/schemas/themes/cinematic.json +69 -12
  216. package/src/schemas/themes/documentary.json +58 -11
  217. package/src/schemas/themes/gezellig.json +60 -11
  218. package/src/schemas/themes/magazine.json +54 -9
  219. package/src/schemas/themes/morning-light.json +52 -9
  220. package/src/schemas/themes/standard-dark.json +48 -13
  221. package/src/schemas/themes/standard.json +44 -12
  222. package/src/schemas/themes/tech-dark.json +65 -12
  223. package/src/spatial/Geohash.ts +52 -21
  224. package/src/storage/ContentContainer.ts +6 -2
  225. package/src/transform/applyTransform.ts +43 -4
  226. package/src/transform/index.ts +1 -0
  227. package/src/transform/registry.ts +44 -13
  228. package/src/transform/styles/dataDriven.ts +2 -1
  229. package/src/transform/styles/documentary.ts +2 -1
  230. package/src/transform/styles/magazine.ts +3 -1
  231. package/src/transform/styles/minimal.ts +2 -1
  232. package/src/transform/styles/narrative.ts +3 -1
  233. package/src/transform/templateSelector.ts +87 -11
  234. package/src/transform/types.ts +35 -2
  235. package/dist/chunk-2TMAWB4Y.js.map +0 -1
  236. package/dist/chunk-3E5F2XMR.js.map +0 -1
  237. package/dist/chunk-3K5OG6KI.js.map +0 -1
  238. package/dist/chunk-4X3JQXNM.js +0 -35
  239. package/dist/chunk-4X3JQXNM.js.map +0 -1
  240. package/dist/chunk-57CVQCFX.js.map +0 -1
  241. package/dist/chunk-5WFRKURX.js.map +0 -1
  242. package/dist/chunk-7UDSRZKG.js.map +0 -1
  243. package/dist/chunk-B4EEON3N.js.map +0 -1
  244. package/dist/chunk-FR2RBTKO.js.map +0 -1
  245. package/dist/chunk-H3AXU4MJ.js +0 -179
  246. package/dist/chunk-H3AXU4MJ.js.map +0 -1
  247. package/dist/chunk-K32VJONL.js.map +0 -1
  248. package/dist/chunk-KSWJR66U.js +0 -3706
  249. package/dist/chunk-KSWJR66U.js.map +0 -1
  250. package/dist/chunk-MYIH7FWD.js +0 -145
  251. package/dist/chunk-MYIH7FWD.js.map +0 -1
  252. package/dist/chunk-ZTX4PFFT.js.map +0 -1
  253. package/src/__tests__/slideshowGenerator.test.ts +0 -128
  254. package/src/generate/slideshowGenerator.ts +0 -273
@@ -0,0 +1,133 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { computeDrawingLayout } from '../doc/templates/drawingLayout.js';
3
+ import { drawingBlock } from '../doc/templates/drawingBlock.js';
4
+ import { diagramBlock } from '../doc/templates/diagramBlock.js';
5
+ import { createTemplateContext } from '../schemas/BlockTemplates.js';
6
+ import { DEFAULT_THEME } from '../schemas/themeLibrary.js';
7
+ import { VIEWPORT_PRESETS } from '../schemas/Viewport.js';
8
+ import type { Block, PathLayer } from '../schemas/Doc.js';
9
+ import type { DiagramBlockInput } from '../schemas/BlockTemplates.js';
10
+
11
+ function shape(id: string, template: string, overrides: Record<string, string> = {}): Block {
12
+ return {
13
+ id,
14
+ startTime: 0,
15
+ duration: 0,
16
+ audioSegment: 0,
17
+ template,
18
+ templateOverrides: overrides,
19
+ } as Block;
20
+ }
21
+
22
+ function ctx(children: Block[]) {
23
+ const c = createTemplateContext(DEFAULT_THEME, 0, 1, VIEWPORT_PRESETS.landscape);
24
+ c.children = children;
25
+ return c;
26
+ }
27
+
28
+ describe('drawing shape vocabulary', () => {
29
+ it('recognizes new polygon kinds and aliases', () => {
30
+ const layout = computeDrawingLayout([
31
+ shape('s', 'star', { x: '0', y: '0' }),
32
+ shape('h', 'hexagon', { x: '0', y: '0' }),
33
+ shape('r', 'rhombus', { x: '0', y: '0' }), // alias → diamond
34
+ shape('a', 'rightarrow', { x: '0', y: '0' }), // alias → arrow-right
35
+ ]);
36
+ const kinds = layout.shapes.map((s) => s.kind);
37
+ expect(kinds).toEqual(['star', 'hexagon', 'diamond', 'arrow-right']);
38
+ });
39
+
40
+ it('renders a polygon kind as a PathLayer in the block', () => {
41
+ const layers = drawingBlock(
42
+ { template: 'drawing', id: 'd', duration: 0, audioSegment: 0 },
43
+ ctx([shape('s', 'star', { x: '10', y: '10', width: '100', height: '100' })]),
44
+ );
45
+ const star = layers.find((l) => l.id === 'shape-s');
46
+ expect(star?.type).toBe('path');
47
+ });
48
+ });
49
+
50
+ describe('drawing connector semantics', () => {
51
+ function conn(overrides: Record<string, string>) {
52
+ return computeDrawingLayout([
53
+ shape('a', 'rect', { x: '0', y: '0', width: '50', height: '50' }),
54
+ shape('b', 'rect', { x: '0', y: '200', width: '50', height: '50' }),
55
+ shape('c', 'arrow', { from: 'a', to: 'b', ...overrides }),
56
+ ]).connectors[0];
57
+ }
58
+
59
+ it('parses end/start markers, line style, and routing', () => {
60
+ expect(
61
+ conn({
62
+ endStyle: 'diamond',
63
+ startStyle: 'circle',
64
+ lineStyle: 'dashed',
65
+ routing: 'orthogonal',
66
+ }),
67
+ ).toMatchObject({
68
+ endMarker: 'diamond',
69
+ startMarker: 'circle',
70
+ dasharray: '8 6',
71
+ routing: 'orthogonal',
72
+ });
73
+ });
74
+
75
+ it('defaults arrow → end arrow, line → no marker, straight routing', () => {
76
+ expect(conn({})).toMatchObject({
77
+ endMarker: 'arrow',
78
+ startMarker: 'none',
79
+ routing: 'straight',
80
+ });
81
+ const line = computeDrawingLayout([
82
+ shape('a', 'rect', { x: '0', y: '0', width: '50', height: '50' }),
83
+ shape('b', 'rect', { x: '0', y: '200', width: '50', height: '50' }),
84
+ shape('l', 'line', { from: 'a', to: 'b' }),
85
+ ]).connectors[0];
86
+ expect(line.endMarker).toBe('none');
87
+ });
88
+
89
+ it('emits the marker + dash on the rendered connector PathLayer', () => {
90
+ const layers = drawingBlock(
91
+ { template: 'drawing', id: 'd', duration: 0, audioSegment: 0 },
92
+ ctx([
93
+ shape('a', 'rect', { x: '0', y: '0', width: '50', height: '50' }),
94
+ shape('b', 'rect', { x: '0', y: '200', width: '50', height: '50' }),
95
+ shape('c', 'arrow', { from: 'a', to: 'b', endStyle: 'diamond', lineStyle: 'dashed' }),
96
+ ]),
97
+ );
98
+ const connector = layers.find((l) => l.id === 'connector-c') as PathLayer | undefined;
99
+ expect(connector?.content.endMarker).toBe('diamond');
100
+ expect(connector?.content.dasharray).toBe('8 6');
101
+ });
102
+ });
103
+
104
+ describe('diagram edge styles', () => {
105
+ function node(id: string, x: number, y: number, connectsTo?: string): Block {
106
+ return {
107
+ id,
108
+ startTime: 0,
109
+ duration: 0,
110
+ audioSegment: 0,
111
+ x,
112
+ y,
113
+ ...(connectsTo ? { connectsTo: [{ target: connectsTo }] } : {}),
114
+ } as Block;
115
+ }
116
+
117
+ it('applies endStyle and lineStyle to all edges', () => {
118
+ const c = createTemplateContext(DEFAULT_THEME, 0, 1, VIEWPORT_PRESETS.landscape);
119
+ c.children = [node('a', 0, 0, 'b'), node('b', 300, 0)];
120
+ const input: DiagramBlockInput = {
121
+ template: 'diagram',
122
+ id: 'g',
123
+ duration: 0,
124
+ audioSegment: 0,
125
+ endStyle: 'circle',
126
+ lineStyle: 'dashed',
127
+ };
128
+ const layers = diagramBlock(input, c);
129
+ const edge = layers.find((l) => l.id.startsWith('edge-')) as PathLayer | undefined;
130
+ expect(edge?.content.endMarker).toBe('circle');
131
+ expect(edge?.content.dasharray).toBe('8 6');
132
+ });
133
+ });
@@ -0,0 +1,249 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { parseMarkdown } from '../markdown/parse.js';
3
+ import { markdownToDoc } from '../doc/markdownToDoc.js';
4
+ import { parseYamlSubset, replaceDataFence } from '../doc/structuredData.js';
5
+ import type { MarkdownCodeBlock } from '../markdown/types.js';
6
+
7
+ function toDoc(md: string) {
8
+ return markdownToDoc(parseMarkdown(md));
9
+ }
10
+
11
+ describe('parseYamlSubset', () => {
12
+ it('parses scalars with type coercion', () => {
13
+ expect(parseYamlSubset('title: Hello world\ncount: 3\nlive: true\nnothing: null')).toEqual({
14
+ title: 'Hello world',
15
+ count: 3,
16
+ live: true,
17
+ nothing: null,
18
+ });
19
+ });
20
+
21
+ it('parses inline arrays', () => {
22
+ expect(parseYamlSubset('headers: [Name, Age]')).toEqual({ headers: ['Name', 'Age'] });
23
+ });
24
+
25
+ it('parses block sequences of scalars and inline arrays', () => {
26
+ expect(
27
+ parseYamlSubset('rows:\n - [Alice, 30]\n - [Bob, 25]\nmarkers:\n - "47.6,-122.3"'),
28
+ ).toEqual({
29
+ rows: [
30
+ ['Alice', 30],
31
+ ['Bob', 25],
32
+ ],
33
+ markers: ['47.6,-122.3'],
34
+ });
35
+ });
36
+
37
+ it('preserves quoted strings (commas, numbers stay strings)', () => {
38
+ expect(parseYamlSubset('label: "1,234"')).toEqual({ label: '1,234' });
39
+ });
40
+
41
+ it('skips comments and blank lines', () => {
42
+ expect(parseYamlSubset('# comment\n\nkey: value')).toEqual({ key: 'value' });
43
+ });
44
+
45
+ it('parses one level of nested mapping', () => {
46
+ expect(parseYamlSubset('center:\n lat: 47.6\n lng: -122.3\nzoom: 12')).toEqual({
47
+ center: { lat: 47.6, lng: -122.3 },
48
+ zoom: 12,
49
+ });
50
+ });
51
+
52
+ it('rejects nesting deeper than one level with a line-anchored error', () => {
53
+ expect(() => parseYamlSubset('a:\n b:\n c: 1')).toThrow(/line 2/);
54
+ expect(() => parseYamlSubset('a:\n b: 1\n c: 2')).toThrow(/line 3/);
55
+ });
56
+
57
+ it('rejects mixing list items and mapping keys under one key', () => {
58
+ expect(() => parseYamlSubset('a:\n - x\n b: 1')).toThrow(/mix/);
59
+ expect(() => parseYamlSubset('a:\n b: 1\n - x')).toThrow(/mix/);
60
+ });
61
+ });
62
+
63
+ describe('data fences → block.templateData', () => {
64
+ it('parses a ```json data fence into templateData', () => {
65
+ const md = [
66
+ '## Numbers {[dataTable]}',
67
+ '',
68
+ '```json data',
69
+ '{ "headers": ["Q", "Revenue"], "rows": [["Q1", "1.2M"]] }',
70
+ '```',
71
+ ].join('\n');
72
+ const doc = toDoc(md);
73
+ expect(doc.blocks[0].templateData).toEqual({
74
+ headers: ['Q', 'Revenue'],
75
+ rows: [['Q1', '1.2M']],
76
+ });
77
+ expect(doc.diagnostics).toBeUndefined();
78
+ });
79
+
80
+ it('parses a ```yaml data fence into templateData', () => {
81
+ const md = [
82
+ '## Map {[map]}',
83
+ '',
84
+ '```yaml data',
85
+ 'zoom: 12',
86
+ 'markers:',
87
+ ' - "47.6,-122.3"',
88
+ '```',
89
+ ].join('\n');
90
+ const doc = toDoc(md);
91
+ expect(doc.blocks[0].templateData).toEqual({ zoom: 12, markers: ['47.6,-122.3'] });
92
+ });
93
+
94
+ it('ignores plain ```json fences without the data marker', () => {
95
+ const md = '## Code {[sectionHeader]}\n\n```json\n{ "just": "a sample" }\n```';
96
+ const doc = toDoc(md);
97
+ expect(doc.blocks[0].templateData).toBeUndefined();
98
+ });
99
+
100
+ it('records a diagnostic for unparseable fences and degrades gracefully', () => {
101
+ const md = '## Bad {[dataTable]}\n\n```json data\n{ not valid json\n```';
102
+ const doc = toDoc(md);
103
+ expect(doc.blocks[0].templateData).toBeUndefined();
104
+ expect(doc.diagnostics).toHaveLength(1);
105
+ expect(doc.diagnostics![0]).toMatchObject({ severity: 'error', code: 'data-fence-parse' });
106
+ expect(doc.diagnostics![0].line).toBe(3);
107
+ });
108
+ });
109
+
110
+ describe('replaceDataFence', () => {
111
+ it('replaces the first data fence content, keeping lang and meta', () => {
112
+ const doc = toDoc(
113
+ '## Numbers {[dataTable]}\n\nIntro.\n\n```json data\n{ "headers": ["Q"] }\n```',
114
+ );
115
+ const contents = doc.blocks[0].contents!;
116
+
117
+ const next = replaceDataFence(contents, { headers: ['Q', 'Revenue'] });
118
+
119
+ const fence = next.find((n): n is MarkdownCodeBlock => n.type === 'code')!;
120
+ expect(fence.lang).toBe('json');
121
+ expect(fence.meta).toBe('data');
122
+ expect(JSON.parse(fence.value)).toEqual({ headers: ['Q', 'Revenue'] });
123
+ // Pretty-printed, not single-line.
124
+ expect(fence.value).toContain('\n');
125
+ // Same length, other nodes untouched.
126
+ expect(next).toHaveLength(contents.length);
127
+ expect(next[0]).toBe(contents[0]);
128
+ });
129
+
130
+ it('does not mutate the input array or the original fence node', () => {
131
+ const doc = toDoc('## Numbers {[dataTable]}\n\n```json data\n{ "a": 1 }\n```');
132
+ const contents = doc.blocks[0].contents!;
133
+ const originalFence = contents.find((n): n is MarkdownCodeBlock => n.type === 'code')!;
134
+
135
+ replaceDataFence(contents, { a: 2 });
136
+
137
+ expect(originalFence.value).toBe('{ "a": 1 }');
138
+ });
139
+
140
+ it('appends a new ```json data fence when none exists', () => {
141
+ const doc = toDoc('## Numbers {[dataTable]}\n\nJust text.');
142
+ const contents = doc.blocks[0].contents!;
143
+
144
+ const next = replaceDataFence(contents, { rows: [['Q1', '1.2M']] });
145
+
146
+ expect(next).toHaveLength(contents.length + 1);
147
+ const fence = next[next.length - 1] as MarkdownCodeBlock;
148
+ expect(fence).toMatchObject({ type: 'code', lang: 'json', meta: 'data' });
149
+ expect(JSON.parse(fence.value)).toEqual({ rows: [['Q1', '1.2M']] });
150
+ });
151
+
152
+ it('treats plain code fences (no data marker) as non-fences and appends', () => {
153
+ const doc = toDoc('## Code {[sectionHeader]}\n\n```json\n{ "just": "a sample" }\n```');
154
+ const contents = doc.blocks[0].contents!;
155
+
156
+ const next = replaceDataFence(contents, { a: 1 });
157
+
158
+ // The sample fence is untouched; a data fence is appended after it.
159
+ const sample = next.find((n): n is MarkdownCodeBlock => n.type === 'code' && !n.meta)!;
160
+ expect(sample.value).toBe('{ "just": "a sample" }');
161
+ expect(next).toHaveLength(contents.length + 1);
162
+ expect((next[next.length - 1] as MarkdownCodeBlock).meta).toBe('data');
163
+ });
164
+ });
165
+
166
+ describe('dataTable eats GFM tables', () => {
167
+ const table = ['| Name | Age |', '| --- | ---: |', '| Alice | 30 |', '| Bob | 25 |'].join('\n');
168
+
169
+ it('supplies headers/rows/align from the first table in the body', () => {
170
+ const doc = toDoc(`## People {[dataTable]}\n\n${table}`);
171
+ expect(doc.blocks[0].templateData).toEqual({
172
+ headers: ['Name', 'Age'],
173
+ rows: [
174
+ ['Alice', '30'],
175
+ ['Bob', '25'],
176
+ ],
177
+ align: [null, 'right'],
178
+ });
179
+ });
180
+
181
+ it('does not extract tables for non-dataTable templates', () => {
182
+ const doc = toDoc(`## People {[sectionHeader]}\n\n${table}`);
183
+ expect(doc.blocks[0].templateData).toBeUndefined();
184
+ });
185
+
186
+ it('explicit fence data wins over the body table', () => {
187
+ const md = [
188
+ '## People {[dataTable]}',
189
+ '',
190
+ '```json data',
191
+ '{ "headers": ["X"], "rows": [["1"]] }',
192
+ '```',
193
+ '',
194
+ table,
195
+ ].join('\n');
196
+ const doc = toDoc(md);
197
+ expect(doc.blocks[0].templateData).toEqual({ headers: ['X'], rows: [['1']] });
198
+ });
199
+ });
200
+
201
+ describe('deterministic conversion', () => {
202
+ const md = '# Title\n\nSome body text.\n\n## Section {[quote]}\n\nA quote here.';
203
+
204
+ it('produces identical Docs for identical input', () => {
205
+ expect(toDoc(md)).toEqual(toDoc(md));
206
+ });
207
+
208
+ it('omits captions.generatedAt unless a timestamp is supplied', () => {
209
+ const doc = toDoc(md);
210
+ expect(doc.captions).toBeDefined();
211
+ expect(doc.captions!.generatedAt).toBeUndefined();
212
+
213
+ const stamped = markdownToDoc(parseMarkdown(md), {
214
+ captionsGeneratedAt: '2026-06-10T00:00:00.000Z',
215
+ });
216
+ expect(stamped.captions!.generatedAt).toBe('2026-06-10T00:00:00.000Z');
217
+ });
218
+ });
219
+
220
+ describe('conversion diagnostics', () => {
221
+ it('flags duplicate pinned ids', () => {
222
+ const doc = toDoc('## A {#dup}\n\n## B {#dup}');
223
+ expect(doc.diagnostics).toBeDefined();
224
+ expect(doc.diagnostics![0]).toMatchObject({ severity: 'error', code: 'duplicate-id' });
225
+ });
226
+
227
+ it('a pinned id reserves the slug so a later heading does not collide', () => {
228
+ const doc = toDoc('## Other name {#intro}\n\n## Intro');
229
+ const ids = doc.blocks.map((b) => b.id);
230
+ expect(ids[0]).toBe('intro');
231
+ expect(ids[1]).not.toBe('intro');
232
+ expect(doc.diagnostics).toBeUndefined();
233
+ });
234
+
235
+ it('flags connectsTo targets that do not resolve', () => {
236
+ const doc = toDoc('## A {#a connectsTo=ghost}\n\n## B {#b}');
237
+ expect(doc.diagnostics).toBeDefined();
238
+ expect(doc.diagnostics![0]).toMatchObject({
239
+ severity: 'warning',
240
+ code: 'unresolved-connection',
241
+ blockId: 'a',
242
+ });
243
+ });
244
+
245
+ it('resolved connections produce no diagnostics', () => {
246
+ const doc = toDoc('## A {#a connectsTo=b}\n\n## B {#b}');
247
+ expect(doc.diagnostics).toBeUndefined();
248
+ });
249
+ });
@@ -1,7 +1,15 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { parseMarkdown } from '../markdown/parse.js';
3
+ import { stringifyMarkdown } from '../markdown/stringify.js';
3
4
  import { markdownToDoc } from '../doc/markdownToDoc.js';
4
5
 
6
+ function getHeading(md: string) {
7
+ const doc = parseMarkdown(md);
8
+ const heading = doc.children[0];
9
+ if (heading.type !== 'heading') throw new Error('expected heading');
10
+ return heading;
11
+ }
12
+
5
13
  describe('Template annotation in Heading parse path', () => {
6
14
  it('parseMarkdown extracts {[template]} from a heading', () => {
7
15
  const md = '## Getting Started {[comparisonBar]}';
@@ -40,3 +48,103 @@ describe('Template annotation in Heading parse path', () => {
40
48
  expect(heading.templateAnnotation).toBeUndefined();
41
49
  });
42
50
  });
51
+
52
+ describe('Quoted values in {[…]} annotations', () => {
53
+ it('parses double-quoted values with spaces (the documented syntax)', () => {
54
+ const h = getHeading(
55
+ '## Gallery {[imageWithCaption src="photo.jpg" caption="Beach at sunset"]}',
56
+ );
57
+ expect(h.templateAnnotation).toEqual({
58
+ template: 'imageWithCaption',
59
+ params: { src: 'photo.jpg', caption: 'Beach at sunset' },
60
+ });
61
+ });
62
+
63
+ it('parses single-quoted values with spaces', () => {
64
+ const h = getHeading("## X {[quote text='A long caption']}");
65
+ expect(h.templateAnnotation?.params).toEqual({ text: 'A long caption' });
66
+ });
67
+
68
+ it('parses a quoted value containing ]', () => {
69
+ const h = getHeading('## X {[quote text="a ] b"]}');
70
+ expect(h.templateAnnotation?.params).toEqual({ text: 'a ] b' });
71
+ });
72
+
73
+ it('parses a quoted value containing commas without splitting', () => {
74
+ const h = getHeading('## X {[quote text="hello, friend"]}');
75
+ expect(h.templateAnnotation?.params).toEqual({ text: 'hello, friend' });
76
+ });
77
+
78
+ it('treats an apostrophe inside an unquoted value as literal', () => {
79
+ const h = getHeading("## X {[quote attribution=O'Brien align=left]}");
80
+ expect(h.templateAnnotation?.params).toEqual({ attribution: "O'Brien", align: 'left' });
81
+ });
82
+
83
+ it('parses a double quote inside a single-quoted value', () => {
84
+ const h = getHeading('## X {[quote text=\'She said "hi"\']}');
85
+ expect(h.templateAnnotation?.params).toEqual({ text: 'She said "hi"' });
86
+ });
87
+
88
+ it('parses backslash-escaped emphasis characters inside quoted values', () => {
89
+ // Bare * would be parsed as markdown emphasis and fragment the heading
90
+ // text run; the documented escape hatch is to backslash it. remark
91
+ // resolves the escape before annotation extraction.
92
+ const h = getHeading('## X {[quote text="a \\*b\\* c"]}');
93
+ expect(h.templateAnnotation?.params).toEqual({ text: 'a *b* c' });
94
+ });
95
+
96
+ it('parses a template-less key=value annotation with a quoted value', () => {
97
+ const h = getHeading('## X {[audio="intro track.mp3"]}');
98
+ expect(h.templateAnnotation).toEqual({ params: { audio: 'intro track.mp3' } });
99
+ });
100
+ });
101
+
102
+ describe('Round-trip of quoted template params', () => {
103
+ function roundTrip(src: string): string {
104
+ return stringifyMarkdown(parseMarkdown(src)).trim();
105
+ }
106
+
107
+ it('spacey double-quoted values round-trip verbatim', () => {
108
+ const src = '## Gallery {[imageWithCaption src=photo.jpg caption="Beach at sunset"]}';
109
+ expect(roundTrip(src)).toBe(src);
110
+ });
111
+
112
+ it('single quotes canonicalize to double quotes', () => {
113
+ expect(roundTrip("## X {[quote text='A long caption']}")).toBe(
114
+ '## X {[quote text="A long caption"]}',
115
+ );
116
+ });
117
+
118
+ it('a value containing a double quote round-trips via single quotes', () => {
119
+ const src = '## X {[quote text=\'She said "hi"\']}';
120
+ expect(roundTrip(src)).toBe(src);
121
+ });
122
+
123
+ it('a quoted ] round-trips', () => {
124
+ const src = '## X {[quote text="a ] b"]}';
125
+ expect(roundTrip(src)).toBe(src);
126
+ });
127
+
128
+ it('emphasis characters survive a full stringify → parse cycle', () => {
129
+ // The emitted source keeps \* escaped (so the heading text run stays
130
+ // intact); reparsing resolves the escape back to the bare character.
131
+ const src = '## X {[quote text="a \\*b\\* c"]}';
132
+ const emitted = roundTrip(src);
133
+ expect(emitted).toBe(src);
134
+ const h = getHeading(emitted);
135
+ expect(h.templateAnnotation?.params).toEqual({ text: 'a *b* c' });
136
+ });
137
+
138
+ it('stringify quotes spacey values produced programmatically', () => {
139
+ const doc = parseMarkdown('## X {[quote]}');
140
+ const heading = doc.children[0];
141
+ if (heading.type !== 'heading') throw new Error('expected heading');
142
+ heading.templateAnnotation = {
143
+ template: 'quote',
144
+ params: { text: 'Beach at sunset', attribution: 'someone' },
145
+ };
146
+ expect(stringifyMarkdown(doc).trim()).toBe(
147
+ '## X {[quote text="Beach at sunset" attribution=someone]}',
148
+ );
149
+ });
150
+ });
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { templateRegistry, TEMPLATE_METADATA, TEMPLATE_ALIASES } from '../doc/templates/index';
3
+
4
+ describe('TEMPLATE_METADATA', () => {
5
+ it('stays exactly 1:1 with templateRegistry (same ids)', () => {
6
+ const registryIds = Object.keys(templateRegistry).sort();
7
+ const metadataIds = Object.keys(TEMPLATE_METADATA).sort();
8
+ // If this fails, a template was added to the registry without metadata
9
+ // (or vice versa). Add the missing entry — the editor's TemplatePicker
10
+ // renders its gallery from TEMPLATE_METADATA, so a registry-only template
11
+ // would never appear in the picker.
12
+ expect(metadataIds).toEqual(registryIds);
13
+ });
14
+
15
+ it('every entry has a non-empty label and description', () => {
16
+ for (const [id, meta] of Object.entries(TEMPLATE_METADATA)) {
17
+ expect(meta.label, `label for "${id}"`).toBeTruthy();
18
+ expect(meta.description, `description for "${id}"`).toBeTruthy();
19
+ }
20
+ });
21
+ });
22
+
23
+ describe('TEMPLATE_ALIASES', () => {
24
+ it('every alias target resolves to a real registry entry', () => {
25
+ // A typo'd alias target would otherwise fall through resolveTemplateName's
26
+ // `?? name` fallback and silently resolve to a non-existent template.
27
+ for (const [alias, target] of Object.entries(TEMPLATE_ALIASES)) {
28
+ expect(target in templateRegistry, `alias "${alias}" → "${target}"`).toBe(true);
29
+ }
30
+ });
31
+ });