@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,701 @@
1
+ // What a film page's layout gets wrong at a given moment, read from the page
2
+ // itself — the defects an author who cannot watch the film misses:
3
+ //
4
+ // text-over-text two pieces of text drawn on top of each other (a caption
5
+ // over the real interface's own text, inside an <iframe> too)
6
+ // text-over-badge text running into a small painted element that is not
7
+ // its own box (a number growing into a "vs" disc)
8
+ // text-off-frame text cut by the edge of the frame
9
+ //
10
+ // Only what is clearly visible counts: both pieces at an effective opacity of
11
+ // at least 0.6 (a cross-fade's two scenes are not a collision), where their
12
+ // glyphs reach (not their fonts' full line boxes), as far as the boxes that
13
+ // hold them let them show. The size each piece of text is drawn at is read
14
+ // too — its font size times how much it is scaled on screen — as
15
+ // information: what is too small to read is not decided here. Nothing here
16
+ // judges taste; contrast and crowding are not checked, and text drawn into a
17
+ // canvas or a video is pixels, not text.
18
+ //
19
+ // `readPageLayout` plays the film's page on its clock and samples it over the
20
+ // film's time; a finding counts once it holds for two samples in a row (an
21
+ // entrance sliding past an edge for a moment does not).
22
+ //
23
+ // The probe is serialized into the page (Function#toString): it must not
24
+ // reference anything outside its own body.
25
+
26
+ import { type HtmlBrowser, launchHtmlBrowser } from "../html/cdp";
27
+ import { serveDirectory } from "../html/server";
28
+ import { type FilmPageInfo, filmClockSource } from "./clock";
29
+ import { resolveFilmPage } from "./render";
30
+
31
+ export type LayoutFinding = {
32
+ kind: "text-over-text" | "text-over-badge" | "text-off-frame";
33
+ /** the two parties, described (the second is absent for text-off-frame) */
34
+ a: string;
35
+ b?: string;
36
+ /** where, in frame CSS px: x, y, w, h */
37
+ box: [number, number, number, number];
38
+ };
39
+
40
+ /** a finding that held, and from when to when (seconds, the film's own time) */
41
+ export type LayoutSpan = LayoutFinding & { from: number; to: number };
42
+
43
+ /** a piece of text as drawn: its description and its size in frame px */
44
+ type DrawnText = { text: string; px: number };
45
+
46
+ export function layoutProbeSource(): string {
47
+ return `(() => { const __name = (f) => f; return (${probeLayout.toString()})(); })()`;
48
+ }
49
+
50
+ function probeLayout(): { findings: LayoutFinding[]; texts: DrawnText[]; unread: string[] } {
51
+ const vw = innerWidth;
52
+ const vh = innerHeight;
53
+ type Box = { x: number; y: number; w: number; h: number };
54
+ type Text = { el: Element; boxes: Box[]; label: string; root: Document; px: number };
55
+ type Badge = { el: Element; box: Box; label: string };
56
+ const MIN_OPACITY = 0.6;
57
+
58
+ /** how much an element is scaled on screen — by its ancestors' transforms,
59
+ * a camera's zoom: the box it is drawn in over the box it is laid out in */
60
+ const scaleOf = (el: Element): number => {
61
+ const drawn = el.getBoundingClientRect().height;
62
+ const laid = (el as HTMLElement).offsetHeight;
63
+ if (typeof laid === "number") return laid > 0 ? drawn / laid : 1;
64
+ try {
65
+ // SVG text: its box in its own units
66
+ const own = (el as SVGGraphicsElement).getBBox?.().height;
67
+ return own && own > 0 ? drawn / own : 1;
68
+ } catch {
69
+ return 1;
70
+ }
71
+ };
72
+
73
+ // effective opacity: none when the element itself is not visible — its own
74
+ // computed visibility, which a descendant can set back to visible under a
75
+ // hidden ancestor (a part a lifted screen shows), or a display:none
76
+ // ancestor — else its opacity times every ancestor's (memoized per probe)
77
+ const alphas = new Map<Element, number>();
78
+ const alphaOf = (el: Element | null, view: Window): number => {
79
+ if (!el) return 1;
80
+ const hit = alphas.get(el);
81
+ if (hit !== undefined) return hit;
82
+ const cs = view.getComputedStyle(el);
83
+ const own = cs.display === "none" ? 0 : Number(cs.opacity) || 0;
84
+ const o = own === 0 ? 0 : own * alphaOf(el.parentElement, view);
85
+ alphas.set(el, o);
86
+ return o;
87
+ };
88
+ const opacityOf = (el: Element | null, view: Window): number => {
89
+ if (!el) return 1;
90
+ const v = view.getComputedStyle(el).visibility;
91
+ return v === "hidden" || v === "collapse" ? 0 : alphaOf(el, view);
92
+ };
93
+ /** the alpha of a computed colour: rgba(…, a) or 1 */
94
+ const alpha = (c: string): number => {
95
+ const m = /rgba?\(([^)]*)\)/.exec(c);
96
+ if (!m) return c === "transparent" ? 0 : 1;
97
+ const parts = m[1]!.split(/[,/\s]+/).filter(Boolean);
98
+ return parts.length >= 4 ? Number.parseFloat(parts[3]!) : 1;
99
+ };
100
+ /** what an element's own and its ancestors' transforms (an iframe's
101
+ * included) do to it on screen, without what moves it: a, b, c, d of a 2D
102
+ * matrix. Within a 3D context (`transform-style: preserve-3d`) the whole
103
+ * matrices multiply before the plane is taken; perspective is left out.
104
+ * Memoized per probe. */
105
+ type Lin = [number, number, number, number];
106
+ const UPRIGHT: Lin = [1, 0, 0, 1];
107
+ const SVG_NS = "http://www.w3.org/2000/svg";
108
+ /** what transforms apply to when `display` is inline: replaced elements */
109
+ const REPLACED = new Set([
110
+ "img",
111
+ "video",
112
+ "canvas",
113
+ "iframe",
114
+ "embed",
115
+ "object",
116
+ "input",
117
+ "select",
118
+ "textarea",
119
+ "svg",
120
+ ]);
121
+ /** an element's own transform — `rotate` and `scale` first, then
122
+ * `transform`, which does not show them; an SVG's stretched viewBox too —
123
+ * or null where there is none, or none applies (a box-less or plain
124
+ * inline element) */
125
+ const ownOf = (el: Element, cs: CSSStyleDeclaration): DOMMatrix | null => {
126
+ if (cs.display === "contents" || cs.display === "none") return null;
127
+ if (cs.display === "inline" && el.namespaceURI !== SVG_NS && !REPLACED.has(el.localName))
128
+ return null;
129
+ let m = new DOMMatrix();
130
+ if (cs.rotate && cs.rotate !== "none") {
131
+ const v = cs.rotate.trim().split(/\s+/); // "30deg", "x 30deg", "1 1 0 30deg"
132
+ const deg = Number.parseFloat(v[v.length - 1] ?? "0");
133
+ const axis =
134
+ v.length === 4
135
+ ? v.slice(0, 3).map(Number)
136
+ : v[0] === "x"
137
+ ? [1, 0, 0]
138
+ : v[0] === "y"
139
+ ? [0, 1, 0]
140
+ : [0, 0, 1];
141
+ m = m.rotateAxisAngle(axis[0], axis[1], axis[2], deg);
142
+ }
143
+ if (cs.scale && cs.scale !== "none") {
144
+ const v = cs.scale.trim().split(/\s+/).map(Number.parseFloat);
145
+ m = m.scale(v[0], v[1] ?? v[0], v[2] ?? 1);
146
+ }
147
+ if (cs.transform && cs.transform !== "none") m = m.multiply(new DOMMatrix(cs.transform));
148
+ if (el.namespaceURI === SVG_NS && el.localName === "svg") {
149
+ const svg = el as SVGSVGElement;
150
+ const vb = svg.viewBox?.baseVal;
151
+ // SVG_PRESERVEASPECTRATIO_NONE: the viewBox stretched to the box
152
+ if (vb && vb.width > 0 && vb.height > 0 && svg.preserveAspectRatio?.baseVal.align === 1) {
153
+ const w = svg.clientWidth || svg.width.baseVal.value;
154
+ const h = svg.clientHeight || svg.height.baseVal.value;
155
+ if (w > 0 && h > 0) m = m.scale(w / vb.width, h / vb.height);
156
+ }
157
+ }
158
+ return m.isIdentity ? null : m;
159
+ };
160
+ const times = (u: Lin, m: DOMMatrix): Lin => [
161
+ u[0] * m.a + u[2] * m.b,
162
+ u[1] * m.a + u[3] * m.b,
163
+ u[0] * m.c + u[2] * m.d,
164
+ u[1] * m.c + u[3] * m.d,
165
+ ];
166
+ /** whether what an element holds stays in its 3D space: `preserve-3d`,
167
+ * unless a grouping property flattens it all the same (a clip, a fade, a
168
+ * filter, a blend, a mask, isolation, paint containment) */
169
+ const keeps3D = (cs: CSSStyleDeclaration): boolean =>
170
+ cs.transformStyle === "preserve-3d" &&
171
+ /^(visible|clip)$/.test(cs.overflowX) &&
172
+ /^(visible|clip)$/.test(cs.overflowY) &&
173
+ !(Number(cs.opacity) < 1) &&
174
+ cs.filter === "none" &&
175
+ (!cs.backdropFilter || cs.backdropFilter === "none") &&
176
+ cs.clipPath === "none" &&
177
+ (!cs.clip || cs.clip === "auto") &&
178
+ cs.isolation !== "isolate" &&
179
+ (!cs.maskImage || cs.maskImage === "none") &&
180
+ cs.mixBlendMode === "normal" &&
181
+ !/paint|strict|content/.test(cs.contain);
182
+ /** what a parent's `perspective` does to what it holds (about its origin:
183
+ * which plane is tilted, not where, is what matters here) */
184
+ const perspectiveOf = (cs: CSSStyleDeclaration): DOMMatrix | null => {
185
+ const d = Number.parseFloat(cs.perspective);
186
+ return cs.perspective !== "none" && d > 0
187
+ ? new DOMMatrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / d, 0, 0, 0, 1])
188
+ : null;
189
+ };
190
+ /** a plane tilted under perspective: no single 2D matrix maps it */
191
+ const projective = (m: DOMMatrix) => Math.abs(m.m14) + Math.abs(m.m24) > 1e-9;
192
+ /** per element: its 2D part on screen; the 3D context it belongs to (the
193
+ * whole matrix from that context's root down) and the 2D part above it;
194
+ * whether it, or what holds it, is tilted under perspective */
195
+ type Turn = { lin: Lin; ctx: DOMMatrix; above: Lin; projected: boolean };
196
+ const turns = new Map<Element, Turn>();
197
+ const turnOf = (el: Element, view: Window, base: Lin): Turn => {
198
+ const hit = turns.get(el);
199
+ if (hit) return hit;
200
+ const p = el.parentElement;
201
+ const pcs = p ? view.getComputedStyle(p) : null;
202
+ const own = ownOf(el, view.getComputedStyle(el));
203
+ // a parent's perspective reaches whatever it holds in its 3D space, an
204
+ // untransformed wrapper included
205
+ const persp = pcs ? perspectiveOf(pcs) : null;
206
+ const local = persp ? (own ? persp.multiply(own) : persp) : own;
207
+ let t: Turn;
208
+ if (p && pcs && keeps3D(pcs)) {
209
+ const pt = turnOf(p, view, base);
210
+ const ctx = local ? pt.ctx.multiply(local) : pt.ctx;
211
+ t = {
212
+ lin: times(pt.above, ctx),
213
+ ctx,
214
+ above: pt.above,
215
+ projected: pt.projected || projective(ctx),
216
+ };
217
+ } else {
218
+ const pt = p ? turnOf(p, view, base) : null;
219
+ const above = pt ? pt.lin : base;
220
+ const ctx = local ?? new DOMMatrix();
221
+ t = {
222
+ lin: local ? times(above, local) : above,
223
+ ctx,
224
+ above,
225
+ projected: !!pt?.projected || projective(ctx),
226
+ };
227
+ }
228
+ turns.set(el, t);
229
+ return t;
230
+ };
231
+ const linOf = (el: Element, view: Window, base: Lin): Lin => turnOf(el, view, base).lin;
232
+ /** turned, skewed or mirrored on screen: its boxes would be the upright
233
+ * boxes around it, and its size a guess — such text is named, not read */
234
+ const askew = (l: Lin) =>
235
+ l[0] < 0 ||
236
+ l[3] < 0 ||
237
+ Math.abs(l[1]) + Math.abs(l[2]) > 0.01 * (Math.abs(l[0]) + Math.abs(l[3]));
238
+ const unread = new Set<string>();
239
+ const describe = (el: Element, prefix: string): string => {
240
+ const id = el.id ? `#${el.id}` : "";
241
+ const cls =
242
+ typeof el.className === "string" && el.className.trim()
243
+ ? `.${el.className.trim().split(/\s+/).slice(0, 2).join(".")}`
244
+ : "";
245
+ const text = (el.textContent || "").replace(/\s+/g, " ").trim().slice(0, 28);
246
+ return `${prefix}${el.localName}${id}${cls}${text ? ` "${text}"` : ""}`;
247
+ };
248
+ const texts: Text[] = [];
249
+ const badges: Badge[] = [];
250
+ const intersect = (a: Box, b: Box): Box | null => {
251
+ const x0 = Math.max(a.x, b.x);
252
+ const y0 = Math.max(a.y, b.y);
253
+ const x1 = Math.min(a.x + a.w, b.x + b.w);
254
+ const y1 = Math.min(a.y + a.h, b.y + b.h);
255
+ return x1 > x0 && y1 > y0 ? { x: x0, y: y0, w: x1 - x0, h: y1 - y0 } : null;
256
+ };
257
+ /** whether an element is where positioned descendants are placed from: a
258
+ * positioned one (for `absolute`), or one with a transform, a filter or
259
+ * containment (for `fixed` too) */
260
+ const holds = (cs: CSSStyleDeclaration, fixed: boolean): boolean =>
261
+ (!fixed && cs.position !== "static") ||
262
+ cs.transform !== "none" ||
263
+ cs.perspective !== "none" ||
264
+ cs.filter !== "none" ||
265
+ (!!cs.backdropFilter && cs.backdropFilter !== "none") ||
266
+ /paint|layout|strict|content/.test(cs.contain) ||
267
+ /transform|perspective|filter/.test(cs.willChange);
268
+ /** the element whose overflow can clip `el`: its parent, or for an
269
+ * absolutely or fixed positioned one the ancestor it is placed from — those
270
+ * in between do not clip it; null when that is the frame itself */
271
+ const containerOf = (el: Element, view: Window): Element | null => {
272
+ const pos = view.getComputedStyle(el).position;
273
+ if (pos !== "absolute" && pos !== "fixed") return el.parentElement;
274
+ for (let a = el.parentElement; a; a = a.parentElement)
275
+ if (holds(view.getComputedStyle(a), pos === "fixed")) return a;
276
+ return null;
277
+ };
278
+ /** an element's overflow clips what it holds — except the root's, and the
279
+ * body's while the root's is visible: those belong to the frame */
280
+ const clipping = (el: Element, view: Window): boolean => {
281
+ const doc = el.ownerDocument;
282
+ if (el === doc.documentElement) return false;
283
+ const visible = (cs: CSSStyleDeclaration) =>
284
+ cs.overflowX === "visible" && cs.overflowY === "visible";
285
+ if (el === doc.body && visible(view.getComputedStyle(doc.documentElement))) return false;
286
+ const cs = view.getComputedStyle(el);
287
+ return cs.display !== "contents" && !visible(cs);
288
+ };
289
+ /** what of `base` shows of what `holder` holds: its own box when its
290
+ * overflow clips, within what its own holder lets show (a film's "window"
291
+ * around a scaled iframe, a masked line) — memoized per holder */
292
+ const clips = new Map<Element, Box | null>();
293
+ const shownIn = (
294
+ holder: Element | null,
295
+ view: Window,
296
+ map: (b: DOMRect) => Box,
297
+ base: Box,
298
+ ): Box | null => {
299
+ if (!holder) return base;
300
+ if (clips.has(holder)) return clips.get(holder)!;
301
+ let clip = shownIn(containerOf(holder, view), view, map, base);
302
+ if (clip && clipping(holder, view)) clip = intersect(clip, map(holder.getBoundingClientRect()));
303
+ clips.set(holder, clip);
304
+ return clip;
305
+ };
306
+ /** what of `base` shows of an element: what its holder lets show */
307
+ const clipOf = (el: Element, view: Window, map: (b: DOMRect) => Box, base: Box) =>
308
+ shownIn(containerOf(el, view), view, map, base);
309
+
310
+ const collect = (
311
+ doc: Document,
312
+ view: Window,
313
+ map: (b: DOMRect) => Box,
314
+ clip: Box,
315
+ baseOpacity: number,
316
+ prefix: string,
317
+ /** how much the document itself is scaled on screen (an iframe's) */
318
+ scale: number,
319
+ /** what the frame holding the document turns or skews (an iframe's) */
320
+ base: Lin,
321
+ /** whether the frame's box maps what it holds: not when the frame is
322
+ * turned, mirrored or tilted under perspective — then all its text is
323
+ * named */
324
+ mapped: boolean,
325
+ ) => {
326
+ const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
327
+ const range = doc.createRange();
328
+ const seen = new Map<Element, Text>();
329
+ // the document's own fonts, to measure its text's glyphs with
330
+ const pen = doc.createElement("canvas").getContext("2d");
331
+ /** how much of a line of text's box, top and bottom, its glyphs leave
332
+ * empty: the box is the font's full height, the ink only what these
333
+ * characters reach — a label tucked under a big number shares its line
334
+ * box, not its glyphs */
335
+ const inkOf = (cs: CSSStyleDeclaration, text: string) => {
336
+ const whole = { top: 0, bottom: 0 };
337
+ if (!pen) return whole;
338
+ pen.font = "10px serif";
339
+ pen.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
340
+ if (pen.font === "10px serif") return whole; // a font canvas cannot read
341
+ const m = pen.measureText(text);
342
+ const box = m.fontBoundingBoxAscent + m.fontBoundingBoxDescent;
343
+ if (!(box > 0)) return whole;
344
+ const top = Math.max(0, (m.fontBoundingBoxAscent - m.actualBoundingBoxAscent) / box);
345
+ const bottom = Math.max(0, (m.fontBoundingBoxDescent - m.actualBoundingBoxDescent) / box);
346
+ return top + bottom < 0.95 ? { top, bottom } : whole;
347
+ };
348
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
349
+ if (!n.nodeValue?.trim()) continue;
350
+ const el = n.parentElement;
351
+ if (!el || ["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"].includes(el.tagName)) continue;
352
+ if (baseOpacity * opacityOf(el, view) < MIN_OPACITY) continue;
353
+ // the block the text belongs to: a caption split into per-character
354
+ // spans for its entrance is one piece of text, not one per character
355
+ let owner: Element = el;
356
+ while (
357
+ owner.parentElement &&
358
+ owner.parentElement !== doc.body &&
359
+ /^(inline|inline-block|inline-flex|contents)$/.test(view.getComputedStyle(owner).display)
360
+ )
361
+ owner = owner.parentElement;
362
+ range.selectNodeContents(n);
363
+ if (!mapped) {
364
+ // the frame's box cannot place it: named when drawn in the frame's
365
+ // own view at all
366
+ const inView = Array.from(range.getClientRects()).some(
367
+ (r) =>
368
+ r.width >= 2 &&
369
+ r.height >= 2 &&
370
+ r.right > 0 &&
371
+ r.bottom > 0 &&
372
+ r.left < view.innerWidth &&
373
+ r.top < view.innerHeight,
374
+ );
375
+ if (inView) unread.add(describe(owner, prefix));
376
+ continue;
377
+ }
378
+ // what the frame, the iframe's box and any clipping box that holds the
379
+ // text — its own element first — cut off is not drawn
380
+ const visible = shownIn(el, view, map, clip);
381
+ if (!visible) continue;
382
+ const ink = inkOf(view.getComputedStyle(el), n.nodeValue);
383
+ const boxes: Box[] = [];
384
+ for (const r of Array.from(range.getClientRects())) {
385
+ if (r.width < 2 || r.height < 2) continue;
386
+ const glyphs = new DOMRect(
387
+ r.left,
388
+ r.top + ink.top * r.height,
389
+ r.width,
390
+ r.height * (1 - ink.top - ink.bottom),
391
+ );
392
+ const v = intersect(map(glyphs), visible);
393
+ if (v && v.w >= 2 && v.h >= 2) boxes.push(v);
394
+ }
395
+ if (!boxes.length) continue;
396
+ // drawn at all, but turned: named, not read
397
+ if (askew(linOf(el, view, base))) {
398
+ unread.add(describe(owner, prefix));
399
+ continue;
400
+ }
401
+ // the size it is drawn at: its own font size, as scaled on screen
402
+ const px = (Number.parseFloat(view.getComputedStyle(el).fontSize) || 0) * scaleOf(el) * scale;
403
+ const t = seen.get(owner);
404
+ if (t) {
405
+ t.boxes.push(...boxes);
406
+ t.px = Math.min(t.px, px);
407
+ } else {
408
+ const entry = { el: owner, boxes, label: describe(owner, prefix), root: doc, px };
409
+ seen.set(owner, entry);
410
+ texts.push(entry);
411
+ }
412
+ }
413
+ // small painted elements: badges, chips, discs, buttons
414
+ for (const el of Array.from(doc.body.querySelectorAll("*"))) {
415
+ if (!mapped || askew(linOf(el, view, base))) continue; // its box would be the one around it
416
+ const cs = view.getComputedStyle(el);
417
+ const painted =
418
+ alpha(cs.backgroundColor) >= 0.5 ||
419
+ (Number.parseFloat(cs.borderTopWidth) > 0 &&
420
+ cs.borderTopStyle !== "none" &&
421
+ alpha(cs.borderTopColor) >= 0.5);
422
+ if (!painted) continue;
423
+ const r = el.getBoundingClientRect();
424
+ if (r.width < 8 || r.height < 8) continue;
425
+ const full = map(r);
426
+ if (full.w * full.h > 0.04 * vw * vh) continue; // a panel or a page, not a badge
427
+ if (baseOpacity * opacityOf(el, view) < MIN_OPACITY) continue;
428
+ const visible = clipOf(el, view, map, clip);
429
+ const m = visible && intersect(full, visible);
430
+ if (!m) continue;
431
+ badges.push({ el, box: m, label: describe(el, prefix) });
432
+ }
433
+ };
434
+
435
+ const frame: Box = { x: 0, y: 0, w: vw, h: vh };
436
+ collect(
437
+ document,
438
+ window,
439
+ (r) => ({ x: r.left, y: r.top, w: r.width, h: r.height }),
440
+ frame,
441
+ 1,
442
+ "",
443
+ 1,
444
+ UPRIGHT,
445
+ true,
446
+ );
447
+ // same-origin iframes, mapped into the frame through their own box and scale
448
+ for (const f of Array.from(document.querySelectorAll("iframe"))) {
449
+ let doc: Document | null = null;
450
+ try {
451
+ doc = f.contentDocument;
452
+ } catch {
453
+ continue;
454
+ }
455
+ const view = f.contentWindow;
456
+ if (!doc?.body || !view) continue;
457
+ const o = opacityOf(f, window);
458
+ if (o < MIN_OPACITY) continue;
459
+ // its page shows in its content box (inside its border and padding), as
460
+ // scaled as the frame's own box is on screen
461
+ const fb = f.getBoundingClientRect();
462
+ const sx = f.offsetWidth ? fb.width / f.offsetWidth : 1;
463
+ const sy = f.offsetHeight ? fb.height / f.offsetHeight : 1;
464
+ const fcs = getComputedStyle(f);
465
+ const pad = (side: "Left" | "Right" | "Top" | "Bottom") =>
466
+ Number.parseFloat(fcs[`padding${side}`]) || 0;
467
+ const left = fb.left + (f.clientLeft + pad("Left")) * sx;
468
+ const top = fb.top + (f.clientTop + pad("Top")) * sy;
469
+ const map = (r: DOMRect) => ({
470
+ x: left + r.left * sx,
471
+ y: top + r.top * sy,
472
+ w: r.width * sx,
473
+ h: r.height * sy,
474
+ });
475
+ // that box, within what the boxes holding it let show (measured from
476
+ // the frame, as everything on this page is: the clips are shared)
477
+ const own = {
478
+ x: left,
479
+ y: top,
480
+ w: Math.max(0, f.clientWidth - pad("Left") - pad("Right")) * sx,
481
+ h: Math.max(0, f.clientHeight - pad("Top") - pad("Bottom")) * sy,
482
+ };
483
+ const shown = clipOf(
484
+ f,
485
+ window,
486
+ (r) => ({ x: r.left, y: r.top, w: r.width, h: r.height }),
487
+ frame,
488
+ );
489
+ // a frame turned, mirrored or tilted in perspective: its box cannot map
490
+ // what it holds, and whether it shows at all is read from the box around it
491
+ const turn = turnOf(f, window, UPRIGHT);
492
+ const mapped = !askew(turn.lin) && !turn.projected;
493
+ const clip =
494
+ shown &&
495
+ intersect(mapped ? own : { x: fb.left, y: fb.top, w: fb.width, h: fb.height }, shown);
496
+ if (clip) collect(doc, view, map, clip, o, `iframe › `, sy, turn.lin, mapped);
497
+ }
498
+
499
+ const overlap = (a: Box, b: Box) => {
500
+ const x0 = Math.max(a.x, b.x);
501
+ const y0 = Math.max(a.y, b.y);
502
+ const x1 = Math.min(a.x + a.w, b.x + b.w);
503
+ const y1 = Math.min(a.y + a.h, b.y + b.h);
504
+ return x1 > x0 && y1 > y0 ? { x: x0, y: y0, w: x1 - x0, h: y1 - y0 } : null;
505
+ };
506
+ const related = (a: Element, b: Element) => a === b || a.contains(b) || b.contains(a);
507
+ const findings: LayoutFinding[] = [];
508
+ const round = (b: Box): [number, number, number, number] => [
509
+ Math.round(b.x),
510
+ Math.round(b.y),
511
+ Math.round(b.w),
512
+ Math.round(b.h),
513
+ ];
514
+
515
+ // text over text: a real overlap of glyph boxes, not a touch
516
+ for (let i = 0; i < texts.length; i++)
517
+ for (let j = i + 1; j < texts.length; j++) {
518
+ const A = texts[i]!;
519
+ const B = texts[j]!;
520
+ if (A.root === B.root && related(A.el, B.el)) continue;
521
+ // inside one embedded page the overlap is the product's own design
522
+ if (A.root === B.root && A.root !== document) continue;
523
+ let hit: Box | null = null;
524
+ for (const a of A.boxes)
525
+ for (const b of B.boxes) {
526
+ const o = overlap(a, b);
527
+ if (o && o.w * o.h >= Math.max(40, 0.2 * Math.min(a.w * a.h, b.w * b.h))) hit = o;
528
+ }
529
+ if (hit) findings.push({ kind: "text-over-text", a: A.label, b: B.label, box: round(hit) });
530
+ }
531
+ // text into a badge that is not its own box
532
+ for (const T of texts)
533
+ for (const G of badges) {
534
+ if (T.root === G.el.ownerDocument && related(T.el, G.el)) continue;
535
+ if (T.root === G.el.ownerDocument && T.root !== document) continue;
536
+ for (const a of T.boxes) {
537
+ const o = overlap(a, G.box);
538
+ if (o && o.w * o.h >= Math.max(40, 0.15 * Math.min(a.w * a.h, G.box.w * G.box.h))) {
539
+ findings.push({ kind: "text-over-badge", a: T.label, b: G.label, box: round(o) });
540
+ break;
541
+ }
542
+ }
543
+ }
544
+ // the film's own text cut by the frame's edge — where what shows of it
545
+ // reaches that edge: a box inside the frame that clips it first is design
546
+ for (const T of texts) {
547
+ if (T.root !== document) continue;
548
+ const r = T.el.getBoundingClientRect();
549
+ const range = document.createRange();
550
+ range.selectNodeContents(T.el);
551
+ const full = range.getBoundingClientRect();
552
+ const box = full.width > 0 ? full : r;
553
+ const reaches = (edge: (b: Box) => boolean) => T.boxes.some(edge);
554
+ if (
555
+ (box.left < -1 && reaches((b) => b.x <= 1)) ||
556
+ (box.top < -1 && reaches((b) => b.y <= 1)) ||
557
+ (box.right > vw + 1 && reaches((b) => b.x + b.w >= vw - 1)) ||
558
+ (box.bottom > vh + 1 && reaches((b) => b.y + b.h >= vh - 1))
559
+ ) {
560
+ const vis = overlap({ x: box.left, y: box.top, w: box.width, h: box.height }, frame);
561
+ if (vis) findings.push({ kind: "text-off-frame", a: T.label, box: round(vis) });
562
+ }
563
+ }
564
+ return {
565
+ findings,
566
+ texts: texts.map((t) => ({ text: t.label, px: Math.round(t.px * 10) / 10 })),
567
+ unread: [...unread],
568
+ };
569
+ }
570
+
571
+ export type PageReading = {
572
+ /** what held for two samples in a row */
573
+ spans: LayoutSpan[];
574
+ /** the smallest text drawn — at about the same size for two samples in a
575
+ * row, so text growing in from nothing does not count — and when */
576
+ smallest: { px: number; at: number; text: string } | null;
577
+ /** text drawn turned, skewed or mirrored, which is named rather than read */
578
+ unread: string[];
579
+ /** the page's own window.__film.marks, as prepare() returned them */
580
+ marks: unknown;
581
+ /** the size the page was laid out at (CSS px: the master's frame) */
582
+ width: number;
583
+ height: number;
584
+ };
585
+
586
+ /** Play the film's page on the film clock and read its layout every `every`
587
+ * seconds of [from, from + duration) — the stretch of the page the film
588
+ * shows. Times come back in the film's own time (its first frame is 0). */
589
+ export async function readPageLayout(opts: {
590
+ page: string;
591
+ root?: string;
592
+ chromePath: string;
593
+ from: number;
594
+ duration: number;
595
+ every: number;
596
+ /** the size the film was rendered at; default the page's own, else `fallback` */
597
+ width?: number;
598
+ height?: number;
599
+ fallback: { width: number; height: number };
600
+ onConsole?: (level: string, text: string) => void;
601
+ }): Promise<PageReading> {
602
+ const { root, urlPath } = resolveFilmPage(opts.page, opts.root);
603
+ const server = await serveDirectory(root);
604
+ // as `film render` opens it: the same clock, animations still until it sets them
605
+ const open = (width: number, height: number) =>
606
+ launchHtmlBrowser({
607
+ chromePath: opts.chromePath,
608
+ url: `${server.url}${urlPath}`,
609
+ width,
610
+ height,
611
+ initScript: filmClockSource({ seed: 0x5eed, epochMs: Date.now() }),
612
+ stillAnimations: true,
613
+ onConsole: opts.onConsole,
614
+ timeoutMs: 120_000,
615
+ profilePrefix: "open-take-check-",
616
+ });
617
+ const prepare = async (b: HtmlBrowser) => {
618
+ if (!(await b.evaluate<boolean>(`typeof window.__ot === "object"`)))
619
+ throw new Error("film check: the film clock did not install in the page");
620
+ return b.evaluate<FilmPageInfo>("window.__ot.prepare()", { timeoutMs: 120_000 });
621
+ };
622
+ try {
623
+ let width = opts.width ?? opts.fallback.width;
624
+ let height = opts.height ?? opts.fallback.height;
625
+ let browser = await open(width, height);
626
+ try {
627
+ let info = await prepare(browser);
628
+ // a page that declares its size, when the film does not say, is laid
629
+ // out again at it — as `film render` does
630
+ if (
631
+ opts.width === undefined &&
632
+ info.width &&
633
+ info.height &&
634
+ (info.width !== width || info.height !== height)
635
+ ) {
636
+ await browser.close();
637
+ width = info.width;
638
+ height = info.height;
639
+ browser = await open(width, height);
640
+ info = await prepare(browser);
641
+ }
642
+ // findings seen at the last sample, and since when
643
+ const running = new Map<string, LayoutSpan & { count: number }>();
644
+ const spans: LayoutSpan[] = [];
645
+ const end = (key: string) => {
646
+ const s = running.get(key)!;
647
+ running.delete(key);
648
+ if (s.count >= 2)
649
+ spans.push({ kind: s.kind, a: s.a, b: s.b, box: s.box, from: s.from, to: s.to });
650
+ };
651
+ let smallest: PageReading["smallest"] = null;
652
+ const unread = new Set<string>();
653
+ // each piece of text's size at the sample before, and when that was
654
+ let before = new Map<string, number>();
655
+ let beforeAt = 0;
656
+ for (let k = 0; ; k++) {
657
+ const at = Math.round(k * opts.every * 1000) / 1000;
658
+ if (at >= opts.duration - 1e-9) break;
659
+ await browser.evaluate(`window.__ot.seek(${opts.from + at})`);
660
+ const read = await browser.evaluate<ReturnType<typeof probeLayout>>(layoutProbeSource());
661
+ const { findings, texts } = read;
662
+ for (const u of read.unread) unread.add(u);
663
+ const now = new Set<string>();
664
+ for (const f of findings) {
665
+ const key = `${f.kind}|${f.a}|${f.b ?? ""}`;
666
+ now.add(key);
667
+ const s = running.get(key);
668
+ if (s) {
669
+ s.to = at;
670
+ s.count++;
671
+ } else running.set(key, { ...f, from: at, to: at, count: 1 });
672
+ }
673
+ for (const key of [...running.keys()]) if (!now.has(key)) end(key);
674
+ // a size counts once a piece of text keeps it, within a tenth, from
675
+ // one sample to the next
676
+ const sizes = new Map<string, number>();
677
+ for (const t of texts) sizes.set(t.text, Math.min(t.px, sizes.get(t.text) ?? t.px));
678
+ for (const [text, px] of sizes) {
679
+ const was = before.get(text);
680
+ if (was === undefined || Math.abs(px - was) > 0.1 * Math.max(px, was)) continue;
681
+ if (!smallest || was < smallest.px) smallest = { px: was, at: beforeAt, text };
682
+ }
683
+ before = sizes;
684
+ beforeAt = at;
685
+ }
686
+ for (const key of [...running.keys()]) end(key);
687
+ return {
688
+ spans: spans.sort((a, b) => a.from - b.from),
689
+ smallest,
690
+ unread: [...unread],
691
+ marks: info.marks,
692
+ width,
693
+ height,
694
+ };
695
+ } finally {
696
+ await browser.close();
697
+ }
698
+ } finally {
699
+ await server.close();
700
+ }
701
+ }