@hyperframes/core 0.9.51 → 0.9.53
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/htmlBundler.d.ts +1 -0
- package/dist/compiler/htmlBundler.js +28 -36
- package/dist/compiler/svgIdNamespacing.js +13 -24
- package/dist/fonts/deterministicFonts.js +98 -12
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/keyCombo.d.ts +20 -0
- package/dist/keyCombo.js +85 -0
- package/dist/sceneParts.js +2 -1
- package/dist/studioPreviewMark.d.ts +2 -0
- package/dist/studioPreviewMark.js +4 -0
- package/dist/typingTarget.d.ts +20 -0
- package/dist/typingTarget.js +78 -0
- package/package.json +12 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Combo {
|
|
2
|
+
mod: boolean;
|
|
3
|
+
meta: boolean;
|
|
4
|
+
ctrl: boolean;
|
|
5
|
+
shift: boolean;
|
|
6
|
+
alt: boolean;
|
|
7
|
+
key: string;
|
|
8
|
+
named: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** "mod+shift+z", "Space", "b": mod is Cmd or Ctrl; Ctrl+Alt is refused because Windows sends AltGr as Ctrl+Alt. */
|
|
11
|
+
export declare function parseCombo(text: string): Combo | null;
|
|
12
|
+
/** The one string a combo is stored and compared as. */
|
|
13
|
+
export declare function comboText(c: Combo): string;
|
|
14
|
+
export type ComboEvent = Pick<KeyboardEvent, "key" | "altKey" | "ctrlKey" | "metaKey" | "shiftKey"> & {
|
|
15
|
+
code?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function matchCombo(e: ComboEvent, c: Combo): boolean;
|
|
18
|
+
export declare function formatCombo(c: Combo): string;
|
|
19
|
+
/** Two combos clash when one press could satisfy both; Cmd and Ctrl both count as mod. */
|
|
20
|
+
export declare const comboClashKey: (c: Combo) => string;
|
package/dist/keyCombo.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const NAMED = new Set([
|
|
2
|
+
"Space",
|
|
3
|
+
"ArrowLeft",
|
|
4
|
+
"ArrowRight",
|
|
5
|
+
"ArrowUp",
|
|
6
|
+
"ArrowDown",
|
|
7
|
+
"Home",
|
|
8
|
+
"End",
|
|
9
|
+
"PageUp",
|
|
10
|
+
"PageDown",
|
|
11
|
+
"Delete",
|
|
12
|
+
"Backspace",
|
|
13
|
+
"Escape",
|
|
14
|
+
"Enter",
|
|
15
|
+
"Tab",
|
|
16
|
+
]);
|
|
17
|
+
const SYMBOL = {
|
|
18
|
+
ArrowLeft: "←",
|
|
19
|
+
ArrowRight: "→",
|
|
20
|
+
ArrowUp: "↑",
|
|
21
|
+
ArrowDown: "↓",
|
|
22
|
+
Delete: "Del",
|
|
23
|
+
Backspace: "⌫",
|
|
24
|
+
Escape: "Esc",
|
|
25
|
+
};
|
|
26
|
+
const MODIFIERS = new Set(["mod", "cmd", "ctrl", "shift", "alt"]);
|
|
27
|
+
/** "mod+shift+z", "Space", "b": mod is Cmd or Ctrl; Ctrl+Alt is refused because Windows sends AltGr as Ctrl+Alt. */
|
|
28
|
+
export function parseCombo(text) {
|
|
29
|
+
const split = text.length > 1 ? text.slice(0, -1).lastIndexOf("+") : -1;
|
|
30
|
+
const tokens = split < 0
|
|
31
|
+
? []
|
|
32
|
+
: text
|
|
33
|
+
.slice(0, split)
|
|
34
|
+
.split("+")
|
|
35
|
+
.map((t) => t.toLowerCase());
|
|
36
|
+
const key = text.slice(split + 1);
|
|
37
|
+
const named = NAMED.has(key);
|
|
38
|
+
const symbol = !named && !/^[A-Za-z]$/.test(key);
|
|
39
|
+
if (tokens.some((t) => !MODIFIERS.has(t)) || (!named && [...key].length !== 1))
|
|
40
|
+
return null;
|
|
41
|
+
if (symbol && tokens.includes("shift"))
|
|
42
|
+
return null;
|
|
43
|
+
const combo = {
|
|
44
|
+
mod: tokens.includes("mod"),
|
|
45
|
+
meta: tokens.includes("cmd"),
|
|
46
|
+
ctrl: tokens.includes("ctrl"),
|
|
47
|
+
shift: tokens.includes("shift"),
|
|
48
|
+
alt: tokens.includes("alt"),
|
|
49
|
+
key: named ? key : key.toLowerCase(),
|
|
50
|
+
named,
|
|
51
|
+
};
|
|
52
|
+
return combo.alt && (combo.ctrl || combo.mod) ? null : combo;
|
|
53
|
+
}
|
|
54
|
+
/** The one string a combo is stored and compared as. */
|
|
55
|
+
export function comboText(c) {
|
|
56
|
+
const mods = [
|
|
57
|
+
c.mod && "mod",
|
|
58
|
+
c.meta && "cmd",
|
|
59
|
+
c.ctrl && "ctrl",
|
|
60
|
+
c.alt && "alt",
|
|
61
|
+
c.shift && "shift",
|
|
62
|
+
];
|
|
63
|
+
return [...mods.filter(Boolean), c.key].join("+");
|
|
64
|
+
}
|
|
65
|
+
const namedMatches = (e, name) => e.code === name || e.key === (name === "Space" ? " " : name);
|
|
66
|
+
function charMatches(e, c) {
|
|
67
|
+
if (e.key.toLowerCase() === c.key)
|
|
68
|
+
return true;
|
|
69
|
+
// Option rewrites e.key on macOS (Option+D is "∂"), so fall back to the physical key.
|
|
70
|
+
const code = /^[0-9]$/.test(c.key) ? `Digit${c.key}` : `Key${c.key.toUpperCase()}`;
|
|
71
|
+
return e.altKey && /^[a-z0-9]$/.test(c.key) && e.code === code;
|
|
72
|
+
}
|
|
73
|
+
export function matchCombo(e, c) {
|
|
74
|
+
const symbol = !c.named && !/^[a-z]$/.test(c.key);
|
|
75
|
+
if ((!symbol && !!e.shiftKey !== c.shift) || !!e.altKey !== c.alt)
|
|
76
|
+
return false;
|
|
77
|
+
const modsOk = c.mod ? e.metaKey || e.ctrlKey : !!e.metaKey === c.meta && !!e.ctrlKey === c.ctrl;
|
|
78
|
+
return modsOk && (c.named ? namedMatches(e, c.key) : charMatches(e, c));
|
|
79
|
+
}
|
|
80
|
+
export function formatCombo(c) {
|
|
81
|
+
const mods = `${c.ctrl ? "⌃" : ""}${c.alt ? "⌥" : ""}${c.mod || c.meta ? "⌘" : ""}${c.shift ? "⇧" : ""}`;
|
|
82
|
+
return mods + (SYMBOL[c.key] ?? (c.named ? c.key : c.key.toUpperCase()));
|
|
83
|
+
}
|
|
84
|
+
/** Two combos clash when one press could satisfy both; Cmd and Ctrl both count as mod. */
|
|
85
|
+
export const comboClashKey = (c) => [c.mod || c.meta || c.ctrl, c.alt, c.shift, c.key].join("|");
|
package/dist/sceneParts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { fontFaceBlockMatches } from "@hyperframes/parsers/css-url-scans";
|
|
1
2
|
export const SCENE_PART_ATTR = "data-hf-scene";
|
|
2
3
|
export const SCENE_PARTS_META = "hf-scene-parts";
|
|
3
4
|
export const SCENE_FONTS_ATTR = "data-hf-scene-fonts";
|
|
4
|
-
export const fontFaceBlocks = (css) =>
|
|
5
|
+
export const fontFaceBlocks = (css) => Array.from(fontFaceBlockMatches(css), ({ parts }) => parts[0]);
|
|
5
6
|
/** On a scene's top-level host: why the scene cannot be swapped in place, so edits to it reload. */
|
|
6
7
|
export const SCENE_NO_SWAP_ATTR = "data-hf-scene-no-swap";
|
|
@@ -4,6 +4,8 @@ export declare const PREVIEW_VIDEO_FRAME_ATTR = "data-hf-preview-video-frame";
|
|
|
4
4
|
export declare const PREVIEW_VIDEO_SOURCE_ATTR = "data-hf-preview-video-source";
|
|
5
5
|
export declare const PREVIEW_VIDEO_CANVAS_ATTR = "data-hf-preview-video-canvas";
|
|
6
6
|
export declare const STUDIO_PREVIEW_CAPTURE_MODE = "capture";
|
|
7
|
+
export declare const PREVIEW_FOR_ANOTHER_SITE_META = "hyperframes-preview-for-another-site";
|
|
8
|
+
export declare function servedToAnotherSite(doc: Document): boolean;
|
|
7
9
|
export declare function getLogicalOpacity(el: Element, computed: CSSStyleDeclaration): string;
|
|
8
10
|
export declare const PLAYER_FRAME_ATTR = "data-hf-player-frame";
|
|
9
11
|
export declare function inPlayerFrame(doc: Document): boolean;
|
|
@@ -5,6 +5,10 @@ export const PREVIEW_VIDEO_FRAME_ATTR = "data-hf-preview-video-frame";
|
|
|
5
5
|
export const PREVIEW_VIDEO_SOURCE_ATTR = "data-hf-preview-video-source";
|
|
6
6
|
export const PREVIEW_VIDEO_CANVAS_ATTR = "data-hf-preview-video-canvas";
|
|
7
7
|
export const STUDIO_PREVIEW_CAPTURE_MODE = "capture";
|
|
8
|
+
export const PREVIEW_FOR_ANOTHER_SITE_META = "hyperframes-preview-for-another-site";
|
|
9
|
+
export function servedToAnotherSite(doc) {
|
|
10
|
+
return doc.querySelector(`meta[name="${PREVIEW_FOR_ANOTHER_SITE_META}"]`) !== null;
|
|
11
|
+
}
|
|
8
12
|
export function getLogicalOpacity(el, computed) {
|
|
9
13
|
const overlay = el.previousElementSibling;
|
|
10
14
|
if (el.hasAttribute(PREVIEW_VIDEO_FRAME_ATTR) &&
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a keystroke is going somewhere the user is typing.
|
|
3
|
+
*
|
|
4
|
+
* Every keyboard shortcut in Studio has to ask this before claiming a key, and
|
|
5
|
+
* they were each asking it slightly differently. The version that matched
|
|
6
|
+
* `[contenteditable='true']` missed `contenteditable="plaintext-only"`, which
|
|
7
|
+
* is what inline text editing uses, so the playback shortcuts kept claiming
|
|
8
|
+
* letters out of it: `a` seeked to the in-point and `e` to the out-point,
|
|
9
|
+
* `preventDefault` and all, and the character never reached the text.
|
|
10
|
+
*
|
|
11
|
+
* `isContentEditable` is the property to ask, not the attribute to match: it is
|
|
12
|
+
* true for every editable value and for an element made editable by an
|
|
13
|
+
* ancestor, which an attribute selector on the target alone cannot see.
|
|
14
|
+
* The wider input gate is deliberate too: checkboxes and readonly fields own
|
|
15
|
+
* Space and arrow keys even when they do not accept text.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isTypingTarget(target: EventTarget | null): boolean;
|
|
18
|
+
/** Plain keys (arrows, Space, Delete) also belong to a focused slider or player; Cmd shortcuts still do not. */
|
|
19
|
+
export declare function ownsPlainKeys(target: EventTarget | null): boolean;
|
|
20
|
+
export declare function shouldIgnorePlaybackShortcutTarget(target: EventTarget | null): boolean;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a keystroke is going somewhere the user is typing.
|
|
3
|
+
*
|
|
4
|
+
* Every keyboard shortcut in Studio has to ask this before claiming a key, and
|
|
5
|
+
* they were each asking it slightly differently. The version that matched
|
|
6
|
+
* `[contenteditable='true']` missed `contenteditable="plaintext-only"`, which
|
|
7
|
+
* is what inline text editing uses, so the playback shortcuts kept claiming
|
|
8
|
+
* letters out of it: `a` seeked to the in-point and `e` to the out-point,
|
|
9
|
+
* `preventDefault` and all, and the character never reached the text.
|
|
10
|
+
*
|
|
11
|
+
* `isContentEditable` is the property to ask, not the attribute to match: it is
|
|
12
|
+
* true for every editable value and for an element made editable by an
|
|
13
|
+
* ancestor, which an attribute selector on the target alone cannot see.
|
|
14
|
+
* The wider input gate is deliberate too: checkboxes and readonly fields own
|
|
15
|
+
* Space and arrow keys even when they do not accept text.
|
|
16
|
+
*/
|
|
17
|
+
export function isTypingTarget(target) {
|
|
18
|
+
const element = asElement(target);
|
|
19
|
+
if (!element)
|
|
20
|
+
return false;
|
|
21
|
+
if (element.isContentEditable)
|
|
22
|
+
return true;
|
|
23
|
+
return element.closest(TYPING_SELECTOR) !== null;
|
|
24
|
+
}
|
|
25
|
+
/** Plain keys (arrows, Space, Delete) also belong to a focused slider or player; Cmd shortcuts still do not. */
|
|
26
|
+
export function ownsPlainKeys(target) {
|
|
27
|
+
return isTypingTarget(target) || asElement(target)?.closest(KEY_OWNING_CONTROLS) != null;
|
|
28
|
+
}
|
|
29
|
+
// A slider steps and a native player seeks and plays with these keys themselves.
|
|
30
|
+
const KEY_OWNING_CONTROLS = "[role='slider'],video[controls],audio[controls]";
|
|
31
|
+
/**
|
|
32
|
+
* Things a keystroke belongs to rather than to a shortcut. `contenteditable` is
|
|
33
|
+
* matched by value as well, for a host whose own property is not yet true.
|
|
34
|
+
*/
|
|
35
|
+
const TYPING_SELECTOR = [
|
|
36
|
+
"input",
|
|
37
|
+
"textarea",
|
|
38
|
+
"select",
|
|
39
|
+
"[contenteditable]:not([contenteditable='false'])",
|
|
40
|
+
"[role='textbox']",
|
|
41
|
+
"[role='searchbox']",
|
|
42
|
+
"[role='combobox']",
|
|
43
|
+
// A switch is a button in the DOM, but the native checkbox it replaces was an
|
|
44
|
+
// `input` and matched above. Without this row the shared Toggle would let a
|
|
45
|
+
// global shortcut claim Space instead of flipping the control (KTD13).
|
|
46
|
+
"[role='switch']",
|
|
47
|
+
"[role='dialog'][aria-modal='true']",
|
|
48
|
+
".cm-editor",
|
|
49
|
+
].join(",");
|
|
50
|
+
function asElement(target) {
|
|
51
|
+
if (!target || typeof target !== "object")
|
|
52
|
+
return null;
|
|
53
|
+
const candidate = target;
|
|
54
|
+
return typeof candidate.closest === "function" ? target : null;
|
|
55
|
+
}
|
|
56
|
+
const PLAYBACK_SHORTCUT_IGNORED_SELECTOR = [
|
|
57
|
+
"button",
|
|
58
|
+
"a[href]",
|
|
59
|
+
"[role='button']",
|
|
60
|
+
"[role='checkbox']",
|
|
61
|
+
"[role='menuitem']",
|
|
62
|
+
// Base UI's menu radio item is a `<div>`, so `button` above no longer catches it.
|
|
63
|
+
"[role='menuitemradio']",
|
|
64
|
+
"[role='radio']",
|
|
65
|
+
"[role='spinbutton']",
|
|
66
|
+
].join(",");
|
|
67
|
+
export function shouldIgnorePlaybackShortcutTarget(target) {
|
|
68
|
+
// Anything the user is typing into owns its keys outright, editable elements
|
|
69
|
+
// included: a letter claimed here never reaches the text. So does a native player.
|
|
70
|
+
if (ownsPlainKeys(target))
|
|
71
|
+
return true;
|
|
72
|
+
if (!target || typeof target !== "object")
|
|
73
|
+
return false;
|
|
74
|
+
const candidate = target;
|
|
75
|
+
if (typeof candidate.closest !== "function")
|
|
76
|
+
return false;
|
|
77
|
+
return (candidate.closest.call(target, PLAYBACK_SHORTCUT_IGNORED_SELECTOR) !== null);
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.53",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -108,6 +108,14 @@
|
|
|
108
108
|
"import": "./dist/compositionContract.js",
|
|
109
109
|
"types": "./dist/compositionContract.d.ts"
|
|
110
110
|
},
|
|
111
|
+
"./key-combo": {
|
|
112
|
+
"import": "./dist/keyCombo.js",
|
|
113
|
+
"types": "./dist/keyCombo.d.ts"
|
|
114
|
+
},
|
|
115
|
+
"./typing-target": {
|
|
116
|
+
"import": "./dist/typingTarget.js",
|
|
117
|
+
"types": "./dist/typingTarget.d.ts"
|
|
118
|
+
},
|
|
111
119
|
"./studio-preview-mark": {
|
|
112
120
|
"import": "./dist/studioPreviewMark.js",
|
|
113
121
|
"types": "./dist/studioPreviewMark.d.ts"
|
|
@@ -449,9 +457,9 @@
|
|
|
449
457
|
"linkedom": "^0.18.12",
|
|
450
458
|
"postcss": "^8.5.8",
|
|
451
459
|
"wawoff2": "^2.0.1",
|
|
452
|
-
"@hyperframes/
|
|
453
|
-
"@hyperframes/
|
|
454
|
-
"@hyperframes/
|
|
460
|
+
"@hyperframes/lint": "0.9.53",
|
|
461
|
+
"@hyperframes/studio-server": "0.9.53",
|
|
462
|
+
"@hyperframes/parsers": "0.9.53"
|
|
455
463
|
},
|
|
456
464
|
"devDependencies": {
|
|
457
465
|
"@fontsource/archivo-black": "^5.2.8",
|