MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / createPickerModule

Function createPickerModule

packages/core/src/runtime/picker.ts:28–313  ·  view source on GitHub ↗
(deps: PickerModuleDeps)

Source from the content-addressed store, hash-verified

26};
27
28export function createPickerModule(deps: PickerModuleDeps): PickerModule {
29 let pickModeActive = false;
30 let pickModeHighlightEl: Element | null = null;
31 let pickModeStyleEl: HTMLStyleElement | null = null;
32 let pickLastHoveredInfo: RuntimePickerElementInfo | null = null;
33 let pickLastSelectedInfo: RuntimePickerElementInfo | null = null;
34
35 function emitPickerRuntimeEvent(eventName: string, detail: RuntimeJson): void {
36 try {
37 window.dispatchEvent(new CustomEvent(eventName, { detail }));
38 } catch (err) {
39 // no-op in unsupported contexts
40 swallow("runtime.picker.site1", err);
41 }
42 }
43
44 function setLastHoveredInfo(info: RuntimePickerElementInfo | null): void {
45 pickLastHoveredInfo = info;
46 emitPickerRuntimeEvent("hyperframe:picker:hovered", {
47 elementInfo: pickLastHoveredInfo,
48 isPickMode: pickModeActive,
49 timestamp: Date.now(),
50 });
51 }
52
53 function setLastSelectedInfo(info: RuntimePickerElementInfo | null): void {
54 pickLastSelectedInfo = info;
55 emitPickerRuntimeEvent("hyperframe:picker:selected", {
56 elementInfo: pickLastSelectedInfo,
57 isPickMode: pickModeActive,
58 timestamp: Date.now(),
59 });
60 }
61
62 function isEffectivelyHidden(el: HTMLElement): boolean {
63 const win = el.ownerDocument.defaultView;
64 if (!win) return false;
65 let current: HTMLElement | null = el;
66 while (current && current !== document.body && current !== document.documentElement) {
67 const computed = win.getComputedStyle(current);
68 if (computed.display === "none" || computed.visibility === "hidden") return true;
69 if (computed.pointerEvents === "none") return true;
70 const opacity = Number.parseFloat(computed.opacity);
71 if (
72 Number.isFinite(opacity) &&
73 opacity <= 0.01 &&
74 !current.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)
75 )
76 return true;
77 current = current.parentElement;
78 }
79 return false;
80 }
81
82 function isPickableElement(el: Element | null): el is Element {
83 if (!el || el === document.body || el === document.documentElement) return false;
84 const tag = el.tagName.toLowerCase();
85 if (tag === "script" || tag === "style" || tag === "link" || tag === "meta") return false;

Callers 2

picker.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected