@open-take/compositor 0.5.3 → 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,729 @@
1
+ // The product's parts as files: each part of a saved screen (the same set
2
+ // components.json lists) written as a standalone HTML file —
3
+ // `parts/<state>-<el>-<kind>.html` — that opens alone, at any size, in the
4
+ // product's own styles, with no page CSS.
5
+ //
6
+ // Two halves:
7
+ //
8
+ // - in the page (`PART_DOM_JS`, evaluated by the runtime in the restored
9
+ // state.html right after the component probe, before the pictures — the
10
+ // moment computed styles are live): each part's subtree rebuilt with
11
+ // every computed style that differs from what the browser would give it
12
+ // anyway inlined on its element (all inherited ones on the part itself,
13
+ // so it reads the same wherever it is put), ::before / ::after /
14
+ // ::placeholder as rules, shadow roots flattened, live input values
15
+ // written into the markup, a canvas as its picture, local SVG references
16
+ // (a gradient, a <use>d symbol) carried along. References to the saved
17
+ // screen's files are marked state-relative; nothing on the page is
18
+ // changed but a hidden frame for the browser's defaults, removed after.
19
+ // Written as `states/<id>/parts-dom.json`.
20
+ // - in Node (`writePartFiles`, beside writeComponents): each part's file,
21
+ // with the page's @font-face rules for the families it uses (the saved
22
+ // fonts in states/assets/), every reference made relative to the parts
23
+ // folder, a header saying where it came from and what it holds, and
24
+ // `parts/index.json` listing them. A part the page could not give
25
+ // (a frame from another site, too many elements) is listed as skipped
26
+ // with its reason.
27
+ //
28
+ // Measurement and copying only: which part a film uses is not said here.
29
+
30
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
31
+ import { dirname, join, relative, resolve, sep } from "node:path";
32
+ import type { ComponentEntry, ComponentSource, ComponentsFile } from "./components";
33
+
34
+ // --- in the page ----------------------------------------------------------------
35
+
36
+ /** One part as the page gave it. */
37
+ export type PartDom = {
38
+ el: string;
39
+ /** the part's own element and everything inside it, every style inlined;
40
+ * references to the saved screen's files are `otrel:<path from states/>` */
41
+ html: string;
42
+ /** rules the markup cannot carry: ::before / ::after / ::placeholder, by
43
+ * `[data-ot-p="<n>"]` */
44
+ css: string;
45
+ /** a hidden <svg> holding what the part's SVG refers to outside itself
46
+ * (a gradient, a symbol), or "" */
47
+ defs: string;
48
+ /** its natural size, CSS px (border box, untransformed) */
49
+ w: number;
50
+ h: number;
51
+ /** what it draws to the right and below, its box included, when that is
52
+ * more than its box (a heading set nowrap past its width) */
53
+ drawn?: [number, number];
54
+ /** font families its text is set in (lower case, unquoted) */
55
+ families: string[];
56
+ /** elements in it */
57
+ nodes: number;
58
+ };
59
+
60
+ /** `states/<id>/parts-dom.json` — version 1. */
61
+ export type PartDomFile = {
62
+ version: 1;
63
+ state: string;
64
+ parts: PartDom[];
65
+ skipped: { el: string; why: string }[];
66
+ /** time in the page */
67
+ ms: number;
68
+ };
69
+
70
+ /** What the page script takes. */
71
+ export type PartDomInput = {
72
+ /** element ids (data-ot-id), the component probe's parts */
73
+ els: string[];
74
+ /** most elements in one part (default 3000) */
75
+ maxNodes?: number;
76
+ /** most characters of markup per screen, all parts together (default 12 000 000) */
77
+ maxChars?: number;
78
+ };
79
+
80
+ /**
81
+ * A function expression: `(${PART_DOM_JS})(input)` returns a JSON string
82
+ * (Omit<PartDomFile, "version" | "state"> or { error }). Reads the page; the
83
+ * only thing it adds is a hidden about:blank frame (the browser's own
84
+ * defaults per tag), removed before it returns.
85
+ */
86
+ export const PART_DOM_JS = String.raw`function (input) {
87
+ var frame = null;
88
+ try {
89
+ var t0 = performance.now();
90
+ var HTML_NS = "http://www.w3.org/1999/xhtml", SVG_NS = "http://www.w3.org/2000/svg";
91
+ var maxNodes = input.maxNodes || 3000, maxChars = input.maxChars || 12000000;
92
+ var here = location.href.replace(/#.*$/, "");
93
+ var statesBase = new URL("../", location.href).href;
94
+ // a reference into the saved files: marked relative to states/ (the
95
+ // caller makes it relative to wherever the part's file goes)
96
+ var rel = function (u) {
97
+ if (!u) return u;
98
+ if (/^(data|blob|about|javascript|mailto|tel):/i.test(u) || u.charAt(0) === "#") return u;
99
+ var a;
100
+ try { a = new URL(u, location.href).href; } catch (e) { return u; }
101
+ if (a.replace(/#.*$/, "") === here) { var h = a.indexOf("#"); return h >= 0 ? a.slice(h) : u; }
102
+ if (a.indexOf(statesBase) === 0) return "otrel:" + a.slice(statesBase.length);
103
+ return a;
104
+ };
105
+ var fixUrls = function (v) {
106
+ if (v.indexOf("url(") < 0) return v;
107
+ return v.replace(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*?))\s*\)/g, function (m, a, b, c) {
108
+ var u = a != null ? a : b != null ? b : c;
109
+ return 'url("' + rel(u).replace(/"/g, "%22") + '")';
110
+ });
111
+ };
112
+
113
+ // --- what the browser would give each element anyway -------------------
114
+ frame = document.createElement("iframe");
115
+ frame.setAttribute("aria-hidden", "true");
116
+ frame.style.cssText = "position:absolute;left:-20000px;top:0;width:1200px;height:900px;border:0;visibility:hidden";
117
+ // after <body>, not in it: nothing of the page's own (a :last-child) changes
118
+ document.documentElement.appendChild(frame);
119
+ var fd = frame.contentDocument, fw = frame.contentWindow;
120
+ fd.open();
121
+ fd.write('<!doctype html><html><head><style>#ot-ps::before,#ot-ps::after{content:""}</style></head><body><div id="ot-ps"></div><input id="ot-ph" placeholder="x"></body></html>');
122
+ fd.close();
123
+ var EXCLUDE = /^(--|transition|animation|will-change|view-transition|inline-size|block-size|min-inline-size|max-inline-size|min-block-size|max-block-size|margin-(block|inline)|padding-(block|inline)|border-(block|inline)|inset-(block|inline)|scroll-(margin|padding)-(block|inline)|overflow-(block|inline)|contain-intrinsic-(block|inline)|border-(start|end)-|offset|app-region|-webkit-app-region)/;
124
+ var probeCs = getComputedStyle(document.documentElement);
125
+ var PROPS = [];
126
+ for (var i = 0; i < probeCs.length; i++) if (!EXCLUDE.test(probeCs[i])) PROPS.push(probeCs[i]);
127
+ var INH = {};
128
+ ("border-collapse border-spacing caption-side caret-color color color-scheme cursor direction empty-cells " +
129
+ "font-family font-feature-settings font-kerning font-optical-sizing font-palette font-size font-size-adjust " +
130
+ "font-stretch font-style font-synthesis-small-caps font-synthesis-style font-synthesis-weight font-variant " +
131
+ "font-variant-alternates font-variant-caps font-variant-east-asian font-variant-emoji font-variant-ligatures " +
132
+ "font-variant-numeric font-variant-position font-variation-settings font-weight hyphens hyphenate-character " +
133
+ "image-rendering letter-spacing line-break line-height list-style-image list-style-position list-style-type " +
134
+ "orphans overflow-wrap paint-order pointer-events quotes ruby-position tab-size text-align text-align-last " +
135
+ "text-anchor text-combine-upright text-decoration-skip-ink text-emphasis-color text-emphasis-position " +
136
+ "text-emphasis-style text-indent text-orientation text-rendering text-shadow text-size-adjust text-transform " +
137
+ "text-underline-offset text-underline-position text-wrap-mode text-wrap-style visibility white-space-collapse " +
138
+ "widows word-break word-spacing writing-mode -webkit-text-fill-color -webkit-text-stroke-color " +
139
+ "-webkit-text-stroke-width -webkit-font-smoothing -webkit-locale -webkit-text-security " +
140
+ "-webkit-border-horizontal-spacing -webkit-border-vertical-spacing fill fill-opacity fill-rule stroke " +
141
+ "stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity " +
142
+ "stroke-width clip-rule color-interpolation color-interpolation-filters color-rendering marker-start " +
143
+ "marker-mid marker-end shape-rendering")
144
+ .split(" ").forEach(function (p) { INH[p] = 1; });
145
+ // always written: a default frame's width can equal the page's by chance
146
+ var ALWAYS = { width: 1, height: 1 };
147
+ // what the part itself always carries of what it inherits, so it reads
148
+ // the same put into any page (the rest only where it is not the default)
149
+ var ROOT = {};
150
+ ("color font-family font-size font-weight font-style font-stretch font-variant-numeric font-feature-settings " +
151
+ "font-variation-settings line-height letter-spacing word-spacing text-align text-transform text-indent " +
152
+ "text-shadow white-space-collapse text-wrap-mode visibility direction writing-mode cursor list-style-type")
153
+ .split(" ").forEach(function (p) { ROOT[p] = 1; });
154
+ // colours that follow the text's own colour unless set (currentColor)
155
+ var CURRENT = {};
156
+ ("border-top-color border-right-color border-bottom-color border-left-color outline-color column-rule-color " +
157
+ "row-rule-color text-decoration-color text-emphasis-color caret-color -webkit-text-fill-color " +
158
+ "-webkit-text-stroke-color").split(" ").forEach(function (p) { CURRENT[p] = 1; });
159
+ var snap = function (cs) { var o = {}; for (var i = 0; i < PROPS.length; i++) o[PROPS[i]] = cs.getPropertyValue(PROPS[i]); return o; };
160
+ var defs = {};
161
+ // the attributes the browser's own sheet styles by (a link's underline,
162
+ // an input's type, an open <details>), copied onto the default element
163
+ var UA_ATTRS = { href: 1, type: 1, open: 1, multiple: 1, size: 1, controls: 1 };
164
+ var defaultsOf = function (el) {
165
+ var ns = el.namespaceURI || HTML_NS, tag = el.localName, key = ns + " " + tag, set = [];
166
+ if (ns === HTML_NS)
167
+ for (var a in UA_ATTRS) if (el.hasAttribute(a)) { var av = a === "href" ? "#" : el.getAttribute(a); set.push([a, av]); key += " " + a + "=" + av; }
168
+ if (defs[key]) return defs[key];
169
+ var holder = null, d;
170
+ if (ns === SVG_NS) {
171
+ holder = fd.createElementNS(SVG_NS, "svg"); fd.body.appendChild(holder);
172
+ d = tag === "svg" ? holder : holder.appendChild(fd.createElementNS(SVG_NS, tag));
173
+ } else if (ns === HTML_NS) {
174
+ d = fd.createElement(tag);
175
+ set.forEach(function (kv) { try { d.setAttribute(kv[0], kv[1]); } catch (e) {} });
176
+ fd.body.appendChild(d); holder = d;
177
+ } else { d = fd.createElementNS(ns, tag); fd.body.appendChild(d); holder = d; }
178
+ var v = snap(fw.getComputedStyle(d)), up = snap(fw.getComputedStyle(d.parentNode)), ua = {};
179
+ // an inherited property the browser's own sheet sets for this tag (an h1's size)
180
+ for (var p in INH) if (v[p] !== up[p]) ua[p] = 1;
181
+ holder.remove();
182
+ return (defs[key] = { v: v, ua: ua });
183
+ };
184
+ var psDefault = snap(fw.getComputedStyle(fd.getElementById("ot-ps"), "::before"));
185
+ var phDefault = snap(fw.getComputedStyle(fd.getElementById("ot-ph"), "::placeholder"));
186
+
187
+ var cache = new Map();
188
+ var computed = function (el) {
189
+ var c = cache.get(el);
190
+ if (!c) { c = snap(getComputedStyle(el)); cache.set(el, c); }
191
+ return c;
192
+ };
193
+ var styleOf = function (el, cs, parent, root) {
194
+ var d = defaultsOf(el), out = [];
195
+ for (var i = 0; i < PROPS.length; i++) {
196
+ var p = PROPS[i], v = cs[p];
197
+ if (!v) continue;
198
+ if (CURRENT[p] && v === cs.color && d.v[p] === d.v.color) continue;
199
+ if (INH[p]) {
200
+ if (root ? !ROOT[p] && v === d.v[p] : parent && v === parent[p] && !d.ua[p]) continue;
201
+ } else if (v === d.v[p] && !(ALWAYS[p] && v !== "auto")) continue;
202
+ out.push(p + ":" + fixUrls(v));
203
+ }
204
+ return out;
205
+ };
206
+ var pseudoN = 0;
207
+ var pseudoCss = function (el, cs, out, fams) {
208
+ var rules = "";
209
+ var id = null;
210
+ var tag = function () { if (id == null) { id = String(++pseudoN); out.setAttribute("data-ot-p", id); } return id; };
211
+ ["::before", "::after"].forEach(function (ps) {
212
+ var live = getComputedStyle(el, ps), c = live.getPropertyValue("content");
213
+ if (!c || c === "none" || c === "normal") return;
214
+ var p = snap(live);
215
+ var st = [];
216
+ for (var i = 0; i < PROPS.length; i++) {
217
+ var k = PROPS[i], v = p[k];
218
+ if (!v) continue;
219
+ if (CURRENT[k] && v === p.color && psDefault[k] === psDefault.color) continue;
220
+ if (INH[k] ? v === cs[k] : v === psDefault[k] && k !== "content") continue;
221
+ st.push(k + ":" + fixUrls(v));
222
+ }
223
+ addFamilies(p["font-family"], fams);
224
+ rules += '[data-ot-p="' + tag() + '"]' + ps + "{" + st.join(";") + "}";
225
+ });
226
+ if ((el.localName === "input" || el.localName === "textarea") && el.getAttribute("placeholder")) {
227
+ var ph = snap(getComputedStyle(el, "::placeholder")), st2 = [];
228
+ ["color", "opacity", "font-style", "font-weight", "letter-spacing", "text-transform", "-webkit-text-fill-color"].forEach(function (k) {
229
+ if (ph[k] && ph[k] !== phDefault[k] && ph[k] !== cs[k]) st2.push(k + ":" + ph[k]);
230
+ });
231
+ if (st2.length) rules += '[data-ot-p="' + tag() + '"]::placeholder{' + st2.join(";") + "}";
232
+ }
233
+ return rules;
234
+ };
235
+ var addFamilies = function (ff, fams) {
236
+ (ff || "").split(",").forEach(function (f) {
237
+ f = f.trim().replace(/^["']|["']$/g, "").toLowerCase();
238
+ if (f) fams[f] = 1;
239
+ });
240
+ };
241
+ var URL_ATTR = { src: 1, href: 1, poster: 1, "xlink:href": 1, background: 1 };
242
+ var SKIP = { script: 1, style: 1, link: 1, meta: 1, noscript: 1, template: 1, title: 1, base: 1 };
243
+ var FRAMES = { iframe: 1, frame: 1, object: 1, embed: 1, portal: 1, fencedframe: 1 };
244
+ var kids = function (n) {
245
+ if (n.shadowRoot) return Array.prototype.slice.call(n.shadowRoot.childNodes);
246
+ if (n.localName === "slot" && n.assignedNodes) { var a = n.assignedNodes(); if (a.length) return a; }
247
+ return Array.prototype.slice.call(n.childNodes);
248
+ };
249
+
250
+ var build = function (el, parent, root, st) {
251
+ var tag = el.localName, ns = el.namespaceURI || HTML_NS;
252
+ if (SKIP[tag]) return null;
253
+ if (FRAMES[tag]) throw new Error("it holds an <" + tag + ">: what is inside a frame is another page, not carried into a file");
254
+ if (++st.nodes > maxNodes) throw new Error("more than " + maxNodes + " elements in it");
255
+ if (tag === "source" && el.parentElement && el.parentElement.localName === "picture") return null;
256
+ var cs = computed(el), out;
257
+ if (tag === "canvas") {
258
+ out = document.createElement("img");
259
+ try { out.setAttribute("src", el.toDataURL("image/png")); } catch (e) { out.setAttribute("alt", "a canvas that could not be read"); }
260
+ } else out = document.createElementNS(ns, tag);
261
+ for (var i = 0; i < el.attributes.length; i++) {
262
+ var a = el.attributes[i], n = a.name.toLowerCase(), v = a.value;
263
+ if (n === "style" || n.indexOf("on") === 0 || n.indexOf("data-ot-") === 0 || n === "srcset" || n === "sizes" || n === "loading") continue;
264
+ if (tag === "canvas" && n !== "class" && n !== "id") continue;
265
+ if (URL_ATTR[n]) v = rel(v);
266
+ try { if (a.namespaceURI) out.setAttributeNS(a.namespaceURI, a.name, v); else out.setAttribute(a.name, v); } catch (e) { /* a name markup cannot hold */ }
267
+ }
268
+ if (tag === "img" && (el.currentSrc || el.getAttribute("src"))) out.setAttribute("src", rel(el.currentSrc || el.getAttribute("src")));
269
+ if (tag === "video" && el.currentSrc) out.setAttribute("src", rel(el.currentSrc));
270
+ if (tag === "input") {
271
+ var ty = (el.type || "").toLowerCase();
272
+ if (ty === "checkbox" || ty === "radio") { if (el.checked) out.setAttribute("checked", ""); else out.removeAttribute("checked"); }
273
+ else if (ty !== "file" && ty !== "password") out.setAttribute("value", el.value);
274
+ }
275
+ if (tag === "option") { if (el.selected) out.setAttribute("selected", ""); else out.removeAttribute("selected"); }
276
+ var style = styleOf(el, cs, parent, root);
277
+ if (root) {
278
+ // the part itself: where it sat on the page is not its own
279
+ style = style.filter(function (s) { return !/^(margin-|position:|top:|left:|right:|bottom:|transform:|translate:|rotate:|scale:|float:|z-index:)/.test(s); });
280
+ style.push("margin:0", "position:relative", "float:none");
281
+ }
282
+ if (style.length) out.setAttribute("style", style.join(";"));
283
+ addFamilies(cs["font-family"], st.fams);
284
+ var r = pseudoCss(el, cs, out, st.fams);
285
+ if (r) st.css += r;
286
+ if (tag === "textarea") { out.textContent = el.value; return out; }
287
+ if (tag === "canvas") return out;
288
+ var ks = kids(el);
289
+ for (var k = 0; k < ks.length; k++) {
290
+ var c = ks[k];
291
+ if (c.nodeType === 3) out.appendChild(document.createTextNode(c.data));
292
+ else if (c.nodeType === 1) { var b = build(c, cs, false, st); if (b) out.appendChild(b); }
293
+ }
294
+ return out;
295
+ };
296
+
297
+ // what the part's SVG names outside itself (url(#g), <use href="#icon">)
298
+ var refsIn = function (node, ids) {
299
+ var all = [node].concat(Array.prototype.slice.call(node.querySelectorAll("*")));
300
+ all.forEach(function (n) {
301
+ var h = n.getAttribute("href") || n.getAttribute("xlink:href");
302
+ if (h && h.charAt(0) === "#") ids[h.slice(1)] = 1;
303
+ var s = (n.getAttribute("style") || "") + " " + (n.getAttribute("fill") || "") + " " + (n.getAttribute("stroke") || "") + " " + (n.getAttribute("clip-path") || "") + " " + (n.getAttribute("mask") || "") + " " + (n.getAttribute("filter") || "");
304
+ s.replace(/url\(\s*["']?#([^"')]+)["']?\s*\)/g, function (m, id) { ids[id] = 1; return m; });
305
+ });
306
+ };
307
+ var carried = function (root, st) {
308
+ var have = {}, out = [];
309
+ Array.prototype.forEach.call(root.querySelectorAll("[id]"), function (n) { have[n.id] = 1; });
310
+ if (root.id) have[root.id] = 1;
311
+ var queue = {};
312
+ refsIn(root, queue);
313
+ for (var round = 0; round < 3; round++) {
314
+ var next = {};
315
+ for (var id in queue) {
316
+ if (have[id]) continue;
317
+ have[id] = 1;
318
+ var src = document.getElementById(id);
319
+ if (!src) continue;
320
+ // a symbol takes its paint from the <use> that shows it: copied as
321
+ // it is; a gradient, a clip, a mask or a filter with its styles
322
+ var copy = src.localName === "symbol" ? src.cloneNode(true) : build(src, null, false, st);
323
+ if (!copy) continue;
324
+ out.push(copy);
325
+ refsIn(copy, next);
326
+ }
327
+ queue = next;
328
+ }
329
+ if (!out.length) return "";
330
+ var svg = document.createElementNS(SVG_NS, "svg");
331
+ svg.setAttribute("aria-hidden", "true");
332
+ svg.setAttribute("style", "position:absolute;width:0;height:0;overflow:hidden");
333
+ var d = document.createElementNS(SVG_NS, "defs");
334
+ out.forEach(function (n) { d.appendChild(n); });
335
+ svg.appendChild(d);
336
+ return svg.outerHTML;
337
+ };
338
+
339
+ var parts = [], skipped = [], chars = 0;
340
+ (input.els || []).forEach(function (id) {
341
+ var el = document.querySelector('[data-ot-id="' + id + '"]');
342
+ if (!el) { skipped.push({ el: id, why: "not found in the restored page" }); return; }
343
+ if (chars > maxChars) { skipped.push({ el: id, why: "this screen's part files already hold " + Math.round(maxChars / 1e6) + " MB of markup" }); return; }
344
+ var st = { nodes: 0, css: "", fams: {} };
345
+ try {
346
+ var r = el.getBoundingClientRect();
347
+ var w = el.offsetWidth != null ? el.offsetWidth : r.width, h = el.offsetHeight != null ? el.offsetHeight : r.height;
348
+ if (!(w > 0 && h > 0)) { w = r.width; h = r.height; }
349
+ if (!(w > 0 && h > 0)) { skipped.push({ el: id, why: "it has no size on the page" }); return; }
350
+ var node = build(el, el.parentElement ? computed(el.parentElement) : null, true, st);
351
+ if (!node) { skipped.push({ el: id, why: "a <" + el.localName + "> is not drawn" }); return; }
352
+ var html = node.outerHTML, defsHtml = carried(node, st);
353
+ chars += html.length + defsHtml.length + st.css.length;
354
+ var dw = Math.max(w, el.scrollWidth || 0), dh = Math.max(h, el.scrollHeight || 0);
355
+ var item = { el: id, html: html, css: st.css, defs: defsHtml, w: Math.round(w * 100) / 100, h: Math.round(h * 100) / 100, families: Object.keys(st.fams), nodes: st.nodes };
356
+ if (dw > w + 1 || dh > h + 1) item.drawn = [Math.ceil(dw), Math.ceil(dh)];
357
+ parts.push(item);
358
+ } catch (e) {
359
+ skipped.push({ el: id, why: String(e && e.message || e) });
360
+ }
361
+ });
362
+ return JSON.stringify({ parts: parts, skipped: skipped, ms: Math.round(performance.now() - t0) });
363
+ } catch (e) {
364
+ return JSON.stringify({ error: String(e && e.stack || e) });
365
+ } finally {
366
+ if (frame) frame.remove();
367
+ }
368
+ }`;
369
+
370
+ /** The expression to evaluate in a restored state.html for these parts. */
371
+ export function partDomExpression(els: string[], opts: Omit<PartDomInput, "els"> = {}): string {
372
+ return `(${PART_DOM_JS})(${JSON.stringify({ els, ...opts } satisfies PartDomInput)})`;
373
+ }
374
+
375
+ // --- the page's fonts -------------------------------------------------------------
376
+
377
+ /** a url() in CSS, quoted or not */
378
+ const CSS_URL = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*?))\s*\)/g;
379
+
380
+ /** `css` with every relative url() resolved from `fromDir` and written
381
+ * relative to `toDir` (posix separators) */
382
+ function moveCssUrls(css: string, fromDir: string, toDir: string): string {
383
+ return css.replace(CSS_URL, (m, a?: string, b?: string, c?: string) => {
384
+ const u = (a ?? b ?? c ?? "").trim();
385
+ if (!u || /^([a-z][a-z0-9+.-]*:|#|\/)/i.test(u)) return m;
386
+ const [path, rest] = splitRef(u);
387
+ const to = relative(toDir, resolve(fromDir, decodeURIComponentSafe(path)))
388
+ .split(sep)
389
+ .join("/");
390
+ return `url("${encodeURI(to)}${rest}")`;
391
+ });
392
+ }
393
+
394
+ const splitRef = (u: string): [string, string] => {
395
+ const i = u.search(/[?#]/);
396
+ return i < 0 ? [u, ""] : [u.slice(0, i), u.slice(i)];
397
+ };
398
+ const decodeURIComponentSafe = (s: string): string => {
399
+ try {
400
+ return decodeURIComponent(s);
401
+ } catch {
402
+ return s;
403
+ }
404
+ };
405
+
406
+ /** the family an @font-face block declares, unquoted */
407
+ function faceFamily(block: string): string | null {
408
+ const m = /font-family\s*:\s*([^;}]+)/i.exec(block);
409
+ return m ? m[1]!.trim().replace(/^["']|["']$/g, "") : null;
410
+ }
411
+
412
+ /**
413
+ * Every @font-face rule a saved screen's state.html carries — in its own
414
+ * <style> elements and in the stylesheets it links (and those they @import)
415
+ * — each with its url()s written relative to `toDir`, and the family it
416
+ * declares (as written, and lower case to match by).
417
+ */
418
+ export function stateFontFaces(
419
+ stateDir: string,
420
+ toDir: string,
421
+ ): { family: string; key: string; css: string }[] {
422
+ const out: { family: string; key: string; css: string }[] = [];
423
+ const seen = new Set<string>();
424
+ const take = (css: string, fromDir: string) => {
425
+ for (const m of css.matchAll(/@font-face\s*\{[^}]*\}/gi)) {
426
+ // a face whose files the snapshot did not carry (cut off: about:blank) draws nothing
427
+ const urls = [...m[0].matchAll(CSS_URL)].map((u) => (u[1] ?? u[2] ?? u[3] ?? "").trim());
428
+ if (urls.length && urls.every((u) => /^about:/i.test(u))) continue;
429
+ const family = faceFamily(m[0]);
430
+ if (family)
431
+ out.push({ family, key: family.toLowerCase(), css: moveCssUrls(m[0], fromDir, toDir) });
432
+ }
433
+ };
434
+ const sheet = (file: string, depth: number) => {
435
+ if (depth > 4 || seen.has(file) || !existsSync(file)) return;
436
+ seen.add(file);
437
+ let css: string;
438
+ try {
439
+ css = readFileSync(file, "utf8");
440
+ } catch {
441
+ return;
442
+ }
443
+ take(css, dirname(file));
444
+ for (const m of css.matchAll(/@import\s+(?:url\(\s*)?["']?([^"')\s;]+)/gi)) {
445
+ const ref = m[1]!;
446
+ if (/^[a-z][a-z0-9+.-]*:/i.test(ref)) continue;
447
+ sheet(resolve(dirname(file), decodeURIComponentSafe(splitRef(ref)[0])), depth + 1);
448
+ }
449
+ };
450
+ let html: string;
451
+ try {
452
+ html = readFileSync(join(stateDir, "state.html"), "utf8");
453
+ } catch {
454
+ return out;
455
+ }
456
+ for (const m of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) {
457
+ take(m[1]!, stateDir);
458
+ for (const im of m[1]!.matchAll(/@import\s+(?:url\(\s*)?["']?([^"')\s;]+)/gi))
459
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(im[1]!))
460
+ sheet(resolve(stateDir, decodeURIComponentSafe(splitRef(im[1]!)[0])), 1);
461
+ }
462
+ for (const m of html.matchAll(/<link\b[^>]*>/gi)) {
463
+ const tag = m[0];
464
+ if (!/\brel\s*=\s*["']?[^"'>]*stylesheet/i.test(tag)) continue;
465
+ const href = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(tag);
466
+ const ref = href ? (href[1] ?? href[2] ?? href[3] ?? "") : "";
467
+ if (!ref || /^[a-z][a-z0-9+.-]*:/i.test(ref)) continue;
468
+ sheet(resolve(stateDir, decodeURIComponentSafe(splitRef(ref.replace(/&amp;/g, "&"))[0])), 0);
469
+ }
470
+ return out;
471
+ }
472
+
473
+ // --- the files ----------------------------------------------------------------------
474
+
475
+ /** One part's file in `parts/index.json`. */
476
+ export type PartFileEntry = {
477
+ /** the file, relative to index.json */
478
+ file: string;
479
+ ref: string;
480
+ state: string;
481
+ el: string;
482
+ kind: ComponentEntry["kind"];
483
+ label: string;
484
+ /** what it holds, by field, as the page showed it (components.json has
485
+ * each with where it was read) */
486
+ values: Record<string, string>;
487
+ /** its natural size, CSS px — the file's body is this size */
488
+ w: number;
489
+ h: number;
490
+ /** what it draws to the right and below, when more than w × h (as on the page) */
491
+ drawn?: [number, number];
492
+ /** where it sat on its screen, the screen's CSS px */
493
+ box: [number, number, number, number];
494
+ /** its crisp picture (components.json's), relative to index.json */
495
+ picture?: string;
496
+ /** what was behind it on the page (the file itself is see-through) */
497
+ backdrop: string;
498
+ /** font families set in it that have their font in the file */
499
+ fonts: string[];
500
+ };
501
+
502
+ /** `parts/index.json` — version 1. */
503
+ export type PartFilesIndex = {
504
+ version: 1;
505
+ about: string;
506
+ /** components.json, relative to index.json */
507
+ components: string;
508
+ parts: PartFileEntry[];
509
+ skipped: { ref: string; kind: ComponentEntry["kind"]; label: string; why: string }[];
510
+ };
511
+
512
+ const INDEX_ABOUT =
513
+ "Each part of the product's saved screens (the parts components.json lists) as a standalone HTML file: its own elements with every computed style inlined, the page's @font-face rules for the fonts it uses (the saved font files), its images from the saved files — it opens alone, at any size, in the product's own styles. w × h is its natural size; each file's header says where it came from and how to show it. Nothing here says which part a film uses.";
514
+
515
+ /** `<state>-<el>-<kind>.html`, safe as a file name */
516
+ export function partFileName(e: Pick<ComponentEntry, "state" | "el" | "kind">): string {
517
+ return `${e.state}-${e.el}-${e.kind}.html`.replace(/[^\w.-]+/g, "_");
518
+ }
519
+
520
+ const esc = (s: string): string =>
521
+ s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
522
+ /** text safe inside an HTML comment (nothing in it ends the comment) */
523
+ const inComment = (s: string): string => s.replace(/--(?=!?>)/g, "-\\u002d");
524
+
525
+ /** One part's file. */
526
+ export function partFileHtml(o: {
527
+ entry: ComponentEntry;
528
+ dom: PartDom;
529
+ /** where the part's file goes, to mark-relative references from */
530
+ statesPrefix: string;
531
+ /** @font-face rules, their url()s relative to the file */
532
+ fonts: string[];
533
+ /** the families they declare */
534
+ families: string[];
535
+ file: string;
536
+ values: Record<string, string>;
537
+ /** the saved screen, relative to the file */
538
+ stateHtml: string;
539
+ }): string {
540
+ const { entry: e, dom } = o;
541
+ const w = Math.ceil(dom.w);
542
+ const h = Math.ceil(dom.h);
543
+ // the iframe shows all it draws (a heading set past its width included)
544
+ const [fw, fh] = dom.drawn ?? [w, h];
545
+ const local = (s: string) => s.replace(/otrel:/g, o.statesPrefix);
546
+ const header = [
547
+ `${e.label || e.kind} — a ${e.kind} of ${e.provenance.url ?? "the product's page"}, as it stood on the saved screen "${e.state}"`,
548
+ "",
549
+ `source: ${e.provenance.url ?? "(not recorded)"}`,
550
+ `state: ${e.state} (${o.stateHtml})`,
551
+ `ref: ${e.ref}`,
552
+ `selector: ${e.selector}`,
553
+ `kind: ${e.kind}${e.sub ? ` (${e.sub})` : ""}`,
554
+ `label: ${JSON.stringify(e.label)}`,
555
+ `values: ${JSON.stringify(o.values)}`,
556
+ `captured: ${e.provenance.capturedAt ?? "(not recorded)"}`,
557
+ `size: ${w} × ${h} CSS px (natural; data-w / data-h on <body>, --part-w / --part-h)`,
558
+ ...(dom.drawn
559
+ ? [`drawn: ${fw} × ${fh} CSS px (it draws past its box, as on the page)`]
560
+ : []),
561
+ `backdrop: ${e.look.backdrop} (what was behind it on the page; this file is see-through)`,
562
+ `fonts: ${o.families.length ? `${o.families.join(", ")} (the saved font files, declared below)` : "none of its own (system fonts)"}`,
563
+ "",
564
+ "Its elements carry every computed style inline and its fonts are declared below, so it",
565
+ "renders as the page did with no page CSS. At any size, from a page beside parts/:",
566
+ ` <iframe src="parts/${o.file}" width="${fw}" height="${fh}" scrolling="no" style="border:0;transform:scale(2);transform-origin:0 0"></iframe>`,
567
+ `or put into the page itself: (await partFiles("parts/")).node("${e.ref}") — kit/media.js`,
568
+ ]
569
+ .map((l) => (l ? ` ${inComment(l)}` : ""))
570
+ .join("\n");
571
+ return `<!doctype html>
572
+ <!--
573
+ ${header}
574
+ -->
575
+ <html>
576
+ <head>
577
+ <meta charset="utf-8">
578
+ <title>${esc(e.label || e.ref)}</title>
579
+ <style>
580
+ :root{--part-w:${w}px;--part-h:${h}px;--part-backdrop:${e.look.backdrop}}
581
+ html,body{margin:0;padding:0;background:transparent}
582
+ body{width:var(--part-w);height:var(--part-h)}
583
+ </style>
584
+ ${o.fonts.length ? `<style data-part-fonts>\n${local(o.fonts.join("\n"))}\n</style>\n` : ""}${dom.css ? `<style data-part-pseudo>\n${local(dom.css)}\n</style>\n` : ""}</head>
585
+ <body data-w="${w}" data-h="${h}" data-ref="${esc(e.ref)}" data-kind="${e.kind}">
586
+ ${local(dom.html)}${dom.defs ? `\n${local(dom.defs)}` : ""}
587
+ </body>
588
+ </html>
589
+ `;
590
+ }
591
+
592
+ export type PartFilesResult = {
593
+ /** the parts folder (absolute) */
594
+ dir: string;
595
+ /** parts/index.json (absolute) */
596
+ index: string;
597
+ written: number;
598
+ skipped: PartFilesIndex["skipped"];
599
+ };
600
+
601
+ /** a part's values as text, by field */
602
+ const valuesText = (e: ComponentEntry): Record<string, string> =>
603
+ Object.fromEntries(Object.entries(e.values).map(([k, v]) => [k, v.text]));
604
+
605
+ /**
606
+ * Write each part of `file` (gathered from `source`) as
607
+ * `<dir>/<state>-<el>-<kind>.html`, from what its screen's page gave
608
+ * (states/<id>/parts-dom.json), and `<dir>/index.json`. A part whose screen
609
+ * has no parts-dom.json, or that the page could not give, is skipped with
610
+ * its reason. A folder of part files written before is replaced; one that
611
+ * is something else is refused.
612
+ */
613
+ export function writePartFiles(
614
+ file: ComponentsFile,
615
+ source: Pick<ComponentSource, "root" | "states">,
616
+ dir: string,
617
+ ): PartFilesResult {
618
+ const out = resolve(dir);
619
+ const indexPath = join(out, "index.json");
620
+ if (existsSync(out)) {
621
+ let ours = false;
622
+ try {
623
+ ours =
624
+ (JSON.parse(readFileSync(indexPath, "utf8")) as { about?: string }).about === INDEX_ABOUT;
625
+ } catch {
626
+ ours = readdirSync(out).length === 0;
627
+ }
628
+ if (!ours)
629
+ throw new Error(`${out} is there and holds something else than part files — not replaced`);
630
+ rmSync(out, { recursive: true, force: true });
631
+ }
632
+ const parts: PartFileEntry[] = [];
633
+ const skipped: PartFilesIndex["skipped"] = [];
634
+ const doms = new Map<string, Map<string, PartDom> | string>();
635
+ const skips = new Map<string, Map<string, string>>();
636
+ const faces = new Map<string, ReturnType<typeof stateFontFaces>>();
637
+ const dirOf = new Map(source.states.map((s) => [s.id, s.dir]));
638
+ const toPosix = (p: string) => p.split(sep).join("/");
639
+ for (const e of file.components) {
640
+ const skip = (why: string) => skipped.push({ ref: e.ref, kind: e.kind, label: e.label, why });
641
+ const stateDir = dirOf.get(e.state);
642
+ if (!stateDir) {
643
+ skip("its saved screen is not in this inventory's source");
644
+ continue;
645
+ }
646
+ if (!doms.has(e.state)) {
647
+ try {
648
+ const f = JSON.parse(readFileSync(join(stateDir, "parts-dom.json"), "utf8")) as PartDomFile;
649
+ doms.set(e.state, new Map(f.parts.map((p) => [p.el, p])));
650
+ skips.set(e.state, new Map(f.skipped.map((s) => [s.el, s.why])));
651
+ } catch {
652
+ doms.set(
653
+ e.state,
654
+ existsSync(join(stateDir, "parts-dom.json"))
655
+ ? "its screen's parts-dom.json could not be read"
656
+ : "its screen was saved before parts were kept as files (no parts-dom.json) — save it again",
657
+ );
658
+ }
659
+ }
660
+ const byEl = doms.get(e.state)!;
661
+ if (typeof byEl === "string") {
662
+ skip(byEl);
663
+ continue;
664
+ }
665
+ const dom = byEl.get(e.el);
666
+ if (!dom) {
667
+ skip(skips.get(e.state)?.get(e.el) ?? "the page gave nothing for it");
668
+ continue;
669
+ }
670
+ if (!faces.has(e.state)) faces.set(e.state, stateFontFaces(stateDir, out));
671
+ const fams = new Set(dom.families);
672
+ const used = faces.get(e.state)!.filter((f) => fams.has(f.key));
673
+ const name = partFileName(e);
674
+ const values = valuesText(e);
675
+ const statesPrefix = `${toPosix(relative(out, dirname(stateDir))) || "."}/`;
676
+ mkdirSync(out, { recursive: true });
677
+ writeFileSync(
678
+ join(out, name),
679
+ partFileHtml({
680
+ entry: e,
681
+ dom,
682
+ statesPrefix,
683
+ // the fonts are already relative to the parts folder
684
+ fonts: used.map((f) => f.css),
685
+ families: [...new Set(used.map((f) => f.family))],
686
+ file: name,
687
+ values,
688
+ stateHtml: toPosix(relative(out, join(stateDir, "state.html"))),
689
+ }),
690
+ );
691
+ parts.push({
692
+ file: name,
693
+ ref: e.ref,
694
+ state: e.state,
695
+ el: e.el,
696
+ kind: e.kind,
697
+ label: e.label,
698
+ values,
699
+ w: Math.ceil(dom.w),
700
+ h: Math.ceil(dom.h),
701
+ ...(dom.drawn ? { drawn: dom.drawn } : {}),
702
+ box: e.box,
703
+ ...(e.picture ? { picture: toPosix(relative(out, resolve(source.root, e.picture))) } : {}),
704
+ backdrop: e.look.backdrop,
705
+ fonts: [...new Set(used.map((f) => f.family))],
706
+ });
707
+ }
708
+ const index: PartFilesIndex = {
709
+ version: 1,
710
+ about: INDEX_ABOUT,
711
+ components: toPosix(relative(out, join(source.root, "components.json"))),
712
+ parts,
713
+ skipped,
714
+ };
715
+ mkdirSync(out, { recursive: true });
716
+ writeFileSync(indexPath, `${JSON.stringify(index, null, 2)}\n`);
717
+ return { dir: out, index: indexPath, written: parts.length, skipped };
718
+ }
719
+
720
+ /** The one line a summary prints about the part files. */
721
+ export function partFilesLine(r: PartFilesResult, shownDir: string): string {
722
+ const sk = r.skipped.length;
723
+ if (!r.written)
724
+ return `parts: no part files in ${shownDir}/ — ${r.skipped[0]?.why ?? "no parts measured"} (index.json)`;
725
+ return (
726
+ `parts: ${r.written} part${r.written === 1 ? "" : "s"} as files in ${shownDir}/ (index.json) — each opens alone at any size, in the product's styles` +
727
+ (sk ? `; ${sk} skipped, each with its reason in index.json` : "")
728
+ );
729
+ }