@bendyline/squisq 0.1.2 → 1.1.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 (349) hide show
  1. package/dist/{themeLibrary-DySHPcgj.d.ts → Doc-1hmT1LZl.d.ts} +1 -42
  2. package/dist/MediaProvider-wpSe21B3.d.ts +66 -0
  3. package/dist/__tests__/animationUtils.test.d.ts +2 -0
  4. package/dist/__tests__/animationUtils.test.d.ts.map +1 -0
  5. package/dist/__tests__/animationUtils.test.js +60 -0
  6. package/dist/__tests__/animationUtils.test.js.map +1 -0
  7. package/dist/__tests__/contentContainer.test.d.ts +2 -0
  8. package/dist/__tests__/contentContainer.test.d.ts.map +1 -0
  9. package/dist/__tests__/contentContainer.test.js +234 -0
  10. package/dist/__tests__/contentContainer.test.js.map +1 -0
  11. package/dist/__tests__/contentExtractor.test.d.ts +2 -0
  12. package/dist/__tests__/contentExtractor.test.d.ts.map +1 -0
  13. package/dist/__tests__/contentExtractor.test.js +151 -0
  14. package/dist/__tests__/contentExtractor.test.js.map +1 -0
  15. package/dist/__tests__/geohash.test.d.ts +2 -0
  16. package/dist/__tests__/geohash.test.d.ts.map +1 -0
  17. package/dist/__tests__/geohash.test.js +87 -0
  18. package/dist/__tests__/geohash.test.js.map +1 -0
  19. package/dist/__tests__/getLayers.test.d.ts +2 -0
  20. package/dist/__tests__/getLayers.test.d.ts.map +1 -0
  21. package/dist/__tests__/getLayers.test.js +167 -0
  22. package/dist/__tests__/getLayers.test.js.map +1 -0
  23. package/dist/__tests__/haversine.test.d.ts +2 -0
  24. package/dist/__tests__/haversine.test.d.ts.map +1 -0
  25. package/dist/__tests__/haversine.test.js +56 -0
  26. package/dist/__tests__/haversine.test.js.map +1 -0
  27. package/dist/__tests__/localForageAdapter.test.d.ts +8 -0
  28. package/dist/__tests__/localForageAdapter.test.d.ts.map +1 -0
  29. package/dist/__tests__/localForageAdapter.test.js +130 -0
  30. package/dist/__tests__/localForageAdapter.test.js.map +1 -0
  31. package/dist/__tests__/markdown.test.d.ts +2 -0
  32. package/dist/__tests__/markdown.test.d.ts.map +1 -0
  33. package/dist/__tests__/markdown.test.js +654 -0
  34. package/dist/__tests__/markdown.test.js.map +1 -0
  35. package/dist/__tests__/markdownToDoc.test.d.ts +2 -0
  36. package/dist/__tests__/markdownToDoc.test.d.ts.map +1 -0
  37. package/dist/__tests__/markdownToDoc.test.js +313 -0
  38. package/dist/__tests__/markdownToDoc.test.js.map +1 -0
  39. package/dist/__tests__/seededRandom.test.d.ts +2 -0
  40. package/dist/__tests__/seededRandom.test.d.ts.map +1 -0
  41. package/dist/__tests__/seededRandom.test.js +125 -0
  42. package/dist/__tests__/seededRandom.test.js.map +1 -0
  43. package/dist/__tests__/slideshowGenerator.test.d.ts +2 -0
  44. package/dist/__tests__/slideshowGenerator.test.d.ts.map +1 -0
  45. package/dist/__tests__/slideshowGenerator.test.js +114 -0
  46. package/dist/__tests__/slideshowGenerator.test.js.map +1 -0
  47. package/dist/__tests__/storage.test.d.ts +2 -0
  48. package/dist/__tests__/storage.test.d.ts.map +1 -0
  49. package/dist/__tests__/storage.test.js +51 -0
  50. package/dist/__tests__/storage.test.js.map +1 -0
  51. package/dist/__tests__/templates.test.d.ts +2 -0
  52. package/dist/__tests__/templates.test.d.ts.map +1 -0
  53. package/dist/__tests__/templates.test.js +217 -0
  54. package/dist/__tests__/templates.test.js.map +1 -0
  55. package/dist/__tests__/timing.test.d.ts +2 -0
  56. package/dist/__tests__/timing.test.d.ts.map +1 -0
  57. package/dist/__tests__/timing.test.js +131 -0
  58. package/dist/__tests__/timing.test.js.map +1 -0
  59. package/dist/chunk-3E5F2XMR.js +129 -0
  60. package/dist/chunk-3E5F2XMR.js.map +1 -0
  61. package/dist/chunk-4CRBS35L.js +292 -0
  62. package/dist/chunk-4CRBS35L.js.map +1 -0
  63. package/dist/chunk-6YJPI6VI.js +35 -0
  64. package/dist/chunk-6YJPI6VI.js.map +1 -0
  65. package/dist/chunk-FVTQSNR7.js +100 -0
  66. package/dist/chunk-FVTQSNR7.js.map +1 -0
  67. package/dist/chunk-V543AI2F.js +1 -0
  68. package/dist/chunk-V543AI2F.js.map +1 -0
  69. package/dist/chunk-VP5SZTZ2.js +792 -0
  70. package/dist/chunk-VP5SZTZ2.js.map +1 -0
  71. package/dist/doc/docToMarkdown.d.ts +41 -0
  72. package/dist/doc/docToMarkdown.d.ts.map +1 -0
  73. package/dist/doc/docToMarkdown.js +88 -0
  74. package/dist/doc/docToMarkdown.js.map +1 -0
  75. package/dist/doc/getLayers.d.ts +65 -0
  76. package/dist/doc/getLayers.d.ts.map +1 -0
  77. package/dist/doc/getLayers.js +103 -0
  78. package/dist/doc/getLayers.js.map +1 -0
  79. package/dist/doc/index.d.ts +9 -3
  80. package/dist/doc/index.d.ts.map +1 -0
  81. package/dist/doc/index.js +6 -125
  82. package/dist/doc/index.js.map +1 -1
  83. package/dist/doc/markdownToDoc.d.ts +68 -0
  84. package/dist/doc/markdownToDoc.d.ts.map +1 -0
  85. package/dist/doc/markdownToDoc.js +225 -0
  86. package/dist/doc/markdownToDoc.js.map +1 -0
  87. package/dist/doc/templates/accentImage.d.ts +59 -0
  88. package/dist/doc/templates/accentImage.d.ts.map +1 -0
  89. package/dist/doc/templates/accentImage.js +275 -0
  90. package/dist/doc/templates/accentImage.js.map +1 -0
  91. package/dist/doc/templates/captionUtils.d.ts +20 -0
  92. package/dist/doc/templates/captionUtils.d.ts.map +1 -0
  93. package/dist/doc/templates/captionUtils.js +29 -0
  94. package/dist/doc/templates/captionUtils.js.map +1 -0
  95. package/dist/doc/templates/comparisonBar.d.ts +13 -0
  96. package/dist/doc/templates/comparisonBar.d.ts.map +1 -0
  97. package/dist/doc/templates/comparisonBar.js +127 -0
  98. package/dist/doc/templates/comparisonBar.js.map +1 -0
  99. package/dist/doc/templates/coverBlock.d.ts +51 -0
  100. package/dist/doc/templates/coverBlock.d.ts.map +1 -0
  101. package/dist/doc/templates/coverBlock.js +125 -0
  102. package/dist/doc/templates/coverBlock.js.map +1 -0
  103. package/dist/doc/templates/dateEvent.d.ts +15 -0
  104. package/dist/doc/templates/dateEvent.d.ts.map +1 -0
  105. package/dist/doc/templates/dateEvent.js +110 -0
  106. package/dist/doc/templates/dateEvent.js.map +1 -0
  107. package/dist/doc/templates/definitionCard.d.ts +13 -0
  108. package/dist/doc/templates/definitionCard.d.ts.map +1 -0
  109. package/dist/doc/templates/definitionCard.js +114 -0
  110. package/dist/doc/templates/definitionCard.js.map +1 -0
  111. package/dist/doc/templates/factCard.d.ts +15 -0
  112. package/dist/doc/templates/factCard.d.ts.map +1 -0
  113. package/dist/doc/templates/factCard.js +100 -0
  114. package/dist/doc/templates/factCard.js.map +1 -0
  115. package/dist/doc/templates/fullBleedQuote.d.ts +13 -0
  116. package/dist/doc/templates/fullBleedQuote.d.ts.map +1 -0
  117. package/dist/doc/templates/fullBleedQuote.js +54 -0
  118. package/dist/doc/templates/fullBleedQuote.js.map +1 -0
  119. package/dist/doc/templates/imageWithCaption.d.ts +13 -0
  120. package/dist/doc/templates/imageWithCaption.d.ts.map +1 -0
  121. package/dist/doc/templates/imageWithCaption.js +142 -0
  122. package/dist/doc/templates/imageWithCaption.js.map +1 -0
  123. package/dist/doc/templates/index.d.ts +104 -0
  124. package/dist/doc/templates/index.d.ts.map +1 -0
  125. package/dist/doc/templates/index.js +442 -0
  126. package/dist/doc/templates/index.js.map +1 -0
  127. package/dist/doc/templates/listBlock.d.ts +13 -0
  128. package/dist/doc/templates/listBlock.d.ts.map +1 -0
  129. package/dist/doc/templates/listBlock.js +89 -0
  130. package/dist/doc/templates/listBlock.js.map +1 -0
  131. package/dist/doc/templates/mapBlock.d.ts +17 -0
  132. package/dist/doc/templates/mapBlock.d.ts.map +1 -0
  133. package/dist/doc/templates/mapBlock.js +112 -0
  134. package/dist/doc/templates/mapBlock.js.map +1 -0
  135. package/dist/doc/templates/persistentLayers.d.ts +39 -0
  136. package/dist/doc/templates/persistentLayers.d.ts.map +1 -0
  137. package/dist/doc/templates/persistentLayers.js +447 -0
  138. package/dist/doc/templates/persistentLayers.js.map +1 -0
  139. package/dist/doc/templates/photoGrid.d.ts +20 -0
  140. package/dist/doc/templates/photoGrid.d.ts.map +1 -0
  141. package/dist/doc/templates/photoGrid.js +172 -0
  142. package/dist/doc/templates/photoGrid.js.map +1 -0
  143. package/dist/doc/templates/pullQuote.d.ts +13 -0
  144. package/dist/doc/templates/pullQuote.d.ts.map +1 -0
  145. package/dist/doc/templates/pullQuote.js +109 -0
  146. package/dist/doc/templates/pullQuote.js.map +1 -0
  147. package/dist/doc/templates/quoteBlock.d.ts +15 -0
  148. package/dist/doc/templates/quoteBlock.d.ts.map +1 -0
  149. package/dist/doc/templates/quoteBlock.js +97 -0
  150. package/dist/doc/templates/quoteBlock.js.map +1 -0
  151. package/dist/doc/templates/sectionHeader.d.ts +14 -0
  152. package/dist/doc/templates/sectionHeader.d.ts.map +1 -0
  153. package/dist/doc/templates/sectionHeader.js +96 -0
  154. package/dist/doc/templates/sectionHeader.js.map +1 -0
  155. package/dist/doc/templates/statHighlight.d.ts +15 -0
  156. package/dist/doc/templates/statHighlight.d.ts.map +1 -0
  157. package/dist/doc/templates/statHighlight.js +99 -0
  158. package/dist/doc/templates/statHighlight.js.map +1 -0
  159. package/dist/doc/templates/titleBlock.d.ts +13 -0
  160. package/dist/doc/templates/titleBlock.d.ts.map +1 -0
  161. package/dist/doc/templates/titleBlock.js +92 -0
  162. package/dist/doc/templates/titleBlock.js.map +1 -0
  163. package/dist/doc/templates/twoColumn.d.ts +15 -0
  164. package/dist/doc/templates/twoColumn.d.ts.map +1 -0
  165. package/dist/doc/templates/twoColumn.js +219 -0
  166. package/dist/doc/templates/twoColumn.js.map +1 -0
  167. package/dist/doc/templates/videoPullQuote.d.ts +20 -0
  168. package/dist/doc/templates/videoPullQuote.d.ts.map +1 -0
  169. package/dist/doc/templates/videoPullQuote.js +118 -0
  170. package/dist/doc/templates/videoPullQuote.js.map +1 -0
  171. package/dist/doc/templates/videoWithCaption.d.ts +20 -0
  172. package/dist/doc/templates/videoWithCaption.d.ts.map +1 -0
  173. package/dist/doc/templates/videoWithCaption.js +104 -0
  174. package/dist/doc/templates/videoWithCaption.js.map +1 -0
  175. package/dist/doc/utils/animationUtils.d.ts +34 -0
  176. package/dist/doc/utils/animationUtils.d.ts.map +1 -0
  177. package/dist/doc/utils/animationUtils.js +110 -0
  178. package/dist/doc/utils/animationUtils.js.map +1 -0
  179. package/dist/doc/utils/themeUtils.d.ts +55 -0
  180. package/dist/doc/utils/themeUtils.d.ts.map +1 -0
  181. package/dist/doc/utils/themeUtils.js +109 -0
  182. package/dist/doc/utils/themeUtils.js.map +1 -0
  183. package/dist/generate/contentExtractor.d.ts +112 -0
  184. package/dist/generate/contentExtractor.d.ts.map +1 -0
  185. package/dist/generate/contentExtractor.js +638 -0
  186. package/dist/generate/contentExtractor.js.map +1 -0
  187. package/dist/generate/index.d.ts +7 -0
  188. package/dist/generate/index.d.ts.map +1 -0
  189. package/dist/generate/index.js +4 -0
  190. package/dist/generate/index.js.map +1 -0
  191. package/dist/generate/slideshowGenerator.d.ts +72 -0
  192. package/dist/generate/slideshowGenerator.d.ts.map +1 -0
  193. package/dist/generate/slideshowGenerator.js +159 -0
  194. package/dist/generate/slideshowGenerator.js.map +1 -0
  195. package/dist/generate/templateMapper.d.ts +23 -0
  196. package/dist/generate/templateMapper.d.ts.map +1 -0
  197. package/dist/generate/templateMapper.js +114 -0
  198. package/dist/generate/templateMapper.js.map +1 -0
  199. package/dist/index.d.ts +9 -8
  200. package/dist/index.d.ts.map +1 -0
  201. package/dist/index.js +8 -216
  202. package/dist/index.js.map +1 -1
  203. package/dist/markdown/convert.d.ts +71 -0
  204. package/dist/markdown/convert.d.ts.map +1 -0
  205. package/dist/markdown/convert.js +746 -0
  206. package/dist/markdown/convert.js.map +1 -0
  207. package/dist/markdown/htmlParse.d.ts +26 -0
  208. package/dist/markdown/htmlParse.d.ts.map +1 -0
  209. package/dist/markdown/htmlParse.js +195 -0
  210. package/dist/markdown/htmlParse.js.map +1 -0
  211. package/dist/markdown/index.d.ts +19 -225
  212. package/dist/markdown/index.d.ts.map +1 -0
  213. package/dist/markdown/index.js +33 -32
  214. package/dist/markdown/index.js.map +1 -1
  215. package/dist/markdown/parse.d.ts +27 -0
  216. package/dist/markdown/parse.d.ts.map +1 -0
  217. package/dist/markdown/parse.js +90 -0
  218. package/dist/markdown/parse.js.map +1 -0
  219. package/dist/markdown/stringify.d.ts +32 -0
  220. package/dist/markdown/stringify.d.ts.map +1 -0
  221. package/dist/markdown/stringify.js +108 -0
  222. package/dist/markdown/stringify.js.map +1 -0
  223. package/dist/markdown/types.d.ts +496 -0
  224. package/dist/markdown/types.d.ts.map +1 -0
  225. package/dist/markdown/types.js +17 -0
  226. package/dist/markdown/types.js.map +1 -0
  227. package/dist/markdown/utils.d.ts +78 -0
  228. package/dist/markdown/utils.d.ts.map +1 -0
  229. package/dist/markdown/utils.js +149 -0
  230. package/dist/markdown/utils.js.map +1 -0
  231. package/dist/random/SeededRandom.d.ts +50 -0
  232. package/dist/random/SeededRandom.d.ts.map +1 -0
  233. package/dist/random/SeededRandom.js +115 -0
  234. package/dist/random/SeededRandom.js.map +1 -0
  235. package/dist/random/index.d.ts +2 -0
  236. package/dist/random/index.d.ts.map +1 -0
  237. package/dist/random/index.js +2 -0
  238. package/dist/random/index.js.map +1 -0
  239. package/dist/schemas/BlockTemplates.d.ts +583 -0
  240. package/dist/schemas/BlockTemplates.d.ts.map +1 -0
  241. package/dist/schemas/BlockTemplates.js +72 -0
  242. package/dist/schemas/BlockTemplates.js.map +1 -0
  243. package/dist/schemas/Doc.d.ts +411 -0
  244. package/dist/schemas/Doc.d.ts.map +1 -0
  245. package/dist/schemas/Doc.js +90 -0
  246. package/dist/schemas/Doc.js.map +1 -0
  247. package/dist/schemas/LayoutStrategy.d.ts +84 -0
  248. package/dist/schemas/LayoutStrategy.d.ts.map +1 -0
  249. package/dist/schemas/LayoutStrategy.js +123 -0
  250. package/dist/schemas/LayoutStrategy.js.map +1 -0
  251. package/dist/schemas/MediaProvider.d.ts +65 -0
  252. package/dist/schemas/MediaProvider.d.ts.map +1 -0
  253. package/dist/schemas/MediaProvider.js +13 -0
  254. package/dist/schemas/MediaProvider.js.map +1 -0
  255. package/dist/schemas/Theme.d.ts +163 -0
  256. package/dist/schemas/Theme.d.ts.map +1 -0
  257. package/dist/schemas/Theme.js +62 -0
  258. package/dist/schemas/Theme.js.map +1 -0
  259. package/dist/schemas/Types.d.ts +14 -0
  260. package/dist/schemas/Types.d.ts.map +1 -0
  261. package/dist/schemas/Types.js +5 -0
  262. package/dist/schemas/Types.js.map +1 -0
  263. package/dist/schemas/Viewport.d.ts +74 -0
  264. package/dist/schemas/Viewport.d.ts.map +1 -0
  265. package/dist/schemas/Viewport.js +63 -0
  266. package/dist/schemas/Viewport.js.map +1 -0
  267. package/dist/schemas/index.d.ts +10 -70
  268. package/dist/schemas/index.d.ts.map +1 -0
  269. package/dist/schemas/index.js +7 -60
  270. package/dist/schemas/index.js.map +1 -1
  271. package/dist/schemas/themeLibrary.d.ts +41 -0
  272. package/dist/schemas/themeLibrary.d.ts.map +1 -0
  273. package/dist/schemas/themeLibrary.js +466 -0
  274. package/dist/schemas/themeLibrary.js.map +1 -0
  275. package/dist/spatial/Geohash.d.ts +85 -0
  276. package/dist/spatial/Geohash.d.ts.map +1 -0
  277. package/dist/spatial/Geohash.js +142 -0
  278. package/dist/spatial/Geohash.js.map +1 -0
  279. package/dist/spatial/Haversine.d.ts +24 -0
  280. package/dist/spatial/Haversine.d.ts.map +1 -0
  281. package/dist/spatial/Haversine.js +48 -0
  282. package/dist/spatial/Haversine.js.map +1 -0
  283. package/dist/spatial/index.d.ts +3 -111
  284. package/dist/spatial/index.d.ts.map +1 -0
  285. package/dist/spatial/index.js +2 -24
  286. package/dist/spatial/index.js.map +1 -1
  287. package/dist/storage/ContentContainer.d.ts +87 -0
  288. package/dist/storage/ContentContainer.d.ts.map +1 -0
  289. package/dist/storage/ContentContainer.js +122 -0
  290. package/dist/storage/ContentContainer.js.map +1 -0
  291. package/dist/storage/LocalForageAdapter.d.ts +36 -0
  292. package/dist/storage/LocalForageAdapter.d.ts.map +1 -0
  293. package/dist/storage/LocalForageAdapter.js +82 -0
  294. package/dist/storage/LocalForageAdapter.js.map +1 -0
  295. package/dist/storage/LocalStorageAdapter.d.ts +16 -0
  296. package/dist/storage/LocalStorageAdapter.d.ts.map +1 -0
  297. package/dist/storage/LocalStorageAdapter.js +50 -0
  298. package/dist/storage/LocalStorageAdapter.js.map +1 -0
  299. package/dist/storage/MediaProviderFromContainer.d.ts +21 -0
  300. package/dist/storage/MediaProviderFromContainer.d.ts.map +1 -0
  301. package/dist/storage/MediaProviderFromContainer.js +79 -0
  302. package/dist/storage/MediaProviderFromContainer.js.map +1 -0
  303. package/dist/storage/MemoryStorageAdapter.d.ts +15 -0
  304. package/dist/storage/MemoryStorageAdapter.d.ts.map +1 -0
  305. package/dist/storage/MemoryStorageAdapter.js +34 -0
  306. package/dist/storage/MemoryStorageAdapter.js.map +1 -0
  307. package/dist/storage/Storage.d.ts +23 -0
  308. package/dist/storage/Storage.d.ts.map +1 -0
  309. package/dist/storage/Storage.js +9 -0
  310. package/dist/storage/Storage.js.map +1 -0
  311. package/dist/storage/index.d.ts +9 -91
  312. package/dist/storage/index.d.ts.map +1 -0
  313. package/dist/storage/index.js +5 -10
  314. package/dist/storage/index.js.map +1 -1
  315. package/dist/story/index.d.ts +3 -2
  316. package/dist/themeLibrary-DR1VRo-8.d.ts +44 -0
  317. package/dist/timing/index.d.ts +4 -0
  318. package/dist/timing/index.d.ts.map +1 -0
  319. package/dist/timing/index.js +3 -0
  320. package/dist/timing/index.js.map +1 -0
  321. package/dist/timing/narrationTiming.d.ts +54 -0
  322. package/dist/timing/narrationTiming.d.ts.map +1 -0
  323. package/dist/timing/narrationTiming.js +190 -0
  324. package/dist/timing/narrationTiming.js.map +1 -0
  325. package/dist/timing/readingTime.d.ts +54 -0
  326. package/dist/timing/readingTime.d.ts.map +1 -0
  327. package/dist/timing/readingTime.js +49 -0
  328. package/dist/timing/readingTime.js.map +1 -0
  329. package/package.json +17 -3
  330. package/src/__tests__/contentContainer.test.ts +282 -0
  331. package/src/__tests__/contentExtractor.test.ts +183 -0
  332. package/src/__tests__/seededRandom.test.ts +142 -0
  333. package/src/__tests__/slideshowGenerator.test.ts +128 -0
  334. package/src/__tests__/timing.test.ts +167 -0
  335. package/src/generate/contentExtractor.ts +808 -0
  336. package/src/generate/index.ts +21 -0
  337. package/src/generate/slideshowGenerator.ts +273 -0
  338. package/src/generate/templateMapper.ts +170 -0
  339. package/src/index.ts +3 -0
  340. package/src/random/SeededRandom.ts +127 -0
  341. package/src/random/index.ts +1 -0
  342. package/src/storage/ContentContainer.ts +200 -0
  343. package/src/storage/MediaProviderFromContainer.ts +92 -0
  344. package/src/storage/index.ts +3 -0
  345. package/src/timing/index.ts +17 -0
  346. package/src/timing/narrationTiming.ts +220 -0
  347. package/src/timing/readingTime.ts +94 -0
  348. package/dist/chunk-VJN7UB2Z.js +0 -145
  349. package/dist/chunk-VJN7UB2Z.js.map +0 -1
@@ -0,0 +1,200 @@
1
+ /**
2
+ * ContentContainer — virtual file system for document containers.
3
+ *
4
+ * A Squisq document is more than just markdown: it's a container of files
5
+ * including the primary markdown document, images, audio, timing data, and
6
+ * other media. ContentContainer provides an abstract async file system
7
+ * interface for reading, writing, and listing these files.
8
+ *
9
+ * Paths are forward-slash separated strings relative to the container root
10
+ * (e.g., 'images/hero.jpg', 'index.md'). No leading slash.
11
+ *
12
+ * Implementations:
13
+ * - MemoryContentContainer — in-memory Map (for zip import, tests, transient use)
14
+ * - SlotContentContainer — backed by IndexedDB slot storage (in the site package)
15
+ */
16
+
17
+ /**
18
+ * Metadata about a file in a ContentContainer.
19
+ */
20
+ export interface ContentEntry {
21
+ /** Relative path within the container (e.g., 'images/hero.jpg') */
22
+ path: string;
23
+ /** MIME type (e.g., 'image/jpeg') */
24
+ mimeType: string;
25
+ /** File size in bytes */
26
+ size: number;
27
+ }
28
+
29
+ /**
30
+ * Abstract async file system for document containers.
31
+ *
32
+ * All paths are forward-slash separated, relative to the container root,
33
+ * with no leading slash. Example: 'images/hero.jpg', 'index.md'.
34
+ */
35
+ export interface ContentContainer {
36
+ /** Read a file's binary content. Returns null if the file does not exist. */
37
+ readFile(path: string): Promise<ArrayBuffer | null>;
38
+
39
+ /** Write a file. Creates or overwrites. */
40
+ writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void>;
41
+
42
+ /** Remove a file. No-op if the file does not exist. */
43
+ removeFile(path: string): Promise<void>;
44
+
45
+ /**
46
+ * List files in the container.
47
+ * @param prefix — Optional path prefix to filter by (e.g., 'images/')
48
+ */
49
+ listFiles(prefix?: string): Promise<ContentEntry[]>;
50
+
51
+ /** Check whether a file exists. */
52
+ exists(path: string): Promise<boolean>;
53
+
54
+ /**
55
+ * Find the primary markdown document path.
56
+ *
57
+ * Discovery order: index.md → doc.md → document.md → first *.md at root.
58
+ * Returns null if no markdown file is found at the root level.
59
+ */
60
+ getDocumentPath(): Promise<string | null>;
61
+
62
+ /**
63
+ * Convenience: read the primary markdown document as a UTF-8 string.
64
+ * Returns null if no markdown file is found.
65
+ */
66
+ readDocument(): Promise<string | null>;
67
+
68
+ /**
69
+ * Convenience: write a markdown document.
70
+ * @param markdown — The markdown content
71
+ * @param filename — Filename to use (defaults to 'index.md')
72
+ */
73
+ writeDocument(markdown: string, filename?: string): Promise<void>;
74
+ }
75
+
76
+ // ============================================
77
+ // Well-known markdown filenames in priority order
78
+ // ============================================
79
+
80
+ const MARKDOWN_PRIORITY = ['index.md', 'doc.md', 'document.md'];
81
+
82
+ /**
83
+ * Find the primary markdown path from a list of file entries.
84
+ * Exported for reuse by other ContentContainer implementations.
85
+ */
86
+ export function findDocumentPath(entries: ContentEntry[]): string | null {
87
+ // Only consider root-level files (no '/' in path)
88
+ const rootFiles = entries.filter((e) => !e.path.includes('/'));
89
+
90
+ for (const name of MARKDOWN_PRIORITY) {
91
+ if (rootFiles.some((e) => e.path.toLowerCase() === name)) {
92
+ return name;
93
+ }
94
+ }
95
+
96
+ // Fallback: first .md file at root
97
+ const firstMd = rootFiles.find((e) => e.path.toLowerCase().endsWith('.md'));
98
+ return firstMd?.path ?? null;
99
+ }
100
+
101
+ // ============================================
102
+ // MemoryContentContainer
103
+ // ============================================
104
+
105
+ interface MemoryFile {
106
+ data: ArrayBuffer;
107
+ mimeType: string;
108
+ }
109
+
110
+ /**
111
+ * In-memory ContentContainer backed by a Map.
112
+ *
113
+ * Used for zip import (deserialize into memory), tests, and transient operations.
114
+ */
115
+ export class MemoryContentContainer implements ContentContainer {
116
+ private files = new Map<string, MemoryFile>();
117
+
118
+ async readFile(path: string): Promise<ArrayBuffer | null> {
119
+ return this.files.get(path)?.data ?? null;
120
+ }
121
+
122
+ async writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void> {
123
+ const buffer = data instanceof ArrayBuffer ? data : data.slice().buffer;
124
+ this.files.set(path, {
125
+ data: buffer,
126
+ mimeType: mimeType ?? guessMimeType(path),
127
+ });
128
+ }
129
+
130
+ async removeFile(path: string): Promise<void> {
131
+ this.files.delete(path);
132
+ }
133
+
134
+ async listFiles(prefix?: string): Promise<ContentEntry[]> {
135
+ const entries: ContentEntry[] = [];
136
+ for (const [path, file] of this.files) {
137
+ if (prefix && !path.startsWith(prefix)) continue;
138
+ entries.push({
139
+ path,
140
+ mimeType: file.mimeType,
141
+ size: file.data.byteLength,
142
+ });
143
+ }
144
+ return entries;
145
+ }
146
+
147
+ async exists(path: string): Promise<boolean> {
148
+ return this.files.has(path);
149
+ }
150
+
151
+ async getDocumentPath(): Promise<string | null> {
152
+ return findDocumentPath(await this.listFiles());
153
+ }
154
+
155
+ async readDocument(): Promise<string | null> {
156
+ const docPath = await this.getDocumentPath();
157
+ if (!docPath) return null;
158
+ const data = await this.readFile(docPath);
159
+ if (!data) return null;
160
+ return new TextDecoder().decode(data);
161
+ }
162
+
163
+ async writeDocument(markdown: string, filename?: string): Promise<void> {
164
+ const name = filename ?? 'index.md';
165
+ const data = new TextEncoder().encode(markdown);
166
+ await this.writeFile(name, data, 'text/markdown');
167
+ }
168
+ }
169
+
170
+ // ============================================
171
+ // MIME type guessing
172
+ // ============================================
173
+
174
+ const EXTENSION_MIME_MAP: Record<string, string> = {
175
+ '.md': 'text/markdown',
176
+ '.txt': 'text/plain',
177
+ '.json': 'application/json',
178
+ '.jpg': 'image/jpeg',
179
+ '.jpeg': 'image/jpeg',
180
+ '.png': 'image/png',
181
+ '.gif': 'image/gif',
182
+ '.svg': 'image/svg+xml',
183
+ '.webp': 'image/webp',
184
+ '.avif': 'image/avif',
185
+ '.mp4': 'video/mp4',
186
+ '.webm': 'video/webm',
187
+ '.mp3': 'audio/mpeg',
188
+ '.wav': 'audio/wav',
189
+ '.ogg': 'audio/ogg',
190
+ '.css': 'text/css',
191
+ '.html': 'text/html',
192
+ '.js': 'application/javascript',
193
+ };
194
+
195
+ function guessMimeType(path: string): string {
196
+ const dot = path.lastIndexOf('.');
197
+ if (dot === -1) return 'application/octet-stream';
198
+ const ext = path.slice(dot).toLowerCase();
199
+ return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';
200
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * MediaProviderFromContainer — bridges ContentContainer to MediaProvider.
3
+ *
4
+ * Creates a MediaProvider that resolves relative paths by reading binary data
5
+ * from a ContentContainer and generating blob URLs. Blob URLs are cached and
6
+ * revoked on dispose().
7
+ *
8
+ * This allows any ContentContainer (memory, slot-backed, zip-loaded) to be
9
+ * used with existing rendering components (DocPlayer, ImageLayer, VideoLayer)
10
+ * that consume MediaProvider.
11
+ */
12
+
13
+ import type { MediaProvider, MediaEntry } from '../schemas/MediaProvider.js';
14
+ import type { ContentContainer } from './ContentContainer.js';
15
+
16
+ /**
17
+ * Create a MediaProvider backed by a ContentContainer.
18
+ *
19
+ * @param container — The ContentContainer to read/write media from
20
+ * @returns A MediaProvider that resolves paths to blob URLs
21
+ */
22
+ export function createMediaProviderFromContainer(container: ContentContainer): MediaProvider {
23
+ const blobUrlCache = new Map<string, string>();
24
+
25
+ return {
26
+ async resolveUrl(relativePath: string): Promise<string> {
27
+ const cached = blobUrlCache.get(relativePath);
28
+ if (cached) return cached;
29
+
30
+ const data = await container.readFile(relativePath);
31
+ if (!data) return relativePath;
32
+
33
+ const entries = await container.listFiles();
34
+ const entry = entries.find((e) => e.path === relativePath);
35
+ const mimeType = entry?.mimeType ?? 'application/octet-stream';
36
+
37
+ const blob = new Blob([data], { type: mimeType });
38
+ const url = URL.createObjectURL(blob);
39
+ blobUrlCache.set(relativePath, url);
40
+ return url;
41
+ },
42
+
43
+ async listMedia(): Promise<MediaEntry[]> {
44
+ const entries = await container.listFiles();
45
+ return entries
46
+ .filter((e) => !e.path.toLowerCase().endsWith('.md'))
47
+ .map((e) => ({
48
+ name: e.path,
49
+ mimeType: e.mimeType,
50
+ size: e.size,
51
+ }));
52
+ },
53
+
54
+ async addMedia(
55
+ name: string,
56
+ data: ArrayBuffer | Blob | Uint8Array,
57
+ mimeType: string,
58
+ ): Promise<string> {
59
+ // Invalidate any cached blob URL for this path before overwriting
60
+ const cached = blobUrlCache.get(name);
61
+ if (cached) {
62
+ URL.revokeObjectURL(cached);
63
+ blobUrlCache.delete(name);
64
+ }
65
+
66
+ let buffer: ArrayBuffer | Uint8Array;
67
+ if (data instanceof Blob) {
68
+ buffer = await data.arrayBuffer();
69
+ } else {
70
+ buffer = data;
71
+ }
72
+ await container.writeFile(name, buffer, mimeType);
73
+ return name;
74
+ },
75
+
76
+ async removeMedia(relativePath: string): Promise<void> {
77
+ const cached = blobUrlCache.get(relativePath);
78
+ if (cached) {
79
+ URL.revokeObjectURL(cached);
80
+ blobUrlCache.delete(relativePath);
81
+ }
82
+ await container.removeFile(relativePath);
83
+ },
84
+
85
+ dispose(): void {
86
+ for (const url of blobUrlCache.values()) {
87
+ URL.revokeObjectURL(url);
88
+ }
89
+ blobUrlCache.clear();
90
+ },
91
+ };
92
+ }
@@ -3,3 +3,6 @@ export { MemoryStorageAdapter } from './MemoryStorageAdapter.js';
3
3
  export { LocalStorageAdapter } from './LocalStorageAdapter.js';
4
4
  export { LocalForageAdapter } from './LocalForageAdapter.js';
5
5
  export type { LocalForageAdapterOptions } from './LocalForageAdapter.js';
6
+ export type { ContentContainer, ContentEntry } from './ContentContainer.js';
7
+ export { MemoryContentContainer, findDocumentPath } from './ContentContainer.js';
8
+ export { createMediaProviderFromContainer } from './MediaProviderFromContainer.js';
@@ -0,0 +1,17 @@
1
+ export {
2
+ DEFAULT_WORDS_PER_SECOND,
3
+ estimateSpokenWordCount,
4
+ countSpokenWords,
5
+ estimateTimeFromText,
6
+ calculatePrefixDuration,
7
+ estimateNarrationDuration,
8
+ } from './narrationTiming.js';
9
+
10
+ export { estimateReadingTime, estimateNarrationTime } from './readingTime.js';
11
+
12
+ export type {
13
+ ReadingTimeEstimate,
14
+ ReadingTimeOptions,
15
+ NarrationTimeEstimate,
16
+ NarrationTimeOptions,
17
+ } from './readingTime.js';
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Narration timing estimation.
3
+ *
4
+ * Estimates how long text takes to speak aloud, accounting for:
5
+ * - Numbers spoken as multiple words (e.g., "1910" → "nineteen ten")
6
+ * - Pauses at commas
7
+ * - Year pronunciation conventions (1000–2099)
8
+ *
9
+ * Ported from qualla-internal's AudioTiming.ts (pure functions, no Node.js deps).
10
+ */
11
+
12
+ /** Numbers are spoken more slowly than regular words (1.3× multiplier). */
13
+ const NUMBER_SPEAKING_MULTIPLIER = 1.3;
14
+
15
+ /** Comma pause in "word equivalents" — speakers pause ~0.3 words at commas. */
16
+ const COMMA_PAUSE_PENALTY = 0.3;
17
+
18
+ /** Default speaking rate in words per second (~150 WPM). */
19
+ export const DEFAULT_WORDS_PER_SECOND = 2.5;
20
+
21
+ /**
22
+ * Estimate how many "spoken word equivalents" a single token represents.
23
+ * Numbers get expanded (e.g., "175,000" → ~5 words × 1.3 multiplier).
24
+ */
25
+ export function estimateSpokenWordCount(token: string): number {
26
+ const cleaned = token.replace(/,/g, '');
27
+ const num = parseFloat(cleaned);
28
+
29
+ if (isNaN(num) || !isFinite(num)) {
30
+ return 1; // Not a number — count as 1 word
31
+ }
32
+
33
+ return estimateNumberWordCount(cleaned, num) * NUMBER_SPEAKING_MULTIPLIER;
34
+ }
35
+
36
+ /**
37
+ * Raw word count for a number (before the speaking multiplier).
38
+ */
39
+ function estimateNumberWordCount(cleaned: string, num: number): number {
40
+ // Handle decimals: "3.14" → words("3") + "point" + 2 digits
41
+ if (cleaned.includes('.')) {
42
+ const [whole, decimal] = cleaned.split('.');
43
+ const wholeNum = parseFloat(whole) || 0;
44
+ return estimateNumberWordCount(whole, wholeNum) + 1 + decimal.length;
45
+ }
46
+
47
+ const absNum = Math.abs(num);
48
+ let words = num < 0 ? 1 : 0; // "negative" / "minus"
49
+
50
+ if (absNum === 0) return 1; // "zero"
51
+
52
+ // Years (1000–2099) are spoken as two two-digit groups:
53
+ // "1910" → "nineteen ten", "2024" → "twenty twenty-four"
54
+ if (absNum >= 1000 && absNum <= 2099 && Number.isInteger(absNum)) {
55
+ const yearStr = absNum.toString();
56
+ if (yearStr.length === 4) {
57
+ const firstTwo = parseInt(yearStr.slice(0, 2));
58
+ const lastTwo = parseInt(yearStr.slice(2));
59
+
60
+ // First part
61
+ if (firstTwo >= 10 && firstTwo <= 19) {
62
+ words += 1;
63
+ } else if (firstTwo >= 20 && firstTwo <= 99) {
64
+ words += firstTwo % 10 === 0 ? 1 : 2;
65
+ } else {
66
+ words += 2; // "two thousand"
67
+ }
68
+
69
+ // Second part
70
+ if (lastTwo === 0) {
71
+ if (firstTwo >= 10 && firstTwo <= 99 && firstTwo !== 20) {
72
+ words += 1; // "hundred"
73
+ }
74
+ } else if (lastTwo >= 1 && lastTwo <= 9) {
75
+ words += 2; // "oh five"
76
+ } else if (lastTwo >= 10 && lastTwo <= 19) {
77
+ words += 1;
78
+ } else {
79
+ words += lastTwo % 10 === 0 ? 1 : 2;
80
+ }
81
+
82
+ return Math.max(words, 2);
83
+ }
84
+ }
85
+
86
+ // General number handling — each magnitude group adds words
87
+ let remaining = absNum;
88
+
89
+ if (remaining >= 1_000_000_000) {
90
+ const billions = Math.floor(remaining / 1_000_000_000);
91
+ words += estimateNumberWordCount(String(billions), billions);
92
+ words += 1; // "billion"
93
+ remaining %= 1_000_000_000;
94
+ }
95
+
96
+ if (remaining >= 1_000_000) {
97
+ const millions = Math.floor(remaining / 1_000_000);
98
+ words += estimateNumberWordCount(String(millions), millions);
99
+ words += 1; // "million"
100
+ remaining %= 1_000_000;
101
+ }
102
+
103
+ if (remaining >= 1_000) {
104
+ const thousands = Math.floor(remaining / 1_000);
105
+ words += estimateNumberWordCount(String(thousands), thousands);
106
+ words += 1; // "thousand"
107
+ remaining %= 1_000;
108
+ }
109
+
110
+ if (remaining >= 100) {
111
+ words += 2; // digit + "hundred"
112
+ remaining %= 100;
113
+ }
114
+
115
+ if (remaining >= 1) {
116
+ if (remaining >= 20) {
117
+ words += remaining % 10 === 0 ? 1 : 2;
118
+ } else {
119
+ words += 1; // 1–19
120
+ }
121
+ }
122
+
123
+ return Math.max(words, 1);
124
+ }
125
+
126
+ /**
127
+ * Count "spoken word equivalents" in a block of text,
128
+ * expanding numbers and adding comma pauses.
129
+ */
130
+ export function countSpokenWords(text: string): number {
131
+ const tokens = text.split(/\s+/).filter((w) => w.length > 0);
132
+ let count = 0;
133
+
134
+ for (const token of tokens) {
135
+ // Strip punctuation only at token boundaries so internal punctuation
136
+ // (e.g., decimals like "3.14" or digit-grouping commas "1,000") is preserved.
137
+ const stripped = token.replace(/^[.,!?;:'"()[\]{}]+|[.,!?;:'"()[\]{}]+$/g, '');
138
+ count += estimateSpokenWordCount(stripped);
139
+
140
+ // Count only punctuation commas for pauses: exclude digit-grouping commas
141
+ // (i.e., commas with digits on both sides, like in "1,234").
142
+ let punctuationCommaCount = 0;
143
+ for (let i = 0; i < token.length; i++) {
144
+ if (token[i] === ',') {
145
+ const prev = i > 0 ? token[i - 1] : '';
146
+ const next = i < token.length - 1 ? token[i + 1] : '';
147
+ const prevIsDigit = prev >= '0' && prev <= '9';
148
+ const nextIsDigit = next >= '0' && next <= '9';
149
+ if (!(prevIsDigit && nextIsDigit)) {
150
+ punctuationCommaCount++;
151
+ }
152
+ }
153
+ }
154
+ count += punctuationCommaCount * COMMA_PAUSE_PENALTY;
155
+ }
156
+
157
+ return count;
158
+ }
159
+
160
+ /**
161
+ * Estimate audio time at a character offset using word-proportion mapping.
162
+ *
163
+ * Given the full source text and a character position, returns the
164
+ * estimated time (in seconds) at which that position would be spoken.
165
+ *
166
+ * @param text - Full source text
167
+ * @param charOffset - Character offset to estimate timing for
168
+ * @param totalDuration - Total audio duration in seconds
169
+ * @returns Estimated time in seconds
170
+ */
171
+ export function estimateTimeFromText(
172
+ text: string,
173
+ charOffset: number,
174
+ totalDuration: number,
175
+ ): number {
176
+ const textBefore = text.slice(0, charOffset);
177
+ const spokenWordsBefore = countSpokenWords(textBefore);
178
+ const totalSpokenWords = countSpokenWords(text);
179
+
180
+ if (totalSpokenWords === 0) return 0;
181
+ return (spokenWordsBefore / totalSpokenWords) * totalDuration;
182
+ }
183
+
184
+ /**
185
+ * Estimate how long a spoken prefix adds to audio duration.
186
+ *
187
+ * When audio includes a spoken title or header before the main content,
188
+ * this calculates the extra duration to offset timing calculations.
189
+ *
190
+ * @param prefix - Prefix text (e.g., an article title spoken before the body)
191
+ * @param wordsPerSecond - Speaking rate (default: 2.5)
192
+ * @returns Estimated duration in seconds
193
+ */
194
+ export function calculatePrefixDuration(
195
+ prefix: string,
196
+ wordsPerSecond: number = DEFAULT_WORDS_PER_SECOND,
197
+ ): number {
198
+ if (!prefix) return 0;
199
+
200
+ const words = prefix.split(/\s+/).filter((w) => w.length > 0);
201
+ const newlineCount = (prefix.match(/\n\n/g) || []).length;
202
+ const pauseTime = newlineCount * 0.5;
203
+
204
+ return words.length / wordsPerSecond + pauseTime;
205
+ }
206
+
207
+ /**
208
+ * Estimate narration duration for a block of text.
209
+ *
210
+ * @param text - The text to estimate
211
+ * @param wordsPerSecond - Speaking rate (default: 2.5, i.e. ~150 WPM)
212
+ * @returns Duration in seconds
213
+ */
214
+ export function estimateNarrationDuration(
215
+ text: string,
216
+ wordsPerSecond: number = DEFAULT_WORDS_PER_SECOND,
217
+ ): number {
218
+ const spokenWords = countSpokenWords(text);
219
+ return spokenWords / wordsPerSecond;
220
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Reading time estimation.
3
+ *
4
+ * Estimates how long it takes to read text silently vs. narrate it aloud.
5
+ * Uses configurable words-per-minute rates.
6
+ */
7
+
8
+ import { countSpokenWords, DEFAULT_WORDS_PER_SECOND } from './narrationTiming.js';
9
+
10
+ /** Default silent reading rate (adults average ~200–250 WPM). */
11
+ const DEFAULT_READING_WPM = 200;
12
+
13
+ /** Result of a reading-time estimate. */
14
+ export interface ReadingTimeEstimate {
15
+ /** Number of words (plain word count, not spoken equivalents). */
16
+ words: number;
17
+ /** Estimated minutes (decimal). */
18
+ minutes: number;
19
+ /** Estimated seconds (rounded). */
20
+ seconds: number;
21
+ }
22
+
23
+ /** Options for reading-time estimation. */
24
+ export interface ReadingTimeOptions {
25
+ /** Words per minute for silent reading (default: 200). */
26
+ wordsPerMinute?: number;
27
+ }
28
+
29
+ /**
30
+ * Estimate silent reading time for a block of text.
31
+ *
32
+ * @param text - The text to estimate
33
+ * @param options - Optional configuration
34
+ * @returns Word count + time estimate
35
+ */
36
+ export function estimateReadingTime(
37
+ text: string,
38
+ options?: ReadingTimeOptions,
39
+ ): ReadingTimeEstimate {
40
+ const configuredWpm = options?.wordsPerMinute;
41
+ const wpm =
42
+ typeof configuredWpm === 'number' && configuredWpm > 0 ? configuredWpm : DEFAULT_READING_WPM;
43
+ const words = text.split(/\s+/).filter((w) => w.length > 0).length;
44
+ const minutes = words / wpm;
45
+
46
+ return {
47
+ words,
48
+ minutes,
49
+ seconds: Math.round(minutes * 60),
50
+ };
51
+ }
52
+
53
+ /** Result of a narration-time estimate. */
54
+ export interface NarrationTimeEstimate {
55
+ /** Spoken word equivalents (numbers expanded, comma pauses added). */
56
+ spokenWords: number;
57
+ /** Estimated minutes (decimal). */
58
+ minutes: number;
59
+ /** Estimated seconds (rounded). */
60
+ seconds: number;
61
+ }
62
+
63
+ /** Options for narration-time estimation. */
64
+ export interface NarrationTimeOptions {
65
+ /** Words per second for narration (default: 2.5 ≈ 150 WPM). */
66
+ wordsPerSecond?: number;
67
+ }
68
+
69
+ /**
70
+ * Estimate narration (spoken) time for a block of text.
71
+ *
72
+ * Unlike silent reading, this accounts for numbers being spoken as
73
+ * multiple words and pauses at commas.
74
+ *
75
+ * @param text - The text to estimate
76
+ * @param options - Optional configuration
77
+ * @returns Spoken word equivalents + time estimate
78
+ */
79
+ export function estimateNarrationTime(
80
+ text: string,
81
+ options?: NarrationTimeOptions,
82
+ ): NarrationTimeEstimate {
83
+ const providedWps = options?.wordsPerSecond;
84
+ const wps =
85
+ typeof providedWps === 'number' && providedWps > 0 ? providedWps : DEFAULT_WORDS_PER_SECOND;
86
+ const spokenWords = countSpokenWords(text);
87
+ const totalSeconds = spokenWords / wps;
88
+
89
+ return {
90
+ spokenWords,
91
+ minutes: totalSeconds / 60,
92
+ seconds: Math.round(totalSeconds),
93
+ };
94
+ }