@teamnovu/nuxt-image 0.5.5 → 1.0.0-beta.2

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 (91) hide show
  1. package/README.md +229 -24
  2. package/dist/module.d.mts +70 -0
  3. package/dist/module.json +12 -0
  4. package/dist/module.mjs +67 -0
  5. package/dist/runtime/components/NovuBunnyImage.d.vue.ts +11 -0
  6. package/dist/runtime/components/NovuBunnyImage.vue +67 -0
  7. package/dist/runtime/components/NovuBunnyImage.vue.d.ts +11 -0
  8. package/dist/runtime/components/NovuCloudinaryImage.d.vue.ts +19 -0
  9. package/dist/runtime/components/NovuCloudinaryImage.vue +79 -0
  10. package/dist/runtime/components/NovuCloudinaryImage.vue.d.ts +19 -0
  11. package/dist/runtime/components/NovuImage.d.vue.ts +28 -0
  12. package/dist/runtime/components/NovuImage.vue +90 -0
  13. package/dist/runtime/components/NovuImage.vue.d.ts +28 -0
  14. package/dist/runtime/components/NovuImgproxyImage.d.vue.ts +12 -0
  15. package/dist/runtime/components/NovuImgproxyImage.vue +68 -0
  16. package/dist/runtime/components/NovuImgproxyImage.vue.d.ts +12 -0
  17. package/dist/runtime/components/NovuStatamicImage.d.vue.ts +17 -0
  18. package/dist/runtime/components/NovuStatamicImage.vue +87 -0
  19. package/dist/runtime/components/NovuStatamicImage.vue.d.ts +17 -0
  20. package/dist/runtime/composables/useResponsiveImage.d.ts +42 -0
  21. package/dist/runtime/composables/useResponsiveImage.js +115 -0
  22. package/dist/runtime/providers/imgproxy.d.ts +68 -0
  23. package/dist/runtime/providers/imgproxy.js +160 -0
  24. package/dist/runtime/types.d.ts +56 -0
  25. package/dist/runtime/types.js +0 -0
  26. package/dist/runtime/utils/focal.d.ts +11 -0
  27. package/dist/runtime/utils/focal.js +33 -0
  28. package/dist/runtime/utils/i18n.d.ts +1 -0
  29. package/dist/runtime/utils/i18n.js +10 -0
  30. package/dist/runtime/utils/numbers.d.ts +1 -0
  31. package/dist/runtime/utils/numbers.js +6 -0
  32. package/dist/runtime/utils/providerModifiers.d.ts +4 -0
  33. package/dist/runtime/utils/providerModifiers.js +36 -0
  34. package/dist/runtime/utils/screens.d.ts +5 -0
  35. package/dist/runtime/utils/screens.js +19 -0
  36. package/dist/runtime/utils/statamic.d.ts +3 -0
  37. package/dist/runtime/utils/statamic.js +143 -0
  38. package/dist/types.d.mts +3 -0
  39. package/package.json +65 -68
  40. package/CHANGELOG.md +0 -373
  41. package/LICENSE +0 -21
  42. package/dist/module.js +0 -482
  43. package/dist/runtime/components/image.mixin.d.ts +0 -46
  44. package/dist/runtime/components/image.mixin.js +0 -58
  45. package/dist/runtime/components/nuxt-img.vue +0 -49
  46. package/dist/runtime/components/nuxt-img.vue.d.ts +0 -12
  47. package/dist/runtime/components/nuxt-picture.vue +0 -86
  48. package/dist/runtime/components/nuxt-picture.vue.d.ts +0 -15
  49. package/dist/runtime/image.d.ts +0 -2
  50. package/dist/runtime/image.js +0 -194
  51. package/dist/runtime/index.d.ts +0 -2
  52. package/dist/runtime/index.js +0 -2
  53. package/dist/runtime/ipx.d.ts +0 -3
  54. package/dist/runtime/ipx.js +0 -3
  55. package/dist/runtime/plugin.d.ts +0 -1
  56. package/dist/runtime/plugin.js +0 -31
  57. package/dist/runtime/providers/cloudinary.d.ts +0 -2
  58. package/dist/runtime/providers/cloudinary.js +0 -96
  59. package/dist/runtime/providers/fastly.d.ts +0 -2
  60. package/dist/runtime/providers/fastly.js +0 -21
  61. package/dist/runtime/providers/glide.d.ts +0 -2
  62. package/dist/runtime/providers/glide.js +0 -49
  63. package/dist/runtime/providers/imagekit.d.ts +0 -2
  64. package/dist/runtime/providers/imagekit.js +0 -172
  65. package/dist/runtime/providers/imgix.d.ts +0 -3
  66. package/dist/runtime/providers/imgix.js +0 -153
  67. package/dist/runtime/providers/ipx.d.ts +0 -4
  68. package/dist/runtime/providers/ipx.js +0 -28
  69. package/dist/runtime/providers/netlify.d.ts +0 -3
  70. package/dist/runtime/providers/netlify.js +0 -40
  71. package/dist/runtime/providers/prismic.d.ts +0 -2
  72. package/dist/runtime/providers/prismic.js +0 -10
  73. package/dist/runtime/providers/sanity.d.ts +0 -2
  74. package/dist/runtime/providers/sanity.js +0 -87
  75. package/dist/runtime/providers/static.d.ts +0 -3
  76. package/dist/runtime/providers/static.js +0 -6
  77. package/dist/runtime/providers/storyblok.d.ts +0 -2
  78. package/dist/runtime/providers/storyblok.js +0 -27
  79. package/dist/runtime/providers/twicpics.d.ts +0 -2
  80. package/dist/runtime/providers/twicpics.js +0 -58
  81. package/dist/runtime/providers/vercel.d.ts +0 -3
  82. package/dist/runtime/providers/vercel.js +0 -28
  83. package/dist/runtime/utils/index.d.ts +0 -17
  84. package/dist/runtime/utils/index.js +0 -72
  85. package/dist/runtime/utils/meta.d.ts +0 -2
  86. package/dist/runtime/utils/meta.js +0 -67
  87. package/dist/runtime/utils/static-map.d.ts +0 -2
  88. package/dist/runtime/utils/static-map.js +0 -20
  89. package/dist/types.d.ts +0 -172
  90. package/vetur/attributes.json +0 -32
  91. package/vetur/tags.json +0 -32
@@ -1,72 +0,0 @@
1
- export default function imageFetch(url) {
2
- return fetch(cleanDoubleSlashes(url));
3
- }
4
- export function getInt(x) {
5
- if (typeof x === "number") {
6
- return x;
7
- }
8
- if (typeof x === "string") {
9
- return parseInt(x, 10);
10
- }
11
- return void 0;
12
- }
13
- export function getFileExtension(url = "") {
14
- const extension = url.split(/[?#]/).shift().split("/").pop().split(".").pop();
15
- return extension;
16
- }
17
- export function cleanDoubleSlashes(path = "") {
18
- return path.replace(/(https?:\/\/)|(\/)+/g, "$1$2");
19
- }
20
- export function createMapper(map) {
21
- return (key) => {
22
- return key ? map[key] || key : map.missingValue;
23
- };
24
- }
25
- export function createOperationsGenerator({formatter, keyMap, joinWith = "/", valueMap} = {}) {
26
- if (!formatter) {
27
- formatter = (key, value) => `${key}=${value}`;
28
- }
29
- if (keyMap && typeof keyMap !== "function") {
30
- keyMap = createMapper(keyMap);
31
- }
32
- const map = valueMap || {};
33
- Object.keys(map).forEach((valueKey) => {
34
- if (typeof map[valueKey] !== "function") {
35
- map[valueKey] = createMapper(map[valueKey]);
36
- }
37
- });
38
- return (modifiers = {}) => {
39
- const operations = Object.entries(modifiers).filter(([_, value]) => typeof value !== "undefined").map(([key, value]) => {
40
- const mapper = map[key];
41
- if (typeof mapper === "function") {
42
- value = mapper(modifiers[key]);
43
- }
44
- key = typeof keyMap === "function" ? keyMap(key) : key;
45
- return formatter(key, value);
46
- });
47
- return operations.join(joinWith);
48
- };
49
- }
50
- export function renderAttributesToString(attributes = {}) {
51
- return Object.entries(attributes).map(([key, value]) => value ? `${key}="${value}"` : "").filter(Boolean).join(" ");
52
- }
53
- export function renderTag(tag, attrs, contents) {
54
- const html = `<${tag} ${renderAttributesToString(attrs)}>`;
55
- if (!contents) {
56
- return html;
57
- }
58
- return html + contents + `</${tag}>`;
59
- }
60
- export function generateAlt(src = "") {
61
- return src.split(/[?#]/).shift().split("/").pop().split(".").shift();
62
- }
63
- export function parseSize(input = "") {
64
- if (typeof input === "number") {
65
- return input;
66
- }
67
- if (typeof input === "string") {
68
- if (input.replace("px", "").match(/^\d+$/g)) {
69
- return parseInt(input, 10);
70
- }
71
- }
72
- }
@@ -1,2 +0,0 @@
1
- import type { ImageInfo, ImageCTX } from '../../types/image';
2
- export declare function imageMeta(ctx: ImageCTX, url: string): Promise<ImageInfo>;
@@ -1,67 +0,0 @@
1
- export async function imageMeta(ctx, url) {
2
- const cache = getCache(ctx);
3
- const cacheKey = "image:meta:" + url;
4
- if (cache.has(cacheKey)) {
5
- return cache.get(cacheKey);
6
- }
7
- const meta = await _imageMeta(url).catch((err) => {
8
- console.error("Failed to get image meta for " + url, err + "");
9
- return {
10
- width: 0,
11
- height: 0,
12
- ratio: 0
13
- };
14
- });
15
- cache.set(cacheKey, meta);
16
- return meta;
17
- }
18
- async function _imageMeta(url) {
19
- if (process.server) {
20
- const imageMeta2 = await import("image-meta").then((r) => r.default || r);
21
- const data = await fetch(url).then((res) => res.buffer());
22
- const metadata = imageMeta2(data);
23
- if (!metadata) {
24
- throw new Error(`No metadata could be extracted from the image \`${url}\`.`);
25
- }
26
- const {width, height} = metadata;
27
- const meta = {
28
- width,
29
- height,
30
- ratio: width && height ? width / height : void 0
31
- };
32
- return meta;
33
- }
34
- if (typeof Image === "undefined") {
35
- throw new TypeError("Image not supported");
36
- }
37
- return new Promise((resolve, reject) => {
38
- const img = new Image();
39
- img.onload = () => {
40
- const meta = {
41
- width: img.width,
42
- height: img.height,
43
- ratio: img.width / img.height
44
- };
45
- resolve(meta);
46
- };
47
- img.onerror = (err) => reject(err);
48
- img.src = url;
49
- });
50
- }
51
- function getCache(ctx) {
52
- if (!ctx.nuxtContext.cache) {
53
- if (ctx.nuxtContext.ssrContext && ctx.nuxtContext.ssrContext.cache) {
54
- ctx.nuxtContext.cache = ctx.nuxtContext.ssrContext.cache;
55
- } else {
56
- const _cache = {};
57
- ctx.nuxtContext.cache = {
58
- get: (id) => _cache[id],
59
- set: (id, value) => {
60
- _cache[id] = value;
61
- },
62
- has: (id) => typeof _cache[id] !== "undefined"
63
- };
64
- }
65
- }
66
- return ctx.nuxtContext.cache;
67
- }
@@ -1,2 +0,0 @@
1
- import type { Context } from '@nuxt/types';
2
- export declare function useStaticImageMap(nuxtContext?: Context): {};
@@ -1,20 +0,0 @@
1
- const staticImageMap = {};
2
- function updateImageMap() {
3
- if (typeof window.$nuxt !== "undefined") {
4
- const pageImages = window.$nuxt._pagePayload?.data?.[0]?._img || {};
5
- Object.assign(staticImageMap, pageImages);
6
- } else if (typeof window.__NUXT__ !== "undefined") {
7
- const pageImages = window.__NUXT__?._img || {};
8
- Object.assign(staticImageMap, pageImages);
9
- }
10
- }
11
- export function useStaticImageMap(nuxtContext) {
12
- updateImageMap();
13
- if (nuxtContext) {
14
- nuxtContext.app.router?.afterEach(updateImageMap);
15
- }
16
- if (window.onNuxtReady) {
17
- window.onNuxtReady(updateImageMap);
18
- }
19
- return staticImageMap;
20
- }
package/dist/types.d.ts DELETED
@@ -1,172 +0,0 @@
1
- import { IPXOptions } from 'ipx';
2
-
3
- interface ImageModifiers {
4
- width: number;
5
- height: number;
6
- fit: string;
7
- format: string;
8
- [key: string]: any;
9
- }
10
- interface ImageOptions {
11
- provider?: string;
12
- preset?: string;
13
- modifiers?: Partial<ImageModifiers>;
14
- [key: string]: any;
15
- }
16
- interface ImageSizesOptions extends ImageOptions {
17
- sizes: Record<string, string | number> | string;
18
- }
19
- declare type ProviderGetImage = (src: string, options: ImageOptions, ctx: ImageCTX) => ResolvedImage;
20
- interface ImageProvider {
21
- defaults?: any;
22
- getImage: ProviderGetImage;
23
- validateDomains?: Boolean;
24
- supportsAlias?: Boolean;
25
- }
26
- interface CreateImageOptions {
27
- providers: {
28
- [name: string]: {
29
- defaults: any;
30
- provider: ImageProvider;
31
- };
32
- };
33
- presets: {
34
- [name: string]: ImageOptions;
35
- };
36
- provider: string;
37
- screens: Record<string, number>;
38
- srcset: number[];
39
- alias: Record<string, string>;
40
- domains: string[];
41
- }
42
- interface ImageInfo {
43
- width: number;
44
- height: number;
45
- placeholder?: string;
46
- }
47
- interface ResolvedImage {
48
- url: string;
49
- format?: string;
50
- isStatic?: boolean;
51
- getMeta?: () => Promise<ImageInfo>;
52
- }
53
- interface ImageSizes {
54
- srcset: string;
55
- sizes: string;
56
- src: string;
57
- }
58
- interface Img {
59
- (source: string, modifiers?: ImageOptions['modifiers'], options?: ImageOptions): ResolvedImage['url'];
60
- options: CreateImageOptions;
61
- getImage: (source: string, options?: ImageOptions) => ResolvedImage;
62
- getSizes: (source: string, options?: ImageOptions, sizes?: string[]) => ImageSizes;
63
- getMeta: (source: string, options?: ImageOptions) => Promise<ImageInfo>;
64
- }
65
- declare type $Img = Img & {
66
- [preset: string]: $Img;
67
- };
68
- interface ImageCTX {
69
- options: CreateImageOptions;
70
- nuxtContext: {
71
- ssrContext: any;
72
- cache?: any;
73
- isDev: boolean;
74
- isStatic: boolean;
75
- nuxtState?: any;
76
- };
77
- $img?: $Img;
78
- }
79
- interface ImageSize {
80
- width: number;
81
- media: string;
82
- breakpoint: number;
83
- format: string;
84
- url: string;
85
- }
86
- interface RuntimePlaceholder extends ImageInfo {
87
- url: string;
88
- }
89
- declare type OperationFormatter = (key: string, value: string) => string;
90
- declare type OperationMapper = {
91
- [key: string]: string | false;
92
- } | ((key: string) => string);
93
- interface OperationGeneratorConfig {
94
- keyMap?: OperationMapper;
95
- formatter?: OperationFormatter;
96
- joinWith?: string;
97
- valueMap?: {
98
- [key: string]: OperationMapper;
99
- };
100
- }
101
- declare type MapToStatic = (image: ResolvedImage, input: string) => string;
102
-
103
- declare type ProviderSetup = (providerOptions: ImageModuleProvider, moduleOptions: ModuleOptions, nuxt: any) => void | Promise<void>;
104
- interface InputProvider<T = any> {
105
- name?: string;
106
- provider?: string;
107
- options?: T;
108
- setup?: ProviderSetup;
109
- }
110
- interface ImageProviders {
111
- cloudinary?: any;
112
- fastly?: any;
113
- glide?: any;
114
- imagekit?: any;
115
- imgix?: any;
116
- prismic?: any;
117
- twicpics?: any;
118
- storyblok?: any;
119
- ipx?: Partial<IPXOptions>;
120
- static?: Partial<IPXOptions>;
121
- }
122
- interface ModuleOptions extends ImageProviders {
123
- staticFilename: string;
124
- provider: CreateImageOptions['provider'];
125
- presets: {
126
- [name: string]: ImageOptions;
127
- };
128
- dir: string;
129
- domains: string[];
130
- sharp: any;
131
- alias: Record<string, string>;
132
- screens: CreateImageOptions['screens'];
133
- srcset: number[];
134
- internalUrl: string;
135
- providers: {
136
- [name: string]: InputProvider | any;
137
- } & ImageProviders;
138
- [key: string]: any;
139
- }
140
- interface ImageModuleProvider {
141
- name: string;
142
- importName: string;
143
- options: any;
144
- provider: string;
145
- runtime: string;
146
- runtimeOptions: any;
147
- setup: ProviderSetup;
148
- }
149
-
150
- declare module '@nuxt/types' {
151
- interface Context {
152
- $img: $Img;
153
- }
154
- interface NuxtAppOptions {
155
- $img: $Img;
156
- }
157
- interface Configuration {
158
- image?: Partial<ModuleOptions>;
159
- }
160
- }
161
- declare module 'vue/types/vue' {
162
- interface Vue {
163
- $img: $Img;
164
- }
165
- }
166
- declare module 'vuex/types/index' {
167
- interface Store<S> {
168
- $img: $Img;
169
- }
170
- }
171
-
172
- export { $Img, CreateImageOptions, ImageCTX, ImageInfo, ImageModifiers, ImageModuleProvider, ImageOptions, ImageProvider, ImageProviders, ImageSize, ImageSizes, ImageSizesOptions, Img, InputProvider, MapToStatic, ModuleOptions, OperationFormatter, OperationGeneratorConfig, OperationMapper, ProviderGetImage, ProviderSetup, ResolvedImage, RuntimePlaceholder };
@@ -1,32 +0,0 @@
1
- {
2
- "src":{
3
- "description":"Path to image file"
4
- },
5
- "width":{
6
- "description":"Specify width of the image."
7
- },
8
- "height":{
9
- "description":"Specify height of the image."
10
- },
11
- "sizes":{
12
- "description":"Specify responsive reiszes. `sm:100vw md:50vw lg:400px`"
13
- },
14
- "provider":{
15
- "description":"Use other provider instead of default provider option specified in nuxt.config`"
16
- },
17
- "preset":{
18
- "description":"Presets are predefined sets of image modifiers that can be used create unified form of images in your projects."
19
- },
20
- "format":{
21
- "description":"In case you want to serve images in a specific format, use this prop. `webp`, `jpeg`, `jpg`, `png`, `gif` and `svg`"
22
- },
23
- "quality":{
24
- "description":"The quality for the generated image(s)."
25
- },
26
- "fit":{
27
- "description":"The fit property specifies the size of the images. There are five standard values you can use with this property. `cover` `contain` `fill` `inside` `outside`"
28
- },
29
- "modifiers":{
30
- "description":"In addition to standard modifiers, every provider can have their own modifiers. `:modifiers=\"{ roundCorner: '0:100' }\"`"
31
- }
32
- }
package/vetur/tags.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "nuxt-picture":{
3
- "attributes":[
4
- "src",
5
- "width",
6
- "height",
7
- "sizes",
8
- "provider",
9
- "preset",
10
- "format",
11
- "quality",
12
- "fit",
13
- "modifiers"
14
- ],
15
- "description":"drop-in replacement for the native `<picture>` tag"
16
- },
17
- "nuxt-img":{
18
- "attributes":[
19
- "src",
20
- "width",
21
- "height",
22
- "sizes",
23
- "provider",
24
- "preset",
25
- "format",
26
- "quality",
27
- "fit",
28
- "modifiers"
29
- ],
30
- "description":"drop-in replacement for the native `<img>` tag"
31
- }
32
- }