@artis-lab/cli 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/package.json +2 -3
- package/src/bin.js +6 -5
- package/src/lib/app.js +6 -5
- package/src/lib/chunk-4O5BCFCD.js +60 -0
- package/src/lib/{chunk-43EXTJSU.js → chunk-FSJVBXCW.js} +3 -31
- package/src/lib/chunk-I5P3FLKO.js +929 -0
- package/src/lib/{chunk-VBJGJXYL.js → chunk-P4O6TXMP.js} +16 -20
- package/src/lib/{chunk-VLYS5R67.js → chunk-T24DNA2K.js} +1 -1
- package/src/lib/{chunk-JPCT7RRK.js → chunk-XTAKEL34.js} +58 -17
- package/src/lib/cli.js +3 -3
- package/src/lib/commands.js +5 -4
- package/src/lib/files.js +2 -1
- package/src/lib/verify.js +2 -3
- package/src/lib/chunk-QZFIUZXT.js +0 -10954
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseTypeSourceIssueLine,
|
|
3
|
+
toTypeSourceIssue
|
|
4
|
+
} from "./chunk-4O5BCFCD.js";
|
|
5
|
+
|
|
6
|
+
// packages/cli/src/lib/verify.ts
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { createServer } from "node:http";
|
|
9
|
+
|
|
10
|
+
// packages/sdk/src/lib/assets.ts
|
|
11
|
+
var assetLimits = {
|
|
12
|
+
/** One asset. */
|
|
13
|
+
maxFileBytes: 20 * 1024 * 1024,
|
|
14
|
+
maxArtifactBytes: 256 * 1024 * 1024,
|
|
15
|
+
maxArtifactAssets: 1e3,
|
|
16
|
+
maxOwnerBytes: 2 * 1024 * 1024 * 1024,
|
|
17
|
+
/** One upload through MCP, whose body carries the bytes as base64. */
|
|
18
|
+
maxMcpFileBytes: 2 * 1024 * 1024,
|
|
19
|
+
/** Code points kept of an asset's original name. */
|
|
20
|
+
maxNameLength: 255,
|
|
21
|
+
/** A pending upload older than this is reclaimed by the next upload. */
|
|
22
|
+
pendingTtlMs: 60 * 60 * 1e3,
|
|
23
|
+
/** How many leading bytes decide a file's type: the binary signatures
|
|
24
|
+
* need 12, an svg's `<svg` can sit behind a prolog and comments. */
|
|
25
|
+
sniffBytes: 64 * 1024
|
|
26
|
+
};
|
|
27
|
+
function assetResponseCsp(contentType) {
|
|
28
|
+
if (contentType === "image/svg+xml") {
|
|
29
|
+
return "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
30
|
+
}
|
|
31
|
+
if (/^(text\/|application\/json)/.test(contentType)) {
|
|
32
|
+
return "default-src 'none'; sandbox";
|
|
33
|
+
}
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// packages/sdk/src/lib/contract.ts
|
|
38
|
+
var pageViewEvents = {
|
|
39
|
+
/** The bridge dispatches it on an annotation's anchor element (bubbling)
|
|
40
|
+
* before it scrolls to that annotation. */
|
|
41
|
+
reveal: "artis:reveal",
|
|
42
|
+
/** A page dispatches it on `document` (or any element; it should bubble)
|
|
43
|
+
* after it changed which content is visible. */
|
|
44
|
+
viewChanged: "artis:view-changed"
|
|
45
|
+
};
|
|
46
|
+
var pageViewEventsDocs = `Pages that show only part of their content at a time (tabs, accordions, carousels, slides) can cooperate with review comments through two DOM events. Both work on every page; a page that ignores them still works.
|
|
47
|
+
|
|
48
|
+
- **\`${pageViewEvents.reveal}\`**: when a reviewer opens a comment, Artis dispatches a bubbling \`CustomEvent\` on the commented element (for a text comment, the element holding the start of the quote) before scrolling to it, even when that element is hidden. \`event.detail\` is \`{ annotationId: string }\`. Listen on \`document\` and make \`event.target\` visible (switch to its tab, open its \`<details>\`, go to its slide), synchronously or soon after. Artis waits one frame, or for \`${pageViewEvents.viewChanged}\` if it comes first; if the element is still hidden after that frame, it waits up to half a second more for \`${pageViewEvents.viewChanged}\`. Then it scrolls to the element.
|
|
49
|
+
- **\`${pageViewEvents.viewChanged}\`**: dispatch \`document.dispatchEvent(new Event('${pageViewEvents.viewChanged}'))\` after the page changes which content is visible (any cause: the reader's click, a key, a timer, \`${pageViewEvents.reveal}\`). Artis then re-places comment pins at once. Without it, pins move only after a DOM mutation settles (about a second) and not at all for a pure class, attribute or style switch. No \`detail\` is read.
|
|
50
|
+
|
|
51
|
+
Comments on content that is currently not rendered (\`display: none\`, \`visibility: hidden\`, a closed \`<details>\`, \`hidden\`) show no pin until it becomes visible again.`;
|
|
52
|
+
var pageAddressDocs = `In the Artis viewer the page's own \`#fragment\` shows in the viewer's address bar, so a copied link opens the page where the reader was (a slide, a tab, a section), and a fragment the reader types or follows there reaches the page as an ordinary \`hashchange\`.
|
|
53
|
+
|
|
54
|
+
- **Change it with \`history.replaceState\`** (or \`location.replace\`), not by assigning \`location.hash\` or \`pushState\`: the page runs in a frame whose history is the viewer's, so every pushed entry is one more press of Back before the reader leaves. After a \`replaceState\`, which fires no event, dispatch \`${pageViewEvents.viewChanged}\` (above) so Artis sees the new fragment.
|
|
55
|
+
- **Leave the \`artis=\` part alone.** The fragment Artis loads the page with ends in \`&artis=\u2026\`, the viewer's configuration. Read and write only the part in front of it, and keep the rest when you write.
|
|
56
|
+
- Only a plain target is mirrored: up to 200 URL fragment characters without \`&\`, \`=\` or \`#\`, such as \`slide-4\` or \`pricing\`. Other fragments still work in the page; the address bar just keeps its previous one.`;
|
|
57
|
+
var pageViewEventsTypes = ` /** \`event.detail\` of \`${pageViewEvents.reveal}\`. */
|
|
58
|
+
interface ArtisRevealDetail {
|
|
59
|
+
readonly annotationId: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface DocumentEventMap {
|
|
63
|
+
/** Dispatched by Artis on a commented element (bubbling) before it
|
|
64
|
+
* scrolls to it: make \`event.target\` visible. */
|
|
65
|
+
'${pageViewEvents.reveal}': CustomEvent<ArtisRevealDetail>;
|
|
66
|
+
/** Dispatch it after changing which content is visible. */
|
|
67
|
+
'${pageViewEvents.viewChanged}': Event;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface HTMLElementEventMap {
|
|
71
|
+
'${pageViewEvents.reveal}': CustomEvent<ArtisRevealDetail>;
|
|
72
|
+
}`;
|
|
73
|
+
|
|
74
|
+
// packages/slides-format/src/lib/constants.ts
|
|
75
|
+
var SLIDE_SIZES = ["16:9", "4:3"];
|
|
76
|
+
var SLIDE_CANVAS = {
|
|
77
|
+
"16:9": { width: 1920, height: 1080 },
|
|
78
|
+
"4:3": { width: 1440, height: 1080 },
|
|
79
|
+
margin: 128
|
|
80
|
+
};
|
|
81
|
+
var SLIDE_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
82
|
+
var GOOGLE_FONTS_STYLESHEET_PREFIX = "https://fonts.googleapis.com/css2?";
|
|
83
|
+
var SLIDES_LIMITS = {
|
|
84
|
+
/** Slides in one deck. */
|
|
85
|
+
slidesPerDeck: 500,
|
|
86
|
+
/** Element boxes in one slide (see `checkSlidesDeck` for what counts). */
|
|
87
|
+
boxesPerSlide: 200,
|
|
88
|
+
/** Nested `<div>`s in one slide. */
|
|
89
|
+
divDepth: 15,
|
|
90
|
+
/** Characters of slide text, speaker notes excluded. */
|
|
91
|
+
textPerSlide: 2e4,
|
|
92
|
+
/** Inline marks (`<b>`, `<span>`, `<a>`, …) in one slide. */
|
|
93
|
+
inlineMarksPerSlide: 100,
|
|
94
|
+
/** Table cells in one slide. */
|
|
95
|
+
tableCellsPerSlide: 4e3,
|
|
96
|
+
/** Rows in one table. */
|
|
97
|
+
tableRows: 100,
|
|
98
|
+
/** Columns in one table. */
|
|
99
|
+
tableColumns: 24,
|
|
100
|
+
/** Characters of speaker notes in one slide (a hint, not an error). */
|
|
101
|
+
notesLength: 4e3,
|
|
102
|
+
/** Bytes of one inline `<svg>` (a hint, not an error). */
|
|
103
|
+
svgBytes: 52 * 1024
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// packages/slides-format/src/lib/files.ts
|
|
107
|
+
var SLIDES_DECK_FILE = "deck.json";
|
|
108
|
+
var MAX_FONT_STYLESHEETS = 4;
|
|
109
|
+
function readSlidesDeckManifest(text) {
|
|
110
|
+
if (text === void 0) {
|
|
111
|
+
return { ok: false, error: `${SLIDES_DECK_FILE} is missing.` };
|
|
112
|
+
}
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = JSON.parse(text);
|
|
116
|
+
} catch {
|
|
117
|
+
return { ok: false, error: `${SLIDES_DECK_FILE} is not valid JSON.` };
|
|
118
|
+
}
|
|
119
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
120
|
+
return { ok: false, error: `${SLIDES_DECK_FILE} must be a JSON object.` };
|
|
121
|
+
}
|
|
122
|
+
const deck = parsed;
|
|
123
|
+
const title = deck.title ?? "";
|
|
124
|
+
if (typeof title !== "string") {
|
|
125
|
+
return { ok: false, error: `${SLIDES_DECK_FILE}: title must be a string.` };
|
|
126
|
+
}
|
|
127
|
+
const size = deck.size ?? "16:9";
|
|
128
|
+
if (!SLIDE_SIZES.includes(size)) {
|
|
129
|
+
return {
|
|
130
|
+
ok: false,
|
|
131
|
+
error: `${SLIDES_DECK_FILE}: size must be ${SLIDE_SIZES.map((s) => `"${s}"`).join(" or ")}.`
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const fonts = deck.fonts ?? [];
|
|
135
|
+
if (!Array.isArray(fonts) || fonts.length > MAX_FONT_STYLESHEETS || !fonts.every(
|
|
136
|
+
(font) => typeof font === "string" && font.startsWith(GOOGLE_FONTS_STYLESHEET_PREFIX) && !/[\s"<>]/.test(font)
|
|
137
|
+
)) {
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
error: `${SLIDES_DECK_FILE}: fonts must be at most ${MAX_FONT_STYLESHEETS} Google Fonts stylesheet URLs (${GOOGLE_FONTS_STYLESHEET_PREFIX}\u2026).`
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const slides = deck.slides;
|
|
144
|
+
if (!Array.isArray(slides) || slides.length === 0 || slides.length > SLIDES_LIMITS.slidesPerDeck) {
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
error: `${SLIDES_DECK_FILE}: slides must list 1 to ${SLIDES_LIMITS.slidesPerDeck} slide ids.`
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
151
|
+
for (const id of slides) {
|
|
152
|
+
if (typeof id !== "string" || !SLIDE_ID_PATTERN.test(id)) {
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
error: `${SLIDES_DECK_FILE}: ${JSON.stringify(id)} is not a slide id (letters, digits, _ and -, at most 64).`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (seen.has(id)) {
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
error: `${SLIDES_DECK_FILE}: slide ${id} is listed twice.`
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
seen.add(id);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
ok: true,
|
|
168
|
+
value: {
|
|
169
|
+
title,
|
|
170
|
+
size,
|
|
171
|
+
fonts,
|
|
172
|
+
slides
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// packages/cli/src/lib/verify.ts
|
|
178
|
+
var verifyWidths = [1280, 390];
|
|
179
|
+
var verifyThemes = ["light", "dark"];
|
|
180
|
+
function runWidths(type) {
|
|
181
|
+
return type ? [verifyWidths[0]] : verifyWidths;
|
|
182
|
+
}
|
|
183
|
+
var GOOGLE_FONTS_STYLE_ORIGIN = "https://fonts.googleapis.com";
|
|
184
|
+
var GOOGLE_FONTS_FONT_ORIGIN = "https://fonts.gstatic.com";
|
|
185
|
+
function artifactContentSecurityPolicy(origin, sandboxTokens = [], options = {}) {
|
|
186
|
+
const styleSrc = options.googleFonts ? `'unsafe-inline' ${GOOGLE_FONTS_STYLE_ORIGIN}` : "'unsafe-inline'";
|
|
187
|
+
const fontSrc = options.googleFonts ? `data: ${GOOGLE_FONTS_FONT_ORIGIN}` : "data:";
|
|
188
|
+
const sandbox = options.artifactHost ? ["allow-scripts", "allow-forms", "allow-same-origin"] : ["allow-scripts", "allow-forms"];
|
|
189
|
+
for (const token of sandboxTokens) {
|
|
190
|
+
if (/^allow-[a-z-]+$/.test(token) && !sandbox.includes(token)) {
|
|
191
|
+
sandbox.push(token);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const assets = `${origin}/_blob/`;
|
|
195
|
+
const connectSrc = options.connectSrc && /^https?:\/\/[^\s;,'"]+\/$/.test(options.connectSrc) ? `connect-src ${options.connectSrc} ${assets}; ` : `connect-src ${assets}; `;
|
|
196
|
+
return `sandbox ${sandbox.join(" ")}; default-src 'none'; script-src 'unsafe-inline' ${origin}/__artis/; style-src ${styleSrc}; img-src data: blob: ${assets}; font-src ${fontSrc} ${assets}; media-src ${assets}; ${connectSrc}form-action 'none'; base-uri 'none'`;
|
|
197
|
+
}
|
|
198
|
+
var VerifyUnavailableError = class extends Error {
|
|
199
|
+
};
|
|
200
|
+
async function launchBrowser() {
|
|
201
|
+
let chromium;
|
|
202
|
+
try {
|
|
203
|
+
const specifier = "playwright-core";
|
|
204
|
+
({ chromium } = await import(specifier));
|
|
205
|
+
} catch {
|
|
206
|
+
throw new VerifyUnavailableError(
|
|
207
|
+
"artis verify needs playwright-core. Install it next to the CLI: npm install -g playwright-core"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const executablePath = process.env["ARTIS_CHROME_PATH"];
|
|
211
|
+
const attempts = executablePath ? [{ executablePath }] : [{ channel: "chrome" }, { channel: "msedge" }, { channel: "chromium" }];
|
|
212
|
+
for (const attempt of attempts) {
|
|
213
|
+
try {
|
|
214
|
+
return await chromium.launch({
|
|
215
|
+
headless: true,
|
|
216
|
+
// The page's artifact host, `<uuid>.localhost`, is the loopback
|
|
217
|
+
// address the server listens on, whatever the system resolver says.
|
|
218
|
+
args: ["--host-resolver-rules=MAP *.localhost 127.0.0.1"],
|
|
219
|
+
...attempt
|
|
220
|
+
});
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
throw new VerifyUnavailableError(
|
|
225
|
+
executablePath ? `Could not launch the browser at ARTIS_CHROME_PATH (${executablePath}).` : "artis verify uses the system Google Chrome (or Edge). Install one, or set ARTIS_CHROME_PATH to a Chromium-based browser."
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
var RUNTIME_PATH = "/__artis/types/verify/v1/verify.js";
|
|
229
|
+
var LOCAL_REVISION = "verify";
|
|
230
|
+
var ASSET_PATH = /^\/_blob\/([0-9a-f-]{36})$/;
|
|
231
|
+
var FILE_PATH = /^\/r\/([^/]+)\/files\/(.+)$/;
|
|
232
|
+
async function serveRevision(files, type, assets = { notLoaded: /* @__PURE__ */ new Set() }) {
|
|
233
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
234
|
+
const pagePath = `/r/${LOCAL_REVISION}/`;
|
|
235
|
+
const server = createServer((request, response) => {
|
|
236
|
+
const url = new URL(request.url ?? "/", "http://localhost");
|
|
237
|
+
const origin = `http://${request.headers.host}`;
|
|
238
|
+
const asset = ASSET_PATH.exec(url.pathname);
|
|
239
|
+
if (asset) {
|
|
240
|
+
const id = asset[1];
|
|
241
|
+
if (!assets.load) {
|
|
242
|
+
assets.notLoaded.add(id);
|
|
243
|
+
response.writeHead(204).end();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
let pending = loaded.get(id);
|
|
247
|
+
if (!pending) {
|
|
248
|
+
pending = assets.load(id).catch(() => "unchecked");
|
|
249
|
+
loaded.set(id, pending);
|
|
250
|
+
}
|
|
251
|
+
void pending.then((found) => {
|
|
252
|
+
if (found === "unchecked") {
|
|
253
|
+
assets.notLoaded.add(id);
|
|
254
|
+
response.writeHead(204).end();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!found) {
|
|
258
|
+
response.writeHead(404).end();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const csp = assetResponseCsp(found.contentType);
|
|
262
|
+
response.writeHead(200, {
|
|
263
|
+
"content-type": found.contentType,
|
|
264
|
+
"x-content-type-options": "nosniff",
|
|
265
|
+
...csp ? { "content-security-policy": csp } : {}
|
|
266
|
+
});
|
|
267
|
+
response.end(found.bytes);
|
|
268
|
+
});
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (type && url.pathname === RUNTIME_PATH) {
|
|
272
|
+
response.writeHead(200, {
|
|
273
|
+
"content-type": "text/javascript; charset=utf-8"
|
|
274
|
+
});
|
|
275
|
+
response.end(type.runtime);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const file = FILE_PATH.exec(url.pathname);
|
|
279
|
+
if (file) {
|
|
280
|
+
let filePath;
|
|
281
|
+
try {
|
|
282
|
+
filePath = decodeURIComponent(file[2]);
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
const content = file[1] === LOCAL_REVISION && filePath !== void 0 && Object.prototype.hasOwnProperty.call(files, filePath) ? files[filePath] : void 0;
|
|
286
|
+
if (content === void 0) {
|
|
287
|
+
response.writeHead(404).end();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
response.writeHead(200, {
|
|
291
|
+
"content-type": "text/plain; charset=utf-8",
|
|
292
|
+
"content-security-policy": artifactContentSecurityPolicy(origin),
|
|
293
|
+
"x-content-type-options": "nosniff"
|
|
294
|
+
});
|
|
295
|
+
response.end(content);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (url.pathname === "/" || url.pathname === `/r/${LOCAL_REVISION}`) {
|
|
299
|
+
response.writeHead(302, { location: `${pagePath}${url.search}` }).end();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (url.pathname !== pagePath) {
|
|
303
|
+
response.writeHead(404).end();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const theme = url.searchParams.get("theme") === "dark" ? "dark" : "light";
|
|
307
|
+
response.writeHead(200, {
|
|
308
|
+
"content-type": "text/html; charset=utf-8",
|
|
309
|
+
"content-security-policy": artifactContentSecurityPolicy(origin, [], {
|
|
310
|
+
googleFonts: type?.googleFonts === true,
|
|
311
|
+
artifactHost: true,
|
|
312
|
+
// The runtime may fetch this revision's files, and nothing else.
|
|
313
|
+
connectSrc: type ? `${origin}/r/${LOCAL_REVISION}/files/` : void 0
|
|
314
|
+
})
|
|
315
|
+
});
|
|
316
|
+
const page = stampTheme(
|
|
317
|
+
type ? type.entry : files["index.html"] ?? "",
|
|
318
|
+
theme
|
|
319
|
+
);
|
|
320
|
+
response.end(type ? injectRuntime(page, RUNTIME_PATH) : page);
|
|
321
|
+
});
|
|
322
|
+
await new Promise((resolve, reject) => {
|
|
323
|
+
server.once("error", reject);
|
|
324
|
+
server.listen(0, "127.0.0.1", () => {
|
|
325
|
+
server.off("error", reject);
|
|
326
|
+
resolve();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
const { port } = server.address();
|
|
330
|
+
const host = `${randomUUID()}.localhost:${port}`;
|
|
331
|
+
return {
|
|
332
|
+
server,
|
|
333
|
+
url: (theme) => `http://${host}${pagePath}?theme=${theme}`
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function stampTheme(html, theme) {
|
|
337
|
+
const boot = `<script>document.documentElement.setAttribute('data-theme','${theme}');document.documentElement.style.colorScheme='${theme}';</script>`;
|
|
338
|
+
const head = /<head\b[^>]*>/i.exec(html);
|
|
339
|
+
if (!head) {
|
|
340
|
+
return html;
|
|
341
|
+
}
|
|
342
|
+
const at = head.index + head[0].length;
|
|
343
|
+
return html.slice(0, at) + boot + html.slice(at);
|
|
344
|
+
}
|
|
345
|
+
function injectRuntime(html, src) {
|
|
346
|
+
const tag = `<script src="${src}"></script>`;
|
|
347
|
+
const close = html.toLowerCase().lastIndexOf("</body");
|
|
348
|
+
return close < 0 ? html + tag : html.slice(0, close) + tag + html.slice(close);
|
|
349
|
+
}
|
|
350
|
+
var RECORD_CSP_VIOLATIONS = `
|
|
351
|
+
window.__artisCsp = [];
|
|
352
|
+
document.addEventListener('securitypolicyviolation', (event) => {
|
|
353
|
+
window.__artisCsp.push({
|
|
354
|
+
directive: event.effectiveDirective || event.violatedDirective,
|
|
355
|
+
blocked: event.blockedURI || 'inline',
|
|
356
|
+
});
|
|
357
|
+
});`;
|
|
358
|
+
var INSPECT_PAGE = `(() => {
|
|
359
|
+
const describe = (el) => {
|
|
360
|
+
let text = el.tagName.toLowerCase();
|
|
361
|
+
if (el.id) text += '#' + el.id;
|
|
362
|
+
const cls = typeof el.className === 'string' ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0, 2) : [];
|
|
363
|
+
if (cls.length) text += '.' + cls.join('.');
|
|
364
|
+
return text;
|
|
365
|
+
};
|
|
366
|
+
const root = document.documentElement;
|
|
367
|
+
const clientWidth = root.clientWidth;
|
|
368
|
+
const scrollWidth = Math.max(root.scrollWidth, document.body ? document.body.scrollWidth : 0);
|
|
369
|
+
let overflow = null;
|
|
370
|
+
if (scrollWidth > clientWidth + 1) {
|
|
371
|
+
// Elements past either edge whose own scroll container is the page:
|
|
372
|
+
// an element inside overflow-x: auto/hidden is contained, not the cause.
|
|
373
|
+
const scrolls = (el) => {
|
|
374
|
+
const ox = getComputedStyle(el).overflowX;
|
|
375
|
+
return ox === 'auto' || ox === 'scroll' || ox === 'hidden' || ox === 'clip';
|
|
376
|
+
};
|
|
377
|
+
const contained = (el) => {
|
|
378
|
+
for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
|
|
379
|
+
if (scrolls(p)) return true;
|
|
380
|
+
}
|
|
381
|
+
return false;
|
|
382
|
+
};
|
|
383
|
+
const rtl = getComputedStyle(root).direction === 'rtl';
|
|
384
|
+
const offenders = [];
|
|
385
|
+
for (const el of document.body ? document.body.querySelectorAll('*') : []) {
|
|
386
|
+
const rect = el.getBoundingClientRect();
|
|
387
|
+
const left = rect.left + window.scrollX;
|
|
388
|
+
const right = rect.right + window.scrollX;
|
|
389
|
+
// Past the left edge only counts in a right-to-left document: in LTR
|
|
390
|
+
// it is the usual off-screen pattern (skip links, visually-hidden
|
|
391
|
+
// text), which the page cannot scroll to anyway.
|
|
392
|
+
const past = rtl ? Math.max(right - clientWidth, -left) : right - clientWidth;
|
|
393
|
+
if (past > 1 && !contained(el)) offenders.push({ element: describe(el), right: Math.round(right), past });
|
|
394
|
+
}
|
|
395
|
+
offenders.sort((a, b) => b.past - a.past);
|
|
396
|
+
// overflow-x: hidden on <html>/<body> hides the scrollbar but still cuts
|
|
397
|
+
// the content off, so it is reported, flagged as hidden.
|
|
398
|
+
const hiddenBy = [root, document.body].find((el) => {
|
|
399
|
+
if (!el) return false;
|
|
400
|
+
const ox = getComputedStyle(el).overflowX;
|
|
401
|
+
return ox === 'hidden' || ox === 'clip';
|
|
402
|
+
});
|
|
403
|
+
overflow = {
|
|
404
|
+
scrollWidth,
|
|
405
|
+
clientWidth,
|
|
406
|
+
hiddenByPage: Boolean(hiddenBy),
|
|
407
|
+
offenders: offenders.slice(0, 5).map(({ element, right }) => ({ element, right })),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Drawn content of an <svg>, in its user units: the union of its visible
|
|
412
|
+
// leaf shapes (with half their stroke), skipping anything under a
|
|
413
|
+
// clip-path or mask (clipped on purpose) and anything not painted.
|
|
414
|
+
const LEAVES = 'path, rect, circle, ellipse, line, polyline, polygon, text, image, use, foreignObject';
|
|
415
|
+
const drawnBox = (svg) => {
|
|
416
|
+
const toUser = svg.getScreenCTM();
|
|
417
|
+
if (!toUser) return null;
|
|
418
|
+
const inverse = toUser.inverse();
|
|
419
|
+
let box = null;
|
|
420
|
+
for (const leaf of svg.querySelectorAll(LEAVES)) {
|
|
421
|
+
if (leaf.closest('defs, clipPath, mask, marker, pattern, symbol, linearGradient, radialGradient')) continue;
|
|
422
|
+
// A nested <svg> clips its own content; it is checked on its own terms
|
|
423
|
+
// only when it is the outermost one.
|
|
424
|
+
if (leaf.parentElement && leaf.parentElement.closest('svg') !== svg) continue;
|
|
425
|
+
let hidden = false;
|
|
426
|
+
for (let el = leaf; el && el !== svg; el = el.parentElement) {
|
|
427
|
+
const cs = getComputedStyle(el);
|
|
428
|
+
if (el.hasAttribute('clip-path') || el.hasAttribute('mask') || (cs.clipPath && cs.clipPath !== 'none') || (cs.mask && cs.mask !== 'none') || cs.display === 'none' || Number(cs.opacity) === 0) {
|
|
429
|
+
hidden = true;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const leafStyle = getComputedStyle(leaf);
|
|
434
|
+
if (hidden || leafStyle.visibility !== 'visible') continue;
|
|
435
|
+
// Paints nothing (a transparent hover overlay): not visible content.
|
|
436
|
+
const paints = (paint) => Boolean(paint) && paint !== 'none' && paint !== 'transparent' && !(paint.startsWith('rgba(') && paint.replace(/ /g, '').endsWith(',0)'));
|
|
437
|
+
if (leaf.tagName !== 'image' && leaf.tagName !== 'use' && leaf.tagName !== 'foreignObject' && !paints(leafStyle.fill) && !paints(leafStyle.stroke)) continue;
|
|
438
|
+
let b;
|
|
439
|
+
try { b = leaf.getBBox(); } catch { continue; }
|
|
440
|
+
if (b.width === 0 && b.height === 0) continue;
|
|
441
|
+
const half = leafStyle.stroke && leafStyle.stroke !== 'none' ? (parseFloat(leafStyle.strokeWidth) || 0) / 2 : 0;
|
|
442
|
+
const matrix = leaf.getScreenCTM();
|
|
443
|
+
if (!matrix) continue;
|
|
444
|
+
const m = inverse.multiply(matrix);
|
|
445
|
+
for (const [x, y] of [[b.x - half, b.y - half], [b.x + b.width + half, b.y - half], [b.x - half, b.y + b.height + half], [b.x + b.width + half, b.y + b.height + half]]) {
|
|
446
|
+
const px = m.a * x + m.c * y + m.e;
|
|
447
|
+
const py = m.b * x + m.d * y + m.f;
|
|
448
|
+
box = box
|
|
449
|
+
? { x1: Math.min(box.x1, px), y1: Math.min(box.y1, py), x2: Math.max(box.x2, px), y2: Math.max(box.y2, py) }
|
|
450
|
+
: { x1: px, y1: py, x2: px, y2: py };
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return box;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
// The region of user space the SVG actually shows: the viewBox scaled into
|
|
457
|
+
// the element's box under preserveAspectRatio (meet shows more than the
|
|
458
|
+
// viewBox, slice less), or the box itself without a viewBox.
|
|
459
|
+
const visibleRegion = (svg) => {
|
|
460
|
+
const width = svg.clientWidth || svg.getBoundingClientRect().width;
|
|
461
|
+
const height = svg.clientHeight || svg.getBoundingClientRect().height;
|
|
462
|
+
if (!width || !height) return null;
|
|
463
|
+
const vb = svg.viewBox && svg.viewBox.baseVal;
|
|
464
|
+
if (!vb || !(vb.width > 0) || !(vb.height > 0)) return { x1: 0, y1: 0, x2: width, y2: height };
|
|
465
|
+
const par = svg.preserveAspectRatio.baseVal;
|
|
466
|
+
if (par.align === 1) return { x1: vb.x, y1: vb.y, x2: vb.x + vb.width, y2: vb.y + vb.height };
|
|
467
|
+
const scale = par.meetOrSlice === 2
|
|
468
|
+
? Math.max(width / vb.width, height / vb.height)
|
|
469
|
+
: Math.min(width / vb.width, height / vb.height);
|
|
470
|
+
const shownWidth = width / scale;
|
|
471
|
+
const shownHeight = height / scale;
|
|
472
|
+
const xAlign = (par.align - 2) % 3;
|
|
473
|
+
const yAlign = Math.floor((par.align - 2) / 3);
|
|
474
|
+
const x1 = vb.x - ((shownWidth - vb.width) * xAlign) / 2;
|
|
475
|
+
const y1 = vb.y - ((shownHeight - vb.height) * yAlign) / 2;
|
|
476
|
+
return { x1, y1, x2: x1 + shownWidth, y2: y1 + shownHeight };
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const clippedSvgs = [];
|
|
480
|
+
for (const svg of document.querySelectorAll('svg')) {
|
|
481
|
+
if (svg.parentElement && svg.parentElement.closest('svg')) continue;
|
|
482
|
+
const style = getComputedStyle(svg);
|
|
483
|
+
if (style.overflow === 'visible' || style.display === 'none') continue;
|
|
484
|
+
const shown = visibleRegion(svg);
|
|
485
|
+
const drawn = shown && drawnBox(svg);
|
|
486
|
+
if (!drawn) continue;
|
|
487
|
+
const tolerance = Math.max(1, (shown.x2 - shown.x1) / 500);
|
|
488
|
+
const over = {
|
|
489
|
+
top: Math.max(0, shown.y1 - drawn.y1),
|
|
490
|
+
right: Math.max(0, drawn.x2 - shown.x2),
|
|
491
|
+
bottom: Math.max(0, drawn.y2 - shown.y2),
|
|
492
|
+
left: Math.max(0, shown.x1 - drawn.x1),
|
|
493
|
+
};
|
|
494
|
+
if (Object.values(over).some((v) => v > tolerance)) {
|
|
495
|
+
const round = (v) => Math.round(v * 10) / 10;
|
|
496
|
+
clippedSvgs.push({
|
|
497
|
+
element: describe(svg),
|
|
498
|
+
overflow: { top: round(over.top), right: round(over.right), bottom: round(over.bottom), left: round(over.left) },
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return { overflow, clippedSvgs, cspViolations: window.__artisCsp || [] };
|
|
504
|
+
})()`;
|
|
505
|
+
function isCspConsoleMessage(text) {
|
|
506
|
+
return /Content Security Policy/i.test(text);
|
|
507
|
+
}
|
|
508
|
+
function isOptionalFileMissing(type, message) {
|
|
509
|
+
if (!type || !/status of 404/.test(message.text())) return false;
|
|
510
|
+
const file = FILE_PATH.exec(
|
|
511
|
+
new URL(message.location().url, "http://x").pathname
|
|
512
|
+
);
|
|
513
|
+
if (!file) return false;
|
|
514
|
+
let filePath;
|
|
515
|
+
try {
|
|
516
|
+
filePath = decodeURIComponent(file[2]);
|
|
517
|
+
} catch {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
return !type.layout?.required.includes(filePath);
|
|
521
|
+
}
|
|
522
|
+
function pageRendered(type) {
|
|
523
|
+
const name = JSON.stringify(type);
|
|
524
|
+
return `new Promise((resolve) => {
|
|
525
|
+
const started = Date.now();
|
|
526
|
+
const poll = () => {
|
|
527
|
+
const state = document.documentElement.getAttribute('data-artis-type');
|
|
528
|
+
if (state === 'ready') return resolve(null);
|
|
529
|
+
if (state === 'error') {
|
|
530
|
+
const alert = document.querySelector('[role="alert"]');
|
|
531
|
+
return resolve('The ' + ${name} + ' page did not render' + (alert ? ': ' + alert.textContent : '.'));
|
|
532
|
+
}
|
|
533
|
+
if (Date.now() - started > 10000) return resolve('The ' + ${name} + ' page did not render: its runtime said nothing within 10 s.');
|
|
534
|
+
setTimeout(poll, 50);
|
|
535
|
+
};
|
|
536
|
+
poll();
|
|
537
|
+
})`;
|
|
538
|
+
}
|
|
539
|
+
var CHECK_TIMEOUT_MS = 3e4;
|
|
540
|
+
async function runFormatCheck(browser, source, files) {
|
|
541
|
+
const context = await browser.newContext({ offline: true });
|
|
542
|
+
try {
|
|
543
|
+
await context.route("**/*", (route) => route.abort());
|
|
544
|
+
const page = await context.newPage();
|
|
545
|
+
await page.setContent(
|
|
546
|
+
`<!doctype html><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src data:">`
|
|
547
|
+
);
|
|
548
|
+
const module = `data:text/javascript;base64,${Buffer.from(source).toString("base64")}`;
|
|
549
|
+
const run = page.evaluate(`(async () => {
|
|
550
|
+
const { default: check } = await import(${JSON.stringify(module)});
|
|
551
|
+
if (typeof check !== 'function') throw new Error('The check module has no default export function.');
|
|
552
|
+
return JSON.parse(JSON.stringify(await check(${JSON.stringify(files)})));
|
|
553
|
+
})()`);
|
|
554
|
+
let timer;
|
|
555
|
+
const timeout = new Promise((_, reject) => {
|
|
556
|
+
timer = setTimeout(
|
|
557
|
+
() => reject(
|
|
558
|
+
new Error(
|
|
559
|
+
`The format's check did not finish within ${CHECK_TIMEOUT_MS / 1e3} s.`
|
|
560
|
+
)
|
|
561
|
+
),
|
|
562
|
+
CHECK_TIMEOUT_MS
|
|
563
|
+
);
|
|
564
|
+
});
|
|
565
|
+
let result;
|
|
566
|
+
try {
|
|
567
|
+
result = await Promise.race([run, timeout]);
|
|
568
|
+
} catch (error) {
|
|
569
|
+
run.catch(() => void 0);
|
|
570
|
+
return [
|
|
571
|
+
{
|
|
572
|
+
severity: "error",
|
|
573
|
+
code: "check-failed",
|
|
574
|
+
message: `The format's check failed: ${error instanceof Error ? error.message : String(error)}`
|
|
575
|
+
}
|
|
576
|
+
];
|
|
577
|
+
} finally {
|
|
578
|
+
clearTimeout(timer);
|
|
579
|
+
}
|
|
580
|
+
if (!Array.isArray(result)) {
|
|
581
|
+
return [
|
|
582
|
+
{
|
|
583
|
+
severity: "error",
|
|
584
|
+
code: "check-failed",
|
|
585
|
+
message: "The format's check did not return a list of issues."
|
|
586
|
+
}
|
|
587
|
+
];
|
|
588
|
+
}
|
|
589
|
+
return result.flatMap((value) => {
|
|
590
|
+
const issue = toTypeSourceIssue(value);
|
|
591
|
+
return issue ? [issue] : [];
|
|
592
|
+
});
|
|
593
|
+
} finally {
|
|
594
|
+
await context.close().catch(() => void 0);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function issueKey(issue) {
|
|
598
|
+
return JSON.stringify([
|
|
599
|
+
issue.severity,
|
|
600
|
+
issue.code,
|
|
601
|
+
issue.path,
|
|
602
|
+
issue.line,
|
|
603
|
+
issue.column,
|
|
604
|
+
issue.message
|
|
605
|
+
]);
|
|
606
|
+
}
|
|
607
|
+
function measureSlides(canvas) {
|
|
608
|
+
const args = [canvas, pageViewEvents.reveal, pageViewEvents.viewChanged].map((value) => JSON.stringify(value)).join(", ");
|
|
609
|
+
return `(async (canvas, reveal, viewChanged) => {
|
|
610
|
+
const describe = (el) => {
|
|
611
|
+
let text = el.tagName.toLowerCase();
|
|
612
|
+
if (el.id) text += '#' + el.id;
|
|
613
|
+
const cls = typeof el.className === 'string' ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0, 2) : [];
|
|
614
|
+
if (cls.length) text += '.' + cls.join('.');
|
|
615
|
+
return text;
|
|
616
|
+
};
|
|
617
|
+
const still = document.createElement('style');
|
|
618
|
+
still.textContent = '*, *::before, *::after { animation: none !important; transition: none !important; }';
|
|
619
|
+
(document.head || document.documentElement).append(still);
|
|
620
|
+
if (document.fonts) await document.fonts.ready;
|
|
621
|
+
const frame = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
622
|
+
const shown = (section) =>
|
|
623
|
+
section.getBoundingClientRect().width > 0 && getComputedStyle(section).visibility === 'visible';
|
|
624
|
+
const bringUp = async (section) => {
|
|
625
|
+
const changed = new Promise((resolve) => {
|
|
626
|
+
const timer = setTimeout(resolve, 500);
|
|
627
|
+
document.addEventListener(viewChanged, () => { clearTimeout(timer); resolve(); }, { once: true });
|
|
628
|
+
});
|
|
629
|
+
section.dispatchEvent(new CustomEvent(reveal, { bubbles: true, detail: { annotationId: 'artis-verify' } }));
|
|
630
|
+
if (!shown(section)) await changed;
|
|
631
|
+
await frame();
|
|
632
|
+
};
|
|
633
|
+
const clipsBetween = (el, section) => {
|
|
634
|
+
for (let p = el.parentElement; p && p !== section; p = p.parentElement) {
|
|
635
|
+
if (getComputedStyle(p).overflow !== 'visible') return true;
|
|
636
|
+
}
|
|
637
|
+
return false;
|
|
638
|
+
};
|
|
639
|
+
const sections = Array.from(document.body ? document.body.children : []).filter((el) => el.tagName === 'SECTION');
|
|
640
|
+
const findings = [];
|
|
641
|
+
for (const [i, section] of sections.entries()) {
|
|
642
|
+
if (section.hasAttribute('hidden')) continue;
|
|
643
|
+
await bringUp(section);
|
|
644
|
+
if (!shown(section)) continue;
|
|
645
|
+
const box = section.getBoundingClientRect();
|
|
646
|
+
const scale = box.width / canvas.width;
|
|
647
|
+
const reach = (rect) => ({
|
|
648
|
+
top: (box.top - rect.top) / scale,
|
|
649
|
+
right: (rect.right - box.right) / scale,
|
|
650
|
+
bottom: (rect.bottom - box.bottom) / scale,
|
|
651
|
+
left: (box.left - rect.left) / scale,
|
|
652
|
+
});
|
|
653
|
+
const past = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
654
|
+
const flagged = new Set();
|
|
655
|
+
const offenders = [];
|
|
656
|
+
for (const el of section.querySelectorAll('*')) {
|
|
657
|
+
if (el.closest('aside, style, script, template')) continue;
|
|
658
|
+
if (el.parentElement && el.parentElement.closest('svg')) continue;
|
|
659
|
+
if (clipsBetween(el, section)) continue;
|
|
660
|
+
const style = getComputedStyle(el);
|
|
661
|
+
if (style.display === 'none' || style.visibility !== 'visible') continue;
|
|
662
|
+
const rects = [el.getBoundingClientRect()];
|
|
663
|
+
if (Array.from(el.childNodes).some((node) => node.nodeType === 3 && node.textContent.trim())) {
|
|
664
|
+
const range = document.createRange();
|
|
665
|
+
range.selectNodeContents(el);
|
|
666
|
+
rects.push(range.getBoundingClientRect());
|
|
667
|
+
}
|
|
668
|
+
let furthest = 0;
|
|
669
|
+
for (const rect of rects) {
|
|
670
|
+
if (rect.width === 0 && rect.height === 0) continue;
|
|
671
|
+
const r = reach(rect);
|
|
672
|
+
for (const side of Object.keys(past)) {
|
|
673
|
+
if (r[side] > 1) past[side] = Math.max(past[side], Math.round(r[side]));
|
|
674
|
+
furthest = Math.max(furthest, r[side]);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (furthest <= 1) continue;
|
|
678
|
+
flagged.add(el);
|
|
679
|
+
let outermost = true;
|
|
680
|
+
for (let p = el.parentElement; p && p !== section; p = p.parentElement) {
|
|
681
|
+
if (flagged.has(p)) { outermost = false; break; }
|
|
682
|
+
}
|
|
683
|
+
if (outermost) offenders.push({ element: describe(el), past: Math.round(furthest) });
|
|
684
|
+
}
|
|
685
|
+
if (offenders.length) {
|
|
686
|
+
offenders.sort((a, b) => b.past - a.past);
|
|
687
|
+
const finding = { index: i + 1, past, offenders: offenders.slice(0, 5) };
|
|
688
|
+
if (section.id) finding.id = section.id;
|
|
689
|
+
findings.push(finding);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return findings;
|
|
693
|
+
})(${args})`;
|
|
694
|
+
}
|
|
695
|
+
function deckCanvas(files) {
|
|
696
|
+
const manifest = readSlidesDeckManifest(files[SLIDES_DECK_FILE]);
|
|
697
|
+
return SLIDE_CANVAS[manifest.ok ? manifest.value.size : "16:9"];
|
|
698
|
+
}
|
|
699
|
+
function verifyHtml(html, options = {}) {
|
|
700
|
+
return verifyFiles({ "index.html": html }, options);
|
|
701
|
+
}
|
|
702
|
+
async function verifyFiles(files, options = {}) {
|
|
703
|
+
const { type } = options;
|
|
704
|
+
const notLoaded = /* @__PURE__ */ new Set();
|
|
705
|
+
const report = (runs, issues) => {
|
|
706
|
+
const ok = runs.every(runIsClean) && !issues?.some((issue) => issue.severity === "error");
|
|
707
|
+
return {
|
|
708
|
+
...type ? { ok, type: type.name, formatIssues: issues ?? [], runs } : { ok, runs },
|
|
709
|
+
...notLoaded.size ? { assetsNotLoaded: [...notLoaded] } : {}
|
|
710
|
+
};
|
|
711
|
+
};
|
|
712
|
+
const { server, url } = await serveRevision(files, type, {
|
|
713
|
+
load: options.loadAsset,
|
|
714
|
+
notLoaded
|
|
715
|
+
});
|
|
716
|
+
try {
|
|
717
|
+
const browser = await launchBrowser();
|
|
718
|
+
try {
|
|
719
|
+
const checked = type?.check ? await runFormatCheck(browser, type.check, files) : [];
|
|
720
|
+
const printed = [];
|
|
721
|
+
const runs = await runChecks(browser, url, type, files, printed);
|
|
722
|
+
if (!type) return report(runs, void 0);
|
|
723
|
+
const seen = /* @__PURE__ */ new Set();
|
|
724
|
+
const issues = [...checked, ...printed].filter((issue) => {
|
|
725
|
+
const key = issueKey(issue);
|
|
726
|
+
if (seen.has(key)) return false;
|
|
727
|
+
seen.add(key);
|
|
728
|
+
return true;
|
|
729
|
+
});
|
|
730
|
+
return report(runs, issues);
|
|
731
|
+
} finally {
|
|
732
|
+
await browser.close().catch(() => void 0);
|
|
733
|
+
}
|
|
734
|
+
} finally {
|
|
735
|
+
await new Promise((resolve) => server.close(resolve));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function runIsClean(run) {
|
|
739
|
+
return !run.overflow && !run.clippedSvgs.length && !run.consoleErrors.length && !run.cspViolations.length && !run.slideOverflow?.length;
|
|
740
|
+
}
|
|
741
|
+
async function runChecks(browser, url, type, files, printed) {
|
|
742
|
+
const runs = [];
|
|
743
|
+
for (const width of runWidths(type)) {
|
|
744
|
+
for (const theme of verifyThemes) {
|
|
745
|
+
const context = await browser.newContext({
|
|
746
|
+
viewport: { width, height: 900 },
|
|
747
|
+
colorScheme: theme
|
|
748
|
+
});
|
|
749
|
+
try {
|
|
750
|
+
const page = await context.newPage();
|
|
751
|
+
const consoleErrors = [];
|
|
752
|
+
page.on("console", (message) => {
|
|
753
|
+
const issue = type ? parseTypeSourceIssueLine(type.name, message.text()) : void 0;
|
|
754
|
+
if (issue) {
|
|
755
|
+
printed.push(issue);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (message.type() === "error" && !isCspConsoleMessage(message.text()) && !isOptionalFileMissing(type, message)) {
|
|
759
|
+
consoleErrors.push(message.text());
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
page.on("pageerror", (error) => {
|
|
763
|
+
if (!isCspConsoleMessage(error.message)) {
|
|
764
|
+
consoleErrors.push(error.message);
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
await page.addInitScript(RECORD_CSP_VIOLATIONS);
|
|
768
|
+
await page.goto(url(theme), { waitUntil: "load", timeout: 15e3 });
|
|
769
|
+
if (type) {
|
|
770
|
+
const failed = await page.evaluate(
|
|
771
|
+
pageRendered(type.name)
|
|
772
|
+
);
|
|
773
|
+
if (failed) consoleErrors.push(failed);
|
|
774
|
+
}
|
|
775
|
+
await page.waitForTimeout(400);
|
|
776
|
+
const findings = await page.evaluate(INSPECT_PAGE);
|
|
777
|
+
const run = {
|
|
778
|
+
width,
|
|
779
|
+
theme,
|
|
780
|
+
// The runtime scales a fixed canvas into the window: the page's
|
|
781
|
+
// width says nothing about a deck.
|
|
782
|
+
overflow: type ? null : findings.overflow,
|
|
783
|
+
clippedSvgs: findings.clippedSvgs,
|
|
784
|
+
consoleErrors: [...new Set(consoleErrors)],
|
|
785
|
+
cspViolations: dedupe(findings.cspViolations)
|
|
786
|
+
};
|
|
787
|
+
if (type?.name === "slides") {
|
|
788
|
+
page.setDefaultTimeout(12e4);
|
|
789
|
+
run.slideOverflow = await page.evaluate(
|
|
790
|
+
measureSlides(deckCanvas(files))
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
runs.push(run);
|
|
794
|
+
} finally {
|
|
795
|
+
await context.close();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return runs;
|
|
800
|
+
}
|
|
801
|
+
function dedupe(violations) {
|
|
802
|
+
const seen = /* @__PURE__ */ new Set();
|
|
803
|
+
return violations.filter((violation) => {
|
|
804
|
+
const key = `${violation.directive} ${violation.blocked}`;
|
|
805
|
+
if (seen.has(key)) return false;
|
|
806
|
+
seen.add(key);
|
|
807
|
+
return true;
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
function stripControlCharacters(text) {
|
|
811
|
+
return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, "");
|
|
812
|
+
}
|
|
813
|
+
function issueLocation(issue) {
|
|
814
|
+
const line = issue.line !== void 0 ? `line ${issue.line}${issue.column !== void 0 ? `:${issue.column}` : ""}` : void 0;
|
|
815
|
+
const place = [issue.path, line].filter(Boolean).join(" ");
|
|
816
|
+
return place || "the source";
|
|
817
|
+
}
|
|
818
|
+
function formatFormatIssues(issues) {
|
|
819
|
+
return formatIssueLines(issues).map(stripControlCharacters);
|
|
820
|
+
}
|
|
821
|
+
function formatIssueLines(issues) {
|
|
822
|
+
const errors = issues.filter((issue) => issue.severity === "error");
|
|
823
|
+
const hints = issues.filter((issue) => issue.severity === "hint");
|
|
824
|
+
const count = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
825
|
+
return [
|
|
826
|
+
...[...errors, ...hints].flatMap((issue) => [
|
|
827
|
+
`${issue.severity} ${issue.code} at ${issueLocation(issue)}: ${issue.message}`,
|
|
828
|
+
...issue.example ? [` for example: ${issue.example}`] : []
|
|
829
|
+
]),
|
|
830
|
+
issues.length ? `Format check: ${count(errors.length, "error")}, ${count(hints.length, "hint")}${errors.length ? "." : " (hints are reported only)."}` : "Format check: no issues."
|
|
831
|
+
];
|
|
832
|
+
}
|
|
833
|
+
function formatVerifyReport(report) {
|
|
834
|
+
const lines = reportLines(report);
|
|
835
|
+
if (report.assetsNotLoaded?.length) {
|
|
836
|
+
const count = report.assetsNotLoaded.length;
|
|
837
|
+
lines.push(
|
|
838
|
+
`${count} asset${count === 1 ? "" : "s"} (/_blob/\u2026) not loaded: a local file has none, and a published artifact's are read signed in as someone who may upload to it. Verify the published artifact signed in as such a user to check them.`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
return lines.map(stripControlCharacters);
|
|
842
|
+
}
|
|
843
|
+
function reportLines(report) {
|
|
844
|
+
const lines = report.formatIssues ? formatFormatIssues(report.formatIssues) : [];
|
|
845
|
+
if (report.runs.every(runIsClean)) {
|
|
846
|
+
if (!report.type) {
|
|
847
|
+
return [
|
|
848
|
+
`No problems found at ${verifyWidths.join(" and ")} px in light and dark themes.`
|
|
849
|
+
];
|
|
850
|
+
}
|
|
851
|
+
if (report.runs.length) {
|
|
852
|
+
lines.push(
|
|
853
|
+
`Rendering: no problems at ${runWidths(report.type).join(" and ")} px in light and dark themes${report.type === "slides" ? "; every slide fits its canvas" : ""}.`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
return lines;
|
|
857
|
+
}
|
|
858
|
+
const label = (run) => `${run.width}px ${run.theme}`;
|
|
859
|
+
const group = (pick, key) => {
|
|
860
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
861
|
+
for (const run of report.runs) {
|
|
862
|
+
for (const item of pick(run)) {
|
|
863
|
+
const entry = byKey.get(key(item)) ?? { item, runs: [] };
|
|
864
|
+
entry.runs.push(label(run));
|
|
865
|
+
byKey.set(key(item), entry);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return [...byKey.values()];
|
|
869
|
+
};
|
|
870
|
+
for (const run of report.runs) {
|
|
871
|
+
if (run.overflow) {
|
|
872
|
+
const offenders = run.overflow.offenders.map((o) => `${o.element} (to ${o.right}px)`).join(", ");
|
|
873
|
+
const hidden = run.overflow.hiddenByPage ? " (hidden by overflow-x on the page, so the content past the edge is cut off)" : "";
|
|
874
|
+
lines.push(
|
|
875
|
+
`Horizontal overflow at ${label(run)}: page is ${run.overflow.scrollWidth}px wide in a ${run.overflow.clientWidth}px viewport${hidden}${offenders ? `; widest: ${offenders}` : ""}.`
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
for (const { item, runs } of group(
|
|
880
|
+
(run) => run.clippedSvgs,
|
|
881
|
+
(svg) => `${svg.element} ${JSON.stringify(svg.overflow)}`
|
|
882
|
+
)) {
|
|
883
|
+
const sides = Object.entries(item.overflow).filter(([, value]) => value > 0).map(([side, value]) => `${side} ${value}`).join(", ");
|
|
884
|
+
lines.push(
|
|
885
|
+
`Clipped SVG ${item.element} (content past its viewport: ${sides}) at ${runs.join(", ")}.`
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
for (const { item, runs } of group(
|
|
889
|
+
(run) => run.consoleErrors,
|
|
890
|
+
(text) => text
|
|
891
|
+
)) {
|
|
892
|
+
lines.push(`Console error at ${runs.join(", ")}: ${item}`);
|
|
893
|
+
}
|
|
894
|
+
for (const { item, runs } of group(
|
|
895
|
+
(run) => run.cspViolations,
|
|
896
|
+
(violation) => `${violation.directive} ${violation.blocked}`
|
|
897
|
+
)) {
|
|
898
|
+
lines.push(
|
|
899
|
+
`CSP violation (${item.directive}) blocking ${item.blocked} at ${runs.join(", ")}. Artifacts may load nothing external: inline it or use a data: URL.`
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
for (const { item, runs } of group(
|
|
903
|
+
(run) => run.slideOverflow ?? [],
|
|
904
|
+
(slide) => JSON.stringify(slide)
|
|
905
|
+
)) {
|
|
906
|
+
const sides = Object.entries(item.past).filter(([, value]) => value > 0).map(([side, value]) => `${side} ${value}px`).join(", ");
|
|
907
|
+
const offenders = item.offenders.map((o) => `${o.element} (${o.past}px)`).join(", ");
|
|
908
|
+
lines.push(
|
|
909
|
+
`Slide ${item.index}${item.id ? ` (#${item.id})` : ""} runs past its canvas (${sides}) at ${runs.join(", ")}; furthest: ${offenders}. Nothing scrolls or shrinks on a slide: cut content or split the slide.`
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
return lines;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
export {
|
|
916
|
+
verifyWidths,
|
|
917
|
+
verifyThemes,
|
|
918
|
+
GOOGLE_FONTS_STYLE_ORIGIN,
|
|
919
|
+
GOOGLE_FONTS_FONT_ORIGIN,
|
|
920
|
+
artifactContentSecurityPolicy,
|
|
921
|
+
VerifyUnavailableError,
|
|
922
|
+
stampTheme,
|
|
923
|
+
injectRuntime,
|
|
924
|
+
verifyHtml,
|
|
925
|
+
verifyFiles,
|
|
926
|
+
stripControlCharacters,
|
|
927
|
+
formatFormatIssues,
|
|
928
|
+
formatVerifyReport
|
|
929
|
+
};
|