@hyperframes/core 0.9.103 → 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/compositionScoping.js +3 -3
- package/dist/compiler/htmlDocument.js +9 -2
- package/dist/compiler/svgIdNamespacing.js +2 -2
- package/dist/fonts/authoredGoogleFonts.js +2 -2
- package/dist/fonts/deterministicFonts.js +14 -12
- 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 +69 -69
- package/dist/runtime/drawnBox.d.ts +5 -0
- package/dist/runtime/drawnBox.js +5 -0
- package/dist/runtime/editing/canvasKeys.d.ts +0 -1
- package/dist/runtime/editing/canvasKeys.js +4 -28
- package/dist/runtime/editing/dragChrome.d.ts +32 -0
- package/dist/runtime/editing/dragChrome.js +154 -0
- package/dist/runtime/editing/pausedFrames.js +7 -7
- package/dist/runtime/editing/softReload.js +4 -2
- package/dist/runtime/editing/stageAct.js +3 -2
- package/dist/runtime/editing/textEdit.js +4 -3
- package/dist/runtime/editing/watchGeometry.js +8 -8
- 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 +22 -3
- package/dist/runtime/editingPort.js +63 -8
- package/dist/runtime/mediaProxy.js +78 -7
- package/dist/runtime/runtimePort.d.ts +21 -0
- package/dist/runtime/runtimePort.js +122 -0
- package/dist/studioPreviewMark.d.ts +2 -0
- package/dist/studioPreviewMark.js +2 -0
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSvgSelectorAliasesScript } from "../generated/svg-selector-aliases-inline.js";
|
|
2
|
-
import
|
|
2
|
+
import { parseCss as parseProjectCss } from "@hyperframes/parsers/postcss";
|
|
3
3
|
import { escapeCssIdentifier, replaceSelectorIdTokens } from "./selectorIdTokens.js";
|
|
4
4
|
import { SCENE_PARTS_META } from "../sceneParts.js";
|
|
5
5
|
const AUTHORED_ROOT_ID_ATTR = "data-hf-authored-id";
|
|
@@ -169,7 +169,7 @@ function scopedSelectorsBound(selectors, scope, authoredRootId) {
|
|
|
169
169
|
}
|
|
170
170
|
function parseCss(css) {
|
|
171
171
|
try {
|
|
172
|
-
return
|
|
172
|
+
return parseProjectCss(css);
|
|
173
173
|
}
|
|
174
174
|
catch {
|
|
175
175
|
return null;
|
|
@@ -287,7 +287,7 @@ function dropFontFaces(styleTexts, hoisted) {
|
|
|
287
287
|
return css;
|
|
288
288
|
let root;
|
|
289
289
|
try {
|
|
290
|
-
root =
|
|
290
|
+
root = parseProjectCss(css);
|
|
291
291
|
}
|
|
292
292
|
catch {
|
|
293
293
|
return css; // unparseable text ships as authored and takes no part
|
|
@@ -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
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* data-hf-authored-id for script lookup compatibility.
|
|
7
7
|
*/
|
|
8
8
|
import { replaceMatches, urlHashRefMatches } from "@hyperframes/parsers/css-url-scans";
|
|
9
|
-
import
|
|
9
|
+
import { parseCss } from "@hyperframes/parsers/postcss";
|
|
10
10
|
import { fnv1a32 } from "../canary.js";
|
|
11
11
|
import { escapeCssIdentifier, selectorIdTokens } from "./selectorIdTokens.js";
|
|
12
12
|
import { SVG_REFERENCE_ALIASES_ATTR, readSvgReferenceAliases, recordedSvgIds, rewriteSvgSelectors, } from "./svgSelectorAliases.js";
|
|
@@ -422,7 +422,7 @@ export function rewriteSvgIdReferencesInCss(css, idMap, references = [], charge)
|
|
|
422
422
|
return css;
|
|
423
423
|
let root;
|
|
424
424
|
try {
|
|
425
|
-
root =
|
|
425
|
+
root = parseCss(css);
|
|
426
426
|
}
|
|
427
427
|
catch {
|
|
428
428
|
// Unparseable CSS is the caller's problem to report; leaving it untouched
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readPage } from "./pageTree.js";
|
|
2
|
-
import
|
|
2
|
+
import { parseCss } from "@hyperframes/parsers/postcss";
|
|
3
3
|
function screenStylesheet(media) {
|
|
4
4
|
return !media?.trim() || media.split(",").some((query) => /^(all|screen)$/i.test(query.trim()));
|
|
5
5
|
}
|
|
@@ -24,7 +24,7 @@ function importUrls(css) {
|
|
|
24
24
|
return [];
|
|
25
25
|
let root;
|
|
26
26
|
try {
|
|
27
|
-
root =
|
|
27
|
+
root = parseCss(css);
|
|
28
28
|
}
|
|
29
29
|
catch {
|
|
30
30
|
return [];
|
|
@@ -7,11 +7,11 @@ import { FONT_ALIAS_MAP, resolveAliasDisplayName } from "./aliases.js";
|
|
|
7
7
|
import { extractSfntFace } from "./sfntNames.js";
|
|
8
8
|
import { locateSystemFontVariants, SYSTEM_FONT_SIZE_LIMIT } from "./systemFontLocator.js";
|
|
9
9
|
import { forgetPage, readPage, takePage } from "./pageTree.js";
|
|
10
|
-
import
|
|
10
|
+
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
|
/**
|
|
@@ -112,7 +112,7 @@ function systemPrimaryReplacement(value, deterministicPrimary, customProperties)
|
|
|
112
112
|
}
|
|
113
113
|
function parseCssRoot(css) {
|
|
114
114
|
try {
|
|
115
|
-
return
|
|
115
|
+
return parseCss(css);
|
|
116
116
|
}
|
|
117
117
|
catch {
|
|
118
118
|
return null;
|
|
@@ -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
|
+
}
|