@absolutejs/absolute 0.19.0-beta.179 → 0.19.0-beta.180
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/vue/components/Image.vue +140 -0
- package/package.json +8 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue';
|
|
3
|
+
import type { ImageProps } from '../../../types/image';
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_QUALITY,
|
|
6
|
+
buildOptimizedUrl,
|
|
7
|
+
generateBlurSvg,
|
|
8
|
+
generateSrcSet
|
|
9
|
+
} from '../../utils/imageProcessing';
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<ImageProps>(), {
|
|
12
|
+
quality: DEFAULT_QUALITY,
|
|
13
|
+
loading: 'lazy'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const blurRemoved = ref(false);
|
|
17
|
+
|
|
18
|
+
const resolvedSrc = computed(() => {
|
|
19
|
+
if (props.overrideSrc) return props.overrideSrc;
|
|
20
|
+
if (props.unoptimized) return props.src;
|
|
21
|
+
if (props.loader) return props.loader({ src: props.src, width: props.width ?? 0, quality: props.quality });
|
|
22
|
+
if (!props.width) return buildOptimizedUrl(props.src, 0, props.quality);
|
|
23
|
+
return buildOptimizedUrl(props.src, props.width, props.quality);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const srcSet = computed(() =>
|
|
27
|
+
props.unoptimized
|
|
28
|
+
? undefined
|
|
29
|
+
: generateSrcSet(props.src, props.width, props.sizes, undefined, props.loader ?? undefined)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const resolvedSizes = computed(() => props.sizes ?? (props.fill ? '100vw' : undefined));
|
|
33
|
+
|
|
34
|
+
const resolvedLoading = computed(() => (props.priority ? 'eager' : props.loading));
|
|
35
|
+
|
|
36
|
+
const resolvedFetchPriority = computed(() => (props.priority ? 'high' : props.fetchPriority));
|
|
37
|
+
|
|
38
|
+
const hasBlur = computed(() =>
|
|
39
|
+
props.placeholder === 'blur' ||
|
|
40
|
+
(typeof props.placeholder === 'string' &&
|
|
41
|
+
props.placeholder !== 'empty' &&
|
|
42
|
+
props.placeholder.startsWith('data:'))
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const blurBackground = computed(() => {
|
|
46
|
+
if (!hasBlur.value || blurRemoved.value) return undefined;
|
|
47
|
+
if (
|
|
48
|
+
typeof props.placeholder === 'string' &&
|
|
49
|
+
props.placeholder !== 'blur' &&
|
|
50
|
+
props.placeholder.startsWith('data:')
|
|
51
|
+
) {
|
|
52
|
+
return generateBlurSvg(props.placeholder);
|
|
53
|
+
}
|
|
54
|
+
if (props.blurDataURL) return generateBlurSvg(props.blurDataURL);
|
|
55
|
+
return undefined;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const imgStyle = computed(() => {
|
|
59
|
+
const base: Record<string, string | number> = {
|
|
60
|
+
...(props.style ?? {}),
|
|
61
|
+
color: 'transparent'
|
|
62
|
+
};
|
|
63
|
+
if (blurBackground.value) {
|
|
64
|
+
base.backgroundImage = blurBackground.value;
|
|
65
|
+
base.backgroundSize = 'cover';
|
|
66
|
+
base.backgroundPosition = 'center';
|
|
67
|
+
base.backgroundRepeat = 'no-repeat';
|
|
68
|
+
}
|
|
69
|
+
if (props.fill) {
|
|
70
|
+
base.position = 'absolute';
|
|
71
|
+
base.height = '100%';
|
|
72
|
+
base.width = '100%';
|
|
73
|
+
base.inset = '0';
|
|
74
|
+
base.objectFit = 'cover';
|
|
75
|
+
}
|
|
76
|
+
return base;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const handleLoad = (e: Event) => {
|
|
80
|
+
blurRemoved.value = true;
|
|
81
|
+
if (props.onLoad) (props.onLoad as (event: Event) => void)(e);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleError = (e: Event) => {
|
|
85
|
+
if (props.onError) (props.onError as (event: Event) => void)(e);
|
|
86
|
+
};
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<Teleport to="head" v-if="priority">
|
|
91
|
+
<link
|
|
92
|
+
rel="preload"
|
|
93
|
+
as="image"
|
|
94
|
+
:href="resolvedSrc"
|
|
95
|
+
:imagesrcset="srcSet"
|
|
96
|
+
:imagesizes="resolvedSizes"
|
|
97
|
+
:crossorigin="crossOrigin"
|
|
98
|
+
/>
|
|
99
|
+
</Teleport>
|
|
100
|
+
|
|
101
|
+
<span
|
|
102
|
+
v-if="fill"
|
|
103
|
+
style="position: relative; overflow: hidden; display: block; width: 100%; height: 100%"
|
|
104
|
+
>
|
|
105
|
+
<img
|
|
106
|
+
:alt="alt"
|
|
107
|
+
:src="resolvedSrc"
|
|
108
|
+
:srcset="srcSet"
|
|
109
|
+
:sizes="resolvedSizes"
|
|
110
|
+
:loading="resolvedLoading"
|
|
111
|
+
:class="className"
|
|
112
|
+
:style="imgStyle"
|
|
113
|
+
:crossorigin="crossOrigin"
|
|
114
|
+
:referrerpolicy="referrerPolicy"
|
|
115
|
+
:fetchpriority="resolvedFetchPriority"
|
|
116
|
+
decoding="async"
|
|
117
|
+
@load="handleLoad"
|
|
118
|
+
@error="handleError"
|
|
119
|
+
/>
|
|
120
|
+
</span>
|
|
121
|
+
|
|
122
|
+
<img
|
|
123
|
+
v-else
|
|
124
|
+
:alt="alt"
|
|
125
|
+
:src="resolvedSrc"
|
|
126
|
+
:srcset="srcSet"
|
|
127
|
+
:sizes="resolvedSizes"
|
|
128
|
+
:width="width"
|
|
129
|
+
:height="height"
|
|
130
|
+
:loading="resolvedLoading"
|
|
131
|
+
:class="className"
|
|
132
|
+
:style="imgStyle"
|
|
133
|
+
:crossorigin="crossOrigin"
|
|
134
|
+
:referrerpolicy="referrerPolicy"
|
|
135
|
+
:fetchpriority="resolvedFetchPriority"
|
|
136
|
+
decoding="async"
|
|
137
|
+
@load="handleLoad"
|
|
138
|
+
@error="handleError"
|
|
139
|
+
/>
|
|
140
|
+
</template>
|
package/package.json
CHANGED
|
@@ -103,6 +103,12 @@
|
|
|
103
103
|
"import": "./dist/vue/components/index.js",
|
|
104
104
|
"types": "./dist/src/vue/components/index.d.ts"
|
|
105
105
|
},
|
|
106
|
+
"./vue/components/Image.vue": {
|
|
107
|
+
"import": "./dist/vue/components/Image.vue"
|
|
108
|
+
},
|
|
109
|
+
"./vue/components/Image.js": {
|
|
110
|
+
"import": "./dist/vue/components/Image.vue"
|
|
111
|
+
},
|
|
106
112
|
"./angular/components": {
|
|
107
113
|
"import": "./dist/angular/components/index.js",
|
|
108
114
|
"types": "./dist/src/angular/components/index.d.ts"
|
|
@@ -184,7 +190,7 @@
|
|
|
184
190
|
"url": "git+https://github.com/absolutejs/absolutejs.git"
|
|
185
191
|
},
|
|
186
192
|
"scripts": {
|
|
187
|
-
"build": "rm -rf dist && bun build src/index.ts src/build.ts src/angular/index.ts src/angular/components/index.ts src/react/index.ts src/react/hooks/index.ts src/svelte/index.ts src/vue/index.ts src/vue/components/index.ts --outdir dist --sourcemap --target=bun --external react --external react-dom --external vue --external @vue/compiler-sfc --external vue/server-renderer --external svelte --external svelte/compiler --external svelte/server --external elysia --external @elysiajs/static --external @angular/compiler-cli --external @angular/core --external @angular/common --external @angular/platform-browser --external @angular/platform-server --external @angular/ssr --external zone.js --external debug --external sharp --external @absolutejs/native-linux-x64 --external @absolutejs/native-linux-arm64 --external @absolutejs/native-darwin-x64 --external @absolutejs/native-darwin-arm64 && bun build src/cli/index.ts --outfile dist/cli/index.js --target=bun && tsc --emitDeclarationOnly --project tsconfig.build.json && mkdir -p dist/dev && cp -r src/dev/client dist/dev/client && mkdir -p dist/svelte/components && cp src/svelte/components/*.svelte dist/svelte/components/",
|
|
193
|
+
"build": "rm -rf dist && bun build src/index.ts src/build.ts src/angular/index.ts src/angular/components/index.ts src/react/index.ts src/react/hooks/index.ts src/svelte/index.ts src/vue/index.ts src/vue/components/index.ts --outdir dist --sourcemap --target=bun --external react --external react-dom --external vue --external @vue/compiler-sfc --external vue/server-renderer --external svelte --external svelte/compiler --external svelte/server --external elysia --external @elysiajs/static --external @angular/compiler-cli --external @angular/core --external @angular/common --external @angular/platform-browser --external @angular/platform-server --external @angular/ssr --external zone.js --external debug --external sharp --external @absolutejs/native-linux-x64 --external @absolutejs/native-linux-arm64 --external @absolutejs/native-darwin-x64 --external @absolutejs/native-darwin-arm64 && bun build src/cli/index.ts --outfile dist/cli/index.js --target=bun && tsc --emitDeclarationOnly --project tsconfig.build.json && mkdir -p dist/dev && cp -r src/dev/client dist/dev/client && mkdir -p dist/svelte/components && cp src/svelte/components/*.svelte dist/svelte/components/ && mkdir -p dist/vue/components && cp src/vue/components/*.vue dist/vue/components/",
|
|
188
194
|
"build:native": "./native/build.sh",
|
|
189
195
|
"db:push": "drizzle-kit push",
|
|
190
196
|
"db:studio": "drizzle-kit studio",
|
|
@@ -198,5 +204,5 @@
|
|
|
198
204
|
"typecheck": "bun run vue-tsc --noEmit"
|
|
199
205
|
},
|
|
200
206
|
"types": "./dist/src/index.d.ts",
|
|
201
|
-
"version": "0.19.0-beta.
|
|
207
|
+
"version": "0.19.0-beta.180"
|
|
202
208
|
}
|