@adea-ai/ui 0.151.11 → 0.151.12

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.
Files changed (67) hide show
  1. package/dist/components/composites/appearance-editor/appearance-rows.d.ts.map +1 -1
  2. package/dist/components/composites/appearance-editor/appearance-rows.js +16 -3
  3. package/dist/components/composites/appearance-editor/appearance-rows.js.map +1 -1
  4. package/dist/components/layout/contextual-sidebar/contextual-sidebar.d.ts +12 -0
  5. package/dist/components/layout/contextual-sidebar/contextual-sidebar.d.ts.map +1 -1
  6. package/dist/components/layout/contextual-sidebar/contextual-sidebar.js +51 -16
  7. package/dist/components/layout/contextual-sidebar/contextual-sidebar.js.map +1 -1
  8. package/dist/components/layout/contextual-sidebar/index.d.ts +1 -1
  9. package/dist/components/layout/contextual-sidebar/index.d.ts.map +1 -1
  10. package/dist/components/layout/shell-top-bar/shell-top-bar.d.ts +16 -10
  11. package/dist/components/layout/shell-top-bar/shell-top-bar.d.ts.map +1 -1
  12. package/dist/components/layout/shell-top-bar/shell-top-bar.js +2 -1
  13. package/dist/components/layout/shell-top-bar/shell-top-bar.js.map +1 -1
  14. package/dist/components/theme/script-projection.d.ts +17 -0
  15. package/dist/components/theme/script-projection.d.ts.map +1 -0
  16. package/dist/components/theme/script-projection.js +16 -0
  17. package/dist/components/theme/script-projection.js.map +1 -0
  18. package/dist/components/theme/theme-document-core.d.ts +5 -4
  19. package/dist/components/theme/theme-document-core.d.ts.map +1 -1
  20. package/dist/components/theme/theme-document-core.js +13 -3
  21. package/dist/components/theme/theme-document-core.js.map +1 -1
  22. package/dist/components/theme/theme-provider-value.d.ts +2 -1
  23. package/dist/components/theme/theme-provider-value.d.ts.map +1 -1
  24. package/dist/components/theme/theme-provider-value.js +7 -0
  25. package/dist/components/theme/theme-provider-value.js.map +1 -1
  26. package/dist/components/theme/theme-script.d.ts +12 -0
  27. package/dist/components/theme/theme-script.d.ts.map +1 -1
  28. package/dist/components/theme/theme-script.js +14 -5
  29. package/dist/components/theme/theme-script.js.map +1 -1
  30. package/dist/components/theme/theme-state-core.d.ts +6 -0
  31. package/dist/components/theme/theme-state-core.d.ts.map +1 -1
  32. package/dist/components/theme/theme-state-core.js.map +1 -1
  33. package/dist/components/theme/token-projection-options.d.ts +3 -0
  34. package/dist/components/theme/token-projection-options.d.ts.map +1 -0
  35. package/dist/components/theme/token-projection-options.js +9 -0
  36. package/dist/components/theme/token-projection-options.js.map +1 -0
  37. package/dist/components/theme/token-projection.d.ts +22 -0
  38. package/dist/components/theme/token-projection.d.ts.map +1 -0
  39. package/dist/components/theme/token-projection.js +1 -0
  40. package/dist/r/appearance-editor.json +1 -1
  41. package/dist/r/lib.json +1 -1
  42. package/dist/r/registry.json +18 -3
  43. package/dist/r/src/components/composites/appearance-editor/appearance-rows.tsx +17 -9
  44. package/dist/r/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +76 -19
  45. package/dist/r/src/components/layout/contextual-sidebar/index.ts +1 -0
  46. package/dist/r/src/components/layout/shell-top-bar/shell-top-bar.tsx +22 -14
  47. package/dist/r/src/components/theme/script-projection.ts +40 -0
  48. package/dist/r/src/components/theme/theme-document-core.ts +17 -4
  49. package/dist/r/src/components/theme/theme-provider-value.ts +11 -1
  50. package/dist/r/src/components/theme/theme-script.ts +52 -4
  51. package/dist/r/src/components/theme/theme-state-core.ts +6 -0
  52. package/dist/r/src/components/theme/token-projection-options.ts +14 -0
  53. package/dist/r/src/components/theme/token-projection.ts +37 -0
  54. package/dist/r/theming.json +16 -1
  55. package/package.json +14 -2
  56. package/registry.json +18 -3
  57. package/src/components/composites/appearance-editor/appearance-rows.tsx +17 -9
  58. package/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +76 -19
  59. package/src/components/layout/contextual-sidebar/index.ts +1 -0
  60. package/src/components/layout/shell-top-bar/shell-top-bar.tsx +22 -14
  61. package/src/components/theme/script-projection.ts +40 -0
  62. package/src/components/theme/theme-document-core.ts +17 -4
  63. package/src/components/theme/theme-provider-value.ts +11 -1
  64. package/src/components/theme/theme-script.ts +52 -4
  65. package/src/components/theme/theme-state-core.ts +6 -0
  66. package/src/components/theme/token-projection-options.ts +14 -0
  67. package/src/components/theme/token-projection.ts +37 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Opt-in no-flash script entry that can project imported token maps synchronously.
3
+ * Import this path only when the host supplies declarative projection rules; the
4
+ * ordinary `components/theme/script` entry stays free of the browser bundle.
5
+ */
6
+ import { themeTokenProjectionBundle } from '@adea-ai/themes/theme-token-projection/script'
7
+ import {
8
+ inlineScriptLiteral,
9
+ themeScriptWithProjection,
10
+ type ThemeScriptOptions as BaseThemeScriptOptions,
11
+ type ThemeTokenProjectionFallback,
12
+ } from './theme-script'
13
+ import type { ThemeTokenProjection } from './token-projection'
14
+
15
+ const tokenProjectionFallbackScript = `if(storedTheme&&tokenProjectionFallbacks.length){var sourceTokens=Object.create(null);for(var sourceName in tokens){if(Object.prototype.hasOwnProperty.call(tokens,sourceName))sourceTokens[sourceName]=tokens[sourceName]}for(var fi=0;fi<tokenProjectionFallbacks.length;fi++){var fallbackToken=tokenProjectionFallbacks[fi];if(!fallbackToken||typeof fallbackToken.token!=='string'||!/^--[A-Za-z0-9_-]+$/.test(fallbackToken.token)||Object.prototype.hasOwnProperty.call(sourceTokens,fallbackToken.token)||!Array.isArray(fallbackToken.path)||fallbackToken.path.length===0)continue;var sourceValue=storedTheme;for(var pi=0;pi<fallbackToken.path.length;pi++){var pathKey=fallbackToken.path[pi];if(typeof pathKey!=='string'||!sourceValue||typeof sourceValue!=='object'||!Object.prototype.hasOwnProperty.call(sourceValue,pathKey)){sourceValue=undefined;break}sourceValue=sourceValue[pathKey]}if(typeof sourceValue==='string')sourceTokens[fallbackToken.token]=sourceValue}tokens=sourceTokens}`
16
+
17
+ /** Options for the projection-enabled boot script. */
18
+ export type ThemeScriptOptions = Omit<BaseThemeScriptOptions, 'libraryKey'> & {
19
+ libraryKey: string
20
+ tokenProjection: ThemeTokenProjection
21
+ /** Optional serialized-record sources for projection tokens omitted by flatTokens. */
22
+ tokenProjectionFallbacks?: readonly ThemeTokenProjectionFallback[]
23
+ }
24
+
25
+ /** Alias that makes the opt-in projection requirement explicit at call sites. */
26
+ export type ThemeScriptProjectionOptions = ThemeScriptOptions
27
+
28
+ /** Emit a no-flash script with the same projector used by provider hydration. */
29
+ export function themeScript(options: ThemeScriptOptions): string {
30
+ return themeScriptWithProjection(
31
+ options,
32
+ options.tokenProjection,
33
+ themeTokenProjectionBundle,
34
+ tokenProjectionFallbackScript
35
+ )
36
+ }
37
+
38
+ export { inlineScriptLiteral }
39
+ export type { ThemeTokenProjectionFallback }
40
+ export type { ThemeStorageSchema } from './theme-persistence'
@@ -3,6 +3,8 @@ import {
3
3
  normalizeAppearanceEditorFontSettings,
4
4
  } from '#lib/appearance-font-settings'
5
5
  import { terminalCssVariables } from '#lib/theme-css'
6
+ import type { ThemeTokenProjectionOptions } from './token-projection'
7
+ import { assertThemeTokenProjectionConfig } from './token-projection-options'
6
8
  import type { ThemeEngine } from '#lib/theme-engine'
7
9
  import type { EditorRolesMode, ThemeAppearance, ThemeVariant } from '#lib/themes'
8
10
  import { isCustomAccent } from '#lib/accent-roles'
@@ -78,7 +80,7 @@ export type ThemeDocumentOptions = {
78
80
  * palette stays in the stylesheet.
79
81
  */
80
82
  editorRoles?: EditorRolesMode
81
- }
83
+ } & ThemeTokenProjectionOptions
82
84
 
83
85
  /**
84
86
  * What a catalogue variant still writes inline when its palette is the stylesheet's:
@@ -99,9 +101,9 @@ function stylesheetOverrides(
99
101
  }
100
102
 
101
103
  /**
102
- * The custom properties a state paints: the variant's roles, with the accent
103
- * selection laid over them, the pinned terminal palette over that, the surface
104
- * alpha, then `transformTokens`.
104
+ * The custom properties a state paints: the variant's roles, an optional projection
105
+ * from the raw host map, the accent, the pinned terminal palette, the surface alpha,
106
+ * then `transformTokens`.
105
107
  *
106
108
  * The accent is applied *here* rather than left to the `[data-accent]` blocks in
107
109
  * `theme.css`, because the properties are written inline and an inline declaration
@@ -115,11 +117,22 @@ export function themeDocumentTokensWith(
115
117
  state: ThemeDocumentState,
116
118
  options: ThemeDocumentOptions = {}
117
119
  ): { tokens: Record<string, string>; accented: boolean } {
120
+ assertThemeTokenProjectionConfig(options.tokenProjection)
118
121
  const fromStylesheet =
119
122
  options.palette === 'stylesheet' && engine.isCatalogueVariant(state.variant)
120
123
  const properties = fromStylesheet
121
124
  ? stylesheetOverrides(engine, state.variant, options.editorRoles)
122
125
  : { ...engine.themeCssVariables(state.variant, { editor: options.editorRoles }) }
126
+ if (options.tokenProjection && !engine.isCatalogueVariant(state.variant)) {
127
+ const rawTokens = state.variant.tokens ?? {}
128
+ const projected = options.tokenProjection.project(rawTokens, options.tokenProjection.rules)
129
+ for (const rule of options.tokenProjection.rules) {
130
+ if (!rule || typeof rule.target !== 'string') continue
131
+ if (Object.hasOwn(projected, rule.target)) {
132
+ properties[rule.target] = projected[rule.target]!
133
+ }
134
+ }
135
+ }
123
136
  const accent = engine.accentVariables(state.selection.accent, state.appearance, state.selection, {
124
137
  background: state.variant.colors.background,
125
138
  floor: options.accentContrastFloor,
@@ -1,5 +1,7 @@
1
1
  import type { JSX } from 'solid-js'
2
2
  import { createEffect, createMemo, createSignal, onCleanup, splitProps, untrack } from 'solid-js'
3
+ import type { ThemeTokenProjectionOptions } from './token-projection'
4
+ import { assertThemeTokenProjectionConfig } from './token-projection-options'
3
5
  import { fontZoomShortcut, type FontZoomIntent } from '#lib/font-zoom'
4
6
  import { REDUCED_TRANSPARENCY_QUERY, resolveSurfaceState } from '#lib/theme-surface'
5
7
  import { CatalogueRequired, needsCatalogue, type ThemeEngine } from '#lib/theme-engine'
@@ -156,7 +158,7 @@ export type ThemeProviderProps = {
156
158
  * `zoomFonts` on the context does the same from a menu or a host's own binding.
157
159
  */
158
160
  fontZoom?: boolean
159
- }
161
+ } & ThemeTokenProjectionOptions
160
162
 
161
163
  /**
162
164
  * Where the provider's catalogue questions are answered, and whether the whole
@@ -199,6 +201,7 @@ function reducedTransparencyMedia(): MediaQueryList | undefined {
199
201
  export function createThemeContextValue(
200
202
  props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }
201
203
  ): ThemeContextValue {
204
+ assertThemeTokenProjectionConfig(props.tokenProjection)
202
205
  const [local] = splitProps(props, [
203
206
  'catalogue',
204
207
  'storageKey',
@@ -207,6 +210,7 @@ export function createThemeContextValue(
207
210
  'persistence',
208
211
  'themes',
209
212
  'transformTokens',
213
+ 'tokenProjection',
210
214
  'disableTransitionOnChange',
211
215
  'accentContrastFloor',
212
216
  'surface',
@@ -266,6 +270,7 @@ export function createThemeContextValue(
266
270
  const shown = createMemo(() =>
267
271
  draft() ? resolveThemeState(shownSelection(), systemAppearance(), registry()) : committed()
268
272
  )
273
+ const shownAppearance = createMemo<ThemeAppearance>(() => shown().appearance)
269
274
 
270
275
  // The surface axis. Off, none of this reads the operating system: the media query
271
276
  // is subscribed only while the axis is on, so a provider that never opts in adds no
@@ -328,8 +333,12 @@ export function createThemeContextValue(
328
333
  terminalVariant: resolveTerminalVariant(shownSelection().terminalThemeId, registry()),
329
334
  surface: axisOn() ? surfaceStateOf(shownSelection()) : undefined,
330
335
  }
336
+ const projectionOptions = local.tokenProjection
337
+ ? { tokenProjection: local.tokenProjection }
338
+ : {}
331
339
  const options = {
332
340
  transformTokens: local.transformTokens,
341
+ ...projectionOptions,
333
342
  accentContrastFloor: local.accentContrastFloor,
334
343
  palette: local.palette,
335
344
  editorRoles: local.editorRoles,
@@ -382,6 +391,7 @@ export function createThemeContextValue(
382
391
  const value: ThemeContextValue = {
383
392
  selection,
384
393
  resolvedAppearance,
394
+ shownAppearance,
385
395
  variant,
386
396
  get themes() {
387
397
  return engine().builtinThemes
@@ -13,6 +13,7 @@ import { safeScriptStringLiteral } from '#lib/safe-script'
13
13
  import { REDUCED_TRANSPARENCY_QUERY, surfaceAlpha } from '#lib/theme-surface'
14
14
  import { accentPresets } from '#lib/accent-presets'
15
15
  import { THEME_INDEX, defaultDarkThemeId, defaultLightThemeId } from '#lib/theme-defaults'
16
+ import type { ThemeTokenProjection } from '@adea-ai/themes/theme-token-projection'
16
17
  import type { ThemeStorageSchema } from './theme-persistence'
17
18
 
18
19
  /**
@@ -37,6 +38,14 @@ export function inlineScriptLiteral(value: string): string {
37
38
  return safeScriptStringLiteral(value)
38
39
  }
39
40
 
41
+ /** A stored-record path that can supply an absent projection source token. */
42
+ export type ThemeTokenProjectionFallback = Readonly<{
43
+ /** The CSS custom property to fill only when the stored token map omits it. */
44
+ token: string
45
+ /** Own-property path from the stored library record to a string value. */
46
+ path: readonly string[]
47
+ }>
48
+
40
49
  /**
41
50
  * Options for the host-shaped no-flash script: the document's {@link ThemeStorageSchema}
42
51
  * plus what the script paints from it.
@@ -122,6 +131,24 @@ export function themeScript(input: string | ThemeScriptOptions = 'adea-appearanc
122
131
  return optionsFormScript(input)
123
132
  }
124
133
 
134
+ /** Internal hook for the opt-in script entry, which supplies its generated browser bundle. */
135
+ export function themeScriptWithProjection(
136
+ options: ThemeScriptOptions & {
137
+ tokenProjectionFallbacks?: readonly ThemeTokenProjectionFallback[]
138
+ },
139
+ tokenProjection: ThemeTokenProjection,
140
+ projectionBundle: string,
141
+ projectionFallbackScript: string
142
+ ): string {
143
+ return optionsFormScript(
144
+ options,
145
+ tokenProjection,
146
+ projectionBundle,
147
+ projectionFallbackScript,
148
+ options.tokenProjectionFallbacks
149
+ )
150
+ }
151
+
125
152
  function stringFormScript(storageKey: string): string {
126
153
  const script = `(function(){try{var s=localStorage.getItem(${inlineScriptLiteral(storageKey)});var p=s?JSON.parse(s):{};var a=p.appearance||'system';var d=a==='dark'||(a==='system'&&window.matchMedia('(prefers-color-scheme: dark)').matches);var r=document.documentElement;if(d)r.classList.add('dark');r.style.colorScheme=d?'dark':'light';if(p.accent&&p.accent!=='theme')r.dataset.accent=p.accent;if(p.density==='compact')r.dataset.density='compact';}catch(e){}})();`
127
154
  return `${script}${fontSettingsBootstrapScript(storageKey)}`
@@ -129,7 +156,13 @@ function stringFormScript(storageKey: string): string {
129
156
 
130
157
  const literal = safeScriptStringLiteral
131
158
 
132
- function optionsFormScript(options: ThemeScriptOptions): string {
159
+ function optionsFormScript(
160
+ options: ThemeScriptOptions,
161
+ projection?: ThemeTokenProjection,
162
+ projectionBundle?: string,
163
+ projectionFallbackScript = '',
164
+ projectionFallbacks?: readonly ThemeTokenProjectionFallback[]
165
+ ): string {
133
166
  const field = options.appearanceField ?? 'appearance'
134
167
  const versionGuard =
135
168
  options.version === undefined ? '' : `&&x.version===${Number(options.version)}`
@@ -142,6 +175,20 @@ function optionsFormScript(options: ThemeScriptOptions): string {
142
175
  : isCustomAccent(options.defaultAccent)
143
176
  ? 'custom'
144
177
  : options.defaultAccent
178
+ const canProjectTokens =
179
+ options.libraryKey !== undefined &&
180
+ projection &&
181
+ projection.length > 0 &&
182
+ projectionBundle !== undefined
183
+ const hasProjectionFallbacks = canProjectTokens && !!projectionFallbacks?.length
184
+ const tokenProjection = canProjectTokens
185
+ ? `var projectTokens=${projectionBundle};var tokenProjection=JSON.parse(${literal(JSON.stringify(projection))});${
186
+ hasProjectionFallbacks
187
+ ? `var tokenProjectionFallbacks=JSON.parse(${literal(JSON.stringify(projectionFallbacks))});`
188
+ : ''
189
+ }`
190
+ : ''
191
+ const projectionFallbackCode = hasProjectionFallbacks ? projectionFallbackScript : ''
145
192
 
146
193
  const parts: string[] = []
147
194
  parts.push(
@@ -165,16 +212,17 @@ function optionsFormScript(options: ThemeScriptOptions): string {
165
212
  `var want=doc?(dark?doc.darkThemeId:doc.lightThemeId):null;`,
166
213
  `if(typeof want!=='string')want=fallback;`,
167
214
  `var ids=[${THEME_INDEX.map(([id]) => literal(id)).join(',')}];`,
168
- `var id=ids.indexOf(want)!==-1?want:null,tokens=null;`
215
+ `var id=ids.indexOf(want)!==-1?want:null,tokens=null${hasProjectionFallbacks ? ',storedTheme=null' : ''};`
169
216
  )
170
217
  if (options.libraryKey !== undefined) {
171
218
  parts.push(
172
219
  `if(id===null){try{var lib=JSON.parse(get(${literal(options.libraryKey)})||'null');`,
173
220
  `if(lib&&typeof lib==='object'&&lib.version===${Number(options.libraryVersion ?? 1)}&&Array.isArray(lib.themes)){`,
174
221
  `for(var i=0;i!==lib.themes.length;i++){var t=lib.themes[i];`,
175
- `if(t&&t.id===want&&t.flatTokens&&typeof t.flatTokens==='object'){id=want;tokens=t.flatTokens;break}}}}catch(e){}}`
222
+ `if(t&&t.id===want&&t.flatTokens&&typeof t.flatTokens==='object'){id=want;tokens=t.flatTokens;${hasProjectionFallbacks ? 'storedTheme=t;' : ''}break}}}}catch(e){}}`
176
223
  )
177
224
  }
225
+ if (options.libraryKey !== undefined && tokenProjection) parts.push(tokenProjection)
178
226
  parts.push(
179
227
  `if(id===null)id=fallback;`,
180
228
  `r.classList.toggle('dark',dark);`,
@@ -184,7 +232,7 @@ function optionsFormScript(options: ThemeScriptOptions): string {
184
232
  )
185
233
  if (options.libraryKey !== undefined) {
186
234
  parts.push(
187
- `if(tokens){for(var n in tokens){if(Object.prototype.hasOwnProperty.call(tokens,n)&&n.slice(0,2)==='--'&&typeof tokens[n]==='string')s.setProperty(n,tokens[n])}}`
235
+ `if(tokens){if(typeof projectTokens==='function'){${projectionFallbackCode}tokens=projectTokens(tokens,tokenProjection)}for(var n in tokens){if(Object.prototype.hasOwnProperty.call(tokens,n)&&n.slice(0,2)==='--'&&typeof tokens[n]==='string')s.setProperty(n,tokens[n])}}`
188
236
  )
189
237
  }
190
238
  parts.push(
@@ -131,6 +131,12 @@ export type ThemeContextValue = {
131
131
  selection: () => ThemeSelection
132
132
  /** What the preference resolves to right now, after `system`. */
133
133
  resolvedAppearance: () => ThemeAppearance
134
+ /**
135
+ * The appearance currently shown by the provider, including an active preview.
136
+ * Optional for compatibility with values supplied by an older copy of the UI
137
+ * package or by a host-owned context mock; providers always expose it.
138
+ */
139
+ shownAppearance?: () => ThemeAppearance
134
140
  /** The variant in use. */
135
141
  variant: () => ThemeVariant
136
142
  /** Update part of the preference. */
@@ -0,0 +1,14 @@
1
+ /** Keep the runtime configuration check free of the optional Themes projector import. */
2
+ export function assertThemeTokenProjectionConfig(config: unknown): void {
3
+ if (config === undefined) return
4
+ if (
5
+ !config ||
6
+ typeof config !== 'object' ||
7
+ !('rules' in config) ||
8
+ !Array.isArray(config.rules) ||
9
+ !('project' in config) ||
10
+ typeof config.project !== 'function'
11
+ ) {
12
+ throw new TypeError('tokenProjection requires both rules and project')
13
+ }
14
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Runtime token projection for hosts that opt in to projecting legacy theme maps.
3
+ * The default provider and boot script do not import this entry.
4
+ */
5
+ import type { ThemeTokenProjection } from '@adea-ai/themes/theme-token-projection'
6
+
7
+ export {
8
+ projectThemeTokens,
9
+ projectThemeTokensDetailed,
10
+ } from '@adea-ai/themes/theme-token-projection'
11
+ export type {
12
+ ThemeTokenContrastRule,
13
+ ThemeTokenProjection,
14
+ ThemeTokenProjectionFailure,
15
+ ThemeTokenProjectionResult,
16
+ ThemeTokenProjectionRule,
17
+ } from '@adea-ai/themes/theme-token-projection'
18
+
19
+ /** Function type for the shared projector supplied by opt-in hosts. */
20
+ export type ThemeTokenProjector = (
21
+ tokens: Readonly<Record<string, string>>,
22
+ projection: ThemeTokenProjection
23
+ ) => Record<string, string>
24
+
25
+ /** Rules and their projector travel together through provider/document options. */
26
+ export type ThemeTokenProjectionConfig = Readonly<{
27
+ rules: ThemeTokenProjection
28
+ project: ThemeTokenProjector
29
+ }>
30
+
31
+ /**
32
+ * Projection rules and their runtime; hosts that opt in provide both. The rules operate
33
+ * on each custom variant's raw `tokens` map, preserving the prepaint source's availability.
34
+ */
35
+ export type ThemeTokenProjectionOptions = {
36
+ tokenProjection?: ThemeTokenProjectionConfig
37
+ }