diff --git a/packages/studio/package-subpaths.json b/packages/studio/package-subpaths.json index 56bf81e5de..55a2fa4ad1 100644 --- a/packages/studio/package-subpaths.json +++ b/packages/studio/package-subpaths.json @@ -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", diff --git a/packages/studio/package.json b/packages/studio/package.json index 4138734066..9687ea4539 100644 --- a/packages/studio/package.json +++ b/packages/studio/package.json @@ -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" diff --git a/packages/studio/src/keys.test.ts b/packages/studio/src/keys.test.ts new file mode 100644 index 0000000000..f7b75bf583 --- /dev/null +++ b/packages/studio/src/keys.test.ts @@ -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(); + const packages = new Set(); + 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); + }); +}); diff --git a/packages/studio/src/keys.ts b/packages/studio/src/keys.ts new file mode 100644 index 0000000000..81a1d8ab8c --- /dev/null +++ b/packages/studio/src/keys.ts @@ -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"; diff --git a/packages/studio/src/player/components/studioKeyDefaults.ts b/packages/studio/src/player/components/studioKeyDefaults.ts new file mode 100644 index 0000000000..7cd87bfcee --- /dev/null +++ b/packages/studio/src/player/components/studioKeyDefaults.ts @@ -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>; diff --git a/packages/studio/src/player/components/studioShortcuts.ts b/packages/studio/src/player/components/studioShortcuts.ts index 4fe98ced21..d08ae0fb52 100644 --- a/packages/studio/src/player/components/studioShortcuts.ts +++ b/packages/studio/src/player/components/studioShortcuts.ts @@ -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>; +export { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults"; const SHARED_BY_DESIGN: ReadonlyArray = [ ["pause", "addKeyframe"], diff --git a/packages/studio/tsup.config.ts b/packages/studio/tsup.config.ts index e9d54eca40..98920fab21 100644 --- a/packages/studio/tsup.config.ts +++ b/packages/studio/tsup.config.ts @@ -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"],