From ad2ae51b97d84dcb9d2547b4cfef7402f2410404 Mon Sep 17 00:00:00 2001 From: Luan Date: Sun, 8 Dec 2024 17:11:27 -0300 Subject: [PATCH] feat(parser): Add mobile guide nodes --- src/parser/classes/mweb/MobileTopbar.ts | 20 ++++++++++++++ .../classes/mweb/MultiPageMenuSection.ts | 14 ++++++++++ src/parser/classes/mweb/PivotBar.ts | 13 +++++++++ src/parser/classes/mweb/PivotBarItem.ts | 27 +++++++++++++++++++ src/parser/classes/mweb/TopbarMenuButton.ts | 18 +++++++++++++ src/parser/nodes.ts | 5 ++++ 6 files changed, 97 insertions(+) create mode 100644 src/parser/classes/mweb/MobileTopbar.ts create mode 100644 src/parser/classes/mweb/MultiPageMenuSection.ts create mode 100644 src/parser/classes/mweb/PivotBar.ts create mode 100644 src/parser/classes/mweb/PivotBarItem.ts create mode 100644 src/parser/classes/mweb/TopbarMenuButton.ts diff --git a/src/parser/classes/mweb/MobileTopbar.ts b/src/parser/classes/mweb/MobileTopbar.ts new file mode 100644 index 00000000..4930aa4f --- /dev/null +++ b/src/parser/classes/mweb/MobileTopbar.ts @@ -0,0 +1,20 @@ +import { YTNode } from '../../helpers.js'; +import Text from '../misc/Text.js'; +import { Parser, type RawNode } from '../../index.js'; + +export default class MobileTopbar extends YTNode { + static type = 'MobileTopbar'; + + public placeholder_text: Text; + public buttons; + public logo_type?: string; + + constructor(data: RawNode) { + super(); + this.placeholder_text = new Text(data.placeholderText); + this.buttons = Parser.parseArray(data.buttons); + + if (Reflect.has(data, 'logo') && Reflect.has(data.logo, 'iconType')) + this.logo_type = data.logo.iconType; + } +} \ No newline at end of file diff --git a/src/parser/classes/mweb/MultiPageMenuSection.ts b/src/parser/classes/mweb/MultiPageMenuSection.ts new file mode 100644 index 00000000..138feb53 --- /dev/null +++ b/src/parser/classes/mweb/MultiPageMenuSection.ts @@ -0,0 +1,14 @@ +import type { ObservedArray } from '../../helpers.js'; +import { YTNode } from '../../helpers.js'; +import { Parser, type RawNode } from '../../index.js'; + +export default class MultiPageMenuSection extends YTNode { + static type = 'MultiPageMenuSection'; + + public items: ObservedArray | null; + + constructor(data: RawNode) { + super(); + this.items = Parser.parseArray(data.items); + } +} \ No newline at end of file diff --git a/src/parser/classes/mweb/PivotBar.ts b/src/parser/classes/mweb/PivotBar.ts new file mode 100644 index 00000000..f4b63b62 --- /dev/null +++ b/src/parser/classes/mweb/PivotBar.ts @@ -0,0 +1,13 @@ +import { YTNode } from '../../helpers.js'; +import { Parser, type RawNode } from '../../index.js'; + +export default class PivotBar extends YTNode { + static type = 'PivotBar'; + + public items; + + constructor(data: RawNode) { + super(); + this.items = Parser.parseArray(data.items); + } +} \ No newline at end of file diff --git a/src/parser/classes/mweb/PivotBarItem.ts b/src/parser/classes/mweb/PivotBarItem.ts new file mode 100644 index 00000000..dda664db --- /dev/null +++ b/src/parser/classes/mweb/PivotBarItem.ts @@ -0,0 +1,27 @@ +import { YTNode } from '../../helpers.js'; +import { type RawNode } from '../../index.js'; +import Text from '../misc/Text.js'; +import NavigationEndpoint from '../NavigationEndpoint.js'; + +export default class PivotBarItem extends YTNode { + static type = 'PivotBarItem'; + + public pivot_identifier: string; + public endpoint: NavigationEndpoint; + public title: Text; + public accessibility_label?: string; + public icon_type?: string; + + constructor(data: RawNode) { + super(); + this.pivot_identifier = data.pivotIdentifier; + this.endpoint = new NavigationEndpoint(data.navigationEndpoint); + this.title = new Text(data.title); + + if (Reflect.has(data, 'accessibility') && Reflect.has(data.accessibility, 'accessibilityData')) + this.accessibility_label = data.accessibility.accessibilityData.label; + + if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) + this.icon_type = data.icon.iconType; + } +} \ No newline at end of file diff --git a/src/parser/classes/mweb/TopbarMenuButton.ts b/src/parser/classes/mweb/TopbarMenuButton.ts new file mode 100644 index 00000000..e2e2ce24 --- /dev/null +++ b/src/parser/classes/mweb/TopbarMenuButton.ts @@ -0,0 +1,18 @@ +import { YTNode } from '../../helpers.js'; +import { Parser, type RawNode } from '../../index.js'; + +export default class TopbarMenuButton extends YTNode { + static type = 'TopbarMenuButton'; + + public icon_type?: string; + public menu_renderer: YTNode | null; + public target_id: string; + + constructor(data: RawNode) { + super(); + if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) + this.icon_type = data.icon.iconType; + this.menu_renderer = Parser.parseItem(data.menuRenderer); + this.target_id = data.targetId; + } +} \ No newline at end of file diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index 7ed4a31a..06586753 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -323,6 +323,11 @@ export { default as MusicTastebuilderShelfThumbnail } from './classes/MusicTaste export { default as MusicThumbnail } from './classes/MusicThumbnail.js'; export { default as MusicTwoRowItem } from './classes/MusicTwoRowItem.js'; export { default as MusicVisualHeader } from './classes/MusicVisualHeader.js'; +export { default as MobileTopbar } from './classes/mweb/MobileTopbar.js'; +export { default as MultiPageMenuSection } from './classes/mweb/MultiPageMenuSection.js'; +export { default as PivotBar } from './classes/mweb/PivotBar.js'; +export { default as PivotBarItem } from './classes/mweb/PivotBarItem.js'; +export { default as TopbarMenuButton } from './classes/mweb/TopbarMenuButton.js'; export { default as NavigationEndpoint } from './classes/NavigationEndpoint.js'; export { default as Notification } from './classes/Notification.js'; export { default as NotificationAction } from './classes/NotificationAction.js';