@aphexcms/cms-core 9.9.0 → 10.0.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 (324) hide show
  1. package/dist/api/assets.d.ts +62 -7
  2. package/dist/api/assets.d.ts.map +1 -1
  3. package/dist/api/assets.js +116 -9
  4. package/dist/api/client.d.ts +1 -1
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/client.js +39 -9
  7. package/dist/api/limits.d.ts +55 -0
  8. package/dist/api/limits.d.ts.map +1 -0
  9. package/dist/api/limits.js +58 -0
  10. package/dist/api/schemas/assets.d.ts +94 -4
  11. package/dist/api/schemas/assets.d.ts.map +1 -1
  12. package/dist/api/schemas/assets.js +82 -5
  13. package/dist/api/schemas/documents.d.ts +1 -0
  14. package/dist/api/schemas/documents.d.ts.map +1 -1
  15. package/dist/api/schemas/documents.js +1 -0
  16. package/dist/api/types.d.ts +25 -0
  17. package/dist/api/types.d.ts.map +1 -1
  18. package/dist/api/upload-timeout.d.ts +17 -0
  19. package/dist/api/upload-timeout.d.ts.map +1 -0
  20. package/dist/api/upload-timeout.js +35 -0
  21. package/dist/api/upload.d.ts +42 -0
  22. package/dist/api/upload.d.ts.map +1 -0
  23. package/dist/api/upload.js +144 -0
  24. package/dist/components/AdminApp.svelte +213 -32
  25. package/dist/components/AdminApp.svelte.d.ts.map +1 -1
  26. package/dist/components/admin/AssetBrowserModal.svelte +4 -3
  27. package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
  28. package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
  29. package/dist/components/admin/MediaBrowser.svelte +1859 -281
  30. package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
  31. package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
  32. package/dist/components/admin/fields/ArrayField.svelte +21 -10
  33. package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
  34. package/dist/components/admin/fields/FileField.svelte +9 -2
  35. package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
  36. package/dist/components/admin/fields/ImageField.svelte +47 -12
  37. package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +14 -0
  40. package/dist/db/interfaces/asset.d.ts +114 -5
  41. package/dist/db/interfaces/asset.d.ts.map +1 -1
  42. package/dist/db/interfaces/document.d.ts +107 -3
  43. package/dist/db/interfaces/document.d.ts.map +1 -1
  44. package/dist/hooks.d.ts.map +1 -1
  45. package/dist/hooks.js +2 -1
  46. package/dist/image/Image.svelte +72 -0
  47. package/dist/image/Image.svelte.d.ts +40 -0
  48. package/dist/image/Image.svelte.d.ts.map +1 -0
  49. package/dist/image/index.d.ts +3 -0
  50. package/dist/image/index.d.ts.map +1 -0
  51. package/dist/image/index.js +11 -0
  52. package/dist/image/types.d.ts +28 -0
  53. package/dist/image/types.d.ts.map +1 -0
  54. package/dist/image/types.js +1 -0
  55. package/dist/images/generate.d.ts +55 -0
  56. package/dist/images/generate.d.ts.map +1 -0
  57. package/dist/images/generate.js +243 -0
  58. package/dist/images/index.d.ts +2 -0
  59. package/dist/images/index.d.ts.map +1 -0
  60. package/dist/images/index.js +7 -0
  61. package/dist/images/variants.d.ts +82 -0
  62. package/dist/images/variants.d.ts.map +1 -0
  63. package/dist/images/variants.js +124 -0
  64. package/dist/jobs/asset-reference-jobs.d.ts +49 -0
  65. package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
  66. package/dist/jobs/asset-reference-jobs.js +74 -0
  67. package/dist/jobs/run-batch.d.ts.map +1 -1
  68. package/dist/jobs/run-batch.js +5 -0
  69. package/dist/lib/api/assets.d.ts +62 -7
  70. package/dist/lib/api/assets.d.ts.map +1 -1
  71. package/dist/lib/api/assets.js +116 -9
  72. package/dist/lib/api/assets.js.map +1 -1
  73. package/dist/lib/api/client.d.ts +1 -1
  74. package/dist/lib/api/client.d.ts.map +1 -1
  75. package/dist/lib/api/client.js +39 -9
  76. package/dist/lib/api/client.js.map +1 -1
  77. package/dist/lib/api/limits.d.ts +55 -0
  78. package/dist/lib/api/limits.d.ts.map +1 -0
  79. package/dist/lib/api/limits.js +59 -0
  80. package/dist/lib/api/limits.js.map +1 -0
  81. package/dist/lib/api/schemas/assets.d.ts +94 -4
  82. package/dist/lib/api/schemas/assets.d.ts.map +1 -1
  83. package/dist/lib/api/schemas/assets.js +82 -5
  84. package/dist/lib/api/schemas/assets.js.map +1 -1
  85. package/dist/lib/api/schemas/documents.d.ts +1 -0
  86. package/dist/lib/api/schemas/documents.d.ts.map +1 -1
  87. package/dist/lib/api/schemas/documents.js +1 -0
  88. package/dist/lib/api/schemas/documents.js.map +1 -1
  89. package/dist/lib/api/types.d.ts +25 -0
  90. package/dist/lib/api/types.d.ts.map +1 -1
  91. package/dist/lib/api/upload-timeout.d.ts +17 -0
  92. package/dist/lib/api/upload-timeout.d.ts.map +1 -0
  93. package/dist/lib/api/upload-timeout.js +36 -0
  94. package/dist/lib/api/upload-timeout.js.map +1 -0
  95. package/dist/lib/api/upload.d.ts +42 -0
  96. package/dist/lib/api/upload.d.ts.map +1 -0
  97. package/dist/lib/api/upload.js +145 -0
  98. package/dist/lib/api/upload.js.map +1 -0
  99. package/dist/lib/config.d.ts.map +1 -1
  100. package/dist/lib/config.js +14 -0
  101. package/dist/lib/config.js.map +1 -1
  102. package/dist/lib/db/interfaces/asset.d.ts +114 -5
  103. package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
  104. package/dist/lib/db/interfaces/document.d.ts +107 -3
  105. package/dist/lib/db/interfaces/document.d.ts.map +1 -1
  106. package/dist/lib/hooks.d.ts.map +1 -1
  107. package/dist/lib/hooks.js +2 -1
  108. package/dist/lib/hooks.js.map +1 -1
  109. package/dist/lib/image/index.d.ts +3 -0
  110. package/dist/lib/image/index.d.ts.map +1 -0
  111. package/dist/lib/image/index.js +12 -0
  112. package/dist/lib/image/index.js.map +1 -0
  113. package/dist/lib/image/types.d.ts +28 -0
  114. package/dist/lib/image/types.d.ts.map +1 -0
  115. package/dist/lib/image/types.js +2 -0
  116. package/dist/lib/image/types.js.map +1 -0
  117. package/dist/lib/images/generate.d.ts +55 -0
  118. package/dist/lib/images/generate.d.ts.map +1 -0
  119. package/dist/lib/images/generate.js +244 -0
  120. package/dist/lib/images/generate.js.map +1 -0
  121. package/dist/lib/images/index.d.ts +2 -0
  122. package/dist/lib/images/index.d.ts.map +1 -0
  123. package/dist/lib/images/index.js +8 -0
  124. package/dist/lib/images/index.js.map +1 -0
  125. package/dist/lib/images/variants.d.ts +82 -0
  126. package/dist/lib/images/variants.d.ts.map +1 -0
  127. package/dist/lib/images/variants.js +125 -0
  128. package/dist/lib/images/variants.js.map +1 -0
  129. package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
  130. package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
  131. package/dist/lib/jobs/asset-reference-jobs.js +75 -0
  132. package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
  133. package/dist/lib/jobs/run-batch.d.ts.map +1 -1
  134. package/dist/lib/jobs/run-batch.js +5 -0
  135. package/dist/lib/jobs/run-batch.js.map +1 -1
  136. package/dist/lib/local-api/collection-api.d.ts +25 -2
  137. package/dist/lib/local-api/collection-api.d.ts.map +1 -1
  138. package/dist/lib/local-api/collection-api.js +107 -20
  139. package/dist/lib/local-api/collection-api.js.map +1 -1
  140. package/dist/lib/preview/assets.d.ts +19 -0
  141. package/dist/lib/preview/assets.d.ts.map +1 -1
  142. package/dist/lib/preview/assets.js +6 -0
  143. package/dist/lib/preview/assets.js.map +1 -1
  144. package/dist/lib/routes/assets-cdn.d.ts +19 -0
  145. package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
  146. package/dist/lib/routes/assets-cdn.js +295 -17
  147. package/dist/lib/routes/assets-cdn.js.map +1 -1
  148. package/dist/lib/schema-utils/utils.d.ts +31 -1
  149. package/dist/lib/schema-utils/utils.d.ts.map +1 -1
  150. package/dist/lib/schema-utils/utils.js +68 -0
  151. package/dist/lib/schema-utils/utils.js.map +1 -1
  152. package/dist/lib/server/api/index.d.ts.map +1 -1
  153. package/dist/lib/server/api/index.js +87 -8
  154. package/dist/lib/server/api/index.js.map +1 -1
  155. package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
  156. package/dist/lib/server/api/routes/assets-bulk.js +36 -7
  157. package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
  158. package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
  159. package/dist/lib/server/api/routes/assets-by-id.js +32 -15
  160. package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
  161. package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
  162. package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  163. package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
  164. package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
  165. package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
  166. package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
  167. package/dist/lib/server/api/routes/assets-poster.js +120 -0
  168. package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
  169. package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
  170. package/dist/lib/server/api/routes/assets-references.js +64 -5
  171. package/dist/lib/server/api/routes/assets-references.js.map +1 -1
  172. package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
  173. package/dist/lib/server/api/routes/assets.js +116 -12
  174. package/dist/lib/server/api/routes/assets.js.map +1 -1
  175. package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
  176. package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
  177. package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
  178. package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
  179. package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
  180. package/dist/lib/server/api/routes/documents.js +28 -1
  181. package/dist/lib/server/api/routes/documents.js.map +1 -1
  182. package/dist/lib/server/index.d.ts +2 -0
  183. package/dist/lib/server/index.d.ts.map +1 -1
  184. package/dist/lib/server/index.js +4 -0
  185. package/dist/lib/server/index.js.map +1 -1
  186. package/dist/lib/services/asset-references-service.d.ts +93 -0
  187. package/dist/lib/services/asset-references-service.d.ts.map +1 -0
  188. package/dist/lib/services/asset-references-service.js +198 -0
  189. package/dist/lib/services/asset-references-service.js.map +1 -0
  190. package/dist/lib/services/asset-service.d.ts +115 -14
  191. package/dist/lib/services/asset-service.d.ts.map +1 -1
  192. package/dist/lib/services/asset-service.js +312 -31
  193. package/dist/lib/services/asset-service.js.map +1 -1
  194. package/dist/lib/services/references-service.d.ts +19 -15
  195. package/dist/lib/services/references-service.d.ts.map +1 -1
  196. package/dist/lib/services/references-service.js +59 -31
  197. package/dist/lib/services/references-service.js.map +1 -1
  198. package/dist/lib/services/version-service.d.ts +10 -1
  199. package/dist/lib/services/version-service.d.ts.map +1 -1
  200. package/dist/lib/services/version-service.js +26 -4
  201. package/dist/lib/services/version-service.js.map +1 -1
  202. package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
  203. package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  204. package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
  205. package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
  206. package/dist/lib/storage/index.d.ts +1 -0
  207. package/dist/lib/storage/index.d.ts.map +1 -1
  208. package/dist/lib/storage/index.js +2 -0
  209. package/dist/lib/storage/index.js.map +1 -1
  210. package/dist/lib/storage/interfaces/storage.d.ts +135 -5
  211. package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
  212. package/dist/lib/storage/keys.d.ts +96 -0
  213. package/dist/lib/storage/keys.d.ts.map +1 -0
  214. package/dist/lib/storage/keys.js +160 -0
  215. package/dist/lib/storage/keys.js.map +1 -0
  216. package/dist/lib/type-gen.d.ts.map +1 -1
  217. package/dist/lib/type-gen.js +11 -5
  218. package/dist/lib/type-gen.js.map +1 -1
  219. package/dist/lib/types/asset.d.ts +92 -12
  220. package/dist/lib/types/asset.d.ts.map +1 -1
  221. package/dist/lib/types/capabilities.d.ts +11 -0
  222. package/dist/lib/types/capabilities.d.ts.map +1 -1
  223. package/dist/lib/types/capabilities.js +20 -6
  224. package/dist/lib/types/capabilities.js.map +1 -1
  225. package/dist/lib/types/config.d.ts +127 -0
  226. package/dist/lib/types/config.d.ts.map +1 -1
  227. package/dist/lib/types/filters.d.ts +31 -0
  228. package/dist/lib/types/filters.d.ts.map +1 -1
  229. package/dist/lib/types/schemas.d.ts +14 -0
  230. package/dist/lib/types/schemas.d.ts.map +1 -1
  231. package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
  232. package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
  233. package/dist/lib/utils/asset-reference-walk.js +144 -0
  234. package/dist/lib/utils/asset-reference-walk.js.map +1 -0
  235. package/dist/lib/utils/image-url.d.ts +61 -26
  236. package/dist/lib/utils/image-url.d.ts.map +1 -1
  237. package/dist/lib/utils/image-url.js +143 -26
  238. package/dist/lib/utils/image-url.js.map +1 -1
  239. package/dist/lib/utils/video-metadata.d.ts +39 -0
  240. package/dist/lib/utils/video-metadata.d.ts.map +1 -0
  241. package/dist/lib/utils/video-metadata.js +161 -0
  242. package/dist/lib/utils/video-metadata.js.map +1 -0
  243. package/dist/local-api/collection-api.d.ts +25 -2
  244. package/dist/local-api/collection-api.d.ts.map +1 -1
  245. package/dist/local-api/collection-api.js +107 -20
  246. package/dist/preview/assets.d.ts +19 -0
  247. package/dist/preview/assets.d.ts.map +1 -1
  248. package/dist/preview/assets.js +6 -0
  249. package/dist/routes/assets-cdn.d.ts +19 -0
  250. package/dist/routes/assets-cdn.d.ts.map +1 -1
  251. package/dist/routes/assets-cdn.js +295 -17
  252. package/dist/schema-utils/utils.d.ts +31 -1
  253. package/dist/schema-utils/utils.d.ts.map +1 -1
  254. package/dist/schema-utils/utils.js +68 -0
  255. package/dist/server/api/index.d.ts.map +1 -1
  256. package/dist/server/api/index.js +87 -8
  257. package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
  258. package/dist/server/api/routes/assets-bulk.js +36 -7
  259. package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
  260. package/dist/server/api/routes/assets-by-id.js +32 -15
  261. package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
  262. package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  263. package/dist/server/api/routes/assets-direct-upload.js +163 -0
  264. package/dist/server/api/routes/assets-poster.d.ts +4 -0
  265. package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
  266. package/dist/server/api/routes/assets-poster.js +119 -0
  267. package/dist/server/api/routes/assets-references.d.ts.map +1 -1
  268. package/dist/server/api/routes/assets-references.js +64 -5
  269. package/dist/server/api/routes/assets.d.ts.map +1 -1
  270. package/dist/server/api/routes/assets.js +116 -12
  271. package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
  272. package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
  273. package/dist/server/api/routes/clear-asset-references.js +31 -0
  274. package/dist/server/api/routes/documents.d.ts.map +1 -1
  275. package/dist/server/api/routes/documents.js +28 -1
  276. package/dist/server/index.d.ts +2 -0
  277. package/dist/server/index.d.ts.map +1 -1
  278. package/dist/server/index.js +4 -0
  279. package/dist/services/asset-references-service.d.ts +93 -0
  280. package/dist/services/asset-references-service.d.ts.map +1 -0
  281. package/dist/services/asset-references-service.js +197 -0
  282. package/dist/services/asset-service.d.ts +115 -14
  283. package/dist/services/asset-service.d.ts.map +1 -1
  284. package/dist/services/asset-service.js +312 -31
  285. package/dist/services/references-service.d.ts +19 -15
  286. package/dist/services/references-service.d.ts.map +1 -1
  287. package/dist/services/references-service.js +59 -31
  288. package/dist/services/version-service.d.ts +10 -1
  289. package/dist/services/version-service.d.ts.map +1 -1
  290. package/dist/services/version-service.js +26 -4
  291. package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
  292. package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  293. package/dist/storage/adapters/local-storage-adapter.js +86 -19
  294. package/dist/storage/index.d.ts +1 -0
  295. package/dist/storage/index.d.ts.map +1 -1
  296. package/dist/storage/index.js +2 -0
  297. package/dist/storage/interfaces/storage.d.ts +135 -5
  298. package/dist/storage/interfaces/storage.d.ts.map +1 -1
  299. package/dist/storage/keys.d.ts +96 -0
  300. package/dist/storage/keys.d.ts.map +1 -0
  301. package/dist/storage/keys.js +159 -0
  302. package/dist/type-gen.d.ts.map +1 -1
  303. package/dist/type-gen.js +11 -5
  304. package/dist/types/asset.d.ts +92 -12
  305. package/dist/types/asset.d.ts.map +1 -1
  306. package/dist/types/capabilities.d.ts +11 -0
  307. package/dist/types/capabilities.d.ts.map +1 -1
  308. package/dist/types/capabilities.js +20 -6
  309. package/dist/types/config.d.ts +127 -0
  310. package/dist/types/config.d.ts.map +1 -1
  311. package/dist/types/filters.d.ts +31 -0
  312. package/dist/types/filters.d.ts.map +1 -1
  313. package/dist/types/schemas.d.ts +14 -0
  314. package/dist/types/schemas.d.ts.map +1 -1
  315. package/dist/utils/asset-reference-walk.d.ts +44 -0
  316. package/dist/utils/asset-reference-walk.d.ts.map +1 -0
  317. package/dist/utils/asset-reference-walk.js +143 -0
  318. package/dist/utils/image-url.d.ts +61 -26
  319. package/dist/utils/image-url.d.ts.map +1 -1
  320. package/dist/utils/image-url.js +143 -26
  321. package/dist/utils/video-metadata.d.ts +39 -0
  322. package/dist/utils/video-metadata.d.ts.map +1 -0
  323. package/dist/utils/video-metadata.js +160 -0
  324. package/package.json +6 -1
@@ -23,40 +23,73 @@ export declare class ImageUrlBuilder {
23
23
  */
24
24
  image(source: ImageValue | ImageAsset | string | Asset | null | undefined): this;
25
25
  /**
26
- * Set width (for future dynamic image rendering)
26
+ * Request a rendered width in pixels.
27
+ *
28
+ * Snaps to the narrowest generated variant that covers it — the ladder is a
29
+ * closed allowlist, so `width(333)` returns the 640px rung rather than a
30
+ * 333px image. Asking for a width no variant covers returns the widest one.
27
31
  */
28
32
  width(width: number): this;
29
33
  /**
30
- * Set height (for future dynamic image rendering)
34
+ * Request a rendered height in pixels.
35
+ *
36
+ * Honoured only as a *width* request: derivatives are resized by width and
37
+ * keep the original's aspect ratio, so this converts through the asset's
38
+ * intrinsic dimensions and then snaps like {@link width}. Without those
39
+ * dimensions there's nothing to convert through and it's ignored.
31
40
  */
32
41
  height(height: number): this;
33
42
  /**
34
- * Set both width and height (for future dynamic image rendering)
43
+ * Set both dimensions. Width wins — see {@link height}; nothing crops.
35
44
  */
36
45
  size(width: number, height: number): this;
37
46
  /**
38
- * Set quality (for future dynamic image rendering)
47
+ * @deprecated No effect. Quality is a property of the pipeline, not the URL:
48
+ * it's set once via `images.quality` and hashed into every variant filename,
49
+ * which is what lets variants be cached immutably. A per-URL override would
50
+ * mean generating and storing a second copy of every image per quality value
51
+ * any caller ever passed.
39
52
  */
40
53
  quality(quality: number): this;
41
54
  /**
42
- * Set format (for future dynamic image rendering)
55
+ * @deprecated No effect. Every derivative is WebP; the original is served in
56
+ * whatever format it was uploaded as. Transcoding on request would reopen the
57
+ * unbounded-generation hole the width allowlist exists to close.
43
58
  */
44
59
  format(format: 'jpg' | 'jpeg' | 'png' | 'webp' | 'avif'): this;
45
60
  /**
46
- * Set fit mode (for future dynamic image rendering)
61
+ * @deprecated No effect. Derivatives are width-resized and preserve aspect
62
+ * ratio, so there is no second dimension for a fit mode to act on. Per-preset
63
+ * `fit`/`aspectRatio` is post-V1, and lands on top of focal points.
47
64
  */
48
65
  fit(fit: 'cover' | 'contain' | 'fill' | 'inside' | 'outside'): this;
49
66
  /**
50
- * Enable automatic format selection (for future dynamic image rendering)
67
+ * @deprecated No effect, and already the behaviour: variants are always WebP.
51
68
  */
52
69
  auto(mode: 'format'): this;
53
70
  /**
54
- * Build the final URL
55
- * Returns /api/assets/{id}?dl=1 which redirects to the actual S3/R2 URL
56
- * Transformations (.width(), .quality(), etc) are stored but not yet applied
71
+ * The requested width, converting a height request through the asset's own
72
+ * aspect ratio.
73
+ *
74
+ * Width wins when both are set: a derivative is only ever resized by width,
75
+ * so honouring a height as well would require cropping — which the V1
76
+ * pipeline deliberately doesn't do.
77
+ */
78
+ private targetWidth;
79
+ /** The ladder variant covering the requested size, if one can be resolved. */
80
+ private snappedUrl;
81
+ /**
82
+ * Build the final URL.
83
+ *
84
+ * With a width (or a height that can be converted to one) and an injected
85
+ * `srcset`, this returns the variant URL for the nearest covering rung.
86
+ * Otherwise it returns the asset's own URL — the full-size original.
57
87
  *
58
- * For multi-tenant access, use signAssetUrl config to generate signed URLs
59
- * TODO: Add dynamic image rendering support
88
+ * **Prefer `<Image>` for anything rendered.** This returns one fixed URL, so
89
+ * it can't respond to viewport or device pixel ratio; `<Image>` emits the
90
+ * whole `srcset` and lets the browser choose. Reach for this when you need a
91
+ * bare string and the size is genuinely fixed — an OG image, an email, a
92
+ * canvas or PDF source.
60
93
  */
61
94
  url(): string | null;
62
95
  /**
@@ -65,24 +98,26 @@ export declare class ImageUrlBuilder {
65
98
  toString(): string | null;
66
99
  }
67
100
  /**
68
- * Factory function to create an image URL builder
101
+ * Factory for a Sanity-style image URL builder.
69
102
  *
70
- * Note: Currently returns direct S3/R2 URLs without transformations.
71
- * The baseUrl parameter is accepted for future compatibility but not currently used
72
- * since assets already contain their full public URLs.
103
+ * ```ts
104
+ * const urlFor = imageUrlBuilder();
105
+ * urlFor(post.coverImage).width(800).url(); // → the 960px rung
106
+ * urlFor(post.coverImage).url(); // → the original
107
+ * ```
73
108
  *
74
- * For multi-tenant access with API keys, provide a signAssetUrl function:
75
- * const urlFor = imageUrlBuilder({
76
- * signAssetUrl: (assetId) => `/api/assets/${assetId}?token=${generateToken(assetId)}`
77
- * })
109
+ * `width` snaps to the nearest generated variant that covers it, read off the
110
+ * `srcset` that `injectAssetUrls` attached — so the source must have been
111
+ * through injection (any value from the Local API, a load function, or GraphQL
112
+ * has been). Without a width, or without a srcset, you get the original.
78
113
  *
79
- * Usage:
80
- * const urlFor = imageUrlBuilder({ baseUrl: 'https://yourdomain.com' })
81
- * const url = urlFor(image).url() // Returns asset.url directly
114
+ * Takes no arguments. It previously documented a `baseUrl` and a `signAssetUrl`
115
+ * hook, neither of which the function ever accepted — assets carry their own
116
+ * urls, and `/media/:id/:filename` handles access control centrally rather than
117
+ * through per-caller signing. Signed delivery is `config.signedDownloads`.
82
118
  *
83
- * Future usage with transformations:
84
- * const url = urlFor(image).width(800).quality(80).url()
85
- * // Will return transformed image once dynamic rendering is implemented
119
+ * `quality`, `format`, `fit` and `auto` remain on the builder for source
120
+ * compatibility but are deprecated no-ops; see each one for why.
86
121
  */
87
122
  export declare function imageUrlBuilder(): (source?: ImageValue | ImageAsset | string | Asset | null) => ImageUrlBuilder;
88
123
  //# sourceMappingURL=image-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-url.d.ts","sourceRoot":"","sources":["../../src/lib/utils/image-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGpE,MAAM,WAAW,sBAAsB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AA8BD,qBAAa,eAAe;IAC3B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,QAAQ,CAA8B;IAE9C;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAKhF;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMzC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK9B;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI;IAK9D;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI;IAKnE;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAK1B;;;;;;;OAOG;IACH,GAAG,IAAI,MAAM,GAAG,IAAI;IA0CpB;;OAEG;IACH,QAAQ,IAAI,MAAM,GAAG,IAAI;CAGzB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,KACtB,SAAS,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,qBAOhE"}
1
+ {"version":3,"file":"image-url.d.ts","sourceRoot":"","sources":["../../src/lib/utils/image-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGpE,MAAM,WAAW,sBAAsB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AA2FD,qBAAa,eAAe;IAC3B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,QAAQ,CAA8B;IAE9C;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAKhF;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMzC;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK9B;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI;IAK9D;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI;IAKnE;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAK1B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IAUnB,8EAA8E;IAC9E,OAAO,CAAC,UAAU;IAclB;;;;;;;;;;;;OAYG;IACH,GAAG,IAAI,MAAM,GAAG,IAAI;IAgDpB;;OAEG;IACH,QAAQ,IAAI,MAAM,GAAG,IAAI;CAGzB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,KACtB,SAAS,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,qBAOhE"}
@@ -23,6 +23,61 @@ function extractUrl(source) {
23
23
  }
24
24
  return null;
25
25
  }
26
+ /**
27
+ * The `srcset` injection attached to this source, if any.
28
+ *
29
+ * Mirrors {@link extractUrl}'s shape-sniffing because the same call accepts a
30
+ * bare url string, an `Asset`, an `ImageAsset`, or an `ImageValue`.
31
+ */
32
+ function extractSrcset(source) {
33
+ if (!source || typeof source !== 'object')
34
+ return null;
35
+ if (typeof source.srcset === 'string')
36
+ return source.srcset;
37
+ if (source.asset && typeof source.asset.srcset === 'string')
38
+ return source.asset.srcset;
39
+ return null;
40
+ }
41
+ /** Intrinsic dimensions, used to turn a height request into a width. */
42
+ function extractDimensions(source) {
43
+ const target = source && typeof source === 'object' ? (source.asset ?? source) : null;
44
+ if (!target || typeof target !== 'object')
45
+ return {};
46
+ return {
47
+ width: typeof target.width === 'number' ? target.width : undefined,
48
+ height: typeof target.height === 'number' ? target.height : undefined
49
+ };
50
+ }
51
+ /**
52
+ * Parse a `srcset` into its width candidates, smallest first.
53
+ *
54
+ * This is what makes snapping trustworthy: the srcset was built server-side by
55
+ * `buildSrcset`, so its URLs already carry the current config hash and already
56
+ * exclude rungs wider than the original. Re-deriving them here from a copy of
57
+ * the ladder would be a second source of truth that silently rots the day
58
+ * someone edits `images.widths` — and it would rot invisibly, because a stale
59
+ * hash serves the original rather than failing.
60
+ */
61
+ function parseSrcsetCandidates(srcset) {
62
+ return srcset
63
+ .split(',')
64
+ .map((part) => part.trim().split(/\s+/))
65
+ .flatMap(([url, descriptor]) => url && descriptor?.endsWith('w') ? [{ url, width: Number(descriptor.slice(0, -1)) }] : [])
66
+ .filter((candidate) => Number.isFinite(candidate.width) && candidate.width > 0)
67
+ .sort((a, b) => a.width - b.width);
68
+ }
69
+ /**
70
+ * The narrowest rung that still covers `target`, or the widest available.
71
+ *
72
+ * Rounds *up* on purpose. Snapping down would hand back an image that has to be
73
+ * upscaled by the browser, which is a visible quality regression; snapping up
74
+ * costs bytes, which is the cheaper mistake and the one the caller can see.
75
+ */
76
+ function snapToLadder(candidates, target) {
77
+ if (candidates.length === 0)
78
+ return null;
79
+ return candidates.find((c) => c.width >= target) ?? candidates[candidates.length - 1];
80
+ }
26
81
  export class ImageUrlBuilder {
27
82
  _source = null;
28
83
  _options = {};
@@ -34,21 +89,30 @@ export class ImageUrlBuilder {
34
89
  return this;
35
90
  }
36
91
  /**
37
- * Set width (for future dynamic image rendering)
92
+ * Request a rendered width in pixels.
93
+ *
94
+ * Snaps to the narrowest generated variant that covers it — the ladder is a
95
+ * closed allowlist, so `width(333)` returns the 640px rung rather than a
96
+ * 333px image. Asking for a width no variant covers returns the widest one.
38
97
  */
39
98
  width(width) {
40
99
  this._options.width = width;
41
100
  return this;
42
101
  }
43
102
  /**
44
- * Set height (for future dynamic image rendering)
103
+ * Request a rendered height in pixels.
104
+ *
105
+ * Honoured only as a *width* request: derivatives are resized by width and
106
+ * keep the original's aspect ratio, so this converts through the asset's
107
+ * intrinsic dimensions and then snaps like {@link width}. Without those
108
+ * dimensions there's nothing to convert through and it's ignored.
45
109
  */
46
110
  height(height) {
47
111
  this._options.height = height;
48
112
  return this;
49
113
  }
50
114
  /**
51
- * Set both width and height (for future dynamic image rendering)
115
+ * Set both dimensions. Width wins — see {@link height}; nothing crops.
52
116
  */
53
117
  size(width, height) {
54
118
  this._options.width = width;
@@ -56,40 +120,86 @@ export class ImageUrlBuilder {
56
120
  return this;
57
121
  }
58
122
  /**
59
- * Set quality (for future dynamic image rendering)
123
+ * @deprecated No effect. Quality is a property of the pipeline, not the URL:
124
+ * it's set once via `images.quality` and hashed into every variant filename,
125
+ * which is what lets variants be cached immutably. A per-URL override would
126
+ * mean generating and storing a second copy of every image per quality value
127
+ * any caller ever passed.
60
128
  */
61
129
  quality(quality) {
62
130
  this._options.quality = Math.max(1, Math.min(100, quality));
63
131
  return this;
64
132
  }
65
133
  /**
66
- * Set format (for future dynamic image rendering)
134
+ * @deprecated No effect. Every derivative is WebP; the original is served in
135
+ * whatever format it was uploaded as. Transcoding on request would reopen the
136
+ * unbounded-generation hole the width allowlist exists to close.
67
137
  */
68
138
  format(format) {
69
139
  this._options.format = format;
70
140
  return this;
71
141
  }
72
142
  /**
73
- * Set fit mode (for future dynamic image rendering)
143
+ * @deprecated No effect. Derivatives are width-resized and preserve aspect
144
+ * ratio, so there is no second dimension for a fit mode to act on. Per-preset
145
+ * `fit`/`aspectRatio` is post-V1, and lands on top of focal points.
74
146
  */
75
147
  fit(fit) {
76
148
  this._options.fit = fit;
77
149
  return this;
78
150
  }
79
151
  /**
80
- * Enable automatic format selection (for future dynamic image rendering)
152
+ * @deprecated No effect, and already the behaviour: variants are always WebP.
81
153
  */
82
154
  auto(mode) {
83
155
  this._options.auto = mode;
84
156
  return this;
85
157
  }
86
158
  /**
87
- * Build the final URL
88
- * Returns /api/assets/{id}?dl=1 which redirects to the actual S3/R2 URL
89
- * Transformations (.width(), .quality(), etc) are stored but not yet applied
159
+ * The requested width, converting a height request through the asset's own
160
+ * aspect ratio.
90
161
  *
91
- * For multi-tenant access, use signAssetUrl config to generate signed URLs
92
- * TODO: Add dynamic image rendering support
162
+ * Width wins when both are set: a derivative is only ever resized by width,
163
+ * so honouring a height as well would require cropping — which the V1
164
+ * pipeline deliberately doesn't do.
165
+ */
166
+ targetWidth() {
167
+ const { width, height } = this._options;
168
+ if (typeof width === 'number' && width > 0)
169
+ return width;
170
+ if (typeof height !== 'number' || height <= 0)
171
+ return null;
172
+ const intrinsic = extractDimensions(this._source);
173
+ if (!intrinsic.width || !intrinsic.height)
174
+ return null;
175
+ return Math.round(height * (intrinsic.width / intrinsic.height));
176
+ }
177
+ /** The ladder variant covering the requested size, if one can be resolved. */
178
+ snappedUrl() {
179
+ const target = this.targetWidth();
180
+ if (target === null)
181
+ return null;
182
+ // No srcset means no variants to snap to: the pipeline is disabled, the
183
+ // asset is an SVG or animated, or the value was never passed through
184
+ // `injectAssetUrls`. Falling back to the original is correct in all four —
185
+ // a smaller image simply doesn't exist to hand back.
186
+ const srcset = extractSrcset(this._source);
187
+ if (!srcset)
188
+ return null;
189
+ return snapToLadder(parseSrcsetCandidates(srcset), target)?.url ?? null;
190
+ }
191
+ /**
192
+ * Build the final URL.
193
+ *
194
+ * With a width (or a height that can be converted to one) and an injected
195
+ * `srcset`, this returns the variant URL for the nearest covering rung.
196
+ * Otherwise it returns the asset's own URL — the full-size original.
197
+ *
198
+ * **Prefer `<Image>` for anything rendered.** This returns one fixed URL, so
199
+ * it can't respond to viewport or device pixel ratio; `<Image>` emits the
200
+ * whole `srcset` and lets the browser choose. Reach for this when you need a
201
+ * bare string and the size is genuinely fixed — an OG image, an email, a
202
+ * canvas or PDF source.
93
203
  */
94
204
  url() {
95
205
  cmsLogger.debug('[ImageUrlBuilder] url() called with source:', JSON.stringify(this._source));
@@ -97,6 +207,11 @@ export class ImageUrlBuilder {
97
207
  cmsLogger.debug('[ImageUrlBuilder] No source provided');
98
208
  return null;
99
209
  }
210
+ const snapped = this.snappedUrl();
211
+ if (snapped) {
212
+ cmsLogger.debug('[ImageUrlBuilder] Snapped to ladder variant:', snapped);
213
+ return snapped;
214
+ }
100
215
  // First try to extract a direct URL (if asset was already resolved)
101
216
  const directUrl = extractUrl(this._source);
102
217
  if (directUrl) {
@@ -136,24 +251,26 @@ export class ImageUrlBuilder {
136
251
  }
137
252
  }
138
253
  /**
139
- * Factory function to create an image URL builder
254
+ * Factory for a Sanity-style image URL builder.
140
255
  *
141
- * Note: Currently returns direct S3/R2 URLs without transformations.
142
- * The baseUrl parameter is accepted for future compatibility but not currently used
143
- * since assets already contain their full public URLs.
256
+ * ```ts
257
+ * const urlFor = imageUrlBuilder();
258
+ * urlFor(post.coverImage).width(800).url(); // → the 960px rung
259
+ * urlFor(post.coverImage).url(); // → the original
260
+ * ```
144
261
  *
145
- * For multi-tenant access with API keys, provide a signAssetUrl function:
146
- * const urlFor = imageUrlBuilder({
147
- * signAssetUrl: (assetId) => `/api/assets/${assetId}?token=${generateToken(assetId)}`
148
- * })
262
+ * `width` snaps to the nearest generated variant that covers it, read off the
263
+ * `srcset` that `injectAssetUrls` attached — so the source must have been
264
+ * through injection (any value from the Local API, a load function, or GraphQL
265
+ * has been). Without a width, or without a srcset, you get the original.
149
266
  *
150
- * Usage:
151
- * const urlFor = imageUrlBuilder({ baseUrl: 'https://yourdomain.com' })
152
- * const url = urlFor(image).url() // Returns asset.url directly
267
+ * Takes no arguments. It previously documented a `baseUrl` and a `signAssetUrl`
268
+ * hook, neither of which the function ever accepted — assets carry their own
269
+ * urls, and `/media/:id/:filename` handles access control centrally rather than
270
+ * through per-caller signing. Signed delivery is `config.signedDownloads`.
153
271
  *
154
- * Future usage with transformations:
155
- * const url = urlFor(image).width(800).quality(80).url()
156
- * // Will return transformed image once dynamic rendering is implemented
272
+ * `quality`, `format`, `fit` and `auto` remain on the builder for source
273
+ * compatibility but are deprecated no-ops; see each one for why.
157
274
  */
158
275
  export function imageUrlBuilder() {
159
276
  return (source) => {
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Read a video's duration, real pixel dimensions and a representative frame —
3
+ * in the browser, from the file the user just picked.
4
+ *
5
+ * Done here rather than on the server because the alternative is ffmpeg: a large
6
+ * native dependency, awkward on serverless, and a build-time burden for every
7
+ * self-hoster who never uploads a video. The browser already has a demuxer and a
8
+ * decoder for exactly the formats it can play, and at upload time the file is
9
+ * local — no download, no storage round-trip.
10
+ *
11
+ * What it cannot do is the honest tradeoff: a codec this browser can't decode
12
+ * (or a server-side/API upload, which never runs this) yields nothing. Every
13
+ * field is therefore optional, and callers must render a video with no poster
14
+ * and no duration rather than treating absence as an error.
15
+ */
16
+ export interface VideoInfo {
17
+ /** Seconds. Absent for streams the browser reports as unbounded or unknown. */
18
+ duration?: number;
19
+ width?: number;
20
+ height?: number;
21
+ /** A frame from early in the video, for use as a poster. */
22
+ poster?: Blob;
23
+ }
24
+ export declare function extractVideoInfo(file: File): Promise<VideoInfo>;
25
+ /**
26
+ * Read duration, dimensions and a poster frame from a video already in storage.
27
+ *
28
+ * For assets uploaded before posters existed, or through the API, where no
29
+ * browser ever saw the file. Only viable because `/media/:id/:filename` serves
30
+ * byte ranges: the browser fetches the container header and the frames around
31
+ * the seek point, not the whole video. Against a 200-only server this would
32
+ * download the entire file to grab one frame.
33
+ *
34
+ * `crossOrigin` is left unset deliberately — the media route is same-origin, and
35
+ * a canvas tainted by a cross-origin frame throws on `toBlob` rather than
36
+ * returning anything.
37
+ */
38
+ export declare function extractVideoInfoFromUrl(url: string): Promise<VideoInfo>;
39
+ //# sourceMappingURL=video-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-metadata.d.ts","sourceRoot":"","sources":["../../src/lib/utils/video-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,SAAS;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,IAAI,CAAC;CACd;AAkBD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAuCrE;AA6CD;;;;;;;;;;;;GAYG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAmC7E"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Read a video's duration, real pixel dimensions and a representative frame —
3
+ * in the browser, from the file the user just picked.
4
+ *
5
+ * Done here rather than on the server because the alternative is ffmpeg: a large
6
+ * native dependency, awkward on serverless, and a build-time burden for every
7
+ * self-hoster who never uploads a video. The browser already has a demuxer and a
8
+ * decoder for exactly the formats it can play, and at upload time the file is
9
+ * local — no download, no storage round-trip.
10
+ *
11
+ * What it cannot do is the honest tradeoff: a codec this browser can't decode
12
+ * (or a server-side/API upload, which never runs this) yields nothing. Every
13
+ * field is therefore optional, and callers must render a video with no poster
14
+ * and no duration rather than treating absence as an error.
15
+ */
16
+ /** Give up rather than hang a queue on a file the browser silently won't decode. */
17
+ const TIMEOUT_MS = 10_000;
18
+ /**
19
+ * Where to grab the poster frame from.
20
+ *
21
+ * Not 0: the first frame of a video is very often black, a fade-in, or a slate,
22
+ * which makes for a poster that identifies nothing. A little way in is far more
23
+ * likely to be representative — capped so a long recording doesn't seek minutes
24
+ * deep, which would mean fetching that far into the file.
25
+ */
26
+ function posterTimestamp(duration) {
27
+ if (!Number.isFinite(duration) || duration <= 0)
28
+ return 0;
29
+ return Math.min(duration * 0.1, 3);
30
+ }
31
+ export async function extractVideoInfo(file) {
32
+ if (typeof document === 'undefined' || !file.type.startsWith('video/'))
33
+ return {};
34
+ const objectUrl = URL.createObjectURL(file);
35
+ const video = document.createElement('video');
36
+ // Muted + playsinline are what make programmatic seeking work on iOS Safari,
37
+ // which otherwise refuses to decode without a user gesture.
38
+ video.muted = true;
39
+ video.playsInline = true;
40
+ video.preload = 'metadata';
41
+ video.src = objectUrl;
42
+ try {
43
+ const metadata = await once(video, 'loadedmetadata', TIMEOUT_MS);
44
+ if (!metadata)
45
+ return {};
46
+ const info = {
47
+ duration: Number.isFinite(video.duration) && video.duration > 0 ? video.duration : undefined,
48
+ width: video.videoWidth || undefined,
49
+ height: video.videoHeight || undefined
50
+ };
51
+ // The frame is a bonus, never a reason to lose the metadata above: a
52
+ // browser may expose duration and dimensions yet refuse to paint a frame
53
+ // (a codec it can demux but not decode, or a tainted canvas).
54
+ try {
55
+ info.poster = await captureFrame(video, posterTimestamp(video.duration));
56
+ }
57
+ catch {
58
+ /* no poster; duration and dimensions still stand */
59
+ }
60
+ return info;
61
+ }
62
+ catch {
63
+ return {};
64
+ }
65
+ finally {
66
+ video.removeAttribute('src');
67
+ video.load();
68
+ URL.revokeObjectURL(objectUrl);
69
+ }
70
+ }
71
+ async function captureFrame(video, time) {
72
+ video.currentTime = time;
73
+ if (!(await once(video, 'seeked', TIMEOUT_MS)))
74
+ return undefined;
75
+ const canvas = document.createElement('canvas');
76
+ canvas.width = video.videoWidth;
77
+ canvas.height = video.videoHeight;
78
+ if (!canvas.width || !canvas.height)
79
+ return undefined;
80
+ const context = canvas.getContext('2d');
81
+ if (!context)
82
+ return undefined;
83
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
84
+ return new Promise((resolve) => {
85
+ // WebP over JPEG: a poster is a thumbnail, and the size difference is worth
86
+ // more than the marginal compatibility, which every target browser has.
87
+ canvas.toBlob((blob) => resolve(blob ?? undefined), 'image/webp', 0.8);
88
+ });
89
+ }
90
+ /**
91
+ * Resolve on an event, or `false` on timeout or error.
92
+ *
93
+ * A rejected promise would be wrong: none of these are exceptional. A video the
94
+ * browser can't decode is an ordinary outcome, and the caller's response is the
95
+ * same as for a plain file — upload it without extras.
96
+ */
97
+ function once(target, event, timeoutMs) {
98
+ return new Promise((resolve) => {
99
+ const done = (result) => {
100
+ clearTimeout(timer);
101
+ target.removeEventListener(event, onEvent);
102
+ target.removeEventListener('error', onError);
103
+ resolve(result);
104
+ };
105
+ const onEvent = () => done(true);
106
+ const onError = () => done(false);
107
+ const timer = setTimeout(() => done(false), timeoutMs);
108
+ target.addEventListener(event, onEvent, { once: true });
109
+ target.addEventListener('error', onError, { once: true });
110
+ });
111
+ }
112
+ /**
113
+ * Read duration, dimensions and a poster frame from a video already in storage.
114
+ *
115
+ * For assets uploaded before posters existed, or through the API, where no
116
+ * browser ever saw the file. Only viable because `/media/:id/:filename` serves
117
+ * byte ranges: the browser fetches the container header and the frames around
118
+ * the seek point, not the whole video. Against a 200-only server this would
119
+ * download the entire file to grab one frame.
120
+ *
121
+ * `crossOrigin` is left unset deliberately — the media route is same-origin, and
122
+ * a canvas tainted by a cross-origin frame throws on `toBlob` rather than
123
+ * returning anything.
124
+ */
125
+ export async function extractVideoInfoFromUrl(url) {
126
+ if (typeof document === 'undefined')
127
+ return {};
128
+ const video = document.createElement('video');
129
+ video.muted = true;
130
+ video.playsInline = true;
131
+ video.preload = 'metadata';
132
+ video.src = url;
133
+ try {
134
+ if (!(await once(video, 'loadedmetadata', TIMEOUT_MS)))
135
+ return {};
136
+ // Duration and dimensions come off the same event as the frame, so an
137
+ // existing video gets all three from one pass. Returning only the poster
138
+ // here — as this did at first — left every pre-existing video with a
139
+ // thumbnail and a blank duration, for no saving whatsoever.
140
+ const info = {
141
+ duration: Number.isFinite(video.duration) && video.duration > 0 ? video.duration : undefined,
142
+ width: video.videoWidth || undefined,
143
+ height: video.videoHeight || undefined
144
+ };
145
+ try {
146
+ info.poster = await captureFrame(video, posterTimestamp(video.duration));
147
+ }
148
+ catch {
149
+ /* metadata still stands without a frame */
150
+ }
151
+ return info;
152
+ }
153
+ catch {
154
+ return {};
155
+ }
156
+ finally {
157
+ video.removeAttribute('src');
158
+ video.load();
159
+ }
160
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aphexcms/cms-core",
3
- "version": "9.9.0",
3
+ "version": "10.0.0",
4
4
  "description": "Aphex CMS Core - A Sanity-style CMS with ports and adapters architecture",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -32,6 +32,11 @@
32
32
  "types": "./dist/client/index.d.ts",
33
33
  "default": "./dist/client/index.js"
34
34
  },
35
+ "./image": {
36
+ "types": "./dist/image/index.d.ts",
37
+ "svelte": "./dist/image/index.js",
38
+ "default": "./dist/image/index.js"
39
+ },
35
40
  "./schema": {
36
41
  "types": "./dist/schema/index.d.ts",
37
42
  "default": "./dist/schema/index.js"