@uniweb/core 1.6.16 → 1.6.18
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 +3 -3
- package/src/block.js +115 -11
- package/src/index.js +2 -0
- package/src/seo.js +29 -0
- package/src/structured-data-ids.js +22 -0
- package/src/theme.js +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.18",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"vitest": "^4.1.7"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@uniweb/
|
|
57
|
-
"@uniweb/
|
|
56
|
+
"@uniweb/theming": "~1.3.5",
|
|
57
|
+
"@uniweb/semantic-parser": "~1.13.6"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run"
|
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,9 +143,18 @@ 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
|
-
|
|
146
|
+
// A named background (`background: glow`): the site's theme's, else the foundation's, with the
|
|
147
|
+
// theme it needs where the section names none (`namedBackground`, 2026-11-28).
|
|
148
|
+
const named = Block.namedBackground(rawBg, this.website)
|
|
149
|
+
const themeData = this.website?.themeData
|
|
150
|
+
const theme = Block.normalizeSectionTheme(rawTheme ?? named?.theme, (name) => Block.contextFollowsScheme(name, themeData))
|
|
147
151
|
this.themeName = theme.mode
|
|
148
152
|
this.themeOverrides = theme.overrides
|
|
153
|
+
// Whether the context the section pins follows the site's scheme — `medium`, and a site's own
|
|
154
|
+
// with a dark version — so its own colors for that context are the light scheme's, and its
|
|
155
|
+
// `dark:` ones the dark scheme's (`@uniweb/theming`'s section overrides), as an Auto section's
|
|
156
|
+
// are (2026-11-28).
|
|
157
|
+
this.themeFollowsScheme = theme.followsScheme
|
|
149
158
|
// The tokens in effect whatever the scheme (`normalizeSectionTheme`): the renderers apply
|
|
150
159
|
// them inline on the section, and a neighbour reads them through `getBlockInfo()`.
|
|
151
160
|
this.contextOverrides = theme.effectiveTokens
|
|
@@ -153,7 +162,8 @@ export default class Block {
|
|
|
153
162
|
// What the runtime draws behind the section — normalized once (its shape, and store-held
|
|
154
163
|
// assets resolved to URLs) for every renderer, and for a component that draws it itself
|
|
155
164
|
// (`background: 'self'` in `meta.js`, with kit's `SectionBackground`).
|
|
156
|
-
|
|
165
|
+
const backgroundValue = named ? named.value : rawBg
|
|
166
|
+
this.background = backgroundValue ? Block.normalizeBackground(backgroundValue, this.parseOptions()) : null
|
|
157
167
|
|
|
158
168
|
// Values for the CSS variables the component declares in `meta.js` `vars:` — merged into
|
|
159
169
|
// `componentVars` when the component is known (`initComponent`).
|
|
@@ -830,9 +840,12 @@ export default class Block {
|
|
|
830
840
|
* follows the site, those beside `mode` it sets in no context — or null. The renderers
|
|
831
841
|
* apply them inline, so they reach the page even where a host places no page stylesheet.
|
|
832
842
|
*/
|
|
833
|
-
static normalizeSectionTheme(raw) {
|
|
834
|
-
if (raw === undefined || raw === null || raw === '') return { mode: '', overrides: null, effectiveTokens: null }
|
|
835
|
-
if (typeof raw !== 'object' || Array.isArray(raw))
|
|
843
|
+
static normalizeSectionTheme(raw, follows = (name) => name === 'medium') {
|
|
844
|
+
if (raw === undefined || raw === null || raw === '') return { mode: '', overrides: null, effectiveTokens: null, followsScheme: false }
|
|
845
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
846
|
+
const mode = String(raw)
|
|
847
|
+
return { mode, overrides: null, effectiveTokens: null, followsScheme: Boolean(follows(mode)) }
|
|
848
|
+
}
|
|
836
849
|
|
|
837
850
|
const { mode, colors, contexts, vars, ...tokens } = raw
|
|
838
851
|
// A token is written into the page — inline on the section and in its stylesheet — so
|
|
@@ -853,36 +866,127 @@ export default class Block {
|
|
|
853
866
|
const nonEmpty = (map) =>
|
|
854
867
|
map && typeof map === 'object' && !Array.isArray(map) && Object.keys(map).length > 0 ? { ...map } : null
|
|
855
868
|
|
|
869
|
+
// A context's map may hold `dark:`, its version under a dark scheme, as `theme.yml`'s does —
|
|
870
|
+
// read for a context that follows the scheme (`medium`, a site's own with a dark version).
|
|
856
871
|
const byContext = {}
|
|
872
|
+
const darkByContext = {}
|
|
857
873
|
if (contexts && typeof contexts === 'object') {
|
|
858
874
|
for (const [context, map] of Object.entries(contexts)) {
|
|
859
875
|
const normalized = tokenMap(map)
|
|
860
876
|
if (normalized) byContext[context] = normalized
|
|
877
|
+
const dark = map && typeof map === 'object' && !Array.isArray(map) ? tokenMap(map.dark) : null
|
|
878
|
+
if (dark) darkByContext[context] = dark
|
|
861
879
|
}
|
|
862
880
|
}
|
|
863
881
|
const overrides = {
|
|
864
882
|
colors: nonEmpty(colors),
|
|
865
883
|
contexts: Object.keys(byContext).length > 0 ? byContext : null,
|
|
884
|
+
...(Object.keys(darkByContext).length > 0 && { darkContexts: darkByContext }),
|
|
866
885
|
vars: nonEmpty(vars),
|
|
867
886
|
tokens: tokenMap(tokens),
|
|
868
887
|
}
|
|
869
888
|
const pinned = typeof mode === 'string' ? mode : ''
|
|
889
|
+
const followsScheme = Boolean(pinned && follows(pinned))
|
|
870
890
|
// A context's own token beats one written beside `mode`, as in the page stylesheet. A
|
|
871
891
|
// section that follows the site has no context of its own, so a token it also sets per
|
|
872
|
-
// context is left to the stylesheet's per-scheme rules rather than applied here.
|
|
892
|
+
// context is left to the stylesheet's per-scheme rules rather than applied here. ⭐ So is a
|
|
893
|
+
// pinned context that follows the scheme: its own tokens are the light scheme's and its
|
|
894
|
+
// `dark:` ones the dark scheme's, in the stylesheet, and only a token beside `mode` that
|
|
895
|
+
// neither sets is applied here. ⛔ For an hour of 2026-11-28 (1.37.0) a `medium` section's own
|
|
896
|
+
// colors were applied in both schemes, over `medium`'s dark text: a light band, light text.
|
|
873
897
|
const perContext = new Set(Object.values(byContext).flatMap((map) => Object.keys(map)))
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
898
|
+
const ownPerScheme = new Set([...Object.keys(byContext[pinned] || {}), ...Object.keys(darkByContext[pinned] || {})])
|
|
899
|
+
const effective = !pinned
|
|
900
|
+
? Object.fromEntries(Object.entries(overrides.tokens || {}).filter(([name]) => !perContext.has(name)))
|
|
901
|
+
: followsScheme
|
|
902
|
+
? Object.fromEntries(Object.entries(overrides.tokens || {}).filter(([name]) => !ownPerScheme.has(name)))
|
|
903
|
+
: { ...(overrides.tokens || {}), ...(byContext[pinned] || {}) }
|
|
877
904
|
return {
|
|
878
905
|
mode: pinned,
|
|
879
906
|
overrides: Object.values(overrides).some(Boolean) ? overrides : null,
|
|
880
907
|
effectiveTokens: Object.keys(effective).length > 0 ? effective : null,
|
|
908
|
+
followsScheme,
|
|
881
909
|
}
|
|
882
910
|
}
|
|
883
911
|
|
|
912
|
+
/**
|
|
913
|
+
* A background a section names (`background: glow`), defined once: by the site's theme
|
|
914
|
+
* (`theme.yml` `backgrounds:`), which wins, else by the foundation (`main.js` `backgrounds:`, its
|
|
915
|
+
* lean copy in `foundationConfig`). Its value is drawn as any background is; its `theme`, the
|
|
916
|
+
* context it reads in, applies where the section's own `theme:` names none. A name nothing
|
|
917
|
+
* defines is not one: the value is read as written, a color in the theme's words included.
|
|
918
|
+
*
|
|
919
|
+
* @param {unknown} raw - the section's `background` as written
|
|
920
|
+
* @param {Object} [website]
|
|
921
|
+
* @returns {{ value: string|Object|null, theme: string|undefined }|null}
|
|
922
|
+
*/
|
|
923
|
+
static namedBackground(raw, website) {
|
|
924
|
+
if (typeof raw !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(raw)) return null
|
|
925
|
+
const lookup = (map) => (map && typeof map === 'object' && Object.hasOwn(map, raw) ? map[raw] : undefined)
|
|
926
|
+
const fromSite = lookup(website?.themeData?.backgrounds)
|
|
927
|
+
const definition = fromSite ?? lookup(globalThis.uniweb?.foundationConfig?.backgrounds)
|
|
928
|
+
if (typeof definition === 'string') return definition.trim() ? { value: definition, theme: undefined } : null
|
|
929
|
+
if (!definition || typeof definition !== 'object' || Array.isArray(definition)) return null
|
|
930
|
+
const { theme, className, label: _label, description: _description, preview: _preview, ...value } = definition
|
|
931
|
+
// ⭐ A foundation's own CSS art: a class its stylesheet draws on the background's layer, with
|
|
932
|
+
// the section's tokens (a dot grid, a glow). Only a foundation's definition names one: content
|
|
933
|
+
// and a site's theme hold no CSS. With no other layer it is drawn alone (`mode: 'art'`).
|
|
934
|
+
if (fromSite === undefined && typeof className === 'string' && /^-?[A-Za-z_][\w-]*(?: -?[A-Za-z_][\w-]*)*$/.test(className)) {
|
|
935
|
+
value.className = className
|
|
936
|
+
const layered = ['mode', 'color', 'gradient', 'image', 'video', 'src', 'sources'].some((key) => value[key] !== undefined)
|
|
937
|
+
if (!layered) value.mode = 'art'
|
|
938
|
+
}
|
|
939
|
+
return {
|
|
940
|
+
value: Object.keys(value).length > 0 ? value : null,
|
|
941
|
+
theme: typeof theme === 'string' && theme ? theme : undefined,
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Whether a context follows the site's scheme: `medium` does, with a version for each; a site's
|
|
947
|
+
* own does when `theme.yml` gives it `dark:` (`darkContexts` once processed, its `dark` key as
|
|
948
|
+
* written before); `light` and `dark` are the scheme's own two and never do.
|
|
949
|
+
*
|
|
950
|
+
* @param {string} name
|
|
951
|
+
* @param {Object} [themeData] - the website's theme, processed or as written
|
|
952
|
+
* @returns {boolean}
|
|
953
|
+
*/
|
|
954
|
+
static contextFollowsScheme(name, themeData) {
|
|
955
|
+
if (name === 'medium') return true
|
|
956
|
+
if (!name || name === 'light' || name === 'dark') return false
|
|
957
|
+
const processed = themeData?.darkContexts
|
|
958
|
+
if (processed && typeof processed === 'object' && Object.hasOwn(processed, name)) return true
|
|
959
|
+
const written = themeData?.contexts && Object.hasOwn(themeData.contexts, name) ? themeData.contexts[name] : null
|
|
960
|
+
return Boolean(written && typeof written === 'object' && written.dark && typeof written.dark === 'object')
|
|
961
|
+
}
|
|
962
|
+
|
|
884
963
|
static normalizeBackground(raw, options) {
|
|
885
|
-
return Block.resolveBackgroundMedia(Block.normalizeBackgroundShape(raw), options)
|
|
964
|
+
return Block.resolveBackgroundMedia(Block.inThemeWords(Block.normalizeBackgroundShape(raw)), options)
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* A background's colors in the theme's words, as CSS: its color, its gradient's two ends and
|
|
969
|
+
* its overlay gradient's, each a palette shade (`primary-100`, `neutral-900/40`) or a semantic
|
|
970
|
+
* token (`section`, `muted`, `primary`…), so it follows the section's surface, the scheme and
|
|
971
|
+
* the palette (`normalizeColorValue`, @uniweb/theming). A CSS value an author wrote stays as
|
|
972
|
+
* written. ⛔ Until 2026-11-28 only the string shorthand read a palette name, and no form read a
|
|
973
|
+
* token's: `{ color: primary-600 }` and a gradient from `primary-100` drew nothing, so agents
|
|
974
|
+
* wrote `var(--…)` [Diego, 2026-11-28].
|
|
975
|
+
*/
|
|
976
|
+
static inThemeWords(bg) {
|
|
977
|
+
if (!bg || typeof bg !== 'object') return bg
|
|
978
|
+
const color = (value) => (typeof value === 'string' ? normalizeColorValue(value) : value)
|
|
979
|
+
const ends = (gradient) =>
|
|
980
|
+
gradient && typeof gradient === 'object' && !Array.isArray(gradient)
|
|
981
|
+
? { ...gradient, start: color(gradient.start), end: color(gradient.end) }
|
|
982
|
+
: gradient
|
|
983
|
+
let out = bg
|
|
984
|
+
if (typeof bg.color === 'string') out = { ...out, color: color(bg.color) }
|
|
985
|
+
if (bg.gradient && typeof bg.gradient === 'object') out = { ...out, gradient: ends(bg.gradient) }
|
|
986
|
+
if (bg.overlay?.gradient && typeof bg.overlay.gradient === 'object') {
|
|
987
|
+
out = { ...out, overlay: { ...bg.overlay, gradient: ends(bg.overlay.gradient) } }
|
|
988
|
+
}
|
|
989
|
+
return out
|
|
886
990
|
}
|
|
887
991
|
|
|
888
992
|
/**
|
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/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 (!
|
|
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
|
-
|
|
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
|
// ============================================================
|