@open-take/compositor 0.5.2 → 0.6.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 (439) hide show
  1. package/dist/cdp-CzT5BKNY.js +3 -0
  2. package/dist/cdp-QXbQfXna.js +373 -0
  3. package/dist/cdp-QXbQfXna.js.map +1 -0
  4. package/dist/index.d.ts +4327 -195
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +26282 -160
  7. package/dist/index.js.map +1 -1
  8. package/dist/server-841PMF2H.js +163 -0
  9. package/dist/server-841PMF2H.js.map +1 -0
  10. package/dist/server-C2aVv4-t.js +3 -0
  11. package/kit/audio.mjs +2366 -0
  12. package/kit/camera.js +587 -0
  13. package/kit/cursor.js +264 -0
  14. package/kit/cut.js +427 -0
  15. package/kit/draw.js +346 -0
  16. package/kit/look.js +589 -0
  17. package/kit/map.js +170 -0
  18. package/kit/media.js +3568 -0
  19. package/kit/motion.js +1115 -0
  20. package/kit/seams.js +1006 -0
  21. package/kit/stage.js +923 -0
  22. package/kit/time.js +812 -0
  23. package/kit/world.js +1072 -0
  24. package/package.json +7 -3
  25. package/src/ffmpeg.ts +63 -0
  26. package/src/film/beats.ts +1285 -0
  27. package/src/film/carry.ts +221 -0
  28. package/src/film/changes.ts +330 -0
  29. package/src/film/check.ts +996 -0
  30. package/src/film/clock.ts +2530 -0
  31. package/src/film/components-probe.ts +809 -0
  32. package/src/film/components.ts +1566 -0
  33. package/src/film/frames.ts +389 -0
  34. package/src/film/gallery.ts +3276 -0
  35. package/src/film/kit.ts +515 -0
  36. package/src/film/layout.ts +701 -0
  37. package/src/film/listen.ts +1979 -0
  38. package/src/film/look.ts +3829 -0
  39. package/src/film/materials.ts +976 -0
  40. package/src/film/moving.ts +248 -0
  41. package/src/film/part-files.ts +729 -0
  42. package/src/film/picture.ts +74 -0
  43. package/src/film/probe-text.ts +843 -0
  44. package/src/film/probe.ts +3456 -0
  45. package/src/film/provenance.ts +596 -0
  46. package/src/film/render.ts +2447 -0
  47. package/src/film/report.ts +1631 -0
  48. package/src/film/sheet.ts +156 -0
  49. package/src/film/study-declared.ts +123 -0
  50. package/src/film/study-picture.ts +791 -0
  51. package/src/film/study-sound.ts +416 -0
  52. package/src/film/study.ts +864 -0
  53. package/src/film/tuning.ts +155 -0
  54. package/src/film/viewer.ts +174 -0
  55. package/src/html/cdp.ts +575 -0
  56. package/src/html/server.ts +208 -0
  57. package/src/index.ts +202 -0
  58. package/src/launch-render.ts +3 -2
  59. package/src/math.ts +3 -3
  60. package/src/mjpeg-matroska.ts +228 -0
  61. package/src/render.ts +6 -4
  62. package/src/state-diff.ts +215 -0
  63. package/src/state-index.ts +99 -0
  64. package/src/types.ts +59 -1
  65. package/starter/PLAN.md +84 -0
  66. package/starter/START.md +460 -0
  67. package/starter/lib/anim.js +760 -0
  68. package/starter/lib/devices.js +1402 -0
  69. package/starter/lib/handoff.js +421 -0
  70. package/starter/lib/hud.js +1879 -0
  71. package/starter/lib/measure.mjs +154 -0
  72. package/starter/lib/moves.js +1095 -0
  73. package/starter/lib/palette.mjs +803 -0
  74. package/starter/lib/physics-seeds.mjs +198 -0
  75. package/starter/lib/physics.js +738 -0
  76. package/starter/lib/sampler.mjs +242 -0
  77. package/starter/lib/solid.js +727 -0
  78. package/starter/lib/space.js +1227 -0
  79. package/starter/lib/swarm.js +1398 -0
  80. package/starter/reference/motion.md +276 -0
  81. package/starter/reference/structure.md +466 -0
  82. package/starter/reference/travel/motion.md +433 -0
  83. package/starter/reference/travel/sound.md +241 -0
  84. package/starter/reference/travel/structure.md +518 -0
  85. package/starter/samples/NOTICE.txt +55 -0
  86. package/starter/samples/celli/celli_24_1.opus +0 -0
  87. package/starter/samples/celli/celli_24_3.opus +0 -0
  88. package/starter/samples/celli/celli_28_1.opus +0 -0
  89. package/starter/samples/celli/celli_28_3.opus +0 -0
  90. package/starter/samples/celli/celli_31_1.opus +0 -0
  91. package/starter/samples/celli/celli_31_3.opus +0 -0
  92. package/starter/samples/celli/celli_35_1.opus +0 -0
  93. package/starter/samples/celli/celli_35_3.opus +0 -0
  94. package/starter/samples/celli/celli_38_1.opus +0 -0
  95. package/starter/samples/celli/celli_38_3.opus +0 -0
  96. package/starter/samples/celli/celli_41_1.opus +0 -0
  97. package/starter/samples/celli/celli_41_3.opus +0 -0
  98. package/starter/samples/celli/celli_45_1.opus +0 -0
  99. package/starter/samples/celli/celli_45_3.opus +0 -0
  100. package/starter/samples/celli/celli_48_1.opus +0 -0
  101. package/starter/samples/celli/celli_48_3.opus +0 -0
  102. package/starter/samples/celli/celli_52_1.opus +0 -0
  103. package/starter/samples/celli/celli_52_3.opus +0 -0
  104. package/starter/samples/celli/celli_55_1.opus +0 -0
  105. package/starter/samples/celli/celli_55_3.opus +0 -0
  106. package/starter/samples/celli/celli_59_1.opus +0 -0
  107. package/starter/samples/celli/celli_59_3.opus +0 -0
  108. package/starter/samples/celli/celli_62_1.opus +0 -0
  109. package/starter/samples/celli/celli_62_3.opus +0 -0
  110. package/starter/samples/celli/celli_65_1.opus +0 -0
  111. package/starter/samples/celli/celli_65_3.opus +0 -0
  112. package/starter/samples/crash/crash_f_1.flac +0 -0
  113. package/starter/samples/crash/crash_fff_1.flac +0 -0
  114. package/starter/samples/ebass/ebass_0_x.flac +0 -0
  115. package/starter/samples/ebass/ebass_10_x.flac +0 -0
  116. package/starter/samples/ebass/ebass_11_x.flac +0 -0
  117. package/starter/samples/ebass/ebass_1_x.flac +0 -0
  118. package/starter/samples/ebass/ebass_2_x.flac +0 -0
  119. package/starter/samples/ebass/ebass_3_x.flac +0 -0
  120. package/starter/samples/ebass/ebass_4_x.flac +0 -0
  121. package/starter/samples/ebass/ebass_5_x.flac +0 -0
  122. package/starter/samples/ebass/ebass_6_x.flac +0 -0
  123. package/starter/samples/ebass/ebass_7_x.flac +0 -0
  124. package/starter/samples/ebass/ebass_8_x.flac +0 -0
  125. package/starter/samples/ebass/ebass_9_x.flac +0 -0
  126. package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
  127. package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
  128. package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
  129. package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
  130. package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
  131. package/starter/samples/glock/glock_67_x.flac +0 -0
  132. package/starter/samples/glock/glock_72_x.flac +0 -0
  133. package/starter/samples/glock/glock_79_x.flac +0 -0
  134. package/starter/samples/glock/glock_84_x.flac +0 -0
  135. package/starter/samples/glock/glock_91_x.flac +0 -0
  136. package/starter/samples/glock/glock_96_x.flac +0 -0
  137. package/starter/samples/harp/harp_101_f.opus +0 -0
  138. package/starter/samples/harp/harp_28_f.opus +0 -0
  139. package/starter/samples/harp/harp_31_mp.opus +0 -0
  140. package/starter/samples/harp/harp_35_mf.opus +0 -0
  141. package/starter/samples/harp/harp_38_mf.opus +0 -0
  142. package/starter/samples/harp/harp_41_mf.opus +0 -0
  143. package/starter/samples/harp/harp_45_mf.opus +0 -0
  144. package/starter/samples/harp/harp_48_mf.opus +0 -0
  145. package/starter/samples/harp/harp_52_mf.opus +0 -0
  146. package/starter/samples/harp/harp_55_mf.opus +0 -0
  147. package/starter/samples/harp/harp_59_mf.opus +0 -0
  148. package/starter/samples/harp/harp_62_mf.opus +0 -0
  149. package/starter/samples/harp/harp_65_mf.opus +0 -0
  150. package/starter/samples/harp/harp_69_mf.opus +0 -0
  151. package/starter/samples/harp/harp_72_mf.opus +0 -0
  152. package/starter/samples/harp/harp_76_mf.opus +0 -0
  153. package/starter/samples/harp/harp_79_mf.opus +0 -0
  154. package/starter/samples/harp/harp_83_mf.opus +0 -0
  155. package/starter/samples/harp/harp_86_mf.opus +0 -0
  156. package/starter/samples/harp/harp_89_mf.opus +0 -0
  157. package/starter/samples/harp/harp_93_mf.opus +0 -0
  158. package/starter/samples/harp/harp_95_mf.opus +0 -0
  159. package/starter/samples/harp/harp_98_f.opus +0 -0
  160. package/starter/samples/manifest.json +2951 -0
  161. package/starter/samples/marimba/marimba_29_x.flac +0 -0
  162. package/starter/samples/marimba/marimba_36_x.flac +0 -0
  163. package/starter/samples/marimba/marimba_43_x.flac +0 -0
  164. package/starter/samples/marimba/marimba_47_x.flac +0 -0
  165. package/starter/samples/marimba/marimba_53_x.flac +0 -0
  166. package/starter/samples/marimba/marimba_60_x.flac +0 -0
  167. package/starter/samples/marimba/marimba_67_x.flac +0 -0
  168. package/starter/samples/marimba/marimba_71_x.flac +0 -0
  169. package/starter/samples/marimba/marimba_77_x.flac +0 -0
  170. package/starter/samples/marimba/marimba_84_x.flac +0 -0
  171. package/starter/samples/piano/piano_102_12.opus +0 -0
  172. package/starter/samples/piano/piano_102_16.opus +0 -0
  173. package/starter/samples/piano/piano_102_4.opus +0 -0
  174. package/starter/samples/piano/piano_102_8.opus +0 -0
  175. package/starter/samples/piano/piano_105_12.opus +0 -0
  176. package/starter/samples/piano/piano_105_16.opus +0 -0
  177. package/starter/samples/piano/piano_105_4.opus +0 -0
  178. package/starter/samples/piano/piano_105_8.opus +0 -0
  179. package/starter/samples/piano/piano_108_12.opus +0 -0
  180. package/starter/samples/piano/piano_108_16.opus +0 -0
  181. package/starter/samples/piano/piano_108_4.opus +0 -0
  182. package/starter/samples/piano/piano_108_8.opus +0 -0
  183. package/starter/samples/piano/piano_21_12.opus +0 -0
  184. package/starter/samples/piano/piano_21_16.opus +0 -0
  185. package/starter/samples/piano/piano_21_4.opus +0 -0
  186. package/starter/samples/piano/piano_21_8.opus +0 -0
  187. package/starter/samples/piano/piano_24_12.opus +0 -0
  188. package/starter/samples/piano/piano_24_16.opus +0 -0
  189. package/starter/samples/piano/piano_24_4.opus +0 -0
  190. package/starter/samples/piano/piano_24_8.opus +0 -0
  191. package/starter/samples/piano/piano_27_12.opus +0 -0
  192. package/starter/samples/piano/piano_27_16.opus +0 -0
  193. package/starter/samples/piano/piano_27_4.opus +0 -0
  194. package/starter/samples/piano/piano_27_8.opus +0 -0
  195. package/starter/samples/piano/piano_30_12.opus +0 -0
  196. package/starter/samples/piano/piano_30_16.opus +0 -0
  197. package/starter/samples/piano/piano_30_4.opus +0 -0
  198. package/starter/samples/piano/piano_30_8.opus +0 -0
  199. package/starter/samples/piano/piano_33_12.opus +0 -0
  200. package/starter/samples/piano/piano_33_16.opus +0 -0
  201. package/starter/samples/piano/piano_33_4.opus +0 -0
  202. package/starter/samples/piano/piano_33_8.opus +0 -0
  203. package/starter/samples/piano/piano_36_12.opus +0 -0
  204. package/starter/samples/piano/piano_36_16.opus +0 -0
  205. package/starter/samples/piano/piano_36_4.opus +0 -0
  206. package/starter/samples/piano/piano_36_8.opus +0 -0
  207. package/starter/samples/piano/piano_39_12.opus +0 -0
  208. package/starter/samples/piano/piano_39_16.opus +0 -0
  209. package/starter/samples/piano/piano_39_4.opus +0 -0
  210. package/starter/samples/piano/piano_39_8.opus +0 -0
  211. package/starter/samples/piano/piano_42_12.opus +0 -0
  212. package/starter/samples/piano/piano_42_16.opus +0 -0
  213. package/starter/samples/piano/piano_42_4.opus +0 -0
  214. package/starter/samples/piano/piano_42_8.opus +0 -0
  215. package/starter/samples/piano/piano_45_12.opus +0 -0
  216. package/starter/samples/piano/piano_45_16.opus +0 -0
  217. package/starter/samples/piano/piano_45_4.opus +0 -0
  218. package/starter/samples/piano/piano_45_8.opus +0 -0
  219. package/starter/samples/piano/piano_48_12.opus +0 -0
  220. package/starter/samples/piano/piano_48_16.opus +0 -0
  221. package/starter/samples/piano/piano_48_4.opus +0 -0
  222. package/starter/samples/piano/piano_48_8.opus +0 -0
  223. package/starter/samples/piano/piano_51_12.opus +0 -0
  224. package/starter/samples/piano/piano_51_16.opus +0 -0
  225. package/starter/samples/piano/piano_51_4.opus +0 -0
  226. package/starter/samples/piano/piano_51_8.opus +0 -0
  227. package/starter/samples/piano/piano_54_12.opus +0 -0
  228. package/starter/samples/piano/piano_54_16.opus +0 -0
  229. package/starter/samples/piano/piano_54_4.opus +0 -0
  230. package/starter/samples/piano/piano_54_8.opus +0 -0
  231. package/starter/samples/piano/piano_57_12.opus +0 -0
  232. package/starter/samples/piano/piano_57_16.opus +0 -0
  233. package/starter/samples/piano/piano_57_4.opus +0 -0
  234. package/starter/samples/piano/piano_57_8.opus +0 -0
  235. package/starter/samples/piano/piano_60_12.opus +0 -0
  236. package/starter/samples/piano/piano_60_16.opus +0 -0
  237. package/starter/samples/piano/piano_60_4.opus +0 -0
  238. package/starter/samples/piano/piano_60_8.opus +0 -0
  239. package/starter/samples/piano/piano_63_12.opus +0 -0
  240. package/starter/samples/piano/piano_63_16.opus +0 -0
  241. package/starter/samples/piano/piano_63_4.opus +0 -0
  242. package/starter/samples/piano/piano_63_8.opus +0 -0
  243. package/starter/samples/piano/piano_66_12.opus +0 -0
  244. package/starter/samples/piano/piano_66_16.opus +0 -0
  245. package/starter/samples/piano/piano_66_4.opus +0 -0
  246. package/starter/samples/piano/piano_66_8.opus +0 -0
  247. package/starter/samples/piano/piano_69_12.opus +0 -0
  248. package/starter/samples/piano/piano_69_16.opus +0 -0
  249. package/starter/samples/piano/piano_69_4.opus +0 -0
  250. package/starter/samples/piano/piano_69_8.opus +0 -0
  251. package/starter/samples/piano/piano_72_12.opus +0 -0
  252. package/starter/samples/piano/piano_72_16.opus +0 -0
  253. package/starter/samples/piano/piano_72_4.opus +0 -0
  254. package/starter/samples/piano/piano_72_8.opus +0 -0
  255. package/starter/samples/piano/piano_75_12.opus +0 -0
  256. package/starter/samples/piano/piano_75_16.opus +0 -0
  257. package/starter/samples/piano/piano_75_4.opus +0 -0
  258. package/starter/samples/piano/piano_75_8.opus +0 -0
  259. package/starter/samples/piano/piano_78_12.opus +0 -0
  260. package/starter/samples/piano/piano_78_16.opus +0 -0
  261. package/starter/samples/piano/piano_78_4.opus +0 -0
  262. package/starter/samples/piano/piano_78_8.opus +0 -0
  263. package/starter/samples/piano/piano_81_12.opus +0 -0
  264. package/starter/samples/piano/piano_81_16.opus +0 -0
  265. package/starter/samples/piano/piano_81_4.opus +0 -0
  266. package/starter/samples/piano/piano_81_8.opus +0 -0
  267. package/starter/samples/piano/piano_84_12.opus +0 -0
  268. package/starter/samples/piano/piano_84_16.opus +0 -0
  269. package/starter/samples/piano/piano_84_4.opus +0 -0
  270. package/starter/samples/piano/piano_84_8.opus +0 -0
  271. package/starter/samples/piano/piano_87_12.opus +0 -0
  272. package/starter/samples/piano/piano_87_16.opus +0 -0
  273. package/starter/samples/piano/piano_87_4.opus +0 -0
  274. package/starter/samples/piano/piano_87_8.opus +0 -0
  275. package/starter/samples/piano/piano_90_12.opus +0 -0
  276. package/starter/samples/piano/piano_90_16.opus +0 -0
  277. package/starter/samples/piano/piano_90_4.opus +0 -0
  278. package/starter/samples/piano/piano_90_8.opus +0 -0
  279. package/starter/samples/piano/piano_93_12.opus +0 -0
  280. package/starter/samples/piano/piano_93_16.opus +0 -0
  281. package/starter/samples/piano/piano_93_4.opus +0 -0
  282. package/starter/samples/piano/piano_93_8.opus +0 -0
  283. package/starter/samples/piano/piano_96_12.opus +0 -0
  284. package/starter/samples/piano/piano_96_16.opus +0 -0
  285. package/starter/samples/piano/piano_96_4.opus +0 -0
  286. package/starter/samples/piano/piano_96_8.opus +0 -0
  287. package/starter/samples/piano/piano_99_12.opus +0 -0
  288. package/starter/samples/piano/piano_99_16.opus +0 -0
  289. package/starter/samples/piano/piano_99_4.opus +0 -0
  290. package/starter/samples/piano/piano_99_8.opus +0 -0
  291. package/starter/samples/piano/piano_rel_102_x.opus +0 -0
  292. package/starter/samples/piano/piano_rel_105_x.opus +0 -0
  293. package/starter/samples/piano/piano_rel_108_x.opus +0 -0
  294. package/starter/samples/piano/piano_rel_21_x.opus +0 -0
  295. package/starter/samples/piano/piano_rel_24_x.opus +0 -0
  296. package/starter/samples/piano/piano_rel_27_x.opus +0 -0
  297. package/starter/samples/piano/piano_rel_30_x.opus +0 -0
  298. package/starter/samples/piano/piano_rel_33_x.opus +0 -0
  299. package/starter/samples/piano/piano_rel_36_x.opus +0 -0
  300. package/starter/samples/piano/piano_rel_39_x.opus +0 -0
  301. package/starter/samples/piano/piano_rel_42_x.opus +0 -0
  302. package/starter/samples/piano/piano_rel_45_x.opus +0 -0
  303. package/starter/samples/piano/piano_rel_48_x.opus +0 -0
  304. package/starter/samples/piano/piano_rel_51_x.opus +0 -0
  305. package/starter/samples/piano/piano_rel_54_x.opus +0 -0
  306. package/starter/samples/piano/piano_rel_57_x.opus +0 -0
  307. package/starter/samples/piano/piano_rel_60_x.opus +0 -0
  308. package/starter/samples/piano/piano_rel_63_x.opus +0 -0
  309. package/starter/samples/piano/piano_rel_66_x.opus +0 -0
  310. package/starter/samples/piano/piano_rel_69_x.opus +0 -0
  311. package/starter/samples/piano/piano_rel_72_x.opus +0 -0
  312. package/starter/samples/piano/piano_rel_75_x.opus +0 -0
  313. package/starter/samples/piano/piano_rel_78_x.opus +0 -0
  314. package/starter/samples/piano/piano_rel_81_x.opus +0 -0
  315. package/starter/samples/piano/piano_rel_84_x.opus +0 -0
  316. package/starter/samples/piano/piano_rel_87_x.opus +0 -0
  317. package/starter/samples/piano/piano_rel_90_x.opus +0 -0
  318. package/starter/samples/piano/piano_rel_93_x.opus +0 -0
  319. package/starter/samples/piano/piano_rel_96_x.opus +0 -0
  320. package/starter/samples/piano/piano_rel_99_x.opus +0 -0
  321. package/starter/samples/pizz/pizz_24_2.flac +0 -0
  322. package/starter/samples/pizz/pizz_28_2.flac +0 -0
  323. package/starter/samples/pizz/pizz_31_2.flac +0 -0
  324. package/starter/samples/pizz/pizz_35_2.flac +0 -0
  325. package/starter/samples/pizz/pizz_38_2.flac +0 -0
  326. package/starter/samples/pizz/pizz_41_2.flac +0 -0
  327. package/starter/samples/pizz/pizz_45_2.flac +0 -0
  328. package/starter/samples/pizz/pizz_48_2.flac +0 -0
  329. package/starter/samples/pizz/pizz_52_2.flac +0 -0
  330. package/starter/samples/pizz/pizz_57_2.flac +0 -0
  331. package/starter/samples/pizz/pizz_60_2.flac +0 -0
  332. package/starter/samples/pizz/pizz_64_2.flac +0 -0
  333. package/starter/samples/pizz/pizz_67_2.flac +0 -0
  334. package/starter/samples/pizz/pizz_71_2.flac +0 -0
  335. package/starter/samples/pizz/pizz_74_2.flac +0 -0
  336. package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
  337. package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
  338. package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
  339. package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
  340. package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
  341. package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
  342. package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
  343. package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
  344. package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
  345. package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
  346. package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
  347. package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
  348. package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
  349. package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
  350. package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
  351. package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
  352. package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
  353. package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
  354. package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
  355. package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
  356. package/starter/samples/shaker/shaker_1_1.flac +0 -0
  357. package/starter/samples/shaker/shaker_2_1.flac +0 -0
  358. package/starter/samples/snap/snap_r_1.flac +0 -0
  359. package/starter/samples/snap/snap_r_2.flac +0 -0
  360. package/starter/samples/snap/snap_r_3.flac +0 -0
  361. package/starter/samples/snap/snap_r_4.flac +0 -0
  362. package/starter/samples/snap/snap_r_5.flac +0 -0
  363. package/starter/samples/snap/snap_r_6.flac +0 -0
  364. package/starter/samples/tom/tom_3_1.flac +0 -0
  365. package/starter/samples/tom/tom_3_2.flac +0 -0
  366. package/starter/samples/tom/tom_4_1.flac +0 -0
  367. package/starter/samples/tom/tom_4_2.flac +0 -0
  368. package/starter/samples/vibes/vibes_41_1.opus +0 -0
  369. package/starter/samples/vibes/vibes_41_2.opus +0 -0
  370. package/starter/samples/vibes/vibes_45_1.opus +0 -0
  371. package/starter/samples/vibes/vibes_45_2.opus +0 -0
  372. package/starter/samples/vibes/vibes_48_1.opus +0 -0
  373. package/starter/samples/vibes/vibes_48_2.opus +0 -0
  374. package/starter/samples/vibes/vibes_52_1.opus +0 -0
  375. package/starter/samples/vibes/vibes_52_2.opus +0 -0
  376. package/starter/samples/vibes/vibes_55_1.opus +0 -0
  377. package/starter/samples/vibes/vibes_55_2.opus +0 -0
  378. package/starter/samples/vibes/vibes_59_1.opus +0 -0
  379. package/starter/samples/vibes/vibes_59_2.opus +0 -0
  380. package/starter/samples/vibes/vibes_62_1.opus +0 -0
  381. package/starter/samples/vibes/vibes_62_2.opus +0 -0
  382. package/starter/samples/vibes/vibes_65_1.opus +0 -0
  383. package/starter/samples/vibes/vibes_65_2.opus +0 -0
  384. package/starter/samples/vibes/vibes_69_1.opus +0 -0
  385. package/starter/samples/vibes/vibes_69_2.opus +0 -0
  386. package/starter/samples/vibes/vibes_72_1.opus +0 -0
  387. package/starter/samples/vibes/vibes_72_2.opus +0 -0
  388. package/starter/samples/vibes/vibes_76_1.opus +0 -0
  389. package/starter/samples/vibes/vibes_76_2.opus +0 -0
  390. package/starter/samples/violas/violas_36_1.opus +0 -0
  391. package/starter/samples/violas/violas_36_2.opus +0 -0
  392. package/starter/samples/violas/violas_38_1.opus +0 -0
  393. package/starter/samples/violas/violas_38_2.opus +0 -0
  394. package/starter/samples/violas/violas_40_1.opus +0 -0
  395. package/starter/samples/violas/violas_40_2.opus +0 -0
  396. package/starter/samples/violas/violas_43_1.opus +0 -0
  397. package/starter/samples/violas/violas_43_2.opus +0 -0
  398. package/starter/samples/violas/violas_47_1.opus +0 -0
  399. package/starter/samples/violas/violas_47_2.opus +0 -0
  400. package/starter/samples/violas/violas_50_1.opus +0 -0
  401. package/starter/samples/violas/violas_50_2.opus +0 -0
  402. package/starter/samples/violas/violas_53_1.opus +0 -0
  403. package/starter/samples/violas/violas_53_2.opus +0 -0
  404. package/starter/samples/violas/violas_57_1.opus +0 -0
  405. package/starter/samples/violas/violas_57_2.opus +0 -0
  406. package/starter/samples/violas/violas_60_1.opus +0 -0
  407. package/starter/samples/violas/violas_60_2.opus +0 -0
  408. package/starter/samples/violas/violas_64_1.opus +0 -0
  409. package/starter/samples/violas/violas_64_2.opus +0 -0
  410. package/starter/samples/violas/violas_67_1.opus +0 -0
  411. package/starter/samples/violas/violas_67_2.opus +0 -0
  412. package/starter/samples/violas/violas_71_1.opus +0 -0
  413. package/starter/samples/violas/violas_71_2.opus +0 -0
  414. package/starter/samples/violas/violas_74_1.opus +0 -0
  415. package/starter/samples/violas/violas_74_2.opus +0 -0
  416. package/starter/samples/violins/violins_43_1.opus +0 -0
  417. package/starter/samples/violins/violins_43_2.opus +0 -0
  418. package/starter/samples/violins/violins_45_1.opus +0 -0
  419. package/starter/samples/violins/violins_45_2.opus +0 -0
  420. package/starter/samples/violins/violins_47_1.opus +0 -0
  421. package/starter/samples/violins/violins_47_2.opus +0 -0
  422. package/starter/samples/violins/violins_50_1.opus +0 -0
  423. package/starter/samples/violins/violins_50_2.opus +0 -0
  424. package/starter/samples/violins/violins_54_1.opus +0 -0
  425. package/starter/samples/violins/violins_54_2.opus +0 -0
  426. package/starter/samples/violins/violins_57_1.opus +0 -0
  427. package/starter/samples/violins/violins_57_2.opus +0 -0
  428. package/starter/samples/violins/violins_60_1.opus +0 -0
  429. package/starter/samples/violins/violins_60_2.opus +0 -0
  430. package/starter/samples/violins/violins_64_1.opus +0 -0
  431. package/starter/samples/violins/violins_64_2.opus +0 -0
  432. package/starter/samples/violins/violins_67_1.opus +0 -0
  433. package/starter/samples/violins/violins_67_2.opus +0 -0
  434. package/starter/samples/violins/violins_71_1.opus +0 -0
  435. package/starter/samples/violins/violins_71_2.opus +0 -0
  436. package/starter/samples/violins/violins_74_1.opus +0 -0
  437. package/starter/samples/violins/violins_74_2.opus +0 -0
  438. package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
  439. package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
@@ -0,0 +1,596 @@
1
+ // `film probe`'s provenance lines: where the values on screen come from, as
2
+ // information. The page says where with kit/time.js `tl.source` (a part of
3
+ // components.json, a live url, or a note — "demo", "illustrative");
4
+ // kit/media.js `readValues(url, { tl })` says it for every value it reads.
5
+ // The probe reads the film's own text (outside saved screens and lifted
6
+ // parts: those are the product's page) on the film clock, takes the numbers
7
+ // in it, and sets each beside the declared sources and the values the
8
+ // product's parts showed (components.json):
9
+ //
10
+ // - declared: a source covers it (its element, its label or text, or the
11
+ // values of the part it names);
12
+ // - matches a part: no source says so, but a part of components.json
13
+ // showed the same number;
14
+ // - no source declared: neither.
15
+ //
16
+ // Nothing is graded and nothing is blocked: a number the saved screens did
17
+ // not keep can still be real (a formula, the product's code, a live page).
18
+ // A count's in-between numbers are the film's, not the product's — a value
19
+ // its element shows once, between two others, is counted apart and not
20
+ // listed.
21
+
22
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
23
+ import { dirname, join, relative, resolve } from "node:path";
24
+ import { checkSources, type FilmSource } from "./render";
25
+
26
+ type How = "measured" | "estimated" | "not detected" | "not measured";
27
+ type Span = [number, number];
28
+
29
+ // --- the page ------------------------------------------------------------------------
30
+
31
+ /** One block of the film's own text at one moment: `k` the same element
32
+ * across samples, `text` its visible text in full, `cov` the indices of the
33
+ * page's sources whose selector holds it. */
34
+ export type ProvenanceItem = { k: number; text: string; cov: number[] };
35
+ export type ProvenanceSample = { t: number; items: ProvenanceItem[]; sources?: unknown };
36
+
37
+ /** An expression for the film's page (awaited): its own text, block by block
38
+ * (a caption split into spans is one block), as shown now — text outside
39
+ * the viewport, hidden or all but transparent is left out; iframes (saved
40
+ * screens, lifted parts) are not entered — and window.__film.sources as
41
+ * the page has it. Elements keep their number across calls on one page. */
42
+ export const PROVENANCE_PAGE_JS = `(async () => {
43
+ const st = (window.__otProv ??= { ids: new WeakMap(), n: 0 });
44
+ const idOf = (el) => { let k = st.ids.get(el); if (k == null) { k = ++st.n; st.ids.set(el, k); } return k; };
45
+ let sources = window.__film?.sources;
46
+ try { if (typeof sources === "function") sources = await sources(); } catch { sources = null; }
47
+ sources = Array.isArray(sources) ? JSON.parse(JSON.stringify(sources)) : null;
48
+ const sels = (sources ?? []).map((s) => (s && typeof s.selector === "string" ? s.selector : null));
49
+ const vw = innerWidth, vh = innerHeight;
50
+ const shown = new Map();
51
+ const shows = (el) => {
52
+ if (shown.has(el)) return shown.get(el);
53
+ let o = 1, ok = true;
54
+ for (let n = el; n && ok; n = n.parentElement) {
55
+ const cs = getComputedStyle(n);
56
+ if (cs.display === "none") ok = false;
57
+ o *= Number(cs.opacity);
58
+ if (o < 0.05) ok = false;
59
+ }
60
+ if (ok && getComputedStyle(el).visibility !== "visible") ok = false;
61
+ shown.set(el, ok);
62
+ return ok;
63
+ };
64
+ const blocks = new Map();
65
+ const range = document.createRange();
66
+ if (document.body) {
67
+ const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
68
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
69
+ const v = n.nodeValue ?? "";
70
+ if (!v.trim()) continue;
71
+ const el = n.parentElement;
72
+ if (!el || ["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"].includes(el.tagName)) continue;
73
+ if (!shows(el)) continue;
74
+ range.selectNodeContents(n);
75
+ const on = Array.from(range.getClientRects()).some(
76
+ (r) => r.width >= 1 && r.height >= 1 && r.right > 0 && r.bottom > 0 && r.left < vw && r.top < vh,
77
+ );
78
+ if (!on) continue;
79
+ let owner = el;
80
+ while (
81
+ owner.parentElement &&
82
+ owner.parentElement !== document.body &&
83
+ /^(inline|inline-block|inline-flex|contents)$/.test(getComputedStyle(owner).display)
84
+ )
85
+ owner = owner.parentElement;
86
+ let b = blocks.get(owner);
87
+ if (!b) {
88
+ b = { k: idOf(owner), parts: [], cov: new Set() };
89
+ blocks.set(owner, b);
90
+ }
91
+ b.parts.push(v);
92
+ sels.forEach((sel, i) => {
93
+ if (!sel) return;
94
+ try { if (el.closest(sel)) b.cov.add(i); } catch {}
95
+ });
96
+ }
97
+ }
98
+ const items = [...blocks.values()].map((b) => ({
99
+ k: b.k,
100
+ text: b.parts.join("").replace(/\\s+/g, " ").trim(),
101
+ cov: [...b.cov].sort((x, y) => x - y),
102
+ }));
103
+ return { items, sources };
104
+ })()`;
105
+
106
+ // --- numbers ---------------------------------------------------------------------------
107
+
108
+ export type NumberToken = { raw: string; norm: string };
109
+
110
+ const NUMBER_RE = /(?:[A-Z]{0,3}[$€£¥₩₹]\s?)?\d+(?:[.,]\d+)*(?:\s?%)?/g;
111
+
112
+ /** the numbers in a text, as written, and each as a plain number to compare
113
+ * ("US$3,376" → "3376", "4.50" → "4.5"): separators of thousands are commas
114
+ * followed by three digits; any other comma is read as a decimal point */
115
+ export function numberTokens(text: string): NumberToken[] {
116
+ const out: NumberToken[] = [];
117
+ for (const m of text.matchAll(NUMBER_RE)) {
118
+ const raw = m[0].trim();
119
+ const digits = raw.replace(/^[^\d]+/, "").replace(/\s?%$/, "");
120
+ const plain = /^\d{1,3}(,\d{3})+(\.\d+)?$/.test(digits)
121
+ ? digits.replace(/,/g, "")
122
+ : digits.replace(/,/g, ".");
123
+ const n = Number(plain);
124
+ out.push({ raw, norm: Number.isFinite(n) ? String(n) : plain });
125
+ }
126
+ return out;
127
+ }
128
+
129
+ const normText = (s: string) => s.replace(/\s+/g, " ").trim().toLowerCase();
130
+
131
+ // --- components.json ------------------------------------------------------------------
132
+
133
+ /** a value a part of components.json showed, flattened for matching */
134
+ export type PartValueEntry = {
135
+ ref: string;
136
+ field?: string;
137
+ text: string;
138
+ value?: number;
139
+ /** the components.json it is in (absolute) */
140
+ file: string;
141
+ /** a version 2 value; a version 1 file's label or a track's step (matched
142
+ * on, never shown as a value) */
143
+ by: "values" | "label" | "track";
144
+ };
145
+
146
+ export type ComponentValueIndex = {
147
+ files: { file: string; version: number; parts: number; values: number }[];
148
+ entries: PartValueEntry[];
149
+ refs: Set<string>;
150
+ /** files that could not be read, and why */
151
+ unread: { file: string; why: string }[];
152
+ };
153
+
154
+ /** every value the parts of these components.json files showed */
155
+ export function componentValueIndex(files: readonly string[]): ComponentValueIndex {
156
+ const idx: ComponentValueIndex = { files: [], entries: [], refs: new Set(), unread: [] };
157
+ for (const file of [...new Set(files.map((f) => resolve(f)))]) {
158
+ let raw: Record<string, unknown>;
159
+ try {
160
+ raw = JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>;
161
+ } catch (e) {
162
+ idx.unread.push({ file, why: (e as Error).message.split("\n")[0] ?? "" });
163
+ continue;
164
+ }
165
+ if (!raw || !Array.isArray(raw.components)) {
166
+ idx.unread.push({ file, why: "no components list" });
167
+ continue;
168
+ }
169
+ const version = typeof raw.version === "number" ? raw.version : 0;
170
+ let parts = 0;
171
+ let values = 0;
172
+ for (const c of raw.components as Record<string, unknown>[]) {
173
+ if (!c || typeof c.ref !== "string") continue;
174
+ parts++;
175
+ idx.refs.add(c.ref);
176
+ const v =
177
+ c.values && typeof c.values === "object" ? (c.values as Record<string, unknown>) : null;
178
+ if (v)
179
+ for (const [field, x] of Object.entries(v)) {
180
+ const e = x as { text?: unknown; value?: unknown };
181
+ if (!e || typeof e.text !== "string") continue;
182
+ values++;
183
+ idx.entries.push({
184
+ ref: c.ref,
185
+ field,
186
+ text: e.text,
187
+ ...(typeof e.value === "number" && Number.isFinite(e.value) ? { value: e.value } : {}),
188
+ file,
189
+ by: "values",
190
+ });
191
+ }
192
+ else if (typeof c.label === "string" && c.label)
193
+ idx.entries.push({ ref: c.ref, text: c.label, file, by: "label" });
194
+ }
195
+ // a version 1 file: what each step of a track read, too
196
+ if (version < 2 && Array.isArray(raw.tracks))
197
+ for (const tr of raw.tracks as { steps?: { ref?: unknown; text?: unknown }[] }[])
198
+ for (const s of tr?.steps ?? [])
199
+ if (typeof s?.ref === "string" && typeof s.text === "string" && s.text)
200
+ idx.entries.push({ ref: s.ref, text: s.text, file, by: "track" });
201
+ idx.files.push({ file, version, parts, values });
202
+ }
203
+ return idx;
204
+ }
205
+
206
+ /** each entry's numbers, compared as plain numbers */
207
+ const entryNorms = (e: PartValueEntry): Set<string> => {
208
+ const s = new Set(numberTokens(e.text).map((x) => x.norm));
209
+ if (e.value != null) s.add(String(e.value));
210
+ return s;
211
+ };
212
+
213
+ /** the components.json files a film's page can mean: those its sources name
214
+ * (relative to the page's folder, else to `base`; "/…" from the folder it
215
+ * is served from), and those in the page's
216
+ * folder and the folders under it, two deep (node_modules, dot folders and
217
+ * probe folders left out) */
218
+ export function findComponentFiles(o: {
219
+ pageDir?: string;
220
+ /** the folder the page is served from: where "/…" paths start */
221
+ root?: string;
222
+ base: string;
223
+ sources: readonly FilmSource[];
224
+ }): string[] {
225
+ const out: string[] = [];
226
+ const add = (f: string) => {
227
+ if (existsSync(f) && !out.includes(f)) out.push(f);
228
+ };
229
+ for (const s of o.sources) {
230
+ if (!s.file || /^[a-z]+:/i.test(s.file)) continue;
231
+ let f = s.file.replace(/[?#].*$/, "");
232
+ try {
233
+ f = decodeURIComponent(f);
234
+ } catch {}
235
+ add(
236
+ f.startsWith("/") ? join(o.root ?? o.pageDir ?? o.base, f) : resolve(o.pageDir ?? o.base, f),
237
+ );
238
+ }
239
+ const walk = (dir: string, depth: number) => {
240
+ let names: string[];
241
+ try {
242
+ names = readdirSync(dir).sort();
243
+ } catch {
244
+ return;
245
+ }
246
+ for (const n of names) {
247
+ const p = join(dir, n);
248
+ if (n === "components.json") add(p);
249
+ else if (
250
+ depth > 0 &&
251
+ !n.startsWith(".") &&
252
+ n !== "node_modules" &&
253
+ !n.endsWith(".probe") &&
254
+ isDir(p)
255
+ )
256
+ walk(p, depth - 1);
257
+ }
258
+ };
259
+ if (o.pageDir) walk(o.pageDir, 2);
260
+ return out;
261
+ }
262
+
263
+ const isDir = (p: string) => {
264
+ try {
265
+ return statSync(p).isDirectory();
266
+ } catch {
267
+ return false;
268
+ }
269
+ };
270
+
271
+ // --- the reading ------------------------------------------------------------------------
272
+
273
+ export type ProvenanceKind = "declared" | "matches a part" | "no source declared";
274
+
275
+ export type ProvenanceValue = {
276
+ /** the number as shown */
277
+ text: string;
278
+ how: ProvenanceKind;
279
+ /** film seconds it is held on screen */
280
+ spans: Span[];
281
+ /** the text of its element where it was first seen, in full */
282
+ in: string;
283
+ /** the labels of the sources that cover it */
284
+ sources?: string[];
285
+ /** the parts that showed it: "<ref> <field>" (or the ref alone) */
286
+ parts?: string[];
287
+ };
288
+
289
+ export type ProvenanceSource = FilmSource & {
290
+ /** film seconds its element, label or text is on screen; null: not read */
291
+ seen: Span[] | null;
292
+ /** for a ref: whether the components.json read has that part */
293
+ part?: "in components.json" | "not in the components.json read" | "no components.json read";
294
+ };
295
+
296
+ export type FilmProvenance = {
297
+ how: How;
298
+ note?: string;
299
+ every: number;
300
+ sources: { from: "page" | "events file" | null; list: ProvenanceSource[] };
301
+ components: ComponentValueIndex["files"];
302
+ unreadComponents: ComponentValueIndex["unread"];
303
+ values: ProvenanceValue[];
304
+ /** a block of the film's own text without a digit that reads exactly as a
305
+ * part's value */
306
+ strings: { text: string; spans: Span[]; parts: string[] }[];
307
+ /** numbers shown once while their element kept changing (a count, a
308
+ * tween): not product data, not listed */
309
+ between: { values: number; elements: number };
310
+ };
311
+
312
+ const round3 = (v: number) => Math.round(v * 1000) / 1000;
313
+
314
+ /** add [t, t + every) to a list of spans, joined to the last when it touches */
315
+ const addSpan = (spans: Span[], t: number, every: number) => {
316
+ const last = spans[spans.length - 1];
317
+ if (last && t <= last[1] + every * 0.5 + 1e-6) last[1] = round3(Math.max(last[1], t + every));
318
+ else spans.push([round3(t), round3(t + every)]);
319
+ };
320
+
321
+ const partName = (e: PartValueEntry) => (e.field ? `${e.ref} ${e.field}` : e.ref);
322
+
323
+ /**
324
+ * The film's own text over time set beside its declared sources and the
325
+ * values the product's parts showed. A value counts as shown when its
326
+ * element holds the same text in two samples in a row, or it is the last
327
+ * text the element shows (it then leaves, or the film ends); any other — a
328
+ * text shown once between two others — is in-between and only counted.
329
+ */
330
+ export function readProvenance(
331
+ samples: readonly ProvenanceSample[] | null,
332
+ o: {
333
+ sources: readonly FilmSource[];
334
+ sourcesFrom: "page" | "events file" | null;
335
+ index: ComponentValueIndex;
336
+ every: number;
337
+ note?: string;
338
+ },
339
+ ): FilmProvenance {
340
+ const { index, every } = o;
341
+ const partState = (ref: string): ProvenanceSource["part"] =>
342
+ !index.files.length
343
+ ? "no components.json read"
344
+ : index.refs.has(ref)
345
+ ? "in components.json"
346
+ : "not in the components.json read";
347
+ const base = {
348
+ every,
349
+ components: index.files,
350
+ unreadComponents: index.unread,
351
+ };
352
+ if (!samples)
353
+ return {
354
+ how: "not measured",
355
+ ...(o.note ? { note: o.note } : {}),
356
+ ...base,
357
+ sources: {
358
+ from: o.sourcesFrom,
359
+ list: o.sources.map((s) => ({
360
+ ...s,
361
+ seen: null,
362
+ ...(s.ref ? { part: partState(s.ref) } : {}),
363
+ })),
364
+ },
365
+ values: [],
366
+ strings: [],
367
+ between: { values: 0, elements: 0 },
368
+ };
369
+ const list = [...samples].sort((a, b) => a.t - b.t);
370
+ const at = list.map((s) => new Map(s.items.map((x) => [x.k, x])));
371
+ const norms = index.entries.map(entryNorms);
372
+ // what each source covers: its label's and text's numbers, its part's values
373
+ const srcNorms = o.sources.map((s) => {
374
+ const n = new Set<string>();
375
+ for (const str of [s.label, ...(s.text ?? [])])
376
+ for (const t of numberTokens(str)) n.add(t.norm);
377
+ if (s.ref)
378
+ index.entries.forEach((e, i) => {
379
+ if (e.ref === s.ref && (!s.field || e.field === s.field))
380
+ for (const v of norms[i]!) n.add(v);
381
+ });
382
+ return n;
383
+ });
384
+ const srcStrings = o.sources.map((s) =>
385
+ [s.label, ...(s.text ?? [])].map(normText).filter((x) => x.length >= 2),
386
+ );
387
+ const seen = o.sources.map(() => [] as Span[]);
388
+ const values = new Map<string, ProvenanceValue>();
389
+ const strings = new Map<string, { text: string; spans: Span[]; parts: string[] }>();
390
+ let between = 0;
391
+ const betweenEls = new Set<number>();
392
+
393
+ list.forEach((s, i) => {
394
+ const hit = new Set<number>();
395
+ for (const item of s.items) {
396
+ const low = normText(item.text);
397
+ for (const j of item.cov) hit.add(j);
398
+ srcStrings.forEach((ss, j) => {
399
+ if (ss.some((x) => low.includes(x))) hit.add(j);
400
+ });
401
+ const tokens = numberTokens(item.text);
402
+ const prev = i > 0 ? at[i - 1]!.get(item.k) : undefined;
403
+ const next = i < list.length - 1 ? at[i + 1]!.get(item.k) : undefined;
404
+ const held = prev?.text === item.text || next?.text === item.text || next === undefined;
405
+ if (!held) {
406
+ if (tokens.length) {
407
+ between += tokens.length;
408
+ betweenEls.add(item.k);
409
+ }
410
+ continue;
411
+ }
412
+ if (!tokens.length) {
413
+ if (low.length < 2) continue;
414
+ const parts = index.entries.filter((e) => normText(e.text) === low).map(partName);
415
+ if (!parts.length) continue;
416
+ const cur = strings.get(low) ?? { text: item.text, spans: [], parts: [] };
417
+ addSpan(cur.spans, s.t, every);
418
+ for (const p of parts) if (!cur.parts.includes(p)) cur.parts.push(p);
419
+ strings.set(low, cur);
420
+ continue;
421
+ }
422
+ for (const tok of tokens) {
423
+ const by = new Set<number>(item.cov);
424
+ srcNorms.forEach((n, j) => {
425
+ if (n.has(tok.norm)) by.add(j);
426
+ });
427
+ const parts = index.entries.filter((_, j) => norms[j]!.has(tok.norm)).map(partName);
428
+ const how: ProvenanceKind = by.size
429
+ ? "declared"
430
+ : parts.length
431
+ ? "matches a part"
432
+ : "no source declared";
433
+ const key = `${tok.raw}\u0000${how}`;
434
+ const cur = values.get(key) ?? { text: tok.raw, how, spans: [], in: item.text };
435
+ addSpan(cur.spans, s.t, every);
436
+ if (by.size) {
437
+ cur.sources ??= [];
438
+ for (const j of by) {
439
+ const label = o.sources[j]?.label;
440
+ if (label != null && !cur.sources.includes(label)) cur.sources.push(label);
441
+ }
442
+ }
443
+ if (parts.length) {
444
+ cur.parts ??= [];
445
+ for (const p of parts) if (!cur.parts.includes(p)) cur.parts.push(p);
446
+ }
447
+ values.set(key, cur);
448
+ }
449
+ }
450
+ for (const j of hit) addSpan(seen[j]!, s.t, every);
451
+ });
452
+
453
+ const vals = [...values.values()].sort(
454
+ (a, b) => a.spans[0]![0] - b.spans[0]![0] || a.text.localeCompare(b.text),
455
+ );
456
+ return {
457
+ how: vals.length || strings.size || between ? "measured" : "not detected",
458
+ ...(o.note ? { note: o.note } : {}),
459
+ ...base,
460
+ sources: {
461
+ from: o.sourcesFrom,
462
+ list: o.sources.map((s, j) => ({
463
+ ...s,
464
+ seen: seen[j]!,
465
+ ...(s.ref ? { part: partState(s.ref) } : {}),
466
+ })),
467
+ },
468
+ values: vals,
469
+ strings: [...strings.values()].sort((a, b) => a.spans[0]![0] - b.spans[0]![0]),
470
+ between: { values: between, elements: betweenEls.size },
471
+ };
472
+ }
473
+
474
+ /** every source the page gave over the samples, checked, in the order first
475
+ * given (a source declared late — a value read in __render — is kept too),
476
+ * and each sample's `cov` renumbered to that list (an entry the check left
477
+ * out covers nothing); null when no sample had a list */
478
+ export function pageSourcesOf(
479
+ samples: readonly ProvenanceSample[],
480
+ ): { sources: FilmSource[]; samples: ProvenanceSample[] } | null {
481
+ const sources: FilmSource[] = [];
482
+ const at = new Map<string, number>();
483
+ let any = false;
484
+ const out = samples.map((s) => {
485
+ if (!Array.isArray(s.sources)) return { ...s, items: s.items.map((x) => ({ ...x, cov: [] })) };
486
+ any = true;
487
+ const local = (s.sources as unknown[]).map((raw) => {
488
+ const [c] = checkSources([raw]);
489
+ if (!c) return -1;
490
+ const key = JSON.stringify(c);
491
+ let j = at.get(key);
492
+ if (j == null) {
493
+ j = sources.length;
494
+ sources.push(c);
495
+ at.set(key, j);
496
+ }
497
+ return j;
498
+ });
499
+ return {
500
+ ...s,
501
+ items: s.items.map((x) => ({
502
+ ...x,
503
+ cov: [...new Set(x.cov.map((i) => local[i] ?? -1).filter((j) => j >= 0))].sort(
504
+ (a, b) => a - b,
505
+ ),
506
+ })),
507
+ };
508
+ });
509
+ return any ? { sources, samples: out } : null;
510
+ }
511
+
512
+ // --- the lines -----------------------------------------------------------------------------
513
+
514
+ const fmtT = (t: number) => {
515
+ if (t < 60) return `${t.toFixed(2)}s`;
516
+ const m = Math.floor(t / 60);
517
+ return `${m}:${(t - m * 60).toFixed(2).padStart(5, "0")}`;
518
+ };
519
+ const spansText = (sp: readonly Span[]) => sp.map(([a, b]) => `${fmtT(a)}–${fmtT(b)}`).join(", ");
520
+ const clip = (s: string, n = 80) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
521
+ const few = (xs: readonly string[], n = 3) =>
522
+ xs.length > n ? `${xs.slice(0, n).join(", ")} and ${xs.length - n} more` : xs.join(", ");
523
+
524
+ /** probe.md's section; `base` makes the components.json paths relative */
525
+ export function formatProvenance(p: FilmProvenance, base?: string): string[] {
526
+ const L: string[] = ["## Where the values on screen come from"];
527
+ const shown = (f: string) => (base ? relative(base, f) || f : f);
528
+ const files = p.components.length
529
+ ? `components.json read: ${p.components.map((c) => `${shown(c.file)} (version ${c.version || "?"}, ${c.parts} parts${c.version >= 2 ? `, ${c.values} values` : ", no values — matched on its labels"})`).join("; ")}`
530
+ : "no components.json read beside the page";
531
+ if (p.how === "not measured")
532
+ L.push(
533
+ `[not measured] the film's own text was not read${p.note ? ` (${p.note})` : " — give the film's page (--page)"}; ${files}.`,
534
+ );
535
+ else
536
+ L.push(
537
+ `[${p.how}] the numbers in the film's own text (outside saved screens and lifted parts, which are the product's page), every ${p.every} s, set beside the sources the page declares (tl.source) and the values the product's parts showed; ${files}. Information only: a value the saved screens did not keep can still be real — a formula, the product's code, a live page.`,
538
+ );
539
+ for (const u of p.unreadComponents) L.push(`- could not read ${shown(u.file)}: ${u.why}`);
540
+ const src = p.sources.list;
541
+ if (!src.length)
542
+ L.push(
543
+ `Declared sources: none${p.sources.from ? ` (from the ${p.sources.from})` : ""} — kit/time.js \`tl.source(label, { ref | url | note })\`; kit/media.js \`readValues(url, { tl })\` declares what it reads.`,
544
+ );
545
+ else {
546
+ L.push(`Declared sources (from the ${p.sources.from ?? "page"}), ${src.length}:`);
547
+ for (const s of src) {
548
+ const where = [
549
+ s.ref ? `${s.ref}${s.field ? ` ${s.field}` : ""}${s.part ? ` (${s.part})` : ""}` : "",
550
+ s.url ? `url ${s.url}` : "",
551
+ s.note ? `note: ${s.note}` : "",
552
+ s.selector ? `covers ${s.selector}` : "",
553
+ s.text?.length ? `text ${s.text.map((x) => `"${clip(x, 40)}"`).join(", ")}` : "",
554
+ ]
555
+ .filter(Boolean)
556
+ .join("; ");
557
+ const on =
558
+ s.seen == null
559
+ ? ""
560
+ : s.seen.length
561
+ ? ` — on screen ${spansText(s.seen)}`
562
+ : " — not seen in the film's own text";
563
+ L.push(`- "${clip(s.label, 60)}" — ${where}${on}`);
564
+ }
565
+ }
566
+ if (p.how === "not measured") return L;
567
+ if (!p.values.length) L.push("[not detected] no number held in the film's own text");
568
+ else {
569
+ L.push("Numbers held in the film's own text:");
570
+ for (const v of p.values) {
571
+ const why =
572
+ v.how === "declared"
573
+ ? ` (${few((v.sources ?? []).map((x) => `"${clip(x, 40)}"`))})`
574
+ : v.how === "matches a part"
575
+ ? ` (${few(v.parts ?? [])})`
576
+ : "";
577
+ const inText = v.in !== v.text ? ` in "${clip(v.in)}"` : "";
578
+ L.push(`- ${v.how}: ${v.text} ${spansText(v.spans)}${inText}${why}`);
579
+ }
580
+ }
581
+ if (p.strings.length)
582
+ L.push(
583
+ `Text that reads exactly as a part's value: ${p.strings.map((s) => `"${clip(s.text, 40)}" ${spansText(s.spans)} (${few(s.parts)})`).join("; ")}`,
584
+ );
585
+ if (p.between.values)
586
+ L.push(
587
+ `In-between numbers (shown once while their element kept changing — a count, a tween), not listed: ${p.between.values} in ${p.between.elements} element(s).`,
588
+ );
589
+ return L;
590
+ }
591
+
592
+ /** the page's folder: the page itself when it is one, else the folder it is in */
593
+ export function pageDirOf(page: string): string {
594
+ const p = resolve(page);
595
+ return isDir(p) ? p : dirname(p);
596
+ }