storybook-addon-pseudo-states 4.0.0--canary.124.4a85ada.0 → 4.0.0--canary.124.92df327.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.
@@ -1,8 +1,8 @@
1
1
  import * as storybook_internal_types from 'storybook/internal/types';
2
2
 
3
3
  declare const decorators: storybook_internal_types.DecoratorFunction[];
4
- declare const globals: {
4
+ declare const initialGlobals: {
5
5
  pseudo: boolean;
6
6
  };
7
7
 
8
- export { decorators, globals };
8
+ export { decorators, initialGlobals };
package/dist/preview.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as storybook_internal_types from 'storybook/internal/types';
2
2
 
3
3
  declare const decorators: storybook_internal_types.DecoratorFunction[];
4
- declare const globals: {
4
+ declare const initialGlobals: {
5
5
  pseudo: boolean;
6
6
  };
7
7
 
8
- export { decorators, globals };
8
+ export { decorators, initialGlobals };
package/dist/preview.js CHANGED
@@ -6,4 +6,4 @@ var previewApi = require('storybook/internal/preview-api');
6
6
  var g="pseudo",R=["::-(webkit|moz|ms)-[a-z-]+","::part\\([^)]+\\)"],u={hover:"hover",active:"active",focusVisible:"focus-visible",focusWithin:"focus-within",focus:"focus",visited:"visited",link:"link",target:"target"};var k=e=>e.indexOf("@")===0,y=e=>{if(k(e))return [e];let o=[],t=0,s=0,n="";for(let r=0,c=e.length;r<c;r++){let a=e[r];if(a==="(")t+=1;else if(a===")")t-=1;else if(a==="[")s+=1;else if(a==="]")s-=1;else if(a===","&&!t&&!s){o.push(n.trim()),n="";continue}n+=a;}return o.push(n.trim()),o};var A=Object.values(u),O=`:(${A.join("|")})`,h=new RegExp(O),j=new RegExp(O,"g"),P=new Set,w=e=>{P.has(e)||(console.warn(e),P.add(e));},d=(e,o)=>{let t=`(?<!(?:${R.join("|")})\\S*)`;return A.reduce((s,n)=>s.replace(new RegExp(`${t}:${n}`,"g"),`.pseudo-${n}${o?"-all":""}`),e)},m=(e,o,t)=>{let{states:s,withoutPseudoStates:n}=U(e);if(s.length===0&&!t)return e;let r=`${t??""}${s.map(c=>`.pseudo-${c}-all`).join("")}`;return n=n.replace(":host-context(*)","").trimStart(),n.startsWith(":host-context(")?n.replace(new RegExp("(?<=:host-context\\(\\S+)\\)"),`)${r}`):o?`:host(${r}) ${n}`:`${r} ${n}`},U=e=>{let o=new Set,t=e.replace(j,(s,n)=>(o.add(n),"")).replaceAll("()","(*)").replace(new RegExp("(?<=[\\s(]),\\s+|(,\\s+)+(?=\\))","g"),"")||"*";return {states:Array.from(o),withoutPseudoStates:t}},_=(e,o)=>[...e.matchAll(/:not\(([^)]+)\)/g)].reduce((t,s)=>{let n=s[0],r=s[1],c=q(r,o);return t.replace(n,c)},e),q=(e,o)=>{let t=[];for(let s of e.split(/,\s*/))t.push(m(s,o));return `:not(${t.join(", ")})`},v=({cssText:e,selectorText:o},t)=>e.replace(o,y(o).flatMap(s=>{if(s.includes(".pseudo-"))return [];let n=[s];if(!h.test(s))return n;let r=d(s);r!==s&&n.push(r);let c="";if(s.startsWith(":host(")){let a=s.match(/^:host\((\S+)\)\s+(.+)$/);if(a&&h.test(a[2])){let l=a[1],i=a[2];l=d(l,!0),i=_(i,!0),c=m(i,!0,l);}else c=d(s,!0);}else {let a=_(s,t);c=m(a,t);}return n.push(c),n}).join(", ")),b=(e,o=!1)=>{try{let s=x(e,1e3,o);return s>=1e3&&w("Reached maximum of 1000 pseudo selectors per sheet, skipping the rest."),s>0}catch(t){return String(t).includes("cssRules")?w(`Can't access cssRules, likely due to CORS restrictions: ${e.href}`):console.error(t,e.href),!1}},x=(e,o,t)=>{let s=0,n=-1;for(let r of e.cssRules){n++;let c=0;if(r.__processed)c=r.__pseudoStatesRewrittenCount;else {if("cssRules"in r&&r.cssRules.length)c=x(r,o-s,t);else {if(!("selectorText"in r))continue;let a=r;if(h.test(a.selectorText)){let l=v(a,t);e.deleteRule(n),e.insertRule(l,n),c=1;}}r.__processed=!0,r.__pseudoStatesRewrittenCount=c;}if(s+=c,s>=o)break}return s};var S=previewApi.addons.getChannel(),f=new Set,C=(e,o)=>{Object.values(u).forEach(t=>{e.classList.remove(`pseudo-${t}`),e.classList.remove(`pseudo-${t}-all`);}),o.forEach(t=>e.classList.add(t));};function E(e,o){let t=[];return e.querySelectorAll("*").forEach(s=>{s.shadowRoot&&t.push(...E(s.shadowRoot,o));}),t.push(...e.querySelectorAll(o).values()),t}var K=(e,o={})=>{let t=new Map([[e,new Set]]),s=(n,r)=>t.set(n,new Set([...t.get(n)||[],r]));Object.entries(o||{}).forEach(([n,r])=>{typeof r=="boolean"?r&&s(e,`${n}-all`):typeof r=="string"?E(e,r).forEach(c=>s(c,n)):Array.isArray(r)&&r.forEach(c=>E(e,c).forEach(a=>s(a,n)));}),t.forEach((n,r)=>{let c=new Set;n.forEach(a=>{let l=a.replace("-all","");u[a]?c.add(`pseudo-${u[a]}`):u[l]&&c.add(`pseudo-${u[l]}-all`);}),C(r,c);});},D=e=>{let o=new Set;e.className.split(" ").filter(t=>t.match(/^pseudo-(.(?!-all))+$/)).forEach(t=>o.add(t));for(let t=e.parentNode;t;){if(t instanceof ShadowRoot){t=t.host;continue}if(t instanceof Element){let s=t;s.className&&s.className.split(" ").filter(n=>n.match(/^pseudo-.+-all$/)!==null).forEach(n=>o.add(n));}t=t.parentNode;}C(e,o);},$=e=>{let{rootSelector:o,...t}=e||{};return t},X=(e={},o={})=>e!==null&&o!==null&&Object.keys(e).length===Object.keys(o).length&&Object.keys(e).every(t=>JSON.stringify(e[t])===JSON.stringify(o[t])),N=(e,{viewMode:o,parameters:t,id:s,globals:n})=>{let{pseudo:r}=t,{pseudo:c}=n,{rootSelector:a}=r||{},l=previewApi.useMemo(()=>a?document.querySelector(a):o==="docs"?document.getElementById(`story--${s}`):document.getElementById("storybook-root")||document.getElementById("root"),[a,o,s]);return previewApi.useEffect(()=>{let i=$(r);o==="story"&&!X(i,c)&&S.emit(coreEvents.UPDATE_GLOBALS,{globals:{pseudo:i}});},[r,o]),previewApi.useEffect(()=>{if(!l)return;let i=setTimeout(()=>{K(l,c||$(r)),f.forEach(D);},0);return ()=>clearTimeout(i)},[l,c,r]),e()},p=e=>{let o=Array.from(e?e.styleSheets:document.styleSheets);e?.adoptedStyleSheets?.length&&(o=e.adoptedStyleSheets),o.forEach(t=>b(t,!!e)),e&&f&&f.add(e.host);};S.on(coreEvents.STORY_CHANGED,()=>f.clear());S.on(coreEvents.STORY_RENDERED,()=>p());S.on(coreEvents.GLOBALS_UPDATED,()=>p());S.on(coreEvents.FORCE_RE_RENDER,()=>p());S.on(coreEvents.FORCE_REMOUNT,()=>p());S.on(coreEvents.DOCS_RENDERED,()=>p());Element.prototype.attachShadow&&(Element.prototype._attachShadow=Element.prototype.attachShadow,Element.prototype.attachShadow=function(o){let t=this._attachShadow({...o,mode:"open"});return requestAnimationFrame(()=>{p(t),f.has(t.host)&&D(t.host);}),t});var ue=[N],Se={[g]:!1};
7
7
 
8
8
  exports.decorators = ue;
9
- exports.globals = Se;
9
+ exports.initialGlobals = Se;
package/dist/preview.mjs CHANGED
@@ -3,4 +3,4 @@ import { addons, useMemo, useEffect } from 'storybook/internal/preview-api';
3
3
 
4
4
  var g="pseudo",R=["::-(webkit|moz|ms)-[a-z-]+","::part\\([^)]+\\)"],u={hover:"hover",active:"active",focusVisible:"focus-visible",focusWithin:"focus-within",focus:"focus",visited:"visited",link:"link",target:"target"};var k=e=>e.indexOf("@")===0,y=e=>{if(k(e))return [e];let o=[],t=0,s=0,n="";for(let r=0,c=e.length;r<c;r++){let a=e[r];if(a==="(")t+=1;else if(a===")")t-=1;else if(a==="[")s+=1;else if(a==="]")s-=1;else if(a===","&&!t&&!s){o.push(n.trim()),n="";continue}n+=a;}return o.push(n.trim()),o};var A=Object.values(u),O=`:(${A.join("|")})`,h=new RegExp(O),j=new RegExp(O,"g"),P=new Set,w=e=>{P.has(e)||(console.warn(e),P.add(e));},d=(e,o)=>{let t=`(?<!(?:${R.join("|")})\\S*)`;return A.reduce((s,n)=>s.replace(new RegExp(`${t}:${n}`,"g"),`.pseudo-${n}${o?"-all":""}`),e)},m=(e,o,t)=>{let{states:s,withoutPseudoStates:n}=U(e);if(s.length===0&&!t)return e;let r=`${t??""}${s.map(c=>`.pseudo-${c}-all`).join("")}`;return n=n.replace(":host-context(*)","").trimStart(),n.startsWith(":host-context(")?n.replace(new RegExp("(?<=:host-context\\(\\S+)\\)"),`)${r}`):o?`:host(${r}) ${n}`:`${r} ${n}`},U=e=>{let o=new Set,t=e.replace(j,(s,n)=>(o.add(n),"")).replaceAll("()","(*)").replace(new RegExp("(?<=[\\s(]),\\s+|(,\\s+)+(?=\\))","g"),"")||"*";return {states:Array.from(o),withoutPseudoStates:t}},_=(e,o)=>[...e.matchAll(/:not\(([^)]+)\)/g)].reduce((t,s)=>{let n=s[0],r=s[1],c=q(r,o);return t.replace(n,c)},e),q=(e,o)=>{let t=[];for(let s of e.split(/,\s*/))t.push(m(s,o));return `:not(${t.join(", ")})`},v=({cssText:e,selectorText:o},t)=>e.replace(o,y(o).flatMap(s=>{if(s.includes(".pseudo-"))return [];let n=[s];if(!h.test(s))return n;let r=d(s);r!==s&&n.push(r);let c="";if(s.startsWith(":host(")){let a=s.match(/^:host\((\S+)\)\s+(.+)$/);if(a&&h.test(a[2])){let l=a[1],i=a[2];l=d(l,!0),i=_(i,!0),c=m(i,!0,l);}else c=d(s,!0);}else {let a=_(s,t);c=m(a,t);}return n.push(c),n}).join(", ")),b=(e,o=!1)=>{try{let s=x(e,1e3,o);return s>=1e3&&w("Reached maximum of 1000 pseudo selectors per sheet, skipping the rest."),s>0}catch(t){return String(t).includes("cssRules")?w(`Can't access cssRules, likely due to CORS restrictions: ${e.href}`):console.error(t,e.href),!1}},x=(e,o,t)=>{let s=0,n=-1;for(let r of e.cssRules){n++;let c=0;if(r.__processed)c=r.__pseudoStatesRewrittenCount;else {if("cssRules"in r&&r.cssRules.length)c=x(r,o-s,t);else {if(!("selectorText"in r))continue;let a=r;if(h.test(a.selectorText)){let l=v(a,t);e.deleteRule(n),e.insertRule(l,n),c=1;}}r.__processed=!0,r.__pseudoStatesRewrittenCount=c;}if(s+=c,s>=o)break}return s};var S=addons.getChannel(),f=new Set,C=(e,o)=>{Object.values(u).forEach(t=>{e.classList.remove(`pseudo-${t}`),e.classList.remove(`pseudo-${t}-all`);}),o.forEach(t=>e.classList.add(t));};function E(e,o){let t=[];return e.querySelectorAll("*").forEach(s=>{s.shadowRoot&&t.push(...E(s.shadowRoot,o));}),t.push(...e.querySelectorAll(o).values()),t}var K=(e,o={})=>{let t=new Map([[e,new Set]]),s=(n,r)=>t.set(n,new Set([...t.get(n)||[],r]));Object.entries(o||{}).forEach(([n,r])=>{typeof r=="boolean"?r&&s(e,`${n}-all`):typeof r=="string"?E(e,r).forEach(c=>s(c,n)):Array.isArray(r)&&r.forEach(c=>E(e,c).forEach(a=>s(a,n)));}),t.forEach((n,r)=>{let c=new Set;n.forEach(a=>{let l=a.replace("-all","");u[a]?c.add(`pseudo-${u[a]}`):u[l]&&c.add(`pseudo-${u[l]}-all`);}),C(r,c);});},D=e=>{let o=new Set;e.className.split(" ").filter(t=>t.match(/^pseudo-(.(?!-all))+$/)).forEach(t=>o.add(t));for(let t=e.parentNode;t;){if(t instanceof ShadowRoot){t=t.host;continue}if(t instanceof Element){let s=t;s.className&&s.className.split(" ").filter(n=>n.match(/^pseudo-.+-all$/)!==null).forEach(n=>o.add(n));}t=t.parentNode;}C(e,o);},$=e=>{let{rootSelector:o,...t}=e||{};return t},X=(e={},o={})=>e!==null&&o!==null&&Object.keys(e).length===Object.keys(o).length&&Object.keys(e).every(t=>JSON.stringify(e[t])===JSON.stringify(o[t])),N=(e,{viewMode:o,parameters:t,id:s,globals:n})=>{let{pseudo:r}=t,{pseudo:c}=n,{rootSelector:a}=r||{},l=useMemo(()=>a?document.querySelector(a):o==="docs"?document.getElementById(`story--${s}`):document.getElementById("storybook-root")||document.getElementById("root"),[a,o,s]);return useEffect(()=>{let i=$(r);o==="story"&&!X(i,c)&&S.emit(UPDATE_GLOBALS,{globals:{pseudo:i}});},[r,o]),useEffect(()=>{if(!l)return;let i=setTimeout(()=>{K(l,c||$(r)),f.forEach(D);},0);return ()=>clearTimeout(i)},[l,c,r]),e()},p=e=>{let o=Array.from(e?e.styleSheets:document.styleSheets);e?.adoptedStyleSheets?.length&&(o=e.adoptedStyleSheets),o.forEach(t=>b(t,!!e)),e&&f&&f.add(e.host);};S.on(STORY_CHANGED,()=>f.clear());S.on(STORY_RENDERED,()=>p());S.on(GLOBALS_UPDATED,()=>p());S.on(FORCE_RE_RENDER,()=>p());S.on(FORCE_REMOUNT,()=>p());S.on(DOCS_RENDERED,()=>p());Element.prototype.attachShadow&&(Element.prototype._attachShadow=Element.prototype.attachShadow,Element.prototype.attachShadow=function(o){let t=this._attachShadow({...o,mode:"open"});return requestAnimationFrame(()=>{p(t),f.has(t.host)&&D(t.host);}),t});var ue=[N],Se={[g]:!1};
5
5
 
6
- export { ue as decorators, Se as globals };
6
+ export { ue as decorators, Se as initialGlobals };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-pseudo-states",
3
- "version": "4.0.0--canary.124.4a85ada.0",
3
+ "version": "4.0.0--canary.124.92df327.0",
4
4
  "description": "CSS pseudo states for Storybook",
5
5
  "keywords": [
6
6
  "storybook-addons",