/** * Publisher-toggleable features (see types.ts#CanvasFeature). When a canvas is * published to the web, the person publishing gets a checklist of the canvas's * declared `features` and can switch any off for visitors; the disabled ids are * injected into the published page as `window.__CASPIAN_DISABLED_FEATURES__`. * * Inside the Caspian app the global is absent, so every feature is enabled. * A canvas should read `featureEnabled(id)` while building its UI and, when a * feature is off, not create that control at all (and hold the feature at its * default state). * * Copy this file into your canvas's own sdk/ folder alongside bridge.ts and * types.ts. Optional: only canvases that declare `features` in canvas.json need it. */ import { DISABLED_FEATURES_GLOBAL } from './types' function disabledSet(): Set { const raw = (globalThis as Record)[DISABLED_FEATURES_GLOBAL] return new Set(Array.isArray(raw) ? raw.filter((x): x is string => typeof x === 'string') : []) } /** True unless this feature id was switched off for the published copy. */ export function featureEnabled(id: string): boolean { return !disabledSet().has(id) }