@kaptures/storybook 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
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.
|
|
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.8.0`;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};
|