viewev 0.0.0-stage → 0.1.0-beta.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 (181) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -2
  3. package/assets/logo/Logo-horizontal.png +0 -0
  4. package/dist/adapters/storybook/index.d.ts +5 -0
  5. package/dist/adapters/storybook/index.js +4 -0
  6. package/dist/adapters/storybook/index.js.map +1 -0
  7. package/dist/adapters/storybook/provider.d.ts +24 -0
  8. package/dist/adapters/storybook/provider.js +114 -0
  9. package/dist/adapters/storybook/provider.js.map +1 -0
  10. package/dist/adapters/storybook/scenarios.d.ts +30 -0
  11. package/dist/adapters/storybook/scenarios.js +64 -0
  12. package/dist/adapters/storybook/scenarios.js.map +1 -0
  13. package/dist/adapters/storybook/static-server.d.ts +10 -0
  14. package/dist/adapters/storybook/static-server.js +105 -0
  15. package/dist/adapters/storybook/static-server.js.map +1 -0
  16. package/dist/adapters/storybook/storybook-index.d.ts +32 -0
  17. package/dist/adapters/storybook/storybook-index.js +35 -0
  18. package/dist/adapters/storybook/storybook-index.js.map +1 -0
  19. package/dist/baselines/environment-check.d.ts +7 -0
  20. package/dist/baselines/environment-check.js +24 -0
  21. package/dist/baselines/environment-check.js.map +1 -0
  22. package/dist/baselines/environment-key.d.ts +8 -0
  23. package/dist/baselines/environment-key.js +12 -0
  24. package/dist/baselines/environment-key.js.map +1 -0
  25. package/dist/baselines/file-store.d.ts +12 -0
  26. package/dist/baselines/file-store.js +81 -0
  27. package/dist/baselines/file-store.js.map +1 -0
  28. package/dist/baselines/git-store.d.ts +16 -0
  29. package/dist/baselines/git-store.js +150 -0
  30. package/dist/baselines/git-store.js.map +1 -0
  31. package/dist/baselines/metadata.d.ts +16 -0
  32. package/dist/baselines/metadata.js +84 -0
  33. package/dist/baselines/metadata.js.map +1 -0
  34. package/dist/baselines/types.d.ts +33 -0
  35. package/dist/baselines/types.js +2 -0
  36. package/dist/baselines/types.js.map +1 -0
  37. package/dist/browser/playwright/capturer.d.ts +2 -0
  38. package/dist/browser/playwright/capturer.js +142 -0
  39. package/dist/browser/playwright/capturer.js.map +1 -0
  40. package/dist/browser/playwright/environment.d.ts +4 -0
  41. package/dist/browser/playwright/environment.js +36 -0
  42. package/dist/browser/playwright/environment.js.map +1 -0
  43. package/dist/browser/playwright/index.d.ts +1 -0
  44. package/dist/browser/playwright/index.js +2 -0
  45. package/dist/browser/playwright/index.js.map +1 -0
  46. package/dist/browser/types.d.ts +43 -0
  47. package/dist/browser/types.js +2 -0
  48. package/dist/browser/types.js.map +1 -0
  49. package/dist/ci/github-summary.d.ts +5 -0
  50. package/dist/ci/github-summary.js +95 -0
  51. package/dist/ci/github-summary.js.map +1 -0
  52. package/dist/cli/baseline-ref.d.ts +6 -0
  53. package/dist/cli/baseline-ref.js +11 -0
  54. package/dist/cli/baseline-ref.js.map +1 -0
  55. package/dist/cli/bin.d.ts +2 -0
  56. package/dist/cli/bin.js +13 -0
  57. package/dist/cli/bin.js.map +1 -0
  58. package/dist/cli/commands/baseline.d.ts +3 -0
  59. package/dist/cli/commands/baseline.js +90 -0
  60. package/dist/cli/commands/baseline.js.map +1 -0
  61. package/dist/cli/commands/capture.d.ts +3 -0
  62. package/dist/cli/commands/capture.js +42 -0
  63. package/dist/cli/commands/capture.js.map +1 -0
  64. package/dist/cli/commands/config.d.ts +3 -0
  65. package/dist/cli/commands/config.js +25 -0
  66. package/dist/cli/commands/config.js.map +1 -0
  67. package/dist/cli/commands/doctor.d.ts +3 -0
  68. package/dist/cli/commands/doctor.js +19 -0
  69. package/dist/cli/commands/doctor.js.map +1 -0
  70. package/dist/cli/commands/report.d.ts +3 -0
  71. package/dist/cli/commands/report.js +16 -0
  72. package/dist/cli/commands/report.js.map +1 -0
  73. package/dist/cli/commands/scenarios.d.ts +3 -0
  74. package/dist/cli/commands/scenarios.js +30 -0
  75. package/dist/cli/commands/scenarios.js.map +1 -0
  76. package/dist/cli/commands/test.d.ts +3 -0
  77. package/dist/cli/commands/test.js +123 -0
  78. package/dist/cli/commands/test.js.map +1 -0
  79. package/dist/cli/context.d.ts +21 -0
  80. package/dist/cli/context.js +22 -0
  81. package/dist/cli/context.js.map +1 -0
  82. package/dist/cli/doctor.d.ts +12 -0
  83. package/dist/cli/doctor.js +104 -0
  84. package/dist/cli/doctor.js.map +1 -0
  85. package/dist/cli/format.d.ts +17 -0
  86. package/dist/cli/format.js +106 -0
  87. package/dist/cli/format.js.map +1 -0
  88. package/dist/cli/impact.d.ts +13 -0
  89. package/dist/cli/impact.js +57 -0
  90. package/dist/cli/impact.js.map +1 -0
  91. package/dist/cli/program.d.ts +11 -0
  92. package/dist/cli/program.js +70 -0
  93. package/dist/cli/program.js.map +1 -0
  94. package/dist/cli/session.d.ts +27 -0
  95. package/dist/cli/session.js +53 -0
  96. package/dist/cli/session.js.map +1 -0
  97. package/dist/comparison/compare.d.ts +11 -0
  98. package/dist/comparison/compare.js +41 -0
  99. package/dist/comparison/compare.js.map +1 -0
  100. package/dist/comparison/types.d.ts +34 -0
  101. package/dist/comparison/types.js +2 -0
  102. package/dist/comparison/types.js.map +1 -0
  103. package/dist/config/load.d.ts +23 -0
  104. package/dist/config/load.js +93 -0
  105. package/dist/config/load.js.map +1 -0
  106. package/dist/config/schema.d.ts +299 -0
  107. package/dist/config/schema.js +134 -0
  108. package/dist/config/schema.js.map +1 -0
  109. package/dist/core/artifacts.d.ts +6 -0
  110. package/dist/core/artifacts.js +2 -0
  111. package/dist/core/artifacts.js.map +1 -0
  112. package/dist/core/baseline-run.d.ts +37 -0
  113. package/dist/core/baseline-run.js +85 -0
  114. package/dist/core/baseline-run.js.map +1 -0
  115. package/dist/core/capture-settings.d.ts +6 -0
  116. package/dist/core/capture-settings.js +21 -0
  117. package/dist/core/capture-settings.js.map +1 -0
  118. package/dist/core/discovery.d.ts +3 -0
  119. package/dist/core/discovery.js +17 -0
  120. package/dist/core/discovery.js.map +1 -0
  121. package/dist/core/impact.d.ts +19 -0
  122. package/dist/core/impact.js +28 -0
  123. package/dist/core/impact.js.map +1 -0
  124. package/dist/core/pool.d.ts +5 -0
  125. package/dist/core/pool.js +21 -0
  126. package/dist/core/pool.js.map +1 -0
  127. package/dist/core/result.d.ts +111 -0
  128. package/dist/core/result.js +53 -0
  129. package/dist/core/result.js.map +1 -0
  130. package/dist/core/selection.d.ts +8 -0
  131. package/dist/core/selection.js +8 -0
  132. package/dist/core/selection.js.map +1 -0
  133. package/dist/core/test-run.d.ts +38 -0
  134. package/dist/core/test-run.js +140 -0
  135. package/dist/core/test-run.js.map +1 -0
  136. package/dist/impact/git.d.ts +17 -0
  137. package/dist/impact/git.js +55 -0
  138. package/dist/impact/git.js.map +1 -0
  139. package/dist/impact/types.d.ts +24 -0
  140. package/dist/impact/types.js +23 -0
  141. package/dist/impact/types.js.map +1 -0
  142. package/dist/index.d.ts +4 -0
  143. package/dist/index.js +4 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/reporting/artifacts.d.ts +8 -0
  146. package/dist/reporting/artifacts.js +23 -0
  147. package/dist/reporting/artifacts.js.map +1 -0
  148. package/dist/reporting/html.d.ts +4 -0
  149. package/dist/reporting/html.js +244 -0
  150. package/dist/reporting/html.js.map +1 -0
  151. package/dist/reporting/report.d.ts +12 -0
  152. package/dist/reporting/report.js +55 -0
  153. package/dist/reporting/report.js.map +1 -0
  154. package/dist/reporting/results-json.d.ts +35 -0
  155. package/dist/reporting/results-json.js +37 -0
  156. package/dist/reporting/results-json.js.map +1 -0
  157. package/dist/scenarios/glob.d.ts +7 -0
  158. package/dist/scenarios/glob.js +21 -0
  159. package/dist/scenarios/glob.js.map +1 -0
  160. package/dist/scenarios/model.d.ts +61 -0
  161. package/dist/scenarios/model.js +31 -0
  162. package/dist/scenarios/model.js.map +1 -0
  163. package/dist/scenarios/schema.d.ts +8 -0
  164. package/dist/scenarios/schema.js +70 -0
  165. package/dist/scenarios/schema.js.map +1 -0
  166. package/dist/shared/environment.d.ts +23 -0
  167. package/dist/shared/environment.js +2 -0
  168. package/dist/shared/environment.js.map +1 -0
  169. package/dist/shared/errors.d.ts +23 -0
  170. package/dist/shared/errors.js +29 -0
  171. package/dist/shared/errors.js.map +1 -0
  172. package/dist/shared/png.d.ts +3 -0
  173. package/dist/shared/png.js +14 -0
  174. package/dist/shared/png.js.map +1 -0
  175. package/dist/shared/size.d.ts +4 -0
  176. package/dist/shared/size.js +2 -0
  177. package/dist/shared/size.js.map +1 -0
  178. package/docs/architecture.md +180 -0
  179. package/docs/ci.md +212 -0
  180. package/docs/impact.md +46 -0
  181. package/package.json +58 -4
@@ -0,0 +1,38 @@
1
+ import type { BaselineReader } from '../baselines/types.js';
2
+ import type { CaptureSession } from '../browser/types.js';
3
+ import type { ComparisonOptions, ImageComparator } from '../comparison/types.js';
4
+ import type { ViewevConfig } from '../config/schema.js';
5
+ import type { ScenarioId, VisualScenario } from '../scenarios/model.js';
6
+ import type { ArtifactWriter } from './artifacts.js';
7
+ import type { RunResult, ScenarioResult, SelectionInfo } from './result.js';
8
+ export interface TestRunDeps {
9
+ readonly session: CaptureSession;
10
+ /** The approved baselines. The only thing a scenario is judged against. */
11
+ readonly store: BaselineReader;
12
+ readonly compare: ImageComparator;
13
+ readonly artifacts: ArtifactWriter;
14
+ /**
15
+ * Baselines proposed by the change under test (a pull request). A difference from the
16
+ * approved baselines that matches a proposed baseline is reported as "changed" instead of
17
+ * a regression, so reviewers see exactly which visual changes the change makes. The
18
+ * proposal is never trusted on its own: it only counts if the screenshot matches it.
19
+ */
20
+ readonly proposed?: BaselineReader;
21
+ }
22
+ export interface TestRunOptions {
23
+ readonly config: ViewevConfig;
24
+ /** The scenarios to run, after filtering. */
25
+ readonly scenarios: readonly VisualScenario[];
26
+ /** Every discovered scenario, before filtering; baselines without one are obsolete. */
27
+ readonly discoveredIds: readonly ScenarioId[];
28
+ /** How the scenarios were chosen, recorded in the result when impact analysis took part. */
29
+ readonly selection?: SelectionInfo;
30
+ readonly onResult?: (result: ScenarioResult) => void;
31
+ }
32
+ /** Scenario-level options override the global comparison settings. */
33
+ export declare function comparisonOptionsFor(scenario: VisualScenario, config: ViewevConfig): ComparisonOptions;
34
+ /**
35
+ * Captures every scenario and compares it with its approved baseline. It never writes or
36
+ * changes a baseline: approving a visual change is always a separate, explicit step.
37
+ */
38
+ export declare function runTest(deps: TestRunDeps, options: TestRunOptions): Promise<RunResult>;
@@ -0,0 +1,140 @@
1
+ import { environmentDifferences } from '../baselines/environment-check.js';
2
+ import { captureRequestFor } from './capture-settings.js';
3
+ import { mapWithConcurrency } from './pool.js';
4
+ /** Scenario-level options override the global comparison settings. */
5
+ export function comparisonOptionsFor(scenario, config) {
6
+ const global = config.comparison;
7
+ const own = scenario.comparison;
8
+ const maxDiffRatio = own?.maxDiffRatio ?? global.maxDiffRatio;
9
+ return {
10
+ colorThreshold: own?.colorThreshold ?? global.colorThreshold,
11
+ maxDiffPixels: own?.maxDiffPixels ?? global.maxDiffPixels,
12
+ ...(maxDiffRatio !== undefined ? { maxDiffRatio } : {}),
13
+ };
14
+ }
15
+ function errorOutcome(phase, error) {
16
+ const message = error instanceof Error ? error.message : String(error);
17
+ return { status: 'error', error: { phase, message } };
18
+ }
19
+ async function evaluateScenario(deps, config, scenario, warnings) {
20
+ const captured = await deps.session.capture(captureRequestFor(scenario, config));
21
+ if (!captured.ok) {
22
+ return {
23
+ outcome: {
24
+ status: 'error',
25
+ error: { phase: captured.error.phase, message: captured.error.message },
26
+ },
27
+ };
28
+ }
29
+ const clipped = captured.clipped;
30
+ const options = comparisonOptionsFor(scenario, config);
31
+ let phase = 'baseline';
32
+ try {
33
+ const approved = await deps.store.read(scenario.id);
34
+ // Only looked at when the screenshot differs from what is approved.
35
+ const proposalMatches = async () => {
36
+ const proposed = await deps.proposed?.read(scenario.id);
37
+ return (proposed !== undefined && deps.compare(proposed.png, captured.png, options).kind === 'match');
38
+ };
39
+ if (approved === undefined) {
40
+ const matches = await proposalMatches();
41
+ const actual = await deps.artifacts.write(scenario.id, 'actual', captured.png);
42
+ return {
43
+ outcome: matches
44
+ ? { status: 'changed', change: 'added', artifacts: { actual } }
45
+ : { status: 'missing-baseline', artifacts: { actual } },
46
+ clipped,
47
+ };
48
+ }
49
+ const differences = environmentDifferences(approved.metadata.environment, deps.session.environment);
50
+ if (differences.length > 0) {
51
+ const message = `Baselines were captured in a different environment: ${differences.join('; ')}.`;
52
+ if (config.baselines.strictEnvironment) {
53
+ return { outcome: { status: 'error', error: { phase: 'baseline', message } }, clipped };
54
+ }
55
+ warnings.add(message);
56
+ }
57
+ phase = 'compare';
58
+ const result = deps.compare(approved.png, captured.png, options);
59
+ if (result.kind === 'match') {
60
+ return { outcome: { status: 'passed', stats: result.stats }, clipped };
61
+ }
62
+ const expected = await deps.artifacts.write(scenario.id, 'expected', approved.png);
63
+ const actual = await deps.artifacts.write(scenario.id, 'actual', captured.png);
64
+ const status = (await proposalMatches()) ? 'changed' : 'regression';
65
+ if (result.cause === 'dimensions') {
66
+ const artifacts = { expected, actual };
67
+ return {
68
+ outcome: status === 'changed'
69
+ ? {
70
+ status,
71
+ change: 'modified',
72
+ cause: 'dimensions',
73
+ expected: result.expected,
74
+ actual: result.actual,
75
+ artifacts,
76
+ }
77
+ : {
78
+ status,
79
+ cause: 'dimensions',
80
+ expected: result.expected,
81
+ actual: result.actual,
82
+ artifacts,
83
+ },
84
+ clipped,
85
+ };
86
+ }
87
+ const diff = await deps.artifacts.write(scenario.id, 'diff', result.diffPng);
88
+ const artifacts = { expected, actual, diff };
89
+ return {
90
+ outcome: status === 'changed'
91
+ ? { status, change: 'modified', cause: 'pixels', stats: result.stats, artifacts }
92
+ : { status, cause: 'pixels', stats: result.stats, artifacts },
93
+ clipped,
94
+ };
95
+ }
96
+ catch (error) {
97
+ return { outcome: errorOutcome(phase, error), clipped };
98
+ }
99
+ }
100
+ /**
101
+ * Captures every scenario and compares it with its approved baseline. It never writes or
102
+ * changes a baseline: approving a visual change is always a separate, explicit step.
103
+ */
104
+ export async function runTest(deps, options) {
105
+ const startedAt = new Date();
106
+ const warnings = new Set();
107
+ const scenarios = await mapWithConcurrency(options.scenarios, options.config.concurrency, async (scenario) => {
108
+ const started = Date.now();
109
+ const { outcome, clipped } = await evaluateScenario(deps, options.config, scenario, warnings);
110
+ const result = {
111
+ scenario,
112
+ outcome,
113
+ durationMs: Date.now() - started,
114
+ ...(clipped === true ? { clipped } : {}),
115
+ };
116
+ options.onResult?.(result);
117
+ return result;
118
+ });
119
+ const known = new Set(options.discoveredIds);
120
+ const withoutScenario = (await deps.store.list()).filter((id) => !known.has(id));
121
+ // A baseline whose scenario is gone is only acceptable if the change removes it too.
122
+ let obsolete = withoutScenario;
123
+ let removed = [];
124
+ if (deps.proposed !== undefined) {
125
+ const stillProposed = new Set(await deps.proposed.list());
126
+ obsolete = withoutScenario.filter((id) => stillProposed.has(id));
127
+ removed = withoutScenario.filter((id) => !stillProposed.has(id));
128
+ }
129
+ return {
130
+ startedAt: startedAt.toISOString(),
131
+ durationMs: Date.now() - startedAt.getTime(),
132
+ environment: deps.session.environment,
133
+ scenarios,
134
+ obsolete,
135
+ ...(deps.proposed !== undefined ? { removed } : {}),
136
+ ...(options.selection !== undefined ? { selection: options.selection } : {}),
137
+ ...(warnings.size > 0 ? { warnings: [...warnings] } : {}),
138
+ };
139
+ }
140
+ //# sourceMappingURL=test-run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-run.js","sourceRoot":"","sources":["../../src/core/test-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAmC/C,sEAAsE;AACtE,MAAM,UAAU,oBAAoB,CAClC,QAAwB,EACxB,MAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;IACjC,MAAM,GAAG,GAAG,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,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,WAAW,EAAE;QAClC,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE;QAC5C,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;QACrC,SAAS;QACT,QAAQ;QACR,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ export interface ChangedFiles {
2
+ /** Absolute path of the repository root. */
3
+ readonly repoRoot: string;
4
+ /** The commit the change is measured from. */
5
+ readonly mergeBase: string;
6
+ /** Paths relative to the repository root, using forward slashes. */
7
+ readonly files: readonly string[];
8
+ }
9
+ /**
10
+ * Lists the files a change touches: everything that differs from the merge base of `baseRef`
11
+ * and HEAD, in commits, in the working tree, and untracked files that are not ignored.
12
+ *
13
+ * Measuring from the merge base (not from the tip of `baseRef`) means that work merged into
14
+ * the base branch after this branch was created is not mistaken for part of this change.
15
+ * Renames are reported as a deletion plus an addition, so both paths are seen.
16
+ */
17
+ export declare function changedFiles(cwd: string, baseRef: string): Promise<ChangedFiles>;
@@ -0,0 +1,55 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { ConfigError } from '../shared/errors.js';
4
+ const execFileAsync = promisify(execFile);
5
+ async function git(cwd, args) {
6
+ try {
7
+ const { stdout } = await execFileAsync('git', [...args], {
8
+ cwd,
9
+ maxBuffer: 256 * 1024 * 1024,
10
+ });
11
+ return stdout;
12
+ }
13
+ catch (error) {
14
+ const stderr = error.stderr;
15
+ const detail = typeof stderr === 'string' && stderr.trim() !== '' ? stderr.trim() : String(error);
16
+ throw new ConfigError(`git ${args[0] ?? ''} failed: ${detail}`, { cause: error });
17
+ }
18
+ }
19
+ function splitNul(output) {
20
+ return output.split('\0').filter((entry) => entry !== '');
21
+ }
22
+ /**
23
+ * Lists the files a change touches: everything that differs from the merge base of `baseRef`
24
+ * and HEAD, in commits, in the working tree, and untracked files that are not ignored.
25
+ *
26
+ * Measuring from the merge base (not from the tip of `baseRef`) means that work merged into
27
+ * the base branch after this branch was created is not mistaken for part of this change.
28
+ * Renames are reported as a deletion plus an addition, so both paths are seen.
29
+ */
30
+ export async function changedFiles(cwd, baseRef) {
31
+ let repoRoot;
32
+ try {
33
+ repoRoot = (await git(cwd, ['rev-parse', '--show-toplevel'])).trim();
34
+ }
35
+ catch {
36
+ throw new ConfigError(`${cwd} is not inside a Git repository, so changed files are unknown.`);
37
+ }
38
+ let mergeBase;
39
+ try {
40
+ mergeBase = (await git(repoRoot, ['merge-base', baseRef, 'HEAD'])).trim();
41
+ }
42
+ catch (error) {
43
+ throw new ConfigError(`Could not find the merge base of "${baseRef}" and HEAD. In CI, fetch the full history ` +
44
+ `(for GitHub Actions: actions/checkout with fetch-depth: 0) and make sure "${baseRef}" ` +
45
+ 'exists. ' +
46
+ (error instanceof Error ? error.message : ''), { cause: error });
47
+ }
48
+ const [tracked, untracked] = await Promise.all([
49
+ git(repoRoot, ['diff', '--name-only', '--no-renames', '-z', mergeBase]),
50
+ git(repoRoot, ['ls-files', '--others', '--exclude-standard', '-z']),
51
+ ]);
52
+ const files = [...new Set([...splitNul(tracked), ...splitNul(untracked)])].sort();
53
+ return { repoRoot, m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EAAE,CAAC;IAClF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { VisualScenario } from '../scenarios/model.js';
2
+ export interface ImpactInput {
3
+ /** Files changed since the merge base with `baseRef`, relative to the repository root. */
4
+ readonly changedFiles: readonly string[];
5
+ /** Every scenario that was discovered (before any --filter, include or exclude). */
6
+ readonly scenarios: readonly VisualScenario[];
7
+ /** Absolute path of the repository root. */
8
+ readonly repoRoot: string;
9
+ readonly baseRef: string;
10
+ }
11
+ export type ImpactSelection =
12
+ /** Run every scenario, for example because a global style or token file changed. */
13
+ {
14
+ readonly mode: 'all';
15
+ readonly reason: string;
16
+ }
17
+ /** Run only these scenarios. Each id maps to the reasons it was selected. */
18
+ | {
19
+ readonly mode: 'subset';
20
+ readonly scenarios: Readonly<Record<string, readonly string[]>>;
21
+ };
22
+ export type ImpactAnalyzer = (input: ImpactInput) => ImpactSelection | Promise<ImpactSelection>;
23
+ /** Checks what a consumer module returned, because Viewev cannot trust its types at runtime. */
24
+ export declare function parseImpactSelection(value: unknown): ImpactSelection;
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ const selectionSchema = z.discriminatedUnion('mode', [
3
+ z.object({ mode: z.literal('all'), reason: z.string().min(1) }).strict(),
4
+ z
5
+ .object({
6
+ mode: z.literal('subset'),
7
+ scenarios: z.record(z.array(z.string().min(1)).min(1)),
8
+ })
9
+ .strict(),
10
+ ]);
11
+ /** Checks what a consumer module returned, because Viewev cannot trust its types at runtime. */
12
+ export function parseImpactSelection(value) {
13
+ const parsed = selectionSchema.safeParse(value);
14
+ if (!parsed.success) {
15
+ const details = parsed.error.issues
16
+ .map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`)
17
+ .join('; ');
18
+ throw new Error(`The impact analysis returned an invalid result (${details}). ` +
19
+ 'Expected { mode: "all", reason } or { mode: "subset", scenarios: { id: [reasons] } }.');
20
+ }
21
+ return parsed.data;
22
+ }
23
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/impact/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACnD,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACxE,CAAC;SACE,MAAM,CAAC;QACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACzB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KACvD,CAAC;SACD,MAAM,EAAE;CACZ,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAChC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;aACvE,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,KAAK,CACb,mDAAmD,OAAO,KAAK;YAC7D,uFAAuF,CAC1F,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { defineConfig } from './config/schema.js';
2
+ export type { ViewevConfig, ViewevConfigInput } from './config/schema.js';
3
+ export type { ScenarioId, ScenarioProvider, ScenarioProviderContext, VisualScenario, } from './scenarios/model.js';
4
+ export { ExitCode } from './shared/errors.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // Public API: what config files and future integrations may import.
2
+ export { defineConfig } from './config/schema.js';
3
+ export { ExitCode } from './shared/errors.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ArtifactWriter } from '../core/artifacts.js';
2
+ /**
3
+ * Prepares the report directory for a new run. Only the `artifacts` folder inside it is
4
+ * removed, never the report directory itself, so a mistyped path cannot delete anything else.
5
+ */
6
+ export declare function prepareReportDir(reportDir: string): Promise<void>;
7
+ /** Writes report images as `artifacts/<scenario-id>.<kind>.png` inside the report directory. */
8
+ export declare function createArtifactWriter(reportDir: string): ArtifactWriter;
@@ -0,0 +1,23 @@
1
+ import { mkdir, rm, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ const ARTIFACTS_DIR = 'artifacts';
4
+ /**
5
+ * Prepares the report directory for a new run. Only the `artifacts` folder inside it is
6
+ * removed, never the report directory itself, so a mistyped path cannot delete anything else.
7
+ */
8
+ export async function prepareReportDir(reportDir) {
9
+ await rm(path.join(reportDir, ARTIFACTS_DIR), { recursive: true, force: true });
10
+ await mkdir(path.join(reportDir, ARTIFACTS_DIR), { recursive: true });
11
+ }
12
+ /** Writes report images as `artifacts/<scenario-id>.<kind>.png` inside the report directory. */
13
+ export function createArtifactWriter(reportDir) {
14
+ return {
15
+ async write(id, kind, png) {
16
+ const fileName = `${id}.${kind}.png`;
17
+ await writeFile(path.join(reportDir, ARTIFACTS_DIR, fileName), png);
18
+ // Always forward slashes, so the same path works in JSON and HTML on every platform.
19
+ return path.posix.join(ARTIFACTS_DIR, fileName);
20
+ },
21
+ };
22
+ }
23
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../src/reporting/artifacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,aAAa,GAAG,WAAW,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,SAAiB;IACtD,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChF,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,IAAkB,EAAE,GAAG;YACrC,MAAM,QAAQ,GAAG,GAAG,EAAE,IAAI,IAAI,MAAM,CAAC;YACrC,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;YACpE,qFAAqF;YACrF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ResultsFile } from './results-json.js';
2
+ export declare function escapeHtml(value: string): string;
3
+ /** Renders the whole report as one self-contained HTML document (no external requests). */
4
+ export declare function renderReportHtml(file: ResultsFile): string;
@@ -0,0 +1,244 @@
1
+ export function escapeHtml(value) {
2
+ return value
3
+ .replace(/&/g, '&amp;')
4
+ .replace(/</g, '&lt;')
5
+ .replace(/>/g, '&gt;')
6
+ .replace(/"/g, '&quot;')
7
+ .replace(/'/g, '&#39;');
8
+ }
9
+ const e = escapeHtml;
10
+ const STATUS_ORDER = ['error', 'regression', 'changed', 'missing-baseline', 'passed'];
11
+ const STATUS_LABELS = {
12
+ error: 'Error',
13
+ regression: 'Regression',
14
+ changed: 'Changed in this PR',
15
+ 'missing-baseline': 'No baseline',
16
+ passed: 'Passed',
17
+ };
18
+ function percent(ratio) {
19
+ const value = ratio * 100;
20
+ return value > 0 && value < 0.01 ? '<0.01%' : `${value.toFixed(2)}%`;
21
+ }
22
+ function figure(label, source, id) {
23
+ if (source === undefined)
24
+ return '';
25
+ return (`<figure><figcaption>${e(label)}</figcaption>` +
26
+ `<a href="${e(source)}" target="_blank" rel="noopener">` +
27
+ `<img src="${e(source)}" loading="lazy" alt="${e(`${label} screenshot of ${id}`)}"></a></figure>`);
28
+ }
29
+ function blink(expected, actual, id) {
30
+ if (expected === undefined || actual === undefined)
31
+ return '';
32
+ return ('<div class="blink" data-state="expected">' +
33
+ '<button type="button" class="blink-toggle">Switch expected / actual</button> ' +
34
+ '<span class="blink-label muted">showing expected</span>' +
35
+ `<div class="blink-stack"><img class="b-expected" src="${e(expected)}" loading="lazy" alt="Expected screenshot of ${e(id)}">` +
36
+ `<img class="b-actual" src="${e(actual)}" loading="lazy" alt="Actual screenshot of ${e(id)}"></div></div>`);
37
+ }
38
+ function details(scenario) {
39
+ const rows = [
40
+ ['Viewport', `${scenario.viewport.width}x${scenario.viewport.height}`],
41
+ ['Source', `${scenario.origin.provider}: ${scenario.origin.ref}`],
42
+ ['Duration', `${scenario.durationMs} ms`],
43
+ ];
44
+ if (scenario.variant !== undefined) {
45
+ rows.push([
46
+ 'Variant',
47
+ Object.entries(scenario.variant)
48
+ .map(([k, v]) => `${k}=${v}`)
49
+ .join(', '),
50
+ ]);
51
+ }
52
+ if (scenario.clipped === true) {
53
+ rows.push(['Note', 'The page is larger than the viewport, so only part of it is captured.']);
54
+ }
55
+ return ('<table class="meta">' +
56
+ rows.map(([name, value]) => `<tr><th>${e(name)}</th><td>${e(value)}</td></tr>`).join('') +
57
+ '</table>');
58
+ }
59
+ function summaryText(scenario) {
60
+ const { outcome } = scenario;
61
+ switch (outcome.status) {
62
+ case 'passed':
63
+ return `${percent(outcome.stats.diffRatio)} different`;
64
+ case 'regression':
65
+ return outcome.cause === 'dimensions'
66
+ ? `size changed ${outcome.expected.width}x${outcome.expected.height} → ${outcome.actual.width}x${outcome.actual.height}`
67
+ : `${percent(outcome.stats.diffRatio)} different (${outcome.stats.diffPixels} of ${outcome.stats.totalPixels} px)`;
68
+ case 'missing-baseline':
69
+ return 'no approved baseline yet';
70
+ case 'changed':
71
+ if (outcome.change === 'added')
72
+ return 'new baseline proposed by this change';
73
+ return outcome.cause === 'dimensions'
74
+ ? `baseline update proposed: size ${outcome.expected.width}x${outcome.expected.height} → ${outcome.actual.width}x${outcome.actual.height}`
75
+ : `baseline update proposed: ${percent(outcome.stats.diffRatio)} different from the approved baseline`;
76
+ case 'error':
77
+ return `[${outcome.error.phase}] ${outcome.error.message}`;
78
+ }
79
+ }
80
+ function body(scenario) {
81
+ const { outcome, id } = scenario;
82
+ switch (outcome.status) {
83
+ case 'passed':
84
+ return '';
85
+ case 'error':
86
+ return `<p class="error-text">${e(outcome.error.message)}</p>`;
87
+ case 'missing-baseline':
88
+ return `<div class="images">${figure('Actual', outcome.artifacts.actual, id)}</div>`;
89
+ case 'changed': {
90
+ const { expected, actual, diff } = outcome.artifacts;
91
+ return (`<p class="muted">The approved baseline differs, but this change proposes a matching one. ` +
92
+ `Review the baseline images in the pull request.</p>` +
93
+ `<div class="images">${figure('Approved', expected, id)}${figure('New', actual, id)}` +
94
+ `${figure('Difference', diff, id)}</div>${blink(expected, actual, id)}`);
95
+ }
96
+ case 'regression': {
97
+ const { expected, actual, diff } = outcome.artifacts;
98
+ return (`<div class="images">${figure('Expected', expected, id)}${figure('Actual', actual, id)}` +
99
+ `${figure('Difference', diff, id)}</div>${blink(expected, actual, id)}`);
100
+ }
101
+ }
102
+ }
103
+ function scenarioHtml(scenario) {
104
+ const { status } = scenario.outcome;
105
+ const label = `<span class="badge ${status}">${STATUS_LABELS[status]}</span>`;
106
+ const title = `${label} <span class="id">${e(scenario.id)}</span> ` +
107
+ `<span class="muted">${e(scenario.name)}</span> <span class="muted">— ${e(summaryText(scenario))}</span>`;
108
+ if (status === 'passed') {
109
+ return `<div class="scenario row" data-status="${status}">${title}</div>`;
110
+ }
111
+ return (`<details class="scenario" data-status="${status}" open><summary>${title}</summary>` +
112
+ `${body(scenario)}${details(scenario)}</details>`);
113
+ }
114
+ const STYLE = `
115
+ :root{color-scheme:light dark;--bg:#fff;--fg:#161616;--muted:#6f6f6f;--line:#d0d0d0;--card:#f4f4f4;
116
+ --ok:#198038;--bad:#da1e28;--warn:#b28600;--info:#0f62fe}
117
+ @media (prefers-color-scheme:dark){:root{--bg:#161616;--fg:#f4f4f4;--muted:#a8a8a8;--line:#393939;--card:#262626;
118
+ --ok:#42be65;--bad:#fa4d56;--warn:#f1c21b;--info:#78a9ff}}
119
+ *{box-sizing:border-box}
120
+ body{margin:0;background:var(--bg);color:var(--fg);font:14px/1.5 system-ui,-apple-system,Segoe UI,sans-serif}
121
+ header,main,footer{max-width:1200px;margin:0 auto;padding:16px 24px}
122
+ h1{margin:0 0 4px;font-size:22px}h2{font-size:16px;margin:24px 0 8px}
123
+ .muted{color:var(--muted)}.id{font-family:ui-monospace,Menlo,Consolas,monospace;font-weight:600}
124
+ .counts{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0}
125
+ .counts button{border:1px solid var(--line);background:var(--card);color:var(--fg);border-radius:6px;padding:6px 12px;cursor:pointer;font:inherit}
126
+ .counts button[aria-pressed=true]{border-color:var(--info);outline:1px solid var(--info)}
127
+ .badge{display:inline-block;border-radius:4px;padding:0 8px;font-size:12px;font-weight:600;color:#fff}
128
+ .badge.passed{background:var(--ok)}.badge.changed{background:var(--info)}.badge.regression,.badge.error{background:var(--bad)}.badge.missing-baseline{background:var(--warn);color:#161616}
129
+ .scenario{border:1px solid var(--line);border-radius:6px;margin:8px 0;background:var(--card)}
130
+ .scenario.row{padding:6px 12px}details.scenario>summary{padding:8px 12px;cursor:pointer}
131
+ details.scenario>*:not(summary){margin:8px 12px 12px}
132
+ .images{display:flex;gap:12px;flex-wrap:wrap}figure{margin:0;flex:1 1 280px;min-width:0}
133
+ figcaption{font-weight:600;margin-bottom:4px}img{max-width:100%;height:auto;border:1px solid var(--line);background:#fff}
134
+ .blink{margin-top:12px}.blink-stack{margin-top:6px}.blink[data-state=expected] .b-actual,.blink[data-state=actual] .b-expected{display:none}
135
+ .meta{border-collapse:collapse}.meta th{text-align:left;padding:2px 16px 2px 0;color:var(--muted);font-weight:500}
136
+ .error-text{color:var(--bad);font-family:ui-monospace,Menlo,Consolas,monospace}
137
+ .warnings{border-left:4px solid var(--warn);padding:4px 12px;background:var(--card)}
138
+ .notice{border-left:4px solid var(--info);padding:6px 12px;margin:12px 0;background:var(--card)}
139
+ ul.plain{padding-left:20px}
140
+ `;
141
+ const FILTERS = ['all', ...STATUS_ORDER];
142
+ function filterRules() {
143
+ return FILTERS.filter((f) => f !== 'all')
144
+ .map((f) => `main[data-filter="${f}"] .scenario:not([data-status="${f}"]){display:none}`)
145
+ .join('\n');
146
+ }
147
+ const SCRIPT = `
148
+ document.addEventListener('click', function (event) {
149
+ var target = event.target;
150
+ if (!(target instanceof Element)) return;
151
+ var filter = target.closest('[data-set-filter]');
152
+ if (filter) {
153
+ document.querySelector('main').setAttribute('data-filter', filter.getAttribute('data-set-filter'));
154
+ document.querySelectorAll('[data-set-filter]').forEach(function (button) {
155
+ button.setAttribute('aria-pressed', String(button === filter));
156
+ });
157
+ return;
158
+ }
159
+ var toggle = target.closest('.blink-toggle');
160
+ if (toggle) {
161
+ var blink = toggle.closest('.blink');
162
+ var next = blink.getAttribute('data-state') === 'expected' ? 'actual' : 'expected';
163
+ blink.setAttribute('data-state', next);
164
+ blink.querySelector('.blink-label').textContent = 'showing ' + next;
165
+ }
166
+ });
167
+ `;
168
+ /** Renders the whole report as one self-contained HTML document (no external requests). */
169
+ export function renderReportHtml(file) {
170
+ const { summary } = file;
171
+ const counts = {
172
+ all: summary.total,
173
+ error: summary.errors,
174
+ regression: summary.regressions,
175
+ changed: summary.changed,
176
+ 'missing-baseline': summary.missingBaselines,
177
+ passed: summary.passed,
178
+ };
179
+ const filterLabels = {
180
+ all: 'All',
181
+ ...STATUS_LABELS,
182
+ };
183
+ const buttons = FILTERS.map((f) => `<button type="button" data-set-filter="${f}" aria-pressed="${f === 'all'}">` +
184
+ `${filterLabels[f]} (${counts[f]})</button>`).join('');
185
+ const sorted = [...file.scenarios].sort((a, b) => STATUS_ORDER.indexOf(a.outcome.status) - STATUS_ORDER.indexOf(b.outcome.status) ||
186
+ a.id.localeCompare(b.id));
187
+ const environment = file.environment === undefined
188
+ ? ''
189
+ : `Chromium ${e(file.environment.browser.version)} on ${e(file.environment.os.platform)}/` +
190
+ `${e(file.environment.os.arch)} (${e(file.environment.automation.name)} ` +
191
+ `${e(file.environment.automation.version)})`;
192
+ const selection = file.selection;
193
+ const selectionHtml = selection === undefined
194
+ ? ''
195
+ : selection.mode === 'all'
196
+ ? `<div class="notice">Impact analysis: every scenario ran. ${e(selection.reason ?? '')}</div>`
197
+ : `<div class="notice">Selective run: ${selection.selected} of ${selection.total} scenarios were selected` +
198
+ `${selection.baseRef !== undefined ? ` for the changes since ${e(selection.baseRef)}` : ''}` +
199
+ ` (${selection.changedFileCount ?? 0} changed files). Scenarios that were not selected were ` +
200
+ 'not tested, so this report is not full visual coverage.</div>';
201
+ const warnings = file.warnings.length > 0
202
+ ? `<h2>Warnings</h2><div class="warnings">${file.warnings.map((w) => `<p>${e(w)}</p>`).join('')}</div>`
203
+ : '';
204
+ const removed = file.removed ?? [];
205
+ const removedHtml = removed.length > 0
206
+ ? `<h2>Baselines removed by this change (${removed.length})</h2>` +
207
+ '<p class="muted">Their scenarios no longer exist and this change deletes the baselines too.</p>' +
208
+ `<ul class="plain">${removed.map((id) => `<li class="id">${e(id)}</li>`).join('')}</ul>`
209
+ : '';
210
+ const obsolete = file.obsolete.length > 0
211
+ ? `<h2>Obsolete baselines (${file.obsolete.length})</h2>` +
212
+ '<p class="muted">These baselines have no matching scenario. Remove them with <code>viewev baseline prune --yes</code>.</p>' +
213
+ `<ul class="plain">${file.obsolete.map((id) => `<li class="id">${e(id)}</li>`).join('')}</ul>`
214
+ : '';
215
+ return `<!doctype html>
216
+ <html lang="en">
217
+ <head>
218
+ <meta charset="utf-8">
219
+ <meta name="viewport" content="width=device-width, initial-scale=1">
220
+ <title>Viewev report</title>
221
+ <style>${STYLE}${filterRules()}</style>
222
+ </head>
223
+ <body>
224
+ <header>
225
+ <h1>Viewev report</h1>
226
+ <div class="muted"><time datetime="${e(file.startedAt)}">${e(file.startedAt)}</time> · ${file.durationMs} ms</div>
227
+ <div class="muted">${environment}</div>
228
+ ${selectionHtml}
229
+ <div class="counts">${buttons}</div>
230
+ </header>
231
+ <main data-filter="all">
232
+ ${warnings}
233
+ <h2>Scenarios</h2>
234
+ ${sorted.length > 0 ? sorted.map(scenarioHtml).join('\n') : '<p class="muted">No scenarios were run.</p>'}
235
+ ${obsolete}
236
+ ${removedHtml}
237
+ </main>
238
+ <footer class="muted">Generated by Viewev. Approve intended changes with <code>viewev baseline update</code> and review the changed images in Git.</footer>
239
+ <script>${SCRIPT}</script>
240
+ </body>
241
+ </html>
242
+ `;
243
+ }
244
+ //# sourceMappingURL=html.js.map