@hyperframes/core 0.8.229 → 0.8.231
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/cacheDir.d.ts +1 -0
- package/dist/cacheDir.js +6 -0
- package/dist/colorLuts.d.ts +2 -1
- package/dist/colorLuts.js +30 -1
- package/dist/fonts/deterministicFonts.js +3 -2
- package/dist/fonts/fontCompression.js +3 -2
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +62 -62
- package/package.json +8 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hyperframesCacheDir(...parts: string[]): string;
|
package/dist/cacheDir.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
export function hyperframesCacheDir(...parts) {
|
|
4
|
+
const named = process.env["HYPERFRAMES_CACHE_DIR"];
|
|
5
|
+
return join(named ? resolve(named) : join(homedir(), ".cache", "hyperframes"), ...parts);
|
|
6
|
+
}
|
package/dist/colorLuts.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ export declare class CubeLutParseError extends Error {
|
|
|
18
18
|
readonly lineNumber: number | null;
|
|
19
19
|
constructor(message: string, lineNumber?: number | null);
|
|
20
20
|
}
|
|
21
|
-
export declare const DEFAULT_MAX_CUBE_LUT_SIZE =
|
|
21
|
+
export declare const DEFAULT_MAX_CUBE_LUT_SIZE = 65;
|
|
22
22
|
export declare function parseCubeLut(input: string, options?: ParseCubeLutOptions): CubeLut3D;
|
|
23
23
|
export declare function unitFloatToByte(value: number): number;
|
|
24
24
|
export declare function packCubeLutToRgba8(lut: CubeLut3D): PackedCubeLut2D;
|
|
25
|
+
export declare function fitCubeLutToTexture(lut: CubeLut3D, maxTextureSize: number): CubeLut3D;
|
package/dist/colorLuts.js
CHANGED
|
@@ -8,7 +8,7 @@ export class CubeLutParseError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
const DEFAULT_DOMAIN_MIN = [0, 0, 0];
|
|
10
10
|
const DEFAULT_DOMAIN_MAX = [1, 1, 1];
|
|
11
|
-
export const DEFAULT_MAX_CUBE_LUT_SIZE =
|
|
11
|
+
export const DEFAULT_MAX_CUBE_LUT_SIZE = 65;
|
|
12
12
|
function stripComment(line) {
|
|
13
13
|
let inQuote = false;
|
|
14
14
|
for (let i = 0; i < line.length; i++) {
|
|
@@ -182,3 +182,32 @@ export function packCubeLutToRgba8(lut) {
|
|
|
182
182
|
}
|
|
183
183
|
return { width, height, data: packed };
|
|
184
184
|
}
|
|
185
|
+
export function fitCubeLutToTexture(lut, maxTextureSize) {
|
|
186
|
+
if (!(maxTextureSize >= 4) || lut.size * lut.size <= maxTextureSize)
|
|
187
|
+
return lut;
|
|
188
|
+
const size = Math.max(2, Math.floor(Math.sqrt(maxTextureSize)));
|
|
189
|
+
const data = new Float32Array(size * size * size * 3);
|
|
190
|
+
const last = lut.size - 1;
|
|
191
|
+
const at = (r, g, b, c) => lut.data[((b * lut.size + g) * lut.size + r) * 3 + c] ?? 0;
|
|
192
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
193
|
+
for (let b = 0; b < size; b++) {
|
|
194
|
+
for (let g = 0; g < size; g++) {
|
|
195
|
+
for (let r = 0; r < size; r++) {
|
|
196
|
+
const pr = (r / (size - 1)) * last;
|
|
197
|
+
const pg = (g / (size - 1)) * last;
|
|
198
|
+
const pb = (b / (size - 1)) * last;
|
|
199
|
+
const r0 = Math.floor(pr);
|
|
200
|
+
const g0 = Math.floor(pg);
|
|
201
|
+
const b0 = Math.floor(pb);
|
|
202
|
+
const r1 = Math.min(last, r0 + 1);
|
|
203
|
+
const g1 = Math.min(last, g0 + 1);
|
|
204
|
+
const b1 = Math.min(last, b0 + 1);
|
|
205
|
+
for (let c = 0; c < 3; c++) {
|
|
206
|
+
const plane = (bi) => lerp(lerp(at(r0, g0, bi, c), at(r1, g0, bi, c), pr - r0), lerp(at(r0, g1, bi, c), at(r1, g1, bi, c), pr - r0), pg - g0);
|
|
207
|
+
data[((b * size + g) * size + r) * 3 + c] = lerp(plane(b0), plane(b1), pb - b0);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { ...lut, size, data };
|
|
213
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { FONT_ALIAS_MAP, resolveAliasDisplayName } from "./aliases.js";
|
|
6
6
|
import { locateSystemFontVariants, SYSTEM_FONT_SIZE_LIMIT } from "./systemFontLocator.js";
|
|
@@ -10,6 +10,7 @@ import { EMBEDDED_FONT_DATA } from "./fontData.generated.js";
|
|
|
10
10
|
import { fontToDataUri } from "./fontCompression.js";
|
|
11
11
|
import { authoredGoogleFontStylesheets, withPageText } from "./authoredGoogleFonts.js";
|
|
12
12
|
import { FontDiagCollector, } from "./fontDiagnostics.js";
|
|
13
|
+
import { hyperframesCacheDir } from "../cacheDir.js";
|
|
13
14
|
/**
|
|
14
15
|
* Family names that resolve to a host-OS font (or a CSS generic that the
|
|
15
16
|
* browser substitutes with a host-OS font). Exported so plan-time validators
|
|
@@ -887,7 +888,7 @@ function resolveFontCacheRoot() {
|
|
|
887
888
|
lambdaFontCacheRoot ??= mkdtempSync(join(tmpdir(), "hyperframes-fonts-"));
|
|
888
889
|
return lambdaFontCacheRoot;
|
|
889
890
|
}
|
|
890
|
-
return
|
|
891
|
+
return hyperframesCacheDir("fonts");
|
|
891
892
|
}
|
|
892
893
|
// Chrome UA triggers woff2 responses from Google Fonts CSS API
|
|
893
894
|
const WOFF2_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import wawoff2 from "wawoff2";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
5
|
-
import {
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
|
+
import { hyperframesCacheDir } from "../cacheDir.js";
|
|
7
8
|
const { compress } = wawoff2;
|
|
8
9
|
export async function compressToWoff2(input) {
|
|
9
10
|
return Buffer.from(await compress(input));
|
|
@@ -19,7 +20,7 @@ function defaultCacheDir() {
|
|
|
19
20
|
const root = process.env.HYPERFRAMES_FONT_CACHE_DIR ??
|
|
20
21
|
(process.env.AWS_LAMBDA_FUNCTION_NAME
|
|
21
22
|
? join(tmpdir(), "hyperframes", "fonts")
|
|
22
|
-
:
|
|
23
|
+
: hyperframesCacheDir("fonts"));
|
|
23
24
|
return join(root, "local-compression-v1");
|
|
24
25
|
}
|
|
25
26
|
function cachedCompressionPath(input, originalFormat, cacheDir) {
|