@hyperframes/core 0.9.104 → 0.9.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/htmlDocument.js +9 -2
- package/dist/fonts/deterministicFonts.js +12 -10
- package/dist/fonts/fontDiagnostics.d.ts +3 -0
- package/dist/fonts/fontDiagnostics.js +32 -1
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/runtime/drawnBox.d.ts +5 -0
- package/dist/runtime/drawnBox.js +5 -0
- package/dist/runtime/editing/dragChrome.d.ts +32 -0
- package/dist/runtime/editing/dragChrome.js +154 -0
- package/dist/runtime/editing/softReload.js +4 -2
- package/dist/runtime/editing/watchPointer.d.ts +26 -0
- package/dist/runtime/editing/watchPointer.js +105 -0
- package/dist/runtime/editingDraft.d.ts +3 -2
- package/dist/runtime/editingDraft.js +13 -8
- package/dist/runtime/editingDraftEnd.d.ts +1 -0
- package/dist/runtime/editingElement.d.ts +4 -0
- package/dist/runtime/editingGeometry.js +1 -4
- package/dist/runtime/editingHandles.d.ts +0 -5
- package/dist/runtime/editingHandles.js +7 -0
- package/dist/runtime/editingPort.d.ts +18 -2
- package/dist/runtime/editingPort.js +45 -6
- package/dist/runtime/mediaProxy.js +78 -7
- package/dist/studioPreviewMark.d.ts +1 -0
- package/dist/studioPreviewMark.js +1 -0
- package/package.json +4 -4
|
@@ -353,11 +353,18 @@ function insertTagInHead(html, tag) {
|
|
|
353
353
|
const ACCEL_TRACKER_ATTR = "data-hf-accel-tracker";
|
|
354
354
|
const OPTS_INTO_MOTION_BLUR = /\sdata-motion-blur\s*=\s*["']?on[\s"'>]/i;
|
|
355
355
|
export function insertRuntimeTag(html, tag, atHeadStart = false) {
|
|
356
|
-
const withRuntime = atHeadStart
|
|
356
|
+
const withRuntime = atHeadStart
|
|
357
|
+
? insertWhereScriptsFirstRun(html, tag)
|
|
358
|
+
: insertTagInHead(html, tag);
|
|
357
359
|
if (!OPTS_INTO_MOTION_BLUR.test(html) || html.includes(ACCEL_TRACKER_ATTR))
|
|
358
360
|
return withRuntime;
|
|
359
361
|
const tracker = `<script ${ACCEL_TRACKER_ATTR}>${acceleratedCanvasTrackerSource()}</script>`;
|
|
360
|
-
return injectTagsAtHeadStart(withRuntime, tracker);
|
|
362
|
+
return (atHeadStart ? insertWhereScriptsFirstRun : injectTagsAtHeadStart)(withRuntime, tracker);
|
|
363
|
+
}
|
|
364
|
+
function insertWhereScriptsFirstRun(html, tags) {
|
|
365
|
+
const at = headContentStart(html);
|
|
366
|
+
const opensWithMarkup = html.charAt(at - 1) === ">";
|
|
367
|
+
return `${html.slice(0, at)}${opensWithMarkup ? "\n" : ""}${tags}${html.slice(at)}`;
|
|
361
368
|
}
|
|
362
369
|
/**
|
|
363
370
|
* Insert raw tag markup at the very start of `<head>`, ahead of every author
|
|
@@ -11,7 +11,7 @@ import { parseCss } from "@hyperframes/parsers/postcss";
|
|
|
11
11
|
import { EMBEDDED_FONT_DATA } from "./fontData.generated.js";
|
|
12
12
|
import { fontToDataUri } from "./fontCompression.js";
|
|
13
13
|
import { authoredGoogleFontStylesheets, withPageText } from "./authoredGoogleFonts.js";
|
|
14
|
-
import { FontDiagCollector, } from "./fontDiagnostics.js";
|
|
14
|
+
import { FontDiagCollector, summarizeFontDiagnostics, } from "./fontDiagnostics.js";
|
|
15
15
|
import { hyperframesCacheDir } from "../cacheDir.js";
|
|
16
16
|
import { terminalText } from "../terminalText.js";
|
|
17
17
|
/**
|
|
@@ -950,8 +950,9 @@ function fontCacheDir(slug) {
|
|
|
950
950
|
function subsetToken(woff2Url) {
|
|
951
951
|
return createHash("sha1").update(woff2Url).digest("hex").slice(0, 12);
|
|
952
952
|
}
|
|
953
|
-
|
|
954
|
-
|
|
953
|
+
/** One file per address: a variable font names the same address for every weight it covers. */
|
|
954
|
+
function cachedWoff2Path(slug, woff2Url) {
|
|
955
|
+
return join(fontCacheDir(slug), `${subsetToken(woff2Url)}.woff2`);
|
|
955
956
|
}
|
|
956
957
|
/**
|
|
957
958
|
* Typed codes let distributed workflow adapters distinguish deterministic
|
|
@@ -1150,16 +1151,17 @@ async function ensureWoff2DataUri(cachePath, woff2Url, familyName, weight, style
|
|
|
1150
1151
|
}
|
|
1151
1152
|
catch (err) {
|
|
1152
1153
|
throwIfCallerAborted(options.abortSignal);
|
|
1153
|
-
if (err instanceof FontFetchError)
|
|
1154
|
-
throw err;
|
|
1155
1154
|
if (err.code === "EEXIST") {
|
|
1156
1155
|
// Concurrent call wrote it — read their result below.
|
|
1157
1156
|
tally.diskCacheHit += 1;
|
|
1158
1157
|
}
|
|
1159
|
-
else if (options.failClosedFontFetch) {
|
|
1160
|
-
throw fontFetchError(familyName, woff2Url, woff2What, { error: err });
|
|
1161
|
-
}
|
|
1162
1158
|
else {
|
|
1159
|
+
tally.errored += 1;
|
|
1160
|
+
if (err instanceof FontFetchError)
|
|
1161
|
+
throw err;
|
|
1162
|
+
if (options.failClosedFontFetch) {
|
|
1163
|
+
throw fontFetchError(familyName, woff2Url, woff2What, { error: err });
|
|
1164
|
+
}
|
|
1163
1165
|
return null;
|
|
1164
1166
|
}
|
|
1165
1167
|
}
|
|
@@ -1382,7 +1384,7 @@ async function fetchGoogleFontStylesheet(familyName, url, options, attempt) {
|
|
|
1382
1384
|
if (!source)
|
|
1383
1385
|
continue;
|
|
1384
1386
|
const { weight, style, unicodeRange, url: woff2Url } = source;
|
|
1385
|
-
const cachePath = cachedWoff2Path(slug,
|
|
1387
|
+
const cachePath = cachedWoff2Path(slug, woff2Url);
|
|
1386
1388
|
const dataUri = await ensureWoff2DataUri(cachePath, woff2Url, familyName, weight, style, options, attempt.assets);
|
|
1387
1389
|
if (dataUri)
|
|
1388
1390
|
faces.push({ weight, style, dataUri, unicodeRange });
|
|
@@ -1648,7 +1650,7 @@ export async function injectDeterministicFontFaces(html, options = {}) {
|
|
|
1648
1650
|
return html;
|
|
1649
1651
|
}
|
|
1650
1652
|
let declaredFamilies;
|
|
1651
|
-
const { css, unresolved } = await buildFontFaceCss(pendingFamilies, fetchOptions, () => (declaredFamilies ??= collectDeclaredFontFamilies(html)), extractGoogleFontsText(html));
|
|
1653
|
+
const { css, unresolved } = await buildFontFaceCss(pendingFamilies, fetchOptions, () => (declaredFamilies ??= collectDeclaredFontFamilies(html)), extractGoogleFontsText(html)).finally(() => fetchOptions.log.info(`[Compiler] font_resolution ${summarizeFontDiagnostics(diag.snapshot(), failClosedFontFetch ? "closed" : "open")}`));
|
|
1652
1654
|
// An optional family that no source serves, or that stayed unavailable, is tolerated.
|
|
1653
1655
|
const required = unresolved.filter((family) => !pendingFamilies.get(family.toLowerCase())?.optional);
|
|
1654
1656
|
if (required.length > 0 && options.failClosedFontFetch) {
|
|
@@ -4,6 +4,8 @@ export interface FontAssetDiag {
|
|
|
4
4
|
diskCacheHit: number;
|
|
5
5
|
fetchedOk: number;
|
|
6
6
|
nonOk: Record<string, number>;
|
|
7
|
+
/** Fetches that ended in an error instead of an HTTP response. */
|
|
8
|
+
errored: number;
|
|
7
9
|
}
|
|
8
10
|
export interface FontAttemptDiag {
|
|
9
11
|
path: FontDiagPath;
|
|
@@ -34,3 +36,4 @@ export declare class FontDiagCollector {
|
|
|
34
36
|
startAttempt(path: FontDiagPath, urlSource: FontAttemptDiag["urlSource"], textParam: FontAttemptDiag["textParam"]): FontAttemptDiag;
|
|
35
37
|
snapshot(): FontDiagnostics;
|
|
36
38
|
}
|
|
39
|
+
export declare function summarizeFontDiagnostics({ families }: FontDiagnostics, mode: "open" | "closed"): string;
|
|
@@ -19,7 +19,7 @@ export class FontDiagCollector {
|
|
|
19
19
|
cssStatus: null,
|
|
20
20
|
blocksTotal: 0,
|
|
21
21
|
regexMatches: 0,
|
|
22
|
-
assets: { total: 0, diskCacheHit: 0, fetchedOk: 0, nonOk: {} },
|
|
22
|
+
assets: { total: 0, diskCacheHit: 0, fetchedOk: 0, nonOk: {}, errored: 0 },
|
|
23
23
|
};
|
|
24
24
|
this.current?.attempts.push(attempt);
|
|
25
25
|
return attempt;
|
|
@@ -28,3 +28,34 @@ export class FontDiagCollector {
|
|
|
28
28
|
return { families: this.families };
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
const usableFiles = (attempt) => attempt.assets.diskCacheHit + attempt.assets.fetchedOk;
|
|
32
|
+
const lookupFailed = ({ cssStatus }) => cssStatus === null || cssStatus < 200 || cssStatus >= 300;
|
|
33
|
+
const bundledFacesOnly = (family) => {
|
|
34
|
+
const supplements = family.attempts.filter((attempt) => attempt.path === "bundled_supplement");
|
|
35
|
+
return family.resolved && supplements.length > 0 && !supplements.some(usableFiles);
|
|
36
|
+
};
|
|
37
|
+
const count = (items, matches) => items.filter(matches).length;
|
|
38
|
+
const sum = (items, value) => items.reduce((total, item) => total + value(item), 0);
|
|
39
|
+
export function summarizeFontDiagnostics({ families }, mode) {
|
|
40
|
+
const attempts = families.flatMap((family) => family.attempts);
|
|
41
|
+
const fields = [
|
|
42
|
+
["mode", mode],
|
|
43
|
+
["families", families.length],
|
|
44
|
+
["resolved", count(families, (family) => family.resolved)],
|
|
45
|
+
["unresolved_required", count(families, (family) => !family.resolved && family.required)],
|
|
46
|
+
["unresolved_optional", count(families, (family) => !family.resolved && !family.required)],
|
|
47
|
+
["bundled_faces_only", count(families, bundledFacesOnly)],
|
|
48
|
+
["css_lookups", attempts.length],
|
|
49
|
+
["css_cache_hit", count(attempts, (attempt) => attempt.cssCache === "hit")],
|
|
50
|
+
["css_failed", count(attempts, lookupFailed)],
|
|
51
|
+
["files", sum(attempts, (attempt) => attempt.assets.total)],
|
|
52
|
+
["files_cache_hit", sum(attempts, (attempt) => attempt.assets.diskCacheHit)],
|
|
53
|
+
["files_fetched", sum(attempts, (attempt) => attempt.assets.fetchedOk)],
|
|
54
|
+
[
|
|
55
|
+
"files_failed",
|
|
56
|
+
sum(attempts, (attempt) => sum(Object.values(attempt.assets.nonOk), (failed) => failed)),
|
|
57
|
+
],
|
|
58
|
+
["files_errored", sum(attempts, (attempt) => attempt.assets.errored)],
|
|
59
|
+
];
|
|
60
|
+
return fields.map(([name, value]) => `${name}=${value}`).join(" ");
|
|
61
|
+
}
|