@visual-check/storybook 0.0.0 → 0.1.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD-PARTY-NOTICES.md +51 -0
  3. package/dist/angular-port/combinations.d.ts +89 -0
  4. package/dist/angular-port/combinations.d.ts.map +1 -0
  5. package/dist/angular-port/combinations.js +97 -0
  6. package/dist/angular-port/combinations.js.map +1 -0
  7. package/dist/angular.d.ts +4 -0
  8. package/dist/angular.d.ts.map +1 -0
  9. package/dist/angular.js +4 -0
  10. package/dist/angular.js.map +1 -0
  11. package/dist/dom-port/combinations.d.ts +59 -0
  12. package/dist/dom-port/combinations.d.ts.map +1 -0
  13. package/dist/dom-port/combinations.js +137 -0
  14. package/dist/dom-port/combinations.js.map +1 -0
  15. package/dist/forced-state/force-states.d.ts +68 -0
  16. package/dist/forced-state/force-states.d.ts.map +1 -0
  17. package/dist/forced-state/force-states.js +388 -0
  18. package/dist/forced-state/force-states.js.map +1 -0
  19. package/dist/forced-state/forced-states.d.ts +27 -0
  20. package/dist/forced-state/forced-states.d.ts.map +1 -0
  21. package/dist/forced-state/forced-states.js +41 -0
  22. package/dist/forced-state/forced-states.js.map +1 -0
  23. package/dist/forced-state/prototype-hooks.d.ts +28 -0
  24. package/dist/forced-state/prototype-hooks.d.ts.map +1 -0
  25. package/dist/forced-state/prototype-hooks.js +49 -0
  26. package/dist/forced-state/prototype-hooks.js.map +1 -0
  27. package/dist/forced-state/style-sheet-rewrite.d.ts +29 -0
  28. package/dist/forced-state/style-sheet-rewrite.d.ts.map +1 -0
  29. package/dist/forced-state/style-sheet-rewrite.js +148 -0
  30. package/dist/forced-state/style-sheet-rewrite.js.map +1 -0
  31. package/dist/forced-state/twin-selectors.d.ts +21 -0
  32. package/dist/forced-state/twin-selectors.d.ts.map +1 -0
  33. package/dist/forced-state/twin-selectors.js +316 -0
  34. package/dist/forced-state/twin-selectors.js.map +1 -0
  35. package/dist/grid-story/grid-layout.d.ts +156 -0
  36. package/dist/grid-story/grid-layout.d.ts.map +1 -0
  37. package/dist/grid-story/grid-layout.js +163 -0
  38. package/dist/grid-story/grid-layout.js.map +1 -0
  39. package/dist/index.d.ts +8 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +6 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/per-story-options/define-visual-check.d.ts +247 -0
  44. package/dist/per-story-options/define-visual-check.d.ts.map +1 -0
  45. package/dist/per-story-options/define-visual-check.js +60 -0
  46. package/dist/per-story-options/define-visual-check.js.map +1 -0
  47. package/dist/react-port/combinations.d.ts +27 -0
  48. package/dist/react-port/combinations.d.ts.map +1 -0
  49. package/dist/react-port/combinations.js +45 -0
  50. package/dist/react-port/combinations.js.map +1 -0
  51. package/dist/react.d.ts +4 -0
  52. package/dist/react.d.ts.map +1 -0
  53. package/dist/react.js +4 -0
  54. package/dist/react.js.map +1 -0
  55. package/dist/vue-port/combinations.d.ts +35 -0
  56. package/dist/vue-port/combinations.d.ts.map +1 -0
  57. package/dist/vue-port/combinations.js +75 -0
  58. package/dist/vue-port/combinations.js.map +1 -0
  59. package/dist/vue.d.ts +4 -0
  60. package/dist/vue.d.ts.map +1 -0
  61. package/dist/vue.js +4 -0
  62. package/dist/vue.js.map +1 -0
  63. package/package.json +78 -4
  64. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-layout.d.ts","sourceRoot":"","sources":["../../src/grid-story/grid-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,WAAW,EAAsB,MAAM,kCAAkC,CAAA;AAExG;;;;GAIG;AACH,eAAO,MAAM,aAAa,2BAA2B,CAAA;AAErD;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI;IAAE,QAAQ,EAAE,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE,SAAS,KAAK,CAAC,IAAI,CAAC,EAAE;CAA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AC/B;;OAEG;IACH,KAAK,EAAE,SAAS,CAAA;IAChB;;OAEG;IACH,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAA;IACtB;;;OAGG;IACH,MAAM,EAAE,WAAW,EAAE,CAAA;CACtB;AA8JD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CA2B7F"}
@@ -0,0 +1,163 @@
1
+ import { checkedStatesOf, forcedStateClassOf } from '../forced-state/forced-states.js';
2
+ /**
3
+ * The attribute the grid's element carries, empty, which capture finds a grid by.
4
+ *
5
+ * @public
6
+ */
7
+ export const gridAttribute = 'data-visual-check-grid';
8
+ /**
9
+ * The gap between two columns, in CSS pixels.
10
+ */
11
+ const columnGap = 16;
12
+ /**
13
+ * The space above every row's caption but the first, in CSS pixels.
14
+ */
15
+ const rowGap = 16;
16
+ /**
17
+ * The space between a caption and its row's cells, in CSS pixels.
18
+ */
19
+ const captionGap = 4;
20
+ /**
21
+ * The space between the header row and the first row, in CSS pixels.
22
+ */
23
+ const headerGap = 16;
24
+ /**
25
+ * The styles captions and headers share: small grey monospace, their text never widening a column. Each use puts
26
+ * the `all: 'initial'` reset first.
27
+ */
28
+ const labelStyle = {
29
+ contain: 'inline-size',
30
+ 'font-family': 'monospace',
31
+ 'font-size': '11px',
32
+ 'line-height': '14px',
33
+ color: '#737373',
34
+ 'overflow-wrap': 'anywhere',
35
+ };
36
+ /**
37
+ * Every combination of the listed values, in the entries' order, the last prop changing fastest.
38
+ *
39
+ * @throws When a prop lists no values.
40
+ */
41
+ function combinationsOf(entries) {
42
+ return entries.reduce((rows, [name, values]) => {
43
+ if (values.length === 0) {
44
+ throw new Error(`visual-check: the grid lists no values for the prop "${name}".`);
45
+ }
46
+ return rows.flatMap((row) => values.map((value) => ({ ...row, [name]: value })));
47
+ }, [{}]);
48
+ }
49
+ /**
50
+ * How a value reads in a default caption: strings as they are, numbers, booleans, `null` and `undefined` through
51
+ * `String()`, anything else an ellipsis.
52
+ */
53
+ function captionValueOf(value) {
54
+ if (typeof value === 'string') {
55
+ return value;
56
+ }
57
+ if (typeof value === 'number' || typeof value === 'boolean' || value === null || value === undefined) {
58
+ return String(value);
59
+ }
60
+ return '…';
61
+ }
62
+ /**
63
+ * A caption's text: `caption`'s result when given, else `key: value` for each varying prop, joined by `, `.
64
+ */
65
+ function captionTextOf(varying, caption) {
66
+ if (caption) {
67
+ return caption(varying);
68
+ }
69
+ return Object.entries(varying)
70
+ .map(([name, value]) => `${name}: ${captionValueOf(value)}`)
71
+ .join(', ');
72
+ }
73
+ /**
74
+ * The grid element's styles: one column per entry, as wide as its widest cell or `cellWidth`. Only properties that
75
+ * aren't inherited, so cells inherit from the page.
76
+ */
77
+ function gridStyleOf(columns, cellWidth) {
78
+ const column = cellWidth === undefined ? 'max-content' : `${cellWidth}px`;
79
+ return {
80
+ display: 'grid',
81
+ 'grid-template-columns': Array.from({ length: columns }, () => column).join(' '),
82
+ 'column-gap': `${columnGap}px`,
83
+ 'row-gap': '0',
84
+ width: 'max-content',
85
+ margin: '0',
86
+ padding: '0',
87
+ border: 'none',
88
+ background: 'none',
89
+ };
90
+ }
91
+ /**
92
+ * A caption element's styles: reset, spanning every column, its text never widening a column.
93
+ */
94
+ function captionStyleOf(rowIndex) {
95
+ const top = rowIndex === 0 ? '0' : `${rowGap}px`;
96
+ return {
97
+ all: 'initial',
98
+ display: 'block',
99
+ 'grid-column': '1 / -1',
100
+ margin: `${top} 0 ${captionGap}px`,
101
+ ...labelStyle,
102
+ };
103
+ }
104
+ /**
105
+ * The header row: none without states, else `default` then `:<state>` for each state, in one grid row above the
106
+ * first caption.
107
+ */
108
+ function headersOf(states) {
109
+ if (states.length === 0) {
110
+ return [];
111
+ }
112
+ const style = { all: 'initial', display: 'block', margin: `0 0 ${headerGap}px`, ...labelStyle };
113
+ return ['default', ...states.map((state) => `:${state}`)].map((text) => ({ text, style }));
114
+ }
115
+ /**
116
+ * A row's cells: the default state's, then each state's with its class, all styled alike.
117
+ */
118
+ function cellsOf(states, cellWidth) {
119
+ const style = cellStyleOf(cellWidth);
120
+ return [null, ...states.map(forcedStateClassOf)].map((stateClass) => ({ style, stateClass }));
121
+ }
122
+ /**
123
+ * A cell element's styles: aligned to the start, and exactly `cellWidth` wide when given.
124
+ */
125
+ function cellStyleOf(cellWidth) {
126
+ const alignment = { 'justify-self': 'start', 'align-self': 'start' };
127
+ if (cellWidth === undefined) {
128
+ return alignment;
129
+ }
130
+ return { ...alignment, width: `${cellWidth}px` };
131
+ }
132
+ /**
133
+ * Works out a grid: its columns (the default state's, then one per forced state), its header row, its rows (every
134
+ * combination of the listed props), each caption's text and every element's inline styles. Each port only turns the
135
+ * layout into elements, and forces the layout's states while it's shown.
136
+ *
137
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice.
138
+ * @public
139
+ */
140
+ export function gridLayoutOf(input) {
141
+ const states = checkedStatesOf(input.states ?? [], 'the grid');
142
+ const entries = Object.entries(input.props).filter((entry) => entry[1] !== undefined);
143
+ const varyingNames = entries.filter(([, values]) => values.length > 1).map(([name]) => name);
144
+ // Safe: `caption` only ever gets values taken from `props`, which are `PropValues<Props>`.
145
+ const caption = input.caption;
146
+ const rows = combinationsOf(entries).map((combination, rowIndex) => {
147
+ const varying = Object.fromEntries(varyingNames.map((name) => [name, combination[name]]));
148
+ return {
149
+ // The contract, not the types, makes this whole: `args` and `props` together hold every prop the component
150
+ // requires. One cast here spares every port its own.
151
+ props: { ...input.args, ...combination },
152
+ caption: varyingNames.length === 0 ? null : { text: captionTextOf(varying, caption), style: captionStyleOf(rowIndex) },
153
+ cells: cellsOf(states, input.cellWidth),
154
+ };
155
+ });
156
+ return {
157
+ style: gridStyleOf(1 + states.length, input.cellWidth),
158
+ headers: headersOf(states),
159
+ rows,
160
+ states,
161
+ };
162
+ }
163
+ //# sourceMappingURL=grid-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-layout.js","sourceRoot":"","sources":["../../src/grid-story/grid-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAoB,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAExG;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,wBAAwB,CAAA;AAmJrD;;GAEG;AACH,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB;;GAEG;AACH,MAAM,MAAM,GAAG,EAAE,CAAA;AAEjB;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,CAAA;AAEpB;;GAEG;AACH,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB;;;GAGG;AACH,MAAM,UAAU,GAAc;IAC5B,OAAO,EAAE,aAAa;IACtB,aAAa,EAAE,WAAW;IAC1B,WAAW,EAAE,MAAM;IACnB,aAAa,EAAE,MAAM;IACrB,KAAK,EAAE,SAAS;IAChB,eAAe,EAAE,UAAU;CAC5B,CAAA;AAOD;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAuC;IAC7D,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;QACvB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,wDAAwD,IAAI,IAAI,CAAC,CAAA;QACnF,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IAClF,CAAC,EACD,CAAC,EAAE,CAAC,CACL,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,cAA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IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE;YAC/G,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;SACxC,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,KAAK,EAAE,WAAW,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;QACtD,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC;QAC1B,IAAI;QACJ,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type CombinationsInput, combinations } from './dom-port/combinations.js';
2
+ import { forceStates } from './forced-state/force-states.js';
3
+ import type { ForcedState } from './forced-state/forced-states.js';
4
+ import { type GridCaption, type GridCell, type GridHeader, type GridInput, type GridLayout, type GridRow, type GridStyle, gridAttribute, gridLayoutOf, type PropValues } from './grid-story/grid-layout.js';
5
+ import { defineVisualCheck, type GlobalValue, type Mask, type ModeDefinition, type Tolerance, type Viewport, type VisualCheck, type VisualCheckDeclaration, type VisualCheckOptions, type VisualCheckParameter, type WaitHook, type WrittenMask } from './per-story-options/define-visual-check.js';
6
+ export type { CombinationsInput, ForcedState, GlobalValue, GridCaption, GridCell, GridHeader, GridInput, GridLayout, GridRow, GridStyle, Mask, ModeDefinition, PropValues, Tolerance, Viewport, VisualCheck, VisualCheckDeclaration, VisualCheckOptions, VisualCheckParameter, WaitHook, WrittenMask, };
7
+ export { combinations, defineVisualCheck, forceStates, gridAttribute, gridLayoutOf };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,aAAa,EACb,YAAY,EACZ,KAAK,UAAU,EAChB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,QAAQ,EACb,KAAK,WAAW,EACjB,MAAM,4CAA4C,CAAA;AAEnD,YAAY,EACV,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,WAAW,EACX,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,SAAS,EACT,IAAI,EACJ,cAAc,EACd,UAAU,EACV,SAAS,EACT,QAAQ,EACR,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,QAAQ,EACR,WAAW,GACZ,CAAA;AACD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { combinations } from './dom-port/combinations.js';
2
+ import { forceStates } from './forced-state/force-states.js';
3
+ import { gridAttribute, gridLayoutOf, } from './grid-story/grid-layout.js';
4
+ import { defineVisualCheck, } from './per-story-options/define-visual-check.js';
5
+ export { combinations, defineVisualCheck, forceStates, gridAttribute, gridLayoutOf };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAE5D,OAAO,EAQL,aAAa,EACb,YAAY,GAEb,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,iBAAiB,GAYlB,MAAM,4CAA4C,CAAA;AAyBnD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,247 @@
1
+ import type { StoryContext } from 'storybook/internal/types';
2
+ /**
3
+ * A value of a Storybook global: what a mode sets and what the story's URL carries.
4
+ *
5
+ * @public
6
+ */
7
+ export type GlobalValue = string | number | boolean;
8
+ /**
9
+ * The size and device a story is laid out and captured at.
10
+ *
11
+ * @public
12
+ */
13
+ export interface Viewport {
14
+ /**
15
+ * The width in CSS pixels.
16
+ */
17
+ width?: number;
18
+ /**
19
+ * The height in CSS pixels.
20
+ */
21
+ height?: number;
22
+ /**
23
+ * The device pixel ratio.
24
+ */
25
+ deviceScaleFactor?: number;
26
+ /**
27
+ * Whether the browser emulates a touch device.
28
+ */
29
+ touch?: boolean;
30
+ }
31
+ /**
32
+ * How much a snapshot may differ from its baseline before it fails.
33
+ *
34
+ * @public
35
+ */
36
+ export interface Tolerance {
37
+ /**
38
+ * How far a pixel's color may move and still count as unchanged, from 0 to 1 (pixelmatch's threshold).
39
+ */
40
+ color?: number;
41
+ /**
42
+ * How many pixels may differ. A whole number of 0 or more counts differing CSS pixels: at device scale factor `s` it
43
+ * allows `⌊pixels × s²⌋` image pixels. A string from `'0%'` to `'100%'` is a share of the image's own pixels.
44
+ */
45
+ pixels?: number | `${number}%`;
46
+ }
47
+ /**
48
+ * A region that is painted over before the capture, found by a CSS selector or by the host of its remote content.
49
+ *
50
+ * @public
51
+ */
52
+ export type Mask = {
53
+ selector: string;
54
+ host?: never;
55
+ } | {
56
+ host: string;
57
+ selector?: never;
58
+ };
59
+ /**
60
+ * A mask as the helper writes it: both keys, the unused one `null`. Storybook merges two masks of the same name key by
61
+ * key, so a mask that set only `selector` would pick up a `host` from a less specific level. With `null` in the unused
62
+ * key, a more specific level always replaces the kind.
63
+ *
64
+ * @public
65
+ */
66
+ export type WrittenMask = {
67
+ selector: string;
68
+ host: null;
69
+ } | {
70
+ host: string;
71
+ selector: null;
72
+ };
73
+ /**
74
+ * What a generic that types a mode's globals must look like: global names that map to global values. It takes a `type`
75
+ * alias and an `interface` alike.
76
+ */
77
+ type GlobalsConstraint<Globals> = object & {
78
+ [Name in keyof Globals]: GlobalValue;
79
+ };
80
+ /**
81
+ * The shape of globals when no generic types them: any name, any global value.
82
+ */
83
+ type GlobalsShape = Record<string, GlobalValue>;
84
+ /**
85
+ * The globals a mode may set. A typed `Globals` makes every global optional, since a mode sets some of them. The
86
+ * untyped shape stays as it is, so that a global can't be set to `undefined`.
87
+ */
88
+ type ModeGlobals<Globals> = string extends keyof Globals ? Globals : Partial<Globals>;
89
+ /**
90
+ * A named set of globals and viewport that a story can be captured in besides its default capture.
91
+ *
92
+ * @public
93
+ */
94
+ export interface ModeDefinition<Globals extends GlobalsConstraint<Globals> = GlobalsShape> {
95
+ /**
96
+ * The Storybook globals the mode sets, which go into the story's URL. A mode sets some of the globals, not all.
97
+ */
98
+ globals?: ModeGlobals<Globals>;
99
+ /**
100
+ * The viewport the mode sets. It merges over the story's own viewport, so the mode wins.
101
+ */
102
+ viewport?: Viewport;
103
+ }
104
+ /**
105
+ * The modes a Storybook declares, once, for its project.
106
+ *
107
+ * @public
108
+ */
109
+ export interface VisualCheckDeclaration<ModeName extends string, Globals extends GlobalsConstraint<Globals> = GlobalsShape> {
110
+ /**
111
+ * The Storybook's modes by name. A name takes lowercase letters, digits and `-`.
112
+ */
113
+ modes: Record<ModeName, ModeDefinition<Globals>>;
114
+ }
115
+ /**
116
+ * A hook that runs after a story renders and before it is captured. The capture waits until it settles.
117
+ *
118
+ * It gets only the story's context as Storybook builds it, its `viewMode` and `canvasElement`, and, when the Storybook
119
+ * has `storybook/test`, `canvas` and `userEvent` as `play` gets them. Its type is Storybook's `StoryContext`, which
120
+ * names more than that.
121
+ *
122
+ * @public
123
+ */
124
+ export type WaitHook = (context: StoryContext) => void | Promise<void>;
125
+ /**
126
+ * What a project sets for a Storybook, a stories file or a story. A key set to `undefined` counts as not set.
127
+ *
128
+ * @public
129
+ */
130
+ export interface VisualCheckOptions<ModeName extends string> {
131
+ /**
132
+ * The modes to capture besides the default capture, as the exact set for these stories. `[]` captures the default
133
+ * only.
134
+ */
135
+ modes?: readonly ModeName[] | undefined;
136
+ /**
137
+ * The default capture's viewport. Deep-merges over the inherited one.
138
+ */
139
+ viewport?: Viewport | undefined;
140
+ /**
141
+ * A CSS selector for the element to capture instead of the full page. `null` returns to the full page.
142
+ */
143
+ element?: string | null | undefined;
144
+ /**
145
+ * Whether a full-page capture first grows the viewport's height to the page's, so fixed and sticky elements sit where
146
+ * they would on a screen as tall as the page. `false` keeps the viewport's height, so `100vh` stays it. Defaults to
147
+ * `true`. An element's capture never grows it.
148
+ */
149
+ growViewport?: boolean | undefined;
150
+ /**
151
+ * The regions to paint over, by name. A name set to `null` drops the inherited mask. `null` drops them all.
152
+ */
153
+ masks?: Record<string, Mask | null> | null | undefined;
154
+ /**
155
+ * How much a snapshot may differ from its baseline. Deep-merges over the inherited one.
156
+ */
157
+ tolerance?: Tolerance | undefined;
158
+ /**
159
+ * Whether to leave the stories out. `false` on a story brings it back from a disabled file.
160
+ */
161
+ disable?: boolean | undefined;
162
+ /**
163
+ * A hook to wait for before the capture. `null` turns an inherited hook off.
164
+ */
165
+ wait?: WaitHook | null | undefined;
166
+ }
167
+ /**
168
+ * What the helper writes into `parameters.visualCheck`. The same keys as the options, except two. `modes` lists every
169
+ * declared mode: its definition when the level names it, `null` when it doesn't. Each mask is written with both keys,
170
+ * the unused one `null` (see `WrittenMask`).
171
+ *
172
+ * @public
173
+ */
174
+ export interface VisualCheckParameter {
175
+ /**
176
+ * One entry per declared mode, in the declaration's key order.
177
+ */
178
+ modes?: Record<string, ModeDefinition | null>;
179
+ /**
180
+ * The default capture's viewport.
181
+ */
182
+ viewport?: Viewport;
183
+ /**
184
+ * A CSS selector for the element to capture, or `null` for the full page.
185
+ */
186
+ element?: string | null;
187
+ /**
188
+ * Whether a full-page capture first grows the viewport's height to the page's.
189
+ */
190
+ growViewport?: boolean;
191
+ /**
192
+ * The regions to paint over, by name, or `null` for none.
193
+ */
194
+ masks?: Record<string, WrittenMask | null> | null;
195
+ /**
196
+ * How much a snapshot may differ from its baseline.
197
+ */
198
+ tolerance?: Tolerance;
199
+ /**
200
+ * Whether to leave the stories out.
201
+ */
202
+ disable?: boolean;
203
+ /**
204
+ * A hook to wait for before the capture, or `null` for none.
205
+ */
206
+ wait?: WaitHook | null;
207
+ }
208
+ /**
209
+ * The function that writes `parameters.visualCheck` for one level, with mode names checked against the declaration.
210
+ *
211
+ * @public
212
+ */
213
+ export type VisualCheck<ModeName extends string> = (options: VisualCheckOptions<NoInfer<ModeName>>) => {
214
+ visualCheck: VisualCheckParameter;
215
+ };
216
+ /**
217
+ * Declares a Storybook's modes once and returns the function that writes `parameters.visualCheck`.
218
+ *
219
+ * The project calls it in `<configDir>/visual-check.ts` and exports the result as `visualCheck`. Stories files import
220
+ * that `visualCheck`, not this package, and spread its result into `parameters` of `preview`, a meta or a story:
221
+ * `parameters: { ...visualCheck({ modes: ['dark'] }) }`. Mode names are checked against the declaration.
222
+ *
223
+ * To type the globals a mode sets, pass them as a generic and call the result: `defineVisualCheck<Globals>()({ modes })`.
224
+ *
225
+ * Storybook merges the three levels, and the most specific level wins:
226
+ *
227
+ * - `modes`: the most specific list.
228
+ * - `viewport` and `tolerance`: merged key by key.
229
+ * - `masks`: merged by name. A name set to `null` drops one mask, and `masks: null` drops all of them.
230
+ * - `wait`, `element`, `growViewport` and `disable`: the most specific value.
231
+ *
232
+ * A key set to `undefined` is left out, so it never hides an inherited value. `null` is kept, and turns one off. The
233
+ * helper checks nothing at run time. visual-check validates the merged options before it captures.
234
+ *
235
+ * @public
236
+ */
237
+ export declare function defineVisualCheck<const ModeName extends string>(declaration: VisualCheckDeclaration<ModeName>): VisualCheck<ModeName>;
238
+ /**
239
+ * Types the globals a mode sets. It takes no argument and returns the function that takes the declaration, because
240
+ * TypeScript can't infer the mode names when it is given only the generic. To type the globals, pass them as a generic
241
+ * and call the result: `defineVisualCheck<Globals>()({ modes })`.
242
+ *
243
+ * @public
244
+ */
245
+ export declare function defineVisualCheck<Globals extends GlobalsConstraint<Globals>>(): <const ModeName extends string>(declaration: VisualCheckDeclaration<ModeName, Globals>) => VisualCheck<ModeName>;
246
+ export {};
247
+ //# sourceMappingURL=define-visual-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-visual-check.d.ts","sourceRoot":"","sources":["../../src/per-story-options/define-visual-check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAEnD;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,MAAM,GAAG,CAAA;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,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BAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK;IACrG,WAAW,EAAE,oBAAoB,CAAA;CAClC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,QAAQ,SAAS,MAAM,EAC7D,WAAW,EAAE,sBAAsB,CAAC,QAAQ,CAAC,GAC5C,WAAW,CAAC,QAAQ,CAAC,CAAA;AACxB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,SAAS,MAAM,EAC7G,WAAW,EAAE,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,KACnD,WAAW,CAAC,QAAQ,CAAC,CAAA"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Implements both call forms: without a declaration it returns the declarer, with one it declares the modes.
3
+ *
4
+ * @public
5
+ */
6
+ export function defineVisualCheck(declaration) {
7
+ if (declaration === undefined) {
8
+ return declareModes;
9
+ }
10
+ return declareModes(declaration);
11
+ }
12
+ /**
13
+ * Returns the function that writes `parameters.visualCheck` for the declared modes.
14
+ */
15
+ function declareModes(declaration) {
16
+ /**
17
+ * Writes the parameter for one level.
18
+ */
19
+ return function visualCheck(options) {
20
+ const { modes, masks, ...rest } = options;
21
+ const parameter = {};
22
+ for (const [key, value] of Object.entries(rest)) {
23
+ if (value !== undefined) {
24
+ parameter[key] = value;
25
+ }
26
+ }
27
+ if (modes !== undefined) {
28
+ parameter.modes = writeModes(declaration.modes, modes);
29
+ }
30
+ if (masks !== undefined) {
31
+ parameter.masks = masks === null ? null : writeMasks(masks);
32
+ }
33
+ return { visualCheck: parameter };
34
+ };
35
+ }
36
+ /**
37
+ * Writes one entry per declared mode, in the key order of the declaration: the definition when the list names the mode,
38
+ * `null` when it doesn't.
39
+ */
40
+ function writeModes(declared, listed) {
41
+ const names = new Set(listed);
42
+ const written = {};
43
+ for (const [name, definition] of Object.entries(declared)) {
44
+ written[name] = names.has(name) ? definition : null;
45
+ }
46
+ return written;
47
+ }
48
+ /**
49
+ * Writes each mask with both keys, the unused one `null`, and keeps a `null` mask as it is. It keeps extra keys and a
50
+ * two-kind mask as they are, so that visual-check's validation sees them.
51
+ */
52
+ function writeMasks(masks) {
53
+ const written = {};
54
+ for (const [name, mask] of Object.entries(masks)) {
55
+ written[name] =
56
+ mask === null ? null : { ...mask, selector: mask.selector ?? null, host: mask.host ?? null };
57
+ }
58
+ return written;
59
+ }
60
+ //# sourceMappingURL=define-visual-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-visual-check.js","sourceRoot":"","sources":["../../src/per-story-options/define-visual-check.ts"],"names":[],"mappings":"AA6PA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAA4C;IAC5E,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,OAAO,YAAY,CAAC,WAAW,CAAC,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,WAA2C;IAC/D;;OAEG;IACH,OAAO,SAAS,WAAW,CAAC,OAAO;QACjC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;QACzC,MAAM,SAAS,GAA4B,EAAE,CAAA;QAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACxB,CAAC;QACH,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS,CAAC,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACxD,CAAC;QAED,IAAI,KAAK,K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combinations>` takes: the component in every cell, and the grid's inputs, typed by its props. Its types need
5
+ * TypeScript 5.4 or later, for `NoInfer`.
6
+ *
7
+ * @public
8
+ */
9
+ export interface CombinationsProps<Props extends object> extends GridInput<NoInfer<Props>> {
10
+ /**
11
+ * The component each cell renders, with its row's props. Its props type `props`, `args` and `caption`.
12
+ */
13
+ component: ComponentType<Props>;
14
+ }
15
+ /**
16
+ * Renders one component in every combination of the props it lists, as captioned rows in one grid. The cells are
17
+ * children of the grid in React's own tree, with no portal and no second root, so the context around the grid reaches
18
+ * them. Nothing here depends on Storybook. It works with React 18 and 19.
19
+ *
20
+ * With `states`, a header row names the columns, and each state cell carries its state's class. The page's stylesheets
21
+ * are rewritten to force those states from when the grid appears until it unmounts.
22
+ *
23
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice.
24
+ * @public
25
+ */
26
+ export declare function Combinations<Props extends object>({ component, ...input }: CombinationsProps<Props>): ReactElement;
27
+ //# sourceMappingURL=combinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/react-port/combinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAqC,KAAK,YAAY,EAAsB,MAAM,OAAO,CAAA;AAGpH,OAAO,EAAE,KAAK,SAAS,EAA+C,MAAM,8BAA8B,CAAA;AAE1G;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,MAAM,CAAE,SAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxF;;OAEG;IACH,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;CAChC;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,YAAY,CA+BlH"}
@@ -0,0 +1,45 @@
1
+ import { createElement, useInsertionEffect } from 'react';
2
+ import { forceStates } from '../forced-state/force-states.js';
3
+ import { checkedStatesOf } from '../forced-state/forced-states.js';
4
+ import { gridAttribute, gridLayoutOf } from '../grid-story/grid-layout.js';
5
+ /**
6
+ * A layout's style as React takes it: each CSS property name camel-cased, in the same order.
7
+ */
8
+ function reactStyleOf(style) {
9
+ const entries = Object.entries(style).map(([name, value]) => [
10
+ name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()),
11
+ value,
12
+ ]);
13
+ // Safe: every name comes from the layout, which writes only standard CSS properties.
14
+ return Object.fromEntries(entries);
15
+ }
16
+ /**
17
+ * Renders one component in every combination of the props it lists, as captioned rows in one grid. The cells are
18
+ * children of the grid in React's own tree, with no portal and no second root, so the context around the grid reaches
19
+ * them. Nothing here depends on Storybook. It works with React 18 and 19.
20
+ *
21
+ * With `states`, a header row names the columns, and each state cell carries its state's class. The page's stylesheets
22
+ * are rewritten to force those states from when the grid appears until it unmounts.
23
+ *
24
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice.
25
+ * @public
26
+ */
27
+ export function Combinations({ component, ...input }) {
28
+ const layout = gridLayoutOf(input);
29
+ // A string, so the effect stays put across re-renders that list the same states.
30
+ const statesKey = layout.states.join(' ');
31
+ // Insertion effects run before the commit's DOM mutations, so the twins exist before the cells do, and never on the
32
+ // server.
33
+ useInsertionEffect(() => {
34
+ if (statesKey === '') {
35
+ return undefined;
36
+ }
37
+ return forceStates(checkedStatesOf(statesKey.split(' '), 'the grid'));
38
+ }, [statesKey]);
39
+ // Children passed one by one, not as an array: they are static, so they need no keys.
40
+ return createElement('div', { [gridAttribute]: '', style: reactStyleOf(layout.style) }, ...layout.headers.map((header) => createElement('div', { style: reactStyleOf(header.style) }, header.text)), ...layout.rows.flatMap((row) => [
41
+ ...(row.caption ? [createElement('div', { style: reactStyleOf(row.caption.style) }, row.caption.text)] : []),
42
+ ...row.cells.map((cell) => createElement('div', { className: cell.stateClass ?? undefined, style: reactStyleOf(cell.style) }, createElement(component, row.props))),
43
+ ]));
44
+ }
45
+ //# sourceMappingURL=combinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.js","sourceRoot":"","sources":["../../src/react-port/combinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,aAAa,EAAqB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AACpH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAkC,aAAa,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAe1G;;GAEG;AACH,SAAS,YAAY,CAAC,KAAgB;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACtE,KAAK;KACN,CAAC,CAAA;IAEF,qFAAqF;IACrF,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAkB,CAAA;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAuB,EAAE,SAAS,EAAE,GAAG,KAAK,EAA4B;IAClG,MAAM,MAAM,GAAG,YAAY,CAAQ,KAAK,CAAC,CAAA;IACzC,iFAAiF;IACjF,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEzC,oHAAoH;IACpH,UAAU;IACV,kBAAkB,CAAC,GAAG,EAAE;QACtB,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;YACrB,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC,CAAA;IACvE,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,sFAAsF;IACtF,OAAO,aAAa,CAClB,KAAK,EACL,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC1D,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,EAC3G,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAC9B,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5G,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxB,aAAa,CACX,KAAK,EACL,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAC5E,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,CACpC,CACF;KACF,CAAC,CACH,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Combinations, type CombinationsProps } from './react-port/combinations.js';
2
+ export type { CombinationsProps };
3
+ export { Combinations };
4
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAEnF,YAAY,EAAE,iBAAiB,EAAE,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,CAAA"}
package/dist/react.js ADDED
@@ -0,0 +1,4 @@
1
+ // The React port of the grid: `@visual-check/storybook/react`.
2
+ import { Combinations } from './react-port/combinations.js';
3
+ export { Combinations };
4
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,YAAY,EAA0B,MAAM,8BAA8B,CAAA;AAGnF,OAAO,EAAE,YAAY,EAAE,CAAA"}