feat(studio): add a light @hyperframes/studio/keys subpath for key parsing and defaults (#7600)

* feat(studio): add a light @hyperframes/studio/keys subpath for key parsing and defaults

parseCombo, matchCombo and DEFAULT_STUDIO_KEYS, with their types, from an
entry that imports nothing else, so a host can read Studio's keys without
loading the editor. The defaults move to a module of their own, which
studioShortcuts re-exports as before.

* fix(studio): declare the keys subpath in package-subpaths.json and regenerate the manifest

* test(studio): read the keys import graph with platform paths so it passes on Windows
This commit is contained in:
Miguel Ángel
2026-11-12 11:04:44 +00:00
committed by GitHub
parent 01618d504a
commit 234fb1aeef
7 changed files with 150 additions and 67 deletions
+6
View File
@@ -19,6 +19,12 @@
"types": "./dist/player.d.ts",
"environments": ["browser"]
},
"./keys": {
"source": "./src/keys.ts",
"runtime": "./dist/keys.js",
"types": "./dist/keys.d.ts",
"environments": ["browser", "bun", "node"]
},
"./tailwind-preset": {
"source": "./src/styles/tailwind-preset.ts",
"runtime": "./dist/styles/tailwind-preset.js",
+9
View File
@@ -33,6 +33,11 @@
"import": "./src/playerEntry.ts",
"types": "./src/playerEntry.ts"
},
"./keys": {
"bun": "./src/keys.ts",
"import": "./src/keys.ts",
"types": "./src/keys.ts"
},
"./tailwind-preset": {
"bun": "./src/styles/tailwind-preset.ts",
"import": "./src/styles/tailwind-preset.ts",
@@ -58,6 +63,10 @@
"import": "./dist/player.js",
"types": "./dist/player.d.ts"
},
"./keys": {
"import": "./dist/keys.js",
"types": "./dist/keys.d.ts"
},
"./tailwind-preset": {
"import": "./dist/styles/tailwind-preset.js",
"types": "./dist/styles/tailwind-preset.d.ts"
+53
View File
@@ -0,0 +1,53 @@
import { readFileSync } from "node:fs";
import { dirname, join, relative, resolve, sep } from "node:path";
import ts from "typescript";
import { describe, expect, it } from "vitest";
const src = import.meta.dirname;
/** Every file `entry` reaches through static imports and re-exports, with any package it names. */
function importGraph(entry: string): { files: string[]; packages: string[] } {
const files = new Set<string>();
const packages = new Set<string>();
const visit = (file: string) => {
if (files.has(file)) return;
files.add(file);
for (const { fileName } of ts.preProcessFile(readFileSync(file, "utf8")).importedFiles) {
if (!fileName.startsWith(".")) {
packages.add(fileName);
continue;
}
const base = resolve(dirname(file), fileName);
visit(
[`${base}.ts`, `${base}.tsx`, join(base, "index.ts")].find((f) => ts.sys.fileExists(f))!,
);
}
};
visit(join(src, entry));
return {
files: [...files].map((f) => relative(src, f).split(sep).join("/")).sort(),
packages: [...packages],
};
}
describe("@hyperframes/studio/keys", () => {
it("imports only the key helpers: no package and no editor module", () => {
expect(importGraph("keys.ts")).toEqual({
files: [
"keys.ts",
"player/components/studioCombo.ts",
"player/components/studioKeyDefaults.ts",
],
packages: [],
});
});
it("is a published subpath sharing the defaults the root entry exports", async () => {
const pkg = JSON.parse(readFileSync(join(src, "../package.json"), "utf8"));
expect(pkg.exports["./keys"].import).toBe("./src/keys.ts");
expect(pkg.publishConfig.exports["./keys"].import).toBe("./dist/keys.js");
const keys = await import("./keys");
const shortcuts = await import("./player/components/studioShortcuts");
expect(keys.DEFAULT_STUDIO_KEYS).toBe(shortcuts.DEFAULT_STUDIO_KEYS);
});
});
+11
View File
@@ -0,0 +1,11 @@
export {
matchCombo,
parseCombo,
type Combo,
type ComboEvent,
} from "./player/components/studioCombo";
export {
DEFAULT_STUDIO_KEYS,
type StudioKeyAction,
type StudioKeys,
} from "./player/components/studioKeyDefaults";
@@ -0,0 +1,68 @@
/** Every single-character bare key Studio answers, by action. */
export const DEFAULT_STUDIO_KEYS = {
fullscreen: "f",
split: "s",
record: "r",
addKeyframe: "k",
audioGain: "g",
zoomSelection: "z",
mute: "m",
pause: "k",
shuttleBack: "j",
shuttleForward: "l",
inPoint: "i",
outPoint: "o",
seekToIn: "a",
seekToOut: "e",
selectTool: "v",
razorTool: "b",
selectLeftward: "[",
selectRightward: "]",
exitRazor: "a",
snap: "s",
grid: "g",
timelineSnap: "n",
playPause: "Space",
frameBack: "ArrowLeft",
frameForward: "ArrowRight",
frameBackTen: "shift+ArrowLeft",
frameForwardTen: "shift+ArrowRight",
loop: "shift+l",
clearInPoint: "shift+i",
clearOutPoint: "shift+o",
undo: "mod+z",
redo: "mod+shift+z",
redoAlt: "ctrl+y",
tabCompositions: "mod+1",
tabAssets: "mod+2",
group: "mod+g",
ungroup: "mod+shift+g",
copy: "mod+c",
paste: "mod+v",
cut: "mod+x",
duplicate: "mod+d",
linkToggle: "mod+l",
detachAudio: "alt+shift+d",
deleteLinked: "alt+Backspace",
deleteLinkedAlt: "alt+Delete",
deleteSelected: "Delete",
deleteSelectedAlt: "Backspace",
resetKeyframes: "Backspace",
nudgeLeft: "ArrowLeft",
nudgeRight: "ArrowRight",
nudgeUp: "ArrowUp",
nudgeDown: "ArrowDown",
nudgeLeftTen: "shift+ArrowLeft",
nudgeRightTen: "shift+ArrowRight",
nudgeUpTen: "shift+ArrowUp",
nudgeDownTen: "shift+ArrowDown",
captionSelectAll: "mod+a",
pickupClip: "Space",
pickupUp: "ArrowUp",
pickupDown: "ArrowDown",
pickupDrop: "Enter",
cancel: "Escape",
};
export type StudioKeyAction = keyof typeof DEFAULT_STUDIO_KEYS;
export type StudioKeys = Readonly<Record<StudioKeyAction, string>>;
@@ -8,74 +8,9 @@ import {
parseCombo,
} from "./studioCombo";
/** Every single-character bare key Studio answers, by action. */
export const DEFAULT_STUDIO_KEYS = {
fullscreen: "f",
split: "s",
record: "r",
addKeyframe: "k",
audioGain: "g",
zoomSelection: "z",
mute: "m",
pause: "k",
shuttleBack: "j",
shuttleForward: "l",
inPoint: "i",
outPoint: "o",
seekToIn: "a",
seekToOut: "e",
selectTool: "v",
razorTool: "b",
selectLeftward: "[",
selectRightward: "]",
exitRazor: "a",
snap: "s",
grid: "g",
timelineSnap: "n",
playPause: "Space",
frameBack: "ArrowLeft",
frameForward: "ArrowRight",
frameBackTen: "shift+ArrowLeft",
frameForwardTen: "shift+ArrowRight",
loop: "shift+l",
clearInPoint: "shift+i",
clearOutPoint: "shift+o",
undo: "mod+z",
redo: "mod+shift+z",
redoAlt: "ctrl+y",
tabCompositions: "mod+1",
tabAssets: "mod+2",
group: "mod+g",
ungroup: "mod+shift+g",
copy: "mod+c",
paste: "mod+v",
cut: "mod+x",
duplicate: "mod+d",
linkToggle: "mod+l",
detachAudio: "alt+shift+d",
deleteLinked: "alt+Backspace",
deleteLinkedAlt: "alt+Delete",
deleteSelected: "Delete",
deleteSelectedAlt: "Backspace",
resetKeyframes: "Backspace",
nudgeLeft: "ArrowLeft",
nudgeRight: "ArrowRight",
nudgeUp: "ArrowUp",
nudgeDown: "ArrowDown",
nudgeLeftTen: "shift+ArrowLeft",
nudgeRightTen: "shift+ArrowRight",
nudgeUpTen: "shift+ArrowUp",
nudgeDownTen: "shift+ArrowDown",
captionSelectAll: "mod+a",
pickupClip: "Space",
pickupUp: "ArrowUp",
pickupDown: "ArrowDown",
pickupDrop: "Enter",
cancel: "Escape",
};
import { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults";
export type StudioKeyAction = keyof typeof DEFAULT_STUDIO_KEYS;
export type StudioKeys = Readonly<Record<StudioKeyAction, string>>;
export { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults";
const SHARED_BY_DESIGN: ReadonlyArray<readonly [StudioKeyAction, StudioKeyAction]> = [
["pause", "addKeyframe"],
+1
View File
@@ -6,6 +6,7 @@ export default defineConfig({
index: "src/index.ts",
ui: "src/ui.ts",
player: "src/playerEntry.ts",
keys: "src/keys.ts",
"styles/tailwind-preset": "src/styles/tailwind-preset.ts",
},
format: ["esm"],