ReadViewSDK/Doc/WXRead/decompiled/DTHTMLElement.h
2026-05-21 19:40:51 +08:00

136 lines
4.0 KiB
Objective-C

//
// DTHTMLElement.h
// DTCoreText (WeRead custom fork)
//
// Reverse-engineered from WeChat Reading (微信读书) binary.
// Represents a single HTML element in the DOM tree built during parsing.
// Each node can produce an NSAttributedString via -attributedString.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class DTTextAttachment;
@class DTBorderStyle;
@class DTBackgroundImageStyle;
@class DTTableStyle;
@class DTCSSStylesheet;
@class DTCoreTextFontDescriptor;
@class DTCoreTextParagraphStyle;
// ---------------------------------------------------------------------------
// DTHTMLElement
// ---------------------------------------------------------------------------
@interface DTHTMLElement : NSObject
// --- Initialization ---
- (instancetype)initWithTagName:(NSString *)tagName
attributes:(NSDictionary *)attributes;
// --- Tree structure ---
@property (nonatomic, weak) DTHTMLElement *parent;
@property (nonatomic, strong) NSMutableArray *children;
// --- Tag identity ---
@property (nonatomic, copy) NSString *tagName;
@property (nonatomic, copy) NSString *elementId;
@property (nonatomic, strong) NSArray *classNames;
// --- Attributes & style ---
@property (nonatomic, strong) NSDictionary *attributes;
@property (nonatomic, strong) NSDictionary *styleDictionary;
// --- Text content ---
@property (nonatomic, copy) NSString *text;
@property (nonatomic, strong) NSArray *textRuns;
// --- Display properties ---
@property (nonatomic, assign) BOOL isLineBreak;
@property (nonatomic, assign) BOOL isBlockElement;
@property (nonatomic, assign) BOOL shouldAvoidPageBreakInside;
@property (nonatomic, assign) BOOL pageBreakAfter;
@property (nonatomic, assign) BOOL pageBreakBefore;
// --- Font & paragraph ---
@property (nonatomic, strong) DTCoreTextFontDescriptor *fontDescriptor;
@property (nonatomic, strong) DTCoreTextParagraphStyle *paragraphStyle;
// --- Colors ---
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) UIColor *backgroundColor;
// --- Links ---
@property (nonatomic, strong) NSURL *linkURL;
// --- Images & attachments ---
@property (nonatomic, strong) NSURL *imageURL;
@property (nonatomic, strong) DTTextAttachment *textAttachment;
// --- WeRead-specific page layout properties ---
@property (nonatomic, copy) NSString *verticalCenterStyle;
@property (nonatomic, copy) NSString *pageRelate;
@property (nonatomic, strong) UIColor *pageBackgroundColor;
@property (nonatomic, copy) NSString *pageBackgroundImage;
// --- Border & background ---
@property (nonatomic, strong) DTBorderStyle *borderStyle;
@property (nonatomic, strong) DTBackgroundImageStyle *backgroundImageStyle;
@property (nonatomic, strong) DTTableStyle *tableStyle;
// --- Additional string fields observed in ivars ---
@property (nonatomic, copy) NSString *cssClass;
@property (nonatomic, copy) NSString *cssId;
@property (nonatomic, copy) NSString *lang;
@property (nonatomic, copy) NSString *direction; // ltr / rtl
@property (nonatomic, copy) NSString *whiteSpace;
@property (nonatomic, copy) NSString *textAlign;
// --- Public methods ---
/**
Applies a CSS style dictionary to this element, resolving font, color,
paragraph style, etc.
@param styleDict The CSS properties to apply.
@param isLatin Whether the content language is Latin-script.
*/
- (void)applyStyleDictionary:(NSDictionary *)styleDict
isLatinLanguageBook:(BOOL)isLatin;
/**
Recursively converts this element and its children into an NSAttributedString.
@return The attributed string representing this subtree.
*/
- (NSAttributedString *)attributedString;
/**
Finalizes attributes after all children have been parsed.
Called when the closing tag is encountered.
*/
- (void)interpretAttributes;
/**
Appends text content to this element (called during SAX foundCharacters:).
*/
- (void)appendText:(NSString *)text;
/**
Returns YES if this element is a void / self-closing element (img, br, hr, etc.)
*/
- (BOOL)isVoidElement;
@end