@etchteam/storybook-addon-css-variables-theme
Version:
Switch CSS files to change themes
9 lines (6 loc) • 1.19 kB
JavaScript
;
var previewApi = require('@storybook/preview-api');
var c="cssVariables",l="No Theme",u="storybookcssvariables:theme:change";function d(e){let t=`${e}=`,o=decodeURIComponent(document.cookie).split(";");for(let s=0;s<o.length;s++){let a=o[s];for(;a.startsWith(" ");)a=a.substring(1);if(a.startsWith(t))return a.substring(t.length,a.length)}return null}function p(e,t,n){let o=new Date;o.setTime(o.getTime()+n*24*60*60*1e3);let s=`expires=${o.toUTCString()}`;document.cookie=`${e}=${t};${s};path=/`;}var r=null;async function b(e,t){let n=t[e];n&&(n.use(),r&&r.unuse(),r=n),r&&e===l&&(r.unuse(),r=null);}function f({id:e,files:t,save:n}){b(e,t),n&&p(c,e,10);let o=new CustomEvent(u,{detail:{theme:e}});document?.dispatchEvent(o);}var w=previewApi.makeDecorator({name:"CSS Variables Theme",parameterName:c,wrapper:(e,t,{parameters:n})=>{let{files:o,theme:s,defaultTheme:a}=n,g=t.globals[c],C=previewApi.addons.getChannel(),i=d(c),m=Object.hasOwn(o,i)||i===l?i:null,h=g||s||m||a;return t.globals[c]=h,f({id:h,files:o,save:!s||!m}),C.on(`${c}Change`,({id:E})=>f({id:E,files:o,save:!0})),e(t)}});
module.exports = w;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map