@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.
- package/dist/api/assets.d.ts +62 -7
- package/dist/api/assets.d.ts.map +1 -1
- package/dist/api/assets.js +116 -9
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +39 -9
- package/dist/api/limits.d.ts +55 -0
- package/dist/api/limits.d.ts.map +1 -0
- package/dist/api/limits.js +58 -0
- package/dist/api/schemas/assets.d.ts +94 -4
- package/dist/api/schemas/assets.d.ts.map +1 -1
- package/dist/api/schemas/assets.js +82 -5
- package/dist/api/types.d.ts +25 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/upload-timeout.d.ts +17 -0
- package/dist/api/upload-timeout.d.ts.map +1 -0
- package/dist/api/upload-timeout.js +35 -0
- package/dist/api/upload.d.ts +42 -0
- package/dist/api/upload.d.ts.map +1 -0
- package/dist/api/upload.js +144 -0
- package/dist/components/AdminApp.svelte +130 -26
- package/dist/components/AdminApp.svelte.d.ts.map +1 -1
- package/dist/components/admin/AssetBrowserModal.svelte +4 -3
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
- package/dist/components/admin/MediaBrowser.svelte +1859 -281
- package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
- package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ArrayField.svelte +21 -10
- package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/FileField.svelte +9 -2
- package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ImageField.svelte +47 -12
- package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/db/interfaces/asset.d.ts +114 -5
- package/dist/db/interfaces/asset.d.ts.map +1 -1
- package/dist/db/interfaces/document.d.ts +98 -3
- package/dist/db/interfaces/document.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +2 -1
- package/dist/image/Image.svelte +72 -0
- package/dist/image/Image.svelte.d.ts +40 -0
- package/dist/image/Image.svelte.d.ts.map +1 -0
- package/dist/image/index.d.ts +3 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +11 -0
- package/dist/image/types.d.ts +28 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +1 -0
- package/dist/images/generate.d.ts +55 -0
- package/dist/images/generate.d.ts.map +1 -0
- package/dist/images/generate.js +243 -0
- package/dist/images/index.d.ts +2 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +7 -0
- package/dist/images/variants.d.ts +82 -0
- package/dist/images/variants.d.ts.map +1 -0
- package/dist/images/variants.js +124 -0
- package/dist/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/jobs/asset-reference-jobs.js +74 -0
- package/dist/jobs/run-batch.d.ts.map +1 -1
- package/dist/jobs/run-batch.js +5 -0
- package/dist/lib/api/assets.d.ts +62 -7
- package/dist/lib/api/assets.d.ts.map +1 -1
- package/dist/lib/api/assets.js +116 -9
- package/dist/lib/api/assets.js.map +1 -1
- package/dist/lib/api/client.d.ts +1 -1
- package/dist/lib/api/client.d.ts.map +1 -1
- package/dist/lib/api/client.js +39 -9
- package/dist/lib/api/client.js.map +1 -1
- package/dist/lib/api/limits.d.ts +55 -0
- package/dist/lib/api/limits.d.ts.map +1 -0
- package/dist/lib/api/limits.js +59 -0
- package/dist/lib/api/limits.js.map +1 -0
- package/dist/lib/api/schemas/assets.d.ts +94 -4
- package/dist/lib/api/schemas/assets.d.ts.map +1 -1
- package/dist/lib/api/schemas/assets.js +82 -5
- package/dist/lib/api/schemas/assets.js.map +1 -1
- package/dist/lib/api/types.d.ts +25 -0
- package/dist/lib/api/types.d.ts.map +1 -1
- package/dist/lib/api/upload-timeout.d.ts +17 -0
- package/dist/lib/api/upload-timeout.d.ts.map +1 -0
- package/dist/lib/api/upload-timeout.js +36 -0
- package/dist/lib/api/upload-timeout.js.map +1 -0
- package/dist/lib/api/upload.d.ts +42 -0
- package/dist/lib/api/upload.d.ts.map +1 -0
- package/dist/lib/api/upload.js +145 -0
- package/dist/lib/api/upload.js.map +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/db/interfaces/asset.d.ts +114 -5
- package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
- package/dist/lib/db/interfaces/document.d.ts +98 -3
- package/dist/lib/db/interfaces/document.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +2 -1
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/image/index.d.ts +3 -0
- package/dist/lib/image/index.d.ts.map +1 -0
- package/dist/lib/image/index.js +12 -0
- package/dist/lib/image/index.js.map +1 -0
- package/dist/lib/image/types.d.ts +28 -0
- package/dist/lib/image/types.d.ts.map +1 -0
- package/dist/lib/image/types.js +2 -0
- package/dist/lib/image/types.js.map +1 -0
- package/dist/lib/images/generate.d.ts +55 -0
- package/dist/lib/images/generate.d.ts.map +1 -0
- package/dist/lib/images/generate.js +244 -0
- package/dist/lib/images/generate.js.map +1 -0
- package/dist/lib/images/index.d.ts +2 -0
- package/dist/lib/images/index.d.ts.map +1 -0
- package/dist/lib/images/index.js +8 -0
- package/dist/lib/images/index.js.map +1 -0
- package/dist/lib/images/variants.d.ts +82 -0
- package/dist/lib/images/variants.d.ts.map +1 -0
- package/dist/lib/images/variants.js +125 -0
- package/dist/lib/images/variants.js.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.js +75 -0
- package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
- package/dist/lib/jobs/run-batch.d.ts.map +1 -1
- package/dist/lib/jobs/run-batch.js +5 -0
- package/dist/lib/jobs/run-batch.js.map +1 -1
- package/dist/lib/local-api/collection-api.d.ts +19 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +65 -17
- package/dist/lib/local-api/collection-api.js.map +1 -1
- package/dist/lib/preview/assets.d.ts +19 -0
- package/dist/lib/preview/assets.d.ts.map +1 -1
- package/dist/lib/preview/assets.js +6 -0
- package/dist/lib/preview/assets.js.map +1 -1
- package/dist/lib/routes/assets-cdn.d.ts +19 -0
- package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
- package/dist/lib/routes/assets-cdn.js +295 -17
- package/dist/lib/routes/assets-cdn.js.map +1 -1
- package/dist/lib/server/api/index.d.ts.map +1 -1
- package/dist/lib/server/api/index.js +87 -8
- package/dist/lib/server/api/index.js.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.js +36 -7
- package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.js +32 -15
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.js +120 -0
- package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-references.js +64 -5
- package/dist/lib/server/api/routes/assets-references.js.map +1 -1
- package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets.js +116 -12
- package/dist/lib/server/api/routes/assets.js.map +1 -1
- package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
- package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
- package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
- package/dist/lib/server/api/routes/documents.js +27 -1
- package/dist/lib/server/api/routes/documents.js.map +1 -1
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +4 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/services/asset-references-service.d.ts +93 -0
- package/dist/lib/services/asset-references-service.d.ts.map +1 -0
- package/dist/lib/services/asset-references-service.js +198 -0
- package/dist/lib/services/asset-references-service.js.map +1 -0
- package/dist/lib/services/asset-service.d.ts +115 -14
- package/dist/lib/services/asset-service.d.ts.map +1 -1
- package/dist/lib/services/asset-service.js +312 -31
- package/dist/lib/services/asset-service.js.map +1 -1
- package/dist/lib/services/references-service.d.ts +19 -15
- package/dist/lib/services/references-service.d.ts.map +1 -1
- package/dist/lib/services/references-service.js +59 -31
- package/dist/lib/services/references-service.js.map +1 -1
- package/dist/lib/services/version-service.d.ts +10 -1
- package/dist/lib/services/version-service.d.ts.map +1 -1
- package/dist/lib/services/version-service.js +26 -4
- package/dist/lib/services/version-service.js.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
- package/dist/lib/storage/index.d.ts +1 -0
- package/dist/lib/storage/index.d.ts.map +1 -1
- package/dist/lib/storage/index.js +2 -0
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/interfaces/storage.d.ts +135 -5
- package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/lib/storage/keys.d.ts +96 -0
- package/dist/lib/storage/keys.d.ts.map +1 -0
- package/dist/lib/storage/keys.js +160 -0
- package/dist/lib/storage/keys.js.map +1 -0
- package/dist/lib/types/asset.d.ts +92 -12
- package/dist/lib/types/asset.d.ts.map +1 -1
- package/dist/lib/types/capabilities.d.ts +11 -0
- package/dist/lib/types/capabilities.d.ts.map +1 -1
- package/dist/lib/types/capabilities.js +20 -6
- package/dist/lib/types/capabilities.js.map +1 -1
- package/dist/lib/types/config.d.ts +127 -0
- package/dist/lib/types/config.d.ts.map +1 -1
- package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
- package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/lib/utils/asset-reference-walk.js +144 -0
- package/dist/lib/utils/asset-reference-walk.js.map +1 -0
- package/dist/lib/utils/image-url.d.ts +61 -26
- package/dist/lib/utils/image-url.d.ts.map +1 -1
- package/dist/lib/utils/image-url.js +143 -26
- package/dist/lib/utils/image-url.js.map +1 -1
- package/dist/lib/utils/video-metadata.d.ts +39 -0
- package/dist/lib/utils/video-metadata.d.ts.map +1 -0
- package/dist/lib/utils/video-metadata.js +161 -0
- package/dist/lib/utils/video-metadata.js.map +1 -0
- package/dist/local-api/collection-api.d.ts +19 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +65 -17
- package/dist/preview/assets.d.ts +19 -0
- package/dist/preview/assets.d.ts.map +1 -1
- package/dist/preview/assets.js +6 -0
- package/dist/routes/assets-cdn.d.ts +19 -0
- package/dist/routes/assets-cdn.d.ts.map +1 -1
- package/dist/routes/assets-cdn.js +295 -17
- package/dist/server/api/index.d.ts.map +1 -1
- package/dist/server/api/index.js +87 -8
- package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/server/api/routes/assets-bulk.js +36 -7
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/assets-by-id.js +32 -15
- package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/server/api/routes/assets-direct-upload.js +163 -0
- package/dist/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/server/api/routes/assets-poster.js +119 -0
- package/dist/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/server/api/routes/assets-references.js +64 -5
- package/dist/server/api/routes/assets.d.ts.map +1 -1
- package/dist/server/api/routes/assets.js +116 -12
- package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/server/api/routes/clear-asset-references.js +31 -0
- package/dist/server/api/routes/documents.d.ts.map +1 -1
- package/dist/server/api/routes/documents.js +27 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/services/asset-references-service.d.ts +93 -0
- package/dist/services/asset-references-service.d.ts.map +1 -0
- package/dist/services/asset-references-service.js +197 -0
- package/dist/services/asset-service.d.ts +115 -14
- package/dist/services/asset-service.d.ts.map +1 -1
- package/dist/services/asset-service.js +312 -31
- package/dist/services/references-service.d.ts +19 -15
- package/dist/services/references-service.d.ts.map +1 -1
- package/dist/services/references-service.js +59 -31
- package/dist/services/version-service.d.ts +10 -1
- package/dist/services/version-service.d.ts.map +1 -1
- package/dist/services/version-service.js +26 -4
- package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/interfaces/storage.d.ts +135 -5
- package/dist/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/storage/keys.d.ts +96 -0
- package/dist/storage/keys.d.ts.map +1 -0
- package/dist/storage/keys.js +159 -0
- package/dist/types/asset.d.ts +92 -12
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +11 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/capabilities.js +20 -6
- package/dist/types/config.d.ts +127 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/asset-reference-walk.d.ts +44 -0
- package/dist/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/utils/asset-reference-walk.js +143 -0
- package/dist/utils/image-url.d.ts +61 -26
- package/dist/utils/image-url.d.ts.map +1 -1
- package/dist/utils/image-url.js +143 -26
- package/dist/utils/video-metadata.d.ts +39 -0
- package/dist/utils/video-metadata.d.ts.map +1 -0
- package/dist/utils/video-metadata.js +160 -0
- 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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
43
|
+
* Set both dimensions. Width wins — see {@link height}; nothing crops.
|
|
35
44
|
*/
|
|
36
45
|
size(width: number, height: number): this;
|
|
37
46
|
/**
|
|
38
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
67
|
+
* @deprecated No effect, and already the behaviour: variants are always WebP.
|
|
51
68
|
*/
|
|
52
69
|
auto(mode: 'format'): this;
|
|
53
70
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
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
|
-
*
|
|
59
|
-
*
|
|
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
|
|
101
|
+
* Factory for a Sanity-style image URL builder.
|
|
69
102
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
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
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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
|
-
*
|
|
84
|
-
*
|
|
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;
|
|
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"}
|
package/dist/utils/image-url.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
88
|
-
*
|
|
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
|
-
*
|
|
92
|
-
*
|
|
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
|
|
254
|
+
* Factory for a Sanity-style image URL builder.
|
|
140
255
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
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
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
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
|
-
*
|
|
155
|
-
*
|
|
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"}
|