@aphexcms/cms-core 9.10.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 (297) 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/types.d.ts +25 -0
  14. package/dist/api/types.d.ts.map +1 -1
  15. package/dist/api/upload-timeout.d.ts +17 -0
  16. package/dist/api/upload-timeout.d.ts.map +1 -0
  17. package/dist/api/upload-timeout.js +35 -0
  18. package/dist/api/upload.d.ts +42 -0
  19. package/dist/api/upload.d.ts.map +1 -0
  20. package/dist/api/upload.js +144 -0
  21. package/dist/components/AdminApp.svelte +130 -26
  22. package/dist/components/AdminApp.svelte.d.ts.map +1 -1
  23. package/dist/components/admin/AssetBrowserModal.svelte +4 -3
  24. package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
  25. package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
  26. package/dist/components/admin/MediaBrowser.svelte +1859 -281
  27. package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
  28. package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
  29. package/dist/components/admin/fields/ArrayField.svelte +21 -10
  30. package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
  31. package/dist/components/admin/fields/FileField.svelte +9 -2
  32. package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
  33. package/dist/components/admin/fields/ImageField.svelte +47 -12
  34. package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/config.js +14 -0
  37. package/dist/db/interfaces/asset.d.ts +114 -5
  38. package/dist/db/interfaces/asset.d.ts.map +1 -1
  39. package/dist/db/interfaces/document.d.ts +98 -3
  40. package/dist/db/interfaces/document.d.ts.map +1 -1
  41. package/dist/hooks.d.ts.map +1 -1
  42. package/dist/hooks.js +2 -1
  43. package/dist/image/Image.svelte +72 -0
  44. package/dist/image/Image.svelte.d.ts +40 -0
  45. package/dist/image/Image.svelte.d.ts.map +1 -0
  46. package/dist/image/index.d.ts +3 -0
  47. package/dist/image/index.d.ts.map +1 -0
  48. package/dist/image/index.js +11 -0
  49. package/dist/image/types.d.ts +28 -0
  50. package/dist/image/types.d.ts.map +1 -0
  51. package/dist/image/types.js +1 -0
  52. package/dist/images/generate.d.ts +55 -0
  53. package/dist/images/generate.d.ts.map +1 -0
  54. package/dist/images/generate.js +243 -0
  55. package/dist/images/index.d.ts +2 -0
  56. package/dist/images/index.d.ts.map +1 -0
  57. package/dist/images/index.js +7 -0
  58. package/dist/images/variants.d.ts +82 -0
  59. package/dist/images/variants.d.ts.map +1 -0
  60. package/dist/images/variants.js +124 -0
  61. package/dist/jobs/asset-reference-jobs.d.ts +49 -0
  62. package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
  63. package/dist/jobs/asset-reference-jobs.js +74 -0
  64. package/dist/jobs/run-batch.d.ts.map +1 -1
  65. package/dist/jobs/run-batch.js +5 -0
  66. package/dist/lib/api/assets.d.ts +62 -7
  67. package/dist/lib/api/assets.d.ts.map +1 -1
  68. package/dist/lib/api/assets.js +116 -9
  69. package/dist/lib/api/assets.js.map +1 -1
  70. package/dist/lib/api/client.d.ts +1 -1
  71. package/dist/lib/api/client.d.ts.map +1 -1
  72. package/dist/lib/api/client.js +39 -9
  73. package/dist/lib/api/client.js.map +1 -1
  74. package/dist/lib/api/limits.d.ts +55 -0
  75. package/dist/lib/api/limits.d.ts.map +1 -0
  76. package/dist/lib/api/limits.js +59 -0
  77. package/dist/lib/api/limits.js.map +1 -0
  78. package/dist/lib/api/schemas/assets.d.ts +94 -4
  79. package/dist/lib/api/schemas/assets.d.ts.map +1 -1
  80. package/dist/lib/api/schemas/assets.js +82 -5
  81. package/dist/lib/api/schemas/assets.js.map +1 -1
  82. package/dist/lib/api/types.d.ts +25 -0
  83. package/dist/lib/api/types.d.ts.map +1 -1
  84. package/dist/lib/api/upload-timeout.d.ts +17 -0
  85. package/dist/lib/api/upload-timeout.d.ts.map +1 -0
  86. package/dist/lib/api/upload-timeout.js +36 -0
  87. package/dist/lib/api/upload-timeout.js.map +1 -0
  88. package/dist/lib/api/upload.d.ts +42 -0
  89. package/dist/lib/api/upload.d.ts.map +1 -0
  90. package/dist/lib/api/upload.js +145 -0
  91. package/dist/lib/api/upload.js.map +1 -0
  92. package/dist/lib/config.d.ts.map +1 -1
  93. package/dist/lib/config.js +14 -0
  94. package/dist/lib/config.js.map +1 -1
  95. package/dist/lib/db/interfaces/asset.d.ts +114 -5
  96. package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
  97. package/dist/lib/db/interfaces/document.d.ts +98 -3
  98. package/dist/lib/db/interfaces/document.d.ts.map +1 -1
  99. package/dist/lib/hooks.d.ts.map +1 -1
  100. package/dist/lib/hooks.js +2 -1
  101. package/dist/lib/hooks.js.map +1 -1
  102. package/dist/lib/image/index.d.ts +3 -0
  103. package/dist/lib/image/index.d.ts.map +1 -0
  104. package/dist/lib/image/index.js +12 -0
  105. package/dist/lib/image/index.js.map +1 -0
  106. package/dist/lib/image/types.d.ts +28 -0
  107. package/dist/lib/image/types.d.ts.map +1 -0
  108. package/dist/lib/image/types.js +2 -0
  109. package/dist/lib/image/types.js.map +1 -0
  110. package/dist/lib/images/generate.d.ts +55 -0
  111. package/dist/lib/images/generate.d.ts.map +1 -0
  112. package/dist/lib/images/generate.js +244 -0
  113. package/dist/lib/images/generate.js.map +1 -0
  114. package/dist/lib/images/index.d.ts +2 -0
  115. package/dist/lib/images/index.d.ts.map +1 -0
  116. package/dist/lib/images/index.js +8 -0
  117. package/dist/lib/images/index.js.map +1 -0
  118. package/dist/lib/images/variants.d.ts +82 -0
  119. package/dist/lib/images/variants.d.ts.map +1 -0
  120. package/dist/lib/images/variants.js +125 -0
  121. package/dist/lib/images/variants.js.map +1 -0
  122. package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
  123. package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
  124. package/dist/lib/jobs/asset-reference-jobs.js +75 -0
  125. package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
  126. package/dist/lib/jobs/run-batch.d.ts.map +1 -1
  127. package/dist/lib/jobs/run-batch.js +5 -0
  128. package/dist/lib/jobs/run-batch.js.map +1 -1
  129. package/dist/lib/local-api/collection-api.d.ts +19 -2
  130. package/dist/lib/local-api/collection-api.d.ts.map +1 -1
  131. package/dist/lib/local-api/collection-api.js +65 -17
  132. package/dist/lib/local-api/collection-api.js.map +1 -1
  133. package/dist/lib/preview/assets.d.ts +19 -0
  134. package/dist/lib/preview/assets.d.ts.map +1 -1
  135. package/dist/lib/preview/assets.js +6 -0
  136. package/dist/lib/preview/assets.js.map +1 -1
  137. package/dist/lib/routes/assets-cdn.d.ts +19 -0
  138. package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
  139. package/dist/lib/routes/assets-cdn.js +295 -17
  140. package/dist/lib/routes/assets-cdn.js.map +1 -1
  141. package/dist/lib/server/api/index.d.ts.map +1 -1
  142. package/dist/lib/server/api/index.js +87 -8
  143. package/dist/lib/server/api/index.js.map +1 -1
  144. package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
  145. package/dist/lib/server/api/routes/assets-bulk.js +36 -7
  146. package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
  147. package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
  148. package/dist/lib/server/api/routes/assets-by-id.js +32 -15
  149. package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
  150. package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
  151. package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  152. package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
  153. package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
  154. package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
  155. package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
  156. package/dist/lib/server/api/routes/assets-poster.js +120 -0
  157. package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
  158. package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
  159. package/dist/lib/server/api/routes/assets-references.js +64 -5
  160. package/dist/lib/server/api/routes/assets-references.js.map +1 -1
  161. package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
  162. package/dist/lib/server/api/routes/assets.js +116 -12
  163. package/dist/lib/server/api/routes/assets.js.map +1 -1
  164. package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
  165. package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
  166. package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
  167. package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
  168. package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
  169. package/dist/lib/server/api/routes/documents.js +27 -1
  170. package/dist/lib/server/api/routes/documents.js.map +1 -1
  171. package/dist/lib/server/index.d.ts +2 -0
  172. package/dist/lib/server/index.d.ts.map +1 -1
  173. package/dist/lib/server/index.js +4 -0
  174. package/dist/lib/server/index.js.map +1 -1
  175. package/dist/lib/services/asset-references-service.d.ts +93 -0
  176. package/dist/lib/services/asset-references-service.d.ts.map +1 -0
  177. package/dist/lib/services/asset-references-service.js +198 -0
  178. package/dist/lib/services/asset-references-service.js.map +1 -0
  179. package/dist/lib/services/asset-service.d.ts +115 -14
  180. package/dist/lib/services/asset-service.d.ts.map +1 -1
  181. package/dist/lib/services/asset-service.js +312 -31
  182. package/dist/lib/services/asset-service.js.map +1 -1
  183. package/dist/lib/services/references-service.d.ts +19 -15
  184. package/dist/lib/services/references-service.d.ts.map +1 -1
  185. package/dist/lib/services/references-service.js +59 -31
  186. package/dist/lib/services/references-service.js.map +1 -1
  187. package/dist/lib/services/version-service.d.ts +10 -1
  188. package/dist/lib/services/version-service.d.ts.map +1 -1
  189. package/dist/lib/services/version-service.js +26 -4
  190. package/dist/lib/services/version-service.js.map +1 -1
  191. package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
  192. package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  193. package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
  194. package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
  195. package/dist/lib/storage/index.d.ts +1 -0
  196. package/dist/lib/storage/index.d.ts.map +1 -1
  197. package/dist/lib/storage/index.js +2 -0
  198. package/dist/lib/storage/index.js.map +1 -1
  199. package/dist/lib/storage/interfaces/storage.d.ts +135 -5
  200. package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
  201. package/dist/lib/storage/keys.d.ts +96 -0
  202. package/dist/lib/storage/keys.d.ts.map +1 -0
  203. package/dist/lib/storage/keys.js +160 -0
  204. package/dist/lib/storage/keys.js.map +1 -0
  205. package/dist/lib/types/asset.d.ts +92 -12
  206. package/dist/lib/types/asset.d.ts.map +1 -1
  207. package/dist/lib/types/capabilities.d.ts +11 -0
  208. package/dist/lib/types/capabilities.d.ts.map +1 -1
  209. package/dist/lib/types/capabilities.js +20 -6
  210. package/dist/lib/types/capabilities.js.map +1 -1
  211. package/dist/lib/types/config.d.ts +127 -0
  212. package/dist/lib/types/config.d.ts.map +1 -1
  213. package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
  214. package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
  215. package/dist/lib/utils/asset-reference-walk.js +144 -0
  216. package/dist/lib/utils/asset-reference-walk.js.map +1 -0
  217. package/dist/lib/utils/image-url.d.ts +61 -26
  218. package/dist/lib/utils/image-url.d.ts.map +1 -1
  219. package/dist/lib/utils/image-url.js +143 -26
  220. package/dist/lib/utils/image-url.js.map +1 -1
  221. package/dist/lib/utils/video-metadata.d.ts +39 -0
  222. package/dist/lib/utils/video-metadata.d.ts.map +1 -0
  223. package/dist/lib/utils/video-metadata.js +161 -0
  224. package/dist/lib/utils/video-metadata.js.map +1 -0
  225. package/dist/local-api/collection-api.d.ts +19 -2
  226. package/dist/local-api/collection-api.d.ts.map +1 -1
  227. package/dist/local-api/collection-api.js +65 -17
  228. package/dist/preview/assets.d.ts +19 -0
  229. package/dist/preview/assets.d.ts.map +1 -1
  230. package/dist/preview/assets.js +6 -0
  231. package/dist/routes/assets-cdn.d.ts +19 -0
  232. package/dist/routes/assets-cdn.d.ts.map +1 -1
  233. package/dist/routes/assets-cdn.js +295 -17
  234. package/dist/server/api/index.d.ts.map +1 -1
  235. package/dist/server/api/index.js +87 -8
  236. package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
  237. package/dist/server/api/routes/assets-bulk.js +36 -7
  238. package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
  239. package/dist/server/api/routes/assets-by-id.js +32 -15
  240. package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
  241. package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  242. package/dist/server/api/routes/assets-direct-upload.js +163 -0
  243. package/dist/server/api/routes/assets-poster.d.ts +4 -0
  244. package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
  245. package/dist/server/api/routes/assets-poster.js +119 -0
  246. package/dist/server/api/routes/assets-references.d.ts.map +1 -1
  247. package/dist/server/api/routes/assets-references.js +64 -5
  248. package/dist/server/api/routes/assets.d.ts.map +1 -1
  249. package/dist/server/api/routes/assets.js +116 -12
  250. package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
  251. package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
  252. package/dist/server/api/routes/clear-asset-references.js +31 -0
  253. package/dist/server/api/routes/documents.d.ts.map +1 -1
  254. package/dist/server/api/routes/documents.js +27 -1
  255. package/dist/server/index.d.ts +2 -0
  256. package/dist/server/index.d.ts.map +1 -1
  257. package/dist/server/index.js +4 -0
  258. package/dist/services/asset-references-service.d.ts +93 -0
  259. package/dist/services/asset-references-service.d.ts.map +1 -0
  260. package/dist/services/asset-references-service.js +197 -0
  261. package/dist/services/asset-service.d.ts +115 -14
  262. package/dist/services/asset-service.d.ts.map +1 -1
  263. package/dist/services/asset-service.js +312 -31
  264. package/dist/services/references-service.d.ts +19 -15
  265. package/dist/services/references-service.d.ts.map +1 -1
  266. package/dist/services/references-service.js +59 -31
  267. package/dist/services/version-service.d.ts +10 -1
  268. package/dist/services/version-service.d.ts.map +1 -1
  269. package/dist/services/version-service.js +26 -4
  270. package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
  271. package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  272. package/dist/storage/adapters/local-storage-adapter.js +86 -19
  273. package/dist/storage/index.d.ts +1 -0
  274. package/dist/storage/index.d.ts.map +1 -1
  275. package/dist/storage/index.js +2 -0
  276. package/dist/storage/interfaces/storage.d.ts +135 -5
  277. package/dist/storage/interfaces/storage.d.ts.map +1 -1
  278. package/dist/storage/keys.d.ts +96 -0
  279. package/dist/storage/keys.d.ts.map +1 -0
  280. package/dist/storage/keys.js +159 -0
  281. package/dist/types/asset.d.ts +92 -12
  282. package/dist/types/asset.d.ts.map +1 -1
  283. package/dist/types/capabilities.d.ts +11 -0
  284. package/dist/types/capabilities.d.ts.map +1 -1
  285. package/dist/types/capabilities.js +20 -6
  286. package/dist/types/config.d.ts +127 -0
  287. package/dist/types/config.d.ts.map +1 -1
  288. package/dist/utils/asset-reference-walk.d.ts +44 -0
  289. package/dist/utils/asset-reference-walk.d.ts.map +1 -0
  290. package/dist/utils/asset-reference-walk.js +143 -0
  291. package/dist/utils/image-url.d.ts +61 -26
  292. package/dist/utils/image-url.d.ts.map +1 -1
  293. package/dist/utils/image-url.js +143 -26
  294. package/dist/utils/video-metadata.d.ts +39 -0
  295. package/dist/utils/video-metadata.d.ts.map +1 -0
  296. package/dist/utils/video-metadata.js +160 -0
  297. package/package.json +6 -1
@@ -0,0 +1,143 @@
1
+ // Walks a document's data and collects every *asset* reference, with the field
2
+ // path it was found at.
3
+ //
4
+ // The sibling of `reference-walk.ts`, which collects document references and
5
+ // deliberately steps over image/file nodes because those point at the assets
6
+ // table rather than at documents. This one is the other half: it collects only
7
+ // those, because they are what the asset-reference index is built from.
8
+ //
9
+ // The path matters as much as the id. "This asset is used by 3 documents" is a
10
+ // number; "Homepage · Hero image" is something an editor can act on — and it is
11
+ // also what makes an orphaned reference diagnosable rather than mysterious.
12
+ /**
13
+ * Collect every asset reference in a document's data.
14
+ *
15
+ * Deduplicated by `assetId` + `fieldPath`, so the same asset used twice in
16
+ * different fields yields two rows, while the same asset at the same path (which
17
+ * shouldn't happen, but costs nothing to guard) yields one.
18
+ */
19
+ export function collectAssetReferences(data) {
20
+ const found = new Map();
21
+ walk(data, '', found);
22
+ return Array.from(found.values());
23
+ }
24
+ /**
25
+ * Every asset id reachable anywhere in the data, ignoring structure entirely.
26
+ *
27
+ * The unstructured twin of {@link collectAssetReferences}, and deliberately dumb:
28
+ * it descends through everything and collects any `asset: { _ref }` it meets, at
29
+ * any depth, under any wrapper, with no notion of which shapes are legitimate.
30
+ * It therefore cannot tell you *where* a reference lives, which is why it is not
31
+ * the indexer.
32
+ *
33
+ * It exists to check the indexer. The walker is a structural allowlist — it finds
34
+ * references in the shapes it knows — while the delete guard is a substring scan
35
+ * that finds them in shapes nobody anticipated. That asymmetry is permanent, and
36
+ * every gap it has produced looked identical from the outside: an asset that
37
+ * reads as unused and then refuses to delete. Comparing these two sets turns the
38
+ * next such gap into a log line at rebuild time instead of a support question
39
+ * months later.
40
+ *
41
+ * Not a substitute for the guard's scan: that one matches raw text, so it also
42
+ * catches an id sitting somewhere this doesn't model at all.
43
+ */
44
+ export function collectAssetIdsUnstructured(data) {
45
+ const ids = new Set();
46
+ const seen = new Set();
47
+ const visit = (value) => {
48
+ if (value == null || typeof value !== 'object')
49
+ return;
50
+ // Documents are JSON, so cycles shouldn't occur — but this runs over every
51
+ // document in an organization during a rebuild, and an accidental cycle
52
+ // must not turn a repair pass into a hang.
53
+ if (seen.has(value))
54
+ return;
55
+ seen.add(value);
56
+ if (Array.isArray(value)) {
57
+ for (const item of value)
58
+ visit(item);
59
+ return;
60
+ }
61
+ const id = assetRefIn(value);
62
+ if (id)
63
+ ids.add(id);
64
+ for (const nested of Object.values(value))
65
+ visit(nested);
66
+ };
67
+ visit(data);
68
+ return ids;
69
+ }
70
+ /**
71
+ * The asset id held by `node.asset`, when that is a reference.
72
+ *
73
+ * `asset` is the key that makes a reference an *asset* reference — a `_ref`
74
+ * under any other key points at the documents table and belongs to
75
+ * `reference-walk.ts`.
76
+ */
77
+ function assetRefIn(node) {
78
+ if (node == null || typeof node !== 'object')
79
+ return null;
80
+ const ref = node.asset;
81
+ if (ref?._type === 'reference' && typeof ref._ref === 'string' && ref._ref)
82
+ return ref._ref;
83
+ return null;
84
+ }
85
+ /**
86
+ * @param skipOwnAsset - Don't record this node's own `asset`; the caller already
87
+ * recorded it at a better path. Set when descending into a wrapper's `data`,
88
+ * which would otherwise report the same reference twice — once as
89
+ * `content[3]` and once as `content[3].data`.
90
+ */
91
+ function walk(value, path, found, skipOwnAsset = false) {
92
+ if (value == null || typeof value !== 'object')
93
+ return;
94
+ if (Array.isArray(value)) {
95
+ for (const [index, item] of value.entries()) {
96
+ walk(item, `${path}[${index}]`, found);
97
+ }
98
+ return;
99
+ }
100
+ const obj = value;
101
+ // Where the reference actually sits, in the two shapes that exist:
102
+ //
103
+ // a plain image field { _type: 'image', asset: { _ref } }
104
+ // a rich-text block { _type: 'image', _key, data: { asset: { _ref } } }
105
+ //
106
+ // The second was missed entirely. Checking only `obj.asset` found nothing on
107
+ // the block, and the recursion that would have reached `data.asset` ran into
108
+ // the `_type === 'reference'` guard below and turned back — so every image
109
+ // placed in block content was invisible to the index, while the delete guard's
110
+ // `LIKE '%assetId%'` found it regardless of shape.
111
+ //
112
+ // That asymmetry is the whole failure mode of this file: a structure-blind
113
+ // scan finds what a structure-aware walk does not model, so any gap here reads
114
+ // as "unused" in the browser and "still referenced" at the point of deletion.
115
+ // New wrappers belong here rather than worked around downstream.
116
+ //
117
+ // Recorded at the containing node's path rather than the inner `asset` key —
118
+ // `coverImage` and `content[3]` are what an editor recognises,
119
+ // `coverImage.asset` and `content[3].data.asset` are not.
120
+ const ownAsset = skipOwnAsset ? null : assetRefIn(obj);
121
+ const wrappedAsset = ownAsset ? null : assetRefIn(obj.data);
122
+ const assetId = ownAsset ?? wrappedAsset;
123
+ if (assetId) {
124
+ const fieldPath = path || (typeof obj._type === 'string' ? obj._type : 'asset');
125
+ found.set(`${assetId} ${fieldPath}`, { assetId, fieldPath });
126
+ }
127
+ // Keep descending regardless: an image object can carry nested fields of its
128
+ // own, and a custom block may embed further media below it.
129
+ // A document reference points at the documents table, not at assets — that is
130
+ // `reference-walk.ts`'s job. Stopping here also prevents a `_ref` that happens
131
+ // to be a document id from being recorded as an asset. Anything reached
132
+ // *through* an `asset` key has already been collected above.
133
+ if (obj._type === 'reference')
134
+ return;
135
+ for (const key of Object.keys(obj)) {
136
+ // Underscore keys are structural (_type, _key, _ref), never content.
137
+ if (key.startsWith('_'))
138
+ continue;
139
+ // A `data` whose asset was just credited to this node still gets walked —
140
+ // it can hold further media — but must not re-report the one already taken.
141
+ walk(obj[key], path ? `${path}.${key}` : key, found, key === 'data' && !!wrappedAsset);
142
+ }
143
+ }
@@ -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"}