image-renditions 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/nuxt/runtime.d.mts +19 -2
- package/dist/nuxt/runtime.mjs +9 -1
- package/dist/nuxt.mjs +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,16 +278,17 @@ For such a path, `<RenditionImg>` and `useRenditions()` give the URL of the sour
|
|
|
278
278
|
- Changing `originals` keeps the hashes of the preset.
|
|
279
279
|
|
|
280
280
|
Only the app knows where its sources are served from, so it builds their URLs.
|
|
281
|
-
Set the module option `originalUrl` to a module whose default export is a composable returning a function from the scope and the logical path to the URL
|
|
281
|
+
Set the module option `originalUrl` to a module whose default export is a composable returning a function from the scope and the logical path to the URL.
|
|
282
|
+
`defineRenditionOriginalUrl()`, which the module auto-imports, types them by the catalog:
|
|
282
283
|
|
|
283
284
|
```ts
|
|
284
285
|
// app/renditions/original-url.ts
|
|
285
|
-
import { encodePath
|
|
286
|
+
import { encodePath } from "image-renditions"
|
|
286
287
|
|
|
287
|
-
export default
|
|
288
|
+
export default defineRenditionOriginalUrl(() => {
|
|
288
289
|
const { uploadsUrl } = useRuntimeConfig().public
|
|
289
|
-
return ({ path }
|
|
290
|
-
}
|
|
290
|
+
return ({ path }) => `${uploadsUrl}/${encodePath(path)}`
|
|
291
|
+
})
|
|
291
292
|
```
|
|
292
293
|
|
|
293
294
|
```ts
|
package/dist/nuxt/runtime.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RenditionTarget, t as Catalog } from "../catalog-6wdmwTO7.mjs";
|
|
1
|
+
import { a as RenditionTarget, s as ScopeName, t as Catalog } from "../catalog-6wdmwTO7.mjs";
|
|
2
2
|
import { PropType } from "vue";
|
|
3
3
|
//#region src/nuxt/runtime.d.ts
|
|
4
4
|
/** Attributes of an `img` element showing a rendition. */
|
|
@@ -34,6 +34,22 @@ export interface RenditionAttrsOptions<Scope extends string = string> {
|
|
|
34
34
|
/** Whether to set `width` and `height`; `false` leaves the size to a component that sizes the image itself. */
|
|
35
35
|
size?: boolean;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Registry of the catalog the Nuxt module serves, which the module fills with the type of its catalog.
|
|
39
|
+
*
|
|
40
|
+
* It types helpers defined in files of the application, such as {@link defineRenditionOriginalUrl}.
|
|
41
|
+
*/
|
|
42
|
+
export interface RenditionRegister {}
|
|
43
|
+
/** Scope of the catalog in {@link RenditionRegister}, or any string without one. */
|
|
44
|
+
type RegisteredScope = RenditionRegister extends {
|
|
45
|
+
catalog: infer C extends Pick<Catalog, "scopes">;
|
|
46
|
+
} ? ScopeName<C> : string;
|
|
47
|
+
/**
|
|
48
|
+
* Defines the composable of the `originalUrl` module option, typing its targets by the catalog of the Nuxt module.
|
|
49
|
+
*
|
|
50
|
+
* The Nuxt module auto-imports it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function defineRenditionOriginalUrl(useOriginalUrl: () => (target: RenditionTarget<RegisteredScope>) => string): () => (target: RenditionTarget<RegisteredScope>) => string;
|
|
37
53
|
/** Options of {@link createRenditionHelpers}. */
|
|
38
54
|
export interface RenditionHelpersOptions<Scope extends string = string> {
|
|
39
55
|
/** Scope of calls that set none. */
|
|
@@ -94,4 +110,5 @@ export declare function createRenditionHelpers<Name extends string, Scope extend
|
|
|
94
110
|
scope: unknown extends Scope ? keyof Scope extends never ? undefined : Scope : Scope;
|
|
95
111
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
96
112
|
};
|
|
97
|
-
//#endregion
|
|
113
|
+
//#endregion
|
|
114
|
+
export {};
|
package/dist/nuxt/runtime.mjs
CHANGED
|
@@ -6,6 +6,14 @@ import { useRuntimeConfig } from "nuxt/app";
|
|
|
6
6
|
import { defineComponent, h } from "vue";
|
|
7
7
|
//#region src/nuxt/runtime.ts
|
|
8
8
|
/**
|
|
9
|
+
* Defines the composable of the `originalUrl` module option, typing its targets by the catalog of the Nuxt module.
|
|
10
|
+
*
|
|
11
|
+
* The Nuxt module auto-imports it.
|
|
12
|
+
*/
|
|
13
|
+
function defineRenditionOriginalUrl(useOriginalUrl) {
|
|
14
|
+
return useOriginalUrl;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
9
17
|
* Binds `useRenditions()` and `<RenditionImg>` to a catalog.
|
|
10
18
|
*
|
|
11
19
|
* The Nuxt module calls it in a generated module; applications use the generated helpers.
|
|
@@ -150,4 +158,4 @@ function createRenditionHelpers(catalog, { defaultScope, useOriginalUrl, imgAttr
|
|
|
150
158
|
};
|
|
151
159
|
}
|
|
152
160
|
//#endregion
|
|
153
|
-
export { createRenditionHelpers };
|
|
161
|
+
export { createRenditionHelpers, defineRenditionOriginalUrl };
|
package/dist/nuxt.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { r as isSafeScope } from "./path-hNFUjCbA.mjs";
|
|
|
2
2
|
import { n as isDeclaredScope } from "./scopes-C1kzqQHz.mjs";
|
|
3
3
|
import { t as findRenditionAttr } from "./img-attrs-BoCAHpl5.mjs";
|
|
4
4
|
import { createJiti } from "jiti";
|
|
5
|
-
import { addComponent, addImports, addServerHandler, addTemplate, defineNuxtModule, resolvePath } from "nuxt/kit";
|
|
5
|
+
import { addComponent, addImports, addServerHandler, addTemplate, addTypeTemplate, defineNuxtModule, resolvePath } from "nuxt/kit";
|
|
6
6
|
//#region src/nuxt/module.ts
|
|
7
7
|
/**
|
|
8
8
|
* Nuxt module that mounts the rendition handler and provides `useRenditions()` and `<RenditionImg>` typed by the catalog.
|
|
@@ -46,6 +46,28 @@ const module = defineNuxtModule({
|
|
|
46
46
|
name: "useRenditions",
|
|
47
47
|
from: template.dst
|
|
48
48
|
});
|
|
49
|
+
addTypeTemplate({
|
|
50
|
+
filename: "types/image-renditions.d.ts",
|
|
51
|
+
getContents: () => [
|
|
52
|
+
`declare module "image-renditions/nuxt/runtime" {`,
|
|
53
|
+
` interface RenditionRegister {`,
|
|
54
|
+
` catalog: typeof import(${formatImportSpecifier(catalogPath)}).default`,
|
|
55
|
+
` }`,
|
|
56
|
+
`}`,
|
|
57
|
+
"",
|
|
58
|
+
"export {}",
|
|
59
|
+
""
|
|
60
|
+
].join("\n")
|
|
61
|
+
});
|
|
62
|
+
const defineTemplate = addTemplate({
|
|
63
|
+
filename: "image-renditions-define.ts",
|
|
64
|
+
write: true,
|
|
65
|
+
getContents: () => `export { defineRenditionOriginalUrl } from "image-renditions/nuxt/runtime"\n`
|
|
66
|
+
});
|
|
67
|
+
addImports({
|
|
68
|
+
name: "defineRenditionOriginalUrl",
|
|
69
|
+
from: defineTemplate.dst
|
|
70
|
+
});
|
|
49
71
|
addComponent({
|
|
50
72
|
name: "RenditionImg",
|
|
51
73
|
export: "RenditionImg",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-renditions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "On-demand image transformations that persist every result to durable storage and keep app servers stateless.",
|
|
5
5
|
"homepage": "https://github.com/IlyaSemenov/image-renditions#readme",
|
|
6
6
|
"bugs": "https://github.com/IlyaSemenov/image-renditions/issues",
|