@bagelink/vue 1.20.58 → 1.20.66

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.20.58",
4
+ "version": "1.20.66",
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.58"
66
+ "@bagelink/sdk": "1.20.66"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@bagelink/sdk": "*",
@@ -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',
@@ -13,7 +13,7 @@ const props = withDefaults(
13
13
  iconSize?: number | string
14
14
  iconMobileSize?: number | string
15
15
  color?: ExtendedThemeType
16
- variant?: 'solid' | 'flat' | 'outline' | 'soft' | 'frost'
16
+ variant?: 'solid' | 'flat' | 'outline' | 'soft' | 'frost' | 'gloss' | 'bevel'
17
17
  /** Boolean variant shorthands: <Btn flat /> — same as variant="flat" */
18
18
  flat?: boolean
19
19
  outline?: boolean
@@ -23,6 +23,17 @@ const props = withDefaults(
23
23
  /** Frost variant: translucent + blur, tinted by `color`. Reads beautifully
24
24
  over photos / gradients / dark heroes. Shorthand for variant="frost". */
25
25
  frost?: boolean
26
+ /** Gloss variant: a glossy, tactile 3D fill — a tone-derived top-light
27
+ sweep, an inner top highlight + bottom bevel, a soft drop shadow, and a
28
+ press-down :active state. Driven by `color`; works with every size,
29
+ `round` (pill) and icon-only (circle) shape. Shorthand for
30
+ variant="gloss". e.g. <Btn color="blue" gloss value="Save" /> */
31
+ gloss?: boolean
32
+ /** Bevel variant: `gloss`'s material without any shadow — the same
33
+ tone-derived sweep and inner highlight/bevel, but flush with the
34
+ surface. Use it in dense toolbars, list rows, or inside a card that
35
+ already has its own elevation. Shorthand for variant="bevel". */
36
+ bevel?: boolean
26
37
  /** Gradient fill (white text). Boolean = auto (a darker shade of `color`);
27
38
  or a space-separated tone list — "purple" pairs with `color`
28
39
  (blue→purple), "blue purple pink" defines all stops. */
@@ -92,6 +103,10 @@ const { isGradient, gradientStyle } = useGradientVariant({
92
103
  const computedVariant = computed(() => {
93
104
  if (props.variant) { return props.variant }
94
105
  if (isGradient.value) { return 'gradient' }
106
+ // Gloss / bevel are filled variants like gradient, so they resolve before the
107
+ // translucent / tinted ones and override an inherited `flat`.
108
+ if (props.gloss) { return 'gloss' }
109
+ if (props.bevel) { return 'bevel' }
95
110
  if (props.frost) { return 'frost' }
96
111
  if (props.soft) { return 'soft' }
97
112
  // An explicit `outline` wins over `flat` — components like Dropdown default
@@ -114,7 +129,8 @@ const computedPairClass = computed(() => {
114
129
  }
115
130
  // Gradient with explicit stops (e.g. gradient="blue purple") needs a pair
116
131
  // class only to activate `.gradient`; default to primary for the auto case.
117
- if (computedVariant.value === 'gradient') {
132
+ // Gloss / bevel likewise default to primary — a colored button is the point.
133
+ if (computedVariant.value === 'gradient' || computedVariant.value === 'gloss' || computedVariant.value === 'bevel') {
118
134
  return 'pair-primary'
119
135
  }
120
136
  // Only flat/outline/soft buttons get a default for visibility
@@ -230,6 +246,8 @@ const slots: SetupContext['slots'] = useSlots()
230
246
  'bgl_pill-border': computedVariant === 'outline',
231
247
  'soft': computedVariant === 'soft',
232
248
  'frost': computedVariant === 'frost',
249
+ 'gloss': computedVariant === 'gloss',
250
+ 'bevel': computedVariant === 'bevel',
233
251
  'gradient': computedVariant === 'gradient',
234
252
  'bgl_pill-frame': frame,
235
253
  relative: loading,
@@ -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(imageSrc, value => {
44
- if (!value) imageLoaded.value = false
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="imageSrc"
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="imageSrc"
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="imageSrc"
168
+ :src="deliveredSrc"
163
169
  :alt="alt"
164
170
  :loading="lazy ? 'lazy' : undefined"
165
171
  decoding="async"
@@ -210,41 +210,22 @@ th {
210
210
  getCleanHTML(), which strips the editor-only .image-figure class from output. */
211
211
  .richtext-editor-content figure.align-full {
212
212
  float: none;
213
- /* See rich-content.css: without clearing, a full-width figure's box starts at
214
- the float's top and its badge is painted over the floated media. */
215
- clear: both;
216
213
  width: 100%;
217
214
  margin-inline: auto;
218
215
  }
219
216
 
220
- /* The gap is reserved inside the 50% so two opposing floats fit one line:
221
- 2 × (50% - gap) + 2 × gap = 100%. See rich-content.css for the rationale. */
222
- .richtext-editor-content figure.align-start,
223
- .richtext-editor-content figure.align-end {
224
- --rich-figure-gap: 1.5rem;
225
- width: 50%;
226
- max-width: calc(50% - var(--rich-figure-gap) - 1px);
227
- margin-block: 0.25rem 0.75rem;
228
- }
229
-
230
217
  .richtext-editor-content figure.align-start {
231
218
  float: inline-start;
232
- margin-inline: 0 var(--rich-figure-gap);
219
+ max-width: 50%;
220
+ margin-block: 0.25rem 0.75rem;
221
+ margin-inline: 0 1.5rem;
233
222
  }
234
223
 
235
224
  .richtext-editor-content figure.align-end {
236
225
  float: inline-end;
237
- margin-inline: var(--rich-figure-gap) 0;
238
- }
239
-
240
- /* Floats collapse their wrapper's height — see rich-content.css. */
241
- .richtext-editor-content p:has(> figure.align-start),
242
- .richtext-editor-content p:has(> figure.align-end),
243
- .richtext-editor-content li:has(> figure.align-start),
244
- .richtext-editor-content li:has(> figure.align-end),
245
- .richtext-editor-content div:has(> figure.align-start),
246
- .richtext-editor-content div:has(> figure.align-end) {
247
- display: flow-root;
226
+ max-width: 50%;
227
+ margin-block: 0.25rem 0.75rem;
228
+ margin-inline: 1.5rem 0;
248
229
  }
249
230
 
250
231
  .richtext-editor-content figure.align-start img,
@@ -2982,10 +2982,6 @@ async function initEditor() {
2982
2982
  margin: 0;
2983
2983
  padding: 14px 8px 8px 8px;
2984
2984
  min-height: 200px;
2985
- /* Floated figures do not contribute height, so without a block
2986
- formatting context the editable body collapses and content below
2987
- overlaps the floats. */
2988
- display: flow-root;
2989
2985
  font-family: ${currentFontFamily.value};
2990
2986
  line-height: 1.5;
2991
2987
  color: ${currentTextColor.value};
@@ -3328,32 +3324,22 @@ async function initEditor() {
3328
3324
  /* Default: full width block. */
3329
3325
  figure.align-full {
3330
3326
  float: none;
3331
- /* A block box following a float starts at the float's top, which paints
3332
- this figure's edit badge over the floated media above it. Clearing
3333
- forces the new row that "full width" implies. */
3334
- clear: both;
3335
3327
  width: 100%;
3336
3328
  margin-inline: 0;
3337
3329
  }
3338
3330
 
3339
- /* Gap reserved inside the 50% so two opposing floats share a line:
3340
- 2 × (50% - gap) + 2 × gap = 100%. */
3341
- figure.align-start,
3342
- figure.align-end {
3343
- --rich-figure-gap: 1.25em;
3344
- width: 50%;
3345
- max-width: calc(50% - var(--rich-figure-gap) - 1px);
3346
- margin-block: 0.25em 0.75em;
3347
- }
3348
-
3349
3331
  figure.align-start {
3350
3332
  float: inline-start;
3351
- margin-inline: 0 var(--rich-figure-gap);
3333
+ max-width: 50%;
3334
+ margin-block: 0.25em 0.75em;
3335
+ margin-inline: 0 1.25em;
3352
3336
  }
3353
3337
 
3354
3338
  figure.align-end {
3355
3339
  float: inline-end;
3356
- margin-inline: var(--rich-figure-gap) 0;
3340
+ max-width: 50%;
3341
+ margin-block: 0.25em 0.75em;
3342
+ margin-inline: 1.25em 0;
3357
3343
  }
3358
3344
 
3359
3345
  figure.align-start img,
@@ -3363,20 +3349,7 @@ async function initEditor() {
3363
3349
 
3364
3350
  figure.video-figure.align-start,
3365
3351
  figure.video-figure.align-end {
3366
- max-width: calc(50% - var(--rich-figure-gap) - 1px);
3367
- }
3368
-
3369
- /* Floats remove themselves from flow, so a paragraph whose only children
3370
- are floated figures collapses to zero height and the next block is
3371
- painted over them. flow-root gives the wrapper back its height
3372
- without clipping the edit badges or captions. */
3373
- p:has(> figure.align-start),
3374
- p:has(> figure.align-end),
3375
- li:has(> figure.align-start),
3376
- li:has(> figure.align-end),
3377
- div:has(> figure.align-start),
3378
- div:has(> figure.align-end) {
3379
- display: flow-root;
3352
+ max-width: 50%;
3380
3353
  }
3381
3354
 
3382
3355
  figure.video-figure .video-container {
@@ -171,6 +171,87 @@
171
171
  border: none !important;
172
172
  }
173
173
 
174
+ /* 5) GLOSS / BEVEL — the glossy, tactile "3D" fill.
175
+ *
176
+ * Two halves make the look, and they are separable:
177
+ *
178
+ * MATERIAL a tone-derived vertical sweep (lighter at the top, deeper at the
179
+ * bottom) + a hairline white highlight along the top edge + a dark
180
+ * bevel at the bottom edge. Everything scales with `em`, which the
181
+ * size classes drive — xs gets a hairline edge, xl a chunky one.
182
+ *
183
+ * ELEVATION gloss adds a contact shadow + a tinted glow underneath (the
184
+ * button "floats"), plus a 1px sink on :active.
185
+ * bevel drops ALL of it — same material, no shadow at all — for
186
+ * dense toolbars, list rows, or sitting inside a card that already
187
+ * casts its own shadow.
188
+ *
189
+ * Text keeps the pair-* contrast color, so it works for every tone/shade, and
190
+ * the fill follows the tone in dark mode too. Composes with `round` (pill) and
191
+ * icon-only (circle) shapes, and with any pair-* element:
192
+ *
193
+ * <Btn color="blue" gloss value="Save" /> <!-- lifted -->
194
+ * <Btn color="blue" bevel value="Save" /> <!-- flush -->
195
+ * <Btn color="purple" bevel round icon="bolt" />
196
+ * <Badge color="green" class="bevel" value="New" />
197
+ */
198
+
199
+ /* --- the shared MATERIAL ------------------------------------------------- */
200
+ [class*="pair-"]:is(.gloss, .bevel) {
201
+ --bgl-gloss-highlight: rgba(255, 255, 255, 0.38);
202
+ --bgl-gloss-bevel: rgba(0, 0, 0, 0.24);
203
+ --bgl-gloss-from: color-mix(in oklab, var(--bgl-pair-tone, var(--bgl-primary)) 92%, white);
204
+ --bgl-gloss-to: color-mix(in oklab, var(--bgl-pair-tone, var(--bgl-primary)) 88%, black);
205
+
206
+ background: linear-gradient(180deg, var(--bgl-gloss-from), var(--bgl-gloss-to)) !important;
207
+ box-shadow: var(--bgl-gloss-shadow);
208
+ }
209
+
210
+ /* --- ELEVATION presets --------------------------------------------------- */
211
+
212
+ /* gloss: floats — inner edge light + bevel, a contact shadow, and a tinted glow. */
213
+ [class*="pair-"].gloss {
214
+ --bgl-gloss-shadow:
215
+ inset 0 1px 0 var(--bgl-gloss-highlight),
216
+ inset 0 -0.11em 0 var(--bgl-gloss-bevel),
217
+ 0 1px 2px rgba(0, 0, 0, 0.22),
218
+ 0 0.45em 1.1em -0.4em color-mix(in oklab, var(--bgl-pair-tone, var(--bgl-primary)) 75%, transparent);
219
+ --bgl-gloss-shadow-active:
220
+ inset 0 2px 5px rgba(0, 0, 0, 0.35),
221
+ inset 0 -1px 0 rgba(255, 255, 255, 0.1),
222
+ 0 1px 1px rgba(0, 0, 0, 0.18);
223
+ }
224
+
225
+ /* bevel: flush with the surface — the same material, zero shadow. */
226
+ [class*="pair-"].bevel {
227
+ --bgl-gloss-shadow:
228
+ inset 0 1px 0 var(--bgl-gloss-highlight),
229
+ inset 0 -0.11em 0 var(--bgl-gloss-bevel);
230
+ --bgl-gloss-shadow-active:
231
+ inset 0 2px 5px rgba(0, 0, 0, 0.35),
232
+ inset 0 -1px 0 rgba(255, 255, 255, 0.1);
233
+ }
234
+
235
+ /* --- interaction --------------------------------------------------------- */
236
+
237
+ /* A gentle lift on hover (overrides the generic darken/lighten filter, which
238
+ would flatten the gloss). */
239
+ [class*="pair-"]:is(.gloss, .bevel):hover:not(:disabled) {
240
+ filter: brightness(1.05);
241
+ }
242
+
243
+ /* Press: lose the top highlight, deepen into an inset shadow. Only `gloss`
244
+ also sinks a pixel — `bevel` has no elevation, so translating it would read
245
+ as a jump rather than as landing. */
246
+ [class*="pair-"]:is(.gloss, .bevel):active:not(:disabled) {
247
+ filter: none;
248
+ box-shadow: var(--bgl-gloss-shadow-active);
249
+ }
250
+
251
+ [class*="pair-"].gloss:active:not(:disabled) {
252
+ translate: 0 1px;
253
+ }
254
+
174
255
  /* New role colors — tone map */
175
256
  .pair-secondary,
176
257
  .pair-secondary-light, .pair-secondary-tint { --bgl-pair-tone: var(--bgl-secondary); }
@@ -202,6 +202,17 @@
202
202
  background: var(--bgl-primary-tint);
203
203
  }
204
204
 
205
+ /* A GLOSS/BEVEL white or gray button is a *secondary surface* in dark mode,
206
+ exactly like the regular filled pairs below — so derive the gloss from the
207
+ raised dark surface token instead of keeping a glaring white sweep. The pair
208
+ rule below already re-points its text to the light token. */
209
+ .bgl-dark-mode .pair-white.gloss,
210
+ .bgl-dark-mode .pair-gray.gloss,
211
+ .bgl-dark-mode .pair-white.bevel,
212
+ .bgl-dark-mode .pair-gray.bevel {
213
+ --bgl-pair-tone: var(--bgl-dm-surface-2);
214
+ }
215
+
205
216
  /* Soft color pairs (.pair-*-light / .pair-*-tint) hard-code dark text in
206
217
  base-colors.css. Once their fills become dark washes (see the variable
207
218
  remaps above) that text is unreadable, so flip it to the light text token.
@@ -37,52 +37,26 @@ figure[data-media-type='video'] video {
37
37
 
38
38
  figure.align-full {
39
39
  float: none;
40
- /* A block box that follows a float starts at the float's top, so a full-width
41
- figure would paint its box (and its edit badge) over the floated media while
42
- its image stays below. Clearing forces the new row the width implies. */
43
- clear: both;
44
- width: 100%;
40
+ width: 100% !important;
45
41
  max-width: 100%;
46
42
  margin-inline: 0;
47
43
  }
48
44
 
49
- /* Floats only share a line while their outer widths fit. The gap is reserved
50
- *inside* the 50% instead of being added on top of it, so a pair of opposing
51
- floats fits exactly once:
52
- 2 × (50% - gap) + 2 × gap = 100%
53
- Without that, 50% + gap twice always overflows and the second figure drops to
54
- the next line. The extra 1px absorbs sub-pixel rounding.
55
- `!important` is deliberately absent so an explicit width from the author (the
56
- inline style written from `data-width`) still wins. */
57
45
  figure.align-start,
58
46
  figure.align-end {
59
- --rich-figure-gap: 1.25em;
60
- width: 50%;
61
- max-width: calc(50% - var(--rich-figure-gap) - 1px);
47
+ width: 50% !important;
48
+ max-width: 50%;
62
49
  margin-block: 0.25em 0.75em;
63
50
  }
64
51
 
65
52
  figure.align-start {
66
53
  float: inline-start;
67
- margin-inline: 0 var(--rich-figure-gap);
54
+ margin-inline: 0 1.25em;
68
55
  }
69
56
 
70
57
  figure.align-end {
71
58
  float: inline-end;
72
- margin-inline: var(--rich-figure-gap) 0;
73
- }
74
-
75
- /* Floated figures take themselves out of flow, so a wrapper whose only children
76
- are floats collapses to zero height and whatever follows is painted on top of
77
- them. `flow-root` establishes a block formatting context without clipping the
78
- overlapping badges or captions. */
79
- p:has(> figure.align-start),
80
- p:has(> figure.align-end),
81
- li:has(> figure.align-start),
82
- li:has(> figure.align-end),
83
- div:has(> figure.align-start),
84
- div:has(> figure.align-end) {
85
- display: flow-root;
59
+ margin-inline: 1.25em 0;
86
60
  }
87
61
 
88
62
  .video-responsive {