From 52c3319350808bef1beb9022b045f59442008de0 Mon Sep 17 00:00:00 2001 From: LastLeaf Date: Tue, 23 Jul 2024 10:38:00 +0800 Subject: [PATCH] fix: getAllComputedStyles in domlike backend impl --- .../src/backend/current_window_backend_context.ts | 10 +++++----- glass-easel/src/backend/suggested_backend_protocol.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/glass-easel/src/backend/current_window_backend_context.ts b/glass-easel/src/backend/current_window_backend_context.ts index cbabf5a..4e4b55c 100644 --- a/glass-easel/src/backend/current_window_backend_context.ts +++ b/glass-easel/src/backend/current_window_backend_context.ts @@ -522,17 +522,17 @@ export class CurrentWindowBackendContext implements Context { cb(node?.__wxElement ?? null) } - getAllComputedStyle( + getAllComputedStyles( target: Element, - cb: (computedStyle: { name: string; value: string }[]) => void, + cb: (computedStyle: { properties: { name: string; value: string }[] }) => void, ): void { const style = window.getComputedStyle(target as unknown as HTMLElement) - const res: { name: string; value: string }[] = [] + const properties: { name: string; value: string }[] = [] for (let i = 0; i < style.length; i += 1) { const name = style[i]! - res.push({ name, value: style.getPropertyValue(name) }) + properties.push({ name, value: style.getPropertyValue(name) }) } - cb(res) + cb({ properties }) } getScrollOffset(target: Element, cb: (res: ScrollOffset) => void): void { diff --git a/glass-easel/src/backend/suggested_backend_protocol.ts b/glass-easel/src/backend/suggested_backend_protocol.ts index 4351ecc..690d5c8 100644 --- a/glass-easel/src/backend/suggested_backend_protocol.ts +++ b/glass-easel/src/backend/suggested_backend_protocol.ts @@ -16,6 +16,14 @@ interface GetWrapper { export type Element = { getAllComputedStyles(cb: (res: GetAllComputedStylesResponses) => void): void getBoundingClientRect(cb: (res: BoundingClientRect) => void): void + getBoxModel( + cb: (res: { + margin: BoundingClientRect + border: BoundingClientRect + padding: BoundingClientRect + content: BoundingClientRect + }) => void, + ): void createIntersectionObserver( relativeElement: E | null, relativeElementMargin: string,