@visual-check/storybook 0.0.0-stage → 0.1.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.
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 +237 -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 -3
  64. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bartek Czyż
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Third-party notices
2
+
3
+ The code in `src/forced-state/` is adapted from Storybook's pseudo-states addon (`storybook-addon-pseudo-states`, https://github.com/storybookjs/storybook/tree/next/code/addons/pseudo-states). It was first published in https://github.com/storybookjs/storybook-addon-pseudo-states, under the first notice below, and now lives in the Storybook monorepo, under the second.
4
+
5
+ ## storybook-addon-pseudo-states
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2021 Chromatic
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ ## Storybook
30
+
31
+ The MIT License (MIT)
32
+
33
+ Copyright (c) 2024 Storybook
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ of this software and associated documentation files (the "Software"), to deal
37
+ in the Software without restriction, including without limitation the rights
38
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
+ copies of the Software, and to permit persons to whom the Software is
40
+ furnished to do so, subject to the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included in
43
+ all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51
+ THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ import { type InputSignalWithTransform, type OutputRef, type Type } from '@angular/core';
2
+ import { type GridInput } from '../grid-story/grid-layout.js';
3
+ /**
4
+ * What a field of a cell's component takes as an input: a signal input's write type (`model()` included), nothing for
5
+ * a function (a method, `computed`, another signal) or an output, else the field's own type (a decorator `@Input()`).
6
+ */
7
+ type InputValueOf<Field> = Field extends InputSignalWithTransform<infer _Read, infer Write> ? Write : Field extends ((...args: never) => unknown) | OutputRef<unknown> ? never : Field;
8
+ /**
9
+ * The inputs a cell's component takes, by name: each of its public fields that can be an input, with the type it takes.
10
+ */
11
+ type CellInputsOf<Component> = {
12
+ [Name in keyof Component as [InputValueOf<Component[Name]>] extends [never] ? never : Name]: InputValueOf<Component[Name]>;
13
+ };
14
+ /**
15
+ * What `combinations()` takes: the component in every cell, and the grid's inputs, typed by the component's inputs. Its
16
+ * types need TypeScript 5.4 or later, for `NoInfer`.
17
+ *
18
+ * @public
19
+ */
20
+ export interface CombinationsInput<Component> extends GridInput<NoInfer<CellInputsOf<Component>>> {
21
+ /**
22
+ * The component each cell creates, with its row's props as inputs. Its inputs type `props`, `args` and `caption`.
23
+ */
24
+ component: Type<Component>;
25
+ }
26
+ /**
27
+ * What `combinations()` returns, for a story's render to return: the grid's template, the props it reads and the
28
+ * module metadata it needs, as Storybook's Angular renderer takes them.
29
+ *
30
+ * @public
31
+ */
32
+ export interface CombinationsStory {
33
+ /**
34
+ * The grid's template. It reads only `visualCheckGrid`, so it is the same for any grid of the same shape.
35
+ */
36
+ template: string;
37
+ /**
38
+ * What the template reads.
39
+ */
40
+ props: {
41
+ /**
42
+ * The grid's component, each row's inputs, and every header's and caption's text, in document order.
43
+ */
44
+ visualCheckGrid: {
45
+ /**
46
+ * The component each cell creates.
47
+ */
48
+ component: Type<unknown>;
49
+ /**
50
+ * Each row's inputs: `{ ...args, ...combination }`.
51
+ */
52
+ rows: object[];
53
+ /**
54
+ * Every header's text, then every caption's, in document order.
55
+ */
56
+ texts: string[];
57
+ };
58
+ };
59
+ /**
60
+ * What the template uses: `NgComponentOutlet`, which creates the cells, and with states the directive that forces
61
+ * them.
62
+ */
63
+ moduleMetadata: {
64
+ /**
65
+ * The standalone directives the template uses.
66
+ */
67
+ imports: Type<unknown>[];
68
+ };
69
+ }
70
+ /**
71
+ * Renders one component in every combination of the props it lists, as captioned rows in one grid, returned as the
72
+ * story's `template`, `props` and `moduleMetadata` for Storybook's Angular renderer:
73
+ * `render: (args) => combinations({ component: Button, props: { size: ['sm', 'lg'] }, args })`. The cells are created
74
+ * by `NgComponentOutlet` in the story's own view, so the injector reaches them, the story's `moduleMetadata` providers
75
+ * and the app's included, and their inputs, signal inputs included, are set with `setInput`. A story may wrap
76
+ * `template` in its own markup, spreading `props` and `moduleMetadata`. Nothing here depends on Storybook. It works
77
+ * with Angular 18 and later, with Angular's JIT compiler loaded, as Storybook's Angular renderer has it.
78
+ *
79
+ * With `states`, a header row names the columns, each state cell carries its state's class, and stylesheets are
80
+ * rewritten to force those states from when the grid's element is created, before any cell, until Angular destroys
81
+ * it, and never while rendering on the server.
82
+ *
83
+ * @throws When the component is not an Angular component, a name in `props` or `args` is none of its inputs, a prop
84
+ * lists no values, or `states` lists an unknown state or one twice.
85
+ * @public
86
+ */
87
+ export declare function combinations<Component>({ component, ...input }: CombinationsInput<Component>): CombinationsStory;
88
+ export {};
89
+ //# sourceMappingURL=combinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/angular-port/combinations.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAG7B,KAAK,SAAS,EAGd,KAAK,IAAI,EACV,MAAM,eAAe,CAAA;AAGtB,OAAO,EAGL,KAAK,SAAS,EAKf,MAAM,8BAA8B,CAAA;AAErC;;;GAGG;AACH,KAAK,YAAY,CAAC,KAAK,IACrB,KAAK,SAAS,wBAAwB,CAAC,MAAM,KAAK,EAAE,MAAM,KAAK,CAAC,GAC5D,KAAK,GACL,KAAK,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,GAC9D,KAAK,GACL,KAAK,CAAA;AAEb;;GAEG;AACH,KAAK,YAAY,CAAC,SAAS,IAAI;KAC5B,IAAI,IAAI,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,YAAY,CACvG,SAAS,CAAC,IAAI,CAAC,CAChB;CACF,CAAA;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,SAAS,CAAE,SAAQ,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/F;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,eAAe,EAAE;YACf;;eAEG;YACH,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YACxB;;eAEG;YACH,IAAI,EAAE,MAAM,EAAE,CAAA;YACd;;eAEG;YACH,KAAK,EAAE,MAAM,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;OAGG;IACH,cAAc,EAAE;QACd;;WAEG;QACH,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;KACzB,CAAA;CACF;AA8FD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,iBAAiB,CAchH"}
@@ -0,0 +1,97 @@
1
+ import { isPlatformServer, NgComponentOutlet } from '@angular/common';
2
+ import { Directive, inject, PLATFORM_ID, reflectComponentType, } from '@angular/core';
3
+ import { forceStates } from '../forced-state/force-states.js';
4
+ import { gridAttribute, gridLayoutOf, } from '../grid-story/grid-layout.js';
5
+ /**
6
+ * A style as an inline `style` attribute's text: `name:value`, joined by `;`, in the layout's order. Values come only
7
+ * from the layout, so nothing needs escaping.
8
+ */
9
+ function styleTextOf(style) {
10
+ return Object.entries(style)
11
+ .map(([name, value]) => `${name}:${value}`)
12
+ .join(';');
13
+ }
14
+ /**
15
+ * The grid's template, drawing the same elements and styles as the React port, and the texts it reads. Headers' and
16
+ * captions' text goes through interpolation, so it's written literally, never parsed as a template.
17
+ */
18
+ function gridTemplateOf(layout) {
19
+ const texts = [];
20
+ const label = ({ text, style }) => `<div style="${styleTextOf(style)}">{{ visualCheckGrid.texts[${texts.push(text) - 1}] }}</div>`;
21
+ const headers = layout.headers.map(label);
22
+ const rows = layout.rows.flatMap((row, index) => [
23
+ ...(row.caption ? [label(row.caption)] : []),
24
+ ...row.cells.map((cell) => `<div${cell.stateClass === null ? '' : ` class="${cell.stateClass}"`} style="${styleTextOf(cell.style)}">` +
25
+ `<ng-container *ngComponentOutlet="visualCheckGrid.component; inputs: visualCheckGrid.rows[${index}]" />` +
26
+ '</div>'),
27
+ ]);
28
+ return {
29
+ template: `<div ${gridAttribute}="" style="${styleTextOf(layout.style)}">${[...headers, ...rows].join('')}</div>`,
30
+ texts,
31
+ };
32
+ }
33
+ /**
34
+ * A standalone directive, made for one grid, that matches the grid's own element and forces the states from when it's
35
+ * created, before any cell, until Angular destroys it. It forces nothing while rendering on the server.
36
+ */
37
+ function forcingDirectiveOf(states) {
38
+ return Directive({ selector: `div[${gridAttribute}]`, standalone: true })(class ForcedStates {
39
+ /**
40
+ * Stops forcing the states, or nothing on the server.
41
+ */
42
+ #stop = isPlatformServer(inject(PLATFORM_ID)) ? undefined : forceStates(states);
43
+ /**
44
+ * Stops forcing the states when Angular destroys the grid.
45
+ */
46
+ ngOnDestroy() {
47
+ this.#stop?.();
48
+ }
49
+ });
50
+ }
51
+ /**
52
+ * Checks that the component is an Angular component that takes every prop the grid sets, by the input's public name.
53
+ *
54
+ * @throws When the component is not an Angular component, or a name in `props` or `args` is none of its inputs.
55
+ */
56
+ function checkInputs(component, input) {
57
+ const mirror = reflectComponentType(component);
58
+ if (mirror === null) {
59
+ throw new Error(`visual-check: ${component.name} is not an Angular component.`);
60
+ }
61
+ const inputs = new Set(mirror.inputs.map(({ templateName }) => templateName));
62
+ for (const name of [...Object.keys(input.props), ...Object.keys(input.args ?? {})]) {
63
+ if (!inputs.has(name)) {
64
+ throw new Error(`visual-check: ${component.name} has no input "${name}".`);
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * Renders one component in every combination of the props it lists, as captioned rows in one grid, returned as the
70
+ * story's `template`, `props` and `moduleMetadata` for Storybook's Angular renderer:
71
+ * `render: (args) => combinations({ component: Button, props: { size: ['sm', 'lg'] }, args })`. The cells are created
72
+ * by `NgComponentOutlet` in the story's own view, so the injector reaches them, the story's `moduleMetadata` providers
73
+ * and the app's included, and their inputs, signal inputs included, are set with `setInput`. A story may wrap
74
+ * `template` in its own markup, spreading `props` and `moduleMetadata`. Nothing here depends on Storybook. It works
75
+ * with Angular 18 and later, with Angular's JIT compiler loaded, as Storybook's Angular renderer has it.
76
+ *
77
+ * With `states`, a header row names the columns, each state cell carries its state's class, and stylesheets are
78
+ * rewritten to force those states from when the grid's element is created, before any cell, until Angular destroys
79
+ * it, and never while rendering on the server.
80
+ *
81
+ * @throws When the component is not an Angular component, a name in `props` or `args` is none of its inputs, a prop
82
+ * lists no values, or `states` lists an unknown state or one twice.
83
+ * @public
84
+ */
85
+ export function combinations({ component, ...input }) {
86
+ checkInputs(component, input);
87
+ const layout = gridLayoutOf(input);
88
+ const { template, texts } = gridTemplateOf(layout);
89
+ return {
90
+ template,
91
+ props: { visualCheckGrid: { component, rows: layout.rows.map((row) => row.props), texts } },
92
+ moduleMetadata: {
93
+ imports: layout.states.length === 0 ? [NgComponentOutlet] : [NgComponentOutlet, forcingDirectiveOf(layout.states)],
94
+ },
95
+ };
96
+ }
97
+ //# sourceMappingURL=combinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.js","sourceRoot":"","sources":["../../src/angular-port/combinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EACL,SAAS,EAET,MAAM,EAGN,WAAW,EACX,oBAAoB,GAErB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,iC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AI,KAAK,CAAC,iBAAiB,SAAS,CAAC,IAAI,kBAAkB,IAAI,IAAI,CAAC,CAAA;QAC5E,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAY,EAAE,SAAS,EAAE,GAAG,KAAK,EAAgC;IAC3F,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IAE7B,MAAM,MAAM,GAAG,YAAY,CAAS,KAAK,CAAC,CAAA;IAC1C,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;IAElD,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE;QAC3F,cAAc,EAAE;YACd,OAAO,EACL,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC5G;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type CombinationsInput, type CombinationsStory, combinations } from './angular-port/combinations.js';
2
+ export type { CombinationsInput, CombinationsStory };
3
+ export { combinations };
4
+ //# sourceMappingURL=angular.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.d.ts","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAE7G,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ // The Angular port of the grid: `@visual-check/storybook/angular`.
2
+ import { combinations } from './angular-port/combinations.js';
3
+ export { combinations };
4
+ //# sourceMappingURL=angular.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.js","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EAAkD,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAG7G,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,59 @@
1
+ import type { ForcedState } from '../forced-state/forced-states.js';
2
+ import { type GridInput, type GridLayout } from '../grid-story/grid-layout.js';
3
+ /**
4
+ * What `combinations()` takes: how to render each 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 CombinationsInput<Props extends object> extends GridInput<NoInfer<Props>> {
10
+ /**
11
+ * Renders one cell with its row's props: a new node, or a string of HTML, which the cell holds. It's called once per
12
+ * cell, in document order. Its parameter's type gives the types of `props`, `args` and `caption`. A lit template isn't
13
+ * a node: render it into an element first.
14
+ */
15
+ render: (props: Props) => Node | string;
16
+ }
17
+ /**
18
+ * What the plain-DOM port reaches in the page.
19
+ */
20
+ export interface GridPage {
21
+ /**
22
+ * The document the grid's elements are created in.
23
+ */
24
+ document: Document;
25
+ /**
26
+ * What watches the document for the grid leaving it.
27
+ */
28
+ MutationObserver: typeof MutationObserver;
29
+ /**
30
+ * What forces states, `forceStates` in the page.
31
+ */
32
+ forceStates: (states: readonly ForcedState[]) => () => void;
33
+ }
34
+ /**
35
+ * The grid's element for the layout, in the page's document: the same elements and styles as the React port draws,
36
+ * with no whitespace between them. Each element gets its attributes first, then its style, one property at a time in
37
+ * the layout's order, then its children. With the layout's states, it starts forcing them before `render` is first
38
+ * called, and stops when drawing or watching the page fails, or when the grid, once in the page, leaves it.
39
+ *
40
+ * @throws When `render` returns neither a node nor HTML, or the same node for two cells.
41
+ */
42
+ export declare function gridElementOf<Props extends object>(page: GridPage, layout: GridLayout<Props>, render: (props: Props) => Node | string): HTMLElement;
43
+ /**
44
+ * Renders every combination of the props it lists, as captioned rows in one grid, and returns the grid's `<div>` for
45
+ * the story to return or place. It draws the same elements and styles as the React port, so one grid gives the same
46
+ * images through either. Nothing here depends on Storybook. It works with Storybook's html and web-components
47
+ * renderers; with web components, `render` returns a node, not a lit template. Call it in the story's render, so each
48
+ * render makes its own grid.
49
+ *
50
+ * With `states`, a header row names the columns, and each state cell carries its state's class. The page's stylesheets
51
+ * are rewritten to force those states from this call, before any cell is rendered, until the grid, once in the page,
52
+ * leaves it.
53
+ *
54
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice; when there is no DOM; when
55
+ * `render` returns neither a node nor HTML, or the same node for two cells.
56
+ * @public
57
+ */
58
+ export declare function combinations<Props extends object>({ render, ...input }: CombinationsInput<Props>): HTMLElement;
59
+ //# sourceMappingURL=combinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/dom-port/combinations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,UAAU,EAIhB,MAAM,8BAA8B,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,MAAM,CAAE,SAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxF;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,CAAA;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAClB;;OAEG;IACH,gBAAgB,EAAE,OAAO,gBAAgB,CAAA;IACzC;;OAEG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,KAAK,MAAM,IAAI,CAAA;CAC5D;AA0HD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,MAAM,EAChD,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,EACzB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,GACtC,WAAW,CAgBb;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,WAAW,CAY9G"}
@@ -0,0 +1,137 @@
1
+ import { forceStates } from '../forced-state/force-states.js';
2
+ import { gridAttribute, gridLayoutOf, } from '../grid-story/grid-layout.js';
3
+ /**
4
+ * Sets the style on the element one property at a time, in the layout's order.
5
+ */
6
+ function styled(element, style) {
7
+ for (const [name, value] of Object.entries(style)) {
8
+ element.style.setProperty(name, value);
9
+ }
10
+ }
11
+ /**
12
+ * A header's or a caption's `div`: its style, then its text.
13
+ */
14
+ function labelOf(document, { text, style }) {
15
+ const label = document.createElement('div');
16
+ styled(label, style);
17
+ label.textContent = text;
18
+ return label;
19
+ }
20
+ /**
21
+ * Whether the value is a node, of this page or of another realm: an object with a numeric `nodeType`.
22
+ */
23
+ function isNode(value) {
24
+ return typeof value === 'object' && value !== null && typeof value.nodeType === 'number';
25
+ }
26
+ /**
27
+ * Puts what `render` returned in the cell: HTML as its markup, a node as its child.
28
+ *
29
+ * @throws When the content is neither a node nor a string, or is a node another cell already holds.
30
+ */
31
+ function fill(cell, content, rendered) {
32
+ if (typeof content === 'string') {
33
+ cell.innerHTML = content;
34
+ return;
35
+ }
36
+ if (!isNode(content)) {
37
+ throw new Error("visual-check: the grid's render returned neither a node nor HTML. Return a new node, or a string of HTML.");
38
+ }
39
+ if (rendered.has(content)) {
40
+ throw new Error("visual-check: the grid's render returned the same node for two cells. Return a new node each time it's called.");
41
+ }
42
+ rendered.add(content);
43
+ cell.append(content);
44
+ }
45
+ /**
46
+ * Stops forcing once the grid, having been in the page, leaves it, or once a batch of changes both adds it and removes
47
+ * it. Until the grid enters the page, changes elsewhere keep the states forced.
48
+ */
49
+ function stopWhenRemoved(page, grid, stop) {
50
+ let shown = false;
51
+ const observer = new page.MutationObserver((records) => {
52
+ if (grid.isConnected) {
53
+ shown = true;
54
+ return;
55
+ }
56
+ if (shown || records.some((record) => Array.from(record.removedNodes).some((node) => node.contains(grid)))) {
57
+ observer.disconnect();
58
+ stop();
59
+ }
60
+ });
61
+ observer.observe(page.document, { childList: true, subtree: true });
62
+ }
63
+ /**
64
+ * The grid's elements for the layout, created in the document but not placed, with each cell holding what `render`
65
+ * returned for it.
66
+ *
67
+ * @throws When `render` returns neither a node nor HTML, or the same node for two cells.
68
+ */
69
+ function drawnGridOf(document, layout, render) {
70
+ const grid = document.createElement('div');
71
+ const rendered = new Set();
72
+ grid.setAttribute(gridAttribute, '');
73
+ styled(grid, layout.style);
74
+ for (const header of layout.headers) {
75
+ grid.append(labelOf(document, header));
76
+ }
77
+ for (const row of layout.rows) {
78
+ if (row.caption !== null) {
79
+ grid.append(labelOf(document, row.caption));
80
+ }
81
+ for (const cell of row.cells) {
82
+ const element = document.createElement('div');
83
+ if (cell.stateClass !== null) {
84
+ element.className = cell.stateClass;
85
+ }
86
+ styled(element, cell.style);
87
+ fill(element, render(row.props), rendered);
88
+ grid.append(element);
89
+ }
90
+ }
91
+ return grid;
92
+ }
93
+ /**
94
+ * The grid's element for the layout, in the page's document: the same elements and styles as the React port draws,
95
+ * with no whitespace between them. Each element gets its attributes first, then its style, one property at a time in
96
+ * the layout's order, then its children. With the layout's states, it starts forcing them before `render` is first
97
+ * called, and stops when drawing or watching the page fails, or when the grid, once in the page, leaves it.
98
+ *
99
+ * @throws When `render` returns neither a node nor HTML, or the same node for two cells.
100
+ */
101
+ export function gridElementOf(page, layout, render) {
102
+ const stop = layout.states.length === 0 ? undefined : page.forceStates(layout.states);
103
+ try {
104
+ const grid = drawnGridOf(page.document, layout, render);
105
+ if (stop !== undefined) {
106
+ stopWhenRemoved(page, grid, stop);
107
+ }
108
+ return grid;
109
+ }
110
+ catch (error) {
111
+ stop?.();
112
+ throw error;
113
+ }
114
+ }
115
+ /**
116
+ * Renders every combination of the props it lists, as captioned rows in one grid, and returns the grid's `<div>` for
117
+ * the story to return or place. It draws the same elements and styles as the React port, so one grid gives the same
118
+ * images through either. Nothing here depends on Storybook. It works with Storybook's html and web-components
119
+ * renderers; with web components, `render` returns a node, not a lit template. Call it in the story's render, so each
120
+ * render makes its own grid.
121
+ *
122
+ * With `states`, a header row names the columns, and each state cell carries its state's class. The page's stylesheets
123
+ * are rewritten to force those states from this call, before any cell is rendered, until the grid, once in the page,
124
+ * leaves it.
125
+ *
126
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice; when there is no DOM; when
127
+ * `render` returns neither a node nor HTML, or the same node for two cells.
128
+ * @public
129
+ */
130
+ export function combinations({ render, ...input }) {
131
+ const layout = gridLayoutOf(input);
132
+ if (typeof globalThis.document === 'undefined') {
133
+ throw new Error("visual-check: combinations() needs a DOM. Call it in a story's render.");
134
+ }
135
+ return gridElementOf({ document: globalThis.document, MutationObserver: globalThis.MutationObserver, forceStates }, layout, render);
136
+ }
137
+ //# sourceMappingURL=combinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.js","sourceRoot":"","sources":["../../src/dom-port/combinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,EAML,aAAa,EACb,YAAY,GACb,MAAM,8BAA8B,CAAA;AAmCrC;;GAEG;AACH,SAAS,MAAM,CAAC,OAAoB,EAAE,KAAgB;IACpD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QA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AK,EAA4B;IAC/F,MAAM,MAAM,GAAG,YAAY,CAAQ,KAAK,CAAC,CAAA;IAEzC,IAAI,OAAO,UAAU,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAA;IAC3F,CAAC;IAED,OAAO,aAAa,CAClB,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,EAAE,WAAW,EAAE,EAC7F,MAAM,EACN,MAAM,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type ForcedState } from './forced-states.js';
2
+ /**
3
+ * What forcing states reaches in a page: its document, the constructors whose prototypes it hooks, and its console.
4
+ */
5
+ export interface PageGlobals {
6
+ /**
7
+ * The page's document.
8
+ */
9
+ document: Document;
10
+ /**
11
+ * What watches the document and shadow roots for added and changed styles.
12
+ */
13
+ MutationObserver: typeof MutationObserver;
14
+ /**
15
+ * Whose `insertRule`, `replaceSync` and `replace` are hooked.
16
+ */
17
+ CSSStyleSheet: typeof CSSStyleSheet;
18
+ /**
19
+ * Whose `insertRule` is hooked, when the browser has it.
20
+ */
21
+ CSSGroupingRule: typeof CSSGroupingRule | undefined;
22
+ /**
23
+ * Whose `adoptedStyleSheets` setter is hooked.
24
+ */
25
+ Document: typeof Document;
26
+ /**
27
+ * Whose `adoptedStyleSheets` setter is hooked, and what tells a shadow root's sheets from the document's.
28
+ */
29
+ ShadowRoot: typeof ShadowRoot;
30
+ /**
31
+ * Whose `attachShadow` is hooked.
32
+ */
33
+ Element: typeof Element;
34
+ /**
35
+ * Where cross-origin stylesheets are reported.
36
+ */
37
+ console: Pick<Console, 'warn'>;
38
+ }
39
+ /**
40
+ * A page's forced states: the active requests and what keeps the page rewritten while there are any.
41
+ */
42
+ export interface PageRewriter {
43
+ /**
44
+ * Starts forcing the states, beside any already forced, and gives the function that ends this request.
45
+ */
46
+ force(states: ReadonlySet<ForcedState>): () => void;
47
+ }
48
+ /**
49
+ * The rewriter of one page. Creating it touches nothing in the page.
50
+ */
51
+ export declare function pageRewriterOf(page: PageGlobals): PageRewriter;
52
+ /**
53
+ * Forces states on this page, the way a grid's state columns do. Every stylesheet rule that uses one of the states gets a
54
+ * twin selector, at the same specificity, that matches under the state's class: `visual-check-hover`, `visual-check-active`,
55
+ * `visual-check-focus`, `visual-check-focus-visible` or `visual-check-focus-within`. Put the class on any ancestor of what
56
+ * should show the state. It reaches `<style>` and `<link>` sheets, adopted sheets and shadow roots' sheets, and keeps
57
+ * rewriting styles added or changed later, CSS-in-JS rules included, until the returned function is called. That makes
58
+ * it fit a story's `beforeEach`. Rewritten rules stay rewritten, and without the classes nothing in the page changes. The
59
+ * browser's default styles, states inside `:not()` and cross-origin stylesheets without CORS, which log a warning,
60
+ * aren't forced. A sheet pushed onto `adoptedStyleSheets`, rather than assigned, is rewritten on the next change to the
61
+ * DOM, so one pushed with no change after it may be missed. Without a DOM, it does nothing. Adapted from Storybook's
62
+ * pseudo-states addon (MIT).
63
+ *
64
+ * @throws When a state isn't one visual-check forces, or is listed twice.
65
+ * @public
66
+ */
67
+ export declare function forceStates(states: readonly ForcedState[]): () => void;
68
+ //# sourceMappingURL=force-states.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"force-states.d.ts","sourceRoot":"","sources":["../../src/forced-state/force-states.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,WAAW,EAAoC,MAAM,oBAAoB,CAAA;AAKxG;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAClB;;OAEG;IACH,gBAAgB,EAAE,OAAO,gBAAgB,CAAA;IACzC;;OAEG;IACH,aAAa,EAAE,OAAO,aAAa,CAAA;IACnC;;OAEG;IACH,eAAe,EAAE,OAAO,eAAe,GAAG,SAAS,CAAA;IACnD;;OAEG;IACH,QAAQ,EAAE,OAAO,QAAQ,CAAA;IACzB;;OAEG;IACH,UAAU,EAAE,OAAO,UAAU,CAAA;IAC7B;;OAEG;IACH,OAAO,EAAE,OAAO,OAAO,CAAA;IACvB;;OAEG;IACH,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI,CAAA;CACpD;AA0ED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAe9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,IAAI,CAUtE"}