@uniweb/theming 0.1.16 → 0.2.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 +1 -1
- package/src/section-overrides.js +10 -59
package/package.json
CHANGED
package/src/section-overrides.js
CHANGED
|
@@ -12,32 +12,7 @@ import { generatePalettes } from './shade-generator.js'
|
|
|
12
12
|
import { normalizeTokenValue } from './normalize.js'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} standardOptions - Block's standardOptions
|
|
18
|
-
* @returns {boolean}
|
|
19
|
-
*/
|
|
20
|
-
function hasOverrides(standardOptions) {
|
|
21
|
-
if (!standardOptions) return false
|
|
22
|
-
|
|
23
|
-
const { colors, foundationStyles } = standardOptions
|
|
24
|
-
|
|
25
|
-
if (foundationStyles && Object.keys(foundationStyles).length > 0) return true
|
|
26
|
-
if (!colors) return false
|
|
27
|
-
|
|
28
|
-
const hasColors =
|
|
29
|
-
colors.colors?.light && Object.keys(colors.colors.light).length > 0
|
|
30
|
-
const hasElements =
|
|
31
|
-
colors.elements &&
|
|
32
|
-
Object.values(colors.elements).some(
|
|
33
|
-
(ctx) => ctx && Object.keys(ctx).length > 0
|
|
34
|
-
)
|
|
35
|
-
return hasColors || hasElements
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Build CSS variable declarations for base palette overrides.
|
|
40
|
-
* Base palette is context-independent — always stored under the 'light' key.
|
|
15
|
+
* Build CSS variable declarations for base palette overrides — context-independent.
|
|
41
16
|
*
|
|
42
17
|
* @param {Object} baseColors - e.g. { primary: "#3b82f6", accent: "#f59e0b" }
|
|
43
18
|
* @returns {string[]} CSS declaration lines
|
|
@@ -75,7 +50,7 @@ function buildElementVars(elements) {
|
|
|
75
50
|
}
|
|
76
51
|
|
|
77
52
|
/**
|
|
78
|
-
* Build CSS variable declarations for
|
|
53
|
+
* Build CSS variable declarations for variable overrides — a section's `vars`, a component's.
|
|
79
54
|
*
|
|
80
55
|
* @param {Object} styles - e.g. { "border-radius": "0.5rem" }
|
|
81
56
|
* @returns {string[]} CSS declaration lines
|
|
@@ -92,13 +67,12 @@ function buildFoundationVars(styles) {
|
|
|
92
67
|
}
|
|
93
68
|
|
|
94
69
|
/**
|
|
95
|
-
* Split
|
|
96
|
-
* context-keyed (color/gradient) values.
|
|
70
|
+
* Split variables into flat (context-independent) and context-keyed (color/gradient) values.
|
|
97
71
|
*
|
|
98
72
|
* Flat values: { "radius-xl": "1.5rem" }
|
|
99
73
|
* Context-keyed values: { "colorful-bg": { light: "linear-gradient(...)", dark: "..." } }
|
|
100
74
|
*
|
|
101
|
-
* @param {Object} styles -
|
|
75
|
+
* @param {Object} styles - a section's `vars`
|
|
102
76
|
* @returns {{ flat: Object, contexts: Object }} - flat styles + { light: {...}, dark: {...} }
|
|
103
77
|
*/
|
|
104
78
|
function splitFoundationStyles(styles) {
|
|
@@ -149,11 +123,13 @@ function buildRule(selector, vars) {
|
|
|
149
123
|
* `{ colors, contexts, vars, tokens }` — a palette, tokens per color context, the
|
|
150
124
|
* foundation's variables, and tokens for the section in any context
|
|
151
125
|
* - block.componentVars — merged meta.js defaults + frontmatter overrides
|
|
152
|
-
* - block.standardOptions — ⚠️ the older editor envelope, `{ colors, foundationStyles }`,
|
|
153
|
-
* read by its own rules until an editor writes the section's `theme` instead
|
|
154
126
|
* - block.childBlocks — child sections get the same, at any depth: rendered as sections,
|
|
155
127
|
* they carry the `#section-{id}` these rules select [2026-09-28]
|
|
156
128
|
*
|
|
129
|
+
* ⛔ An editor's older envelope, `block.standardOptions` — `{ colors, foundationStyles }` — is
|
|
130
|
+
* no longer read (2026-09-28): an editor writes the section's `theme`, and @uniweb/core no longer
|
|
131
|
+
* sets it.
|
|
132
|
+
*
|
|
157
133
|
* ⭐ Which context's values apply, for the section's `theme`: a pinned section uses its own
|
|
158
134
|
* context's; a section that follows the site (Auto) uses `light` under a light scheme and
|
|
159
135
|
* `dark` under `.scheme-dark` — two rules, so no knowledge of whether the site can go dark
|
|
@@ -189,33 +165,8 @@ function buildBlockRules(block, appearance) {
|
|
|
189
165
|
const light = []
|
|
190
166
|
const dark = []
|
|
191
167
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
const legacy = block.standardOptions
|
|
195
|
-
const compVars = buildFoundationVars(block.componentVars)
|
|
196
|
-
if (hasOverrides(legacy)) {
|
|
197
|
-
const { colors, foundationStyles } = legacy
|
|
198
|
-
const hasToggle = appearance.allowToggle
|
|
199
|
-
const paletteVars = buildPaletteVars(colors?.colors?.light)
|
|
200
|
-
const { flat: flatFoundation, contexts: ctxFoundation } = splitFoundationStyles(foundationStyles)
|
|
201
|
-
const foundationVars = buildFoundationVars(flatFoundation)
|
|
202
|
-
if (isAuto && hasToggle) {
|
|
203
|
-
always.push(...paletteVars, ...foundationVars, ...compVars)
|
|
204
|
-
light.push(...buildElementVars(colors?.elements?.light), ...buildFoundationVars(ctxFoundation.light))
|
|
205
|
-
dark.push(...buildElementVars(colors?.elements?.dark), ...buildFoundationVars(ctxFoundation.dark))
|
|
206
|
-
} else {
|
|
207
|
-
const ctx = hasToggle ? (block.themeName || 'light') : 'light'
|
|
208
|
-
always.push(
|
|
209
|
-
...paletteVars,
|
|
210
|
-
...buildElementVars(colors?.elements?.[ctx]),
|
|
211
|
-
...foundationVars,
|
|
212
|
-
...compVars,
|
|
213
|
-
...buildFoundationVars(ctxFoundation[ctx])
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
always.push(...compVars)
|
|
218
|
-
}
|
|
168
|
+
// The component's variables: `meta.js` defaults with the section's values over them.
|
|
169
|
+
always.push(...buildFoundationVars(block.componentVars))
|
|
219
170
|
|
|
220
171
|
// The section's `theme:` — theme.yml's keys, scoped to the section.
|
|
221
172
|
const theme = block.themeOverrides
|