@uniweb/core 0.3.9 → 0.3.10
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 +55 -0
package/package.json
CHANGED
package/src/block.js
CHANGED
|
@@ -47,6 +47,17 @@ export default class Block {
|
|
|
47
47
|
this.standardOptions = blockConfig.standardOptions || {}
|
|
48
48
|
this.properties = blockConfig.properties || blockConfig
|
|
49
49
|
|
|
50
|
+
// Extract background from params into standardOptions
|
|
51
|
+
// Content authors set background in section frontmatter; the runtime
|
|
52
|
+
// reads it from standardOptions to render the Background component.
|
|
53
|
+
const rawBg = blockConfig.background
|
|
54
|
+
if (rawBg && !this.standardOptions.background) {
|
|
55
|
+
this.standardOptions = {
|
|
56
|
+
...this.standardOptions,
|
|
57
|
+
background: Block.normalizeBackground(rawBg)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
// Child blocks (subsections)
|
|
51
62
|
this.childBlocks = blockData.subsections
|
|
52
63
|
? blockData.subsections.map((block, i) => new Block(block, `${id}_${i}`))
|
|
@@ -427,6 +438,50 @@ export default class Block {
|
|
|
427
438
|
return null
|
|
428
439
|
}
|
|
429
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Normalize a background value from section frontmatter
|
|
443
|
+
*
|
|
444
|
+
* Accepts:
|
|
445
|
+
* - String URL: "/images/hero.jpg" → { mode: 'image', image: { src } }
|
|
446
|
+
* - String URL (video): "/videos/bg.mp4" → { mode: 'video', video: { src } }
|
|
447
|
+
* - Object with mode: passed through as-is
|
|
448
|
+
* - Object without mode: mode inferred from which fields are present
|
|
449
|
+
*
|
|
450
|
+
* @param {string|Object} raw - Raw background value from frontmatter
|
|
451
|
+
* @returns {Object} Normalized background config with mode
|
|
452
|
+
*/
|
|
453
|
+
static normalizeBackground(raw) {
|
|
454
|
+
// String URL shorthand
|
|
455
|
+
if (typeof raw === 'string') {
|
|
456
|
+
const ext = raw.split('.').pop()?.toLowerCase()
|
|
457
|
+
const isVideo = ['mp4', 'webm', 'ogv', 'ogg'].includes(ext)
|
|
458
|
+
|
|
459
|
+
if (isVideo) {
|
|
460
|
+
return { mode: 'video', video: { src: raw } }
|
|
461
|
+
}
|
|
462
|
+
return { mode: 'image', image: { src: raw } }
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Object with explicit mode — pass through
|
|
466
|
+
if (raw.mode) return raw
|
|
467
|
+
|
|
468
|
+
// Infer mode from fields
|
|
469
|
+
if (raw.video || raw.sources) return { mode: 'video', ...raw }
|
|
470
|
+
if (raw.image || raw.src) {
|
|
471
|
+
// Support flat { src, position, size } shorthand
|
|
472
|
+
if (raw.src) {
|
|
473
|
+
const { src, position, size, lazy, ...rest } = raw
|
|
474
|
+
return { mode: 'image', image: { src, position, size, lazy }, ...rest }
|
|
475
|
+
}
|
|
476
|
+
return { mode: 'image', ...raw }
|
|
477
|
+
}
|
|
478
|
+
if (raw.gradient) return { mode: 'gradient', ...raw }
|
|
479
|
+
if (raw.color) return { mode: 'color', ...raw }
|
|
480
|
+
|
|
481
|
+
// Can't infer — return as-is (BlockRenderer checks for mode)
|
|
482
|
+
return raw
|
|
483
|
+
}
|
|
484
|
+
|
|
430
485
|
/**
|
|
431
486
|
* Parse nested links structure
|
|
432
487
|
*/
|