@bendyline/squisq 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/{Doc-BeSeH2iX.d.ts → Doc-BsMkmzH8.d.ts} +838 -268
  2. package/dist/{ImageEditDoc-BTIvw0oq.d.ts → ImageEditDoc-DvoeHMP9.d.ts} +11 -4
  3. package/dist/{chunk-ZTX4PFFT.js → chunk-2OIBZYKP.js} +75 -2
  4. package/dist/chunk-2OIBZYKP.js.map +1 -0
  5. package/dist/chunk-2UQOHYE2.js +45 -0
  6. package/dist/chunk-2UQOHYE2.js.map +1 -0
  7. package/dist/{chunk-B4EEON3N.js → chunk-4AKUQPEE.js} +536 -103
  8. package/dist/chunk-4AKUQPEE.js.map +1 -0
  9. package/dist/chunk-4ZFRZBU2.js +6582 -0
  10. package/dist/chunk-4ZFRZBU2.js.map +1 -0
  11. package/dist/{chunk-57CVQCFX.js → chunk-7MQGNR76.js} +79 -3
  12. package/dist/chunk-7MQGNR76.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-MYIH7FWD.js → chunk-FBKP5CAO.js} +1 -1
  16. package/dist/chunk-FBKP5CAO.js.map +1 -0
  17. package/dist/chunk-KZNXZ5SM.js +333 -0
  18. package/dist/chunk-KZNXZ5SM.js.map +1 -0
  19. package/dist/{chunk-WMOI7FN3.js → chunk-LRCV7N7F.js} +12 -2
  20. package/dist/{chunk-WMOI7FN3.js.map → chunk-LRCV7N7F.js.map} +1 -1
  21. package/dist/{chunk-3K5OG6KI.js → chunk-OH43RPTP.js} +403 -187
  22. package/dist/chunk-OH43RPTP.js.map +1 -0
  23. package/dist/{chunk-H3AXU4MJ.js → chunk-OKJOQXK4.js} +149 -2
  24. package/dist/chunk-OKJOQXK4.js.map +1 -0
  25. package/dist/chunk-PGGGKYWG.js +1 -0
  26. package/dist/chunk-PGGGKYWG.js.map +1 -0
  27. package/dist/{chunk-7UDSRZKG.js → chunk-Q3ROPT5H.js} +35 -14
  28. package/dist/chunk-Q3ROPT5H.js.map +1 -0
  29. package/dist/chunk-QE7TWGVT.js +178 -0
  30. package/dist/chunk-QE7TWGVT.js.map +1 -0
  31. package/dist/chunk-RUDYOTA6.js +345 -0
  32. package/dist/chunk-RUDYOTA6.js.map +1 -0
  33. package/dist/chunk-TVSGLUID.js +596 -0
  34. package/dist/chunk-TVSGLUID.js.map +1 -0
  35. package/dist/chunk-ZLQKNOZQ.js +1 -0
  36. package/dist/chunk-ZLQKNOZQ.js.map +1 -0
  37. package/dist/doc/index.d.ts +4 -4
  38. package/dist/doc/index.js +124 -6
  39. package/dist/generate/index.d.ts +9 -2
  40. package/dist/generate/index.js +1 -1
  41. package/dist/icons/index.d.ts +3 -26
  42. package/dist/icons/index.js +13 -0
  43. package/dist/icons/inlineIconMarker.d.ts +1 -0
  44. package/dist/icons/inlineIconMarker.js +15 -0
  45. package/dist/icons/inlineIconMarker.js.map +1 -0
  46. package/dist/imageEdit/index.d.ts +11 -5
  47. package/dist/imageEdit/index.js +4 -1
  48. package/dist/index.d.ts +11 -8
  49. package/dist/index.js +243 -24
  50. package/dist/inlineIconMarker-CiE8Hlvz.d.ts +59 -0
  51. package/dist/markdown/index.d.ts +212 -3
  52. package/dist/markdown/index.js +40 -7
  53. package/dist/recommend/index.d.ts +1 -1
  54. package/dist/recommend/index.js +3 -2
  55. package/dist/schemas/index.d.ts +28 -8
  56. package/dist/schemas/index.js +35 -5
  57. package/dist/spatial/index.d.ts +9 -4
  58. package/dist/spatial/index.js +1 -1
  59. package/dist/story/index.d.ts +906 -40
  60. package/dist/story/index.js +124 -6
  61. package/dist/{themeLibrary-BHjJ0Qx6.d.ts → themeLibrary-DQQKuRMx.d.ts} +1 -1
  62. package/dist/transform/index.d.ts +48 -10
  63. package/dist/transform/index.js +17 -481
  64. package/dist/transform/index.js.map +1 -1
  65. package/dist/{types-BdZkdJ3z.d.ts → types-DlAZ7MW4.d.ts} +115 -1
  66. package/package.json +6 -1
  67. package/src/__tests__/animationUtils.test.ts +40 -0
  68. package/src/__tests__/annotationCoercion.test.ts +243 -0
  69. package/src/__tests__/applyRenderStyle.test.ts +146 -0
  70. package/src/__tests__/atmosphereLayers.test.ts +108 -0
  71. package/src/__tests__/attrTokens.test.ts +162 -0
  72. package/src/__tests__/customTemplateSample.test.ts +83 -0
  73. package/src/__tests__/customTemplatesFrontmatter.test.ts +205 -0
  74. package/src/__tests__/customThemesFrontmatter.test.ts +118 -0
  75. package/src/__tests__/diagramBlock.test.ts +122 -0
  76. package/src/__tests__/diagramLayout.test.ts +134 -0
  77. package/src/__tests__/drawing.test.ts +109 -0
  78. package/src/__tests__/drawingBlock.test.ts +124 -0
  79. package/src/__tests__/drawingLayout.test.ts +171 -0
  80. package/src/__tests__/geohash.test.ts +6 -5
  81. package/src/__tests__/getLayers.test.ts +6 -2
  82. package/src/__tests__/getLayersFallback.test.ts +103 -0
  83. package/src/__tests__/imageEditExportSvg.test.ts +70 -0
  84. package/src/__tests__/imageEditVersions.test.ts +72 -0
  85. package/src/__tests__/inlineIconMarker.test.ts +36 -0
  86. package/src/__tests__/layoutBlock.test.ts +83 -0
  87. package/src/__tests__/layoutLayout.test.ts +169 -0
  88. package/src/__tests__/markdown.test.ts +23 -0
  89. package/src/__tests__/markdownSanitize.test.ts +64 -0
  90. package/src/__tests__/markdownToDoc.test.ts +223 -2
  91. package/src/__tests__/mediaAnnotations.test.ts +64 -0
  92. package/src/__tests__/mediaSchedule.test.ts +118 -0
  93. package/src/__tests__/pandocAttrParse.test.ts +187 -0
  94. package/src/__tests__/resolveDocTheme.test.ts +55 -0
  95. package/src/__tests__/rootExports.test.ts +43 -0
  96. package/src/__tests__/shapeGeometry.test.ts +89 -0
  97. package/src/__tests__/shapeVocabulary.test.ts +133 -0
  98. package/src/__tests__/structuredData.test.ts +179 -0
  99. package/src/__tests__/templateAnnotationParse.test.ts +108 -0
  100. package/src/__tests__/templateMetadata.test.ts +21 -0
  101. package/src/__tests__/templates.test.ts +145 -4
  102. package/src/__tests__/themeCompile.test.ts +42 -0
  103. package/src/__tests__/themeValidator.test.ts +6 -0
  104. package/src/__tests__/transformV2.test.ts +137 -0
  105. package/src/__tests__/transitionNormalize.test.ts +61 -0
  106. package/src/__tests__/validateDoc.test.ts +100 -0
  107. package/src/doc/customTemplatesFrontmatter.ts +308 -0
  108. package/src/doc/customThemesFrontmatter.ts +90 -0
  109. package/src/doc/docToMarkdown.ts +73 -4
  110. package/src/doc/getLayers.ts +40 -17
  111. package/src/doc/index.ts +35 -1
  112. package/src/doc/markdownToDoc.ts +333 -12
  113. package/src/doc/mediaAnnotations.ts +118 -0
  114. package/src/doc/resolveDocTheme.ts +55 -0
  115. package/src/doc/structuredData.ts +230 -0
  116. package/src/doc/templateInputs.ts +240 -0
  117. package/src/doc/templates/__tests__/customTemplate.test.ts +151 -0
  118. package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +110 -0
  119. package/src/doc/templates/accentImage.ts +30 -6
  120. package/src/doc/templates/captionUtils.ts +23 -0
  121. package/src/doc/templates/comparisonBar.ts +26 -18
  122. package/src/doc/templates/coverBlock.ts +7 -4
  123. package/src/doc/templates/customTemplate.ts +45 -0
  124. package/src/doc/templates/dataTable.ts +37 -19
  125. package/src/doc/templates/dateEvent.ts +41 -20
  126. package/src/doc/templates/definitionCard.ts +26 -18
  127. package/src/doc/templates/diagramBlock.ts +204 -0
  128. package/src/doc/templates/diagramLayout.ts +159 -0
  129. package/src/doc/templates/drawingBlock.ts +325 -0
  130. package/src/doc/templates/drawingLayout.ts +539 -0
  131. package/src/doc/templates/factCard.ts +51 -25
  132. package/src/doc/templates/fallbackBlock.ts +123 -0
  133. package/src/doc/templates/featureBlock.ts +20 -13
  134. package/src/doc/templates/fullBleedQuote.ts +18 -8
  135. package/src/doc/templates/imageWithCaption.ts +22 -9
  136. package/src/doc/templates/index.ts +215 -46
  137. package/src/doc/templates/layoutBlock.ts +43 -0
  138. package/src/doc/templates/layoutLayout.ts +243 -0
  139. package/src/doc/templates/listBlock.ts +56 -30
  140. package/src/doc/templates/mapBlock.ts +15 -12
  141. package/src/doc/templates/metadata.ts +120 -0
  142. package/src/doc/templates/persistentLayers.ts +129 -11
  143. package/src/doc/templates/photoGrid.ts +23 -12
  144. package/src/doc/templates/pullQuote.ts +30 -12
  145. package/src/doc/templates/quoteBlock.ts +54 -29
  146. package/src/doc/templates/sectionHeader.ts +25 -11
  147. package/src/doc/templates/statHighlight.ts +39 -22
  148. package/src/doc/templates/titleBlock.ts +59 -21
  149. package/src/doc/templates/tokens/__tests__/resolveTokens.test.ts +221 -0
  150. package/src/doc/templates/tokens/resolveTokens.ts +0 -0
  151. package/src/doc/templates/twoColumn.ts +48 -30
  152. package/src/doc/templates/videoPullQuote.ts +22 -12
  153. package/src/doc/templates/videoWithCaption.ts +13 -8
  154. package/src/doc/utils/animationUtils.ts +267 -3
  155. package/src/doc/utils/applyRenderStyle.ts +113 -0
  156. package/src/doc/utils/imageTreatment.ts +70 -0
  157. package/src/doc/utils/shapeGeometry.ts +464 -0
  158. package/src/doc/utils/themeUtils.ts +75 -1
  159. package/src/doc/validate.ts +476 -0
  160. package/src/generate/slideshowGenerator.ts +7 -0
  161. package/src/icons/index.ts +8 -0
  162. package/src/icons/inlineIconMarker.ts +73 -0
  163. package/src/imageEdit/export.ts +85 -2
  164. package/src/imageEdit/index.ts +1 -0
  165. package/src/imageEdit/persistence.ts +51 -0
  166. package/src/index.ts +2 -0
  167. package/src/markdown/annotationCoercion.ts +295 -0
  168. package/src/markdown/attrTokens.ts +222 -0
  169. package/src/markdown/convert.ts +229 -26
  170. package/src/markdown/index.ts +36 -0
  171. package/src/markdown/sanitize.ts +298 -0
  172. package/src/markdown/stringify.ts +84 -3
  173. package/src/markdown/types.ts +66 -0
  174. package/src/markdown/utils.ts +49 -1
  175. package/src/recommend/templates.ts +24 -0
  176. package/src/schemas/BlockTemplates.ts +133 -4
  177. package/src/schemas/CustomTemplates.ts +74 -0
  178. package/src/schemas/Doc.ts +353 -29
  179. package/src/schemas/ImageEditDoc.ts +11 -4
  180. package/src/schemas/Media.ts +169 -0
  181. package/src/schemas/Theme.ts +23 -1
  182. package/src/schemas/Transitions.ts +224 -0
  183. package/src/schemas/colorUtils.ts +33 -0
  184. package/src/schemas/fontStacks.ts +5 -2
  185. package/src/schemas/index.ts +3 -0
  186. package/src/schemas/themeCompile.ts +23 -4
  187. package/src/schemas/themeValidator.ts +49 -11
  188. package/src/schemas/themes/cinematic.json +69 -12
  189. package/src/schemas/themes/documentary.json +58 -11
  190. package/src/schemas/themes/gezellig.json +60 -11
  191. package/src/schemas/themes/magazine.json +54 -9
  192. package/src/schemas/themes/morning-light.json +52 -9
  193. package/src/schemas/themes/standard-dark.json +48 -13
  194. package/src/schemas/themes/standard.json +44 -12
  195. package/src/schemas/themes/tech-dark.json +65 -12
  196. package/src/spatial/Geohash.ts +52 -21
  197. package/src/transform/applyTransform.ts +43 -4
  198. package/src/transform/index.ts +1 -0
  199. package/src/transform/registry.ts +44 -13
  200. package/src/transform/styles/dataDriven.ts +2 -1
  201. package/src/transform/styles/documentary.ts +2 -1
  202. package/src/transform/styles/magazine.ts +3 -1
  203. package/src/transform/styles/minimal.ts +2 -1
  204. package/src/transform/styles/narrative.ts +3 -1
  205. package/src/transform/templateSelector.ts +87 -11
  206. package/src/transform/types.ts +35 -2
  207. package/dist/chunk-3K5OG6KI.js.map +0 -1
  208. package/dist/chunk-57CVQCFX.js.map +0 -1
  209. package/dist/chunk-5WFRKURX.js.map +0 -1
  210. package/dist/chunk-7UDSRZKG.js.map +0 -1
  211. package/dist/chunk-B4EEON3N.js.map +0 -1
  212. package/dist/chunk-H3AXU4MJ.js.map +0 -1
  213. package/dist/chunk-KSWJR66U.js +0 -3706
  214. package/dist/chunk-KSWJR66U.js.map +0 -1
  215. package/dist/chunk-MYIH7FWD.js.map +0 -1
  216. package/dist/chunk-ZTX4PFFT.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import * as root from '../index';
3
+ import * as icons from '../icons/index';
4
+ import * as transform from '../transform/index';
5
+
6
+ const transformRuntimeExports = [
7
+ 'applyTransform',
8
+ 'resolveTransformStyle',
9
+ 'getTransformStyleIds',
10
+ 'getTransformStyleSummaries',
11
+ 'DEFAULT_TRANSFORM_STYLE_ID',
12
+ 'analyzeBlocks',
13
+ 'extractDocImages',
14
+ ] as const;
15
+
16
+ const iconRuntimeExports = [
17
+ 'ICONS',
18
+ 'resolveIcon',
19
+ 'canonicalIconToken',
20
+ 'looksLikeIconToken',
21
+ 'suggestIcons',
22
+ 'iconGlyph',
23
+ ] as const;
24
+
25
+ function expectReExported(
26
+ rootExports: Record<string, unknown>,
27
+ subpathExports: Record<string, unknown>,
28
+ names: readonly string[],
29
+ ): void {
30
+ for (const name of names) {
31
+ expect(rootExports[name], `root barrel should re-export ${name}`).toBe(subpathExports[name]);
32
+ }
33
+ }
34
+
35
+ describe('root barrel exports', () => {
36
+ it('re-exports transform runtime APIs', () => {
37
+ expectReExported(root, transform, transformRuntimeExports);
38
+ });
39
+
40
+ it('re-exports icon runtime APIs', () => {
41
+ expectReExported(root, icons, iconRuntimeExports);
42
+ });
43
+ });
@@ -0,0 +1,89 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ shapePath,
4
+ markerPath,
5
+ connectorPath,
6
+ clipEndpoints,
7
+ lineStyleDasharray,
8
+ PATH_SHAPE_KINDS,
9
+ } from '../doc/utils/shapeGeometry.js';
10
+
11
+ describe('shapePath', () => {
12
+ it('returns a non-empty path beginning with M for every path-shape kind', () => {
13
+ for (const kind of PATH_SHAPE_KINDS) {
14
+ const d = shapePath(kind, 0, 0, 100, 80);
15
+ expect(d, kind).toBeTruthy();
16
+ expect(d?.startsWith('M'), kind).toBe(true);
17
+ }
18
+ });
19
+
20
+ it('returns null for natively-rendered primitives', () => {
21
+ for (const kind of ['rect', 'circle', 'line', 'text', 'path', 'arrow']) {
22
+ expect(shapePath(kind, 0, 0, 10, 10), kind).toBeNull();
23
+ }
24
+ });
25
+
26
+ it('triangle is a closed 3-point polygon inscribed in the box', () => {
27
+ expect(shapePath('triangle', 0, 0, 100, 100)).toBe('M 50 0 L 100 100 L 0 100 Z');
28
+ });
29
+
30
+ it('diamond hits the four edge midpoints', () => {
31
+ expect(shapePath('diamond', 0, 0, 100, 100)).toBe('M 50 0 L 100 50 L 50 100 L 0 50 Z');
32
+ });
33
+
34
+ it('honors the bounding-box offset', () => {
35
+ expect(shapePath('triangle', 10, 20, 100, 100)).toBe('M 60 20 L 110 120 L 10 120 Z');
36
+ });
37
+ });
38
+
39
+ describe('markerPath', () => {
40
+ it('arrow end is a filled triangle; none is null', () => {
41
+ expect(markerPath('arrow', 'end')).toEqual({ d: 'M 0 0 L 10 5 L 0 10 z', filled: true });
42
+ expect(markerPath('none', 'end')).toBeNull();
43
+ });
44
+
45
+ it('open is unfilled; diamond/circle/square are filled', () => {
46
+ expect(markerPath('open', 'end')?.filled).toBe(false);
47
+ expect(markerPath('diamond', 'end')?.filled).toBe(true);
48
+ expect(markerPath('circle', 'end')?.filled).toBe(true);
49
+ expect(markerPath('square', 'end')?.filled).toBe(true);
50
+ });
51
+
52
+ it('start mirrors the arrow horizontally', () => {
53
+ expect(markerPath('arrow', 'start')).toEqual({ d: 'M 10 0 L 0 5 L 10 10 z', filled: true });
54
+ });
55
+ });
56
+
57
+ describe('connectorPath', () => {
58
+ const a = { x: 0, y: 0 };
59
+ const b = { x: 100, y: 50 };
60
+
61
+ it('straight is a single line segment', () => {
62
+ expect(connectorPath('straight', a, b)).toBe('M 0 0 L 100 50');
63
+ });
64
+
65
+ it('orthogonal has a mid elbow', () => {
66
+ expect(connectorPath('orthogonal', a, b)).toBe('M 0 0 L 50 0 L 50 50 L 100 50');
67
+ });
68
+
69
+ it('curved is a cubic bezier', () => {
70
+ expect(connectorPath('curved', a, b).startsWith('M 0 0 C')).toBe(true);
71
+ });
72
+ });
73
+
74
+ describe('clipEndpoints', () => {
75
+ it('clips both endpoints to the box edges', () => {
76
+ const r = clipEndpoints({ cx: 0, cy: 0, rx: 10, ry: 10 }, { cx: 100, cy: 0, rx: 10, ry: 10 });
77
+ expect(r.start).toEqual({ x: 10, y: 0 });
78
+ expect(r.end).toEqual({ x: 90, y: 0 });
79
+ });
80
+ });
81
+
82
+ describe('lineStyleDasharray', () => {
83
+ it('maps line styles to dash patterns', () => {
84
+ expect(lineStyleDasharray('dashed')).toBe('8 6');
85
+ expect(lineStyleDasharray('dotted')).toBe('2 6');
86
+ expect(lineStyleDasharray('solid')).toBeUndefined();
87
+ expect(lineStyleDasharray(undefined)).toBeUndefined();
88
+ });
89
+ });
@@ -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,179 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { parseMarkdown } from '../markdown/parse.js';
3
+ import { markdownToDoc } from '../doc/markdownToDoc.js';
4
+ import { parseYamlSubset } from '../doc/structuredData.js';
5
+
6
+ function toDoc(md: string) {
7
+ return markdownToDoc(parseMarkdown(md));
8
+ }
9
+
10
+ describe('parseYamlSubset', () => {
11
+ it('parses scalars with type coercion', () => {
12
+ expect(parseYamlSubset('title: Hello world\ncount: 3\nlive: true\nnothing: null')).toEqual({
13
+ title: 'Hello world',
14
+ count: 3,
15
+ live: true,
16
+ nothing: null,
17
+ });
18
+ });
19
+
20
+ it('parses inline arrays', () => {
21
+ expect(parseYamlSubset('headers: [Name, Age]')).toEqual({ headers: ['Name', 'Age'] });
22
+ });
23
+
24
+ it('parses block sequences of scalars and inline arrays', () => {
25
+ expect(
26
+ parseYamlSubset('rows:\n - [Alice, 30]\n - [Bob, 25]\nmarkers:\n - "47.6,-122.3"'),
27
+ ).toEqual({
28
+ rows: [
29
+ ['Alice', 30],
30
+ ['Bob', 25],
31
+ ],
32
+ markers: ['47.6,-122.3'],
33
+ });
34
+ });
35
+
36
+ it('preserves quoted strings (commas, numbers stay strings)', () => {
37
+ expect(parseYamlSubset('label: "1,234"')).toEqual({ label: '1,234' });
38
+ });
39
+
40
+ it('skips comments and blank lines', () => {
41
+ expect(parseYamlSubset('# comment\n\nkey: value')).toEqual({ key: 'value' });
42
+ });
43
+
44
+ it('rejects nested mappings with a line-anchored error', () => {
45
+ expect(() => parseYamlSubset('outer:\n inner: 1')).toThrow(/line 2/);
46
+ });
47
+ });
48
+
49
+ describe('data fences → block.templateData', () => {
50
+ it('parses a ```json data fence into templateData', () => {
51
+ const md = [
52
+ '## Numbers {[dataTable]}',
53
+ '',
54
+ '```json data',
55
+ '{ "headers": ["Q", "Revenue"], "rows": [["Q1", "1.2M"]] }',
56
+ '```',
57
+ ].join('\n');
58
+ const doc = toDoc(md);
59
+ expect(doc.blocks[0].templateData).toEqual({
60
+ headers: ['Q', 'Revenue'],
61
+ rows: [['Q1', '1.2M']],
62
+ });
63
+ expect(doc.diagnostics).toBeUndefined();
64
+ });
65
+
66
+ it('parses a ```yaml data fence into templateData', () => {
67
+ const md = [
68
+ '## Map {[map]}',
69
+ '',
70
+ '```yaml data',
71
+ 'zoom: 12',
72
+ 'markers:',
73
+ ' - "47.6,-122.3"',
74
+ '```',
75
+ ].join('\n');
76
+ const doc = toDoc(md);
77
+ expect(doc.blocks[0].templateData).toEqual({ zoom: 12, markers: ['47.6,-122.3'] });
78
+ });
79
+
80
+ it('ignores plain ```json fences without the data marker', () => {
81
+ const md = '## Code {[sectionHeader]}\n\n```json\n{ "just": "a sample" }\n```';
82
+ const doc = toDoc(md);
83
+ expect(doc.blocks[0].templateData).toBeUndefined();
84
+ });
85
+
86
+ it('records a diagnostic for unparseable fences and degrades gracefully', () => {
87
+ const md = '## Bad {[dataTable]}\n\n```json data\n{ not valid json\n```';
88
+ const doc = toDoc(md);
89
+ expect(doc.blocks[0].templateData).toBeUndefined();
90
+ expect(doc.diagnostics).toHaveLength(1);
91
+ expect(doc.diagnostics![0]).toMatchObject({ severity: 'error', code: 'data-fence-parse' });
92
+ expect(doc.diagnostics![0].line).toBe(3);
93
+ });
94
+ });
95
+
96
+ describe('dataTable eats GFM tables', () => {
97
+ const table = ['| Name | Age |', '| --- | ---: |', '| Alice | 30 |', '| Bob | 25 |'].join('\n');
98
+
99
+ it('supplies headers/rows/align from the first table in the body', () => {
100
+ const doc = toDoc(`## People {[dataTable]}\n\n${table}`);
101
+ expect(doc.blocks[0].templateData).toEqual({
102
+ headers: ['Name', 'Age'],
103
+ rows: [
104
+ ['Alice', '30'],
105
+ ['Bob', '25'],
106
+ ],
107
+ align: [null, 'right'],
108
+ });
109
+ });
110
+
111
+ it('does not extract tables for non-dataTable templates', () => {
112
+ const doc = toDoc(`## People {[sectionHeader]}\n\n${table}`);
113
+ expect(doc.blocks[0].templateData).toBeUndefined();
114
+ });
115
+
116
+ it('explicit fence data wins over the body table', () => {
117
+ const md = [
118
+ '## People {[dataTable]}',
119
+ '',
120
+ '```json data',
121
+ '{ "headers": ["X"], "rows": [["1"]] }',
122
+ '```',
123
+ '',
124
+ table,
125
+ ].join('\n');
126
+ const doc = toDoc(md);
127
+ expect(doc.blocks[0].templateData).toEqual({ headers: ['X'], rows: [['1']] });
128
+ });
129
+ });
130
+
131
+ describe('deterministic conversion', () => {
132
+ const md = '# Title\n\nSome body text.\n\n## Section {[quote]}\n\nA quote here.';
133
+
134
+ it('produces identical Docs for identical input', () => {
135
+ expect(toDoc(md)).toEqual(toDoc(md));
136
+ });
137
+
138
+ it('omits captions.generatedAt unless a timestamp is supplied', () => {
139
+ const doc = toDoc(md);
140
+ expect(doc.captions).toBeDefined();
141
+ expect(doc.captions!.generatedAt).toBeUndefined();
142
+
143
+ const stamped = markdownToDoc(parseMarkdown(md), {
144
+ captionsGeneratedAt: '2026-06-10T00:00:00.000Z',
145
+ });
146
+ expect(stamped.captions!.generatedAt).toBe('2026-06-10T00:00:00.000Z');
147
+ });
148
+ });
149
+
150
+ describe('conversion diagnostics', () => {
151
+ it('flags duplicate pinned ids', () => {
152
+ const doc = toDoc('## A {#dup}\n\n## B {#dup}');
153
+ expect(doc.diagnostics).toBeDefined();
154
+ expect(doc.diagnostics![0]).toMatchObject({ severity: 'error', code: 'duplicate-id' });
155
+ });
156
+
157
+ it('a pinned id reserves the slug so a later heading does not collide', () => {
158
+ const doc = toDoc('## Other name {#intro}\n\n## Intro');
159
+ const ids = doc.blocks.map((b) => b.id);
160
+ expect(ids[0]).toBe('intro');
161
+ expect(ids[1]).not.toBe('intro');
162
+ expect(doc.diagnostics).toBeUndefined();
163
+ });
164
+
165
+ it('flags connectsTo targets that do not resolve', () => {
166
+ const doc = toDoc('## A {#a connectsTo=ghost}\n\n## B {#b}');
167
+ expect(doc.diagnostics).toBeDefined();
168
+ expect(doc.diagnostics![0]).toMatchObject({
169
+ severity: 'warning',
170
+ code: 'unresolved-connection',
171
+ blockId: 'a',
172
+ });
173
+ });
174
+
175
+ it('resolved connections produce no diagnostics', () => {
176
+ const doc = toDoc('## A {#a connectsTo=b}\n\n## B {#b}');
177
+ expect(doc.diagnostics).toBeUndefined();
178
+ });
179
+ });
@@ -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,21 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { templateRegistry, TEMPLATE_METADATA } 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
+ });