@kaptures/storybook 0.11.1 → 0.12.1

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/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{PLAY_FUNCTION_THREW_EXCEPTION as e,STORY_FINISHED as t,STORY_RENDER_PHASE_CHANGED as n,UNHANDLED_ERRORS_WHILE_PLAYING as r}from"storybook/internal/core-events";import{definePreviewAddon as i}from"storybook/internal/csf";import{addons as a}from"storybook/preview-api";function o(e){let t=h(e,`parameters`);return E({captureEnabled:y(t.captureEnabled,`captureEnabled`),captureViewports:s(t.captureViewports),captureArea:c(t.captureArea),captureDelayMs:S(t.captureDelayMs,`captureDelayMs`),waitForElement:u(t.waitForElement),animationState:d(t.animationState),maskSelectors:m(t.maskSelectors,`maskSelectors`),diffIgnoreSelectors:m(t.diffIgnoreSelectors,`diffIgnoreSelectors`),waitForFonts:y(t.waitForFonts,`waitForFonts`),fontAssertions:t.fontAssertions===void 0?void 0:g(t.fontAssertions,`fontAssertions`).map((e,t)=>f(e,`fontAssertions[${t}]`)),diff:p(t.diff)})}function s(e){if(e===void 0)return;let t=g(e,`captureViewports`);if(t.length===0)throw Error(`Kapture captureViewports must contain at least one viewport; use captureEnabled: false to skip`);return t.map((e,t)=>l(e,`captureViewports[${t}]`))}function c(e){if(e===void 0||e===`full-page`||e===`viewport`)return e;throw Error(`Invalid Kapture captureArea: ${String(e)}`)}function l(e,t){let n=h(e,t);return{name:_(n.name,`${t}.name`),width:C(n.width,`${t}.width`),height:C(n.height,`${t}.height`)}}function u(e){if(e===void 0)return;let t=h(e,`waitForElement`),n=t.state;if(n!==void 0&&n!==`attached`&&n!==`visible`&&n!==`hidden`&&n!==`detached`)throw Error(`Invalid Kapture waitForElement state: ${String(n)}`);return E({selector:_(t.selector,`waitForElement.selector`),state:n,timeoutMs:S(t.timeoutMs,`waitForElement.timeoutMs`)})}function d(e){if(e!==void 0)return e===`disabled`||e===`start`||e===`end`?e:{atMs:x(h(e,`animationState`).atMs,`animationState.atMs`)}}function f(e,t){let n=h(e,t),r=n.weight;if(r!==void 0&&typeof r!=`string`&&typeof r!=`number`)throw Error(`${t}.weight must be a string or number`);return E({family:_(n.family,`${t}.family`),glyphs:_(n.glyphs,`${t}.glyphs`),style:v(n.style,`${t}.style`),weight:r})}function p(e){if(e===void 0)return;let t=h(e,`diff`);if(`maxChangedPixelRatio`in t)throw Error(`Kapture diff.maxChangedPixelRatio is not supported; use diff.maxChangedPixelPercentage with a value between 0 and 100`);return E({pixelColorThreshold:w(t.pixelColorThreshold,`diff.pixelColorThreshold`),maxChangedPixelPercentage:T(t.maxChangedPixelPercentage,`diff.maxChangedPixelPercentage`)})}function m(e,t){if(e!==void 0)return g(e,t).map((e,n)=>_(e,`${t}[${n}]`))}function h(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Kapture ${t} must be an object`);return e}function g(e,t){if(!Array.isArray(e))throw Error(`Kapture ${t} must be an array`);return e}function _(e,t){if(typeof e!=`string`||!e.trim())throw Error(`Kapture ${t} must be a non-empty string`);return e}function v(e,t){return e===void 0?void 0:_(e,t)}function y(e,t){if(e!==void 0){if(typeof e!=`boolean`)throw Error(`Kapture ${t} must be a boolean`);return e}}function b(e,t){if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Kapture ${t} must be a finite number`);return e}}function x(e,t){let n=b(e,t);if(n===void 0||n<0)throw Error(`Kapture ${t} must be a non-negative number`);return n}function S(e,t){return e===void 0?void 0:x(e,t)}function C(e,t){let n=b(e,t);if(n===void 0||n<=0)throw Error(`Kapture ${t} must be positive`);return n}function w(e,t){if(e===void 0)return;let n=x(e,t);if(n>1)throw Error(`Kapture ${t} must be between 0 and 1`);return n}function T(e,t){if(e===void 0)return;let n=x(e,t);if(n>100)throw Error(`Kapture ${t} must be between 0 and 100`);return n}function E(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}var D=`0.11.1`;const O={set:e=>setTimeout(e,0),clear:e=>clearTimeout(e)};function k(e,t,n=O){let r=0,i,a,o=new Map,s=[],c=()=>{a!==void 0&&n.clear(a),a=void 0},l=()=>{if(!i)return;let{configurationError:n,storybookError:r,...a}=i;t({protocolVersion:4,adapterVersion:e,state:`rendering`,...a})},u=(e,t)=>{let n={storyId:e,generation:++r,renderId:t};return o.set(n.generation,n),i=n,n},d=(r,o)=>{c(),a=n.set(()=>{if(a=void 0,!(!i||i.generation!==r.generation)&&!(r.configurationError||r.storybookError)){if(o===`error`){t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,error:{kind:`storybook`,message:`Storybook failed while rendering, playing, or finishing this story.`}});return}if(r.renderId===void 0||r.parameters===void 0){t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,error:{kind:`configuration`,message:`Kapture did not receive resolved story parameters before Storybook finished.`}});return}t({protocolVersion:4,adapterVersion:e,state:`ready`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,parameters:r.parameters})}})};return{boot(){c(),r=0,i=void 0,o.clear(),s.length=0,t({protocolVersion:4,adapterVersion:e,state:`booting`})},startStory(e,t){return c(),(!i||i.storyId!==e||i.parameters!==void 0||i.configurationError!==void 0||i.storybookError!==void 0)&&u(e),i.parameters=t,l(),i.generation},completeStory(e,t){let n=o.get(t);!n||n.storyId!==e||n.configurationError||n.storybookError||s.includes(t)||s.push(t)},failConfiguration(n,r){c(),(!i||i.storyId!==n||i.parameters!==void 0)&&u(n),i.configurationError=r.message,t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:n,generation:i.generation,renderId:i.renderId,error:{kind:`configuration`,message:r.message}})},failStorybook(n){c(),i&&(i.storybookError=n.message,t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:i.storyId,generation:i.generation,renderId:i.renderId,error:{kind:`storybook`,message:n.message}}))},handlePhase(e){if(e.newPhase===`loading`){c(),u(e.storyId,e.renderId),l();return}i?.storyId===e.storyId&&(i.renderId=e.renderId)},handleFinished(e){let t=s.findIndex(t=>o.get(t)?.storyId===e.storyId),n=t<0?void 0:s.splice(t,1)[0],r=n===void 0?i:o.get(n);!r||r.storyId!==e.storyId||r.configurationError||r.storybookError||(e.status!==`success`||n!==void 0)&&d(r,e.status)},dispose(){c(),i=void 0,o.clear(),s.length=0}}}function A(e,t){try{let e=P(t,`Storybook parameters`),n=e.kapture===void 0?{}:P(e.kapture,`parameters.kapture`),r=n.captureViewports?.map((t,n)=>typeof t==`string`?j(t,e.viewport):M(t,n));return o({captureEnabled:n.captureEnabled,captureViewports:r,captureArea:n.captureArea,captureDelayMs:n.captureDelayMs,waitForElement:n.waitForElement,animationState:n.animationState,maskSelectors:n.maskSelectors,diffIgnoreSelectors:n.diffIgnoreSelectors,waitForFonts:n.waitForFonts,fontAssertions:n.fontAssertions,diff:n.diff})}catch(t){let n=t instanceof Error?t.message:String(t);throw Error(`Kapture story ${e}: ${n}`,{cause:t})}}function j(e,t){if(!e.trim())throw Error(`captureViewports entries must not be empty`);let n=P(P(P(t,`parameters.viewport`).options,`parameters.viewport.options`)[e],`viewport option ${e}`);return{name:e,width:N(n.styles?.width,`${e}.styles.width`),height:N(n.styles?.height,`${e}.styles.height`)}}function M(e,t){if(typeof e!=`object`||!e)throw Error(`captureViewports[${t}] must be a viewport name or object`);return{name:e.name,width:e.width,height:e.height}}function N(e,t){if(typeof e!=`string`)throw Error(`${t} must be an exact pixel dimension`);let n=/^(\d+)px$/.exec(e.trim());if(!n?.[1])throw Error(`${t} must use an exact pixel dimension such as 360px`);let r=Number(n[1]);if(r<=0)throw Error(`${t} must be positive`);return r}function P(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be an object`);return e}function F(e){globalThis.__KAPTURE_STORYBOOK__=e}function I(){let o=k(D,F),s=new WeakMap;return i({beforeAll(){o.boot();let i=a.getChannel(),s=e=>o.handlePhase(e),c=e=>o.handleFinished(e),l=e=>o.failStorybook(L(e));return i.on(n,s),i.on(t,c),i.on(e,l),i.on(r,l),()=>{i.off(n,s),i.off(t,c),i.off(e,l),i.off(r,l),o.dispose()}},beforeEach(e){try{let t=o.startStory(e.id,A(e.id,e.parameters));s.set(e,t)}catch(t){let n=t instanceof Error?t:Error(String(t));throw o.failConfiguration(e.id,n),n}},afterEach(e){let t=s.get(e);t!==void 0&&o.completeStory(e.id,t)}})}function L(e){let t=Array.isArray(e)?e[0]:e;if(typeof t==`object`&&t&&`message`in t){let e=t.message;if(typeof e==`string`&&e.trim())return Error(`Storybook play function failed: ${e}`)}return Error(`Storybook play function failed.`)}const R=I;var z=I;export{z as default,R as kapture};
1
+ import{PLAY_FUNCTION_THREW_EXCEPTION as e,STORY_FINISHED as t,STORY_RENDER_PHASE_CHANGED as n,UNHANDLED_ERRORS_WHILE_PLAYING as r}from"storybook/internal/core-events";import{definePreviewAddon as i}from"storybook/internal/csf";import{addons as a}from"storybook/preview-api";function o(e){let t=h(e,`parameters`);return E({captureEnabled:y(t.captureEnabled,`captureEnabled`),captureViewports:s(t.captureViewports),captureArea:c(t.captureArea),captureDelayMs:S(t.captureDelayMs,`captureDelayMs`),waitForElement:u(t.waitForElement),animationState:d(t.animationState),maskSelectors:m(t.maskSelectors,`maskSelectors`),diffIgnoreSelectors:m(t.diffIgnoreSelectors,`diffIgnoreSelectors`),waitForFonts:y(t.waitForFonts,`waitForFonts`),fontAssertions:t.fontAssertions===void 0?void 0:g(t.fontAssertions,`fontAssertions`).map((e,t)=>f(e,`fontAssertions[${t}]`)),diff:p(t.diff)})}function s(e){if(e===void 0)return;let t=g(e,`captureViewports`);if(t.length===0)throw Error(`Kapture captureViewports must contain at least one viewport; use captureEnabled: false to skip`);return t.map((e,t)=>l(e,`captureViewports[${t}]`))}function c(e){if(e===void 0||e===`full-page`||e===`viewport`)return e;throw Error(`Invalid Kapture captureArea: ${String(e)}`)}function l(e,t){let n=h(e,t);return{name:_(n.name,`${t}.name`),width:C(n.width,`${t}.width`),height:C(n.height,`${t}.height`)}}function u(e){if(e===void 0)return;let t=h(e,`waitForElement`),n=t.state;if(n!==void 0&&n!==`attached`&&n!==`visible`&&n!==`hidden`&&n!==`detached`)throw Error(`Invalid Kapture waitForElement state: ${String(n)}`);return E({selector:_(t.selector,`waitForElement.selector`),state:n,timeoutMs:S(t.timeoutMs,`waitForElement.timeoutMs`)})}function d(e){if(e!==void 0)return e===`disabled`||e===`start`||e===`end`?e:{atMs:x(h(e,`animationState`).atMs,`animationState.atMs`)}}function f(e,t){let n=h(e,t),r=n.weight;if(r!==void 0&&typeof r!=`string`&&typeof r!=`number`)throw Error(`${t}.weight must be a string or number`);return E({family:_(n.family,`${t}.family`),glyphs:_(n.glyphs,`${t}.glyphs`),style:v(n.style,`${t}.style`),weight:r})}function p(e){if(e===void 0)return;let t=h(e,`diff`);if(`maxChangedPixelRatio`in t)throw Error(`Kapture diff.maxChangedPixelRatio is not supported; use diff.maxChangedPixelPercentage with a value between 0 and 100`);return E({pixelColorThreshold:w(t.pixelColorThreshold,`diff.pixelColorThreshold`),maxChangedPixelPercentage:T(t.maxChangedPixelPercentage,`diff.maxChangedPixelPercentage`)})}function m(e,t){if(e!==void 0)return g(e,t).map((e,n)=>_(e,`${t}[${n}]`))}function h(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Kapture ${t} must be an object`);return e}function g(e,t){if(!Array.isArray(e))throw Error(`Kapture ${t} must be an array`);return e}function _(e,t){if(typeof e!=`string`||!e.trim())throw Error(`Kapture ${t} must be a non-empty string`);return e}function v(e,t){return e===void 0?void 0:_(e,t)}function y(e,t){if(e!==void 0){if(typeof e!=`boolean`)throw Error(`Kapture ${t} must be a boolean`);return e}}function b(e,t){if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Kapture ${t} must be a finite number`);return e}}function x(e,t){let n=b(e,t);if(n===void 0||n<0)throw Error(`Kapture ${t} must be a non-negative number`);return n}function S(e,t){return e===void 0?void 0:x(e,t)}function C(e,t){let n=b(e,t);if(n===void 0||n<=0)throw Error(`Kapture ${t} must be positive`);return n}function w(e,t){if(e===void 0)return;let n=x(e,t);if(n>1)throw Error(`Kapture ${t} must be between 0 and 1`);return n}function T(e,t){if(e===void 0)return;let n=x(e,t);if(n>100)throw Error(`Kapture ${t} must be between 0 and 100`);return n}function E(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}var D=`0.12.1`;const O={set:e=>setTimeout(e,0),clear:e=>clearTimeout(e)};function k(e,t,n=O){let r=0,i,a,o=new Map,s=[],c=()=>{a!==void 0&&n.clear(a),a=void 0},l=()=>{if(!i)return;let{configurationError:n,storybookError:r,...a}=i;t({protocolVersion:4,adapterVersion:e,state:`rendering`,...a})},u=(e,t)=>{let n={storyId:e,generation:++r,renderId:t};return o.set(n.generation,n),i=n,n},d=(r,o)=>{c(),a=n.set(()=>{if(a=void 0,!(!i||i.generation!==r.generation)&&!(r.configurationError||r.storybookError)){if(o===`error`){t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,error:{kind:`storybook`,message:`Storybook failed while rendering, playing, or finishing this story.`}});return}if(r.renderId===void 0||r.parameters===void 0){t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,error:{kind:`configuration`,message:`Kapture did not receive resolved story parameters before Storybook finished.`}});return}t({protocolVersion:4,adapterVersion:e,state:`ready`,storyId:r.storyId,generation:r.generation,renderId:r.renderId,parameters:r.parameters})}})};return{boot(){c(),r=0,i=void 0,o.clear(),s.length=0,t({protocolVersion:4,adapterVersion:e,state:`booting`})},startStory(e,t){return c(),(!i||i.storyId!==e||i.parameters!==void 0||i.configurationError!==void 0||i.storybookError!==void 0)&&u(e),i.parameters=t,l(),i.generation},completeStory(e,t){let n=o.get(t);!n||n.storyId!==e||n.configurationError||n.storybookError||s.includes(t)||s.push(t)},failConfiguration(n,r){c(),(!i||i.storyId!==n||i.parameters!==void 0)&&u(n),i.configurationError=r.message,t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:n,generation:i.generation,renderId:i.renderId,error:{kind:`configuration`,message:r.message}})},failStorybook(n){c(),i&&(i.storybookError=n.message,t({protocolVersion:4,adapterVersion:e,state:`error`,storyId:i.storyId,generation:i.generation,renderId:i.renderId,error:{kind:`storybook`,message:n.message}}))},handlePhase(e){if(e.newPhase===`loading`){c(),u(e.storyId,e.renderId),l();return}i?.storyId===e.storyId&&(i.renderId=e.renderId)},handleFinished(e){let t=s.findIndex(t=>o.get(t)?.storyId===e.storyId),n=t<0?void 0:s.splice(t,1)[0],r=n===void 0?i:o.get(n);!r||r.storyId!==e.storyId||r.configurationError||r.storybookError||(e.status!==`success`||n!==void 0)&&d(r,e.status)},dispose(){c(),i=void 0,o.clear(),s.length=0}}}function A(e,t){try{let e=P(t,`Storybook parameters`),n=e.kapture===void 0?{}:P(e.kapture,`parameters.kapture`),r=n.captureViewports?.map((t,n)=>typeof t==`string`?j(t,e.viewport):M(t,n));return o({captureEnabled:n.captureEnabled,captureViewports:r,captureArea:n.captureArea,captureDelayMs:n.captureDelayMs,waitForElement:n.waitForElement,animationState:n.animationState,maskSelectors:n.maskSelectors,diffIgnoreSelectors:n.diffIgnoreSelectors,waitForFonts:n.waitForFonts,fontAssertions:n.fontAssertions,diff:n.diff})}catch(t){let n=t instanceof Error?t.message:String(t);throw Error(`Kapture story ${e}: ${n}`,{cause:t})}}function j(e,t){if(!e.trim())throw Error(`captureViewports entries must not be empty`);let n=P(P(P(t,`parameters.viewport`).options,`parameters.viewport.options`)[e],`viewport option ${e}`);return{name:e,width:N(n.styles?.width,`${e}.styles.width`),height:N(n.styles?.height,`${e}.styles.height`)}}function M(e,t){if(typeof e!=`object`||!e)throw Error(`captureViewports[${t}] must be a viewport name or object`);return{name:e.name,width:e.width,height:e.height}}function N(e,t){if(typeof e!=`string`)throw Error(`${t} must be an exact pixel dimension`);let n=/^(\d+)px$/.exec(e.trim());if(!n?.[1])throw Error(`${t} must use an exact pixel dimension such as 360px`);let r=Number(n[1]);if(r<=0)throw Error(`${t} must be positive`);return r}function P(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be an object`);return e}function F(e){globalThis.__KAPTURE_STORYBOOK__=e}function I(){let o=k(D,F),s=new WeakMap;return i({beforeAll(){o.boot();let i=a.getChannel(),s=e=>o.handlePhase(e),c=e=>o.handleFinished(e),l=e=>o.failStorybook(L(e));return i.on(n,s),i.on(t,c),i.on(e,l),i.on(r,l),()=>{i.off(n,s),i.off(t,c),i.off(e,l),i.off(r,l),o.dispose()}},beforeEach(e){try{let t=o.startStory(e.id,A(e.id,e.parameters));s.set(e,t)}catch(t){let n=t instanceof Error?t:Error(String(t));throw o.failConfiguration(e.id,n),n}},afterEach(e){let t=s.get(e);t!==void 0&&o.completeStory(e.id,t)}})}function L(e){let t=Array.isArray(e)?e[0]:e;if(typeof t==`object`&&t&&`message`in t){let e=t.message;if(typeof e==`string`&&e.trim())return Error(`Storybook play function failed: ${e}`)}return Error(`Storybook play function failed.`)}const R=I;var z=I;export{z as default,R as kapture};
package/dist/preset.d.ts CHANGED
@@ -28,9 +28,9 @@ interface KaptureDependencyManifestV1 {
28
28
  }>;
29
29
  /** Directory prefixes whose complete file set must match outputInventory. */
30
30
  outputInventoryPrefixes: string[];
31
- /** Imported export names for direct project-module edges. `*` means conservative traversal. */
31
+ /** Legacy v1 field; always empty. Selection uses emitted module closures. */
32
32
  importBindings: Record<string, Record<string, string[]>>;
33
- /** Export provenance for syntax-proven import-and-export-only barrel modules. */
33
+ /** Legacy v1 field; always empty. */
34
34
  reexportBindings: Record<string, Record<string, {
35
35
  module: string;
36
36
  imported: string;
package/dist/preset.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createHash as e}from"node:crypto";import{lstatSync as t,readFileSync as n,readdirSync as r,writeFileSync as i}from"node:fs";import{dirname as a,isAbsolute as o,matchesGlob as s,posix as c,relative as l,resolve as u,sep as d}from"node:path";import{fileURLToPath as f}from"node:url";const p=`kapture-dependencies.json`,m=[`\0`,`virtual:`,`/@id/`,`vite:`];function h({projectRoot:e,storybookRoot:t,globalInputs:n,ignoredInputs:r,fingerprintedInputs:i=[],containerModuleIds:a=[],modules:o}){let s=u(e),c=new Map,l=new Map,d=new Map,f=new Set,p=new Set(a);for(let e of o){let t=c.get(e.id)??new Set;for(let n of[...e.importedIds??[],...e.dynamicallyImportedIds??[]])t.add(n);if(c.set(e.id,t),l.set(e.id,e),typeof e.code==`string`||e.sourceFingerprint){let t=d.get(e.id)??new Set;t.add(U(JSON.stringify({transformedCode:typeof e.code==`string`?U(W(e.code,s)):null,sourceFingerprint:e.sourceFingerprint??null}))),d.set(e.id,t)}}let m=new Map;for(let e of c.keys()){let t=J(e,s);if(t.kind===`project`){let n=m.get(t.path)??new Set;n.add(e),m.set(t.path,n)}else t.kind===`outside`&&!p.has(e)&&f.add(`module-outside-project-root`)}let h={},g={};for(let[e,t]of[...m].sort(([e],[t])=>e.localeCompare(t))){let n=new Set([e]),r=new Set,a=[...t].flatMap(e=>[...c.get(e)??[]]);for(;a.length>0;){let e=a.pop();if(!e)continue;let t=J(e,s);if(t.kind===`project`){n.add(t.path),m.has(t.path)||f.add(`unresolved-project-module`);continue}if(t.kind===`outside`&&!p.has(e)&&f.add(`module-outside-project-root`),Ie(e)&&c.has(e)&&f.add(`unresolved-virtual-module`),!(!X(e)||!c.has(e)||r.has(e))){r.add(e);for(let t of c.get(e)??[])a.push(t)}}h[e]=[...n].sort();let o=Fe(t,c),l=[...t,...o],u=l.flatMap(e=>[...d.get(e)??[]]);l.every(e=>(d.get(e)?.size??0)>0)?g[e]=U(JSON.stringify([...new Set(u)].sort())):(i.length>0&&f.add(`module-fingerprint-missing`),[...o].some(e=>(d.get(e)?.size??0)===0)&&f.add(`unresolved-virtual-module`))}let _=q(t,`storybookRoot`,!0),v=K(n,`globalInputs`),y=Te({projectRoot:s,modulesById:l,dependencyGraph:h});return{kind:`kapture-storybook-dependencies`,version:1,complete:f.size===0,storybookRoot:_,globalInputs:Me(v,h),ignoredInputs:K(r,`ignoredInputs`),fingerprintedInputs:K(i,`fingerprintedInputs`),diagnostics:[...f].sort(),modules:h,moduleFingerprints:g,globalOutputFingerprints:{},globalOutputStories:{},outputInventory:{},outputInventoryPrefixes:[],importBindings:y.importBindings,reexportBindings:y.reexportBindings,renderedOutputFingerprints:{}}}function g(e){return Object.fromEntries([...b({...e,requireContainerEvidence:!1}).entries].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t.modules].sort()]))}function _(e){let t=b({...e,requireContainerEvidence:!0}),n=new Set(t.diagnostics),r={},i={};for(let[e,a]of[...t.entries].sort(([e],[t])=>e.localeCompare(t))){r[e]=[...a.modules].sort();let o=[],s=a.chunks.size>0;for(let e of[...a.chunks].sort()){let n=t.chunkFingerprints.get(e);if(!n){s=!1;continue}o.push(n)}s?i[e]=U(JSON.stringify(o.sort())):n.add(`rendered-output-fingerprint-missing`)}let a=Se(t),o={},s={};for(let t of Object.values(e.bundle).sort((e,t)=>e.fileName.localeCompare(t.fileName))){if(t.type!==`asset`||!V(t.fileName))continue;let e=q(t.fileName,`bundle asset`,!1);if(s[e]=[...a.get(e)??[]].sort(),typeof t.source!=`string`&&!(t.source instanceof Uint8Array)){n.add(`global-output-fingerprint-missing`);continue}o[e]=U(t.source)}return{renderedModules:r,renderedOutputFingerprints:i,globalOutputFingerprints:o,globalOutputStories:s,...t.globalRuntimeFingerprint?{globalRuntimeFingerprint:t.globalRuntimeFingerprint}:{},containerModuleIds:[...t.containerModuleIds].sort(),diagnostics:[...n].sort()}}function v(e,t){if(t)return y(e,t);let n={};for(let t of Object.values(e).sort((e,t)=>e.fileName.localeCompare(t.fileName))){let e=q(t.fileName,`bundle output`,!1);if(e===`kapture-dependencies.json`)continue;let r=we(t);r&&(n[e]={type:t.type,size:r.byteLength,sha256:U(r)})}return{outputInventory:n,outputInventoryPrefixes:[...new Set(Object.keys(n).filter(e=>e.includes(`/`)).map(e=>`${e.split(`/`)[0]}/`))].sort()}}function y(e,i){let a=u(i),o=new Map(Object.values(e).map(e=>[q(e.fileName,`bundle output`,!1),e.type])),s={},c=[``],l=0;for(;c.length>0;){let e=c.pop();if(e===void 0)continue;let i=e?u(a,e):a;for(let d of r(i,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){if(l+=1,l>1e5)throw Error(`@kaptures/storybook output inventory contains too many entries`);let r=q(e?`${e}/${d.name}`:d.name,`storybook output`,!1),i=u(a,r),f=t(i);if(f.isSymbolicLink())throw Error(`@kaptures/storybook cannot inventory symbolic link: ${r}`);if(f.isDirectory()){c.push(r);continue}if(!f.isFile())throw Error(`@kaptures/storybook cannot inventory special file: ${r}`);if(r===`kapture-dependencies.json`)continue;let p=n(i);s[r]={type:o.get(r)??`asset`,size:p.byteLength,sha256:U(p)}}}return{outputInventory:Object.fromEntries(Object.entries(s).sort(([e],[t])=>e.localeCompare(t))),outputInventoryPrefixes:Object.keys(s).length>0?[``]:[]}}function b(e){let t=u(e.projectRoot),n=new Map([...e.modules].map(e=>[e.id,e])),r=new Map,i=[],a=new Map,o=new Map,s=new Map,c=new Set,l=new Set,d=new Set;for(let n of Object.values(e.bundle)){let e=q(n.fileName,`bundle output`,!1);if(r.set(e,n),n.type===`chunk`){i.push(n),a.set(e,n),n.facadeModuleId&&H(n.facadeModuleId)&&(c.add(n.facadeModuleId),l.add(e));for(let r of Object.keys(n.modules)){H(r)&&(c.add(r),l.add(e));let n=o.get(r)??new Set;n.add(e),o.set(r,n);let i=J(r,t);if(i.kind!==`project`)continue;let a=s.get(i.path)??new Set;a.add(r),s.set(i.path,a)}}}let f=ee(r,a);if(e.requireContainerEvidence)for(let e of f.diagnostics)d.add(e);let p=te({roots:f.chunkRoots,chunksByFileName:a,outputs:r,directStoryChunks:l,diagnostics:d}),m=new Set;for(let e of p){let t=a.get(e),n=t?.facadeModuleId;n&&m.add(n);for(let e of Object.keys(t?.modules??{}))m.add(e)}let h=new Map;for(let[e,i]of[...s].sort(([e],[t])=>e.localeCompare(t))){if(![...i].some(e=>c.has(e)))continue;let s=[...i].flatMap(e=>[...o.get(e)??[]]),l=new Set,u=new Set;for(;s.length>0;){let e=s.pop();if(!e||l.has(e)||p.has(e))continue;l.add(e);let i=a.get(e);if(i){for(let e of x(i,r,d))s.push(e);for(let e of Object.keys(i.modules)){let r=J(e,t);if(r.kind===`project`){u.add(r.path);for(let t of n.get(e)?.dynamicallyImportedIds??[])for(let e of o.get(t)??[])s.push(e)}}}}h.set(e,{modules:u,chunks:l})}let g=new Set(p);for(let e of h.values())for(let t of e.chunks)g.add(t);i.some(e=>!g.has(R(e.fileName)))&&d.add(`unowned-output-chunk`);let _=ne({root:t,chunks:i,outputs:r,containerRootIds:re(f.chunkRoots,a,t)}),v=new Map;for(let n of i){let i=R(n.fileName);if(typeof n.code!=`string`)continue;let a=ae({code:n.code,fromFileName:i,projectRoot:t,outputs:r,logicalOutputIds:_,directStoryChunks:l,parseCode:e.parseCode});if(a===null)continue;let o={output:_.get(i)??i,...a.observesFileName?{fileName:i}:{},code:U(a.code),imports:F(n.imports??[],i,r,_),dynamicImports:F((n.dynamicImports??[]).filter(e=>{let t=I(e,i,r);return!t||!a.storyRegistryChunks.has(t)}),i,r,_),implicitlyLoadedBefore:F(n.implicitlyLoadedBefore??[],i,r,_),referencedFiles:F(n.referencedFiles??[],i,r,_)},s=U(JSON.stringify(o));v.set(i,s)}let y;if(f.source!==null&&f.chunkRoots.size>0){let e=ye(f,r,_),t=[...p].map(e=>v.get(e)).filter(e=>!!e).sort();t.length===p.size&&(y=U(JSON.stringify({html:U(e),chunks:t})))}return e.requireContainerEvidence&&!y&&d.add(`global-runtime-fingerprint-missing`),{root:t,modulesById:n,outputs:r,entries:h,chunks:i,chunkFingerprints:v,containerChunks:p,containerModuleIds:m,...y?{globalRuntimeFingerprint:y}:{},diagnostics:d}}function ee(e,t){let n=new Set,r=e.get(`iframe.html`);if(!r||r.type!==`asset`)return n.add(`global-runtime-fingerprint-missing`),{source:null,chunkRoots:new Set,loadReferences:[],diagnostics:n};let i=B(r);if(i===null)return n.add(`global-runtime-fingerprint-missing`),{source:null,chunkRoots:new Set,loadReferences:[],diagnostics:n};let a=new Set,o=[];for(let r of be(i)){let i=I(r.value,`iframe.html`,e);if(!i){r.requiresBundleTarget&&n.add(`global-runtime-fingerprint-missing`);continue}o.push({start:r.start,end:r.end,target:i}),r.loadsJavaScript&&(t.has(i)?a.add(i):n.add(`global-runtime-fingerprint-missing`))}return a.size===0&&n.add(`global-runtime-fingerprint-missing`),{source:i,chunkRoots:a,loadReferences:o,diagnostics:n}}function te(e){let t=new Set,n=[...e.roots];for(;n.length>0;){let r=n.pop();if(!r||t.has(r))continue;let i=e.chunksByFileName.get(r);if(!i){e.diagnostics.add(`global-runtime-fingerprint-missing`);continue}t.add(r);for(let t of S(i,e.outputs,e.diagnostics))n.push(t);for(let t of i.dynamicImports??[]){let i=I(t,r,e.outputs);i?e.directStoryChunks.has(i)||n.push(i):e.diagnostics.add(`global-runtime-fingerprint-missing`)}}return t}function x(e,t,n){return[...S(e,t,n),...(e.dynamicImports??[]).flatMap(r=>{let i=I(r,e.fileName,t);return i?t.get(i)?.type===`chunk`?[i]:[]:(n.add(`rendered-output-fingerprint-missing`),[])})]}function S(e,t,n){return[...e.imports??[],...e.implicitlyLoadedBefore??[],...e.referencedFiles??[]].flatMap(r=>{let i=I(r,e.fileName,t);return i?t.get(i)?.type===`chunk`?[i]:[]:(n.add(`rendered-output-fingerprint-missing`),[])})}function ne(e){let t=new Map,n=new Map;for(let r of e.chunks){let i=R(r.fileName),a=e.containerRootIds.get(i),o=`chunk:${U(JSON.stringify({facade:a||(r.facadeModuleId?C(r.facadeModuleId,e.root):null),modules:a?[]:Object.keys(r.modules).map(t=>C(t,e.root)).sort()}))}`;t.set(i,o),n.set(o,(n.get(o)??0)+1)}let r=new Map;for(let[e,i]of t)n.get(i)===1&&r.set(e,i);let i=new Map,a=new Map;for(let t of e.chunks){let n=r.get(R(t.fileName));if(n)for(let r of t.viteMetadata?.importedCss??[]){let a=I(r,t.fileName,e.outputs);if(!a||e.outputs.get(a)?.type!==`asset`)continue;let o=i.get(a);i.set(a,o?`${o}\n${n}`:n)}}for(let[e,t]of i){let n=`css:${U(JSON.stringify([...new Set(t.split(`
2
- `))].sort()))}`;i.set(e,n),a.set(n,(a.get(n)??0)+1)}for(let[e,t]of i)a.get(t)===1&&r.set(e,t);return r}function re(e,t,n){let r=new Map,i=new Map;for(let a of e){let e=t.get(a);if(!e)continue;let o=e.facadeModuleId,s=o?ie(o,n):`modules:${JSON.stringify(Object.keys(e.modules).map(e=>C(e,n)).sort())}`;r.set(a,s),i.set(s,(i.get(s)??0)+1)}return new Map([...r].filter(([,e])=>i.get(e)===1))}function ie(e,t){if(J(e,t).kind!==`outside`)return C(e,t);let n=Y(e).replaceAll(`\\`,`/`);return c.basename(n)===`iframe.html`?`storybook-generated:iframe.html`:C(e,t)}function C(e,t){let n=J(e,t);return n.kind===`project`?`project:${n.path}`:`module:${W(e,t)}`}function ae(e){let t;try{if(!e.parseCode)return[...e.outputs.keys()].some(t=>e.code.includes(c.basename(t)))?null:{code:e.code,observesFileName:e.code.includes(`import.meta`),storyRegistryChunks:new Set};t=e.parseCode(e.code)}catch{return null}let n=new Map,r=[];j(t,void 0,(e,t)=>{r.push(e),t&&n.set(e,t)});let i=T({nodes:r,parents:n,fromFileName:e.fromFileName,outputs:e.outputs,parseCode:e.parseCode}),a=oe({nodes:r,projectRoot:e.projectRoot,fromFileName:e.fromFileName,outputs:e.outputs,directStoryChunks:e.directStoryChunks,viteMapEvidence:i}),o=a.ranges,s=o.map(e=>({...e,value:`{}`}));if(i.declarator&&M(i.declarator.init)){let e=i.declarator.init;if(typeof e.start!=`number`||typeof e.end!=`number`)return null;s.push({start:e.start,end:e.end,value:`__kapture_vite_map__`})}for(let t of i.calls){if(w(t.call,o))continue;if(typeof t.call.start!=`number`||typeof t.call.end!=`number`)return null;let n=t.indexes.map(t=>{let n=i.literals[t],r=n?A(n):null,a=r?I(r,e.fromFileName,e.outputs):void 0,o=a?e.logicalOutputIds.get(a):void 0;return r&&o?`${o}${L(r)}`:null});if(n.some(e=>e===null))return null;s.push({start:t.call.start,end:t.call.end,value:`__kapture_vite_deps__(${JSON.stringify(n)})`})}for(let t of r){if(w(t,s))continue;let r=A(t);if(r===null||typeof t.start!=`number`||typeof t.end!=`number`)continue;let i=n.get(t);if(!(i&&(i?.type===`ImportDeclaration`&&i.source===t||i?.type===`ExportNamedDeclaration`&&i.source===t||i?.type===`ExportAllDeclaration`&&i.source===t||i?.type===`ImportExpression`&&i.source===t)))continue;let a=I(r,e.fromFileName,e.outputs),o=a?e.logicalOutputIds.get(a):void 0;o&&s.push({start:t.start,end:t.end,value:JSON.stringify(`${o}${L(r)}`)})}return{code:P(e.code,s),observesFileName:r.some(e=>ve(e)&&!w(e,o)&&!i.allowedImportMetaUrls.has(n.get(e)??e)),storyRegistryChunks:a.storyChunks}}function oe(e){let t=()=>({ranges:[],storyChunks:new Set});if(!e.viteMapEvidence.declarator)return t();let n=new Map(e.viteMapEvidence.calls.map(e=>[e.outer,e])),r=[],i=new Set;for(let t of e.nodes){if(t.type!==`ObjectExpression`||!Array.isArray(t.properties)||t.properties.length===0||typeof t.start!=`number`||typeof t.end!=`number`)continue;let a=new Set,o=new Set;if(t.properties.every(t=>{if(!M(t)||t.type!==`Property`||t.computed!==!1||t.kind!==`init`||t.method!==!1||t.shorthand!==!1)return!1;let r=M(t.key)?A(t.key):null;if(!r||a.has(r)||!H(r)||!r.startsWith(`./`))return!1;a.add(r);let i=se({key:r,value:t.value,projectRoot:e.projectRoot,fromFileName:e.fromFileName,outputs:e.outputs,directStoryChunks:e.directStoryChunks,callsByOuter:n});return i?(o.add(i),!0):!1})){r.push({start:t.start,end:t.end});for(let e of o)i.add(e)}}return{ranges:r,storyChunks:i}}function se(e){let t=e.value;if(!M(t)||t.type!==`ArrowFunctionExpression`||t.async!==!1||t.generator!==!1||!Array.isArray(t.params)||t.params.length!==0||!M(t.body)||t.body.type!==`CallExpression`)return null;let n=t.body,r=e.callsByOuter.get(n);if(!r||!Array.isArray(n.arguments)||n.arguments.length!==3||n.arguments[1]!==r.call||n.arguments[2]!==r.importMetaUrl)return null;let i=n.arguments[0];if(!M(i)||i.type!==`ArrowFunctionExpression`||i.async!==!1||i.generator!==!1||!Array.isArray(i.params)||i.params.length!==0||!M(i.body)||i.body.type!==`ImportExpression`||!M(i.body.source))return null;let a=A(i.body.source),o=a?I(a,e.fromFileName,e.outputs):void 0,s=o?e.outputs.get(o):void 0;if(!o||!e.directStoryChunks.has(o)||s?.type!==`chunk`)return null;let c;try{c=q(e.key.slice(2),`generated story registry key`,!1)}catch{return null}return Object.keys(s.modules).some(t=>{let n=J(t,e.projectRoot);return n.kind===`project`&&(n.path===c||n.path.endsWith(`/${c}`))})?o:null}function w(e,t){return typeof e.start!=`number`||typeof e.end!=`number`?!1:t.some(t=>e.start>=t.start&&e.end<=t.end)}function T(e){let t=()=>({literals:[],allowedImportMetaUrls:new Set,calls:[]}),{nodes:n,parents:r}=e,i=n.find(e=>e.type===`VariableDeclarator`&&N(e.id,`__vite__mapDeps`)&&M(e.init)&&e.init.type===`ArrowFunctionExpression`);if(!i||!M(i.init))return t();let a=ce(i,r);if(!a||!Array.isArray(a.elements))return t();let o=a.elements.filter(e=>M(e)&&e.type===`Literal`&&typeof e.value==`string`);if(o.length!==a.elements.length)return t();let s=new Set,c=new Set,l=[];for(let a of n){if(!N(a,`__vite__mapDeps`)||a===i.id)continue;let n=r.get(a);if(n?.type===`AssignmentPattern`&&n.right===a)continue;if(n?.type!==`CallExpression`||n.callee!==a)return t();let u=ue(n,e,o.length);if(!u)return t();for(let e of u.indexes)c.add(e);s.add(u.importMetaUrl),l.push({call:n,...u})}return o.some((e,t)=>!c.has(t))?t():{declarator:i,literals:o,allowedImportMetaUrls:s,calls:l}}function ce(e,t){let n=t.get(e);if(n?.type!==`VariableDeclaration`||n.kind!==`const`||!Array.isArray(n.declarations)||n.declarations.length!==1||n.declarations[0]!==e)return null;let r=e.init;if(!M(r)||r.type!==`ArrowFunctionExpression`||r.async!==!1||r.generator!==!1||!Array.isArray(r.params)||r.params.length!==3||!N(r.params[0],`i`))return null;let i=r.params[1],a=r.params[2];return!M(i)||i.type!==`AssignmentPattern`||!N(i.left,`m`)||!N(i.right,`__vite__mapDeps`)||!M(a)||a.type!==`AssignmentPattern`||!N(a.left,`d`)||!M(a.right)||a.right.type!==`LogicalExpression`||a.right.operator!==`||`||!k(a.right.left,`m`,`f`)||!M(a.right.right)||a.right.right.type!==`AssignmentExpression`||a.right.right.operator!==`=`||!k(a.right.right.left,`m`,`f`)||!M(a.right.right.right)||a.right.right.right.type!==`ArrayExpression`||!le(r.body)?null:a.right.right.right}function le(e){if(!M(e)||e.type!==`CallExpression`||!M(e.callee)||e.callee.type!==`MemberExpression`||e.callee.computed!==!1||!N(e.callee.object,`i`)||!N(e.callee.property,`map`)||!Array.isArray(e.arguments)||e.arguments.length!==1)return!1;let t=e.arguments[0];return M(t)&&t.type===`ArrowFunctionExpression`&&t.async===!1&&t.generator===!1&&Array.isArray(t.params)&&t.params.length===1&&N(t.params[0],`i`)&&M(t.body)&&t.body.type===`MemberExpression`&&t.body.computed===!0&&N(t.body.object,`d`)&&N(t.body.property,`i`)}function ue(e,t,n){if(!Array.isArray(e.arguments)||e.arguments.length!==1)return null;let r=e.arguments[0];if(!M(r)||r.type!==`ArrayExpression`||!Array.isArray(r.elements))return null;let i=r.elements.map(e=>M(e)&&e.type===`Literal`&&typeof e.value==`number`&&Number.isInteger(e.value)&&e.value>=0&&e.value<n?e.value:null);if(i.some(e=>e===null))return null;let a=t.parents.get(e);return a?.type!==`CallExpression`||!Array.isArray(a.arguments)||a.arguments.length!==3||a.arguments[1]!==e||!M(a.arguments[2])||!_e(a.arguments[2])||!fe(a.callee,t)?null:{outer:a,indexes:i,importMetaUrl:a.arguments[2]}}const de=new Set([`4f5090408061e66b82e2a30dd449c982fdb4a6586d712ab6bb5614e01656fa23`]);function fe(e,t){if(!M(e)||e.type!==`Identifier`||typeof e.name!=`string`)return!1;let n=me(e,t.parents);if(!n||!N(n.imported,`t`))return!1;let r=t.parents.get(n);if(r?.type!==`ImportDeclaration`||!M(r.source))return!1;let i=A(r.source),a=i?I(i,t.fromFileName,t.outputs):void 0,o=a?t.outputs.get(a):void 0;return!o||o.type!==`chunk`||!t.parseCode||typeof o.code!=`string`?!1:de.has(pe(o.code,t.parseCode))}function pe(e,t){let n;try{n=t(e)}catch{return``}let r=[];return j(n,void 0,(e,t)=>{t?.type===`ImportDeclaration`&&t.source===e&&typeof e.start==`number`&&typeof e.end==`number`&&r.push({start:e.start,end:e.end,value:JSON.stringify(`kapture-import:${r.length}`)})}),U(P(e,r))}function me(e,t){let n=e.name;if(typeof n!=`string`)return null;let r=t.get(e);for(;r;){if(O(r)&&(D(r.params,n)||D(r.id,n)||E(r.body,n))||r.type===`CatchClause`&&D(r.param,n)||he(r,n)||r.type===`BlockStatement`&&ge(r,n))return null;if(r.type===`Program`){let e=[];return j(r,void 0,(t,r)=>{t.type===`ImportSpecifier`&&N(t.local,n)&&r?.type===`ImportDeclaration`&&e.push(t)}),e.length===1?e[0]??null:null}r=t.get(r)}return null}function E(e,t,n=!0){return Array.isArray(e)?e.some(e=>E(e,t,!1)):!M(e)||!n&&(O(e)||e.type.includes(`Class`))?!1:e.type===`VariableDeclaration`&&e.kind===`var`&&Array.isArray(e.declarations)&&e.declarations.some(e=>M(e)&&D(e.id,t))?!0:Object.entries(e).some(([e,n])=>e!==`loc`&&e!==`start`&&e!==`end`&&e!==`type`&&E(n,t,!1))}function he(e,t){let n=e.type===`ForStatement`?e.init:e.type===`ForInStatement`||e.type===`ForOfStatement`?e.left:void 0;return M(n)&&n.type===`VariableDeclaration`&&Array.isArray(n.declarations)&&n.declarations.some(e=>M(e)&&D(e.id,t))}function ge(e,t){return Array.isArray(e.body)?e.body.some(e=>M(e)?e.type===`VariableDeclaration`&&Array.isArray(e.declarations)?e.declarations.some(e=>M(e)&&D(e.id,t)):(e.type===`FunctionDeclaration`||e.type===`ClassDeclaration`)&&N(e.id,t):!1):!1}function D(e,t){let n=!1;return j(e,void 0,e=>{N(e,t)&&(n=!0)}),n}function O(e){return[`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`].includes(e.type)}function k(e,t,n){return M(e)&&e.type===`MemberExpression`&&e.computed===!1&&N(e.object,t)&&N(e.property,n)}function _e(e){return M(e)&&e.type===`MemberExpression`&&M(e.object)&&e.object.type===`MetaProperty`&&N(e.object.meta,`import`)&&N(e.object.property,`meta`)&&N(e.property,`url`)}function ve(e){return M(e)&&e.type===`MetaProperty`&&N(e.meta,`import`)&&N(e.property,`meta`)}function A(e){if(e.type===`Literal`&&typeof e.value==`string`)return e.value;if(e.type!==`TemplateLiteral`||!Array.isArray(e.expressions)||e.expressions.length||!Array.isArray(e.quasis)||e.quasis.length!==1||!M(e.quasis[0]))return null;let t=e.quasis[0].value;return typeof t==`object`&&t&&`cooked`in t&&typeof t.cooked==`string`?t.cooked:null}function j(e,t,n){if(Array.isArray(e)){for(let r of e)j(r,t,n);return}if(M(e)){n(e,t);for(let[t,r]of Object.entries(e))t!==`loc`&&t!==`start`&&t!==`end`&&t!==`type`&&j(r,e,n)}}function M(e){return typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`}function N(e,t){return M(e)&&e.type===`Identifier`&&e.name===t}function P(e,t){let n=e;for(let e of t.sort((e,t)=>t.start-e.start))n=`${n.slice(0,e.start)}${e.value}${n.slice(e.end)}`;return n}function F(e,t,n,r){return e.map(e=>{let i=I(e,t,n),a=i&&r.get(i);return a?`${a}${L(e)}`:R(e)}).sort()}function I(e,t,n){let r=e.split(/[?#]/,1)[0]?.replaceAll(`\\`,`/`)??``;return[r.replace(/^\/+/,``),c.normalize(c.join(c.dirname(t),r))].find(e=>n.has(e))}function L(e){let t=e.search(/[?#]/);return t===-1?``:e.slice(t)}function R(e){return q(e,`bundle output`,!1)}function ye(e,t,n){return e.source===null?``:P(e.source,e.loadReferences.flatMap(t=>{let r=n.get(t.target);return r?[{start:t.start,end:t.end,value:JSON.stringify(`${r}${L(e.source?.slice(t.start,t.end)??``)}`)}]:[]}))}function be(e){let t=[],n=0;for(;n<e.length;){let r=e.indexOf(`<`,n);if(r===-1)break;if(e.startsWith(`<!--`,r)){let t=e.indexOf(`-->`,r+4);n=t===-1?e.length:t+3;continue}let i=e.slice(r+1).match(/^\/?\s*([A-Za-z][\w:-]*)/);if(!i?.[1]||e[r+1]===`/`){n=r+1;continue}let a=i[1].toLowerCase(),o=xe(e,r+1);if(o===-1)break;let s=z(e.slice(r,o+1),r),c=new Map(s.map(e=>[e.name,e]));if(a===`script`){let e=c.get(`src`);e&&t.push({start:e.start,end:e.end,value:e.value,loadsJavaScript:!0,requiresBundleTarget:!/^(?:https?:)?\/\//i.test(e.value)})}else if(a===`link`){let e=c.get(`href`),n=c.get(`rel`)?.value.toLowerCase().split(/\s+/)??[];if(e&&n.some(e=>[`modulepreload`,`preload`,`stylesheet`].includes(e))){let r=/^(?:https?:)?\/\//i.test(e.value);t.push({start:e.start,end:e.end,value:e.value,loadsJavaScript:n.includes(`modulepreload`),requiresBundleTarget:!r})}}if(n=o+1,[`script`,`style`,`textarea`,`title`].includes(a)){let t=e.toLowerCase().indexOf(`</${a}`,n);t!==-1&&(n=t)}}return t}function xe(e,t){let n=``;for(let r=t;r<e.length;r+=1){let t=e[r]??``;if(n)t===n&&(n=``);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}function z(e,t){let n=[];for(let r of e.matchAll(/([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g)){let e=r[2]??r[3]??r[4];if(e===void 0||r.index===void 0)continue;let i=r[0].lastIndexOf(e);n.push({name:(r[1]??``).toLowerCase(),value:e,start:t+r.index+i,end:t+r.index+i+e.length})}return n}function Se(e){let t=Ce(e);for(let n of e.containerChunks){let r=e.outputs.get(n);if(!(!r||r.type!==`chunk`))for(let i of r.viteMetadata?.importedCss??[]){let r=I(i,n,e.outputs);r&&t.add(r)}}let n=new Map;for(let r of e.chunks){let i=new Set(r.viteMetadata?.importedCss??[]);for(let a of i){let i=e.outputs.get(a);if(!i||i.type!==`asset`||!i.fileName.toLowerCase().endsWith(`.css`)||!V(i.fileName))continue;let o=q(i.fileName,`bundle asset reference`,!1);if(t.has(o))continue;let s=n.get(o)??new Set;s.add(r.fileName),n.set(o,s)}}let r=new Map;for(let t of e.outputs.values()){if(t.type!==`asset`||!V(t.fileName))continue;let e=q(t.fileName,`bundle asset`,!1);r.set(e,new Set)}for(let[t,i]of e.entries)for(let[e,a]of n)[...a].some(e=>i.chunks.has(e))&&r.get(e)?.add(t);return r}function Ce(e){let t=new Map;for(let n of e.outputs.values())n.type===`asset`&&t.set(q(n.fileName,`bundle asset`,!1),n);let n=[...t].filter(([e])=>e.toLowerCase()===`iframe.html`);if(n.some(([,e])=>B(e)===null))return new Set([...t.keys()].filter(e=>V(e)));let r=new Set,i=n.map(([e])=>e);for(;i.length>0;){let e=i.pop();if(!e)continue;let n=B(t.get(e));if(n!==null)for(let[a]of t)a===e||r.has(a)||!n.includes(a)||(r.add(a),i.push(a))}return r}function B(e){return typeof e?.source==`string`?e.source:e?.source instanceof Uint8Array?new TextDecoder().decode(e.source):null}function V(e){let t=e.replaceAll(`\\`,`/`).toLowerCase();return t!==`kapture-dependencies.json`&&t!==`iframe.html`}function we(e){return e.type===`chunk`?typeof e.code==`string`?new TextEncoder().encode(e.code):null:typeof e.source==`string`?new TextEncoder().encode(e.source):e.source instanceof Uint8Array?e.source:null}function H(e){return/\.(?:stories|story)\.[cm]?[jt]sx?(?:[?#]|$)/i.test(e)}function U(t){return e(`sha256`).update(t).digest(`hex`)}function W(e,t){let n=t.replaceAll(`\\`,`/`),r=new Set([t,n,n.replaceAll(`/`,`\\`),encodeURI(n)]),i=e;for(let e of[...r].filter(Boolean).sort((e,t)=>t.length-e.length))i=i.replaceAll(e,`<projectRoot>`),i=i.replaceAll(e.replaceAll(`\\`,`\\\\`),`<projectRoot>`);return i}function Te(e){let t=new Map,n=new Map;for(let[r,i]of[...e.modulesById].sort(([e],[t])=>e.localeCompare(t))){let a=J(r,e.projectRoot);if(a.kind!==`project`||typeof i.code!=`string`)continue;let o=Ee(i.code,i.importedIds??[],r);if(!o){let e=n.get(a.path)??[];e.push(null),n.set(a.path,e);continue}for(let n of o){if(!n.resolvedId)continue;let r=J(n.resolvedId,e.projectRoot);if(r.kind!==`project`)continue;let i=t.get(a.path)??new Map,o=i.get(r.path)??new Set;je(o,n.names),i.set(r.path,o),t.set(a.path,i)}let s=Oe(i.code,o),c=n.get(a.path)??[];c.push(s),n.set(a.path,c)}let r={};for(let[n,i]of[...t].sort(([e],[t])=>e.localeCompare(t))){let t={};for(let[r,a]of[...i].sort(([e],[t])=>e.localeCompare(t)))e.dependencyGraph[n]?.includes(r)&&(t[r]=[...a].sort());Object.keys(t).length>0&&(r[n]=t)}let i={};for(let[t,r]of[...n].sort(([e],[t])=>e.localeCompare(t))){if(r.length===0||r.some(e=>e===null))continue;let n=new Map,a=new Set;for(let i of r)if(i)for(let[r,o]of i){let i=J(o.rawModule,e.projectRoot);if(i.kind!==`project`||!e.dependencyGraph[t]?.includes(i.path))continue;let s={module:i.path,imported:o.imported},c=n.get(r);if(c&&(c.module!==s.module||c.imported!==s.imported)){a.add(r),n.delete(r);continue}a.has(r)||n.set(r,s)}n.size>0&&(i[t]=Object.fromEntries([...n].sort(([e],[t])=>e.localeCompare(t))))}return{importBindings:r,reexportBindings:i}}function Ee(e,t,n){let r=[];for(let t of e.matchAll(/^[ \t]*import(?:[ \t]+(.+?)[ \t]+from)?[ \t]*["']([^"']+)["'][ \t]*;?[ \t]*$/gm)){let e=t.index,n=De(t[1]?.trim()??``);r.push({start:e,end:e+t[0].length,specifier:t[2]??``,names:n.names,locals:n.locals})}if(r.length!==t.length)return null;for(let[e,i]of r.entries()){let r=t[e];if(!r||!Ae(n,i.specifier,r))return null;i.resolvedId=r}return r}function De(e){let t=new Set,n=new Map;if(e===``)return{names:[`*`],locals:n};let r=e.trim(),i=r.match(/^([A-Za-z_$][\w$]*)\s*(?:,|$)/);if(i){let e=i[1];e&&n.set(e,`default`),t.add(`default`),r=r.slice(i[0].length).trim()}if(r.startsWith(`*`)){let e=r.match(/^\*\s+as\s+([A-Za-z_$][\w$]*)$/);return e?.[1]?(t.add(`*`),n.set(e[1],`*`),{names:[...t],locals:n}):{names:[`*`],locals:new Map}}if(r.startsWith(`{`)&&r.endsWith(`}`)){for(let e of r.slice(1,-1).split(`,`)){let r=e.trim();if(!r)continue;let i=r.match(/^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);if(!i?.[1])return{names:[`*`],locals:new Map};let a=i[1],o=i[2]??a;t.add(a),n.set(o,a)}return{names:[...t],locals:n}}return{names:[`*`],locals:new Map}}function Oe(e,t){let n=ke(e);if(n.length===0)return null;let r=[...e];for(let e of[...t,...n])for(let t=e.start;t<e.end;t+=1)r[t]=` `;if(r.join(``).replace(/\/\*[\s\S]*?\*\//g,``).replace(/\/\/[^\n]*/g,``).replace(/(?:^|\n)[ \t]*["']use (?:client|strict)["'][ \t]*;?[ \t]*(?=\n|$)/g,``).trim()!==``)return null;let i=new Map;for(let e of t)if(e.resolvedId)for(let[t,n]of e.locals)i.set(t,{rawModule:e.resolvedId,imported:n});let a=new Map;for(let e of n)for(let t of e.specifiers){let e=i.get(t.local);e&&a.set(t.exported,e)}return a}function ke(e){let t=[];for(let n of e.matchAll(/(?:^|\n)[ \t]*export[ \t]*\{([^}]*)\}[ \t]*;?[ \t]*(?=\n|$)/g)){let e=n.index,r=[];for(let e of(n[1]??``).split(`,`)){let t=e.trim();if(!t)continue;let n=t.match(/^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);n?.[1]&&r.push({local:n[1],exported:n[2]??n[1]})}t.push({start:e,end:e+n[0].length,specifiers:r})}return t}function Ae(e,t,n){if(!t.startsWith(`.`))return!0;let r=Y(e),i=Y(n),o=u(a(r),t);return i===o||G(i)===G(o)||G(i)===`${G(o)}/index`}function G(e){return e.replace(/\.(?:[cm]?[jt]sx?|css|scss|sass|less|styl|json)$/i,``)}function je(e,t){if(!e.has(`*`)){if(t.includes(`*`)){e.clear(),e.add(`*`);return}for(let n of t)e.add(n)}}function Me(e,t){let n=new Set(e),r=Object.keys(t).filter(t=>e.some(e=>Ne(t,e)));for(;r.length>0;){let e=r.pop();if(e)for(let i of t[e]??[])n.has(i)||(n.add(i),r.push(i))}return[...n].sort()}function Ne(e,t){if(e===t)return!0;try{return s(e,t)}catch(e){throw Error(`Invalid globalInputs pattern: ${t}`,{cause:e})}}function K(e,t){let n=e.map((e,n)=>q(e,`${t}[${n}]`,!1));return[...new Set(n)].sort()}function q(e,t,n){let r=e.replaceAll(`\\`,`/`).replace(/^\.\//,``).replace(/\/{2,}/g,`/`),i=r===``?``:c.normalize(r).replace(/\/$/,``);if(!n&&i.length===0||i.includes(`\0`))throw Error(`${t} must be a non-empty project-relative path`);if(o(i)||i===`..`||i.startsWith(`../`))throw Error(`${t} must stay within projectRoot`);return i}function J(e,t){let n=Y(e);if(!n||m.some(e=>n.startsWith(e))||/^(?:node:|https?:|data:)/.test(n))return{kind:`external`};let r=n;if(r.startsWith(`file://`))try{r=f(r)}catch{return{kind:`external`}}if(!o(r)||Pe(r))return{kind:`external`};let i=l(t,r);return i===``||i===`.`?{kind:`external`}:i===`..`||i.startsWith(`..${d}`)||o(i)?{kind:`outside`}:{kind:`project`,path:i.split(d).join(`/`)}}function Y(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=Math.min(t===-1?e.length:t,n===-1?e.length:n);return e.slice(0,r)}function Pe(e){return e.split(d).join(`/`).includes(`/node_modules/`)}function X(e){return m.some(t=>e.startsWith(t))}function Fe(e,t){let n=new Set,r=[...e].flatMap(e=>[...t.get(e)??[]]);for(;r.length>0;){let e=r.pop();if(!(!e||n.has(e)||!X(e))){n.add(e);for(let n of t.get(e)??[])r.push(n)}}return n}function Ie(e){let t=Y(e);return t.length>0&&!o(t)&&!t.startsWith(`file://`)&&!/^(?:node:|https?:|data:)/.test(t)&&!X(t)}const Le=[`package.json`,`bun.lock`,`package-lock.json`,`pnpm-lock.yaml`,`yarn.lock`];async function Re(e,t){let n=process.cwd(),r=u(n,t.projectRoot??`.`),i=l(r,n);if(i===`..`||i.startsWith(`..${process.platform===`win32`?`\\`:`/`}`))throw Error(`@kaptures/storybook preset projectRoot must contain Storybook's working directory`);let a=t.configDir?l(r,u(t.configDir)):null,o=[...Le,...a&&!a.startsWith(`..`)?[`${$(a)}/**`]:[],...t.globalInputs??[]];return{...e,plugins:[...e.plugins??[],Z({projectRoot:r,storybookRoot:$(i),globalInputs:o,ignoredInputs:t.ignoredInputs??[],fingerprintedInputs:t.fingerprintedInputs??[]})]}}function Z(e){let t=new Map;return{name:`kapture:storybook-dependencies`,apply:`build`,moduleParsed(e){t.set(e.id,{id:e.id,importedIds:[...e.importedIds??[]],dynamicallyImportedIds:[...e.dynamicallyImportedIds??[]],code:e.code,sourceFingerprint:Ve(e.id)})},generateBundle:{order:`post`,handler(n,r){let i=Q(e,t.values(),r,e=>this.parse(e));this.emitFile({type:`asset`,fileName:p,source:`${JSON.stringify(i,null,2)}\n`})}},writeBundle:{order:`post`,handler(n,r){let o=n.dir?u(n.dir):n.file?a(u(n.file)):null;if(!o)throw Error(`@kaptures/storybook requires a Rollup output directory`);let s=Q(e,t.values(),r,e=>this.parse(e),o);i(u(o,p),`${JSON.stringify(s,null,2)}\n`)}}}}function Q(e,t,n,r,i){let a=[...t],o=_({projectRoot:e.projectRoot,modules:a,bundle:n,parseCode:r}),s=h({...e,containerModuleIds:o.containerModuleIds,modules:a});s.renderedModules=o.renderedModules,s.renderedOutputFingerprints=o.renderedOutputFingerprints,s.globalOutputFingerprints=o.globalOutputFingerprints,s.globalOutputStories=o.globalOutputStories,s.globalRuntimeFingerprint=o.globalRuntimeFingerprint;let c=v(n),l=v(n,i);Object.assign(s,l);for(let[e,t]of Object.entries(l.outputInventory))e in c.outputInventory||ze(e)||(s.globalOutputFingerprints[e]=t.sha256,s.globalOutputStories[e]=[]);let u=Object.entries(c.outputInventory).some(([e,t])=>{let n=l.outputInventory[e];return!n||n.type!==t.type||n.size!==t.size||n.sha256!==t.sha256});return s.diagnostics=[...new Set([...s.diagnostics,...o.diagnostics,...u?[`output-inventory-mismatch`]:[]])].sort(),s.complete=s.diagnostics.length===0,s}function ze(e){return[`index.html`,`index.json`,`project.json`,`favicon.svg`,`favicon-wrapper.svg`,`nunito-sans-bold-italic.woff2`,`nunito-sans-bold.woff2`,`nunito-sans-italic.woff2`,`nunito-sans-regular.woff2`].includes(e)||[`sb-addons/`,`sb-common-assets/`,`sb-manager/`].some(t=>e.startsWith(t))}function $(e){return e.replaceAll(`\\`,`/`)}const Be=/\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss|apng|bmp|png|jpe?g|jfif|pjpeg|pjp|gif|svg|ico|webp|avif|cur|jxl|mp4|webm|ogg|mp3|wav|flac|aac|opus|mov|m4a|vtt|woff2?|eot|ttf|otf|webmanifest|pdf|txt|wasm)$/i;function Ve(t){let r=t.indexOf(`?`),i=t.indexOf(`#`),a=Math.min(r===-1?t.length:r,i===-1?t.length:i),s=t.slice(0,a);if(s.startsWith(`file://`))try{s=f(s)}catch{return}if(!(!o(s)||s.replaceAll(`\\`,`/`).includes(`/node_modules/`)||!Be.test(s)))try{return e(`sha256`).update(n(s)).digest(`hex`)}catch{return}}export{p as KAPTURE_DEPENDENCY_MANIFEST_FILE,h as buildKaptureDependencyManifest,v as buildKaptureOutputInventory,_ as buildKaptureRenderedEvidence,g as buildKaptureRenderedModuleClosures,Z as createKaptureDependencyPlugin,Re as viteFinal};
1
+ import{createHash as e}from"node:crypto";import{lstatSync as t,readFileSync as n,readdirSync as r,writeFileSync as i}from"node:fs";import{dirname as a,isAbsolute as o,matchesGlob as s,posix as c,relative as l,resolve as u,sep as d}from"node:path";import{fileURLToPath as f}from"node:url";const p=`kapture-dependencies.json`,m=[`\0`,`virtual:`,`/@id/`,`vite:`];function h({projectRoot:e,storybookRoot:t,globalInputs:n,ignoredInputs:r,fingerprintedInputs:i=[],containerModuleIds:a=[],modules:o}){let s=u(e),c=new Map,l=new Map,d=new Set,f=new Set(a);for(let e of o){let t=c.get(e.id)??new Set;for(let n of[...e.importedIds??[],...e.dynamicallyImportedIds??[]])t.add(n);if(c.set(e.id,t),typeof e.code==`string`||e.sourceFingerprint){let t=l.get(e.id)??new Set;t.add(U(JSON.stringify({transformedCode:typeof e.code==`string`?U(W(e.code,s)):null,sourceFingerprint:e.sourceFingerprint??null}))),l.set(e.id,t)}}let p=new Map;for(let e of c.keys()){let t=q(e,s);if(t.kind===`project`){let n=p.get(t.path)??new Set;n.add(e),p.set(t.path,n)}else t.kind===`outside`&&!f.has(e)&&d.add(`module-outside-project-root`)}let m={},h={};for(let[e,t]of[...p].sort(([e],[t])=>e.localeCompare(t))){let n=new Set([e]),r=new Set,a=[...t].flatMap(e=>[...c.get(e)??[]]);for(;a.length>0;){let e=a.pop();if(!e)continue;let t=q(e,s);if(t.kind===`project`){n.add(t.path),p.has(t.path)||d.add(`unresolved-project-module`);continue}if(t.kind===`outside`&&!f.has(e)&&d.add(`module-outside-project-root`),ke(e)&&c.has(e)&&d.add(`unresolved-virtual-module`),!(!Y(e)||!c.has(e)||r.has(e))){r.add(e);for(let t of c.get(e)??[])a.push(t)}}m[e]=[...n].sort();let o=Oe(t,c),u=[...t,...o],g=u.flatMap(e=>[...l.get(e)??[]]);u.every(e=>(l.get(e)?.size??0)>0)?h[e]=U(JSON.stringify([...new Set(g)].sort())):(i.length>0&&d.add(`module-fingerprint-missing`),[...o].some(e=>(l.get(e)?.size??0)===0)&&d.add(`unresolved-virtual-module`))}let g=K(t,`storybookRoot`,!0),_=G(n,`globalInputs`);return{kind:`kapture-storybook-dependencies`,version:1,complete:d.size===0,storybookRoot:g,globalInputs:Te(_,m),ignoredInputs:G(r,`ignoredInputs`),fingerprintedInputs:G(i,`fingerprintedInputs`),diagnostics:[...d].sort(),modules:m,moduleFingerprints:h,globalOutputFingerprints:{},globalOutputStories:{},outputInventory:{},outputInventoryPrefixes:[],importBindings:{},reexportBindings:{},renderedOutputFingerprints:{}}}function g(e){return Object.fromEntries([...b({...e,requireContainerEvidence:!1}).entries].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t.modules].sort()]))}function _(e){let t=b({...e,requireContainerEvidence:!0}),n=new Set(t.diagnostics),r={},i={};for(let[e,a]of[...t.entries].sort(([e],[t])=>e.localeCompare(t))){r[e]=[...a.modules].sort();let o=[],s=a.chunks.size>0;for(let e of[...a.chunks].sort()){let n=t.chunkFingerprints.get(e);if(!n){s=!1;continue}o.push(n)}s?i[e]=U(JSON.stringify(o.sort())):n.add(`rendered-output-fingerprint-missing`)}let a=Se(t),o={},s={};for(let t of Object.values(e.bundle).sort((e,t)=>e.fileName.localeCompare(t.fileName))){if(t.type!==`asset`||!V(t.fileName))continue;let e=K(t.fileName,`bundle asset`,!1);if(s[e]=[...a.get(e)??[]].sort(),typeof t.source!=`string`&&!(t.source instanceof Uint8Array)){n.add(`global-output-fingerprint-missing`);continue}o[e]=U(t.source)}return{renderedModules:r,renderedOutputFingerprints:i,globalOutputFingerprints:o,globalOutputStories:s,...t.globalRuntimeFingerprint?{globalRuntimeFingerprint:t.globalRuntimeFingerprint}:{},containerModuleIds:[...t.containerModuleIds].sort(),diagnostics:[...n].sort()}}function v(e,t){if(t)return y(e,t);let n={};for(let t of Object.values(e).sort((e,t)=>e.fileName.localeCompare(t.fileName))){let e=K(t.fileName,`bundle output`,!1);if(e===`kapture-dependencies.json`)continue;let r=we(t);r&&(n[e]={type:t.type,size:r.byteLength,sha256:U(r)})}return{outputInventory:n,outputInventoryPrefixes:[...new Set(Object.keys(n).filter(e=>e.includes(`/`)).map(e=>`${e.split(`/`)[0]}/`))].sort()}}function y(e,i){let a=u(i),o=new Map(Object.values(e).map(e=>[K(e.fileName,`bundle output`,!1),e.type])),s={},c=[``],l=0;for(;c.length>0;){let e=c.pop();if(e===void 0)continue;let i=e?u(a,e):a;for(let d of r(i,{withFileTypes:!0}).sort((e,t)=>e.name.localeCompare(t.name))){if(l+=1,l>1e5)throw Error(`@kaptures/storybook output inventory contains too many entries`);let r=K(e?`${e}/${d.name}`:d.name,`storybook output`,!1),i=u(a,r),f=t(i);if(f.isSymbolicLink())throw Error(`@kaptures/storybook cannot inventory symbolic link: ${r}`);if(f.isDirectory()){c.push(r);continue}if(!f.isFile())throw Error(`@kaptures/storybook cannot inventory special file: ${r}`);if(r===`kapture-dependencies.json`)continue;let p=n(i);s[r]={type:o.get(r)??`asset`,size:p.byteLength,sha256:U(p)}}}return{outputInventory:Object.fromEntries(Object.entries(s).sort(([e],[t])=>e.localeCompare(t))),outputInventoryPrefixes:Object.keys(s).length>0?[``]:[]}}function b(e){let t=u(e.projectRoot),n=new Map([...e.modules].map(e=>[e.id,e])),r=new Map,i=[],a=new Map,o=new Map,s=new Map,c=new Set,l=new Set,d=new Set;for(let n of Object.values(e.bundle)){let e=K(n.fileName,`bundle output`,!1);if(r.set(e,n),n.type===`chunk`){i.push(n),a.set(e,n),n.facadeModuleId&&H(n.facadeModuleId)&&(c.add(n.facadeModuleId),l.add(e));for(let r of Object.keys(n.modules)){H(r)&&(c.add(r),l.add(e));let n=o.get(r)??new Set;n.add(e),o.set(r,n);let i=q(r,t);if(i.kind!==`project`)continue;let a=s.get(i.path)??new Set;a.add(r),s.set(i.path,a)}}}let f=ee(r,a);if(e.requireContainerEvidence)for(let e of f.diagnostics)d.add(e);let p=te({roots:f.chunkRoots,chunksByFileName:a,outputs:r,directStoryChunks:l,diagnostics:d}),m=new Set;for(let e of p){let t=a.get(e),n=t?.facadeModuleId;n&&m.add(n);for(let e of Object.keys(t?.modules??{}))m.add(e)}let h=new Map;for(let[e,i]of[...s].sort(([e],[t])=>e.localeCompare(t))){if(![...i].some(e=>c.has(e)))continue;let s=[...i].flatMap(e=>[...o.get(e)??[]]),l=new Set,u=new Set;for(;s.length>0;){let e=s.pop();if(!e||l.has(e)||p.has(e))continue;l.add(e);let i=a.get(e);if(i){for(let e of ne(i,r,d))s.push(e);for(let e of Object.keys(i.modules)){let r=q(e,t);if(r.kind===`project`){u.add(r.path);for(let t of n.get(e)?.dynamicallyImportedIds??[])for(let e of o.get(t)??[])s.push(e)}}}}h.set(e,{modules:u,chunks:l})}let g=new Set(p);for(let e of h.values())for(let t of e.chunks)g.add(t);i.some(e=>!g.has(z(e.fileName)))&&d.add(`unowned-output-chunk`);let _=re({root:t,chunks:i,outputs:r,containerRootIds:ie(f.chunkRoots,a,t)}),v=new Map;for(let n of i){let i=z(n.fileName);if(typeof n.code!=`string`)continue;let a=oe({code:n.code,fromFileName:i,projectRoot:t,outputs:r,logicalOutputIds:_,directStoryChunks:l,parseCode:e.parseCode});if(a===null)continue;let o={output:_.get(i)??i,...a.observesFileName?{fileName:i}:{},code:U(a.code),imports:I(n.imports??[],i,r,_),dynamicImports:I((n.dynamicImports??[]).filter(e=>{let t=L(e,i,r);return!t||!a.storyRegistryChunks.has(t)}),i,r,_),implicitlyLoadedBefore:I(n.implicitlyLoadedBefore??[],i,r,_),referencedFiles:I(n.referencedFiles??[],i,r,_)},s=U(JSON.stringify(o));v.set(i,s)}let y;if(f.source!==null&&f.chunkRoots.size>0){let e=ve(f,r,_),t=[...p].map(e=>v.get(e)).filter(e=>!!e).sort();t.length===p.size&&(y=U(JSON.stringify({html:U(e),chunks:t})))}return e.requireContainerEvidence&&!y&&d.add(`global-runtime-fingerprint-missing`),{root:t,modulesById:n,outputs:r,entries:h,chunks:i,chunkFingerprints:v,containerChunks:p,containerModuleIds:m,...y?{globalRuntimeFingerprint:y}:{},diagnostics:d}}function ee(e,t){let n=new Set,r=e.get(`iframe.html`);if(!r||r.type!==`asset`)return n.add(`global-runtime-fingerprint-missing`),{source:null,chunkRoots:new Set,loadReferences:[],diagnostics:n};let i=B(r);if(i===null)return n.add(`global-runtime-fingerprint-missing`),{source:null,chunkRoots:new Set,loadReferences:[],diagnostics:n};let a=new Set,o=[];for(let r of ye(i)){let i=L(r.value,`iframe.html`,e);if(!i){r.requiresBundleTarget&&n.add(`global-runtime-fingerprint-missing`);continue}o.push({start:r.start,end:r.end,target:i}),r.loadsJavaScript&&(t.has(i)?a.add(i):n.add(`global-runtime-fingerprint-missing`))}return a.size===0&&n.add(`global-runtime-fingerprint-missing`),{source:i,chunkRoots:a,loadReferences:o,diagnostics:n}}function te(e){let t=new Set,n=[...e.roots];for(;n.length>0;){let r=n.pop();if(!r||t.has(r))continue;let i=e.chunksByFileName.get(r);if(!i){e.diagnostics.add(`global-runtime-fingerprint-missing`);continue}t.add(r);for(let t of x(i,e.outputs,e.diagnostics))n.push(t);for(let t of i.dynamicImports??[]){let i=L(t,r,e.outputs);i?e.directStoryChunks.has(i)||n.push(i):e.diagnostics.add(`global-runtime-fingerprint-missing`)}}return t}function ne(e,t,n){return[...x(e,t,n),...(e.dynamicImports??[]).flatMap(r=>{let i=L(r,e.fileName,t);return i?t.get(i)?.type===`chunk`?[i]:[]:(n.add(`rendered-output-fingerprint-missing`),[])})]}function x(e,t,n){return[...e.imports??[],...e.implicitlyLoadedBefore??[],...e.referencedFiles??[]].flatMap(r=>{let i=L(r,e.fileName,t);return i?t.get(i)?.type===`chunk`?[i]:[]:(n.add(`rendered-output-fingerprint-missing`),[])})}function re(e){let t=new Map,n=new Map;for(let r of e.chunks){let i=z(r.fileName),a=e.containerRootIds.get(i),o=`chunk:${U(JSON.stringify({facade:a||(r.facadeModuleId?S(r.facadeModuleId,e.root):null),modules:a?[]:Object.keys(r.modules).map(t=>S(t,e.root)).sort()}))}`;t.set(i,o),n.set(o,(n.get(o)??0)+1)}let r=new Map;for(let[e,i]of t)n.get(i)===1&&r.set(e,i);let i=new Map,a=new Map;for(let t of e.chunks){let n=r.get(z(t.fileName));if(n)for(let r of t.viteMetadata?.importedCss??[]){let a=L(r,t.fileName,e.outputs);if(!a||e.outputs.get(a)?.type!==`asset`)continue;let o=i.get(a);i.set(a,o?`${o}\n${n}`:n)}}for(let[e,t]of i){let n=`css:${U(JSON.stringify([...new Set(t.split(`
2
+ `))].sort()))}`;i.set(e,n),a.set(n,(a.get(n)??0)+1)}for(let[e,t]of i)a.get(t)===1&&r.set(e,t);return r}function ie(e,t,n){let r=new Map,i=new Map;for(let a of e){let e=t.get(a);if(!e)continue;let o=e.facadeModuleId,s=o?ae(o,n):`modules:${JSON.stringify(Object.keys(e.modules).map(e=>S(e,n)).sort())}`;r.set(a,s),i.set(s,(i.get(s)??0)+1)}return new Map([...r].filter(([,e])=>i.get(e)===1))}function ae(e,t){if(q(e,t).kind!==`outside`)return S(e,t);let n=J(e).replaceAll(`\\`,`/`);return c.basename(n)===`iframe.html`?`storybook-generated:iframe.html`:S(e,t)}function S(e,t){let n=q(e,t);return n.kind===`project`?`project:${n.path}`:`module:${W(e,t)}`}function oe(e){let t;try{if(!e.parseCode)return[...e.outputs.keys()].some(t=>e.code.includes(c.basename(t)))?null:{code:e.code,observesFileName:e.code.includes(`import.meta`),storyRegistryChunks:new Set};t=e.parseCode(e.code)}catch{return null}let n=new Map,r=[];M(t,void 0,(e,t)=>{r.push(e),t&&n.set(e,t)});let i=le({nodes:r,parents:n,fromFileName:e.fromFileName,outputs:e.outputs,parseCode:e.parseCode}),a=se({nodes:r,projectRoot:e.projectRoot,fromFileName:e.fromFileName,outputs:e.outputs,directStoryChunks:e.directStoryChunks,viteMapEvidence:i}),o=a.ranges,s=o.map(e=>({...e,value:`{}`}));if(i.declarator&&N(i.declarator.init)){let e=i.declarator.init;if(typeof e.start!=`number`||typeof e.end!=`number`)return null;s.push({start:e.start,end:e.end,value:`__kapture_vite_map__`})}for(let t of i.calls){if(C(t.call,o))continue;if(typeof t.call.start!=`number`||typeof t.call.end!=`number`)return null;let n=t.indexes.map(t=>{let n=i.literals[t],r=n?j(n):null,a=r?L(r,e.fromFileName,e.outputs):void 0,o=a?e.logicalOutputIds.get(a):void 0;return r&&o?`${o}${R(r)}`:null});if(n.some(e=>e===null))return null;s.push({start:t.call.start,end:t.call.end,value:`__kapture_vite_deps__(${JSON.stringify(n)})`})}for(let t of r){if(C(t,s))continue;let r=j(t);if(r===null||typeof t.start!=`number`||typeof t.end!=`number`)continue;let i=n.get(t);if(!(i&&(i?.type===`ImportDeclaration`&&i.source===t||i?.type===`ExportNamedDeclaration`&&i.source===t||i?.type===`ExportAllDeclaration`&&i.source===t||i?.type===`ImportExpression`&&i.source===t)))continue;let a=L(r,e.fromFileName,e.outputs),o=a?e.logicalOutputIds.get(a):void 0;o&&s.push({start:t.start,end:t.end,value:JSON.stringify(`${o}${R(r)}`)})}return{code:F(e.code,s),observesFileName:r.some(e=>_e(e)&&!C(e,o)&&!i.allowedImportMetaUrls.has(n.get(e)??e)),storyRegistryChunks:a.storyChunks}}function se(e){let t=()=>({ranges:[],storyChunks:new Set});if(!e.viteMapEvidence.declarator)return t();let n=new Map(e.viteMapEvidence.calls.map(e=>[e.outer,e])),r=[],i=new Set;for(let t of e.nodes){if(t.type!==`ObjectExpression`||!Array.isArray(t.properties)||t.properties.length===0||typeof t.start!=`number`||typeof t.end!=`number`)continue;let a=new Set,o=new Set;if(t.properties.every(t=>{if(!N(t)||t.type!==`Property`||t.computed!==!1||t.kind!==`init`||t.method!==!1||t.shorthand!==!1)return!1;let r=N(t.key)?j(t.key):null;if(!r||a.has(r)||!H(r)||!r.startsWith(`./`))return!1;a.add(r);let i=ce({key:r,value:t.value,projectRoot:e.projectRoot,fromFileName:e.fromFileName,outputs:e.outputs,directStoryChunks:e.directStoryChunks,callsByOuter:n});return i?(o.add(i),!0):!1})){r.push({start:t.start,end:t.end});for(let e of o)i.add(e)}}return{ranges:r,storyChunks:i}}function ce(e){let t=e.value;if(!N(t)||t.type!==`ArrowFunctionExpression`||t.async!==!1||t.generator!==!1||!Array.isArray(t.params)||t.params.length!==0||!N(t.body)||t.body.type!==`CallExpression`)return null;let n=t.body,r=e.callsByOuter.get(n);if(!r||!Array.isArray(n.arguments)||n.arguments.length!==3||n.arguments[1]!==r.call||n.arguments[2]!==r.importMetaUrl)return null;let i=n.arguments[0];if(!N(i)||i.type!==`ArrowFunctionExpression`||i.async!==!1||i.generator!==!1||!Array.isArray(i.params)||i.params.length!==0||!N(i.body)||i.body.type!==`ImportExpression`||!N(i.body.source))return null;let a=j(i.body.source),o=a?L(a,e.fromFileName,e.outputs):void 0,s=o?e.outputs.get(o):void 0;if(!o||!e.directStoryChunks.has(o)||s?.type!==`chunk`)return null;let c;try{c=K(e.key.slice(2),`generated story registry key`,!1)}catch{return null}return Object.keys(s.modules).some(t=>{let n=q(t,e.projectRoot);return n.kind===`project`&&(n.path===c||n.path.endsWith(`/${c}`))})?o:null}function C(e,t){return typeof e.start!=`number`||typeof e.end!=`number`?!1:t.some(t=>e.start>=t.start&&e.end<=t.end)}function le(e){let t=()=>({literals:[],allowedImportMetaUrls:new Set,calls:[]}),{nodes:n,parents:r}=e,i=n.find(e=>e.type===`VariableDeclarator`&&P(e.id,`__vite__mapDeps`)&&N(e.init)&&e.init.type===`ArrowFunctionExpression`);if(!i||!N(i.init))return t();let a=ue(i,r);if(!a||!Array.isArray(a.elements))return t();let o=a.elements.filter(e=>N(e)&&e.type===`Literal`&&typeof e.value==`string`);if(o.length!==a.elements.length)return t();let s=new Set,c=new Set,l=[];for(let a of n){if(!P(a,`__vite__mapDeps`)||a===i.id)continue;let n=r.get(a);if(n?.type===`AssignmentPattern`&&n.right===a)continue;if(n?.type!==`CallExpression`||n.callee!==a)return t();let u=T(n,e,o.length);if(!u)return t();for(let e of u.indexes)c.add(e);s.add(u.importMetaUrl),l.push({call:n,...u})}return o.some((e,t)=>!c.has(t))?t():{declarator:i,literals:o,allowedImportMetaUrls:s,calls:l}}function ue(e,t){let n=t.get(e);if(n?.type!==`VariableDeclaration`||n.kind!==`const`||!Array.isArray(n.declarations)||n.declarations.length!==1||n.declarations[0]!==e)return null;let r=e.init;if(!N(r)||r.type!==`ArrowFunctionExpression`||r.async!==!1||r.generator!==!1||!Array.isArray(r.params)||r.params.length!==3||!P(r.params[0],`i`))return null;let i=r.params[1],a=r.params[2];return!N(i)||i.type!==`AssignmentPattern`||!P(i.left,`m`)||!P(i.right,`__vite__mapDeps`)||!N(a)||a.type!==`AssignmentPattern`||!P(a.left,`d`)||!N(a.right)||a.right.type!==`LogicalExpression`||a.right.operator!==`||`||!A(a.right.left,`m`,`f`)||!N(a.right.right)||a.right.right.type!==`AssignmentExpression`||a.right.right.operator!==`=`||!A(a.right.right.left,`m`,`f`)||!N(a.right.right.right)||a.right.right.right.type!==`ArrayExpression`||!w(r.body)?null:a.right.right.right}function w(e){if(!N(e)||e.type!==`CallExpression`||!N(e.callee)||e.callee.type!==`MemberExpression`||e.callee.computed!==!1||!P(e.callee.object,`i`)||!P(e.callee.property,`map`)||!Array.isArray(e.arguments)||e.arguments.length!==1)return!1;let t=e.arguments[0];return N(t)&&t.type===`ArrowFunctionExpression`&&t.async===!1&&t.generator===!1&&Array.isArray(t.params)&&t.params.length===1&&P(t.params[0],`i`)&&N(t.body)&&t.body.type===`MemberExpression`&&t.body.computed===!0&&P(t.body.object,`d`)&&P(t.body.property,`i`)}function T(e,t,n){if(!Array.isArray(e.arguments)||e.arguments.length!==1)return null;let r=e.arguments[0];if(!N(r)||r.type!==`ArrayExpression`||!Array.isArray(r.elements))return null;let i=r.elements.map(e=>N(e)&&e.type===`Literal`&&typeof e.value==`number`&&Number.isInteger(e.value)&&e.value>=0&&e.value<n?e.value:null);if(i.some(e=>e===null))return null;let a=t.parents.get(e);return a?.type!==`CallExpression`||!Array.isArray(a.arguments)||a.arguments.length!==3||a.arguments[1]!==e||!N(a.arguments[2])||!ge(a.arguments[2])||!de(a.callee,t)?null:{outer:a,indexes:i,importMetaUrl:a.arguments[2]}}const E=new Set([`4f5090408061e66b82e2a30dd449c982fdb4a6586d712ab6bb5614e01656fa23`]);function de(e,t){if(!N(e)||e.type!==`Identifier`||typeof e.name!=`string`)return!1;let n=pe(e,t.parents);if(!n||!P(n.imported,`t`))return!1;let r=t.parents.get(n);if(r?.type!==`ImportDeclaration`||!N(r.source))return!1;let i=j(r.source),a=i?L(i,t.fromFileName,t.outputs):void 0,o=a?t.outputs.get(a):void 0;return!o||o.type!==`chunk`||!t.parseCode||typeof o.code!=`string`?!1:E.has(fe(o.code,t.parseCode))}function fe(e,t){let n;try{n=t(e)}catch{return``}let r=[];return M(n,void 0,(e,t)=>{t?.type===`ImportDeclaration`&&t.source===e&&typeof e.start==`number`&&typeof e.end==`number`&&r.push({start:e.start,end:e.end,value:JSON.stringify(`kapture-import:${r.length}`)})}),U(F(e,r))}function pe(e,t){let n=e.name;if(typeof n!=`string`)return null;let r=t.get(e);for(;r;){if(k(r)&&(O(r.params,n)||O(r.id,n)||D(r.body,n))||r.type===`CatchClause`&&O(r.param,n)||me(r,n)||r.type===`BlockStatement`&&he(r,n))return null;if(r.type===`Program`){let e=[];return M(r,void 0,(t,r)=>{t.type===`ImportSpecifier`&&P(t.local,n)&&r?.type===`ImportDeclaration`&&e.push(t)}),e.length===1?e[0]??null:null}r=t.get(r)}return null}function D(e,t,n=!0){return Array.isArray(e)?e.some(e=>D(e,t,!1)):!N(e)||!n&&(k(e)||e.type.includes(`Class`))?!1:e.type===`VariableDeclaration`&&e.kind===`var`&&Array.isArray(e.declarations)&&e.declarations.some(e=>N(e)&&O(e.id,t))?!0:Object.entries(e).some(([e,n])=>e!==`loc`&&e!==`start`&&e!==`end`&&e!==`type`&&D(n,t,!1))}function me(e,t){let n=e.type===`ForStatement`?e.init:e.type===`ForInStatement`||e.type===`ForOfStatement`?e.left:void 0;return N(n)&&n.type===`VariableDeclaration`&&Array.isArray(n.declarations)&&n.declarations.some(e=>N(e)&&O(e.id,t))}function he(e,t){return Array.isArray(e.body)?e.body.some(e=>N(e)?e.type===`VariableDeclaration`&&Array.isArray(e.declarations)?e.declarations.some(e=>N(e)&&O(e.id,t)):(e.type===`FunctionDeclaration`||e.type===`ClassDeclaration`)&&P(e.id,t):!1):!1}function O(e,t){let n=!1;return M(e,void 0,e=>{P(e,t)&&(n=!0)}),n}function k(e){return[`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`].includes(e.type)}function A(e,t,n){return N(e)&&e.type===`MemberExpression`&&e.computed===!1&&P(e.object,t)&&P(e.property,n)}function ge(e){return N(e)&&e.type===`MemberExpression`&&N(e.object)&&e.object.type===`MetaProperty`&&P(e.object.meta,`import`)&&P(e.object.property,`meta`)&&P(e.property,`url`)}function _e(e){return N(e)&&e.type===`MetaProperty`&&P(e.meta,`import`)&&P(e.property,`meta`)}function j(e){if(e.type===`Literal`&&typeof e.value==`string`)return e.value;if(e.type!==`TemplateLiteral`||!Array.isArray(e.expressions)||e.expressions.length||!Array.isArray(e.quasis)||e.quasis.length!==1||!N(e.quasis[0]))return null;let t=e.quasis[0].value;return typeof t==`object`&&t&&`cooked`in t&&typeof t.cooked==`string`?t.cooked:null}function M(e,t,n){if(Array.isArray(e)){for(let r of e)M(r,t,n);return}if(N(e)){n(e,t);for(let[t,r]of Object.entries(e))t!==`loc`&&t!==`start`&&t!==`end`&&t!==`type`&&M(r,e,n)}}function N(e){return typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`}function P(e,t){return N(e)&&e.type===`Identifier`&&e.name===t}function F(e,t){let n=e;for(let e of t.sort((e,t)=>t.start-e.start))n=`${n.slice(0,e.start)}${e.value}${n.slice(e.end)}`;return n}function I(e,t,n,r){return e.map(e=>{let i=L(e,t,n),a=i&&r.get(i);return a?`${a}${R(e)}`:z(e)}).sort()}function L(e,t,n){let r=e.split(/[?#]/,1)[0]?.replaceAll(`\\`,`/`)??``;return[r.replace(/^\/+/,``),c.normalize(c.join(c.dirname(t),r))].find(e=>n.has(e))}function R(e){let t=e.search(/[?#]/);return t===-1?``:e.slice(t)}function z(e){return K(e,`bundle output`,!1)}function ve(e,t,n){return e.source===null?``:F(e.source,e.loadReferences.flatMap(t=>{let r=n.get(t.target);return r?[{start:t.start,end:t.end,value:JSON.stringify(`${r}${R(e.source?.slice(t.start,t.end)??``)}`)}]:[]}))}function ye(e){let t=[],n=0;for(;n<e.length;){let r=e.indexOf(`<`,n);if(r===-1)break;if(e.startsWith(`<!--`,r)){let t=e.indexOf(`-->`,r+4);n=t===-1?e.length:t+3;continue}let i=e.slice(r+1).match(/^\/?\s*([A-Za-z][\w:-]*)/);if(!i?.[1]||e[r+1]===`/`){n=r+1;continue}let a=i[1].toLowerCase(),o=be(e,r+1);if(o===-1)break;let s=xe(e.slice(r,o+1),r),c=new Map(s.map(e=>[e.name,e]));if(a===`script`){let e=c.get(`src`);e&&t.push({start:e.start,end:e.end,value:e.value,loadsJavaScript:!0,requiresBundleTarget:!/^(?:https?:)?\/\//i.test(e.value)})}else if(a===`link`){let e=c.get(`href`),n=c.get(`rel`)?.value.toLowerCase().split(/\s+/)??[];if(e&&n.some(e=>[`modulepreload`,`preload`,`stylesheet`].includes(e))){let r=/^(?:https?:)?\/\//i.test(e.value);t.push({start:e.start,end:e.end,value:e.value,loadsJavaScript:n.includes(`modulepreload`),requiresBundleTarget:!r})}}if(n=o+1,[`script`,`style`,`textarea`,`title`].includes(a)){let t=e.toLowerCase().indexOf(`</${a}`,n);t!==-1&&(n=t)}}return t}function be(e,t){let n=``;for(let r=t;r<e.length;r+=1){let t=e[r]??``;if(n)t===n&&(n=``);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}function xe(e,t){let n=[];for(let r of e.matchAll(/([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g)){let e=r[2]??r[3]??r[4];if(e===void 0||r.index===void 0)continue;let i=r[0].lastIndexOf(e);n.push({name:(r[1]??``).toLowerCase(),value:e,start:t+r.index+i,end:t+r.index+i+e.length})}return n}function Se(e){let t=Ce(e);for(let n of e.containerChunks){let r=e.outputs.get(n);if(!(!r||r.type!==`chunk`))for(let i of r.viteMetadata?.importedCss??[]){let r=L(i,n,e.outputs);r&&t.add(r)}}let n=new Map;for(let r of e.chunks){let i=new Set(r.viteMetadata?.importedCss??[]);for(let a of i){let i=e.outputs.get(a);if(!i||i.type!==`asset`||!i.fileName.toLowerCase().endsWith(`.css`)||!V(i.fileName))continue;let o=K(i.fileName,`bundle asset reference`,!1);if(t.has(o))continue;let s=n.get(o)??new Set;s.add(r.fileName),n.set(o,s)}}let r=new Map;for(let t of e.outputs.values()){if(t.type!==`asset`||!V(t.fileName))continue;let e=K(t.fileName,`bundle asset`,!1);r.set(e,new Set)}for(let[t,i]of e.entries)for(let[e,a]of n)[...a].some(e=>i.chunks.has(e))&&r.get(e)?.add(t);return r}function Ce(e){let t=new Map;for(let n of e.outputs.values())n.type===`asset`&&t.set(K(n.fileName,`bundle asset`,!1),n);let n=[...t].filter(([e])=>e.toLowerCase()===`iframe.html`);if(n.some(([,e])=>B(e)===null))return new Set([...t.keys()].filter(e=>V(e)));let r=new Set,i=n.map(([e])=>e);for(;i.length>0;){let e=i.pop();if(!e)continue;let n=B(t.get(e));if(n!==null)for(let[a]of t)a===e||r.has(a)||!n.includes(a)||(r.add(a),i.push(a))}return r}function B(e){return typeof e?.source==`string`?e.source:e?.source instanceof Uint8Array?new TextDecoder().decode(e.source):null}function V(e){let t=e.replaceAll(`\\`,`/`).toLowerCase();return t!==`kapture-dependencies.json`&&t!==`iframe.html`}function we(e){return e.type===`chunk`?typeof e.code==`string`?new TextEncoder().encode(e.code):null:typeof e.source==`string`?new TextEncoder().encode(e.source):e.source instanceof Uint8Array?e.source:null}function H(e){return/\.(?:stories|story)\.[cm]?[jt]sx?(?:[?#]|$)/i.test(e)}function U(t){return e(`sha256`).update(t).digest(`hex`)}function W(e,t){let n=t.replaceAll(`\\`,`/`),r=new Set([t,n,n.replaceAll(`/`,`\\`),encodeURI(n)]),i=e;for(let e of[...r].filter(Boolean).sort((e,t)=>t.length-e.length))i=i.replaceAll(e,`<projectRoot>`),i=i.replaceAll(e.replaceAll(`\\`,`\\\\`),`<projectRoot>`);return i}function Te(e,t){let n=new Set(e),r=Object.keys(t).filter(t=>e.some(e=>Ee(t,e)));for(;r.length>0;){let e=r.pop();if(e)for(let i of t[e]??[])n.has(i)||(n.add(i),r.push(i))}return[...n].sort()}function Ee(e,t){if(e===t)return!0;try{return s(e,t)}catch(e){throw Error(`Invalid globalInputs pattern: ${t}`,{cause:e})}}function G(e,t){let n=e.map((e,n)=>K(e,`${t}[${n}]`,!1));return[...new Set(n)].sort()}function K(e,t,n){let r=e.replaceAll(`\\`,`/`).replace(/^\.\//,``).replace(/\/{2,}/g,`/`),i=r===``?``:c.normalize(r).replace(/\/$/,``);if(!n&&i.length===0||i.includes(`\0`))throw Error(`${t} must be a non-empty project-relative path`);if(o(i)||i===`..`||i.startsWith(`../`))throw Error(`${t} must stay within projectRoot`);return i}function q(e,t){let n=J(e);if(!n||m.some(e=>n.startsWith(e))||/^(?:node:|https?:|data:)/.test(n))return{kind:`external`};let r=n;if(r.startsWith(`file://`))try{r=f(r)}catch{return{kind:`external`}}if(!o(r)||De(r))return{kind:`external`};let i=l(t,r);return i===``||i===`.`?{kind:`external`}:i===`..`||i.startsWith(`..${d}`)||o(i)?{kind:`outside`}:{kind:`project`,path:i.split(d).join(`/`)}}function J(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=Math.min(t===-1?e.length:t,n===-1?e.length:n);return e.slice(0,r)}function De(e){return e.split(d).join(`/`).includes(`/node_modules/`)}function Y(e){return m.some(t=>e.startsWith(t))}function Oe(e,t){let n=new Set,r=[...e].flatMap(e=>[...t.get(e)??[]]);for(;r.length>0;){let e=r.pop();if(!(!e||n.has(e)||!Y(e))){n.add(e);for(let n of t.get(e)??[])r.push(n)}}return n}function ke(e){let t=J(e);return t.length>0&&!o(t)&&!t.startsWith(`file://`)&&!/^(?:node:|https?:|data:)/.test(t)&&!Y(t)}const Ae=[`package.json`,`bun.lock`,`package-lock.json`,`pnpm-lock.yaml`,`yarn.lock`];async function je(e,t){let n=process.cwd(),r=u(n,t.projectRoot??`.`),i=l(r,n);if(i===`..`||i.startsWith(`..${process.platform===`win32`?`\\`:`/`}`))throw Error(`@kaptures/storybook preset projectRoot must contain Storybook's working directory`);let a=t.configDir?l(r,u(t.configDir)):null,o=[...Ae,...a&&!a.startsWith(`..`)?[`${$(a)}/**`]:[],...t.globalInputs??[]];return{...e,plugins:[...e.plugins??[],X({projectRoot:r,storybookRoot:$(i),globalInputs:o,ignoredInputs:t.ignoredInputs??[],fingerprintedInputs:t.fingerprintedInputs??[]})]}}function X(e){let t=new Map;return{name:`kapture:storybook-dependencies`,apply:`build`,moduleParsed(e){t.set(e.id,{id:e.id,importedIds:[...e.importedIds??[]],dynamicallyImportedIds:[...e.dynamicallyImportedIds??[]],code:e.code,sourceFingerprint:Ne(e.id)})},generateBundle:{order:`post`,handler(n,r){let i=Z(e,t.values(),r,e=>this.parse(e));this.emitFile({type:`asset`,fileName:p,source:`${JSON.stringify(i,null,2)}\n`})}},writeBundle:{order:`post`,handler(n,r){let o=n.dir?u(n.dir):n.file?a(u(n.file)):null;if(!o)throw Error(`@kaptures/storybook requires a Rollup output directory`);let s=Z(e,t.values(),r,e=>this.parse(e),o);i(u(o,p),`${JSON.stringify(s,null,2)}\n`)}}}}function Z(e,t,n,r,i){let a=[...t],o=_({projectRoot:e.projectRoot,modules:a,bundle:n,parseCode:r}),s=h({...e,containerModuleIds:o.containerModuleIds,modules:a});s.renderedModules=o.renderedModules,s.renderedOutputFingerprints=o.renderedOutputFingerprints,s.globalOutputFingerprints=o.globalOutputFingerprints,s.globalOutputStories=o.globalOutputStories,s.globalRuntimeFingerprint=o.globalRuntimeFingerprint;let c=v(n),l=v(n,i);Object.assign(s,l);for(let[e,t]of Object.entries(l.outputInventory))e in c.outputInventory||Q(e)||(s.globalOutputFingerprints[e]=t.sha256,s.globalOutputStories[e]=[]);let u=Object.entries(c.outputInventory).some(([e,t])=>{let n=l.outputInventory[e];return!n||n.type!==t.type||n.size!==t.size||n.sha256!==t.sha256});return s.diagnostics=[...new Set([...s.diagnostics,...o.diagnostics,...u?[`output-inventory-mismatch`]:[]])].sort(),s.complete=s.diagnostics.length===0,s}function Q(e){return[`index.html`,`index.json`,`project.json`,`favicon.svg`,`favicon-wrapper.svg`,`nunito-sans-bold-italic.woff2`,`nunito-sans-bold.woff2`,`nunito-sans-italic.woff2`,`nunito-sans-regular.woff2`].includes(e)||[`sb-addons/`,`sb-common-assets/`,`sb-manager/`].some(t=>e.startsWith(t))}function $(e){return e.replaceAll(`\\`,`/`)}const Me=/\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss|apng|bmp|png|jpe?g|jfif|pjpeg|pjp|gif|svg|ico|webp|avif|cur|jxl|mp4|webm|ogg|mp3|wav|flac|aac|opus|mov|m4a|vtt|woff2?|eot|ttf|otf|webmanifest|pdf|txt|wasm)$/i;function Ne(t){let r=t.indexOf(`?`),i=t.indexOf(`#`),a=Math.min(r===-1?t.length:r,i===-1?t.length:i),s=t.slice(0,a);if(s.startsWith(`file://`))try{s=f(s)}catch{return}if(!(!o(s)||s.replaceAll(`\\`,`/`).includes(`/node_modules/`)||!Me.test(s)))try{return e(`sha256`).update(n(s)).digest(`hex`)}catch{return}}export{p as KAPTURE_DEPENDENCY_MANIFEST_FILE,h as buildKaptureDependencyManifest,v as buildKaptureOutputInventory,_ as buildKaptureRenderedEvidence,g as buildKaptureRenderedModuleClosures,X as createKaptureDependencyPlugin,je as viteFinal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaptures/storybook",
3
- "version": "0.11.1",
3
+ "version": "0.12.1",
4
4
  "description": "Typed Storybook lifecycle adapter for Kapture visual review",
5
5
  "type": "module",
6
6
  "license": "MIT",