mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
feat: Add AccessibilityContext and CommandContext classes + improve type definitions and parsing logic across multiple nodes
This commit is contained in:
9
src/parser/classes/misc/AccessibilityContext.ts
Normal file
9
src/parser/classes/misc/AccessibilityContext.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { RawNode } from '../../types/index.js';
|
||||
|
||||
export default class AccessibilityContext {
|
||||
public label: string;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
this.label = data.label;
|
||||
}
|
||||
}
|
||||
47
src/parser/classes/misc/CommandContext.ts
Normal file
47
src/parser/classes/misc/CommandContext.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { RawNode } from '../../types/index.js';
|
||||
import NavigationEndpoint from '../NavigationEndpoint.js';
|
||||
|
||||
export default class CommandContext {
|
||||
public on_focus?: NavigationEndpoint;
|
||||
public on_hidden?: NavigationEndpoint;
|
||||
public on_touch_end?: NavigationEndpoint;
|
||||
public on_touch_move?: NavigationEndpoint;
|
||||
public on_long_press?: NavigationEndpoint;
|
||||
public on_tap?: NavigationEndpoint;
|
||||
public on_touch_start?: NavigationEndpoint;
|
||||
public on_visible?: NavigationEndpoint;
|
||||
public on_first_visible?: NavigationEndpoint;
|
||||
public on_hover?: NavigationEndpoint;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
if ('onFocus' in data)
|
||||
this.on_focus = new NavigationEndpoint(data.onFocus);
|
||||
|
||||
if ('onHidden' in data)
|
||||
this.on_hidden = new NavigationEndpoint(data.onHidden);
|
||||
|
||||
if ('onTouchEnd' in data)
|
||||
this.on_touch_end = new NavigationEndpoint(data.onTouchEnd);
|
||||
|
||||
if ('onTouchMove' in data)
|
||||
this.on_touch_move = new NavigationEndpoint(data.onTouchMove);
|
||||
|
||||
if ('onLongPress' in data)
|
||||
this.on_long_press = new NavigationEndpoint(data.onLongPress);
|
||||
|
||||
if ('onTap' in data)
|
||||
this.on_tap = new NavigationEndpoint(data.onTap);
|
||||
|
||||
if ('onTouchStart' in data)
|
||||
this.on_touch_start = new NavigationEndpoint(data.onTouchStart);
|
||||
|
||||
if ('onVisible' in data)
|
||||
this.on_visible = new NavigationEndpoint(data.onVisible);
|
||||
|
||||
if ('onFirstVisible' in data)
|
||||
this.on_first_visible = new NavigationEndpoint(data.onFirstVisible);
|
||||
|
||||
if ('onHover' in data)
|
||||
this.on_hover = new NavigationEndpoint(data.onHover);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,21 @@
|
||||
import type { RawNode } from '../../types/index.js';
|
||||
import NavigationEndpoint from '../NavigationEndpoint.js';
|
||||
|
||||
export type CommandContext = {
|
||||
on_tap?: NavigationEndpoint;
|
||||
};
|
||||
|
||||
export type AccessibilityContext = {
|
||||
label?: string;
|
||||
};
|
||||
import CommandContext from './CommandContext.js';
|
||||
import AccessibilityContext from './AccessibilityContext.js';
|
||||
|
||||
export default class RendererContext {
|
||||
public command_context: CommandContext;
|
||||
public accessibility_context: AccessibilityContext;
|
||||
public command_context?: CommandContext;
|
||||
public accessibility_context?: AccessibilityContext;
|
||||
|
||||
constructor(data?: RawNode) {
|
||||
this.command_context = {};
|
||||
this.accessibility_context = {};
|
||||
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
if (Reflect.has(data, 'commandContext')) {
|
||||
if (Reflect.has(data.commandContext, 'onTap')) {
|
||||
this.command_context.on_tap = new NavigationEndpoint(data.commandContext.onTap);
|
||||
}
|
||||
if ('commandContext' in data) {
|
||||
this.command_context = new CommandContext(data.commandContext);
|
||||
}
|
||||
|
||||
if (Reflect.has(data, 'accessibilityContext')) {
|
||||
if (Reflect.has(data.accessibilityContext, 'label')) {
|
||||
this.accessibility_context.label = data.accessibilityContext.label;
|
||||
}
|
||||
if ('accessibilityContext' in data) {
|
||||
this.accessibility_context = new AccessibilityContext(data.accessibilityContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/parser/classes/misc/SubscriptionButton.ts
Normal file
17
src/parser/classes/misc/SubscriptionButton.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { RawNode } from '../../index.js';
|
||||
import Text from './Text.js';
|
||||
|
||||
export default class SubscriptionButton {
|
||||
static type = 'SubscriptionButton';
|
||||
|
||||
public text: Text;
|
||||
public subscribed: boolean;
|
||||
public subscription_type?: 'FREE' | 'PAID' | 'UNAVAILABLE';
|
||||
|
||||
constructor(data: RawNode) {
|
||||
this.text = new Text(data.text);
|
||||
this.subscribed = data.isSubscribed;
|
||||
if ('subscriptionType' in data)
|
||||
this.subscription_type = data.subscriptionType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user