postext 1.70.6 → 1.72.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 (308) hide show
  1. package/README.md +1 -0
  2. package/dist/__tests__/exports.test.js +7 -0
  3. package/dist/__tests__/exports.test.js.map +1 -1
  4. package/dist/__tests__/fonts/strikeout.test.d.ts +2 -0
  5. package/dist/__tests__/fonts/strikeout.test.d.ts.map +1 -0
  6. package/dist/__tests__/fonts/strikeout.test.js +106 -0
  7. package/dist/__tests__/fonts/strikeout.test.js.map +1 -0
  8. package/dist/__tests__/paint/canvasFormFields.test.d.ts +2 -0
  9. package/dist/__tests__/paint/canvasFormFields.test.d.ts.map +1 -0
  10. package/dist/__tests__/paint/canvasFormFields.test.js +89 -0
  11. package/dist/__tests__/paint/canvasFormFields.test.js.map +1 -0
  12. package/dist/__tests__/paint/strikethrough.test.d.ts +2 -0
  13. package/dist/__tests__/paint/strikethrough.test.d.ts.map +1 -0
  14. package/dist/__tests__/paint/strikethrough.test.js +177 -0
  15. package/dist/__tests__/paint/strikethrough.test.js.map +1 -0
  16. package/dist/__tests__/paint/underline.test.d.ts +2 -0
  17. package/dist/__tests__/paint/underline.test.d.ts.map +1 -0
  18. package/dist/__tests__/paint/underline.test.js +140 -0
  19. package/dist/__tests__/paint/underline.test.js.map +1 -0
  20. package/dist/__tests__/parse/formFields.test.d.ts +2 -0
  21. package/dist/__tests__/parse/formFields.test.d.ts.map +1 -0
  22. package/dist/__tests__/parse/formFields.test.js +107 -0
  23. package/dist/__tests__/parse/formFields.test.js.map +1 -0
  24. package/dist/__tests__/parse/strikethrough.test.d.ts +2 -0
  25. package/dist/__tests__/parse/strikethrough.test.d.ts.map +1 -0
  26. package/dist/__tests__/parse/strikethrough.test.js +97 -0
  27. package/dist/__tests__/parse/strikethrough.test.js.map +1 -0
  28. package/dist/__tests__/parse/underline.test.d.ts +2 -0
  29. package/dist/__tests__/parse/underline.test.d.ts.map +1 -0
  30. package/dist/__tests__/parse/underline.test.js +161 -0
  31. package/dist/__tests__/parse/underline.test.js.map +1 -0
  32. package/dist/__tests__/pipeline/callouts/calloutHangingIndent.test.d.ts +2 -0
  33. package/dist/__tests__/pipeline/callouts/calloutHangingIndent.test.d.ts.map +1 -0
  34. package/dist/__tests__/pipeline/callouts/calloutHangingIndent.test.js +139 -0
  35. package/dist/__tests__/pipeline/callouts/calloutHangingIndent.test.js.map +1 -0
  36. package/dist/canvas-backend/annotations.d.ts.map +1 -1
  37. package/dist/canvas-backend/annotations.js +4 -0
  38. package/dist/canvas-backend/annotations.js.map +1 -1
  39. package/dist/canvas-backend/blockRender/linkPaint.d.ts +3 -0
  40. package/dist/canvas-backend/blockRender/linkPaint.d.ts.map +1 -1
  41. package/dist/canvas-backend/blockRender/linkPaint.js +5 -0
  42. package/dist/canvas-backend/blockRender/linkPaint.js.map +1 -1
  43. package/dist/canvas-backend/chip.d.ts +4 -0
  44. package/dist/canvas-backend/chip.d.ts.map +1 -1
  45. package/dist/canvas-backend/chip.js +33 -1
  46. package/dist/canvas-backend/chip.js.map +1 -1
  47. package/dist/canvas-backend/index.d.ts +5 -0
  48. package/dist/canvas-backend/index.d.ts.map +1 -1
  49. package/dist/canvas-backend/index.js +5 -1
  50. package/dist/canvas-backend/index.js.map +1 -1
  51. package/dist/defaults/boxes/calloutStyles/resolve.d.ts.map +1 -1
  52. package/dist/defaults/boxes/calloutStyles/resolve.js +4 -0
  53. package/dist/defaults/boxes/calloutStyles/resolve.js.map +1 -1
  54. package/dist/defaults/boxes/calloutStyles/strip.d.ts.map +1 -1
  55. package/dist/defaults/boxes/calloutStyles/strip.js +2 -0
  56. package/dist/defaults/boxes/calloutStyles/strip.js.map +1 -1
  57. package/dist/defaults/text/bodyText/resolve.d.ts.map +1 -1
  58. package/dist/defaults/text/bodyText/resolve.js +2 -0
  59. package/dist/defaults/text/bodyText/resolve.js.map +1 -1
  60. package/dist/defaults/text/bodyText/strip.d.ts.map +1 -1
  61. package/dist/defaults/text/bodyText/strip.js +5 -0
  62. package/dist/defaults/text/bodyText/strip.js.map +1 -1
  63. package/dist/fonts/glyphFallback.d.ts +2 -1
  64. package/dist/fonts/glyphFallback.d.ts.map +1 -1
  65. package/dist/fonts/glyphFallback.js +6 -1
  66. package/dist/fonts/glyphFallback.js.map +1 -1
  67. package/dist/fonts/strikeout.d.ts +30 -0
  68. package/dist/fonts/strikeout.d.ts.map +1 -0
  69. package/dist/fonts/strikeout.js +127 -0
  70. package/dist/fonts/strikeout.js.map +1 -0
  71. package/dist/html-backend/htmlAnnotations.d.ts.map +1 -1
  72. package/dist/html-backend/htmlAnnotations.js +3 -1
  73. package/dist/html-backend/htmlAnnotations.js.map +1 -1
  74. package/dist/html-backend/lines.d.ts.map +1 -1
  75. package/dist/html-backend/lines.js +8 -0
  76. package/dist/html-backend/lines.js.map +1 -1
  77. package/dist/html-backend/linkPaint.d.ts +3 -0
  78. package/dist/html-backend/linkPaint.d.ts.map +1 -1
  79. package/dist/html-backend/linkPaint.js +5 -0
  80. package/dist/html-backend/linkPaint.js.map +1 -1
  81. package/dist/html-backend/resources.js +3 -3
  82. package/dist/html-backend/resources.js.map +1 -1
  83. package/dist/html-backend/segmentText.d.ts +5 -0
  84. package/dist/html-backend/segmentText.d.ts.map +1 -1
  85. package/dist/html-backend/segmentText.js +8 -0
  86. package/dist/html-backend/segmentText.js.map +1 -1
  87. package/dist/html-backend/segments.js +3 -3
  88. package/dist/html-backend/segments.js.map +1 -1
  89. package/dist/html-backend/vertical.d.ts.map +1 -1
  90. package/dist/html-backend/vertical.js +3 -1
  91. package/dist/html-backend/vertical.js.map +1 -1
  92. package/dist/hyphenation/locale.d.ts +5 -0
  93. package/dist/hyphenation/locale.d.ts.map +1 -1
  94. package/dist/hyphenation/locale.js +8 -0
  95. package/dist/hyphenation/locale.js.map +1 -1
  96. package/dist/idml/colours.d.ts +14 -0
  97. package/dist/idml/colours.d.ts.map +1 -0
  98. package/dist/idml/colours.js +53 -0
  99. package/dist/idml/colours.js.map +1 -0
  100. package/dist/idml/fields.d.ts +19 -0
  101. package/dist/idml/fields.d.ts.map +1 -0
  102. package/dist/idml/fields.js +76 -0
  103. package/dist/idml/fields.js.map +1 -0
  104. package/dist/idml/fonts.d.ts +12 -0
  105. package/dist/idml/fonts.d.ts.map +1 -0
  106. package/dist/idml/fonts.js +19 -0
  107. package/dist/idml/fonts.js.map +1 -0
  108. package/dist/idml/geometry.d.ts +25 -0
  109. package/dist/idml/geometry.d.ts.map +1 -0
  110. package/dist/idml/geometry.js +37 -0
  111. package/dist/idml/geometry.js.map +1 -0
  112. package/dist/idml/idml.test.d.ts +2 -0
  113. package/dist/idml/idml.test.d.ts.map +1 -0
  114. package/dist/idml/idml.test.js +494 -0
  115. package/dist/idml/idml.test.js.map +1 -0
  116. package/dist/idml/images.d.ts +6 -0
  117. package/dist/idml/images.d.ts.map +1 -0
  118. package/dist/idml/images.js +75 -0
  119. package/dist/idml/images.js.map +1 -0
  120. package/dist/idml/index.d.ts +5 -0
  121. package/dist/idml/index.d.ts.map +1 -0
  122. package/dist/idml/index.js +100 -0
  123. package/dist/idml/index.js.map +1 -0
  124. package/dist/idml/paragraphs.d.ts +33 -0
  125. package/dist/idml/paragraphs.d.ts.map +1 -0
  126. package/dist/idml/paragraphs.js +203 -0
  127. package/dist/idml/paragraphs.js.map +1 -0
  128. package/dist/idml/parts.d.ts +89 -0
  129. package/dist/idml/parts.d.ts.map +1 -0
  130. package/dist/idml/parts.js +136 -0
  131. package/dist/idml/parts.js.map +1 -0
  132. package/dist/idml/shapes.d.ts +21 -0
  133. package/dist/idml/shapes.d.ts.map +1 -0
  134. package/dist/idml/shapes.js +146 -0
  135. package/dist/idml/shapes.js.map +1 -0
  136. package/dist/idml/spreads.d.ts +5 -0
  137. package/dist/idml/spreads.d.ts.map +1 -0
  138. package/dist/idml/spreads.js +154 -0
  139. package/dist/idml/spreads.js.map +1 -0
  140. package/dist/idml/story.d.ts +13 -0
  141. package/dist/idml/story.d.ts.map +1 -0
  142. package/dist/idml/story.js +238 -0
  143. package/dist/idml/story.js.map +1 -0
  144. package/dist/idml/writer.d.ts +86 -0
  145. package/dist/idml/writer.d.ts.map +1 -0
  146. package/dist/idml/writer.js +8 -0
  147. package/dist/idml/writer.js.map +1 -0
  148. package/dist/index.d.ts +5 -5
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +3 -3
  151. package/dist/index.js.map +1 -1
  152. package/dist/marks/strikeGeometry.d.ts +14 -0
  153. package/dist/marks/strikeGeometry.d.ts.map +1 -0
  154. package/dist/marks/strikeGeometry.js +14 -0
  155. package/dist/marks/strikeGeometry.js.map +1 -0
  156. package/dist/marks/strikethrough.d.ts +57 -0
  157. package/dist/marks/strikethrough.d.ts.map +1 -0
  158. package/dist/marks/strikethrough.js +222 -0
  159. package/dist/marks/strikethrough.js.map +1 -0
  160. package/dist/measure/cache.d.ts.map +1 -1
  161. package/dist/measure/cache.js +8 -2
  162. package/dist/measure/cache.js.map +1 -1
  163. package/dist/measure/links.d.ts.map +1 -1
  164. package/dist/measure/links.js +71 -5
  165. package/dist/measure/links.js.map +1 -1
  166. package/dist/measure/rich/chips.d.ts.map +1 -1
  167. package/dist/measure/rich/chips.js +70 -0
  168. package/dist/measure/rich/chips.js.map +1 -1
  169. package/dist/paint/displayList/blocks.d.ts.map +1 -1
  170. package/dist/paint/displayList/blocks.js +2 -0
  171. package/dist/paint/displayList/blocks.js.map +1 -1
  172. package/dist/paint/displayList/displayList.test.js +22 -0
  173. package/dist/paint/displayList/displayList.test.js.map +1 -1
  174. package/dist/paint/displayList/inline.d.ts.map +1 -1
  175. package/dist/paint/displayList/inline.js +2 -1
  176. package/dist/paint/displayList/inline.js.map +1 -1
  177. package/dist/paint/displayList/lines.d.ts.map +1 -1
  178. package/dist/paint/displayList/lines.js +21 -0
  179. package/dist/paint/displayList/lines.js.map +1 -1
  180. package/dist/paint/displayList/page.d.ts.map +1 -1
  181. package/dist/paint/displayList/page.js +6 -2
  182. package/dist/paint/displayList/page.js.map +1 -1
  183. package/dist/paint/displayList/types.d.ts +24 -3
  184. package/dist/paint/displayList/types.d.ts.map +1 -1
  185. package/dist/parse/blockParser/headingLines.d.ts +3 -0
  186. package/dist/parse/blockParser/headingLines.d.ts.map +1 -1
  187. package/dist/parse/blockParser/headingLines.js +2 -2
  188. package/dist/parse/blockParser/headingLines.js.map +1 -1
  189. package/dist/parse/blockParser/verse.d.ts +3 -0
  190. package/dist/parse/blockParser/verse.d.ts.map +1 -1
  191. package/dist/parse/blockParser/verse.js +5 -5
  192. package/dist/parse/blockParser/verse.js.map +1 -1
  193. package/dist/parse/blockParser.d.ts.map +1 -1
  194. package/dist/parse/blockParser.js +6 -3
  195. package/dist/parse/blockParser.js.map +1 -1
  196. package/dist/parse/exerciseGaps.d.ts +4 -3
  197. package/dist/parse/exerciseGaps.d.ts.map +1 -1
  198. package/dist/parse/exerciseGaps.js +6 -6
  199. package/dist/parse/exerciseGaps.js.map +1 -1
  200. package/dist/parse/formFields.d.ts +118 -0
  201. package/dist/parse/formFields.d.ts.map +1 -0
  202. package/dist/parse/formFields.js +156 -0
  203. package/dist/parse/formFields.js.map +1 -0
  204. package/dist/parse/index.d.ts +4 -0
  205. package/dist/parse/index.d.ts.map +1 -1
  206. package/dist/parse/index.js +2 -0
  207. package/dist/parse/index.js.map +1 -1
  208. package/dist/parse/injectSpans.d.ts +2 -1
  209. package/dist/parse/injectSpans.d.ts.map +1 -1
  210. package/dist/parse/injectSpans.js +22 -2
  211. package/dist/parse/injectSpans.js.map +1 -1
  212. package/dist/parse/inlineFormatting/inlineDirectives.d.ts +5 -1
  213. package/dist/parse/inlineFormatting/inlineDirectives.d.ts.map +1 -1
  214. package/dist/parse/inlineFormatting/inlineDirectives.js +8 -3
  215. package/dist/parse/inlineFormatting/inlineDirectives.js.map +1 -1
  216. package/dist/parse/inlineFormatting/markup.d.ts +82 -1
  217. package/dist/parse/inlineFormatting/markup.d.ts.map +1 -1
  218. package/dist/parse/inlineFormatting/markup.js +140 -4
  219. package/dist/parse/inlineFormatting/markup.js.map +1 -1
  220. package/dist/parse/inlineFormatting/parse.d.ts +8 -4
  221. package/dist/parse/inlineFormatting/parse.d.ts.map +1 -1
  222. package/dist/parse/inlineFormatting/parse.js +75 -10
  223. package/dist/parse/inlineFormatting/parse.js.map +1 -1
  224. package/dist/parse/inlineFormatting.d.ts +2 -1
  225. package/dist/parse/inlineFormatting.d.ts.map +1 -1
  226. package/dist/parse/inlineFormatting.js +1 -1
  227. package/dist/parse/inlineFormatting.js.map +1 -1
  228. package/dist/parse/inlineSnippet.d.ts +7 -4
  229. package/dist/parse/inlineSnippet.d.ts.map +1 -1
  230. package/dist/parse/inlineSnippet.js +8 -5
  231. package/dist/parse/inlineSnippet.js.map +1 -1
  232. package/dist/parse/sourceMapping.d.ts.map +1 -1
  233. package/dist/parse/sourceMapping.js +14 -4
  234. package/dist/parse/sourceMapping.js.map +1 -1
  235. package/dist/parse/types/contentBlock.d.ts +3 -0
  236. package/dist/parse/types/contentBlock.d.ts.map +1 -1
  237. package/dist/parse/types/inlineSpan.d.ts +20 -1
  238. package/dist/parse/types/inlineSpan.d.ts.map +1 -1
  239. package/dist/pipeline/build/drivers.d.ts.map +1 -1
  240. package/dist/pipeline/build/drivers.js +3 -0
  241. package/dist/pipeline/build/drivers.js.map +1 -1
  242. package/dist/pipeline/callouts/calloutLayout/plan.d.ts.map +1 -1
  243. package/dist/pipeline/callouts/calloutLayout/plan.js +14 -1
  244. package/dist/pipeline/callouts/calloutLayout/plan.js.map +1 -1
  245. package/dist/pipeline/code/codeBlocks.d.ts +3 -2
  246. package/dist/pipeline/code/codeBlocks.d.ts.map +1 -1
  247. package/dist/pipeline/code/codeBlocks.js +7 -4
  248. package/dist/pipeline/code/codeBlocks.js.map +1 -1
  249. package/dist/pipeline/contentWarnings/sourceWarnings.d.ts.map +1 -1
  250. package/dist/pipeline/contentWarnings/sourceWarnings.js +3 -2
  251. package/dist/pipeline/contentWarnings/sourceWarnings.js.map +1 -1
  252. package/dist/pipeline/references/linkNotes.js +1 -1
  253. package/dist/pipeline/references/linkNotes.js.map +1 -1
  254. package/dist/pipeline/resources/resourceLayout/captions.js +1 -1
  255. package/dist/pipeline/resources/resourceLayout/captions.js.map +1 -1
  256. package/dist/pipeline/resources/resourceLayout/resourceBlock/captionNotes.js +1 -1
  257. package/dist/pipeline/resources/resourceLayout/resourceBlock/captionNotes.js.map +1 -1
  258. package/dist/pipeline/resources/resourceLayout/resourceBlock.js +1 -0
  259. package/dist/pipeline/resources/resourceLayout/resourceBlock.js.map +1 -1
  260. package/dist/pipeline/resources/resourceLayout/tableLayout.d.ts +2 -0
  261. package/dist/pipeline/resources/resourceLayout/tableLayout.d.ts.map +1 -1
  262. package/dist/pipeline/resources/resourceLayout/tableLayout.js +1 -1
  263. package/dist/pipeline/resources/resourceLayout/tableLayout.js.map +1 -1
  264. package/dist/pipeline/styles.d.ts.map +1 -1
  265. package/dist/pipeline/styles.js +20 -12
  266. package/dist/pipeline/styles.js.map +1 -1
  267. package/dist/pipeline/text/tabs.js +1 -1
  268. package/dist/pipeline/text/tabs.js.map +1 -1
  269. package/dist/types/boxes/calloutParts.d.ts +21 -0
  270. package/dist/types/boxes/calloutParts.d.ts.map +1 -1
  271. package/dist/types/boxes/callouts.d.ts +6 -0
  272. package/dist/types/boxes/callouts.d.ts.map +1 -1
  273. package/dist/types/text/bodyText/config.d.ts +9 -0
  274. package/dist/types/text/bodyText/config.d.ts.map +1 -1
  275. package/dist/types/text/bodyText/resolved.d.ts +9 -0
  276. package/dist/types/text/bodyText/resolved.d.ts.map +1 -1
  277. package/dist/vdt/lines.d.ts +4 -0
  278. package/dist/vdt/lines.d.ts.map +1 -1
  279. package/dist/vdt/segments.d.ts +34 -0
  280. package/dist/vdt/segments.d.ts.map +1 -1
  281. package/dist/vdt.d.ts +1 -1
  282. package/dist/vdt.d.ts.map +1 -1
  283. package/dist/word/formatted/runs.d.ts.map +1 -1
  284. package/dist/word/formatted/runs.js +6 -2
  285. package/dist/word/formatted/runs.js.map +1 -1
  286. package/dist/word/semantic/boxHangingIndent.test.d.ts +2 -0
  287. package/dist/word/semantic/boxHangingIndent.test.d.ts.map +1 -0
  288. package/dist/word/semantic/boxHangingIndent.test.js +38 -0
  289. package/dist/word/semantic/boxHangingIndent.test.js.map +1 -0
  290. package/dist/word/semantic/index.js +1 -1
  291. package/dist/word/semantic/index.js.map +1 -1
  292. package/dist/word/semantic/inline.d.ts.map +1 -1
  293. package/dist/word/semantic/inline.js +8 -3
  294. package/dist/word/semantic/inline.js.map +1 -1
  295. package/dist/word/semantic/prose/paragraphStyle.d.ts +8 -1
  296. package/dist/word/semantic/prose/paragraphStyle.d.ts.map +1 -1
  297. package/dist/word/semantic/prose/paragraphStyle.js +19 -0
  298. package/dist/word/semantic/prose/paragraphStyle.js.map +1 -1
  299. package/dist/word/semantic/snippet.js +1 -1
  300. package/dist/word/semantic/snippet.js.map +1 -1
  301. package/dist/word/semantic/strikethrough.test.d.ts +2 -0
  302. package/dist/word/semantic/strikethrough.test.d.ts.map +1 -0
  303. package/dist/word/semantic/strikethrough.test.js +17 -0
  304. package/dist/word/semantic/strikethrough.test.js.map +1 -0
  305. package/dist/word/semantic/styles.d.ts.map +1 -1
  306. package/dist/word/semantic/styles.js +2 -2
  307. package/dist/word/semantic/styles.js.map +1 -1
  308. package/package.json +5 -1
@@ -0,0 +1,37 @@
1
+ // Geometry: sheet px on the page to pt on the spread, path points, a
2
+ // box's transform and outline.
3
+ import { num } from './parts.js';
4
+ export const toSpread = (w, x, y) => ({ x: (x - w.ox) * w.k, y: (y - w.oy) * w.k - w.pageH / 2 });
5
+ export const pp = (a, l = a, r = a) => `<PathPointType Anchor="${num(a.x)} ${num(a.y)}" LeftDirection="${num(l.x)} ${num(l.y)}" RightDirection="${num(r.x)} ${num(r.y)}"/>`;
6
+ export function pathGeometry(paths) {
7
+ return `<Properties><PathGeometry>${paths.map((p) => `<GeometryPathType PathOpen="${p.open}"><PathPointArray>${p.points.join('')}</PathPointArray></GeometryPathType>`).join('')}</PathGeometry></Properties>`;
8
+ }
9
+ /** A box `r` (sheet px) turned `rotate`° clockwise about its centre: its
10
+ * item transform and its outline in its own frame (centred, pt). */
11
+ export function boxGeometry(w, r, rotate = 0) {
12
+ const c = toSpread(w, r.x + r.width / 2, r.y + r.height / 2);
13
+ const hw = (r.width * w.k) / 2;
14
+ const hh = (r.height * w.k) / 2;
15
+ const t = (rotate * Math.PI) / 180;
16
+ const cos = Math.cos(t);
17
+ const sin = Math.sin(t);
18
+ const transform = `${num(cos)} ${num(sin)} ${num(-sin)} ${num(cos)} ${num(c.x)} ${num(c.y)}`;
19
+ const points = [pp({ x: -hw, y: -hh }), pp({ x: -hw, y: hh }), pp({ x: hw, y: hh }), pp({ x: hw, y: -hh })];
20
+ return { transform, geometry: pathGeometry([{ points, open: false }]), width: hw * 2, height: hh * 2 };
21
+ }
22
+ export function opacityXml(opacity) {
23
+ return opacity < 1 ? `<TransparencySetting><BlendingSetting Opacity="${num(opacity * 100)}"/></TransparencySetting>` : '';
24
+ }
25
+ /** The sheet box of a chip whose box starts on `run` of `line`. */
26
+ export function chipRect(run, line) {
27
+ const b = run.inline?.kind === 'chip' ? run.inline.box : undefined;
28
+ return b ? { x: run.x + b.dx, y: line.baseline - b.ascent, width: b.width, height: b.ascent + b.descent } : undefined;
29
+ }
30
+ export const union = (rects) => {
31
+ const x = Math.min(...rects.map((r) => r.x));
32
+ const y = Math.min(...rects.map((r) => r.y));
33
+ const right = Math.max(...rects.map((r) => r.x + r.width));
34
+ const bottom = Math.max(...rects.map((r) => r.y + r.height));
35
+ return { x, y, width: right - x, height: bottom - y };
36
+ };
37
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/idml/geometry.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,+BAA+B;AAG/B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC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MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;AACxD,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=idml.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idml.test.d.ts","sourceRoot":"","sources":["../../src/idml/idml.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,494 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { strFromU8, unzipSync } from 'fflate';
3
+ import { build, config, mm, LOREM } from '../word/formatted/formatted.test-helper.js';
4
+ import { parseXml, children, descendants, attr } from '../word/xml.js';
5
+ import { parseFieldCalc } from '../parse/formFields.js';
6
+ import { idmlDocument } from './index.js';
7
+ import { parseCssFont, defaultFontStyleName } from './fonts.js';
8
+ import { pageDisplayList } from '../paint/displayList/page.js';
9
+ import { initMathEngine } from '../math/engine.js';
10
+ const cmyk = (hex, [c, m, y, k]) => ({ hex, model: 'cmyk', cmyk: { c: c, m: m, y: y, k: k } });
11
+ const hex = (h) => ({ hex: h, model: 'hex' });
12
+ const top = (x, y) => ({ anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(x), y: mm(y) } });
13
+ const BLUE = cmyk('#1d4f91', [95, 65, 0, 5]);
14
+ const plain = (id, size, extra = {}) => ({ id, border: { enabled: false }, backgroundEnabled: false, body: { fontSize: { value: size, unit: 'pt' }, ...extra } });
15
+ /** A one-page template: frames by name, each styled by the callout style of its name. */
16
+ function composedConfig(frames, styles, over = {}, decoration) {
17
+ return config({
18
+ colorPalette: [{ id: 'blue', name: 'House blue', value: BLUE }],
19
+ calloutStyles: styles,
20
+ pageTemplates: [{ id: 'sheet', area: 'trim', header: false, footer: false, ...(decoration ? { decoration } : {}), frames }],
21
+ ...over,
22
+ });
23
+ }
24
+ const sheet = (body) => `::::page{template="sheet"}\n${body}\n::::\n`;
25
+ const text = (f, path) => strFromU8(f[path]);
26
+ const xml = (f, path) => parseXml(text(f, path));
27
+ const spreads = (f) => Object.keys(f).filter((p) => p.startsWith('Spreads/')).sort();
28
+ const storyOf = (f, frame) => text(f, `Stories/Story_${attr(frame, 'ParentStory')}.xml`);
29
+ const contents = (story) => [...story.matchAll(/<Content>([^<]*)<\/Content>/g)].map((m) => m[1]).join('');
30
+ /** Write an IDML package and check what InDesign needs to open it: the
31
+ * mimetype first and stored, every part the document map names present
32
+ * and well-formed, ids unique, every frame's story, paragraph style,
33
+ * swatch and face defined. */
34
+ function idml(md, cfg, opts = {}) {
35
+ const { bytes } = idmlDocument({ docs: [build(md, cfg)], ...opts });
36
+ expect(strFromU8(bytes.subarray(30, 38))).toBe('mimetype');
37
+ expect(bytes[8]).toBe(0);
38
+ const f = unzipSync(bytes);
39
+ expect(text(f, 'mimetype')).toBe('application/vnd.adobe.indesign-idml-package');
40
+ const map = xml(f, 'designmap.xml');
41
+ for (const src of [...text(f, 'designmap.xml').matchAll(/src="([^"]+)"/g)].map((m) => m[1]))
42
+ expect(f[src], src).toBeDefined();
43
+ const raw = Object.entries(f).filter(([p]) => p.endsWith('.xml')).map(([p, d]) => [p, strFromU8(d)]);
44
+ for (const [path, source] of raw)
45
+ expect(() => parseXml(source), path).not.toThrow();
46
+ // Self ids: swatches and styles are named by kind, everything else unique.
47
+ const selfs = raw.flatMap(([, source]) => [...source.matchAll(/ Self="([^"]+)"/g)].map((m) => m[1]));
48
+ expect(selfs.filter((s, i) => selfs.indexOf(s) !== i)).toEqual([]);
49
+ const storyList = (attr(map, 'StoryList') ?? '').split(' ').filter(Boolean);
50
+ const stories = Object.keys(f).filter((p) => p.startsWith('Stories/')).map((p) => p.slice('Stories/Story_'.length, -4));
51
+ expect(new Set(storyList)).toEqual(new Set(stories));
52
+ const styles = text(f, 'Resources/Styles.xml');
53
+ const graphic = text(f, 'Resources/Graphic.xml');
54
+ const faces = new Set(descendants(xml(f, 'Resources/Fonts.xml'), 'Font').map((x) => `${attr(x, 'FontFamily')}|${attr(x, 'FontStyleName')}`));
55
+ for (const [path, source] of raw) {
56
+ if (!path.startsWith('Spreads/') && !path.startsWith('Stories/'))
57
+ continue;
58
+ for (const m of source.matchAll(/ ParentStory="([^"]+)"/g))
59
+ expect(stories).toContain(m[1]);
60
+ for (const m of source.matchAll(/ (?:FillColor|StrokeColor)="([^"]+)"/g))
61
+ if (m[1] !== 'Swatch/None')
62
+ expect(graphic, m[1]).toContain(`Self="${m[1]}"`);
63
+ for (const m of source.matchAll(/ AppliedParagraphStyle="([^"]+)"/g))
64
+ expect(styles).toContain(`Self="${m[1]}"`);
65
+ }
66
+ // Every face a style or range sets is in the font list.
67
+ for (const m of styles.matchAll(/FontStyle="([^"]+)"[^>]*>(?:(?!<\/ParagraphStyle>).)*?<AppliedFont type="string">([^<]+)</gs))
68
+ expect(faces).toContain(`${m[2]}|${m[1]}`);
69
+ return f;
70
+ }
71
+ const TITLE_BODY = composedConfig([
72
+ { name: 'title', style: 'title', placement: top(10, 15), width: mm(120), height: mm(15) },
73
+ { name: 'body', style: 'text', placement: top(10, 70), width: mm(120), height: mm(100) },
74
+ ], [plain('title', 20, { color: BLUE }), plain('text', 10, { textAlign: 'justify' })], {}, {
75
+ elements: [
76
+ { kind: 'box', id: 'band', style: { backgroundColor: BLUE }, placement: { ...top(0, 0), size: { width: mm(140), height: mm(40) } } },
77
+ { kind: 'rule', id: 'line', direction: 'horizontal', color: BLUE, thickness: mm(0.5), placement: { ...top(10, 60), size: { width: mm(120) } } },
78
+ ],
79
+ });
80
+ const MD = sheet(`:::frame{slot="title"}
81
+ A title
82
+ :::
83
+
84
+ :::frame{slot="body"}
85
+ ${LOREM}
86
+
87
+ A second paragraph with *italic* words.
88
+ :::`);
89
+ describe('idmlDocument', () => {
90
+ it('writes a package InDesign can read: mimetype first and stored, every part referenced, ids unique', () => {
91
+ const f = idml(MD, TITLE_BODY);
92
+ expect(text(f, 'designmap.xml')).toContain('DOMVersion="8.0"');
93
+ expect(text(f, 'MasterSpreads/MasterSpread_umaster.xml')).toContain('Name="A-Master"');
94
+ });
95
+ it('declares one page per document in the preferences, as InDesign does, however many spreads follow', () => {
96
+ // With the page count there InDesign adds that many pages less one, empty, before the spreads.
97
+ const f = idml(`${MD}\n# A flow page\n\nSome text.\n`, TITLE_BODY);
98
+ expect(spreads(f).length).toBeGreaterThan(1);
99
+ expect(text(f, 'Resources/Preferences.xml')).toContain('PagesPerDocument="1"');
100
+ });
101
+ it('hyphenates only the paragraphs the composer hyphenated', () => {
102
+ const doc = build(MD, TITLE_BODY);
103
+ const f = idml(MD, TITLE_BODY);
104
+ const styles = text(f, 'Resources/Styles.xml');
105
+ for (const m of styles.matchAll(/<ParagraphStyle Self="ParagraphStyle\/(title|text)"[^>]*>/g))
106
+ expect(m[0]).toContain('Hyphenation="false"');
107
+ const items = pageDisplayList(doc, 0).items.filter((i) => i.kind === 'text' && i.frame?.endsWith('body'));
108
+ const hyphenated = items.some((i) => i.kind === 'text' && i.source?.blockKey === items[0].source?.blockKey && i.lines.some((l) => l.addedHyphen));
109
+ expect(hyphenated).toBe(true);
110
+ const frames = descendants(xml(f, spreads(f)[0]), 'TextFrame');
111
+ const body = descendants(parseXml(storyOf(f, frames[1])), 'ParagraphStyleRange');
112
+ const title = descendants(parseXml(storyOf(f, frames[0])), 'ParagraphStyleRange');
113
+ expect(attr(title[0], 'Hyphenation')).toBeUndefined();
114
+ expect(attr(body[0], 'Hyphenation')).toBe('true');
115
+ expect(attr(body[1], 'Hyphenation')).toBeUndefined();
116
+ });
117
+ it('leaves out characters that set nothing and show as a missing glyph (word joiner)', () => {
118
+ const f = idml('Wordjoined\u2060text and a zero-width\uFEFF no-break space.', config());
119
+ const story = Object.keys(f).filter((p) => p.startsWith('Stories/')).map((p) => text(f, p)).join('');
120
+ expect(contents(story)).toContain('Wordjoinedtext');
121
+ expect(contents(story)).not.toMatch(/[\u2060\uFEFF]/);
122
+ expect(contents(story)).toContain('zero-width no-break');
123
+ });
124
+ it('turns each composed frame into one text frame and one story, styled by its callout style', () => {
125
+ const f = idml(MD, TITLE_BODY);
126
+ const spread = xml(f, spreads(f)[0]);
127
+ const frames = descendants(spread, 'TextFrame');
128
+ expect(frames.map((fr) => attr(fr, 'Name'))).toEqual(['title', 'body']);
129
+ expect(descendants(spread, 'GraphicLine')).toHaveLength(1);
130
+ expect(descendants(spread, 'Rectangle').some((r) => attr(r, 'FillColor') === 'Color/House blue')).toBe(true);
131
+ const body = storyOf(f, frames[1]);
132
+ const paras = descendants(parseXml(body), 'ParagraphStyleRange');
133
+ expect(paras.map((p) => attr(p, 'AppliedParagraphStyle'))).toEqual(['ParagraphStyle/text', 'ParagraphStyle/text']);
134
+ // The lines join back into the paragraph: no added hyphens, no lost spaces.
135
+ const words = contents(body);
136
+ expect(words).toContain(LOREM.slice(0, 120));
137
+ expect(words).toContain('internationalization and representativeness');
138
+ expect(body).toMatch(/FontStyle="Italic"[^>]*><Content>italic<\/Content>/);
139
+ expect(body).not.toContain('Justification=');
140
+ const graphic = text(f, 'Resources/Graphic.xml');
141
+ expect(graphic).toContain('Self="Color/House blue" Model="Process" Space="CMYK" ColorValue="95 65 0 5"');
142
+ const styles = text(f, 'Resources/Styles.xml');
143
+ expect(styles).toContain('Self="ParagraphStyle/title"');
144
+ expect(styles).toMatch(/Self="ParagraphStyle\/text"[^>]*Justification="LeftJustified"/);
145
+ });
146
+ it('sets a chip’s words in the text and its box as a rectangle behind the frame; an empty chip is room in thin spaces', () => {
147
+ const cfg = composedConfig([{ name: 'body', style: 'text', placement: top(10, 20), width: mm(120), height: mm(60) }], [plain('text', 10)], {
148
+ chipStyles: [{ id: 'key', paddingX: { value: 2, unit: 'pt' }, background: hex('#eeeeee'), borderColor: hex('#333333'), borderWidth: { value: 1, unit: 'pt' } }],
149
+ });
150
+ const f = idml(sheet(':::frame{slot="body"}\nPress :chip[Enter]{style=key} to go on, or fill in :chip[ ]{style=key} here.\n:::'), cfg);
151
+ const spread = text(f, spreads(f)[0]);
152
+ const story = storyOf(f, descendants(parseXml(spread), 'TextFrame')[0]);
153
+ const words = contents(story);
154
+ expect(words).toMatch(/Press  +Enter + to go on/);
155
+ expect(words).toMatch(/fill in  {3,} here/);
156
+ expect(words).not.toContain('');
157
+ // Two boxes, both painted before (under) the text frame.
158
+ const boxes = [...spread.matchAll(/<Rectangle[^>]*FillColor="Color\/R=238 G=238 B=238"[^>]*StrokeColor="Color\/R=51 G=51 B=51"/g)];
159
+ expect(boxes).toHaveLength(2);
160
+ expect(boxes.every((b) => b.index < spread.indexOf('<TextFrame'))).toBe(true);
161
+ });
162
+ it('sets the text of a frame its fit shrank at the shrunk size and leading', () => {
163
+ const long = Array.from({ length: 4 }, () => LOREM).join('\n\n');
164
+ const frames = (height) => [{ name: 'body', style: 'text', placement: top(10, 20), width: mm(120), height: mm(height), minHeight: mm(height), maxHeight: mm(height) }];
165
+ const styles = [plain('text', 10, { lineHeight: { value: 14, unit: 'pt' } })];
166
+ const md = sheet(`:::frame{slot="body"}\n${long}\n:::`);
167
+ const doc = build(md, composedConfig(frames(40), styles));
168
+ const scale = doc.pages.find((p) => p.composed).composed.frames[0].scale;
169
+ expect(scale).toBeLessThan(1);
170
+ const f = idml(md, composedConfig(frames(40), styles));
171
+ const style = /<ParagraphStyle Self="ParagraphStyle\/text"[^>]*PointSize="([\d.]+)"[^>]*>.*?<Leading type="unit">([\d.]+)</s.exec(text(f, 'Resources/Styles.xml'));
172
+ expect(Number(style[1])).toBeCloseTo(10 * scale, 2);
173
+ expect(Number(style[2])).toBeCloseTo(14 * scale, 2);
174
+ });
175
+ it('puts a list item’s marker in its paragraph: marker, tab, text, hanging indent', () => {
176
+ const cfg = composedConfig([{ name: 'body', style: 'text', placement: top(10, 20), width: mm(120), height: mm(60) }], [plain('text', 10)]);
177
+ const f = idml(sheet(':::frame{slot="body"}\n- First point\n- Second point\n:::'), cfg);
178
+ const story = storyOf(f, descendants(xml(f, spreads(f)[0]), 'TextFrame')[0]);
179
+ const paras = descendants(parseXml(story), 'ParagraphStyleRange');
180
+ expect(paras).toHaveLength(2);
181
+ expect(contents(story)).toMatch(/^\S+\tFirst point\S*\tSecond point$/);
182
+ for (const p of paras) {
183
+ expect(Number(attr(p, 'LeftIndent'))).toBeGreaterThan(0);
184
+ expect(Number(attr(p, 'FirstLineIndent'))).toBeLessThan(0);
185
+ // An explicit tab stop at the text's indent, not InDesign's default stops.
186
+ const stop = descendants(p, 'Position')[0];
187
+ expect(Number(stop.children.join(''))).toBeCloseTo(Number(attr(p, 'LeftIndent')), 3);
188
+ }
189
+ });
190
+ it('keeps a list marker with its item outside composed frames: one text frame, marker and tab first', () => {
191
+ const f = idml('Intro.\n\n- First point\n- Second point', config());
192
+ const frames = descendants(xml(f, spreads(f)[0]), 'TextFrame');
193
+ expect(frames).toHaveLength(3);
194
+ const items = frames.slice(1).map((fr) => contents(storyOf(f, fr)));
195
+ expect(items).toEqual(['•\tFirst point', '•\tSecond point']);
196
+ });
197
+ it('writes frames chained by next as one story through linked text frames, a split paragraph whole', () => {
198
+ const cfg = composedConfig([
199
+ { name: 'a', style: 'text', placement: top(10, 20), width: mm(55), height: mm(40), minHeight: mm(40), maxHeight: mm(40), next: 'b', fit: { shrinkText: false } },
200
+ { name: 'b', style: 'text', placement: top(75, 20), width: mm(55), height: mm(120), fit: { shrinkText: false } },
201
+ ], [plain('text', 10, { lineHeight: { value: 14, unit: 'pt' } })]);
202
+ const md = sheet(`:::frame{slot="a"}\n${LOREM}\n\n${LOREM}\n:::`);
203
+ const doc = build(md, cfg);
204
+ const vframes = doc.pages.find((p) => p.composed).composed.frames;
205
+ expect(vframes.find((x) => x.name === 'a').continuesTo).toBeDefined();
206
+ const f = idml(md, cfg);
207
+ const frames = descendants(xml(f, spreads(f)[0]), 'TextFrame');
208
+ expect(frames.map((x) => attr(x, 'Name'))).toEqual(['a', 'b']);
209
+ const [a, b] = frames;
210
+ expect(attr(a, 'ParentStory')).toBe(attr(b, 'ParentStory'));
211
+ expect(attr(a, 'NextTextFrame')).toBe(attr(b, 'Self'));
212
+ expect(attr(b, 'PreviousTextFrame')).toBe(attr(a, 'Self'));
213
+ expect(attr(a, 'PreviousTextFrame')).toBe('n');
214
+ expect(attr(b, 'NextTextFrame')).toBe('n');
215
+ expect(Object.keys(f).filter((p) => p.startsWith('Stories/'))).toHaveLength(1);
216
+ const story = storyOf(f, a);
217
+ // Two paragraphs, the first cut by the frame break: three ranges, one paragraph return.
218
+ expect(descendants(parseXml(story), 'ParagraphStyleRange')).toHaveLength(3);
219
+ expect(story.match(/<Br\/>/g)).toHaveLength(1);
220
+ expect(contents(story)).toBe(`${LOREM}${LOREM}`);
221
+ });
222
+ // 4.5 mm and 1 mm in pt.
223
+ const MM45 = (4.5 * 72) / 25.4;
224
+ const MM1 = 72 / 25.4;
225
+ const tabsOf = (el) => descendants(el, 'ListItem').map((li) => ({
226
+ align: descendants(li, 'Alignment')[0].children.join(''),
227
+ leader: descendants(li, 'Leader')[0].children.join(''),
228
+ at: Number(descendants(li, 'Position')[0].children.join('')),
229
+ }));
230
+ const storyNo = (path) => parseInt(/Story_u([0-9a-f]+)\.xml$/.exec(path)[1], 16);
231
+ const paraStyle = (f, name) => descendants(xml(f, 'Resources/Styles.xml'), 'ParagraphStyle').find((s) => attr(s, 'Name') === name);
232
+ it('gives a frame style its tab stops and space after; its padding is the frame inset, not an indent', () => {
233
+ const notes = { ...plain('notes', 8, { tabStops: [{ position: mm(4.5) }], paragraphSpacing: mm(1) }), padding: { top: mm(0), right: mm(0), bottom: mm(0), left: mm(4.5) } };
234
+ const cfg = composedConfig([{ name: 'notes', style: 'notes', placement: top(10, 20), width: mm(120), height: mm(60) }], [notes]);
235
+ const f = idml(sheet(':::frame{slot="notes"}\n\\*\tNote\n\n\\*\\*\\*\\*\tNote\n:::'), cfg);
236
+ const style = paraStyle(f, 'notes');
237
+ expect(tabsOf(style)).toEqual([{ align: 'LeftAlign', leader: '', at: expect.closeTo(MM45, 3) }]);
238
+ expect(Number(attr(style, 'SpaceAfter'))).toBeCloseTo(MM1, 3);
239
+ // The engine sets the lines at the padding: that is the frame's inset.
240
+ expect(attr(style, 'LeftIndent')).toBeUndefined();
241
+ expect(attr(style, 'FirstLineIndent')).toBeUndefined();
242
+ const frame = descendants(xml(f, spreads(f)[0]), 'TextFrame')[0];
243
+ expect(Number(attr(descendants(frame, 'TextFramePreference')[0], 'InsetSpacing').split(' ')[1])).toBeCloseTo(MM45, 3);
244
+ // Both notes follow the style: no indents, stops or spacing of their own.
245
+ const story = storyOf(f, frame);
246
+ const paras = descendants(parseXml(story), 'ParagraphStyleRange');
247
+ expect(paras).toHaveLength(2);
248
+ for (const p of paras)
249
+ for (const a of ['LeftIndent', 'FirstLineIndent', 'RightIndent', 'SpaceBefore', 'SpaceAfter'])
250
+ expect(attr(p, a), a).toBeUndefined();
251
+ expect(story).not.toContain('<TabList');
252
+ expect(contents(story)).toBe('*\tNote****\tNote');
253
+ });
254
+ it('keeps a forced line break as InDesign’s (U+2028)', () => {
255
+ const cfg = composedConfig([{ name: 'notes', style: 'notes', placement: top(10, 20), width: mm(120), height: mm(60) }], [plain('notes', 8, { tabStops: [{ position: mm(4.5) }] })]);
256
+ const f = idml(sheet(':::frame{slot="notes"}\n\\*\tNote\\\n\\*\\*\\*\\*\tNote\n:::'), cfg);
257
+ const story = storyOf(f, descendants(xml(f, spreads(f)[0]), 'TextFrame')[0]);
258
+ expect(descendants(parseXml(story), 'ParagraphStyleRange')).toHaveLength(1);
259
+ expect(contents(story)).toBe('*\tNote
****\tNote');
260
+ });
261
+ it('writes a paragraph style’s hanging indent, first-line indent and stops (a leader the stop’s, not text)', () => {
262
+ const cfg = config({
263
+ paragraphStyles: [
264
+ { id: 'hang', name: 'Hang', hangingIndent: mm(4.5), tabStops: [{ position: mm(4.5) }, { position: 'end', align: 'end', leader: '.' }] },
265
+ { id: 'indented', name: 'Indented', indent: mm(3), firstLineIndent: mm(5) },
266
+ ],
267
+ });
268
+ const md = `:::paragraphs{style="hang"}\n\\*\t${LOREM.slice(0, 160)}\tend\n\n\\*\\*\\*\\*\tShort.\n:::\n\n:::paragraphs{style="indented"}\n${LOREM}\n:::\n\nA plain paragraph.`;
269
+ const f = idml(md, cfg);
270
+ // The first paragraph names the style (`Body`): the hanging note's.
271
+ const style = paraStyle(f, 'Body');
272
+ expect(Number(attr(style, 'LeftIndent'))).toBeCloseTo(MM45, 3);
273
+ expect(Number(attr(style, 'FirstLineIndent'))).toBeCloseTo(-MM45, 3);
274
+ const measure = (120 * 72) / 25.4;
275
+ expect(tabsOf(style)).toEqual([
276
+ { align: 'LeftAlign', leader: '', at: expect.closeTo(MM45, 3) },
277
+ { align: 'RightAlign', leader: '.', at: expect.closeTo(measure, 2) },
278
+ ]);
279
+ const stories = Object.keys(f).filter((p) => p.startsWith('Stories/')).sort((a, b) => storyNo(a) - storyNo(b)).map((p) => text(f, p));
280
+ const [long, short, indented, plainText] = stories.map((s) => ({ story: s, para: descendants(parseXml(s), 'ParagraphStyleRange')[0] }));
281
+ // The leader's dots are the stop's: the text holds only the tab.
282
+ expect(contents(long.story)).toMatch(/^\*\tTypesetting .*\tend$/);
283
+ // A note of one line hangs as its style says, with nothing of its own.
284
+ expect(contents(short.story)).toBe('****\tShort.');
285
+ expect(attr(short.para, 'LeftIndent')).toBeUndefined();
286
+ expect(short.story).not.toContain('<TabList');
287
+ // An indented paragraph: indent plus first-line indent, the stops cleared.
288
+ expect(Number(attr(indented.para, 'LeftIndent'))).toBeCloseTo((3 * 72) / 25.4, 3);
289
+ expect(Number(attr(indented.para, 'FirstLineIndent'))).toBeCloseTo((5 * 72) / 25.4, 3);
290
+ expect(indented.story).toContain('<TabList type="list"></TabList>');
291
+ // A paragraph without indents takes none.
292
+ expect(Number(attr(plainText.para, 'LeftIndent'))).toBe(0);
293
+ expect(Number(attr(plainText.para, 'FirstLineIndent'))).toBe(0);
294
+ });
295
+ it('sets a frame its fit shrank as painted: indents, stops, spacing and first baseline at the scale, the padding as it stands', () => {
296
+ const over = { paragraphStyles: [{ id: 'hang', name: 'Hang', hangingIndent: mm(4.5), tabStops: [{ position: mm(4.5) }] }] };
297
+ const styles = [{ ...plain('text', 10, { lineHeight: { value: 14, unit: 'pt' }, paragraphSpacing: mm(2) }), padding: { top: mm(2), right: mm(2), bottom: mm(2), left: mm(3) } }];
298
+ const md = sheet(`:::frame{slot="body"}\n:::paragraphs{style="hang"}\n\\*\t${LOREM}\n\n\\*\t${LOREM}\n:::\n\n${LOREM}\n:::`);
299
+ const at = (height) => {
300
+ const cfg = composedConfig([{ name: 'body', style: 'text', placement: top(10, 20), width: mm(120), height: mm(height), minHeight: mm(height), maxHeight: mm(height) }], styles, over);
301
+ const scale = build(md, cfg).pages.find((p) => p.composed).composed.frames[0].scale ?? 1;
302
+ const f = idml(md, cfg);
303
+ const style = paraStyle(f, 'text');
304
+ const frame = descendants(xml(f, spreads(f)[0]), 'TextFrame')[0];
305
+ const pref = descendants(frame, 'TextFramePreference')[0];
306
+ const paras = descendants(parseXml(storyOf(f, frame)), 'ParagraphStyleRange');
307
+ const n = (el, a) => Number(attr(el, a) ?? 0);
308
+ return {
309
+ scale,
310
+ left: n(style, 'LeftIndent'),
311
+ first: n(style, 'FirstLineIndent'),
312
+ tab: tabsOf(style)[0].at,
313
+ leading: Number(descendants(style, 'Leading')[0].children.join('')),
314
+ inset: attr(pref, 'InsetSpacing'),
315
+ baseline: n(pref, 'MinimumFirstBaselineOffset'),
316
+ space: paras.map((p) => [n(p, 'SpaceBefore'), n(p, 'SpaceAfter')]),
317
+ };
318
+ };
319
+ const full = at(200);
320
+ const shrunk = at(40);
321
+ expect(full.scale).toBe(1);
322
+ const s = shrunk.scale;
323
+ expect(s).toBeLessThan(1);
324
+ // At full size the note hangs 4.5 mm, its stop where the turnover lines start.
325
+ expect(full.left).toBeCloseTo(MM45, 3);
326
+ expect(full.first).toBeCloseTo(-MM45, 3);
327
+ expect(full.tab).toBeCloseTo(MM45, 3);
328
+ // Shrunk, all of it scales alike: the stop still where the turnover lines start.
329
+ expect(shrunk.left).toBeCloseTo(MM45 * s, 3);
330
+ expect(shrunk.first).toBeCloseTo(-MM45 * s, 3);
331
+ expect(shrunk.tab).toBeCloseTo(shrunk.left, 3);
332
+ expect(shrunk.leading).toBeCloseTo(14 * s, 3);
333
+ expect(shrunk.baseline).toBeCloseTo(full.baseline * s, 2);
334
+ expect(shrunk.space).toHaveLength(full.space.length);
335
+ shrunk.space.forEach(([before, after], i) => {
336
+ expect(before).toBeCloseTo(full.space[i][0] * s, 2);
337
+ expect(after).toBeCloseTo(full.space[i][1] * s, 2);
338
+ });
339
+ // The frame's padding is its box's, not scaled: the same insets.
340
+ expect(shrunk.inset).toBe(full.inset);
341
+ expect(Number(full.inset.split(' ')[1])).toBeCloseTo((3 * 72) / 25.4, 3);
342
+ });
343
+ it('sets no indents, stops or spacing for paragraphs without them', () => {
344
+ const f = idml(MD, TITLE_BODY);
345
+ const styles = text(f, 'Resources/Styles.xml');
346
+ const own = [...styles.matchAll(/<ParagraphStyle Self="ParagraphStyle\/(?:title|text)"[^>]*>.*?<\/ParagraphStyle>/gs)].map((m) => m[0]);
347
+ expect(own).toHaveLength(2);
348
+ for (const s of own)
349
+ expect(s).not.toMatch(/LeftIndent|FirstLineIndent|RightIndent|TabList/);
350
+ for (const p of Object.keys(f).filter((k) => k.startsWith('Stories/')))
351
+ expect(text(f, p)).not.toMatch(/LeftIndent|FirstLineIndent|RightIndent|TabList/);
352
+ });
353
+ it('names text outside frames by role, with names the caller may set', () => {
354
+ const cfg = config();
355
+ const md = '# A heading\n\nSome body text.';
356
+ expect(text(idml(md, cfg), 'Resources/Styles.xml')).toMatch(/Name="Heading 1".*Name="Body"/s);
357
+ expect(text(idml(md, cfg, { styleNames: { heading: 'Titel', body: 'Grundtext' } }), 'Resources/Styles.xml')).toMatch(/Name="Titel 1".*Name="Grundtext"/s);
358
+ });
359
+ it('reads CSS font shorthands', () => {
360
+ expect(parseCssFont('italic 700 16px "EB Garamond", serif')).toEqual({ family: 'EB Garamond', weight: 700, italic: true, sizePx: 16 });
361
+ expect(defaultFontStyleName('X', 700, true)).toBe('Bold Italic');
362
+ expect(defaultFontStyleName('X', 400, false)).toBe('Regular');
363
+ expect(parseCssFont('16px Times')).toEqual({ family: 'Times', weight: 400, italic: false, sizePx: 16 });
364
+ expect(parseCssFont('oblique bold 12.5px \'Source Serif 4\', serif')).toEqual({ family: 'Source Serif 4', weight: 700, italic: true, sizePx: 12.5 });
365
+ });
366
+ it('gives each swatch its own id and name, none taking one of InDesign’s own', () => {
367
+ const red = cmyk('#c00000', [0, 100, 100, 0]);
368
+ const green = hex('#00a000');
369
+ const orange = hex('#ffaa00');
370
+ const grey = hex('#123456');
371
+ const colours = [BLUE, red, green, orange, grey];
372
+ const cfg = composedConfig([{ name: 'body', style: 'text', placement: top(10, 120), width: mm(120), height: mm(40) }], [plain('text', 10)], {
373
+ colorPalette: [
374
+ { id: 'a', name: 'House blue', value: BLUE },
375
+ { id: 'b', name: 'Black', value: red },
376
+ { id: 'c', name: 'Paper', value: green },
377
+ { id: 'd', name: 'House blue', value: orange },
378
+ { id: 'e', name: 'None', value: grey },
379
+ ],
380
+ }, { elements: colours.map((c, i) => ({ kind: 'box', id: `b${i}`, style: { backgroundColor: c }, placement: { ...top(10, 10 + i * 20), size: { width: mm(20), height: mm(10) } } })) });
381
+ const graphic = xml(idml(sheet(':::frame{slot="body"}\nText.\n:::'), cfg), 'Resources/Graphic.xml');
382
+ const swatches = descendants(graphic, 'Color').concat(descendants(graphic, 'Swatch'));
383
+ const names = swatches.map((s) => attr(s, 'Name'));
384
+ expect(names.filter((n, i) => names.indexOf(n) !== i)).toEqual([]);
385
+ expect(names).toEqual(expect.arrayContaining(['Black', 'Paper', 'Registration', 'None', 'House blue', 'House blue 2', 'Black 2', 'Paper 2', 'None 2']));
386
+ const byName = (n) => swatches.find((s) => attr(s, 'Name') === n);
387
+ expect(attr(byName('Black 2'), 'ColorValue')).toBe('0 100 100 0');
388
+ expect(attr(byName('Black 2'), 'Self')).toBe('Color/Black 2');
389
+ expect(attr(byName('Paper 2'), 'ColorValue')).toBe('0 160 0');
390
+ });
391
+ it('ends a story with its last paragraph that holds text, with no empty paragraph after it', async () => {
392
+ // The last paragraph is maths alone, which the package leaves out.
393
+ await initMathEngine();
394
+ const md = sheet(':::frame{slot="body"}\nFirst paragraph.\n\nSecond paragraph.\n\n$a^2 + b^2$\n:::');
395
+ const warnings = [];
396
+ const f = idml(md, TITLE_BODY, { onWarning: (w) => warnings.push(w.code) });
397
+ expect(warnings).toContain('text.inline');
398
+ const body = storyOf(f, descendants(xml(f, spreads(f)[0]), 'TextFrame').find((fr) => attr(fr, 'Name') === 'body'));
399
+ expect(descendants(parseXml(body), 'ParagraphStyleRange')).toHaveLength(2);
400
+ expect(body.match(/<Br\/>/g)).toHaveLength(1);
401
+ expect(body).not.toMatch(/<Br\/><\/CharacterStyleRange><\/ParagraphStyleRange><\/Story>/);
402
+ });
403
+ it('warns that right-to-left text is written left to right', () => {
404
+ const ar = 'قال إن كلمة يهتم مسعد كتاب جميلة وكانت المدينة عامرة بالناس والكتب والعلماء.';
405
+ const warnings = [];
406
+ idml(`${ar}\n\n${ar}`, config({ locale: 'ar', direction: 'rtl' }), { onWarning: (w) => warnings.push(w) });
407
+ expect(warnings.filter((w) => w.code === 'text.rtl')).toHaveLength(1);
408
+ expect(warnings.find((w) => w.code === 'text.rtl').message).toMatch(/left to right/);
409
+ const latin = [];
410
+ idml('Some text.', config(), { onWarning: (w) => latin.push(w.code) });
411
+ expect(latin).not.toContain('text.rtl');
412
+ expect(latin).not.toContain('text.vertical');
413
+ });
414
+ it('warns that vertical text is written horizontally', () => {
415
+ const warnings = [];
416
+ const cfg = { ...config(), locale: 'ja', layout: { layoutType: 'single', writingMode: 'vertical-rl' } };
417
+ idml('吾輩は猫である。名前はまだ無い。どこで生れたかとんと見当がつかぬ。', cfg, { onWarning: (w) => warnings.push(w) });
418
+ expect(warnings.filter((w) => w.code === 'text.vertical')).toHaveLength(1);
419
+ expect(warnings.find((w) => w.code === 'text.vertical').message).toMatch(/horizontal/);
420
+ });
421
+ });
422
+ describe('idmlDocument: form fields (#1445)', () => {
423
+ const cfg = composedConfig([{ name: 'body', style: 'text', placement: top(10, 20), width: mm(120), height: mm(120) }], [plain('text', 10)], {
424
+ chipStyles: [
425
+ { id: 'field', minWidth: { value: 40, unit: 'pt' }, paddingX: { value: 2, unit: 'pt' }, background: hex('#f4f4f4'), borderColor: hex('#333333'), borderWidth: { value: 0.5, unit: 'pt' } },
426
+ { id: 'box', minWidth: { value: 10, unit: 'pt' }, borderColor: hex('#333333'), borderWidth: { value: 0.5, unit: 'pt' } },
427
+ ],
428
+ });
429
+ const ORDER = sheet(`:::frame{slot="body"}
430
+ Quantity :chip[ ]{style=field field="order.qty" kind="number"} at :chip[120]{style=field field="order.price" format="currency"} makes :chip[ ]{style=field field="order.total" format="currency" calc="product(order.qty, order.price)"}.
431
+
432
+ Gift wrap :chip[x]{style=box field="order.gift" kind="checkbox"} in :chip[Blue]{style=field field="order.colour" kind="choice" options="Red|Blue|Light green"}, size :chip[M]{style=field field="order.size" kind="choice" options="S|M|L"}.
433
+
434
+ Notes :chip[ ]{style=field field="order.notes" multiline tooltip="Anything else"}
435
+ :::`);
436
+ it('writes a text, number, choice and check box field on each field chip’s box, over the text', () => {
437
+ const warnings = [];
438
+ const f = idml(ORDER, cfg, { onWarning: (w) => warnings.push(w.code) });
439
+ const source = text(f, spreads(f)[0]);
440
+ const spread = parseXml(source);
441
+ const boxes = descendants(spread, 'TextBox');
442
+ expect(boxes.map((b) => attr(b, 'Name'))).toEqual(['order.qty', 'order.price', 'order.total', 'order.notes']);
443
+ expect(source.indexOf('<TextBox')).toBeGreaterThan(source.indexOf('<TextFrame'));
444
+ for (const b of boxes) {
445
+ expect(Number(attr(b, 'FontSize'))).toBeCloseTo(10, 1);
446
+ // Bounds about the field's own origin, its box a rectangle inside it.
447
+ const bounds = descendants(b, 'PathBoundingBox')[0];
448
+ expect(Number(attr(bounds, 'Left'))).toBeCloseTo(-Number(attr(bounds, 'Right')), 3);
449
+ const look = descendants(b, 'Rectangle');
450
+ expect(look).toHaveLength(1);
451
+ expect(attr(look[0], 'FillColor')).toBe('Color/R=244 G=244 B=244');
452
+ expect(attr(look[0], 'StrokeColor')).toBe('Color/R=51 G=51 B=51');
453
+ }
454
+ const byName = (n) => boxes.find((b) => attr(b, 'Name') === n);
455
+ expect(attr(byName('order.notes'), 'Multiline')).toBe('true');
456
+ expect(attr(byName('order.notes'), 'Description')).toBe('Anything else');
457
+ expect(attr(byName('order.total'), 'ReadOnly')).toBe('true');
458
+ const label = (b) => Object.fromEntries(descendants(b, 'KeyValuePair').map((p) => [attr(p, 'Key'), attr(p, 'Value')]));
459
+ expect(label(byName('order.price'))).toEqual({ 'postext:value': '120', 'postext:format': 'currency' });
460
+ expect(label(byName('order.total'))).toEqual({ 'postext:format': 'currency', 'postext:calc': 'product(order.qty, order.price)' });
461
+ const [gift] = descendants(spread, 'CheckBox');
462
+ expect(attr(gift, 'Name')).toBe('order.gift');
463
+ expect(attr(gift, 'CheckedByDefault')).toBe('true');
464
+ const states = descendants(gift, 'State');
465
+ expect(states.map((st) => descendants(st, 'Statetype')[0].children.join(''))).toEqual(['UpOff', 'UpOn']);
466
+ expect(descendants(states[1], 'Polygon')).toHaveLength(1);
467
+ const combos = descendants(spread, 'ComboBox');
468
+ expect(combos.map((c) => attr(c, 'Name'))).toEqual(['order.colour', 'order.size']);
469
+ expect(descendants(combos[0], 'ListItem').map((li) => li.children.join(''))).toEqual(['Red', 'Blue', 'Light green']);
470
+ expect(attr(combos[1], 'ChoiceList')).toBe('S M L');
471
+ // The field chips' words are not in the text, their boxes no loose rectangles.
472
+ const words = contents(storyOf(f, descendants(spread, 'TextFrame')[0]));
473
+ expect(words).toMatch(/^Quantity  + at  + makes  +\.Gift wrap  + in  +, size  +\.Notes  +$/);
474
+ expect(children(descendants(spread, 'Spread')[0], 'Rectangle')).toHaveLength(0);
475
+ expect(warnings).toEqual(expect.arrayContaining(['field.value', 'field.script']));
476
+ });
477
+ it('labels a calculation in full, numbers and nested calculations, as the calc attribute reads it', () => {
478
+ const calc = 'sum(order.total, product(order.gift, 4.5), max(order.fee, 2))';
479
+ const f = idml(sheet(`:::frame{slot="body"}\nTotal :chip[ ]{style=field field="order.sum" format="currency" calc="${calc}"}\n:::`), cfg);
480
+ const box = descendants(xml(f, spreads(f)[0]), 'TextBox')[0];
481
+ const label = descendants(box, 'KeyValuePair').find((p) => attr(p, 'Key') === 'postext:calc');
482
+ expect(attr(label, 'Value')).toBe(calc);
483
+ expect(parseFieldCalc(attr(label, 'Value'))).toEqual(parseFieldCalc(calc));
484
+ });
485
+ it('writes field chips as chips with forms: false', () => {
486
+ const f = idml(ORDER, cfg, { forms: false });
487
+ const source = text(f, spreads(f)[0]);
488
+ expect(source).not.toMatch(/<(TextBox|CheckBox|ComboBox)/);
489
+ const words = contents(storyOf(f, descendants(parseXml(source), 'TextFrame')[0]));
490
+ expect(words).toContain('120');
491
+ expect(words).toContain('Blue');
492
+ });
493
+ });
494
+ //# sourceMappingURL=idml.test.js.map