@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
package/kit/look.js ADDED
@@ -0,0 +1,589 @@
1
+ // @ts-check
2
+ // Type and colour at film scale — open-take's film kit. Nothing here picks a
3
+ // look: the colours and fonts are the product's (`npx open-take film look`
4
+ // reads them into look/look.json) or yours. These are measurements to execute
5
+ // with, at the size a film is watched:
6
+ //
7
+ // - fitText: the biggest size a text can be set at in a box, and where its
8
+ // lines break — CJK by phrase and never before a closing mark, Latin at
9
+ // spaces, lines balanced so none is left with one word;
10
+ // - contrast: the WCAG contrast ratio of a colour on a ground;
11
+ // - readable: how big a size in the 1920-wide frame shows on a phone, a
12
+ // timeline, a laptop — information, not a rule;
13
+ // - palette: look.json's colours and fonts by role, ready for CSS;
14
+ // - frame: the product's own surface for a picture of it — the corner and
15
+ // shadow its cards have (look.json), a margin of its own ground — for a
16
+ // screenshot shown as an object rather than cut flush; only where called.
17
+ //
18
+ // import { fitText, contrast, readable, palette, loadLook, fontsReady } from "./kit/look.js";
19
+ // const look = palette(await loadLook("look/look.json"));
20
+ // await fontsReady(look.font(), "700", "找到你的下一間健身房");
21
+ // const f = fitText({ width: 1400, height: 400 }, "找到你的下一間健身房", { font: look.font(), weight: 700, lines: 2 });
22
+ // title.style.font = f.font; // "700 168px ..." — the size it fits at
23
+ // title.innerHTML = f.lines.join("<br>"); // its own line breaks
24
+ // contrast(look.text, look.bg) // 13.1
25
+ // readable(f.size).on[0] // { screen: "phone, upright…", px: 34.4, mm: 5.7 }
26
+ // Object.assign(shot.style, frame(lookJson).style); // its corner, shadow, margin, ground
27
+ //
28
+ // fitText measures with the browser's own text engine (a canvas), so the font
29
+ // must have loaded before it is asked — `fontsReady` loads it; the film clock
30
+ // waits for fonts anyway, but a measurement taken before they are in is taken
31
+ // in the fallback font.
32
+
33
+ /** @typedef {{ r: number, g: number, b: number, a: number }} Rgba sRGB 0..255, alpha 0..1 */
34
+ /** @typedef {{ width: number, height: number }} Size */
35
+
36
+ // --- colour -----------------------------------------------------------------
37
+
38
+ /** @type {CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null | undefined} */
39
+ let ctx2d;
40
+ const context = () => {
41
+ if (ctx2d !== undefined) return ctx2d;
42
+ try {
43
+ const c =
44
+ typeof OffscreenCanvas !== "undefined"
45
+ ? new OffscreenCanvas(1, 1)
46
+ : typeof document !== "undefined"
47
+ ? document.createElement("canvas")
48
+ : null;
49
+ ctx2d = c ? /** @type {any} */ (c.getContext("2d", { willReadFrequently: true })) : null;
50
+ } catch {
51
+ ctx2d = null;
52
+ }
53
+ return ctx2d;
54
+ };
55
+
56
+ /**
57
+ * A CSS colour as sRGB. Hex, rgb(), hsl() and `transparent` are read here;
58
+ * anything else a browser knows (names, oklch(), color-mix()…) is painted on
59
+ * one canvas pixel and read back. null when it is not a colour.
60
+ * @param {string | Rgba} css
61
+ * @returns {Rgba | null}
62
+ */
63
+ export function parseColor(css) {
64
+ if (typeof css === "object" && css) return css;
65
+ const s = String(css).trim().toLowerCase();
66
+ if (s === "transparent") return { r: 0, g: 0, b: 0, a: 0 };
67
+ const hex = /^#([0-9a-f]{3,8})$/.exec(s);
68
+ if (hex) {
69
+ let h = hex[1] ?? "";
70
+ if (h.length === 3 || h.length === 4) h = [...h].map((c) => c + c).join("");
71
+ if (h.length !== 6 && h.length !== 8) return null;
72
+ /** @param {number} i */
73
+ const n = (i) => parseInt(h.slice(i, i + 2), 16);
74
+ return { r: n(0), g: n(2), b: n(4), a: h.length === 8 ? n(6) / 255 : 1 };
75
+ }
76
+ const fn = /^(rgba?|hsla?)\(([^)]*)\)$/.exec(s);
77
+ if (fn) {
78
+ const kind = fn[1] ?? "";
79
+ const parts = (fn[2] ?? "")
80
+ .replace(/\s*\/\s*/, " / ")
81
+ .split(/[\s,]+/)
82
+ .filter((p) => p && p !== "/");
83
+ /** @param {string} p @param {number} scale */
84
+ const num = (p, scale) => (p.endsWith("%") ? (parseFloat(p) / 100) * scale : parseFloat(p));
85
+ if (parts.length < 3) return null;
86
+ const [p0 = "", p1 = "", p2 = "", p3] = parts;
87
+ const a = p3 != null ? Math.max(0, Math.min(1, num(p3, 1))) : 1;
88
+ if (kind.startsWith("rgb")) {
89
+ /** @param {string} p */
90
+ const c = (p) => Math.max(0, Math.min(255, Math.round(num(p, 255))));
91
+ const [r, g, b] = [c(p0), c(p1), c(p2)];
92
+ if ([r, g, b, a].every(Number.isFinite)) return { r, g, b, a };
93
+ return null;
94
+ }
95
+ const h = (((parseFloat(p0) % 360) + 360) % 360) / 360;
96
+ const sat = parseFloat(p1) / 100;
97
+ const l = parseFloat(p2) / 100;
98
+ if (![h, sat, l, a].every(Number.isFinite)) return null;
99
+ const q = l < 0.5 ? l * (1 + sat) : l + sat - l * sat;
100
+ const p = 2 * l - q;
101
+ /** @param {number} t */
102
+ const ch = (t) => {
103
+ const u = t < 0 ? t + 1 : t > 1 ? t - 1 : t;
104
+ const v =
105
+ u < 1 / 6
106
+ ? p + (q - p) * 6 * u
107
+ : u < 1 / 2
108
+ ? q
109
+ : u < 2 / 3
110
+ ? p + (q - p) * (2 / 3 - u) * 6
111
+ : p;
112
+ return Math.round(v * 255);
113
+ };
114
+ return { r: ch(h + 1 / 3), g: ch(h), b: ch(h - 1 / 3), a };
115
+ }
116
+ const c = context();
117
+ if (!c) return null;
118
+ c.clearRect(0, 0, 1, 1);
119
+ c.fillStyle = "rgba(0, 0, 0, 0)";
120
+ c.fillStyle = s;
121
+ if (c.fillStyle === "rgba(0, 0, 0, 0)" && !/^(rgba?|hsla?)\(.*\b0\)$/.test(s)) return null; // not a colour
122
+ c.fillRect(0, 0, 1, 1);
123
+ const [r = 0, g = 0, b = 0, a = 0] = c.getImageData(0, 0, 1, 1).data;
124
+ return { r, g, b, a: a / 255 };
125
+ }
126
+
127
+ /** @param {number} v */
128
+ const lin = (v) => {
129
+ const c = v / 255;
130
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
131
+ };
132
+
133
+ /** WCAG relative luminance, 0 (black) .. 1 (white) @param {string | Rgba} c */
134
+ export function luminance(c) {
135
+ const x = parseColor(c);
136
+ if (!x) return Number.NaN;
137
+ return 0.2126 * lin(x.r) + 0.7152 * lin(x.g) + 0.0722 * lin(x.b);
138
+ }
139
+
140
+ /** @param {Rgba} fg @param {Rgba} bg @returns {Rgba} */
141
+ const over = (fg, bg) => ({
142
+ r: fg.r * fg.a + bg.r * (1 - fg.a),
143
+ g: fg.g * fg.a + bg.g * (1 - fg.a),
144
+ b: fg.b * fg.a + bg.b * (1 - fg.a),
145
+ a: 1,
146
+ });
147
+
148
+ /**
149
+ * The WCAG contrast ratio of `fg` on `bg`, 1 (none) to 21 (black on white). A
150
+ * translucent fg is laid over bg first; a translucent bg over white. For
151
+ * reference only: WCAG asks 4.5 for body text and 3 for large text on a page
152
+ * read up close — a film is read for a moment, at whatever size it is shown.
153
+ * @param {string | Rgba} fg
154
+ * @param {string | Rgba} bg
155
+ */
156
+ export function contrast(fg, bg) {
157
+ const f = parseColor(fg);
158
+ let b = parseColor(bg);
159
+ if (!f || !b) return Number.NaN;
160
+ if (b.a < 1) b = over(b, { r: 255, g: 255, b: 255, a: 1 });
161
+ const l1 = luminance(over(f, b));
162
+ const l2 = luminance(b);
163
+ return Math.round(((Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05)) * 100) / 100;
164
+ }
165
+
166
+ // --- text at film scale -------------------------------------------------------
167
+
168
+ /**
169
+ * Where a film is watched: the CSS px width the frame is shown across. The
170
+ * millimetres assume a 6.1-inch phone (393 px across 65 mm upright).
171
+ * @type {{ name: string, widthPx: number, mmPerPx?: number }[]}
172
+ */
173
+ export const SCREENS = [
174
+ { name: "phone, upright, film across the screen", widthPx: 393, mmPerPx: 65.1 / 393 },
175
+ { name: "phone, sideways, full screen", widthPx: 852, mmPerPx: 141.2 / 852 },
176
+ { name: "desktop timeline (about 600 px wide)", widthPx: 600 },
177
+ { name: "laptop, full screen", widthPx: 1440 },
178
+ ];
179
+
180
+ /**
181
+ * How big text set at `sizePx` in a `filmWidth`-wide film shows on the screens
182
+ * it is watched on — information, not a rule.
183
+ * @param {number} sizePx
184
+ * @param {{ filmWidth?: number, screens?: typeof SCREENS }} [opts]
185
+ */
186
+ export function readable(sizePx, { filmWidth = 1920, screens = SCREENS } = {}) {
187
+ return {
188
+ filmPx: sizePx,
189
+ filmWidth,
190
+ on: screens.map((s) => {
191
+ const px = Math.round(((sizePx * s.widthPx) / filmWidth) * 10) / 10;
192
+ return {
193
+ screen: s.name,
194
+ px,
195
+ ...(s.mmPerPx ? { mm: Math.round(px * s.mmPerPx * 10) / 10 } : {}),
196
+ };
197
+ }),
198
+ reference: "iOS default text: body 17 px, footnote 13 px, caption 12 px, the smallest 11 px",
199
+ };
200
+ }
201
+
202
+ /** a family name as CSS: quoted unless it is already a stack or a generic @param {string} font */
203
+ const fontStack = (font) =>
204
+ /[,"']/.test(font) || /^(serif|sans-serif|monospace|system-ui|cursive|fantasy)$/.test(font)
205
+ ? font
206
+ : `${JSON.stringify(font)}, sans-serif`;
207
+
208
+ /**
209
+ * Load a font (every weight asked, for the characters given) so a measurement
210
+ * of it is a measurement of it. Resolves once it is in, or has failed.
211
+ * @param {string} font a family name or a CSS font-family stack
212
+ * @param {string | number | (string | number)[]} [weights]
213
+ * @param {string} [text]
214
+ */
215
+ export async function fontsReady(font, weights = "400", text) {
216
+ if (typeof document === "undefined" || !document.fonts) return;
217
+ const list = Array.isArray(weights) ? weights : [weights];
218
+ await Promise.all(
219
+ list.map((w) => document.fonts.load(`${w} 32px ${fontStack(font)}`, text).catch(() => [])),
220
+ );
221
+ }
222
+
223
+ /**
224
+ * A width function for one font: (text, sizePx) → px, by the browser's canvas.
225
+ * @param {{ font: string, weight?: string | number, style?: string, letterSpacing?: number }} f
226
+ * letterSpacing in em, like the product's CSS may have it
227
+ * @returns {(text: string, sizePx: number) => number}
228
+ */
229
+ export function measurer({ font, weight = 400, style = "normal", letterSpacing = 0 }) {
230
+ const c = context();
231
+ if (!c) throw new Error("look: no canvas to measure text with — pass measure(text, sizePx)");
232
+ const stack = fontStack(font);
233
+ /** @type {Map<string, number>} */
234
+ const cache = new Map();
235
+ return (text, sizePx) => {
236
+ const k = `${sizePx}|${text}`;
237
+ const hit = cache.get(k);
238
+ if (hit !== undefined) return hit;
239
+ c.font = `${style} ${weight} ${sizePx}px ${stack}`;
240
+ if ("letterSpacing" in c) c.letterSpacing = `${letterSpacing * sizePx}px`;
241
+ const w = c.measureText(text).width;
242
+ cache.set(k, w);
243
+ return w;
244
+ };
245
+ }
246
+
247
+ // CJK and the marks that must not begin a line (they cling to the unit before)
248
+ // or end one (they cling to the unit after) — the line-start/line-end rules
249
+ // Chinese and Japanese typesetting follow
250
+ const NO_START =
251
+ /^[、。,.,.;;::!!??)\]})]}」』】〉》〕〗〙〛・…‥ー〜~%%’”»›゛゜ゝゞヽヾぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ]/u;
252
+ const NO_END = /[([{([{「『【〈《〔〖〘〚‘“«‹$$¥£]$/u;
253
+ const CJK = /[⺀-鿿가-힯豈-﫿＀-￯\u{20000}-\u{3134f}]/u;
254
+
255
+ /**
256
+ * The text's units that a line can break between: words with the space after
257
+ * them, CJK phrases (Intl.Segmenter's words when `phrases`, else characters),
258
+ * marks attached by the line-start and line-end rules.
259
+ * @param {string} text
260
+ * @param {boolean} phrases
261
+ * @returns {string[]}
262
+ */
263
+ function units(text, phrases) {
264
+ /** @type {string[]} */
265
+ let segs = [];
266
+ const Seg = /** @type {any} */ (Intl).Segmenter;
267
+ if (Seg) {
268
+ const lang = CJK.test(text) ? (/[぀-ヿ]/.test(text) ? "ja" : "zh") : "en";
269
+ const s = new Seg(lang, { granularity: "word" });
270
+ for (const x of s.segment(text)) segs.push(x.segment);
271
+ } else segs = text.split(/(\s+)/).filter(Boolean);
272
+ // CJK runs broken into characters unless kept as phrases; Latin words kept
273
+ if (!phrases) segs = segs.flatMap((s) => (CJK.test(s) ? [...s] : [s]));
274
+ // no break inside Latin, numbers and their marks ("$3,176", "example.com"):
275
+ // only at a space, next to a CJK character, or after a dash
276
+ /** @type {string[]} */
277
+ const glued = [];
278
+ for (const s of segs) {
279
+ const prev = glued[glued.length - 1];
280
+ const last = prev ? ([...prev].pop() ?? "") : "";
281
+ const first = [...s][0] ?? "";
282
+ if (prev && !/\s/.test(last + first) && !CJK.test(last + first) && !/[-‐–—]/.test(last))
283
+ glued[glued.length - 1] = prev + s;
284
+ else glued.push(s);
285
+ }
286
+ /** @type {string[]} */
287
+ const out = [];
288
+ let carry = "";
289
+ for (const s of glued) {
290
+ if (/^\s+$/.test(s)) {
291
+ if (out.length) out[out.length - 1] += s;
292
+ continue;
293
+ }
294
+ if (NO_START.test(s) && out.length && !carry) {
295
+ out[out.length - 1] += s;
296
+ continue;
297
+ }
298
+ const u = carry + s;
299
+ carry = "";
300
+ if (NO_END.test(u)) {
301
+ carry = u;
302
+ continue;
303
+ }
304
+ out.push(u);
305
+ }
306
+ if (carry) out.push(carry);
307
+ return out;
308
+ }
309
+
310
+ /** a unit holding Latin letters or digits, which a character break would cut mid-word @param {string} u */
311
+ const wordy = (u) => /[\p{L}\p{N}]/u.test(u.replace(new RegExp(CJK.source, "gu"), ""));
312
+
313
+ /**
314
+ * breakLines, and whether it had to cut a Latin word or number by character.
315
+ * @param {string} text
316
+ * @param {number} maxWidth
317
+ * @param {(s: string) => number} widthOf
318
+ * @param {{ phrases?: boolean }} [opts]
319
+ * @returns {{ lines: string[], cut: boolean }}
320
+ */
321
+ function lineBreaks(text, maxWidth, widthOf, { phrases = true } = {}) {
322
+ /** @type {string[]} */
323
+ const lines = [];
324
+ let cut = false;
325
+ for (const para of String(text).split("\n")) {
326
+ let line = "";
327
+ const push = () => {
328
+ lines.push(line.trimEnd());
329
+ line = "";
330
+ };
331
+ /** too wide alone: by character @param {string} u */
332
+ const byChar = (u) => {
333
+ if (wordy(u)) cut = true;
334
+ for (const ch of u) {
335
+ if (line && widthOf((line + ch).trimEnd()) > maxWidth) push();
336
+ line += ch;
337
+ }
338
+ };
339
+ for (const u of units(para.trim(), phrases)) {
340
+ if (widthOf((line + u).trimEnd()) <= maxWidth || !line) {
341
+ if (!line && widthOf(u.trimEnd()) > maxWidth) byChar(u);
342
+ else line += u;
343
+ } else {
344
+ push();
345
+ if (widthOf(u.trimEnd()) > maxWidth) byChar(u);
346
+ else line = u;
347
+ }
348
+ }
349
+ push();
350
+ }
351
+ return { lines, cut };
352
+ }
353
+
354
+ /**
355
+ * Lines of `text` no wider than `maxWidth` by `widthOf`: greedy, a unit wider
356
+ * than the line broken by character. "\n" always breaks.
357
+ * @param {string} text
358
+ * @param {number} maxWidth
359
+ * @param {(s: string) => number} widthOf
360
+ * @param {{ phrases?: boolean }} [opts]
361
+ * @returns {string[]}
362
+ */
363
+ export function breakLines(text, maxWidth, widthOf, opts) {
364
+ return lineBreaks(text, maxWidth, widthOf, opts).lines;
365
+ }
366
+
367
+ /**
368
+ * The same number of lines, as even as they go: the narrowest width that
369
+ * still breaks into as many lines as `maxWidth` does, cutting no word that
370
+ * `maxWidth` leaves whole.
371
+ * @param {string} text
372
+ * @param {number} maxWidth
373
+ * @param {(s: string) => number} widthOf
374
+ * @param {{ phrases?: boolean }} [opts]
375
+ */
376
+ function balancedLines(text, maxWidth, widthOf, opts) {
377
+ const first = lineBreaks(text, maxWidth, widthOf, opts);
378
+ if (first.lines.length < 2) return first;
379
+ let lo = maxWidth / first.lines.length;
380
+ let hi = maxWidth;
381
+ let best = first;
382
+ for (let i = 0; i < 14; i++) {
383
+ const mid = (lo + hi) / 2;
384
+ const l = lineBreaks(text, mid, widthOf, opts);
385
+ if (l.lines.length <= first.lines.length && (first.cut || !l.cut)) {
386
+ best = l;
387
+ hi = mid;
388
+ } else lo = mid;
389
+ }
390
+ return best;
391
+ }
392
+
393
+ /**
394
+ * @typedef {object} FitOptions
395
+ * @property {string} [font] family name or CSS stack (needed unless `measure` is given)
396
+ * @property {string | number} [weight] default 400
397
+ * @property {string} [style] default "normal"
398
+ * @property {number} [min] smallest size tried, px (default 8)
399
+ * @property {number} [max] biggest size tried, px (default the box height)
400
+ * @property {number} [lines] at most this many lines (default: as many as fit)
401
+ * @property {number} [lineHeight] line box as a multiple of the size (default 1.15)
402
+ * @property {number} [letterSpacing] in em (default 0)
403
+ * @property {boolean} [balance] even out the lines (default true)
404
+ * @property {boolean} [phrases] keep CJK words whole across lines (default true)
405
+ * @property {number} [step] sizes are whole multiples of this (default 0.5 px)
406
+ * @property {(text: string, sizePx: number) => number} [measure] your own width function
407
+ */
408
+
409
+ /**
410
+ * The biggest size `text` can be set at inside `box` and its lines there.
411
+ * `fits: false` means even `min` does not fit — the result is at `min`,
412
+ * overflowing. Height counts `lineHeight` per line.
413
+ * @param {Size} box
414
+ * @param {string} text
415
+ * @param {FitOptions} [opts]
416
+ */
417
+ export function fitText(box, text, opts = {}) {
418
+ const {
419
+ font = "sans-serif",
420
+ weight = 400,
421
+ style = "normal",
422
+ min = 8,
423
+ max = box.height,
424
+ lines: maxLines,
425
+ lineHeight = 1.15,
426
+ letterSpacing = 0,
427
+ balance = true,
428
+ phrases = true,
429
+ step = 0.5,
430
+ } = opts;
431
+ if (!(box.width > 0 && box.height > 0))
432
+ throw new Error("fitText: the box needs a width and a height above 0");
433
+ const measure = opts.measure ?? measurer({ font, weight, style, letterSpacing });
434
+ /** @param {number} size */
435
+ const layout = (size) => {
436
+ /** @param {string} s */
437
+ const w = (s) => measure(s, size);
438
+ const { lines: ls, cut } = balance
439
+ ? balancedLines(text, box.width, w, { phrases })
440
+ : lineBreaks(text, box.width, w, { phrases });
441
+ const widest = Math.max(0, ...ls.map(w));
442
+ return { lines: ls, cut, width: widest, height: ls.length * size * lineHeight };
443
+ };
444
+ // a Latin word or number is cut by character only when no size from `min`
445
+ // up fits it whole
446
+ let whole = true;
447
+ /** @param {ReturnType<typeof layout>} l */
448
+ const ok = (l) =>
449
+ l.width <= box.width + 0.01 &&
450
+ l.height <= box.height + 0.01 &&
451
+ (maxLines == null || l.lines.length <= maxLines) &&
452
+ !(whole && l.cut);
453
+ if (!ok(layout(min))) whole = false;
454
+ let lo = min;
455
+ let hi = Math.max(min, max);
456
+ let found = ok(layout(lo));
457
+ if (found && ok(layout(hi))) lo = hi;
458
+ else if (found)
459
+ while (hi - lo > step / 2) {
460
+ const mid = (lo + hi) / 2;
461
+ if (ok(layout(mid))) lo = mid;
462
+ else hi = mid;
463
+ }
464
+ // the search ends within half a step of the edge: take the biggest whole step that fits
465
+ let size = Math.max(min, Math.floor(lo / step) * step);
466
+ for (let s = Math.floor(hi / step) * step; s > size; s -= step)
467
+ if (ok(layout(s))) {
468
+ size = s;
469
+ break;
470
+ }
471
+ const l = layout(size);
472
+ whole = false;
473
+ found = ok(l);
474
+ const stack = fontStack(font);
475
+ return {
476
+ size,
477
+ lines: l.lines,
478
+ /** px between baselines */
479
+ lineHeight: size * lineHeight,
480
+ width: l.width,
481
+ height: l.height,
482
+ fits: found,
483
+ /** the CSS font shorthand at that size */
484
+ font: `${style} ${weight} ${size}px/${lineHeight} ${stack}`,
485
+ readable: readable(size),
486
+ };
487
+ }
488
+
489
+ // --- the product's look -----------------------------------------------------------
490
+
491
+ /**
492
+ * look.json, fetched (written by `npx open-take film look`).
493
+ * @param {string} [url]
494
+ */
495
+ export async function loadLook(url = "look/look.json") {
496
+ const r = await fetch(url);
497
+ if (!r.ok)
498
+ throw new Error(
499
+ `look: ${url} answered ${r.status} — run npx open-take film look <take|url> --out look`,
500
+ );
501
+ return r.json();
502
+ }
503
+
504
+ /**
505
+ * The product's colours and fonts from a look.json, by role. Every role is the
506
+ * reader's estimate (look.json says why for each); `null` where none was found.
507
+ * @param {any} look
508
+ */
509
+ export function palette(look) {
510
+ /** @type {Record<string, string | null>} */
511
+ const roles = {};
512
+ for (const [k, r] of Object.entries(look?.roles ?? {}))
513
+ roles[k] = /** @type {any} */ (r)?.hex ?? null;
514
+ /** @type {string[]} */
515
+ const fonts = (look?.fonts ?? [])
516
+ .filter((/** @type {any} */ f) => f.webfont)
517
+ .map((/** @type {any} */ f) => f.family);
518
+ /** @type {string[]} */
519
+ const colours = (look?.colours ?? []).map((/** @type {any} */ c) => c.hex);
520
+ return {
521
+ ...roles,
522
+ roles,
523
+ colours,
524
+ fonts,
525
+ /** a role's colour, or `fallback` when the reader found none @param {string} role @param {string} [fallback] */
526
+ get: (role, fallback) => roles[role] ?? fallback ?? null,
527
+ /** the i-th font family the product's text is set in (by characters), as a CSS stack @param {number} [i] */
528
+ font: (i = 0) => (fonts[i] ? fontStack(fonts[i]) : "sans-serif"),
529
+ /** the product's colours by contrast on `ground`, most first @param {string} ground */
530
+ byContrast: (ground) =>
531
+ colours
532
+ .map((hex) => ({ hex, contrast: contrast(hex, ground) }))
533
+ .sort((a, b) => b.contrast - a.contrast),
534
+ /** the roles as CSS custom properties: "--look-bg: #fff; …" @param {string} [prefix] */
535
+ css: (prefix = "--look-") =>
536
+ Object.entries(roles)
537
+ .filter(([, v]) => v)
538
+ .map(([k, v]) => `${prefix}${k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}: ${v};`)
539
+ .join(" "),
540
+ };
541
+ }
542
+
543
+ /** the largest blur in a box-shadow list (px), to rank shadows by @param {string} v */
544
+ function shadowBlur(v) {
545
+ let most = 0;
546
+ for (const layer of v.split(/,(?![^(]*\))/)) {
547
+ const px = [...layer.matchAll(/(-?[\d.]+)px/g)].map((m) => Number(m[1]));
548
+ if (px.length >= 3) most = Math.max(most, px[2] ?? 0);
549
+ }
550
+ return most;
551
+ }
552
+
553
+ /**
554
+ * The product's own surface, for a picture of it shown as an object: the
555
+ * corner of its roundest card (look.json `radii`, pills and circles aside),
556
+ * its softest shadow (`shadows`, by blur), and a margin of its own ground
557
+ * (`roles.surface`, else `bg`) — so a screenshot reads as the product's
558
+ * card, not a sheet cut flush. Each is null when the product has none; the
559
+ * margin is the corner's size unless `pad` says. Nothing is applied: put
560
+ * `style` on the picture (or its wrapper) where the film wants it.
561
+ * @param {any} look a look.json
562
+ * @param {{ pad?: number }} [o]
563
+ * @returns {{ radius: number | null, shadow: string | null, ground: string | null, pad: number,
564
+ * style: Record<string, string> }}
565
+ */
566
+ export function frame(look, o = {}) {
567
+ const radii = (look?.radii ?? []).filter(
568
+ (/** @type {any} */ r) => Number.isFinite(r?.px) && r.value !== "pill" && r.value !== "circle",
569
+ );
570
+ const radius = radii.length ? Math.max(...radii.map((/** @type {any} */ r) => r.px)) : null;
571
+ const shadows = (look?.shadows ?? []).filter(
572
+ (/** @type {any} */ x) => typeof x?.value === "string",
573
+ );
574
+ const shadow = shadows.length
575
+ ? shadows.reduce((/** @type {any} */ a, /** @type {any} */ b) =>
576
+ shadowBlur(b.value) > shadowBlur(a.value) ? b : a,
577
+ ).value
578
+ : null;
579
+ const ground = look?.roles?.surface?.hex ?? look?.roles?.bg?.hex ?? null;
580
+ const pad = o.pad ?? radius ?? 0;
581
+ /** @type {Record<string, string>} */
582
+ const style = {};
583
+ if (radius != null) style.borderRadius = `${radius}px`;
584
+ if (shadow) style.boxShadow = shadow;
585
+ if (pad) style.padding = `${pad}px`;
586
+ if (ground) style.background = ground;
587
+ if (radius != null || pad) style.overflow = "hidden";
588
+ return { radius, shadow, ground, pad, style };
589
+ }