@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,809 @@
1
+ // The component probe: which pieces of a saved screen stand on their own — a
2
+ // number the product worked out, a stat, a heading, a button, a field, a
3
+ // card, a row of like items — measured in the restored page itself
4
+ // (state.html, after `data-ot-ready`, so `data-ot-id` is on every indexed
5
+ // element and computed styles are live). The runtime evaluates it in the
6
+ // fidelity page right after the fidelity screenshot (dom-state.ts
7
+ // `finalizeDomStates`) and writes the result as `states/<id>/parts.json`;
8
+ // `open-take components` runs the same string for states saved before it
9
+ // existed. One copy, shared by both.
10
+ //
11
+ // What it writes is measurement: kinds by stated tests, styles, the text's
12
+ // ink box, the backdrop, whether something covers it, and what each part
13
+ // holds in full — its text, an input's value apart from its placeholder, its
14
+ // accessible name, the state a tab or a toggle shows. Nothing here grades a
15
+ // part; `skipped` keeps every candidate that was left out with its reason.
16
+
17
+ import type { StateIndex } from "../state-index";
18
+ import { cardsOf } from "../state-index";
19
+
20
+ type Box = [number, number, number, number];
21
+
22
+ export type PartKind =
23
+ | "number"
24
+ | "stat"
25
+ | "heading"
26
+ | "button"
27
+ | "input"
28
+ | "control"
29
+ | "field"
30
+ | "badge"
31
+ | "media"
32
+ | "logo"
33
+ | "card"
34
+ | "group"
35
+ | "text";
36
+
37
+ /** One part of a saved screen, as measured in the restored page. */
38
+ export type PartCandidate = {
39
+ /** the element id in this state's index.json ("e170"; the ref is `<state>:e170`) */
40
+ el: string;
41
+ kind: PartKind;
42
+ /** cards: "result" (holds a number) | "form" (holds inputs) | "media" (holds media) */
43
+ sub?: "result" | "form" | "media";
44
+ /** the button with the strongest fill contrast in this state */
45
+ primary?: true;
46
+ /** what it reads, for a glance (visible text, collapsed, ≤ 80 chars; an
47
+ * input's value or placeholder; an icon-only control's name) */
48
+ label: string;
49
+ /** its visible text in full, collapsed — never cut (absent in parts.json
50
+ * measured before the probe kept it) */
51
+ text?: string;
52
+ /** what the element itself holds, apart from its visible text: its
53
+ * accessible name when that is not its text (aria-label, aria-labelledby,
54
+ * title, an svg's <title>, an image's alt), an input's value and
55
+ * placeholder kept apart, a range's bounds, a checkbox's state, a
56
+ * select's options — each as the page had it */
57
+ fields?: PartFields;
58
+ /** the ARIA / form state it shows (aria-selected, aria-pressed,
59
+ * aria-checked, aria-expanded, aria-current, disabled, open) — what a tab
60
+ * or a toggle changes besides its text */
61
+ state?: Record<string, string>;
62
+ /** element ids its aria-controls names (a tab → its panel) */
63
+ controls?: string[];
64
+ /** element ids its aria-labelledby names (the heading that names a card) */
65
+ labelledBy?: string[];
66
+ /** a CSS path that finds it in state.html */
67
+ selector: string;
68
+ /** layout box, viewport CSS px */
69
+ box: Box;
70
+ /** the text's own extent (union of its text's line boxes) — text kinds
71
+ * (number, stat, heading, text, button, badge) */
72
+ ink?: Box;
73
+ /** the nearest part around it */
74
+ inside?: string;
75
+ /** its content children in order — what an assemble / stagger would act on */
76
+ parts?: string[];
77
+ /** a group's members (also on a part of another kind that passes the group test) */
78
+ members?: string[];
79
+ axis?: "row" | "column" | "grid";
80
+ /** input → its field (input + label); field → its input */
81
+ field?: string;
82
+ input?: string;
83
+ look: {
84
+ fontPx: number;
85
+ weight: number;
86
+ family: string;
87
+ fg: string;
88
+ /** its own fill (#rrggbb[aa]); "image" for a gradient / background image */
89
+ fill: string | null;
90
+ /** what is behind it: the nearest ancestor fill, else the root's, else white */
91
+ backdrop: string;
92
+ /** an ancestor between it and that fill paints an image / gradient */
93
+ backdropImage?: true;
94
+ radius: number;
95
+ shadow: boolean;
96
+ border: boolean;
97
+ };
98
+ facts: {
99
+ /** box area / viewport area */
100
+ areaShare: number;
101
+ /** its font size / the page's median text size */
102
+ fontRatio: number;
103
+ /** WCAG contrast of its text against its fill or backdrop */
104
+ contrast: number;
105
+ /** WCAG contrast of its own fill against the backdrop (1 when it has none) */
106
+ fillContrast: number;
107
+ numeric: boolean;
108
+ /** within the first screen of the page (scroll 0) */
109
+ inFirstScreen: boolean;
110
+ };
111
+ /** the crisp picture (states/assets/<sha1>.png, relative to the state folder), if taken */
112
+ picture?: string;
113
+ /** why no picture was taken */
114
+ noPicture?: string;
115
+ /** the window the picture shows, viewport CSS px, and its pixel scale */
116
+ clip?: Box;
117
+ clipScale?: number;
118
+ /** the lift() options that reproduce the picture */
119
+ lift: { around: "clear"; box: "ink" | "box"; pad: number };
120
+ };
121
+
122
+ export type PartFields = {
123
+ name?: string;
124
+ value?: string;
125
+ placeholder?: string;
126
+ min?: string;
127
+ max?: string;
128
+ step?: string;
129
+ checked?: boolean;
130
+ options?: string[];
131
+ };
132
+
133
+ /** A candidate left out, and why (nothing is dropped silently). */
134
+ export type PartSkipped = {
135
+ el: string;
136
+ kind: PartKind;
137
+ why: string;
138
+ label?: string;
139
+ box?: Box;
140
+ };
141
+
142
+ /** `states/<id>/parts.json` — version 1. */
143
+ export type PartsFile = {
144
+ version: 1;
145
+ state: string;
146
+ viewport: { w: number; h: number };
147
+ scroll: { x: number; y: number };
148
+ /** median font size over the page's visible text, weighted by characters */
149
+ medianTextPx: number;
150
+ parts: PartCandidate[];
151
+ skipped: PartSkipped[];
152
+ /** measured: time in the page, and taking the pictures */
153
+ ms: { measure: number; pictures?: number };
154
+ };
155
+
156
+ /** What the page script takes. */
157
+ export type ComponentProbeInput = {
158
+ /** element ids that pass `cardsOf` (states-list's card test, from index.json) */
159
+ cards: string[];
160
+ /** the size floor, a fraction of the viewport (default 0.0005) */
161
+ minArea?: number;
162
+ };
163
+
164
+ /** What the page script returns (JSON string): PartsFile without the
165
+ * fields only the caller knows. */
166
+ export type ComponentProbeResult =
167
+ | (Omit<PartsFile, "version" | "state" | "ms"> & { ms: number })
168
+ | { error: string };
169
+
170
+ /**
171
+ * A function expression: `(${COMPONENT_PROBE_JS})(input)` returns a JSON
172
+ * string (ComponentProbeResult). Reads the page only, except that it may
173
+ * set nothing at all — the pictures are taken separately.
174
+ */
175
+ export const COMPONENT_PROBE_JS = String.raw`function (input) {
176
+ try {
177
+ var t0 = performance.now();
178
+ var vw = innerWidth, vh = innerHeight, VA = vw * vh;
179
+ var minArea = input.minArea != null ? input.minArea : 0.0005;
180
+ var cardSet = {};
181
+ (input.cards || []).forEach(function (id) { cardSet[id] = 1; });
182
+ var nodes = Array.prototype.slice.call(document.querySelectorAll("[data-ot-id]"));
183
+ var byId = {};
184
+ nodes.forEach(function (el) { byId[el.getAttribute("data-ot-id")] = el; });
185
+ var idOf = function (el) { return el.getAttribute("data-ot-id"); };
186
+ var collapse = function (s) { return (s || "").replace(/\s+/g, " ").trim(); };
187
+ var cut = function (s, n) { return s.length > n ? s.slice(0, n - 1) + "…" : s; };
188
+ var R = function (v) { return Math.round(v); };
189
+ var rectBox = function (r) { return [R(r.left), R(r.top), R(r.width), R(r.height)]; };
190
+ var area = function (b) { return Math.max(0, b[2]) * Math.max(0, b[3]); };
191
+ var near = function (a, b, t) { return Math.abs(a - b) <= t; };
192
+ var sameBox = function (a, b) { return a.every(function (v, i) { return near(v, b[i], 2); }); };
193
+ var indexedUp = function (n) {
194
+ while (n && !(n.nodeType === 1 && n.hasAttribute && n.hasAttribute("data-ot-id"))) n = n.parentNode || n.host;
195
+ return n || null;
196
+ };
197
+ var indexedParent = function (el) { return el.parentElement ? indexedUp(el.parentElement) : null; };
198
+
199
+ // --- colours (any CSS colour → sRGB through a 1×1 canvas) ---------------
200
+ var cv = document.createElement("canvas"); cv.width = 1; cv.height = 1;
201
+ var cx = cv.getContext("2d", { willReadFrequently: true });
202
+ var colourCache = {};
203
+ var rgba = function (s) {
204
+ if (!s || s === "transparent" || s === "rgba(0, 0, 0, 0)") return [0, 0, 0, 0];
205
+ if (colourCache[s]) return colourCache[s];
206
+ cx.clearRect(0, 0, 1, 1); cx.fillStyle = "#000"; cx.fillStyle = s; cx.fillRect(0, 0, 1, 1);
207
+ var d = cx.getImageData(0, 0, 1, 1).data;
208
+ var c = [d[0], d[1], d[2], d[3] / 255];
209
+ colourCache[s] = c; return c;
210
+ };
211
+ var over = function (top, under) {
212
+ var a = top[3];
213
+ return [top[0] * a + under[0] * (1 - a), top[1] * a + under[1] * (1 - a), top[2] * a + under[2] * (1 - a), 1];
214
+ };
215
+ var hex2 = function (v) { var h = R(v).toString(16); return h.length < 2 ? "0" + h : h; };
216
+ var hex = function (c) { return "#" + hex2(c[0]) + hex2(c[1]) + hex2(c[2]) + (c[3] < 0.995 ? hex2(c[3] * 255) : ""); };
217
+ var lum = function (c) {
218
+ var f = function (v) { v /= 255; return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); };
219
+ return 0.2126 * f(c[0]) + 0.7152 * f(c[1]) + 0.0722 * f(c[2]);
220
+ };
221
+ var contrast = function (a, b) { var x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
222
+
223
+ var styleCache = new Map();
224
+ var cs = function (el) { var s = styleCache.get(el); if (!s) { s = getComputedStyle(el); styleCache.set(el, s); } return s; };
225
+ var hasImage = function (s) { return s.backgroundImage && s.backgroundImage !== "none"; };
226
+ var ownFill = function (el) {
227
+ var s = cs(el), c = rgba(s.backgroundColor);
228
+ if (c[3] >= 0.1) return c;
229
+ return null;
230
+ };
231
+ var white = [255, 255, 255, 1];
232
+ var rootFill = function () {
233
+ var h = rgba(cs(document.documentElement).backgroundColor);
234
+ if (h[3] >= 0.5) return over(h, white);
235
+ var b = document.body ? rgba(cs(document.body).backgroundColor) : [0, 0, 0, 0];
236
+ if (b[3] >= 0.5) return over(b, white);
237
+ return white;
238
+ };
239
+ var ROOT = rootFill();
240
+ var backdropCache = new Map();
241
+ // what is behind el: the nearest ancestor with an opaque-enough fill
242
+ var backdropOf = function (el) {
243
+ if (backdropCache.has(el)) return backdropCache.get(el);
244
+ var image = false, n = el.parentElement, res = null;
245
+ while (n && n !== document.documentElement) {
246
+ var s = cs(n), c = rgba(s.backgroundColor);
247
+ if (c[3] >= 0.5) { res = { c: over(c, n.parentElement ? backdropOf(n).c : ROOT), image: image }; break; }
248
+ if (hasImage(s)) image = true;
249
+ n = n.parentElement;
250
+ }
251
+ if (!res) res = { c: ROOT, image: image };
252
+ backdropCache.set(el, res);
253
+ return res;
254
+ };
255
+
256
+ // --- text --------------------------------------------------------------
257
+ var ownText = function (el) { var s = ""; for (var i = 0; i < el.childNodes.length; i++) { var n = el.childNodes[i]; if (n.nodeType === 3) s += n.data; } return collapse(s); };
258
+ var textCache = new Map();
259
+ var textOf = function (el) {
260
+ if (textCache.has(el)) return textCache.get(el);
261
+ var t = el.localName === "input" || el.localName === "textarea" ? collapse(el.value || el.getAttribute("placeholder") || el.getAttribute("aria-label") || "")
262
+ : el.localName === "select" ? collapse(el.selectedOptions && el.selectedOptions[0] ? el.selectedOptions[0].textContent : "")
263
+ : collapse(el.innerText != null ? el.innerText : el.textContent);
264
+ textCache.set(el, t); return t;
265
+ };
266
+ // its accessible name, as far as the page states one: aria-label, the
267
+ // text aria-labelledby points at, title, an svg's own <title>, an
268
+ // image's alt — what an icon-only button is called
269
+ var nameOf = function (el) {
270
+ var n = el.getAttribute("aria-label");
271
+ if (!n) {
272
+ var lb = el.getAttribute("aria-labelledby");
273
+ if (lb) n = lb.split(/\s+/).map(function (id) { var x = document.getElementById(id); return x ? x.textContent : ""; }).join(" ");
274
+ }
275
+ if (!collapse(n)) n = el.getAttribute("title");
276
+ if (!collapse(n)) {
277
+ var tt = el.localName === "svg" ? el.querySelector(":scope > title") : el.querySelector("svg > title");
278
+ n = tt ? tt.textContent : "";
279
+ }
280
+ if (!collapse(n)) {
281
+ var im = el.localName === "img" ? el : el.querySelector("img[alt]");
282
+ n = im ? im.getAttribute("alt") : "";
283
+ }
284
+ return collapse(n || "");
285
+ };
286
+ var visibleText = function (n) {
287
+ var p = n.parentElement;
288
+ return !!p && cs(p).visibility === "visible" && (typeof p.checkVisibility !== "function" || p.checkVisibility());
289
+ };
290
+ // the union of the line boxes of el's text — the text's real extent
291
+ var inkOf = function (el) {
292
+ var w = document.createTreeWalker(el, NodeFilter.SHOW_TEXT), n, x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
293
+ var range = document.createRange();
294
+ while ((n = w.nextNode())) {
295
+ if (!n.data.trim() || !visibleText(n)) continue;
296
+ range.selectNodeContents(n);
297
+ var rs = range.getClientRects();
298
+ for (var i = 0; i < rs.length; i++) {
299
+ var r = rs[i]; if (r.width < 0.5 || r.height < 0.5) continue;
300
+ x0 = Math.min(x0, r.left); y0 = Math.min(y0, r.top); x1 = Math.max(x1, r.right); y1 = Math.max(y1, r.bottom);
301
+ }
302
+ }
303
+ if (x0 === Infinity) return null;
304
+ var a = Math.floor(x0), b = Math.floor(y0);
305
+ return [a, b, Math.ceil(x1) - a, Math.ceil(y1) - b];
306
+ };
307
+
308
+ // --- the page's statistics -----------------------------------------------
309
+ var info = new Map();
310
+ var sizes = [];
311
+ nodes.forEach(function (el) {
312
+ var r = el.getBoundingClientRect();
313
+ var s = cs(el);
314
+ var own = ownText(el);
315
+ var it = { el: el, id: idOf(el), box: rectBox(r), own: own, font: parseFloat(s.fontSize) || 0, weight: parseInt(s.fontWeight, 10) || 400 };
316
+ info.set(el, it);
317
+ if (own && s.visibility === "visible" && r.bottom > 0 && r.top < vh && r.right > 0 && r.left < vw) sizes.push([it.font, own.length]);
318
+ });
319
+ sizes.sort(function (a, b) { return a[0] - b[0]; });
320
+ var total = sizes.reduce(function (s, x) { return s + x[1]; }, 0), acc = 0, median = 16;
321
+ for (var i = 0; i < sizes.length; i++) { acc += sizes[i][1]; if (acc >= total / 2) { median = sizes[i][0]; break; } }
322
+ median = median || 16;
323
+
324
+ // --- tests ----------------------------------------------------------------
325
+ var CURRENCY = /(NT\$|US\$|HK\$|[$€£¥₩])/;
326
+ var numericText = function (t) {
327
+ if (!t || t.length > 24 || !/\d/.test(t)) return false;
328
+ var ns = t.replace(/\s+/g, "");
329
+ var digits = (ns.match(/\d/g) || []).length;
330
+ return digits / ns.length >= 0.3 || CURRENCY.test(t);
331
+ };
332
+ var isBlock = function (s) { return /^(block|flex|grid|list-item|table|flow-root)$/.test(s.display); };
333
+ var interactiveTag = function (el) { var t = el.localName; return t === "button" || t === "a" || t === "input" || t === "select" || t === "textarea" || t === "summary"; };
334
+ var roleOf = function (el) { return (el.getAttribute("role") || "").trim().split(/\s+/)[0]; };
335
+ var isButtonEl = function (el) {
336
+ var t = el.localName, role = roleOf(el);
337
+ if (t === "button" || role === "button") return true;
338
+ if (t === "input") { var ty = (el.getAttribute("type") || "").toLowerCase(); return ty === "button" || ty === "submit" || ty === "reset"; }
339
+ return false;
340
+ };
341
+ var CONTROL_TYPES = { checkbox: 1, radio: 1 };
342
+ var INPUT_ROLES = { textbox: 1, searchbox: 1, combobox: 1, slider: 1, spinbutton: 1 };
343
+ var CONTROL_ROLES = { checkbox: 1, radio: 1, "switch": 1 };
344
+ var inputKind = function (el) {
345
+ var t = el.localName, role = roleOf(el);
346
+ if (t === "input") {
347
+ var ty = (el.getAttribute("type") || "text").toLowerCase();
348
+ if (ty === "hidden" || ty === "button" || ty === "submit" || ty === "reset" || ty === "image") return null;
349
+ return CONTROL_TYPES[ty] ? "control" : "input";
350
+ }
351
+ if (t === "textarea" || t === "select") return "input";
352
+ if (CONTROL_ROLES[role]) return "control";
353
+ if (INPUT_ROLES[role]) return "input";
354
+ var ce = el.getAttribute("contenteditable");
355
+ if (ce != null && ce !== "false" && !(el.parentElement && el.parentElement.closest("[contenteditable]:not([contenteditable=false])"))) return "input";
356
+ return null;
357
+ };
358
+ var MEDIA = { img: 1, svg: 1, picture: 1, canvas: 1, video: 1 };
359
+ var looks = function (el) {
360
+ var s = cs(el), fill = ownFill(el), image = hasImage(s), bd = backdropOf(el);
361
+ var fillC = fill ? contrast(over(fill, bd.c), bd.c) : 1;
362
+ var bw = ["Top", "Right", "Bottom", "Left"].some(function (k) {
363
+ return parseFloat(s["border" + k + "Width"]) >= 1 && s["border" + k + "Style"] !== "none" && rgba(s["border" + k + "Color"])[3] >= 0.1;
364
+ });
365
+ return { s: s, fill: fill, image: image, bd: bd, fillC: fillC, border: bw, shadow: !!s.boxShadow && s.boxShadow !== "none", radius: parseFloat(s.borderTopLeftRadius) || 0 };
366
+ };
367
+ var separate = function (L) { return L.fillC >= 1.05 || L.image || L.border || L.shadow; };
368
+ var labelledOrMedia = function (el) { return !!textOf(el) || !!el.querySelector("img,svg,picture,canvas,video") || !!MEDIA[el.localName]; };
369
+ var indexedChildren = function (el) {
370
+ var out = [];
371
+ var walk = function (n) {
372
+ for (var i = 0; i < n.children.length; i++) {
373
+ var c = n.children[i];
374
+ if (c.hasAttribute("data-ot-id")) out.push(c); else walk(c);
375
+ }
376
+ };
377
+ walk(el);
378
+ return out;
379
+ };
380
+ // the content children an assemble acts on: through same-box wrappers
381
+ var contentChildren = function (el) {
382
+ var n = el, guard = 0, kids = indexedChildren(n);
383
+ while (kids.length === 1 && guard++ < 6 && sameBox(info.get(kids[0]).box, info.get(n).box)) { n = kids[0]; kids = indexedChildren(n); }
384
+ return kids.filter(labelledOrMedia);
385
+ };
386
+ var groupTest = function (el) {
387
+ var kids = indexedChildren(el);
388
+ var byTag = {};
389
+ kids.forEach(function (k) { (byTag[k.localName] = byTag[k.localName] || []).push(k); });
390
+ var best = null;
391
+ Object.keys(byTag).forEach(function (tag) {
392
+ var list = byTag[tag];
393
+ if (list.length < 3) return;
394
+ var sig = list.map(function (k) { return indexedChildren(k).length; });
395
+ var common = sig.slice().sort(function (a, b) { return a - b; })[Math.floor(sig.length / 2)];
396
+ var same = list.filter(function (k, i) { return sig[i] === common; });
397
+ if (same.length < 3) return;
398
+ var ws = same.map(function (k) { return info.get(k).box[2]; }).sort(function (a, b) { return a - b; });
399
+ var hs = same.map(function (k) { return info.get(k).box[3]; }).sort(function (a, b) { return a - b; });
400
+ var mw = ws[Math.floor(ws.length / 2)], mh = hs[Math.floor(hs.length / 2)];
401
+ if (!(mw > 0 && mh > 0)) return;
402
+ var m = same.filter(function (k) { var b = info.get(k).box; return Math.abs(b[2] - mw) <= 0.15 * mw && Math.abs(b[3] - mh) <= 0.15 * mh && labelledOrMedia(k); });
403
+ if (m.length < 3) return;
404
+ var tops = {}, lefts = {}, tol = function (v, unit) { return Math.round(v / Math.max(4, unit * 0.1)); };
405
+ m.forEach(function (k) { var b = info.get(k).box; tops[tol(b[1], mh)] = 1; lefts[tol(b[0], mw)] = 1; });
406
+ var nt = Object.keys(tops).length, nl = Object.keys(lefts).length;
407
+ var axis = nt === 1 ? "row" : nl === 1 ? "column" : nt * nl >= m.length && nt < m.length && nl < m.length ? "grid" : null;
408
+ if (!axis) return;
409
+ if (!best || m.length > best.members.length) best = { members: m, axis: axis };
410
+ });
411
+ return best;
412
+ };
413
+
414
+ var textLeaves = function (el) {
415
+ var out = [];
416
+ if (ownText(el)) out.push(el);
417
+ el.querySelectorAll("[data-ot-id]").forEach(function (d) { if (ownText(d) && cs(d).visibility === "visible") out.push(d); });
418
+ return out;
419
+ };
420
+ var verdicts = new Map(); // el → { kind, ... }
421
+ var skipped = [];
422
+ // a value cell: inside a table cell, a <dd>, an <output> / <data>, or the
423
+ // value of a label/value pair — its parent holds 1–3 other short text
424
+ // leaves (≤ 16 characters), each set smaller than it
425
+ var inValueCell = function (el) { return !!el.closest("dd,td,output,data,[role=cell],[role=gridcell],[role=definition]"); };
426
+ var pairValue = function (el) {
427
+ var p = indexedParent(el);
428
+ if (!p) return false;
429
+ var f = info.get(el).font;
430
+ var others = textLeaves(p).filter(function (l) { return l !== el && !el.contains(l); });
431
+ return others.length >= 1 && others.length <= 3 && others.every(function (l) {
432
+ return (l === p ? ownText(l) : textOf(l)).length <= 16 && info.get(l).font < f;
433
+ });
434
+ };
435
+ var valueCell = function (el) { return inValueCell(el) || pairValue(el); };
436
+ // a value with a digit too long for numericText's 24 characters
437
+ // ("US$16 起 / 月(含稅)") — a number when it sits in a value cell
438
+ var valueText = function (t) { return !!t && t.length <= 40 && /\d/.test(t); };
439
+ // 1. numbers — text from one leaf (its own, or one element inside it);
440
+ // innermost wins; a control whose label is a number is a control
441
+ var numCand = [];
442
+ nodes.forEach(function (el) {
443
+ if (interactiveTag(el) || isButtonEl(el) || inputKind(el)) return;
444
+ if (el.querySelector("input,select,textarea,button") || (el.localName === "label" && el.control)) return;
445
+ // a number on a button or a chip-label is that control's text
446
+ var host = el.parentElement && el.parentElement.closest("button,[role=button],label");
447
+ if (host && (host.localName !== "label" || host.control)) return;
448
+ var leaves = textLeaves(el);
449
+ // its own digits plus a unit in a child of its own ("18.5<small>個月</small>")
450
+ var unit = leaves.length === 2 && leaves[0] === el && /\d/.test(ownText(el)) &&
451
+ indexedChildren(leaves[1]).length === 0 && !/\d/.test(textOf(leaves[1])) && textOf(leaves[1]).length <= 4;
452
+ if (leaves.length !== 1 && !unit) return;
453
+ var t = textOf(el), it = info.get(el);
454
+ if (!numericText(t) && !(valueText(t) && valueCell(el))) return;
455
+ if (it.font >= 1.25 * median || it.weight >= 600) numCand.push(el);
456
+ else skipped.push({ el: it.id, kind: "number", why: "a number at body size and weight (" + R(it.font) + " px, " + it.weight + ")", label: cut(t, 80), box: it.box });
457
+ });
458
+ var numbers = numCand.filter(function (el) { return !numCand.some(function (o) { return o !== el && el.contains(o); }); });
459
+ numbers.forEach(function (el) { verdicts.set(el, { kind: "number" }); });
460
+ var isNumber = function (el) { var v = verdicts.get(el); return v && v.kind === "number"; };
461
+ // a value cell without a digit ("不收", "Unlimited"), set large or bold,
462
+ // one leaf, ≤ 24 characters: the value of the stat around it — not a
463
+ // part of its own, and never a heading
464
+ var cellValues = nodes.filter(function (el) {
465
+ if (verdicts.has(el) || interactiveTag(el) || isButtonEl(el) || inputKind(el)) return false;
466
+ if (/^h[1-6]$/.test(el.localName) || roleOf(el) === "heading") return false;
467
+ var it = info.get(el), t = textOf(el);
468
+ if (!t || t.length > 24 || textLeaves(el).length !== 1 || !inValueCell(el)) return false;
469
+ return (it.font >= 1.25 * median || it.weight >= 600) && pairValue(el);
470
+ });
471
+ var cellSet = new Set(cellValues);
472
+ // 2. stats: one number (the largest, when there are several) and 1–3
473
+ // short labels; the innermost such holder
474
+ var statCand = [];
475
+ nodes.forEach(function (el) {
476
+ if (verdicts.has(el) || interactiveTag(el) || isButtonEl(el)) return;
477
+ var it = info.get(el);
478
+ if (area(it.box) > 0.03 * VA) return;
479
+ var nums = numbers.concat(cellValues).filter(function (n) { return n !== el && el.contains(n); });
480
+ if (!nums.length) return;
481
+ nums.sort(function (a, b) { return info.get(b).font - info.get(a).font; });
482
+ if (nums.length > 1 && info.get(nums[1]).font >= info.get(nums[0]).font) return;
483
+ var num = nums[0];
484
+ var leaves = textLeaves(el);
485
+ if (leaves.length > 4) return;
486
+ var labels = leaves.filter(function (l) { return l !== num && !num.contains(l); });
487
+ if (labels.length < 1 || labels.length > 3) return;
488
+ var ok = labels.every(function (l) { return (l === el ? ownText(l) : textOf(l)).length <= 16; });
489
+ if (ok) statCand.push(el);
490
+ });
491
+ statCand.filter(function (el) { return !statCand.some(function (o) { return o !== el && el.contains(o); }); })
492
+ .forEach(function (el) { verdicts.set(el, { kind: "stat" }); });
493
+ // 3–9. one kind per element, in order
494
+ var logoSeen = new Set();
495
+ var title = collapse(document.title).toLowerCase();
496
+ nodes.forEach(function (el) {
497
+ if (verdicts.has(el)) return;
498
+ var it = info.get(el), t = el.localName, s = cs(el), role = roleOf(el), text = textOf(el);
499
+ var share = area(it.box) / VA;
500
+ var lvl = parseInt(el.getAttribute("aria-level") || "2", 10);
501
+ if (text && (t === "h1" || t === "h2" || t === "h3" || (role === "heading" && lvl <= 3) ||
502
+ (it.font >= 1.6 * median && text.length <= 90 && isBlock(s) && !cellSet.has(el) &&
503
+ !inValueCell(el) && !(valueText(text) && pairValue(el))))) { verdicts.set(el, { kind: "heading" }); return; }
504
+ if (isButtonEl(el) && it.box[3] >= 20 && it.box[3] <= 140) { verdicts.set(el, { kind: "button" }); return; }
505
+ if (t === "a" && text && it.box[3] >= 20 && it.box[3] <= 140) {
506
+ var L = looks(el);
507
+ var pad = Math.min(parseFloat(s.paddingLeft) || 0, parseFloat(s.paddingRight) || 0);
508
+ if ((L.fillC >= 1.3 || L.border || L.image) && pad >= 4) { verdicts.set(el, { kind: "button" }); return; }
509
+ }
510
+ var ik = inputKind(el);
511
+ if (ik) { verdicts.set(el, { kind: ik }); return; }
512
+ if (MEDIA[t]) {
513
+ var bar = el.closest("header, nav, [role=banner], [role=navigation]");
514
+ var nm = collapse(el.getAttribute("alt") || el.getAttribute("aria-label") || "").toLowerCase();
515
+ var named = nm.length >= 2 && title.indexOf(nm) >= 0;
516
+ if ((bar && !logoSeen.has(bar) || named) && share < 0.03 && it.box[3] >= 16) {
517
+ if (bar) logoSeen.add(bar);
518
+ verdicts.set(el, { kind: "logo" }); return;
519
+ }
520
+ if (share >= 0.015) { verdicts.set(el, { kind: "media" }); return; }
521
+ return;
522
+ }
523
+ if (cardSet[it.id] && share <= 0.4 && separate(looks(el))) {
524
+ if (it.box[2] < 0.9 * vw) { verdicts.set(el, { kind: "card" }); return; }
525
+ skipped.push({ el: it.id, kind: "card", why: "spans the screen's width (a bar)", label: cut(text, 80), box: it.box });
526
+ return;
527
+ }
528
+ // a short label on its own fill or border (a "VS" disc, a status pill)
529
+ if (text && text.length <= 16 && !interactiveTag(el) && share <= 0.01 && indexedChildren(el).length === 0) {
530
+ var Lb = looks(el);
531
+ if (Lb.fillC >= 1.3 || Lb.border || Lb.image) { verdicts.set(el, { kind: "badge" }); return; }
532
+ }
533
+ var g = groupTest(el);
534
+ if (g) { verdicts.set(el, { kind: "group", members: g.members, axis: g.axis }); return; }
535
+ if (text.length >= 40 && text.length <= 600 && it.font >= 1.2 * median && isBlock(s) &&
536
+ !Array.prototype.some.call(el.querySelectorAll("[data-ot-id]"), function (d) { return isBlock(cs(d)) && ownText(d); })) {
537
+ verdicts.set(el, { kind: "text" });
538
+ }
539
+ });
540
+ // a visually hidden checkbox / radio (a 1×1 input behind a styled
541
+ // label): its label is what is on screen — the label stands for it
542
+ verdicts.forEach(function (v, el) {
543
+ if (v.kind !== "input" && v.kind !== "control") return;
544
+ if (area(info.get(el).box) >= 16) return;
545
+ var lab = el.labels && el.labels[0] || el.closest("label");
546
+ var stand = lab && indexedUp(lab);
547
+ if (!stand || stand === el || verdicts.has(stand) || area(info.get(stand).box) < 16) return;
548
+ verdicts.delete(el);
549
+ verdicts.set(stand, { kind: v.kind, input: el });
550
+ skipped.push({ el: idOf(el), kind: v.kind, why: "visually hidden; its label " + idOf(stand) + " stands for it", box: info.get(el).box });
551
+ });
552
+ // fields: the input with its label, at most 4× the input's area
553
+ verdicts.forEach(function (v, el) {
554
+ if (v.kind !== "input" && v.kind !== "control") return;
555
+ if (v.input) return;
556
+ var a = area(info.get(el).box) || 1, n = indexedParent(el);
557
+ while (n && area(info.get(n).box) <= 4 * a) {
558
+ var labelled = textLeaves(n).some(function (l) { return l !== el && !el.contains(l); });
559
+ if (labelled) { if (!verdicts.has(n)) verdicts.set(n, { kind: "field", input: el }); v.field = n; break; }
560
+ n = indexedParent(n);
561
+ }
562
+ });
563
+
564
+ // --- exclusions ---------------------------------------------------------
565
+ var COOKIE = /cookie|consent|gdpr|privacy (settings|preferences)|we use cookies/i;
566
+ var fixedRoot = function (el) {
567
+ var n = el, found = null;
568
+ while (n && n !== document.body && n !== document.documentElement) { var p = cs(n).position; if (p === "fixed" || p === "sticky") found = n; n = n.parentElement; }
569
+ return found;
570
+ };
571
+ var hitId = function (x, y, el) {
572
+ var h = document.elementFromPoint(x, y);
573
+ if (!h) return { ok: false, by: null };
574
+ if (h === el || el.contains(h)) return { ok: true };
575
+ // a part inside a shadow host reports the host
576
+ var up = indexedUp(h);
577
+ return { ok: false, by: up ? idOf(up) : h.localName, fixed: !!(up && fixedRoot(up)) };
578
+ };
579
+ var why = function (el, v) {
580
+ var it = info.get(el), b = it.box, share = area(b) / VA;
581
+ if (share < minArea) return "smaller than " + (minArea * 100).toFixed(2) + "% of the screen";
582
+ var vx = Math.max(0, Math.min(b[0] + b[2], vw) - Math.max(b[0], 0)), vy = Math.max(0, Math.min(b[1] + b[3], vh) - Math.max(b[1], 0));
583
+ if (vx * vy < 0.5 * area(b)) return "less than half of it on screen";
584
+ if (el.closest("[aria-hidden=true]") && (v.kind === "media" || v.kind === "logo" || !textOf(el))) return "aria-hidden (decoration)";
585
+ var fr = fixedRoot(el);
586
+ if (fr && COOKIE.test(textOf(fr).slice(0, 400))) return "inside a cookie / consent banner";
587
+ if (v.kind !== "button" && v.kind !== "logo" && el.closest("nav, footer, [role=navigation], [role=contentinfo]")) return "inside nav / footer";
588
+ var cy = b[1] + b[3] / 2, pts = [[b[0] + b[2] / 2, cy], [b[0] + b[2] * 0.25, cy], [b[0] + b[2] * 0.75, cy]];
589
+ var tried = 0, hits = 0, by = null;
590
+ pts.forEach(function (p) {
591
+ if (p[0] < 0 || p[1] < 0 || p[0] >= vw || p[1] >= vh) return;
592
+ tried++;
593
+ var r = hitId(p[0], p[1], el);
594
+ if (r.ok) hits++; else if (!by) by = r;
595
+ });
596
+ if (tried && hits < Math.min(2, tried)) return "covered (" + (by && by.fixed ? "fixed element" : "element") + " at its centre: " + (by && by.by || "?") + ")";
597
+ return null;
598
+ };
599
+ var kept = [];
600
+ verdicts.forEach(function (v, el) {
601
+ var w = why(el, v);
602
+ var it = info.get(el);
603
+ if (w) skipped.push({ el: it.id, kind: v.kind, why: w, label: cut(textOf(el), 80), box: it.box });
604
+ else kept.push(el);
605
+ });
606
+ // a candidate with the box of a kept one of the same kind inside it:
607
+ // outermost kept for blocks, innermost for the rest
608
+ var OUTER = { card: 1, group: 1, stat: 1, field: 1, media: 1 };
609
+ var keptSet = new Set(kept);
610
+ kept.slice().forEach(function (el) {
611
+ if (!keptSet.has(el)) return;
612
+ var v = verdicts.get(el), b = info.get(el).box;
613
+ kept.forEach(function (o) {
614
+ if (o === el || !keptSet.has(o) || !keptSet.has(el)) return;
615
+ var vo = verdicts.get(o);
616
+ if (vo.kind !== v.kind || !el.contains(o) || !sameBox(b, info.get(o).box)) return;
617
+ var drop = OUTER[v.kind] ? o : el, keep = drop === o ? el : o;
618
+ keptSet.delete(drop);
619
+ skipped.push({ el: idOf(drop), kind: v.kind, why: "same box as " + idOf(keep) + " (kept: the " + (OUTER[v.kind] ? "outermost" : "innermost") + ")", label: cut(textOf(drop), 80), box: info.get(drop).box });
620
+ });
621
+ });
622
+ kept = kept.filter(function (el) { return keptSet.has(el); });
623
+ kept.sort(function (a, b) { var p = a.compareDocumentPosition(b); return p & 4 ? -1 : p & 2 ? 1 : 0; });
624
+
625
+ // --- the entries ----------------------------------------------------------
626
+ var cssIdent = /^-?[A-Za-z_][A-Za-z0-9_-]*$/;
627
+ var selectorOf = function (el) {
628
+ var steps = [], n = el;
629
+ while (n && n !== document.documentElement) {
630
+ if (n.id && cssIdent.test(n.id) && document.querySelectorAll("#" + n.id).length === 1) { steps.unshift("#" + n.id); break; }
631
+ var tag = n.localName, par = n.parentElement;
632
+ var step = tag;
633
+ var cls = Array.prototype.find.call(n.classList || [], function (c) { return cssIdent.test(c) && c.length <= 24 && !/\d{3,}|^(css|sc|jsx|svelte)-/.test(c); });
634
+ if (cls) step += "." + cls;
635
+ if (par) {
636
+ var same = Array.prototype.filter.call(par.children, function (c) { return c.localName === tag; });
637
+ if (same.length > 1) step += ":nth-of-type(" + (same.indexOf(n) + 1) + ")";
638
+ }
639
+ steps.unshift(step);
640
+ if (tag === "body") break;
641
+ n = par;
642
+ }
643
+ var sel = steps.join(" > ");
644
+ try { if (document.querySelector(sel) === el) return sel; } catch (e) {}
645
+ return "[data-ot-id=" + idOf(el) + "]";
646
+ };
647
+ var TEXTY = { number: 1, heading: 1, text: 1, button: 1, badge: 1, stat: 1 };
648
+ // what an input holds, apart from what it shows: the value and the
649
+ // placeholder kept apart, a range's bounds, a checkbox's state
650
+ var inputFields = function (el, f) {
651
+ var t = el.localName;
652
+ if (t === "input" || t === "textarea") {
653
+ var ty = (el.getAttribute("type") || "text").toLowerCase();
654
+ if (ty === "checkbox" || ty === "radio") f.checked = !!el.checked;
655
+ else {
656
+ f.value = el.value;
657
+ var ph = el.getAttribute("placeholder");
658
+ if (ph) f.placeholder = collapse(ph);
659
+ ["min", "max", "step"].forEach(function (k) { var a = el.getAttribute(k); if (a != null && a !== "") f[k] = a; });
660
+ }
661
+ } else if (t === "select") {
662
+ var o = el.selectedOptions && el.selectedOptions[0];
663
+ f.value = o ? collapse(o.textContent) : "";
664
+ f.options = Array.prototype.map.call(el.options, function (x) { return collapse(x.textContent); });
665
+ } else {
666
+ var now = el.getAttribute("aria-valuenow");
667
+ if (now != null) {
668
+ f.value = el.getAttribute("aria-valuetext") || now;
669
+ var mn = el.getAttribute("aria-valuemin"), mx = el.getAttribute("aria-valuemax");
670
+ if (mn != null) f.min = mn;
671
+ if (mx != null) f.max = mx;
672
+ } else if (el.isContentEditable) f.value = collapse(el.innerText);
673
+ var ac = el.getAttribute("aria-checked");
674
+ if (ac != null) f.checked = ac === "true";
675
+ }
676
+ };
677
+ var STATE_ATTRS = ["aria-selected", "aria-pressed", "aria-checked", "aria-expanded", "aria-current"];
678
+ var stateOf = function (el) {
679
+ var st = {}, any = false;
680
+ STATE_ATTRS.forEach(function (a) { var x = el.getAttribute(a); if (x != null && x !== "false") { st[a.slice(5)] = x; any = true; } });
681
+ if (el.disabled || el.getAttribute("aria-disabled") === "true") { st.disabled = "true"; any = true; }
682
+ if (el.localName === "details" || el.localName === "dialog") { st.open = el.open ? "true" : "false"; any = true; }
683
+ return any ? st : null;
684
+ };
685
+ var sy = scrollY;
686
+ var parts = kept.map(function (el) {
687
+ var v = verdicts.get(el), it = info.get(el), L = looks(el), s = L.s;
688
+ var text = textOf(el);
689
+ var shown = el.localName === "input" || el.localName === "textarea" || el.localName === "select" ? text : collapse(el.innerText != null ? el.innerText : el.textContent);
690
+ var name = nameOf(el);
691
+ var ink = text && TEXTY[v.kind] ? inkOf(el) : null;
692
+ var fg = rgba(s.color), under = L.fill ? over(L.fill, L.bd.c) : L.bd.c;
693
+ var e = {
694
+ el: it.id, kind: v.kind, label: cut(text || name, 80), text: shown, selector: selectorOf(el), box: it.box,
695
+ look: {
696
+ fontPx: Math.round(it.font * 10) / 10, weight: it.weight,
697
+ family: (s.fontFamily || "").split(",")[0].replace(/["']/g, "").trim(),
698
+ fg: hex(fg), fill: L.fill ? hex(L.fill) : L.image ? "image" : null, backdrop: hex(L.bd.c),
699
+ radius: Math.round(L.radius), shadow: L.shadow, border: L.border
700
+ },
701
+ facts: {
702
+ areaShare: Math.round(area(it.box) / VA * 1e5) / 1e5,
703
+ fontRatio: Math.round(it.font / median * 100) / 100,
704
+ contrast: Math.round(contrast(over(fg, under), under) * 10) / 10,
705
+ fillContrast: Math.round(L.fillC * 100) / 100,
706
+ numeric: numericText(text),
707
+ inFirstScreen: it.box[1] + sy < vh
708
+ },
709
+ // a fill, border, shadow or image is part of how it looks: the
710
+ // picture keeps it (box); bare text is cut to its ink
711
+ lift: { around: "clear", box: ink && !separate(L) ? "ink" : "box", pad: 8 }
712
+ };
713
+ if (L.bd.image) e.look.backdropImage = true;
714
+ var fields = {};
715
+ if (name && name !== shown) fields.name = name;
716
+ if (v.kind === "input" || v.kind === "control") inputFields(v.input || el, fields);
717
+ if (Object.keys(fields).length) e.fields = fields;
718
+ var st = stateOf(v.input && v.kind !== "field" ? v.input : el);
719
+ if (st) e.state = st;
720
+ var ctl = (el.getAttribute("aria-controls") || "").split(/\s+/).map(function (id) {
721
+ var x = id && document.getElementById(id); var up = x ? indexedUp(x) : null; return up ? idOf(up) : null;
722
+ }).filter(Boolean);
723
+ if (ctl.length) e.controls = ctl;
724
+ var lby = (el.getAttribute("aria-labelledby") || "").split(/\s+/).map(function (id) {
725
+ var x = id && document.getElementById(id); var up = x ? indexedUp(x) : null; return up && up !== el ? idOf(up) : null;
726
+ }).filter(Boolean);
727
+ if (lby.length) e.labelledBy = lby;
728
+ if (ink) e.ink = ink;
729
+ if (v.members) { e.members = v.members.map(idOf); e.axis = v.axis; }
730
+ if (v.field) e.field = idOf(v.field);
731
+ if (v.input) e.input = idOf(v.input);
732
+ if (v.kind === "card" || v.kind === "stat" || v.kind === "group" || v.kind === "field") {
733
+ var cc = v.members || contentChildren(el);
734
+ if (cc.length) e.parts = cc.map(idOf);
735
+ }
736
+ return e;
737
+ });
738
+ var keptById = {};
739
+ parts.forEach(function (p, i) { keptById[p.el] = { p: p, el: kept[i] }; });
740
+ parts.forEach(function (p, i) {
741
+ var n = indexedParent(kept[i]);
742
+ while (n) { var k = keptById[idOf(n)]; if (k) { p.inside = k.p.el; break; } n = indexedParent(n); }
743
+ });
744
+ // card subtypes, from what is inside
745
+ parts.forEach(function (p, i) {
746
+ if (p.kind !== "card") return;
747
+ var el = kept[i];
748
+ var holds = function (kinds) { return parts.some(function (q, j) { return j !== i && kinds[q.kind] && el.contains(kept[j]); }); };
749
+ if (holds({ number: 1, stat: 1 })) p.sub = "result";
750
+ else if (holds({ input: 1, control: 1, field: 1 }) || el.querySelector("input:not([type=hidden]),textarea,select")) p.sub = "form";
751
+ else if (holds({ media: 1 })) p.sub = "media";
752
+ });
753
+ var best = null;
754
+ parts.forEach(function (p) { if (p.kind === "button" && (!best || p.facts.fillContrast > best.facts.fillContrast)) best = p; });
755
+ if (best && best.facts.fillContrast > 1) best.primary = true;
756
+ return JSON.stringify({
757
+ viewport: { w: vw, h: vh }, scroll: { x: R(scrollX), y: R(scrollY) }, medianTextPx: median,
758
+ parts: parts, skipped: skipped, ms: Math.round(performance.now() - t0)
759
+ });
760
+ } catch (e) {
761
+ return JSON.stringify({ error: String(e && e.stack || e) });
762
+ }
763
+ }`;
764
+
765
+ /** The largest card the probe considers, a fraction of the screen (the page
766
+ * script also requires a fill, border or shadow; `open-take states` keeps
767
+ * cardsOf's 20 %). */
768
+ const CARD_MAX_SHARE = 0.4;
769
+
770
+ /** The expression to evaluate in a restored state.html: runs the probe on
771
+ * this state's index (its card test runs here, in Node, on index.json). */
772
+ export function componentProbeExpression(
773
+ index: StateIndex,
774
+ opts: { minArea?: number } = {},
775
+ ): string {
776
+ const input: ComponentProbeInput = {
777
+ cards: [...cardsOf(index, undefined, { maxFrac: CARD_MAX_SHARE })],
778
+ ...(opts.minArea != null ? { minArea: opts.minArea } : {}),
779
+ };
780
+ return `(${COMPONENT_PROBE_JS})(${JSON.stringify(input)})`;
781
+ }
782
+
783
+ /** The CSS that leaves only `[data-ot-clip]` drawn, on a see-through page —
784
+ * what lift(…, { around: "clear" }) shows (kit/media.js). */
785
+ export const CLIP_CLEAR_CSS =
786
+ "html,body{background:transparent!important}" +
787
+ "body *{visibility:hidden!important}" +
788
+ "[data-ot-clip],[data-ot-clip] *{visibility:visible!important}";
789
+
790
+ /** The window a part's picture shows: its ink (text kinds) or box, ± pad,
791
+ * inside the viewport; and the pixel scale (3×, less if that would pass
792
+ * `maxSide` px). Null when nothing of it is on screen. */
793
+ export function pictureClip(
794
+ part: Pick<PartCandidate, "box" | "ink" | "lift">,
795
+ viewport: { w: number; h: number },
796
+ opts: { scale?: number; maxSide?: number } = {},
797
+ ): { clip: Box; scale: number } | null {
798
+ const b = part.lift.box === "ink" && part.ink ? part.ink : part.box;
799
+ const pad = part.lift.pad;
800
+ const x0 = Math.max(0, Math.floor(b[0] - pad));
801
+ const y0 = Math.max(0, Math.floor(b[1] - pad));
802
+ const x1 = Math.min(viewport.w, Math.ceil(b[0] + b[2] + pad));
803
+ const y1 = Math.min(viewport.h, Math.ceil(b[1] + b[3] + pad));
804
+ if (x1 - x0 < 1 || y1 - y0 < 1) return null;
805
+ const want = opts.scale ?? 3;
806
+ const side = Math.max(x1 - x0, y1 - y0);
807
+ const scale = Math.max(1, Math.min(want, (opts.maxSide ?? 4096) / side));
808
+ return { clip: [x0, y0, x1 - x0, y1 - y0], scale: Math.round(scale * 100) / 100 };
809
+ }