@teamnovu/nuxt-image 0.5.4 → 1.0.0-beta.1
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 +229 -24
- package/dist/module.d.mts +70 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +67 -0
- package/dist/runtime/components/NovuBunnyImage.d.vue.ts +11 -0
- package/dist/runtime/components/NovuBunnyImage.vue +67 -0
- package/dist/runtime/components/NovuBunnyImage.vue.d.ts +11 -0
- package/dist/runtime/components/NovuCloudinaryImage.d.vue.ts +19 -0
- package/dist/runtime/components/NovuCloudinaryImage.vue +79 -0
- package/dist/runtime/components/NovuCloudinaryImage.vue.d.ts +19 -0
- package/dist/runtime/components/NovuImage.d.vue.ts +28 -0
- package/dist/runtime/components/NovuImage.vue +90 -0
- package/dist/runtime/components/NovuImage.vue.d.ts +28 -0
- package/dist/runtime/components/NovuImgproxyImage.d.vue.ts +12 -0
- package/dist/runtime/components/NovuImgproxyImage.vue +68 -0
- package/dist/runtime/components/NovuImgproxyImage.vue.d.ts +12 -0
- package/dist/runtime/components/NovuStatamicImage.d.vue.ts +17 -0
- package/dist/runtime/components/NovuStatamicImage.vue +87 -0
- package/dist/runtime/components/NovuStatamicImage.vue.d.ts +17 -0
- package/dist/runtime/composables/useResponsiveImage.d.ts +42 -0
- package/dist/runtime/composables/useResponsiveImage.js +115 -0
- package/dist/runtime/providers/imgproxy.d.ts +68 -0
- package/dist/runtime/providers/imgproxy.js +161 -0
- package/dist/runtime/types.d.ts +56 -0
- package/dist/runtime/types.js +0 -0
- package/dist/runtime/utils/focal.d.ts +11 -0
- package/dist/runtime/utils/focal.js +33 -0
- package/dist/runtime/utils/i18n.d.ts +1 -0
- package/dist/runtime/utils/i18n.js +10 -0
- package/dist/runtime/utils/numbers.d.ts +1 -0
- package/dist/runtime/utils/numbers.js +6 -0
- package/dist/runtime/utils/providerModifiers.d.ts +4 -0
- package/dist/runtime/utils/providerModifiers.js +36 -0
- package/dist/runtime/utils/screens.d.ts +5 -0
- package/dist/runtime/utils/screens.js +19 -0
- package/dist/runtime/utils/statamic.d.ts +3 -0
- package/dist/runtime/utils/statamic.js +143 -0
- package/dist/types.d.mts +3 -0
- package/package.json +65 -68
- package/CHANGELOG.md +0 -371
- package/LICENSE +0 -21
- package/dist/module.js +0 -482
- package/dist/runtime/components/image.mixin.d.ts +0 -46
- package/dist/runtime/components/image.mixin.js +0 -58
- package/dist/runtime/components/nuxt-img.vue +0 -49
- package/dist/runtime/components/nuxt-img.vue.d.ts +0 -12
- package/dist/runtime/components/nuxt-picture.vue +0 -86
- package/dist/runtime/components/nuxt-picture.vue.d.ts +0 -15
- package/dist/runtime/image.d.ts +0 -2
- package/dist/runtime/image.js +0 -194
- package/dist/runtime/index.d.ts +0 -2
- package/dist/runtime/index.js +0 -2
- package/dist/runtime/ipx.d.ts +0 -3
- package/dist/runtime/ipx.js +0 -3
- package/dist/runtime/plugin.d.ts +0 -1
- package/dist/runtime/plugin.js +0 -31
- package/dist/runtime/providers/cloudinary.d.ts +0 -2
- package/dist/runtime/providers/cloudinary.js +0 -96
- package/dist/runtime/providers/fastly.d.ts +0 -2
- package/dist/runtime/providers/fastly.js +0 -21
- package/dist/runtime/providers/glide.d.ts +0 -2
- package/dist/runtime/providers/glide.js +0 -49
- package/dist/runtime/providers/imagekit.d.ts +0 -2
- package/dist/runtime/providers/imagekit.js +0 -172
- package/dist/runtime/providers/imgix.d.ts +0 -3
- package/dist/runtime/providers/imgix.js +0 -153
- package/dist/runtime/providers/ipx.d.ts +0 -4
- package/dist/runtime/providers/ipx.js +0 -28
- package/dist/runtime/providers/netlify.d.ts +0 -3
- package/dist/runtime/providers/netlify.js +0 -40
- package/dist/runtime/providers/prismic.d.ts +0 -2
- package/dist/runtime/providers/prismic.js +0 -10
- package/dist/runtime/providers/sanity.d.ts +0 -2
- package/dist/runtime/providers/sanity.js +0 -87
- package/dist/runtime/providers/static.d.ts +0 -3
- package/dist/runtime/providers/static.js +0 -6
- package/dist/runtime/providers/storyblok.d.ts +0 -2
- package/dist/runtime/providers/storyblok.js +0 -27
- package/dist/runtime/providers/twicpics.d.ts +0 -2
- package/dist/runtime/providers/twicpics.js +0 -58
- package/dist/runtime/providers/vercel.d.ts +0 -3
- package/dist/runtime/providers/vercel.js +0 -28
- package/dist/runtime/utils/index.d.ts +0 -17
- package/dist/runtime/utils/index.js +0 -72
- package/dist/runtime/utils/meta.d.ts +0 -2
- package/dist/runtime/utils/meta.js +0 -67
- package/dist/runtime/utils/static-map.d.ts +0 -2
- package/dist/runtime/utils/static-map.js +0 -20
- package/dist/types.d.ts +0 -172
- package/vetur/attributes.json +0 -32
- package/vetur/tags.json +0 -32
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<picture :key="nSources[0].src">
|
|
3
|
-
<source
|
|
4
|
-
v-if="nSources[1]"
|
|
5
|
-
:type="nSources[1].type"
|
|
6
|
-
:srcset="nSources[1].srcset"
|
|
7
|
-
:sizes="nSources[1].sizes"
|
|
8
|
-
>
|
|
9
|
-
<img
|
|
10
|
-
v-bind="nImgAttrs"
|
|
11
|
-
:src="nSources[0].src"
|
|
12
|
-
:srcset="nSources[0].srcset"
|
|
13
|
-
:sizes="nSources[0].sizes"
|
|
14
|
-
>
|
|
15
|
-
</picture>
|
|
16
|
-
</template>
|
|
17
|
-
|
|
18
|
-
<script>
|
|
19
|
-
import {imageMixin} from "./image.mixin";
|
|
20
|
-
import {getFileExtension} from "~image";
|
|
21
|
-
const defineComponent = (opts) => opts;
|
|
22
|
-
export default defineComponent({
|
|
23
|
-
name: "NuxtPicture",
|
|
24
|
-
mixins: [imageMixin],
|
|
25
|
-
props: {
|
|
26
|
-
legacyFormat: {type: String, default: null}
|
|
27
|
-
},
|
|
28
|
-
computed: {
|
|
29
|
-
isTransparent() {
|
|
30
|
-
return ["png", "webp", "gif"].includes(this.originalFormat);
|
|
31
|
-
},
|
|
32
|
-
originalFormat() {
|
|
33
|
-
return getFileExtension(this.src);
|
|
34
|
-
},
|
|
35
|
-
nFormat() {
|
|
36
|
-
if (this.format) {
|
|
37
|
-
return this.format;
|
|
38
|
-
}
|
|
39
|
-
if (this.originalFormat === "svg") {
|
|
40
|
-
return "svg";
|
|
41
|
-
}
|
|
42
|
-
return "webp";
|
|
43
|
-
},
|
|
44
|
-
nLegacyFormat() {
|
|
45
|
-
if (this.legacyFormat) {
|
|
46
|
-
return this.legacyFormat;
|
|
47
|
-
}
|
|
48
|
-
const formats = {
|
|
49
|
-
webp: this.isTransparent ? "png" : "jpeg",
|
|
50
|
-
svg: "png"
|
|
51
|
-
};
|
|
52
|
-
return formats[this.nFormat] || this.originalFormat;
|
|
53
|
-
},
|
|
54
|
-
nSources() {
|
|
55
|
-
if (this.nFormat === "svg") {
|
|
56
|
-
return [{
|
|
57
|
-
srcset: this.src
|
|
58
|
-
}];
|
|
59
|
-
}
|
|
60
|
-
const formats = this.nLegacyFormat !== this.nFormat ? [this.nLegacyFormat, this.nFormat] : [this.nFormat];
|
|
61
|
-
const sources = formats.map((format) => {
|
|
62
|
-
const {srcset, sizes, src} = this.$img.getSizes(this.src, {
|
|
63
|
-
...this.nOptions,
|
|
64
|
-
sizes: this.sizes || this.$img.options.screens,
|
|
65
|
-
modifiers: {
|
|
66
|
-
...this.nModifiers,
|
|
67
|
-
format
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return {
|
|
71
|
-
src,
|
|
72
|
-
type: `image/${format}`,
|
|
73
|
-
sizes,
|
|
74
|
-
srcset
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
return sources;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
created() {
|
|
81
|
-
if (process.server && process.static) {
|
|
82
|
-
this.nSources;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
</script>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare const _default: import("vue/types/vue").ExtendedVue<import("vue").default, unknown, unknown, {
|
|
2
|
-
isTransparent: boolean;
|
|
3
|
-
originalFormat: string;
|
|
4
|
-
nFormat: string;
|
|
5
|
-
nLegacyFormat: string;
|
|
6
|
-
nSources: {
|
|
7
|
-
srcset: string;
|
|
8
|
-
src?: string;
|
|
9
|
-
type?: string;
|
|
10
|
-
sizes?: string;
|
|
11
|
-
}[];
|
|
12
|
-
}, {
|
|
13
|
-
legacyFormat: string;
|
|
14
|
-
}>;
|
|
15
|
-
export default _default;
|
package/dist/runtime/image.d.ts
DELETED
package/dist/runtime/image.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import defu from "defu";
|
|
2
|
-
import {hasProtocol, parseURL, joinURL, withLeadingSlash} from "ufo";
|
|
3
|
-
import {imageMeta} from "./utils/meta";
|
|
4
|
-
import {parseSize} from "./utils";
|
|
5
|
-
import {useStaticImageMap} from "./utils/static-map";
|
|
6
|
-
export function createImage(globalOptions, nuxtContext) {
|
|
7
|
-
const staticImageManifest = process.client && process.static ? useStaticImageMap(nuxtContext) : {};
|
|
8
|
-
const ctx = {
|
|
9
|
-
options: globalOptions,
|
|
10
|
-
nuxtContext
|
|
11
|
-
};
|
|
12
|
-
const getImage = function(input, options = {}) {
|
|
13
|
-
const image = resolveImage(ctx, input, options);
|
|
14
|
-
if (image.isStatic) {
|
|
15
|
-
handleStaticImage(image, input);
|
|
16
|
-
}
|
|
17
|
-
return image;
|
|
18
|
-
};
|
|
19
|
-
const $img = function $img2(input, modifiers = {}, options = {}) {
|
|
20
|
-
return getImage(input, {
|
|
21
|
-
...options,
|
|
22
|
-
modifiers: defu(modifiers, options.modifiers || {})
|
|
23
|
-
}).url;
|
|
24
|
-
};
|
|
25
|
-
function handleStaticImage(image, input) {
|
|
26
|
-
if (process.static) {
|
|
27
|
-
if (process.client && "fetchPayload" in window.$nuxt) {
|
|
28
|
-
const mappedURL = staticImageManifest[image.url];
|
|
29
|
-
image.url = mappedURL || input;
|
|
30
|
-
return image;
|
|
31
|
-
}
|
|
32
|
-
if (process.server) {
|
|
33
|
-
const {ssrContext} = ctx.nuxtContext;
|
|
34
|
-
if (ssrContext) {
|
|
35
|
-
const ssrState = ssrContext.nuxt || {};
|
|
36
|
-
const staticImages = ssrState._img = ssrState._img || {};
|
|
37
|
-
const ssrData = ssrState.data?.[0];
|
|
38
|
-
if (ssrData) {
|
|
39
|
-
ssrData._img = staticImages;
|
|
40
|
-
}
|
|
41
|
-
const mapToStatic = ssrContext.image?.mapToStatic;
|
|
42
|
-
if (typeof mapToStatic === "function") {
|
|
43
|
-
const mappedURL = mapToStatic(image, input);
|
|
44
|
-
if (mappedURL) {
|
|
45
|
-
staticImages[image.url] = mappedURL;
|
|
46
|
-
image.url = mappedURL;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} else if (process.env.NODE_ENV === "production") {
|
|
52
|
-
image.url = input;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
for (const presetName in globalOptions.presets) {
|
|
56
|
-
$img[presetName] = (source, modifiers, options) => $img(source, modifiers, {...globalOptions.presets[presetName], ...options});
|
|
57
|
-
}
|
|
58
|
-
$img.options = globalOptions;
|
|
59
|
-
$img.getImage = getImage;
|
|
60
|
-
$img.getMeta = (input, options) => getMeta(ctx, input, options);
|
|
61
|
-
$img.getSizes = (input, options) => getSizes(ctx, input, options);
|
|
62
|
-
ctx.$img = $img;
|
|
63
|
-
return $img;
|
|
64
|
-
}
|
|
65
|
-
async function getMeta(ctx, input, options) {
|
|
66
|
-
const image = resolveImage(ctx, input, {...options});
|
|
67
|
-
if (typeof image.getMeta === "function") {
|
|
68
|
-
return await image.getMeta();
|
|
69
|
-
} else {
|
|
70
|
-
return await imageMeta(ctx, image.url);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function resolveImage(ctx, input, options) {
|
|
74
|
-
if (typeof input !== "string" || input === "") {
|
|
75
|
-
throw new TypeError(`input must be a string (received ${typeof input}: ${JSON.stringify(input)})`);
|
|
76
|
-
}
|
|
77
|
-
if (input.startsWith("data:")) {
|
|
78
|
-
return {
|
|
79
|
-
url: input
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const {provider, defaults} = getProvider(ctx, options.provider || ctx.options.provider);
|
|
83
|
-
const preset = getPreset(ctx, options.preset);
|
|
84
|
-
input = hasProtocol(input) ? input : withLeadingSlash(input);
|
|
85
|
-
if (!provider.supportsAlias) {
|
|
86
|
-
for (const base in ctx.options.alias) {
|
|
87
|
-
if (input.startsWith(base)) {
|
|
88
|
-
input = joinURL(ctx.options.alias[base], input.substr(base.length));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (provider.validateDomains && hasProtocol(input)) {
|
|
93
|
-
const inputHost = parseURL(input).host;
|
|
94
|
-
if (!ctx.options.domains.find((d) => d === inputHost)) {
|
|
95
|
-
return {
|
|
96
|
-
url: input
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const _options = defu(options, preset, defaults);
|
|
101
|
-
_options.modifiers = {..._options.modifiers};
|
|
102
|
-
const expectedFormat = _options.modifiers.format;
|
|
103
|
-
if (_options.modifiers?.width) {
|
|
104
|
-
_options.modifiers.width = parseSize(_options.modifiers.width);
|
|
105
|
-
}
|
|
106
|
-
if (_options.modifiers?.height) {
|
|
107
|
-
_options.modifiers.height = parseSize(_options.modifiers.height);
|
|
108
|
-
}
|
|
109
|
-
const image = provider.getImage(input, _options, ctx);
|
|
110
|
-
image.format = image.format || expectedFormat || "";
|
|
111
|
-
return image;
|
|
112
|
-
}
|
|
113
|
-
function getProvider(ctx, name) {
|
|
114
|
-
const provider = ctx.options.providers[name];
|
|
115
|
-
if (!provider) {
|
|
116
|
-
throw new Error("Unknown provider: " + name);
|
|
117
|
-
}
|
|
118
|
-
return provider;
|
|
119
|
-
}
|
|
120
|
-
function getPreset(ctx, name) {
|
|
121
|
-
if (!name) {
|
|
122
|
-
return {};
|
|
123
|
-
}
|
|
124
|
-
if (!ctx.options.presets[name]) {
|
|
125
|
-
throw new Error("Unknown preset: " + name);
|
|
126
|
-
}
|
|
127
|
-
return ctx.options.presets[name];
|
|
128
|
-
}
|
|
129
|
-
function getSizes(ctx, input, opts) {
|
|
130
|
-
const width = parseSize(opts.modifiers?.width);
|
|
131
|
-
const height = parseSize(opts.modifiers?.height);
|
|
132
|
-
const hwRatio = width && height ? height / width : 0;
|
|
133
|
-
const variants = [];
|
|
134
|
-
const sizes = {};
|
|
135
|
-
if (typeof opts.sizes === "string") {
|
|
136
|
-
for (const entry of opts.sizes.split(/[\s,]+/).filter((e) => e)) {
|
|
137
|
-
const s = entry.split(":");
|
|
138
|
-
if (s.length !== 2) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
sizes[s[0].trim()] = s[1].trim();
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
Object.assign(sizes, opts.sizes);
|
|
145
|
-
}
|
|
146
|
-
for (const key in sizes) {
|
|
147
|
-
const screenMaxWidth = ctx.options.screens && ctx.options.screens[key] || parseInt(key);
|
|
148
|
-
let size = String(sizes[key]);
|
|
149
|
-
const isFluid = size.endsWith("vw");
|
|
150
|
-
if (!isFluid && /^\d+$/.test(size)) {
|
|
151
|
-
size = size + "px";
|
|
152
|
-
}
|
|
153
|
-
if (!isFluid && !size.endsWith("px")) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
let _cWidth = parseInt(size);
|
|
157
|
-
if (!screenMaxWidth || !_cWidth) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (isFluid) {
|
|
161
|
-
_cWidth = Math.round(_cWidth / 100 * screenMaxWidth);
|
|
162
|
-
}
|
|
163
|
-
const _cHeight = hwRatio ? Math.round(_cWidth * hwRatio) : height;
|
|
164
|
-
variants.push({
|
|
165
|
-
width: _cWidth,
|
|
166
|
-
size,
|
|
167
|
-
screenMaxWidth,
|
|
168
|
-
media: `(max-width: ${screenMaxWidth}px)`,
|
|
169
|
-
src: ctx.$img(input, {...opts.modifiers, width: _cWidth, height: _cHeight}, opts)
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
variants.sort((v1, v2) => v1.screenMaxWidth - v2.screenMaxWidth);
|
|
173
|
-
const defaultVar = variants[variants.length - 1];
|
|
174
|
-
if (defaultVar) {
|
|
175
|
-
defaultVar.media = "";
|
|
176
|
-
}
|
|
177
|
-
let srcset = [];
|
|
178
|
-
if (ctx.options.srcset && ctx.options.srcset.length) {
|
|
179
|
-
srcset = ctx.options.srcset.map((width2) => {
|
|
180
|
-
const _cHeight = hwRatio ? Math.round(width2 * hwRatio) : height;
|
|
181
|
-
return {
|
|
182
|
-
src: ctx.$img(input, {...opts.modifiers, width: width2, height: _cHeight}, opts),
|
|
183
|
-
width: width2
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
} else {
|
|
187
|
-
srcset = variants;
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
sizes: variants.map((v) => `${v.media ? v.media + " " : ""}${v.size}`).join(", "),
|
|
191
|
-
srcset: srcset.map((v) => `${v.src} ${v.width}w`).join(", "),
|
|
192
|
-
src: defaultVar?.src
|
|
193
|
-
};
|
|
194
|
-
}
|
package/dist/runtime/index.d.ts
DELETED
package/dist/runtime/index.js
DELETED
package/dist/runtime/ipx.d.ts
DELETED
package/dist/runtime/ipx.js
DELETED
package/dist/runtime/plugin.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function _default(nuxtContext: any, inject: any): void;
|
package/dist/runtime/plugin.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Vue from 'vue'
|
|
2
|
-
import { createImage} from '~image'
|
|
3
|
-
import NuxtImg from '~image/components/nuxt-img.vue'
|
|
4
|
-
import NuxtPicture from '~image/components/nuxt-picture.vue'
|
|
5
|
-
|
|
6
|
-
<%=options.providers.map(p => `import * as ${p.importName} from '${p.runtime}'`).join('\n')%>
|
|
7
|
-
|
|
8
|
-
const imageOptions = <%= JSON.stringify(options.imageOptions, null, 2) %>
|
|
9
|
-
|
|
10
|
-
imageOptions.providers = {
|
|
11
|
-
<%=options.providers.map(p => ` ['${p.name}']: { provider: ${p.importName}, defaults: ${JSON.stringify(p.runtimeOptions)} }`).join(',\n') %>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Vue.component(NuxtImg.name, NuxtImg)
|
|
16
|
-
Vue.component(NuxtPicture.name, NuxtPicture)
|
|
17
|
-
Vue.component('NImg', NuxtImg)
|
|
18
|
-
Vue.component('NPicture', NuxtPicture)
|
|
19
|
-
|
|
20
|
-
export default function (nuxtContext, inject) {
|
|
21
|
-
const $img = createImage(imageOptions, nuxtContext)
|
|
22
|
-
|
|
23
|
-
if (process.static && process.server) {
|
|
24
|
-
nuxtContext.beforeNuxtRender(({ nuxtState }) => {
|
|
25
|
-
const ssrData = nuxtState.data[0] || {}
|
|
26
|
-
ssrData._img = nuxtState._img || {}
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
inject('img', $img)
|
|
31
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {joinURL, encodePath} from "ufo";
|
|
2
|
-
import defu from "defu";
|
|
3
|
-
import {createOperationsGenerator} from "~image";
|
|
4
|
-
const convertHextoRGBFormat = (value) => value.startsWith("#") ? value.replace("#", "rgb_") : value;
|
|
5
|
-
const removePathExtension = (value) => value.replace(/\.[^/.]+$/, "");
|
|
6
|
-
const operationsGenerator = createOperationsGenerator({
|
|
7
|
-
keyMap: {
|
|
8
|
-
fit: "c",
|
|
9
|
-
width: "w",
|
|
10
|
-
height: "h",
|
|
11
|
-
format: "f",
|
|
12
|
-
quality: "q",
|
|
13
|
-
background: "b",
|
|
14
|
-
rotate: "a",
|
|
15
|
-
roundCorner: "r",
|
|
16
|
-
gravity: "g",
|
|
17
|
-
effect: "e",
|
|
18
|
-
color: "co",
|
|
19
|
-
flags: "fl",
|
|
20
|
-
dpr: "dpr",
|
|
21
|
-
opacity: "o",
|
|
22
|
-
overlay: "l",
|
|
23
|
-
underlay: "u",
|
|
24
|
-
transformation: "t",
|
|
25
|
-
zoom: "z",
|
|
26
|
-
colorSpace: "cs",
|
|
27
|
-
customFunc: "fn",
|
|
28
|
-
density: "dpi"
|
|
29
|
-
},
|
|
30
|
-
valueMap: {
|
|
31
|
-
fit: {
|
|
32
|
-
fill: "fill",
|
|
33
|
-
inside: "pad",
|
|
34
|
-
outside: "lpad",
|
|
35
|
-
cover: "fit",
|
|
36
|
-
contain: "scale",
|
|
37
|
-
minCover: "mfit",
|
|
38
|
-
minInside: "mpad",
|
|
39
|
-
thumbnail: "thumb",
|
|
40
|
-
cropping: "crop",
|
|
41
|
-
coverLimit: "limit"
|
|
42
|
-
},
|
|
43
|
-
format: {
|
|
44
|
-
jpeg: "jpg"
|
|
45
|
-
},
|
|
46
|
-
background(value) {
|
|
47
|
-
return convertHextoRGBFormat(value);
|
|
48
|
-
},
|
|
49
|
-
color(value) {
|
|
50
|
-
return convertHextoRGBFormat(value);
|
|
51
|
-
},
|
|
52
|
-
gravity: {
|
|
53
|
-
auto: "auto",
|
|
54
|
-
subject: "auto:subject",
|
|
55
|
-
face: "face",
|
|
56
|
-
sink: "sink",
|
|
57
|
-
faceCenter: "face:center",
|
|
58
|
-
multipleFaces: "faces",
|
|
59
|
-
multipleFacesCenter: "faces:center",
|
|
60
|
-
north: "north",
|
|
61
|
-
northEast: "north_east",
|
|
62
|
-
northWest: "north_west",
|
|
63
|
-
west: "west",
|
|
64
|
-
southWest: "south_west",
|
|
65
|
-
south: "south",
|
|
66
|
-
southEast: "south_east",
|
|
67
|
-
east: "east",
|
|
68
|
-
center: "center"
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
joinWith: ",",
|
|
72
|
-
formatter: (key, value) => `${key}_${value}`
|
|
73
|
-
});
|
|
74
|
-
const defaultModifiers = {
|
|
75
|
-
format: "auto",
|
|
76
|
-
quality: "auto"
|
|
77
|
-
};
|
|
78
|
-
export const getImage = (src, {modifiers = {}, baseURL = "/"} = {}) => {
|
|
79
|
-
const mergeModifiers = defu(modifiers, defaultModifiers);
|
|
80
|
-
const operations = operationsGenerator(mergeModifiers);
|
|
81
|
-
const remoteFolderMapping = baseURL.match(/\/image\/upload\/(.*)/);
|
|
82
|
-
if (remoteFolderMapping?.length >= 1) {
|
|
83
|
-
const remoteFolder = remoteFolderMapping[1];
|
|
84
|
-
const baseURLWithoutRemoteFolder = baseURL.replace(remoteFolder, "");
|
|
85
|
-
return {
|
|
86
|
-
url: joinURL(baseURLWithoutRemoteFolder, operations, remoteFolder, src)
|
|
87
|
-
};
|
|
88
|
-
} else if (/\/image\/fetch\/?/.test(baseURL)) {
|
|
89
|
-
src = encodePath(src);
|
|
90
|
-
} else {
|
|
91
|
-
src = removePathExtension(src);
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
url: joinURL(baseURL, operations, src)
|
|
95
|
-
};
|
|
96
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {joinURL} from "ufo";
|
|
2
|
-
import {createOperationsGenerator} from "~image";
|
|
3
|
-
const operationsGenerator = createOperationsGenerator({
|
|
4
|
-
valueMap: {
|
|
5
|
-
fit: {
|
|
6
|
-
fill: "crop",
|
|
7
|
-
inside: "crop",
|
|
8
|
-
outside: "crop",
|
|
9
|
-
cover: "bounds",
|
|
10
|
-
contain: "bounds"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
joinWith: "&",
|
|
14
|
-
formatter: (key, value) => `${key}=${value}`
|
|
15
|
-
});
|
|
16
|
-
export const getImage = (src, {modifiers = {}, baseURL = "/"} = {}) => {
|
|
17
|
-
const operations = operationsGenerator(modifiers);
|
|
18
|
-
return {
|
|
19
|
-
url: joinURL(baseURL, src + (operations ? "?" + operations : ""))
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {joinURL, encodeQueryItem, encodePath} from "ufo";
|
|
2
|
-
import {createOperationsGenerator} from "~image";
|
|
3
|
-
const operationsGenerator = createOperationsGenerator({
|
|
4
|
-
keyMap: {
|
|
5
|
-
orientation: "or",
|
|
6
|
-
flip: "flip",
|
|
7
|
-
crop: "crop",
|
|
8
|
-
width: "w",
|
|
9
|
-
height: "h",
|
|
10
|
-
fit: "fit",
|
|
11
|
-
dpr: "dpr",
|
|
12
|
-
bri: "bri",
|
|
13
|
-
con: "con",
|
|
14
|
-
gam: "gam",
|
|
15
|
-
sharp: "sharp",
|
|
16
|
-
blur: "blur",
|
|
17
|
-
pixel: "pixel",
|
|
18
|
-
filt: "filt",
|
|
19
|
-
mark: "mark",
|
|
20
|
-
markw: "markw",
|
|
21
|
-
markh: "markh",
|
|
22
|
-
markx: "markx",
|
|
23
|
-
marky: "marky",
|
|
24
|
-
markpad: "markpad",
|
|
25
|
-
markpos: "markpos",
|
|
26
|
-
markalpha: "markalpha",
|
|
27
|
-
background: "bg",
|
|
28
|
-
border: "border",
|
|
29
|
-
quality: "q",
|
|
30
|
-
format: "fm"
|
|
31
|
-
},
|
|
32
|
-
valueMap: {
|
|
33
|
-
fit: {
|
|
34
|
-
fill: "fill",
|
|
35
|
-
inside: "max",
|
|
36
|
-
outside: "stretch",
|
|
37
|
-
cover: "crop",
|
|
38
|
-
contain: "contain"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
joinWith: "&",
|
|
42
|
-
formatter: (key, val) => encodeQueryItem(key, val)
|
|
43
|
-
});
|
|
44
|
-
export const getImage = (src, {modifiers = {}, baseURL = "/"} = {}) => {
|
|
45
|
-
const params = operationsGenerator(modifiers);
|
|
46
|
-
return {
|
|
47
|
-
url: joinURL(baseURL, encodePath(src) + (params ? "?" + params : ""))
|
|
48
|
-
};
|
|
49
|
-
};
|