Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __tests__/unit/options/parse-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ describe('parseOptions', () => {
);
});

it('accepts a ShadowRoot instance as the container target', () => {
const host = document.createElement('div');
document.body.appendChild(host);

const shadowRoot = host.attachShadow({ mode: 'open' });
const parsed = parseOptions({
container: shadowRoot,
} as any);

expect(parsed.container).toBe(shadowRoot);
});

it('skips design when structure is null', () => {
itemMap.set('custom-item', {
type: 'custom-item',
Expand Down
2 changes: 1 addition & 1 deletion src/options/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function parseOptions(
: undefined;

const parsed: Partial<ParsedInfographicOptions> = {
container: parsedContainer as HTMLElement,
container: parsedContainer as Element | ShadowRoot,
padding: parsePadding(padding),
};

Expand Down
6 changes: 3 additions & 3 deletions src/options/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { Data, Padding, ParsedData } from '../types';
import type { Path } from '../utils';

export interface InfographicOptions {
/** 容器,可以是选择器或者 HTMLElement */
container?: string | HTMLElement;
/** 容器,可以是选择器、Element 或 ShadowRoot */
container?: string | Element | ShadowRoot;
/** 宽度 */
width?: number | string;
/** 高度 */
Expand Down Expand Up @@ -37,7 +37,7 @@ export interface InfographicOptions {
}

export interface ParsedInfographicOptions {
container: HTMLElement;
container: Element | ShadowRoot;
width?: number | string;
height?: number | string;
padding?: Padding;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Renderer implements IRenderer {
});

try {
observer.observe(document, {
observer.observe(this.options.container, {
childList: true,
subtree: true,
});
Expand Down
Loading