@bagelink/vue 1.20.58 → 1.20.64
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/assets.d.ts +5 -0
- package/dist/assets.d.ts.map +1 -1
- package/dist/components/Image.vue.d.ts +2 -0
- package/dist/components/Image.vue.d.ts.map +1 -1
- package/dist/core.css +1 -1
- package/dist/index.cjs +40 -40
- package/dist/index.css +1 -1
- package/dist/index.mjs +2886 -2873
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/assets.test.ts +21 -1
- package/src/assets.ts +23 -0
- package/src/components/Image.vue +11 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.20.
|
|
4
|
+
"version": "1.20.64",
|
|
5
5
|
"description": "Bagel core sdk packages",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@types/signature_pad": "^4.0.0",
|
|
64
64
|
"vue": "^3.5.43",
|
|
65
65
|
"vue-component-type-helpers": "^2.2.12",
|
|
66
|
-
"@bagelink/sdk": "1.20.
|
|
66
|
+
"@bagelink/sdk": "1.20.64"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@bagelink/sdk": "*",
|
package/src/assets.test.ts
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
-
import { createAssetClient, ASSET_CLIENT_KEY, useAssetDelivery, useAssetUpload, type AssetTransport } from './assets'
|
|
3
|
+
import { optimizeAssetImage, createAssetClient, ASSET_CLIENT_KEY, useAssetDelivery, useAssetUpload, type AssetTransport } from './assets'
|
|
4
4
|
import { mount } from '@vue/test-utils'
|
|
5
5
|
import { defineComponent, nextTick } from 'vue'
|
|
6
6
|
|
|
7
7
|
const BASE = 'https://cdn.bgl.dev/auctentic'
|
|
8
8
|
|
|
9
|
+
describe('public image optimization', () => {
|
|
10
|
+
it('bounds both original and format-only URLs', () => {
|
|
11
|
+
for (const source of [`${BASE}/a`, `${BASE}/a?fmt=webp`]) {
|
|
12
|
+
expect(optimizeAssetImage(source, 640)).toBe(`${BASE}/a?fmt=webp&w=640&fit=inside&q=75`)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('preserves authored transforms, signatures, formats and other origins', () => {
|
|
17
|
+
for (const source of [
|
|
18
|
+
`${BASE}/a?w=1200&h=630&fit=cover`,
|
|
19
|
+
`${BASE}/a?token=secret`,
|
|
20
|
+
`${BASE}/a?fmt=gif`,
|
|
21
|
+
'https://other.example/a.jpg',
|
|
22
|
+
'/logo.svg',
|
|
23
|
+
]) expect(optimizeAssetImage(source, 640)).toBe(source)
|
|
24
|
+
expect(optimizeAssetImage(null, 640)).toBe('')
|
|
25
|
+
expect(optimizeAssetImage(`${BASE}/a`, NaN)).toBe(`${BASE}/a`)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
9
29
|
function makeClient(upload?: AssetTransport['upload']) {
|
|
10
30
|
const transport = { upload: upload ?? (async () => ({ asset_id: 'a' })) }
|
|
11
31
|
return createAssetClient(transport, BASE)
|
package/src/assets.ts
CHANGED
|
@@ -29,6 +29,29 @@ export interface AssetUploadOptions {
|
|
|
29
29
|
/** Display purpose → on-demand transform query params (mirrors common/blox). */
|
|
30
30
|
export type AssetPurpose = 'original' | 'preview' | 'thumbnail' | 'website' | 'social'
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Bound public CDN images without rewriting explicit crops, signed URLs, or
|
|
34
|
+
* third-party sources. Format-only URLs still need a display-size bound.
|
|
35
|
+
*/
|
|
36
|
+
export function optimizeAssetImage(
|
|
37
|
+
source: string | null | undefined,
|
|
38
|
+
width: number,
|
|
39
|
+
): string {
|
|
40
|
+
if (!source) return ''
|
|
41
|
+
let url: URL
|
|
42
|
+
try { url = new URL(source) } catch { return source }
|
|
43
|
+
if (url.protocol !== 'https:' || url.hostname !== 'cdn.bgl.dev') return source
|
|
44
|
+
if (!Number.isFinite(width) || width <= 0) return source
|
|
45
|
+
if ([...url.searchParams.keys()].some(key => key !== 'fmt')) return source
|
|
46
|
+
// Preserve explicitly selected formats, including animated originals.
|
|
47
|
+
if (url.searchParams.has('fmt') && url.searchParams.get('fmt') !== 'webp') return source
|
|
48
|
+
url.searchParams.set('fmt', 'webp')
|
|
49
|
+
url.searchParams.set('w', String(Math.round(width)))
|
|
50
|
+
url.searchParams.set('fit', 'inside')
|
|
51
|
+
url.searchParams.set('q', '75')
|
|
52
|
+
return url.toString()
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
const PURPOSE_PARAMS: Record<AssetPurpose, string> = {
|
|
33
56
|
original: '',
|
|
34
57
|
preview: 'fmt=webp',
|
package/src/components/Image.vue
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
defineOptions({ name: 'BglImage', inheritAttrs: false })
|
|
3
3
|
import { Skeleton, normalizeDimension, Icon, useImageSrc } from '../index'
|
|
4
4
|
import type { AssetDeliveryRequest, AssetPurpose } from '../assets'
|
|
5
|
+
import { optimizeAssetImage } from '../assets'
|
|
5
6
|
import { Comment, computed, ref, useSlots, watch, type StyleValue, type VNode } from 'vue'
|
|
6
7
|
|
|
7
8
|
interface ImageProps {
|
|
@@ -14,6 +15,8 @@ interface ImageProps {
|
|
|
14
15
|
pathKey?: string
|
|
15
16
|
alt?: string
|
|
16
17
|
width?: string | number
|
|
18
|
+
/** CDN pixel bound, independent of layout width. Preserves explicit crops. */
|
|
19
|
+
deliveryWidth?: number
|
|
17
20
|
height?: string | number
|
|
18
21
|
caption?: string
|
|
19
22
|
modelValue?: string
|
|
@@ -38,10 +41,13 @@ const { imageSrc, loadingError, onError } = useImageSrc(() => props.assetId
|
|
|
38
41
|
: typeof props.src === 'object'
|
|
39
42
|
? { ...props.src, representation: props.purpose ?? props.src.representation }
|
|
40
43
|
: props.src ?? props.pathKey ?? props.modelValue)
|
|
44
|
+
const deliveredSrc = computed(() => props.deliveryWidth
|
|
45
|
+
? optimizeAssetImage(imageSrc.value, props.deliveryWidth)
|
|
46
|
+
: imageSrc.value)
|
|
41
47
|
const imageLoaded = ref(false)
|
|
42
48
|
|
|
43
|
-
watch(
|
|
44
|
-
|
|
49
|
+
watch(deliveredSrc, () => {
|
|
50
|
+
imageLoaded.value = false
|
|
45
51
|
})
|
|
46
52
|
watch(() => [props.assetId, props.versionId, props.purpose, props.src, props.pathKey, props.modelValue], () => {
|
|
47
53
|
imageLoaded.value = false
|
|
@@ -110,7 +116,7 @@ const imgFit = computed(() => props.fit ?? 'cover')
|
|
|
110
116
|
>
|
|
111
117
|
<img
|
|
112
118
|
v-if="imageSrc"
|
|
113
|
-
:src="
|
|
119
|
+
:src="deliveredSrc"
|
|
114
120
|
:alt="alt"
|
|
115
121
|
:loading="lazy ? 'lazy' : undefined"
|
|
116
122
|
decoding="async"
|
|
@@ -131,7 +137,7 @@ const imgFit = computed(() => props.fit ?? 'cover')
|
|
|
131
137
|
<div class="relative">
|
|
132
138
|
<img
|
|
133
139
|
v-if="imageSrc"
|
|
134
|
-
:src="
|
|
140
|
+
:src="deliveredSrc"
|
|
135
141
|
v-bind="$attrs"
|
|
136
142
|
:alt="alt"
|
|
137
143
|
:loading="lazy ? 'lazy' : undefined"
|
|
@@ -159,7 +165,7 @@ const imgFit = computed(() => props.fit ?? 'cover')
|
|
|
159
165
|
>
|
|
160
166
|
<img
|
|
161
167
|
v-if="imageSrc"
|
|
162
|
-
:src="
|
|
168
|
+
:src="deliveredSrc"
|
|
163
169
|
:alt="alt"
|
|
164
170
|
:loading="lazy ? 'lazy' : undefined"
|
|
165
171
|
decoding="async"
|