@uniweb/core 1.6.17 → 1.6.19

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.17",
3
+ "version": "1.6.19",
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.4",
56
+ "@uniweb/theming": "~1.3.8",
57
57
  "@uniweb/semantic-parser": "~1.13.6"
58
58
  },
59
59
  "scripts": {
package/src/block.js CHANGED
@@ -144,11 +144,17 @@ export default class Block {
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
- // surface it needs where the section names none (`namedBackground`, 2026-11-28).
147
+ // theme it needs where the section names none (`namedBackground`, 2026-11-28).
148
148
  const named = Block.namedBackground(rawBg, this.website)
149
- const theme = Block.normalizeSectionTheme(rawTheme ?? named?.surface)
149
+ const themeData = this.website?.themeData
150
+ const theme = Block.normalizeSectionTheme(rawTheme ?? named?.theme, (name) => Block.contextFollowsScheme(name, themeData))
150
151
  this.themeName = theme.mode
151
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
152
158
  // The tokens in effect whatever the scheme (`normalizeSectionTheme`): the renderers apply
153
159
  // them inline on the section, and a neighbour reads them through `getBlockInfo()`.
154
160
  this.contextOverrides = theme.effectiveTokens
@@ -834,9 +840,12 @@ export default class Block {
834
840
  * follows the site, those beside `mode` it sets in no context — or null. The renderers
835
841
  * apply them inline, so they reach the page even where a host places no page stylesheet.
836
842
  */
837
- static normalizeSectionTheme(raw) {
838
- if (raw === undefined || raw === null || raw === '') return { mode: '', overrides: null, effectiveTokens: null }
839
- if (typeof raw !== 'object' || Array.isArray(raw)) return { mode: String(raw), overrides: null, effectiveTokens: null }
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
+ }
840
849
 
841
850
  const { mode, colors, contexts, vars, ...tokens } = raw
842
851
  // A token is written into the page — inline on the section and in its stylesheet — so
@@ -857,53 +866,68 @@ export default class Block {
857
866
  const nonEmpty = (map) =>
858
867
  map && typeof map === 'object' && !Array.isArray(map) && Object.keys(map).length > 0 ? { ...map } : null
859
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).
860
871
  const byContext = {}
872
+ const darkByContext = {}
861
873
  if (contexts && typeof contexts === 'object') {
862
874
  for (const [context, map] of Object.entries(contexts)) {
863
875
  const normalized = tokenMap(map)
864
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
865
879
  }
866
880
  }
867
881
  const overrides = {
868
882
  colors: nonEmpty(colors),
869
883
  contexts: Object.keys(byContext).length > 0 ? byContext : null,
884
+ ...(Object.keys(darkByContext).length > 0 && { darkContexts: darkByContext }),
870
885
  vars: nonEmpty(vars),
871
886
  tokens: tokenMap(tokens),
872
887
  }
873
888
  const pinned = typeof mode === 'string' ? mode : ''
889
+ const followsScheme = Boolean(pinned && follows(pinned))
874
890
  // A context's own token beats one written beside `mode`, as in the page stylesheet. A
875
891
  // section that follows the site has no context of its own, so a token it also sets per
876
- // 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.
877
897
  const perContext = new Set(Object.values(byContext).flatMap((map) => Object.keys(map)))
878
- const effective = pinned
879
- ? { ...(overrides.tokens || {}), ...(byContext[pinned] || {}) }
880
- : Object.fromEntries(Object.entries(overrides.tokens || {}).filter(([name]) => !perContext.has(name)))
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] || {}) }
881
904
  return {
882
905
  mode: pinned,
883
906
  overrides: Object.values(overrides).some(Boolean) ? overrides : null,
884
907
  effectiveTokens: Object.keys(effective).length > 0 ? effective : null,
908
+ followsScheme,
885
909
  }
886
910
  }
887
911
 
888
912
  /**
889
913
  * A background a section names (`background: glow`), defined once: by the site's theme
890
914
  * (`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
915
+ * lean copy in `foundationConfig`). Its value is drawn as any background is; its `theme`, the
892
916
  * context it reads in, applies where the section's own `theme:` names none. A name nothing
893
917
  * defines is not one: the value is read as written, a color in the theme's words included.
894
918
  *
895
919
  * @param {unknown} raw - the section's `background` as written
896
920
  * @param {Object} [website]
897
- * @returns {{ value: string|Object|null, surface: string|undefined }|null}
921
+ * @returns {{ value: string|Object|null, theme: string|undefined }|null}
898
922
  */
899
923
  static namedBackground(raw, website) {
900
924
  if (typeof raw !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(raw)) return null
901
925
  const lookup = (map) => (map && typeof map === 'object' && Object.hasOwn(map, raw) ? map[raw] : undefined)
902
926
  const fromSite = lookup(website?.themeData?.backgrounds)
903
927
  const definition = fromSite ?? lookup(globalThis.uniweb?.foundationConfig?.backgrounds)
904
- if (typeof definition === 'string') return definition.trim() ? { value: definition, surface: undefined } : null
928
+ if (typeof definition === 'string') return definition.trim() ? { value: definition, theme: undefined } : null
905
929
  if (!definition || typeof definition !== 'object' || Array.isArray(definition)) return null
906
- const { surface, className, label: _label, description: _description, preview: _preview, ...value } = definition
930
+ const { theme, className, label: _label, description: _description, preview: _preview, ...value } = definition
907
931
  // ⭐ A foundation's own CSS art: a class its stylesheet draws on the background's layer, with
908
932
  // the section's tokens (a dot grid, a glow). Only a foundation's definition names one: content
909
933
  // and a site's theme hold no CSS. With no other layer it is drawn alone (`mode: 'art'`).
@@ -914,10 +938,28 @@ export default class Block {
914
938
  }
915
939
  return {
916
940
  value: Object.keys(value).length > 0 ? value : null,
917
- surface: typeof surface === 'string' && surface ? surface : undefined,
941
+ theme: typeof theme === 'string' && theme ? theme : undefined,
918
942
  }
919
943
  }
920
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
+
921
963
  static normalizeBackground(raw, options) {
922
964
  return Block.resolveBackgroundMedia(Block.inThemeWords(Block.normalizeBackgroundShape(raw)), options)
923
965
  }
package/src/uniweb.js CHANGED
@@ -105,12 +105,14 @@ export default class Uniweb {
105
105
  // `defaultInsets` above.
106
106
  this.tracking = null
107
107
 
108
- // Reserved for `@uniweb/api` — the one client instance per page. That
109
- // package is bundled into each foundation, so a page with a primary
110
- // foundation and extensions holds several copies of its code; the first to
111
- // need a client creates one and parks it here, and every other copy adopts
112
- // it instead of creating another. Core implements nothing on it: declared
113
- // null so the seal permits the assignment, nothing more. Same pattern as
108
+ // The site's client for its `backend` service. `@uniweb/api`, which the
109
+ // foundation bundles, makes it the first time one is needed and keeps it
110
+ // here. It lasts the whole visit: this singleton is made once, every page
111
+ // renders on it, so the session and the reads the client holds carry from
112
+ // page to page. A process holding several sites holds a Uniweb, and so a
113
+ // client, for each. Another copy of that package (an extension's) adopts
114
+ // the one kept here. Core implements nothing on it: declared null so the
115
+ // seal permits the assignment, nothing more. Same pattern as
114
116
  // `defaultInsets` above.
115
117
  this.api = null
116
118