@uniweb/core 1.6.15 → 1.6.17

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": "1.6.15",
3
+ "version": "1.6.17",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,7 +53,7 @@
53
53
  "vitest": "^4.1.7"
54
54
  },
55
55
  "dependencies": {
56
- "@uniweb/theming": "~1.3.3",
56
+ "@uniweb/theming": "~1.3.4",
57
57
  "@uniweb/semantic-parser": "~1.13.6"
58
58
  },
59
59
  "scripts": {
package/src/block.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  parseContent as parseSemanticContent,
10
10
  resolveAssetUrl
11
11
  } from '@uniweb/semantic-parser'
12
- import { normalizeTokenValue, isCssName, isCssValue } from '@uniweb/theming'
12
+ import { normalizeTokenValue, normalizeColorValue, isCssName, isCssValue } from '@uniweb/theming'
13
13
  import { sectionDomId } from './section-id.js'
14
14
  import { liftInsets } from './insets.js'
15
15
 
@@ -143,7 +143,10 @@ export default class Block {
143
143
  // 'light' = Pinned to light context
144
144
  // 'medium' = Pinned to dim context
145
145
  // 'dark' = Pinned to dark context
146
- const theme = Block.normalizeSectionTheme(rawTheme)
146
+ // A named background (`background: glow`): the site's theme's, else the foundation's, with the
147
+ // surface it needs where the section names none (`namedBackground`, 2026-11-28).
148
+ const named = Block.namedBackground(rawBg, this.website)
149
+ const theme = Block.normalizeSectionTheme(rawTheme ?? named?.surface)
147
150
  this.themeName = theme.mode
148
151
  this.themeOverrides = theme.overrides
149
152
  // The tokens in effect whatever the scheme (`normalizeSectionTheme`): the renderers apply
@@ -153,7 +156,8 @@ export default class Block {
153
156
  // What the runtime draws behind the section — normalized once (its shape, and store-held
154
157
  // assets resolved to URLs) for every renderer, and for a component that draws it itself
155
158
  // (`background: 'self'` in `meta.js`, with kit's `SectionBackground`).
156
- this.background = rawBg ? Block.normalizeBackground(rawBg, this.parseOptions()) : null
159
+ const backgroundValue = named ? named.value : rawBg
160
+ this.background = backgroundValue ? Block.normalizeBackground(backgroundValue, this.parseOptions()) : null
157
161
 
158
162
  // Values for the CSS variables the component declares in `meta.js` `vars:` — merged into
159
163
  // `componentVars` when the component is known (`initComponent`).
@@ -881,8 +885,66 @@ export default class Block {
881
885
  }
882
886
  }
883
887
 
888
+ /**
889
+ * A background a section names (`background: glow`), defined once: by the site's theme
890
+ * (`theme.yml` `backgrounds:`), which wins, else by the foundation (`main.js` `backgrounds:`, its
891
+ * lean copy in `foundationConfig`). Its value is drawn as any background is; its `surface`, the
892
+ * context it reads in, applies where the section's own `theme:` names none. A name nothing
893
+ * defines is not one: the value is read as written, a color in the theme's words included.
894
+ *
895
+ * @param {unknown} raw - the section's `background` as written
896
+ * @param {Object} [website]
897
+ * @returns {{ value: string|Object|null, surface: string|undefined }|null}
898
+ */
899
+ static namedBackground(raw, website) {
900
+ if (typeof raw !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(raw)) return null
901
+ const lookup = (map) => (map && typeof map === 'object' && Object.hasOwn(map, raw) ? map[raw] : undefined)
902
+ const fromSite = lookup(website?.themeData?.backgrounds)
903
+ const definition = fromSite ?? lookup(globalThis.uniweb?.foundationConfig?.backgrounds)
904
+ if (typeof definition === 'string') return definition.trim() ? { value: definition, surface: undefined } : null
905
+ if (!definition || typeof definition !== 'object' || Array.isArray(definition)) return null
906
+ const { surface, className, label: _label, description: _description, preview: _preview, ...value } = definition
907
+ // ⭐ A foundation's own CSS art: a class its stylesheet draws on the background's layer, with
908
+ // the section's tokens (a dot grid, a glow). Only a foundation's definition names one: content
909
+ // and a site's theme hold no CSS. With no other layer it is drawn alone (`mode: 'art'`).
910
+ if (fromSite === undefined && typeof className === 'string' && /^-?[A-Za-z_][\w-]*(?: -?[A-Za-z_][\w-]*)*$/.test(className)) {
911
+ value.className = className
912
+ const layered = ['mode', 'color', 'gradient', 'image', 'video', 'src', 'sources'].some((key) => value[key] !== undefined)
913
+ if (!layered) value.mode = 'art'
914
+ }
915
+ return {
916
+ value: Object.keys(value).length > 0 ? value : null,
917
+ surface: typeof surface === 'string' && surface ? surface : undefined,
918
+ }
919
+ }
920
+
884
921
  static normalizeBackground(raw, options) {
885
- return Block.resolveBackgroundMedia(Block.normalizeBackgroundShape(raw), options)
922
+ return Block.resolveBackgroundMedia(Block.inThemeWords(Block.normalizeBackgroundShape(raw)), options)
923
+ }
924
+
925
+ /**
926
+ * A background's colors in the theme's words, as CSS: its color, its gradient's two ends and
927
+ * its overlay gradient's, each a palette shade (`primary-100`, `neutral-900/40`) or a semantic
928
+ * token (`section`, `muted`, `primary`…), so it follows the section's surface, the scheme and
929
+ * the palette (`normalizeColorValue`, @uniweb/theming). A CSS value an author wrote stays as
930
+ * written. ⛔ Until 2026-11-28 only the string shorthand read a palette name, and no form read a
931
+ * token's: `{ color: primary-600 }` and a gradient from `primary-100` drew nothing, so agents
932
+ * wrote `var(--…)` [Diego, 2026-11-28].
933
+ */
934
+ static inThemeWords(bg) {
935
+ if (!bg || typeof bg !== 'object') return bg
936
+ const color = (value) => (typeof value === 'string' ? normalizeColorValue(value) : value)
937
+ const ends = (gradient) =>
938
+ gradient && typeof gradient === 'object' && !Array.isArray(gradient)
939
+ ? { ...gradient, start: color(gradient.start), end: color(gradient.end) }
940
+ : gradient
941
+ let out = bg
942
+ if (typeof bg.color === 'string') out = { ...out, color: color(bg.color) }
943
+ if (bg.gradient && typeof bg.gradient === 'object') out = { ...out, gradient: ends(bg.gradient) }
944
+ if (bg.overlay?.gradient && typeof bg.overlay.gradient === 'object') {
945
+ out = { ...out, overlay: { ...bg.overlay, gradient: ends(bg.overlay.gradient) } }
946
+ }
947
+ return out
886
948
  }
887
949
 
888
950
  /**
package/src/index.js CHANGED
@@ -111,6 +111,8 @@ export { resolveService, resolveServiceUrl, readServiceOptions } from './service
111
111
  export { applyBasePath } from './base-path.js'
112
112
  // A site's address and the absolute URLs stated on it — also the leaf `@uniweb/core/site-address`.
113
113
  export { siteAddress, pageUrl, absoluteUrl } from './site-address.js'
114
+ // The @ids a page's structured data links its nodes by — the runtime's and kit's (`./structured-data-ids.js`).
115
+ export { structuredDataIds } from './structured-data-ids.js'
114
116
  // The content parser and its sanitizer, for code a foundation BUNDLES (kit's `Render`, `Icon`,
115
117
  // `Scene`). A foundation leaves `@uniweb/core` for the runtime to supply, so what it takes from
116
118
  // here is the runtime's copy, the one Block parses every section with, never a second copy frozen
package/src/page-data.js CHANGED
@@ -92,9 +92,13 @@ export function blockFills({ declared, levels, holds = {}, queries = null, optio
92
92
  const out = new Map()
93
93
  if (!declared || declared.length === 0) return out
94
94
 
95
+ // A key the block holds is filled from what it holds (`@uniweb/runtime`'s prepare-props), except a key
96
+ // that expects whole records and holds only briefs — a static build's prerendered list — which is
97
+ // planned, so its records are completed whole (`keyProgram`).
98
+ const wholeKeys = new Set(declared.filter(([, , whole]) => whole === true).map(([key]) => key))
95
99
  const fills = fillDeclaredKeys(declared, levels, {
96
100
  queries,
97
- held: declared.map(([key]) => key).filter((key) => holds[key] !== undefined),
101
+ held: declared.map(([key]) => key).filter((key) => holds[key] !== undefined && !(wholeKeys.has(key) && isBriefList(holds[key]))),
98
102
  })
99
103
  // where the first fetch of each key reaching the block sits — the one a held answer belongs to
100
104
  const firstOfKey = new Map()
@@ -390,8 +394,6 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
390
394
  const maybe = (request) => (opportunistic ? { request, optional: true } : request)
391
395
  /** A step answered from what is held, on both drivers: never dispatched, `{ missing: true }` when not held. */
392
396
  const fromHeld = (request) => ({ request, held: true })
393
- // The block holds this fetch's answer already — a static build prerendered it.
394
- if (held !== undefined) return { value: held }
395
397
 
396
398
  // ⭐ WHOLE OR BRIEF IS A QUESTION ABOUT RECORDS OF A DATA SCHEMA — the records service's, or a
397
399
  // compiled query's. An external query's records have none, so they have no brief: a list is what
@@ -409,6 +411,18 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
409
411
  const listed = single ? firstOnly(cfg) : cfg
410
412
  const cut = (data) => (single && Array.isArray(data) ? data.slice(0, 1) : data)
411
413
 
414
+ // The block holds this fetch's answer already — a static build prerendered it, as its compiled list
415
+ // holds it: briefs. ⭐ A key that expects whole records takes those briefs as the set to complete,
416
+ // each record asked for whole by its own request, as an answer fetched here is completed below; a
417
+ // held answer that is not a list of briefs (records already whole, or anything without a handle) is
418
+ // the answer as it is. ⛔ Until 2026-11-23 the held list was the answer whatever the key expected, so
419
+ // a section showing one record whole by its own fetch got the record's card and no body, on a
420
+ // static build only.
421
+ if (held !== undefined) {
422
+ if (whole && isBriefList(held)) return yield* wholeRecordsOf(cfg, cut(held))
423
+ return { value: held }
424
+ }
425
+
412
426
  if (current === 'exclude') {
413
427
  // The query's records without this page's, its `limit` counting the others.
414
428
  const view = othersView(listed)
@@ -560,6 +574,25 @@ function* ownRecord(cfg, dynamicContext, match, peekRecord, maybe) {
560
574
  * @param {*} records - the list's answer
561
575
  * @returns {Generator<Object[], { value?: *, error?: string, errorConfig?: Object }>}
562
576
  */
577
+ /** A record as a list holds it: its card, with its handle, not yet asked for whole (`{ brief, body }`). */
578
+ function isBrief(record) {
579
+ return !!record && typeof record === 'object' && !Array.isArray(record) &&
580
+ record.$name !== undefined && record.$name !== null && record.$name !== '' &&
581
+ record.brief === undefined && record.body === undefined
582
+ }
583
+
584
+ /**
585
+ * Whether a held value is a list of briefs: what a static build prerenders for a fetch, which a key
586
+ * expecting whole records completes rather than takes. Records already whole, a tagged data block, or
587
+ * anything without a handle is not.
588
+ *
589
+ * @param {*} value
590
+ * @returns {boolean}
591
+ */
592
+ export function isBriefList(value) {
593
+ return Array.isArray(value) && value.length > 0 && value.every(isBrief)
594
+ }
595
+
563
596
  function* wholeRecordsOf(cfg, records) {
564
597
  if (!Array.isArray(records)) return { value: null }
565
598
  if (records.length === 0) return { value: [] }
package/src/seo.js CHANGED
@@ -9,6 +9,9 @@
9
9
  * (`defaultLanguage`, etc.). `changefreq`/`priority` are sitemap hints — only
10
10
  * meaningful per-page, but carried uniformly so the shape never drifts.
11
11
  * `twitterHandle` names the site's account (`twitter:site`, e.g. `@acme`).
12
+ * `publisher` says who the site is for, for its structured data (`@uniweb/runtime`'s
13
+ * `structured-data.js`): a schema.org `type` (`Organization` when left out), a `name`, a `logo` and
14
+ * the `profiles` its `sameAs` lists — a site's own, read at the site level (2026-11-28).
12
15
  *
13
16
  * @param {Object} [raw] - raw `seo:` block from site.yml / page.yml
14
17
  * @returns {{ noindex: boolean, image: string|null, ogTitle: string|null,
@@ -26,5 +29,31 @@ export function normalizeSeo(raw) {
26
29
  changefreq: seo.changefreq || null,
27
30
  priority: seo.priority || null,
28
31
  twitterHandle: seo.twitterHandle || null,
32
+ publisher: normalizePublisher(seo.publisher),
33
+ }
34
+ }
35
+
36
+ /** A schema.org type's name: `Organization`, `LocalBusiness`, `Dentist`, `Person`. */
37
+ const SCHEMA_TYPE = /^[A-Z][A-Za-z]{1,63}$/
38
+
39
+ /**
40
+ * Who the site is for, as `seo.publisher` states it, or null when it states nothing usable: its
41
+ * type, name and logo as strings, its profiles as web addresses. What is not one is left out.
42
+ *
43
+ * @param {unknown} raw
44
+ * @returns {{ type: string|null, name: string|null, logo: string|null, profiles: string[] }|null}
45
+ */
46
+ function normalizePublisher(raw) {
47
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null
48
+ const text = (value) => (typeof value === 'string' && value.trim() ? value.trim() : null)
49
+ const type = text(raw.type)
50
+ const profiles = (Array.isArray(raw.profiles) ? raw.profiles : [])
51
+ .filter((value) => typeof value === 'string' && /^https?:\/\//.test(value.trim()))
52
+ .map((value) => value.trim())
53
+ return {
54
+ type: type && SCHEMA_TYPE.test(type) ? type : null,
55
+ name: text(raw.name),
56
+ logo: text(raw.logo),
57
+ profiles,
29
58
  }
30
59
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The `@id`s of a page's structured data — one rule, for the runtime that writes the site's and the
3
+ * page's nodes into the prerendered head (`@uniweb/runtime`'s `structured-data.js`) and for kit's
4
+ * `<StructuredData>`, whose section nodes point at them (`mainEntityOfPage`, `publisher`). Two
5
+ * copies of these suffixes would let a section's node point at a node no page has.
6
+ *
7
+ * Each is on the site's address: the home page's in the site's default language, and the page's
8
+ * own (`Website#getPageUrl`). Null where the address is unknown, as a canonical is.
9
+ *
10
+ * @param {Object} website - a Website
11
+ * @param {Object} [page] - a Page
12
+ * @returns {{ site: string|null, publisher: string|null, page: string|null }}
13
+ */
14
+ export function structuredDataIds(website, page) {
15
+ const home = website?.getPageUrl?.('/', website.siteDefaultLocale ?? website.defaultLocale) ?? null
16
+ const url = page ? website?.getPageUrl?.(page) ?? null : null
17
+ return {
18
+ site: home ? `${home}#website` : null,
19
+ publisher: home ? `${home}#publisher` : null,
20
+ page: url ? `${url}#webpage` : null,
21
+ }
22
+ }
package/src/theme.js CHANGED
@@ -179,7 +179,7 @@ export default class Theme {
179
179
  * theme.getContextClass('dark') // → "context-dark"
180
180
  */
181
181
  getContextClass(context) {
182
- if (!VALID_CONTEXTS.includes(context)) {
182
+ if (!this.isValidContext(context)) {
183
183
  console.warn(`Invalid context: ${context}. Using 'light'.`)
184
184
  return 'context-light'
185
185
  }
@@ -193,7 +193,9 @@ export default class Theme {
193
193
  * @returns {boolean}
194
194
  */
195
195
  isValidContext(context) {
196
- return VALID_CONTEXTS.includes(context)
196
+ // A surface of the site's own counts too: a name under `theme.yml` `contexts:`, which the
197
+ // processed theme carries beside the three built-in ones (@uniweb/theming, 2026-11-28).
198
+ return VALID_CONTEXTS.includes(context) || (typeof context === 'string' && Object.hasOwn(this._contexts, context))
197
199
  }
198
200
 
199
201
  /**
@@ -202,7 +204,7 @@ export default class Theme {
202
204
  * @returns {string[]}
203
205
  */
204
206
  getValidContexts() {
205
- return [...VALID_CONTEXTS]
207
+ return [...new Set([...VALID_CONTEXTS, ...Object.keys(this._contexts)])]
206
208
  }
207
209
 
208
210
  // ============================================================