@dfosco/storyboard-core 1.17.3 → 1.18.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/devtools.js +113 -9
- package/src/featureFlags.js +112 -0
- package/src/index.js +3 -0
package/package.json
CHANGED
package/src/devtools.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { loadScene } from './loader.js'
|
|
17
17
|
import { isCommentsEnabled } from './comments/config.js'
|
|
18
18
|
import { isHideMode, activateHideMode, deactivateHideMode } from './hideMode.js'
|
|
19
|
+
import { getAllFlags, toggleFlag, getFlagKeys } from './featureFlags.js'
|
|
19
20
|
|
|
20
21
|
const STYLES = `
|
|
21
22
|
.sb-devtools-wrapper {
|
|
@@ -67,7 +68,7 @@ const STYLES = `
|
|
|
67
68
|
border: none;
|
|
68
69
|
color: #c9d1d9;
|
|
69
70
|
font-size: 14px;
|
|
70
|
-
font-family:
|
|
71
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
|
71
72
|
cursor: pointer;
|
|
72
73
|
text-align: left;
|
|
73
74
|
}
|
|
@@ -101,6 +102,7 @@ const STYLES = `
|
|
|
101
102
|
width: 100%;
|
|
102
103
|
max-width: 640px;
|
|
103
104
|
max-height: 60vh;
|
|
105
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
|
104
106
|
background-color: #0d1117;
|
|
105
107
|
border: 1px solid #30363d;
|
|
106
108
|
border-radius: 12px;
|
|
@@ -151,6 +153,19 @@ const STYLES = `
|
|
|
151
153
|
word-break: break-word;
|
|
152
154
|
}
|
|
153
155
|
.sb-devtools-error { color: #f85149; }
|
|
156
|
+
.sb-devtools-separator {
|
|
157
|
+
height: 1px;
|
|
158
|
+
background-color: #21262d;
|
|
159
|
+
margin: 4px 0;
|
|
160
|
+
}
|
|
161
|
+
.sb-devtools-group-header {
|
|
162
|
+
padding: 6px 16px 2px;
|
|
163
|
+
font-size: 12px;
|
|
164
|
+
font-weight: 600;
|
|
165
|
+
color: #8b949e;
|
|
166
|
+
text-transform: uppercase;
|
|
167
|
+
letter-spacing: 0.5px;
|
|
168
|
+
}
|
|
154
169
|
`
|
|
155
170
|
|
|
156
171
|
// SVG icons (inline to avoid external deps)
|
|
@@ -161,6 +176,8 @@ const VIEWFINDER_ICON = '<svg viewBox="0 0 16 16"><path d="M8.5 1.75a.75.75 0 0
|
|
|
161
176
|
const X_ICON = '<svg viewBox="0 0 16 16"><path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"/></svg>'
|
|
162
177
|
const EYE_ICON = '<svg viewBox="0 0 16 16"><path d="M8 2c1.981 0 3.671.992 4.933 2.078 1.27 1.091 2.187 2.345 2.637 3.023a1.62 1.62 0 0 1 0 1.798c-.45.678-1.367 1.932-2.637 3.023C11.67 13.008 9.981 14 8 14s-3.671-.992-4.933-2.078C1.797 10.831.88 9.577.43 8.899a1.62 1.62 0 0 1 0-1.798c.45-.678 1.367-1.932 2.637-3.023C4.33 2.992 6.019 2 8 2ZM1.679 7.932a.12.12 0 0 0 0 .136c.411.622 1.241 1.75 2.366 2.717C5.176 11.758 6.527 12.5 8 12.5s2.823-.742 3.955-1.715c1.124-.967 1.954-2.096 2.366-2.717a.12.12 0 0 0 0-.136c-.412-.621-1.242-1.75-2.366-2.717C10.824 4.242 9.473 3.5 8 3.5s-2.824.742-3.955 1.715c-1.124.967-1.954 2.096-2.366 2.717ZM8 10a2 2 0 1 1-.001-3.999A2 2 0 0 1 8 10Z"/></svg>'
|
|
163
178
|
const EYE_CLOSED_ICON = '<svg viewBox="0 0 16 16"><path d="M.143 2.31a.75.75 0 0 1 1.047-.167l14.5 10.5a.75.75 0 1 1-.88 1.214l-2.248-1.628C11.346 13.19 9.792 14 8 14c-1.981 0-3.671-.992-4.933-2.078C1.797 10.831.88 9.577.43 8.899a1.62 1.62 0 0 1 0-1.798c.35-.527 1.06-1.476 2.019-2.398L.31 3.357A.75.75 0 0 1 .143 2.31Zm3.386 3.378a14.21 14.21 0 0 0-1.85 2.244.12.12 0 0 0 0 .136c.411.622 1.241 1.75 2.366 2.717C5.176 11.758 6.527 12.5 8 12.5c1.195 0 2.31-.488 3.29-1.191L9.063 9.695A2 2 0 0 1 6.058 7.39L3.529 5.688ZM8 3.5c-.516 0-1.017.09-1.499.251a.75.75 0 1 1-.473-1.423A6.23 6.23 0 0 1 8 2c1.981 0 3.671.992 4.933 2.078 1.27 1.091 2.187 2.345 2.637 3.023a1.62 1.62 0 0 1 0 1.798c-.11.166-.248.365-.41.587a.75.75 0 1 1-1.21-.887c.14-.191.26-.367.36-.524a.12.12 0 0 0 0-.136c-.412-.621-1.242-1.75-2.366-2.717C10.824 4.242 9.473 3.5 8 3.5Z"/></svg>'
|
|
179
|
+
const CHECK_ICON = '<svg viewBox="0 0 16 16"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>'
|
|
180
|
+
const ZAP_ICON = '<svg viewBox="0 0 16 16"><path d="M9.504.43a1.516 1.516 0 0 1 2.437 1.713L10.415 5.5h2.123c1.57 0 2.346 1.909 1.22 3.004l-7.34 7.142a1.249 1.249 0 0 1-.871.354h-.302a1.25 1.25 0 0 1-1.157-1.723L5.633 10.5H3.462c-1.57 0-2.346-1.909-1.22-3.004Z"/></svg>'
|
|
164
181
|
|
|
165
182
|
function getSceneName() {
|
|
166
183
|
return new URLSearchParams(window.location.search).get('scene') || 'default'
|
|
@@ -227,10 +244,11 @@ export function mountDevTools(options = {}) {
|
|
|
227
244
|
hint.className = 'sb-devtools-hint'
|
|
228
245
|
hint.innerHTML = 'Press <code>⌘ + .</code> to hide'
|
|
229
246
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
menu
|
|
233
|
-
|
|
247
|
+
// Feature flags entry (opens a dedicated panel)
|
|
248
|
+
const featureFlagsBtn = document.createElement('button')
|
|
249
|
+
featureFlagsBtn.className = 'sb-devtools-menu-item'
|
|
250
|
+
featureFlagsBtn.innerHTML = `${ZAP_ICON} Feature Flags`
|
|
251
|
+
featureFlagsBtn.addEventListener('click', openFlagsPanel)
|
|
234
252
|
|
|
235
253
|
// Comments menu items (injected dynamically if comments are enabled)
|
|
236
254
|
function refreshCommentMenuItems() {
|
|
@@ -258,19 +276,104 @@ export function mountDevTools(options = {}) {
|
|
|
258
276
|
})
|
|
259
277
|
}
|
|
260
278
|
|
|
279
|
+
function renderMainMenu() {
|
|
280
|
+
while (menu.firstChild) menu.removeChild(menu.firstChild)
|
|
281
|
+
menu.appendChild(viewfinderBtn)
|
|
282
|
+
menu.appendChild(showInfoBtn)
|
|
283
|
+
menu.appendChild(resetBtn)
|
|
284
|
+
menu.appendChild(hideModeBtn)
|
|
285
|
+
if (getFlagKeys().length > 0) {
|
|
286
|
+
const sep = document.createElement('div')
|
|
287
|
+
sep.className = 'sb-devtools-separator'
|
|
288
|
+
menu.appendChild(sep)
|
|
289
|
+
menu.appendChild(featureFlagsBtn)
|
|
290
|
+
}
|
|
291
|
+
refreshCommentMenuItems()
|
|
292
|
+
menu.appendChild(hint)
|
|
293
|
+
}
|
|
294
|
+
|
|
261
295
|
// Refresh dynamic items when menu opens
|
|
262
296
|
trigger.addEventListener('click', () => {
|
|
263
|
-
|
|
297
|
+
renderMainMenu()
|
|
264
298
|
updateHideModeBtn()
|
|
265
299
|
})
|
|
266
300
|
|
|
267
|
-
menu.
|
|
301
|
+
// Build initial (closed) menu content so tests and static DOM inspection work.
|
|
302
|
+
renderMainMenu()
|
|
268
303
|
wrapper.appendChild(menu)
|
|
269
304
|
wrapper.appendChild(trigger)
|
|
270
305
|
container.appendChild(wrapper)
|
|
271
306
|
|
|
272
|
-
//
|
|
307
|
+
// Overlays (created lazily)
|
|
273
308
|
let overlay = null
|
|
309
|
+
let flagsOverlay = null
|
|
310
|
+
|
|
311
|
+
function closeFlagsPanel() {
|
|
312
|
+
if (flagsOverlay) {
|
|
313
|
+
flagsOverlay.remove()
|
|
314
|
+
flagsOverlay = null
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function openFlagsPanel() {
|
|
319
|
+
menuOpen = false
|
|
320
|
+
menu.classList.remove('open')
|
|
321
|
+
closeFlagsPanel()
|
|
322
|
+
|
|
323
|
+
flagsOverlay = document.createElement('div')
|
|
324
|
+
flagsOverlay.className = 'sb-devtools-overlay'
|
|
325
|
+
|
|
326
|
+
const backdrop = document.createElement('div')
|
|
327
|
+
backdrop.className = 'sb-devtools-backdrop'
|
|
328
|
+
backdrop.addEventListener('click', closeFlagsPanel)
|
|
329
|
+
|
|
330
|
+
const panel = document.createElement('div')
|
|
331
|
+
panel.className = 'sb-devtools-panel'
|
|
332
|
+
|
|
333
|
+
const header = document.createElement('div')
|
|
334
|
+
header.className = 'sb-devtools-panel-header'
|
|
335
|
+
header.innerHTML = '<span class="sb-devtools-panel-title">Feature Flags</span>'
|
|
336
|
+
|
|
337
|
+
const closeBtn = document.createElement('button')
|
|
338
|
+
closeBtn.className = 'sb-devtools-panel-close'
|
|
339
|
+
closeBtn.setAttribute('aria-label', 'Close feature flags panel')
|
|
340
|
+
closeBtn.innerHTML = X_ICON
|
|
341
|
+
closeBtn.addEventListener('click', closeFlagsPanel)
|
|
342
|
+
header.appendChild(closeBtn)
|
|
343
|
+
|
|
344
|
+
const body = document.createElement('div')
|
|
345
|
+
body.className = 'sb-devtools-panel-body'
|
|
346
|
+
|
|
347
|
+
function renderFlagItems() {
|
|
348
|
+
body.innerHTML = ''
|
|
349
|
+
const keys = getFlagKeys()
|
|
350
|
+
if (keys.length === 0) {
|
|
351
|
+
body.innerHTML = '<span class="sb-devtools-hint">No feature flags are configured.</span>'
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
const flags = getAllFlags()
|
|
355
|
+
for (const key of keys) {
|
|
356
|
+
const btn = document.createElement('button')
|
|
357
|
+
btn.className = 'sb-devtools-menu-item'
|
|
358
|
+
const icon = flags[key].current
|
|
359
|
+
? `<span style="width:16px;height:16px;display:flex;align-items:center;justify-content:center;">${CHECK_ICON}</span>`
|
|
360
|
+
: '<span style="width:16px;height:16px;"></span>'
|
|
361
|
+
btn.innerHTML = `${icon} ${key}`
|
|
362
|
+
btn.addEventListener('click', () => {
|
|
363
|
+
toggleFlag(key)
|
|
364
|
+
renderFlagItems()
|
|
365
|
+
})
|
|
366
|
+
body.appendChild(btn)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
renderFlagItems()
|
|
370
|
+
|
|
371
|
+
panel.appendChild(header)
|
|
372
|
+
panel.appendChild(body)
|
|
373
|
+
flagsOverlay.appendChild(backdrop)
|
|
374
|
+
flagsOverlay.appendChild(panel)
|
|
375
|
+
container.appendChild(flagsOverlay)
|
|
376
|
+
}
|
|
274
377
|
|
|
275
378
|
function openPanel() {
|
|
276
379
|
menuOpen = false
|
|
@@ -367,7 +470,7 @@ export function mountDevTools(options = {}) {
|
|
|
367
470
|
menu.classList.remove('open')
|
|
368
471
|
})
|
|
369
472
|
|
|
370
|
-
// Close menu when clicking outside
|
|
473
|
+
// Close menu when clicking outside — reset to main view
|
|
371
474
|
document.addEventListener('click', (e) => {
|
|
372
475
|
if (menuOpen && !wrapper.contains(e.target)) {
|
|
373
476
|
menuOpen = false
|
|
@@ -385,6 +488,7 @@ export function mountDevTools(options = {}) {
|
|
|
385
488
|
menuOpen = false
|
|
386
489
|
menu.classList.remove('open')
|
|
387
490
|
closePanel()
|
|
491
|
+
closeFlagsPanel()
|
|
388
492
|
}
|
|
389
493
|
}
|
|
390
494
|
})
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature flag system for Storyboard.
|
|
3
|
+
*
|
|
4
|
+
* Flags are defined in storyboard.config.json under "featureFlags" and
|
|
5
|
+
* initialized at app startup via the Vite data plugin.
|
|
6
|
+
*
|
|
7
|
+
* Read priority: URL hash → localStorage → config defaults
|
|
8
|
+
* Write target: URL hash (shareable)
|
|
9
|
+
*
|
|
10
|
+
* All flag keys in hash/localStorage are prefixed with "flag." to avoid
|
|
11
|
+
* collisions with scene overrides.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { getParam, setParam, removeParam, getAllParams } from './session.js'
|
|
15
|
+
import { getLocal, setLocal, removeLocal, getAllLocal } from './localStorage.js'
|
|
16
|
+
|
|
17
|
+
const FLAG_PREFIX = 'flag.'
|
|
18
|
+
|
|
19
|
+
/** Module-level storage for config defaults */
|
|
20
|
+
let _defaults = {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the feature flag system with config defaults.
|
|
24
|
+
* Seeds localStorage with defaults (doesn't overwrite existing values).
|
|
25
|
+
* @param {Record<string, boolean>} defaults - Flag key → default value
|
|
26
|
+
*/
|
|
27
|
+
export function initFeatureFlags(defaults = {}) {
|
|
28
|
+
_defaults = { ...defaults }
|
|
29
|
+
// Seed localStorage with defaults (don't overwrite existing)
|
|
30
|
+
for (const [key, value] of Object.entries(_defaults)) {
|
|
31
|
+
if (getLocal(FLAG_PREFIX + key) === null) {
|
|
32
|
+
setLocal(FLAG_PREFIX + key, String(value))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Read a flag value. Priority: hash → localStorage → config default.
|
|
39
|
+
* @param {string} key - Flag key (without prefix)
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
export function getFlag(key) {
|
|
43
|
+
// 1. URL hash (highest priority)
|
|
44
|
+
const hashVal = getParam(FLAG_PREFIX + key)
|
|
45
|
+
if (hashVal !== null) return hashVal === 'true'
|
|
46
|
+
|
|
47
|
+
// 2. localStorage
|
|
48
|
+
const localVal = getLocal(FLAG_PREFIX + key)
|
|
49
|
+
if (localVal !== null) return localVal === 'true'
|
|
50
|
+
|
|
51
|
+
// 3. Config default
|
|
52
|
+
return _defaults[key] ?? false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Set a flag value. Writes to URL hash for shareability.
|
|
57
|
+
* @param {string} key - Flag key (without prefix)
|
|
58
|
+
* @param {boolean} value
|
|
59
|
+
*/
|
|
60
|
+
export function setFlag(key, value) {
|
|
61
|
+
setParam(FLAG_PREFIX + key, String(value))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Toggle a flag. Reads current value, writes opposite to hash.
|
|
66
|
+
* @param {string} key - Flag key (without prefix)
|
|
67
|
+
*/
|
|
68
|
+
export function toggleFlag(key) {
|
|
69
|
+
setFlag(key, !getFlag(key))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get all flags with their default and current (resolved) values.
|
|
74
|
+
* @returns {Record<string, { default: boolean, current: boolean }>}
|
|
75
|
+
*/
|
|
76
|
+
export function getAllFlags() {
|
|
77
|
+
const result = {}
|
|
78
|
+
for (const key of Object.keys(_defaults)) {
|
|
79
|
+
result[key] = {
|
|
80
|
+
default: _defaults[key] ?? false,
|
|
81
|
+
current: getFlag(key),
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Reset all flags — removes hash and localStorage overrides.
|
|
89
|
+
* Flags revert to config defaults.
|
|
90
|
+
*/
|
|
91
|
+
export function resetFlags() {
|
|
92
|
+
const allParams = getAllParams()
|
|
93
|
+
for (const paramKey of Object.keys(allParams)) {
|
|
94
|
+
if (paramKey.startsWith(FLAG_PREFIX)) {
|
|
95
|
+
removeParam(paramKey)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const allLocal = getAllLocal()
|
|
99
|
+
for (const localKey of Object.keys(allLocal)) {
|
|
100
|
+
if (localKey.startsWith(FLAG_PREFIX)) {
|
|
101
|
+
removeLocal(localKey)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get all registered flag keys.
|
|
108
|
+
* @returns {string[]}
|
|
109
|
+
*/
|
|
110
|
+
export function getFlagKeys() {
|
|
111
|
+
return Object.keys(_defaults)
|
|
112
|
+
}
|
package/src/index.js
CHANGED
|
@@ -37,5 +37,8 @@ export { mountSceneDebug } from './sceneDebug.js'
|
|
|
37
37
|
// Viewfinder utilities
|
|
38
38
|
export { hash, resolveSceneRoute, getSceneMeta } from './viewfinder.js'
|
|
39
39
|
|
|
40
|
+
// Feature flags
|
|
41
|
+
export { initFeatureFlags, getFlag, setFlag, toggleFlag, getAllFlags, resetFlags, getFlagKeys } from './featureFlags.js'
|
|
42
|
+
|
|
40
43
|
// Comments system
|
|
41
44
|
export { initCommentsConfig, getCommentsConfig, isCommentsEnabled } from './comments/config.js'
|