mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
feat(Parser): Implement utility class to parse rendererContext
This field is found in most of the newer view model nodes. It can contain accessibility labels, text, commands or nothing but logging info.
This commit is contained in:
32
src/parser/classes/misc/RendererContext.ts
Normal file
32
src/parser/classes/misc/RendererContext.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { RawNode } from '../../types/index.js';
|
||||
import NavigationEndpoint from '../NavigationEndpoint.js';
|
||||
|
||||
export type CommandContext = {
|
||||
on_tap?: NavigationEndpoint;
|
||||
};
|
||||
|
||||
export type AccessibilityContext = {
|
||||
label?: string;
|
||||
};
|
||||
|
||||
export default class RendererContext {
|
||||
public command_context: CommandContext;
|
||||
public accessibility_context: AccessibilityContext;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
this.command_context = {};
|
||||
this.accessibility_context = {};
|
||||
|
||||
if (Reflect.has(data, 'commandContext')) {
|
||||
if (Reflect.has(data.commandContext, 'onTap')) {
|
||||
this.command_context.on_tap = new NavigationEndpoint(data.commandContext.onTap);
|
||||
}
|
||||
}
|
||||
|
||||
if (Reflect.has(data, 'accessibilityContext')) {
|
||||
if (Reflect.has(data.accessibilityContext, 'label')) {
|
||||
this.accessibility_context.label = data.accessibilityContext.label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export { default as Author } from './classes/misc/Author.js';
|
||||
export { default as ChildElement } from './classes/misc/ChildElement.js';
|
||||
export { default as EmojiRun } from './classes/misc/EmojiRun.js';
|
||||
export { default as Format } from './classes/misc/Format.js';
|
||||
export { default as RendererContext } from './classes/misc/RendererContext.js';
|
||||
export { default as Text } from './classes/misc/Text.js';
|
||||
export { default as TextRun } from './classes/misc/TextRun.js';
|
||||
export { default as Thumbnail } from './classes/misc/Thumbnail.js';
|
||||
|
||||
Reference in New Issue
Block a user