@dfosco/storyboard-core 3.5.0 → 3.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfosco/storyboard-core",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -131,7 +131,7 @@ const THEMES = {
131
131
 
132
132
  /**
133
133
  * Resolve the current theme ID based on page theme and config.
134
- * Always follows the page theme (data-sb-theme attribute).
134
+ * Follows code-box theme (data-sb-code-theme attribute).
135
135
  */
136
136
  function normalizeThemeId(requested, mode) {
137
137
  const fallback = mode === 'light' ? 'github' : 'github-dark-dimmed'
@@ -166,11 +166,11 @@ function resolveThemeId() {
166
166
  const darkTheme = normalizeThemeId(highlighting.dark, 'dark')
167
167
  const lightTheme = normalizeThemeId(highlighting.light, 'light')
168
168
 
169
- const sbTheme = typeof document !== 'undefined'
170
- ? document.documentElement.getAttribute('data-sb-theme') || 'dark'
169
+ const codeTheme = typeof document !== 'undefined'
170
+ ? document.documentElement.getAttribute('data-sb-code-theme') || 'light'
171
171
  : 'dark'
172
172
 
173
- return sbTheme.startsWith('dark') ? darkTheme : lightTheme
173
+ return codeTheme.startsWith('dark') ? darkTheme : lightTheme
174
174
  }
175
175
 
176
176
  /**
@@ -92,35 +92,52 @@ function _applyToDOM(theme: ThemeValue, resolved: string): void {
92
92
  if (typeof document === 'undefined') return
93
93
  const el = document.documentElement
94
94
 
95
- // Internal attribute
96
- el.setAttribute('data-sb-theme', resolved)
95
+ // Per-target resolved themes
96
+ const prototypeTheme = _syncTargets.prototype ? resolved : 'light'
97
+ const toolbarTheme = _syncTargets.toolbar ? resolved : 'light'
98
+ const codeTheme = _syncTargets.codeBoxes ? resolved : 'light'
99
+
100
+ // Internal attributes
101
+ el.setAttribute('data-sb-theme', prototypeTheme)
102
+ el.setAttribute('data-sb-code-theme', codeTheme)
97
103
 
98
104
  // Toolbar theme — follows global theme when synced, stays light otherwise
99
- const toolbarTheme = _syncTargets.toolbar ? resolved : 'light'
100
105
  el.setAttribute('data-sb-toolbar-theme', toolbarTheme)
101
106
 
102
107
  // Primer CSS attributes — these drive @primer/react ThemeProvider and
103
108
  // Primer CSS custom-property layers without needing React state updates.
104
- if (theme === 'system') {
109
+ if (theme === 'system' && _syncTargets.prototype) {
105
110
  el.setAttribute('data-color-mode', 'auto')
106
111
  el.setAttribute('data-light-theme', 'light')
107
112
  el.setAttribute('data-dark-theme', 'dark')
108
- } else if (resolved.startsWith('dark')) {
113
+ } else if (prototypeTheme.startsWith('dark')) {
109
114
  el.setAttribute('data-color-mode', 'dark')
110
- el.setAttribute('data-dark-theme', resolved)
115
+ el.setAttribute('data-dark-theme', prototypeTheme)
111
116
  el.setAttribute('data-light-theme', 'light')
112
117
  } else {
113
118
  el.setAttribute('data-color-mode', 'light')
114
- el.setAttribute('data-light-theme', resolved)
119
+ el.setAttribute('data-light-theme', prototypeTheme)
115
120
  el.setAttribute('data-dark-theme', 'dark')
116
121
  }
117
122
  }
118
123
 
119
124
  function _dispatchEvent(theme: ThemeValue, resolved: string): void {
120
125
  if (typeof document === 'undefined') return
126
+ const prototypeTheme = _syncTargets.prototype ? theme : 'light'
127
+ const prototypeResolved = _syncTargets.prototype ? resolved : 'light'
128
+ const toolbarResolved = _syncTargets.toolbar ? resolved : 'light'
129
+ const codeResolved = _syncTargets.codeBoxes ? resolved : 'light'
130
+
121
131
  document.dispatchEvent(
122
132
  new CustomEvent('storyboard:theme:changed', {
123
- detail: { theme, resolved },
133
+ detail: {
134
+ theme,
135
+ resolved,
136
+ prototypeTheme,
137
+ prototypeResolved,
138
+ toolbarResolved,
139
+ codeResolved,
140
+ },
124
141
  }),
125
142
  )
126
143
  }
@@ -19,8 +19,9 @@ export async function handler(ctx) {
19
19
  path = path.replace(/\/+$/, '') || '/'
20
20
  const segments = path.split('/').filter(Boolean)
21
21
 
22
- // Skip branch-- segment on deployed branch builds
23
- const protoIdx = (segments[0] && segments[0].startsWith('branch--')) ? 1 : 0
22
+ // Detect and preserve branch-- segment on deployed branch builds
23
+ const branchSegment = (segments[0] && segments[0].startsWith('branch--')) ? segments[0] : null
24
+ const protoIdx = branchSegment ? 1 : 0
24
25
  const proto = segments[protoIdx] || null
25
26
  if (!proto) return []
26
27
 
@@ -49,7 +50,13 @@ export async function handler(ctx) {
49
50
  label: meta?.title || f.name,
50
51
  type: 'radio',
51
52
  active: f.key === active,
52
- execute: () => { window.location.href = vf.resolveFlowRoute(f.key) },
53
+ execute: () => {
54
+ let url = vf.resolveFlowRoute(f.key)
55
+ // Re-apply basePath and branch-- prefix so deployed branch builds stay on the correct path
56
+ const prefix = (base || '') + (branchSegment ? `/${branchSegment}` : '')
57
+ if (prefix) url = prefix + url
58
+ window.location.href = url
59
+ },
53
60
  }
54
61
  })
55
62
  },