@uniweb/core 1.4.5 → 1.4.6
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 +1 -1
- package/src/block.js +24 -3
package/package.json
CHANGED
package/src/block.js
CHANGED
|
@@ -13,6 +13,27 @@ import { normalizeTokenValue, isCssName, isCssValue } from '@uniweb/theming'
|
|
|
13
13
|
import { sectionDomId } from './section-id.js'
|
|
14
14
|
import { liftInsets } from './insets.js'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A video background's own fields, in its `video`: `video: <url>` is its `src`, and a `poster`,
|
|
18
|
+
* `sources`, `loop` or `muted` written beside it are the video's — the shorthand the reference
|
|
19
|
+
* documents. A video given only as `sources` takes the first one's as its `src`.
|
|
20
|
+
* ⛔ Until 2026-10-25 these passed through as written, while every renderer reads
|
|
21
|
+
* `background.video.src`: the documented `video: /videos/hero.mp4` beside a `poster:` drew nothing.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} raw - a background object whose mode is video
|
|
24
|
+
* @returns {Object}
|
|
25
|
+
*/
|
|
26
|
+
function gatherVideoFields(raw) {
|
|
27
|
+
const { video, poster, sources, loop, muted, ...rest } = raw
|
|
28
|
+
const own = typeof video === 'string' ? { src: video } : { ...(video || {}) }
|
|
29
|
+
for (const [key, value] of Object.entries({ poster, sources, loop, muted })) {
|
|
30
|
+
if (value !== undefined && own[key] === undefined) own[key] = value
|
|
31
|
+
}
|
|
32
|
+
const first = !own.src && Array.isArray(own.sources) ? own.sources.find((s) => s?.src) : null
|
|
33
|
+
if (first) own.src = first.src
|
|
34
|
+
return { ...rest, video: own }
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
export default class Block {
|
|
17
38
|
constructor(blockData, id, page) {
|
|
18
39
|
this.id = id
|
|
@@ -880,8 +901,8 @@ export default class Block {
|
|
|
880
901
|
return { mode: 'color', color: normalizeTokenValue(raw) }
|
|
881
902
|
}
|
|
882
903
|
|
|
883
|
-
// Object with explicit mode — pass through
|
|
884
|
-
if (raw.mode) return raw
|
|
904
|
+
// Object with explicit mode — pass through, a video's own fields gathered into it
|
|
905
|
+
if (raw.mode) return raw.mode === 'video' ? gatherVideoFields(raw) : raw
|
|
885
906
|
|
|
886
907
|
// Normalize overlay shorthand: number → { enabled: true, type: 'dark', opacity }
|
|
887
908
|
if (typeof raw.overlay === 'number') {
|
|
@@ -889,7 +910,7 @@ export default class Block {
|
|
|
889
910
|
}
|
|
890
911
|
|
|
891
912
|
// Infer mode from fields
|
|
892
|
-
if (raw.video || raw.sources) return { mode: 'video', ...raw }
|
|
913
|
+
if (raw.video || raw.sources) return gatherVideoFields({ mode: 'video', ...raw })
|
|
893
914
|
if (raw.image || raw.src) {
|
|
894
915
|
// Support flat { src, position, size } shorthand
|
|
895
916
|
if (raw.src) {
|