From 3a11b99429ff9d8cc9aebc7bbee0b7645e30f7ff Mon Sep 17 00:00:00 2001 From: Luan Date: Tue, 31 Dec 2024 06:04:53 -0300 Subject: [PATCH] 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. --- src/parser/classes/misc/RendererContext.ts | 32 ++++++++++++++++++++++ src/parser/misc.ts | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/parser/classes/misc/RendererContext.ts diff --git a/src/parser/classes/misc/RendererContext.ts b/src/parser/classes/misc/RendererContext.ts new file mode 100644 index 000000000..013c20122 --- /dev/null +++ b/src/parser/classes/misc/RendererContext.ts @@ -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; + } + } + } +} \ No newline at end of file diff --git a/src/parser/misc.ts b/src/parser/misc.ts index 87ab1e4d5..99a6b2deb 100644 --- a/src/parser/misc.ts +++ b/src/parser/misc.ts @@ -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';