@uniweb/core 0.32.2 → 0.33.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.32.2",
3
+ "version": "0.33.0",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -48,8 +48,8 @@
48
48
  "vitest": "^4.1.7"
49
49
  },
50
50
  "dependencies": {
51
- "@uniweb/semantic-parser": "^1.4.1",
52
- "@uniweb/theming": "^0.1.15"
51
+ "@uniweb/theming": "^0.1.16",
52
+ "@uniweb/semantic-parser": "^1.4.1"
53
53
  },
54
54
  "scripts": {
55
55
  "test": "vitest run"
package/src/block.js CHANGED
@@ -71,60 +71,63 @@ export default class Block {
71
71
  const blockConfig = blockData.params || blockData.config || {}
72
72
  this.preset = blockData.preset
73
73
 
74
- // Normalize theme: supports string ("light") or object ({ mode, ...tokenOverrides })
75
- // Resolve bare palette refs (e.g. "primary: neutral-900" → var(--neutral-900))
74
+ // ⭐ THE SECTION'S OWN SETTINGS — the names framework reserves in its params
75
+ // (`@uniweb/schemas/section`): `theme`, `background`, `grid`, `vars`. Framework applies
76
+ // each — the runtime paints the background and the color context around the component,
77
+ // the page stylesheet applies the section's theme and its component's variables, kit's
78
+ // `ChildGrid` lays out the child sections — so each is lifted onto the block, normalized
79
+ // once for every renderer, and a component NEVER receives one as a param [Diego,
80
+ // 2026-09-28]. It reads them from the block, or through kit. ⛔ Until then a component
81
+ // also received `theme` (the mode), `background` and `vars` as params, and nothing read
82
+ // them there. `standardOptions` and `properties` are the older editor envelopes.
83
+ const own = blockConfig.properties || blockConfig
84
+ const setting = (name) => (blockConfig[name] !== undefined ? blockConfig[name] : own[name])
85
+ const rawTheme = setting('theme')
86
+ const rawBg = setting('background')
87
+ const gridParam = setting('grid')
88
+ const varsParam = setting('vars')
89
+ const standardOptions = blockConfig.standardOptions
90
+ const {
91
+ theme: _theme, background: _background, grid: _grid, vars: _vars,
92
+ standardOptions: _standardOptions, properties: _properties,
93
+ ...componentParams
94
+ } = own
95
+ this.properties = componentParams
96
+
97
+ // The section's theme: `theme.yml`'s own keys scoped to the section — `colors`,
98
+ // `contexts`, `vars` — plus `mode`, the color context it pins. `theme: dark` is the
99
+ // shorthand for `{ mode: dark }`, and a token written beside `mode` applies to the section
100
+ // in any context (`normalizeSectionTheme`). The page stylesheet applies the overrides
101
+ // (`buildSectionOverrides`, @uniweb/theming).
76
102
  //
77
103
  // themeName values:
78
- // '' (empty) = Auto — section inherits from site's appearance/scheme
104
+ // '' (empty) = Auto — the section follows the site's light/dark scheme
79
105
  // 'light' = Pinned to light context
80
106
  // 'medium' = Pinned to dim context
81
107
  // 'dark' = Pinned to dark context
82
- const rawTheme = blockConfig.theme
83
- if (rawTheme && typeof rawTheme === 'object') {
84
- const { mode, ...overrides } = rawTheme
85
- this.themeName = mode || ''
86
- if (Object.keys(overrides).length > 0) {
87
- for (const key of Object.keys(overrides)) {
88
- overrides[key] = normalizeTokenValue(overrides[key])
89
- }
90
- this.contextOverrides = overrides
91
- } else {
92
- this.contextOverrides = null
93
- }
94
- } else {
95
- this.themeName = rawTheme ?? ''
96
- this.contextOverrides = null
97
- }
98
-
99
- this.standardOptions = blockConfig.standardOptions || {}
100
- this.properties = blockConfig.properties || blockConfig
101
-
102
- // Normalize params.theme to string so components always see "light"/"dark"/"medium",
103
- // not the raw object. Done after properties assignment to avoid mutating source data.
104
- if (this.properties.theme && typeof this.properties.theme === 'object') {
105
- this.properties = { ...this.properties, theme: this.themeName }
106
- }
107
-
108
- // `grid` rides in the section's params, as every key the author writes does — so it
109
- // travels and round-trips with no field of its own — but the NAME is framework's:
110
- // it is lifted to `block.grid` below and a component never receives it as a param.
111
- let gridParam = null
112
- if (Object.hasOwn(this.properties, 'grid')) {
113
- const { grid, ...rest } = this.properties
114
- gridParam = grid
115
- this.properties = rest
116
- }
117
-
118
- // Extract background from params into standardOptions
119
- // Content authors set background in section frontmatter; the runtime
120
- // reads it from standardOptions to render the Background component.
121
- const rawBg = blockConfig.background
122
- if (rawBg && !this.standardOptions.background) {
123
- this.standardOptions = {
124
- ...this.standardOptions,
125
- background: Block.normalizeBackground(rawBg, this.parseOptions())
126
- }
127
- }
108
+ const theme = Block.normalizeSectionTheme(rawTheme)
109
+ this.themeName = theme.mode
110
+ this.themeOverrides = theme.overrides
111
+ // The tokens in effect whatever the scheme (`normalizeSectionTheme`): the renderers apply
112
+ // them inline on the section, and a neighbour reads them through `getBlockInfo()`.
113
+ this.contextOverrides = theme.effectiveTokens
114
+
115
+ // ⚠️ The older editor envelope: `colors` (a section palette, and tokens per context) and
116
+ // `foundationStyles`, read by the page stylesheet until an editor writes the section's
117
+ // `theme` instead (uwx-format.md § A page section's fields). Nothing else reads it.
118
+ this.standardOptions = standardOptions || {}
119
+
120
+ // What the runtime draws behind the section — normalized once (its shape, and store-held
121
+ // assets resolved to URLs) for every renderer, and for a component that draws it itself
122
+ // (`background: 'self'` in `meta.js`, with kit's `SectionBackground`). An editor's preview
123
+ // may still send it inside the older envelope, which wins while it does.
124
+ this.background =
125
+ this.standardOptions.background ||
126
+ (rawBg ? Block.normalizeBackground(rawBg, this.parseOptions()) : null)
127
+
128
+ // Values for the CSS variables the component declares in `meta.js` `vars:` — merged into
129
+ // `componentVars` when the component is known (`initComponent`).
130
+ this.sectionVars = varsParam && typeof varsParam === 'object' ? varsParam : null
128
131
 
129
132
  // Child blocks (subsections)
130
133
  this.childBlocks = blockData.subsections
@@ -511,7 +514,7 @@ export default class Block {
511
514
  // Merge component-level CSS vars: meta.js defaults + frontmatter overrides
512
515
  // Source: meta.js vars field (defaults), section frontmatter vars: key (overrides)
513
516
  if (meta.vars) {
514
- this.componentVars = Block.mergeComponentVars(meta.vars, this.properties.vars)
517
+ this.componentVars = Block.mergeComponentVars(meta.vars, this.sectionVars)
515
518
  }
516
519
 
517
520
  return this.Component
@@ -725,6 +728,73 @@ export default class Block {
725
728
  * asset-URL pattern, used to resolve a store-held background.
726
729
  * @returns {Object} Normalized background config with mode
727
730
  */
731
+ /**
732
+ * A section's theme, from its `theme:` — `theme.yml`'s own keys scoped to the section,
733
+ * plus `mode`, the color context it pins:
734
+ *
735
+ * theme: dark the shorthand for { mode: dark }
736
+ * theme:
737
+ * mode: dark light | medium | dark; left out, the section follows the site
738
+ * colors: { primary: '#0a6' } like theme.yml `colors` — a palette, shades generated
739
+ * contexts: { dark: { … } } like theme.yml `contexts` — tokens per color context
740
+ * vars: { header-height: 5rem } like theme.yml `vars` — the foundation's variables
741
+ * heading: primary-900 a token beside `mode` — the section's in any context
742
+ *
743
+ * Token values resolve bare palette references (`neutral-900` → `var(--neutral-900)`).
744
+ *
745
+ * @param {string|Object|null|undefined} raw
746
+ * @returns {{ mode: string, overrides: Object|null, effectiveTokens: Object|null }}
747
+ * `overrides` is `{ colors, contexts, vars, tokens }` (each null when unset) or null when
748
+ * the section overrides nothing; `effectiveTokens` are the tokens in effect whatever the
749
+ * scheme — a pinned section's context's own over those beside `mode`; for a section that
750
+ * follows the site, those beside `mode` it sets in no context — or null. The renderers
751
+ * apply them inline, so they reach the page even where a host places no page stylesheet.
752
+ */
753
+ static normalizeSectionTheme(raw) {
754
+ if (raw === undefined || raw === null || raw === '') return { mode: '', overrides: null, effectiveTokens: null }
755
+ if (typeof raw !== 'object' || Array.isArray(raw)) return { mode: String(raw), overrides: null, effectiveTokens: null }
756
+
757
+ const { mode, colors, contexts, vars, ...tokens } = raw
758
+ const tokenMap = (map) => {
759
+ if (!map || typeof map !== 'object' || Array.isArray(map)) return null
760
+ const out = {}
761
+ for (const [name, value] of Object.entries(map)) {
762
+ if (value === undefined || value === null || value === '') continue
763
+ out[name] = normalizeTokenValue(value)
764
+ }
765
+ return Object.keys(out).length > 0 ? out : null
766
+ }
767
+ const nonEmpty = (map) =>
768
+ map && typeof map === 'object' && !Array.isArray(map) && Object.keys(map).length > 0 ? { ...map } : null
769
+
770
+ const byContext = {}
771
+ if (contexts && typeof contexts === 'object') {
772
+ for (const [context, map] of Object.entries(contexts)) {
773
+ const normalized = tokenMap(map)
774
+ if (normalized) byContext[context] = normalized
775
+ }
776
+ }
777
+ const overrides = {
778
+ colors: nonEmpty(colors),
779
+ contexts: Object.keys(byContext).length > 0 ? byContext : null,
780
+ vars: nonEmpty(vars),
781
+ tokens: tokenMap(tokens),
782
+ }
783
+ const pinned = typeof mode === 'string' ? mode : ''
784
+ // A context's own token beats one written beside `mode`, as in the page stylesheet. A
785
+ // section that follows the site has no context of its own, so a token it also sets per
786
+ // context is left to the stylesheet's per-scheme rules rather than applied here.
787
+ const perContext = new Set(Object.values(byContext).flatMap((map) => Object.keys(map)))
788
+ const effective = pinned
789
+ ? { ...(overrides.tokens || {}), ...(byContext[pinned] || {}) }
790
+ : Object.fromEntries(Object.entries(overrides.tokens || {}).filter(([name]) => !perContext.has(name)))
791
+ return {
792
+ mode: pinned,
793
+ overrides: Object.values(overrides).some(Boolean) ? overrides : null,
794
+ effectiveTokens: Object.keys(effective).length > 0 ? effective : null,
795
+ }
796
+ }
797
+
728
798
  static normalizeBackground(raw, options) {
729
799
  return Block.resolveBackgroundMedia(Block.normalizeBackgroundShape(raw), options)
730
800
  }
package/src/page.js CHANGED
@@ -326,6 +326,22 @@ export default class Page {
326
326
  return blocks
327
327
  }
328
328
 
329
+ /**
330
+ * Every section block the page renders at its top level: its body, and each layout area it
331
+ * shows — header, footer, and any other area its layout declares, a sidebar included. A
332
+ * block's child sections are its own (`block.childBlocks`). What the page stylesheet covers
333
+ * (`buildSectionOverrides`, @uniweb/theming), where `getPageBlocks()` is the header · body ·
334
+ * footer order that neighbours count in.
335
+ * @returns {Block[]}
336
+ */
337
+ getAllBlocks() {
338
+ const blocks = [...this.bodyBlocks]
339
+ for (const areaBlocks of Object.values(this.getLayoutAreas())) {
340
+ if (Array.isArray(areaBlocks)) blocks.push(...areaBlocks)
341
+ }
342
+ return blocks
343
+ }
344
+
329
345
  /**
330
346
  * Get body blocks
331
347
  * @returns {Block[]}
package/src/uniweb.js CHANGED
@@ -53,6 +53,10 @@ export default class Uniweb {
53
53
  }
54
54
 
55
55
  this.childBlockRenderer = null
56
+ // The runtime's section-background renderer — the same one it draws behind every section —
57
+ // for kit's `SectionBackground`, which a component that paints its own background uses
58
+ // (`background: 'self'`). Filled by each boot path, like `childBlockRenderer`.
59
+ this.backgroundRenderer = null
56
60
  this.routingComponents = {}
57
61
  this.language = 'en'
58
62